@temporal-contract/worker 0.2.0 → 2.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,8 +1,40 @@
1
- import { a as ChildWorkflowNotFoundError, c as SignalInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as WorkerInferOutput, h as WorkerInferInput, i as ChildWorkflowError, l as UpdateInputValidationError, m as ClientInferOutput, n as ActivityInputValidationError, o as QueryInputValidationError, p as ClientInferInput, r as ActivityOutputValidationError, s as QueryOutputValidationError, u as UpdateOutputValidationError } from "./errors-4jH78z8m.cjs";
1
+ import { _ as WorkerInferOutput, a as ChildWorkflowNotFoundError, c as SignalInputValidationError, d as WorkflowCancelledError, f as WorkflowInputValidationError, g as WorkerInferInput, h as ClientInferOutput, i as ChildWorkflowError, l as UpdateInputValidationError, m as ClientInferInput, n as ActivityInputValidationError, o as QueryInputValidationError, p as WorkflowOutputValidationError, r as ActivityOutputValidationError, s as QueryOutputValidationError, u as UpdateOutputValidationError } from "./errors-BeIXtRJe.cjs";
2
2
  import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefinition, UpdateDefinition, WorkflowDefinition } from "@temporal-contract/contract";
3
- import { Future, Result } from "@temporal-contract/boxed";
4
- import { ActivityOptions, ChildWorkflowOptions, WorkflowInfo } from "@temporalio/workflow";
3
+ import { ResultAsync } from "neverthrow";
4
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
+ import { ActivityOptions, ChildWorkflowOptions, ContinueAsNewOptions, WorkflowInfo } from "@temporalio/workflow";
5
6
 
7
+ //#region src/handlers.d.ts
8
+ /**
9
+ * Signal handler implementation
10
+ *
11
+ * Processes signal input and can optionally perform asynchronous operations.
12
+ * Should not return a value (signals are fire-and-forget).
13
+ */
14
+ type SignalHandlerImplementation<TSignal extends SignalDefinition> = (args: WorkerInferInput<TSignal>) => void | Promise<void>;
15
+ /**
16
+ * Query handler implementation
17
+ *
18
+ * Processes query input and returns a synchronous response.
19
+ * Must be synchronous to satisfy Temporal's query constraints.
20
+ */
21
+ type QueryHandlerImplementation<TQuery extends QueryDefinition> = (args: WorkerInferInput<TQuery>) => WorkerInferOutput<TQuery>;
22
+ /**
23
+ * Update handler implementation
24
+ *
25
+ * Processes update input and returns a validated response after modifying workflow state.
26
+ * Can perform asynchronous operations.
27
+ */
28
+ type UpdateHandlerImplementation<TUpdate extends UpdateDefinition> = (args: WorkerInferInput<TUpdate>) => Promise<WorkerInferOutput<TUpdate>>;
29
+ //#endregion
30
+ //#region src/internal.d.ts
31
+ /**
32
+ * Continue-as-new options the typed wrapper does not own. `workflowType` and
33
+ * `taskQueue` are derived from the contract; everything else is forwarded to
34
+ * Temporal's `makeContinueAsNewFunc`.
35
+ */
36
+ type TypedContinueAsNewOptions = Omit<ContinueAsNewOptions, "workflowType" | "taskQueue">;
37
+ //#endregion
6
38
  //#region src/workflow.d.ts
7
39
  /**
8
40
  * Create a typed workflow implementation with automatic validation
@@ -27,6 +59,15 @@ import { ActivityOptions, ChildWorkflowOptions, WorkflowInfo } from "@temporalio
27
59
  * activityOptions: {
28
60
  * startToCloseTimeout: '1 minute',
29
61
  * },
62
+ * // Optional: override `activityOptions` for specific activities. Each
63
+ * // entry shallow-merges over the workflow default — the override wins on
64
+ * // every property it specifies, including the whole `retry` block.
65
+ * activityOptionsByName: {
66
+ * chargePayment: {
67
+ * startToCloseTimeout: '5 minutes',
68
+ * retry: { maximumAttempts: 5 },
69
+ * },
70
+ * },
30
71
  * implementation: async (context, args) => {
31
72
  * // context.activities: typed activities (workflow + global)
32
73
  * // context.info: WorkflowInfo
@@ -72,29 +113,14 @@ declare function declareWorkflow<TContract extends ContractDefinition, TWorkflow
72
113
  workflowName,
73
114
  contract,
74
115
  implementation,
75
- activityOptions
116
+ activityOptions,
117
+ activityOptionsByName
76
118
  }: DeclareWorkflowOptions<TContract, TWorkflowName>): (...args: unknown[]) => Promise<WorkerInferOutput<TContract["workflows"][TWorkflowName]>>;
77
119
  /**
78
- * Signal handler implementation
79
- *
80
- * Processes signal input and can optionally perform asynchronous operations.
81
- * Should not return a value (signals are fire-and-forget).
82
- */
83
- type SignalHandlerImplementation<TSignal extends SignalDefinition> = (args: WorkerInferInput<TSignal>) => void | Promise<void>;
84
- /**
85
- * Query handler implementation
86
- *
87
- * Processes query input and returns a synchronous response.
88
- * Must be synchronous to satisfy Temporal's query constraints.
120
+ * Union of all activity names available to a workflow — the workflow-local
121
+ * activities plus the contract's global activities.
89
122
  */
