@tak-ps/node-cot 14.59.0 → 14.60.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.
Files changed (77) hide show
  1. package/.github/workflows/doc.yml +5 -0
  2. package/.oxlintrc.json +100 -0
  3. package/CHANGELOG.md +9 -0
  4. package/README.md +17 -0
  5. package/cli.ts +21 -22
  6. package/dist/cli.js +18 -19
  7. package/dist/cli.js.map +1 -1
  8. package/dist/lib/builders/chat.d.ts +4 -4
  9. package/dist/lib/builders/chat.js +3 -6
  10. package/dist/lib/builders/chat.js.map +1 -1
  11. package/dist/lib/builders/route.js +2 -2
  12. package/dist/lib/cot.js +44 -56
  13. package/dist/lib/cot.js.map +1 -1
  14. package/dist/lib/data-package.d.ts +3 -3
  15. package/dist/lib/data-package.js +68 -81
  16. package/dist/lib/data-package.js.map +1 -1
  17. package/dist/lib/parser/from_geojson.js +24 -30
  18. package/dist/lib/parser/from_geojson.js.map +1 -1
  19. package/dist/lib/parser/normalize_geojson.js +22 -22
  20. package/dist/lib/parser/normalize_geojson.js.map +1 -1
  21. package/dist/lib/parser/to_geojson.js +94 -86
  22. package/dist/lib/parser/to_geojson.js.map +1 -1
  23. package/dist/lib/parser-normalize.d.ts +5 -0
  24. package/dist/lib/parser-normalize.js +25 -8
  25. package/dist/lib/parser-normalize.js.map +1 -1
  26. package/dist/lib/parser.js +96 -81
  27. package/dist/lib/parser.js.map +1 -1
  28. package/dist/lib/sensor.js +11 -5
  29. package/dist/lib/sensor.js.map +1 -1
  30. package/dist/lib/type.js +5 -10
  31. package/dist/lib/type.js.map +1 -1
  32. package/dist/lib/types/cot-types.js +4 -4
  33. package/dist/lib/types/cot-types.js.map +1 -1
  34. package/dist/lib/types/feature.d.ts +755 -755
  35. package/dist/lib/types/types.d.ts +55 -9
  36. package/dist/lib/types/types.js +18 -3
  37. package/dist/lib/types/types.js.map +1 -1
  38. package/dist/lib/utils/2525.js +139 -92
  39. package/dist/lib/utils/2525.js.map +1 -1
  40. package/dist/lib/utils/color.js +1 -1
  41. package/dist/lib/utils/color.js.map +1 -1
  42. package/dist/lib/utils/type.js +5 -10
  43. package/dist/lib/utils/type.js.map +1 -1
  44. package/dist/lib/utils/util.d.ts +5 -0
  45. package/dist/lib/utils/util.js +25 -16
  46. package/dist/lib/utils/util.js.map +1 -1
  47. package/dist/lib/xml/basemap.js +10 -9
  48. package/dist/lib/xml/basemap.js.map +1 -1
  49. package/dist/lib/xml/iconset.js +1 -1
  50. package/dist/lib/xml/iconset.js.map +1 -1
  51. package/dist/lib/xml-document.d.ts +1 -1
  52. package/dist/lib/xml-document.js +6 -3
  53. package/dist/lib/xml-document.js.map +1 -1
  54. package/dist/package.json +8 -8
  55. package/dist/tsconfig.tsbuildinfo +1 -1
  56. package/lib/builders/chat.ts +3 -3
  57. package/lib/builders/route.ts +2 -2
  58. package/lib/cot.ts +42 -47
  59. package/lib/data-package.ts +72 -76
  60. package/lib/parser/from_geojson.ts +24 -29
  61. package/lib/parser/normalize_geojson.ts +22 -26
  62. package/lib/parser/to_geojson.ts +105 -94
  63. package/lib/parser-normalize.ts +30 -9
  64. package/lib/parser.ts +121 -92
  65. package/lib/sensor.ts +12 -5
  66. package/lib/type.ts +5 -5
  67. package/lib/types/cot-types.ts +4 -4
  68. package/lib/types/types.ts +20 -3
  69. package/lib/utils/2525.ts +147 -96
  70. package/lib/utils/color.ts +1 -1
  71. package/lib/utils/type.ts +5 -5
  72. package/lib/utils/util.ts +31 -15
  73. package/lib/xml/basemap.ts +10 -9
  74. package/lib/xml/iconset.ts +1 -1
  75. package/lib/xml-document.ts +7 -4
  76. package/package.json +8 -8
  77. package/eslint.config.js +0 -15
