@temporal-contract/worker 0.0.4 → 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 +1 -26
- package/dist/activity.d.cts +2 -3
- package/dist/activity.d.mts +2 -3
- package/dist/activity.mjs +2 -3
- package/dist/{handler-D9BllGor.cjs → handler-BAzNuAZz.cjs} +167 -51
- package/dist/handler-Cp9h_XCy.d.cts +560 -0
- package/dist/{handler-B7B5QHez.mjs → handler-DFFpSaGN.mjs} +157 -53
- 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 +24 -19
- package/dist/handler-Czi-kgwZ.d.cts +0 -316
- package/dist/handler-DThqdaaS.d.mts +0 -316
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,33 +1,8 @@
|
|
|
1
|
-
const require_handler = require('./handler-
|
|
2
|
-
let __swan_io_boxed = require("@swan-io/boxed");
|
|
1
|
+
const require_handler = require('./handler-BAzNuAZz.cjs');
|
|
3
2
|
|
|
4
3
|
exports.ActivityDefinitionNotFoundError = require_handler.ActivityDefinitionNotFoundError;
|
|
5
4
|
exports.ActivityError = require_handler.ActivityError;
|
|
6
5
|
exports.ActivityInputValidationError = require_handler.ActivityInputValidationError;
|
|
7
6
|
exports.ActivityOutputValidationError = require_handler.ActivityOutputValidationError;
|
|
8
|
-
Object.defineProperty(exports, 'AsyncData', {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () {
|
|
11
|
-
return __swan_io_boxed.AsyncData;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(exports, 'Future', {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
get: function () {
|
|
17
|
-
return __swan_io_boxed.Future;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
Object.defineProperty(exports, 'Option', {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return __swan_io_boxed.Option;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, 'Result', {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return __swan_io_boxed.Result;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
7
|
exports.WorkerError = require_handler.WorkerError;
|
|
33
8
|
exports.declareActivitiesHandler = require_handler.declareActivitiesHandler;
|
package/dist/activity.d.cts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, AsyncData, type BoxedActivityImplementation, type DeclareActivitiesHandlerOptions, Future, Option, Result, WorkerError, declareActivitiesHandler };
|
|
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,3 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export { type ActivitiesHandler, ActivityDefinitionNotFoundError, ActivityError, type ActivityImplementations, ActivityInputValidationError, ActivityOutputValidationError, AsyncData, type BoxedActivityImplementation, type DeclareActivitiesHandlerOptions, Future, Option, Result, WorkerError, declareActivitiesHandler };
|
|
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,4 +1,3 @@
|
|
|
1
|
-
import { a as ActivityInputValidationError,
|
|
2
|
-
import { AsyncData, Future, Option, Result } from "@swan-io/boxed";
|
|
1
|
+
import { a as ActivityInputValidationError, i as ActivityError, m as WorkerError, o as ActivityOutputValidationError, r as ActivityDefinitionNotFoundError, t as declareActivitiesHandler } from "./handler-DFFpSaGN.mjs";
|
|
3
2
|
|
|
4
|
-
export { ActivityDefinitionNotFoundError, ActivityError, ActivityInputValidationError, ActivityOutputValidationError,
|
|
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
|
|
@@ -146,6 +147,27 @@ var UpdateOutputValidationError = class extends WorkerError {
|
|
|
146
147
|
this.name = "UpdateOutputValidationError";
|
|
147
148
|
}
|
|
148
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
|
+
};
|
|
149
171
|
|
|
150
172
|
//#endregion
|
|
151
173
|
//#region src/handler.ts
|
|
@@ -191,7 +213,7 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
191
213
|
* @example
|
|
192
214
|
* ```ts
|
|
193
215
|
* import { declareActivitiesHandler, ActivityError } from '@temporal-contract/worker/activity';
|
|
194
|
-
* import { Result, Future } from '@
|
|
216
|
+
* import { Result, Future } from '@temporal-contract/boxed';
|
|
195
217
|
* import myContract from './contract';
|
|
196
218
|
*
|
|
197
219
|
* export const activitiesHandler = declareActivitiesHandler({
|
|
@@ -247,7 +269,7 @@ function declareActivitiesHandler(options) {
|
|
|
247
269
|
const input = args.length === 1 ? args[0] : args;
|
|
248
270
|
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
249
271
|
if (inputResult.issues) throw new ActivityInputValidationError(activityName, inputResult.issues);
|
|
250
|
-
const result = await activityImpl(inputResult.value)
|
|
272
|
+
const result = await activityImpl(inputResult.value);
|
|
251
273
|
if (result.isOk()) {
|
|
252
274
|
const outputResult = await activityDef.output["~standard"].validate(result.value);
|
|
253
275
|
if (outputResult.issues) throw new ActivityOutputValidationError(activityName, outputResult.issues);
|
|
@@ -325,68 +347,150 @@ function declareActivitiesHandler(options) {
|
|
|
325
347
|
* ```
|
|
326
348
|
*/
|
|
327
349
|
function declareWorkflow(options) {
|
|
328
|
-
const { workflowName, contract, implementation, activityOptions
|
|
350
|
+
const { workflowName, contract, implementation, activityOptions } = options;
|
|
329
351
|
const definition = contract.workflows[workflowName];
|
|
330
352
|
return async (args) => {
|
|
331
353
|
const singleArg = Array.isArray(args) ? args[0] : args;
|
|
332
354
|
const inputResult = await definition.input["~standard"].validate(singleArg);
|
|
333
355
|
if (inputResult.issues) throw new WorkflowInputValidationError(String(workflowName), inputResult.issues);
|
|
334
356
|
const validatedInput = inputResult.value;
|
|
335
|
-
if (definition.signals && signals) {
|
|
336
|
-
const signalDefs = definition.signals;
|
|
337
|
-
const signalHandlers = signals;
|
|
338
|
-
for (const [signalName, signalDef] of Object.entries(signalDefs)) {
|
|
339
|
-
const handler = signalHandlers[signalName];
|
|
340
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineSignal)(signalName), async (...args$1) => {
|
|
341
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
342
|
-
const inputResult$1 = await signalDef.input["~standard"].validate(input);
|
|
343
|
-
if (inputResult$1.issues) throw new SignalInputValidationError(signalName, inputResult$1.issues);
|
|
344
|
-
await handler(inputResult$1.value);
|
|
345
|
-
});
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (definition.queries && queries) {
|
|
349
|
-
const queryDefs = definition.queries;
|
|
350
|
-
const queryHandlers = queries;
|
|
351
|
-
for (const [queryName, queryDef] of Object.entries(queryDefs)) {
|
|
352
|
-
const handler = queryHandlers[queryName];
|
|
353
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineQuery)(queryName), (...args$1) => {
|
|
354
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
355
|
-
const inputResult$1 = queryDef.input["~standard"].validate(input);
|
|
356
|
-
if (inputResult$1 instanceof Promise) throw new Error(`Query "${queryName}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
357
|
-
if (inputResult$1.issues) throw new QueryInputValidationError(queryName, inputResult$1.issues);
|
|
358
|
-
const result$1 = handler(inputResult$1.value);
|
|
359
|
-
const outputResult$1 = queryDef.output["~standard"].validate(result$1);
|
|
360
|
-
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.`);
|
|
361
|
-
if (outputResult$1.issues) throw new QueryOutputValidationError(queryName, outputResult$1.issues);
|
|
362
|
-
return outputResult$1.value;
|
|
363
|
-
});
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
if (definition.updates && updates) {
|
|
367
|
-
const updateDefs = definition.updates;
|
|
368
|
-
const updateHandlers = updates;
|
|
369
|
-
for (const [updateName, updateDef] of Object.entries(updateDefs)) {
|
|
370
|
-
const handler = updateHandlers[updateName];
|
|
371
|
-
if (handler) (0, __temporalio_workflow.setHandler)((0, __temporalio_workflow.defineUpdate)(updateName), async (...args$1) => {
|
|
372
|
-
const input = args$1.length === 1 ? args$1[0] : args$1;
|
|
373
|
-
const inputResult$1 = await updateDef.input["~standard"].validate(input);
|
|
374
|
-
if (inputResult$1.issues) throw new UpdateInputValidationError(updateName, inputResult$1.issues);
|
|
375
|
-
const result$1 = await handler(inputResult$1.value);
|
|
376
|
-
const outputResult$1 = await updateDef.output["~standard"].validate(result$1);
|
|
377
|
-
if (outputResult$1.issues) throw new UpdateOutputValidationError(updateName, outputResult$1.issues);
|
|
378
|
-
return outputResult$1.value;
|
|
379
|
-
});
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
357
|
let contextActivities = {};
|
|
383
358
|
if (definition.activities || contract.activities) contextActivities = createValidatedActivities((0, __temporalio_workflow.proxyActivities)({
|
|
384
359
|
startToCloseTimeout: activityOptions?.startToCloseTimeout ?? 6e4,
|
|
385
360
|
...activityOptions
|
|
386
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
|
+
}
|
|
387
486
|
const result = await implementation({
|
|
388
487
|
activities: contextActivities,
|
|
389
|
-
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
|
|
390
494
|
}, validatedInput);
|
|
391
495
|
const outputResult = await definition.output["~standard"].validate(result);
|
|
392
496
|
if (outputResult.issues) throw new WorkflowOutputValidationError(String(workflowName), outputResult.issues);
|
|
@@ -419,6 +523,18 @@ Object.defineProperty(exports, 'ActivityOutputValidationError', {
|
|
|
419
523
|
return ActivityOutputValidationError;
|
|
420
524
|
}
|
|
421
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
|
+
});
|
|
422
538
|
Object.defineProperty(exports, 'QueryInputValidationError', {
|
|
423
539
|
enumerable: true,
|
|
424
540
|
get: function () {
|