@uns-kit/core 0.0.1

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -0
  3. package/dist/app-config.d.ts +177 -0
  4. package/dist/app-config.js +1 -0
  5. package/dist/base-path.d.ts +1 -0
  6. package/dist/base-path.js +5 -0
  7. package/dist/config/project.config.extension.d.ts +3 -0
  8. package/dist/config/project.config.extension.js +3 -0
  9. package/dist/config-file.d.ts +12 -0
  10. package/dist/config-file.js +44 -0
  11. package/dist/examples/data-example.d.ts +1 -0
  12. package/dist/examples/data-example.js +44 -0
  13. package/dist/examples/load-test-data.d.ts +1 -0
  14. package/dist/examples/load-test-data.js +72 -0
  15. package/dist/examples/table-example.d.ts +4 -0
  16. package/dist/examples/table-example.js +52 -0
  17. package/dist/examples/uns-gateway.d.ts +1 -0
  18. package/dist/examples/uns-gateway.js +5 -0
  19. package/dist/graphql/schema.d.ts +377 -0
  20. package/dist/graphql/schema.js +13 -0
  21. package/dist/index.d.ts +5 -0
  22. package/dist/index.js +4 -0
  23. package/dist/logger.d.ts +2 -0
  24. package/dist/logger.js +18 -0
  25. package/dist/tools/auth/auth-client.d.ts +23 -0
  26. package/dist/tools/auth/auth-client.js +172 -0
  27. package/dist/tools/auth/index.d.ts +1 -0
  28. package/dist/tools/auth/index.js +1 -0
  29. package/dist/tools/auth/secure-store.d.ts +17 -0
  30. package/dist/tools/auth/secure-store.js +110 -0
  31. package/dist/tools/base-path.d.ts +1 -0
  32. package/dist/tools/base-path.js +5 -0
  33. package/dist/tools/generate-config-schema.d.ts +1 -0
  34. package/dist/tools/generate-config-schema.js +23 -0
  35. package/dist/tools/initialize.d.ts +1 -0
  36. package/dist/tools/initialize.js +103 -0
  37. package/dist/tools/make.d.ts +1 -0
  38. package/dist/tools/make.js +27 -0
  39. package/dist/tools/pull-request.d.ts +1 -0
  40. package/dist/tools/pull-request.js +157 -0
  41. package/dist/tools/refresh-uns.d.ts +1 -0
  42. package/dist/tools/refresh-uns.js +109 -0
  43. package/dist/tools/schema.d.ts +208 -0
  44. package/dist/tools/schema.js +1 -0
  45. package/dist/tools/update-rtt.d.ts +1 -0
  46. package/dist/tools/update-rtt.js +169 -0
  47. package/dist/tools/update-tools.d.ts +1 -0
  48. package/dist/tools/update-tools.js +72 -0
  49. package/dist/uns/handover-manager-event-emitter.d.ts +6 -0
  50. package/dist/uns/handover-manager-event-emitter.js +19 -0
  51. package/dist/uns/handover-manager.d.ts +34 -0
  52. package/dist/uns/handover-manager.js +227 -0
  53. package/dist/uns/process-config.d.ts +10 -0
  54. package/dist/uns/process-config.js +12 -0
  55. package/dist/uns/process-name-service.d.ts +7 -0
  56. package/dist/uns/process-name-service.js +28 -0
  57. package/dist/uns/status-monitor.d.ts +35 -0
  58. package/dist/uns/status-monitor.js +82 -0
  59. package/dist/uns/uns-event-emitter.d.ts +6 -0
  60. package/dist/uns/uns-event-emitter.js +19 -0
  61. package/dist/uns/uns-interfaces.d.ts +156 -0
  62. package/dist/uns/uns-interfaces.js +5 -0
  63. package/dist/uns/uns-measurements.d.ts +95 -0
  64. package/dist/uns/uns-measurements.js +146 -0
  65. package/dist/uns/uns-packet.d.ts +28 -0
  66. package/dist/uns/uns-packet.js +223 -0
  67. package/dist/uns/uns-proxy-process.d.ts +56 -0
  68. package/dist/uns/uns-proxy-process.js +179 -0
  69. package/dist/uns/uns-proxy.d.ts +31 -0
  70. package/dist/uns/uns-proxy.js +120 -0
  71. package/dist/uns/uns-tags.d.ts +1 -0
  72. package/dist/uns/uns-tags.js +1 -0
  73. package/dist/uns/uns-topic-matcher.d.ts +9 -0
  74. package/dist/uns/uns-topic-matcher.js +34 -0
  75. package/dist/uns/uns-topics.d.ts +1 -0
  76. package/dist/uns/uns-topics.js +1 -0
  77. package/dist/uns-config/config-schema.d.ts +7 -0
  78. package/dist/uns-config/config-schema.js +5 -0
  79. package/dist/uns-config/host-placeholders.d.ts +139 -0
  80. package/dist/uns-config/host-placeholders.js +70 -0
  81. package/dist/uns-config/schema-tolls.d.ts +2 -0
  82. package/dist/uns-config/schema-tolls.js +4 -0
  83. package/dist/uns-config/schema-tools.d.ts +2 -0
  84. package/dist/uns-config/schema-tools.js +18 -0
  85. package/dist/uns-config/secret-placeholders.d.ts +128 -0
  86. package/dist/uns-config/secret-placeholders.js +64 -0
  87. package/dist/uns-config/secret-resolver.d.ts +77 -0
  88. package/dist/uns-config/secret-resolver.js +285 -0
  89. package/dist/uns-config/uns-core-schema.d.ts +705 -0
  90. package/dist/uns-config/uns-core-schema.js +25 -0
  91. package/dist/uns-grpc/uns-gateway-cli.d.ts +2 -0
  92. package/dist/uns-grpc/uns-gateway-cli.js +32 -0
  93. package/dist/uns-grpc/uns-gateway-server.d.ts +47 -0
  94. package/dist/uns-grpc/uns-gateway-server.js +424 -0
  95. package/dist/uns-mqtt/mqtt-interfaces.d.ts +22 -0
  96. package/dist/uns-mqtt/mqtt-interfaces.js +1 -0
  97. package/dist/uns-mqtt/mqtt-proxy.d.ts +34 -0
  98. package/dist/uns-mqtt/mqtt-proxy.js +245 -0
  99. package/dist/uns-mqtt/mqtt-topic-builder.d.ts +51 -0
  100. package/dist/uns-mqtt/mqtt-topic-builder.js +70 -0
  101. package/dist/uns-mqtt/mqtt-worker-init.d.ts +1 -0
  102. package/dist/uns-mqtt/mqtt-worker-init.js +5 -0
  103. package/dist/uns-mqtt/mqtt-worker.d.ts +20 -0
  104. package/dist/uns-mqtt/mqtt-worker.js +120 -0
  105. package/dist/uns-mqtt/throttled-queue.d.ts +166 -0
  106. package/dist/uns-mqtt/throttled-queue.js +388 -0
  107. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts +107 -0
  108. package/dist/uns-mqtt/uns-mqtt-proxy.js +349 -0
  109. package/dist/uns-mqtt/ws-proxy.d.ts +38 -0
  110. package/dist/uns-mqtt/ws-proxy.js +86 -0
  111. package/package.json +48 -0
