@tak-ps/node-cot 12.31.0 → 12.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/lib/types/cot-types.js +38 -13
- package/dist/lib/types/cot-types.js.map +1 -1
- package/dist/lib/utils/2525.js +118 -0
- package/dist/lib/utils/2525.js.map +1 -0
- package/dist/lib/utils/type.js +40 -0
- package/dist/lib/utils/type.js.map +1 -0
- package/dist/package.json +5 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/lib/types/cot-types.ts +49 -13
- package/lib/utils/2525.ts +79 -3
- package/lib/utils/type.ts +1 -1
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
import Err from '@openaddresses/batch-error';
|
|
2
1
|
import fsp from 'node:fs/promises';
|
|
3
2
|
import xmljs from 'xml-js';
|
|
3
|
+
import TypeValidator from '../utils/type.js';
|
|
4
|
+
import MilSymType, { StandardIdentity, Domain } from '../utils/2525.js';
|
|
4
5
|
import { Type } from '@sinclair/typebox';
|
|
5
|
-
|
|
6
|
+
export const AugmentedType = Type.Object({
|
|
7
|
+
cot: Type.String(),
|
|
8
|
+
desc: Type.String(),
|
|
9
|
+
full: Type.Optional(Type.String()),
|
|
10
|
+
'2525b': Type.Optional(Type.String())
|
|
11
|
+
});
|
|
6
12
|
export const TypeFormat_COT = Type.Object({
|
|
7
13
|
cot: Type.String(),
|
|
14
|
+
desc: Type.String(),
|
|
8
15
|
full: Type.Optional(Type.String()),
|
|
9
|
-
desc: Type.String()
|
|
10
16
|
});
|
|
11
17
|
export const TypeFormat_Weapon = Type.Object({
|
|
12
18
|
cot: Type.String(),
|
|
@@ -43,12 +49,6 @@ export const TypeFormat = Type.Object({
|
|
|
43
49
|
}))
|
|
44
50
|
})
|
|
45
51
|
});
|
|
46
|
-
const checkTypes = (new AJV({
|
|
47
|
-
allErrors: true,
|
|
48
|
-
coerceTypes: true,
|
|
49
|
-
allowUnionTypes: true
|
|
50
|
-
}))
|
|
51
|
-
.compile(TypeFormat);
|
|
52
52
|
export default class CoTTypes {
|
|
53
53
|
cots;
|
|
54
54
|
weapons;
|
|
@@ -64,10 +64,7 @@ export default class CoTTypes {
|
|
|
64
64
|
}
|
|
65
65
|
static async load() {
|
|
66
66
|
const xml = xmljs.xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true });
|
|
67
|
-
|
|
68
|
-
if (checkTypes.errors)
|
|
69
|
-
throw new Err(400, null, `${checkTypes.errors[0].message} (${checkTypes.errors[0].instancePath})`);
|
|
70
|
-
const types = xml;
|
|
67
|
+
const types = TypeValidator.type(TypeFormat, xml);
|
|
71
68
|
const cots = new Map();
|
|
72
69
|
for (const cot of types.types.cot) {
|
|
73
70
|
cots.set(cot._attributes.cot, cot._attributes);
|
|
@@ -90,5 +87,33 @@ export default class CoTTypes {
|
|
|
90
87
|
}
|
|
91
88
|
return new CoTTypes(cots, weapons, relations, is, how);
|
|
92
89
|
}
|
|
90
|
+
types(si, opts = {}) {
|
|
91
|
+
if (!si)
|
|
92
|
+
throw new TypeError('No StandardIdentity Parameter provided');
|
|
93
|
+
const filtered = new Set();
|
|
94
|
+
for (const cot of this.cots.values()) {
|
|
95
|
+
if (opts.domain) {
|
|
96
|
+
if (!cot.cot.startsWith(`${opts.domain}-`)) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
;
|
|
100
|
+
}
|
|
101
|
+
if (cot.cot.match(/^a-\.-/)) {
|
|
102
|
+
const type = cot.cot.replace(/^a-\.-/, `a-${si}-`);
|
|
103
|
+
filtered.add({
|
|
104
|
+
...cot,
|
|
105
|
+
cot: type,
|
|
106
|
+
'2525b': MilSymType.is2525BConvertable(type) ? MilSymType.to2525B(type) : undefined
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
filtered.add({
|
|
111
|
+
...cot,
|
|
112
|
+
'2525b': MilSymType.is2525BConvertable(cot.cot) ? MilSymType.to2525B(cot.cot) : undefined
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return filtered;
|
|
117
|
+
}
|
|
93
118
|
}
|
|
94
119
|
//# sourceMappingURL=cot-types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cot-types.js","sourceRoot":"","sources":["../../../lib/types/cot-types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"cot-types.js","sourceRoot":"","sources":["../../../lib/types/cot-types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B,OAAO,aAAa,MAAM,kBAAkB,CAAC;AAC7C,OAAO,UAAU,EAAE,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAExC,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;IACrC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IAEnB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAElC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CACxC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;CACrC,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,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,EAAE,CAAC;oBACzC,SAAS;gBACb,CAAC;gBAAA,CAAC;YACN,CAAC;YAED,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC1B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;gBAEnD,QAAQ,CAAC,GAAG,CAAC;oBACT,GAAG,GAAG;oBACN,GAAG,EAAE,IAAI;oBACT,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;iBACtF,CAAC,CAAA;YACN,CAAC;iBAAM,CAAC;gBACJ,QAAQ,CAAC,GAAG,CAAC;oBACT,GAAG,GAAG;oBACN,OAAO,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;iBAC5F,CAAC,CAAC;YACP,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,CAAC;IACpB,CAAC;CACJ"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
export var Domain;
|
|
2
|
+
(function (Domain) {
|
|
3
|
+
Domain["ATOM"] = "a";
|
|
4
|
+
Domain["BITS"] = "b";
|
|
5
|
+
Domain["REFERENCE"] = "r";
|
|
6
|
+
Domain["TASK"] = "t";
|
|
7
|
+
Domain["CAPABILITY"] = "c";
|
|
8
|
+
Domain["REPLY"] = "y";
|
|
9
|
+
})(Domain || (Domain = {}));
|
|
10
|
+
export var StandardIdentity;
|
|
11
|
+
(function (StandardIdentity) {
|
|
12
|
+
StandardIdentity["PENDING"] = "p";
|
|
13
|
+
StandardIdentity["UNKNOWN"] = "u";
|
|
14
|
+
StandardIdentity["ASSUMED_FRIEND"] = "a";
|
|
15
|
+
StandardIdentity["FRIEND"] = "f";
|
|
16
|
+
StandardIdentity["NEUTRAL"] = "n";
|
|
17
|
+
StandardIdentity["SUSPECT"] = "s";
|
|
18
|
+
StandardIdentity["HOSTILE"] = "h";
|
|
19
|
+
StandardIdentity["JOKER"] = "j";
|
|
20
|
+
StandardIdentity["FAKER"] = "k";
|
|
21
|
+
StandardIdentity["NONE"] = "o";
|
|
22
|
+
})(StandardIdentity || (StandardIdentity = {}));
|
|
23
|
+
/**
|
|
24
|
+
* @class
|
|
25
|
+
*
|
|
26
|
+
* Convert a COT Atom Type to/from Symbol Identification Code (SIDC)
|
|
27
|
+
* Migrated to TypeScript from the original Kotlin verison
|
|
28
|
+
* @ https://github.com/cyberpython/kotcot under the MIT License
|
|
29
|
+
*/
|
|
30
|
+
export default class Type2525 {
|
|
31
|
+
/**
|
|
32
|
+
* Check a given COT Type to see if it is compatible with conversion to SIDC
|
|
33
|
+
*
|
|
34
|
+
* @param cotType - Cursor On Target Type to test
|
|
35
|
+
*/
|
|
36
|
+
static is2525BConvertable(cotType) {
|
|
37
|
+
return !!cotType.match(/^a-[puafnshjkox]-[PAGSUFXZ](-\w+)*$/);
|
|
38
|
+
}
|
|
39
|
+
static domain(cotType) {
|
|
40
|
+
const unknownDomain = cotType.split('-')[0];
|
|
41
|
+
const d = enumFromStringValue(Domain, unknownDomain);
|
|
42
|
+
if (d) {
|
|
43
|
+
return d;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error('Domain could not be determined');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
static standardIdentity(cotType) {
|
|
50
|
+
if (!cotType.startsWith('a-'))
|
|
51
|
+
return StandardIdentity.NONE;
|
|
52
|
+
if (cotType.split('-').length < 2)
|
|
53
|
+
return StandardIdentity.NONE;
|
|
54
|
+
const unknownIdentity = cotType.split('-')[1];
|
|
55
|
+
const si = enumFromStringValue(StandardIdentity, unknownIdentity);
|
|
56
|
+
if (si) {
|
|
57
|
+
return si;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return StandardIdentity.NONE;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Given a COT Atom Type, return an SIDC
|
|
65
|
+
*
|
|
66
|
+
* @param cotType - Cursor On Target Type (Note must start with atomic "a")
|
|
67
|
+
*/
|
|
68
|
+
static to2525B(cotType) {
|
|
69
|
+
if (!this.is2525BConvertable(cotType)) {
|
|
70
|
+
throw new TypeError("CoT to 2525B can only be applied to well-formed Atom type CoT Events.");
|
|
71
|
+
}
|
|
72
|
+
const m2525bChars = cotType.substring(4).replace(/[^A-Z0-9]+/g, "");
|
|
73
|
+
const m2525bBattleDim = m2525bChars.substring(0, 1);
|
|
74
|
+
const cotAffiliation = cotType.substring(2, 3);
|
|
75
|
+
const m2525bAffiliation = (cotAffiliation === "o" || cotAffiliation === "x")
|
|
76
|
+
? "U"
|
|
77
|
+
: cotAffiliation.toUpperCase();
|
|
78
|
+
const m2525bFuncId = m2525bChars.length > 1
|
|
79
|
+
? m2525bChars.substring(1).padEnd(6, "-").substring(0, 6)
|
|
80
|
+
: "------";
|
|
81
|
+
return `S${m2525bAffiliation}${m2525bBattleDim}P${m2525bFuncId}-----`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Check a given SIDC to see if it is compatible with conversion to CoT Type
|
|
85
|
+
*
|
|
86
|
+
* @param sidc - SIDC to test
|
|
87
|
+
*/
|
|
88
|
+
static isTypeConvertable(sidc) {
|
|
89
|
+
return !!sidc.match(/^S[PUAFNSHGWMDLJK-][PAGSUFXZ-][AP-][A-Z0-9-]{10}[AECGNS-]$/);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Given an SIDC, return a CoT Type
|
|
93
|
+
*
|
|
94
|
+
* @param sidc - SIDC to convert
|
|
95
|
+
*/
|
|
96
|
+
static from2525B(sidc) {
|
|
97
|
+
if (!this.isTypeConvertable(sidc)) {
|
|
98
|
+
throw new Error("2525B to CoT can only be applied to well-formed warfighting 2525B SIDCs.");
|
|
99
|
+
}
|
|
100
|
+
const m2525bAffiliation = sidc.substring(1, 2);
|
|
101
|
+
const cotAffiliation = ["G", "W", "M", "D", "L"].includes(m2525bAffiliation)
|
|
102
|
+
? "f"
|
|
103
|
+
: m2525bAffiliation === "-"
|
|
104
|
+
? "o"
|
|
105
|
+
: m2525bAffiliation.toLowerCase();
|
|
106
|
+
const cotBattleDim = sidc.substring(2, 3);
|
|
107
|
+
const cotFuncId = Array.from(sidc.substring(4, 10).replace(/[^A-Z0-9]+/g, ""))
|
|
108
|
+
.map((x) => `-${x}`)
|
|
109
|
+
.join("");
|
|
110
|
+
return `a-${cotAffiliation}-${cotBattleDim}${cotFuncId}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function enumFromStringValue(enm, value) {
|
|
114
|
+
return Object.values(enm).includes(value)
|
|
115
|
+
? value
|
|
116
|
+
: undefined;
|
|
117
|
+
}
|
|
118
|
+
//# sourceMappingURL=2525.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2525.js","sourceRoot":"","sources":["../../../lib/utils/2525.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,MAOX;AAPD,WAAY,MAAM;IACd,oBAAU,CAAA;IACV,oBAAU,CAAA;IACV,yBAAe,CAAA;IACf,oBAAU,CAAA;IACV,0BAAgB,CAAA;IAChB,qBAAW,CAAA;AACf,CAAC,EAPW,MAAM,KAAN,MAAM,QAOjB;AAED,MAAM,CAAN,IAAY,gBAWX;AAXD,WAAY,gBAAgB;IACxB,iCAAa,CAAA;IACb,iCAAa,CAAA;IACb,wCAAoB,CAAA;IACpB,gCAAY,CAAA;IACZ,iCAAa,CAAA;IACb,iCAAa,CAAA;IACb,iCAAa,CAAA;IACb,+BAAW,CAAA;IACX,+BAAW,CAAA;IACX,8BAAU,CAAA;AACd,CAAC,EAXW,gBAAgB,KAAh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C,CAAC,QAAQ,CAAC,iBAAiB,CAAC;YACxE,CAAC,CAAC,GAAG;YACL,CAAC,CAAC,iBAAiB,KAAK,GAAG;gBACvB,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,iBAAiB,CAAC,WAAW,EAAE,CAAC;QAElC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1C,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;aAC7E,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;aACnB,IAAI,CAAC,EAAE,CAAC,CAAC;QAElB,OAAO,KAAK,cAAc,IAAI,YAAY,GAAG,SAAS,EAAE,CAAC;IAC7D,CAAC;CACJ;AAED,SAAS,mBAAmB,CAAK,GAAsB,EAAE,KAAa;IAClE,OAAQ,MAAM,CAAC,MAAM,CAAC,GAAG,CAAyB,CAAC,QAAQ,CAAC,KAAK,CAAC;QAC9D,CAAC,CAAC,KAAqB;QACvB,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Value } from '@sinclair/typebox/value';
|
|
2
|
+
export default class TypeValidator {
|
|
3
|
+
/**
|
|
4
|
+
* Arbitrary JSON objects occasionally need to get typed as part of an ETL
|
|
5
|
+
* This function provides the ability to strictly type unknown objects at runtime
|
|
6
|
+
*/
|
|
7
|
+
static type(type, body, opts) {
|
|
8
|
+
if (!opts)
|
|
9
|
+
opts = {};
|
|
10
|
+
if (opts.verbose === undefined)
|
|
11
|
+
opts.verbose = false;
|
|
12
|
+
if (opts.default === undefined)
|
|
13
|
+
opts.default = true;
|
|
14
|
+
if (opts.convert === undefined)
|
|
15
|
+
opts.convert = true;
|
|
16
|
+
if (opts.clean === undefined)
|
|
17
|
+
opts.clean = true;
|
|
18
|
+
if (opts.default) {
|
|
19
|
+
Value.Default(type, body);
|
|
20
|
+
}
|
|
21
|
+
if (opts.clean) {
|
|
22
|
+
Value.Clean(type, body);
|
|
23
|
+
}
|
|
24
|
+
if (opts.convert) {
|
|
25
|
+
Value.Convert(type, body);
|
|
26
|
+
}
|
|
27
|
+
const result = Value.Check(type, body);
|
|
28
|
+
if (result)
|
|
29
|
+
return body;
|
|
30
|
+
const errors = Value.Errors(type, body);
|
|
31
|
+
const firstError = errors.First();
|
|
32
|
+
if (opts.verbose) {
|
|
33
|
+
throw new Error(`Internal Validation Error: ${JSON.stringify(firstError)} -- Body: ${JSON.stringify(body)}`);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
throw new Error(`Internal Validation Error`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../lib/utils/type.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAS/C,MAAM,CAAC,OAAO,OAAO,aAAa;IAC9B;;;OAGG;IACH,MAAM,CAAC,IAAI,CACP,IAAO,EACP,IAAa,EACb,IAAe;QAEf,IAAI,CAAC,IAAI;YAAE,IAAI,GAAG,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;QACrD,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpD,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS;YAAE,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAEhD,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC7B,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;YACb,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC3B,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAC7B,CAAC;QAED,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;QAEtC,IAAI,MAAM;YAAE,OAAO,IAAI,CAAC;QAExB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAExC,MAAM,UAAU,GAAG,MAAM,CAAC,KAAK,EAAE,CAAC;QAElC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,8BAA8B,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,aAAa,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACjH,CAAC;aAAM,CAAC;YACJ,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;QACjD,CAAC;IACL,CAAC;CACJ"}
|
package/dist/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tak-ps/node-cot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.32.1",
|
|
5
5
|
"description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
|
|
6
6
|
"author": "Nick Ingalls <nick@ingalls.ca>",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./2525": "./dist/lib/utils/2525.js"
|
|
12
|
+
},
|
|
9
13
|
"scripts": {
|
|
10
14
|
"test": "c8 --reporter=lcov ts-node-test test/",
|
|
11
15
|
"lint": "eslint *.ts lib/ test/",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"root":["../index.ts","../test/basemaps.test.ts","../test/chat.test.ts","../test/cot-fileshare.test.ts","../test/cot-itak.test.ts","../test/cot-mma.test.ts","../test/cot-polyline.test.ts","../test/cot-range-and-bearing.test.ts","../test/cot-routes.test.ts","../test/cot-types.test.ts","../test/cot-uas-tool.test.ts","../test/cot-video.test.ts","../test/cot_is.test.ts","../test/creator.test.ts","../test/diff.test.ts","../test/flow-tags.test.ts","../test/force-delete.ts","../test/from_geojson.test.ts","../test/milsym.test.ts","../test/newlines.test.ts","../test/package.test.ts","../test/reversal-geojson.test.ts","../test/reversal-proto.test.ts","../test/stream.ts","../test/taskings-mission.test.ts","../test/util.test.ts","../test/validation.test.ts","../lib/chat.ts","../lib/cot.ts","../lib/data-package.ts","../lib/fileshare.ts","../lib/force-delete.ts","../lib/sensor.ts","../lib/xml-document.ts","../lib/xml/basemap.ts","../lib/xml/iconset.ts"],"version":"5.8.3"}
|
|
1
|
+
{"root":["../index.ts","../test/2525.test.ts","../test/basemaps.test.ts","../test/chat.test.ts","../test/cot-fileshare.test.ts","../test/cot-itak.test.ts","../test/cot-mma.test.ts","../test/cot-polyline.test.ts","../test/cot-range-and-bearing.test.ts","../test/cot-routes.test.ts","../test/cot-types.test.ts","../test/cot-uas-tool.test.ts","../test/cot-video.test.ts","../test/cot_is.test.ts","../test/creator.test.ts","../test/diff.test.ts","../test/flow-tags.test.ts","../test/force-delete.ts","../test/from_geojson.test.ts","../test/milsym.test.ts","../test/newlines.test.ts","../test/package.test.ts","../test/reversal-geojson.test.ts","../test/reversal-proto.test.ts","../test/stream.ts","../test/taskings-mission.test.ts","../test/util.test.ts","../test/validation.test.ts","../lib/chat.ts","../lib/cot.ts","../lib/data-package.ts","../lib/fileshare.ts","../lib/force-delete.ts","../lib/sensor.ts","../lib/xml-document.ts","../lib/xml/basemap.ts","../lib/xml/iconset.ts"],"version":"5.8.3"}
|
package/lib/types/cot-types.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import Err from '@openaddresses/batch-error';
|
|
2
1
|
import fsp from 'node:fs/promises';
|
|
3
2
|
import xmljs from 'xml-js';
|
|
4
3
|
import type { Static } from '@sinclair/typebox';
|
|
4
|
+
import TypeValidator from '../utils/type.js';
|
|
5
|
+
import MilSymType, { StandardIdentity, Domain } from '../utils/2525.js';
|
|
5
6
|
import { Type } from '@sinclair/typebox'
|
|
6
|
-
|
|
7
|
+
|
|
8
|
+
export const AugmentedType = Type.Object({
|
|
9
|
+
cot: Type.String(),
|
|
10
|
+
desc: Type.String(),
|
|
11
|
+
|
|
12
|
+
full: Type.Optional(Type.String()),
|
|
13
|
+
|
|
14
|
+
'2525b': Type.Optional(Type.String())
|
|
15
|
+
});
|
|
7
16
|
|
|
8
17
|
export const TypeFormat_COT = Type.Object({
|
|
9
18
|
cot: Type.String(),
|
|
19
|
+
desc: Type.String(),
|
|
10
20
|
full: Type.Optional(Type.String()),
|
|
11
|
-
desc: Type.String()
|
|
12
21
|
})
|
|
13
22
|
|
|
14
23
|
export const TypeFormat_Weapon = Type.Object({
|
|
@@ -51,13 +60,6 @@ export const TypeFormat = Type.Object({
|
|
|
51
60
|
})
|
|
52
61
|
});
|
|
53
62
|
|
|
54
|
-
const checkTypes = (new AJV({
|
|
55
|
-
allErrors: true,
|
|
56
|
-
coerceTypes: true,
|
|
57
|
-
allowUnionTypes: true
|
|
58
|
-
}))
|
|
59
|
-
.compile(TypeFormat);
|
|
60
|
-
|
|
61
63
|
export default class CoTTypes {
|
|
62
64
|
cots: Map<string, Static<typeof TypeFormat_COT>>
|
|
63
65
|
weapons: Map<string, Static<typeof TypeFormat_Weapon>>
|
|
@@ -82,9 +84,7 @@ export default class CoTTypes {
|
|
|
82
84
|
static async load(): Promise<CoTTypes> {
|
|
83
85
|
const xml = xmljs.xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true })
|
|
84
86
|
|
|
85
|
-
|
|
86
|
-
if (checkTypes.errors) throw new Err(400, null, `${checkTypes.errors[0].message} (${checkTypes.errors[0].instancePath})`);
|
|
87
|
-
const types = xml as Static<typeof TypeFormat>;
|
|
87
|
+
const types = TypeValidator.type(TypeFormat, xml);
|
|
88
88
|
|
|
89
89
|
const cots: Map<string, Static<typeof TypeFormat_COT>> = new Map();
|
|
90
90
|
for (const cot of types.types.cot) {
|
|
@@ -113,4 +113,40 @@ export default class CoTTypes {
|
|
|
113
113
|
|
|
114
114
|
return new CoTTypes(cots, weapons, relations, is, how);
|
|
115
115
|
}
|
|
116
|
+
|
|
117
|
+
types(
|
|
118
|
+
si: StandardIdentity,
|
|
119
|
+
opts: {
|
|
120
|
+
domain?: Domain
|
|
121
|
+
} = {}
|
|
122
|
+
): Set<Static<typeof AugmentedType>> {
|
|
123
|
+
if (!si) throw new TypeError('No StandardIdentity Parameter provided');
|
|
124
|
+
|
|
125
|
+
const filtered: Set<Static<typeof AugmentedType>> = new Set();
|
|
126
|
+
|
|
127
|
+
for (const cot of this.cots.values()) {
|
|
128
|
+
if (opts.domain) {
|
|
129
|
+
if (!cot.cot.startsWith(`${opts.domain}-`)) {
|
|
130
|
+
continue;
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (cot.cot.match(/^a-\.-/)) {
|
|
135
|
+
const type = cot.cot.replace(/^a-\.-/, `a-${si}-`);
|
|
136
|
+
|
|
137
|
+
filtered.add({
|
|
138
|
+
...cot,
|
|
139
|
+
cot: type,
|
|
140
|
+
'2525b': MilSymType.is2525BConvertable(type) ? MilSymType.to2525B(type) : undefined
|
|
141
|
+
})
|
|
142
|
+
} else {
|
|
143
|
+
filtered.add({
|
|
144
|
+
...cot,
|
|
145
|
+
'2525b': MilSymType.is2525BConvertable(cot.cot) ? MilSymType.to2525B(cot.cot) : undefined
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return filtered;
|
|
151
|
+
}
|
|
116
152
|
}
|
package/lib/utils/2525.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
export enum Domain {
|
|
2
|
+
ATOM = 'a',
|
|
3
|
+
BITS = 'b',
|
|
4
|
+
REFERENCE = 'r',
|
|
5
|
+
TASK = 't',
|
|
6
|
+
CAPABILITY = 'c',
|
|
7
|
+
REPLY = 'y',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum StandardIdentity {
|
|
11
|
+
PENDING = 'p',
|
|
12
|
+
UNKNOWN = 'u',
|
|
13
|
+
ASSUMED_FRIEND = 'a',
|
|
14
|
+
FRIEND = 'f',
|
|
15
|
+
NEUTRAL = 'n',
|
|
16
|
+
SUSPECT = 's',
|
|
17
|
+
HOSTILE = 'h',
|
|
18
|
+
JOKER = 'j',
|
|
19
|
+
FAKER = 'k',
|
|
20
|
+
NONE = 'o'
|
|
21
|
+
}
|
|
22
|
+
|
|
1
23
|
/**
|
|
2
24
|
* @class
|
|
3
25
|
*
|
|
@@ -6,13 +28,47 @@
|
|
|
6
28
|
* @ https://github.com/cyberpython/kotcot under the MIT License
|
|
7
29
|
*/
|
|
8
30
|
export default class Type2525 {
|
|
31
|
+
/**
|
|
32
|
+
* Check a given COT Type to see if it is compatible with conversion to SIDC
|
|
33
|
+
*
|
|
34
|
+
* @param cotType - Cursor On Target Type to test
|
|
35
|
+
*/
|
|
36
|
+
static is2525BConvertable(cotType: string): boolean {
|
|
37
|
+
return !!cotType.match(/^a-[puafnshjkox]-[PAGSUFXZ](-\w+)*$/);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static domain(cotType: string): Domain {
|
|
41
|
+
const unknownDomain = cotType.split('-')[0];
|
|
42
|
+
|
|
43
|
+
const d = enumFromStringValue<Domain>(Domain, unknownDomain);
|
|
44
|
+
if (d) {
|
|
45
|
+
return d;
|
|
46
|
+
} else {
|
|
47
|
+
throw new Error('Domain could not be determined');
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static standardIdentity(cotType: string): StandardIdentity {
|
|
52
|
+
if (!cotType.startsWith('a-')) return StandardIdentity.NONE;
|
|
53
|
+
if (cotType.split('-').length < 2) return StandardIdentity.NONE;
|
|
54
|
+
|
|
55
|
+
const unknownIdentity = cotType.split('-')[1];
|
|
56
|
+
|
|
57
|
+
const si = enumFromStringValue(StandardIdentity, unknownIdentity);
|
|
58
|
+
if (si) {
|
|
59
|
+
return si;
|
|
60
|
+
} else {
|
|
61
|
+
return StandardIdentity.NONE;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
9
64
|
|
|
10
65
|
/**
|
|
11
66
|
* Given a COT Atom Type, return an SIDC
|
|
67
|
+
*
|
|
12
68
|
* @param cotType - Cursor On Target Type (Note must start with atomic "a")
|
|
13
69
|
*/
|
|
14
70
|
static to2525B(cotType: string): string {
|
|
15
|
-
if (!
|
|
71
|
+
if (!this.is2525BConvertable(cotType)) {
|
|
16
72
|
throw new TypeError("CoT to 2525B can only be applied to well-formed Atom type CoT Events.")
|
|
17
73
|
}
|
|
18
74
|
|
|
@@ -31,8 +87,22 @@ export default class Type2525 {
|
|
|
31
87
|
return `S${m2525bAffiliation}${m2525bBattleDim}P${m2525bFuncId}-----`;
|
|
32
88
|
}
|
|
33
89
|
|
|
34
|
-
|
|
35
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Check a given SIDC to see if it is compatible with conversion to CoT Type
|
|
92
|
+
*
|
|
93
|
+
* @param sidc - SIDC to test
|
|
94
|
+
*/
|
|
95
|
+
static isTypeConvertable(sidc: string): boolean {
|
|
96
|
+
return !!sidc.match(/^S[PUAFNSHGWMDLJK-][PAGSUFXZ-][AP-][A-Z0-9-]{10}[AECGNS-]$/)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Given an SIDC, return a CoT Type
|
|
101
|
+
*
|
|
102
|
+
* @param sidc - SIDC to convert
|
|
103
|
+
*/
|
|
104
|
+
static from2525B(sidc: string) : string {
|
|
105
|
+
if (!this.isTypeConvertable(sidc)) {
|
|
36
106
|
throw new Error("2525B to CoT can only be applied to well-formed warfighting 2525B SIDCs.");
|
|
37
107
|
}
|
|
38
108
|
|
|
@@ -51,3 +121,9 @@ export default class Type2525 {
|
|
|
51
121
|
return `a-${cotAffiliation}-${cotBattleDim}${cotFuncId}`;
|
|
52
122
|
}
|
|
53
123
|
}
|
|
124
|
+
|
|
125
|
+
function enumFromStringValue<T> (enm: { [s: string]: T}, value: string): T | undefined {
|
|
126
|
+
return (Object.values(enm) as unknown as string[]).includes(value)
|
|
127
|
+
? value as unknown as T
|
|
128
|
+
: undefined;
|
|
129
|
+
}
|
package/lib/utils/type.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tak-ps/node-cot",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.32.1",
|
|
5
5
|
"description": "Lightweight JavaScript library for parsing and manipulating TAK messages",
|
|
6
6
|
"author": "Nick Ingalls <nick@ingalls.ca>",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"types": "index.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./dist/index.js",
|
|
11
|
+
"./2525": "./dist/lib/utils/2525.js"
|
|
12
|
+
},
|
|
9
13
|
"scripts": {
|
|
10
14
|
"test": "c8 --reporter=lcov ts-node-test test/",
|
|
11
15
|
"lint": "eslint *.ts lib/ test/",
|