From b8ac11d3285ae50426ffad8487533962591c62d4 Mon Sep 17 00:00:00 2001 From: ingalls Date: Wed, 10 Apr 2024 08:05:13 -0600 Subject: [PATCH] Passing TS Build --- lib/cot.ts | 9 +++++++-- lib/types.ts | 36 ++++++++++++++++++++++++++++-------- test/chat.test.ts | 7 +++---- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/cot.ts b/lib/cot.ts index d75d4fe..7f00c93 100644 --- a/lib/cot.ts +++ b/lib/cot.ts @@ -47,7 +47,7 @@ export default class CoT { if (!this.raw.event.detail['_flow-tags_']) this.raw.event.detail['_flow-tags_'] = {}; this.raw.event.detail['_flow-tags_'][`NodeCoT-${pkg.version}`] = new Date().toISOString() - if (this.raw.event.detail.archived && Object.keys(this.raw.event.detail.archived).length === 0) this.raw.event.archived = { _attributes: {} }; + if (this.raw.event.detail.archived && Object.keys(this.raw.event.detail.archived).length === 0) this.raw.event.detail.archived = { _attributes: {} }; } @@ -92,7 +92,11 @@ export default class CoT { const dest = !Array.isArray(feature.properties.dest) ? [ feature.properties.dest ] : feature.properties.dest; cot.event.detail.marti = { - dest: dest.map((dest: Static) => { + dest: dest.map((dest: { + uid?: string; + mission?: string; + callsign?: string; + }) => { return { _attributes: { ...dest } }; }) } @@ -306,6 +310,7 @@ export default class CoT { const coordinates = []; for (const l of raw.event.detail.link) { + if (!l._attributes.point) continue; coordinates.push(l._attributes.point.split(',').map((p: string) => { return Number(p.trim()) }).splice(0, 2).reverse()); } diff --git a/lib/types.ts b/lib/types.ts index 51e0bb7..1044459 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -4,11 +4,33 @@ export const EventAttributes = Type.Object({ version: Type.String(), uid: Type.String(), type: Type.String(), - how: Type.String() + how: Type.String(), + + time: Type.String(), + stale: Type.String(), + start: Type.String(), }); +export const TogAttributes = Type.Object({ + _attributes: Type.Optional(Type.Object({ + enabled: Type.Optional(Type.String()) + })) +}) + +export const LinkAttributes = Type.Object({ + _attributes: Type.Object({ + point: Type.Optional(Type.String()), + + uid: Type.Optional(Type.String()), + type: Type.Optional(Type.String()), + relation: Type.Optional(Type.String()), + }) +}) + export const GenericAttributes = Type.Object({ - _attributes: Type.Optional(Type.Object({})) + _attributes: Type.Optional(Type.Object({ + value: Type.Optional(Type.String()) + })) }) export const TrackAttributes = Type.Object({ @@ -34,7 +56,7 @@ export const Chat = Type.Object({ id: Type.String(), senderCallsign: Type.String() }), - chatgrp: GenericAttributes + chatgrp: Type.Any() }) export const TakVersion = Type.Object({ @@ -46,9 +68,7 @@ export const TakVersion = Type.Object({ }) }) -export const FlowTags = Type.Object({ - _attributes: Type.Optional(Type.Object({})) -}) +export const FlowTags = Type.Any(); export const Group = Type.Object({ _attributes: Type.Optional(Type.Object({ @@ -115,7 +135,7 @@ export const UserIcon = Type.Object({ export const Detail = Type.Object({ contact: Type.Optional(Contact), - tog: Type.Optional(GenericAttributes), + tog: Type.Optional(TogAttributes), '__group': Type.Optional(Group), '__chat': Type.Optional(Chat), '_flow-tags_': Type.Optional(FlowTags), @@ -129,7 +149,7 @@ export const Detail = Type.Object({ strokeStyle: Type.Optional(GenericAttributes), labels_on: Type.Optional(GenericAttributes), fillColor: Type.Optional(GenericAttributes), - link: Type.Optional(Type.Union([GenericAttributes, Type.Array(GenericAttributes)])), + link: Type.Optional(Type.Union([LinkAttributes, Type.Array(LinkAttributes)])), usericon: Type.Optional(UserIcon), track: Type.Optional(Track), takv: Type.Optional(TakVersion), diff --git a/test/chat.test.ts b/test/chat.test.ts index 8adfabd..93b36f9 100644 --- a/test/chat.test.ts +++ b/test/chat.test.ts @@ -25,10 +25,9 @@ test('DirectChat - Basic', (t) => { t.ok(cot.raw.event.detail['_flow-tags_']); delete cot.raw.event.detail['_flow-tags_']; - for (const i of ['time', 'start', 'stale']) { - t.equals(typeof cot.raw.event._attributes[i], 'string'); - delete cot.raw.event._attributes[i]; - } + t.equals(typeof cot.raw.event._attributes.time, 'string'); + t.equals(typeof cot.raw.event._attributes.start, 'string'); + t.equals(typeof cot.raw.event._attributes.stale, 'string'); if (!cot.raw.event.detail.__chat) { t.fail('No Detail Section')