@shipfox/node-temporal 0.1.0

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.
@@ -0,0 +1,10 @@
1
+ import { Worker } from '@temporalio/worker';
2
+ export interface CreateWorkerOptions {
3
+ taskQueue?: string;
4
+ workflowsPath: string;
5
+ activities: object;
6
+ maxConcurrentActivityTaskExecutions?: number;
7
+ maxConcurrentWorkflowTaskExecutions?: number;
8
+ }
9
+ export declare function createTemporalWorker(options: CreateWorkerOptions): Promise<Worker>;
10
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../src/worker.ts"],"names":[],"mappings":"AACA,OAAO,EAAmB,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAI5D,MAAM,WAAW,mBAAmB;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,mCAAmC,CAAC,EAAE,MAAM,CAAC;IAC7C,mCAAmC,CAAC,EAAE,MAAM,CAAC;CAC9C;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAwBxF"}
package/dist/worker.js ADDED
@@ -0,0 +1,30 @@
1
+ import { logger } from '@shipfox/node-opentelemetry';
2
+ import { NativeConnection, Worker } from '@temporalio/worker';
3
+ import { config } from './config.js';
4
+ import { getWorkerInterceptors, getWorkflowInterceptorModules } from './interceptors.js';
5
+ export async function createTemporalWorker(options) {
6
+ const connection = await NativeConnection.connect({
7
+ address: config.TEMPORAL_ADDRESS
8
+ });
9
+ const taskQueue = options.taskQueue ?? config.TEMPORAL_TASK_QUEUE;
10
+ const worker = await Worker.create({
11
+ connection,
12
+ namespace: config.TEMPORAL_NAMESPACE,
13
+ taskQueue,
14
+ workflowsPath: options.workflowsPath,
15
+ activities: options.activities,
16
+ interceptors: {
17
+ ...getWorkerInterceptors(),
18
+ workflowModules: getWorkflowInterceptorModules()
19
+ },
20
+ maxConcurrentActivityTaskExecutions: options.maxConcurrentActivityTaskExecutions ?? 10,
21
+ maxConcurrentWorkflowTaskExecutions: options.maxConcurrentWorkflowTaskExecutions ?? 10
22
+ });
23
+ logger().info({
24
+ taskQueue,
25
+ namespace: config.TEMPORAL_NAMESPACE
26
+ }, 'Temporal worker created');
27
+ return worker;
28
+ }
29
+
30
+ //# sourceMappingURL=worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/worker.ts"],"sourcesContent":["import {logger} from '@shipfox/node-opentelemetry';\nimport {NativeConnection, Worker} from '@temporalio/worker';\nimport {config} from './config.js';\nimport {getWorkerInterceptors, getWorkflowInterceptorModules} from './interceptors.js';\n\nexport interface CreateWorkerOptions {\n taskQueue?: string;\n workflowsPath: string;\n activities: object;\n maxConcurrentActivityTaskExecutions?: number;\n maxConcurrentWorkflowTaskExecutions?: number;\n}\n\nexport async function createTemporalWorker(options: CreateWorkerOptions): Promise<Worker> {\n const connection = await NativeConnection.connect({\n address: config.TEMPORAL_ADDRESS,\n });\n\n const taskQueue = options.taskQueue ?? config.TEMPORAL_TASK_QUEUE;\n\n const worker = await Worker.create({\n connection,\n namespace: config.TEMPORAL_NAMESPACE,\n taskQueue,\n workflowsPath: options.workflowsPath,\n activities: options.activities,\n interceptors: {\n ...getWorkerInterceptors(),\n workflowModules: getWorkflowInterceptorModules(),\n },\n maxConcurrentActivityTaskExecutions: options.maxConcurrentActivityTaskExecutions ?? 10,\n maxConcurrentWorkflowTaskExecutions: options.maxConcurrentWorkflowTaskExecutions ?? 10,\n });\n\n logger().info({taskQueue, namespace: config.TEMPORAL_NAMESPACE}, 'Temporal worker created');\n\n return worker;\n}\n"],"names":["logger","NativeConnection","Worker","config","getWorkerInterceptors","getWorkflowInterceptorModules","createTemporalWorker","options","connection","connect","address","TEMPORAL_ADDRESS","taskQueue","TEMPORAL_TASK_QUEUE","worker","create","namespace","TEMPORAL_NAMESPACE","workflowsPath","activities","interceptors","workflowModules","maxConcurrentActivityTaskExecutions","maxConcurrentWorkflowTaskExecutions","info"],"mappings":"AAAA,SAAQA,MAAM,QAAO,8BAA8B;AACnD,SAAQC,gBAAgB,EAAEC,MAAM,QAAO,qBAAqB;AAC5D,SAAQC,MAAM,QAAO,cAAc;AACnC,SAAQC,qBAAqB,EAAEC,6BAA6B,QAAO,oBAAoB;AAUvF,OAAO,eAAeC,qBAAqBC,OAA4B;IACrE,MAAMC,aAAa,MAAMP,iBAAiBQ,OAAO,CAAC;QAChDC,SAASP,OAAOQ,gBAAgB;IAClC;IAEA,MAAMC,YAAYL,QAAQK,SAAS,IAAIT,OAAOU,mBAAmB;IAEjE,MAAMC,SAAS,MAAMZ,OAAOa,MAAM,CAAC;QACjCP;QACAQ,WAAWb,OAAOc,kBAAkB;QACpCL;QACAM,eAAeX,QAAQW,aAAa;QACpCC,YAAYZ,QAAQY,UAAU;QAC9BC,cAAc;YACZ,GAAGhB,uBAAuB;YAC1BiB,iBAAiBhB;QACnB;QACAiB,qCAAqCf,QAAQe,mCAAmC,IAAI;QACpFC,qCAAqChB,QAAQgB,mCAAmC,IAAI;IACtF;IAEAvB,SAASwB,IAAI,CAAC;QAACZ;QAAWI,WAAWb,OAAOc,kBAAkB;IAAA,GAAG;IAEjE,OAAOH;AACT"}
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@shipfox/node-temporal",
3
+ "license": "MIT",
4
+ "private": false,
5
+ "version": "0.1.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/ShipfoxHQ/platform.git",
9
+ "directory": "libs/shared/node/temporal"
10
+ },
11
+ "type": "module",
12
+ "main": "dist/index.js",
13
+ "types": "dist/index.d.ts",
14
+ "imports": {
15
+ "#test/*": "./test/*",
16
+ "#*": "./src/*"
17
+ },
18
+ "exports": {
19
+ ".": {
20
+ "development": {
21
+ "types": "./src/index.ts",
22
+ "default": "./src/index.ts"
23
+ },
24
+ "default": {
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
27
+ }
28
+ }
29
+ },
30
+ "dependencies": {
31
+ "@temporalio/client": "^1.16.1",
32
+ "@temporalio/common": "^1.16.1",
33
+ "@temporalio/interceptors-opentelemetry": "^1.16.1",
34
+ "@temporalio/worker": "^1.16.1",
35
+ "@shipfox/config": "1.2.0",
36
+ "@shipfox/node-opentelemetry": "0.4.1"
37
+ },
38
+ "devDependencies": {
39
+ "@shipfox/typescript": "1.1.5",
40
+ "@shipfox/biome": "1.8.1",
41
+ "@shipfox/ts-config": "1.3.6",
42
+ "@shipfox/swc": "1.2.5"
43
+ },
44
+ "scripts": {
45
+ "build": "shipfox-swc",
46
+ "check": "shipfox-biome-check",
47
+ "check:fix": "shipfox-biome-check --write",
48
+ "type": "shipfox-tsc-check",
49
+ "type:emit": "shipfox-tsc-emit"
50
+ }
51
+ }
package/src/client.ts ADDED
@@ -0,0 +1,49 @@
1
+ import {logger} from '@shipfox/node-opentelemetry';
2
+ import {Client, Connection} from '@temporalio/client';
3
+ import {config} from './config.js';
4
+ import {getClientInterceptors} from './interceptors.js';
5
+
6
+ let _connection: Connection | undefined;
7
+ let _client: Client | undefined;
8
+
9
+ export async function createTemporalClient(): Promise<Client> {
10
+ _connection = await Connection.connect({
11
+ address: config.TEMPORAL_ADDRESS,
12
+ });
13
+
14
+ _client = new Client({
15
+ connection: _connection,
16
+ namespace: config.TEMPORAL_NAMESPACE,
17
+ interceptors: getClientInterceptors(),
18
+ });
19
+
20
+ logger().info(
21
+ {address: config.TEMPORAL_ADDRESS, namespace: config.TEMPORAL_NAMESPACE},
22
+ 'Temporal client connected',
23
+ );
24
+
25
+ return _client;
26
+ }
27
+
28
+ export function temporalClient(): Client {
29
+ if (!_client) {
30
+ throw new Error('Temporal client has not been created');
31
+ }
32
+ return _client;
33
+ }
34
+
35
+ export async function closeTemporalClient(): Promise<void> {
36
+ await _connection?.close();
37
+ _connection = undefined;
38
+ _client = undefined;
39
+ }
40
+
41
+ export async function isTemporalHealthy(): Promise<boolean> {
42
+ if (!_connection) return false;
43
+ try {
44
+ await _connection.healthService.check({});
45
+ return true;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
package/src/config.ts ADDED
@@ -0,0 +1,7 @@
1
+ import {createConfig, str} from '@shipfox/config';
2
+
3
+ export const config = createConfig({
4
+ TEMPORAL_ADDRESS: str({default: 'localhost:7233'}),
5
+ TEMPORAL_NAMESPACE: str({default: 'default'}),
6
+ TEMPORAL_TASK_QUEUE: str({default: 'shipfox'}),
7
+ });
package/src/index.ts ADDED
@@ -0,0 +1,15 @@
1
+ export type * from '@temporalio/client';
2
+ export type {Worker, WorkerOptions} from '@temporalio/worker';
3
+ export {
4
+ closeTemporalClient,
5
+ createTemporalClient,
6
+ isTemporalHealthy,
7
+ temporalClient,
8
+ } from './client.js';
9
+ export {config as temporalConfig} from './config.js';
10
+ export {
11
+ getClientInterceptors,
12
+ getWorkerInterceptors,
13
+ getWorkflowInterceptorModules,
14
+ } from './interceptors.js';
15
+ export {type CreateWorkerOptions, createTemporalWorker} from './worker.js';
@@ -0,0 +1,16 @@
1
+ import type {ClientInterceptors} from '@temporalio/client';
2
+ import type {WorkerInterceptors} from '@temporalio/worker';
3
+
4
+ export function getClientInterceptors(): ClientInterceptors {
5
+ return {};
6
+ }
7
+
8
+ export function getWorkerInterceptors(): WorkerInterceptors {
9
+ return {
10
+ activity: [],
11
+ };
12
+ }
13
+
14
+ export function getWorkflowInterceptorModules(): string[] {
15
+ return [];
16
+ }
package/src/worker.ts ADDED
@@ -0,0 +1,38 @@
1
+ import {logger} from '@shipfox/node-opentelemetry';
2
+ import {NativeConnection, Worker} from '@temporalio/worker';
3
+ import {config} from './config.js';
4
+ import {getWorkerInterceptors, getWorkflowInterceptorModules} from './interceptors.js';
5
+
6
+ export interface CreateWorkerOptions {
7
+ taskQueue?: string;
8
+ workflowsPath: string;
9
+ activities: object;
10
+ maxConcurrentActivityTaskExecutions?: number;
11
+ maxConcurrentWorkflowTaskExecutions?: number;
12
+ }
13
+
14
+ export async function createTemporalWorker(options: CreateWorkerOptions): Promise<Worker> {
15
+ const connection = await NativeConnection.connect({
16
+ address: config.TEMPORAL_ADDRESS,
17
+ });
18
+
19
+ const taskQueue = options.taskQueue ?? config.TEMPORAL_TASK_QUEUE;
20
+
21
+ const worker = await Worker.create({
22
+ connection,
23
+ namespace: config.TEMPORAL_NAMESPACE,
24
+ taskQueue,
25
+ workflowsPath: options.workflowsPath,
26
+ activities: options.activities,
27
+ interceptors: {
28
+ ...getWorkerInterceptors(),
29
+ workflowModules: getWorkflowInterceptorModules(),
30
+ },
31
+ maxConcurrentActivityTaskExecutions: options.maxConcurrentActivityTaskExecutions ?? 10,
32
+ maxConcurrentWorkflowTaskExecutions: options.maxConcurrentWorkflowTaskExecutions ?? 10,
33
+ });
34
+
35
+ logger().info({taskQueue, namespace: config.TEMPORAL_NAMESPACE}, 'Temporal worker created');
36
+
37
+ return worker;
38
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@shipfox/ts-config/node",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist"
6
+ },
7
+ "include": ["src"],
8
+ "exclude": ["**/*.test.tsx", "**/*.test.ts"]
9
+ }