90
- type QueryHandlerImplementation<TQuery extends QueryDefinition> = (args: WorkerInferInput<TQuery>) => WorkerInferOutput<TQuery>;
91
- /**
92
- * Update handler implementation
93
- *
94
- * Processes update input and returns a validated response after modifying workflow state.
95
- * Can perform asynchronous operations.
96
- */
97
- type UpdateHandlerImplementation<TUpdate extends UpdateDefinition> = (args: WorkerInferInput<TUpdate>) => Promise<WorkerInferOutput<TUpdate>>;
123
+ type ActivityNamesFor<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]> = (TContract["workflows"][TWorkflowName]["activities"] extends Record<string, ActivityDefinition> ? keyof TContract["workflows"][TWorkflowName]["activities"] & string : never) | (TContract["activities"] extends Record<string, ActivityDefinition> ? keyof TContract["activities"] & string : never);
98
124
  /**
99
125
  * Options for declaring a workflow implementation
100
126
  */
@@ -103,23 +129,48 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
103
129
  contract: TContract;
104
130
  implementation: WorkflowImplementation<TContract, TWorkflowName>;
105
131
  /**
106
- * Default activity options applied to all activities in this workflow.
107
- * For more control, you can override specific Temporal ActivityOptions like:
108
- * - startToCloseTimeout: Maximum time for activity execution
109
- * - scheduleToCloseTimeout: End-to-end timeout including queuing
110
- * - scheduleToStartTimeout: Maximum time activity can wait in queue
111
- * - heartbeatTimeout: Time between heartbeats before considering activity dead
112
- * - retry: Retry policy for failed activities
132
+ * Default activity options applied to every activity reachable from this
133
+ * workflow (workflow-local + global) unless overridden in
134
+ * {@link activityOptionsByName}. See Temporal's `ActivityOptions` for the
135
+ * full set of fields:
136
+ * - `startToCloseTimeout`: Maximum time for a single attempt to run
137
+ * - `scheduleToCloseTimeout`: End-to-end timeout including queuing and retries
138
+ * - `scheduleToStartTimeout`: Maximum time the activity can wait in the queue
139
+ * - `heartbeatTimeout`: Time between heartbeats before the activity is considered dead
140
+ * - `retry`: Retry policy for failed activities
113
141
  *
114
142
  * @example
115
143
  * ```ts
116
144
  * activityOptions: {
117
145
  * startToCloseTimeout: '5m',
118
- * retry: { maximumAttempts: 3 }
146
+ * retry: { maximumAttempts: 3 },
119
147
  * }
120
148
  * ```
121
149
  */
122
150
  activityOptions: ActivityOptions;
151
+ /**
152
+ * Per-activity `ActivityOptions` overrides. Each entry shallow-merges over
153
+ * {@link activityOptions} for that activity only — the override wins on
154
+ * every property it specifies, replacing the default value (including the
155
+ * entire nested `retry` block when present, matching Temporal's
156
+ * single-options-per-`proxyActivities`-call semantics).
157
+ *
158
+ * Activity names are typed against the contract; typos surface as TypeScript
159
+ * errors rather than running silently with the default options.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * activityOptions: { startToCloseTimeout: '1 minute' }, // default
164
+ * activityOptionsByName: {
165
+ * chargePayment: {
166
+ * startToCloseTimeout: '5 minutes',
167
+ * retry: { maximumAttempts: 5 },
168
+ * },
169
+ * fastValidation: { startToCloseTimeout: '5 seconds' },
170
+ * },
171
+ * ```
172
+ */
173
+ activityOptionsByName?: Partial<Record<ActivityNamesFor<TContract, TWorkflowName>, ActivityOptions>>;
123
174
  };
124
175
  /**
125
176
  * Workflow implementation function
@@ -196,7 +247,7 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
196
247
  */
197
248
  defineUpdate: <K extends keyof TContract["workflows"][TWorkflowName]["updates"]>(updateName: K, handler: UpdateHandlerImplementation<TContract["workflows"][TWorkflowName]["updates"][K] extends UpdateDefinition ? TContract["workflows"][TWorkflowName]["updates"][K] : never>) => void;
