@temporal-contract/worker 2.4.0 → 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.
@@ -1,7 +1,7 @@
1
- import { _ as ClientInferInput, a as ChildWorkflowError, b as WorkerInferOutput, c as QueryOutputValidationError, d as UpdateOutputValidationError, f as ValidationError, g as WorkflowScopeError, 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 ClientInferOutput, y as WorkerInferInput } from "./errors-CE56feY1.mjs";
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 neverthrow `ResultAsync` pattern.
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 `ResultAsync` pattern.
52
+ * Get child workflow result with `AsyncResult` pattern.
53
53
  */
54
- result: () => ResultAsync<ClientInferOutput<TWorkflow>, ChildWorkflowError | ChildWorkflowCancelledError>;
54
+ result: () => AsyncResult<ClientInferOutput<TWorkflow>, ChildWorkflowError | ChildWorkflowCancelledError>;
55
55
  /**
56
56
  * Child workflow ID.
57
57
  */
@@ -313,7 +313,7 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
313
313
  */
314
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;
315
315
  /**
316
- * Start a child workflow and return a typed handle with ResultAsync pattern
316
+ * Start a child workflow and return a typed handle with AsyncResult pattern
317
317
  *
318
318
  * Supports both same-contract and cross-contract child workflows:
319
319
  * - Same contract: Pass workflowName from current contract
@@ -333,18 +333,19 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
333
333
  * args: { message: 'Hello' }
334
334
  * });
335
335
  *
336
- * childResult.match(
337
- * async (handle) => {
336
+ * await childResult.match({
337
+ * ok: async (handle) => {
338
338
  * const result = await handle.result();
339
339
  * // ... handle result
340
340
  * },
341
- * (error) => console.error('Failed to start:', error),
342
- * );
341
+ * err: (error) => console.error('Failed to start:', error),
342
+ * defect: (cause) => console.error('Unexpected failure:', cause),
343
+ * });
343
344
  * ```
344
345
  */
345
- startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError | ChildWorkflowCancelledError | ChildWorkflowNotFoundError>;
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>;
346
347
  /**
347
- * Execute a child workflow (start and wait for result) with ResultAsync pattern
348
+ * Execute a child workflow (start and wait for result) with AsyncResult pattern
348
349
  *
349
350
  * Supports both same-contract and cross-contract child workflows:
350
351
  * - Same contract: Pass workflowName from current contract
@@ -364,62 +365,59 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
364
365
  * args: { message: 'Hello' }
365
366
  * });
366
367
  *
367
- * result.match(
368
- * (output) => console.log('Payment processed:', output),
369
- * (error) => console.error('Processing failed:', error),
370
- * );
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
+ * });
371
373
  * ```
372
374
  */
373
- executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"] & string>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError | ChildWorkflowCancelledError | ChildWorkflowNotFoundError>;
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>;
374
376
  /**
375
377
  * Run `fn` inside a cancellable Temporal scope. If the workflow (or an
376
378
  * ancestor scope) is cancelled while `fn` is in flight, the resulting
377
- * ResultAsync resolves to `err(WorkflowCancelledError)` instead of
379
+ * AsyncResult resolves to `err(WorkflowCancelledError)` instead of
378
380
  * rejecting — letting callers handle cancellation explicitly, typically
379
381
  * to perform a graceful exit from the current step.
380
382
  *
381
- * Non-cancellation errors thrown by `fn` resolve to
382
- * `err(WorkflowScopeError)` (with the original error preserved on
383
- * `cause`). Both failure modes ride neverthrow's railway, so
384
- * `result.match(...)` is exhaustive nothing escapes as an unhandled
385
- * 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.
386
387
  *
387
388
  * @example
388
389
  * ```ts
390
+ *
389
391
  * implementation: async (context, args) => {
390
392
  * const result = await context.cancellableScope(async () => {
391
393
  * return context.activities.processStep(args);
392
394
  * });
393
395
  *
394
- * if (result.isErr()) {
395
- * if (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" };
401
- * }
402
- * // result.error instanceof WorkflowScopeError — domain failure
403
- * 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" };
404
402
  * }
405
403
  *
406
404
  * return { status: "ok" };
407
405
  * }
408
406
  * ```
409
407
  */
410
- cancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError | WorkflowScopeError>;
408
+ cancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
411
409
  /**
412
410
  * Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
413
411
  * from outside the scope are ignored for its duration — the idiomatic way
414
412
  * to perform cleanup work that must not be interrupted.
415
413
  *
416
- * Returns the same `ResultAsync<...>` shape as
414
+ * Returns the same `AsyncResult<...>` shape as
417
415
  * {@link WorkflowContext.cancellableScope} for symmetry; the
418
416
  * `err(WorkflowCancelledError)` branch only triggers when cancellation is
419
417
  * raised from *inside* the scope, which is rare. Non-cancellation errors
420
- * surface as `err(WorkflowScopeError)`.
418
+ * surface on the `defect` channel.
421
419
  */
