@uns-kit/core 2.0.33 → 2.0.34

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.
@@ -29,7 +29,14 @@ export default class UnsProxy {
29
29
  */
30
30
  private emitProducedApiCatchall;
31
31
  /**
32
- * Registers a unique topic so that it is tracked and published only once.
32
+ * Registers a unique topic and keeps its timestamp current.
33
+ *
34
+ * On first call the full entry is created and immediately emitted so the
35
+ * controller can persist the new schema node. On subsequent calls only the
36
+ * timestamp is updated in-place; the 60-second heartbeat interval will carry
37
+ * the updated value to the controller, making the timestamp reflect the time
38
+ * of the most recent data publication rather than the one-off registration
39
+ * moment.
33
40
  *
34
41
  * @param topicObject - The object containing topic details.
35
42
  */
@@ -1 +1 @@
1
- {"version":3,"file":"uns-proxy.d.ts","sourceRoot":"","sources":["../../src/uns/uns-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAG1D,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC3B,OAAO,CAAC,eAAe,CAA+B;IAC/C,KAAK,EAAE,eAAe,CAAC,SAAS,CAAC,CAAoC;IAC5E,SAAS,CAAC,mBAAmB,EAAE,MAAM,CAAC;IACtC,SAAS,CAAC,sBAAsB,EAAE,MAAM,CAAC;IACzC,OAAO,CAAC,cAAc,CAAwC;IAC9D,OAAO,CAAC,oBAAoB,CAAsC;IAClE,OAAO,CAAC,mBAAmB,CAA+C;IAC1E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC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CAAwC;IAC9D,OAAO,CAAC,oBAAoB,CAAsC;IAClE,OAAO,CAAC,mBAAmB,CAA+C;IAC1E,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAqB;IACvD,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAqB;;IAgB7D;;OAEG;YACW,kBAAkB;IAchC;;OAEG;YACW,wBAAwB;IAgBtC;;OAEG;YACW,uBAAuB;IAiBrC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,mBAAmB,CAAC,WAAW,EAAE,YAAY,GAAG,IAAI;IAmC9D;;OAEG;IACH,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,UAAU,GAAG,IAAI;IAoC1D,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAajE,SAAS,CAAC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAC,QAAQ,EAAE,UAAU,EAAE,aAAa,EAAE,QAAQ,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAQ5H,IAAI;CASlB"}
@@ -84,7 +84,14 @@ export default class UnsProxy {
84
84
  }
85
85
  }
86
86
  /**
87
- * Registers a unique topic so that it is tracked and published only once.
87
+ * Registers a unique topic and keeps its timestamp current.
88
+ *
89
+ * On first call the full entry is created and immediately emitted so the
90
+ * controller can persist the new schema node. On subsequent calls only the
91
+ * timestamp is updated in-place; the 60-second heartbeat interval will carry
92
+ * the updated value to the controller, making the timestamp reflect the time
93
+ * of the most recent data publication rather than the one-off registration
94
+ * moment.
88
95
  *
89
96
  * @param topicObject - The object containing topic details.
90
97
  */
@@ -105,11 +112,16 @@ export default class UnsProxy {
105
112
  assetDescription: topicObject.assetDescription,
106
113
  objectType: topicObject.objectType,
107
114
  objectTypeDescription: topicObject.objectTypeDescription,
108
- objectId: topicObject.objectId
115
+ objectId: topicObject.objectId,
109
116
  });
110
117
  this.emitProducedTopics();
111
118
  logger.info(`${this.instanceNameWithSuffix} - Registered new topic: ${fullTopic}`);
112
119
  }
120
+ else {
121
+ // Already registered — refresh only the timestamp so the periodic
122
+ // heartbeat reflects actual data flow rather than frozen startup time.
123
+ this.producedTopics.get(fullTopic).timestamp = topicObject.timestamp;
124
+ }
113
125
  }
114
126
  }