198
249
  /**
199
- * Start a child workflow and return a typed handle with Future/Result pattern
250
+ * Start a child workflow and return a typed handle with ResultAsync pattern
200
251
  *
201
252
  * Supports both same-contract and cross-contract child workflows:
202
253
  * - Same contract: Pass workflowName from current contract
@@ -216,18 +267,18 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
216
267
  * args: { message: 'Hello' }
217
268
  * });
218
269
  *
219
- * childResult.match({
220
- * Ok: async (handle) => {
270
+ * childResult.match(
271
+ * async (handle) => {
221
272
  * const result = await handle.result();
222
273
  * // ... handle result
223
274
  * },
224
- * Error: (error) => console.error('Failed to start:', error),
225
- * });
275
+ * (error) => console.error('Failed to start:', error),
276
+ * );
226
277
  * ```
227
278
  */
228
- startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => Future<Result<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>>;
279
+ startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>;
229
280
  /**
230
- * Execute a child workflow (start and wait for result) with Future/Result pattern
281
+ * Execute a child workflow (start and wait for result) with ResultAsync pattern
231
282
  *
232
283
  * Supports both same-contract and cross-contract child workflows:
233
284
  * - Same contract: Pass workflowName from current contract
@@ -247,13 +298,86 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
247
298
  * args: { message: 'Hello' }
248
299
  * });
249
300
  *
250
- * result.match({
251
- * Ok: (output) => console.log('Payment processed:', output),
252
- * Error: (error) => console.error('Processing failed:', error),
253
- * });
301
+ * result.match(
302
+ * (output) => console.log('Payment processed:', output),
303
+ * (error) => console.error('Processing failed:', error),
304
+ * );
305
+ * ```
306
+ */
307
+ executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>;
308
+ /**
309
+ * Run `fn` inside a cancellable Temporal scope. If the workflow (or an
310
+ * ancestor scope) is cancelled while `fn` is in flight, the resulting
311
+ * ResultAsync resolves to `err(WorkflowCancelledError)` instead of
312
+ * rejecting — letting callers handle cancellation explicitly, typically
313
+ * to perform a graceful exit from the current step.
314
+ *
315
+ * Non-cancellation errors thrown by `fn` propagate as ResultAsync
316
+ * rejections unchanged, preserving their identity for upstream
317
+ * `try/catch` blocks.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * implementation: async (context, args) => {
322
+ * const result = await context.cancellableScope(async () => {
323
+ * return context.activities.processStep(args);
324
+ * });
325
+ *
326
+ * if (result.isErr()) {
327
+ * // workflow was cancelled — perform cleanup that must not be cancelled:
328
+ * await context.nonCancellableScope(async () => {
329
+ * await context.activities.releaseResources(args);
330
+ * });
331
+ * return { status: "cancelled" };
332
+ * }
333
+ *
334
+ * return { status: "ok" };
335
+ * }
336
+ * ```
337
+ */
338
+ cancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError>;
339
+ /**
340
+ * Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
341
+ * from outside the scope are ignored for its duration — the idiomatic way
342
+ * to perform cleanup work that must not be interrupted.
343
+ *
344
+ * Returns the same `ResultAsync<...>` shape as
345
+ * {@link WorkflowContext.cancellableScope} for symmetry; the `err(...)`
346
+ * branch only triggers when cancellation is raised from *inside* the
347
+ * scope, which is rare.
348
+ */
349
+ nonCancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError>;
350
+ /**
351
+ * Continue this workflow execution as a new run, optionally with a different
352
+ * workflow type from another contract.
353
+ *
354
+ * Args are validated against the destination workflow's input schema before
355
+ * Temporal's `continueAsNew` is invoked. On validation failure, throws a
356
+ * {@link WorkflowInputValidationError}; on success, Temporal terminates the
357
+ * current execution and starts a fresh one — which is why the function
358
+ * never returns normally (`Promise<never>`).
359
+ *
360
+ * Idiomatic usage:
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * // Same workflow, validated args
365
+ * implementation: async (context, args) => {
366
+ * if (shouldRoll(args)) {
367
+ * return context.continueAsNew({ ...args, retryCount: args.retryCount + 1 });
368
+ * }
369
+ * return ...;
370
+ * }
371
+ *
372
+ * // Cross-contract continueAsNew (less common — taskQueue and workflow type
373
+ * // come from the other contract)
374
+ * return context.continueAsNew(otherContract, "otherWorkflow", { ...newArgs });
254
375
  * ```
255
376
  */