422
- nonCancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError | WorkflowScopeError>;
420
+ nonCancellableScope: <T>(fn: () => T | Promise<T>) => AsyncResult<T, WorkflowCancelledError>;
423
421
  /**
424
422
  * Continue this workflow execution as a new run, optionally with a different
425
423
  * workflow type from another contract.
@@ -453,5 +451,5 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
453
451
  };
454
452
  }; //# sourceMappingURL=workflow.d.ts.map
455
453
  //#endregion
456
- export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, WorkflowScopeError, declareWorkflow };
454
+ export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
457
455
  //# sourceMappingURL=workflow.d.mts.map
@@ -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;;;;;;;;KCsFnB,yBAAA,GAA4B,IAAI,CAAC,oBAAA;;;;;;;;KChHjC,yBAAA,wBACa,kBAAA,mCACU,cAAA,0BAC/B,IAAA,CAAK,oBAAA;EACP,IAAA,EAAM,gBAAA,CAAiB,cAAA,cAA4B,kBAAA;AAAA;;;;KAMzC,wBAAA,mBAA2C,qBAAA;EFJ3C;;AAAO;EEQjB,MAAA,QAAc,WAAA,CACZ,iBAAA,CAAkB,SAAA,GAClB,kBAAA,GAAqB,2BAAA;EFFa;;;EEQpC,UAAA;AAAA;;;AFlBF;;;;;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,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AChD,WAAA,CACH,wBAAA,CAAyB,cAAA,cAA4B,kBAAA,IACrD,kBAAA,GAAqB,2BAAA,GAA8B,0BAAA;EAxPlC;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsRnB,oBAAA,0BACyB,kBAAA,mCACU,cAAA,wBAEjC,QAAA,EAAU,cAAA,EACV,YAAA,EAAc,kBAAA,EACd,OAAA,EAAS,yBAAA,CAA0B,cAAA,EAAgB,kBAAA,MAChD,WAAA,CACH,iBAAA,CAAkB,cAAA,cAA4B,kBAAA,IAC9C,kBAAA,GAAqB,2BAAA,GAA8B,0BAAA;EAxRH;;;AAC7B;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8TrB,gBAAA,MACE,EAAA,QAAU,CAAA,GAAI,OAAA,CAAQ,CAAA,MACnB,WAAA,CAAY,CAAA,EAAG,sBAAA,GAAyB,kBAAA;EAxP7C;;;;;;;;AACoE;AAAA;;EAoQpE,mBAAA,MACE,EAAA,QAAU,CAAA,GAAI,OAAA,CAAQ,CAAA,MACnB,WAAA,CAAY,CAAA,EAAG,sBAAA,GAAyB,kBAAA;EA3P3B;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwRlB,aAAA;IAnR6B,8EAsRzB,IAAA,EAAM,gBAAA,CAAiB,SAAA,cAAuB,aAAA,IAC9C,OAAA,GAAU,yBAAA,GACT,OAAA,SAxR4D;IAAA,wBA2RtC,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"}
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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A,EACd,OAAA,EAAS,yBAAA,CAA0B,cAAA,EAAgB,kBAAA,MAChD,WAAA,CACH,iBAAA,CAAkB,cAAA,cAA4B,kBAAA,IAC9C,kBAAA,GAAqB,2BAAA,GAA8B,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 { S as WorkflowScopeError, _ as UpdateOutputValidationError, a as formatChildWorkflowValidationMessage, b as WorkflowInputValidationError, c as ActivityInputValidationError, d as ChildWorkflowError, f as ChildWorkflowNotFoundError, g as UpdateInputValidationError, h as SignalInputValidationError, i as extractHandlerInput, l as ActivityOutputValidationError, m as QueryOutputValidationError, n as classifyChildWorkflowError, o as makeResultAsync, p as QueryInputValidationError, r as createContinueAsNew, t as buildRawActivitiesProxy, u as ChildWorkflowCancelledError, v as ValidationError, x as WorkflowOutputValidationError, y as WorkflowCancelledError } from "./internal-D0wfFl0y.mjs";
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 `ResultAsync<...>` shape used elsewhere in the worker
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 wrapped in a
14
- * {@link WorkflowScopeError} (with the original error preserved on
15
- * `cause`) and surfaced on the same `err(...)` channel. Together with
16
- * `WorkflowCancelledError` this makes the failure modes exhaustive on
17
- * `result.match(...)` — nothing escapes as an unhandled rejection.
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 ResultAsync resolves to `err(WorkflowCancelledError)`,
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` resolve to
27
- * `err(WorkflowScopeError)` (with the original error on `cause`) so
28
- * domain failures surface on the same typed error channel rather than
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
- * if (error instanceof WorkflowCancelledError) {
41
- * // graceful exit
42
- * } else {
43
- * // error instanceof WorkflowScopeError domain failure on `cause`
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
- return err(new WorkflowScopeError(error));
53
+ throw error;
56
54
  }
57
55
  };
58
- return makeResultAsync(work, (e) => new WorkflowScopeError(e));
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 `ResultAsync<...>` shape for symmetry; the
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 as
69
- * `err(WorkflowScopeError)`.
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
- return err(new WorkflowScopeError(error));
82
+ throw error;
85
83
  }
86
84
  };
87
- return makeResultAsync(work, (e) => new WorkflowScopeError(e));
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 makeResultAsync(work, (error) => new ChildWorkflowError(`Child workflow execution failed: ${error instanceof Error ? error.message : String(error)}`, error));
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 makeResultAsync(work, (error) => new ChildWorkflowError(`Failed to start child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
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 makeResultAsync(work, (error) => new ChildWorkflowError(`Failed to execute child workflow: ${error instanceof Error ? error.message : String(error)}`, error));
255
+ return makeAsyncResult(work);
255
256
  }
256
257
  //#endregion
257
258
  //#region src/activities-proxy.ts
@@ -395,6 +396,6 @@ function declareWorkflow({ workflowName, contract, implementation, activityOptio
395
396
  return workflowFn;
396
397
  }
397
398
  //#endregion
398
- export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, WorkflowScopeError, declareWorkflow };
399
+ export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowCancelledError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, ValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
399
400
 
400
401
  //# sourceMappingURL=workflow.mjs.map