@temporal-contract/worker 0.0.3 → 0.0.5
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 +49 -0
- package/dist/activity.cjs +2 -2
- package/dist/activity.d.cts +2 -2
- package/dist/activity.d.mts +2 -2
- package/dist/activity.mjs +2 -2
- package/dist/{handler-Cc951VQp.cjs → handler-BAzNuAZz.cjs} +217 -79
- package/dist/handler-Cp9h_XCy.d.cts +560 -0
- package/dist/handler-DFFpSaGN.mjs +502 -0
- package/dist/handler-uAeIi9f0.d.mts +560 -0
- package/dist/workflow.cjs +3 -1
- package/dist/workflow.d.cts +2 -2
- package/dist/workflow.d.mts +2 -2
- package/dist/workflow.mjs +2 -2
- package/package.json +36 -28
- package/dist/errors-B50uht6a.d.cts +0 -302
- package/dist/errors-DgUMRes-.d.mts +0 -302
- package/dist/handler-BP9xAycT.mjs +0 -376
package/README.md
CHANGED
|
@@ -36,6 +36,55 @@ export const processOrder = declareWorkflow({
|
|
|
36
36
|
});
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
+
### Child Workflows
|
|
40
|
+
|
|
41
|
+
Execute child workflows with type-safe Future/Result pattern. Supports both same-contract and cross-contract child workflows:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// workflows.ts
|
|
45
|
+
import { declareWorkflow } from '@temporal-contract/worker/workflow';
|
|
46
|
+
|
|
47
|
+
export const parentWorkflow = declareWorkflow({
|
|
48
|
+
workflowName: 'parentWorkflow',
|
|
49
|
+
contract: myContract,
|
|
50
|
+
implementation: async (context, input) => {
|
|
51
|
+
// Execute child workflow from same contract and wait for result
|
|
52
|
+
const childResult = await context.executeChildWorkflow(myContract, 'processPayment', {
|
|
53
|
+
workflowId: `payment-${input.orderId}`,
|
|
54
|
+
args: { amount: input.totalAmount }
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
childResult.match({
|
|
58
|
+
Ok: (output) => console.log('Payment processed:', output),
|
|
59
|
+
Error: (error) => console.error('Payment failed:', error),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Execute child workflow from another contract (another worker)
|
|
63
|
+
const notificationResult = await context.executeChildWorkflow(notificationContract, 'sendNotification', {
|
|
64
|
+
workflowId: `notification-${input.orderId}`,
|
|
65
|
+
args: { message: 'Order received' }
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// Or start child workflow without waiting
|
|
69
|
+
const handleResult = await context.startChildWorkflow(myContract, 'sendEmail', {
|
|
70
|
+
workflowId: `email-${input.orderId}`,
|
|
71
|
+
args: { to: 'user@example.com', body: 'Order received' }
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
handleResult.match({
|
|
75
|
+
Ok: async (handle) => {
|
|
76
|
+
// Can wait for result later
|
|
77
|
+
const result = await handle.result();
|
|
78
|
+
// ...
|
|
79
|
+
},
|
|
80
|
+
Error: (error) => console.error('Failed to start:', error),
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return { success: true };
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
39
88
|
## Documentation
|
|
40
89
|
|
|
41
90
|
📖 **[Read the full documentation →](https://btravers.github.io/temporal-contract)**
|
package/dist/activity.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const require_handler = require('./handler-
|
|
1
|
+
const require_handler = require('./handler-BAzNuAZz.cjs');
|
|
2
2
|
|
|
3
3
|
exports.ActivityDefinitionNotFoundError = require_handler.ActivityDefinitionNotFoundError;
|
|
4
|
-
exports.
|
|
4
|
+
exports.ActivityError = require_handler.ActivityError;
|
|
5
5
|
exports.ActivityInputValidationError = require_handler.ActivityInputValidationError;
|
|
6
6
|
exports.ActivityOutputValidationError = require_handler.ActivityOutputValidationError;
|
|
7
7
|
exports.WorkerError = require_handler.WorkerError;
|
package/dist/activity.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActivitiesHandler, ActivityDefinitionNotFoundError,
|
|
1
|
+
import { A as WorkerInferActivities, E as WorkerError, M as WorkerInferInput, N as WorkerInferOutput, R as WorkerInferWorkflowActivities, W as WorkflowActivityHandler, _ as ActivityInputValidationError, g as ActivityError, h as ActivityDefinitionNotFoundError, i as DeclareActivitiesHandlerOptions, j as WorkerInferActivity, k as ActivityHandler, n as ActivityImplementations, p as declareActivitiesHandler, r as BoxedActivityImplementation, t as ActivitiesHandler, v as ActivityOutputValidationError, z as WorkerInferWorkflowContextActivities } from "./handler-Cp9h_XCy.cjs";
|
|
2
|
+
export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, type ActivityHandler, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, type BoxedActivityImplementation, type DeclareActivitiesHandlerOptions, WorkerError, type WorkerInferActivities, type WorkerInferActivity, type WorkerInferInput, type WorkerInferOutput, type WorkerInferWorkflowActivities, type WorkerInferWorkflowContextActivities, type WorkflowActivityHandler, declareActivitiesHandler };
|
package/dist/activity.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActivitiesHandler, ActivityDefinitionNotFoundError,
|
|
1
|
+
import { A as WorkerInferActivities, E as WorkerError, M as WorkerInferInput, N as WorkerInferOutput, R as WorkerInferWorkflowActivities, W as WorkflowActivityHandler, _ as ActivityInputValidationError, g as ActivityError, h as ActivityDefinitionNotFoundError, i as DeclareActivitiesHandlerOptions, j as WorkerInferActivity, k as ActivityHandler, n as ActivityImplementations, p as declareActivitiesHandler, r as BoxedActivityImplementation, t as ActivitiesHandler, v as ActivityOutputValidationError, z as WorkerInferWorkflowContextActivities } from "./handler-uAeIi9f0.mjs";
|
|
2
|
+
export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, type ActivityHandler, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, type BoxedActivityImplementation, type DeclareActivitiesHandlerOptions, WorkerError, type WorkerInferActivities, type WorkerInferActivity, type WorkerInferInput, type WorkerInferOutput, type WorkerInferWorkflowActivities, type WorkerInferWorkflowContextActivities, type WorkflowActivityHandler, declareActivitiesHandler };
|
package/dist/activity.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as ActivityInputValidationError,
|
|
1
|
+
import { a as ActivityInputValidationError, i as ActivityError, m as WorkerError, o as ActivityOutputValidationError, r as ActivityDefinitionNotFoundError, t as declareActivitiesHandler } from "./handler-DFFpSaGN.mjs";
|
|
2
2
|
|
|
3
|
-
export { ActivityDefinitionNotFoundError,
|
|
3
|
+
export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError, WorkerError, declareActivitiesHandler };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let __temporal_contract_boxed = require("@temporal-contract/boxed");
|
|
1
2
|
let __temporalio_workflow = require("@temporalio/workflow");
|
|
2
3
|
|
|
3
4
|
//#region src/errors.ts
|
|
@@ -5,29 +6,34 @@ let __temporalio_workflow = require("@temporalio/workflow");
|
|
|
5
6
|
* Base error class for worker errors
|
|
6
7
|
*/
|
|
7
8
|
var WorkerError = class extends Error {
|
|
8
|
-
constructor(message) {
|
|
9
|
-
super(message);
|
|
9
|
+
constructor(message, cause) {
|
|
10
|
+
super(message, { cause });
|
|
10
11
|
this.name = "WorkerError";
|
|
11
12
|
if (Error.captureStackTrace) Error.captureStackTrace(this, this.constructor);
|
|
12
13
|
}
|
|
13
14
|
};
|
|
14
15
|
/**
|
|
15
|
-
*
|
|
16
|
+
* Activity error class that should be used to wrap all technical exceptions
|
|
17
|
+
* Forces proper error handling and enables retry policies
|
|
16
18
|
*/
|
|
17
|
-
var
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
this.
|
|
19
|
+
var ActivityError = class ActivityError extends Error {
|
|
20
|
+
code;
|
|
21
|
+
cause;
|
|
22
|
+
constructor(code, message, cause) {
|
|
23
|
+
super(message, { cause });
|
|
24
|
+
this.code = code;
|
|
25
|
+
this.cause = cause;
|
|
26
|
+
this.name = "ActivityError";
|
|
27
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, ActivityError);
|
|
23
28
|
}
|
|
24
29
|
};
|
|
25
30
|
/**
|
|
26
31
|
* Error thrown when an activity definition is not found in the contract
|
|
27
32
|
*/
|
|
28
33
|
var ActivityDefinitionNotFoundError = class extends WorkerError {
|
|
29
|
-
constructor(activityName, availableDefinitions) {
|
|
30
|
-
|
|
34
|
+
constructor(activityName, availableDefinitions = []) {
|
|
35
|
+
const available = availableDefinitions.length > 0 ? availableDefinitions.join(", ") : "none";
|
|
36
|
+
super(`Activity definition not found for: "${activityName}". Available activities: ${available}`);
|
|
31
37
|
this.activityName = activityName;
|
|
32
38
|
this.availableDefinitions = availableDefinitions;
|
|
33
39
|
this.name = "ActivityDefinitionNotFoundError";
|
|
@@ -141,6 +147,27 @@ var UpdateOutputValidationError = class extends WorkerError {
|
|
|
141
147
|
this.name = "UpdateOutputValidationError";
|
|
142
148
|
}
|
|
143
149
|
};
|
|
150
|
+
/**
|
|
151
|
+
* Error thrown when a child workflow is not found in the contract
|
|
152
|
+
*/
|
|
153
|
+
var ChildWorkflowNotFoundError = class extends WorkerError {
|
|
154
|
+
constructor(workflowName, availableWorkflows = []) {
|
|
155
|
+
const available = availableWorkflows.length > 0 ? availableWorkflows.join(", ") : "none";
|
|
156
|
+
super(`Child workflow not found: "${workflowName}". Available workflows: ${available}`);
|
|
157
|
+
this.workflowName = workflowName;
|
|
158
|
+
this.availableWorkflows = availableWorkflows;
|
|
159
|
+
this.name = "ChildWorkflowNotFoundError";
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
/**
|
|
163
|
+
* Generic error for child workflow operations
|
|
164
|
+
*/
|
|
165
|
+
var ChildWorkflowError = class extends WorkerError {
|
|
166
|
+
constructor(message, cause) {
|
|
167
|
+
super(message, cause);
|
|
168
|
+
this.name = "ChildWorkflowError";
|
|
169
|
+
}
|
|
170
|
+
};
|
|
144
171
|
|
|
145
172
|
//#endregion
|
|
146
173
|
//#region src/handler.ts
|
|
@@ -158,7 +185,7 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
158
185
|
};
|
|
159
186
|
for (const [activityName, activityDef] of Object.entries(allActivitiesDefinition)) {
|
|
160
187
|
const rawActivity = rawActivities[activityName];
|
|
161
|
-
if (!rawActivity) throw new
|
|
188
|
+
if (!rawActivity) throw new Error(`Activity implementation not found for: "${activityName}". Available activities: ${Object.keys(rawActivities).length > 0 ? Object.keys(rawActivities).join(", ") : "none"}`);
|
|
162
189
|
const wrappedActivity = async (input) => {
|
|
163
190
|
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
164
191
|
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
@@ -172,30 +199,44 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
172
199
|
return validatedActivities;
|
|
173
200
|
}
|
|
174
201
|
/**
|
|
175
|
-
* Create a typed activities handler with automatic validation
|
|
202
|
+
* Create a typed activities handler with automatic validation and Result pattern
|
|
203
|
+
*
|
|
204
|
+
* This wraps all activity implementations with:
|
|
205
|
+
* - Validation at network boundaries
|
|
206
|
+
* - Result<T, ActivityError> pattern for explicit error handling
|
|
207
|
+
* - Automatic conversion from Result to Promise (throwing on Error)
|
|
176
208
|
*
|
|
177
|
-
* This wraps all activity implementations with Zod validation at network boundaries.
|
|
178
209
|
* TypeScript ensures ALL activities (global + workflow-specific) are implemented.
|
|
179
210
|
*
|
|
180
211
|
* Use this to create the activities object for the Temporal Worker.
|
|
181
212
|
*
|
|
182
213
|
* @example
|
|
183
214
|
* ```ts
|
|
184
|
-
* import { declareActivitiesHandler } from '@temporal-contract/worker';
|
|
215
|
+
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
216
|
+
* import { Result, Future } from '@temporal-contract/boxed';
|
|
185
217
|
* import myContract from './contract';
|
|
186
218
|
*
|
|
187
219
|
* export const activitiesHandler = declareActivitiesHandler({
|
|
188
220
|
* contract: myContract,
|
|
189
221
|
* activities: {
|
|
190
|
-
* //
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
* return
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
222
|
+
* // Activity returns Result instead of throwing
|
|
223
|
+
* // All technical exceptions must be wrapped in ActivityError for retry policies
|
|
224
|
+
* sendEmail: (args) => {
|
|
225
|
+
* return Future.make(async resolve => {
|
|
226
|
+
* try {
|
|
227
|
+
* await emailService.send(args);
|
|
228
|
+
* resolve(Result.Ok({ sent: true }));
|
|
229
|
+
* } catch (error) {
|
|
230
|
+
* // Wrap technical errors in ActivityError to enable retries
|
|
231
|
+
* resolve(Result.Error(
|
|
232
|
+
* new ActivityError(
|
|
233
|
+
* 'EMAIL_SEND_FAILED',
|
|
234
|
+
* 'Failed to send email',
|
|
235
|
+
* error // Original error as cause for debugging
|
|
236
|
+
* )
|
|
237
|
+
* ));
|
|
238
|
+
* }
|
|
239
|
+
* });
|
|
199
240
|
* },
|
|
200
241
|
* },
|
|
201
242
|
* });
|
|
@@ -224,13 +265,16 @@ function declareActivitiesHandler(options) {
|
|
|
224
265
|
break;
|
|
225
266
|
}
|
|
226
267
|
if (!activityDef) throw new ActivityDefinitionNotFoundError(activityName, allDefinitions);
|
|
227
|
-
wrappedActivities[activityName] = async (
|
|
268
|
+
wrappedActivities[activityName] = async (...args) => {
|
|
269
|
+
const input = args.length === 1 ? args[0] : args;
|
|
228
270
|
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
229
271
|
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
230
272
|
const result = await activityImpl(inputResult.value);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
273
|
+
if (result.isOk()) {
|
|
274
|
+
const outputResult = await activityDef.output["~standard"].validate(result.value);
|
|
275
|
+
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
276
|
+
return outputResult.value;
|
|
277
|
+
} else throw result.error;
|
|
234
278
|
};
|
|
235
279
|
}
|
|
236
280
|
return {
|
|
@@ -303,68 +347,150 @@ function declareActivitiesHandler(options) {
|
|
|
303
347
|
* ```
|
|
304
348
|
*/
|
|
305
349
|
function declareWorkflow(options) {
|
|
306
|
-
const { workflowName, contract, implementation, activityOptions
|
|
350
|
+
const { workflowName, contract, implementation, activityOptions } = options;
|
|
307
351
|
const definition = contract.workflows[workflowName];
|
|
308
352
|
return async (args) => {
|
|
309
353
|
const singleArg = Array.isArray(args) ? args[0] : args;
|
|
310
354
|
const inputResult = await definition.input["~standard"].validate(singleArg);
|
|
311
355
|
if (inputResult.issues) throw new WorkflowInputValidationError(String(workflowName), inputResult.issues);
|
|
312
356
|
const validatedInput = inputResult.value;
|
|
313
|
-
if (definition.signals && signals) {
|
|
314
|
-
const signalDefs = definition.signals;
|
|
315
|
-
const signalHandlers = signals;
|
|
316
|
-
for (const [signalName, signalDef] of Object.entries(signalDefs)) {
|
|
317
|
-
const handler = signalHandlers[signalName];
|
|
318
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineSignal)(signalName), async (...args$1) => {
|
|
319
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
320
|
-
const inputResult$1 = await signalDef.input["~standard"].validate(input);
|
|
321
|
-
if (inputResult$1.issues) throw new SignalInputValidationError(signalName, inputResult$1.issues);
|
|
322
|
-
await handler(inputResult$1.value);
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
if (definition.queries && queries) {
|
|
327
|
-
const queryDefs = definition.queries;
|
|
328
|
-
const queryHandlers = queries;
|
|
329
|
-
for (const [queryName, queryDef] of Object.entries(queryDefs)) {
|
|
330
|
-
const handler = queryHandlers[queryName];
|
|
331
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineQuery)(queryName), (...args$1) => {
|
|
332
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
333
|
-
const inputResult$1 = queryDef.input["~standard"].validate(input);
|
|
334
|
-
if (inputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
335
|
-
if (inputResult$1.issues) throw new QueryInputValidationError(queryName, inputResult$1.issues);
|
|
336
|
-
const result$1 = handler(inputResult$1.value);
|
|
337
|
-
const outputResult$1 = queryDef.output["~standard"].validate(result$1);
|
|
338
|
-
if (outputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
339
|
-
if (outputResult$1.issues) throw new QueryOutputValidationError(queryName, outputResult$1.issues);
|
|
340
|
-
return outputResult$1.value;
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
if (definition.updates && updates) {
|
|
345
|
-
const updateDefs = definition.updates;
|
|
346
|
-
const updateHandlers = updates;
|
|
347
|
-
for (const [updateName, updateDef] of Object.entries(updateDefs)) {
|
|
348
|
-
const handler = updateHandlers[updateName];
|
|
349
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineUpdate)(updateName), async (...args$1) => {
|
|
350
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
351
|
-
const inputResult$1 = await updateDef.input["~standard"].validate(input);
|
|
352
|
-
if (inputResult$1.issues) throw new UpdateInputValidationError(updateName, inputResult$1.issues);
|
|
353
|
-
const result$1 = await handler(inputResult$1.value);
|
|
354
|
-
const outputResult$1 = await updateDef.output["~standard"].validate(result$1);
|
|
355
|
-
if (outputResult$1.issues) throw new UpdateOutputValidationError(updateName, outputResult$1.issues);
|
|
356
|
-
return outputResult$1.value;
|
|
357
|
-
});
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
357
|
let contextActivities = {};
|
|
361
358
|
if (definition.activities || contract.activities) contextActivities = createValidatedActivities((0, __temporalio_workflow.proxyActivities)({
|
|
362
359
|
startToCloseTimeout: activityOptions?.startToCloseTimeout ?? 6e4,
|
|
363
360
|
...activityOptions
|
|
364
361
|
}), definition.activities, contract.activities);
|
|
362
|
+
async function validateChildWorkflowOutput(childDefinition, result$1, childWorkflowName) {
|
|
363
|
+
const outputResult$1 = await childDefinition.output["~standard"].validate(result$1);
|
|
364
|
+
if (outputResult$1.issues) return __temporal_contract_boxed.Result.Error(new ChildWorkflowError(`Child workflow "${childWorkflowName}" output validation failed: ${outputResult$1.issues.map((i) => i.message).join("; ")}`));
|
|
365
|
+
return __temporal_contract_boxed.Result.Ok(outputResult$1.value);
|
|
366
|
+
}
|
|
367
|
+
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args$1) {
|
|
368
|
+
const childDefinition = childContract.workflows[childWorkflowName];
|
|
369
|
+
if (!childDefinition) return __temporal_contract_boxed.Result.Error(new ChildWorkflowNotFoundError(String(childWorkflowName), Object.keys(childContract.workflows)));
|
|
370
|
+
const inputResult$1 = await childDefinition.input["~standard"].validate(args$1);
|
|
371
|
+
if (inputResult$1.issues) return __temporal_contract_boxed.Result.Error(new ChildWorkflowError(`Child workflow "${String(childWorkflowName)}" input validation failed: ${inputResult$1.issues.map((i) => i.message).join("; ")}`));
|
|
372
|
+
const validatedInput$1 = inputResult$1.value;
|
|
373
|
+
return __temporal_contract_boxed.Result.Ok({
|
|
374
|
+
definition: childDefinition,
|
|
375
|
+
validatedInput: validatedInput$1,
|
|
376
|
+
taskQueue: childContract.taskQueue
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
function createTypedChildHandle(handle, childDefinition, childWorkflowName) {
|
|
380
|
+
return {
|
|
381
|
+
workflowId: handle.workflowId,
|
|
382
|
+
result: () => {
|
|
383
|
+
return __temporal_contract_boxed.Future.make((resolve) => {
|
|
384
|
+
(async () => {
|
|
385
|
+
try {
|
|
386
|
+
resolve(await validateChildWorkflowOutput(childDefinition, await handle.result(), childWorkflowName));
|
|
387
|
+
} catch (error) {
|
|
388
|
+
resolve(__temporal_contract_boxed.Result.Error(new ChildWorkflowError(`Child workflow execution failed: ${error instanceof Error ? error.message : String(error)}`, error)));
|
|
389
|
+
}
|
|
390
|
+
})();
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function createStartChildWorkflow(childContract, childWorkflowName, options$1) {
|
|
396
|
+
return __temporal_contract_boxed.Future.make((resolve) => {
|
|
397
|
+
(async () => {
|
|
398
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options$1.args);
|
|
399
|
+
if (validationResult.isError()) {
|
|
400
|
+
resolve(__temporal_contract_boxed.Result.Error(validationResult.error));
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
const { definition: childDefinition, validatedInput: validatedInput$1, taskQueue } = validationResult.value;
|
|
404
|
+
try {
|
|
405
|
+
const { args: _args, ...temporalOptions } = options$1;
|
|
406
|
+
const typedHandle = createTypedChildHandle(await (0, __temporalio_workflow.startChild)(childWorkflowName, {
|
|
407
|
+
...temporalOptions,
|
|
408
|
+
taskQueue,
|
|
409
|
+
args: [validatedInput$1]
|
|
410
|
+
}), childDefinition, String(childWorkflowName));
|
|
411
|
+
resolve(__temporal_contract_boxed.Result.Ok(typedHandle));
|
|
412
|
+
} catch (error) {
|
|
413
|
+
resolve(__temporal_contract_boxed.Result.Error(new ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error)));
|
|
414
|
+
}
|
|
415
|
+
})();
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
function createExecuteChildWorkflow(childContract, childWorkflowName, options$1) {
|
|
419
|
+
return __temporal_contract_boxed.Future.make((resolve) => {
|
|
420
|
+
(async () => {
|
|
421
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options$1.args);
|
|
422
|
+
if (validationResult.isError()) {
|
|
423
|
+
resolve(__temporal_contract_boxed.Result.Error(validationResult.error));
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const { definition: childDefinition, validatedInput: validatedInput$1, taskQueue } = validationResult.value;
|
|
427
|
+
try {
|
|
428
|
+
const { args: _args, ...temporalOptions } = options$1;
|
|
429
|
+
const outputValidationResult = await validateChildWorkflowOutput(childDefinition, await (0, __temporalio_workflow.executeChild)(childWorkflowName, {
|
|
430
|
+
...temporalOptions,
|
|
431
|
+
taskQueue,
|
|
432
|
+
args: [validatedInput$1]
|
|
433
|
+
}), String(childWorkflowName));
|
|
434
|
+
if (outputValidationResult.isError()) {
|
|
435
|
+
resolve(__temporal_contract_boxed.Result.Error(outputValidationResult.error));
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
resolve(__temporal_contract_boxed.Result.Ok(outputValidationResult.value));
|
|
439
|
+
} catch (error) {
|
|
440
|
+
resolve(__temporal_contract_boxed.Result.Error(new ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error)));
|
|
441
|
+
}
|
|
442
|
+
})();
|
|
443
|
+
});
|
|
444
|
+
}
|
|
445
|
+
function createDefineSignal(signalName, handler) {
|
|
446
|
+
if (!definition.signals) throw new Error(`Signal "${String(signalName)}" cannot be defined: workflow "${String(workflowName)}" has no signals in its contract`);
|
|
447
|
+
const signalDef = definition.signals[signalName];
|
|
448
|
+
if (!signalDef) throw new Error(`Signal "${String(signalName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
449
|
+
(0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineSignal)(signalName), async (...args$1) => {
|
|
450
|
+
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
451
|
+
const inputResult$1 = await signalDef.input["~standard"].validate(input);
|
|
452
|
+
if (inputResult$1.issues) throw new SignalInputValidationError(signalName, inputResult$1.issues);
|
|
453
|
+
await handler(inputResult$1.value);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
function createDefineQuery(queryName, handler) {
|
|
457
|
+
if (!definition.queries) throw new Error(`Query "${String(queryName)}" cannot be defined: workflow "${String(workflowName)}" has no queries in its contract`);
|
|
458
|
+
const queryDef = definition.queries[queryName];
|
|
459
|
+
if (!queryDef) throw new Error(`Query "${String(queryName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
460
|
+
(0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineQuery)(queryName), (...args$1) => {
|
|
461
|
+
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
462
|
+
const inputResult$1 = queryDef.input["~standard"].validate(input);
|
|
463
|
+
if (inputResult$1 instanceof Promise) throw new Error(`Query "${String(queryName)}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
464
|
+
if (inputResult$1.issues) throw new QueryInputValidationError(queryName, inputResult$1.issues);
|
|
465
|
+
const result$1 = handler(inputResult$1.value);
|
|
466
|
+
const outputResult$1 = queryDef.output["~standard"].validate(result$1);
|
|
467
|
+
if (outputResult$1 instanceof Promise) throw new Error(`Query "${String(queryName)}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
468
|
+
if (outputResult$1.issues) throw new QueryOutputValidationError(queryName, outputResult$1.issues);
|
|
469
|
+
return outputResult$1.value;
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
function createDefineUpdate(updateName, handler) {
|
|
473
|
+
if (!definition.updates) throw new Error(`Update "${String(updateName)}" cannot be defined: workflow "${String(workflowName)}" has no updates in its contract`);
|
|
474
|
+
const updateDef = definition.updates[updateName];
|
|
475
|
+
if (!updateDef) throw new Error(`Update "${String(updateName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
476
|
+
(0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineUpdate)(updateName), async (...args$1) => {
|
|
477
|
+
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
478
|
+
const inputResult$1 = await updateDef.input["~standard"].validate(input);
|
|
479
|
+
if (inputResult$1.issues) throw new UpdateInputValidationError(updateName, inputResult$1.issues);
|
|
480
|
+
const result$1 = await handler(inputResult$1.value);
|
|
481
|
+
const outputResult$1 = await updateDef.output["~standard"].validate(result$1);
|
|
482
|
+
if (outputResult$1.issues) throw new UpdateOutputValidationError(updateName, outputResult$1.issues);
|
|
483
|
+
return outputResult$1.value;
|
|
484
|
+
});
|
|
485
|
+
}
|
|
365
486
|
const result = await implementation({
|
|
366
487
|
activities: contextActivities,
|
|
367
|
-
info: (0, __temporalio_workflow.workflowInfo)()
|
|
488
|
+
info: (0, __temporalio_workflow.workflowInfo)(),
|
|
489
|
+
startChildWorkflow: createStartChildWorkflow,
|
|
490
|
+
executeChildWorkflow: createExecuteChildWorkflow,
|
|
491
|
+
defineSignal: createDefineSignal,
|
|
492
|
+
defineQuery: createDefineQuery,
|
|
493
|
+
defineUpdate: createDefineUpdate
|
|
368
494
|
}, validatedInput);
|
|
369
495
|
const outputResult = await definition.output["~standard"].validate(result);
|
|
370
496
|
if (outputResult.issues) throw new WorkflowOutputValidationError(String(workflowName), outputResult.issues);
|
|
@@ -379,10 +505,10 @@ Object.defineProperty(exports, 'ActivityDefinitionNotFoundError', {
|
|
|
379
505
|
return ActivityDefinitionNotFoundError;
|
|
380
506
|
}
|
|
381
507
|
});
|
|
382
|
-
Object.defineProperty(exports, '
|
|
508
|
+
Object.defineProperty(exports, 'ActivityError', {
|
|
383
509
|
enumerable: true,
|
|
384
510
|
get: function () {
|
|
385
|
-
return
|
|
511
|
+
return ActivityError;
|
|
386
512
|
}
|
|
387
513
|
});
|
|
388
514
|
Object.defineProperty(exports, 'ActivityInputValidationError', {
|
|
@@ -397,6 +523,18 @@ Object.defineProperty(exports, 'ActivityOutputValidationError', {
|
|
|
397
523
|
return ActivityOutputValidationError;
|
|
398
524
|
}
|
|
399
525
|
});
|
|
526
|
+
Object.defineProperty(exports, 'ChildWorkflowError', {
|
|
527
|
+
enumerable: true,
|
|
528
|
+
get: function () {
|
|
529
|
+
return ChildWorkflowError;
|
|
530
|
+
}
|
|
531
|
+
});
|
|
532
|
+
Object.defineProperty(exports, 'ChildWorkflowNotFoundError', {
|
|
533
|
+
enumerable: true,
|
|
534
|
+
get: function () {
|
|
535
|
+
return ChildWorkflowNotFoundError;
|
|
536
|
+
}
|
|
537
|
+
});
|
|
400
538
|
Object.defineProperty(exports, 'QueryInputValidationError', {
|
|
401
539
|
enumerable: true,
|
|
402
540
|
get: function () {
|