@uns-kit/core 1.0.25 → 1.0.27
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/dist/config/app-config.d.ts +99 -29
- package/dist/config/app-config.d.ts.map +1 -1
- package/dist/config/app-config.js.map +1 -1
- package/dist/tools/generate-config-schema.js +17 -1
- package/dist/tools/generate-config-schema.js.map +1 -1
- package/dist/uns/handover-manager.d.ts +5 -1
- package/dist/uns/handover-manager.d.ts.map +1 -1
- package/dist/uns/handover-manager.js +49 -19
- package/dist/uns/handover-manager.js.map +1 -1
- package/dist/uns/process-config.d.ts +0 -1
- package/dist/uns/process-config.d.ts.map +1 -1
- package/dist/uns/process-config.js +0 -2
- package/dist/uns/process-config.js.map +1 -1
- package/dist/uns/status-monitor.d.ts +6 -1
- package/dist/uns/status-monitor.d.ts.map +1 -1
- package/dist/uns/status-monitor.js +15 -2
- package/dist/uns/status-monitor.js.map +1 -1
- package/dist/uns/uns-interfaces.d.ts +37 -1
- package/dist/uns/uns-interfaces.d.ts.map +1 -1
- package/dist/uns/uns-interfaces.js.map +1 -1
- package/dist/uns/uns-proxy-process.d.ts +2 -1
- package/dist/uns/uns-proxy-process.d.ts.map +1 -1
- package/dist/uns/uns-proxy-process.js +32 -5
- package/dist/uns/uns-proxy-process.js.map +1 -1
- package/dist/uns-config/uns-core-schema.d.ts +1802 -89
- package/dist/uns-config/uns-core-schema.d.ts.map +1 -1
- package/dist/uns-config/uns-core-schema.js +42 -3
- package/dist/uns-config/uns-core-schema.js.map +1 -1
- package/dist/uns-grpc/uns-gateway-server.d.ts +2 -0
- package/dist/uns-grpc/uns-gateway-server.d.ts.map +1 -1
- package/dist/uns-grpc/uns-gateway-server.js +88 -10
- package/dist/uns-grpc/uns-gateway-server.js.map +1 -1
- package/dist/uns-mqtt/mqtt-interfaces.d.ts +33 -1
- package/dist/uns-mqtt/mqtt-interfaces.d.ts.map +1 -1
- package/dist/uns-mqtt/mqtt-interfaces.js.map +1 -1
- package/dist/uns-mqtt/mqtt-proxy.d.ts +3 -0
- package/dist/uns-mqtt/mqtt-proxy.d.ts.map +1 -1
- package/dist/uns-mqtt/mqtt-proxy.js +86 -4
- package/dist/uns-mqtt/mqtt-proxy.js.map +1 -1
- package/dist/uns-mqtt/uns-mqtt-proxy.d.ts.map +1 -1
- package/dist/uns-mqtt/uns-mqtt-proxy.js +17 -0
- package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export class StatusMonitor {
|
|
|
8
8
|
activeSupplier;
|
|
9
9
|
memoryIntervalMs;
|
|
10
10
|
statusIntervalMs;
|
|
11
|
+
processIdentity;
|
|
11
12
|
memoryInterval;
|
|
12
13
|
statusInterval;
|
|
13
14
|
/**
|
|
@@ -16,13 +17,15 @@ export class StatusMonitor {
|
|
|
16
17
|
* @param activeSupplier A function returning the current active state (boolean).
|
|
17
18
|
* @param memoryIntervalMs Interval in milliseconds for publishing memory status.
|
|
18
19
|
* @param statusIntervalMs Interval in milliseconds for publishing active status.
|
|
20
|
+
* @param processIdentity Optional identity to attach to active status messages.
|
|
19
21
|
*/
|
|
20
|
-
constructor(mqttProxy, processStatusTopic, activeSupplier, memoryIntervalMs, statusIntervalMs) {
|
|
22
|
+
constructor(mqttProxy, processStatusTopic, activeSupplier, memoryIntervalMs, statusIntervalMs, processIdentity) {
|
|
21
23
|
this.mqttProxy = mqttProxy;
|
|
22
24
|
this.processStatusTopic = processStatusTopic;
|
|
23
25
|
this.activeSupplier = activeSupplier;
|
|
24
26
|
this.memoryIntervalMs = memoryIntervalMs;
|
|
25
27
|
this.statusIntervalMs = statusIntervalMs;
|
|
28
|
+
this.processIdentity = processIdentity;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Starts the periodic memory and status updates.
|
|
@@ -73,7 +76,17 @@ export class StatusMonitor {
|
|
|
73
76
|
data: { time, value: Number(this.activeSupplier()) },
|
|
74
77
|
};
|
|
75
78
|
const packet = await UnsPacket.unsPacketFromUnsMessage(activeMessage);
|
|
76
|
-
this.mqttProxy.publish(`${this.processStatusTopic}active`, JSON.stringify(packet), {
|
|
79
|
+
this.mqttProxy.publish(`${this.processStatusTopic}active`, JSON.stringify(packet), {
|
|
80
|
+
retain: false,
|
|
81
|
+
properties: this.processIdentity
|
|
82
|
+
? {
|
|
83
|
+
userProperties: {
|
|
84
|
+
processName: this.processIdentity.processName,
|
|
85
|
+
processId: this.processIdentity.processId,
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
});
|
|
77
90
|
}
|
|
78
91
|
catch (error) {
|
|
79
92
|
logger.error(`StatusMonitor - Error publishing status updates: ${error.message}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"status-monitor.js","sourceRoot":"","sources":["../../src/uns/status-monitor.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,aAAa;
|
|
1
|
+
{"version":3,"file":"status-monitor.js","sourceRoot":"","sources":["../../src/uns/status-monitor.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAG5C,MAAM,OAAO,aAAa;IAad;IACA;IACA;IACA;IACA;IACA;IAjBF,cAAc,CAAkB;IAChC,cAAc,CAAkB;IAExC;;;;;;;OAOG;IACH,YACU,SAAoB,EACpB,kBAA0B,EAC1B,cAA6B,EAC7B,gBAAwB,EACxB,gBAAwB,EACxB,eAA4D;QAL5D,cAAS,GAAT,SAAS,CAAW;QACpB,uBAAkB,GAA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;4BACd,WAAW,EAAE,IAAI,CAAC,eAAe,CAAC,WAAW;4BAC7C,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,SAAS;yBAC1C;qBACF;oBACD,CAAC,CAAC,SAAS;aACd,CACF,CAAC;QACJ,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,MAAM,CAAC,KAAK,CAAC,oDAAoD,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;QACpF,CAAC;IACH,CAAC;CACF","sourcesContent":["// status-monitor.ts\nimport logger from \"../logger.js\";\nimport { IUnsMessage } from \"./uns-interfaces.js\";\nimport { DataSizeMeasurements } from \"./uns-measurements.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\nimport type MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\n\nexport class StatusMonitor {\n private memoryInterval?: NodeJS.Timeout;\n private statusInterval?: NodeJS.Timeout;\n\n /**\n * @param mqttProxy The MQTT proxy used to publish messages.\n * @param processStatusTopic The base topic for the process (ending with a slash).\n * @param activeSupplier A function returning the current active state (boolean).\n * @param memoryIntervalMs Interval in milliseconds for publishing memory status.\n * @param statusIntervalMs Interval in milliseconds for publishing active status.\n * @param processIdentity Optional identity to attach to active status messages.\n */\n constructor(\n private mqttProxy: MqttProxy,\n private processStatusTopic: string,\n private activeSupplier: () => boolean,\n private memoryIntervalMs: number,\n private statusIntervalMs: number,\n private processIdentity?: { processName: string; processId: string },\n ) {}\n\n /**\n * Starts the periodic memory and status updates.\n */\n public start(): void {\n this.memoryInterval = setInterval(() => this.publishMemoryUpdates(), this.memoryIntervalMs);\n this.statusInterval = setInterval(() => this.publishStatusUpdates(), this.statusIntervalMs);\n }\n\n /**\n * Stops the periodic updates.\n */\n public stop(): void {\n if (this.memoryInterval) {\n clearInterval(this.memoryInterval);\n this.memoryInterval = undefined;\n }\n if (this.statusInterval) {\n clearInterval(this.statusInterval);\n this.statusInterval = undefined;\n }\n }\n\n /**\n * Publishes memory usage updates via MQTT.\n * In this example, only the `heapUsed` metric is published.\n */\n private async publishMemoryUpdates(): Promise<void> {\n try {\n const time = UnsPacket.formatToISO8601(new Date());\n const memoryUsage = process.memoryUsage();\n const heapUsedMessage: IUnsMessage = { data: { time, value: Math.round(memoryUsage.heapUsed/1048576), uom: DataSizeMeasurements.MegaByte } };\n let packet = await UnsPacket.unsPacketFromUnsMessage(heapUsedMessage);\n this.mqttProxy.publish(\n `${this.processStatusTopic}heap-used`,\n JSON.stringify(packet)\n );\n\n const heapTotalMessage: IUnsMessage = { data: { time, value: Math.round(memoryUsage.heapTotal/1048576), uom: DataSizeMeasurements.MegaByte } };\n packet = await UnsPacket.unsPacketFromUnsMessage(heapTotalMessage);\n this.mqttProxy.publish(\n `${this.processStatusTopic}heap-total`,\n JSON.stringify(packet)\n );\n\n } catch (error: any) {\n logger.error(`StatusMonitor - Error publishing memory updates: ${error.message}`);\n }\n }\n\n /**\n * Publishes the process active status via MQTT.\n */\n private async publishStatusUpdates(): Promise<void> {\n try {\n const time = UnsPacket.formatToISO8601(new Date());\n const activeMessage: IUnsMessage = {\n data: { time, value: Number(this.activeSupplier()) },\n };\n const packet = await UnsPacket.unsPacketFromUnsMessage(activeMessage);\n this.mqttProxy.publish(\n `${this.processStatusTopic}active`,\n JSON.stringify(packet),\n {\n retain: false,\n properties: this.processIdentity\n ? {\n userProperties: {\n processName: this.processIdentity.processName,\n processId: this.processIdentity.processId,\n },\n }\n : undefined,\n },\n );\n } catch (error: any) {\n logger.error(`StatusMonitor - Error publishing status updates: ${error.message}`);\n }\n }\n}\n"]}
|
|
@@ -3,6 +3,7 @@ import { MeasurementUnit } from "./uns-measurements.js";
|
|
|
3
3
|
import { UnsTags } from "./uns-tags.js";
|
|
4
4
|
import type { UnsObjectId, UnsObjectType } from "./uns-object.js";
|
|
5
5
|
import type { UnsAsset } from "./uns-asset.js";
|
|
6
|
+
import type { IMqttConnectProperties, IMqttServerConfig, MqttProtocol } from "../uns-mqtt/mqtt-interfaces.js";
|
|
6
7
|
import { UnsTopics } from "./uns-topics.js";
|
|
7
8
|
import { type KnownUnsAttributeName } from "./uns-attributes.js";
|
|
8
9
|
export type ISO8601 = `${number}-${string}-${string}T${string}:${string}:${string}.${string}Z`;
|
|
@@ -20,13 +21,48 @@ export interface IUnsParameters {
|
|
|
20
21
|
publishThrottlingDelay?: number;
|
|
21
22
|
subscribeThrottlingDelay?: number;
|
|
22
23
|
rejectUnauthorized?: boolean;
|
|
24
|
+
clientId?: string;
|
|
25
|
+
hosts?: string[];
|
|
26
|
+
servers?: IMqttServerConfig[];
|
|
27
|
+
port?: number;
|
|
28
|
+
protocol?: MqttProtocol;
|
|
29
|
+
keepalive?: number;
|
|
30
|
+
clean?: boolean;
|
|
31
|
+
connectTimeout?: number;
|
|
32
|
+
reconnectPeriod?: number;
|
|
33
|
+
reconnectOnConnackError?: boolean;
|
|
34
|
+
resubscribe?: boolean;
|
|
35
|
+
queueQoSZero?: boolean;
|
|
36
|
+
properties?: IMqttConnectProperties;
|
|
37
|
+
ca?: string;
|
|
38
|
+
cert?: string;
|
|
39
|
+
key?: string;
|
|
40
|
+
servername?: string;
|
|
23
41
|
}
|
|
24
42
|
export interface IUnsProcessParameters {
|
|
25
|
-
processName
|
|
43
|
+
processName: string;
|
|
26
44
|
mqttSubToTopics?: string | string[];
|
|
27
45
|
username?: string;
|
|
28
46
|
password?: string;
|
|
29
47
|
mqttSSL?: boolean;
|
|
48
|
+
clientId?: string;
|
|
49
|
+
hosts?: string[];
|
|
50
|
+
servers?: IMqttServerConfig[];
|
|
51
|
+
port?: number;
|
|
52
|
+
protocol?: MqttProtocol;
|
|
53
|
+
keepalive?: number;
|
|
54
|
+
clean?: boolean;
|
|
55
|
+
connectTimeout?: number;
|
|
56
|
+
reconnectPeriod?: number;
|
|
57
|
+
reconnectOnConnackError?: boolean;
|
|
58
|
+
resubscribe?: boolean;
|
|
59
|
+
queueQoSZero?: boolean;
|
|
60
|
+
rejectUnauthorized?: boolean;
|
|
61
|
+
properties?: IMqttConnectProperties;
|
|
62
|
+
ca?: string;
|
|
63
|
+
cert?: string;
|
|
64
|
+
key?: string;
|
|
65
|
+
servername?: string;
|
|
30
66
|
}
|
|
31
67
|
export interface UnsEvents {
|
|
32
68
|
input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uns-interfaces.d.ts","sourceRoot":"","sources":["../../src/uns/uns-interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAsB,KAAK,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAErF,MAAM,MAAM,OAAO,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,GAAG,CAAC;AAC/F,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,OAAO,CAG7D;AAED,MAAM,MAAM,YAAY,GAAG,qBAAqB,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;AAEjE,eAAO,MAAM,UAAU,UAAuB,CAAC;AAC/C,MAAM,MAAM,eAAe,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AACxD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC;AAGxC,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,SAAS,GACT,QAAQ,GACR,MAA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;KAC9C,CAAC;CACH;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,CAAC,EAAE,aAAa,EAAE,CAAC;CAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uns-interfaces.js","sourceRoot":"","sources":["../../src/uns/uns-interfaces.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uns-interfaces.js","sourceRoot":"","sources":["../../src/uns/uns-interfaces.ts"],"names":[],"mappings":"AAUA,MAAM,UAAU,aAAa,CAAC,KAAa;IACzC,MAAM,YAAY,GAAG,+CAA+C,CAAC;IACrE,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClC,CAAC;AAID,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC","sourcesContent":["import { UnsAttributeType } from \"../graphql/schema.js\";\nimport { MeasurementUnit } from \"./uns-measurements.js\";\nimport { UnsTags } from \"./uns-tags.js\";\nimport type { UnsObjectId, UnsObjectType } from \"./uns-object.js\";\nimport type { UnsAsset } from \"./uns-asset.js\";\nimport type { IMqttConnectProperties, IMqttServerConfig, MqttProtocol } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport { UnsTopics } from \"./uns-topics.js\";\nimport { knownUnsAttributes, type KnownUnsAttributeName } from \"./uns-attributes.js\";\n\nexport type ISO8601 = `${number}-${string}-${string}T${string}:${string}:${string}.${string}Z`;\nexport function isIOS8601Type(value: string): value is ISO8601 {\n const iso8601Regex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$/;\n return iso8601Regex.test(value);\n}\n// Known attribute names (with IntelliSense) while still allowing arbitrary strings.\nexport type UnsAttribute = KnownUnsAttributeName | (string & {});\n\nexport const valueTypes = [\"string\", \"number\"];\nexport type ValueTypeString = typeof valueTypes[number];\nexport type ValueType = string | number;\n\n// Supported QuestDB column types for UNS tables.\nexport type QuestDbType =\n | \"boolean\"\n | \"ipv4\"\n | \"byte\"\n | \"short\"\n | \"char\"\n | \"int\"\n | \"float\"\n | \"symbol\"\n | \"varchar\"\n | \"string\"\n | \"long\"\n | \"date\"\n | \"timestamp\"\n | \"timestamp_ns\"\n | \"double\"\n | \"uuid\"\n | \"binary\"\n | \"long256\"\n | `geohash(${number}${\"b\" | \"c\"})`\n | `decimal(${number},${number})`\n | `array<${string}>`;\n\nexport interface IUnsParameters {\n mqttSubToTopics?: string | string[];\n username?: string;\n password?: string;\n mqttSSL?: boolean;\n publishThrottlingDelay?: number; // Delay in milliseconds; default is 1ms\n subscribeThrottlingDelay?: number; // Delay in milliseconds; default is 1ms\n rejectUnauthorized?: boolean;\n clientId?: string;\n hosts?: string[];\n servers?: IMqttServerConfig[];\n port?: number;\n protocol?: MqttProtocol;\n keepalive?: number;\n clean?: boolean;\n connectTimeout?: number;\n reconnectPeriod?: number;\n reconnectOnConnackError?: boolean;\n resubscribe?: boolean;\n queueQoSZero?: boolean;\n properties?: IMqttConnectProperties;\n ca?: string;\n cert?: string;\n key?: string;\n servername?: string;\n}\n\nexport interface IUnsProcessParameters {\n processName: string;\n mqttSubToTopics?: string | string[];\n username?: string;\n password?: string;\n mqttSSL?: boolean;\n clientId?: string;\n hosts?: string[];\n servers?: IMqttServerConfig[];\n port?: number;\n protocol?: MqttProtocol;\n keepalive?: number;\n clean?: boolean;\n connectTimeout?: number;\n reconnectPeriod?: number;\n reconnectOnConnackError?: boolean;\n resubscribe?: boolean;\n queueQoSZero?: boolean;\n rejectUnauthorized?: boolean;\n properties?: IMqttConnectProperties;\n ca?: string;\n cert?: string;\n key?: string;\n servername?: string;\n}\n\nexport interface UnsEvents {\n // Emitters in MqttProxy, UnsMqttProxy\n input: { topic: string; message: string, packet: any };\n mqttProxyStatus: { event: string, value: number, uom: MeasurementUnit, statusTopic: string };\n \n // Emitters in MqttProxy\n error: { code: number; message: string };\n \n // Emitters in UnsMqttProxy\n mqttWorker: { command: string, instanceName: string; batchSize: number, referenceHash: string };\n\n // Emitter in UnsCronProxy\n cronEvent: {};\n\n // Emitters in UnsApiProxy\n apiGetEvent: {req: any, res: any};\n\n // Emitters in UnsProxy\n unsProxyProducedTopics: { producedTopics: ITopicObject[], statusTopic: string };\n\n // Emitters in UnsProxy\n unsProxyProducedApiEndpoints: { producedApiEndpoints: IApiObject[], statusTopic: string };\n}\n\nexport interface IUnsExtendedData extends IUnsData {\n valueType: ValueTypeString;\n}\n\nexport interface IUnsData {\n time: ISO8601;\n value: ValueType;\n dataGroup?: string;\n uom?: MeasurementUnit;\n foreignEventKey?: string;\n}\n\nexport interface IUnsTableColumn {\n name: string;\n type: QuestDbType;\n value: string | number | null;\n uom?: MeasurementUnit;\n}\n\nexport interface IUnsTable {\n time: ISO8601;\n dataGroup?: string;\n columns: IUnsTableColumn[];\n}\n\nexport interface IMqttMessage {\n topic: UnsTopics;\n attribute: UnsAttribute;\n asset: UnsAsset;\n assetDescription?: string;\n objectType: UnsObjectType;\n objectTypeDescription?: string;\n objectId: UnsObjectId;\n description?: string;\n tags?: UnsTags[];\n packet: IUnsPacket;\n attributeNeedsPersistence?: boolean | null;\n}\n\nexport interface IMqttAttributeMessage {\n attribute: UnsAttribute;\n description?: string;\n tags?: UnsTags[];\n attributeNeedsPersistence?: boolean | null;\n}\n\ntype AttributePayload =\n | { message: IUnsMessage; data?: never; table?: never; createdAt?: never; expiresAt?: never }\n | { message?: never; data: IUnsData; table?: never; createdAt?: ISO8601; expiresAt?: ISO8601 }\n | { message?: never; data?: never; table: IUnsTable; createdAt?: ISO8601; expiresAt?: ISO8601 };\n\nexport type IMqttAttributeEntry = IMqttAttributeMessage & AttributePayload;\n\nexport interface IMqttMultiMessage {\n topic: UnsTopics;\n asset: UnsAsset;\n assetDescription?: string;\n objectType: UnsObjectType;\n objectTypeDescription?: string;\n objectId: UnsObjectId;\n attributes: IMqttAttributeEntry[];\n}\n\n// This interface represents a packet for a UNS system\nexport interface IUnsPacket {\n // The message object of the packet\n message: IUnsExtendedMessage;\n \n // The HMAC signature of the message\n messageSignature?: string;\n\n // Automatically calculated interval between two packets in ms\n interval?: number;\n\n // Current library version\n readonly version: string;\n\n // Autogenerated sequence number\n sequenceId?: number;\n}\n\nexport interface IUnsPackatParameters {\n\n}\n\nexport interface IUnsMessage {\n data?: IUnsData;\n table?: IUnsTable;\n expiresAt?: ISO8601;\n createdAt?: ISO8601;\n}\n\nexport interface IUnsExtendedMessage extends IUnsMessage {\n data?: IUnsExtendedData;\n}\n\nexport interface ITopicObject {\n timestamp: string;\n attribute:string;\n attributeType: UnsAttributeType;\n topic:string;\n description:string;\n dataGroup:string;\n tags:string[] | null;\n attributeNeedsPersistence: boolean | null;\n asset: UnsAsset;\n assetDescription?: string;\n objectType: UnsObjectType;\n objectTypeDescription?: string;\n objectId: UnsObjectId;\n}\n\n// API Interfaces below\nexport interface IApiObject {\n timestamp: string;\n attribute:string;\n topic:string;\n attributeType: UnsAttributeType;\n apiDescription?: string; // Optional description for the API endpoint\n apiHost: string; // Hostname of the service\n apiEndpoint: string; // API endpoint for virtual topics\n apiSwaggerEndpoint: string; // Swagger endpoint for API documentation\n apiMethod: \"GET\" | \"POST\" | \"PUT\" | \"DELETE\"; // HTTP method for API endpoint\n apiQueryParams: QueryParamDef[]; // query parameters for the API endpoint\n asset: UnsAsset;\n objectType: UnsObjectType;\n objectId: UnsObjectId;\n}\n\nexport interface QueryParamDef {\n name: string;\n type: \"string\" | \"number\" | \"boolean\";\n required?: boolean;\n description?: string;\n}\n\nexport interface IApiProxyOptions {\n jwtSecret?: string;\n jwks?: {\n wellKnownJwksUrl: string;\n activeKidUrl?: string;\n cacheTtlMs?: number;\n algorithms?: (\"RS256\" | \"RS384\" | \"RS512\")[];\n };\n}\n\nexport interface IGetEndpointOptions {\n apiDescription?: string;\n tags?: string[];\n queryParams?: QueryParamDef[];\n}\n"]}
|
|
@@ -19,6 +19,7 @@ declare class UnsProxyProcess {
|
|
|
19
19
|
private active;
|
|
20
20
|
private processStatusTopic;
|
|
21
21
|
private processName;
|
|
22
|
+
private processId;
|
|
22
23
|
private unsMqttProxies;
|
|
23
24
|
private unsApiProxies;
|
|
24
25
|
private unsTemporalProxies;
|
|
@@ -33,7 +34,7 @@ declare class UnsProxyProcess {
|
|
|
33
34
|
private static applyPlugin;
|
|
34
35
|
private static applyAll;
|
|
35
36
|
private mqttInputHandler;
|
|
36
|
-
constructor(mqttHost: string, unsProxyProcessParameters
|
|
37
|
+
constructor(mqttHost: string, unsProxyProcessParameters: IUnsProcessParameters);
|
|
37
38
|
/**
|
|
38
39
|
* Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.
|
|
39
40
|
* Determines handover and force start modes based on process arguments.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uns-proxy-process.d.ts","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"uns-proxy-process.d.ts","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAEA,OAAO,EAAe,cAAc,EAAE,qBAAqB,EAAa,MAAM,qBAAqB,CAAC;AAGpG,OAAO,YAAY,MAAM,+BAA+B,CAAC;AAUzD;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG,CAAC,IAAI,EAAE,eAAe,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,OAAO,CAAC;AAEjG,MAAM,MAAM,4BAA4B,GAAG,MAAM,CAAC,MAAM,EAAE,2BAA2B,CAAC,CAAC;AAEvF,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,OAAO,EAAE,4BAA4B,GAAG,IAAI,CAAC;IACpD,eAAe,EAAE,OAAO,eAAe,CAAC;CACzC;AAED,MAAM,MAAM,qBAAqB,GAAG,CAAC,GAAG,EAAE,w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ytes } from "crypto";
|
|
2
3
|
import MqttProxy from "../uns-mqtt/mqtt-proxy.js";
|
|
3
4
|
import UnsMqttProxy from "../uns-mqtt/uns-mqtt-proxy.js";
|
|
4
5
|
import { HandoverManager } from "./handover-manager.js";
|
|
5
6
|
// Import configuration and initialization modules.
|
|
6
7
|
import { PACKAGE_INFO, MQTT_UPDATE_INTERVAL } from "./process-config.js";
|
|
7
|
-
import { getProcessName } from "./process-name-service.js";
|
|
8
8
|
import { MqttTopicBuilder } from "../uns-mqtt/mqtt-topic-builder.js";
|
|
9
9
|
import { StatusMonitor } from "./status-monitor.js";
|
|
10
10
|
import { UnsPacket } from "./uns-packet.js";
|
|
@@ -12,6 +12,7 @@ class UnsProxyProcess {
|
|
|
12
12
|
active = false;
|
|
13
13
|
processStatusTopic;
|
|
14
14
|
processName;
|
|
15
|
+
processId;
|
|
15
16
|
unsMqttProxies;
|
|
16
17
|
unsApiProxies;
|
|
17
18
|
unsTemporalProxies;
|
|
@@ -69,7 +70,11 @@ class UnsProxyProcess {
|
|
|
69
70
|
this.unsMqttProxies = [];
|
|
70
71
|
this.unsApiProxies = [];
|
|
71
72
|
this.unsTemporalProxies = [];
|
|
72
|
-
|
|
73
|
+
if (!unsProxyProcessParameters?.processName) {
|
|
74
|
+
throw new Error("UnsProxyProcess requires a processName in configuration.");
|
|
75
|
+
}
|
|
76
|
+
this.processName = unsProxyProcessParameters.processName;
|
|
77
|
+
this.processId = randomBytes(16).toString("hex");
|
|
73
78
|
const { name: packageName, version } = PACKAGE_INFO;
|
|
74
79
|
// Instantiate the topic builder.
|
|
75
80
|
const topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);
|
|
@@ -89,12 +94,30 @@ class UnsProxyProcess {
|
|
|
89
94
|
password: unsProxyProcessParameters?.password ?? "",
|
|
90
95
|
mqttSSL: unsProxyProcessParameters?.mqttSSL ?? false,
|
|
91
96
|
statusTopic: this.processStatusTopic,
|
|
97
|
+
clientId: unsProxyProcessParameters?.clientId ?? `${this.processName}-${this.processId}`,
|
|
98
|
+
hosts: unsProxyProcessParameters?.hosts,
|
|
99
|
+
servers: unsProxyProcessParameters?.servers,
|
|
100
|
+
port: unsProxyProcessParameters?.port,
|
|
101
|
+
protocol: unsProxyProcessParameters?.protocol,
|
|
102
|
+
keepalive: unsProxyProcessParameters?.keepalive,
|
|
103
|
+
clean: unsProxyProcessParameters?.clean,
|
|
104
|
+
connectTimeout: unsProxyProcessParameters?.connectTimeout,
|
|
105
|
+
reconnectPeriod: unsProxyProcessParameters?.reconnectPeriod,
|
|
106
|
+
reconnectOnConnackError: unsProxyProcessParameters?.reconnectOnConnackError,
|
|
107
|
+
resubscribe: unsProxyProcessParameters?.resubscribe,
|
|
108
|
+
queueQoSZero: unsProxyProcessParameters?.queueQoSZero,
|
|
109
|
+
rejectUnauthorized: unsProxyProcessParameters?.rejectUnauthorized ?? false,
|
|
110
|
+
properties: unsProxyProcessParameters?.properties,
|
|
111
|
+
ca: unsProxyProcessParameters?.ca,
|
|
112
|
+
cert: unsProxyProcessParameters?.cert,
|
|
113
|
+
key: unsProxyProcessParameters?.key,
|
|
114
|
+
servername: unsProxyProcessParameters?.servername,
|
|
92
115
|
};
|
|
93
116
|
// Initialize MQTT proxy and start connection.
|
|
94
117
|
this.processMqttProxy = new MqttProxy(mqttHost, this.processName, mqttParameters);
|
|
95
118
|
this.processMqttProxy.start();
|
|
96
119
|
// Instantiate and start the StatusMonitor for memory and status updates.
|
|
97
|
-
this.statusMonitor = new StatusMonitor(this.processMqttProxy, this.processStatusTopic, () => this.active, MQTT_UPDATE_INTERVAL, MQTT_UPDATE_INTERVAL);
|
|
120
|
+
this.statusMonitor = new StatusMonitor(this.processMqttProxy, this.processStatusTopic, () => this.active, MQTT_UPDATE_INTERVAL, MQTT_UPDATE_INTERVAL, { processName: this.processName, processId: this.processId });
|
|
98
121
|
this.statusMonitor.start();
|
|
99
122
|
}
|
|
100
123
|
/**
|
|
@@ -104,7 +127,7 @@ class UnsProxyProcess {
|
|
|
104
127
|
initHandoverManager(instanceMode, handover) {
|
|
105
128
|
const handoverRequestEnabled = instanceMode == "handover" ? true : false;
|
|
106
129
|
const forceStartEnabled = instanceMode == "force" ? true : false;
|
|
107
|
-
this.handoverManager = new HandoverManager(this.processName, this.processMqttProxy, this.unsMqttProxies, handoverRequestEnabled, handover ?? true, forceStartEnabled);
|
|
130
|
+
this.handoverManager = new HandoverManager(this.processName, this.processId, this.processMqttProxy, this.unsMqttProxies, handoverRequestEnabled, handover ?? true, forceStartEnabled);
|
|
108
131
|
// Listen for handover events.
|
|
109
132
|
this.handoverManager.event.on("handoverManager", (event) => {
|
|
110
133
|
this.active = event.active;
|
|
@@ -125,7 +148,11 @@ class UnsProxyProcess {
|
|
|
125
148
|
if (!this.handoverManager) {
|
|
126
149
|
this.initHandoverManager(instanceMode, handover);
|
|
127
150
|
}
|
|
128
|
-
const
|
|
151
|
+
const resolvedUnsParameters = {
|
|
152
|
+
...(unsParameters ?? {}),
|
|
153
|
+
clientId: unsParameters?.clientId ?? `${this.processName}-${instanceName}-${this.processId}`,
|
|
154
|
+
};
|
|
155
|
+
const unsMqttProxy = new UnsMqttProxy(mqttHost, this.processName, instanceName, resolvedUnsParameters);
|
|
129
156
|
// Listen for UNS proxy producing topics and publish them via MQTT.
|
|
130
157
|
unsMqttProxy.event.on("unsProxyProducedTopics", (event) => {
|
|
131
158
|
this.processMqttProxy.publish(event.statusTopic, JSON.stringify(event.producedTopics), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uns-proxy-process.js","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAC;AAGlC,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AACz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Parameters, UnsEvents } from \"./uns-interfaces.js\";\nimport { IMqttParameters } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport { HandoverManager } from \"./handover-manager.js\";\n\n// Import configuration and initialization modules.\nimport { PACKAGE_INFO, MQTT_UPDATE_INTERVAL } from \"./process-config.js\";\nimport { getProcessName } from \"./process-name-service.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { StatusMonitor } from \"./status-monitor.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\n\n\n/**\n * UnsProxyProcess is responsible for managing the process lifecycle,\n * configuring MQTT (subscriptions and publishing for status updates), and\n * handling UNS proxy instances.\n *\n * It leverages HandoverManager for handover events and StatusMonitor for health reporting.\n */\nexport type UnsProxyProcessPluginMethod = (this: UnsProxyProcess, ...args: unknown[]) => unknown;\n\nexport type UnsProxyProcessPluginMethods = Record<string, UnsProxyProcessPluginMethod>;\n\nexport interface UnsProxyProcessPluginApi {\n version: number;\n define(methods: UnsProxyProcessPluginMethods): void;\n UnsProxyProcess: typeof UnsProxyProcess;\n}\n\nexport type UnsProxyProcessPlugin = (api: UnsProxyProcessPluginApi) => void;\n\nclass UnsProxyProcess {\n private active: boolean = false;\n private processStatusTopic: string;\n private processName: string;\n private unsMqttProxies: UnsMqttProxy[];\n private unsApiProxies: unknown[];\n private unsTemporalProxies: unknown[];\n private processMqttProxy: MqttProxy;\n private handoverManager: HandoverManager;\n private statusMonitor: StatusMonitor;\n\n // Plugin\n static pluginApiVersion = 1;\n private static registered = new Set<UnsProxyProcessPlugin>();\n private static registeredMethodNames = new Set<string>();\n private static applied = false;\n\n static use(plugin: UnsProxyProcessPlugin) {\n if (this.registered.has(plugin)) return this;\n this.registered.add(plugin);\n if (this.applied) this.applyPlugin(plugin);\n return this;\n }\n\n private static applyPlugin(plugin: UnsProxyProcessPlugin) {\n const define: UnsProxyProcessPluginApi[\"define\"] = (methods) => {\n for (const [name, fn] of Object.entries(methods)) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`UnsProxyProcess plugin attempted to register non-function member \\\"${name}\\\".`);\n }\n if (this.registeredMethodNames.has(name) || Reflect.has(this.prototype, name)) {\n throw new Error(`UnsProxyProcess plugin attempted to overwrite existing member \\\"${name}\\\".`);\n }\n Object.defineProperty(this.prototype, name, {\n value: fn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n this.registeredMethodNames.add(name);\n }\n };\n\n plugin({\n define,\n version: this.pluginApiVersion,\n UnsProxyProcess: this,\n });\n }\n\n private static applyAll() {\n if (this.applied) return;\n this.applied = true;\n for (const p of this.registered) this.applyPlugin(p);\n }\n\n // References for cleanup.\n private mqttInputHandler: (event: any) => void;\n\n constructor(mqttHost: string, unsProxyProcessParameters?: IUnsProcessParameters) {\n (this.constructor as typeof UnsProxyProcess).applyAll(); // Activate all the plugins\n\n this.unsMqttProxies = [];\n this.unsApiProxies = [];\n this.unsTemporalProxies = [];\n this.processName = unsProxyProcessParameters.processName || getProcessName();\n const { name: packageName, version } = PACKAGE_INFO;\n\n // Instantiate the topic builder.\n const topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);\n\n // Generate topics.\n const processStatusTopic = topicBuilder.getProcessStatusTopic();\n const handoverTopic = topicBuilder.getHandoverTopic();\n const wildcardActiveTopic = topicBuilder.getWildcardActiveTopic();\n\n this.processStatusTopic = processStatusTopic;\n\n // Configure MQTT topics for subscription.\n const mqttSubToTopics = unsProxyProcessParameters?.mqttSubToTopics ?? [\n wildcardActiveTopic,\n handoverTopic,\n ];\n const mqttParameters: IMqttParameters = {\n mqttSubToTopics,\n username: unsProxyProcessParameters?.username ?? \"\",\n password: unsProxyProcessParameters?.password ?? \"\",\n mqttSSL: unsProxyProcessParameters?.mqttSSL ?? false,\n statusTopic: this.processStatusTopic,\n };\n\n // Initialize MQTT proxy and start connection.\n this.processMqttProxy = new MqttProxy(mqttHost, this.processName, mqttParameters);\n this.processMqttProxy.start();\n\n // Instantiate and start the StatusMonitor for memory and status updates.\n this.statusMonitor = new StatusMonitor(\n this.processMqttProxy,\n this.processStatusTopic,\n () => this.active,\n MQTT_UPDATE_INTERVAL,\n MQTT_UPDATE_INTERVAL,\n );\n this.statusMonitor.start();\n }\n\n /**\n * Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.\n * Determines handover and force start modes based on process arguments.\n */\n private initHandoverManager(instanceMode: string, handover: boolean) {\n\n const handoverRequestEnabled = instanceMode == \"handover\" ? true : false;\n const forceStartEnabled = instanceMode == \"force\" ? true : false;\n\n this.handoverManager = new HandoverManager(\n this.processName,\n this.processMqttProxy,\n this.unsMqttProxies,\n handoverRequestEnabled,\n handover ?? true,\n forceStartEnabled\n );\n\n // Listen for handover events.\n this.handoverManager.event.on(\"handoverManager\", (event) => {\n this.active = event.active;\n });\n\n // Delegate MQTT events to the HandoverManager.\n this.mqttInputHandler = async (event: UnsEvents[\"input\"]) => {\n await this.handoverManager.handleMqttMessage(event);\n };\n this.processMqttProxy.event.on(\"input\", this.mqttInputHandler);\n }\n\n /**\n * Creates a new UNS proxy instance and stores it for future management.\n */\n public async createUnsMqttProxy(\n mqttHost: string, \n instanceName: string,\n instanceMode: string,\n handover: boolean,\n unsParameters?: IUnsParameters): Promise<UnsMqttProxy> {\n // Wait until the MQTT connection is established before proceeding.\n await this.waitForProcessConnection();\n\n // Currently handover manager can handle only mqtt events\n if (!this.handoverManager) {\n this.initHandoverManager(instanceMode, handover);\n }\n\n const unsMqttProxy = new UnsMqttProxy(mqttHost, this.processName, instanceName, unsParameters);\n \n // Listen for UNS proxy producing topics and publish them via MQTT.\n unsMqttProxy.event.on(\"unsProxyProducedTopics\", (event) => {\n this.processMqttProxy.publish(\n event.statusTopic,\n JSON.stringify(event.producedTopics),\n {\n retain: true,\n properties: { messageExpiryInterval: 120000 },\n },\n );\n });\n\n // Listen for UNS proxy status events and publish them via MQTT.\n unsMqttProxy.event.on(\"mqttProxyStatus\", (event) => {\n const time = UnsPacket.formatToISO8601(new Date());\n const unsMessage: IUnsMessage = { data: { time, value: event.value, uom: event.uom } };\n UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {\n this.processMqttProxy.publish(\n event.statusTopic,\n JSON.stringify(packet),\n );\n });\n });\n\n this.unsMqttProxies.push(unsMqttProxy);\n return unsMqttProxy;\n }\n\n public async waitForProcessConnection(): Promise<void> {\n while (!this.processMqttProxy?.isConnected) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Shuts down the process by clearing intervals, timeouts, and removing\n * MQTT event listeners, and stopping the StatusMonitor.\n */\n public shutdown(): void {\n logger.info(`${this.processName} - Shutting down UnsProxyProcess...`);\n try {\n this.statusMonitor.stop();\n } catch (e: any) {\n logger.error(`${this.processName} - Error stopping StatusMonitor: ${e.message}`);\n }\n \n if (this.mqttInputHandler) {\n this.processMqttProxy.event.off(\"input\", this.mqttInputHandler);\n }\n \n try {\n if (typeof this.processMqttProxy.stop === \"function\") {\n this.processMqttProxy.stop();\n }\n } catch (e: any) {\n logger.error(`${this.processName} - Error stopping MQTT proxy: ${e.message}`);\n }\n \n logger.info(`${this.processName} - Shutdown complete.`);\n }\n \n}\n\ninterface UnsProxyProcess {}\n\nexport default UnsProxyProcess;\nexport { UnsProxyProcess };\n"]}
|
|
1
|
+
{"version":3,"file":"uns-proxy-process.js","sourceRoot":"","sources":["../../src/uns/uns-proxy-process.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAGrC,OAAO,SAAS,MAAM,2BAA2B,CAAC;AAClD,OAAO,YAAY,MAAM,+BAA+B,CAAC;AACzD,OAAO,EAAE,eA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IUnsParameters, IUnsProcessParameters, UnsEvents } from \"./uns-interfaces.js\";\nimport { IMqttParameters } from \"../uns-mqtt/mqtt-interfaces.js\";\nimport MqttProxy from \"../uns-mqtt/mqtt-proxy.js\";\nimport UnsMqttProxy from \"../uns-mqtt/uns-mqtt-proxy.js\";\nimport { HandoverManager } from \"./handover-manager.js\";\n\n// Import configuration and initialization modules.\nimport { PACKAGE_INFO, MQTT_UPDATE_INTERVAL } from \"./process-config.js\";\nimport { MqttTopicBuilder } from \"../uns-mqtt/mqtt-topic-builder.js\";\nimport { StatusMonitor } from \"./status-monitor.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\n\n\n/**\n * UnsProxyProcess is responsible for managing the process lifecycle,\n * configuring MQTT (subscriptions and publishing for status updates), and\n * handling UNS proxy instances.\n *\n * It leverages HandoverManager for handover events and StatusMonitor for health reporting.\n */\nexport type UnsProxyProcessPluginMethod = (this: UnsProxyProcess, ...args: unknown[]) => unknown;\n\nexport type UnsProxyProcessPluginMethods = Record<string, UnsProxyProcessPluginMethod>;\n\nexport interface UnsProxyProcessPluginApi {\n version: number;\n define(methods: UnsProxyProcessPluginMethods): void;\n UnsProxyProcess: typeof UnsProxyProcess;\n}\n\nexport type UnsProxyProcessPlugin = (api: UnsProxyProcessPluginApi) => void;\n\nclass UnsProxyProcess {\n private active: boolean = false;\n private processStatusTopic: string;\n private processName: string;\n private processId: string;\n private unsMqttProxies: UnsMqttProxy[];\n private unsApiProxies: unknown[];\n private unsTemporalProxies: unknown[];\n private processMqttProxy: MqttProxy;\n private handoverManager: HandoverManager;\n private statusMonitor: StatusMonitor;\n\n // Plugin\n static pluginApiVersion = 1;\n private static registered = new Set<UnsProxyProcessPlugin>();\n private static registeredMethodNames = new Set<string>();\n private static applied = false;\n\n static use(plugin: UnsProxyProcessPlugin) {\n if (this.registered.has(plugin)) return this;\n this.registered.add(plugin);\n if (this.applied) this.applyPlugin(plugin);\n return this;\n }\n\n private static applyPlugin(plugin: UnsProxyProcessPlugin) {\n const define: UnsProxyProcessPluginApi[\"define\"] = (methods) => {\n for (const [name, fn] of Object.entries(methods)) {\n if (typeof fn !== \"function\") {\n throw new TypeError(`UnsProxyProcess plugin attempted to register non-function member \\\"${name}\\\".`);\n }\n if (this.registeredMethodNames.has(name) || Reflect.has(this.prototype, name)) {\n throw new Error(`UnsProxyProcess plugin attempted to overwrite existing member \\\"${name}\\\".`);\n }\n Object.defineProperty(this.prototype, name, {\n value: fn,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n this.registeredMethodNames.add(name);\n }\n };\n\n plugin({\n define,\n version: this.pluginApiVersion,\n UnsProxyProcess: this,\n });\n }\n\n private static applyAll() {\n if (this.applied) return;\n this.applied = true;\n for (const p of this.registered) this.applyPlugin(p);\n }\n\n // References for cleanup.\n private mqttInputHandler: (event: any) => void;\n\n constructor(mqttHost: string, unsProxyProcessParameters: IUnsProcessParameters) {\n (this.constructor as typeof UnsProxyProcess).applyAll(); // Activate all the plugins\n\n this.unsMqttProxies = [];\n this.unsApiProxies = [];\n this.unsTemporalProxies = [];\n if (!unsProxyProcessParameters?.processName) {\n throw new Error(\"UnsProxyProcess requires a processName in configuration.\");\n }\n this.processName = unsProxyProcessParameters.processName;\n this.processId = randomBytes(16).toString(\"hex\");\n const { name: packageName, version } = PACKAGE_INFO;\n\n // Instantiate the topic builder.\n const topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageName)}/${MqttTopicBuilder.sanitizeTopicPart(version)}/${MqttTopicBuilder.sanitizeTopicPart(this.processName)}/`);\n\n // Generate topics.\n const processStatusTopic = topicBuilder.getProcessStatusTopic();\n const handoverTopic = topicBuilder.getHandoverTopic();\n const wildcardActiveTopic = topicBuilder.getWildcardActiveTopic();\n\n this.processStatusTopic = processStatusTopic;\n\n // Configure MQTT topics for subscription.\n const mqttSubToTopics = unsProxyProcessParameters?.mqttSubToTopics ?? [\n wildcardActiveTopic,\n handoverTopic,\n ];\n const mqttParameters: IMqttParameters = {\n mqttSubToTopics,\n username: unsProxyProcessParameters?.username ?? \"\",\n password: unsProxyProcessParameters?.password ?? \"\",\n mqttSSL: unsProxyProcessParameters?.mqttSSL ?? false,\n statusTopic: this.processStatusTopic,\n clientId: unsProxyProcessParameters?.clientId ?? `${this.processName}-${this.processId}`,\n hosts: unsProxyProcessParameters?.hosts,\n servers: unsProxyProcessParameters?.servers,\n port: unsProxyProcessParameters?.port,\n protocol: unsProxyProcessParameters?.protocol,\n keepalive: unsProxyProcessParameters?.keepalive,\n clean: unsProxyProcessParameters?.clean,\n connectTimeout: unsProxyProcessParameters?.connectTimeout,\n reconnectPeriod: unsProxyProcessParameters?.reconnectPeriod,\n reconnectOnConnackError: unsProxyProcessParameters?.reconnectOnConnackError,\n resubscribe: unsProxyProcessParameters?.resubscribe,\n queueQoSZero: unsProxyProcessParameters?.queueQoSZero,\n rejectUnauthorized: unsProxyProcessParameters?.rejectUnauthorized ?? false,\n properties: unsProxyProcessParameters?.properties,\n ca: unsProxyProcessParameters?.ca,\n cert: unsProxyProcessParameters?.cert,\n key: unsProxyProcessParameters?.key,\n servername: unsProxyProcessParameters?.servername,\n };\n\n // Initialize MQTT proxy and start connection.\n this.processMqttProxy = new MqttProxy(mqttHost, this.processName, mqttParameters);\n this.processMqttProxy.start();\n\n // Instantiate and start the StatusMonitor for memory and status updates.\n this.statusMonitor = new StatusMonitor(\n this.processMqttProxy,\n this.processStatusTopic,\n () => this.active,\n MQTT_UPDATE_INTERVAL,\n MQTT_UPDATE_INTERVAL,\n { processName: this.processName, processId: this.processId },\n );\n this.statusMonitor.start();\n }\n\n /**\n * Initializes the HandoverManager instance and sets up event listeners for handover and MQTT input events.\n * Determines handover and force start modes based on process arguments.\n */\n private initHandoverManager(instanceMode: string, handover: boolean) {\n\n const handoverRequestEnabled = instanceMode == \"handover\" ? true : false;\n const forceStartEnabled = instanceMode == \"force\" ? true : false;\n\n this.handoverManager = new HandoverManager(\n this.processName,\n this.processId,\n this.processMqttProxy,\n this.unsMqttProxies,\n handoverRequestEnabled,\n handover ?? true,\n forceStartEnabled\n );\n\n // Listen for handover events.\n this.handoverManager.event.on(\"handoverManager\", (event) => {\n this.active = event.active;\n });\n\n // Delegate MQTT events to the HandoverManager.\n this.mqttInputHandler = async (event: UnsEvents[\"input\"]) => {\n await this.handoverManager.handleMqttMessage(event);\n };\n this.processMqttProxy.event.on(\"input\", this.mqttInputHandler);\n }\n\n /**\n * Creates a new UNS proxy instance and stores it for future management.\n */\n public async createUnsMqttProxy(\n mqttHost: string, \n instanceName: string,\n instanceMode: string,\n handover: boolean,\n unsParameters?: IUnsParameters): Promise<UnsMqttProxy> {\n // Wait until the MQTT connection is established before proceeding.\n await this.waitForProcessConnection();\n\n // Currently handover manager can handle only mqtt events\n if (!this.handoverManager) {\n this.initHandoverManager(instanceMode, handover);\n }\n\n const resolvedUnsParameters: IUnsParameters = {\n ...(unsParameters ?? {}),\n clientId: unsParameters?.clientId ?? `${this.processName}-${instanceName}-${this.processId}`,\n };\n const unsMqttProxy = new UnsMqttProxy(mqttHost, this.processName, instanceName, resolvedUnsParameters);\n \n // Listen for UNS proxy producing topics and publish them via MQTT.\n unsMqttProxy.event.on(\"unsProxyProducedTopics\", (event) => {\n this.processMqttProxy.publish(\n event.statusTopic,\n JSON.stringify(event.producedTopics),\n {\n retain: true,\n properties: { messageExpiryInterval: 120000 },\n },\n );\n });\n\n // Listen for UNS proxy status events and publish them via MQTT.\n unsMqttProxy.event.on(\"mqttProxyStatus\", (event) => {\n const time = UnsPacket.formatToISO8601(new Date());\n const unsMessage: IUnsMessage = { data: { time, value: event.value, uom: event.uom } };\n UnsPacket.unsPacketFromUnsMessage(unsMessage).then((packet) => {\n this.processMqttProxy.publish(\n event.statusTopic,\n JSON.stringify(packet),\n );\n });\n });\n\n this.unsMqttProxies.push(unsMqttProxy);\n return unsMqttProxy;\n }\n\n public async waitForProcessConnection(): Promise<void> {\n while (!this.processMqttProxy?.isConnected) {\n await new Promise((resolve) => setTimeout(resolve, 100));\n }\n }\n\n /**\n * Shuts down the process by clearing intervals, timeouts, and removing\n * MQTT event listeners, and stopping the StatusMonitor.\n */\n public shutdown(): void {\n logger.info(`${this.processName} - Shutting down UnsProxyProcess...`);\n try {\n this.statusMonitor.stop();\n } catch (e: any) {\n logger.error(`${this.processName} - Error stopping StatusMonitor: ${e.message}`);\n }\n \n if (this.mqttInputHandler) {\n this.processMqttProxy.event.off(\"input\", this.mqttInputHandler);\n }\n \n try {\n if (typeof this.processMqttProxy.stop === \"function\") {\n this.processMqttProxy.stop();\n }\n } catch (e: any) {\n logger.error(`${this.processName} - Error stopping MQTT proxy: ${e.message}`);\n }\n \n logger.info(`${this.processName} - Shutdown complete.`);\n }\n \n}\n\ninterface UnsProxyProcess {}\n\nexport default UnsProxyProcess;\nexport { UnsProxyProcess };\n"]}
|