@temporal-contract/worker 2.3.1 → 3.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 +46 -7
- package/dist/activity.cjs +22 -13
- package/dist/activity.d.cts +15 -13
- package/dist/activity.d.cts.map +1 -1
- package/dist/activity.d.mts +15 -13
- package/dist/activity.d.mts.map +1 -1
- package/dist/activity.mjs +22 -14
- package/dist/activity.mjs.map +1 -1
- package/dist/errors-BNnNzSwE.d.cts +213 -0
- package/dist/errors-BNnNzSwE.d.cts.map +1 -0
- package/dist/errors-BNnNzSwE.d.mts +213 -0
- package/dist/errors-BNnNzSwE.d.mts.map +1 -0
- package/dist/{internal-DcM-YWYX.cjs → internal-Clwokr1z.cjs} +108 -134
- package/dist/{internal-D8Dl9D43.mjs → internal-DqYK4YQK.mjs} +105 -131
- package/dist/internal-DqYK4YQK.mjs.map +1 -0
- package/dist/workflow.cjs +56 -51
- package/dist/workflow.d.cts +59 -40
- package/dist/workflow.d.cts.map +1 -1
- package/dist/workflow.d.mts +59 -40
- package/dist/workflow.d.mts.map +1 -1
- package/dist/workflow.mjs +39 -34
- package/dist/workflow.mjs.map +1 -1
- package/package.json +21 -17
- package/dist/errors-BP48RaOI.d.cts +0 -208
- package/dist/errors-BP48RaOI.d.cts.map +0 -1
- package/dist/errors-BP48RaOI.d.mts +0 -208
- package/dist/errors-BP48RaOI.d.mts.map +0 -1
- package/dist/internal-D8Dl9D43.mjs.map +0 -1
package/dist/workflow.cjs
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_internal = require("./internal-
|
|
2
|
+
const require_internal = require("./internal-Clwokr1z.cjs");
|
|
3
|
+
let unthrown = require("unthrown");
|
|
3
4
|
let _temporalio_workflow = require("@temporalio/workflow");
|
|
4
|
-
let neverthrow = require("neverthrow");
|
|
5
5
|
let _temporal_contract_contract_result_async = require("@temporal-contract/contract/result-async");
|
|
6
6
|
//#region src/cancellation.ts
|
|
7
7
|
/**
|
|
8
8
|
* Typed wrappers around Temporal's `CancellationScope` so workflows can
|
|
9
9
|
* opt into cancellation control without reaching for
|
|
10
10
|
* `@temporalio/workflow` directly. The wrappers fold cancellation into
|
|
11
|
-
* the same `
|
|
11
|
+
* the same `AsyncResult<...>` shape used elsewhere in the worker
|
|
12
12
|
* context — callers branch on `err(WorkflowCancelledError)` instead of
|
|
13
13
|
* catching `CancelledFailure`.
|
|
14
14
|
*
|
|
15
|
-
* Non-cancellation errors thrown inside the scope are
|
|
16
|
-
*
|
|
17
|
-
* `cause`)
|
|
18
|
-
*
|
|
19
|
-
*
|
|
15
|
+
* Non-cancellation errors thrown inside the scope are *unmodeled* failures:
|
|
16
|
+
* they ride unthrown's `defect` channel (re-thrown at the edge / inspectable
|
|
17
|
+
* via `result.isDefect()` and `result.cause`) rather than a typed `err(...)`,
|
|
18
|
+
* keeping the modeled error channel to the single anticipated outcome —
|
|
19
|
+
* cancellation.
|
|
20
20
|
*/
|
|
21
21
|
/**
|
|
22
22
|
* Run `fn` inside a cancellable Temporal scope. If the workflow (or an
|
|
23
23
|
* ancestor scope) is cancelled while the function is in flight, the
|
|
24
|
-
* resulting
|
|
24
|
+
* resulting AsyncResult resolves to `err(WorkflowCancelledError)`,
|
|
25
25
|
* letting callers handle cancellation explicitly — typically to perform
|
|
26
26
|
* a graceful exit from the current step.
|
|
27
27
|
*
|
|
28
|
-
* Non-cancellation errors thrown by `fn`
|
|
29
|
-
* `
|
|
30
|
-
*
|
|
31
|
-
* leaking as unhandled rejections.
|
|
28
|
+
* Non-cancellation errors thrown by `fn` are unmodeled failures: they surface
|
|
29
|
+
* on the `defect` channel rather than as a typed `err(...)`, so a genuine bug
|
|
30
|
+
* is not silently treated as an anticipated domain outcome.
|
|
32
31
|
*
|
|
33
32
|
* @example
|
|
34
33
|
* ```ts
|
|
@@ -36,28 +35,27 @@ let _temporal_contract_contract_result_async = require("@temporal-contract/contr
|
|
|
36
35
|
* return await context.activities.processStep(...);
|
|
37
36
|
* });
|
|
38
37
|
*
|
|
39
|
-
* result.match(
|
|
40
|
-
* (output) => { ... },
|
|
41
|
-
* (error) => {
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
* }
|
|
38
|
+
* result.match({
|
|
39
|
+
* ok: (output) => { ... },
|
|
40
|
+
* err: (error) => {
|
|
41
|
+
* // error instanceof WorkflowCancelledError — graceful exit
|
|
42
|
+
* },
|
|
43
|
+
* defect: (cause) => {
|
|
44
|
+
* // a non-cancellation failure thrown inside the scope (a bug)
|
|
47
45
|
* },
|
|
48
|
-
* );
|
|
46
|
+
* });
|
|
49
47
|
* ```
|
|
50
48
|
*/
|
|
51
49
|
function cancellableScope(fn) {
|
|
52
50
|
const work = async () => {
|
|
53
51
|
try {
|
|
54
|
-
return (0,
|
|
52
|
+
return (0, unthrown.ok)(await _temporalio_workflow.CancellationScope.cancellable(async () => fn()));
|
|
55
53
|
} catch (error) {
|
|
56
|
-
if ((0, _temporalio_workflow.isCancellation)(error)) return (0,
|
|
57
|
-
|
|
54
|
+
if ((0, _temporalio_workflow.isCancellation)(error)) return (0, unthrown.err)(new require_internal.WorkflowCancelledError(error));
|
|
55
|
+
throw error;
|
|
58
56
|
}
|
|
59
57
|
};
|
|
60
|
-
return (0, _temporal_contract_contract_result_async.
|
|
58
|
+
return (0, _temporal_contract_contract_result_async._internal_makeAsyncResult)(work);
|
|
61
59
|
}
|
|
62
60
|
/**
|
|
63
61
|
* Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
|
|
@@ -65,10 +63,10 @@ function cancellableScope(fn) {
|
|
|
65
63
|
* to perform cleanup that must not be interrupted (e.g. releasing a
|
|
66
64
|
* resource after a graceful shutdown).
|
|
67
65
|
*
|
|
68
|
-
* Mirrors `cancellableScope`'s `
|
|
66
|
+
* Mirrors `cancellableScope`'s `AsyncResult<...>` shape for symmetry; the
|
|
69
67
|
* `err(WorkflowCancelledError)` branch only triggers when cancellation is
|
|
70
|
-
* raised from inside the scope (rare). Non-cancellation errors surface
|
|
71
|
-
* `
|
|
68
|
+
* raised from inside the scope (rare). Non-cancellation errors surface on the
|
|
69
|
+
* `defect` channel.
|
|
72
70
|
*
|
|
73
71
|
* @example
|
|
74
72
|
* ```ts
|
|
@@ -80,13 +78,13 @@ function cancellableScope(fn) {
|
|
|
80
78
|
function nonCancellableScope(fn) {
|
|
81
79
|
const work = async () => {
|
|
82
80
|
try {
|
|
83
|
-
return (0,
|
|
81
|
+
return (0, unthrown.ok)(await _temporalio_workflow.CancellationScope.nonCancellable(async () => fn()));
|
|
84
82
|
} catch (error) {
|
|
85
|
-
if ((0, _temporalio_workflow.isCancellation)(error)) return (0,
|
|
86
|
-
|
|
83
|
+
if ((0, _temporalio_workflow.isCancellation)(error)) return (0, unthrown.err)(new require_internal.WorkflowCancelledError(error));
|
|
84
|
+
throw error;
|
|
87
85
|
}
|
|
88
86
|
};
|
|
89
|
-
return (0, _temporal_contract_contract_result_async.
|
|
87
|
+
return (0, _temporal_contract_contract_result_async._internal_makeAsyncResult)(work);
|
|
90
88
|
}
|
|
91
89
|
//#endregion
|
|
92
90
|
//#region src/handlers.ts
|
|
@@ -187,16 +185,16 @@ function bindUpdateHandler(workflowDefinition, workflowName, updateName, handler
|
|
|
187
185
|
//#region src/child-workflow.ts
|
|
188
186
|
async function validateChildWorkflowOutput(childDefinition, result, childWorkflowName) {
|
|
189
187
|
const outputResult = await childDefinition.output["~standard"].validate(result);
|
|
190
|
-
if (outputResult.issues) return (0,
|
|
191
|
-
return (0,
|
|
188
|
+
if (outputResult.issues) return (0, unthrown.err)(new require_internal.ChildWorkflowError(require_internal.formatChildWorkflowValidationMessage(childWorkflowName, "output", outputResult.issues)));
|
|
189
|
+
return (0, unthrown.ok)(outputResult.value);
|
|
192
190
|
}
|
|
193
191
|
async function getAndValidateChildWorkflow(childContract, childWorkflowName, args) {
|
|
194
192
|
const childDefinition = childContract.workflows[childWorkflowName];
|
|
195
|
-
if (!childDefinition) return (0,
|
|
193
|
+
if (!childDefinition) return (0, unthrown.err)(new require_internal.ChildWorkflowNotFoundError(childWorkflowName, Object.keys(childContract.workflows)));
|
|
196
194
|
const inputResult = await childDefinition.input["~standard"].validate(args);
|
|
197
|
-
if (inputResult.issues) return (0,
|
|
195
|
+
if (inputResult.issues) return (0, unthrown.err)(new require_internal.ChildWorkflowError(require_internal.formatChildWorkflowValidationMessage(childWorkflowName, "input", inputResult.issues)));
|
|
198
196
|
const validatedInput = inputResult.value;
|
|
199
|
-
return (0,
|
|
197
|
+
return (0, unthrown.ok)({
|
|
200
198
|
definition: childDefinition,
|
|
201
199
|
validatedInput,
|
|
202
200
|
taskQueue: childContract.taskQueue
|
|
@@ -210,35 +208,37 @@ function createTypedChildHandle(handle, childDefinition, childWorkflowName) {
|
|
|
210
208
|
try {
|
|
211
209
|
return validateChildWorkflowOutput(childDefinition, await handle.result(), childWorkflowName);
|
|
212
210
|
} catch (error) {
|
|
213
|
-
return (0,
|
|
211
|
+
return (0, unthrown.err)(require_internal.classifyChildWorkflowError("result", error, childWorkflowName));
|
|
214
212
|
}
|
|
215
213
|
};
|
|
216
|
-
return (0, _temporal_contract_contract_result_async.
|
|
214
|
+
return (0, _temporal_contract_contract_result_async._internal_makeAsyncResult)(work);
|
|
217
215
|
}
|
|
218
216
|
};
|
|
219
217
|
}
|
|
220
218
|
function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
221
219
|
const work = async () => {
|
|
222
220
|
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
223
|
-
|
|
221
|
+
(0, _temporal_contract_contract_result_async._internal_assertNoDefect)(validationResult);
|
|
222
|
+
if (validationResult.isErr()) return (0, unthrown.err)(validationResult.error);
|
|
224
223
|
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
225
224
|
try {
|
|
226
225
|
const { args: _args, ...temporalOptions } = options;
|
|
227
|
-
return (0,
|
|
226
|
+
return (0, unthrown.ok)(createTypedChildHandle(await (0, _temporalio_workflow.startChild)(childWorkflowName, {
|
|
228
227
|
...temporalOptions,
|
|
229
228
|
taskQueue,
|
|
230
229
|
args: [validatedInput]
|
|
231
230
|
}), childDefinition, childWorkflowName));
|
|
232
231
|
} catch (error) {
|
|
233
|
-
return (0,
|
|
232
|
+
return (0, unthrown.err)(require_internal.classifyChildWorkflowError("startChild", error, String(childWorkflowName)));
|
|
234
233
|
}
|
|
235
234
|
};
|
|
236
|
-
return (0, _temporal_contract_contract_result_async.
|
|
235
|
+
return (0, _temporal_contract_contract_result_async._internal_makeAsyncResult)(work);
|
|
237
236
|
}
|
|
238
237
|
function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
239
238
|
const work = async () => {
|
|
240
239
|
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
241
|
-
|
|
240
|
+
(0, _temporal_contract_contract_result_async._internal_assertNoDefect)(validationResult);
|
|
241
|
+
if (validationResult.isErr()) return (0, unthrown.err)(validationResult.error);
|
|
242
242
|
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
243
243
|
try {
|
|
244
244
|
const { args: _args, ...temporalOptions } = options;
|
|
@@ -247,13 +247,14 @@ function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
|
247
247
|
taskQueue,
|
|
248
248
|
args: [validatedInput]
|
|
249
249
|
}), childWorkflowName);
|
|
250
|
-
|
|
251
|
-
return (0,
|
|
250
|
+
(0, _temporal_contract_contract_result_async._internal_assertNoDefect)(outputValidationResult);
|
|
251
|
+
if (outputValidationResult.isErr()) return (0, unthrown.err)(outputValidationResult.error);
|
|
252
|
+
return (0, unthrown.ok)(outputValidationResult.value);
|
|
252
253
|
} catch (error) {
|
|
253
|
-
return (0,
|
|
254
|
+
return (0, unthrown.err)(require_internal.classifyChildWorkflowError("executeChild", error, String(childWorkflowName)));
|
|
254
255
|
}
|
|
255
256
|
};
|
|
256
|
-
return (0, _temporal_contract_contract_result_async.
|
|
257
|
+
return (0, _temporal_contract_contract_result_async._internal_makeAsyncResult)(work);
|
|
257
258
|
}
|
|
258
259
|
//#endregion
|
|
259
260
|
//#region src/activities-proxy.ts
|
|
@@ -310,12 +311,16 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
310
311
|
* },
|
|
311
312
|
* // Optional: override `activityOptions` for specific activities. Each
|
|
312
313
|
* // entry shallow-merges over the workflow default — the override wins on
|
|
313
|
-
* // every property it specifies, including the whole `retry` block.
|
|
314
|
+
* // every property it specifies, including the whole `retry` block. The
|
|
315
|
+
* // override is Temporal's full `ActivityOptions`, so `taskQueue` works too,
|
|
316
|
+
* // letting you route individual activities to a dedicated worker pool.
|
|
314
317
|
* activityOptionsByName: {
|
|
315
318
|
* chargePayment: {
|
|
316
319
|
* startToCloseTimeout: '5 minutes',
|
|
317
320
|
* retry: { maximumAttempts: 5 },
|
|
318
321
|
* },
|
|
322
|
+
* // Route this activity to a dedicated, concurrency-capped queue.
|
|
323
|
+
* scoreRisk: { taskQueue: 'ml-inference' },
|
|
319
324
|
* },
|
|
320
325
|
* implementation: async (context, args) => {
|
|
321
326
|
* // context.activities: typed activities (workflow + global)
|
|
@@ -403,8 +408,8 @@ exports.QueryOutputValidationError = require_internal.QueryOutputValidationError
|
|
|
403
408
|
exports.SignalInputValidationError = require_internal.SignalInputValidationError;
|
|
404
409
|
exports.UpdateInputValidationError = require_internal.UpdateInputValidationError;
|
|
405
410
|
exports.UpdateOutputValidationError = require_internal.UpdateOutputValidationError;
|
|
411
|
+
exports.ValidationError = require_internal.ValidationError;
|
|
406
412
|
exports.WorkflowCancelledError = require_internal.WorkflowCancelledError;
|
|
407
413
|
exports.WorkflowInputValidationError = require_internal.WorkflowInputValidationError;
|
|
408
414
|
exports.WorkflowOutputValidationError = require_internal.WorkflowOutputValidationError;
|
|
409
|
-
exports.WorkflowScopeError = require_internal.WorkflowScopeError;
|
|
410
415
|
exports.declareWorkflow = declareWorkflow;
|
package/dist/workflow.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { _ as ClientInferOutput, a as ChildWorkflowError, c as QueryOutputValidationError, d as UpdateOutputValidationError, f as
|
|
1
|
+
import { _ as ClientInferOutput, a as ChildWorkflowError, c as QueryOutputValidationError, d as UpdateOutputValidationError, f as ValidationError, g as ClientInferInput, h as WorkflowOutputValidationError, i as ChildWorkflowCancelledError, l as SignalInputValidationError, m as WorkflowInputValidationError, n as ActivityInputValidationError, o as ChildWorkflowNotFoundError, p as WorkflowCancelledError, r as ActivityOutputValidationError, s as QueryInputValidationError, u as UpdateInputValidationError, v as WorkerInferInput, y as WorkerInferOutput } from "./errors-BNnNzSwE.cjs";
|
|
2
2
|
import { ActivityDefinition, AnyWorkflowDefinition, ContractDefinition, QueryDefinition, QueryNamesOf, SignalDefinition, SignalNamesOf, UpdateDefinition, UpdateNamesOf } from "@temporal-contract/contract";
|
|
3
|
-
import {
|
|
3
|
+
import { AsyncResult } from "unthrown";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
5
5
|
import { ActivityOptions, ChildWorkflowOptions, ContinueAsNewOptions, WorkflowInfo } from "@temporalio/workflow";
|
|
6
6
|
//#region src/handlers.d.ts
|
|
@@ -44,13 +44,13 @@ type TypedChildWorkflowOptions<TChildContract extends ContractDefinition, TChild
|
|
|
44
44
|
args: ClientInferInput<TChildContract["workflows"][TChildWorkflowName]>;
|
|
45
45
|
};
|
|
46
46
|
/**
|
|
47
|
-
* Typed handle for a child workflow with
|
|
47
|
+
* Typed handle for a child workflow with unthrown `AsyncResult` pattern.
|
|
48
48
|
*/
|
|
49
49
|
type TypedChildWorkflowHandle<TWorkflow extends AnyWorkflowDefinition> = {
|
|
50
50
|
/**
|
|
51
|
-
* Get child workflow result with `
|
|
51
|
+
* Get child workflow result with `AsyncResult` pattern.
|
|
52
52
|
*/
|
|
53
|
-
result: () =>
|
|
53
|
+
result: () => AsyncResult<ClientInferOutput<TWorkflow>, ChildWorkflowError | ChildWorkflowCancelledError>;
|
|
54
54
|
/**
|
|
55
55
|
* Child workflow ID.
|
|
56
56
|
*/
|
|
@@ -105,12 +105,16 @@ type WorkflowInferWorkflowContextActivities<TContract extends ContractDefinition
|
|
|
105
105
|
* },
|
|
106
106
|
* // Optional: override `activityOptions` for specific activities. Each
|
|
107
107
|
* // entry shallow-merges over the workflow default — the override wins on
|
|
108
|
-
* // every property it specifies, including the whole `retry` block.
|
|
108
|
+
* // every property it specifies, including the whole `retry` block. The
|
|
109
|
+
* // override is Temporal's full `ActivityOptions`, so `taskQueue` works too,
|
|
110
|
+
* // letting you route individual activities to a dedicated worker pool.
|
|
109
111
|
* activityOptionsByName: {
|
|
110
112
|
* chargePayment: {
|
|
111
113
|
* startToCloseTimeout: '5 minutes',
|
|
112
114
|
* retry: { maximumAttempts: 5 },
|
|
113
115
|
* },
|
|
116
|
+
* // Route this activity to a dedicated, concurrency-capped queue.
|
|
117
|
+
* scoreRisk: { taskQueue: 'ml-inference' },
|
|
114
118
|
* },
|
|
115
119
|
* implementation: async (context, args) => {
|
|
116
120
|
* // context.activities: typed activities (workflow + global)
|
|
@@ -199,10 +203,17 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
|
|
|
199
203
|
* entire nested `retry` block when present, matching Temporal's
|
|
200
204
|
* single-options-per-`proxyActivities`-call semantics).
|
|
201
205
|
*
|
|
206
|
+
* The override value is Temporal's full `ActivityOptions`, so any field is
|
|
207
|
+
* fair game — including `taskQueue`, which lets you route individual
|
|
208
|
+
* activities to dedicated worker pools (e.g. concurrency-capped queues for
|
|
209
|
+
* LLM calls) while the rest of the workflow's activities stay on the default
|
|
210
|
+
* queue. This keeps the Zod-validated typed-activities boundary intact, where
|
|
211
|
+
* a raw `proxyActivities({ taskQueue })` would forfeit it.
|
|
212
|
+
*
|
|
202
213
|
* Activity names are typed against the contract; typos surface as TypeScript
|
|
203
214
|
* errors rather than running silently with the default options.
|
|
204
215
|
*
|
|
205
|
-
* @example
|
|
216
|
+
* @example Tune timeouts and retries per activity
|
|
206
217
|
* ```ts
|
|
207
218
|
* activityOptions: { startToCloseTimeout: '1 minute' }, // default
|
|
208
219
|
* activityOptionsByName: {
|
|
@@ -213,6 +224,16 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
|
|
|
213
224
|
* fastValidation: { startToCloseTimeout: '5 seconds' },
|
|
214
225
|
* },
|
|
215
226
|
* ```
|
|
227
|
+
*
|
|
228
|
+
* @example Route specific activities to a dedicated task queue
|
|
229
|
+
* ```ts
|
|
230
|
+
* activityOptions: { startToCloseTimeout: '10 minutes' }, // default queue
|
|
231
|
+
* activityOptionsByName: {
|
|
232
|
+
* // LLM call → dedicated, concurrency-capped queue.
|
|
233
|
+
* extractLayoutChunk: { taskQueue: 'gemini-pro' },
|
|
234
|
+
* // finalizeLayout, extractImages, … fall through to the default queue.
|
|
235
|
+
* },
|
|
236
|
+
* ```
|
|
216
237
|
*/
|
|
217
238
|
activityOptionsByName?: Partial<Record<ActivityNamesFor<TContract, TWorkflowName>, ActivityOptions>>;
|
|
218
239
|
};
|
|
@@ -291,7 +312,7 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
291
312
|
*/
|
|
292
313
|
defineUpdate: <K extends UpdateNamesOf<TContract["workflows"][TWorkflowName]>>(updateName: K, handler: UpdateHandlerImplementation<NonNullable<TContract["workflows"][TWorkflowName]["updates"]> extends Record<string, UpdateDefinition> ? NonNullable<TContract["workflows"][TWorkflowName]["updates"]>[K] extends UpdateDefinition ? NonNullable<TContract["workflows"][TWorkflowName]["updates"]>[K] : never : never>) => void;
|
|
293
314
|
/**
|
|
294
|
-
* Start a child workflow and return a typed handle with
|
|
315
|
+
* Start a child workflow and return a typed handle with AsyncResult pattern
|
|
295
316
|
*
|
|
296
317
|
* Supports both same-contract and cross-contract child workflows:
|
|
297
318
|
* - Same contract: Pass workflowName from current contract
|
|
@@ -311,18 +332,19 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
311
332
|
* args: { message: 'Hello' }
|
|
312
333
|
* });
|
|
313
334
|
*
|
|
314
|
-
* childResult.match(
|
|
315
|
-
* async (handle) => {
|
|
335
|
+
* await childResult.match({
|
|
336
|
+
* ok: async (handle) => {
|
|
316
337
|
* const result = await handle.result();
|
|
317
338
|
* // ... handle result
|
|
318
339
|
* },
|
|
319
|
-
* (error) => console.error('Failed to start:', error),
|
|
320
|
-
* )
|
|
340
|
+
* err: (error) => console.error('Failed to start:', error),
|
|
341
|
+
* defect: (cause) => console.error('Unexpected failure:', cause),
|
|
342
|
+
* });
|
|
321
343
|
* ```
|
|
322
344
|
*/
|
|
323
|
-
startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) =>
|
|
345
|
+
startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => AsyncResult<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError | ChildWorkflowCancelledError | ChildWorkflowNotFoundError>;
|
|
324
346
|
/**
|
|
325
|
-
* Execute a child workflow (start and wait for result) with
|
|
347
|
+
* Execute a child workflow (start and wait for result) with AsyncResult pattern
|
|
326
348
|
*
|
|
327
349
|
* Supports both same-contract and cross-contract child workflows:
|
|
328
350
|
* - Same contract: Pass workflowName from current contract
|
|
@@ -342,62 +364,59 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
342
364
|
* args: { message: 'Hello' }
|
|
343
365
|
* });
|
|
344
366
|
*
|
|
345
|
-
* result.match(
|
|
346
|
-
* (output) => console.log('Payment processed:', output),
|
|
347
|
-
* (error) => console.error('Processing failed:', error),
|
|
348
|
-
* )
|
|
367
|
+
* await result.match({
|
|
368
|
+
* ok: (output) => console.log('Payment processed:', output),
|
|
369
|
+
* err: (error) => console.error('Processing failed:', error),
|
|
370
|
+
* defect: (cause) => console.error('Unexpected failure:', cause),
|
|
371
|
+
* });
|
|
349
372
|
* ```
|
|
350
373
|
*/
|
|
351
|
-
executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) =>
|
|
374
|
+
executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => AsyncResult<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError | ChildWorkflowCancelledError | ChildWorkflowNotFoundError>;
|
|
352
375
|
/**
|
|
353
376
|
* Run `fn` inside a cancellable Temporal scope. If the workflow (or an
|
|
354
377
|
* ancestor scope) is cancelled while `fn` is in flight, the resulting
|
|
355
|
-
*
|
|
378
|
+
* AsyncResult resolves to `err(WorkflowCancelledError)` instead of
|
|
356
379
|
* rejecting — letting callers handle cancellation explicitly, typically
|
|
357
380
|
* to perform a graceful exit from the current step.
|
|
358
381
|
*
|
|
359
|
-
* Non-cancellation errors thrown by `fn`
|
|
360
|
-
* `
|
|
361
|
-
* `cause
|
|
362
|
-
*
|
|
363
|
-
* rejection.
|
|
382
|
+
* Non-cancellation errors thrown by `fn` are *unmodeled* failures: they ride
|
|
383
|
+
* unthrown's `defect` channel (inspectable via `result.isDefect()` /
|
|
384
|
+
* `result.cause`, re-thrown at the edge), keeping the modeled error channel
|
|
385
|
+
* to the single anticipated outcome — cancellation.
|
|
364
386
|
*
|
|
365
387
|
* @example
|
|
366
388
|
* ```ts
|
|
389
|
+
*
|
|
367
390
|
* implementation: async (context, args) => {
|
|
368
391
|
* const result = await context.cancellableScope(async () => {
|
|
369
392
|
* return context.activities.processStep(args);
|
|
370
393
|
* });
|
|
371
394
|
*
|
|
372
|
-
* if (result.isErr()) {
|
|
373
|
-
*
|
|
374
|
-
*
|
|
375
|
-
* await context.
|
|
376
|
-
*
|
|
377
|
-
*
|
|
378
|
-
* return { status: "cancelled" };
|
|
379
|
-
* }
|
|
380
|
-
* // result.error instanceof WorkflowScopeError — domain failure
|
|
381
|
-
* return { status: "failed" };
|
|
395
|
+
* if (result.isErr() && result.error instanceof WorkflowCancelledError) {
|
|
396
|
+
* // workflow was cancelled — perform cleanup that must not be cancelled:
|
|
397
|
+
* await context.nonCancellableScope(async () => {
|
|
398
|
+
* await context.activities.releaseResources(args);
|
|
399
|
+
* });
|
|
400
|
+
* return { status: "cancelled" };
|
|
382
401
|
* }
|
|
383
402
|
*
|
|
384
403
|
* return { status: "ok" };
|
|
385
404
|
* }
|
|
386
405
|
* ```
|
|
387
406
|
*/
|
|
388
|
-
cancellableScope: <T>(fn: () => T | Promise<T>) =>
|
|
407
|
+
cancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
|
|
389
408
|
/**
|
|
390
409
|
* Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
|
|
391
410
|
* from outside the scope are ignored for its duration — the idiomatic way
|
|
392
411
|
* to perform cleanup work that must not be interrupted.
|
|
393
412
|
*
|
|
394
|
-
* Returns the same `
|
|
413
|
+
* Returns the same `AsyncResult<...>` shape as
|
|
395
414
|
* {@link WorkflowContext.cancellableScope} for symmetry; the
|
|
396
415
|
* `err(WorkflowCancelledError)` branch only triggers when cancellation is
|
|
397
416
|
* raised from *inside* the scope, which is rare. Non-cancellation errors
|
|
398
|
-
* surface
|
|
417
|
+
* surface on the `defect` channel.
|
|
399
418
|
*/
|
|
400
|
-
nonCancellableScope: <T>(fn: () => T | Promise<T>) =>
|
|
419
|
+
nonCancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
|
|
401
420
|
/**
|
|
402
421
|
* Continue this workflow execution as a new run, optionally with a different
|
|
403
422
|
* workflow type from another contract.
|
|
@@ -431,5 +450,5 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
431
450
|
};
|
|
432
451
|
}; //# sourceMappingURL=workflow.d.ts.map
|
|
433
452
|
//#endregion
|
|
434
|
-
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError,
|
|
453
|
+
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
|
435
454
|
//# sourceMappingURL=workflow.d.cts.map
|
package/dist/workflow.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.cts","names":[],"sources":["../src/handlers.ts","../src/internal.ts","../src/child-workflow.ts","../src/activities-proxy.ts","../src/workflow.ts"],"mappings":";;;;;;;;;;;;KAkCY,2BAAA,iBAA4C,gBAAA,KACtD,IAAA,EAAM,gBAAA,CAAiB,OAAA,aACb,OAAA;;;;;;;KAQA,0BAAA,gBAA0C,eAAA,KACpD,IAAA,EAAM,gBAAA,CAAiB,MAAA,MACpB,iBAAA,CAAkB,MAAA;;;;;;;KAQX,2BAAA,iBAA4C,gBAAA,KACtD,IAAA,EAAM,gBAAA,CAAiB,OAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,OAAA;;;;;;;;
|
|
1
|
+
{"version":3,"file":"workflow.d.cts","names":[],"sources":["../src/handlers.ts","../src/internal.ts","../src/child-workflow.ts","../src/activities-proxy.ts","../src/workflow.ts"],"mappings":";;;;;;;;;;;;KAkCY,2BAAA,iBAA4C,gBAAA,KACtD,IAAA,EAAM,gBAAA,CAAiB,OAAA,aACb,OAAA;;;;;;;KAQA,0BAAA,gBAA0C,eAAA,KACpD,IAAA,EAAM,gBAAA,CAAiB,MAAA,MACpB,iBAAA,CAAkB,MAAA;;;;;;;KAQX,2BAAA,iBAA4C,gBAAA,KACtD,IAAA,EAAM,gBAAA,CAAiB,OAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,OAAA;;;;;;;;KC0FnB,yBAAA,GAA4B,IAAI,CAAC,oBAAA;;;;;;;;KCnHjC,yBAAA,wBACa,kBAAA,mCACU,cAAA,0BAC/B,IAAA,CAAK,oBAAA;EACP,IAAA,EAAM,gBAAA,CAAiB,cAAA,cAA4B,kBAAA;AAAA;;;;KAMzC,wBAAA,mBAA2C,qBAAA;EFL3C;;AAAO;EESjB,MAAA,QAAc,WAAA,CACZ,iBAAA,CAAkB,SAAA,GAClB,kBAAA,GAAqB,2BAAA;EFHa;;;EESpC,UAAA;AAAA;;;AFnBF;;;;;AAAA,KGfY,qBAAA,mBAAwC,kBAAA,KAClD,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,SAAA;;;;KAKnB,uBAAA,mBAA0C,kBAAA,IACpD,SAAA,uBAAgC,MAAA,SAAe,kBAAA,kBAE7B,SAAA,iBAA0B,qBAAA,CAAsB,SAAA,eAAwB,CAAA;;;;KAOhF,+BAAA,WAA0C,qBAAA,IACpD,CAAA,uBAAwB,MAAA,SAAe,kBAAA,kBAErB,CAAA,iBAAkB,qBAAA,CAAsB,CAAA,eAAgB,CAAA;;;;;;KAShE,sCAAA,mBACQ,kBAAA,8BACU,SAAA,0BAC1B,+BAAA,CAAgC,SAAA,cAAuB,aAAA,KACzD,uBAAA,CAA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