256
- executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => Future<Result<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>>;
377
+ continueAsNew: {
378
+ /** Same-workflow continuation — args typed against this workflow's input. */(args: ClientInferInput<TContract["workflows"][TWorkflowName]>, options?: TypedContinueAsNewOptions): Promise<never>; /** Cross-contract continuation — args typed against the destination workflow. */
379
+ <TOtherContract extends ContractDefinition, TOtherWorkflowName extends keyof TOtherContract["workflows"]>(contract: TOtherContract, workflowName: TOtherWorkflowName, args: ClientInferInput<TOtherContract["workflows"][TOtherWorkflowName]>, options?: TypedContinueAsNewOptions): Promise<never>;
380
+ };
257
381
  };
258
382
  /**
259
383
  * Options for starting a child workflow
@@ -262,13 +386,13 @@ type TypedChildWorkflowOptions<TChildContract extends ContractDefinition, TChild
262
386
  args: ClientInferInput<TChildContract["workflows"][TChildWorkflowName]>;
263
387
  };
264
388
  /**
265
- * Typed handle for a child workflow with Future/Result pattern
389
+ * Typed handle for a child workflow with neverthrow ResultAsync pattern
266
390
  */
267
391
  type TypedChildWorkflowHandle<TWorkflow extends WorkflowDefinition> = {
268
392
  /**
269
393
  * Get child workflow result with Result pattern
270
394
  */
271
- result: () => Future<Result<ClientInferOutput<TWorkflow>, ChildWorkflowError>>;
395
+ result: () => ResultAsync<ClientInferOutput<TWorkflow>, ChildWorkflowError>;
272
396
  /**
273
397
  * Child workflow ID
274
398
  */
@@ -295,5 +419,5 @@ type WorkflowInferWorkflowActivities<T extends WorkflowDefinition> = T["activiti
295
419
  */
296
420
  type WorkflowInferWorkflowContextActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]> = WorkflowInferWorkflowActivities<TContract["workflows"][TWorkflowName]> & WorkflowInferActivities<TContract>; //# sourceMappingURL=workflow.d.ts.map
297
421
  //#endregion
298
- export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
422
+ export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
299
423
  //# sourceMappingURL=workflow.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.cts","names":[],"sources":["../src/workflow.ts"],"mappings":";;;;;;AA2HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8aC;;;;;;;;;;;;;;;;;AAUkB;;;;;;;AAxbnB,iBAAgB,eAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAAA;EAE5B,YAAA;EACA,QAAA;EACA,cAAA;EACA;AAAA,GACC,sBAAA,CAAuB,SAAA,EAAW,aAAA,QAChC,IAAA,gBACA,OA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yBAAA,GACT,OAAA;EAAA;AAAA;;;;KAOF,yBAAA,wBACoB,kBAAA,mCACU,cAAA,iBAC/B,IAAA,CAAK,oBAAA;EACP,IAAA,EAAM,gBAAA,CAAiB,cAAA,cAA4B,kBAAA;AAAA;;;;KAMhD,wBAAA,mBAA2C,kBAAA;EAzNkB;;;EA6NhE,MAAA,QAAc,WAAA,CAAY,iBAAA,CAAkB,SAAA,GAAY,kBAAA;EA9NtD;;;EAmOF,UAAA;AAAA;;;;;;KAQG,qBAAA,mBAAwC,kBAAA,KAC3C,IAAA,EAAM,gBAAA,CAAiB,SAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,SAAA;;;;KAK1B,uBAAA,mBAA0C,kBAAA,IAC7C,SAAA,uBAAgC,MAAA,SAAe,kBAAA,kBAE7B,SAAA,iBAA0B,qBAAA,CAAsB,SAAA,eAAwB,CAAA;;;;KAOvF,+BAAA,WAA0C,kBAAA,IAC7C,CAAA,uBAAwB,MAAA,SAAe,kBAAA,kBAErB,CAAA,iBAAkB,qBAAA,CAAsB,CAAA,eAAgB,CAAA;;;;;;KASvE,sCAAA,mBACe,kBAAA,8BACU,SAAA,iBAC1B,+BAAA,CAAgC,SAAA,cAAuB,aAAA,KACzD,uBAAA,CAAwB,SAAA"}
@@ -1,8 +1,40 @@
1
- import { a as ChildWorkflowNotFoundError, c as SignalInputValidationError, d as WorkflowInputValidationError, f as WorkflowOutputValidationError, g as WorkerInferOutput, h as WorkerInferInput, i as ChildWorkflowError, l as UpdateInputValidationError, m as ClientInferOutput, n as ActivityInputValidationError, o as QueryInputValidationError, p as ClientInferInput, r as ActivityOutputValidationError, s as QueryOutputValidationError, u as UpdateOutputValidationError } from "./errors-CmTXZ3JW.mjs";
2
- import { Future, Result } from "@temporal-contract/boxed";
3
- import { ActivityOptions, ChildWorkflowOptions, WorkflowInfo } from "@temporalio/workflow";
1
+ import { _ as WorkerInferOutput, a as ChildWorkflowNotFoundError, c as SignalInputValidationError, d as WorkflowCancelledError, f as WorkflowInputValidationError, g as WorkerInferInput, h as ClientInferOutput, i as ChildWorkflowError, l as UpdateInputValidationError, m as ClientInferInput, n as ActivityInputValidationError, o as QueryInputValidationError, p as WorkflowOutputValidationError, r as ActivityOutputValidationError, s as QueryOutputValidationError, u as UpdateOutputValidationError } from "./errors-BjNG_jUi.mjs";
2
+ import { ActivityOptions, ChildWorkflowOptions, ContinueAsNewOptions, WorkflowInfo } from "@temporalio/workflow";
3
+ import { ResultAsync } from "neverthrow";
4
4
  import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefinition, UpdateDefinition, WorkflowDefinition } from "@temporal-contract/contract";