115
127
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"uns-proxy.js","sourceRoot":"","sources":["../../src/uns/uns-proxy.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,CAAC,OAAO,OAAO,QAAQ;IACnB,eAAe,GAA0B,IAAI,CAAC;IAC/C,KAAK,GAA+B,IAAI,eAAe,EAAa,CAAC;IAClE,mBAAmB,CAAS;IAC5B,sBAAsB,CAAS,CAAC,UAAU;IAC5C,cAAc,GAA8B,IAAI,GAAG,EAAE,CAAC;IACtD,oBAAoB,GAA4B,IAAI,GAAG,EAAE,CAAC;IAC1D,mBAAmB,GAAqC,IAAI,GAAG,EAAE,CAAC;IACzD,iBAAiB,CAAqB;IACtC,iBAAiB,CAAqB;IACtC,iBAAiB,CAAqB;IACtC,uBAAuB,CAAqB;IAE7D;QACE,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,CAAC,iBAAiB,GAAG,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC5D,IAAI,CAAC,uBAAuB;YAC1B,OAAO,CAAC,GA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AAC,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC5C,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,sBAAsB,iCAAiC,SAAS,EAAE,CAAC,CAAC;QAC1F,CAAC;IACH,CAAC;IACM,KAAK,CAAC,IAAI;QACf,iCAAiC;QACjC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,aAAa,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACpC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC9B,CAAC;IAEH,CAAC;CAEF","sourcesContent":["import { IApiObject, ITopicObject, UnsEvents } from \"./uns-interfaces.js\";\nimport logger from \"../logger.js\";\nimport { UnsEventEmitter } from \"./uns-event-emitter.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\nimport { UnsAsset } from \"./uns-asset.js\";\nimport { UnsObjectId, UnsObjectType } from \"./uns-object.js\";\nimport { IApiCatchallMapping } from \"./uns-interfaces.js\";\nimport { buildUnsIdentityPath } from \"./uns-path.js\";\n\nexport default class UnsProxy {\n private publishInterval: NodeJS.Timeout | null = null;\n public event: UnsEventEmitter<UnsEvents> = new UnsEventEmitter<UnsEvents>();\n protected instanceStatusTopic: string;\n protected instanceNameWithSuffix: string; //was prot\n private producedTopics: Map<string, ITopicObject> = new Map();\n private producedApiEndpoints: Map<string, IApiObject> = new Map();\n private producedApiCatchall: Map<string, IApiCatchallMapping> = new Map();\n private readonly controllerNameEnv: string | undefined;\n private readonly controllerHostEnv: string | undefined;\n private readonly controllerPortEnv: string | undefined;\n private readonly controllerPublicBaseEnv: string | undefined;\n\n constructor() {\n this.controllerNameEnv = process.env[\"UNS_CONTROLLER_NAME\"];\n this.controllerHostEnv = process.env[\"UNS_CONTROLLER_HOST\"];\n this.controllerPortEnv = process.env[\"UNS_CONTROLLER_PORT\"];\n this.controllerPublicBaseEnv =\n process.env[\"UNS_CONTROLLER_PUBLIC_BASE\"] ?? process.env[\"UNS_PUBLIC_BASE\"];\n // Set up interval to publish produced topics every 60 seconds.\n this.publishInterval = setInterval(() => {\n this.emitProducedTopics();\n this.emitProducedApiEndpoints();\n this.emitProducedApiCatchall();\n }, 60000); \n }\n \n /**\n * Publishes the list of produced topics to the MQTT broker.\n */\n private async emitProducedTopics(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const topicsArray = [...this.producedTopics.values()];\n if (topicsArray.length > 0) {\n try {\n this.event.emit(\"unsProxyProducedTopics\", { producedTopics: topicsArray, statusTopic: this.instanceStatusTopic + \"topics\" });\n } catch (error) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing produced topics: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published produced topics.`);\n }\n }\n }\n\n /**\n * Publishes the list of produced API endpoints to the MQTT broker.\n */\n private async emitProducedApiEndpoints(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const apiEndpointsArray = [...this.producedApiEndpoints.values()];\n if (apiEndpointsArray.length > 0) {\n try {\n if (apiEndpointsArray.length > 0) {\n this.event.emit(\"unsProxyProducedApiEndpoints\", { producedApiEndpoints: apiEndpointsArray, statusTopic: this.instanceStatusTopic + \"api-endpoints\" });\n }\n } catch (error) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing produced API endpoints: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published produced API endpoints.`);\n }\n }\n }\n\n /**\n * Publishes the list of catch-all API mappings to the MQTT broker.\n */\n private async emitProducedApiCatchall(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const catchallArray = [...this.producedApiCatchall.values()];\n if (catchallArray.length > 0) {\n try {\n this.event.emit(\"unsProxyProducedApiCatchAll\", {\n producedCatchall: catchallArray,\n statusTopic: this.instanceStatusTopic + \"api-catchall\",\n });\n } catch (error: any) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing catch-all API mappings: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published catch-all API mappings.`);\n }\n }\n }\n\n /**\n * Registers a unique topic so that it is tracked and published only once.\n *\n * @param topicObject - The object containing topic details.\n */\n protected registerUniqueTopic(topicObject: ITopicObject): void {\n if (this.instanceStatusTopic !== \"\") {\n const fullTopic = buildUnsIdentityPath(\n topicObject.topic,\n topicObject.asset,\n topicObject.objectType,\n topicObject.objectId,\n topicObject.attribute,\n );\n if (!this.producedTopics.has(fullTopic)) {\n this.producedTopics.set(fullTopic, {\n timestamp: topicObject.timestamp,\n topic: topicObject.topic,\n attribute: topicObject.attribute,\n attributeType: topicObject.attributeType,\n description: topicObject.description,\n tags: topicObject.tags,\n attributeNeedsPersistence: topicObject.attributeNeedsPersistence ?? true,\n dataGroup: topicObject.dataGroup ?? \"\",\n asset: topicObject.asset,\n assetDescription: topicObject.assetDescription,\n objectType: topicObject.objectType,\n objectTypeDescription: topicObject.objectTypeDescription,\n objectId: topicObject.objectId\n });\n this.emitProducedTopics();\n logger.info(`${this.instanceNameWithSuffix} - Registered new topic: ${fullTopic}`);\n }\n }\n } \n\n /**\n * Registers an API endpoint to handle requests for a specific topic and attribute.\n */\n protected registerApiEndpoint(apiObject: IApiObject): void {\n if (this.instanceStatusTopic !== \"\") {\n const fullTopic = buildUnsIdentityPath(\n apiObject.topic,\n apiObject.asset,\n apiObject.objectType,\n apiObject.objectId,\n apiObject.attribute,\n );\n if (!this.producedApiEndpoints.has(fullTopic)) {\n const time = UnsPacket.formatToISO8601(new Date());\n this.producedApiEndpoints.set(fullTopic, {\n timestamp: time,\n topic: apiObject.topic,\n attribute: apiObject.attribute,\n apiHost: apiObject.apiHost,\n apiEndpoint: apiObject.apiEndpoint,\n apiMethod: apiObject.apiMethod,\n apiQueryParams: apiObject.apiQueryParams,\n apiDescription: apiObject.apiDescription,\n attributeType: apiObject.attributeType,\n apiSwaggerEndpoint: apiObject.apiSwaggerEndpoint,\n asset: apiObject.asset,\n objectType: apiObject.objectType,\n objectId: apiObject.objectId,\n ...(this.controllerNameEnv ? { controllerName: this.controllerNameEnv } : {}),\n ...(this.controllerHostEnv ? { controllerHost: this.controllerHostEnv } : {}),\n ...(this.controllerPortEnv ? { controllerPort: this.controllerPortEnv } : {}),\n ...(this.controllerPublicBaseEnv ? { controllerPublicBase: this.controllerPublicBaseEnv } : {}),\n });\n this.emitProducedApiEndpoints();\n logger.info(`${this.instanceNameWithSuffix} - Registered new api endpoint: /${fullTopic}`);\n }\n }\n }\n\n protected registerApiCatchAll(mapping: IApiCatchallMapping): void {\n if (this.instanceStatusTopic !== \"\") {\n const key = mapping.topic.replace(/\\/+$/, \"\");\n if (!this.producedApiCatchall.has(key)) {\n this.producedApiCatchall.set(key, mapping);\n } else {\n this.producedApiCatchall.set(key, { ...this.producedApiCatchall.get(key)!, ...mapping });\n }\n this.emitProducedApiCatchall();\n logger.info(`${this.instanceNameWithSuffix} - Registered catch-all API mapping: ${key}`);\n }\n }\n\n protected unregisterApiEndpoint(topic: string, asset:UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: string): void {\n const fullTopic = buildUnsIdentityPath(topic, asset, objectType, objectId, attribute);\n if (this.producedApiEndpoints.has(fullTopic)) {\n this.producedApiEndpoints.delete(fullTopic);\n this.emitProducedApiEndpoints();\n logger.info(`${this.instanceNameWithSuffix} - Unregistered API endpoint: ${fullTopic}`);\n }\n }\n public async stop() {\n // Clear the publishing interval.\n if (this.publishInterval) {\n clearInterval(this.publishInterval);\n this.publishInterval = null;\n }\n\n }\n\n}\n"]}
1
+ {"version":3,"file":"uns-proxy.js","sourceRoot":"","sources":["../../src/uns/uns-proxy.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI5C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,CAAC,OAAO,OA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Object, ITopicObject, UnsEvents } from \"./uns-interfaces.js\";\nimport logger from \"../logger.js\";\nimport { UnsEventEmitter } from \"./uns-event-emitter.js\";\nimport { UnsPacket } from \"./uns-packet.js\";\nimport { UnsAsset } from \"./uns-asset.js\";\nimport { UnsObjectId, UnsObjectType } from \"./uns-object.js\";\nimport { IApiCatchallMapping } from \"./uns-interfaces.js\";\nimport { buildUnsIdentityPath } from \"./uns-path.js\";\n\nexport default class UnsProxy {\n private publishInterval: NodeJS.Timeout | null = null;\n public event: UnsEventEmitter<UnsEvents> = new UnsEventEmitter<UnsEvents>();\n protected instanceStatusTopic: string;\n protected instanceNameWithSuffix: string; //was prot\n private producedTopics: Map<string, ITopicObject> = new Map();\n private producedApiEndpoints: Map<string, IApiObject> = new Map();\n private producedApiCatchall: Map<string, IApiCatchallMapping> = new Map();\n private readonly controllerNameEnv: string | undefined;\n private readonly controllerHostEnv: string | undefined;\n private readonly controllerPortEnv: string | undefined;\n private readonly controllerPublicBaseEnv: string | undefined;\n\n constructor() {\n this.controllerNameEnv = process.env[\"UNS_CONTROLLER_NAME\"];\n this.controllerHostEnv = process.env[\"UNS_CONTROLLER_HOST\"];\n this.controllerPortEnv = process.env[\"UNS_CONTROLLER_PORT\"];\n this.controllerPublicBaseEnv =\n process.env[\"UNS_CONTROLLER_PUBLIC_BASE\"] ?? process.env[\"UNS_PUBLIC_BASE\"];\n // Set up interval to publish produced topics every 60 seconds.\n this.publishInterval = setInterval(() => {\n this.emitProducedTopics();\n this.emitProducedApiEndpoints();\n this.emitProducedApiCatchall();\n }, 60000); \n }\n \n /**\n * Publishes the list of produced topics to the MQTT broker.\n */\n private async emitProducedTopics(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const topicsArray = [...this.producedTopics.values()];\n if (topicsArray.length > 0) {\n try {\n this.event.emit(\"unsProxyProducedTopics\", { producedTopics: topicsArray, statusTopic: this.instanceStatusTopic + \"topics\" });\n } catch (error) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing produced topics: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published produced topics.`);\n }\n }\n }\n\n /**\n * Publishes the list of produced API endpoints to the MQTT broker.\n */\n private async emitProducedApiEndpoints(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const apiEndpointsArray = [...this.producedApiEndpoints.values()];\n if (apiEndpointsArray.length > 0) {\n try {\n if (apiEndpointsArray.length > 0) {\n this.event.emit(\"unsProxyProducedApiEndpoints\", { producedApiEndpoints: apiEndpointsArray, statusTopic: this.instanceStatusTopic + \"api-endpoints\" });\n }\n } catch (error) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing produced API endpoints: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published produced API endpoints.`);\n }\n }\n }\n\n /**\n * Publishes the list of catch-all API mappings to the MQTT broker.\n */\n private async emitProducedApiCatchall(): Promise<void> {\n if (this.instanceStatusTopic !== \"\") {\n const catchallArray = [...this.producedApiCatchall.values()];\n if (catchallArray.length > 0) {\n try {\n this.event.emit(\"unsProxyProducedApiCatchAll\", {\n producedCatchall: catchallArray,\n statusTopic: this.instanceStatusTopic + \"api-catchall\",\n });\n } catch (error: any) {\n logger.error(`${this.instanceNameWithSuffix} - Error publishing catch-all API mappings: ${error.message}`);\n }\n logger.debug(`${this.instanceNameWithSuffix} - Published catch-all API mappings.`);\n }\n }\n }\n\n /**\n * Registers a unique topic and keeps its timestamp current.\n *\n * On first call the full entry is created and immediately emitted so the\n * controller can persist the new schema node. On subsequent calls only the\n * timestamp is updated in-place; the 60-second heartbeat interval will carry\n * the updated value to the controller, making the timestamp reflect the time\n * of the most recent data publication rather than the one-off registration\n * moment.\n *\n * @param topicObject - The object containing topic details.\n */\n protected registerUniqueTopic(topicObject: ITopicObject): void {\n if (this.instanceStatusTopic !== \"\") {\n const fullTopic = buildUnsIdentityPath(\n topicObject.topic,\n topicObject.asset,\n topicObject.objectType,\n topicObject.objectId,\n topicObject.attribute,\n );\n if (!this.producedTopics.has(fullTopic)) {\n this.producedTopics.set(fullTopic, {\n timestamp: topicObject.timestamp,\n topic: topicObject.topic,\n attribute: topicObject.attribute,\n attributeType: topicObject.attributeType,\n description: topicObject.description,\n tags: topicObject.tags,\n attributeNeedsPersistence: topicObject.attributeNeedsPersistence ?? true,\n dataGroup: topicObject.dataGroup ?? \"\",\n asset: topicObject.asset,\n assetDescription: topicObject.assetDescription,\n objectType: topicObject.objectType,\n objectTypeDescription: topicObject.objectTypeDescription,\n objectId: topicObject.objectId,\n });\n this.emitProducedTopics();\n logger.info(`${this.instanceNameWithSuffix} - Registered new topic: ${fullTopic}`);\n } else {\n // Already registered — refresh only the timestamp so the periodic\n // heartbeat reflects actual data flow rather than frozen startup time.\n this.producedTopics.get(fullTopic)!.timestamp = topicObject.timestamp;\n }\n }\n }\n\n /**\n * Registers an API endpoint to handle requests for a specific topic and attribute.\n */\n protected registerApiEndpoint(apiObject: IApiObject): void {\n if (this.instanceStatusTopic !== \"\") {\n const fullTopic = buildUnsIdentityPath(\n apiObject.topic,\n apiObject.asset,\n apiObject.objectType,\n apiObject.objectId,\n apiObject.attribute,\n );\n if (!this.producedApiEndpoints.has(fullTopic)) {\n const time = UnsPacket.formatToISO8601(new Date());\n this.producedApiEndpoints.set(fullTopic, {\n timestamp: time,\n topic: apiObject.topic,\n attribute: apiObject.attribute,\n apiHost: apiObject.apiHost,\n apiEndpoint: apiObject.apiEndpoint,\n apiMethod: apiObject.apiMethod,\n apiQueryParams: apiObject.apiQueryParams,\n apiDescription: apiObject.apiDescription,\n attributeType: apiObject.attributeType,\n apiSwaggerEndpoint: apiObject.apiSwaggerEndpoint,\n asset: apiObject.asset,\n objectType: apiObject.objectType,\n objectId: apiObject.objectId,\n ...(this.controllerNameEnv ? { controllerName: this.controllerNameEnv } : {}),\n ...(this.controllerHostEnv ? { controllerHost: this.controllerHostEnv } : {}),\n ...(this.controllerPortEnv ? { controllerPort: this.controllerPortEnv } : {}),\n ...(this.controllerPublicBaseEnv ? { controllerPublicBase: this.controllerPublicBaseEnv } : {}),\n });\n this.emitProducedApiEndpoints();\n logger.info(`${this.instanceNameWithSuffix} - Registered new api endpoint: /${fullTopic}`);\n }\n }\n }\n\n protected registerApiCatchAll(mapping: IApiCatchallMapping): void {\n if (this.instanceStatusTopic !== \"\") {\n const key = mapping.topic.replace(/\\/+$/, \"\");\n if (!this.producedApiCatchall.has(key)) {\n this.producedApiCatchall.set(key, mapping);\n } else {\n this.producedApiCatchall.set(key, { ...this.producedApiCatchall.get(key)!, ...mapping });\n }\n this.emitProducedApiCatchall();\n logger.info(`${this.instanceNameWithSuffix} - Registered catch-all API mapping: ${key}`);\n }\n }\n\n protected unregisterApiEndpoint(topic: string, asset:UnsAsset, objectType: UnsObjectType, objectId: UnsObjectId, attribute: string): void {\n const fullTopic = buildUnsIdentityPath(topic, asset, objectType, objectId, attribute);\n if (this.producedApiEndpoints.has(fullTopic)) {\n this.producedApiEndpoints.delete(fullTopic);\n this.emitProducedApiEndpoints();\n logger.info(`${this.instanceNameWithSuffix} - Unregistered API endpoint: ${fullTopic}`);\n }\n }\n public async stop() {\n // Clear the publishing interval.\n if (this.publishInterval) {\n clearInterval(this.publishInterval);\n this.publishInterval = null;\n }\n\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/core",
3
- "version": "2.0.33",
3
+ "version": "2.0.34",
4
4
  "description": "Core utilities and runtime building blocks for UNS-based realtime transformers.",
5
5
  "type": "module",
6
6
  "license": "MIT",