@temporalio/workflow 1.0.0-rc.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/lib/errors.js +9 -5
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +15 -9
- package/lib/index.js +14 -11
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +54 -5
- package/lib/interfaces.js +44 -0
- package/lib/interfaces.js.map +1 -1
- package/lib/sinks.d.ts +2 -1
- package/lib/workflow.d.ts +59 -36
- package/lib/workflow.js +29 -28
- package/lib/workflow.js.map +1 -1
- package/package.json +9 -8
- 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/errors.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isCancellation = exports.DeterminismViolationError = exports.WorkflowError = exports.WorkflowExecutionAlreadyStartedError = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "WorkflowExecutionAlreadyStartedError", { enumerable: true, get: function () { return common_2.WorkflowExecutionAlreadyStartedError; } });
|
|
4
|
+
var common_1 = require("@temporalio/common");
|
|
5
|
+
Object.defineProperty(exports, "WorkflowExecutionAlreadyStartedError", { enumerable: true, get: function () { return common_1.WorkflowExecutionAlreadyStartedError; } });
|
|
7
6
|
/**
|
|
8
7
|
* Base class for all workflow errors
|
|
9
8
|
*/
|
|
@@ -24,12 +23,17 @@ class DeterminismViolationError extends WorkflowError {
|
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
25
|
exports.DeterminismViolationError = DeterminismViolationError;
|
|
26
|
+
function looksLikeError(err) {
|
|
27
|
+
return typeof err === 'object' && err != null && Object.prototype.hasOwnProperty.call(err, 'name');
|
|
28
|
+
}
|
|
27
29
|
/**
|
|
28
30
|
* Returns whether provided `err` is caused by cancellation
|
|
29
31
|
*/
|
|
30
32
|
function isCancellation(err) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
if (!looksLikeError(err))
|
|
34
|
+
return false;
|
|
35
|
+
return (err.name === 'CancelledFailure' ||
|
|
36
|
+
((err.name === 'ActivityFailure' || err.name === 'ChildWorkflowFailure') && isCancellation(err.cause)));
|
|
33
37
|
}
|
|
34
38
|
exports.isCancellation = isCancellation;
|
|
35
39
|
//# sourceMappingURL=errors.js.map
|
package/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,6CAA0E;AAAjE,8HAAA,oCAAoC,OAAA;AAE7C;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAAxC;;QACkB,SAAI,GAAW,eAAe,CAAC;IACjD,CAAC;CAAA;AAFD,sCAEC;AAED;;GAEG;AACH,MAAa,yBAA0B,SAAQ,aAAa;IAA5D;;QACkB,SAAI,GAAW,2BAA2B,CAAC;IAC7D,CAAC;CAAA;AAFD,8DAEC;AAED,SAAS,cAAc,CAAC,GAAY;IAClC,OAAO,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAI,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AACrG,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC;QAAE,OAAO,KAAK,CAAC;IACvC,OAAO,CACL,GAAG,CAAC,IAAI,KAAK,kBAAkB;QAC/B,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,iBAAiB,IAAI,GAAG,CAAC,IAAI,KAAK,sBAAsB,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CACvG,CAAC;AACJ,CAAC;AAND,wCAMC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* This library provides tools required for authoring workflows.
|
|
3
3
|
*
|
|
4
4
|
* ## Usage
|
|
5
|
-
* See the
|
|
5
|
+
* See the {@link https://docs.temporal.io/typescript/hello-world#workflows | tutorial} for writing your first workflow.
|
|
6
6
|
*
|
|
7
7
|
* ### Timers
|
|
8
8
|
*
|
|
9
|
-
* The recommended way of scheduling timers is by using the {@link sleep} function.
|
|
10
|
-
*
|
|
9
|
+
* The recommended way of scheduling timers is by using the {@link sleep} function. We've replaced `setTimeout` and
|
|
10
|
+
* `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well
|
|
11
|
+
* with {@link https://docs.temporal.io/typescript/workflow-scopes-and-cancellation | cancellation scopes}.
|
|
11
12
|
*
|
|
12
13
|
* <!--SNIPSTART typescript-sleep-workflow-->
|
|
13
14
|
* <!--SNIPEND-->
|
|
@@ -21,11 +22,12 @@
|
|
|
21
22
|
*
|
|
22
23
|
* ### Signals and Queries
|
|
23
24
|
*
|
|
24
|
-
* To add signal handlers to a Workflow, add a signals property to the exported `workflow` object.
|
|
25
|
-
*
|
|
25
|
+
* To add signal handlers to a Workflow, add a signals property to the exported `workflow` object. Signal handlers can
|
|
26
|
+
* return either `void` or `Promise<void>`, you may schedule activities and timers from a signal handler.
|
|
26
27
|
*
|
|
27
|
-
* To add query handlers to a Workflow, add a queries property to the exported `workflow` object.
|
|
28
|
-
*
|
|
28
|
+
* To add query handlers to a Workflow, add a queries property to the exported `workflow` object. Query handlers must
|
|
29
|
+
* **not** mutate any variables or generate any commands (like Activities or Timers), they run synchronously and thus
|
|
30
|
+
* **must** return a `Promise`.
|
|
29
31
|
*
|
|
30
32
|
* #### Implementation
|
|
31
33
|
*
|
|
@@ -33,7 +35,8 @@
|
|
|
33
35
|
* <!--SNIPEND-->
|
|
34
36
|
*
|
|
35
37
|
* ### Deterministic built-ins
|
|
36
|
-
* It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We
|
|
38
|
+
* It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We
|
|
39
|
+
* also provide a deterministic {@link uuid4} function for convenience.
|
|
37
40
|
*
|
|
38
41
|
* ### [Cancellation and scopes](https://docs.temporal.io/typescript/workflow-scopes-and-cancellation)
|
|
39
42
|
* - {@link CancellationScope}
|
|
@@ -45,8 +48,11 @@
|
|
|
45
48
|
* @module
|
|
46
49
|
*/
|
|
47
50
|
export { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, defaultPayloadConverter, PayloadConverter, rootCause, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, } from '@temporalio/common';
|
|
48
|
-
export { ActivityCancellationType, ActivityFunction, ActivityInterface,
|
|
51
|
+
export { ActivityCancellationType, ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
|
|
52
|
+
ActivityOptions, RetryPolicy, UntypedActivities, } from '@temporalio/internal-workflow-common';
|
|
53
|
+
export * from '@temporalio/internal-workflow-common/lib/errors';
|
|
49
54
|
export * from '@temporalio/internal-workflow-common/lib/interfaces';
|
|
55
|
+
export * from '@temporalio/internal-workflow-common/lib/workflow-handle';
|
|
50
56
|
export * from '@temporalio/internal-workflow-common/lib/workflow-options';
|
|
51
57
|
export { AsyncLocalStorage, CancellationScope, CancellationScopeOptions, ROOT_SCOPE } from './cancellation-scope';
|
|
52
58
|
export * from './errors';
|
package/lib/index.js
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
* This library provides tools required for authoring workflows.
|
|
4
4
|
*
|
|
5
5
|
* ## Usage
|
|
6
|
-
* See the
|
|
6
|
+
* See the {@link https://docs.temporal.io/typescript/hello-world#workflows | tutorial} for writing your first workflow.
|
|
7
7
|
*
|
|
8
8
|
* ### Timers
|
|
9
9
|
*
|
|
10
|
-
* The recommended way of scheduling timers is by using the {@link sleep} function.
|
|
11
|
-
*
|
|
10
|
+
* The recommended way of scheduling timers is by using the {@link sleep} function. We've replaced `setTimeout` and
|
|
11
|
+
* `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well
|
|
12
|
+
* with {@link https://docs.temporal.io/typescript/workflow-scopes-and-cancellation | cancellation scopes}.
|
|
12
13
|
*
|
|
13
14
|
* <!--SNIPSTART typescript-sleep-workflow-->
|
|
14
15
|
* <!--SNIPEND-->
|
|
@@ -22,11 +23,12 @@
|
|
|
22
23
|
*
|
|
23
24
|
* ### Signals and Queries
|
|
24
25
|
*
|
|
25
|
-
* To add signal handlers to a Workflow, add a signals property to the exported `workflow` object.
|
|
26
|
-
*
|
|
26
|
+
* To add signal handlers to a Workflow, add a signals property to the exported `workflow` object. Signal handlers can
|
|
27
|
+
* return either `void` or `Promise<void>`, you may schedule activities and timers from a signal handler.
|
|
27
28
|
*
|
|
28
|
-
* To add query handlers to a Workflow, add a queries property to the exported `workflow` object.
|
|
29
|
-
*
|
|
29
|
+
* To add query handlers to a Workflow, add a queries property to the exported `workflow` object. Query handlers must
|
|
30
|
+
* **not** mutate any variables or generate any commands (like Activities or Timers), they run synchronously and thus
|
|
31
|
+
* **must** return a `Promise`.
|
|
30
32
|
*
|
|
31
33
|
* #### Implementation
|
|
32
34
|
*
|
|
@@ -34,7 +36,8 @@
|
|
|
34
36
|
* <!--SNIPEND-->
|
|
35
37
|
*
|
|
36
38
|
* ### Deterministic built-ins
|
|
37
|
-
* It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We
|
|
39
|
+
* It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We
|
|
40
|
+
* also provide a deterministic {@link uuid4} function for convenience.
|
|
38
41
|
*
|
|
39
42
|
* ### [Cancellation and scopes](https://docs.temporal.io/typescript/workflow-scopes-and-cancellation)
|
|
40
43
|
* - {@link CancellationScope}
|
|
@@ -60,7 +63,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
60
63
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
61
64
|
};
|
|
62
65
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
63
|
-
exports.Trigger = exports.ParentClosePolicy = exports.ContinueAsNew = exports.ChildWorkflowCancellationType = exports.ROOT_SCOPE = exports.CancellationScope = exports.AsyncLocalStorage = exports.
|
|
66
|
+
exports.Trigger = exports.ParentClosePolicy = exports.ContinueAsNew = exports.ChildWorkflowCancellationType = exports.ROOT_SCOPE = exports.CancellationScope = exports.AsyncLocalStorage = exports.ActivityCancellationType = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.rootCause = exports.defaultPayloadConverter = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = void 0;
|
|
64
67
|
var common_1 = require("@temporalio/common");
|
|
65
68
|
Object.defineProperty(exports, "ActivityFailure", { enumerable: true, get: function () { return common_1.ActivityFailure; } });
|
|
66
69
|
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
|
|
@@ -74,9 +77,9 @@ Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: fun
|
|
|
74
77
|
Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return common_1.TimeoutFailure; } });
|
|
75
78
|
var internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
76
79
|
Object.defineProperty(exports, "ActivityCancellationType", { enumerable: true, get: function () { return internal_workflow_common_1.ActivityCancellationType; } });
|
|
77
|
-
|
|
78
|
-
Object.defineProperty(exports, "ValueError", { enumerable: true, get: function () { return internal_workflow_common_1.ValueError; } });
|
|
80
|
+
__exportStar(require("@temporalio/internal-workflow-common/lib/errors"), exports);
|
|
79
81
|
__exportStar(require("@temporalio/internal-workflow-common/lib/interfaces"), exports);
|
|
82
|
+
__exportStar(require("@temporalio/internal-workflow-common/lib/workflow-handle"), exports);
|
|
80
83
|
__exportStar(require("@temporalio/internal-workflow-common/lib/workflow-options"), exports);
|
|
81
84
|
var cancellation_scope_1 = require("./cancellation-scope");
|
|
82
85
|
Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return cancellation_scope_1.AsyncLocalStorage; } });
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;;;;;;;;;;;;;;;;;AAEH,6CAY4B;AAX1B,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AACpB,iHAAA,uBAAuB,OAAA;AAEvB,mGAAA,SAAS,OAAA;AACT,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAEhB,iFAO8C;AAN5C,oIAAA,wBAAwB,OAAA;AAO1B,kFAAgE;AAChE,sFAAoE;AACpE,2FAAyE;AACzE,4FAA0E;AAC1E,2DAAkH;AAAzG,uHAAA,iBAAiB,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAA4B,gHAAA,UAAU,OAAA;AACnF,2CAAyB;AACzB,iDAA+B;AAC/B,2CAQsB;AAPpB,2HAAA,6BAA6B,OAAA;AAE7B,2GAAA,aAAa,OAAA;AAEb,+GAAA,iBAAiB,OAAA;AAKnB,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,6CAA2B"}
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export interface WorkflowInfo {
|
|
|
21
21
|
/**
|
|
22
22
|
* Indexed information attached to the Workflow Execution
|
|
23
23
|
*/
|
|
24
|
-
searchAttributes
|
|
24
|
+
searchAttributes: SearchAttributes;
|
|
25
25
|
/**
|
|
26
26
|
* Non-indexed information attached to the Workflow Execution
|
|
27
27
|
*/
|
|
@@ -136,16 +136,60 @@ export interface ContinueAsNewOptions {
|
|
|
136
136
|
*/
|
|
137
137
|
searchAttributes?: SearchAttributes;
|
|
138
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Specifies:
|
|
141
|
+
* - whether cancellation requests are sent to the Child
|
|
142
|
+
* - whether and when a {@link CanceledFailure} is thrown from {@link executeChild} or
|
|
143
|
+
* {@link ChildWorkflowHandle.result}
|
|
144
|
+
*
|
|
145
|
+
* @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
|
|
146
|
+
*/
|
|
139
147
|
export declare enum ChildWorkflowCancellationType {
|
|
148
|
+
/**
|
|
149
|
+
* Don't send a cancellation request to the Child.
|
|
150
|
+
*/
|
|
140
151
|
ABANDON = 0,
|
|
152
|
+
/**
|
|
153
|
+
* Send a cancellation request to the Child. Immediately throw the error.
|
|
154
|
+
*/
|
|
141
155
|
TRY_CANCEL = 1,
|
|
156
|
+
/**
|
|
157
|
+
* Send a cancellation request to the Child. The Child may respect cancellation, in which case an error will be thrown
|
|
158
|
+
* when cancellation has completed, and {@link isCancellation}(error) will be true. On the other hand, the Child may
|
|
159
|
+
* ignore the cancellation request, in which case an error might be thrown with a different cause, or the Child may
|
|
160
|
+
* complete successfully.
|
|
161
|
+
*
|
|
162
|
+
* @default
|
|
163
|
+
*/
|
|
142
164
|
WAIT_CANCELLATION_COMPLETED = 2,
|
|
165
|
+
/**
|
|
166
|
+
* Send a cancellation request to the Child. Throw the error once the Server receives the Child cancellation request.
|
|
167
|
+
*/
|
|
143
168
|
WAIT_CANCELLATION_REQUESTED = 3
|
|
144
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* How a Child Workflow reacts to the Parent Workflow reaching a Closed state.
|
|
172
|
+
*
|
|
173
|
+
* @see {@link https://docs.temporal.io/concepts/what-is-a-parent-close-policy/ | Parent Close Policy}
|
|
174
|
+
*/
|
|
145
175
|
export declare enum ParentClosePolicy {
|
|
176
|
+
/**
|
|
177
|
+
* If a `ParentClosePolicy` is set to this, or is not set at all, the server default value will be used.
|
|
178
|
+
*/
|
|
146
179
|
PARENT_CLOSE_POLICY_UNSPECIFIED = 0,
|
|
180
|
+
/**
|
|
181
|
+
* When the Parent is Closed, the Child is Terminated.
|
|
182
|
+
*
|
|
183
|
+
* @default
|
|
184
|
+
*/
|
|
147
185
|
PARENT_CLOSE_POLICY_TERMINATE = 1,
|
|
186
|
+
/**
|
|
187
|
+
* When the Parent is Closed, nothing is done to the Child.
|
|
188
|
+
*/
|
|
148
189
|
PARENT_CLOSE_POLICY_ABANDON = 2,
|
|
190
|
+
/**
|
|
191
|
+
* When the Parent is Closed, the Child is Cancelled.
|
|
192
|
+
*/
|
|
149
193
|
PARENT_CLOSE_POLICY_REQUEST_CANCEL = 3
|
|
150
194
|
}
|
|
151
195
|
export interface ChildWorkflowOptions extends CommonWorkflowOptions {
|
|
@@ -161,13 +205,18 @@ export interface ChildWorkflowOptions extends CommonWorkflowOptions {
|
|
|
161
205
|
*/
|
|
162
206
|
taskQueue?: string;
|
|
163
207
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* @
|
|
208
|
+
* Specifies:
|
|
209
|
+
* - whether cancellation requests are sent to the Child
|
|
210
|
+
* - whether and when an error is thrown from {@link executeChild} or
|
|
211
|
+
* {@link ChildWorkflowHandle.result}
|
|
212
|
+
*
|
|
213
|
+
* @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
|
|
167
214
|
*/
|
|
168
215
|
cancellationType?: ChildWorkflowCancellationType;
|
|
169
216
|
/**
|
|
170
|
-
* Specifies how
|
|
217
|
+
* Specifies how the Child reacts to the Parent Workflow reaching a Closed state.
|
|
218
|
+
*
|
|
219
|
+
* @default {@link ParentClosePolicy.PARENT_CLOSE_POLICY_TERMINATE}
|
|
171
220
|
*/
|
|
172
221
|
parentClosePolicy?: ParentClosePolicy;
|
|
173
222
|
}
|
package/lib/interfaces.js
CHANGED
|
@@ -13,19 +13,63 @@ class ContinueAsNew extends Error {
|
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.ContinueAsNew = ContinueAsNew;
|
|
16
|
+
/**
|
|
17
|
+
* Specifies:
|
|
18
|
+
* - whether cancellation requests are sent to the Child
|
|
19
|
+
* - whether and when a {@link CanceledFailure} is thrown from {@link executeChild} or
|
|
20
|
+
* {@link ChildWorkflowHandle.result}
|
|
21
|
+
*
|
|
22
|
+
* @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
|
|
23
|
+
*/
|
|
16
24
|
var ChildWorkflowCancellationType;
|
|
17
25
|
(function (ChildWorkflowCancellationType) {
|
|
26
|
+
/**
|
|
27
|
+
* Don't send a cancellation request to the Child.
|
|
28
|
+
*/
|
|
18
29
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["ABANDON"] = 0] = "ABANDON";
|
|
30
|
+
/**
|
|
31
|
+
* Send a cancellation request to the Child. Immediately throw the error.
|
|
32
|
+
*/
|
|
19
33
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["TRY_CANCEL"] = 1] = "TRY_CANCEL";
|
|
34
|
+
/**
|
|
35
|
+
* Send a cancellation request to the Child. The Child may respect cancellation, in which case an error will be thrown
|
|
36
|
+
* when cancellation has completed, and {@link isCancellation}(error) will be true. On the other hand, the Child may
|
|
37
|
+
* ignore the cancellation request, in which case an error might be thrown with a different cause, or the Child may
|
|
38
|
+
* complete successfully.
|
|
39
|
+
*
|
|
40
|
+
* @default
|
|
41
|
+
*/
|
|
20
42
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["WAIT_CANCELLATION_COMPLETED"] = 2] = "WAIT_CANCELLATION_COMPLETED";
|
|
43
|
+
/**
|
|
44
|
+
* Send a cancellation request to the Child. Throw the error once the Server receives the Child cancellation request.
|
|
45
|
+
*/
|
|
21
46
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["WAIT_CANCELLATION_REQUESTED"] = 3] = "WAIT_CANCELLATION_REQUESTED";
|
|
22
47
|
})(ChildWorkflowCancellationType = exports.ChildWorkflowCancellationType || (exports.ChildWorkflowCancellationType = {}));
|
|
23
48
|
(0, internal_workflow_common_1.checkExtends)();
|
|
49
|
+
/**
|
|
50
|
+
* How a Child Workflow reacts to the Parent Workflow reaching a Closed state.
|
|
51
|
+
*
|
|
52
|
+
* @see {@link https://docs.temporal.io/concepts/what-is-a-parent-close-policy/ | Parent Close Policy}
|
|
53
|
+
*/
|
|
24
54
|
var ParentClosePolicy;
|
|
25
55
|
(function (ParentClosePolicy) {
|
|
56
|
+
/**
|
|
57
|
+
* If a `ParentClosePolicy` is set to this, or is not set at all, the server default value will be used.
|
|
58
|
+
*/
|
|
26
59
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_UNSPECIFIED"] = 0] = "PARENT_CLOSE_POLICY_UNSPECIFIED";
|
|
60
|
+
/**
|
|
61
|
+
* When the Parent is Closed, the Child is Terminated.
|
|
62
|
+
*
|
|
63
|
+
* @default
|
|
64
|
+
*/
|
|
27
65
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_TERMINATE"] = 1] = "PARENT_CLOSE_POLICY_TERMINATE";
|
|
66
|
+
/**
|
|
67
|
+
* When the Parent is Closed, nothing is done to the Child.
|
|
68
|
+
*/
|
|
28
69
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_ABANDON"] = 2] = "PARENT_CLOSE_POLICY_ABANDON";
|
|
70
|
+
/**
|
|
71
|
+
* When the Parent is Closed, the Child is Cancelled.
|
|
72
|
+
*/
|
|
29
73
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_REQUEST_CANCEL"] = 3] = "PARENT_CLOSE_POLICY_REQUEST_CANCEL";
|
|
30
74
|
})(ParentClosePolicy = exports.ParentClosePolicy || (exports.ParentClosePolicy = {}));
|
|
31
75
|
(0, internal_workflow_common_1.checkExtends)();
|
package/lib/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AACA,mFAA6G;AA2H7G;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAGtC,YAA4B,OAAkE;QAC5F,KAAK,CAAC,2BAA2B,CAAC,CAAC;QADT,YAAO,GAAP,OAAO,CAA2D;QAF9E,SAAI,GAAG,eAAe,CAAC;IAIvC,CAAC;CACF;AAND,sCAMC;AAkCD,IAAY,
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AACA,mFAA6G;AA2H7G;;GAEG;AACH,MAAa,aAAc,SAAQ,KAAK;IAGtC,YAA4B,OAAkE;QAC5F,KAAK,CAAC,2BAA2B,CAAC,CAAC;QADT,YAAO,GAAP,OAAO,CAA2D;QAF9E,SAAI,GAAG,eAAe,CAAC;IAIvC,CAAC;CACF;AAND,sCAMC;AAkCD;;;;;;;GAOG;AACH,IAAY,6BAyBX;AAzBD,WAAY,6BAA6B;IACvC;;OAEG;IACH,uFAAW,CAAA;IAEX;;OAEG;IACH,6FAAc,CAAA;IAEd;;;;;;;OAOG;IACH,+HAA+B,CAAA;IAE/B;;OAEG;IACH,+HAA+B,CAAA;AACjC,CAAC,EAzBW,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QAyBxC;AAED,IAAA,uCAAY,GAAuF,CAAC;AAEpG;;;;GAIG;AACH,IAAY,iBAsBX;AAtBD,WAAY,iBAAiB;IAC3B;;OAEG;IACH,+GAAmC,CAAA;IAEnC;;;;OAIG;IACH,2GAAiC,CAAA;IAEjC;;OAEG;IACH,uGAA+B,CAAA;IAE/B;;OAEG;IACH,qHAAsC,CAAA;AACxC,CAAC,EAtBW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAsB5B;AAED,IAAA,uCAAY,GAA+D,CAAC"}
|
package/lib/sinks.d.ts
CHANGED
|
@@ -16,7 +16,8 @@
|
|
|
16
16
|
/**
|
|
17
17
|
* Any function signature can be used for Sink functions as long as the return type is `void`.
|
|
18
18
|
*
|
|
19
|
-
* When calling a Sink function, arguments are copied from the Workflow isolate to the Node.js environment using
|
|
19
|
+
* When calling a Sink function, arguments are copied from the Workflow isolate to the Node.js environment using
|
|
20
|
+
* {@link https://nodejs.org/api/worker_threads.html#worker_threads_port_postmessage_value_transferlist | postMessage}.
|
|
20
21
|
|
|
21
22
|
* This constrains the argument types to primitives (excluding Symbols).
|
|
22
23
|
*/
|
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';
|
|
@@ -15,11 +15,6 @@ export declare function addDefaultWorkflowOptions<T extends Workflow>(opts: With
|
|
|
15
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
18
|
/**
|
|
24
19
|
* Schedule an activity and run outbound interceptors
|
|
25
20
|
* @hidden
|
|
@@ -30,19 +25,52 @@ export declare function scheduleActivity<R>(activityType: string, args: any[], o
|
|
|
30
25
|
* @hidden
|
|
31
26
|
*/
|
|
32
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
|
+
};
|
|
33
63
|
/**
|
|
34
64
|
* Configure Activity functions with given {@link ActivityOptions}.
|
|
35
65
|
*
|
|
36
66
|
* This method may be called multiple times to setup Activities with different options.
|
|
37
67
|
*
|
|
38
|
-
* @return a
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* @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
|
|
42
70
|
*
|
|
43
71
|
* @example
|
|
44
72
|
* ```ts
|
|
45
|
-
* import { proxyActivities
|
|
73
|
+
* import { proxyActivities } from '@temporalio/workflow';
|
|
46
74
|
* import * as activities from '../activities';
|
|
47
75
|
*
|
|
48
76
|
* // Setup Activities from module exports
|
|
@@ -51,7 +79,7 @@ export declare function scheduleLocalActivity<R>(activityType: string, args: any
|
|
|
51
79
|
* });
|
|
52
80
|
*
|
|
53
81
|
* // Setup Activities from an explicit interface (e.g. when defined by another SDK)
|
|
54
|
-
* interface JavaActivities
|
|
82
|
+
* interface JavaActivities {
|
|
55
83
|
* httpGetFromJava(url: string): Promise<string>
|
|
56
84
|
* someOtherJavaActivity(arg1: number, arg2: string): Promise<string>;
|
|
57
85
|
* }
|
|
@@ -70,22 +98,20 @@ export declare function scheduleLocalActivity<R>(activityType: string, args: any
|
|
|
70
98
|
* }
|
|
71
99
|
* ```
|
|
72
100
|
*/
|
|
73
|
-
export declare function proxyActivities<A
|
|
101
|
+
export declare function proxyActivities<A = UntypedActivities>(options: ActivityOptions): ActivityInterfaceFor<A>;
|
|
74
102
|
/**
|
|
75
103
|
* Configure Local Activity functions with given {@link LocalActivityOptions}.
|
|
76
104
|
*
|
|
77
105
|
* This method may be called multiple times to setup Activities with different options.
|
|
78
106
|
*
|
|
79
|
-
* @return a
|
|
107
|
+
* @return a {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy | Proxy}
|
|
80
108
|
* for which each attribute is a callable Activity function
|
|
81
109
|
*
|
|
82
|
-
* @typeparam A An {@link ActivityInterface} - mapping of name to function
|
|
83
|
-
*
|
|
84
110
|
* @experimental
|
|
85
111
|
*
|
|
86
|
-
*
|
|
112
|
+
* @see {@link proxyActivities} for examples
|
|
87
113
|
*/
|
|
88
|
-
export declare function proxyLocalActivities<A
|
|
114
|
+
export declare function proxyLocalActivities<A = UntypedActivities>(options: LocalActivityOptions): ActivityInterfaceFor<A>;
|
|
89
115
|
/**
|
|
90
116
|
* Returns a client-side handle that can be used to signal and cancel an existing Workflow execution.
|
|
91
117
|
* It takes a Workflow ID and optional run ID.
|
|
@@ -178,7 +204,7 @@ export declare function executeChild<T extends () => WorkflowReturnType>(workflo
|
|
|
178
204
|
*
|
|
179
205
|
* @return The result of the child Workflow.
|
|
180
206
|
*/
|
|
181
|
-
export declare function executeChild<T extends () => WorkflowReturnType>(workflowFunc: T): Promise<
|
|
207
|
+
export declare function executeChild<T extends () => WorkflowReturnType>(workflowFunc: T): Promise<WorkflowResultType<T>>;
|
|
182
208
|
/**
|
|
183
209
|
* Get information about the current Workflow
|
|
184
210
|
*/
|
|
@@ -221,30 +247,27 @@ export declare function proxySinks<T extends Sinks>(): T;
|
|
|
221
247
|
/**
|
|
222
248
|
* Returns a function `f` that will cause the current Workflow to ContinueAsNew when called.
|
|
223
249
|
*
|
|
224
|
-
* `f` takes the same arguments as the Workflow
|
|
250
|
+
* `f` takes the same arguments as the Workflow function supplied to typeparam `F`.
|
|
225
251
|
*
|
|
226
|
-
* Once `f` is called, Workflow
|
|
252
|
+
* Once `f` is called, Workflow Execution immediately completes.
|
|
227
253
|
*/
|
|
228
254
|
export declare function makeContinueAsNewFunc<F extends Workflow>(options?: ContinueAsNewOptions): (...args: Parameters<F>) => Promise<never>;
|
|
229
255
|
/**
|
|
230
|
-
*
|
|
256
|
+
* {@link https://docs.temporal.io/concepts/what-is-continue-as-new/ | Continues-As-New} the current Workflow Execution
|
|
257
|
+
* with default options.
|
|
231
258
|
*
|
|
232
|
-
* Shorthand for `makeContinueAsNewFunc<F>()(...args)`.
|
|
259
|
+
* Shorthand for `makeContinueAsNewFunc<F>()(...args)`. (See: {@link makeContinueAsNewFunc}.)
|
|
233
260
|
*
|
|
234
261
|
* @example
|
|
235
262
|
*
|
|
236
|
-
|
|
237
|
-
*
|
|
263
|
+
*```ts
|
|
264
|
+
*import { continueAsNew } from '@temporalio/workflow';
|
|
238
265
|
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
|
|
244
|
-
* }
|
|
245
|
-
* };
|
|
246
|
-
* }
|
|
247
|
-
* ```
|
|
266
|
+
*export async function myWorkflow(n: number): Promise<void> {
|
|
267
|
+
* // ... Workflow logic
|
|
268
|
+
* await continueAsNew<typeof myWorkflow>(n + 1);
|
|
269
|
+
*}
|
|
270
|
+
*```
|
|
248
271
|
*/
|
|
249
272
|
export declare function continueAsNew<F extends Workflow>(...args: Parameters<F>): Promise<never>;
|
|
250
273
|
/**
|
|
@@ -257,7 +280,7 @@ export declare function uuid4(): string;
|
|
|
257
280
|
/**
|
|
258
281
|
* Patch or upgrade workflow code by checking or stating that this workflow has a certain patch.
|
|
259
282
|
*
|
|
260
|
-
* See
|
|
283
|
+
* See {@link https://docs.temporal.io/typescript/versioning | docs page} for info.
|
|
261
284
|
*
|
|
262
285
|
* If the workflow is replaying an existing history, then this function returns true if that
|
|
263
286
|
* history was produced by a worker which also had a `patched` call with the same `patchId`.
|
|
@@ -275,7 +298,7 @@ export declare function patched(patchId: string): boolean;
|
|
|
275
298
|
/**
|
|
276
299
|
* Indicate that a patch is being phased out.
|
|
277
300
|
*
|
|
278
|
-
* See
|
|
301
|
+
* See {@link https://docs.temporal.io/typescript/versioning | docs page} for info.
|
|
279
302
|
*
|
|
280
303
|
* Workflows with this call may be deployed alongside workflows with a {@link patched} call, but
|
|
281
304
|
* they must *not* be deployed while any workers still exist running old code without a
|