@uns-kit/core 3.0.15 → 3.0.17

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.
@@ -327,7 +327,20 @@ export default class UnsMqttProxy extends UnsProxy {
327
327
  const attrs = Array.isArray(mqttMessage.attributes)
328
328
  ? mqttMessage.attributes
329
329
  : [mqttMessage.attributes];
330
- const { topic, asset, assetDescription, objectType, objectTypeDescription, objectId, virtualGroup: requestVirtualGroup } = mqttMessage;
330
+ const { topic, asset, assetDescription, assetStableEntityId, assetDisplayName, assetIdentityProof, objectType, objectTypeDescription, objectId, virtualGroup: requestVirtualGroup, } = mqttMessage;
331
+ const hasAssetIdentityMetadata = assetStableEntityId !== undefined
332
+ || assetDisplayName !== undefined
333
+ || assetIdentityProof !== undefined;
334
+ if (hasAssetIdentityMetadata) {
335
+ if (typeof assetStableEntityId !== "string"
336
+ || !assetStableEntityId.trim()
337
+ || typeof assetIdentityProof !== "string"
338
+ || !assetIdentityProof.trim()
339
+ || (assetDisplayName !== undefined
340
+ && (typeof assetDisplayName !== "string" || !assetDisplayName.trim()))) {
341
+ throw new Error("Asset identity metadata requires assetStableEntityId and assetIdentityProof; assetDisplayName must be non-empty when supplied.");
342
+ }
343
+ }
331
344
  for (const attrEntry of attrs) {
332
345
  const attrDescription = attrEntry.description ?? getAttributeDescription(attrEntry.attribute);
333
346
  const message = "message" in attrEntry && attrEntry.message
@@ -342,6 +355,11 @@ export default class UnsMqttProxy extends UnsProxy {
342
355
  topic,
343
356
  asset,
344
357
  assetDescription,
358
+ ...(hasAssetIdentityMetadata ? {
359
+ assetStableEntityId: assetStableEntityId.trim().toLowerCase(),
360
+ ...(assetDisplayName ? { assetDisplayName: assetDisplayName.trim() } : {}),
361
+ assetIdentityProof: assetIdentityProof.trim(),
362
+ } : {}),
345
363
  objectType,
346
364
  objectTypeDescription,
347
365
  objectId,
@@ -495,6 +513,9 @@ export default class UnsMqttProxy extends UnsProxy {
495
513
  virtualGroup: msg.virtualGroup,
496
514
  asset,
497
515
  assetDescription: msg.assetDescription,
516
+ assetStableEntityId: msg.assetStableEntityId,
517
+ assetDisplayName: msg.assetDisplayName,
518
+ assetIdentityProof: msg.assetIdentityProof,
498
519
  objectType,
499
520
  objectTypeDescription,
500
521
  objectId,
@@ -1 +1 @@
1
- {"version":3,"file":"uns-mqtt-proxy.js","sourceRoot":"","sources":["../../src/uns-mqtt/uns-mqtt-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAElC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC,OAAO,EAAE,wBAAwB,EAAwC,MAAM,sBAAsB,CAAC;AAGtG,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,QAAQ,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAInE,MAAM,eAAe,GAAG,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAC5D,MAAM,WAAW,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC,CAAC;AAEtE,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrE,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI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path\";\nimport { Worker } from \"worker_threads\";\nimport { fileURLToPath } from \"url\";\nimport { basePath } from \"../base-path.js\";\nimport logger from \"../logger.js\";\nimport { IMqttPublishRequest, IUnsLifecycleMetadata, IUnsMessage, IUnsPacket, IUnsParameters, IUnsRelationshipEvidenceMetadata, IUnsTableColumnMetadata, UnsAttribute, UnsAttributeSystemRole, UnsEvents, ValueType } from \"../uns/uns-interfaces.js\";\nimport { getObjectTypeDescription, type UnsObjectId, type UnsObjectType } from \"../uns/uns-object.js\";\nimport type { UnsAsset } from \"../uns/uns-asset.js\";\nimport { MeasurementUnit } from \"../uns/uns-measurements.js\";\nimport { UnsPacket } from \"../uns/uns-packet.js\";\nimport { IMqttParameters, IMqttWorkerData } from \"./mqtt-interfaces.js\";\nimport { MqttTopicBuilder } from \"./mqtt-topic-builder.js\";\nimport UnsProxy from \"../uns/uns-proxy.js\";\nimport { UnsAttributeType } from \"../graphql/schema.js\";\nimport { getAttributeDescription } from \"../uns/uns-attributes.js\";\nimport { UnsTags } from \"../uns/uns-tags.js\";\nimport { UnsTopics } from \"../uns/uns-topics.js\";\n\nconst packageJsonPath = path.join(basePath, \"package.json\");\nconst packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\"));\n\nconst moduleDirectory = path.dirname(fileURLToPath(import.meta.url));\nconst packageRoot = path.resolve(moduleDirectory, \"..\", \"..\");\nconst workerScriptPath = path.join(packageRoot, \"dist/uns-mqtt/mqtt-worker-init.js\");\n\nexport enum MessageMode {\n Raw = 'raw', // Send only the original message\n /**\n * @deprecated Producer-side delta calculation loses state across restarts.\n * Publish raw cumulative counter values and request delta/rate from Datahub history APIs.\n */\n Delta = 'delta', // Send only the delta message\n /**\n * @deprecated Producer-side delta calculation loses state across restarts.\n * Publish raw cumulative counter values and request delta/rate from Datahub history APIs.\n */\n Both = 'both' // Send both the original and delta messages\n}\n\nexport interface UnsMqttProxyStopOptions {\n drain?: boolean;\n timeoutMs?: number;\n}\n\ntype UnsMqttProxyLifecycleState = \"running\" | \"stopping\" | \"stopped\";\n\ntype InternalMqttMessage = {\n topic: UnsTopics;\n attribute: UnsAttribute;\n asset: UnsAsset;\n assetDescription?: string;\n objectType: UnsObjectType;\n objectTypeDescription?: string;\n objectId: UnsObjectId;\n virtualGroup?: string;\n description?: string;\n tags?: UnsTags[];\n attributeNeedsPersistence?: boolean | null;\n valueType?: string;\n presentationKind?: string;\n defaultAggregation?: string;\n counterResetPolicy?: string;\n tableColumns?: IUnsTableColumnMetadata[];\n systemRole?: UnsAttributeSystemRole;\n relationshipEvidence?: IUnsRelationshipEvidenceMetadata;\n lifecycle?: IUnsLifecycleMetadata;\n validityMode?: \"interval\" | \"lifecycle\" | \"static\";\n expectedIntervalMs?: number;\n lifecycleEndValue?: string;\n packet: IUnsPacket;\n};\n\nexport default class UnsMqttProxy extends UnsProxy {\n public static readonly DEFAULT_DRAIN_TIMEOUT_MS = 30_000;\n private lastValues: Map<string, { value: ValueType; uom: string; timestamp: Date }> = new Map();\n private worker: Worker;\n private pendingEnqueues: Map<string, { resolve: () => void; reject: (reason?: any) => void }> = new Map();\n private pendingPublishCompletions = new Set<string>();\n private unsParameters: IUnsParameters;\n protected processStatusTopic: string;\n public instanceName: string;\n private currentSequenceId: Map<string, number> = new Map();\n private topicBuilder: MqttTopicBuilder;\n private deltaModeDeprecationWarned = false;\n private drainWaiters: Array<{ resolve: () => void; reject: (reason?: any) => void; timer?: NodeJS.Timeout }> = [];\n private workerFailure: Error | null = null;\n private lifecycleState: UnsMqttProxyLifecycleState = \"running\";\n private stopPromise: Promise<void> | null = null;\n private expectedWorkerExit = false;\n\n constructor(\n mqttHost: string,\n processName: string,\n instanceName: string,\n unsParameters?: IUnsParameters,\n publisherActive: boolean = false,\n subscriberActive: boolean = false\n ) {\n super();\n this.instanceName = instanceName;\n // Create the topic builder using packageJson values and the processName.\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageJson.name)}/${MqttTopicBuilder.sanitizeTopicPart(packageJson.version)}/${MqttTopicBuilder.sanitizeTopicPart(processName)}/`);\n\n // Generate the processStatusTopic using the builder.\n this.processStatusTopic = this.topicBuilder.getProcessStatusTopic();\n // Derive the instanceStatusTopic by appending the instance name.\n this.instanceStatusTopic = this.processStatusTopic + instanceName + \"/\";\n\n // Concatenate processName with instanceName for the worker identification.\n this.instanceNameWithSuffix = `${processName}-${instanceName}`;\n \n const mqttParameters: IMqttParameters = {\n mqttSubToTopics: unsParameters?.mqttSubToTopics ?? [],\n username: unsParameters?.username ?? \"\",\n password: unsParameters?.password ?? \"\",\n mqttSSL: unsParameters?.mqttSSL ?? false,\n statusTopic: this.instanceStatusTopic,\n rejectUnauthorized: unsParameters?.rejectUnauthorized ?? false,\n clientId: unsParameters?.clientId,\n hosts: unsParameters?.hosts,\n servers: unsParameters?.servers,\n port: unsParameters?.port,\n protocol: unsParameters?.protocol,\n keepalive: unsParameters?.keepalive,\n clean: unsParameters?.clean,\n connectTimeout: unsParameters?.connectTimeout,\n reconnectPeriod: unsParameters?.reconnectPeriod,\n reconnectOnConnackError: unsParameters?.reconnectOnConnackError,\n resubscribe: unsParameters?.resubscribe,\n queueQoSZero: unsParameters?.queueQoSZero,\n properties: unsParameters?.properties,\n ca: unsParameters?.ca,\n cert: unsParameters?.cert,\n key: unsParameters?.key,\n servername: unsParameters?.servername,\n };\n this.unsParameters = unsParameters ?? {};\n this.startQueueWorker(mqttHost, this.instanceNameWithSuffix, mqttParameters, publisherActive, subscriberActive);\n }\n\n /**\n * Resolve object identity from explicit fields or the tail of the topic path.\n * Falls back to parsing when not provided for backward compatibility.\n */\n private resolveObjectIdentity(msg: InternalMqttMessage): { objectType?: UnsObjectType; objectId?: UnsObjectId; asset?: UnsAsset } {\n const providedType = msg.objectType;\n const providedId = msg.objectId;\n const providedAsset = msg.asset;\n\n const topicParts = msg.topic.split(\"/\").filter((part) => part.length > 0);\n const hasObjectTail = topicParts.length >= 2;\n const parsedType = hasObjectTail ? topicParts[topicParts.length - 2] as UnsObjectType : undefined;\n const parsedId = hasObjectTail ? topicParts[topicParts.length - 1] as UnsObjectId : undefined;\n const parsedAsset = hasObjectTail\n ? (topicParts.length >= 3 ? topicParts[topicParts.length - 3] as UnsAsset : undefined)\n : (topicParts.length >= 1 ? topicParts[topicParts.length - 1] as UnsAsset : undefined);\n\n const objectType = providedType ?? parsedType;\n const objectId = providedId ?? parsedId ?? \"main\";\n const asset = providedAsset ?? parsedAsset;\n\n // If values are provided, trust them; otherwise derive from topic.\n if (!providedType || !providedId) {\n if (parsedType && parsedId) {\n logger.warn(`${this.instanceNameWithSuffix} - objectType/objectId missing; derived from topic tail ${parsedType}/${parsedId}`);\n } else {\n logger.warn(`${this.instanceNameWithSuffix} - objectType/objectId missing; defaulting objectId to 'main' for topic '${msg.topic}'. Expected topic to end with '<objectType>/<objectId>/'`);\n }\n }\n // Asset is optional; no warning on mismatch to avoid noisy logs when base topics don't carry it.\n\n msg.objectType = objectType;\n msg.objectId = objectId;\n msg.asset = asset;\n\n return { objectType, objectId, asset };\n }\n\n /**\n * Ensure the topic ends with a trailing slash for attribute concatenation.\n */\n private normalizeTopicWithObject(topic: string): string {\n return topic.endsWith(\"/\") ? topic : `${topic}/`;\n }\n\n /**\n * Starts a worker thread to process the throttled publish queue.\n */\n private startQueueWorker(\n mqttHost: string,\n instanceNameWithSuffix: string,\n mqttParameters: IMqttParameters,\n publisherActive: boolean,\n subscriberActive: boolean\n ): void {\n const workerData: IMqttWorkerData = {\n publishThrottlingDelay: this.unsParameters.publishThrottlingDelay ?? 1,\n publishConcurrency: this.unsParameters.publishConcurrency ?? 1,\n maxPendingPublishes: this.unsParameters.maxPendingPublishes,\n subscribeThrottlingDelay: this.unsParameters.subscribeThrottlingDelay ?? 1,\n persistToDisk: false,\n mqttHost: mqttHost,\n instanceNameWithSuffix: instanceNameWithSuffix,\n mqttParameters: mqttParameters,\n publisherActive,\n subscriberActive,\n defaultPublishOptions: this.unsParameters.defaultPublishOptions,\n };\n\n this.worker = new Worker(workerScriptPath, { workerData });\n\n this.worker.on(\"message\", (msg) => {\n if (msg && msg.command === \"enqueueAccepted\" && msg.id) {\n const pending = this.pendingEnqueues.get(msg.id);\n if (pending) {\n this.pendingEnqueues.delete(msg.id);\n if (msg.status === \"accepted\") {\n this.pendingPublishCompletions.add(msg.id);\n pending.resolve();\n } else {\n pending.reject(new Error(msg.error));\n }\n this.notifyDrainWaiters();\n }\n } else if (msg && msg.command === \"publishResult\" && msg.id) {\n this.pendingPublishCompletions.delete(msg.id);\n if (msg.status === \"error\") {\n const errorMessage = msg.error ?? `Error publishing to topic ${msg.topic ?? \"unknown\"}`;\n this.event.emit(\"error\", { code: 0, message: errorMessage });\n }\n this.notifyDrainWaiters();\n } else if (msg && msg.command === \"input\") {\n this.event.emit(\"input\", { topic: msg.topic, message: msg.message.toString(), packet: msg.packet });\n } else if (msg && (msg.command === \"handover_subscriber\" || msg.command === \"handover_publisher\")) {\n this.event.emit(\"mqttWorker\", { command: msg.command, batchSize: msg.batchSize, referenceHash: msg.referenceHash, instanceName: this.instanceName });\n } else if (msg && msg.command === \"mqttProxyStatus\") {\n this.event.emit(\"mqttProxyStatus\", { event: msg.event, value: msg.value, uom: msg.uom, statusTopic: msg.statusTopic });\n }\n });\n\n this.worker.on(\"error\", (err) => {\n if (this.expectedWorkerExit) {\n return;\n }\n logger.error(\"Error in worker:\", err);\n const reason = err instanceof Error ? err : new Error(String(err));\n this.failPendingPublishes(reason);\n });\n\n this.worker.on(\"exit\", (code) => {\n if (this.expectedWorkerExit) {\n return;\n }\n logger.error(`Worker exited unexpectedly with code ${code}`);\n const reason = new Error(`MQTT worker exited unexpectedly with code ${code}`);\n this.failPendingPublishes(reason);\n });\n }\n\n /**\n * Enqueues a message to the worker queue.\n *\n * @param topic - The topic to which the message belongs.\n * @param message - The message to be enqueued.\n * @param options - Optional publish options.\n * @returns A promise that resolves when the message is accepted into the worker queue.\n */\n private async enqueueMessageToWorkerQueue(topic: string, message: string, options?: IClientPublishOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.lifecycleState !== \"running\") {\n reject(new Error(`${this.instanceNameWithSuffix} - MQTT proxy is ${this.lifecycleState}; publish rejected.`));\n return;\n }\n if (this.workerFailure) {\n reject(this.workerFailure);\n return;\n }\n const maxPendingPublishes = this.unsParameters.maxPendingPublishes;\n const pendingCount = this.pendingEnqueues.size + this.pendingPublishCompletions.size;\n if (maxPendingPublishes !== undefined && pendingCount >= maxPendingPublishes) {\n reject(new Error(`${this.instanceNameWithSuffix} - Publisher queue is full (${maxPendingPublishes}).`));\n return;\n }\n const id = `${Date.now()}-${Math.random()}`;\n this.pendingEnqueues.set(id, { resolve, reject });\n try {\n this.worker.postMessage({ command: \"enqueue\", id, topic, message, options });\n } catch (error) {\n this.pendingEnqueues.delete(id);\n reject(error);\n }\n this.notifyDrainWaiters();\n });\n }\n\n /**\n * Sets the publisher active state.\n *\n * @param batchSize - Optional batch size.\n * @param referenceHash - Optional reference hash.\n */\n public setPublisherActive(batchSize?: number, referenceHash?: string): void {\n this.worker.postMessage({ command: \"setPublisherActive\", batchSize, referenceHash });\n }\n\n /**\n * Sets the publisher to passive mode.\n * @returns A promise that resolves when the publisher is set to passive.\n */\n public setPublisherPassive(): Promise<UnsEvents[\"mqttWorker\"]> {\n this.worker.postMessage({ command: \"setPublisherPassive\"});\n return new Promise((resolve) => {\n const handler = (msg: UnsEvents[\"mqttWorker\"]) => {\n if (msg.command === \"handover_publisher\") {\n this.event.off(\"mqttWorker\", handler);\n logger.info(`${this.instanceNameWithSuffix} - Publisher set to passive.`);\n resolve(msg);\n }\n };\n this.event.on(\"mqttWorker\", handler);\n });\n }\n\n /**\n * Sets the subscriber active state.\n *\n * @param batchSize - Optional batch size.\n * @param referenceHash - Optional reference hash.\n */\n public setSubscriberActive(batchSize?: number, referenceHash?: string): void {\n this.worker.postMessage({ command: \"setSubscriberActive\", batchSize, referenceHash });\n }\n\n /**\n * Sets the subscriber to passive mode.\n * @returns A promise that resolves when the subscriber is set to passive.\n */\n public setSubscriberPassive(): Promise<UnsEvents[\"mqttWorker\"]> {\n this.worker.postMessage({ command: \"setSubscriberPassive\"});\n return new Promise((resolve) => {\n const handler = (msg: UnsEvents[\"mqttWorker\"]) => {\n if (msg.command === \"handover_subscriber\") {\n this.event.off(\"mqttWorker\", handler);\n logger.info(`${this.instanceNameWithSuffix} - Subscriber set to passive.`);\n resolve(msg);\n }\n };\n this.event.on(\"mqttWorker\", handler);\n });\n }\n\n\n /**\n * Sets the subscriber to passive mode and allows the publisher to run\n * until the queue is empty (all messages are processed).\n */\n public async setSubscriberPassiveAndDrainQueue(): Promise<UnsEvents[\"mqttWorker\"]> {\n const mqttWorkerData = await this.setSubscriberPassive();\n await this.flush();\n logger.info(`${this.instanceNameWithSuffix} - Subscriber set to passive and queue drained.`);\n return mqttWorkerData;\n }\n\n public async drainPublishes(timeoutMs: number = UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS): Promise<void> {\n if (this.workerFailure) {\n throw this.workerFailure;\n }\n if (this.pendingEnqueues.size === 0 && this.pendingPublishCompletions.size === 0) {\n return;\n }\n await new Promise<void>((resolve, reject) => {\n const waiter = { resolve, reject, timer: undefined as NodeJS.Timeout | undefined };\n if (Number.isFinite(timeoutMs) && timeoutMs > 0) {\n waiter.timer = setTimeout(() => {\n this.removeDrainWaiter(waiter);\n reject(new Error(`Timed out waiting for MQTT publishes to drain after ${timeoutMs}ms.`));\n }, timeoutMs);\n }\n this.drainWaiters.push(waiter);\n this.notifyDrainWaiters();\n });\n }\n\n public async flush(timeoutMs: number = UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS): Promise<void> {\n await this.drainPublishes(timeoutMs);\n }\n\n /**\n * Processes and publishes MQTT messages based on the selected message mode.\n *\n * @param mqttMessage - The MQTT message object.\n * @param mode - The message mode. Delta and Both are deprecated because\n * producer-side delta calculation loses state across restarts.\n */\n public async publishMqttMessage(mqttMessage: IMqttPublishRequest | null, mode: MessageMode = MessageMode.Raw) {\n if (!mqttMessage) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing mqtt message: mqttMessage must be defined.`);\n return;\n }\n\n const attrs = Array.isArray(mqttMessage.attributes)\n ? mqttMessage.attributes\n : [mqttMessage.attributes];\n const { topic, asset, assetDescription, objectType, objectTypeDescription, objectId, virtualGroup: requestVirtualGroup } = mqttMessage;\n for (const attrEntry of attrs) {\n const attrDescription = attrEntry.description ?? getAttributeDescription(attrEntry.attribute);\n const message: IUnsMessage =\n \"message\" in attrEntry && attrEntry.message\n ? attrEntry.message\n : \"data\" in attrEntry && attrEntry.data\n ? { data: attrEntry.data, createdAt: attrEntry.createdAt, expiresAt: attrEntry.expiresAt }\n : \"table\" in attrEntry && attrEntry.table\n ? { table: attrEntry.table, createdAt: attrEntry.createdAt, expiresAt: attrEntry.expiresAt }\n : (() => { throw new Error(\"Attribute entry must include exactly one of data/table/message\"); })();\n const packet = await UnsPacket.unsPacketFromUnsMessage(message);\n const singleMsg: InternalMqttMessage = {\n topic,\n asset,\n assetDescription,\n objectType,\n objectTypeDescription,\n objectId,\n virtualGroup: attrEntry.virtualGroup ?? requestVirtualGroup,\n attribute: attrEntry.attribute,\n description: attrDescription,\n tags: attrEntry.tags,\n attributeNeedsPersistence: attrEntry.attributeNeedsPersistence,\n valueType: attrEntry.valueType,\n presentationKind: attrEntry.presentationKind,\n defaultAggregation: attrEntry.defaultAggregation,\n counterResetPolicy: attrEntry.counterResetPolicy,\n tableColumns: attrEntry.tableColumns,\n systemRole: attrEntry.systemRole,\n relationshipEvidence: attrEntry.relationshipEvidence,\n lifecycle: attrEntry.lifecycle,\n ...(attrEntry.validityMode ? { validityMode: attrEntry.validityMode } : {}),\n ...(attrEntry.expectedIntervalMs ? { expectedIntervalMs: attrEntry.expectedIntervalMs } : {}),\n ...(attrEntry.lifecycleEndValue ? { lifecycleEndValue: attrEntry.lifecycleEndValue } : {}),\n packet,\n };\n\n // existing single-attribute flow\n const baseDescription =\n singleMsg.description ??\n getAttributeDescription(singleMsg.attribute) ??\n singleMsg.attribute;\n const mqttMessageWithDesc = { ...singleMsg, description: baseDescription };\n\n const time = UnsPacket.formatToISO8601(new Date());\n if (mode === MessageMode.Delta || mode === MessageMode.Both) {\n this.warnDeprecatedDeltaMode(mode);\n }\n switch (mode) {\n case MessageMode.Raw: {\n await this.processAndEnqueueMessage(mqttMessageWithDesc, time, false);\n break;\n }\n case MessageMode.Delta: {\n const deltaMessage = { ...mqttMessageWithDesc };\n deltaMessage.attribute = `${mqttMessageWithDesc.attribute}-delta`;\n deltaMessage.description = `${baseDescription ?? \"\"} (delta)`;\n await this.processAndEnqueueMessage(deltaMessage, time, true);\n break;\n }\n case MessageMode.Both: {\n await this.processAndEnqueueMessage(mqttMessageWithDesc, time, false);\n const deltaMessageBoth = { ...mqttMessageWithDesc };\n deltaMessageBoth.attribute = `${mqttMessageWithDesc.attribute}-delta`;\n deltaMessageBoth.description = `${baseDescription ?? \"\"} (delta)`;\n await this.processAndEnqueueMessage(deltaMessageBoth, time, true);\n break;\n }\n }\n }\n return;\n }\n\n private warnDeprecatedDeltaMode(mode: MessageMode): void {\n if (this.deltaModeDeprecationWarned) return;\n this.deltaModeDeprecationWarned = true;\n logger.warn(\n `${this.instanceNameWithSuffix} - MessageMode.${mode} is deprecated: producer-side delta calculation loses previous-value state across service restarts. Publish raw cumulative counter values and request delta/rate from Datahub history APIs.`,\n );\n }\n\n /**\n * Publishes a message to a specified topic.\n *\n * @param topic - The MQTT topic.\n * @param message - The message to publish.\n * @returns A promise that resolves when the message is accepted into the worker queue.\n */\n public publishMessage(topic: string, message: string, options?: IClientPublishOptions): Promise<void> {\n return this.enqueueMessageToWorkerQueue(topic, message, options);\n }\n\n /**\n * Parses an MQTT packet from a JSON string.\n *\n * @param mqttPacket - The MQTT packet string.\n * @returns A parsed IUnsPacket object or null.\n */\n public parseMqttPacket(mqttPacket: string): IUnsPacket | null {\n return UnsPacket.parseMqttPacket(mqttPacket, this.instanceNameWithSuffix);\n }\n\n /**\n * Subscribes asynchronously to one or more topics.\n *\n * @param topics - A topic or list of topics.\n */\n public subscribeAsync(topics: string | string[]): void {\n this.worker.postMessage({ command: \"subscribeAsync\", topics });\n }\n\n /**\n * Unsubscribes asynchronously from the given topics.\n *\n * @param topics - A list of topics.\n */\n public unsubscribeAsync(topics: string[]): void {\n this.worker.postMessage({ command: \"unsubscribeAsync\", topics });\n }\n\n /**\n * Processes and enqueues a message to the worker queue, including handling\n * sequencing, value differences, and tracking of unique topics.\n *\n * @param msg - The MQTT message to process.\n * @param time - The timestamp.\n * @param valueIsCumulative - Whether the value is cumulative.\n */\n private async processAndEnqueueMessage(msg: InternalMqttMessage, time: string, valueIsCumulative: boolean = false): Promise<void> {\n try {\n const attributeType =\n msg.packet.message.data ? UnsAttributeType.Data :\n msg.packet.message.table ? UnsAttributeType.Table : null;\n \n let dataGroup = \"\";\n if (attributeType == UnsAttributeType.Data)\n dataGroup = msg.packet.message.data.dataGroup ?? \"\";\n if (attributeType == UnsAttributeType.Table)\n dataGroup = msg.packet.message.table.dataGroup ?? \"\";\n\n const { objectType, objectId, asset } = this.resolveObjectIdentity(msg);\n const normalizedTopic = this.normalizeTopicWithObject(msg.topic);\n msg.topic = normalizedTopic;\n const description = msg.description ?? getAttributeDescription(msg.attribute as string) ?? \"\";\n const objectTypeDescription = msg.objectTypeDescription ?? (objectType ? getObjectTypeDescription(objectType) : undefined);\n\n // Runtime validation for validity fields\n if (msg.validityMode) {\n const validModes = new Set([\"interval\", \"lifecycle\", \"static\"]);\n if (!validModes.has(msg.validityMode)) {\n logger.warn(`${this.instanceNameWithSuffix} - Invalid validityMode \"${msg.validityMode}\" for attribute \"${msg.attribute}\". Expected: interval | lifecycle | static.`);\n }\n if (msg.expectedIntervalMs && msg.validityMode !== \"interval\") {\n logger.warn(`${this.instanceNameWithSuffix} - expectedIntervalMs is set but validityMode is \"${msg.validityMode}\" (only used with \"interval\") for attribute \"${msg.attribute}\".`);\n }\n if (msg.lifecycleEndValue && msg.validityMode !== \"lifecycle\") {\n logger.warn(`${this.instanceNameWithSuffix} - lifecycleEndValue is set but validityMode is \"${msg.validityMode}\" (only used with \"lifecycle\") for attribute \"${msg.attribute}\".`);\n }\n if (msg.validityMode === \"interval\" && !msg.expectedIntervalMs) {\n logger.debug(`${this.instanceNameWithSuffix} - validityMode \"interval\" without expectedIntervalMs for attribute \"${msg.attribute}\" — controller will use its default.`);\n }\n }\n\n this.registerUniqueTopic({\n timestamp: time,\n topic: msg.topic,\n attribute: msg.attribute,\n attributeType: attributeType,\n description,\n tags: msg.tags,\n attributeNeedsPersistence: msg.attributeNeedsPersistence,\n valueType: msg.valueType,\n presentationKind: msg.presentationKind,\n defaultAggregation: msg.defaultAggregation,\n counterResetPolicy: msg.counterResetPolicy,\n tableColumns: msg.tableColumns,\n systemRole: msg.systemRole,\n relationshipEvidence: msg.relationshipEvidence,\n lifecycle: msg.lifecycle,\n dataGroup,\n virtualGroup: msg.virtualGroup,\n asset,\n assetDescription: msg.assetDescription,\n objectType,\n objectTypeDescription,\n objectId,\n ...(msg.validityMode ? { validityMode: msg.validityMode } : {}),\n ...(msg.expectedIntervalMs ? { expectedIntervalMs: msg.expectedIntervalMs } : {}),\n ...(msg.lifecycleEndValue ? { lifecycleEndValue: msg.lifecycleEndValue } : {}),\n });\n\n const publishTopic = `${msg.topic}${asset ? `${asset}/` : \"\"}${objectType ? `${objectType}/` : \"\"}${objectId ? `${objectId}/` : \"\"}${msg.attribute}`;\n const sequenceId = this.currentSequenceId.get(msg.topic) ?? 0;\n this.currentSequenceId.set(msg.topic, sequenceId + 1);\n msg.packet.sequenceId = sequenceId;\n\n if (msg.packet.message.data) {\n const newValue = msg.packet.message.data.value;\n const newUom: MeasurementUnit = msg.packet.message.data.uom;\n const lastValueEntry = this.lastValues.get(publishTopic);\n const currentTime = new Date(msg.packet.message.data.time);\n\n if (lastValueEntry) {\n const intervalBetweenMessages = currentTime.getTime() - lastValueEntry.timestamp.getTime();\n const lastValue = lastValueEntry.value;\n this.lastValues.set(publishTopic, { value: newValue, uom: newUom, timestamp: currentTime });\n // Compute the delta and manage cumulative resets\n if (valueIsCumulative == true && typeof newValue === \"number\" && typeof lastValue === \"number\") {\n // Skip if newValue is 0 (likely a glitch)\n if (newValue === 0) {\n return; // Don't process or enqueue\n }\n const delta = newValue - lastValue;\n msg.packet.message.data.value = delta < 0 ? newValue : delta;\n }\n msg.packet.interval = intervalBetweenMessages;\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n this.lastValues.set(publishTopic, { value: newValue, uom: newUom, timestamp: currentTime });\n logger.debug(`${this.instanceNameWithSuffix} - Need one more packet to calculate interval on topic ${publishTopic}`);\n if (valueIsCumulative === false) {\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n logger.debug(`${this.instanceNameWithSuffix} - Need one more packet to calculate difference on value in data for topic ${publishTopic}`);\n }\n }\n } else if (msg.packet.message.table) {\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing message to topic ${publishTopic}: packet.message must include data or table`);\n }\n } catch (error: any) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing message to topic ${msg.topic}${msg.attribute}: ${error.message}`);\n throw error;\n }\n }\n\n /**\n * Stops the UnsProxy instance and cleans up resources.\n */\n public stop(options: UnsMqttProxyStopOptions = {}): Promise<void> {\n if (this.stopPromise) {\n return this.stopPromise;\n }\n\n this.lifecycleState = \"stopping\";\n this.stopPromise = this.performStop(options);\n return this.stopPromise;\n }\n\n private async performStop(options: UnsMqttProxyStopOptions): Promise<void> {\n await super.stop();\n const drain = options.drain ?? true;\n const timeoutMs = options.timeoutMs ?? UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS;\n let stopError: Error | null = null;\n\n if (drain) {\n try {\n await this.flush(timeoutMs);\n } catch (error: any) {\n stopError = error instanceof Error ? error : new Error(String(error));\n logger.error(`${this.instanceNameWithSuffix} - Error draining publishes before stop: ${stopError.message}`);\n }\n }\n\n if (this.worker) {\n this.expectedWorkerExit = true;\n try {\n const exitCode = await this.worker.terminate();\n logger.info(`${this.instanceNameWithSuffix} - Worker terminated with exit code ${exitCode}`);\n } catch (error: any) {\n const terminationError = error instanceof Error ? error : new Error(String(error));\n logger.error(`${this.instanceNameWithSuffix} - Error terminating worker: ${terminationError.message}`);\n stopError ??= terminationError;\n }\n }\n\n this.lifecycleState = \"stopped\";\n this.rejectOutstandingPublishes(stopError ?? new Error(\"UnsProxy has been stopped\"));\n\n if (stopError) {\n throw stopError;\n }\n }\n\n private failPendingPublishes(reason: Error): void {\n this.workerFailure = reason;\n this.rejectOutstandingPublishes(reason);\n }\n\n private rejectOutstandingPublishes(reason: Error): void {\n for (const pending of this.pendingEnqueues.values()) {\n pending.reject(reason);\n }\n this.pendingEnqueues.clear();\n this.pendingPublishCompletions.clear();\n\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.reject(reason);\n }\n }\n\n private notifyDrainWaiters(): void {\n if (this.workerFailure) {\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.reject(this.workerFailure);\n }\n return;\n }\n if (this.pendingEnqueues.size !== 0 || this.pendingPublishCompletions.size !== 0) {\n return;\n }\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.resolve();\n }\n }\n\n private removeDrainWaiter(waiterToRemove: { resolve: () => void; reject: (reason?: any) => void; timer?: NodeJS.Timeout }): void {\n this.drainWaiters = this.drainWaiters.filter((waiter) => waiter !== waiterToRemove);\n }\n\n}\n"]}
1
+ {"version":3,"file":"uns-mqtt-proxy.js","sourceRoot":"","sources":["../../src/uns-mqtt/uns-mqtt-proxy.ts"],"names":[],"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AC,aAAa,CAAC,CAAC;YACpC,CAAC;YACD,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,KAAK,CAAC,IAAI,IAAI,CAAC,yBAAyB,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;YACjF,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC5C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7B,CAAC;YACD,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,CAAC;IACH,CAAC;IAEO,iBAAiB,CAAC,cAA+F;QACvH,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,cAAc,CAAC,CAAC;IACtF,CAAC","sourcesContent":["import { readFileSync } from \"fs\";\nimport { IClientPublishOptions } from \"mqtt\";\nimport * as path from \"path\";\nimport { Worker } from \"worker_threads\";\nimport { fileURLToPath } from \"url\";\nimport { basePath } from \"../base-path.js\";\nimport logger from \"../logger.js\";\nimport { IMqttPublishRequest, IUnsLifecycleMetadata, IUnsMessage, IUnsPacket, IUnsParameters, IUnsRelationshipEvidenceMetadata, IUnsTableColumnMetadata, UnsAttribute, UnsAttributeSystemRole, UnsEvents, ValueType } from \"../uns/uns-interfaces.js\";\nimport { getObjectTypeDescription, type UnsObjectId, type UnsObjectType } from \"../uns/uns-object.js\";\nimport type { UnsAsset } from \"../uns/uns-asset.js\";\nimport { MeasurementUnit } from \"../uns/uns-measurements.js\";\nimport { UnsPacket } from \"../uns/uns-packet.js\";\nimport { IMqttParameters, IMqttWorkerData } from \"./mqtt-interfaces.js\";\nimport { MqttTopicBuilder } from \"./mqtt-topic-builder.js\";\nimport UnsProxy from \"../uns/uns-proxy.js\";\nimport { UnsAttributeType } from \"../graphql/schema.js\";\nimport { getAttributeDescription } from \"../uns/uns-attributes.js\";\nimport { UnsTags } from \"../uns/uns-tags.js\";\nimport { UnsTopics } from \"../uns/uns-topics.js\";\n\nconst packageJsonPath = path.join(basePath, \"package.json\");\nconst packageJson = JSON.parse(readFileSync(packageJsonPath, \"utf8\"));\n\nconst moduleDirectory = path.dirname(fileURLToPath(import.meta.url));\nconst packageRoot = path.resolve(moduleDirectory, \"..\", \"..\");\nconst workerScriptPath = path.join(packageRoot, \"dist/uns-mqtt/mqtt-worker-init.js\");\n\nexport enum MessageMode {\n Raw = 'raw', // Send only the original message\n /**\n * @deprecated Producer-side delta calculation loses state across restarts.\n * Publish raw cumulative counter values and request delta/rate from Datahub history APIs.\n */\n Delta = 'delta', // Send only the delta message\n /**\n * @deprecated Producer-side delta calculation loses state across restarts.\n * Publish raw cumulative counter values and request delta/rate from Datahub history APIs.\n */\n Both = 'both' // Send both the original and delta messages\n}\n\nexport interface UnsMqttProxyStopOptions {\n drain?: boolean;\n timeoutMs?: number;\n}\n\ntype UnsMqttProxyLifecycleState = \"running\" | \"stopping\" | \"stopped\";\n\ntype InternalMqttMessage = {\n topic: UnsTopics;\n attribute: UnsAttribute;\n asset: UnsAsset;\n assetDescription?: string;\n assetStableEntityId?: string;\n assetDisplayName?: string;\n assetIdentityProof?: string;\n objectType: UnsObjectType;\n objectTypeDescription?: string;\n objectId: UnsObjectId;\n virtualGroup?: string;\n description?: string;\n tags?: UnsTags[];\n attributeNeedsPersistence?: boolean | null;\n valueType?: string;\n presentationKind?: string;\n defaultAggregation?: string;\n counterResetPolicy?: string;\n tableColumns?: IUnsTableColumnMetadata[];\n systemRole?: UnsAttributeSystemRole;\n relationshipEvidence?: IUnsRelationshipEvidenceMetadata;\n lifecycle?: IUnsLifecycleMetadata;\n validityMode?: \"interval\" | \"lifecycle\" | \"static\";\n expectedIntervalMs?: number;\n lifecycleEndValue?: string;\n packet: IUnsPacket;\n};\n\nexport default class UnsMqttProxy extends UnsProxy {\n public static readonly DEFAULT_DRAIN_TIMEOUT_MS = 30_000;\n private lastValues: Map<string, { value: ValueType; uom: string; timestamp: Date }> = new Map();\n private worker: Worker;\n private pendingEnqueues: Map<string, { resolve: () => void; reject: (reason?: any) => void }> = new Map();\n private pendingPublishCompletions = new Set<string>();\n private unsParameters: IUnsParameters;\n protected processStatusTopic: string;\n public instanceName: string;\n private currentSequenceId: Map<string, number> = new Map();\n private topicBuilder: MqttTopicBuilder;\n private deltaModeDeprecationWarned = false;\n private drainWaiters: Array<{ resolve: () => void; reject: (reason?: any) => void; timer?: NodeJS.Timeout }> = [];\n private workerFailure: Error | null = null;\n private lifecycleState: UnsMqttProxyLifecycleState = \"running\";\n private stopPromise: Promise<void> | null = null;\n private expectedWorkerExit = false;\n\n constructor(\n mqttHost: string,\n processName: string,\n instanceName: string,\n unsParameters?: IUnsParameters,\n publisherActive: boolean = false,\n subscriberActive: boolean = false\n ) {\n super();\n this.instanceName = instanceName;\n // Create the topic builder using packageJson values and the processName.\n this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageJson.name)}/${MqttTopicBuilder.sanitizeTopicPart(packageJson.version)}/${MqttTopicBuilder.sanitizeTopicPart(processName)}/`);\n\n // Generate the processStatusTopic using the builder.\n this.processStatusTopic = this.topicBuilder.getProcessStatusTopic();\n // Derive the instanceStatusTopic by appending the instance name.\n this.instanceStatusTopic = this.processStatusTopic + instanceName + \"/\";\n\n // Concatenate processName with instanceName for the worker identification.\n this.instanceNameWithSuffix = `${processName}-${instanceName}`;\n \n const mqttParameters: IMqttParameters = {\n mqttSubToTopics: unsParameters?.mqttSubToTopics ?? [],\n username: unsParameters?.username ?? \"\",\n password: unsParameters?.password ?? \"\",\n mqttSSL: unsParameters?.mqttSSL ?? false,\n statusTopic: this.instanceStatusTopic,\n rejectUnauthorized: unsParameters?.rejectUnauthorized ?? false,\n clientId: unsParameters?.clientId,\n hosts: unsParameters?.hosts,\n servers: unsParameters?.servers,\n port: unsParameters?.port,\n protocol: unsParameters?.protocol,\n keepalive: unsParameters?.keepalive,\n clean: unsParameters?.clean,\n connectTimeout: unsParameters?.connectTimeout,\n reconnectPeriod: unsParameters?.reconnectPeriod,\n reconnectOnConnackError: unsParameters?.reconnectOnConnackError,\n resubscribe: unsParameters?.resubscribe,\n queueQoSZero: unsParameters?.queueQoSZero,\n properties: unsParameters?.properties,\n ca: unsParameters?.ca,\n cert: unsParameters?.cert,\n key: unsParameters?.key,\n servername: unsParameters?.servername,\n };\n this.unsParameters = unsParameters ?? {};\n this.startQueueWorker(mqttHost, this.instanceNameWithSuffix, mqttParameters, publisherActive, subscriberActive);\n }\n\n /**\n * Resolve object identity from explicit fields or the tail of the topic path.\n * Falls back to parsing when not provided for backward compatibility.\n */\n private resolveObjectIdentity(msg: InternalMqttMessage): { objectType?: UnsObjectType; objectId?: UnsObjectId; asset?: UnsAsset } {\n const providedType = msg.objectType;\n const providedId = msg.objectId;\n const providedAsset = msg.asset;\n\n const topicParts = msg.topic.split(\"/\").filter((part) => part.length > 0);\n const hasObjectTail = topicParts.length >= 2;\n const parsedType = hasObjectTail ? topicParts[topicParts.length - 2] as UnsObjectType : undefined;\n const parsedId = hasObjectTail ? topicParts[topicParts.length - 1] as UnsObjectId : undefined;\n const parsedAsset = hasObjectTail\n ? (topicParts.length >= 3 ? topicParts[topicParts.length - 3] as UnsAsset : undefined)\n : (topicParts.length >= 1 ? topicParts[topicParts.length - 1] as UnsAsset : undefined);\n\n const objectType = providedType ?? parsedType;\n const objectId = providedId ?? parsedId ?? \"main\";\n const asset = providedAsset ?? parsedAsset;\n\n // If values are provided, trust them; otherwise derive from topic.\n if (!providedType || !providedId) {\n if (parsedType && parsedId) {\n logger.warn(`${this.instanceNameWithSuffix} - objectType/objectId missing; derived from topic tail ${parsedType}/${parsedId}`);\n } else {\n logger.warn(`${this.instanceNameWithSuffix} - objectType/objectId missing; defaulting objectId to 'main' for topic '${msg.topic}'. Expected topic to end with '<objectType>/<objectId>/'`);\n }\n }\n // Asset is optional; no warning on mismatch to avoid noisy logs when base topics don't carry it.\n\n msg.objectType = objectType;\n msg.objectId = objectId;\n msg.asset = asset;\n\n return { objectType, objectId, asset };\n }\n\n /**\n * Ensure the topic ends with a trailing slash for attribute concatenation.\n */\n private normalizeTopicWithObject(topic: string): string {\n return topic.endsWith(\"/\") ? topic : `${topic}/`;\n }\n\n /**\n * Starts a worker thread to process the throttled publish queue.\n */\n private startQueueWorker(\n mqttHost: string,\n instanceNameWithSuffix: string,\n mqttParameters: IMqttParameters,\n publisherActive: boolean,\n subscriberActive: boolean\n ): void {\n const workerData: IMqttWorkerData = {\n publishThrottlingDelay: this.unsParameters.publishThrottlingDelay ?? 1,\n publishConcurrency: this.unsParameters.publishConcurrency ?? 1,\n maxPendingPublishes: this.unsParameters.maxPendingPublishes,\n subscribeThrottlingDelay: this.unsParameters.subscribeThrottlingDelay ?? 1,\n persistToDisk: false,\n mqttHost: mqttHost,\n instanceNameWithSuffix: instanceNameWithSuffix,\n mqttParameters: mqttParameters,\n publisherActive,\n subscriberActive,\n defaultPublishOptions: this.unsParameters.defaultPublishOptions,\n };\n\n this.worker = new Worker(workerScriptPath, { workerData });\n\n this.worker.on(\"message\", (msg) => {\n if (msg && msg.command === \"enqueueAccepted\" && msg.id) {\n const pending = this.pendingEnqueues.get(msg.id);\n if (pending) {\n this.pendingEnqueues.delete(msg.id);\n if (msg.status === \"accepted\") {\n this.pendingPublishCompletions.add(msg.id);\n pending.resolve();\n } else {\n pending.reject(new Error(msg.error));\n }\n this.notifyDrainWaiters();\n }\n } else if (msg && msg.command === \"publishResult\" && msg.id) {\n this.pendingPublishCompletions.delete(msg.id);\n if (msg.status === \"error\") {\n const errorMessage = msg.error ?? `Error publishing to topic ${msg.topic ?? \"unknown\"}`;\n this.event.emit(\"error\", { code: 0, message: errorMessage });\n }\n this.notifyDrainWaiters();\n } else if (msg && msg.command === \"input\") {\n this.event.emit(\"input\", { topic: msg.topic, message: msg.message.toString(), packet: msg.packet });\n } else if (msg && (msg.command === \"handover_subscriber\" || msg.command === \"handover_publisher\")) {\n this.event.emit(\"mqttWorker\", { command: msg.command, batchSize: msg.batchSize, referenceHash: msg.referenceHash, instanceName: this.instanceName });\n } else if (msg && msg.command === \"mqttProxyStatus\") {\n this.event.emit(\"mqttProxyStatus\", { event: msg.event, value: msg.value, uom: msg.uom, statusTopic: msg.statusTopic });\n }\n });\n\n this.worker.on(\"error\", (err) => {\n if (this.expectedWorkerExit) {\n return;\n }\n logger.error(\"Error in worker:\", err);\n const reason = err instanceof Error ? err : new Error(String(err));\n this.failPendingPublishes(reason);\n });\n\n this.worker.on(\"exit\", (code) => {\n if (this.expectedWorkerExit) {\n return;\n }\n logger.error(`Worker exited unexpectedly with code ${code}`);\n const reason = new Error(`MQTT worker exited unexpectedly with code ${code}`);\n this.failPendingPublishes(reason);\n });\n }\n\n /**\n * Enqueues a message to the worker queue.\n *\n * @param topic - The topic to which the message belongs.\n * @param message - The message to be enqueued.\n * @param options - Optional publish options.\n * @returns A promise that resolves when the message is accepted into the worker queue.\n */\n private async enqueueMessageToWorkerQueue(topic: string, message: string, options?: IClientPublishOptions): Promise<void> {\n return new Promise((resolve, reject) => {\n if (this.lifecycleState !== \"running\") {\n reject(new Error(`${this.instanceNameWithSuffix} - MQTT proxy is ${this.lifecycleState}; publish rejected.`));\n return;\n }\n if (this.workerFailure) {\n reject(this.workerFailure);\n return;\n }\n const maxPendingPublishes = this.unsParameters.maxPendingPublishes;\n const pendingCount = this.pendingEnqueues.size + this.pendingPublishCompletions.size;\n if (maxPendingPublishes !== undefined && pendingCount >= maxPendingPublishes) {\n reject(new Error(`${this.instanceNameWithSuffix} - Publisher queue is full (${maxPendingPublishes}).`));\n return;\n }\n const id = `${Date.now()}-${Math.random()}`;\n this.pendingEnqueues.set(id, { resolve, reject });\n try {\n this.worker.postMessage({ command: \"enqueue\", id, topic, message, options });\n } catch (error) {\n this.pendingEnqueues.delete(id);\n reject(error);\n }\n this.notifyDrainWaiters();\n });\n }\n\n /**\n * Sets the publisher active state.\n *\n * @param batchSize - Optional batch size.\n * @param referenceHash - Optional reference hash.\n */\n public setPublisherActive(batchSize?: number, referenceHash?: string): void {\n this.worker.postMessage({ command: \"setPublisherActive\", batchSize, referenceHash });\n }\n\n /**\n * Sets the publisher to passive mode.\n * @returns A promise that resolves when the publisher is set to passive.\n */\n public setPublisherPassive(): Promise<UnsEvents[\"mqttWorker\"]> {\n this.worker.postMessage({ command: \"setPublisherPassive\"});\n return new Promise((resolve) => {\n const handler = (msg: UnsEvents[\"mqttWorker\"]) => {\n if (msg.command === \"handover_publisher\") {\n this.event.off(\"mqttWorker\", handler);\n logger.info(`${this.instanceNameWithSuffix} - Publisher set to passive.`);\n resolve(msg);\n }\n };\n this.event.on(\"mqttWorker\", handler);\n });\n }\n\n /**\n * Sets the subscriber active state.\n *\n * @param batchSize - Optional batch size.\n * @param referenceHash - Optional reference hash.\n */\n public setSubscriberActive(batchSize?: number, referenceHash?: string): void {\n this.worker.postMessage({ command: \"setSubscriberActive\", batchSize, referenceHash });\n }\n\n /**\n * Sets the subscriber to passive mode.\n * @returns A promise that resolves when the subscriber is set to passive.\n */\n public setSubscriberPassive(): Promise<UnsEvents[\"mqttWorker\"]> {\n this.worker.postMessage({ command: \"setSubscriberPassive\"});\n return new Promise((resolve) => {\n const handler = (msg: UnsEvents[\"mqttWorker\"]) => {\n if (msg.command === \"handover_subscriber\") {\n this.event.off(\"mqttWorker\", handler);\n logger.info(`${this.instanceNameWithSuffix} - Subscriber set to passive.`);\n resolve(msg);\n }\n };\n this.event.on(\"mqttWorker\", handler);\n });\n }\n\n\n /**\n * Sets the subscriber to passive mode and allows the publisher to run\n * until the queue is empty (all messages are processed).\n */\n public async setSubscriberPassiveAndDrainQueue(): Promise<UnsEvents[\"mqttWorker\"]> {\n const mqttWorkerData = await this.setSubscriberPassive();\n await this.flush();\n logger.info(`${this.instanceNameWithSuffix} - Subscriber set to passive and queue drained.`);\n return mqttWorkerData;\n }\n\n public async drainPublishes(timeoutMs: number = UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS): Promise<void> {\n if (this.workerFailure) {\n throw this.workerFailure;\n }\n if (this.pendingEnqueues.size === 0 && this.pendingPublishCompletions.size === 0) {\n return;\n }\n await new Promise<void>((resolve, reject) => {\n const waiter = { resolve, reject, timer: undefined as NodeJS.Timeout | undefined };\n if (Number.isFinite(timeoutMs) && timeoutMs > 0) {\n waiter.timer = setTimeout(() => {\n this.removeDrainWaiter(waiter);\n reject(new Error(`Timed out waiting for MQTT publishes to drain after ${timeoutMs}ms.`));\n }, timeoutMs);\n }\n this.drainWaiters.push(waiter);\n this.notifyDrainWaiters();\n });\n }\n\n public async flush(timeoutMs: number = UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS): Promise<void> {\n await this.drainPublishes(timeoutMs);\n }\n\n /**\n * Processes and publishes MQTT messages based on the selected message mode.\n *\n * @param mqttMessage - The MQTT message object.\n * @param mode - The message mode. Delta and Both are deprecated because\n * producer-side delta calculation loses state across restarts.\n */\n public async publishMqttMessage(mqttMessage: IMqttPublishRequest | null, mode: MessageMode = MessageMode.Raw) {\n if (!mqttMessage) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing mqtt message: mqttMessage must be defined.`);\n return;\n }\n\n const attrs = Array.isArray(mqttMessage.attributes)\n ? mqttMessage.attributes\n : [mqttMessage.attributes];\n const {\n topic,\n asset,\n assetDescription,\n assetStableEntityId,\n assetDisplayName,\n assetIdentityProof,\n objectType,\n objectTypeDescription,\n objectId,\n virtualGroup: requestVirtualGroup,\n } = mqttMessage;\n const hasAssetIdentityMetadata = assetStableEntityId !== undefined\n || assetDisplayName !== undefined\n || assetIdentityProof !== undefined;\n if (hasAssetIdentityMetadata) {\n if (\n typeof assetStableEntityId !== \"string\"\n || !assetStableEntityId.trim()\n || typeof assetIdentityProof !== \"string\"\n || !assetIdentityProof.trim()\n || (assetDisplayName !== undefined\n && (typeof assetDisplayName !== \"string\" || !assetDisplayName.trim()))\n ) {\n throw new Error(\"Asset identity metadata requires assetStableEntityId and assetIdentityProof; assetDisplayName must be non-empty when supplied.\");\n }\n }\n for (const attrEntry of attrs) {\n const attrDescription = attrEntry.description ?? getAttributeDescription(attrEntry.attribute);\n const message: IUnsMessage =\n \"message\" in attrEntry && attrEntry.message\n ? attrEntry.message\n : \"data\" in attrEntry && attrEntry.data\n ? { data: attrEntry.data, createdAt: attrEntry.createdAt, expiresAt: attrEntry.expiresAt }\n : \"table\" in attrEntry && attrEntry.table\n ? { table: attrEntry.table, createdAt: attrEntry.createdAt, expiresAt: attrEntry.expiresAt }\n : (() => { throw new Error(\"Attribute entry must include exactly one of data/table/message\"); })();\n const packet = await UnsPacket.unsPacketFromUnsMessage(message);\n const singleMsg: InternalMqttMessage = {\n topic,\n asset,\n assetDescription,\n ...(hasAssetIdentityMetadata ? {\n assetStableEntityId: assetStableEntityId!.trim().toLowerCase(),\n ...(assetDisplayName ? { assetDisplayName: assetDisplayName.trim() } : {}),\n assetIdentityProof: assetIdentityProof!.trim(),\n } : {}),\n objectType,\n objectTypeDescription,\n objectId,\n virtualGroup: attrEntry.virtualGroup ?? requestVirtualGroup,\n attribute: attrEntry.attribute,\n description: attrDescription,\n tags: attrEntry.tags,\n attributeNeedsPersistence: attrEntry.attributeNeedsPersistence,\n valueType: attrEntry.valueType,\n presentationKind: attrEntry.presentationKind,\n defaultAggregation: attrEntry.defaultAggregation,\n counterResetPolicy: attrEntry.counterResetPolicy,\n tableColumns: attrEntry.tableColumns,\n systemRole: attrEntry.systemRole,\n relationshipEvidence: attrEntry.relationshipEvidence,\n lifecycle: attrEntry.lifecycle,\n ...(attrEntry.validityMode ? { validityMode: attrEntry.validityMode } : {}),\n ...(attrEntry.expectedIntervalMs ? { expectedIntervalMs: attrEntry.expectedIntervalMs } : {}),\n ...(attrEntry.lifecycleEndValue ? { lifecycleEndValue: attrEntry.lifecycleEndValue } : {}),\n packet,\n };\n\n // existing single-attribute flow\n const baseDescription =\n singleMsg.description ??\n getAttributeDescription(singleMsg.attribute) ??\n singleMsg.attribute;\n const mqttMessageWithDesc = { ...singleMsg, description: baseDescription };\n\n const time = UnsPacket.formatToISO8601(new Date());\n if (mode === MessageMode.Delta || mode === MessageMode.Both) {\n this.warnDeprecatedDeltaMode(mode);\n }\n switch (mode) {\n case MessageMode.Raw: {\n await this.processAndEnqueueMessage(mqttMessageWithDesc, time, false);\n break;\n }\n case MessageMode.Delta: {\n const deltaMessage = { ...mqttMessageWithDesc };\n deltaMessage.attribute = `${mqttMessageWithDesc.attribute}-delta`;\n deltaMessage.description = `${baseDescription ?? \"\"} (delta)`;\n await this.processAndEnqueueMessage(deltaMessage, time, true);\n break;\n }\n case MessageMode.Both: {\n await this.processAndEnqueueMessage(mqttMessageWithDesc, time, false);\n const deltaMessageBoth = { ...mqttMessageWithDesc };\n deltaMessageBoth.attribute = `${mqttMessageWithDesc.attribute}-delta`;\n deltaMessageBoth.description = `${baseDescription ?? \"\"} (delta)`;\n await this.processAndEnqueueMessage(deltaMessageBoth, time, true);\n break;\n }\n }\n }\n return;\n }\n\n private warnDeprecatedDeltaMode(mode: MessageMode): void {\n if (this.deltaModeDeprecationWarned) return;\n this.deltaModeDeprecationWarned = true;\n logger.warn(\n `${this.instanceNameWithSuffix} - MessageMode.${mode} is deprecated: producer-side delta calculation loses previous-value state across service restarts. Publish raw cumulative counter values and request delta/rate from Datahub history APIs.`,\n );\n }\n\n /**\n * Publishes a message to a specified topic.\n *\n * @param topic - The MQTT topic.\n * @param message - The message to publish.\n * @returns A promise that resolves when the message is accepted into the worker queue.\n */\n public publishMessage(topic: string, message: string, options?: IClientPublishOptions): Promise<void> {\n return this.enqueueMessageToWorkerQueue(topic, message, options);\n }\n\n /**\n * Parses an MQTT packet from a JSON string.\n *\n * @param mqttPacket - The MQTT packet string.\n * @returns A parsed IUnsPacket object or null.\n */\n public parseMqttPacket(mqttPacket: string): IUnsPacket | null {\n return UnsPacket.parseMqttPacket(mqttPacket, this.instanceNameWithSuffix);\n }\n\n /**\n * Subscribes asynchronously to one or more topics.\n *\n * @param topics - A topic or list of topics.\n */\n public subscribeAsync(topics: string | string[]): void {\n this.worker.postMessage({ command: \"subscribeAsync\", topics });\n }\n\n /**\n * Unsubscribes asynchronously from the given topics.\n *\n * @param topics - A list of topics.\n */\n public unsubscribeAsync(topics: string[]): void {\n this.worker.postMessage({ command: \"unsubscribeAsync\", topics });\n }\n\n /**\n * Processes and enqueues a message to the worker queue, including handling\n * sequencing, value differences, and tracking of unique topics.\n *\n * @param msg - The MQTT message to process.\n * @param time - The timestamp.\n * @param valueIsCumulative - Whether the value is cumulative.\n */\n private async processAndEnqueueMessage(msg: InternalMqttMessage, time: string, valueIsCumulative: boolean = false): Promise<void> {\n try {\n const attributeType =\n msg.packet.message.data ? UnsAttributeType.Data :\n msg.packet.message.table ? UnsAttributeType.Table : null;\n \n let dataGroup = \"\";\n if (attributeType == UnsAttributeType.Data)\n dataGroup = msg.packet.message.data.dataGroup ?? \"\";\n if (attributeType == UnsAttributeType.Table)\n dataGroup = msg.packet.message.table.dataGroup ?? \"\";\n\n const { objectType, objectId, asset } = this.resolveObjectIdentity(msg);\n const normalizedTopic = this.normalizeTopicWithObject(msg.topic);\n msg.topic = normalizedTopic;\n const description = msg.description ?? getAttributeDescription(msg.attribute as string) ?? \"\";\n const objectTypeDescription = msg.objectTypeDescription ?? (objectType ? getObjectTypeDescription(objectType) : undefined);\n\n // Runtime validation for validity fields\n if (msg.validityMode) {\n const validModes = new Set([\"interval\", \"lifecycle\", \"static\"]);\n if (!validModes.has(msg.validityMode)) {\n logger.warn(`${this.instanceNameWithSuffix} - Invalid validityMode \"${msg.validityMode}\" for attribute \"${msg.attribute}\". Expected: interval | lifecycle | static.`);\n }\n if (msg.expectedIntervalMs && msg.validityMode !== \"interval\") {\n logger.warn(`${this.instanceNameWithSuffix} - expectedIntervalMs is set but validityMode is \"${msg.validityMode}\" (only used with \"interval\") for attribute \"${msg.attribute}\".`);\n }\n if (msg.lifecycleEndValue && msg.validityMode !== \"lifecycle\") {\n logger.warn(`${this.instanceNameWithSuffix} - lifecycleEndValue is set but validityMode is \"${msg.validityMode}\" (only used with \"lifecycle\") for attribute \"${msg.attribute}\".`);\n }\n if (msg.validityMode === \"interval\" && !msg.expectedIntervalMs) {\n logger.debug(`${this.instanceNameWithSuffix} - validityMode \"interval\" without expectedIntervalMs for attribute \"${msg.attribute}\" — controller will use its default.`);\n }\n }\n\n this.registerUniqueTopic({\n timestamp: time,\n topic: msg.topic,\n attribute: msg.attribute,\n attributeType: attributeType,\n description,\n tags: msg.tags,\n attributeNeedsPersistence: msg.attributeNeedsPersistence,\n valueType: msg.valueType,\n presentationKind: msg.presentationKind,\n defaultAggregation: msg.defaultAggregation,\n counterResetPolicy: msg.counterResetPolicy,\n tableColumns: msg.tableColumns,\n systemRole: msg.systemRole,\n relationshipEvidence: msg.relationshipEvidence,\n lifecycle: msg.lifecycle,\n dataGroup,\n virtualGroup: msg.virtualGroup,\n asset,\n assetDescription: msg.assetDescription,\n assetStableEntityId: msg.assetStableEntityId,\n assetDisplayName: msg.assetDisplayName,\n assetIdentityProof: msg.assetIdentityProof,\n objectType,\n objectTypeDescription,\n objectId,\n ...(msg.validityMode ? { validityMode: msg.validityMode } : {}),\n ...(msg.expectedIntervalMs ? { expectedIntervalMs: msg.expectedIntervalMs } : {}),\n ...(msg.lifecycleEndValue ? { lifecycleEndValue: msg.lifecycleEndValue } : {}),\n });\n\n const publishTopic = `${msg.topic}${asset ? `${asset}/` : \"\"}${objectType ? `${objectType}/` : \"\"}${objectId ? `${objectId}/` : \"\"}${msg.attribute}`;\n const sequenceId = this.currentSequenceId.get(msg.topic) ?? 0;\n this.currentSequenceId.set(msg.topic, sequenceId + 1);\n msg.packet.sequenceId = sequenceId;\n\n if (msg.packet.message.data) {\n const newValue = msg.packet.message.data.value;\n const newUom: MeasurementUnit = msg.packet.message.data.uom;\n const lastValueEntry = this.lastValues.get(publishTopic);\n const currentTime = new Date(msg.packet.message.data.time);\n\n if (lastValueEntry) {\n const intervalBetweenMessages = currentTime.getTime() - lastValueEntry.timestamp.getTime();\n const lastValue = lastValueEntry.value;\n this.lastValues.set(publishTopic, { value: newValue, uom: newUom, timestamp: currentTime });\n // Compute the delta and manage cumulative resets\n if (valueIsCumulative == true && typeof newValue === \"number\" && typeof lastValue === \"number\") {\n // Skip if newValue is 0 (likely a glitch)\n if (newValue === 0) {\n return; // Don't process or enqueue\n }\n const delta = newValue - lastValue;\n msg.packet.message.data.value = delta < 0 ? newValue : delta;\n }\n msg.packet.interval = intervalBetweenMessages;\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n this.lastValues.set(publishTopic, { value: newValue, uom: newUom, timestamp: currentTime });\n logger.debug(`${this.instanceNameWithSuffix} - Need one more packet to calculate interval on topic ${publishTopic}`);\n if (valueIsCumulative === false) {\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n logger.debug(`${this.instanceNameWithSuffix} - Need one more packet to calculate difference on value in data for topic ${publishTopic}`);\n }\n }\n } else if (msg.packet.message.table) {\n await this.enqueueMessageToWorkerQueue(publishTopic, JSON.stringify(msg.packet));\n } else {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing message to topic ${publishTopic}: packet.message must include data or table`);\n }\n } catch (error: any) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing message to topic ${msg.topic}${msg.attribute}: ${error.message}`);\n throw error;\n }\n }\n\n /**\n * Stops the UnsProxy instance and cleans up resources.\n */\n public stop(options: UnsMqttProxyStopOptions = {}): Promise<void> {\n if (this.stopPromise) {\n return this.stopPromise;\n }\n\n this.lifecycleState = \"stopping\";\n this.stopPromise = this.performStop(options);\n return this.stopPromise;\n }\n\n private async performStop(options: UnsMqttProxyStopOptions): Promise<void> {\n await super.stop();\n const drain = options.drain ?? true;\n const timeoutMs = options.timeoutMs ?? UnsMqttProxy.DEFAULT_DRAIN_TIMEOUT_MS;\n let stopError: Error | null = null;\n\n if (drain) {\n try {\n await this.flush(timeoutMs);\n } catch (error: any) {\n stopError = error instanceof Error ? error : new Error(String(error));\n logger.error(`${this.instanceNameWithSuffix} - Error draining publishes before stop: ${stopError.message}`);\n }\n }\n\n if (this.worker) {\n this.expectedWorkerExit = true;\n try {\n const exitCode = await this.worker.terminate();\n logger.info(`${this.instanceNameWithSuffix} - Worker terminated with exit code ${exitCode}`);\n } catch (error: any) {\n const terminationError = error instanceof Error ? error : new Error(String(error));\n logger.error(`${this.instanceNameWithSuffix} - Error terminating worker: ${terminationError.message}`);\n stopError ??= terminationError;\n }\n }\n\n this.lifecycleState = \"stopped\";\n this.rejectOutstandingPublishes(stopError ?? new Error(\"UnsProxy has been stopped\"));\n\n if (stopError) {\n throw stopError;\n }\n }\n\n private failPendingPublishes(reason: Error): void {\n this.workerFailure = reason;\n this.rejectOutstandingPublishes(reason);\n }\n\n private rejectOutstandingPublishes(reason: Error): void {\n for (const pending of this.pendingEnqueues.values()) {\n pending.reject(reason);\n }\n this.pendingEnqueues.clear();\n this.pendingPublishCompletions.clear();\n\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.reject(reason);\n }\n }\n\n private notifyDrainWaiters(): void {\n if (this.workerFailure) {\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.reject(this.workerFailure);\n }\n return;\n }\n if (this.pendingEnqueues.size !== 0 || this.pendingPublishCompletions.size !== 0) {\n return;\n }\n const waiters = this.drainWaiters.splice(0);\n for (const waiter of waiters) {\n if (waiter.timer) {\n clearTimeout(waiter.timer);\n }\n waiter.resolve();\n }\n }\n\n private removeDrainWaiter(waiterToRemove: { resolve: () => void; reject: (reason?: any) => void; timer?: NodeJS.Timeout }): void {\n this.drainWaiters = this.drainWaiters.filter((waiter) => waiter !== waiterToRemove);\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/core",
3
- "version": "3.0.15",
3
+ "version": "3.0.17",
4
4
  "description": "Core utilities and runtime building blocks for UNS-based realtime transformers.",
5
5
  "type": "module",
6
6
  "license": "MIT",