package/lib/parser.ts CHANGED
@@ -17,19 +17,23 @@ import type {
17
17
  import {
18
18
  InputFeature,
19
19
  } from './types/feature.js';
20
- import { normalizeBooleanAttributeValues } from './parser-normalize.js';
20
+ import { hasUnclosedElements, normalizeBooleanAttributeValues } from './parser-normalize.js';
21
21
  import JSONCoT, { Detail } from './types/types.js'
22
22
  import CoT from './cot.js';
23
23
  import type { CoTOptions } from './cot.js';
24
24
  import AJV from 'ajv';
25
25
  import fs from 'fs';
26
26
  import path from 'node:path';
27
- import { fileURLToPath } from 'node:url';
28
27
 
29
- const protoPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'proto', 'takmessage.proto');
28
+ const protoPath = path.join(import.meta.dirname, 'proto', 'takmessage.proto');
30
29
  const RootMessage = await protobuf.load(protoPath);
31
30
 
32
- const pkg = JSON.parse(String(fs.readFileSync(new URL('../package.json', import.meta.url))));
31
+ function isObject(input: unknown): input is Record<string, unknown> {
32
+ return typeof input === 'object' && input !== null;
33
+ }
34
+
35
+ const pkg: unknown = JSON.parse(String(fs.readFileSync(new URL('../package.json', import.meta.url))));
36
+ const pkgVersion = isObject(pkg) ? String(pkg.version) : 'undefined';
33
37
 
