@temporalio/workflow 0.22.0 → 1.0.0-rc.1
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 +2 -2
- package/lib/cancellation-scope.js +6 -2
- package/lib/cancellation-scope.js.map +1 -1
- package/lib/errors.js +9 -5
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +18 -12
- package/lib/index.js +16 -13
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +3 -1
- package/lib/interfaces.d.ts +129 -13
- package/lib/interfaces.js +44 -0
- package/lib/interfaces.js.map +1 -1
- package/lib/internals.d.ts +17 -2
- package/lib/internals.js +45 -12
- package/lib/internals.js.map +1 -1
- package/lib/sinks.d.ts +2 -1
- package/lib/stack-helpers.d.ts +4 -0
- package/lib/stack-helpers.js +15 -0
- package/lib/stack-helpers.js.map +1 -0
- package/lib/trigger.d.ts +5 -4
- package/lib/trigger.js +10 -7
- package/lib/trigger.js.map +1 -1
- package/lib/worker-interface.d.ts +5 -2
- package/lib/worker-interface.js +17 -11
- package/lib/worker-interface.js.map +1 -1
- package/lib/workflow-handle.d.ts +5 -2
- package/lib/workflow.d.ts +120 -42
- package/lib/workflow.js +164 -78
- package/lib/workflow.js.map +1 -1
- package/package.json +9 -7
- package/src/alea.ts +88 -0
- package/src/cancellation-scope.ts +205 -0
- package/src/errors.ts +30 -0
- package/src/index.ts +91 -0
- package/src/interceptors.ts +239 -0
- package/src/interfaces.ts +272 -0
- package/src/internals.ts +621 -0
- package/src/sinks.ts +41 -0
- package/src/stack-helpers.ts +11 -0
- package/src/trigger.ts +49 -0
- package/src/worker-interface.ts +283 -0
- package/src/workflow-handle.ts +63 -0
- package/src/workflow.ts +1265 -0
package/lib/workflow.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActivityFunction,
|
|
1
|
+
import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/internal-workflow-common';
|
|
2
2
|
import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, WorkflowInfo } from './interfaces';
|
|
3
3
|
import { Sinks } from './sinks';
|
|
4
4
|
import { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
|
|
@@ -11,19 +11,10 @@ export declare function addDefaultWorkflowOptions<T extends Workflow>(opts: With
|
|
|
11
11
|
*
|
|
12
12
|
* Schedules a timer on the Temporal service.
|
|
13
13
|
*
|
|
14
|
-
* @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds.
|
|
15
|
-
*
|
|
14
|
+
* @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds.
|
|
15
|
+
* If given a negative number or 0, value will be set to 1.
|
|
16
16
|
*/
|
|
17
17
|
export declare function sleep(ms: number | string): Promise<void>;
|
|
18
|
-
export interface ActivityInfo {
|
|
19
|
-
name: string;
|
|
20
|
-
type: string;
|
|
21
|
-
}
|
|
22
|
-
export declare type InternalActivityFunction<P extends any[], R> = ActivityFunction<P, R> & ActivityInfo;
|
|
23
|
-
/**
|
|
24
|
-
* @hidden
|
|
25
|
-
*/
|
|
26
|
-
export declare function validateActivityOptions(options: ActivityOptions): void;
|
|
27
18
|
/**
|
|
28
19
|
* Schedule an activity and run outbound interceptors
|
|
29
20
|
* @hidden
|
|
@@ -34,19 +25,52 @@ export declare function scheduleActivity<R>(activityType: string, args: any[], o
|
|
|
34
25
|
* @hidden
|
|
35
26
|
*/
|
|
36
27
|
export declare function scheduleLocalActivity<R>(activityType: string, args: any[], options: LocalActivityOptions): Promise<R>;
|
|
28
|
+
/**
|
|
29
|
+
* Symbol used in the return type of proxy methods to mark that an attribute on the source type is not a method.
|
|
30
|
+
*
|
|
31
|
+
* @see {@link ActivityInterfaceFor}
|
|
32
|
+
* @see {@link proxyActivities}
|
|
33
|
+
* @see {@link proxyLocalActivities}
|
|
34
|
+
*/
|
|
35
|
+
export declare const NotAnActivityMethod: unique symbol;
|
|
36
|
+
/**
|
|
37
|
+
* Type helper that takes a type `T` and transforms attributes that are not {@link ActivityFunction} to
|
|
38
|
+
* {@link NotAnActivityMethod}.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
*
|
|
42
|
+
* Used by {@link proxyActivities} to get this compile-time error:
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* interface MyActivities {
|
|
46
|
+
* valid(input: number): Promise<number>;
|
|
47
|
+
* invalid(input: number): number;
|
|
48
|
+
* }
|
|
49
|
+
*
|
|
50
|
+
* const act = proxyActivities<MyActivities>({ startToCloseTimeout: '5m' });
|
|
51
|
+
*
|
|
52
|
+
* await act.valid(true);
|
|
53
|
+
* await act.invalid();
|
|
54
|
+
* // ^ TS complains with:
|
|
55
|
+
* // (property) invalidDefinition: typeof NotAnActivityMethod
|
|
56
|
+
* // This expression is not callable.
|
|
57
|
+
* // Type 'Symbol' has no call signatures.(2349)
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
export declare type ActivityInterfaceFor<T> = {
|
|
61
|
+
[K in keyof T]: T[K] extends ActivityFunction ? T[K] : typeof NotAnActivityMethod;
|
|
62
|
+
};
|
|
37
63
|
/**
|
|
38
64
|
* Configure Activity functions with given {@link ActivityOptions}.
|
|
39
65
|
*
|
|
40
66
|
* This method may be called multiple times to setup Activities with different options.
|
|
41
67
|
*
|
|
42
|
-
* @return a
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* @typeparam A An {@link ActivityInterface} - mapping of name to function
|
|
68
|
+
* @return a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | Proxy} for
|
|
69
|
+
* which each attribute is a callable Activity function
|
|
46
70
|
*
|
|
47
71
|
* @example
|
|
48
72
|
* ```ts
|
|
49
|
-
* import { proxyActivities
|
|
73
|
+
* import { proxyActivities } from '@temporalio/workflow';
|
|
50
74
|
* import * as activities from '../activities';
|
|
51
75
|
*
|
|
52
76
|
* // Setup Activities from module exports
|
|
@@ -55,7 +79,7 @@ export declare function scheduleLocalActivity<R>(activityType: string, args: any
|
|
|
55
79
|
* });
|
|
56
80
|
*
|
|
57
81
|
* // Setup Activities from an explicit interface (e.g. when defined by another SDK)
|
|
58
|
-
* interface JavaActivities
|
|
82
|
+
* interface JavaActivities {
|
|
59
83
|
* httpGetFromJava(url: string): Promise<string>
|
|
60
84
|
* someOtherJavaActivity(arg1: number, arg2: string): Promise<string>;
|
|
61
85
|
* }
|
|
@@ -74,22 +98,20 @@ export declare function scheduleLocalActivity<R>(activityType: string, args: any
|
|
|
74
98
|
* }
|
|
75
99
|
* ```
|
|
76
100
|
*/
|
|
77
|
-
export declare function proxyActivities<A
|
|
101
|
+
export declare function proxyActivities<A = UntypedActivities>(options: ActivityOptions): ActivityInterfaceFor<A>;
|
|
78
102
|
/**
|
|
79
103
|
* Configure Local Activity functions with given {@link LocalActivityOptions}.
|
|
80
104
|
*
|
|
81
105
|
* This method may be called multiple times to setup Activities with different options.
|
|
82
106
|
*
|
|
83
|
-
* @return a
|
|
107
|
+
* @return a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | Proxy}
|
|
84
108
|
* for which each attribute is a callable Activity function
|
|
85
109
|
*
|
|
86
|
-
* @typeparam A An {@link ActivityInterface} - mapping of name to function
|
|
87
|
-
*
|
|
88
110
|
* @experimental
|
|
89
111
|
*
|
|
90
|
-
*
|
|
112
|
+
* @see {@link proxyActivities} for examples
|
|
91
113
|
*/
|
|
92
|
-
export declare function proxyLocalActivities<A
|
|
114
|
+
export declare function proxyLocalActivities<A = UntypedActivities>(options: LocalActivityOptions): ActivityInterfaceFor<A>;
|
|
93
115
|
/**
|
|
94
116
|
* Returns a client-side handle that can be used to signal and cancel an existing Workflow execution.
|
|
95
117
|
* It takes a Workflow ID and optional run ID.
|
|
@@ -182,7 +204,7 @@ export declare function executeChild<T extends () => WorkflowReturnType>(workflo
|
|
|
182
204
|
*
|
|
183
205
|
* @return The result of the child Workflow.
|
|
184
206
|
*/
|
|
185
|
-
export declare function executeChild<T extends () => WorkflowReturnType>(workflowFunc: T): Promise<
|
|
207
|
+
export declare function executeChild<T extends () => WorkflowReturnType>(workflowFunc: T): Promise<WorkflowResultType<T>>;
|
|
186
208
|
/**
|
|
187
209
|
* Get information about the current Workflow
|
|
188
210
|
*/
|
|
@@ -225,30 +247,27 @@ export declare function proxySinks<T extends Sinks>(): T;
|
|
|
225
247
|
/**
|
|
226
248
|
* Returns a function `f` that will cause the current Workflow to ContinueAsNew when called.
|
|
227
249
|
*
|
|
228
|
-
* `f` takes the same arguments as the Workflow
|
|
250
|
+
* `f` takes the same arguments as the Workflow function supplied to typeparam `F`.
|
|
229
251
|
*
|
|
230
|
-
* Once `f` is called, Workflow
|
|
252
|
+
* Once `f` is called, Workflow Execution immediately completes.
|
|
231
253
|
*/
|
|
232
254
|
export declare function makeContinueAsNewFunc<F extends Workflow>(options?: ContinueAsNewOptions): (...args: Parameters<F>) => Promise<never>;
|
|
233
255
|
/**
|
|
234
|
-
*
|
|
256
|
+
* {@link https://docs.temporal.io/concepts/what-is-continue-as-new/ | Continues-As-New} the current Workflow Execution
|
|
257
|
+
* with default options.
|
|
235
258
|
*
|
|
236
|
-
* Shorthand for `makeContinueAsNewFunc<F>()(...args)`.
|
|
259
|
+
* Shorthand for `makeContinueAsNewFunc<F>()(...args)`. (See: {@link makeContinueAsNewFunc}.)
|
|
237
260
|
*
|
|
238
261
|
* @example
|
|
239
262
|
*
|
|
240
|
-
|
|
241
|
-
*
|
|
263
|
+
*```ts
|
|
264
|
+
*import { continueAsNew } from '@temporalio/workflow';
|
|
242
265
|
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
|
|
248
|
-
* }
|
|
249
|
-
* };
|
|
250
|
-
* }
|
|
251
|
-
* ```
|
|
266
|
+
*export async function myWorkflow(n: number): Promise<void> {
|
|
267
|
+
* // ... Workflow logic
|
|
268
|
+
* await continueAsNew<typeof myWorkflow>(n + 1);
|
|
269
|
+
*}
|
|
270
|
+
*```
|
|
252
271
|
*/
|
|
253
272
|
export declare function continueAsNew<F extends Workflow>(...args: Parameters<F>): Promise<never>;
|
|
254
273
|
/**
|
|
@@ -261,7 +280,7 @@ export declare function uuid4(): string;
|
|
|
261
280
|
/**
|
|
262
281
|
* Patch or upgrade workflow code by checking or stating that this workflow has a certain patch.
|
|
263
282
|
*
|
|
264
|
-
* See
|
|
283
|
+
* See {@link https://docs.temporal.io/typescript/versioning | docs page} for info.
|
|
265
284
|
*
|
|
266
285
|
* If the workflow is replaying an existing history, then this function returns true if that
|
|
267
286
|
* history was produced by a worker which also had a `patched` call with the same `patchId`.
|
|
@@ -279,7 +298,7 @@ export declare function patched(patchId: string): boolean;
|
|
|
279
298
|
/**
|
|
280
299
|
* Indicate that a patch is being phased out.
|
|
281
300
|
*
|
|
282
|
-
* See
|
|
301
|
+
* See {@link https://docs.temporal.io/typescript/versioning | docs page} for info.
|
|
283
302
|
*
|
|
284
303
|
* Workflows with this call may be deployed alongside workflows with a {@link patched} call, but
|
|
285
304
|
* they must *not* be deployed while any workers still exist running old code without a
|
|
@@ -333,3 +352,62 @@ export declare type Handler<Ret, Args extends any[], T extends SignalDefinition<
|
|
|
333
352
|
* @param handler a compatible handler function for the given definition or `undefined` to unset the handler.
|
|
334
353
|
*/
|
|
335
354
|
export declare function setHandler<Ret, Args extends any[], T extends SignalDefinition<Args> | QueryDefinition<Ret, Args>>(def: T, handler: Handler<Ret, Args, T> | undefined): void;
|
|
355
|
+
/**
|
|
356
|
+
* Updates this Workflow's Search Attributes by merging the provided `searchAttributes` with the existing Search
|
|
357
|
+
* Attributes, `workflowInfo().searchAttributes`.
|
|
358
|
+
*
|
|
359
|
+
* For example, this Workflow code:
|
|
360
|
+
*
|
|
361
|
+
* ```ts
|
|
362
|
+
* upsertSearchAttributes({
|
|
363
|
+
* CustomIntField: [1, 2, 3],
|
|
364
|
+
* CustomBoolField: [true]
|
|
365
|
+
* });
|
|
366
|
+
* upsertSearchAttributes({
|
|
367
|
+
* CustomIntField: [42],
|
|
368
|
+
* CustomKeywordField: ['durable code', 'is great']
|
|
369
|
+
* });
|
|
370
|
+
* ```
|
|
371
|
+
*
|
|
372
|
+
* would result in the Workflow having these Search Attributes:
|
|
373
|
+
*
|
|
374
|
+
* ```ts
|
|
375
|
+
* {
|
|
376
|
+
* CustomIntField: [42],
|
|
377
|
+
* CustomBoolField: [true],
|
|
378
|
+
* CustomKeywordField: ['durable code', 'is great']
|
|
379
|
+
* }
|
|
380
|
+
* ```
|
|
381
|
+
*
|
|
382
|
+
* @param searchAttributes The Record to merge. Use a value of `[]` to clear a Search Attribute.
|
|
383
|
+
*/
|
|
384
|
+
export declare function upsertSearchAttributes(searchAttributes: SearchAttributes): void;
|
|
385
|
+
/**
|
|
386
|
+
* Unsafe information about the currently executing Workflow Task.
|
|
387
|
+
*
|
|
388
|
+
* Never rely on this information in Workflow logic as it will cause non-deterministic behavior.
|
|
389
|
+
*/
|
|
390
|
+
export interface UnsafeTaskInfo {
|
|
391
|
+
isReplaying: boolean;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Information about the currently executing Workflow Task.
|
|
395
|
+
*
|
|
396
|
+
* Meant for advanced usage.
|
|
397
|
+
*/
|
|
398
|
+
export interface TaskInfo {
|
|
399
|
+
/**
|
|
400
|
+
* Length of Workflow history up until the current Workflow Task.
|
|
401
|
+
*
|
|
402
|
+
* You may safely use this information to decide when to {@link continueAsNew}.
|
|
403
|
+
*/
|
|
404
|
+
historyLength: number;
|
|
405
|
+
unsafe: UnsafeTaskInfo;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Get information about the currently executing Workflow Task.
|
|
409
|
+
*
|
|
410
|
+
* See {@link TaskInfo}
|
|
411
|
+
*/
|
|
412
|
+
export declare function taskInfo(): TaskInfo;
|
|
413
|
+
export declare const stackTraceQuery: QueryDefinition<string, []>;
|