5
+ import { StandardSchemaV1 } from "@standard-schema/spec";
5
6
 
7
+ //#region src/handlers.d.ts
8
+ /**
9
+ * Signal handler implementation
10
+ *
11
+ * Processes signal input and can optionally perform asynchronous operations.
12
+ * Should not return a value (signals are fire-and-forget).
13
+ */
14
+ type SignalHandlerImplementation<TSignal extends SignalDefinition> = (args: WorkerInferInput<TSignal>) => void | Promise<void>;
15
+ /**
16
+ * Query handler implementation
17
+ *
18
+ * Processes query input and returns a synchronous response.
19
+ * Must be synchronous to satisfy Temporal's query constraints.
20
+ */
21
+ type QueryHandlerImplementation<TQuery extends QueryDefinition> = (args: WorkerInferInput<TQuery>) => WorkerInferOutput<TQuery>;
22
+ /**
23
+ * Update handler implementation
24
+ *
25
+ * Processes update input and returns a validated response after modifying workflow state.
26
+ * Can perform asynchronous operations.
27
+ */
28
+ type UpdateHandlerImplementation<TUpdate extends UpdateDefinition> = (args: WorkerInferInput<TUpdate>) => Promise<WorkerInferOutput<TUpdate>>;
29
+ //#endregion
30
+ //#region src/internal.d.ts
31
+ /**
32
+ * Continue-as-new options the typed wrapper does not own. `workflowType` and
33
+ * `taskQueue` are derived from the contract; everything else is forwarded to
34
+ * Temporal's `makeContinueAsNewFunc`.
35
+ */
36
+ type TypedContinueAsNewOptions = Omit<ContinueAsNewOptions, "workflowType" | "taskQueue">;
37
+ //#endregion
6
38
  //#region src/workflow.d.ts
7
39
  /**
8
40
  * Create a typed workflow implementation with automatic validation
@@ -27,6 +59,15 @@ import { ActivityDefinition, ContractDefinition, QueryDefinition, SignalDefiniti
27
59
  * activityOptions: {
28
60
  * startToCloseTimeout: '1 minute',
29
61
  * },
62
+ * // Optional: override `activityOptions` for specific activities. Each
63
+ * // entry shallow-merges over the workflow default — the override wins on
64
+ * // every property it specifies, including the whole `retry` block.
65
+ * activityOptionsByName: {
66
+ * chargePayment: {
67
+ * startToCloseTimeout: '5 minutes',
68
+ * retry: { maximumAttempts: 5 },
69
+ * },
70
+ * },
30
71
  * implementation: async (context, args) => {
31
72
  * // context.activities: typed activities (workflow + global)
32
73
  * // context.info: WorkflowInfo
@@ -72,29 +113,14 @@ declare function declareWorkflow<TContract extends ContractDefinition, TWorkflow
72
113
  workflowName,
73
114
  contract,
74
115
  implementation,
75
- activityOptions
116
+ activityOptions,
117
+ activityOptionsByName
76
118
  }: DeclareWorkflowOptions<TContract, TWorkflowName>): (...args: unknown[]) => Promise<WorkerInferOutput<TContract["workflows"][TWorkflowName]>>;
77
119
  /**
78
- * Signal handler implementation
79
- *
80
- * Processes signal input and can optionally perform asynchronous operations.
81
- * Should not return a value (signals are fire-and-forget).
82
- */
83
- type SignalHandlerImplementation<TSignal extends SignalDefinition> = (args: WorkerInferInput<TSignal>) => void | Promise<void>;
84
- /**
85
- * Query handler implementation
86
- *
87
- * Processes query input and returns a synchronous response.
88
- * Must be synchronous to satisfy Temporal's query constraints.
120
+ * Union of all activity names available to a workflow — the workflow-local
121
+ * activities plus the contract's global activities.
89
122
  */