34
38
  const checkXML = (new AJV({
35
39
  allErrors: true,
@@ -47,33 +51,51 @@ export interface CoTParseError {
47
51
  event: unknown;
48
52
  }
49
53
 
54
+ interface ProtoLong {
55
+ toNumber: () => number;
56
+ }
57
+
58
+ function isProtoLong(input: unknown): input is ProtoLong {
59
+ return isObject(input) && typeof input.toNumber === 'function';
60
+ }
61
+
62
+ function protoTime(input: unknown): string {
63
+ if (!isProtoLong(input)) throw new Err(400, null, 'Invalid cotEvent Time');
64
+ return new Date(input.toNumber()).toISOString();
65
+ }
66
+
67
+ function toArray(input: unknown): unknown[] {
68
+ if (Array.isArray(input)) return input;
69
+ return [input];
70
+ }
71
+
72
+ function unvalidated(input: unknown): Static<typeof JSONCoT> {
73
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
74
+ return input as Static<typeof JSONCoT>;
75
+ }
76
+
77
+ function stripServerFlowTags(tags: Record<string, unknown>): void {
78
+ for (const key of Object.keys(tags)) {
79
+ if (key !== '_attributes' && key.startsWith('TAK-Server')) {
80
+ delete tags[key];
81
+ }
82
+ }
83
+ }
84
+
50
85
  function resetFlowTags(cot: CoT): void {
51
- const flowTags = cot.raw.event.detail?.['_flow-tags_'];
86
+ const flowTags: unknown = cot.raw.event.detail?.['_flow-tags_'];
52
87
 
53
- if (!flowTags || typeof flowTags !== 'object' || Array.isArray(flowTags)) {
88
+ if (!isObject(flowTags) || Array.isArray(flowTags)) {
54
89
  return;
55
90
  }
56
91
 
57
- const stripServerFlowTags = (tags: Record<string, unknown>): void => {
58
- for (const key of Object.keys(tags)) {
59
- if (key !== '_attributes' && key.startsWith('TAK-Server')) {
60
- delete tags[key];
61
- }
62
- }
63
- };
92
+ stripServerFlowTags(flowTags);
64
93
 
65
- stripServerFlowTags(flowTags as Record<string, unknown>);
66
-
67
- if (
68
- '_attributes' in flowTags
69
- && flowTags._attributes
70
- && typeof flowTags._attributes === 'object'
71
- && !Array.isArray(flowTags._attributes)
72
- ) {
73
- stripServerFlowTags(flowTags._attributes as Record<string, unknown>);
94
+ if (isObject(flowTags._attributes) && !Array.isArray(flowTags._attributes)) {
95
+ stripServerFlowTags(flowTags._attributes);
74
96
  }
75
97
 
76
- flowTags[`NodeCoT-${pkg.version}`] = new Date().toISOString();
98
+ flowTags[`NodeCoT-${pkgVersion}`] = new Date().toISOString();
77
99
  }
78
100
 
79
101
  /**
@@ -100,27 +122,23 @@ const PROTO_DETAIL_ELEMENTS: Record<string, string> = Object.fromEntries(
100
122
  export class CoTParser {
101
123
  static validate(
102
124
  cot: CoT,
103
- opts: {
125
+ opts?: {
104
126
  flow: boolean
105
- } = {
106
- flow: true
107
127
  }
108
128
  ): CoT {
109
- if (opts.flow === undefined) opts.flow = true;
110
-
111
129
  checkXML(cot.raw);
112
130
  if (checkXML.errors) {
113
131
  throw new Err(400, null, `${checkXML.errors[0].message} (${checkXML.errors[0].instancePath})`);
114
132
  }
115
133
 
116
- if (opts.flow) {
117
- if (!cot.raw.event.detail) cot.raw.event.detail = {};
134
+ if (opts?.flow ?? true) {
135
+ cot.raw.event.detail ??= {};
118
136
 
119
- if (!cot.raw.event.detail['_flow-tags_']) {
120
- cot.raw.event.detail['_flow-tags_'] = {};
121
- }
137
+ const existing: unknown = cot.raw.event.detail['_flow-tags_'];
138
+ const flowTags = isObject(existing) ? existing : {};
139
+ cot.raw.event.detail['_flow-tags_'] = flowTags;
122
140
 
123
- cot.raw.event.detail['_flow-tags_'][`NodeCoT-${pkg.version}`] = new Date().toISOString()
141
+ flowTags[`NodeCoT-${pkgVersion}`] = new Date().toISOString()
124
142
  }
125
143
 
126
144
  return cot;
@@ -134,32 +152,32 @@ export class CoTParser {
134
152
  static async isDiff(
135
153
  aCoT: CoT,
136
154
  bCoT: CoT,
137
- opts = {
138
- diffMetadata: false,
139
- diffStaleStartTime: false,
140
- diffDest: false,
141
- diffFlow: false
155
+ opts?: {
156
+ diffMetadata: boolean,
157
+ diffStaleStartTime: boolean,
158
+ diffDest: boolean,
159
+ diffFlow: boolean
142
160
  }
143
161
  ): Promise<boolean> {
144
162
  const a = await this.to_geojson(aCoT) as Static<typeof InputFeature>;
145
163
  const b = await this.to_geojson(bCoT) as Static<typeof InputFeature>;
146
164
 
147
- if (!opts.diffDest) {
165
+ if (!opts?.diffDest) {
148
166
  delete a.properties.dest;
149
167
  delete b.properties.dest;
150
168
  }
151
169
 
152
- if (!opts.diffMetadata) {
170
+ if (!opts?.diffMetadata) {
153
171
  delete a.properties.metadata;
154
172
  delete b.properties.metadata;
155
173
  }
156
174
 
157
- if (!opts.diffFlow) {
175
+ if (!opts?.diffFlow) {
158
176
  delete a.properties.flow;
159
177
  delete b.properties.flow;
160
178
  }
161
179
 
162
- if (!opts.diffStaleStartTime) {
180
+ if (!opts?.diffStaleStartTime) {
163
181
  delete a.properties.time;
164
182
  delete a.properties.stale;
165
183
  delete a.properties.start;
@@ -180,18 +198,22 @@ export class CoTParser {
180
198
  ): CoT {
181
199
  const str = String(raw);
182
200
 
183
- let parsed: Static<typeof JSONCoT>;
201
+ let parsed: unknown;
184
202
  try {
185
- parsed = xml2js(str, { compact: true }) as Static<typeof JSONCoT>;
203
+ parsed = xml2js(str, { compact: true });
186
204
  } catch (err) {
187
205
  console.error(`Failed to parse CoT XML: ${str}`);
188
206
  throw err;
189
207
  }
190
208
 
209
+ if (hasUnclosedElements(parsed)) {
210
+ throw new Err(400, null, 'Malformed XML: unclosed element');
211
+ }
212
+
191
213
  normalizeBooleanAttributeValues(parsed);
192
214
 
193
215
  const cot = new CoT(
194
- parsed,
216
+ unvalidated(parsed),
195
217
  opts
196
218
  );
197
219
 
@@ -207,22 +229,28 @@ export class CoTParser {
207
229
  } {
208
230
  const str = String(raw);
209
231
 
210
- let parsed: any;
232
+ let parsed: unknown;
211
233
  try {
212
- parsed = xml2js(str, { compact: true }) as Record<string, unknown>;
234
+ parsed = xml2js(str, { compact: true });
213
235
  } catch (err) {
214
236
  console.error(`Failed to parse CoT XML Document: ${str}`);
215
237
  throw err;
216
238
  }
217
239
 
240
+ if (hasUnclosedElements(parsed)) {
241
+ throw new Err(400, null, 'Malformed XML: unclosed element');
242
+ }
243
+
218
244
  normalizeBooleanAttributeValues(parsed);
219
245
 
220
246
  let events: unknown[] = [];
221
- if (parsed && typeof parsed === 'object') {
222
- if (parsed.events && parsed.events.event) {
223
- events = Array.isArray(parsed.events.event) ? parsed.events.event : [parsed.events.event];
224
- } else if (parsed.event) {
225
- events = Array.isArray(parsed.event) ? parsed.event : [parsed.event];
247
+ if (isObject(parsed)) {
248
+ const hasEvent = Boolean(parsed.event);
249
+
250
+ if (isObject(parsed.events) && Boolean(parsed.events.event)) {
251
+ events = toArray(parsed.events.event);
252
+ } else if (hasEvent) {
253
+ events = toArray(parsed.event);
226
254
  }
227
255
  }
228
256
 
@@ -232,7 +260,7 @@ export class CoTParser {
232
260
  for (const event of events) {
233
261
  try {
234
262
  cots.push(this.validate(
235
- new CoT({ event: structuredClone(event) } as Static<typeof JSONCoT>, opts),
263
+ new CoT(unvalidated({ event: structuredClone(event) }), opts),
236
264
  { flow: false }
237
265
  ));
238
266
  } catch (err) {
@@ -265,7 +293,7 @@ export class CoTParser {
265
293
  version = 1,
266
294
  opts?: SerializerOptions
267
295
  ): Promise<Uint8Array> {
268
- if (version < 1 || version > 1) throw new Err(400, null, `Unsupported Proto Version: ${version}`);
296
+ if (version !== 1) throw new Err(400, null, `Unsupported Proto Version: ${version}`);
269
297
  const ProtoMessage = RootMessage.lookupType(`atakmap.commoncommo.protobuf.v${version}.TakMessage`)
270
298
 
271
299
  if (opts?.resetFlow) {
@@ -274,16 +302,17 @@ export class CoTParser {
274
302
 
275
303
  // The spread operator is important to make sure the delete doesn't modify the underlying detail object
276
304
  const detail = { ...cot.raw.event.detail };
277
- const msg: any = {
305
+ const protoDetail: Record<string, unknown> = {
306
+ xmlDetail: ''
307
+ };
308
+ const msg = {
278
309
  cotEvent: {
279
310
  ...cot.raw.event._attributes,
280
311
  sendTime: new Date(cot.raw.event._attributes.time).getTime(),
281
312
  startTime: new Date(cot.raw.event._attributes.start).getTime(),
282
313
  staleTime: new Date(cot.raw.event._attributes.stale).getTime(),
283
314
  ...cot.raw.event.point._attributes,
284
- detail: {
285
- xmlDetail: ''
286
- }
315
+ detail: protoDetail
287
316
  }
288
317
  };
289
318
 
@@ -291,12 +320,13 @@ export class CoTParser {
291
320
  for (key in detail) {
292
321
  const field = PROTO_DETAIL_FIELDS[key];
293
322
  if (field) {
294
- msg.cotEvent.detail[field] = detail[key]._attributes;
323
+ const element: unknown = detail[key];
324
+ protoDetail[field] = isObject(element) ? element._attributes : undefined;
295
325
  delete detail[key]
296
326
  }
297
327
  }
298
328
 
299
- msg.cotEvent.detail.xmlDetail = js2xml({
329
+ protoDetail.xmlDetail = js2xml({
300
330
  ...detail,
301
331
  metadata: cot.metadata
302
332
  }, { compact: true });
@@ -308,7 +338,7 @@ export class CoTParser {
308
338
  * Return a GeoJSON Feature from an XML CoT message
309
339
  */
310
340
  static async to_geojson(cot: CoT, opts: ToGeoJSONOptions = {}): Promise<Static<typeof Feature>> {
311
- return await to_geojson(cot, opts);
341
+ return to_geojson(cot, opts);
312
342
  }
313
343
 
314
344
  /**
@@ -321,58 +351,57 @@ export class CoTParser {
321
351
  ): Promise<CoT> {
322
352
  const ProtoMessage = RootMessage.lookupType(`atakmap.commoncommo.protobuf.v${version}.TakMessage`)
323
353
 
324
- // TODO Type this
325
- const msg: any = ProtoMessage.decode(raw);
354
+ const cotEvent: unknown = ProtoMessage.decode(raw).cotEvent;
326
355
 
327
- if (!msg.cotEvent) throw new Err(400, null, 'No cotEvent Data');
356
+ if (!isObject(cotEvent)) throw new Err(400, null, 'No cotEvent Data');
328
357
 
329
- const detail: Record<string, any> = {};
358
+ const protoDetail = isObject(cotEvent.detail) ? cotEvent.detail : {};
359
+
360
+ const detail: Record<string, unknown> = {};
330
361
  const metadata: Record<string, unknown> = {};
331
- for (const key in msg.cotEvent.detail) {
362
+ for (const key in protoDetail) {
332
363
  if (key === 'xmlDetail') {
333
- const parsed: any = xml2js(`<detail>${msg.cotEvent.detail.xmlDetail}</detail>`, { compact: true });
364
+ const xmlDetail = typeof protoDetail.xmlDetail === 'string' ? protoDetail.xmlDetail : '';
365
+ const parsed: unknown = xml2js(`<detail>${xmlDetail}</detail>`, { compact: true });
334
366
  normalizeBooleanAttributeValues(parsed);
335
- Object.assign(detail, parsed.detail);
367
+ if (isObject(parsed)) Object.assign(detail, parsed.detail);
336
368
 
337
- if (detail.metadata) {
338
- for (const key in detail.metadata) {
339
- metadata[key] = detail.metadata[key]._text;
369
+ if (isObject(detail.metadata)) {
370
+ for (const metadataKey in detail.metadata) {
371
+ const entry = detail.metadata[metadataKey];
372
+ metadata[metadataKey] = isObject(entry) ? entry._text : undefined;
340
373
  }
341
374
  delete detail.metadata;
342
375
  }
343
- } else if (key === 'group') {
344
- if (msg.cotEvent.detail[key]) {
345
- detail.__group = { _attributes: msg.cotEvent.detail[key] };
346
- }
347
- } else if (PROTO_DETAIL_ELEMENTS[key]) {
348
- if (msg.cotEvent.detail[key]) {
349
- detail[PROTO_DETAIL_ELEMENTS[key]] = { _attributes: msg.cotEvent.detail[key] };
350
- }
376
+ } else if (key === 'group' && Boolean(protoDetail[key])) {
377
+ detail.__group = { _attributes: protoDetail[key] };
378
+ } else if (PROTO_DETAIL_ELEMENTS[key] && Boolean(protoDetail[key])) {
379
+ detail[PROTO_DETAIL_ELEMENTS[key]] = { _attributes: protoDetail[key] };
351
380
  }
352
381
  }
353
382
 
354
- const cot = new CoT({
383
+ const cot = new CoT(unvalidated({
355
384
  event: {
356
385
  _attributes: {
357
386
  version: '2.0',
358
- uid: msg.cotEvent.uid, type: msg.cotEvent.type, how: msg.cotEvent.how,
359
- qos: msg.cotEvent.qos, opex: msg.cotEvent.opex, access: msg.cotEvent.access,
360
- time: new Date(msg.cotEvent.sendTime.toNumber()).toISOString(),
361
- start: new Date(msg.cotEvent.startTime.toNumber()).toISOString(),
362
- stale: new Date(msg.cotEvent.staleTime.toNumber()).toISOString(),
387
+ uid: cotEvent.uid, type: cotEvent.type, how: cotEvent.how,
388
+ qos: cotEvent.qos, opex: cotEvent.opex, access: cotEvent.access,
389
+ time: protoTime(cotEvent.sendTime),
390
+ start: protoTime(cotEvent.startTime),
391
+ stale: protoTime(cotEvent.staleTime),
363
392
  },
364
393
  detail,
365
394
  point: {
366
395
  _attributes: {
367
- lat: msg.cotEvent.lat,
368
- lon: msg.cotEvent.lon,
369
- hae: msg.cotEvent.hae,
370
- le: msg.cotEvent.le,
371
- ce: msg.cotEvent.ce,
396
+ lat: cotEvent.lat,
397
+ lon: cotEvent.lon,
398
+ hae: cotEvent.hae,
399
+ le: cotEvent.le,
400
+ ce: cotEvent.ce,
372
401
  },
373
402
  }
374
403
  }
375
- }, opts);
404
+ }), opts);
376
405
 
377
406
  cot.metadata = metadata;
378
407
 
package/lib/sensor.ts CHANGED
@@ -3,6 +3,11 @@ import { Position, Polygon } from './types/feature.js';
3
3
  import { SensorAttributes } from './types/types.js';
4
4
  import { sector } from '@turf/sector';
5
5
 
6
+ function orZero(value?: number): number {
7
+ const defined = value ?? 0;
8
+ return Number.isNaN(defined) ? 0 : defined;
9
+ }
10
+
6
11
  export default class Sensor {
7
12
  center: Static<typeof Position>;
8
13
  sensor: Static<typeof SensorAttributes>;
@@ -20,15 +25,17 @@ export default class Sensor {
20
25
  * `range` is a slant range so it is projected to the ground via the elevation
21
26
  */
22
27
  to_geojson(): Static<typeof Polygon> | null {
23
- if (!this.sensor.range) return null;
28
+ const range = orZero(this.sensor.range);
29
+ if (range === 0) return null;
24
30
  if (typeof this.sensor.azimuth !== 'number') return null;
25
- if (!this.sensor.fov) return null;
31
+ const fov = orZero(this.sensor.fov);
32
+ if (fov === 0) return null;
26
33
 
27
- const elevation = this.sensor.elevation || 0;
28
- const ground = this.sensor.range * Math.cos(elevation * Math.PI / 180);
34
+ const elevation = orZero(this.sensor.elevation);
35
+ const ground = range * Math.cos(elevation * Math.PI / 180);
29
36
  if (ground < 1) return null;
30
37
 
31
- const half = this.sensor.fov / 2;
38
+ const half = fov / 2;
32
39
 
33
40
  return sector(
34
41
  this.center,
package/lib/type.ts CHANGED
@@ -14,11 +14,11 @@ export default class TypeValidator {
14
14
  body: unknown,
15
15
  opts?: TypeOpts
16
16
  ): Static<T> {
17
- if (!opts) opts = {};
18
- if (opts.verbose === undefined) opts.verbose = false;
19
- if (opts.default === undefined) opts.default = true;
20
- if (opts.convert === undefined) opts.convert = true;
21
- if (opts.clean === undefined) opts.clean = true;
17
+ opts ??= {};
18
+ opts.verbose ??= false;
19
+ opts.default ??= true;
20
+ opts.convert ??= true;
21
+ opts.clean ??= true;
22
22
 
23
23
  if (opts.default) {
24
24
  Value.Default(type, body)
@@ -1,5 +1,5 @@
1
1
  import fsp from 'node:fs/promises';
2
- import xmljs from '@tak-ps/xml-js';
2
+ import { xml2js } from '@tak-ps/xml-js';
3
3
  import type { Static } from '@sinclair/typebox';
4
4
  import TypeValidator from '../utils/type.js';
5
5
  import MilSymType, { StandardIdentity, Domain } from '../utils/2525.js';
@@ -82,7 +82,7 @@ export default class CoTTypes {
82
82
  }
83
83
 
84
84
  static async load(): Promise<CoTTypes> {
85
- const xml = xmljs.xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true })
85
+ const xml = xml2js(String(await fsp.readFile(new URL('cot-types.xml', import.meta.url))), { compact: true })
86
86
 
87
87
  const types = TypeValidator.type(TypeFormat, xml);
88
88
 
@@ -125,13 +125,13 @@ export default class CoTTypes {
125
125
  const filtered: Set<Static<typeof AugmentedType>> = new Set();
126
126
 
127
127
  for (const cot of this.cots.values()) {
128
- if (opts.domain) {
128
+ if (opts.domain !== undefined) {
129
129
  if (!cot.cot.startsWith(`${opts.domain}-`)) {
130
130
  continue;
131
131
  };
132
132
  }
133
133
 
134
- if (cot.cot.match(/^a-.-/)) {
134
+ if (/^a-.-/.test(cot.cot)) {
135
135
  const type = cot.cot.replace(/^a-.-/, `a-${si}-`);
136
136
 
137
137
  filtered.add({
@@ -95,11 +95,11 @@ export const RouteInfo = Type.Object({
95
95
  })
96
96
 
97
97
  export const Emergency = Type.Object({
98
- _attributes: Type.Object({
98
+ _attributes: Type.Optional(Type.Object({
99
99
  cancel: Type.Optional(Type.Boolean()),
100
100
  type: Type.Optional(Type.String())
101
- }),
102
- _text: Type.String()
101
+ })),
102
+ _text: Type.Optional(Type.String())
103
103
  });
104
104
 
105
105
  export const Link = Type.Object({
@@ -216,6 +216,20 @@ export const GenericNumberAttributes = Type.Object({
216
216
  }))
217
217
  })
218
218
 
219
+ export const Height = Type.Object({
220
+ _attributes: Type.Optional(Type.Object({
221
+ value: Type.Optional(Type.Number())
222
+ })),
223
+ _text: Type.Optional(Type.Number())
224
+ })
225
+
226
+ export const HeightUnit = Type.Object({
227
+ _attributes: Type.Optional(Type.Object({
228
+ value: Type.Optional(Type.Integer())
229
+ })),
230
+ _text: Type.Optional(Type.Integer())
231
+ })
232
+
219
233
  export const GenericOptionalText = Type.Object({
220
234
  _text: Type.Optional(Type.String())
221
235
  })
@@ -1290,6 +1304,9 @@ export const Detail = Type.Object({
1290
1304
  // Controls the display of distance calculation labels on the edge of line/polygon features
1291
1305
  labels_on: Type.Optional(GenericBooleanAttributes),
1292
1306
  fillColor: Type.Optional(GenericIntegerAttributes),
1307
+ height: Type.Optional(Height),
1308
+ height_unit: Type.Optional(HeightUnit),
1309
+ extrudeMode: Type.Optional(GenericStringAttributes),
1293
1310
  mission: Type.Optional(Mission),
1294
1311
  shape: Type.Optional(Shape),
1295
1312