@tak-ps/node-cot 12.3.0 → 12.4.0

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
@@ -12,6 +12,11 @@
12
12
 
13
13
  ### Pending Fixed
14
14
 
15
+ ### v12.4.0 - 2024-09-30
16
+
17
+ - :rocket: Use internal XMLDocument class as base for Iconset/Basemap
18
+ - :tada: Add initial Iconset Types
19
+
15
20
  ### v12.3.0 - 2024-09-18
16
21
 
17
22
  - :bug: Support parsing CoTs with empty/non-populated video tag
package/dist/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './lib/chat.js';
6
6
  export * from './lib/fileshare.js';
7
7
  export * from './lib/force-delete.js';
8
8
  export * from './lib/data-package.js';
9
- export * from './lib/basemap.js';
9
+ export * from './lib/xml/basemap.js';
10
+ export * from './lib/xml/iconset.js';
10
11
  export default CoT;
11
12
  //# sourceMappingURL=index.js.map
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,wBAAwB,CAAA;AACjD,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAA;AACpD,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAEhC,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,wBAAwB,CAAA;AACjD,OAAO,KAAK,KAAK,MAAM,sBAAsB,CAAA;AAC7C,OAAO,KAAK,QAAQ,MAAM,0BAA0B,CAAA;AACpD,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AACrC,cAAc,uBAAuB,CAAA;AACrC,cAAc,sBAAsB,CAAA;AACpC,cAAc,sBAAsB,CAAA;AAEpC,eAAe,GAAG,CAAC"}
@@ -13,7 +13,9 @@ export const BasemapMapSource = Type.Object({
13
13
  _text: Type.String()
14
14
  }),
15
15
  tileUpdate: Type.Optional(Type.Object({
16
- _text: Type.String()
16
+ _text: Type.String({
17
+ default: 'None'
18
+ })
17
19
  })),
