@tak-ps/node-cot 14.58.1 → 14.60.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.
Files changed (79) hide show
  1. package/.oxlintrc.json +100 -0
  2. package/CHANGELOG.md +9 -0
  3. package/README.md +13 -0
  4. package/cli.ts +21 -22
  5. package/dist/cli.js +18 -19
  6. package/dist/cli.js.map +1 -1
  7. package/dist/lib/builders/chat.d.ts +4 -4
  8. package/dist/lib/builders/chat.js +3 -6
  9. package/dist/lib/builders/chat.js.map +1 -1
  10. package/dist/lib/builders/route.js +2 -2
  11. package/dist/lib/cot.js +44 -56
  12. package/dist/lib/cot.js.map +1 -1
  13. package/dist/lib/data-package.d.ts +3 -3
  14. package/dist/lib/data-package.js +68 -81
  15. package/dist/lib/data-package.js.map +1 -1
  16. package/dist/lib/parser/from_geojson.js +27 -30
  17. package/dist/lib/parser/from_geojson.js.map +1 -1
  18. package/dist/lib/parser/normalize_geojson.js +22 -22
  19. package/dist/lib/parser/normalize_geojson.js.map +1 -1
  20. package/dist/lib/parser/to_geojson.js +97 -86
  21. package/dist/lib/parser/to_geojson.js.map +1 -1
  22. package/dist/lib/parser-normalize.d.ts +5 -0
  23. package/dist/lib/parser-normalize.js +25 -8
  24. package/dist/lib/parser-normalize.js.map +1 -1
  25. package/dist/lib/parser.js +96 -81
  26. package/dist/lib/parser.js.map +1 -1
  27. package/dist/lib/sensor.js +11 -5
  28. package/dist/lib/sensor.js.map +1 -1
  29. package/dist/lib/type.js +5 -10
  30. package/dist/lib/type.js.map +1 -1
  31. package/dist/lib/types/cot-types.js +4 -4
  32. package/dist/lib/types/cot-types.js.map +1 -1
  33. package/dist/lib/types/feature.d.ts +782 -752
  34. package/dist/lib/types/feature.js +2 -1
  35. package/dist/lib/types/feature.js.map +1 -1
  36. package/dist/lib/types/types.d.ts +81 -9
  37. package/dist/lib/types/types.js +33 -3
  38. package/dist/lib/types/types.js.map +1 -1
  39. package/dist/lib/utils/2525.js +139 -92
  40. package/dist/lib/utils/2525.js.map +1 -1
  41. package/dist/lib/utils/color.js +1 -1
  42. package/dist/lib/utils/color.js.map +1 -1
  43. package/dist/lib/utils/type.js +5 -10
  44. package/dist/lib/utils/type.js.map +1 -1
  45. package/dist/lib/utils/util.d.ts +5 -0
  46. package/dist/lib/utils/util.js +25 -16
  47. package/dist/lib/utils/util.js.map +1 -1
  48. package/dist/lib/xml/basemap.js +10 -9
  49. package/dist/lib/xml/basemap.js.map +1 -1
  50. package/dist/lib/xml/iconset.js +1 -1
  51. package/dist/lib/xml/iconset.js.map +1 -1
  52. package/dist/lib/xml-document.d.ts +1 -1
  53. package/dist/lib/xml-document.js +6 -3
  54. package/dist/lib/xml-document.js.map +1 -1
  55. package/dist/package.json +7 -7
  56. package/dist/tsconfig.tsbuildinfo +1 -1
  57. package/lib/builders/chat.ts +3 -3
  58. package/lib/builders/route.ts +2 -2
  59. package/lib/cot.ts +42 -47
  60. package/lib/data-package.ts +72 -76
  61. package/lib/parser/from_geojson.ts +28 -29
  62. package/lib/parser/normalize_geojson.ts +22 -26
  63. package/lib/parser/to_geojson.ts +109 -94
  64. package/lib/parser-normalize.ts +30 -9
  65. package/lib/parser.ts +121 -92
  66. package/lib/sensor.ts +12 -5
  67. package/lib/type.ts +5 -5
  68. package/lib/types/cot-types.ts +4 -4
  69. package/lib/types/feature.ts +2 -0
  70. package/lib/types/types.ts +37 -3
  71. package/lib/utils/2525.ts +147 -96
  72. package/lib/utils/color.ts +1 -1
  73. package/lib/utils/type.ts +5 -5
  74. package/lib/utils/util.ts +31 -15
  75. package/lib/xml/basemap.ts +10 -9
  76. package/lib/xml/iconset.ts +1 -1
  77. package/lib/xml-document.ts +7 -4
  78. package/package.json +7 -7
  79. package/eslint.config.js +0 -15
