@temporalio/workflow 0.9.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Temporal Node.js SDK
1
+ Temporal TypeScript SDK
2
2
 
3
3
  MIT License
4
4
 
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  [![NPM](https://img.shields.io/npm/v/@temporalio/workflow?style=for-the-badge)](https://www.npmjs.com/package/@temporalio/workflow)
4
4
 
5
- Part of the [Temporal](https://temporal.io) [Node.js SDK](https://www.npmjs.com/package/temporalio).
5
+ Part of the [Temporal](https://temporal.io) [TypeScript SDK](https://www.npmjs.com/package/temporalio).
6
6
 
7
- See documentation on the [documentation site](https://docs.temporal.io/docs/node/introduction).
7
+ - See API reference [here](https://typescript.temporal.io/api/namespaces/workflow)
8
+ - See code samples [here](https://github.com/temporalio/samples-typescript)
9
+ - See full introduction on the [docs site](https://docs.temporal.io/docs/typescript/introduction)
@@ -112,6 +112,6 @@ export declare class RootCancellationScope extends CancellationScope {
112
112
  /** There can only be one of these */
113
113
  export declare const ROOT_SCOPE: RootCancellationScope;
114
114
  /** This function is here to avoid a circular dependency between this module and workflow.ts */
115
- declare let sleep: (_: number) => Promise<void>;
115
+ declare let sleep: (_: number | string) => Promise<void>;
116
116
  export declare function registerSleepImplementation(fn: typeof sleep): void;
117
117
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"cancellation-scope.js","sourceRoot":"","sources":["../src/cancellation-scope.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+CAAyE;AACzE,+DAA0D;AAE1D,8EAA8E;AAC9E,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;AAuBtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,iBAAiB;IA4B5B,YAAY,OAAkC;QAP9C,6CAAmB,KAAK,EAAC;QAQvB,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,OAAO,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClD,CAAC;IAED,+EAA+E;IAC/E,MAAM,CAAC,WAAW,CAAI,OAAe,EAAE,EAAoB;QACzD,OAAO,IAAI,IAAI,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AA1GD,8CA0GC;;AAED,MAAM,OAAO,GAAG,IAAI,uCAAiB,EAAqB,CAAC;AAE3D,MAAa,qBAAsB,SAAQ,iBAAiB;IAC1D,MAAM;QACJ,IAAI,CAAC,MAAM,CAAC,IAAI,yBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;IAC1D,CAAC;CACF;AAJD,sDAIC;AAED,qCAAqC;AACxB,QAAA,UAAU,GAAG,IAAI,qBAAqB,CAAC,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;AAE9F,+FAA+F;AAC/F,IAAI,KAAK,GAAG,CAAC,CAAkB,EAAiB,EAAE;IAChD,MAAM,IAAI,0BAAiB,CAAC,4CAA4C,CAAC,CAAC;AAC5E,CAAC,CAAC;AAEF,SAAgB,2BAA2B,CAAC,EAAgB;IAC1D,KAAK,GAAG,EAAE,CAAC;AACb,CAAC;AAFD,kEAEC"}
@@ -2,21 +2,20 @@
2
2
  * Type definitions for the Workflow end of the external dependencies mechanism.
3
3
  *
4
4
  * External dependencies are functions injected into a Workflow isolate from the main Node.js isolate.
5
- * They are an advanced feature and should be used with care.
6
5
  *
7
- * @see proposal at https://github.com/temporalio/proposals/blob/master/node/logging-and-metrics-for-user-code.md
6
+ * Dependency functions may not return values to the Workflow in order to prevent breaking determinism.
7
+ *
8
+ * @experimental
8
9
  *
9
10
  * @module
10
11
  */
11
12
  /**
12
- * Any function signature can be used for dependency functions.
13
+ * Any function signature can be used for dependency functions as long as the return type is `void`.
13
14
  *
14
- * Depending on the implementation's and transfer options,
15
- * when calling a dependency function, arguments and return value are transferred between the Workflow isolate and the Node.js isolate.
16
- * - `SYNC*` {@link ApplyMode} variants allow configuring how those are transferred between isolates
17
- * - `ASYNC*` {@link ApplyMode} variants always copy the arguments and return value
15
+ * When calling a dependency function, arguments and return value are copied between the Workflow isolate and the Node.js.
16
+ * This constrains the argument types to primitives (excluding Symbols).
18
17
  */
19
- export declare type ExternalDependencyFunction = (...args: any[]) => any;
18
+ export declare type ExternalDependencyFunction = (...args: any[]) => void;
20
19
  /** A mapping of name to function, defines a single external dependency (e.g. logger) */
21
20
  export declare type ExternalDependency = Record<string, ExternalDependencyFunction>;
22
21
  /**
@@ -24,57 +23,10 @@ export declare type ExternalDependency = Record<string, ExternalDependencyFuncti
24
23
  */
25
24
  export declare type ExternalDependencies = Record<string, ExternalDependency>;
26
25
  /**
27
- * Controls how an external dependency function is executed.
28
- * - `ASYNC*` variants run at the end of an activation and do **not** block the isolate.
29
- * - `SYNC*` variants run during Workflow activation and block the isolate,
30
- * they're passed into the isolate using an {@link https://github.com/laverdet/isolated-vm#referenceapplyreceiver-arguments-options-promise | isolated-vm Reference}
31
- *
32
- * The Worker will log if an error occurs in one of ignored variants.
33
- *
34
- * **NOTE: External dependencies are an advanced feature and should be used with caution**
35
- * - Do not return anything that can break Workflow execution determinism
36
- * - Synchronous variants should be used as a last resort and their execution time should be kept short to free up the Workflow thread
37
- */
38
- export declare enum ApplyMode {
39
- /**
40
- * Injected function will be called at the end of an activation.
41
- * Isolate enqueues function to be called during activation and registers a callback to await its completion.
42
- * Use if exposing an async function to the isolate for which the result should be returned to the isolate.
43
- */
44
- ASYNC = "async",
45
- /**
46
- * Injected function will be called at the end of an activation.
47
- * Isolate enqueues function to be called during activation and does **not** register a callback to await its completion.
48
- * This is the safest async `ApplyMode` because it can not break Workflow code determinism.
49
- * Can only be used when the injected function returns `void` and the implementation returns `void` or `Promise<void>`.
50
- */
51
- ASYNC_IGNORED = "asyncIgnored",
52
- /**
53
- * Injected function is called synchronously, implementation must be a synchronous function.
54
- * Injection is done using an `isolated-vm` reference, function is called with `applySync`.
55
- */
56
- SYNC = "applySync",
57
- /**
58
- * Injected function is called synchronously, implementation must return a promise.
59
- * Injection is done using an `isolated-vm` reference, function is called with `applySyncPromise`.
60
- */
61
- SYNC_PROMISE = "applySyncPromise",
62
- /**
63
- * Injected function is called in the background not blocking the isolate.
64
- * Implementation can be either synchronous or asynchronous.
65
- * Injection is done using an `isolated-vm` reference, function is called with `applyIgnored`.
66
- *
67
- * This is the safest sync `ApplyMode` because it can not break Workflow code determinism.
68
- */
69
- SYNC_IGNORED = "applyIgnored"
70
- }
71
- /**
72
- * Call information for async external dependencies
26
+ * Call information for external dependencies
73
27
  */
74
28
  export interface ExternalCall {
75
29
  ifaceName: string;
76
30
  fnName: string;
77
31
  args: any[];
78
- /** Optional in case applyMode is ASYNC_IGNORED */
79
- seq?: number;
80
32
  }
@@ -3,58 +3,12 @@
3
3
  * Type definitions for the Workflow end of the external dependencies mechanism.
4
4
  *
5
5
  * External dependencies are functions injected into a Workflow isolate from the main Node.js isolate.
6
- * They are an advanced feature and should be used with care.
7
6
  *
8
- * @see proposal at https://github.com/temporalio/proposals/blob/master/node/logging-and-metrics-for-user-code.md
7
+ * Dependency functions may not return values to the Workflow in order to prevent breaking determinism.
8
+ *
9
+ * @experimental
9
10
  *
10
11
  * @module
11
12
  */
12
13
  Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.ApplyMode = void 0;
14
- /**
15
- * Controls how an external dependency function is executed.
16
- * - `ASYNC*` variants run at the end of an activation and do **not** block the isolate.
17
- * - `SYNC*` variants run during Workflow activation and block the isolate,
18
- * they're passed into the isolate using an {@link https://github.com/laverdet/isolated-vm#referenceapplyreceiver-arguments-options-promise | isolated-vm Reference}
19
- *
20
- * The Worker will log if an error occurs in one of ignored variants.
21
- *
22
- * **NOTE: External dependencies are an advanced feature and should be used with caution**
23
- * - Do not return anything that can break Workflow execution determinism
24
- * - Synchronous variants should be used as a last resort and their execution time should be kept short to free up the Workflow thread
25
- */
26
- var ApplyMode;
27
- (function (ApplyMode) {
28
- /**
29
- * Injected function will be called at the end of an activation.
30
- * Isolate enqueues function to be called during activation and registers a callback to await its completion.
31
- * Use if exposing an async function to the isolate for which the result should be returned to the isolate.
32
- */
33
- ApplyMode["ASYNC"] = "async";
34
- /**
35
- * Injected function will be called at the end of an activation.
36
- * Isolate enqueues function to be called during activation and does **not** register a callback to await its completion.
37
- * This is the safest async `ApplyMode` because it can not break Workflow code determinism.
38
- * Can only be used when the injected function returns `void` and the implementation returns `void` or `Promise<void>`.
39
- */
40
- ApplyMode["ASYNC_IGNORED"] = "asyncIgnored";
41
- /**
42
- * Injected function is called synchronously, implementation must be a synchronous function.
43
- * Injection is done using an `isolated-vm` reference, function is called with `applySync`.
44
- */
45
- ApplyMode["SYNC"] = "applySync";
46
- /**
47
- * Injected function is called synchronously, implementation must return a promise.
48
- * Injection is done using an `isolated-vm` reference, function is called with `applySyncPromise`.
49
- */
50
- ApplyMode["SYNC_PROMISE"] = "applySyncPromise";
51
- /**
52
- * Injected function is called in the background not blocking the isolate.
53
- * Implementation can be either synchronous or asynchronous.
54
- * Injection is done using an `isolated-vm` reference, function is called with `applyIgnored`.
55
- *
56
- * This is the safest sync `ApplyMode` because it can not break Workflow code determinism.
57
- */
58
- ApplyMode["SYNC_IGNORED"] = "applyIgnored";
59
- })(ApplyMode = exports.ApplyMode || (exports.ApplyMode = {}));
60
14
  //# sourceMappingURL=dependencies.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;AAkBH;;;;;;;;;;;GAWG;AACH,IAAY,SAgCX;AAhCD,WAAY,SAAS;IACnB;;;;OAIG;IACH,4BAAe,CAAA;IACf;;;;;OAKG;IACH,2CAA8B,CAAA;IAC9B;;;OAGG;IACH,+BAAkB,CAAA;IAClB;;;OAGG;IACH,8CAAiC,CAAA;IACjC;;;;;;OAMG;IACH,0CAA6B,CAAA;AAC/B,CAAC,EAhCW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAgCpB"}
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../src/dependencies.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG"}
package/lib/index.d.ts CHANGED
@@ -2,21 +2,21 @@
2
2
  * This library provides tools required for authoring workflows.
3
3
  *
4
4
  * ## Usage
5
- * See the [tutorial](https://docs.temporal.io/docs/node/hello-world#workflows) for writing your first workflow.
5
+ * See the [tutorial](https://docs.temporal.io/docs/typescript/hello-world#workflows) for writing your first workflow.
6
6
  *
7
7
  * ### Timers
8
8
  *
9
9
  * The recommended way of scheduling timers is by using the {@link sleep} function.
10
- * We've replaced `setTimeout` and `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well with [cancellation scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation).
10
+ * We've replaced `setTimeout` and `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well with [cancellation scopes](https://docs.temporal.io/docs/typescript/workflow-scopes-and-cancellation).
11
11
  *
12
- * <!--SNIPSTART nodejs-sleep-workflow-->
12
+ * <!--SNIPSTART typescript-sleep-workflow-->
13
13
  * <!--SNIPEND-->
14
14
  *
15
15
  * ### Activities
16
16
  *
17
17
  * To schedule Activities, use {@link createActivityHandle} to obtain an Activity function and call.
18
18
  *
19
- * <!--SNIPSTART nodejs-schedule-activity-workflow-->
19
+ * <!--SNIPSTART typescript-schedule-activity-workflow-->
20
20
  * <!--SNIPEND-->
21
21
  *
22
22
  * ### Signals and Queries
@@ -29,34 +29,34 @@
29
29
  *
30
30
  * #### Interface
31
31
  *
32
- * <!--SNIPSTART nodejs-workflow-signal-interface-->
32
+ * <!--SNIPSTART typescript-workflow-signal-interface-->
33
33
  * <!--SNIPEND-->
34
34
  *
35
35
  * #### Implementation
36
36
  *
37
- * <!--SNIPSTART nodejs-workflow-signal-implementation-->
37
+ * <!--SNIPSTART typescript-workflow-signal-implementation-->
38
38
  * <!--SNIPEND-->
39
39
  *
40
40
  * ### Deterministic built-ins
41
41
  * It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We also provide a deterministic {@link uuid4} function for convenience.
42
42
  *
43
- * ### [Cancellation and scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation)
43
+ * ### [Cancellation and scopes](https://docs.temporal.io/docs/typescript/workflow-scopes-and-cancellation)
44
44
  * - {@link CancellationScope}
45
45
  * - {@link Trigger}
46
46
  *
47
- * ### [External dependencies](https://docs.temporal.io/docs/node/workflow-external-dependencies)
47
+ * ### [External dependencies](https://docs.temporal.io/docs/typescript/workflow-external-dependencies)
48
48
  * - {@link ExternalDependencies}
49
49
  * - {@link ApplyMode}
50
50
  *
51
51
  * @module
52
52
  */
53
- export { Workflow, WorkflowHandlers, WorkflowResultType, ActivityCancellationType, ActivityFunction, ActivityInterface, ActivityOptions, RetryOptions, rootCause, IllegalStateError, defaultDataConverter, DataConverter, WorkflowIdReusePolicy, ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, } from '@temporalio/common';
54
- export { ChildWorkflowOptions, ChildWorkflowCancellationType, WorkflowInfo } from './interfaces';
53
+ export { Workflow, WorkflowResultType, ActivityCancellationType, ActivityFunction, ActivityInterface, ActivityOptions, RetryOptions, rootCause, IllegalStateError, defaultDataConverter, DataConverter, WorkflowIdReusePolicy, ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, ValueError, } from '@temporalio/common';
54
+ export { ChildWorkflowOptions, ChildWorkflowCancellationType, ContinueAsNewOptions, ParentClosePolicy, WorkflowInfo, } from './interfaces';
55
55
  export * from './errors';
56
56
  export * from './workflow';
57
57
  export * from './interceptors';
58
- export { AsyncLocalStorage } from './async-local-storage';
59
58
  export { ROOT_SCOPE, CancellationScope, CancellationScopeOptions } from './cancellation-scope';
60
59
  export { Trigger } from './trigger';
61
- export { ApplyMode, ExternalCall, ExternalDependencyFunction, ExternalDependency, ExternalDependencies, } from './dependencies';
60
+ export { ExternalDependencyFunction, ExternalDependency, ExternalDependencies, ExternalCall } from './dependencies';
62
61
  export { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
62
+ export { AsyncLocalStorage } from './async-local-storage';
package/lib/index.js CHANGED
@@ -3,21 +3,21 @@
3
3
  * This library provides tools required for authoring workflows.
4
4
  *
5
5
  * ## Usage
6
- * See the [tutorial](https://docs.temporal.io/docs/node/hello-world#workflows) for writing your first workflow.
6
+ * See the [tutorial](https://docs.temporal.io/docs/typescript/hello-world#workflows) for writing your first workflow.
7
7
  *
8
8
  * ### Timers
9
9
  *
10
10
  * The recommended way of scheduling timers is by using the {@link sleep} function.
11
- * We've replaced `setTimeout` and `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well with [cancellation scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation).
11
+ * We've replaced `setTimeout` and `clearTimeout` with deterministic versions so these are also usable but have a limitation that they don't play well with [cancellation scopes](https://docs.temporal.io/docs/typescript/workflow-scopes-and-cancellation).
12
12
  *
13
- * <!--SNIPSTART nodejs-sleep-workflow-->
13
+ * <!--SNIPSTART typescript-sleep-workflow-->
14
14
  * <!--SNIPEND-->
15
15
  *
16
16
  * ### Activities
17
17
  *
18
18
  * To schedule Activities, use {@link createActivityHandle} to obtain an Activity function and call.
19
19
  *
20
- * <!--SNIPSTART nodejs-schedule-activity-workflow-->
20
+ * <!--SNIPSTART typescript-schedule-activity-workflow-->
21
21
  * <!--SNIPEND-->
22
22
  *
23
23
  * ### Signals and Queries
@@ -30,22 +30,22 @@
30
30
  *
31
31
  * #### Interface
32
32
  *
33
- * <!--SNIPSTART nodejs-workflow-signal-interface-->
33
+ * <!--SNIPSTART typescript-workflow-signal-interface-->
34
34
  * <!--SNIPEND-->
35
35
  *
36
36
  * #### Implementation
37
37
  *
38
- * <!--SNIPSTART nodejs-workflow-signal-implementation-->
38
+ * <!--SNIPSTART typescript-workflow-signal-implementation-->
39
39
  * <!--SNIPEND-->
40
40
  *
41
41
  * ### Deterministic built-ins
42
42
  * It is safe to call `Math.random()` and `Date()` in workflow code as they are replaced with deterministic versions. We also provide a deterministic {@link uuid4} function for convenience.
43
43
  *
44
- * ### [Cancellation and scopes](https://docs.temporal.io/docs/node/workflow-scopes-and-cancellation)
44
+ * ### [Cancellation and scopes](https://docs.temporal.io/docs/typescript/workflow-scopes-and-cancellation)
45
45
  * - {@link CancellationScope}
46
46
  * - {@link Trigger}
47
47
  *
48
- * ### [External dependencies](https://docs.temporal.io/docs/node/workflow-external-dependencies)
48
+ * ### [External dependencies](https://docs.temporal.io/docs/typescript/workflow-external-dependencies)
49
49
  * - {@link ExternalDependencies}
50
50
  * - {@link ApplyMode}
51
51
  *
@@ -62,7 +62,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
62
62
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
63
63
  };
64
64
  Object.defineProperty(exports, "__esModule", { value: true });
65
- exports.ApplyMode = exports.Trigger = exports.CancellationScope = exports.ROOT_SCOPE = exports.AsyncLocalStorage = exports.ChildWorkflowCancellationType = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = exports.WorkflowIdReusePolicy = exports.defaultDataConverter = exports.IllegalStateError = exports.rootCause = exports.ActivityCancellationType = void 0;
65
+ exports.AsyncLocalStorage = exports.Trigger = exports.CancellationScope = exports.ROOT_SCOPE = exports.ParentClosePolicy = exports.ChildWorkflowCancellationType = exports.ValueError = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = exports.WorkflowIdReusePolicy = exports.defaultDataConverter = exports.IllegalStateError = exports.rootCause = exports.ActivityCancellationType = void 0;
66
66
  var common_1 = require("@temporalio/common");
67
67
  Object.defineProperty(exports, "ActivityCancellationType", { enumerable: true, get: function () { return common_1.ActivityCancellationType; } });
68
68
  Object.defineProperty(exports, "rootCause", { enumerable: true, get: function () { return common_1.rootCause; } });
@@ -77,18 +77,18 @@ Object.defineProperty(exports, "ServerFailure", { enumerable: true, get: functio
77
77
  Object.defineProperty(exports, "TemporalFailure", { enumerable: true, get: function () { return common_1.TemporalFailure; } });
78
78
  Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: function () { return common_1.TerminatedFailure; } });
79
79
  Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return common_1.TimeoutFailure; } });
80
+ Object.defineProperty(exports, "ValueError", { enumerable: true, get: function () { return common_1.ValueError; } });
80
81
  var interfaces_1 = require("./interfaces");
81
82
  Object.defineProperty(exports, "ChildWorkflowCancellationType", { enumerable: true, get: function () { return interfaces_1.ChildWorkflowCancellationType; } });
83
+ Object.defineProperty(exports, "ParentClosePolicy", { enumerable: true, get: function () { return interfaces_1.ParentClosePolicy; } });
82
84
  __exportStar(require("./errors"), exports);
83
85
  __exportStar(require("./workflow"), exports);
84
86
  __exportStar(require("./interceptors"), exports);
85
- var async_local_storage_1 = require("./async-local-storage");
86
- Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return async_local_storage_1.AsyncLocalStorage; } });
87
87
  var cancellation_scope_1 = require("./cancellation-scope");
88
88
  Object.defineProperty(exports, "ROOT_SCOPE", { enumerable: true, get: function () { return cancellation_scope_1.ROOT_SCOPE; } });
89
89
  Object.defineProperty(exports, "CancellationScope", { enumerable: true, get: function () { return cancellation_scope_1.CancellationScope; } });
90
90
  var trigger_1 = require("./trigger");
91
91
  Object.defineProperty(exports, "Trigger", { enumerable: true, get: function () { return trigger_1.Trigger; } });
92
- var dependencies_1 = require("./dependencies");
93
- Object.defineProperty(exports, "ApplyMode", { enumerable: true, get: function () { return dependencies_1.ApplyMode; } });
92
+ var async_local_storage_1 = require("./async-local-storage");
93
+ Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return async_local_storage_1.AsyncLocalStorage; } });
94
94
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;;;;;;;;;;;;;AAEH,6CAsB4B;AAlB1B,kHAAA,wBAAwB,OAAA;AAKxB,mGAAA,SAAS,OAAA;AACT,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AAEpB,+GAAA,qBAAqB,OAAA;AACrB,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AACpB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAEhB,2CAAiG;AAAlE,2HAAA,6BAA6B,OAAA;AAC5D,2CAAyB;AACzB,6CAA2B;AAC3B,iDAA+B;AAC/B,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA;AAC1B,2DAA+F;AAAtF,gHAAA,UAAU,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AACtC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,+CAMwB;AALtB,yGAAA,SAAS,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;;;;;;;;;;;;;AAEH,6CAsB4B;AAnB1B,kHAAA,wBAAwB,OAAA;AAKxB,mGAAA,SAAS,OAAA;AACT,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AAEpB,+GAAA,qBAAqB,OAAA;AACrB,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AACpB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AACd,oGAAA,UAAU,OAAA;AAEZ,2CAMsB;AAJpB,2HAAA,6BAA6B,OAAA;AAE7B,+GAAA,iBAAiB,OAAA;AAGnB,2CAAyB;AACzB,6CAA2B;AAC3B,iDAA+B;AAC/B,2DAA+F;AAAtF,gHAAA,UAAU,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AACtC,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAGhB,6DAA0D;AAAjD,wHAAA,iBAAiB,OAAA"}
@@ -5,9 +5,9 @@
5
5
  *
6
6
  * @module
7
7
  */
8
- import { ActivityOptions, WorkflowExecution, Headers, Next, WorkflowHandlers } from '@temporalio/common';
8
+ import { ActivityOptions, WorkflowExecution, Headers, Next } from '@temporalio/common';
9
9
  import { coresdk } from '@temporalio/proto/lib/coresdk';
10
- import { ChildWorkflowOptions, ContinueAsNewOptions } from './interfaces';
10
+ import { ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions } from './interfaces';
11
11
  export { Next, Headers };
12
12
  /** Input for WorkflowInboundCallsInterceptor.create */
13
13
  export interface WorkflowCreateInput {
@@ -34,12 +34,6 @@ export interface QueryInput {
34
34
  * Implement any of these methods to intercept Workflow inbound calls like execution, and signal and query handling.
35
35
  */
36
36
  export interface WorkflowInboundCallsInterceptor {
37
- /**
38
- * Called when Workflow is created from a factory function
39
- *
40
- * @return the Workflow handlers
41
- */
42
- create?: (input: WorkflowCreateInput, next: Next<this, 'create'>) => Promise<WorkflowHandlers>;
43
37
  /**
44
38
  * Called when Workflow execute method is called
45
39
  *
@@ -66,8 +60,7 @@ export interface ActivityInput {
66
60
  /** Input for WorkflowOutboundCallsInterceptor.startChildWorkflowExecution */
67
61
  export interface StartChildWorkflowExecutionInput {
68
62
  readonly workflowType: string;
69
- readonly args: unknown[];
70
- readonly options: ChildWorkflowOptions;
63
+ readonly options: ChildWorkflowOptionsWithDefaults;
71
64
  readonly headers: Headers;
72
65
  readonly seq: number;
73
66
  }
@@ -76,11 +69,15 @@ export interface TimerInput {
76
69
  readonly durationMs: number;
77
70
  readonly seq: number;
78
71
  }
72
+ /**
73
+ * Same as ContinueAsNewOptions but workflowType must be defined
74
+ */
75
+ export declare type ContinueAsNewInputOptions = ContinueAsNewOptions & Required<Pick<ContinueAsNewOptions, 'workflowType'>>;
79
76
  /** Input for WorkflowOutboundCallsInterceptor.continueAsNew */
80
77
  export interface ContinueAsNewInput {
81
78
  args: unknown[];
82
79
  headers: Headers;
83
- options: ContinueAsNewOptions;
80
+ options: ContinueAsNewInputOptions;
84
81
  }
85
82
  /** Input for WorkflowOutboundCallsInterceptor.signalWorkflow */
86
83
  export interface SignalWorkflowInput {
@@ -85,5 +85,7 @@ export interface ChildWorkflowOptions extends WorkflowOptions {
85
85
  */
86
86
  parentClosePolicy?: ParentClosePolicy;
87
87
  }
88
- export declare type RequiredChildWorkflowOptions = Required<Pick<ChildWorkflowOptions, 'workflowId' | 'workflowIdReusePolicy' | 'cancellationType' | 'taskQueue'>>;
88
+ export declare type RequiredChildWorkflowOptions = Required<Pick<ChildWorkflowOptions, 'workflowId' | 'cancellationType'>> & {
89
+ args: unknown[];
90
+ };
89
91
  export declare type ChildWorkflowOptionsWithDefaults = ChildWorkflowOptions & RequiredChildWorkflowOptions;
@@ -1,30 +1,35 @@
1
- import { WorkflowSignalType, DataConverter, WorkflowHandlers } from '@temporalio/common';
1
+ import { WorkflowSignalType, DataConverter, Workflow, WorkflowQueryType } from '@temporalio/common';
2
2
  import { coresdk } from '@temporalio/proto/lib/coresdk';
3
3
  import { RNG } from './alea';
4
4
  import { WorkflowInfo } from './interfaces';
5
- import { QueryInput, SignalInput, WorkflowInterceptors } from './interceptors';
6
- import { ExternalCall, ExternalDependencies } from './dependencies';
5
+ import { QueryInput, SignalInput, WorkflowExecuteInput, WorkflowInterceptors } from './interceptors';
6
+ import { ExternalCall } from './dependencies';
7
7
  export declare type ResolveFunction<T = any> = (val: T) => any;
8
8
  export declare type RejectFunction<E = any> = (val: E) => any;
9
9
  export interface Completion {
10
10
  resolve: ResolveFunction;
11
11
  reject: RejectFunction;
12
12
  }
13
+ export interface Condition {
14
+ fn(): boolean;
15
+ resolve(): void;
16
+ }
13
17
  export declare type ActivationHandlerFunction<K extends keyof coresdk.workflow_activation.IWFActivationJob> = (activation: NonNullable<coresdk.workflow_activation.IWFActivationJob[K]>) => Promise<void> | void;
14
18
  export declare type ActivationHandler = {
15
19
  [P in keyof coresdk.workflow_activation.IWFActivationJob]: ActivationHandlerFunction<P>;
16
20
  };
17
21
  export declare class Activator implements ActivationHandler {
18
- startWorkflowNextHandler(): Promise<any>;
22
+ workflowFunctionWasCalled: boolean;
23
+ startWorkflowNextHandler({ args }: WorkflowExecuteInput): Promise<any>;
19
24
  startWorkflow(activation: coresdk.workflow_activation.IStartWorkflow): void;
20
25
  cancelWorkflow(_activation: coresdk.workflow_activation.ICancelWorkflow): void;
21
26
  fireTimer(activation: coresdk.workflow_activation.IFireTimer): void;
22
27
  resolveActivity(activation: coresdk.workflow_activation.IResolveActivity): Promise<void>;
23
28
  resolveChildWorkflowExecutionStart(activation: coresdk.workflow_activation.IResolveChildWorkflowExecutionStart): Promise<void>;
24
29
  resolveChildWorkflowExecution(activation: coresdk.workflow_activation.IResolveChildWorkflowExecution): Promise<void>;
25
- protected queryWorkflowNextHandler(input: QueryInput): Promise<unknown>;
30
+ protected queryWorkflowNextHandler({ queryName, args }: QueryInput): Promise<unknown>;
26
31
  queryWorkflow(activation: coresdk.workflow_activation.IQueryWorkflow): void;
27
- signalWorkflowNextHandler(fn: WorkflowSignalType, input: SignalInput): Promise<void>;
32
+ signalWorkflowNextHandler({ signalName, args }: SignalInput): Promise<void>;
28
33
  signalWorkflow(activation: coresdk.workflow_activation.ISignalWorkflow): void;
29
34
  resolveSignalExternalWorkflow(activation: coresdk.workflow_activation.IResolveSignalExternalWorkflow): Promise<void>;
30
35
  resolveRequestCancelExternalWorkflow(activation: coresdk.workflow_activation.IResolveRequestCancelExternalWorkflow): Promise<void>;
@@ -55,6 +60,26 @@ export declare class State {
55
60
  signalWorkflow: Map<number, Completion>;
56
61
  cancelWorkflow: Map<number, Completion>;
57
62
  };
63
+ /**
64
+ * Holds buffered signal calls until a listener is registered
65
+ */
66
+ readonly bufferedSignals: Map<string, coresdk.workflow_activation.ISignalWorkflow[]>;
67
+ /**
68
+ * Holds buffered query calls until a listener is registered.
69
+ *
70
+ * **IMPORTANT** queries are only buffered until workflow is started.
71
+ * This is required because async interceptors might block workflow function invocation
72
+ * which delays query handler registration.
73
+ */
74
+ readonly bufferedQueries: coresdk.workflow_activation.IQueryWorkflow[];
75
+ /**
76
+ * Mapping of signal name to listener
77
+ */
78
+ readonly signalListeners: Map<string, WorkflowSignalType>;
79
+ /**
80
+ * Mapping of signal name to listener
81
+ */
82
+ readonly queryListeners: Map<string, WorkflowQueryType>;
58
83
  /**
59
84
  * Loaded in {@link initRuntime}
60
85
  */
@@ -64,9 +89,10 @@ export declare class State {
64
89
  */
65
90
  commands: coresdk.workflow_commands.IWorkflowCommand[];
66
91
  /**
67
- * Buffer containing external dependency calls which have not yet been transferred out of the isolate
92
+ /**
93
+ * Stores all {@link condition}s that haven't been unblocked yet
68
94
  */
69
- pendingExternalCalls: ExternalCall[];
95
+ blockedConditions: Map<number, Condition>;
70
96
  /**
71
97
  * Is this Workflow completed
72
98
  */
@@ -82,16 +108,16 @@ export declare class State {
82
108
  timer: number;
83
109
  activity: number;
84
110
  childWorkflow: number;
85
- dependency: number;
86
111
  signalWorkflow: number;
87
112
  cancelWorkflow: number;
113
+ condition: number;
88
114
  };
89
115
  get now(): number;
90
116
  set now(value: number);
91
117
  /**
92
118
  * Reference to the current Workflow, initialized when a Workflow is started
93
119
  */
94
- workflow?: WorkflowHandlers;
120
+ workflow?: Workflow;
95
121
  /**
96
122
  * Information about the current Workflow
97
123
  */
@@ -100,14 +126,12 @@ export declare class State {
100
126
  * A deterministic RNG, used by the isolate's overridden Math.random
101
127
  */
102
128
  random: RNG;
103
- dependencies: ExternalDependencies;
104
- getAndResetPendingExternalCalls(): ExternalCall[];
105
129
  /**
106
130
  * Used to require user code
107
131
  *
108
132
  * Injected on isolate startup
109
133
  */
110
- require?: (path: string | undefined, workflowType: string) => any;
134
+ require?: (path: string | undefined) => Promise<Record<string, any>>;
111
135
  dataConverter: DataConverter;
112
136
  /**
113
137
  * Patches we know the status of for this workflow, as in {@link patched}
@@ -117,6 +141,8 @@ export declare class State {
117
141
  * Patches we sent to core {@link patched}
118
142
  */
119
143
  readonly sentPatches: Set<string>;
144
+ externalCalls: ExternalCall[];
145
+ getAndResetExternalCalls(): ExternalCall[];
120
146
  /**
121
147
  * Buffer a Workflow command to be collected at the end of the current activation.
122
148
  *