@temporal-contract/worker 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -8
- package/dist/activity.cjs +44 -119
- package/dist/activity.d.cts +37 -27
- package/dist/activity.d.cts.map +1 -1
- package/dist/activity.d.mts +37 -27
- package/dist/activity.d.mts.map +1 -1
- package/dist/activity.mjs +32 -107
- package/dist/activity.mjs.map +1 -1
- package/dist/{errors-4jH78z8m.d.cts → errors-CG1y7SHO.d.cts} +14 -2
- package/dist/{errors-4jH78z8m.d.cts.map → errors-CG1y7SHO.d.cts.map} +1 -1
- package/dist/{errors-CmTXZ3JW.d.mts → errors-DZhaNhwr.d.mts} +14 -2
- package/dist/{errors-CmTXZ3JW.d.mts.map → errors-DZhaNhwr.d.mts.map} +1 -1
- package/dist/internal-BoNcEtYh.mjs +354 -0
- package/dist/internal-BoNcEtYh.mjs.map +1 -0
- package/dist/internal-Tj4m4f_K.cjs +453 -0
- package/dist/worker.cjs +2 -4
- package/dist/worker.mjs +1 -2
- package/dist/worker.mjs.map +1 -1
- package/dist/workflow.cjs +247 -136
- package/dist/workflow.d.cts +154 -31
- package/dist/workflow.d.cts.map +1 -1
- package/dist/workflow.d.mts +154 -31
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +231 -120
- package/dist/workflow.mjs.map +1 -1
- package/package.json +23 -24
- package/dist/activity-utils-B3vP03_P.d.mts +0 -68
- package/dist/activity-utils-B3vP03_P.d.mts.map +0 -1
- package/dist/activity-utils-RsXOceIH.d.cts +0 -68
- package/dist/activity-utils-RsXOceIH.d.cts.map +0 -1
- package/dist/errors-Di6Ja4Rt.mjs +0 -156
- package/dist/errors-Di6Ja4Rt.mjs.map +0 -1
- package/dist/errors-DjSZg-93.cjs +0 -227
package/dist/workflow.cjs
CHANGED
|
@@ -1,8 +1,148 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value:
|
|
2
|
-
const
|
|
3
|
-
let _temporal_contract_boxed = require("@temporal-contract/boxed");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_internal = require("./internal-Tj4m4f_K.cjs");
|
|
4
3
|
let _temporalio_workflow = require("@temporalio/workflow");
|
|
5
|
-
|
|
4
|
+
let _temporal_contract_boxed = require("@temporal-contract/boxed");
|
|
5
|
+
//#region src/cancellation.ts
|
|
6
|
+
/**
|
|
7
|
+
* Typed wrappers around Temporal's `CancellationScope` so workflows can
|
|
8
|
+
* opt into cancellation control without reaching for
|
|
9
|
+
* `@temporalio/workflow` directly. The wrappers fold cancellation into
|
|
10
|
+
* the same `Future<Result<...>>` shape used elsewhere in the worker
|
|
11
|
+
* context — callers branch on `Result.Error(WorkflowCancelledError)`
|
|
12
|
+
* instead of catching `CancelledFailure`.
|
|
13
|
+
*
|
|
14
|
+
* Non-cancellation errors thrown inside the scope are *not* swallowed:
|
|
15
|
+
* the Future rejects with the original error so user-domain failures
|
|
16
|
+
* keep their identity.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Run `fn` inside a cancellable Temporal scope. If the workflow (or an
|
|
20
|
+
* ancestor scope) is cancelled while the function is in flight, the
|
|
21
|
+
* resulting Future resolves to `Result.Error(WorkflowCancelledError)`,
|
|
22
|
+
* letting callers handle cancellation explicitly — typically to perform
|
|
23
|
+
* a graceful exit from the current step.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const result = await context.cancellableScope(async () => {
|
|
28
|
+
* return await context.activities.processStep(...);
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* result.match({
|
|
32
|
+
* Ok: (output) => { ... },
|
|
33
|
+
* Error: (err) => {
|
|
34
|
+
* // err instanceof WorkflowCancelledError — graceful exit
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
function cancellableScope(fn) {
|
|
40
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
41
|
+
try {
|
|
42
|
+
const value = await _temporalio_workflow.CancellationScope.cancellable(async () => fn());
|
|
43
|
+
return _temporal_contract_boxed.Result.Ok(value);
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if ((0, _temporalio_workflow.isCancellation)(error)) return _temporal_contract_boxed.Result.Error(new require_internal.WorkflowCancelledError(error));
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
|
|
52
|
+
* from outside the scope are ignored for its duration — the idiomatic way
|
|
53
|
+
* to perform cleanup that must not be interrupted (e.g. releasing a
|
|
54
|
+
* resource after a graceful shutdown).
|
|
55
|
+
*
|
|
56
|
+
* Mirrors `cancellableScope`'s `Future<Result<...>>` shape for symmetry;
|
|
57
|
+
* the `Result.Error` branch only triggers when cancellation is raised
|
|
58
|
+
* from inside the scope (rare).
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* await context.nonCancellableScope(async () => {
|
|
63
|
+
* await context.activities.releaseResources(...);
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
function nonCancellableScope(fn) {
|
|
68
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
69
|
+
try {
|
|
70
|
+
const value = await _temporalio_workflow.CancellationScope.nonCancellable(async () => fn());
|
|
71
|
+
return _temporal_contract_boxed.Result.Ok(value);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
if ((0, _temporalio_workflow.isCancellation)(error)) return _temporal_contract_boxed.Result.Error(new require_internal.WorkflowCancelledError(error));
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/handlers.ts
|
|
80
|
+
/**
|
|
81
|
+
* Bind a typed signal handler to the running workflow. Validates the
|
|
82
|
+
* signal payload against the contract's input schema before invoking the
|
|
83
|
+
* user-supplied handler.
|
|
84
|
+
*
|
|
85
|
+
* The runtime guard against a missing `signals` block — and an unknown
|
|
86
|
+
* signal name within it — covers the union-typed-`workflowName` case
|
|
87
|
+
* where the type system's keyset constraint collapses; without the
|
|
88
|
+
* check, a caller would see `Cannot read properties of undefined`
|
|
89
|
+
* instead of a controlled error.
|
|
90
|
+
*/
|
|
91
|
+
function bindSignalHandler(workflowDefinition, workflowName, signalName, handler) {
|
|
92
|
+
if (!workflowDefinition.signals) throw new Error(`Signal "${signalName}" cannot be defined: workflow "${workflowName}" has no signals in its contract`);
|
|
93
|
+
const signalDef = workflowDefinition.signals[signalName];
|
|
94
|
+
if (!signalDef) throw new Error(`Signal "${signalName}" not found in workflow "${workflowName}" contract`);
|
|
95
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineSignal)(signalName), async (...args) => {
|
|
96
|
+
const input = require_internal.extractHandlerInput(args);
|
|
97
|
+
const inputResult = await signalDef.input["~standard"].validate(input);
|
|
98
|
+
if (inputResult.issues) throw new require_internal.SignalInputValidationError(signalName, inputResult.issues);
|
|
99
|
+
await handler(inputResult.value);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Bind a typed query handler to the running workflow. Validates input
|
|
104
|
+
* and output against the contract synchronously.
|
|
105
|
+
*
|
|
106
|
+
* Temporal's query API requires a synchronous handler — async
|
|
107
|
+
* validation breaks replay determinism. The handler trips a clear error
|
|
108
|
+
* if the schema library returns a Promise from `validate(...)`, instead
|
|
109
|
+
* of letting the async path silently corrupt query semantics.
|
|
110
|
+
*/
|
|
111
|
+
function bindQueryHandler(workflowDefinition, workflowName, queryName, handler) {
|
|
112
|
+
if (!workflowDefinition.queries) throw new Error(`Query "${queryName}" cannot be defined: workflow "${workflowName}" has no queries in its contract`);
|
|
113
|
+
const queryDef = workflowDefinition.queries[queryName];
|
|
114
|
+
if (!queryDef) throw new Error(`Query "${queryName}" not found in workflow "${workflowName}" contract`);
|
|
115
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineQuery)(queryName), (...args) => {
|
|
116
|
+
const input = require_internal.extractHandlerInput(args);
|
|
117
|
+
const inputResult = queryDef.input["~standard"].validate(input);
|
|
118
|
+
if (inputResult instanceof Promise) throw new Error(`Query "${queryName}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
119
|
+
if (inputResult.issues) throw new require_internal.QueryInputValidationError(queryName, inputResult.issues);
|
|
120
|
+
const result = handler(inputResult.value);
|
|
121
|
+
const outputResult = queryDef.output["~standard"].validate(result);
|
|
122
|
+
if (outputResult instanceof Promise) throw new Error(`Query "${queryName}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
123
|
+
if (outputResult.issues) throw new require_internal.QueryOutputValidationError(queryName, outputResult.issues);
|
|
124
|
+
return outputResult.value;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Bind a typed update handler to the running workflow. Validates both
|
|
129
|
+
* input and output (asynchronously, like signals).
|
|
130
|
+
*/
|
|
131
|
+
function bindUpdateHandler(workflowDefinition, workflowName, updateName, handler) {
|
|
132
|
+
if (!workflowDefinition.updates) throw new Error(`Update "${updateName}" cannot be defined: workflow "${workflowName}" has no updates in its contract`);
|
|
133
|
+
const updateDef = workflowDefinition.updates[updateName];
|
|
134
|
+
if (!updateDef) throw new Error(`Update "${updateName}" not found in workflow "${workflowName}" contract`);
|
|
135
|
+
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineUpdate)(updateName), async (...args) => {
|
|
136
|
+
const input = require_internal.extractHandlerInput(args);
|
|
137
|
+
const inputResult = await updateDef.input["~standard"].validate(input);
|
|
138
|
+
if (inputResult.issues) throw new require_internal.UpdateInputValidationError(updateName, inputResult.issues);
|
|
139
|
+
const result = await handler(inputResult.value);
|
|
140
|
+
const outputResult = await updateDef.output["~standard"].validate(result);
|
|
141
|
+
if (outputResult.issues) throw new require_internal.UpdateOutputValidationError(updateName, outputResult.issues);
|
|
142
|
+
return outputResult.value;
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
//#endregion
|
|
6
146
|
//#region src/workflow.ts
|
|
7
147
|
/**
|
|
8
148
|
* Create a typed workflow implementation with automatic validation
|
|
@@ -27,6 +167,15 @@ let _temporalio_workflow = require("@temporalio/workflow");
|
|
|
27
167
|
* activityOptions: {
|
|
28
168
|
* startToCloseTimeout: '1 minute',
|
|
29
169
|
* },
|
|
170
|
+
* // Optional: override `activityOptions` for specific activities. Each
|
|
171
|
+
* // entry shallow-merges over the workflow default — the override wins on
|
|
172
|
+
* // every property it specifies, including the whole `retry` block.
|
|
173
|
+
* activityOptionsByName: {
|
|
174
|
+
* chargePayment: {
|
|
175
|
+
* startToCloseTimeout: '5 minutes',
|
|
176
|
+
* retry: { maximumAttempts: 5 },
|
|
177
|
+
* },
|
|
178
|
+
* },
|
|
30
179
|
* implementation: async (context, args) => {
|
|
31
180
|
* // context.activities: typed activities (workflow + global)
|
|
32
181
|
* // context.info: WorkflowInfo
|
|
@@ -68,135 +217,29 @@ let _temporalio_workflow = require("@temporalio/workflow");
|
|
|
68
217
|
* });
|
|
69
218
|
* ```
|
|
70
219
|
*/
|
|
71
|
-
function declareWorkflow({ workflowName, contract, implementation, activityOptions }) {
|
|
220
|
+
function declareWorkflow({ workflowName, contract, implementation, activityOptions, activityOptionsByName }) {
|
|
72
221
|
const definition = contract.workflows[workflowName];
|
|
73
222
|
return async (...args) => {
|
|
74
|
-
const input =
|
|
223
|
+
const input = require_internal.extractHandlerInput(args);
|
|
75
224
|
const inputResult = await definition.input["~standard"].validate(input);
|
|
76
|
-
if (inputResult.issues) throw new
|
|
225
|
+
if (inputResult.issues) throw new require_internal.WorkflowInputValidationError(String(workflowName), inputResult.issues);
|
|
77
226
|
const validatedInput = inputResult.value;
|
|
78
227
|
let contextActivities = {};
|
|
79
|
-
if (definition.activities || contract.activities) contextActivities = createValidatedActivities((
|
|
80
|
-
async function validateChildWorkflowOutput(childDefinition, result, childWorkflowName) {
|
|
81
|
-
const outputResult = await childDefinition.output["~standard"].validate(result);
|
|
82
|
-
if (outputResult.issues) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow "${childWorkflowName}" output validation failed: ${outputResult.issues.map((i) => i.message).join("; ")}`));
|
|
83
|
-
return _temporal_contract_boxed.Result.Ok(outputResult.value);
|
|
84
|
-
}
|
|
85
|
-
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args) {
|
|
86
|
-
const childDefinition = childContract.workflows[childWorkflowName];
|
|
87
|
-
if (!childDefinition) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowNotFoundError(String(childWorkflowName), Object.keys(childContract.workflows)));
|
|
88
|
-
const inputResult = await childDefinition.input["~standard"].validate(args);
|
|
89
|
-
if (inputResult.issues) return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow "${String(childWorkflowName)}" input validation failed: ${inputResult.issues.map((i) => i.message).join("; ")}`));
|
|
90
|
-
const validatedInput = inputResult.value;
|
|
91
|
-
return _temporal_contract_boxed.Result.Ok({
|
|
92
|
-
definition: childDefinition,
|
|
93
|
-
validatedInput,
|
|
94
|
-
taskQueue: childContract.taskQueue
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
function createTypedChildHandle(handle, childDefinition, childWorkflowName) {
|
|
98
|
-
return {
|
|
99
|
-
workflowId: handle.workflowId,
|
|
100
|
-
result: () => {
|
|
101
|
-
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
102
|
-
try {
|
|
103
|
-
return validateChildWorkflowOutput(childDefinition, await handle.result(), childWorkflowName);
|
|
104
|
-
} catch (error) {
|
|
105
|
-
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Child workflow execution failed: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
112
|
-
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
113
|
-
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
114
|
-
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
115
|
-
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
116
|
-
try {
|
|
117
|
-
const { args: _args, ...temporalOptions } = options;
|
|
118
|
-
const typedHandle = createTypedChildHandle(await (0, _temporalio_workflow.startChild)(childWorkflowName, {
|
|
119
|
-
...temporalOptions,
|
|
120
|
-
taskQueue,
|
|
121
|
-
args: [validatedInput]
|
|
122
|
-
}), childDefinition, String(childWorkflowName));
|
|
123
|
-
return _temporal_contract_boxed.Result.Ok(typedHandle);
|
|
124
|
-
} catch (error) {
|
|
125
|
-
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
130
|
-
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
131
|
-
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
132
|
-
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
133
|
-
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
134
|
-
try {
|
|
135
|
-
const { args: _args, ...temporalOptions } = options;
|
|
136
|
-
const outputValidationResult = await validateChildWorkflowOutput(childDefinition, await (0, _temporalio_workflow.executeChild)(childWorkflowName, {
|
|
137
|
-
...temporalOptions,
|
|
138
|
-
taskQueue,
|
|
139
|
-
args: [validatedInput]
|
|
140
|
-
}), String(childWorkflowName));
|
|
141
|
-
if (outputValidationResult.isError()) return _temporal_contract_boxed.Result.Error(outputValidationResult.error);
|
|
142
|
-
return _temporal_contract_boxed.Result.Ok(outputValidationResult.value);
|
|
143
|
-
} catch (error) {
|
|
144
|
-
return _temporal_contract_boxed.Result.Error(new require_errors.ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
function createDefineSignal(signalName, handler) {
|
|
149
|
-
if (!definition.signals) throw new Error(`Signal "${String(signalName)}" cannot be defined: workflow "${String(workflowName)}" has no signals in its contract`);
|
|
150
|
-
const signalDef = definition.signals[signalName];
|
|
151
|
-
if (!signalDef) throw new Error(`Signal "${String(signalName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
152
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineSignal)(signalName), async (...args) => {
|
|
153
|
-
const input = args.length === 1 ? args[0] : args;
|
|
154
|
-
const inputResult = await signalDef.input["~standard"].validate(input);
|
|
155
|
-
if (inputResult.issues) throw new require_errors.SignalInputValidationError(signalName, inputResult.issues);
|
|
156
|
-
await handler(inputResult.value);
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function createDefineQuery(queryName, handler) {
|
|
160
|
-
if (!definition.queries) throw new Error(`Query "${String(queryName)}" cannot be defined: workflow "${String(workflowName)}" has no queries in its contract`);
|
|
161
|
-
const queryDef = definition.queries[queryName];
|
|
162
|
-
if (!queryDef) throw new Error(`Query "${String(queryName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
163
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineQuery)(queryName), (...args) => {
|
|
164
|
-
const input = args.length === 1 ? args[0] : args;
|
|
165
|
-
const inputResult = queryDef.input["~standard"].validate(input);
|
|
166
|
-
if (inputResult instanceof Promise) throw new Error(`Query "${String(queryName)}" validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
167
|
-
if (inputResult.issues) throw new require_errors.QueryInputValidationError(queryName, inputResult.issues);
|
|
168
|
-
const result = handler(inputResult.value);
|
|
169
|
-
const outputResult = queryDef.output["~standard"].validate(result);
|
|
170
|
-
if (outputResult instanceof Promise) throw new Error(`Query "${String(queryName)}" output validation must be synchronous. Use a schema library that supports synchronous validation for queries.`);
|
|
171
|
-
if (outputResult.issues) throw new require_errors.QueryOutputValidationError(queryName, outputResult.issues);
|
|
172
|
-
return outputResult.value;
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
function createDefineUpdate(updateName, handler) {
|
|
176
|
-
if (!definition.updates) throw new Error(`Update "${String(updateName)}" cannot be defined: workflow "${String(workflowName)}" has no updates in its contract`);
|
|
177
|
-
const updateDef = definition.updates[updateName];
|
|
178
|
-
if (!updateDef) throw new Error(`Update "${String(updateName)}" not found in workflow "${String(workflowName)}" contract`);
|
|
179
|
-
(0, _temporalio_workflow.setHandler)((0, _temporalio_workflow.defineUpdate)(updateName), async (...args) => {
|
|
180
|
-
const input = args.length === 1 ? args[0] : args;
|
|
181
|
-
const inputResult = await updateDef.input["~standard"].validate(input);
|
|
182
|
-
if (inputResult.issues) throw new require_errors.UpdateInputValidationError(updateName, inputResult.issues);
|
|
183
|
-
const result = await handler(inputResult.value);
|
|
184
|
-
const outputResult = await updateDef.output["~standard"].validate(result);
|
|
185
|
-
if (outputResult.issues) throw new require_errors.UpdateOutputValidationError(updateName, outputResult.issues);
|
|
186
|
-
return outputResult.value;
|
|
187
|
-
});
|
|
188
|
-
}
|
|
228
|
+
if (definition.activities || contract.activities) contextActivities = createValidatedActivities(require_internal.buildRawActivitiesProxy(definition.activities, contract.activities, activityOptions, activityOptionsByName), definition.activities, contract.activities);
|
|
189
229
|
const result = await implementation({
|
|
190
230
|
activities: contextActivities,
|
|
191
231
|
info: (0, _temporalio_workflow.workflowInfo)(),
|
|
192
232
|
startChildWorkflow: createStartChildWorkflow,
|
|
193
233
|
executeChildWorkflow: createExecuteChildWorkflow,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
234
|
+
cancellableScope,
|
|
235
|
+
nonCancellableScope,
|
|
236
|
+
defineSignal: ((signalName, handler) => bindSignalHandler(definition, String(workflowName), signalName, handler)),
|
|
237
|
+
defineQuery: ((queryName, handler) => bindQueryHandler(definition, String(workflowName), queryName, handler)),
|
|
238
|
+
defineUpdate: ((updateName, handler) => bindUpdateHandler(definition, String(workflowName), updateName, handler)),
|
|
239
|
+
continueAsNew: require_internal.createContinueAsNew(contract, workflowName)
|
|
197
240
|
}, validatedInput);
|
|
198
241
|
const outputResult = await definition.output["~standard"].validate(result);
|
|
199
|
-
if (outputResult.issues) throw new
|
|
242
|
+
if (outputResult.issues) throw new require_internal.WorkflowOutputValidationError(String(workflowName), outputResult.issues);
|
|
200
243
|
return outputResult.value;
|
|
201
244
|
};
|
|
202
245
|
}
|
|
@@ -217,26 +260,94 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
217
260
|
if (!rawActivity) throw new Error(`Activity implementation not found for: "${activityName}". Available activities: ${Object.keys(rawActivities).length > 0 ? Object.keys(rawActivities).join(", ") : "none"}`);
|
|
218
261
|
validatedActivities[activityName] = async (input) => {
|
|
219
262
|
const inputResult = await activityDef.input["~standard"].validate(input);
|
|
220
|
-
if (inputResult.issues) throw new
|
|
263
|
+
if (inputResult.issues) throw new require_internal.ActivityInputValidationError(activityName, inputResult.issues);
|
|
221
264
|
const result = await rawActivity(inputResult.value);
|
|
222
265
|
const outputResult = await activityDef.output["~standard"].validate(result);
|
|
223
|
-
if (outputResult.issues) throw new
|
|
266
|
+
if (outputResult.issues) throw new require_internal.ActivityOutputValidationError(activityName, outputResult.issues);
|
|
224
267
|
return outputResult.value;
|
|
225
268
|
};
|
|
226
269
|
}
|
|
227
270
|
return validatedActivities;
|
|
228
271
|
}
|
|
229
|
-
|
|
272
|
+
async function validateChildWorkflowOutput(childDefinition, result, childWorkflowName) {
|
|
273
|
+
const outputResult = await childDefinition.output["~standard"].validate(result);
|
|
274
|
+
if (outputResult.issues) return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowError(require_internal.formatChildWorkflowValidationMessage(childWorkflowName, "output", outputResult.issues)));
|
|
275
|
+
return _temporal_contract_boxed.Result.Ok(outputResult.value);
|
|
276
|
+
}
|
|
277
|
+
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args) {
|
|
278
|
+
const childDefinition = childContract.workflows[childWorkflowName];
|
|
279
|
+
if (!childDefinition) return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowNotFoundError(String(childWorkflowName), Object.keys(childContract.workflows)));
|
|
280
|
+
const inputResult = await childDefinition.input["~standard"].validate(args);
|
|
281
|
+
if (inputResult.issues) return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowError(require_internal.formatChildWorkflowValidationMessage(String(childWorkflowName), "input", inputResult.issues)));
|
|
282
|
+
const validatedInput = inputResult.value;
|
|
283
|
+
return _temporal_contract_boxed.Result.Ok({
|
|
284
|
+
definition: childDefinition,
|
|
285
|
+
validatedInput,
|
|
286
|
+
taskQueue: childContract.taskQueue
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
function createTypedChildHandle(handle, childDefinition, childWorkflowName) {
|
|
290
|
+
return {
|
|
291
|
+
workflowId: handle.workflowId,
|
|
292
|
+
result: () => {
|
|
293
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
294
|
+
try {
|
|
295
|
+
return validateChildWorkflowOutput(childDefinition, await handle.result(), childWorkflowName);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowError(`Child workflow execution failed: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
304
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
305
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
306
|
+
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
307
|
+
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
308
|
+
try {
|
|
309
|
+
const { args: _args, ...temporalOptions } = options;
|
|
310
|
+
const typedHandle = createTypedChildHandle(await (0, _temporalio_workflow.startChild)(childWorkflowName, {
|
|
311
|
+
...temporalOptions,
|
|
312
|
+
taskQueue,
|
|
313
|
+
args: [validatedInput]
|
|
314
|
+
}), childDefinition, String(childWorkflowName));
|
|
315
|
+
return _temporal_contract_boxed.Result.Ok(typedHandle);
|
|
316
|
+
} catch (error) {
|
|
317
|
+
return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
318
|
+
}
|
|
319
|
+
});
|
|
320
|
+
}
|
|
321
|
+
function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
322
|
+
return _temporal_contract_boxed.Future.fromAsync(async () => {
|
|
323
|
+
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
324
|
+
if (validationResult.isError()) return _temporal_contract_boxed.Result.Error(validationResult.error);
|
|
325
|
+
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
326
|
+
try {
|
|
327
|
+
const { args: _args, ...temporalOptions } = options;
|
|
328
|
+
const outputValidationResult = await validateChildWorkflowOutput(childDefinition, await (0, _temporalio_workflow.executeChild)(childWorkflowName, {
|
|
329
|
+
...temporalOptions,
|
|
330
|
+
taskQueue,
|
|
331
|
+
args: [validatedInput]
|
|
332
|
+
}), String(childWorkflowName));
|
|
333
|
+
if (outputValidationResult.isError()) return _temporal_contract_boxed.Result.Error(outputValidationResult.error);
|
|
334
|
+
return _temporal_contract_boxed.Result.Ok(outputValidationResult.value);
|
|
335
|
+
} catch (error) {
|
|
336
|
+
return _temporal_contract_boxed.Result.Error(new require_internal.ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
230
340
|
//#endregion
|
|
231
|
-
exports.ActivityInputValidationError =
|
|
232
|
-
exports.ActivityOutputValidationError =
|
|
233
|
-
exports.ChildWorkflowError =
|
|
234
|
-
exports.ChildWorkflowNotFoundError =
|
|
235
|
-
exports.QueryInputValidationError =
|
|
236
|
-
exports.QueryOutputValidationError =
|
|
237
|
-
exports.SignalInputValidationError =
|
|
238
|
-
exports.UpdateInputValidationError =
|
|
239
|
-
exports.UpdateOutputValidationError =
|
|
240
|
-
exports.
|
|
241
|
-
exports.
|
|
242
|
-
exports.
|
|
341
|
+
exports.ActivityInputValidationError = require_internal.ActivityInputValidationError;
|
|
342
|
+
exports.ActivityOutputValidationError = require_internal.ActivityOutputValidationError;
|
|
343
|
+
exports.ChildWorkflowError = require_internal.ChildWorkflowError;
|
|
344
|
+
exports.ChildWorkflowNotFoundError = require_internal.ChildWorkflowNotFoundError;
|
|
345
|
+
exports.QueryInputValidationError = require_internal.QueryInputValidationError;
|
|
346
|
+
exports.QueryOutputValidationError = require_internal.QueryOutputValidationError;
|
|
347
|
+
exports.SignalInputValidationError = require_internal.SignalInputValidationError;
|
|
348
|
+
exports.UpdateInputValidationError = require_internal.UpdateInputValidationError;
|
|
349
|
+
exports.UpdateOutputValidationError = require_internal.UpdateOutputValidationError;
|
|
350
|
+
exports.WorkflowCancelledError = require_internal.WorkflowCancelledError;
|
|
351
|
+
exports.WorkflowInputValidationError = require_internal.WorkflowInputValidationError;
|
|
352
|
+
exports.WorkflowOutputValidationError = require_internal.WorkflowOutputValidationError;
|
|
353
|
+
exports.declareWorkflow = declareWorkflow;
|