90
- type QueryHandlerImplementation<TQuery extends QueryDefinition> = (args: WorkerInferInput<TQuery>) => WorkerInferOutput<TQuery>;
91
- /**
92
- * Update handler implementation
93
- *
94
- * Processes update input and returns a validated response after modifying workflow state.
95
- * Can perform asynchronous operations.
96
- */
97
- type UpdateHandlerImplementation<TUpdate extends UpdateDefinition> = (args: WorkerInferInput<TUpdate>) => Promise<WorkerInferOutput<TUpdate>>;
123
+ type ActivityNamesFor<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]> = (TContract["workflows"][TWorkflowName]["activities"] extends Record<string, ActivityDefinition> ? keyof TContract["workflows"][TWorkflowName]["activities"] & string : never) | (TContract["activities"] extends Record<string, ActivityDefinition> ? keyof TContract["activities"] & string : never);
98
124
  /**
99
125
  * Options for declaring a workflow implementation
100
126
  */
@@ -103,23 +129,48 @@ type DeclareWorkflowOptions<TContract extends ContractDefinition, TWorkflowName
103
129
  contract: TContract;
104
130
  implementation: WorkflowImplementation<TContract, TWorkflowName>;
105
131
  /**
106
- * Default activity options applied to all activities in this workflow.
107
- * For more control, you can override specific Temporal ActivityOptions like:
108
- * - startToCloseTimeout: Maximum time for activity execution
109
- * - scheduleToCloseTimeout: End-to-end timeout including queuing
110
- * - scheduleToStartTimeout: Maximum time activity can wait in queue
111
- * - heartbeatTimeout: Time between heartbeats before considering activity dead
112
- * - retry: Retry policy for failed activities
132
+ * Default activity options applied to every activity reachable from this
133
+ * workflow (workflow-local + global) unless overridden in
134
+ * {@link activityOptionsByName}. See Temporal's `ActivityOptions` for the
135
+ * full set of fields:
136
+ * - `startToCloseTimeout`: Maximum time for a single attempt to run
137
+ * - `scheduleToCloseTimeout`: End-to-end timeout including queuing and retries
138
+ * - `scheduleToStartTimeout`: Maximum time the activity can wait in the queue
139
+ * - `heartbeatTimeout`: Time between heartbeats before the activity is considered dead
140
+ * - `retry`: Retry policy for failed activities
113
141
  *
114
142
  * @example
115
143
  * ```ts
116
144
  * activityOptions: {
117
145
  * startToCloseTimeout: '5m',
118
- * retry: { maximumAttempts: 3 }
146
+ * retry: { maximumAttempts: 3 },
119
147
  * }
120
148
  * ```
121
149
  */
122
150
  activityOptions: ActivityOptions;
151
+ /**
152
+ * Per-activity `ActivityOptions` overrides. Each entry shallow-merges over
153
+ * {@link activityOptions} for that activity only — the override wins on
154
+ * every property it specifies, replacing the default value (including the
155
+ * entire nested `retry` block when present, matching Temporal's
156
+ * single-options-per-`proxyActivities`-call semantics).
157
+ *
158
+ * Activity names are typed against the contract; typos surface as TypeScript
159
+ * errors rather than running silently with the default options.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * activityOptions: { startToCloseTimeout: '1 minute' }, // default
164
+ * activityOptionsByName: {
165
+ * chargePayment: {
166
+ * startToCloseTimeout: '5 minutes',
167
+ * retry: { maximumAttempts: 5 },
168
+ * },
169
+ * fastValidation: { startToCloseTimeout: '5 seconds' },
170
+ * },
171
+ * ```
172
+ */
173
+ activityOptionsByName?: Partial<Record<ActivityNamesFor<TContract, TWorkflowName>, ActivityOptions>>;
123
174
  };
124
175
  /**
125
176
  * Workflow implementation function
@@ -196,7 +247,7 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
196
247
  */
197
248
  defineUpdate: <K extends keyof TContract["workflows"][TWorkflowName]["updates"]>(updateName: K, handler: UpdateHandlerImplementation<TContract["workflows"][TWorkflowName]["updates"][K] extends UpdateDefinition ? TContract["workflows"][TWorkflowName]["updates"][K] : never>) => void;