@@ -8,7 +8,7 @@ import StreamZip from 'node-stream-zip'
8
8
  import { Readable } from 'node:stream';
9
9
  import CoT from './cot.js';
10
10
  import { CoTParser } from './parser.js';
11
- import xmljs from '@tak-ps/xml-js';
11
+ import { xml2js, js2xml } from '@tak-ps/xml-js';
12
12
  import os from 'node:os';
13
13
  import fs from 'node:fs';
14
14
  import fsp from 'node:fs/promises';
@@ -74,7 +74,7 @@ const checkManifest = (new AJV({
74
74
  coerceTypes: true,
75
75
  allowUnionTypes: true
76
76
  }))
77
- .compile(Manifest);
77
+ .compile<Static<typeof Manifest>>(Manifest);
78
78
 
79
79
  async function materializeDataPackageInput(
80
80
  input: string | URL | Buffer | Readable,
@@ -146,7 +146,7 @@ export class DataPackage {
146
146
  path?: string
147
147
  } = {}
148
148
  ) {
149
- if (opts && opts.path) {
149
+ if (opts?.path) {
150
150
  this.path = opts.path;
151
151
  } else {
152
152
  this.path = os.tmpdir() + '/' + crypto.randomUUID();
@@ -199,13 +199,14 @@ export class DataPackage {
199
199
  };
200
200
 
201
201
  for (const key in this.settings) {
202
- if (!this.settings[key]) continue;
202
+ const value = this.settings[key];
203
+ if (value === undefined || value === false || value === '') continue;
203
204
  manifest.MissionPackageManifest.Configuration.Parameter.push({
204
- _attributes: { name: key, value: String(this.settings[key]) }
205
+ _attributes: { name: key, value: String(value) }
205
206
  })
206
207
  }
207
208
 
208
- const xml = `<?xml version="1.0" encoding="UTF-8"?>\n${xmljs.js2xml(manifest, { compact: true })}`;
209
+ const xml = `<?xml version="1.0" encoding="UTF-8"?>\n${js2xml(manifest, { compact: true })}`;
209
210
 
210
211
  return xml;
211
212
  }
@@ -215,15 +216,15 @@ export class DataPackage {
215
216
  * Return true if the DataPackage is a MissionSync Archive
216
217
  */
217
218
  isMissionArchive(): boolean {
218
- return !!(this.settings.mission_guid && this.settings.mission_name);
219
+ return Boolean(this.settings.mission_guid) && Boolean(this.settings.mission_name);
219
220
  }
220
221
 
221
222
  /**
222
223
  * When DataPackages are uploaded to TAK Server they generally use an EUD
223
224
  * calculated Hash
224
225
  */
225
- static async hash(path: string): Promise<string> {
226
- const input = fs.createReadStream(path);
226
+ static async hash(file: string): Promise<string> {
227
+ const input = fs.createReadStream(file);
227
228
  const hash = createHash('sha256');
228
229
  await pipeline(input, hash);
229
230
  return hash.digest('hex');
@@ -234,7 +235,7 @@ export class DataPackage {
234
235
  * calculated Hash
235
236
  */
236
237
  async hash(entry: string): Promise<string> {
237
- return await DataPackage.hash(this.path + '/raw/' + entry);
238
+ return DataPackage.hash(this.path + '/raw/' + entry);
238
239
  }
239
240
 
240
241
 
@@ -256,9 +257,9 @@ export class DataPackage {
256
257
  name?: string
257
258
  }
258
259
  ): Promise<DataPackage> {
259
- if (!opts) opts = {};
260
- if (opts.strict === undefined) opts.strict = true;
261
- if (opts.cleanup === undefined) opts.cleanup = true;
260
+ opts ??= {};
261
+ opts.strict ??= true;
262
+ opts.cleanup ??= true;
262
263
 
263
264
  const source = await materializeDataPackageInput(input, opts.name);
264
265
 
@@ -270,20 +271,22 @@ export class DataPackage {
270
271
  });
271
272
 
272
273
  const preentries = await zip.entries();
274
+ const manifestEntry: unknown = preentries['MANIFEST/manifest.xml'];
273
275
 
274
- if (opts.strict && !preentries['MANIFEST/manifest.xml']) {
276
+ if (opts.strict && manifestEntry === undefined) {
275
277
  throw new Err(400, null, 'No MANIFEST/manifest.xml found in Data Package');
276
278
  }
277
279
 
278
280
  await fsp.mkdir(pkg.path + '/raw', { recursive: true });
279
281
  await zip.extract(null, pkg.path + '/raw/');
280
282
 
281
- if (preentries['MANIFEST/manifest.xml']) {
282
- const xml = xmljs.xml2js(String(await fsp.readFile(pkg.path + '/raw/MANIFEST/manifest.xml')), { compact: true })
283
+ if (manifestEntry !== undefined) {
284
+ const manifest: unknown = xml2js(String(await fsp.readFile(pkg.path + '/raw/MANIFEST/manifest.xml')), { compact: true })
283
285
 
284
- checkManifest(xml);
285
- if (checkManifest.errors) throw new Err(400, null, `${checkManifest.errors[0].message} (${checkManifest.errors[0].instancePath})`);
286
- const manifest = xml as Static<typeof Manifest>;
286
+ if (!checkManifest(manifest)) {
287
+ const [error] = checkManifest.errors ?? [];
288
+ throw new Err(400, null, `${error?.message} (${error?.instancePath})`);
289
+ }
287
290
 
288
291
  pkg.version = manifest.MissionPackageManifest._attributes.version;
289
292
 
@@ -295,7 +298,7 @@ export class DataPackage {
295
298
 
296
299
  for (const param of manifest.MissionPackageManifest.Configuration.Parameter) {
297
300
  if (['onReceiveImport', 'onReceiveDelete'].includes(param._attributes.name) && typeof param._attributes.value === 'string') {
298
- pkg.settings[param._attributes.name] = param._attributes.value === 'false' ? false : true;
301
+ pkg.settings[param._attributes.name] = param._attributes.value !== 'false';
299
302
  } else {
300
303
  pkg.settings[param._attributes.name] = param._attributes.value;
301
304
  }
@@ -331,7 +334,7 @@ export class DataPackage {
331
334
  #addContent(zipEntry: string, uid: string, name?: string, ignore = false): void {
332
335
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
333
336
 
334
- // TODO: Seen in the wild but not currently implemented here:
337
+ // Seen in the wild but not currently implemented here:
335
338
  // <Parameter name="contentType" value="KML"/>
336
339
  // <Parameter name="visible" value="false"/>
337
340
 
@@ -353,20 +356,21 @@ export class DataPackage {
353
356
  other attachment actions do not automatically populate this field other than the link
354
357
  provided between a CoT and it's attachment in the MANIFEST file
355
358
  */
356
- async cots(opts = {
357
- respectIgnore: true,
358
- parseAttachments: true
359
+ async cots(opts?: {
360
+ respectIgnore: boolean,
361
+ parseAttachments: boolean
359
362
  }): Promise<Array<CoT>> {
360
363
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
361
364
 
365
+ const respectIgnore = opts ? opts.respectIgnore : true;
366
+ const parseAttachments = opts ? opts.parseAttachments : true;
367
+
362
368
  const cotsMap: Map<string, CoT> = new Map();
363
369
 
364
370
  const cots: CoT[] = [];
365
371
  for (const content of this.contents) {
366
- if (!content) continue;
367
-
368
372
  if (path.parse(content._attributes.zipEntry).ext !== '.cot') continue;
369
- if (opts.respectIgnore && content._attributes.ignore) continue;
373
+ if (respectIgnore && content._attributes.ignore) continue;
370
374
 
371
375
  const cot = CoTParser.from_xml(await fsp.readFile(this.path + '/raw/' + content._attributes.zipEntry));
372
376
 
@@ -375,27 +379,22 @@ export class DataPackage {
375
379
  cots.push(cot);
376
380
  }
377
381
 
378
- if (opts.parseAttachments) {
379
- const attachments = this.#attachments(cotsMap, {
380
- respectIgnore: opts.respectIgnore
381
- });
382
+ if (parseAttachments) {
383
+ const attachments = this.#attachments(cotsMap, { respectIgnore });
382
384
 
383
385
  for (const cot of cots) {
384
- if (!cot.raw.event.detail) {
385
- cot.raw.event.detail = {};
386
- }
386
+ cot.raw.event.detail ??= {};
387
387
 
388
388
  const attaches = attachments.get(cot.uid());
389
389
  if (!attaches) continue;
390
390
 
391
391
  for (const attach of attaches) {
392
- if (!cot.raw.event.detail.attachment_list) {
393
- cot.raw.event.detail.attachment_list = {
394
- _attributes: { hashes: '[]' }
395
- };
396
- }
392
+ cot.raw.event.detail.attachment_list ??= {
393
+ _attributes: { hashes: '[]' }
394
+ };
397
395
 
398
- const hashes: string[] = JSON.parse(cot.raw.event.detail.attachment_list._attributes.hashes)
396
+ const hashes: unknown = JSON.parse(cot.raw.event.detail.attachment_list._attributes.hashes)
397
+ if (!Array.isArray(hashes)) throw new Err(400, null, 'attachment_list hashes must be a JSON Array');
399
398
 
400
399
  // Until told otherwise the FileHash appears to always be the directory name
401
400
  const hash = await this.hash(attach._attributes.zipEntry);
@@ -413,29 +412,26 @@ export class DataPackage {
413
412
  return cots;
414
413
  }
415
414
 
416
- #attachments(cots: Map<string, CoT>, opts = { respectIgnore: true }): Map<string, Array<Static<typeof ManifestContent>>> {
415
+ #attachments(cots: Map<string, CoT>, opts: { respectIgnore: boolean }): Map<string, Array<Static<typeof ManifestContent>>> {
417
416
  const attachments: Map<string, Array<Static<typeof ManifestContent>>> = new Map();
418
417
 
419
418
  for (const content of this.contents) {
420
- if (!content) continue;
421
-
422
419
  if (path.parse(content._attributes.zipEntry).ext === '.cot') continue;
423
420
  if (opts.respectIgnore && content._attributes.ignore) continue;
421
+ if (!content.Parameter) continue;
424
422
 
425
- if (content.Parameter) {
426
- const params = Array.isArray(content.Parameter) ? content.Parameter : [content.Parameter];
427
-
428
- for (const param of params) {
429
- if (param._attributes.name === 'uid' && cots.has(param._attributes.value)) {
430
- const existing = attachments.get(param._attributes.value);
431
- if (existing) {
432
- existing.push(content);
433
- } else {
434
- attachments.set(param._attributes.value, [content]);
435
- }
436
- break;
437
- }
423
+ const params = Array.isArray(content.Parameter) ? content.Parameter : [content.Parameter];
424
+
425
+ for (const param of params) {
426
+ if (param._attributes.name !== 'uid' || !cots.has(param._attributes.value)) continue;
427
+
428
+ const existing = attachments.get(param._attributes.value);
429
+ if (existing) {
430
+ existing.push(content);
431
+ } else {
432
+ attachments.set(param._attributes.value, [content]);
438
433
  }
434
+ break;
439
435
  }
440
436
  }
441
437
 
@@ -446,8 +442,9 @@ export class DataPackage {
446
442
  * Return a list of files that are NOT attachments or CoT markers
447
443
  * The Set returned has a list of file paths that can be passed to getFile(path)
448
444
  */
449
- async files(opts = { respectIgnore: true }): Promise<Set<string>> {
450
- const attachments = await this.attachments(opts);
445
+ async files(opts?: { respectIgnore: boolean }): Promise<Set<string>> {
446
+ const respectIgnore = opts ? opts.respectIgnore : true;
447
+ const attachments = await this.attachments({ respectIgnore });
451
448
  const files: Set<string> = new Set();
452
449
 
453
450
  const attachment_entries = new Set<string>();
@@ -458,9 +455,8 @@ export class DataPackage {
458
455
  }
459
456
 
460
457
  for (const content of this.contents) {
461
- if (!content) continue;
462
458
  if (path.parse(content._attributes.zipEntry).ext === '.cot') continue;
463
- if (opts.respectIgnore && content._attributes.ignore) continue;
459
+ if (respectIgnore && content._attributes.ignore) continue;
464
460
 
465
461
  if (attachment_entries.has(content._attributes.zipEntry)) {
466
462
  continue;
@@ -476,43 +472,45 @@ export class DataPackage {
476
472
  * Return attachments that are associated in the Manifest with a given CoT
477
473
  * Note: this does not return files that are NOT associated with a CoT
478
474
  */
479
- async attachments(opts = { respectIgnore: true }): Promise<Map<string, Array<Static<typeof ManifestContent>>>> {
475
+ async attachments(opts?: { respectIgnore: boolean }): Promise<Map<string, Array<Static<typeof ManifestContent>>>> {
476
+ const respectIgnore = opts ? opts.respectIgnore : true;
477
+
480
478
  const cots: Map<string, CoT> = new Map();
481
479
  for (const cot of await this.cots({
482
- respectIgnore: opts.respectIgnore,
480
+ respectIgnore,
483
481
  parseAttachments: false
484
482
  })) {
485
483
  cots.set(cot.uid(), cot);
486
484
  }
487
485
 
488
- return this.#attachments(cots, opts);
486
+ return this.#attachments(cots, { respectIgnore });
489
487
  }
490
488
 
491
- async getFileBuffer(path: string): Promise<Buffer> {
489
+ async getFileBuffer(file: string): Promise<Buffer> {
492
490
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
493
491
 
494
492
  try {
495
- await fsp.access(`${this.path}/raw/${path}`)
493
+ await fsp.access(`${this.path}/raw/${file}`)
496
494
  } catch (err) {
497
495
  throw new Err(400, err instanceof Error ? err : new Error(String(err)), 'Could not access file in Data Package');
498
496
  }
499
497
 
500
- return await fsp.readFile(`${this.path}/raw/${path}`);
498
+ return fsp.readFile(`${this.path}/raw/${file}`);
501
499
  }
502
500
 
503
501
  /**
504
502
  * Get any file from a Package
505
503
  */
506
- async getFile(path: string): Promise<Readable> {
504
+ async getFile(file: string): Promise<Readable> {
507
505
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
508
506
 
509
507
  try {
510
- await fsp.access(`${this.path}/raw/${path}`)
508
+ await fsp.access(`${this.path}/raw/${file}`)
511
509
  } catch (err) {
512
510
  throw new Err(400, err instanceof Error ? err : new Error(String(err)), 'Could not access file in Data Package');
513
511
  }
514
512
 
515
- return fs.createReadStream(`${this.path}/raw/${path}`)
513
+ return fs.createReadStream(`${this.path}/raw/${file}`)
516
514
  }
517
515
 
518
516
  /**
@@ -532,7 +530,7 @@ export class DataPackage {
532
530
  attachment?: string;
533
531
  }): Promise<void> {
534
532
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
535
- if (!opts.ignore) opts.ignore = false;
533
+ opts.ignore ??= false;
536
534
 
537
535
  const uid = opts.uid ?? crypto.randomUUID();
538
536
 
@@ -544,16 +542,14 @@ export class DataPackage {
544
542
  /**
545
543
  * Add a CoT marker to the Package
546
544
  */
547
- async addCoT(cot: CoT, opts: {
545
+ async addCoT(cot: CoT, opts?: {
548
546
  ignore: boolean
549
- } = {
550
- ignore: false
551
547
  }): Promise<void> {
552
548
  if (this.destroyed) throw new Err(400, null, 'Attempt to access Data Package after it has been destroyed');
553
549
 
554
550
  const name = cot.callsign();
555
551
 
556
- this.#addContent(`${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, cot.raw.event._attributes.uid, name, opts.ignore);
552
+ this.#addContent(`${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, cot.raw.event._attributes.uid, name, opts?.ignore);
557
553
  await fsp.mkdir(`${this.path}/raw/${cot.raw.event._attributes.uid}/`, { recursive: true });
558
554
  await fsp.writeFile(`${this.path}/raw/${cot.raw.event._attributes.uid}/${cot.raw.event._attributes.uid}.cot`, CoTParser.to_xml(cot))
559
555
  }
@@ -582,10 +578,10 @@ export class DataPackage {
582
578
  const output = fs.createWriteStream(this.path + `/${this.settings.uid}.zip`)
583
579
  archive.pipe(output);
584
580
  output.on('close', () => {
585
- return resolve(this.path + `/${this.settings.uid}.zip`);
581
+ resolve(this.path + `/${this.settings.uid}.zip`);
586
582
  });
587
583
  archive.directory(this.path + '/raw/', '/');
588
- archive.finalize()
584
+ void archive.finalize()
589
585
  });
590
586
  }
591
587
  }
@@ -13,11 +13,10 @@ import type {
13
13
  import {
14
14
  InputFeature,
15
15
  } from '../types/feature.js';
16
- import type { AllGeoJSON } from "@turf/helpers";
17
16
  import TypeValidator from '../type.js';
18
17
  import Type2525 from '../utils/2525.js';
19
18
  import PointOnFeature from '@turf/point-on-feature';
20
- import Util from '../utils/util.js';
19
+ import Util, { jsonClone } from '../utils/util.js';
21
20
  import Color from '../utils/color.js';
22
21
  import JSONCoT from '../types/types.js'
23
22
  import CoT from '../cot.js';
@@ -39,20 +38,18 @@ export async function from_geojson(
39
38
  const explicitType = typeof feature.properties?.type === 'string';
40
39
 
41
40
  try {
42
- feature = await TypeValidator.type(InputFeature, feature, {
41
+ feature = TypeValidator.type(InputFeature, feature, {
43
42
  verbose: opts.verbose
44
43
  });
45
44
  } catch (err) {
46
- throw new Err(400, null, `Validation Error: ${err}`);
45
+ throw new Err(400, null, `Validation Error: ${String(err)}`);
47
46
  }
48
47
 
49
48
  // The type property can either be a traditional CoT Type or a numeric 2525D/2525E SIDC
50
49
  if (feature.properties.type && Type2525.isNumericSIDCConvertable(feature.properties.type)) {
51
- if (!feature.properties.milicon) {
52
- feature.properties.milicon = {
53
- id: feature.properties.type
54
- };
55
- }
50
+ feature.properties.milicon ??= {
51
+ id: feature.properties.type
52
+ };
56
53
 
57
54
  feature.properties.type = Type2525.cotTypeFromNumericSIDC(feature.properties.type);
58
55
  }
@@ -72,12 +69,12 @@ export async function from_geojson(
72
69
  };
73
70
 
74
71
  if (feature.id) {
75
- cot.event._attributes.uid = String(feature.id);
72
+ cot.event._attributes.uid = feature.id;
76
73
  } else {
77
74
  cot.event._attributes.uid = crypto.randomUUID();
78
75
  }
79
76
 
80
- if (!cot.event.detail) cot.event.detail = {};
77
+ cot.event.detail ??= {};
81
78
 
82
79
  if (feature.properties.droid) {
83
80
  cot.event.detail.uid = { _attributes: { Droid: feature.properties.droid } };
@@ -113,8 +110,8 @@ export async function from_geojson(
113
110
  if (feature.properties.dest) {
114
111
  const dest = !Array.isArray(feature.properties.dest) ? [ feature.properties.dest ] : feature.properties.dest;
115
112
 
116
- cot.event.detail.marti.dest = dest.map((dest) => {
117
- return { _attributes: { ...dest } };
113
+ cot.event.detail.marti.dest = dest.map((d) => {
114
+ return { _attributes: { ...d } };
118
115
  });
119
116
  }
120
117
  }
@@ -165,7 +162,7 @@ export async function from_geojson(
165
162
  || feature.properties.maxzoom !== undefined
166
163
  || feature.properties.rotate !== undefined
167
164
  ) {
168
- if (!cot.event.detail.display || !cot.event.detail.display._attributes) {
165
+ if (!cot.event.detail.display?._attributes) {
169
166
  cot.event.detail.display = { _attributes: {} };
170
167
  }
171
168
 
@@ -299,9 +296,9 @@ export async function from_geojson(
299
296
 
300
297
  if (feature.properties.video) {
301
298
  if (feature.properties.video.connection) {
302
- const video = JSON.parse(JSON.stringify(feature.properties.video));
299
+ const video = jsonClone(feature.properties.video);
303
300
 
304
- const connection = video.connection;
301
+ const connection = jsonClone(feature.properties.video.connection);
305
302
  delete video.connection;
306
303
 
307
304
  cot.event.detail.__video = {
@@ -357,6 +354,10 @@ export async function from_geojson(
357
354
  cot.event.detail.status = { _attributes: { ...feature.properties.status } }
358
355
  }
359
356
 
357
+ if (feature.properties.address) {
358
+ cot.event.detail.__address = { _attributes: { ...feature.properties.address } }
359
+ }
360
+
360
361
  if (feature.properties.precisionlocation) {
361
362
  cot.event.detail.precisionlocation = { _attributes: { ...feature.properties.precisionlocation } }
362
363
  }
@@ -409,9 +410,7 @@ export async function from_geojson(
409
410
 
410
411
  cot.event.detail.remarks = { _attributes: { }, _text: feature.properties.remarks || '' };
411
412
 
412
- if (!feature.geometry) {
413
- throw new Err(400, null, 'Must have Geometry');
414
- } else if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) {
413
+ if (!['Point', 'Polygon', 'LineString'].includes(feature.geometry.type)) {
415
414
  throw new Err(400, null, 'Unsupported Geometry Type');
416
415
  }
417
416
 
@@ -437,9 +436,11 @@ export async function from_geojson(
437
436
  stroke.a = feature.properties['stroke-opacity'] !== undefined ? feature.properties['stroke-opacity'] * 255 : 128;
438
437
  cot.event.detail.strokeColor = { _attributes: { value: stroke.as_32bit() } };
439
438
 
440
- if (!feature.properties['stroke-width']) feature.properties['stroke-width'] = 3;
439
+ let strokeWidth = feature.properties['stroke-width'] ?? 0;
440
+ if (strokeWidth === 0) strokeWidth = 3;
441
+ feature.properties['stroke-width'] = strokeWidth;
441
442
  cot.event.detail.strokeWeight = { _attributes: {
442
- value: feature.properties['stroke-width']
443
+ value: strokeWidth
443
444
  } };
444
445
 
445
446
  if (!feature.properties['stroke-style']) feature.properties['stroke-style'] = 'solid';
@@ -451,15 +452,13 @@ export async function from_geojson(
451
452
  const fill = new Color(feature.properties.fill || -1761607936);
452
453
  fill.a = feature.properties['fill-opacity'] !== undefined ? feature.properties['fill-opacity'] * 255 : 128;
453
454
  cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
454
- } else if (feature.geometry.type === 'LineString') {
455
+ } else if (feature.geometry.type === 'LineString' && feature.properties.type !== 'b-m-r') {
455
456
  // Ensure fill is fully transparent for LineStrings so that if Node treats the
456
457
  // feature as a polygon (when first/last coordinates coincide), no fill is rendered.
457
458
  // Exclude b-m-r (route) types as they are not user-drawn line features.
458
- if (feature.properties.type !== 'b-m-r') {
459
- const fill = new Color(feature.properties.fill || -1761607936);
460
- fill.a = 0;
461
- cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
462
- }
459
+ const fill = new Color(feature.properties.fill || -1761607936);
460
+ fill.a = 0;
461
+ cot.event.detail.fillColor = { _attributes: { value: fill.as_32bit() } };
463
462
  }
464
463
 
465
464
  if (feature.geometry.type === 'Polygon' && feature.properties.type && ELLIPSE_TYPES.has(feature.properties.type)) {
@@ -486,7 +485,7 @@ export async function from_geojson(
486
485
  Style: {
487
486
  LineStyle: {
488
487
  color: { _text: strokeColor.as_kml() },
489
- width: { _text: cot.event.detail.strokeWeight?._attributes?.value ? cot.event.detail.strokeWeight._attributes.value : 3 }
488
+ width: { _text: strokeWidth }
490
489
  },
491
490
  PolyStyle: {
492
491
  color: { _text: fillColor.as_kml() },
@@ -593,7 +592,7 @@ export async function from_geojson(
593
592
  cot.event.point._attributes.hae = 0.0;
594
593
  }
595
594
  } else {
596
- const centre = PointOnFeature(feature as AllGeoJSON);
595
+ const centre = PointOnFeature(feature);
597
596
  cot.event.point._attributes.lon = centre.geometry.coordinates[0];
598
597
  cot.event.point._attributes.lat = centre.geometry.coordinates[1];
599
598
  cot.event.point._attributes.hae = 0.0;
@@ -17,9 +17,9 @@ export async function normalize_geojson(
17
17
  feature: Static<typeof GeoJSONFeature>,
18
18
  ): Promise<Static<typeof Feature>> {
19
19
  try {
20
- feature = await TypeValidator.type(GeoJSONFeature, feature);
20
+ feature = TypeValidator.type(GeoJSONFeature, feature);
21
21
  } catch (err) {
22
- throw new Err(400, null, `Validation Error: ${err}`);
22
+ throw new Err(400, null, `Validation Error: ${String(err)}`);
23
23
  }
24
24
 
25
25
  if (!feature.id) {
@@ -29,7 +29,7 @@ export async function normalize_geojson(
29
29
  const props = feature.properties;
30
30
 
31
31
  feature.properties = {
32
- metadata: props || {}
32
+ metadata: props
33
33
  }
34
34
 
35
35
  if (feature.geometry.type === 'Point') {
@@ -43,47 +43,42 @@ export async function normalize_geojson(
43
43
  }
44
44
 
45
45
  for (const color of ['marker-color', 'stroke', 'fill']) {
46
- if (
47
- props[color]
48
- && typeof props[color] === 'string'
49
- && /^#?[0-9a-fA-F]{6}$/.test(props[color])
50
- ) {
51
- feature.properties[color] = props[color].startsWith('#') ? props[color] : `#${props[color]}`;
46
+ const value = props[color];
47
+ if (typeof value === 'string' && /^#?[0-9a-fA-F]{6}$/.test(value)) {
48
+ feature.properties[color] = value.startsWith('#') ? value : `#${value}`;
52
49
  }
53
50
  }
54
51
 
55
52
  for (const number of ['marker-opacity', 'stroke-opacity', 'stroke-width', 'fill-opacity']) {
56
- if (
57
- props[number]
58
- && typeof props[number] === 'number'
59
- ) {
60
- feature.properties[number] = props[number];
53
+ const value = props[number];
54
+ if (typeof value === 'number' && value) {
55
+ feature.properties[number] = value;
61
56
  }
62
57
  }
63
58
 
64
59
  // Callsign Options
65
- for (const callsign of ['callsign', 'title', 'name']) {
66
- if (props[callsign] && typeof props[callsign] === 'string') {
67
- feature.properties.callsign = props[callsign];
60
+ let callsign = 'New Feature';
61
+ for (const key of ['callsign', 'title', 'name']) {
62
+ const value = props[key];
63
+ if (typeof value === 'string' && value) {
64
+ callsign = value;
68
65
  break;
69
66
  }
70
67
  }
71
68
 
72
- if (!feature.properties.callsign) {
73
- feature.properties.callsign = 'New Feature';
74
- }
69
+ feature.properties.callsign = callsign;
75
70
 
76
71
  // Remarks Options
77
- for (const remarks of ['remarks', 'description']) {
78
- if (props[remarks] && typeof props[remarks] === 'string') {
79
- feature.properties.remarks = props[remarks];
72
+ let remarks = '';
73
+ for (const key of ['remarks', 'description']) {
74
+ const value = props[key];
75
+ if (typeof value === 'string' && value) {
76
+ remarks = value;
80
77
  break;
81
78
  }
82
79
  }
83
80
 
84
- if (!feature.properties.remarks) {
85
- feature.properties.remarks = '';
86
- }
81
+ feature.properties.remarks = remarks;
87
82
 
88
83
  feature.properties.time = new Date().toISOString();
89
84
  feature.properties.start = new Date().toISOString();
@@ -100,5 +95,6 @@ export async function normalize_geojson(
100
95
  coord.splice(3);
101
96
  });
102
97
 
98
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion
103
99
  return feature as Static<typeof Feature>;
104
100
  }