@temporal-contract/worker 0.0.5 → 0.0.7
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 +23 -0
- package/dist/activity-Csptpwgf.d.cts +162 -0
- package/dist/activity-UOnp_bSX.d.mts +162 -0
- package/dist/activity.cjs +190 -7
- package/dist/activity.d.cts +3 -2
- package/dist/activity.d.mts +3 -2
- package/dist/activity.mjs +182 -2
- package/dist/errors-BqVTpfcf.mjs +155 -0
- package/dist/errors-BqYWpdvd.d.cts +137 -0
- package/dist/errors-C1RFkCuD.d.mts +137 -0
- package/dist/errors-DjSZg-93.cjs +227 -0
- package/dist/worker.cjs +65 -0
- package/dist/worker.d.cts +68 -0
- package/dist/worker.d.mts +68 -0
- package/dist/worker.mjs +64 -0
- package/dist/workflow.cjs +255 -12
- package/dist/workflow.d.cts +299 -2
- package/dist/workflow.d.mts +299 -2
- package/dist/workflow.mjs +244 -2
- package/package.json +26 -14
- package/dist/handler-BAzNuAZz.cjs +0 -597
- package/dist/handler-Cp9h_XCy.d.cts +0 -560
- package/dist/handler-DFFpSaGN.mjs +0 -502
- package/dist/handler-uAeIi9f0.d.mts +0 -560
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/errors.ts
|
|
3
|
+
/**
|
|
4
|
+
* Base error class for worker errors
|
|
5
|
+
*/
|
|
6
|
+
var WorkerError = class extends Error {
|
|
7
|
+
constructor(message, cause) {
|
|
8
|
+
super(message, { cause });
|
|
9
|
+
this.name = "WorkerError";
|
|
10
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Error thrown when an activity definition is not found in the contract
|
|
15
|
+
*/
|
|
16
|
+
var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
17
|
+
constructor(activityName, availableDefinitions = []) {
|
|
18
|
+
const available = availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none";
|
|
19
|
+
super(`Activity definition not found for: "${activityName}". Available activities: ${available}`);
|
|
20
|
+
this.activityName = activityName;
|
|
21
|
+
this.availableDefinitions = availableDefinitions;
|
|
22
|
+
this.name = "ActivityDefinitionNotFoundError";
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Error thrown when activity input validation fails
|
|
27
|
+
*/
|
|
28
|
+
var ActivityInputValidationError = class extends WorkerError {
|
|
29
|
+
constructor(activityName, issues) {
|
|
30
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
31
|
+
super(`Activity "${activityName}" input validation failed: ${message}`);
|
|
32
|
+
this.activityName = activityName;
|
|
33
|
+
this.issues = issues;
|
|
34
|
+
this.name = "ActivityInputValidationError";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Error thrown when activity output validation fails
|
|
39
|
+
*/
|
|
40
|
+
var ActivityOutputValidationError = class extends WorkerError {
|
|
41
|
+
constructor(activityName, issues) {
|
|
42
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
43
|
+
super(`Activity "${activityName}" output validation failed: ${message}`);
|
|
44
|
+
this.activityName = activityName;
|
|
45
|
+
this.issues = issues;
|
|
46
|
+
this.name = "ActivityOutputValidationError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Error thrown when workflow input validation fails
|
|
51
|
+
*/
|
|
52
|
+
var WorkflowInputValidationError = class extends WorkerError {
|
|
53
|
+
constructor(workflowName, issues) {
|
|
54
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
55
|
+
super(`Workflow "${workflowName}" input validation failed: ${message}`);
|
|
56
|
+
this.workflowName = workflowName;
|
|
57
|
+
this.issues = issues;
|
|
58
|
+
this.name = "WorkflowInputValidationError";
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Error thrown when workflow output validation fails
|
|
63
|
+
*/
|
|
64
|
+
var WorkflowOutputValidationError = class extends WorkerError {
|
|
65
|
+
constructor(workflowName, issues) {
|
|
66
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
67
|
+
super(`Workflow "${workflowName}" output validation failed: ${message}`);
|
|
68
|
+
this.workflowName = workflowName;
|
|
69
|
+
this.issues = issues;
|
|
70
|
+
this.name = "WorkflowOutputValidationError";
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Error thrown when signal input validation fails
|
|
75
|
+
*/
|
|
76
|
+
var SignalInputValidationError = class extends WorkerError {
|
|
77
|
+
constructor(signalName, issues) {
|
|
78
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
79
|
+
super(`Signal "${signalName}" input validation failed: ${message}`);
|
|
80
|
+
this.signalName = signalName;
|
|
81
|
+
this.issues = issues;
|
|
82
|
+
this.name = "SignalInputValidationError";
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Error thrown when query input validation fails
|
|
87
|
+
*/
|
|
88
|
+
var QueryInputValidationError = class extends WorkerError {
|
|
89
|
+
constructor(queryName, issues) {
|
|
90
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
91
|
+
super(`Query "${queryName}" input validation failed: ${message}`);
|
|
92
|
+
this.queryName = queryName;
|
|
93
|
+
this.issues = issues;
|
|
94
|
+
this.name = "QueryInputValidationError";
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* Error thrown when query output validation fails
|
|
99
|
+
*/
|
|
100
|
+
var QueryOutputValidationError = class extends WorkerError {
|
|
101
|
+
constructor(queryName, issues) {
|
|
102
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
103
|
+
super(`Query "${queryName}" output validation failed: ${message}`);
|
|
104
|
+
this.queryName = queryName;
|
|
105
|
+
this.issues = issues;
|
|
106
|
+
this.name = "QueryOutputValidationError";
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Error thrown when update input validation fails
|
|
111
|
+
*/
|
|
112
|
+
var UpdateInputValidationError = class extends WorkerError {
|
|
113
|
+
constructor(updateName, issues) {
|
|
114
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
115
|
+
super(`Update "${updateName}" input validation failed: ${message}`);
|
|
116
|
+
this.updateName = updateName;
|
|
117
|
+
this.issues = issues;
|
|
118
|
+
this.name = "UpdateInputValidationError";
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Error thrown when update output validation fails
|
|
123
|
+
*/
|
|
124
|
+
var UpdateOutputValidationError = class extends WorkerError {
|
|
125
|
+
constructor(updateName, issues) {
|
|
126
|
+
const message = issues.map((issue) => issue.message).join("; ");
|
|
127
|
+
super(`Update "${updateName}" output validation failed: ${message}`);
|
|
128
|
+
this.updateName = updateName;
|
|
129
|
+
this.issues = issues;
|
|
130
|
+
this.name = "UpdateOutputValidationError";
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Error thrown when a child workflow is not found in the contract
|
|
135
|
+
*/
|
|
136
|
+
var ChildWorkflowNotFoundError = class extends WorkerError {
|
|
137
|
+
constructor(workflowName, availableWorkflows = []) {
|
|
138
|
+
const available = availableWorkflows.length > 0 ? availableWorkflows.join(", ") : "none";
|
|
139
|
+
super(`Child workflow not found: "${workflowName}". Available workflows: ${available}`);
|
|
140
|
+
this.workflowName = workflowName;
|
|
141
|
+
this.availableWorkflows = availableWorkflows;
|
|
142
|
+
this.name = "ChildWorkflowNotFoundError";
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Generic error for child workflow operations
|
|
147
|
+
*/
|
|
148
|
+
var ChildWorkflowError = class extends WorkerError {
|
|
149
|
+
constructor(message, cause) {
|
|
150
|
+
super(message, cause);
|
|
151
|
+
this.name = "ChildWorkflowError";
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
//#endregion
|
|
156
|
+
Object.defineProperty(exports, 'ActivityDefinitionNotFoundError', {
|
|
157
|
+
enumerable: true,
|
|
158
|
+
get: function () {
|
|
159
|
+
return ActivityDefinitionNotFoundError;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
Object.defineProperty(exports, 'ActivityInputValidationError', {
|
|
163
|
+
enumerable: true,
|
|
164
|
+
get: function () {
|
|
165
|
+
return ActivityInputValidationError;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
Object.defineProperty(exports, 'ActivityOutputValidationError', {
|
|
169
|
+
enumerable: true,
|
|
170
|
+
get: function () {
|
|
171
|
+
return ActivityOutputValidationError;
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
Object.defineProperty(exports, 'ChildWorkflowError', {
|
|
175
|
+
enumerable: true,
|
|
176
|
+
get: function () {
|
|
177
|
+
return ChildWorkflowError;
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
Object.defineProperty(exports, 'ChildWorkflowNotFoundError', {
|
|
181
|
+
enumerable: true,
|
|
182
|
+
get: function () {
|
|
183
|
+
return ChildWorkflowNotFoundError;
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
Object.defineProperty(exports, 'QueryInputValidationError', {
|
|
187
|
+
enumerable: true,
|
|
188
|
+
get: function () {
|
|
189
|
+
return QueryInputValidationError;
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
Object.defineProperty(exports, 'QueryOutputValidationError', {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function () {
|
|
195
|
+
return QueryOutputValidationError;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
Object.defineProperty(exports, 'SignalInputValidationError', {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function () {
|
|
201
|
+
return SignalInputValidationError;
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(exports, 'UpdateInputValidationError', {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function () {
|
|
207
|
+
return UpdateInputValidationError;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
Object.defineProperty(exports, 'UpdateOutputValidationError', {
|
|
211
|
+
enumerable: true,
|
|
212
|
+
get: function () {
|
|
213
|
+
return UpdateOutputValidationError;
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
Object.defineProperty(exports, 'WorkflowInputValidationError', {
|
|
217
|
+
enumerable: true,
|
|
218
|
+
get: function () {
|
|
219
|
+
return WorkflowInputValidationError;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
Object.defineProperty(exports, 'WorkflowOutputValidationError', {
|
|
223
|
+
enumerable: true,
|
|
224
|
+
get: function () {
|
|
225
|
+
return WorkflowOutputValidationError;
|
|
226
|
+
}
|
|
227
|
+
});
|
package/dist/worker.cjs
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
let _temporalio_worker = require("@temporalio/worker");
|
|
2
|
+
let node_url = require("node:url");
|
|
3
|
+
let node_path = require("node:path");
|
|
4
|
+
|
|
5
|
+
//#region src/worker.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create a typed Temporal worker with contract-based configuration
|
|
8
|
+
*
|
|
9
|
+
* This helper simplifies worker creation by:
|
|
10
|
+
* - Using the contract's task queue automatically
|
|
11
|
+
* - Providing type-safe configuration
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { NativeConnection } from '@temporalio/worker';
|
|
16
|
+
* import { createWorker } from '@temporal-contract/worker/worker';
|
|
17
|
+
* import { activities } from './activities';
|
|
18
|
+
* import myContract from './contract';
|
|
19
|
+
*
|
|
20
|
+
* const connection = await NativeConnection.connect({
|
|
21
|
+
* address: 'localhost:7233',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const worker = await createWorker({
|
|
25
|
+
* contract: myContract,
|
|
26
|
+
* connection,
|
|
27
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
28
|
+
* activities,
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await worker.run();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async function createWorker(options) {
|
|
35
|
+
const { contract, activities, ...workerOptions } = options;
|
|
36
|
+
return await _temporalio_worker.Worker.create({
|
|
37
|
+
...workerOptions,
|
|
38
|
+
activities,
|
|
39
|
+
taskQueue: contract.taskQueue
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper to create a workflowsPath from a file URL
|
|
44
|
+
*
|
|
45
|
+
* Useful for creating the workflowsPath option when using ES modules
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
|
|
50
|
+
*
|
|
51
|
+
* const worker = await createWorker({
|
|
52
|
+
* contract: myContract,
|
|
53
|
+
* connection,
|
|
54
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
|
|
55
|
+
* activities,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function workflowsPathFromURL(baseURL, relativePath) {
|
|
60
|
+
return (0, node_url.fileURLToPath)(new URL(`${relativePath}${(0, node_path.extname)(baseURL)}`, baseURL));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
exports.createWorker = createWorker;
|
|
65
|
+
exports.workflowsPathFromURL = workflowsPathFromURL;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as ActivitiesHandler } from "./activity-Csptpwgf.cjs";
|
|
2
|
+
import { ContractDefinition } from "@temporal-contract/contract";
|
|
3
|
+
import { Worker, WorkerOptions } from "@temporalio/worker";
|
|
4
|
+
|
|
5
|
+
//#region src/worker.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating a Temporal worker
|
|
9
|
+
*/
|
|
10
|
+
interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit<WorkerOptions, "activities" | "taskQueue"> {
|
|
11
|
+
/**
|
|
12
|
+
* The contract definition for this worker
|
|
13
|
+
*/
|
|
14
|
+
contract: TContract;
|
|
15
|
+
/**
|
|
16
|
+
* Activities handler for this worker
|
|
17
|
+
*/
|
|
18
|
+
activities: ActivitiesHandler<TContract>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a typed Temporal worker with contract-based configuration
|
|
22
|
+
*
|
|
23
|
+
* This helper simplifies worker creation by:
|
|
24
|
+
* - Using the contract's task queue automatically
|
|
25
|
+
* - Providing type-safe configuration
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { NativeConnection } from '@temporalio/worker';
|
|
30
|
+
* import { createWorker } from '@temporal-contract/worker/worker';
|
|
31
|
+
* import { activities } from './activities';
|
|
32
|
+
* import myContract from './contract';
|
|
33
|
+
*
|
|
34
|
+
* const connection = await NativeConnection.connect({
|
|
35
|
+
* address: 'localhost:7233',
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const worker = await createWorker({
|
|
39
|
+
* contract: myContract,
|
|
40
|
+
* connection,
|
|
41
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
42
|
+
* activities,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await worker.run();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
|
|
49
|
+
/**
|
|
50
|
+
* Helper to create a workflowsPath from a file URL
|
|
51
|
+
*
|
|
52
|
+
* Useful for creating the workflowsPath option when using ES modules
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
|
|
57
|
+
*
|
|
58
|
+
* const worker = await createWorker({
|
|
59
|
+
* contract: myContract,
|
|
60
|
+
* connection,
|
|
61
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
|
|
62
|
+
* activities,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { t as ActivitiesHandler } from "./activity-UOnp_bSX.mjs";
|
|
2
|
+
import { Worker, WorkerOptions } from "@temporalio/worker";
|
|
3
|
+
import { ContractDefinition } from "@temporal-contract/contract";
|
|
4
|
+
|
|
5
|
+
//#region src/worker.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Options for creating a Temporal worker
|
|
9
|
+
*/
|
|
10
|
+
interface CreateWorkerOptions<TContract extends ContractDefinition> extends Omit<WorkerOptions, "activities" | "taskQueue"> {
|
|
11
|
+
/**
|
|
12
|
+
* The contract definition for this worker
|
|
13
|
+
*/
|
|
14
|
+
contract: TContract;
|
|
15
|
+
/**
|
|
16
|
+
* Activities handler for this worker
|
|
17
|
+
*/
|
|
18
|
+
activities: ActivitiesHandler<TContract>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a typed Temporal worker with contract-based configuration
|
|
22
|
+
*
|
|
23
|
+
* This helper simplifies worker creation by:
|
|
24
|
+
* - Using the contract's task queue automatically
|
|
25
|
+
* - Providing type-safe configuration
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { NativeConnection } from '@temporalio/worker';
|
|
30
|
+
* import { createWorker } from '@temporal-contract/worker/worker';
|
|
31
|
+
* import { activities } from './activities';
|
|
32
|
+
* import myContract from './contract';
|
|
33
|
+
*
|
|
34
|
+
* const connection = await NativeConnection.connect({
|
|
35
|
+
* address: 'localhost:7233',
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* const worker = await createWorker({
|
|
39
|
+
* contract: myContract,
|
|
40
|
+
* connection,
|
|
41
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
42
|
+
* activities,
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* await worker.run();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare function createWorker<TContract extends ContractDefinition>(options: CreateWorkerOptions<TContract>): Promise<Worker>;
|
|
49
|
+
/**
|
|
50
|
+
* Helper to create a workflowsPath from a file URL
|
|
51
|
+
*
|
|
52
|
+
* Useful for creating the workflowsPath option when using ES modules
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
|
|
57
|
+
*
|
|
58
|
+
* const worker = await createWorker({
|
|
59
|
+
* contract: myContract,
|
|
60
|
+
* connection,
|
|
61
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
|
|
62
|
+
* activities,
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare function workflowsPathFromURL(baseURL: string, relativePath: string): string;
|
|
67
|
+
//#endregion
|
|
68
|
+
export { CreateWorkerOptions, createWorker, workflowsPathFromURL };
|
package/dist/worker.mjs
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Worker } from "@temporalio/worker";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { extname } from "node:path";
|
|
4
|
+
|
|
5
|
+
//#region src/worker.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create a typed Temporal worker with contract-based configuration
|
|
8
|
+
*
|
|
9
|
+
* This helper simplifies worker creation by:
|
|
10
|
+
* - Using the contract's task queue automatically
|
|
11
|
+
* - Providing type-safe configuration
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { NativeConnection } from '@temporalio/worker';
|
|
16
|
+
* import { createWorker } from '@temporal-contract/worker/worker';
|
|
17
|
+
* import { activities } from './activities';
|
|
18
|
+
* import myContract from './contract';
|
|
19
|
+
*
|
|
20
|
+
* const connection = await NativeConnection.connect({
|
|
21
|
+
* address: 'localhost:7233',
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* const worker = await createWorker({
|
|
25
|
+
* contract: myContract,
|
|
26
|
+
* connection,
|
|
27
|
+
* workflowsPath: require.resolve('./workflows'),
|
|
28
|
+
* activities,
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* await worker.run();
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
async function createWorker(options) {
|
|
35
|
+
const { contract, activities, ...workerOptions } = options;
|
|
36
|
+
return await Worker.create({
|
|
37
|
+
...workerOptions,
|
|
38
|
+
activities,
|
|
39
|
+
taskQueue: contract.taskQueue
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Helper to create a workflowsPath from a file URL
|
|
44
|
+
*
|
|
45
|
+
* Useful for creating the workflowsPath option when using ES modules
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* import { workflowsPathFromURL } from '@temporal-contract/worker/worker';
|
|
50
|
+
*
|
|
51
|
+
* const worker = await createWorker({
|
|
52
|
+
* contract: myContract,
|
|
53
|
+
* connection,
|
|
54
|
+
* workflowsPath: workflowsPathFromURL(import.meta.url, './workflows'),
|
|
55
|
+
* activities,
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
function workflowsPathFromURL(baseURL, relativePath) {
|
|
60
|
+
return fileURLToPath(new URL(`${relativePath}${extname(baseURL)}`, baseURL));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//#endregion
|
|
64
|
+
export { createWorker, workflowsPathFromURL };
|