nest-temporal-client 0.0.1
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/README.md +225 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/options/index.d.ts +30 -0
- package/dist/options/index.js +3 -0
- package/dist/options/index.js.map +1 -0
- package/dist/temporal-client.module.d.ts +8 -0
- package/dist/temporal-client.module.js +66 -0
- package/dist/temporal-client.module.js.map +1 -0
- package/dist/temporal-client.options.d.ts +17 -0
- package/dist/temporal-client.options.js +5 -0
- package/dist/temporal-client.options.js.map +1 -0
- package/dist/temporal-client.service.d.ts +20 -0
- package/dist/temporal-client.service.js +82 -0
- package/dist/temporal-client.service.js.map +1 -0
- package/package.json +33 -0
package/README.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# nest-temporal-client
|
|
2
|
+
|
|
3
|
+
A NestJS module that wraps `@temporalio/client` to provide a single injectable service for interacting with [Temporal](https://temporal.io) workflows via gRPC — starting workflows, sending signals, running queries, and dispatching updates.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install nest-temporal-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Setup
|
|
12
|
+
|
|
13
|
+
Register `TemporalClientModule` once in your root `AppModule`. It is globally scoped, so `TemporalClientService` is available anywhere in your application without re-importing.
|
|
14
|
+
|
|
15
|
+
### Synchronous
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { TemporalClientModule } from 'nest-temporal-client';
|
|
19
|
+
|
|
20
|
+
@Module({
|
|
21
|
+
imports: [
|
|
22
|
+
TemporalClientModule.forRoot({
|
|
23
|
+
address: 'localhost:7233',
|
|
24
|
+
namespace: 'default',
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
})
|
|
28
|
+
export class AppModule {}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Asynchronous (with ConfigService)
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { TemporalClientModule } from 'nest-temporal-client';
|
|
35
|
+
|
|
36
|
+
@Module({
|
|
37
|
+
imports: [
|
|
38
|
+
TemporalClientModule.forRootAsync({
|
|
39
|
+
imports: [ConfigModule],
|
|
40
|
+
inject: [ConfigService],
|
|
41
|
+
useFactory: (config: ConfigService) => ({
|
|
42
|
+
address: config.get('TEMPORAL_URL'),
|
|
43
|
+
namespace: config.get('TEMPORAL_NAMESPACE'),
|
|
44
|
+
}),
|
|
45
|
+
}),
|
|
46
|
+
],
|
|
47
|
+
})
|
|
48
|
+
export class AppModule {}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Module options
|
|
52
|
+
|
|
53
|
+
| Option | Type | Default | Description |
|
|
54
|
+
|---|---|---|---|
|
|
55
|
+
| `address` | `string` | `localhost:7233` | Temporal server gRPC address |
|
|
56
|
+
| `namespace` | `string` | `default` | Temporal namespace |
|
|
57
|
+
| `tls` | `TLSConfig` | — | TLS config for Temporal Cloud or secured servers |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
Inject `TemporalClientService` into any service or controller.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { TemporalClientService } from 'nest-temporal-client';
|
|
67
|
+
|
|
68
|
+
@Injectable()
|
|
69
|
+
export class OrderService {
|
|
70
|
+
constructor(private readonly temporal: TemporalClientService) {}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
### `startWorkflow(options)`
|
|
79
|
+
|
|
80
|
+
Starts a new workflow execution and returns its `workflowId`.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
const workflowId = await this.temporal.startWorkflow({
|
|
84
|
+
workflowName: 'processOrder',
|
|
85
|
+
workflowId: 'order-123',
|
|
86
|
+
taskQueue: 'orders',
|
|
87
|
+
args: [{ orderId: 'order-123' }],
|
|
88
|
+
});
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
| Option | Type | Required | Description |
|
|
92
|
+
|---|---|---|---|
|
|
93
|
+
| `workflowName` | `string` | Yes | Name of the workflow function registered on the worker |
|
|
94
|
+
| `workflowId` | `string` | Yes | Unique ID for this workflow execution |
|
|
95
|
+
| `taskQueue` | `string` | Yes | Task queue the worker is listening on |
|
|
96
|
+
| `args` | `unknown[]` | No | Arguments to pass to the workflow function |
|
|
97
|
+
| `workflowExecutionTimeout` | `Duration` | No | Max time the entire workflow (including retries) may run |
|
|
98
|
+
| `workflowRunTimeout` | `Duration` | No | Max time a single workflow run may last |
|
|
99
|
+
| `workflowTaskTimeout` | `Duration` | No | Max time a single workflow task may take |
|
|
100
|
+
| `cronSchedule` | `string` | No | Cron expression for recurring executions |
|
|
101
|
+
| `memo` | `Record<string, unknown>` | No | Non-indexed metadata attached to the execution |
|
|
102
|
+
| `runId` | `string` | No | Optionally target a specific run |
|
|
103
|
+
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
### `signalWorkflow(options)`
|
|
107
|
+
|
|
108
|
+
Sends a signal to a running workflow. Fire-and-forget — returns no value.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
await this.temporal.signalWorkflow({
|
|
112
|
+
workflowId: 'order-123',
|
|
113
|
+
signalName: 'approve',
|
|
114
|
+
args: [{ approvedBy: 'admin' }],
|
|
115
|
+
});
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
| Option | Type | Required | Description |
|
|
119
|
+
|---|---|---|---|
|
|
120
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to signal |
|
|
121
|
+
| `signalName` | `string` | Yes | Name of the signal handler defined in the workflow |
|
|
122
|
+
| `args` | `unknown[]` | No | Arguments to pass to the signal handler |
|
|
123
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### `queryWorkflow<T>(options)`
|
|
128
|
+
|
|
129
|
+
Queries a running or completed workflow and returns the result. Queries do not advance workflow state.
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
const status = await this.temporal.queryWorkflow<string>({
|
|
133
|
+
workflowId: 'order-123',
|
|
134
|
+
queryName: 'getStatus',
|
|
135
|
+
});
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
| Option | Type | Required | Description |
|
|
139
|
+
|---|---|---|---|
|
|
140
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to query |
|
|
141
|
+
| `queryName` | `string` | Yes | Name of the query handler defined in the workflow |
|
|
142
|
+
| `args` | `unknown[]` | No | Arguments to pass to the query handler |
|
|
143
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
### `updateWorkflow<T>(options)`
|
|
148
|
+
|
|
149
|
+
Sends an update to a running workflow and waits for the result. Unlike signals, updates can be validated by the workflow and return a value.
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
const newCount = await this.temporal.updateWorkflow<number>({
|
|
153
|
+
workflowId: 'order-123',
|
|
154
|
+
updateName: 'addItem',
|
|
155
|
+
args: [{ itemId: 'sku-456', quantity: 2 }],
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
| Option | Type | Required | Description |
|
|
160
|
+
|---|---|---|---|
|
|
161
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to update |
|
|
162
|
+
| `updateName` | `string` | Yes | Name of the update handler defined in the workflow |
|
|
163
|
+
| `args` | `unknown[]` | No | Arguments to pass to the update handler |
|
|
164
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
### `cancelWorkflow(options)`
|
|
169
|
+
|
|
170
|
+
Requests graceful cancellation. The workflow receives a `CancelledFailure` and can perform cleanup before stopping.
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
await this.temporal.cancelWorkflow({ workflowId: 'order-123' });
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
| Option | Type | Required | Description |
|
|
177
|
+
|---|---|---|---|
|
|
178
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to cancel |
|
|
179
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### `terminateWorkflow(options)`
|
|
184
|
+
|
|
185
|
+
Forcefully terminates a workflow immediately, bypassing any cleanup logic.
|
|
186
|
+
|
|
187
|
+
```typescript
|
|
188
|
+
await this.temporal.terminateWorkflow({
|
|
189
|
+
workflowId: 'order-123',
|
|
190
|
+
reason: 'manual intervention',
|
|
191
|
+
});
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
| Option | Type | Required | Description |
|
|
195
|
+
|---|---|---|---|
|
|
196
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to terminate |
|
|
197
|
+
| `reason` | `string` | No | Human-readable reason recorded in the event history |
|
|
198
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
### `describeWorkflow(options)`
|
|
203
|
+
|
|
204
|
+
Returns metadata and current state of a workflow execution.
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
const info = await this.temporal.describeWorkflow({ workflowId: 'order-123' });
|
|
208
|
+
console.log(info.status.name); // RUNNING, COMPLETED, FAILED, etc.
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
| Option | Type | Required | Description |
|
|
212
|
+
|---|---|---|---|
|
|
213
|
+
| `workflowId` | `string` | Yes | The ID of the workflow to describe |
|
|
214
|
+
| `runId` | `string` | No | Target a specific run of the workflow |
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
### `getHandle(options)`
|
|
219
|
+
|
|
220
|
+
Returns a raw `WorkflowHandle` for advanced use cases where you need to chain multiple operations on the same execution.
|
|
221
|
+
|
|
222
|
+
```typescript
|
|
223
|
+
const handle = this.temporal.getHandle({ workflowId: 'order-123' });
|
|
224
|
+
const result = await handle.result();
|
|
225
|
+
```
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { TemporalClientModule } from './temporal-client.module';
|
|
2
|
+
export { TemporalClientService } from './temporal-client.service';
|
|
3
|
+
export { WorkflowTargetOptions, StartWorkflowOptions, SignalWorkflowOptions, QueryWorkflowOptions, UpdateWorkflowOptions, TerminateWorkflowOptions, } from './options';
|
|
4
|
+
export { TemporalClientModuleOptions, TemporalClientModuleAsyncOptions, TemporalClientOptionsFactory, } from './temporal-client.options';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TemporalClientService = exports.TemporalClientModule = void 0;
|
|
4
|
+
var temporal_client_module_1 = require("./temporal-client.module");
|
|
5
|
+
Object.defineProperty(exports, "TemporalClientModule", { enumerable: true, get: function () { return temporal_client_module_1.TemporalClientModule; } });
|
|
6
|
+
var temporal_client_service_1 = require("./temporal-client.service");
|
|
7
|
+
Object.defineProperty(exports, "TemporalClientService", { enumerable: true, get: function () { return temporal_client_service_1.TemporalClientService; } });
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mEAAgE;AAAvD,8HAAA,oBAAoB,OAAA;AAC7B,qEAAkE;AAAzD,gIAAA,qBAAqB,OAAA"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Duration } from "@temporalio/common";
|
|
2
|
+
export interface WorkflowTargetOptions {
|
|
3
|
+
workflowId: string;
|
|
4
|
+
runId?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface StartWorkflowOptions extends WorkflowTargetOptions {
|
|
7
|
+
workflowName: string;
|
|
8
|
+
taskQueue: string;
|
|
9
|
+
args?: unknown[];
|
|
10
|
+
workflowExecutionTimeout?: Duration;
|
|
11
|
+
workflowRunTimeout?: Duration;
|
|
12
|
+
workflowTaskTimeout?: Duration;
|
|
13
|
+
cronSchedule?: string;
|
|
14
|
+
memo?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface SignalWorkflowOptions extends WorkflowTargetOptions {
|
|
17
|
+
signalName: string;
|
|
18
|
+
args?: unknown[];
|
|
19
|
+
}
|
|
20
|
+
export interface QueryWorkflowOptions extends WorkflowTargetOptions {
|
|
21
|
+
queryName: string;
|
|
22
|
+
args?: unknown[];
|
|
23
|
+
}
|
|
24
|
+
export interface UpdateWorkflowOptions extends WorkflowTargetOptions {
|
|
25
|
+
updateName: string;
|
|
26
|
+
args?: unknown[];
|
|
27
|
+
}
|
|
28
|
+
export interface TerminateWorkflowOptions extends WorkflowTargetOptions {
|
|
29
|
+
reason?: string;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/options/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { TemporalClientModuleAsyncOptions, TemporalClientModuleOptions } from "./temporal-client.options";
|
|
3
|
+
export declare class TemporalClientModule {
|
|
4
|
+
static forRoot(options?: TemporalClientModuleOptions): DynamicModule;
|
|
5
|
+
static forRootAsync(options: TemporalClientModuleAsyncOptions): DynamicModule;
|
|
6
|
+
private static createAsyncProviders;
|
|
7
|
+
private static createAsyncOptionsProvider;
|
|
8
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var TemporalClientModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.TemporalClientModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const temporal_client_options_1 = require("./temporal-client.options");
|
|
13
|
+
const temporal_client_service_1 = require("./temporal-client.service");
|
|
14
|
+
let TemporalClientModule = TemporalClientModule_1 = class TemporalClientModule {
|
|
15
|
+
static forRoot(options = {}) {
|
|
16
|
+
return {
|
|
17
|
+
module: TemporalClientModule_1,
|
|
18
|
+
global: true,
|
|
19
|
+
providers: [
|
|
20
|
+
{ provide: temporal_client_options_1.TEMPORAL_CLIENT_OPTIONS, useValue: options },
|
|
21
|
+
temporal_client_service_1.TemporalClientService,
|
|
22
|
+
],
|
|
23
|
+
exports: [temporal_client_service_1.TemporalClientService],
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
static forRootAsync(options) {
|
|
27
|
+
return {
|
|
28
|
+
module: TemporalClientModule_1,
|
|
29
|
+
global: true,
|
|
30
|
+
imports: options.imports ?? [],
|
|
31
|
+
providers: [
|
|
32
|
+
...TemporalClientModule_1.createAsyncProviders(options),
|
|
33
|
+
temporal_client_service_1.TemporalClientService,
|
|
34
|
+
],
|
|
35
|
+
exports: [temporal_client_service_1.TemporalClientService],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
static createAsyncProviders(options) {
|
|
39
|
+
if (options.useExisting || options.useFactory) {
|
|
40
|
+
return [TemporalClientModule_1.createAsyncOptionsProvider(options)];
|
|
41
|
+
}
|
|
42
|
+
return [
|
|
43
|
+
TemporalClientModule_1.createAsyncOptionsProvider(options),
|
|
44
|
+
{ provide: options.useClass, useClass: options.useClass },
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
static createAsyncOptionsProvider(options) {
|
|
48
|
+
if (options.useFactory) {
|
|
49
|
+
return {
|
|
50
|
+
provide: temporal_client_options_1.TEMPORAL_CLIENT_OPTIONS,
|
|
51
|
+
useFactory: options.useFactory,
|
|
52
|
+
inject: options.inject ?? [],
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
provide: temporal_client_options_1.TEMPORAL_CLIENT_OPTIONS,
|
|
57
|
+
useFactory: async (factory) => factory.createTemporalClientOptions(),
|
|
58
|
+
inject: [options.useExisting ?? options.useClass],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
exports.TemporalClientModule = TemporalClientModule;
|
|
63
|
+
exports.TemporalClientModule = TemporalClientModule = TemporalClientModule_1 = __decorate([
|
|
64
|
+
(0, common_1.Module)({})
|
|
65
|
+
], TemporalClientModule);
|
|
66
|
+
//# sourceMappingURL=temporal-client.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.module.js","sourceRoot":"","sources":["../src/temporal-client.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAiE;AACjE,uEAKmC;AACnC,uEAAkE;AAG3D,IAAM,oBAAoB,4BAA1B,MAAM,oBAAoB;IAO/B,MAAM,CAAC,OAAO,CAAC,UAAuC,EAAE;QACtD,OAAO;YACL,MAAM,EAAE,sBAAoB;YAC5B,MAAM,EAAE,IAAI;YACZ,SAAS,EAAE;gBACT,EAAE,OAAO,EAAE,iDAAuB,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACvD,+CAAqB;aACtB;YACD,OAAO,EAAE,CAAC,+CAAqB,CAA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A8EhC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ModuleMetadata, Type } from '@nestjs/common';
|
|
2
|
+
import { TLSConfig } from '@temporalio/client';
|
|
3
|
+
export declare const TEMPORAL_CLIENT_OPTIONS: unique symbol;
|
|
4
|
+
export interface TemporalClientModuleOptions {
|
|
5
|
+
address?: string;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
tls?: TLSConfig;
|
|
8
|
+
}
|
|
9
|
+
export interface TemporalClientOptionsFactory {
|
|
10
|
+
createTemporalClientOptions(): Promise<TemporalClientModuleOptions> | TemporalClientModuleOptions;
|
|
11
|
+
}
|
|
12
|
+
export interface TemporalClientModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
|
|
13
|
+
useExisting?: Type<TemporalClientOptionsFactory>;
|
|
14
|
+
useClass?: Type<TemporalClientOptionsFactory>;
|
|
15
|
+
useFactory?: (...args: any[]) => Promise<TemporalClientModuleOptions> | TemporalClientModuleOptions;
|
|
16
|
+
inject?: any[];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.options.js","sourceRoot":"","sources":["../src/temporal-client.options.ts"],"names":[],"mappings":";;;AAGa,QAAA,uBAAuB,GAAG,MAAM,CAAC,yBAAyB,CAAC,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { WorkflowHandle, WorkflowExecutionDescription } from "@temporalio/client";
|
|
3
|
+
import { TemporalClientModuleOptions } from "./temporal-client.options";
|
|
4
|
+
import { WorkflowTargetOptions, StartWorkflowOptions, SignalWorkflowOptions, QueryWorkflowOptions, UpdateWorkflowOptions, TerminateWorkflowOptions } from "./options";
|
|
5
|
+
export declare class TemporalClientService implements OnModuleInit, OnModuleDestroy {
|
|
6
|
+
private readonly options;
|
|
7
|
+
private client;
|
|
8
|
+
private connection;
|
|
9
|
+
constructor(options: TemporalClientModuleOptions);
|
|
10
|
+
onModuleInit(): Promise<void>;
|
|
11
|
+
onModuleDestroy(): Promise<void>;
|
|
12
|
+
getHandle({ workflowId, runId }: WorkflowTargetOptions): WorkflowHandle;
|
|
13
|
+
startWorkflow(options: StartWorkflowOptions): Promise<string>;
|
|
14
|
+
signalWorkflow({ signalName, args, ...target }: SignalWorkflowOptions): Promise<void>;
|
|
15
|
+
queryWorkflow<T = unknown>({ queryName, args, ...target }: QueryWorkflowOptions): Promise<T>;
|
|
16
|
+
updateWorkflow<T = unknown>({ updateName, args, ...target }: UpdateWorkflowOptions): Promise<T>;
|
|
17
|
+
cancelWorkflow(options: WorkflowTargetOptions): Promise<void>;
|
|
18
|
+
terminateWorkflow({ reason, ...target }: TerminateWorkflowOptions): Promise<void>;
|
|
19
|
+
describeWorkflow(options: WorkflowTargetOptions): Promise<WorkflowExecutionDescription>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.TemporalClientService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const client_1 = require("@temporalio/client");
|
|
18
|
+
const temporal_client_options_1 = require("./temporal-client.options");
|
|
19
|
+
let TemporalClientService = class TemporalClientService {
|
|
20
|
+
constructor(options) {
|
|
21
|
+
this.options = options;
|
|
22
|
+
}
|
|
23
|
+
async onModuleInit() {
|
|
24
|
+
this.connection = await client_1.Connection.connect({
|
|
25
|
+
address: this.options.address ?? "localhost:7233",
|
|
26
|
+
tls: this.options.tls,
|
|
27
|
+
});
|
|
28
|
+
this.client = new client_1.Client({
|
|
29
|
+
connection: this.connection,
|
|
30
|
+
namespace: this.options.namespace ?? "default",
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
async onModuleDestroy() {
|
|
34
|
+
await this.connection.close();
|
|
35
|
+
}
|
|
36
|
+
getHandle({ workflowId, runId }) {
|
|
37
|
+
return this.client.workflow.getHandle(workflowId, runId);
|
|
38
|
+
}
|
|
39
|
+
async startWorkflow(options) {
|
|
40
|
+
const { workflowName, args = [], workflowId, taskQueue, runId: _runId, ...rest } = options;
|
|
41
|
+
const handle = await this.client.workflow.start(workflowName, {
|
|
42
|
+
workflowId,
|
|
43
|
+
taskQueue,
|
|
44
|
+
args,
|
|
45
|
+
...rest,
|
|
46
|
+
});
|
|
47
|
+
return handle.workflowId;
|
|
48
|
+
}
|
|
49
|
+
async signalWorkflow({ signalName, args, ...target }) {
|
|
50
|
+
const handle = this.getHandle(target);
|
|
51
|
+
await handle.signal(signalName, ...(args ?? []));
|
|
52
|
+
}
|
|
53
|
+
async queryWorkflow({ queryName, args, ...target }) {
|
|
54
|
+
const handle = this.getHandle(target);
|
|
55
|
+
return handle.query(queryName, ...(args ?? []));
|
|
56
|
+
}
|
|
57
|
+
async updateWorkflow({ updateName, args, ...target }) {
|
|
58
|
+
const handle = this.getHandle(target);
|
|
59
|
+
return handle.executeUpdate(updateName, {
|
|
60
|
+
args: (args ?? []),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async cancelWorkflow(options) {
|
|
64
|
+
const handle = this.getHandle(options);
|
|
65
|
+
await handle.cancel();
|
|
66
|
+
}
|
|
67
|
+
async terminateWorkflow({ reason, ...target }) {
|
|
68
|
+
const handle = this.getHandle(target);
|
|
69
|
+
await handle.terminate(reason);
|
|
70
|
+
}
|
|
71
|
+
async describeWorkflow(options) {
|
|
72
|
+
const handle = this.getHandle(options);
|
|
73
|
+
return handle.describe();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.TemporalClientService = TemporalClientService;
|
|
77
|
+
exports.TemporalClientService = TemporalClientService = __decorate([
|
|
78
|
+
(0, common_1.Injectable)(),
|
|
79
|
+
__param(0, (0, common_1.Inject)(temporal_client_options_1.TEMPORAL_CLIENT_OPTIONS)),
|
|
80
|
+
__metadata("design:paramtypes", [Object])
|
|
81
|
+
], TemporalClientService);
|
|
82
|
+
//# sourceMappingURL=temporal-client.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporal-client.service.js","sourceRoot":"","sources":["../src/temporal-client.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAKwB;AACxB,+CAK4B;AAC5B,uEAGmC;AAW5B,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;IAIhC,YAEmB,OAAoC;QAApC,YAAO,GAAP,OAAO,CAA6B;IACpD,CAAC;IAEJ,KAAK,CAAC,YAAY;QAChB,IAAI,CAAC,UAAU,GAAG,MAAM,mBAAU,CAAC,OAAO,CAAC;YACzC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB;YACjD,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,GAAG;SACtB,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC;YACvB,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,SAAS,EAAE,IAAI,CAAC,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V,IAAI,EACJ,GAAG,MAAM,EACa;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QAEtC,OAAO,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE;YACtC,IAAI,EAAE,CAAC,IAAI,IAAI,EAAE,CAAoB;SACtC,CAAe,CAAC;IACnB,CAAC;IAQD,KAAK,CAAC,cAAc,CAAC,OAA8B;QACjD,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACvC,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;IAQD,KAAK,CAAC,iBAAiB,CAAC,EACtB,MAAM,EACN,GAAG,MAAM,EACgB;QACzB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;QACtC,MAAM,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IACjC,CAAC;IAOD,KAAK,CAAC,gBAAgB,CACpB,OAA8B;QAE9B,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QACvC,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC3B,CAAC;CACF,CAAA;AA3JY,sDAAqB;gCAArB,qBAAqB;IADjC,IAAA,mBAAU,GAAE;IAMR,WAAA,IAAA,eAAM,EAAC,iDAAuB,CAAC,CAAA;;GALvB,qBAAqB,CA2JjC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nest-temporal-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "NestJS module for sending signals, updates, queries, and starting Temporal workflows",
|
|
5
|
+
"author": "Biliksuun",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsc -p tsconfig.build.json",
|
|
14
|
+
"build:watch": "tsc -p tsconfig.build.json --watch",
|
|
15
|
+
"lint": "eslint \"{src}/**/*.ts\" --fix",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@temporalio/client": "^1.15.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@nestjs/common": "^10.0.0 || ^11.0.0",
|
|
23
|
+
"@nestjs/core": "^10.0.0 || ^11.0.0",
|
|
24
|
+
"reflect-metadata": "^0.1.13 || ^0.2.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@nestjs/common": "^11.0.1",
|
|
28
|
+
"@nestjs/core": "^11.0.1",
|
|
29
|
+
"@types/node": "^24.0.0",
|
|
30
|
+
"reflect-metadata": "^0.2.2",
|
|
31
|
+
"typescript": "^5.7.3"
|
|
32
|
+
}
|
|
33
|
+
}
|