@tak-ps/node-cot 10.5.0 → 10.6.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 CHANGED
@@ -10,6 +10,14 @@
10
10
 
11
11
  ## Version History
12
12
 
13
+ ### v10.6.1 - 2024-08-05
14
+
15
+ - :bug: Fix bug in DataPackage attachment hash calculation
16
+
17
+ ### v10.6.0 - 2024-08-05
18
+
19
+ - :tada: Initial release of the CotTypes manager/parser
20
+
13
21
  ### v10.5.0
14
22
 
15
23
  - :bug: Fix an instance of `a-f-g` cot type to `a-f-G`
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import CoT from './lib/cot.js';
2
2
  export * as Feature from './lib/feature.js';
3
3
  export * as Types from './lib/types.js';
4
+ export * as CoTTypes from './lib/cot-types.js';
4
5
  export * from './lib/chat.js';
5
6
  export * from './lib/fileshare.js';
6
7
  export * from './lib/data-package.js';
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AAErC,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,KAAK,OAAO,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,KAAK,MAAM,gBAAgB,CAAA;AACvC,OAAO,KAAK,QAAQ,MAAM,oBAAoB,CAAA;AAC9C,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AAErC,eAAe,GAAG,CAAC"}
@@ -0,0 +1,94 @@
1
+ import Err from '@openaddresses/batch-error';
2
+ import fsp from 'node:fs/promises';
3
+ import xmljs from 'xml-js';
4
+ import { Type } from '@sinclair/typebox';
5
+ import AJV from 'ajv';
6
+ export const TypeFormat_COT = Type.Object({
7
+ cot: Type.String(),
8
+ full: Type.Optional(Type.String()),
9
+ desc: Type.String()
10
+ });
11
+ export const TypeFormat_Weapon = Type.Object({
12
+ cot: Type.String(),
13
+ desc: Type.String()
14
+ });
15
+ export const TypeFormat_Relation = Type.Object({
16
+ cot: Type.String(),
17
+ desc: Type.String()
18
+ });
19
+ export const TypeFormat_Is = Type.Object({
20
+ what: Type.String(),
21
+ match: Type.String()
22
+ });
23
+ export const TypeFormat_How = Type.Object({
24
+ what: Type.String(),
25
+ value: Type.String()
26
+ });
27
+ export const TypeFormat = Type.Object({
28
+ types: Type.Object({
29
+ cot: Type.Array(Type.Object({
30
+ _attributes: TypeFormat_COT
31
+ })),
32
+ weapon: Type.Array(Type.Object({
33
+ _attributes: TypeFormat_Weapon
34
+ })),
35
+ relation: Type.Array(Type.Object({
36
+ _attributes: TypeFormat_Relation
37
+ })),
38
+ is: Type.Array(Type.Object({
39
+ _attributes: TypeFormat_Is
40
+ })),
41
+ how: Type.Array(Type.Object({
42
+ _attributes: TypeFormat_How
43
+ }))
44
+ })
45
+ });
46
+ const checkTypes = (new AJV({
47
+ allErrors: true,
48
+ coerceTypes: true,
49
+ allowUnionTypes: true
50
+ }))
51
+ .compile(TypeFormat);
52
+ export class CoTTypes {
53
+ cots;
54
+ weapons;
55
+ relations;
56
+ is;
57
+ how;
58
+ constructor(cots, weapons, relations, is, how) {
59
+ this.cots = cots;
60
+ this.weapons = weapons;
61
+ this.relations = relations;
62
+ this.is = is;
63
+ this.how = how;
64
+ }
65
+ static async load() {
66
+ const xml = xmljs.xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true });
67
+ checkTypes(xml);
68
+ if (checkTypes.errors)
69
+ throw new Err(400, null, `${checkTypes.errors[0].message} (${checkTypes.errors[0].instancePath})`);
70
+ const types = xml;
71
+ const cots = new Map();
72
+ for (const cot of types.types.cot) {
73
+ cots.set(cot._attributes.cot, cot._attributes);
74
+ }
75
+ const weapons = new Map();
76
+ for (const weapon of types.types.weapon) {
77
+ weapons.set(weapon._attributes.cot, weapon._attributes);
78
+ }
79
+ const relations = new Map();
80
+ for (const relation of types.types.relation) {
81
+ relations.set(relation._attributes.cot, relation._attributes);
82
+ }
83
+ const is = new Map();
84
+ for (const i of types.types.is) {
85
+ is.set(i._attributes.what, i._attributes);
86
+ }
87
+ const how = new Map();
88
+ for (const h of types.types.how) {
89
+ how.set(h._attributes.value, h._attributes);
90
+ }
91
+ return new CoTTypes(cots, weapons, relations, is, how);
92
+ }
93
+ }
94
+ //# sourceMappingURL=cot-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cot-types.js","sourceRoot":"","sources":["../../lib/cot-types.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAC7C,OAAO,GAAG,MAAM,kBAAkB,CAAC;AACnC,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,OAAO,EAAU,IAAI,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,CAAC;IACtC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAClC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;CACtB,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;CACtB,CAAC,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