@tak-ps/node-cot 14.60.1 → 14.61.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 +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/builders/chat.d.ts +45 -0
- package/dist/lib/builders/chat.js +104 -2
- package/dist/lib/builders/chat.js.map +1 -1
- package/dist/lib/parser/to_geojson.js +4 -0
- package/dist/lib/parser/to_geojson.js.map +1 -1
- package/dist/lib/types/feature.d.ts +54 -0
- package/dist/lib/types/feature.js +15 -1
- package/dist/lib/types/feature.js.map +1 -1
- package/dist/lib/types/types.d.ts +10 -0
- package/dist/lib/types/types.js +4 -2
- package/dist/lib/types/types.js.map +1 -1
- package/dist/lib/utils/chat.d.ts +35 -0
- package/dist/lib/utils/chat.js +95 -0
- package/dist/lib/utils/chat.js.map +1 -0
- package/dist/package.json +1 -1
- package/index.ts +1 -0
- package/lib/builders/chat.ts +153 -2
- package/lib/parser/to_geojson.ts +4 -0
- package/lib/types/feature.ts +23 -1
- package/lib/types/types.ts +4 -2
- package/lib/utils/chat.ts +123 -0
- package/package.json +1 -1
package/lib/types/feature.ts
CHANGED
|
@@ -137,6 +137,24 @@ export const FeaturePropertySpatial = Type.Object({
|
|
|
137
137
|
spin: SpatialSpinAttributes
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
export const ChatHierarchy = Type.Object({
|
|
141
|
+
uid: Type.String(),
|
|
142
|
+
name: Type.String(),
|
|
143
|
+
type: Type.Union([Type.Literal('group'), Type.Literal('contact')]),
|
|
144
|
+
children: Type.Optional(Type.Array(Type.Any({
|
|
145
|
+
description: 'Nested ChatHierarchy nodes'
|
|
146
|
+
})))
|
|
147
|
+
}, {
|
|
148
|
+
description: 'Group membership tree sent with a GeoChat to a user created group, rooted at the UserGroups group'
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
export type ChatHierarchyNode = {
|
|
152
|
+
uid: string;
|
|
153
|
+
name: string;
|
|
154
|
+
type: 'group' | 'contact';
|
|
155
|
+
children?: Array<ChatHierarchyNode>;
|
|
156
|
+
};
|
|
157
|
+
|
|
140
158
|
export const Properties = Type.Object({
|
|
141
159
|
callsign: Type.String({ default: 'UNKNOWN' }),
|
|
142
160
|
type: Type.String({ default: 'a-f-G' }),
|
|
@@ -201,7 +219,11 @@ export const Properties = Type.Object({
|
|
|
201
219
|
chatroom: Type.String(),
|
|
202
220
|
id: Type.Optional(Type.String()),
|
|
203
221
|
senderCallsign: Type.String(),
|
|
204
|
-
|
|
222
|
+
deleteChild: Type.Optional(Type.String({
|
|
223
|
+
description: 'UID of a group that the sender deleted from the group this message is addressed to'
|
|
224
|
+
})),
|
|
225
|
+
chatgrp: Type.Any(),
|
|
226
|
+
hierarchy: Type.Optional(ChatHierarchy)
|
|
205
227
|
})),
|
|
206
228
|
track: Type.Optional(TrackAttributes),
|
|
207
229
|
dest: Type.Optional(Type.Union([MartiDestAttributes, Type.Array(MartiDestAttributes)])),
|
package/lib/types/types.ts
CHANGED
|
@@ -582,9 +582,11 @@ export const Chat = Type.Object({
|
|
|
582
582
|
messageId: Type.Optional(Type.String()),
|
|
583
583
|
chatroom: Type.String(),
|
|
584
584
|
id: Type.Optional(Type.String()),
|
|
585
|
-
senderCallsign: Type.String()
|
|
585
|
+
senderCallsign: Type.String(),
|
|
586
|
+
deleteChild: Type.Optional(Type.String())
|
|
586
587
|
}),
|
|
587
|
-
chatgrp: Type.Any()
|
|
588
|
+
chatgrp: Type.Any(),
|
|
589
|
+
hierarchy: Type.Optional(Type.Any())
|
|
588
590
|
})
|
|
589
591
|
|
|
590
592
|
export const TakVersionAttributes = Type.Object({
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { ChatHierarchyNode } from '../types/feature.js';
|
|
2
|
+
|
|
3
|
+
type RawHierarchyNode = {
|
|
4
|
+
_attributes?: { uid?: unknown; name?: unknown };
|
|
5
|
+
group?: unknown;
|
|
6
|
+
contact?: unknown;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
function isRawNode(raw: unknown): raw is RawHierarchyNode {
|
|
10
|
+
return typeof raw === 'object' && raw !== null;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function rawNodes(raw: unknown): Array<RawHierarchyNode> {
|
|
14
|
+
if (Array.isArray(raw)) return raw.filter((item) => isRawNode(item));
|
|
15
|
+
return isRawNode(raw) ? [raw] : [];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function toNode(raw: RawHierarchyNode, type: 'group' | 'contact'): ChatHierarchyNode | undefined {
|
|
19
|
+
const uid = raw._attributes?.uid;
|
|
20
|
+
const name = raw._attributes?.name;
|
|
21
|
+
|
|
22
|
+
if (typeof uid !== 'string' || typeof name !== 'string') return undefined;
|
|
23
|
+
|
|
24
|
+
const node: ChatHierarchyNode = { uid, name, type };
|
|
25
|
+
|
|
26
|
+
if (type === 'group') {
|
|
27
|
+
node.children = [
|
|
28
|
+
...rawNodes(raw.group).map((child) => toNode(child, 'group')),
|
|
29
|
+
...rawNodes(raw.contact).map((child) => toNode(child, 'contact'))
|
|
30
|
+
].filter((child) => child !== undefined);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return node;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Convert the `<hierarchy>` of a `__chat` detail into a tree of groups & contacts
|
|
38
|
+
*/
|
|
39
|
+
export function chatHierarchy(raw: unknown): ChatHierarchyNode | undefined {
|
|
40
|
+
if (!isRawNode(raw)) return undefined;
|
|
41
|
+
|
|
42
|
+
const roots = rawNodes(raw.group);
|
|
43
|
+
if (roots.length === 0) return undefined;
|
|
44
|
+
|
|
45
|
+
const root = roots[0];
|
|
46
|
+
|
|
47
|
+
return toNode(root, 'group');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
type HierarchyDetail = {
|
|
51
|
+
_attributes: { uid: string; name: string };
|
|
52
|
+
group?: Array<HierarchyDetail>;
|
|
53
|
+
contact?: Array<HierarchyDetail>;
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
function toDetail(node: ChatHierarchyNode): HierarchyDetail {
|
|
57
|
+
const detail: HierarchyDetail = {
|
|
58
|
+
_attributes: { uid: node.uid, name: node.name }
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const children = node.children ?? [];
|
|
62
|
+
const groups = children.filter((child) => child.type === 'group');
|
|
63
|
+
const contacts = children.filter((child) => child.type === 'contact');
|
|
64
|
+
|
|
65
|
+
if (groups.length > 0) detail.group = groups.map((group) => toDetail(group));
|
|
66
|
+
if (contacts.length > 0) detail.contact = contacts.map((contact) => toDetail(contact));
|
|
67
|
+
|
|
68
|
+
return detail;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Convert a tree of groups & contacts into the `<hierarchy>` of a `__chat` detail
|
|
73
|
+
*/
|
|
74
|
+
export function chatHierarchyDetail(root: ChatHierarchyNode): { group: HierarchyDetail } {
|
|
75
|
+
return { group: toDetail(root) };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Every contact below a node of a hierarchy, regardless of how deeply it is nested
|
|
80
|
+
*/
|
|
81
|
+
export function chatHierarchyContacts(node: ChatHierarchyNode): Array<{ uid: string; callsign: string }> {
|
|
82
|
+
const contacts = new Map<string, { uid: string; callsign: string }>();
|
|
83
|
+
|
|
84
|
+
const walk = (current: ChatHierarchyNode): void => {
|
|
85
|
+
if (current.type === 'contact') {
|
|
86
|
+
contacts.set(current.uid, { uid: current.uid, callsign: current.name });
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (const child of current.children ?? []) walk(child);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
walk(node);
|
|
93
|
+
|
|
94
|
+
return [...contacts.values()];
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Find a group by UID anywhere in a hierarchy
|
|
99
|
+
*/
|
|
100
|
+
export function chatHierarchyGroup(node: ChatHierarchyNode, uid: string): ChatHierarchyNode | undefined {
|
|
101
|
+
if (node.type === 'group' && node.uid === uid) return node;
|
|
102
|
+
|
|
103
|
+
for (const child of node.children ?? []) {
|
|
104
|
+
const found = chatHierarchyGroup(child, uid);
|
|
105
|
+
if (found) return found;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* UID of the group that directly contains the group with the given UID
|
|
113
|
+
*/
|
|
114
|
+
export function chatHierarchyParent(node: ChatHierarchyNode, uid: string): string | undefined {
|
|
115
|
+
for (const child of node.children ?? []) {
|
|
116
|
+
if (child.type === 'group' && child.uid === uid) return node.uid;
|
|
117
|
+
|
|
118
|
+
const found = chatHierarchyParent(child, uid);
|
|
119
|
+
if (found) return found;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return undefined;
|
|
123
|
+
}
|
package/package.json
CHANGED