198
249
  /**
199
- * Start a child workflow and return a typed handle with Future/Result pattern
250
+ * Start a child workflow and return a typed handle with ResultAsync pattern
200
251
  *
201
252
  * Supports both same-contract and cross-contract child workflows:
202
253
  * - Same contract: Pass workflowName from current contract
@@ -216,18 +267,18 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
216
267
  * args: { message: 'Hello' }
217
268
  * });
218
269
  *
219
- * childResult.match({
220
- * Ok: async (handle) => {
270
+ * childResult.match(
271
+ * async (handle) => {
221
272
  * const result = await handle.result();
222
273
  * // ... handle result
223
274
  * },
224
- * Error: (error) => console.error('Failed to start:', error),
225
- * });
275
+ * (error) => console.error('Failed to start:', error),
276
+ * );
226
277
  * ```
227
278
  */
228
- startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => Future<Result<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>>;
279
+ startChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<TypedChildWorkflowHandle<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>;
229
280
  /**
230
- * Execute a child workflow (start and wait for result) with Future/Result pattern
281
+ * Execute a child workflow (start and wait for result) with ResultAsync pattern
231
282
  *
232
283
  * Supports both same-contract and cross-contract child workflows:
233
284
  * - Same contract: Pass workflowName from current contract
@@ -247,13 +298,86 @@ type WorkflowContext<TContract extends ContractDefinition, TWorkflowName extends
247
298
  * args: { message: 'Hello' }
248
299
  * });
249
300
  *
250
- * result.match({
251
- * Ok: (output) => console.log('Payment processed:', output),
252
- * Error: (error) => console.error('Processing failed:', error),
253
- * });
301
+ * result.match(
302
+ * (output) => console.log('Payment processed:', output),
303
+ * (error) => console.error('Processing failed:', error),
304
+ * );
305
+ * ```
306
+ */
307
+ executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => ResultAsync<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>;
308
+ /**
309
+ * Run `fn` inside a cancellable Temporal scope. If the workflow (or an
310
+ * ancestor scope) is cancelled while `fn` is in flight, the resulting
311
+ * ResultAsync resolves to `err(WorkflowCancelledError)` instead of
312
+ * rejecting — letting callers handle cancellation explicitly, typically
313
+ * to perform a graceful exit from the current step.
314
+ *
315
+ * Non-cancellation errors thrown by `fn` propagate as ResultAsync
316
+ * rejections unchanged, preserving their identity for upstream
317
+ * `try/catch` blocks.
318
+ *
319
+ * @example
320
+ * ```ts
321
+ * implementation: async (context, args) => {
322
+ * const result = await context.cancellableScope(async () => {
323
+ * return context.activities.processStep(args);
324
+ * });
325
+ *
326
+ * if (result.isErr()) {
327
+ * // workflow was cancelled — perform cleanup that must not be cancelled:
328
+ * await context.nonCancellableScope(async () => {
329
+ * await context.activities.releaseResources(args);
330
+ * });
331
+ * return { status: "cancelled" };
332
+ * }
333
+ *
334
+ * return { status: "ok" };
335
+ * }
336
+ * ```
337
+ */
338
+ cancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError>;
339
+ /**
340
+ * Run `fn` inside a non-cancellable Temporal scope. Cancellation requests
341
+ * from outside the scope are ignored for its duration — the idiomatic way
342
+ * to perform cleanup work that must not be interrupted.
343
+ *
344
+ * Returns the same `ResultAsync<...>` shape as
345
+ * {@link WorkflowContext.cancellableScope} for symmetry; the `err(...)`
346
+ * branch only triggers when cancellation is raised from *inside* the
347
+ * scope, which is rare.
348
+ */
349
+ nonCancellableScope: <T>(fn: () => T | Promise<T>) => ResultAsync<T, WorkflowCancelledError>;
350
+ /**
351
+ * Continue this workflow execution as a new run, optionally with a different
352
+ * workflow type from another contract.
353
+ *
354
+ * Args are validated against the destination workflow's input schema before
355
+ * Temporal's `continueAsNew` is invoked. On validation failure, throws a
356
+ * {@link WorkflowInputValidationError}; on success, Temporal terminates the
357
+ * current execution and starts a fresh one — which is why the function
358
+ * never returns normally (`Promise<never>`).
359
+ *
360
+ * Idiomatic usage:
361
+ *
362
+ * @example
363
+ * ```ts
364
+ * // Same workflow, validated args
365
+ * implementation: async (context, args) => {
366
+ * if (shouldRoll(args)) {
367
+ * return context.continueAsNew({ ...args, retryCount: args.retryCount + 1 });
368
+ * }
369
+ * return ...;
370
+ * }
371
+ *
372
+ * // Cross-contract continueAsNew (less common — taskQueue and workflow type
373
+ * // come from the other contract)
374
+ * return context.continueAsNew(otherContract, "otherWorkflow", { ...newArgs });
254
375
  * ```
255
376
  */
