diff --git a/typia-proof-of-concept/.gitignore b/.gitignore similarity index 100% rename from typia-proof-of-concept/.gitignore rename to .gitignore diff --git a/misc/typia-proof-of-concept/.gitignore b/misc/typia-proof-of-concept/.gitignore new file mode 100644 index 0000000..5cdf045 --- /dev/null +++ b/misc/typia-proof-of-concept/.gitignore @@ -0,0 +1,3 @@ +/dist +/node_modules +/yarn.lock diff --git a/typia-proof-of-concept/README.md b/misc/typia-proof-of-concept/README.md similarity index 100% rename from typia-proof-of-concept/README.md rename to misc/typia-proof-of-concept/README.md diff --git a/typia-proof-of-concept/package.json b/misc/typia-proof-of-concept/package.json similarity index 100% rename from typia-proof-of-concept/package.json rename to misc/typia-proof-of-concept/package.json diff --git a/typia-proof-of-concept/src/index.ts b/misc/typia-proof-of-concept/src/index.ts similarity index 100% rename from typia-proof-of-concept/src/index.ts rename to misc/typia-proof-of-concept/src/index.ts diff --git a/typia-proof-of-concept/tsconfig.json b/misc/typia-proof-of-concept/tsconfig.json similarity index 100% rename from typia-proof-of-concept/tsconfig.json rename to misc/typia-proof-of-concept/tsconfig.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..8d1e7bd --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "schemas", + "version": "1.0.0", + "main": "dist/index.js", + "license": "MIT", + "devDependencies": { + "@types/node": "^20.11.30", + "ts-node": "^10.9.2", + "ts-patch": "^3.1.2", + "typescript": "5.4.2" + }, + "dependencies": { + "typia": "^5.5.7" + }, + "scripts": { + "prepare": "ts-patch install && typia patch", + "compile": "tsc", + "cr": "tsc && node dist/index.js" + } +} diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..47ddf84 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,180 @@ +import { AcaDefect, AcaFuelLow, AcaHeadingToBase, Message, MissileToOwnshipDetected, RequestApprovalToAttack } from "./schema"; + +const samples: Array = [ + // example convo 1: high priority, low threat, no collateral + { + id: 0, + priority: 8, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.600045, lng: 11.607559 }, + threatLevel: 0.2, + type: "RS-12", + }, + collateralDamage: "none", + detectedByAca: 4, + attackWeapon: { + type: "ewSuppression", + load: 0.6, + }, + choiceWeight: 0.5, + }, + } satisfies RequestApprovalToAttack, + + // example convo 2: low priority, low threat, no collateral, weapons low + { + id: 0, + priority: 2, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.648044, lng: 11.594554 }, + threatLevel: 0.25, + type: "RS-10", + }, + collateralDamage: "none", + detectedByAca: 2, + attackWeapon: { + type: "kinetic", + load: 0.1, + }, + choiceWeight: -0.2, + }, + } satisfies RequestApprovalToAttack, + + // fuel low on aca + { + id: 0, + priority: 5, + kind: "AcaFuelLow", + data: { + acaId: 5, + fuelLevel: 0.1, + } + } satisfies AcaFuelLow, + + // example convo 3: low priority, low threat, no collateral + { + id: 0, + priority: 3, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.630549, lng: 11.583752 }, + threatLevel: 0.15, + type: "AR-5", + }, + collateralDamage: "none", + detectedByAca: 1, + attackWeapon: { + type: "ewSuppression", + load: 0.8, + }, + choiceWeight: 0.3, + }, + } satisfies RequestApprovalToAttack, + + // aca that previously send low fuel is now heading to base + { + id: 0, + priority: 5, + kind: "AcaHeadingToBase", + data: { + acaId: 5, + reason: "fuelLow", + } + } satisfies AcaHeadingToBase, + + // example convo 4: low priority, high threat, no collateral + { + id: 0, + priority: 3, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.607569, lng: 11.582834 }, + threatLevel: 0.9, + type: "RS-12", + }, + collateralDamage: "none", + detectedByAca: 2, + attackWeapon: { + type: "ewSuppression", + load: 0.7, + }, + choiceWeight: 0, + }, + } satisfies RequestApprovalToAttack, + + // example convo 5: missile heading towards ownship, weapons low on aca + { + id: 0, + priority: 10, + kind: "MissileToOwnshipDetected", + data: { + missileLocation: { lat: 48.603579, lng: 11.592345 }, + survivability: 0.8, + detectedByAca: 1, + acaAttackWeapon: { + type: "veryIntimidatingWeaponName", + load: 0.2, + }, + choiceWeight: 1, + }, + } satisfies MissileToOwnshipDetected, + + // defect on aca + { + id: 0, + priority: 7, + kind: "AcaDefect", + data: { + acaId: 1, + message: "A screw came loose mid-flight.", + }, + } satisfies AcaDefect, + + // example convo 6: high priority, low threat, possible collateral + { + id: 0, + priority: 8, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.599382, lng: 11.593753 }, + threatLevel: 0.1, + type: "DRDX-1", + }, + collateralDamage: "complex", + detectedByAca: 3, + attackWeapon: { + type: "kinetic", + load: 0.5, + }, + choiceWeight: -0.6, + }, + } satisfies RequestApprovalToAttack, + + // example convo 7: high priority, low threat, no collateral, detected by ownship + { + id: 0, + priority: 7, + kind: "RequestApprovalToAttack", + data: { + target: { + location: { lat: 48.599382, lng: 11.593753 }, + threatLevel: 0.15, + type: "DRDX-1", + }, + collateralDamage: "none", + attackWeapon: { + type: "kinetic", + load: 0.5, + }, + choiceWeight: 0.4, + }, + } satisfies RequestApprovalToAttack, +]; + +console.log(samples); diff --git a/src/schema.ts b/src/schema.ts new file mode 100644 index 0000000..cffffe5 --- /dev/null +++ b/src/schema.ts @@ -0,0 +1,67 @@ +import { tags } from "typia"; + + +/* messages *******************************************************************/ + +export type Message = RequestApprovalToAttack | AcaFuelLow | MissileToOwnshipDetected | AcaDefect | AcaHeadingToBase; + +export type BaseMessage = { + id: Id, + priority: Priority, + kind: TKind, + data: TData, +}; + +export type RequestApprovalToAttack = BaseMessage<"RequestApprovalToAttack", { + target: Target, + collateralDamage: "none" | "simple" | "complex", + detectedByAca?: Id, + attackWeapon: Weapon, + choiceWeight: Range<-1, 1>, // specifies which choice option to prefer, -1: deny, 1: approve +}>; + +export type MissileToOwnshipDetected = BaseMessage<"MissileToOwnshipDetected", { + missileLocation: GeoPoint, + survivability: Range<0, 1>, + detectedByAca?: Id, + acaAttackWeapon?: Weapon, + choiceWeight: Range<-1, 1>, // specifies which choice option to prefer, -1: avoid, 1: intervene +}> + +export type AcaFuelLow = BaseMessage<"AcaFuelLow", { + acaId: Id, + fuelLevel: Range<0, 1>, +}>; + +export type AcaDefect = BaseMessage<"AcaDefect", { + acaId: Id, + message: string, +}> + +export type AcaHeadingToBase = BaseMessage<"AcaHeadingToBase", { + acaId: Id, + reason?: "fuelLow" | "weaponsLow", +}> + + +/* utility types **************************************************************/ + +export type Id = number & tags.Type<"uint64">; +export type Priority = number & tags.Type<"uint32"> & tags.Maximum<10>; +export type Range = number & tags.Type<"float"> & tags.Minimum & tags.Maximum; + +export type Target = { + location: GeoPoint, + threatLevel: Range<0, 1>, + type: string, +}; + +export type GeoPoint = { + lat: Range<-90, 90>, + lng: Range<-180, 180>, +}; + +export type Weapon = { + type: string, + load: Range<0, 1>, +}; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..755ae4d --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "target": "es2016", + "module": "commonjs", + "esModuleInterop": true, + "forceConsistentCasingInFileNames": true, + "strict": true, + "skipLibCheck": true, + "rootDir": "src/", + "outDir": "dist/", + "strictNullChecks": true, + "plugins": [ + { + "transform": "typia/lib/transform" + } + ] + }, + "include": [ + "src/" + ] +}