@uns-kit/core 2.0.40 → 2.0.41

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 (54) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +170 -147
  3. package/dist/index.d.ts +9 -8
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +8 -7
  6. package/dist/index.js.map +1 -1
  7. package/dist/tools/datahub/datahub-client.js.map +1 -1
  8. package/dist/tools/file-utils.d.ts +2 -2
  9. package/dist/tools/file-utils.js +24 -24
  10. package/dist/tools/generate-uns-dictionary.d.ts +23 -23
  11. package/dist/tools/generate-uns-dictionary.js +154 -154
  12. package/dist/tools/generate-uns-measurements.d.ts +21 -21
  13. package/dist/tools/generate-uns-measurements.js +126 -126
  14. package/dist/tools/generate-uns-reference.d.ts +2 -2
  15. package/dist/tools/generate-uns-reference.js +85 -85
  16. package/dist/tools/refresh-uns.js +50 -50
  17. package/dist/tools/sync-uns-schema.d.ts +2 -2
  18. package/dist/tools/sync-uns-schema.js +489 -489
  19. package/dist/uns/service-metadata.d.ts +53 -0
  20. package/dist/uns/service-metadata.d.ts.map +1 -0
  21. package/dist/uns/service-metadata.js +56 -0
  22. package/dist/uns/service-metadata.js.map +1 -0
  23. package/dist/uns/uns-asset.d.ts +1 -1
  24. package/dist/uns/uns-asset.js +1 -1
  25. package/dist/uns/uns-attributes.d.ts +6 -6
  26. package/dist/uns/uns-attributes.js +9 -9
  27. package/dist/uns/uns-dictionary-registry.d.ts +4 -4
  28. package/dist/uns/uns-dictionary-registry.js +20 -20
  29. package/dist/uns/uns-dictionary.generated.d.ts +663 -663
  30. package/dist/uns/uns-dictionary.generated.js +745 -745
  31. package/dist/uns/uns-interfaces.d.ts +365 -365
  32. package/dist/uns/uns-measurements.generated.d.ts +362 -362
  33. package/dist/uns/uns-measurements.generated.js +359 -359
  34. package/dist/uns/uns-object.d.ts +20 -20
  35. package/dist/uns/uns-object.js +9 -9
  36. package/dist/uns/uns-packet.js +263 -263
  37. package/dist/uns/uns-path.d.ts +2 -2
  38. package/dist/uns/uns-path.js +10 -10
  39. package/dist/uns/uns-proxy-process.d.ts +11 -0
  40. package/dist/uns/uns-proxy-process.d.ts.map +1 -1
  41. package/dist/uns/uns-proxy-process.js +224 -203
  42. package/dist/uns/uns-proxy-process.js.map +1 -1
  43. package/dist/uns/uns-proxy.d.ts +51 -51
  44. package/dist/uns/uns-proxy.js +190 -190
  45. package/dist/uns-config/uns-core-schema.d.ts +3276 -3276
  46. package/dist/uns-grpc/uns-gateway.proto +104 -104
  47. package/dist/uns-mqtt/mqtt-topic-builder.d.ts +6 -0
  48. package/dist/uns-mqtt/mqtt-topic-builder.d.ts.map +1 -1
  49. package/dist/uns-mqtt/mqtt-topic-builder.js +8 -0
  50. package/dist/uns-mqtt/mqtt-topic-builder.js.map +1 -1
  51. package/dist/uns-mqtt/uns-mqtt-proxy.js +477 -477
  52. package/package.json +1 -1
  53. package/dist/app-config.d.ts.map +0 -1
  54. package/dist/app-config.js.map +0 -1
