@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.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.mjs";
|
|
2
2
|
import { ActivityDefinition, AnyWorkflowDefinition, ContractDefinition, QueryDefinition, QueryNamesOf, SignalDefinition, SignalNamesOf, UpdateDefinition, UpdateNamesOf } from "@temporal-contract/contract";
|
|
3
|
+
import { AsyncResult } from "unthrown";
|
|
3
4
|
import { ActivityOptions, ChildWorkflowOptions, ContinueAsNewOptions, WorkflowInfo } from "@temporalio/workflow";
|
|
4
|
-
import { ResultAsync } from "neverthrow";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
6
|
|
|
7
7
|
//#region src/handlers.d.ts
|
|
@@ -45,13 +45,13 @@ type TypedChildWorkflowOptions<TChildContract extends ContractDefinition, TChild
|
|
|
45
45
|
args: ClientInferInput<TChildContract["workflows"][TChildWorkflowName]>;
|
|
46
46
|
};
|
|
47
47
|
/**
|
|
48
|
-
* Typed handle for a child workflow with
|
|
48
|
+
* Typed handle for a child workflow with unthrown `AsyncResult` pattern.
|
|
49
49
|
*/
|
|
50
50
|
type TypedChildWorkflowHandle<TWorkflow extends AnyWorkflowDefinition> = {
|
|
51
51
|
/**
|
|
52
|
-
* Get child workflow result with `
|
|
52
|
+
* Get child workflow result with `AsyncResult` pattern.
|
|
53
53
|
*/
|
|
54
|
-
result: () =>
|
|
54
|
+
result: () => AsyncResult<ClientInferOutput<TWorkflow>, ChildWorkflowError | ChildWorkflowCancelledError>;
|
|
55
55
|
/**
|
|
56
56
|
* Child workflow ID.
|
|
57
57
|
*/
|
|
@@ -106,12 +106,16 @@ type WorkflowInferWorkflowContextActivities<TContract extends ContractDefinition
|
|
|
106
106
|
* },
|
|
107
107
|
* // Optional: override `activityOptions` for specific activities. Each
|
|
108
108
|
* // entry shallow-merges over the workflow default — the override wins on
|
|
109
|
-
* // every property it specifies, including the whole `retry` block.
|
|
109
|
+
* // every property it specifies, including the whole `retry` block. The
|
|
110
|
+
* // override is Temporal's full `ActivityOptions`, so `taskQueue` works too,
|
|
111
|
+
* // letting you route individual activities to a dedicated worker pool.
|
|
110
112
|
* activityOptionsByName: {
|
|
111
113
|
* chargePayment: {
|
|
112
114
|
* startToCloseTimeout: '5 minutes',
|
|
113
115
|
* retry: { maximumAttempts: 5 },
|
|
114
116
|
* },
|
|
117
|
+
* // Route this activity to a dedicated, concurrency-capped queue.
|
|
118
|
+
* scoreRisk: { taskQueue: 'ml-inference' },
|
|
115
119
|
* },
|
|
116
120
|
* implementation: async (context, args) => {
|
|
117
121
|
* // context.activities: typed activities (workflow + global)
|
|
@@ -200,10 +204,17 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
|
|
|
200
204
|
* entire nested `retry` block when present, matching Temporal's
|
|
201
205
|
* single-options-per-`proxyActivities`-call semantics).
|
|
202
206
|
*
|
|
207
|
+
* The override value is Temporal's full `ActivityOptions`, so any field is
|
|
208
|
+
* fair game — including `taskQueue`, which lets you route individual
|
|
209
|
+
* activities to dedicated worker pools (e.g. concurrency-capped queues for
|
|
210
|
+
* LLM calls) while the rest of the workflow's activities stay on the default
|
|
211
|
+
* queue. This keeps the Zod-validated typed-activities boundary intact, where
|
|
212
|
+
* a raw `proxyActivities({ taskQueue })` would forfeit it.
|
|
213
|
+
*
|
|
203
214
|
* Activity names are typed against the contract; typos surface as TypeScript
|
|
204
215
|
* errors rather than running silently with the default options.
|
|
205
216
|
*
|
|
206
|
-
* @example
|
|
217
|
+
* @example Tune timeouts and retries per activity
|
|
207
218
|
* ```ts
|
|
208
219
|
* activityOptions: { startToCloseTimeout: '1 minute' }, // default
|
|
209
220
|
* activityOptionsByName: {
|
|
@@ -214,6 +225,16 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
|
|
|
214
225
|
* fastValidation: { startToCloseTimeout: '5 seconds' },
|
|
215
226
|
* },
|
|
216
227
|
* ```
|
|
228
|
+
*
|
|
229
|
+
* @example Route specific activities to a dedicated task queue
|
|
230
|
+
* ```ts
|
|
231
|
+
* activityOptions: { startToCloseTimeout: '10 minutes' }, // default queue
|
|
232
|
+
* activityOptionsByName: {
|
|
233
|
+
* // LLM call → dedicated, concurrency-capped queue.
|
|
234
|
+
* extractLayoutChunk: { taskQueue: 'gemini-pro' },
|
|
235
|
+
* // finalizeLayout, extractImages, … fall through to the default queue.
|
|
236
|
+
* },
|
|
237
|
+
* ```
|
|
217
238
|
*/
|
|
218
239
|
activityOptionsByName?: Partial<Record<ActivityNamesFor<TContract, TWorkflowName>, ActivityOptions>>;
|
|
219
240
|
};
|
|
@@ -292,7 +313,7 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
292
313
|
*/
|
|
293
314
|
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;
|
|
294
315
|
/**
|
|
295
|
-
* Start a child workflow and return a typed handle with
|
|
316
|
+
* Start a child workflow and return a typed handle with AsyncResult pattern
|
|
296
317
|
*
|
|
297
318
|
* Supports both same-contract and cross-contract child workflows:
|
|
298
319
|
* - Same contract: Pass workflowName from current contract
|
|
@@ -312,18 +333,19 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
312
333
|
* args: { message: 'Hello' }
|
|
313
334
|
* });
|
|
314
335
|
*
|
|
315
|
-
* childResult.match(
|
|
316
|
-
* async (handle) => {
|
|
336
|
+
* await childResult.match({
|
|
337
|
+
* ok: async (handle) => {
|
|
317
338
|
* const result = await handle.result();
|
|
318
339
|
* // ... handle result
|
|
319
340
|
* },
|
|
320
|
-
* (error) => console.error('Failed to start:', error),
|
|
321
|
-
* )
|
|
341
|
+
* err: (error) => console.error('Failed to start:', error),
|
|
342
|
+
* defect: (cause) => console.error('Unexpected failure:', cause),
|
|
343
|
+
* });
|
|
322
344
|
* ```
|
|
323
345
|
*/
|
|
324
|
-
startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) =>
|
|
346
|
+
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>;
|
|
325
347
|
/**
|
|
326
|
-
* Execute a child workflow (start and wait for result) with
|
|
348
|
+
* Execute a child workflow (start and wait for result) with AsyncResult pattern
|
|
327
349
|
*
|
|
328
350
|
* Supports both same-contract and cross-contract child workflows:
|
|
329
351
|
* - Same contract: Pass workflowName from current contract
|
|
@@ -343,62 +365,59 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
343
365
|
* args: { message: 'Hello' }
|
|
344
366
|
* });
|
|
345
367
|
*
|
|
346
|
-
* result.match(
|
|
347
|
-
* (output) => console.log('Payment processed:', output),
|
|
348
|
-
* (error) => console.error('Processing failed:', error),
|
|
349
|
-
* )
|
|
368
|
+
* await result.match({
|
|
369
|
+
* ok: (output) => console.log('Payment processed:', output),
|
|
370
|
+
* err: (error) => console.error('Processing failed:', error),
|
|
371
|
+
* defect: (cause) => console.error('Unexpected failure:', cause),
|
|
372
|
+
* });
|
|
350
373
|
* ```
|
|
351
374
|
*/
|
|
352
|
-
executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) =>
|
|
375
|
+
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>;
|
|
353
376
|
/**
|
|
354
377
|
* Run `fn` inside a cancellable Temporal scope. If the workflow (or an
|
|
355
378
|
* ancestor scope) is cancelled while `fn` is in flight, the resulting
|
|
356
|
-
*
|
|
379
|
+
* AsyncResult resolves to `err(WorkflowCancelledError)` instead of
|
|
357
380
|
* rejecting — letting callers handle cancellation explicitly, typically
|
|
358
381
|
* to perform a graceful exit from the current step.
|
|
359
382
|
*
|
|
360
|
-
* Non-cancellation errors thrown by `fn`
|
|
361
|
-
* `
|
|
362
|
-
* `cause
|
|
363
|
-
*
|
|
364
|
-
* rejection.
|
|
383
|
+
* Non-cancellation errors thrown by `fn` are *unmodeled* failures: they ride
|
|
384
|
+
* unthrown's `defect` channel (inspectable via `result.isDefect()` /
|
|
385
|
+
* `result.cause`, re-thrown at the edge), keeping the modeled error channel
|
|
386
|
+
* to the single anticipated outcome — cancellation.
|
|
365
387
|
*
|
|
366
388
|
* @example
|
|
367
389
|
* ```ts
|
|
390
|
+
*
|
|
368
391
|
* implementation: async (context, args) => {
|
|
369
392
|
* const result = await context.cancellableScope(async () => {
|
|
370
393
|
* return context.activities.processStep(args);
|
|
371
394
|
* });
|
|
372
395
|
*
|
|
373
|
-
* if (result.isErr()) {
|
|
374
|
-
*
|
|
375
|
-
*
|
|
376
|
-
* await context.
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
* return { status: "cancelled" };
|
|
380
|
-
* }
|
|
381
|
-
* // result.error instanceof WorkflowScopeError — domain failure
|
|
382
|
-
* return { status: "failed" };
|
|
396
|
+
* if (result.isErr() && result.error instanceof WorkflowCancelledError) {
|
|
397
|
+
* // workflow was cancelled — perform cleanup that must not be cancelled:
|
|
398
|
+
* await context.nonCancellableScope(async () => {
|
|
399
|
+
* await context.activities.releaseResources(args);
|
|
400
|
+
* });
|
|
401
|
+
* return { status: "cancelled" };
|
|
383
402
|
* }
|
|
384
403
|
*
|
|
385
404
|
* return { status: "ok" };
|
|
386
405
|
* }
|
|
387
406
|
* ```
|
|
388
407
|
*/
|
|
389
|
-
cancellableScope: <T>(fn: () => T | Promise<T>) =>
|
|
408
|
+
cancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
|
|
390
409
|
/**
|
|
391
410
|
* Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
|
|
392
411
|
* from outside the scope are ignored for its duration — the idiomatic way
|
|
393
412
|
* to perform cleanup work that must not be interrupted.
|
|
394
413
|
*
|
|
395
|
-
* Returns the same `
|
|
414
|
+
* Returns the same `AsyncResult<...>` shape as
|
|
396
415
|
* {@link WorkflowContext.cancellableScope} for symmetry; the
|
|
397
416
|
* `err(WorkflowCancelledError)` branch only triggers when cancellation is
|
|
398
417
|
* raised from *inside* the scope, which is rare. Non-cancellation errors
|
|
399
|
-
* surface
|
|
418
|
+
* surface on the `defect` channel.
|
|
400
419
|
*/
|
|
401
|
-
nonCancellableScope: <T>(fn: () => T | Promise<T>) =>
|
|
420
|
+
nonCancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
|
|
402
421
|
/**
|
|
403
422
|
* Continue this workflow execution as a new run, optionally with a different
|
|
404
423
|
* workflow type from another contract.
|
|
@@ -432,5 +451,5 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
|
|
|
432
451
|
};
|
|
433
452
|
}; //# sourceMappingURL=workflow.d.ts.map
|
|
434
453
|
//#endregion
|
|
435
|
-
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError,
|
|
454
|
+
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
|
436
455
|
//# sourceMappingURL=workflow.d.mts.map
|
package/dist/workflow.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflow.d.mts","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.mts","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,2BAA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AA8B,0BAAA;EAzRhC;AAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA4TrB,gBAAA,MAAsB,EAAA,QAAU,CAAA,GAAI,OAAA,CAAQ,CAAA,MAAO,WAAA,CAAY,CAAA,EAAG,sBAAA;EA5RlE;;;;;;;;;;AAyCoE;EAgQpE,mBAAA,MAAyB,EAAA,QAAU,CAAA,GAAI,OAAA,CAAQ,CAAA,MAAO,WAAA,CAAY,CAAA,EAAG,sBAAA;EAtP5C;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmRzB,aAAA;IA7QG,8EAgRC,IAAA,EAAM,gBAAA,CAAiB,SAAA,cAAuB,aAAA,IAC9C,OAAA,GAAU,yBAAA,GACT,OAAA,SAlRwB;IAAA,wBAqRF,kBAAA,mCACU,cAAA,wBAEjC,QAAA,EAAU,cAAA,EACV,YAAA,EAAc,kBAAA,EACd,IAAA,EAAM,gBAAA,CAAiB,cAAA,cAA4B,kBAAA,IACnD,OAAA,GAAU,yBAAA,GACT,OAAA;EAAA;AAAA"}
|
package/dist/workflow.mjs
CHANGED
|
@@ -1,32 +1,31 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as WorkflowOutputValidationError, _ as UpdateInputValidationError, a as extractHandlerInput, b as WorkflowCancelledError, d as ChildWorkflowCancelledError, f as ChildWorkflowError, g as SignalInputValidationError, h as QueryOutputValidationError, i as createContinueAsNew, l as ActivityInputValidationError, m as QueryInputValidationError, n as buildRawActivitiesProxy, o as formatChildWorkflowValidationMessage, p as ChildWorkflowNotFoundError, r as classifyChildWorkflowError, s as makeAsyncResult, t as assertNoDefect, u as ActivityOutputValidationError, v as UpdateOutputValidationError, x as WorkflowInputValidationError, y as ValidationError } from "./internal-DqYK4YQK.mjs";
|
|
2
|
+
import { err, ok } from "unthrown";
|
|
2
3
|
import { CancellationScope, defineQuery, defineSignal, defineUpdate, executeChild, isCancellation, setHandler, startChild, workflowInfo } from "@temporalio/workflow";
|
|
3
|
-
import { err, ok } from "neverthrow";
|
|
4
4
|
//#region src/cancellation.ts
|
|
5
5
|
/**
|
|
6
6
|
* Typed wrappers around Temporal's `CancellationScope` so workflows can
|
|
7
7
|
* opt into cancellation control without reaching for
|
|
8
8
|
* `@temporalio/workflow` directly. The wrappers fold cancellation into
|
|
9
|
-
* the same `
|
|
9
|
+
* the same `AsyncResult<...>` shape used elsewhere in the worker
|
|
10
10
|
* context — callers branch on `err(WorkflowCancelledError)` instead of
|
|
11
11
|
* catching `CancelledFailure`.
|
|
12
12
|
*
|
|
13
|
-
* Non-cancellation errors thrown inside the scope are
|
|
14
|
-
*
|
|
15
|
-
* `cause`)
|
|
16
|
-
*
|
|
17
|
-
*
|
|
13
|
+
* Non-cancellation errors thrown inside the scope are *unmodeled* failures:
|
|
14
|
+
* they ride unthrown's `defect` channel (re-thrown at the edge / inspectable
|
|
15
|
+
* via `result.isDefect()` and `result.cause`) rather than a typed `err(...)`,
|
|
16
|
+
* keeping the modeled error channel to the single anticipated outcome —
|
|
17
|
+
* cancellation.
|
|
18
18
|
*/
|
|
19
19
|
/**
|
|
20
20
|
* Run `fn` inside a cancellable Temporal scope. If the workflow (or an
|
|
21
21
|
* ancestor scope) is cancelled while the function is in flight, the
|
|
22
|
-
* resulting
|
|
22
|
+
* resulting AsyncResult resolves to `err(WorkflowCancelledError)`,
|
|
23
23
|
* letting callers handle cancellation explicitly — typically to perform
|
|
24
24
|
* a graceful exit from the current step.
|
|
25
25
|
*
|
|
26
|
-
* Non-cancellation errors thrown by `fn`
|
|
27
|
-
* `
|
|
28
|
-
*
|
|
29
|
-
* leaking as unhandled rejections.
|
|
26
|
+
* Non-cancellation errors thrown by `fn` are unmodeled failures: they surface
|
|
27
|
+
* on the `defect` channel rather than as a typed `err(...)`, so a genuine bug
|
|
28
|
+
* is not silently treated as an anticipated domain outcome.
|
|
30
29
|
*
|
|
31
30
|
* @example
|
|
32
31
|
* ```ts
|
|
@@ -34,16 +33,15 @@ import { err, ok } from "neverthrow";
|
|
|
34
33
|
* return await context.activities.processStep(...);
|
|
35
34
|
* });
|
|
36
35
|
*
|
|
37
|
-
* result.match(
|
|
38
|
-
* (output) => { ... },
|
|
39
|
-
* (error) => {
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* }
|
|
36
|
+
* result.match({
|
|
37
|
+
* ok: (output) => { ... },
|
|
38
|
+
* err: (error) => {
|
|
39
|
+
* // error instanceof WorkflowCancelledError — graceful exit
|
|
40
|
+
* },
|
|
41
|
+
* defect: (cause) => {
|
|
42
|
+
* // a non-cancellation failure thrown inside the scope (a bug)
|
|
45
43
|
* },
|
|
46
|
-
* );
|
|
44
|
+
* });
|
|
47
45
|
* ```
|
|
48
46
|
*/
|
|
49
47
|
function cancellableScope(fn) {
|
|
@@ -52,10 +50,10 @@ function cancellableScope(fn) {
|
|
|
52
50
|
return ok(await CancellationScope.cancellable(async () => fn()));
|
|
53
51
|
} catch (error) {
|
|
54
52
|
if (isCancellation(error)) return err(new WorkflowCancelledError(error));
|
|
55
|
-
|
|
53
|
+
throw error;
|
|
56
54
|
}
|
|
57
55
|
};
|
|
58
|
-
return
|
|
56
|
+
return makeAsyncResult(work);
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
|
|
@@ -63,10 +61,10 @@ function cancellableScope(fn) {
|
|
|
63
61
|
* to perform cleanup that must not be interrupted (e.g. releasing a
|
|
64
62
|
* resource after a graceful shutdown).
|
|
65
63
|
*
|
|
66
|
-
* Mirrors `cancellableScope`'s `
|
|
64
|
+
* Mirrors `cancellableScope`'s `AsyncResult<...>` shape for symmetry; the
|
|
67
65
|
* `err(WorkflowCancelledError)` branch only triggers when cancellation is
|
|
68
|
-
* raised from inside the scope (rare). Non-cancellation errors surface
|
|
69
|
-
* `
|
|
66
|
+
* raised from inside the scope (rare). Non-cancellation errors surface on the
|
|
67
|
+
* `defect` channel.
|
|
70
68
|
*
|
|
71
69
|
* @example
|
|
72
70
|
* ```ts
|
|
@@ -81,10 +79,10 @@ function nonCancellableScope(fn) {
|
|
|
81
79
|
return ok(await CancellationScope.nonCancellable(async () => fn()));
|
|
82
80
|
} catch (error) {
|
|
83
81
|
if (isCancellation(error)) return err(new WorkflowCancelledError(error));
|
|
84
|
-
|
|
82
|
+
throw error;
|
|
85
83
|
}
|
|
86
84
|
};
|
|
87
|
-
return
|
|
85
|
+
return makeAsyncResult(work);
|
|
88
86
|
}
|
|
89
87
|
//#endregion
|
|
90
88
|
//#region src/handlers.ts
|
|
@@ -211,13 +209,14 @@ function createTypedChildHandle(handle, childDefinition, childWorkflowName) {
|
|
|
211
209
|
return err(classifyChildWorkflowError("result", error, childWorkflowName));
|
|
212
210
|
}
|
|
213
211
|
};
|
|
214
|
-
return
|
|
212
|
+
return makeAsyncResult(work);
|
|
215
213
|
}
|
|
216
214
|
};
|
|
217
215
|
}
|
|
218
216
|
function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
219
217
|
const work = async () => {
|
|
220
218
|
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
219
|
+
assertNoDefect(validationResult);
|
|
221
220
|
if (validationResult.isErr()) return err(validationResult.error);
|
|
222
221
|
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
223
222
|
try {
|
|
@@ -231,11 +230,12 @@ function createStartChildWorkflow(childContract, childWorkflowName, options) {
|
|
|
231
230
|
return err(classifyChildWorkflowError("startChild", error, String(childWorkflowName)));
|
|
232
231
|
}
|
|
233
232
|
};
|
|
234
|
-
return
|
|
233
|
+
return makeAsyncResult(work);
|
|
235
234
|
}
|
|
236
235
|
function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
237
236
|
const work = async () => {
|
|
238
237
|
const validationResult = await getAndValidateChildWorkflow(childContract, childWorkflowName, options.args);
|
|
238
|
+
assertNoDefect(validationResult);
|
|
239
239
|
if (validationResult.isErr()) return err(validationResult.error);
|
|
240
240
|
const { definition: childDefinition, validatedInput, taskQueue } = validationResult.value;
|
|
241
241
|
try {
|
|
@@ -245,13 +245,14 @@ function createExecuteChildWorkflow(childContract, childWorkflowName, options) {
|
|
|
245
245
|
taskQueue,
|
|
246
246
|
args: [validatedInput]
|
|
247
247
|
}), childWorkflowName);
|
|
248
|
+
assertNoDefect(outputValidationResult);
|
|
248
249
|
if (outputValidationResult.isErr()) return err(outputValidationResult.error);
|
|
249
250
|
return ok(outputValidationResult.value);
|
|
250
251
|
} catch (error) {
|
|
251
252
|
return err(classifyChildWorkflowError("executeChild", error, String(childWorkflowName)));
|
|
252
253
|
}
|
|
253
254
|
};
|
|
254
|
-
return
|
|
255
|
+
return makeAsyncResult(work);
|
|
255
256
|
}
|
|
256
257
|
//#endregion
|
|
257
258
|
//#region src/activities-proxy.ts
|
|
@@ -308,12 +309,16 @@ function createValidatedActivities(rawActivities, workflowActivitiesDefinition,
|
|
|
308
309
|
* },
|
|
309
310
|
* // Optional: override `activityOptions` for specific activities. Each
|
|
310
311
|
* // entry shallow-merges over the workflow default — the override wins on
|
|
311
|
-
* // every property it specifies, including the whole `retry` block.
|
|
312
|
+
* // every property it specifies, including the whole `retry` block. The
|
|
313
|
+
* // override is Temporal's full `ActivityOptions`, so `taskQueue` works too,
|
|
314
|
+
* // letting you route individual activities to a dedicated worker pool.
|
|
312
315
|
* activityOptionsByName: {
|
|
313
316
|
* chargePayment: {
|
|
314
317
|
* startToCloseTimeout: '5 minutes',
|
|
315
318
|
* retry: { maximumAttempts: 5 },
|
|
316
319
|
* },
|
|
320
|
+
* // Route this activity to a dedicated, concurrency-capped queue.
|
|
321
|
+
* scoreRisk: { taskQueue: 'ml-inference' },
|
|
317
322
|
* },
|
|
318
323
|
* implementation: async (context, args) => {
|
|
319
324
|
* // context.activities: typed activities (workflow + global)
|
|
@@ -391,6 +396,6 @@ function declareWorkflow({ workflowName, contract, implementation, activityOptio
|
|
|
391
396
|
return workflowFn;
|
|
392
397
|
}
|
|
393
398
|
//#endregion
|
|
394
|
-
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError,
|
|
399
|
+
export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
|
|
395
400
|
|
|
396
401
|
//# sourceMappingURL=workflow.mjs.map
|