@uns-kit/temporal 2.0.21 → 2.0.22

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Aljoša Vister
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Aljoša Vister
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,62 +1,62 @@
1
- # @uns-kit/temporal
2
-
3
- `@uns-kit/temporal` bridges Temporal.io workflows into the Unified Namespace. The plugin registers a `createTemporalProxy` method on `UnsProxyProcess`, tracks workflow metadata, and republishes workflow results via UNS topics.
4
-
5
- Note: Apps built with uns-kit are intended to be managed by the **UNS Datahub controller**.
6
-
7
- ## uns-kit in context
8
-
9
- uns-kit is a batteries-included toolkit for Unified Namespace applications. It standardizes MQTT wiring, auth, config schemas, and scaffolding so you can focus on orchestrating workflows instead of boilerplate. The toolkit includes:
10
-
11
- | Package | Description |
12
- | --- | --- |
13
- | [`@uns-kit/core`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-core) | Base runtime utilities (UnsProxyProcess, MQTT helpers, configuration tooling, gRPC gateway support). |
14
- | [`@uns-kit/api`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-api) | Express plugin that exposes HTTP endpoints, handles JWT/JWKS auth, and republishes API metadata to UNS. |
15
- | [`@uns-kit/cron`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-cron) | Cron-driven scheduler that emits UNS events on a fixed cadence. |
16
- | [`@uns-kit/temporal`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-temporal) | Temporal.io integration that wires workflows into UnsProxyProcess. |
17
- | [`@uns-kit/cli`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-cli) | Command line tool for scaffolding new UNS applications. |
18
-
19
- ## Installation
20
-
21
- ```bash
22
- pnpm add @uns-kit/temporal
23
- # or
24
- npm install @uns-kit/temporal
25
- ```
26
-
27
- Install `@uns-kit/core` as well—the plugin augments its runtime.
28
-
29
- ## Example
30
-
31
- ```ts
32
- import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
33
- import { UnsAttributeType } from "@uns-kit/core/uns/uns-interfaces";
34
- import type { UnsProxyProcessWithTemporal } from "@uns-kit/temporal";
35
- import "@uns-kit/temporal";
36
-
37
- async function main() {
38
- const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "temporal-demo" }) as UnsProxyProcessWithTemporal;
39
-
40
- const temporal = await process.createTemporalProxy("line-etl", "temporal:7233", "line-namespace");
41
- await temporal.initializeTemporalProxy({
42
- topic: "factory/",
43
- attribute: "line-status",
44
- attributeType: UnsAttributeType.Data,
45
- });
46
-
47
- await temporal.startWorkflow("TransformLineData", { coil_id: "42" }, "ETL_LINE_TASK_QUEUE");
48
- }
49
-
50
- void main();
51
- ```
52
-
53
- ## Scripts
54
-
55
- ```bash
56
- pnpm run typecheck
57
- pnpm run build
58
- ```
59
-
60
- ## License
61
-
62
- MIT © Aljoša Vister
1
+ # @uns-kit/temporal
2
+
3
+ `@uns-kit/temporal` bridges Temporal.io workflows into the Unified Namespace. The plugin registers a `createTemporalProxy` method on `UnsProxyProcess`, tracks workflow metadata, and republishes workflow results via UNS topics.
4
+
5
+ Note: Apps built with uns-kit are intended to be managed by the **UNS Datahub controller**.
6
+
7
+ ## uns-kit in context
8
+
9
+ uns-kit is a batteries-included toolkit for Unified Namespace applications. It standardizes MQTT wiring, auth, config schemas, and scaffolding so you can focus on orchestrating workflows instead of boilerplate. The toolkit includes:
10
+
11
+ | Package | Description |
12
+ | --- | --- |
13
+ | [`@uns-kit/core`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-core) | Base runtime utilities (UnsProxyProcess, MQTT helpers, configuration tooling, gRPC gateway support). |
14
+ | [`@uns-kit/api`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-api) | Express plugin that exposes HTTP endpoints, handles JWT/JWKS auth, and republishes API metadata to UNS. |
15
+ | [`@uns-kit/cron`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-cron) | Cron-driven scheduler that emits UNS events on a fixed cadence. |
16
+ | [`@uns-kit/temporal`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-temporal) | Temporal.io integration that wires workflows into UnsProxyProcess. |
17
+ | [`@uns-kit/cli`](https://github.com/uns-datahub/uns-kit/tree/main/packages/uns-cli) | Command line tool for scaffolding new UNS applications. |
18
+
19
+ ## Installation
20
+
21
+ ```bash
22
+ pnpm add @uns-kit/temporal
23
+ # or
24
+ npm install @uns-kit/temporal
25
+ ```
26
+
27
+ Install `@uns-kit/core` as well—the plugin augments its runtime.
28
+
29
+ ## Example
30
+
31
+ ```ts
32
+ import UnsProxyProcess from "@uns-kit/core/uns/uns-proxy-process";
33
+ import { UnsAttributeType } from "@uns-kit/core/uns/uns-interfaces";
34
+ import type { UnsProxyProcessWithTemporal } from "@uns-kit/temporal";
35
+ import "@uns-kit/temporal";
36
+
37
+ async function main() {
38
+ const process = new UnsProxyProcess("mqtt-broker:1883", { processName: "temporal-demo" }) as UnsProxyProcessWithTemporal;
39
+
40
+ const temporal = await process.createTemporalProxy("line-etl", "temporal:7233", "line-namespace");
41
+ await temporal.initializeTemporalProxy({
42
+ topic: "factory/",
43
+ attribute: "line-status",
44
+ attributeType: UnsAttributeType.Data,
45
+ });
46
+
47
+ await temporal.startWorkflow("TransformLineData", { coil_id: "42" }, "ETL_LINE_TASK_QUEUE");
48
+ }
49
+
50
+ void main();
51
+ ```
52
+
53
+ ## Scripts
54
+
55
+ ```bash
56
+ pnpm run typecheck
57
+ pnpm run build
58
+ ```
59
+
60
+ ## License
61
+
62
+ MIT © Aljoša Vister
@@ -1,15 +1,15 @@
1
- import { UnsAttributeType } from "@uns-kit/core/graphql/schema.js";
2
- import { UnsAsset } from "@uns-kit/core/uns/uns-asset.js";
3
- import { UnsObjectId, UnsObjectType } from "@uns-kit/core/uns/uns-object.js";
4
- export interface ITemporalTopic {
5
- attribute: string;
6
- topic: string;
7
- attributeType: UnsAttributeType;
8
- attributeNeedsPersistence?: boolean | undefined;
9
- dataGroup?: string | undefined;
10
- description?: string | undefined;
11
- tags?: string[] | undefined;
12
- objectType: UnsObjectType;
13
- objectId: UnsObjectId;
14
- asset: UnsAsset;
15
- }
1
+ import { UnsAttributeType } from "@uns-kit/core/graphql/schema.js";
2
+ import { UnsAsset } from "@uns-kit/core/uns/uns-asset.js";
3
+ import { UnsObjectId, UnsObjectType } from "@uns-kit/core/uns/uns-object.js";
4
+ export interface ITemporalTopic {
5
+ attribute: string;
6
+ topic: string;
7
+ attributeType: UnsAttributeType;
8
+ attributeNeedsPersistence?: boolean | undefined;
9
+ dataGroup?: string | undefined;
10
+ description?: string | undefined;
11
+ tags?: string[] | undefined;
12
+ objectType: UnsObjectType;
13
+ objectId: UnsObjectId;
14
+ asset: UnsAsset;
15
+ }
@@ -1,104 +1,104 @@
1
- import UnsProxy from "@uns-kit/core/uns/uns-proxy.js";
2
- import logger from "@uns-kit/core/logger.js";
3
- import { MqttTopicBuilder } from "@uns-kit/core/uns-mqtt/mqtt-topic-builder.js";
4
- import * as path from "path";
5
- import { basePath } from "@uns-kit/core/base-path.js";
6
- import { readFileSync } from "fs";
7
- import { Connection, Client } from '@temporalio/client';
8
- import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
9
- const packageJsonPath = path.join(basePath, "package.json");
10
- const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
11
- export default class UnsTemporalProxy extends UnsProxy {
12
- instanceName;
13
- processStatusTopic;
14
- topicBuilder;
15
- processName;
16
- connectionOptions;
17
- clientOptions;
18
- client;
19
- unsTopic;
20
- constructor(processName, instanceName, connectionOptions, clientOptions) {
21
- super();
22
- this.connectionOptions = connectionOptions;
23
- this.clientOptions = clientOptions;
24
- this.instanceName = instanceName;
25
- this.processName = processName;
26
- // Create the topic builder using packageJson values and the processName.
27
- this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageJson.name)}/${MqttTopicBuilder.sanitizeTopicPart(packageJson.version)}/${MqttTopicBuilder.sanitizeTopicPart(processName)}/`);
28
- // Generate the processStatusTopic using the builder.
29
- this.processStatusTopic = this.topicBuilder.getProcessStatusTopic();
30
- // Derive the instanceStatusTopic by appending the instance name.
31
- this.instanceStatusTopic = this.processStatusTopic + instanceName + "/";
32
- // Concatenate processName with instanceName for the worker identification.
33
- this.instanceNameWithSuffix = `${processName}-${instanceName}`;
34
- }
35
- /**
36
- * Initializes the Temporal proxy by registering the given topic and establishing a client connection.
37
- * @param unsTopic - The topic object to register with Temporal.
38
- * @returns A promise that resolves when initialization is complete.
39
- * @throws If the Temporal client fails to initialize.
40
- */
41
- async initializeTemporalProxy(temporalTopic) {
42
- try {
43
- const unsTopic = {
44
- timestamp: UnsPacket.formatToISO8601(new Date()),
45
- topic: temporalTopic.topic,
46
- asset: temporalTopic.asset,
47
- objectType: temporalTopic.objectType,
48
- objectId: temporalTopic.objectId,
49
- attribute: temporalTopic.attribute,
50
- attributeType: temporalTopic.attributeType,
51
- description: temporalTopic.description ?? "",
52
- tags: temporalTopic.tags ?? [],
53
- attributeNeedsPersistence: temporalTopic.attributeNeedsPersistence ?? true,
54
- dataGroup: temporalTopic.dataGroup ?? "",
55
- };
56
- // Register the UNS topic for temporal data.
57
- this.registerTemporalTopic(unsTopic);
58
- this.clientOptions.connection = this.clientOptions.connection ?? await Connection.connect(this.connectionOptions);
59
- this.client = new Client(this.clientOptions);
60
- }
61
- catch (error) {
62
- logger.error(`Failed to initialize Temporal client: ${error.message}`);
63
- throw error;
64
- }
65
- }
66
- /**
67
- * Creates a temporal proxy for the UNS process.
68
- * This method registers the UNS topic for temporal data.
69
- */
70
- async registerTemporalTopic(unsTopic) {
71
- try {
72
- // Register the UNS topic for temporal data.
73
- this.registerUniqueTopic(unsTopic);
74
- this.unsTopic = unsTopic;
75
- }
76
- catch (error) {
77
- logger.error(`Error creating temporal proxy: ${error.message}`);
78
- throw error;
79
- }
80
- }
81
- async startWorkflow(workflowTypeOrFunc, arg, taskQueue, workflowId) {
82
- try {
83
- const workflowInput = {
84
- input_data: arg,
85
- uns_params: {
86
- uns_attribute: this.unsTopic.attribute,
87
- uns_attribute_type: this.unsTopic.attributeType,
88
- uns_topic: this.unsTopic.topic
89
- }
90
- };
91
- const workflowOptions = {
92
- args: [workflowInput], // single JSON object
93
- taskQueue,
94
- workflowId: workflowId ?? `${this.instanceNameWithSuffix}-${Math.floor(Date.now() / 1000)}`
95
- };
96
- logger.info(`Starting workflow with options: ${JSON.stringify(workflowOptions)}`);
97
- const handle = await this.client.workflow.start(workflowTypeOrFunc, workflowOptions);
98
- return await handle.result();
99
- }
100
- catch (error) {
101
- logger.error(`Failed to start/complete workflow: ${error.message}`);
102
- }
103
- }
104
- }
1
+ import UnsProxy from "@uns-kit/core/uns/uns-proxy.js";
2
+ import logger from "@uns-kit/core/logger.js";
3
+ import { MqttTopicBuilder } from "@uns-kit/core/uns-mqtt/mqtt-topic-builder.js";
4
+ import * as path from "path";
5
+ import { basePath } from "@uns-kit/core/base-path.js";
6
+ import { readFileSync } from "fs";
7
+ import { Connection, Client } from '@temporalio/client';
8
+ import { UnsPacket } from "@uns-kit/core/uns/uns-packet.js";
9
+ const packageJsonPath = path.join(basePath, "package.json");
10
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
11
+ export default class UnsTemporalProxy extends UnsProxy {
12
+ instanceName;
13
+ processStatusTopic;
14
+ topicBuilder;
15
+ processName;
16
+ connectionOptions;
17
+ clientOptions;
18
+ client;
19
+ unsTopic;
20
+ constructor(processName, instanceName, connectionOptions, clientOptions) {
21
+ super();
22
+ this.connectionOptions = connectionOptions;
23
+ this.clientOptions = clientOptions;
24
+ this.instanceName = instanceName;
25
+ this.processName = processName;
26
+ // Create the topic builder using packageJson values and the processName.
27
+ this.topicBuilder = new MqttTopicBuilder(`uns-infra/${MqttTopicBuilder.sanitizeTopicPart(packageJson.name)}/${MqttTopicBuilder.sanitizeTopicPart(packageJson.version)}/${MqttTopicBuilder.sanitizeTopicPart(processName)}/`);
28
+ // Generate the processStatusTopic using the builder.
29
+ this.processStatusTopic = this.topicBuilder.getProcessStatusTopic();
30
+ // Derive the instanceStatusTopic by appending the instance name.
31
+ this.instanceStatusTopic = this.processStatusTopic + instanceName + "/";
32
+ // Concatenate processName with instanceName for the worker identification.
33
+ this.instanceNameWithSuffix = `${processName}-${instanceName}`;
34
+ }
35
+ /**
36
+ * Initializes the Temporal proxy by registering the given topic and establishing a client connection.
37
+ * @param unsTopic - The topic object to register with Temporal.
38
+ * @returns A promise that resolves when initialization is complete.
39
+ * @throws If the Temporal client fails to initialize.
40
+ */
41
+ async initializeTemporalProxy(temporalTopic) {
42
+ try {
43
+ const unsTopic = {
44
+ timestamp: UnsPacket.formatToISO8601(new Date()),
45
+ topic: temporalTopic.topic,
46
+ asset: temporalTopic.asset,
47
+ objectType: temporalTopic.objectType,
48
+ objectId: temporalTopic.objectId,
49
+ attribute: temporalTopic.attribute,
50
+ attributeType: temporalTopic.attributeType,
51
+ description: temporalTopic.description ?? "",
52
+ tags: temporalTopic.tags ?? [],
53
+ attributeNeedsPersistence: temporalTopic.attributeNeedsPersistence ?? true,
54
+ dataGroup: temporalTopic.dataGroup ?? "",
55
+ };
56
+ // Register the UNS topic for temporal data.
57
+ this.registerTemporalTopic(unsTopic);
58
+ this.clientOptions.connection = this.clientOptions.connection ?? await Connection.connect(this.connectionOptions);
59
+ this.client = new Client(this.clientOptions);
60
+ }
61
+ catch (error) {
62
+ logger.error(`Failed to initialize Temporal client: ${error.message}`);
63
+ throw error;
64
+ }
65
+ }
66
+ /**
67
+ * Creates a temporal proxy for the UNS process.
68
+ * This method registers the UNS topic for temporal data.
69
+ */
70
+ async registerTemporalTopic(unsTopic) {
71
+ try {
72
+ // Register the UNS topic for temporal data.
73
+ this.registerUniqueTopic(unsTopic);
74
+ this.unsTopic = unsTopic;
75
+ }
76
+ catch (error) {
77
+ logger.error(`Error creating temporal proxy: ${error.message}`);
78
+ throw error;
79
+ }
80
+ }
81
+ async startWorkflow(workflowTypeOrFunc, arg, taskQueue, workflowId) {
82
+ try {
83
+ const workflowInput = {
84
+ input_data: arg,
85
+ uns_params: {
86
+ uns_attribute: this.unsTopic.attribute,
87
+ uns_attribute_type: this.unsTopic.attributeType,
88
+ uns_topic: this.unsTopic.topic
89
+ }
90
+ };
91
+ const workflowOptions = {
92
+ args: [workflowInput], // single JSON object
93
+ taskQueue,
94
+ workflowId: workflowId ?? `${this.instanceNameWithSuffix}-${Math.floor(Date.now() / 1000)}`
95
+ };
96
+ logger.info(`Starting workflow with options: ${JSON.stringify(workflowOptions)}`);
97
+ const handle = await this.client.workflow.start(workflowTypeOrFunc, workflowOptions);
98
+ return await handle.result();
99
+ }
100
+ catch (error) {
101
+ logger.error(`Failed to start/complete workflow: ${error.message}`);
102
+ }
103
+ }
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uns-kit/temporal",
3
- "version": "2.0.21",
3
+ "version": "2.0.22",
4
4
  "description": "Temporal.io integration plugin for UnsProxyProcess, wiring workflows into the UNS.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -32,7 +32,7 @@
32
32
  "types": "dist/index.d.ts",
33
33
  "dependencies": {
34
34
  "@temporalio/client": "^1.13.0",
35
- "@uns-kit/core": "2.0.21"
35
+ "@uns-kit/core": "2.0.22"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "tsc -p tsconfig.build.json",