@@ -1,21 +1,21 @@
1
- import { GeneratedObjectTypes } from "./uns-dictionary.generated.js";
2
- export declare const ObjectTypes: {
3
- readonly "consumable-resource": "consumable-resource";
4
- readonly "energy-meter": "energy-meter";
5
- readonly "energy-resource": "energy-resource";
6
- readonly equipment: "equipment";
7
- readonly "fluid-resource": "fluid-resource";
8
- readonly material: "material";
9
- readonly personnel: "personnel";
10
- readonly "process-segment": "process-segment";
11
- readonly "product-definition": "product-definition";
12
- readonly "product-quality": "product-quality";
13
- readonly "resource-status": "resource-status";
14
- readonly "utility-resource": "utility-resource";
15
- readonly "work-definition": "work-definition";
16
- };
17
- export type KnownUnsObjectTypeName = keyof typeof GeneratedObjectTypes;
18
- export type UnsObjectType = "" | KnownUnsObjectTypeName | (string & {});
19
- export type UnsObjectId = "main" | "" | (string & {});
20
- export declare function getObjectTypeDescription(objectType: UnsObjectType): string | undefined;
1
+ import { GeneratedObjectTypes } from "./uns-dictionary.generated.js";
2
+ export declare const ObjectTypes: {
3
+ readonly "consumable-resource": "consumable-resource";
4
+ readonly "energy-meter": "energy-meter";
5
+ readonly "energy-resource": "energy-resource";
6
+ readonly equipment: "equipment";
7
+ readonly "fluid-resource": "fluid-resource";
8
+ readonly material: "material";
9
+ readonly personnel: "personnel";
10
+ readonly "process-segment": "process-segment";
11
+ readonly "product-definition": "product-definition";
12
+ readonly "product-quality": "product-quality";
13
+ readonly "resource-status": "resource-status";
14
+ readonly "utility-resource": "utility-resource";
15
+ readonly "work-definition": "work-definition";
16
+ };
17
+ export type KnownUnsObjectTypeName = keyof typeof GeneratedObjectTypes;
18
+ export type UnsObjectType = "" | KnownUnsObjectTypeName | (string & {});
19
+ export type UnsObjectId = "main" | "" | (string & {});
20
+ export declare function getObjectTypeDescription(objectType: UnsObjectType): string | undefined;
21
21
  //# sourceMappingURL=uns-object.d.ts.map
@@ -1,10 +1,10 @@
1
- // Slimmed: use generated dictionary as the source of object types.
2
- // Ensure generate-uns-dictionary is run (or provide your own generated file).
3
- import { GeneratedObjectTypes, GeneratedObjectTypeDescriptions } from "./uns-dictionary.generated.js";
4
- import { resolveObjectTypeDescription } from "./uns-dictionary-registry.js";
5
- export const ObjectTypes = GeneratedObjectTypes;
6
- export function getObjectTypeDescription(objectType) {
7
- return (resolveObjectTypeDescription(objectType) ??
8
- GeneratedObjectTypeDescriptions[objectType]);
9
- }
1
+ // Slimmed: use generated dictionary as the source of object types.
2
+ // Ensure generate-uns-dictionary is run (or provide your own generated file).
3
+ import { GeneratedObjectTypes, GeneratedObjectTypeDescriptions } from "./uns-dictionary.generated.js";
4
+ import { resolveObjectTypeDescription } from "./uns-dictionary-registry.js";
5
+ export const ObjectTypes = GeneratedObjectTypes;
6
+ export function getObjectTypeDescription(objectType) {
7
+ return (resolveObjectTypeDescription(objectType) ??
8
+ GeneratedObjectTypeDescriptions[objectType]);
9
+ }
10
10
  //# sourceMappingURL=uns-object.js.map