18
20
  url: Type.Optional(Type.Object({
19
21
  _text: Type.String()
@@ -1 +1 @@
1
- {"version":3,"file":"basemap.js","sourceRoot":"","sources":["../../../lib/types/basemap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACd,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;KACxB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;KACxB,CAAC;IACF,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC;IACF,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QAClC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC;IACH,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC;IACH,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QACvC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC;CACN,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,MAAM,CAAC;IACvB,eAAe,EAAE,gBAAgB;CACpC,CAAC,CAAA"}
1
+ {"version":3,"file":"basemap.js","sourceRoot":"","sources":["../../../lib/types/basemap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC;IACxC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;QACd,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;KACxB,CAAC;IACF,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE;KACxB,CAAC;IACF,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC;QAClB,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC;IACF,UAAU,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QAClC,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC;YACf,OAAO,EAAE,MAAM;SAClB,CAAC;KACL,CAAC,CAAC;IACH,GAAG,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QAC3B,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC;IACH,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;QACvC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;KACvB,CAAC,CAAC;CACN,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,MAAM,CAAC;IACvB,eAAe,EAAE,gBAAgB;CACpC,CAAC,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { Type } from '@sinclair/typebox';
2
+ export const IconsetAttributes = Type.Object({
3
+ uid: Type.String(),
4
+ version: Type.String(),
5
+ name: Type.String(),
6
+ default_group: Type.Optional(Type.String()),
7
+ default_friendly: Type.Optional(Type.String()),
8
+ default_hostile: Type.Optional(Type.String()),
9
+ default_neutral: Type.Optional(Type.String()),
10
+ default_unknown: Type.Optional(Type.String()),
11
+ skip_resize: Type.Boolean({ default: false }),
12
+ });
13
+ export default Type.Object({
14
+ iconset: Type.Object({
15
+ _attributes: IconsetAttributes
16
+ })
17
+ });
18
+ //# sourceMappingURL=iconset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iconset.js","sourceRoot":"","sources":["../../../lib/types/iconset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAEzC,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC,MAAM,CAAC;IACzC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE;IAClB,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE;IACtB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;IACnB,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC3C,gBAAgB,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC9C,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7C,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7C,eAAe,EAAE,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC7C,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;CAChD,CAAC,CAAA;AAEF,eAAe,IAAI,CAAC,MAAM,CAAC;IACvB,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC;QACjB,WAAW,EAAE,iBAAiB;KACjC,CAAC;CACL,CAAC,CAAA"}
@@ -0,0 +1,22 @@
1
+ import XMLDocument from '../xml-document.js';
2
+ import BasemapSchema from '../types/basemap.js';
3
+ import AJV from 'ajv';
4
+ const checkBasemap = (new AJV({
5
+ allErrors: true,
6
+ coerceTypes: true,
7
+ allowUnionTypes: true
8
+ }))
9
+ .compile(BasemapSchema);
10
+ /**
11
+ * Helper class for creating and parsing Basemap XML documents
12
+ */
13
+ export class Basemap extends XMLDocument {
14
+ /**
15
+ * Return a Basemap from a string XML representation
16
+ */
17
+ static parse(input) {
18
+ const basemap = super.check(input, checkBasemap);
19
+ return new Basemap(basemap);
20
+ }
21
+ }
22
+ //# sourceMappingURL=basemap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"basemap.js","sourceRoot":"","sources":["../../../lib/xml/basemap.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAE7C,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,YAAY,GAAG,CAAC,IAAI,GAAG,CAAC;IAC1B,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;CACxB,CAAC,CAAC;KACE,OAAO,CAAC,aAAa,CAAC,CAAC;AAI5B;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,WAAwB;IACjD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAa;QACtB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAc,KAAK,EAAE,YAAY,CAAC,CAAC;QAC9D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACJ"}
@@ -0,0 +1,22 @@
1
+ import XMLDocument from '../xml-document.js';
2
+ import IconsetSchema from '../types/iconset.js';
3
+ import AJV from 'ajv';
4
+ const checkIconset = (new AJV({
5
+ allErrors: true,
6
+ coerceTypes: true,
7
+ allowUnionTypes: true
8
+ }))
9
+ .compile(IconsetSchema);
10
+ /**
11
+ * Helper class for creating and parsing Iconset XML documents
12
+ */
13
+ export class Iconset extends XMLDocument {
14
+ /**
15
+ * Return an Iconset from a string XML representation
16
+ */
17
+ static parse(input) {
18
+ const basemap = super.check(input, checkIconset);
19
+ return new Iconset(basemap);
20
+ }
21
+ }
22
+ //# sourceMappingURL=iconset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iconset.js","sourceRoot":"","sources":["../../../lib/xml/iconset.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAE7C,OAAO,aAAa,MAAM,qBAAqB,CAAC;AAChD,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,YAAY,GAAG,CAAC,IAAI,GAAG,CAAC;IAC1B,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;CACxB,CAAC,CAAC;KACE,OAAO,CAAC,aAAa,CAAC,CAAC;AAI5B;;GAEG;AACH,MAAM,OAAO,OAAQ,SAAQ,WAAwB;IACjD;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAa;QACtB,MAAM,OAAO,GAAG,KAAK,CAAC,KAAK,CAAc,KAAK,EAAE,YAAY,CAAC,CAAC;QAC9D,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACJ"}
@@ -0,0 +1,23 @@
1
+ import Err from '@openaddresses/batch-error';
2
+ import xmljs from 'xml-js';
3
+ /**
4
+ * Core XML Document support used for XML fortatted DataPackages documents
5
+ * such as Iconsets or Basemaps
6
+ */
7
+ export default class XMLDocument {
8
+ raw;
9
+ constructor(raw) {
10
+ this.raw = raw;
11
+ }
12
+ static check(input, check) {
13
+ const xml = xmljs.xml2js(input, { compact: true });
14
+ check(xml);
15
+ if (check.errors)
16
+ throw new Err(400, null, `${check.errors[0].message} (${check.errors[0].instancePath})`);
17
+ return xml;
18
+ }
19
+ to_xml() {
20
+ return xmljs.js2xml(this.raw, { compact: true });
21
+ }
22
+ }
23
+ //# sourceMappingURL=xml-document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xml-document.js","sourceRoot":"","sources":["../../lib/xml-document.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAE7C,OAAO,KAAK,MAAM,QAAQ,CAAC;AAE3B;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC5B,GAAG,CAAI;IAEP,YAAY,GAAM;QACd,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,MAAM,CAAC,KAAK,CAAI,KAAa,EAAE,KAAgC;QAC3D,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAElD,KAAK,CAAC,GAAG,CAAC,CAAC;QACX,IAAI,KAAK,CAAC,MAAM;YAAE,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC;QAE3G,OAAO,GAAQ,CAAC;IACpB,CAAC;IAED,MAAM;QACF,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAoB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC;CACJ"}
package/dist/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tak-ps/node-cot",
3
3
  "type": "module",
4
- "version": "12.3.0",
4
+ "version": "12.4.0",
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",
@@ -7,7 +7,7 @@ for (const fixturename of await fs.readdir(new URL('./basemaps/', import.meta.ur
7
7
  test(`Basemap Test: ${fixturename}`, async (t) => {
8
8
  const fixture = String(await fs.readFile(path.join(path.parse(fileURLToPath(import.meta.url)).dir, 'basemaps/', fixturename)));
9
9
  const container = await Basemap.parse(fixture);
10
- t.ok(container.basemap.customMapSource.name._text.length);
10
+ t.ok(container.raw.customMapSource.name._text.length);
11
11
  t.end();
12
12
  });
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"basemaps.test.js","sourceRoot":"","sources":["../../test/basemaps.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,KAAK,MAAM,WAAW,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAClF,IAAI,CAAC,iBAAiB,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/H,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE/C,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAEzD,CAAC,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACP,CAAC"}
1
+ {"version":3,"file":"basemaps.test.js","sourceRoot":"","sources":["../../test/basemaps.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,KAAK,MAAM,WAAW,IAAI,MAAM,EAAE,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;IAClF,IAAI,CAAC,iBAAiB,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC;QAC/H,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAE/C,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAErD,CAAC,CAAC,GAAG,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -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-range-and-bearing.test.ts","../test/cot-routes.test.ts","../test/cot-types.test.ts","../test/cot-uas-tool.test.ts","../test/cot_is.test.ts","../test/data-package.test.ts","../test/diff.test.ts","../test/flow-tags.test.ts","../test/force-delete.ts","../test/from_geojson.test.ts","../test/newlines.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/basemap.ts","../lib/chat.ts","../lib/cot.ts","../lib/data-package.ts","../lib/fileshare.ts","../lib/force-delete.ts"],"version":"5.6.2"}
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-range-and-bearing.test.ts","../test/cot-routes.test.ts","../test/cot-types.test.ts","../test/cot-uas-tool.test.ts","../test/cot_is.test.ts","../test/data-package.test.ts","../test/diff.test.ts","../test/flow-tags.test.ts","../test/force-delete.ts","../test/from_geojson.test.ts","../test/newlines.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/xml-document.ts"],"version":"5.6.2"}
package/eslint.config.js CHANGED
@@ -2,11 +2,11 @@ import eslint from '@eslint/js';
2
2
  import tseslint from 'typescript-eslint';
3
3
 
4
4
  export default tseslint.config(
5
- eslint.configs.recommended,
6
- ...tseslint.configs.recommended,
7
- {
8
- "rules": {
9
- "@typescript-eslint/no-explicit-any": "warn"
5
+ eslint.configs.recommended,
6
+ ...tseslint.configs.recommended,
7
+ {
8
+ "rules": {
9
+ "@typescript-eslint/no-explicit-any": "warn"
10
+ }
10
11
  }
11
- }
12
12
  );
package/index.ts CHANGED
@@ -6,6 +6,7 @@ export * from './lib/chat.js'
6
6
  export * from './lib/fileshare.js'
7
7
  export * from './lib/force-delete.js'
8
8
  export * from './lib/data-package.js'
9
- export * from './lib/basemap.js'
9
+ export * from './lib/xml/basemap.js'
10
+ export * from './lib/xml/iconset.js'
10
11
 
11
12
  export default CoT;
@@ -14,7 +14,9 @@ export const BasemapMapSource = Type.Object({
14
14
  _text: Type.String()
15
15
  }),
16
16
  tileUpdate: Type.Optional(Type.Object({
17
- _text: Type.String()
17
+ _text: Type.String({
18
+ default: 'None'
19
+ })
18
20
  })),
19
21
  url: Type.Optional(Type.Object({
20
22
  _text: Type.String()
@@ -0,0 +1,19 @@
1
+ import { Type } from '@sinclair/typebox';
2
+
3
+ export const IconsetAttributes = Type.Object({
4
+ uid: Type.String(),
5
+ version: Type.String(),
6
+ name: Type.String(),
7
+ default_group: Type.Optional(Type.String()),
8
+ default_friendly: Type.Optional(Type.String()),
9
+ default_hostile: Type.Optional(Type.String()),
10
+ default_neutral: Type.Optional(Type.String()),
11
+ default_unknown: Type.Optional(Type.String()),
12
+ skip_resize: Type.Boolean({ default: false }),
13
+ })
14
+
15
+ export default Type.Object({
16
+ iconset: Type.Object({
17
+ _attributes: IconsetAttributes
18
+ })
19
+ })
@@ -0,0 +1,26 @@
1
+ import XMLDocument from '../xml-document.js';
2
+ import type { Static } from '@sinclair/typebox'
3
+ import BasemapSchema from '../types/basemap.js';
4
+ import AJV from 'ajv';
5
+
6
+ const checkBasemap = (new AJV({
7
+ allErrors: true,
8
+ coerceTypes: true,
9
+ allowUnionTypes: true
10
+ }))
11
+ .compile(BasemapSchema);
12
+
13
+ type BasemapType = Static<typeof BasemapSchema>;
14
+
15
+ /**
16
+ * Helper class for creating and parsing Basemap XML documents
17
+ */
18
+ export class Basemap extends XMLDocument<BasemapType> {
19
+ /**
20
+ * Return a Basemap from a string XML representation
21
+ */
22
+ static parse(input: string): Basemap {
23
+ const basemap = super.check<BasemapType>(input, checkBasemap);
24
+ return new Basemap(basemap);
25
+ }
26
+ }
@@ -0,0 +1,26 @@
1
+ import XMLDocument from '../xml-document.js';
2
+ import type { Static } from '@sinclair/typebox'
3
+ import IconsetSchema from '../types/iconset.js';
4
+ import AJV from 'ajv';
5
+
6
+ const checkIconset = (new AJV({
7
+ allErrors: true,
8
+ coerceTypes: true,
9
+ allowUnionTypes: true
10
+ }))
11
+ .compile(IconsetSchema);
12
+
13
+ type IconsetType = Static<typeof IconsetSchema>;
14
+
15
+ /**
16
+ * Helper class for creating and parsing Iconset XML documents
17
+ */
18
+ export class Iconset extends XMLDocument<IconsetType> {
19
+ /**
20
+ * Return an Iconset from a string XML representation
21
+ */
22
+ static parse(input: string): Iconset {
23
+ const basemap = super.check<IconsetType>(input, checkIconset);
24
+ return new Iconset(basemap);
25
+ }
26
+ }
@@ -0,0 +1,28 @@
1
+ import Err from '@openaddresses/batch-error';
2
+ import type { ValidateFunction } from 'ajv';
3
+ import xmljs from 'xml-js';
4
+
5
+ /**
6
+ * Core XML Document support used for XML fortatted DataPackages documents
7
+ * such as Iconsets or Basemaps
8
+ */
9
+ export default class XMLDocument<T> {
10
+ raw: T;
11
+
12
+ constructor(raw: T) {
13
+ this.raw = raw;
14
+ }
15
+
16
+ static check<U>(input: string, check: ValidateFunction<unknown>): U {
17
+ const xml = xmljs.xml2js(input, { compact: true })
18
+
19
+ check(xml);
20
+ if (check.errors) throw new Err(400, null, `${check.errors[0].message} (${check.errors[0].instancePath})`);
21
+
22
+ return xml as U;
23
+ }
24
+
25
+ to_xml(): string {
26
+ return xmljs.js2xml(this.raw as xmljs.Element, { compact: true });
27
+ }
28
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tak-ps/node-cot",
3
3
  "type": "module",
4
- "version": "12.3.0",
4
+ "version": "12.4.0",
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",
@@ -9,7 +9,7 @@ for (const fixturename of await fs.readdir(new URL('./basemaps/', import.meta.ur
9
9
  const fixture = String(await fs.readFile(path.join(path.parse(fileURLToPath(import.meta.url)).dir, 'basemaps/', fixturename)));
10
10
  const container = await Basemap.parse(fixture);
11
11
 
12
- t.ok(container.basemap.customMapSource.name._text.length)
12
+ t.ok(container.raw.customMapSource.name._text.length)
13
13
 
14
14
  t.end();
15
15
  });
@@ -1,31 +0,0 @@
1
- import Err from '@openaddresses/batch-error';
2
- import BasemapType from './types/basemap.js';
3
- import xmljs from 'xml-js';
4
- import AJV from 'ajv';
5
- const checkBasemap = (new AJV({
6
- allErrors: true,
7
- coerceTypes: true,
8
- allowUnionTypes: true
9
- }))
10
- .compile(BasemapType);
11
- /**
12
- * Helper class for creating and parsing Basemap XML documents
13
- */
14
- export class Basemap {
15
- basemap;
16
- constructor(basemap) {
17
- this.basemap = basemap;
18
- }
19
- /**
20
- * Return a Basemap from a string XML representation
21
- */
22
- static async parse(input) {
23
- const xml = xmljs.xml2js(input, { compact: true });
24
- checkBasemap(xml);
25
- if (checkBasemap.errors)
26
- throw new Err(400, null, `${checkBasemap.errors[0].message} (${checkBasemap.errors[0].instancePath})`);
27
- const basemap = xml;
28
- return new Basemap(basemap);
29
- }
30
- }
31
- //# sourceMappingURL=basemap.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"basemap.js","sourceRoot":"","sources":["../../lib/basemap.ts"],"names":[],"mappings":"AACA,OAAO,GAAG,MAAM,4BAA4B,CAAC;AAC7C,OAAO,WAAW,MAAM,oBAAoB,CAAC;AAC7C,OAAO,KAAK,MAAM,QAAQ,CAAC;AAC3B,OAAO,GAAG,MAAM,KAAK,CAAC;AAEtB,MAAM,YAAY,GAAG,CAAC,IAAI,GAAG,CAAC;IAC1B,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,eAAe,EAAE,IAAI;CACxB,CAAC,CAAC;KACE,OAAO,CAAC,WAAW,CAAC,CAAC;AAE1B;;GAEG;AACH,MAAM,OAAO,OAAO;IAChB,OAAO,CAA6B;IAEpC,YAAY,OAAmC;QAC3C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAa;QAC5B,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAA;QAElD,YAAY,CAAC,GAAG,CAAC,CAAC;QAClB,IAAI,YAAY,CAAC,MAAM;YAAE,MAAM,IAAI,GAAG,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,KAAK,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC;QAChI,MAAM,OAAO,GAAG,GAAiC,CAAC;QAElD,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAChC,CAAC;CACJ"}
package/lib/basemap.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { Static } from '@sinclair/typebox'
2
- import Err from '@openaddresses/batch-error';
3
- import BasemapType from './types/basemap.js';
4
- import xmljs from 'xml-js';
5
- import AJV from 'ajv';
6
-
7
- const checkBasemap = (new AJV({
8
- allErrors: true,
9
- coerceTypes: true,
10
- allowUnionTypes: true
11
- }))
12
- .compile(BasemapType);
13
-
14
- /**
15
- * Helper class for creating and parsing Basemap XML documents
16
- */
17
- export class Basemap {
18
- basemap: Static<typeof BasemapType>;
19
-
20
- constructor(basemap: Static<typeof BasemapType>) {
21
- this.basemap = basemap;
22
- }
23
-
24
- /**
25
- * Return a Basemap from a string XML representation
26
- */
27
- static async parse(input: string): Promise<Basemap> {
28
- const xml = xmljs.xml2js(input, { compact: true })
29
-
30
- checkBasemap(xml);
31
- if (checkBasemap.errors) throw new Err(400, null, `${checkBasemap.errors[0].message} (${checkBasemap.errors[0].instancePath})`);
32
- const basemap = xml as Static<typeof BasemapType>;
33
-
34
- return new Basemap(basemap);
35
- }
36
- }