@@ -0,0 +1,388 @@
1
+ import { createHash } from "crypto";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
3
+ import { join } from "path";
4
+ import { basePath } from "../base-path.js";
5
+ import logger from "../logger.js";
6
+ /**
7
+ * Abstract base class that encapsulates common functionality for managing
8
+ * a throttled in‑memory queue with an optional disk persistence.
9
+ */
10
+ class ThrottledQueue {
11
+ queue = [];
12
+ lastProcessedItems = [];
13
+ isProcessing = false;
14
+ delay;
15
+ persistToDisk;
16
+ persistenceFilePath;
17
+ previousLoggedSize = 0;
18
+ instanceName;
19
+ active = true;
20
+ inactiveLogSent = false;
21
+ constructor(delay, persistToDisk, instanceName) {
22
+ this.delay = delay;
23
+ this.persistToDisk = persistToDisk;
24
+ this.instanceName = instanceName;
25
+ if (this.persistToDisk) {
26
+ this.loadQueueFromDisk();
27
+ }
28
+ }
29
+ /**
30
+ * Process the queue items one at a time with a delay between each.
31
+ */
32
+ async processQueue() {
33
+ if (this.isProcessing)
34
+ return;
35
+ this.isProcessing = true;
36
+ if (!this.active) {
37
+ if (!this.inactiveLogSent) {
38
+ logger.info(`${this.instanceName} - Queue is not active. Exiting processQueue.`);
39
+ this.inactiveLogSent = true;
40
+ }
41
+ this.isProcessing = false;
42
+ return;
43
+ }
44
+ // Reset the flag when processing actually starts.
45
+ this.inactiveLogSent = false;
46
+ while (this.queue.length > 0) {
47
+ // Check if the queue is active
48
+ if (!this.active) {
49
+ logger.info(`${this.instanceName} - Queue processing paused.`);
50
+ this.isProcessing = false;
51
+ return; // Exit the loop and stop processing
52
+ }
53
+ const item = this.queue.shift();
54
+ if (item) {
55
+ try {
56
+ await this.processItem(item);
57
+ // Only store 10 last processed items
58
+ if (this.lastProcessedItems.length >= 10) {
59
+ this.lastProcessedItems.shift();
60
+ }
61
+ // Store the last processed item
62
+ this.lastProcessedItems.push(item);
63
+ }
64
+ catch (error) {
65
+ // Specific error handling can be done in the subclass if needed.
66
+ logger.error(`${this.instanceName} - Error processing item: ${error.message}`);
67
+ }
68
+ if (this.persistToDisk) {
69
+ this.saveQueueToDisk();
70
+ }
71
+ if (this.delay > 0) {
72
+ await new Promise((resolve) => setTimeout(resolve, this.delay));
73
+ }
74
+ this.logQueueSize();
75
+ }
76
+ }
77
+ this.isProcessing = false;
78
+ }
79
+ /**
80
+ * Log changes to the queue size at significant thresholds.
81
+ */
82
+ logQueueSize() {
83
+ const className = `${this.constructor.name.includes("Publisher") ? "Publisher" : this.constructor.name.includes("Subscriber") ? "Subscriber" : "Unknown"}`;
84
+ if (this.queue.length > 1
85
+ && this.queue.length > this.previousLoggedSize
86
+ && Math.floor(this.queue.length / 100) > Math.floor(this.previousLoggedSize / 100)) {
87
+ logger.info(`${this.instanceName} - ${className} queue size length is ${this.queue.length}.`);
88
+ this.previousLoggedSize = this.queue.length;
89
+ }
90
+ else if (this.queue.length === 0 && this.previousLoggedSize > 0) {
91
+ logger.info(`${this.instanceName} - ${className} queue is empty.`);
92
+ this.previousLoggedSize = 0;
93
+ }
94
+ }
95
+ /**
96
+ * Save the current queue to disk.
97
+ */
98
+ saveQueueToDisk() {
99
+ try {
100
+ const queueData = this.queue.map((item) => this.serializeItem(item));
101
+ const dir = join(this.persistenceFilePath, "..");
102
+ if (!existsSync(dir)) {
103
+ mkdirSync(dir, { recursive: true });
104
+ }
105
+ writeFileSync(this.persistenceFilePath, JSON.stringify(queueData, null, 2));
106
+ logger.debug(`${this.instanceName} - Queue saved to disk.`);
107
+ }
108
+ catch (error) {
109
+ logger.error(`${this.instanceName} - Error saving queue to disk: ${error.message}`);
110
+ }
111
+ }
112
+ /**
113
+ * Load the queue from disk.
114
+ */
115
+ loadQueueFromDisk() {
116
+ try {
117
+ if (existsSync(this.persistenceFilePath)) {
118
+ const queueData = JSON.parse(readFileSync(this.persistenceFilePath, "utf8"));
119
+ this.queue = queueData.map((data) => this.deserializeItem(data));
120
+ logger.info(`${this.instanceName} - Queue loaded from disk.`);
121
+ }
122
+ }
123
+ catch (error) {
124
+ logger.error(`${this.instanceName} - Error loading queue from disk: ${error.message}`);
125
+ }
126
+ }
127
+ }
128
+ /**
129
+ * ThrottledPublisher: manages a queue of outgoing publish requests,
130
+ * sending one message at a time using a provided publish function.
131
+ */
132
+ export class ThrottledPublisher extends ThrottledQueue {
133
+ publishFunction;
134
+ /**
135
+ * @param delay Delay between messages in milliseconds.
136
+ * @param publishFunction Function to perform the actual publish.
137
+ * @param persistToDisk Whether to persist the queue to disk.
138
+ * @param persistenceFilePath File path for queue persistence.
139
+ * @param instanceName Unique instance name for logging.
140
+ */
141
+ constructor(delay, publishFunction, persistToDisk = false, persistenceFilePath = join(basePath, "/publisherQueue/", "throttled-publisher-queue.json"), instanceName, active) {
142
+ super(delay, persistToDisk, instanceName);
143
+ this.persistenceFilePath = persistenceFilePath;
144
+ this.publishFunction = publishFunction;
145
+ this.active = active;
146
+ if (active) {
147
+ logger.info(`${this.instanceName} - Publisher is active.`);
148
+ }
149
+ else {
150
+ logger.info(`${this.instanceName} - Publisher is passive.`);
151
+ }
152
+ }
153
+ /**
154
+ * Enqueue a publish request.
155
+ */
156
+ enqueue(topic, message, id, options) {
157
+ return new Promise((resolve, reject) => {
158
+ this.queue.push({ topic, message, id, options, resolve, reject });
159
+ // Trigger logging after a new message is added.
160
+ this.logQueueSize();
161
+ if (this.persistToDisk) {
162
+ this.saveQueueToDisk();
163
+ }
164
+ if (this.active) {
165
+ this.processQueue();
166
+ }
167
+ });
168
+ }
169
+ computeHashForBatch(messages) {
170
+ const data = JSON.stringify(messages);
171
+ return createHash("sha256").update(data).digest("hex");
172
+ }
173
+ /**
174
+ * Switch the publisher to a passive state and return a snapshot
175
+ */
176
+ becomeActive(snapshot) {
177
+ // If snapshot is empty (batchSize is zero), start processing from the beginning.
178
+ if (snapshot.batchSize === 0 || snapshot.batchSize === undefined || snapshot.referenceHash === undefined) {
179
+ this.active = true;
180
+ logger.info(`${this.instanceName} - Publisher became active.`);
181
+ this.processQueue();
182
+ return;
183
+ }
184
+ const { referenceHash, batchSize } = snapshot;
185
+ let resumeIndex = -1;
186
+ // Use batchSize as the window length.
187
+ for (let i = 0; i <= this.queue.length - batchSize; i++) {
188
+ const currentBatch = this.queue.slice(i, i + batchSize);
189
+ const currentHash = this.computeHashForBatch(currentBatch);
190
+ if (currentHash === referenceHash) {
191
+ resumeIndex = i + batchSize; // resume immediately after the matched batch
192
+ break;
193
+ }
194
+ }
195
+ if (resumeIndex !== -1) {
196
+ // Adjust the queue so that processing resumes after the matching batch.
197
+ this.queue = this.queue.slice(resumeIndex);
198
+ logger.info(`${this.instanceName} - Publisher resumed from the matched snapshot position.`);
199
+ }
200
+ else if (this.queue.length > 0) {
201
+ // Log info message and process the entire queue if no match is found.
202
+ logger.info(`${this.instanceName} - No matching batch found during resume; processing the entire publisher's queue.`);
203
+ }
204
+ this.active = true;
205
+ logger.info(`${this.instanceName} - Publisher became active.`);
206
+ this.processQueue();
207
+ }
208
+ /**
209
+ * Switch the publisher to a passive state and return a snapshot
210
+ */
211
+ async becomePassive(n) {
212
+ this.active = false;
213
+ logger.info(`${this.instanceName} - Publisher became passive.`);
214
+ const batch = this.queue.slice(-n);
215
+ const batchSize = batch.length;
216
+ const referenceHash = this.computeHashForBatch(batch);
217
+ if (batchSize > 0) {
218
+ logger.info(`${this.instanceName} - Publisher batch reference hash: ${referenceHash}, size: ${batchSize}`);
219
+ }
220
+ return { referenceHash, batchSize };
221
+ }
222
+ getState() {
223
+ return this.active;
224
+ }
225
+ /**
226
+ * Process a single publish request.
227
+ */
228
+ async processItem(item) {
229
+ try {
230
+ await this.publishFunction(item.topic, item.message, item.id, item.options);
231
+ item.resolve();
232
+ }
233
+ catch (error) {
234
+ item.reject(error);
235
+ }
236
+ }
237
+ /**
238
+ * Serialize a publish request for persistence.
239
+ */
240
+ serializeItem(item) {
241
+ return {
242
+ topic: item.topic,
243
+ message: item.message,
244
+ id: item.id,
245
+ options: item.options,
246
+ };
247
+ }
248
+ /**
249
+ * Deserialize persisted data into a publish request.
250
+ */
251
+ deserializeItem(data) {
252
+ return {
253
+ topic: data.topic,
254
+ message: data.message,
255
+ id: data.id,
256
+ options: data.options,
257
+ resolve: () => { },
258
+ reject: (err) => logger.error(`${this.instanceName} - Error processing queued publish item: ${err.message}`),
259
+ };
260
+ }
261
+ }
262
+ /**
263
+ * ThrottledSubscriber: manages a queue of incoming messages and processes
264
+ * them one at a time using a provided message handler.
265
+ */
266
+ export class ThrottledSubscriber extends ThrottledQueue {
267
+ messageHandler;
268
+ /**
269
+ * @param delay Delay between processing messages in milliseconds.
270
+ * @param messageHandler Function to process incoming messages.
271
+ * @param persistToDisk Whether to persist the queue to disk.
272
+ * @param persistenceFilePath File path for queue persistence.
273
+ * @param instanceName Unique instance name for logging.
274
+ */
275
+ constructor(delay, messageHandler, persistToDisk = false, persistenceFilePath = join(basePath, "/subscriberQueue/", "throttled-subscriber-queue.json"), instanceName, active) {
276
+ super(delay, persistToDisk, instanceName);
277
+ this.persistenceFilePath = persistenceFilePath;
278
+ this.messageHandler = messageHandler;
279
+ this.active = active;
280
+ if (active) {
281
+ logger.info(`${this.instanceName} - Subscriber is active.`);
282
+ }
283
+ else {
284
+ logger.info(`${this.instanceName} - Subscriber is passive.`);
285
+ }
286
+ }
287
+ /**
288
+ * Enqueue subscribe messages for processing.
289
+ */
290
+ enqueue(topic, message) {
291
+ this.queue.push({ topic, message, timestamp: Date.now() });
292
+ // Trigger logging after a new message is added.
293
+ this.logQueueSize();
294
+ if (this.persistToDisk) {
295
+ this.saveQueueToDisk();
296
+ }
297
+ if (this.active) {
298
+ this.processQueue();
299
+ }
300
+ }
301
+ /**
302
+ * Process a single subscribe message.
303
+ */
304
+ async processItem(item) {
305
+ await this.messageHandler(item.topic, item.message);
306
+ }
307
+ /**
308
+ * Serialize a subscribe message for persistence.
309
+ */
310
+ serializeItem(item) {
311
+ return {
312
+ message: item.message,
313
+ };
314
+ }
315
+ /**
316
+ * Deserialize persisted data into a subscribe message.
317
+ */
318
+ deserializeItem(data) {
319
+ return {
320
+ topic: data.topic,
321
+ message: data.message,
322
+ timestamp: data.timestamp,
323
+ };
324
+ }
325
+ /**
326
+ * Get the current state of the subscriber (active or passive).
327
+ */
328
+ getState() {
329
+ return this.active;
330
+ }
331
+ /**
332
+ * Computes a SHA‑256 hash for a given batch of subscriber items.
333
+ */
334
+ computeHashForBatch(messages) {
335
+ const data = JSON.stringify(messages.map((item) => this.serializeItem(item)));
336
+ return createHash("sha256").update(data).digest("hex");
337
+ }
338
+ /**
339
+ * Switch the subscriber to a passive state and return a snapshot.
340
+ */
341
+ async becomePassive(n) {
342
+ this.active = false;
343
+ logger.info(`${this.instanceName} - Subscriber is passive.`);
344
+ const batch = this.lastProcessedItems.slice(-n);
345
+ const batchSize = batch.length;
346
+ const referenceHash = this.computeHashForBatch(batch);
347
+ if (batchSize > 0) {
348
+ logger.info(`${this.instanceName} - Subscriber batch reference hash: ${referenceHash}, size: ${batchSize}`);
349
+ }
350
+ return { referenceHash, batchSize };
351
+ }
352
+ /**
353
+ * Switch the subscriber to an active state and resume processing.
354
+ */
355
+ becomeActive(snapshot) {
356
+ // If snapshot is empty (batchSize is zero), start processing from the beginning.
357
+ if (snapshot.batchSize === 0 || snapshot.batchSize === undefined || snapshot.referenceHash === undefined) {
358
+ this.active = true;
359
+ logger.info(`${this.instanceName} - Subscriber became active.`);
360
+ this.processQueue();
361
+ return;
362
+ }
363
+ const { referenceHash, batchSize } = snapshot;
364
+ let resumeIndex = -1;
365
+ // Use batchSize as the window length.
366
+ for (let i = 0; i <= this.queue.length - batchSize; i++) {
367
+ const currentBatch = this.queue.slice(i, i + batchSize);
368
+ const currentHash = this.computeHashForBatch(currentBatch);
369
+ if (currentHash === referenceHash) {
370
+ resumeIndex = i + batchSize; // resume immediately after the matched batch
371
+ break;
372
+ }
373
+ }
374
+ if (resumeIndex !== -1) {
375
+ // Adjust the queue so that processing resumes after the matching batch.
376
+ const queueSlice = this.queue.slice(resumeIndex);
377
+ this.queue = queueSlice;
378
+ logger.info(`${this.instanceName} - Subscriber resumed from the matched snapshot position.`);
379
+ }
380
+ else if (this.queue.length > 0) {
381
+ // Log info message and process the entire queue if no match is found.
382
+ logger.info(`${this.instanceName} - No matching batch found during resume; processing the entire subscriber's queue.`);
383
+ }
384
+ this.active = true;
385
+ logger.info(`${this.instanceName} - Subscriber became active.`);
386
+ this.processQueue();
387
+ }
388
+ }
@@ -0,0 +1,107 @@
1
+ import { IMqttMessage, IUnsPacket, IUnsParameters, UnsEvents } from "../uns/uns-interfaces.js";
2
+ import UnsProxy from "../uns/uns-proxy.js";
3
+ export declare enum MessageMode {
4
+ Raw = "raw",// Send only the original message
5
+ Delta = "delta",// Send only the delta message
6
+ Both = "both"
7
+ }
8
+ export default class UnsMqttProxy extends UnsProxy {
9
+ private lastValues;
10
+ private worker;
11
+ private pendingEnqueues;
12
+ private unsParameters;
13
+ protected processStatusTopic: string;
14
+ instanceName: string;
15
+ private currentSequenceId;
16
+ private topicBuilder;
17
+ constructor(mqttHost: string, processName: string, instanceName: string, unsParameters?: IUnsParameters, publisherActive?: boolean, subscriberActive?: boolean);
18
+ /**
19
+ * Starts a worker thread to process the throttled publish queue.
20
+ */
21
+ private startQueueWorker;
22
+ /**
23
+ * Enqueues a message to the worker queue.
24
+ *
25
+ * @param topic - The topic to which the message belongs.
26
+ * @param message - The message to be enqueued.
27
+ * @param options - Optional publish options.
28
+ * @returns A promise that resolves when the message is successfully enqueued.
29
+ */
30
+ private enqueueMessageToWorkerQueue;
31
+ /**
32
+ * Sets the publisher active state.
33
+ *
34
+ * @param batchSize - Optional batch size.
35
+ * @param referenceHash - Optional reference hash.
36
+ */
37
+ setPublisherActive(batchSize?: number, referenceHash?: string): void;
38
+ /**
39
+ * Sets the publisher to passive mode.
40
+ * @returns A promise that resolves when the publisher is set to passive.
41
+ */
42
+ setPublisherPassive(): Promise<UnsEvents["mqttWorker"]>;
43
+ /**
44
+ * Sets the subscriber active state.
45
+ *
46
+ * @param batchSize - Optional batch size.
47
+ * @param referenceHash - Optional reference hash.
48
+ */
49
+ setSubscriberActive(batchSize?: number, referenceHash?: string): void;
50
+ /**
51
+ * Sets the subscriber to passive mode.
52
+ * @returns A promise that resolves when the subscriber is set to passive.
53
+ */
54
+ setSubscriberPassive(): Promise<UnsEvents["mqttWorker"]>;
55
+ /**
56
+ * Sets the subscriber to passive mode and allows the publisher to run
57
+ * until the queue is empty (all messages are processed).
58
+ */
59
+ setSubscriberPassiveAndDrainQueue(): Promise<UnsEvents["mqttWorker"]>;
60
+ /**
61
+ * Processes and publishes MQTT messages based on the selected message mode.
62
+ *
63
+ * @param mqttMessage - The MQTT message object.
64
+ * @param mode - The message mode (Raw, Delta, or Both).
65
+ */
66
+ publishMqttMessage(mqttMessage: IMqttMessage | null, mode?: MessageMode): void;
67
+ /**
68
+ * Publishes a message to a specified topic.
69
+ *
70
+ * @param topic - The MQTT topic.
71
+ * @param message - The message to publish.
72
+ * @returns A promise that resolves when enqueued.
73
+ */
74
+ publishMessage(topic: string, message: string): Promise<void>;
75
+ /**
76
+ * Parses an MQTT packet from a JSON string.
77
+ *
78
+ * @param mqttPacket - The MQTT packet string.
79
+ * @returns A parsed IUnsPacket object or null.
80
+ */
81
+ parseMqttPacket(mqttPacket: string): IUnsPacket | null;
82
+ /**
83
+ * Subscribes asynchronously to one or more topics.
84
+ *
85
+ * @param topics - A topic or list of topics.
86
+ */
87
+ subscribeAsync(topics: string | string[]): void;
88
+ /**
89
+ * Unsubscribes asynchronously from the given topics.
90
+ *
91
+ * @param topics - A list of topics.
92
+ */
93
+ unsubscribeAsync(topics: string[]): void;
94
+ /**
95
+ * Processes and enqueues a message to the worker queue, including handling
96
+ * sequencing, value differences, and tracking of unique topics.
97
+ *
98
+ * @param msg - The MQTT message to process.
99
+ * @param time - The timestamp.
100
+ * @param valueIsCumulative - Whether the value is cumulative.
101
+ */
102
+ private processAndEnqueueMessage;
103
+ /**
104
+ * Stops the UnsProxy instance and cleans up resources.
105
+ */
106
+ stop(): Promise<void>;
107
+ }