From 728be6da21f8f950d9fea17f23fd36b6b9291ef9 Mon Sep 17 00:00:00 2001 From: thetek Date: Wed, 3 Apr 2024 12:27:49 +0200 Subject: [PATCH] refactor: only types.ts file for use with submodules --- README.md | 15 --- package.json | 19 --- src/schema.ts => schema-types.ts | 0 src/index.ts | 207 ------------------------------- tsconfig.json | 21 ---- 5 files changed, 262 deletions(-) delete mode 100644 README.md delete mode 100644 package.json rename src/schema.ts => schema-types.ts (100%) delete mode 100644 src/index.ts delete mode 100644 tsconfig.json diff --git a/README.md b/README.md deleted file mode 100644 index d70a689..0000000 --- a/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# message-schemas - -## Development - -Install dependencies: - -```sh -yarn install -``` - -Check samples: - -```sh -yarn run check -``` diff --git a/package.json b/package.json deleted file mode 100644 index 8103537..0000000 --- a/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "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", - "check": "tsc && node dist/index.js" - } -} diff --git a/src/schema.ts b/schema-types.ts similarity index 100% rename from src/schema.ts rename to schema-types.ts diff --git a/src/index.ts b/src/index.ts deleted file mode 100644 index 7c0c910..0000000 --- a/src/index.ts +++ /dev/null @@ -1,207 +0,0 @@ -import { AcaDefect, AcaFuelLow, AcaHeadingToBase, Message, MissileToOwnshipDetected, RequestApprovalToAttack } from "./schema"; -import typia from "typia"; - - -/* sample messages ********************************************************************************/ - -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: 1, - 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: 2, - priority: 5, - kind: "AcaFuelLow", - data: { - acaId: 5, - fuelLevel: 0.1, - }, - } satisfies AcaFuelLow, - - // example convo 3: low priority, low threat, no collateral - { - id: 3, - 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: 4, - priority: 5, - kind: "AcaHeadingToBase", - data: { - acaId: 5, - reason: "fuelLow", - }, - } satisfies AcaHeadingToBase, - - // example convo 4: low priority, high threat, no collateral - { - id: 5, - 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: 6, - 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: 7, - 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: 8, - 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: 9, - 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, -]; - - -/* validation *************************************************************************************/ - -const VALIDATORS = { - "AcaDefect": typia.createValidateEquals(), - "AcaFuelLow": typia.createValidateEquals(), - "AcaHeadingToBase": typia.createValidateEquals(), - "MissileToOwnshipDetected": typia.createValidateEquals(), - "RequestApprovalToAttack": typia.createValidateEquals(), -}; - -for (const msg of SAMPLES) { - const validator = VALIDATORS[msg.kind]; - const validationResult = validator(msg); - - if (validationResult.success) { - console.log(`msg ${msg.id}: \x1b[32mOK\x1b[0m`); - } else { - console.log(`msg ${msg.id}: \x1b[31mERROR\x1b[0m`); - for (const error of validationResult.errors) { - console.log(` - ${error.path}, expected ${error.expected}, found value ${error.value}`); - } - } -} diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index 755ae4d..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "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/" - ] -}