@@ -1,264 +1,264 @@
1
- import * as crypto from "crypto";
2
- import * as zlib from "zlib";
3
- import logger from '../logger.js';
4
- import { isIOS8601Type, isQuestDbType, valueTypes } from "./uns-interfaces.js";
5
- // Version of the packet library
6
- const unsPacketVersion = "1.3.0";
7
- export class UnsPacket {
8
- /**
9
- * The given TypeScript function parseMqttPacket is used to parse an MQTT packet,
10
- * which is presumed to be in JSON format. The goal is to transform this string into
11
- * a structured object that adheres to the IUnsPacket interface, or return null
12
- * if parsing fails.
13
- *
14
- * @param mqttPacket
15
- * @param instanceName
16
- * @returns IUnsPacket
17
- */
18
- static parseMqttPacket(mqttPacket, instanceName) {
19
- try {
20
- const parsedMqttPacket = JSON.parse(mqttPacket);
21
- // Check uns packet
22
- if (parsedMqttPacket && parsedMqttPacket.version) {
23
- const version = parsedMqttPacket.version;
24
- const data = parsedMqttPacket.message.data;
25
- const table = parsedMqttPacket.message.table;
26
- const expiresAt = parsedMqttPacket.message.expiresAt;
27
- const createdAt = parsedMqttPacket.message.createdAt;
28
- // Validate data and table objects
29
- UnsPacket.validateMessageComponents(data, table);
30
- const message = {
31
- ...(data !== undefined && { data }),
32
- ...(table !== undefined && { table }),
33
- ...(expiresAt !== undefined && { expiresAt }),
34
- ...(createdAt !== undefined && { createdAt }),
35
- };
36
- const messageSignature = parsedMqttPacket.messageSignature;
37
- const interval = parsedMqttPacket.interval;
38
- const unsPacket = {
39
- message,
40
- messageSignature,
41
- version,
42
- interval
43
- };
44
- return unsPacket;
45
- }
46
- else {
47
- logger.debug("Version number not specified in the mqtt packet");
48
- }
49
- }
50
- catch (error) {
51
- if (instanceName) {
52
- logger.error(`${instanceName} - Could not parse packet: ${error}`);
53
- }
54
- else {
55
- logger.error(`Could not parse packet: ${error}`);
56
- }
57
- }
58
- }
59
- /**
60
- * Validates the data and table objects to ensure they have the required properties
61
- * and that those properties have the correct types.
62
- *
63
- * @param data - The data object to validate
64
- * @param table - The table object to validate
65
- * @returns boolean | null
66
- */
67
- static validateMessageComponents(data, table) {
68
- const isIsoOrEpoch = (value) => {
69
- if (value === null || value === undefined)
70
- return true;
71
- if (typeof value === "number")
72
- return Number.isFinite(value);
73
- return isIOS8601Type(value);
74
- };
75
- if (data) {
76
- if (data.dataGroup) {
77
- if (!/^[A-Za-z0-9_.\-]+$/.test(data.dataGroup)) {
78
- throw new Error(`dataGroup must be a valid name (alphanumeric, underscores, hyphens and dots only)`);
79
- }
80
- }
81
- if (!data.time)
82
- throw new Error(`Time is not defined in data object`);
83
- if (!isIOS8601Type(data.time))
84
- throw new Error(`Time is not ISO8601`);
85
- if (data.value === undefined) {
86
- throw new Error(`Value is not defined in data object`);
87
- }
88
- if (!valueTypes.includes(typeof data.value)) {
89
- throw new Error(`Value in data object must be string or number`);
90
- }
91
- if (data.intervalStart !== undefined && !isIsoOrEpoch(data.intervalStart)) {
92
- throw new Error(`intervalStart is not ISO8601 or epoch ms`);
93
- }
94
- if (data.intervalEnd !== undefined && !isIsoOrEpoch(data.intervalEnd)) {
95
- throw new Error(`intervalEnd is not ISO8601 or epoch ms`);
96
- }
97
- if (data.windowStart !== undefined && !isIsoOrEpoch(data.windowStart)) {
98
- throw new Error(`windowStart is not ISO8601 or epoch ms`);
99
- }
100
- if (data.windowEnd !== undefined && !isIsoOrEpoch(data.windowEnd)) {
101
- throw new Error(`windowEnd is not ISO8601 or epoch ms`);
102
- }
103
- if (data.lastSeen !== undefined && !isIsoOrEpoch(data.lastSeen)) {
104
- throw new Error(`lastSeen is not ISO8601 or epoch ms`);
105
- }
106
- if (data.deletedAt !== undefined && !isIsoOrEpoch(data.deletedAt)) {
107
- throw new Error(`deletedAt is not ISO8601 or epoch ms`);
108
- }
109
- if (data.eventId && typeof data.eventId !== "string") {
110
- throw new Error(`eventId must be a string`);
111
- }
112
- if (data.deleted !== undefined && typeof data.deleted !== "boolean") {
113
- throw new Error(`deleted must be a boolean`);
114
- }
115
- }
116
- // Check table object
117
- if (table) {
118
- if (table.dataGroup) {
119
- if (!/^[A-Za-z0-9_.\-]+$/.test(table.dataGroup)) {
120
- throw new Error(`dataGroup must be a valid name (alphanumeric, underscores, hyphens and dots only)`);
121
- }
122
- }
123
- if (!table.time) {
124
- throw new Error(`Time is not defined in data object`);
125
- }
126
- if (!isIOS8601Type(table.time)) {
127
- throw new Error(`Time is not ISO8601`);
128
- }
129
- if (table.intervalStart !== undefined && !isIsoOrEpoch(table.intervalStart)) {
130
- throw new Error(`intervalStart is not ISO8601 or epoch ms`);
131
- }
132
- if (table.intervalEnd !== undefined && !isIsoOrEpoch(table.intervalEnd)) {
133
- throw new Error(`intervalEnd is not ISO8601 or epoch ms`);
134
- }
135
- if (table.windowStart !== undefined && !isIsoOrEpoch(table.windowStart)) {
136
- throw new Error(`windowStart is not ISO8601 or epoch ms`);
137
- }
138
- if (table.windowEnd !== undefined && !isIsoOrEpoch(table.windowEnd)) {
139
- throw new Error(`windowEnd is not ISO8601 or epoch ms`);
140
- }
141
- if (table.lastSeen !== undefined && !isIsoOrEpoch(table.lastSeen)) {
142
- throw new Error(`lastSeen is not ISO8601 or epoch ms`);
143
- }
144
- if (table.deletedAt !== undefined && !isIsoOrEpoch(table.deletedAt)) {
145
- throw new Error(`deletedAt is not ISO8601 or epoch ms`);
146
- }
147
- if (table.eventId && typeof table.eventId !== "string") {
148
- throw new Error(`eventId must be a string`);
149
- }
150
- if (table.deleted !== undefined && typeof table.deleted !== "boolean") {
151
- throw new Error(`deleted must be a boolean`);
152
- }
153
- if (!Array.isArray(table.columns) || table.columns.length === 0) {
154
- throw new Error(`Table.columns must be a non-empty array`);
155
- }
156
- table.columns.forEach((column, index) => {
157
- if (!column.name) {
158
- throw new Error(`Column at index ${index} is missing a name`);
159
- }
160
- if (!column.type) {
161
- throw new Error(`Column '${column.name}' is missing a QuestDB type`);
162
- }
163
- if (!isQuestDbType(column.type)) {
164
- throw new Error(`Column '${column.name}' has invalid QuestDB type '${column.type}'`);
165
- }
166
- const value = column.value;
167
- if (typeof value !== "number" &&
168
- typeof value !== "string" &&
169
- typeof value !== "boolean" &&
170
- value !== null) {
171
- throw new Error(`Value for column '${column.name}' must be number, string, boolean, or null`);
172
- }
173
- });
174
- }
175
- return true;
176
- }
177
- static async unsPacketFromUnsMessage(message, unsPackatParameters) {
178
- try {
179
- // Validate the packet in message
180
- if (UnsPacket.validateMessageComponents(message.data, message.table)) {
181
- // HMAC
182
- // const algorithm = "sha256";
183
- // const key = "your-secret-key";
184
- // const packetMessage = JSON.stringify(message);
185
- // const hmacHash = this.generateHmac(algorithm, key, packetMessage);
186
- // const unsPacket: IUnsPacket = {
187
- // message,
188
- // messageSignature: hmacHash,
189
- // version: unsPacketVersion
190
- // };
191
- let data = undefined;
192
- if (message.data && message.data.value !== undefined) {
193
- const valueType = typeof message.data.value;
194
- if (!valueTypes.includes(valueType)) {
195
- throw new Error(`Value in data object must be string or number`);
196
- }
197
- data = {
198
- ...message.data,
199
- valueType: valueType
200
- };
201
- }
202
- ;
203
- const extendedMessage = {
204
- data,
205
- table: message.table,
206
- expiresAt: message.expiresAt,
207
- createdAt: message.createdAt,
208
- };
209
- const unsPacket = {
210
- message: extendedMessage,
211
- version: unsPacketVersion,
212
- };
213
- return unsPacket;
214
- }
215
- }
216
- catch (error) {
217
- logger.error(`Could not create packet from message: ${error}`);
218
- }
219
- }
220
- static generateHmac(algorithm, key, data) {
221
- const hmac = crypto.createHmac(algorithm, key);
222
- hmac.update(data);
223
- return hmac.digest("hex");
224
- }
225
- static formatToISO8601(date) {
226
- const year = date.getUTCFullYear();
227
- const month = String(date.getUTCMonth() + 1).padStart(2, "0");
228
- const day = String(date.getUTCDate()).padStart(2, "0");
229
- const hours = String(date.getUTCHours()).padStart(2, "0");
230
- const minutes = String(date.getUTCMinutes()).padStart(2, "0");
231
- const seconds = String(date.getUTCSeconds()).padStart(2, "0");
232
- const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
233
- return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;
234
- }
235
- static compressString(input) {
236
- return new Promise((resolve, reject) => {
237
- zlib.deflate(input, (err, buffer) => {
238
- if (err) {
239
- reject(err);
240
- }
241
- else {
242
- const base64String = buffer.toString("base64");
243
- resolve(base64String);
244
- }
245
- });
246
- });
247
- }
248
- // Function to decompress a Buffer back to a string
249
- static decompressString(base64Compressed) {
250
- return new Promise((resolve, reject) => {
251
- // Decode the base64 string to a Buffer
252
- const compressedBuffer = Buffer.from(base64Compressed, "base64");
253
- zlib.inflate(compressedBuffer, (err, buffer) => {
254
- if (err) {
255
- reject(err);
256
- }
257
- else {
258
- resolve(buffer.toString());
259
- }
260
- });
261
- });
262
- }
263
- }
1
+ import * as crypto from "crypto";
2
+ import * as zlib from "zlib";
3
+ import logger from '../logger.js';
4
+ import { isIOS8601Type, isQuestDbType, valueTypes } from "./uns-interfaces.js";
5
+ // Version of the packet library
6
+ const unsPacketVersion = "1.3.0";
7
+ export class UnsPacket {
8
+ /**
9
+ * The given TypeScript function parseMqttPacket is used to parse an MQTT packet,
10
+ * which is presumed to be in JSON format. The goal is to transform this string into
11
+ * a structured object that adheres to the IUnsPacket interface, or return null
12
+ * if parsing fails.
13
+ *
14
+ * @param mqttPacket
15
+ * @param instanceName
16
+ * @returns IUnsPacket
17
+ */
18
+ static parseMqttPacket(mqttPacket, instanceName) {
19
+ try {
20
+ const parsedMqttPacket = JSON.parse(mqttPacket);
21
+ // Check uns packet
22
+ if (parsedMqttPacket && parsedMqttPacket.version) {
23
+ const version = parsedMqttPacket.version;
24
+ const data = parsedMqttPacket.message.data;
25
+ const table = parsedMqttPacket.message.table;
26
+ const expiresAt = parsedMqttPacket.message.expiresAt;
27
+ const createdAt = parsedMqttPacket.message.createdAt;
28
+ // Validate data and table objects
29
+ UnsPacket.validateMessageComponents(data, table);
30
+ const message = {
31
+ ...(data !== undefined && { data }),
32
+ ...(table !== undefined && { table }),
33
+ ...(expiresAt !== undefined && { expiresAt }),
34
+ ...(createdAt !== undefined && { createdAt }),
35
+ };
36
+ const messageSignature = parsedMqttPacket.messageSignature;
37
+ const interval = parsedMqttPacket.interval;
38
+ const unsPacket = {
39
+ message,
40
+ messageSignature,
41
+ version,
42
+ interval
43
+ };
44
+ return unsPacket;
45
+ }
46
+ else {
47
+ logger.debug("Version number not specified in the mqtt packet");
48
+ }
49
+ }
50
+ catch (error) {
51
+ if (instanceName) {
52
+ logger.error(`${instanceName} - Could not parse packet: ${error}`);
53
+ }
54
+ else {
55
+ logger.error(`Could not parse packet: ${error}`);
56
+ }
57
+ }
58
+ }
59
+ /**
60
+ * Validates the data and table objects to ensure they have the required properties
61
+ * and that those properties have the correct types.
62
+ *
63
+ * @param data - The data object to validate
64
+ * @param table - The table object to validate
65
+ * @returns boolean | null
66
+ */
67
+ static validateMessageComponents(data, table) {
68
+ const isIsoOrEpoch = (value) => {
69
+ if (value === null || value === undefined)
70
+ return true;
71
+ if (typeof value === "number")
72
+ return Number.isFinite(value);
73
+ return isIOS8601Type(value);
74
+ };
75
+ if (data) {
76
+ if (data.dataGroup) {
77
+ if (!/^[A-Za-z0-9_.\-]+$/.test(data.dataGroup)) {
78
+ throw new Error(`dataGroup must be a valid name (alphanumeric, underscores, hyphens and dots only)`);
79
+ }
80
+ }
81
+ if (!data.time)
82
+ throw new Error(`Time is not defined in data object`);
83
+ if (!isIOS8601Type(data.time))
84
+ throw new Error(`Time is not ISO8601`);
85
+ if (data.value === undefined) {
86
+ throw new Error(`Value is not defined in data object`);
87
+ }
88
+ if (!valueTypes.includes(typeof data.value)) {
89
+ throw new Error(`Value in data object must be string or number`);
90
+ }
91
+ if (data.intervalStart !== undefined && !isIsoOrEpoch(data.intervalStart)) {
92
+ throw new Error(`intervalStart is not ISO8601 or epoch ms`);
93
+ }
94
+ if (data.intervalEnd !== undefined && !isIsoOrEpoch(data.intervalEnd)) {
95
+ throw new Error(`intervalEnd is not ISO8601 or epoch ms`);
96
+ }
97
+ if (data.windowStart !== undefined && !isIsoOrEpoch(data.windowStart)) {
98
+ throw new Error(`windowStart is not ISO8601 or epoch ms`);
99
+ }
100
+ if (data.windowEnd !== undefined && !isIsoOrEpoch(data.windowEnd)) {
101
+ throw new Error(`windowEnd is not ISO8601 or epoch ms`);
102
+ }
103
+ if (data.lastSeen !== undefined && !isIsoOrEpoch(data.lastSeen)) {
104
+ throw new Error(`lastSeen is not ISO8601 or epoch ms`);
105
+ }
106
+ if (data.deletedAt !== undefined && !isIsoOrEpoch(data.deletedAt)) {
107
+ throw new Error(`deletedAt is not ISO8601 or epoch ms`);
108
+ }
109
+ if (data.eventId && typeof data.eventId !== "string") {
110
+ throw new Error(`eventId must be a string`);
111
+ }
112
+ if (data.deleted !== undefined && typeof data.deleted !== "boolean") {
113
+ throw new Error(`deleted must be a boolean`);
114
+ }
115
+ }
116
+ // Check table object
117
+ if (table) {
118
+ if (table.dataGroup) {
119
+ if (!/^[A-Za-z0-9_.\-]+$/.test(table.dataGroup)) {
120
+ throw new Error(`dataGroup must be a valid name (alphanumeric, underscores, hyphens and dots only)`);
121
+ }
122
+ }
123
+ if (!table.time) {
124
+ throw new Error(`Time is not defined in data object`);
125
+ }
126
+ if (!isIOS8601Type(table.time)) {
127
+ throw new Error(`Time is not ISO8601`);
128
+ }
129
+ if (table.intervalStart !== undefined && !isIsoOrEpoch(table.intervalStart)) {
130
+ throw new Error(`intervalStart is not ISO8601 or epoch ms`);
131
+ }
132
+ if (table.intervalEnd !== undefined && !isIsoOrEpoch(table.intervalEnd)) {
133
+ throw new Error(`intervalEnd is not ISO8601 or epoch ms`);
134
+ }
135
+ if (table.windowStart !== undefined && !isIsoOrEpoch(table.windowStart)) {
136
+ throw new Error(`windowStart is not ISO8601 or epoch ms`);
137
+ }
138
+ if (table.windowEnd !== undefined && !isIsoOrEpoch(table.windowEnd)) {
139
+ throw new Error(`windowEnd is not ISO8601 or epoch ms`);
140
+ }
141
+ if (table.lastSeen !== undefined && !isIsoOrEpoch(table.lastSeen)) {
142
+ throw new Error(`lastSeen is not ISO8601 or epoch ms`);
143
+ }
144
+ if (table.deletedAt !== undefined && !isIsoOrEpoch(table.deletedAt)) {
145
+ throw new Error(`deletedAt is not ISO8601 or epoch ms`);
146
+ }
147
+ if (table.eventId && typeof table.eventId !== "string") {
148
+ throw new Error(`eventId must be a string`);
149
+ }
150
+ if (table.deleted !== undefined && typeof table.deleted !== "boolean") {
151
+ throw new Error(`deleted must be a boolean`);
152
+ }
153
+ if (!Array.isArray(table.columns) || table.columns.length === 0) {
154
+ throw new Error(`Table.columns must be a non-empty array`);
155
+ }
156
+ table.columns.forEach((column, index) => {
157
+ if (!column.name) {
158
+ throw new Error(`Column at index ${index} is missing a name`);
159
+ }
160
+ if (!column.type) {
161
+ throw new Error(`Column '${column.name}' is missing a QuestDB type`);
162
+ }
163
+ if (!isQuestDbType(column.type)) {
164
+ throw new Error(`Column '${column.name}' has invalid QuestDB type '${column.type}'`);
165
+ }
166
+ const value = column.value;
167
+ if (typeof value !== "number" &&
168
+ typeof value !== "string" &&
169
+ typeof value !== "boolean" &&
170
+ value !== null) {
171
+ throw new Error(`Value for column '${column.name}' must be number, string, boolean, or null`);
172
+ }
173
+ });
174
+ }
175
+ return true;
176
+ }
177
+ static async unsPacketFromUnsMessage(message, unsPackatParameters) {
178
+ try {
179
+ // Validate the packet in message
180
+ if (UnsPacket.validateMessageComponents(message.data, message.table)) {
181
+ // HMAC
182
+ // const algorithm = "sha256";
183
+ // const key = "your-secret-key";
184
+ // const packetMessage = JSON.stringify(message);
185
+ // const hmacHash = this.generateHmac(algorithm, key, packetMessage);
186
+ // const unsPacket: IUnsPacket = {
187
+ // message,
188
+ // messageSignature: hmacHash,
189
+ // version: unsPacketVersion
190
+ // };
191
+ let data = undefined;
192
+ if (message.data && message.data.value !== undefined) {
193
+ const valueType = typeof message.data.value;
194
+ if (!valueTypes.includes(valueType)) {
195
+ throw new Error(`Value in data object must be string or number`);
196
+ }
197
+ data = {
198
+ ...message.data,
199
+ valueType: valueType
200
+ };
201
+ }
202
+ ;
203
+ const extendedMessage = {
204
+ data,
205
+ table: message.table,
206
+ expiresAt: message.expiresAt,
207
+ createdAt: message.createdAt,
208
+ };
209
+ const unsPacket = {
210
+ message: extendedMessage,
211
+ version: unsPacketVersion,
212
+ };
213
+ return unsPacket;
214
+ }
215
+ }
216
+ catch (error) {
217
+ logger.error(`Could not create packet from message: ${error}`);
218
+ }
219
+ }
220
+ static generateHmac(algorithm, key, data) {
221
+ const hmac = crypto.createHmac(algorithm, key);
222
+ hmac.update(data);
223
+ return hmac.digest("hex");
224
+ }
225
+ static formatToISO8601(date) {
226
+ const year = date.getUTCFullYear();
227
+ const month = String(date.getUTCMonth() + 1).padStart(2, "0");
228
+ const day = String(date.getUTCDate()).padStart(2, "0");
229
+ const hours = String(date.getUTCHours()).padStart(2, "0");
230
+ const minutes = String(date.getUTCMinutes()).padStart(2, "0");
231
+ const seconds = String(date.getUTCSeconds()).padStart(2, "0");
232
+ const milliseconds = String(date.getUTCMilliseconds()).padStart(3, "0");
233
+ return `${year}-${month}-${day}T${hours}:${minutes}:${seconds}.${milliseconds}Z`;
234
+ }
235
+ static compressString(input) {
236
+ return new Promise((resolve, reject) => {
237
+ zlib.deflate(input, (err, buffer) => {
238
+ if (err) {
239
+ reject(err);
240
+ }
241
+ else {
242
+ const base64String = buffer.toString("base64");
243
+ resolve(base64String);
244
+ }
245
+ });
246
+ });
247
+ }
248
+ // Function to decompress a Buffer back to a string
249
+ static decompressString(base64Compressed) {
250
+ return new Promise((resolve, reject) => {
251
+ // Decode the base64 string to a Buffer
252
+ const compressedBuffer = Buffer.from(base64Compressed, "base64");
253
+ zlib.inflate(compressedBuffer, (err, buffer) => {
254
+ if (err) {
255
+ reject(err);
256
+ }
257
+ else {
258
+ resolve(buffer.toString());
259
+ }
260
+ });
261
+ });
262
+ }
263
+ }
264
264
  //# sourceMappingURL=uns-packet.js.map