256
- executeChildWorkflow: <TChildContract extends ContractDefinition, TChildWorkflowName extends keyof TChildContract["workflows"]>(contract: TChildContract, workflowName: TChildWorkflowName, options: TypedChildWorkflowOptions<TChildContract, TChildWorkflowName>) => Future<Result<ClientInferOutput<TChildContract["workflows"][TChildWorkflowName]>, ChildWorkflowError>>;
377
+ continueAsNew: {
378
+ /** Same-workflow continuation — args typed against this workflow's input. */(args: ClientInferInput<TContract["workflows"][TWorkflowName]>, options?: TypedContinueAsNewOptions): Promise<never>; /** Cross-contract continuation — args typed against the destination workflow. */
379
+ <TOtherContract extends ContractDefinition, TOtherWorkflowName extends keyof TOtherContract["workflows"]>(contract: TOtherContract, workflowName: TOtherWorkflowName, args: ClientInferInput<TOtherContract["workflows"][TOtherWorkflowName]>, options?: TypedContinueAsNewOptions): Promise<never>;
380
+ };
257
381
  };
258
382
  /**
259
383
  * Options for starting a child workflow
@@ -262,13 +386,13 @@ type TypedChildWorkflowOptions<TChildContract extends ContractDefinition, TChild
262
386
  args: ClientInferInput<TChildContract["workflows"][TChildWorkflowName]>;
263
387
  };
264
388
  /**
265
- * Typed handle for a child workflow with Future/Result pattern
389
+ * Typed handle for a child workflow with neverthrow ResultAsync pattern
266
390
  */
267
391
  type TypedChildWorkflowHandle<TWorkflow extends WorkflowDefinition> = {
268
392
  /**
269
393
  * Get child workflow result with Result pattern
270
394
  */
271
- result: () => Future<Result<ClientInferOutput<TWorkflow>, ChildWorkflowError>>;
395
+ result: () => ResultAsync<ClientInferOutput<TWorkflow>, ChildWorkflowError>;
272
396
  /**
273
397
  * Child workflow ID
274
398
  */
@@ -295,5 +419,5 @@ type WorkflowInferWorkflowActivities<T extends WorkflowDefinition> = T["activiti
295
419
  */
296
420
  type WorkflowInferWorkflowContextActivities<TContract extends ContractDefinition, TWorkflowName extends keyof TContract["workflows"]> = WorkflowInferWorkflowActivities<TContract["workflows"][TWorkflowName]> & WorkflowInferActivities<TContract>; //# sourceMappingURL=workflow.d.ts.map
297
421
  //#endregion
298
- export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
422
+ export { ActivityInputValidationError, ActivityOutputValidationError, ChildWorkflowError, ChildWorkflowNotFoundError, QueryInputValidationError, QueryOutputValidationError, SignalInputValidationError, UpdateInputValidationError, UpdateOutputValidationError, WorkflowCancelledError, WorkflowInputValidationError, WorkflowOutputValidationError, declareWorkflow };
299
423
  //# sourceMappingURL=workflow.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"workflow.d.mts","names":[],"sources":["../src/workflow.ts"],"mappings":";;;;;;AA2HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8aC;;;;;;;;;;;;;;;;;AAUkB;;;;;;;AAxbnB,iBAAgB,eAAA,mBACI,kBAAA,8BACU,SAAA,cAAA,CAAA;EAE5B,YAAA;EACA,QAAA;EACA,cAAA;EACA;AAAA,GACC,sBAAA,CAAuB,SAAA,EAAW,aAAA,QAChC,IAAA,gBACA,OAAA,CAAQ,iBAAA,CAAkB,SAAA,cAAuB,aAAA;;;;;;;KA4ajD,2BAAA,iBAA4C,gBAAA,KAC/C,IAAA,EAAM,gBAAA,CAAiB,OAAA,aACb,OAAA;;;;;AAUiB;;KAFxB,0BAAA,gBAA0C,eAAA,KAC7C,IAAA,EAAM,gBAAA,CAAiB,MAAA,MACpB,iBAAA,CAAkB,MAAA;;;;;;;KAQlB,2BAAA,iBAA4C,gBAAA,KAC/C,IAAA,EAAM,gBAAA,CAAiB,OAAA,MACpB,OAAA,CAAQ,iBAAA,CAAkB,OAAA;;;;KAK1B,sBAAA,mBACe,kBAAA,8BACU,SAAA;EAE5B,YAAA,EAAc,aAAA;EACd,QAAA,EAAU,SAAA;EACV,cAAA,EAAgB,sBAAA,CAAuB,SAAA,EAAW,aAAA;EAXvC;;;;AAAyB;;;;;;;;;;;;;EA6BpC,eAAA,EAAiB,eA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