Skip to content

Commit

Permalink
Passing TS Build
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Apr 10, 2024
1 parent 41a409a commit b8ac11d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
9 changes: 7 additions & 2 deletions lib/cot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {} };

}

Expand Down Expand Up @@ -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<typeof MartiDest>) => {
dest: dest.map((dest: {
uid?: string;
mission?: string;
callsign?: string;
}) => {
return { _attributes: { ...dest } };
})
}
Expand Down Expand Up @@ -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());
}

Expand Down
36 changes: 28 additions & 8 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand All @@ -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({
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand Down
7 changes: 3 additions & 4 deletions test/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b8ac11d

Please sign in to comment.