@@ -1,3 +1,3 @@
1
- export declare function buildUnsIdentityPath(...segments: string[]): string;
2
- export declare function buildUnsRoutePath(...segments: string[]): string;
1
+ export declare function buildUnsIdentityPath(...segments: string[]): string;
2
+ export declare function buildUnsRoutePath(...segments: string[]): string;
3
3
  //# sourceMappingURL=uns-path.d.ts.map
@@ -1,11 +1,11 @@
1
- const normalizeSegment = (value) => value.trim().replace(/^\/+|\/+$/g, "");
2
- export function buildUnsIdentityPath(...segments) {
3
- return segments
4
- .map((segment) => normalizeSegment(String(segment ?? "")))
5
- .filter((segment) => segment.length > 0)
6
- .join("/");
7
- }
8
- export function buildUnsRoutePath(...segments) {
9
- return `/${buildUnsIdentityPath(...segments)}`.replace(/\/{2,}/g, "/");
10
- }
1
+ const normalizeSegment = (value) => value.trim().replace(/^\/+|\/+$/g, "");
2
+ export function buildUnsIdentityPath(...segments) {
3
+ return segments
4
+ .map((segment) => normalizeSegment(String(segment ?? "")))
5
+ .filter((segment) => segment.length > 0)
6
+ .join("/");
7
+ }
8
+ export function buildUnsRoutePath(...segments) {
9
+ return `/${buildUnsIdentityPath(...segments)}`.replace(/\/{2,}/g, "/");
10
+ }
11
11
  //# sourceMappingURL=uns-path.js.map