@temporalio/workflow 0.17.2 → 0.19.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 +4 -4
- package/lib/errors.d.ts +2 -17
- package/lib/errors.js +4 -21
- package/lib/errors.js.map +1 -1
- package/lib/index.d.ts +6 -5
- package/lib/index.js +21 -15
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +5 -4
- package/lib/interfaces.d.ts +2 -2
- package/lib/interfaces.js +5 -5
- package/lib/interfaces.js.map +1 -1
- package/lib/internals.d.ts +9 -5
- package/lib/internals.js +48 -37
- package/lib/internals.js.map +1 -1
- package/lib/worker-interface.d.ts +9 -2
- package/lib/worker-interface.js +50 -14
- package/lib/worker-interface.js.map +1 -1
- package/lib/workflow-handle.d.ts +1 -1
- package/lib/workflow.d.ts +7 -11
- package/lib/workflow.js +34 -33
- package/lib/workflow.js.map +1 -1
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@temporalio/workflow)
|
|
4
4
|
|
|
5
|
-
Part of
|
|
5
|
+
Part of [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/docs/typescript/introduction/).
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- [Workflow docs](https://docs.temporal.io/docs/typescript/workflows)
|
|
8
|
+
- [API reference](https://typescript.temporal.io/api/namespaces/workflow)
|
|
9
|
+
- [Sample projects](https://github.com/temporalio/samples-typescript)
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { WorkflowExecutionAlreadyStartedError } from '@temporalio/common';
|
|
1
2
|
/**
|
|
2
3
|
* Base class for all workflow errors
|
|
3
4
|
*/
|
|
@@ -5,27 +6,11 @@ export declare class WorkflowError extends Error {
|
|
|
5
6
|
readonly name: string;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
|
-
* Thrown in workflow when it
|
|
9
|
+
* Thrown in workflow when it tries to do something that non-deterministic such as construct a WeakMap()
|
|
9
10
|
*/
|
|
10
11
|
export declare class DeterminismViolationError extends WorkflowError {
|
|
11
12
|
readonly name: string;
|
|
12
13
|
}
|
|
13
|
-
/**
|
|
14
|
-
* This exception is thrown in the following cases:
|
|
15
|
-
* - Workflow with the same WorkflowId is currently running
|
|
16
|
-
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
17
|
-
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
|
|
18
|
-
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
19
|
-
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
|
|
20
|
-
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
|
|
21
|
-
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
|
|
22
|
-
*/
|
|
23
|
-
export declare class WorkflowExecutionAlreadyStartedError extends WorkflowError {
|
|
24
|
-
readonly workflowId: string;
|
|
25
|
-
readonly workflowType: string;
|
|
26
|
-
readonly name: string;
|
|
27
|
-
constructor(message: string, workflowId: string, workflowType: string);
|
|
28
|
-
}
|
|
29
14
|
/**
|
|
30
15
|
* Returns whether provided `err` is caused by cancellation
|
|
31
16
|
*/
|
package/lib/errors.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isCancellation = exports.
|
|
3
|
+
exports.isCancellation = exports.DeterminismViolationError = exports.WorkflowError = exports.WorkflowExecutionAlreadyStartedError = void 0;
|
|
4
4
|
const common_1 = require("@temporalio/common");
|
|
5
|
+
var common_2 = require("@temporalio/common");
|
|
6
|
+
Object.defineProperty(exports, "WorkflowExecutionAlreadyStartedError", { enumerable: true, get: function () { return common_2.WorkflowExecutionAlreadyStartedError; } });
|
|
5
7
|
/**
|
|
6
8
|
* Base class for all workflow errors
|
|
7
9
|
*/
|
|
@@ -13,7 +15,7 @@ class WorkflowError extends Error {
|
|
|
13
15
|
}
|
|
14
16
|
exports.WorkflowError = WorkflowError;
|
|
15
17
|
/**
|
|
16
|
-
* Thrown in workflow when it
|
|
18
|
+
* Thrown in workflow when it tries to do something that non-deterministic such as construct a WeakMap()
|
|
17
19
|
*/
|
|
18
20
|
class DeterminismViolationError extends WorkflowError {
|
|
19
21
|
constructor() {
|
|
@@ -22,25 +24,6 @@ class DeterminismViolationError extends WorkflowError {
|
|
|
22
24
|
}
|
|
23
25
|
}
|
|
24
26
|
exports.DeterminismViolationError = DeterminismViolationError;
|
|
25
|
-
/**
|
|
26
|
-
* This exception is thrown in the following cases:
|
|
27
|
-
* - Workflow with the same WorkflowId is currently running
|
|
28
|
-
* - There is a closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
29
|
-
* is `WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE`
|
|
30
|
-
* - There is successfully closed workflow with the same ID and the {@link WorkflowOptions.workflowIdReusePolicy}
|
|
31
|
-
* is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY`
|
|
32
|
-
* - {@link Workflow.execute} is called *more than once* on a handle created through {@link createChildWorkflowHandle} and the
|
|
33
|
-
* {@link WorkflowOptions.workflowIdReusePolicy} is `WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE`
|
|
34
|
-
*/
|
|
35
|
-
class WorkflowExecutionAlreadyStartedError extends WorkflowError {
|
|
36
|
-
constructor(message, workflowId, workflowType) {
|
|
37
|
-
super(message);
|
|
38
|
-
this.workflowId = workflowId;
|
|
39
|
-
this.workflowType = workflowType;
|
|
40
|
-
this.name = 'ChildWorkflowExecutionAlreadyStartedError';
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
exports.WorkflowExecutionAlreadyStartedError = WorkflowExecutionAlreadyStartedError;
|
|
44
27
|
/**
|
|
45
28
|
* Returns whether provided `err` is caused by cancellation
|
|
46
29
|
*/
|
package/lib/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,+CAA6F;
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AAAA,+CAA6F;AAC7F,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;;GAEG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,OAAO,CACL,GAAG,YAAY,yBAAgB;QAC/B,CAAC,CAAC,GAAG,YAAY,wBAAe,IAAI,GAAG,YAAY,6BAAoB,CAAC,IAAI,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CACvG,CAAC;AACJ,CAAC;AALD,wCAKC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -49,12 +49,13 @@
|
|
|
49
49
|
*
|
|
50
50
|
* @module
|
|
51
51
|
*/
|
|
52
|
-
export {
|
|
53
|
-
export {
|
|
52
|
+
export { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, defaultPayloadConverter, PayloadConverter, rootCause, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, } from '@temporalio/common';
|
|
53
|
+
export { ActivityCancellationType, ActivityFunction, ActivityInterface, ActivityOptions, IllegalStateError, RetryPolicy, ValueError, Workflow, WorkflowIdReusePolicy, WorkflowResultType, } from '@temporalio/internal-workflow-common';
|
|
54
|
+
export { AsyncLocalStorage, CancellationScope, CancellationScopeOptions, ROOT_SCOPE } from './cancellation-scope';
|
|
54
55
|
export * from './errors';
|
|
55
|
-
export * from './workflow';
|
|
56
56
|
export * from './interceptors';
|
|
57
|
-
export {
|
|
57
|
+
export { ChildWorkflowCancellationType, ChildWorkflowOptions, ContinueAsNewOptions, ParentClosePolicy, WorkflowInfo, ContinueAsNew, } from './interfaces';
|
|
58
|
+
export { Sink, SinkCall, SinkFunction, Sinks } from './sinks';
|
|
58
59
|
export { Trigger } from './trigger';
|
|
59
|
-
export
|
|
60
|
+
export * from './workflow';
|
|
60
61
|
export { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
|
package/lib/index.js
CHANGED
|
@@ -52,7 +52,11 @@
|
|
|
52
52
|
*/
|
|
53
53
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
54
54
|
if (k2 === undefined) k2 = k;
|
|
55
|
-
Object.
|
|
55
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
56
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
57
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
58
|
+
}
|
|
59
|
+
Object.defineProperty(o, k2, desc);
|
|
56
60
|
}) : (function(o, m, k, k2) {
|
|
57
61
|
if (k2 === undefined) k2 = k;
|
|
58
62
|
o[k2] = m[k];
|
|
@@ -61,32 +65,34 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
61
65
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
62
66
|
};
|
|
63
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
|
-
exports.Trigger = exports.
|
|
68
|
+
exports.Trigger = exports.ContinueAsNew = exports.ParentClosePolicy = exports.ChildWorkflowCancellationType = exports.ROOT_SCOPE = exports.CancellationScope = exports.AsyncLocalStorage = exports.WorkflowIdReusePolicy = exports.ValueError = exports.IllegalStateError = exports.ActivityCancellationType = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.rootCause = exports.defaultPayloadConverter = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = void 0;
|
|
65
69
|
var common_1 = require("@temporalio/common");
|
|
66
|
-
Object.defineProperty(exports, "ActivityCancellationType", { enumerable: true, get: function () { return common_1.ActivityCancellationType; } });
|
|
67
|
-
Object.defineProperty(exports, "rootCause", { enumerable: true, get: function () { return common_1.rootCause; } });
|
|
68
|
-
Object.defineProperty(exports, "IllegalStateError", { enumerable: true, get: function () { return common_1.IllegalStateError; } });
|
|
69
|
-
Object.defineProperty(exports, "defaultDataConverter", { enumerable: true, get: function () { return common_1.defaultDataConverter; } });
|
|
70
|
-
Object.defineProperty(exports, "WorkflowIdReusePolicy", { enumerable: true, get: function () { return common_1.WorkflowIdReusePolicy; } });
|
|
71
70
|
Object.defineProperty(exports, "ActivityFailure", { enumerable: true, get: function () { return common_1.ActivityFailure; } });
|
|
72
71
|
Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
|
|
73
72
|
Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
|
|
74
73
|
Object.defineProperty(exports, "ChildWorkflowFailure", { enumerable: true, get: function () { return common_1.ChildWorkflowFailure; } });
|
|
74
|
+
Object.defineProperty(exports, "defaultPayloadConverter", { enumerable: true, get: function () { return common_1.defaultPayloadConverter; } });
|
|
75
|
+
Object.defineProperty(exports, "rootCause", { enumerable: true, get: function () { return common_1.rootCause; } });
|
|
75
76
|
Object.defineProperty(exports, "ServerFailure", { enumerable: true, get: function () { return common_1.ServerFailure; } });
|
|
76
77
|
Object.defineProperty(exports, "TemporalFailure", { enumerable: true, get: function () { return common_1.TemporalFailure; } });
|
|
77
78
|
Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: function () { return common_1.TerminatedFailure; } });
|
|
78
79
|
Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return common_1.TimeoutFailure; } });
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
Object.defineProperty(exports, "
|
|
82
|
-
Object.defineProperty(exports, "
|
|
83
|
-
|
|
84
|
-
__exportStar(require("./workflow"), exports);
|
|
85
|
-
__exportStar(require("./interceptors"), exports);
|
|
80
|
+
var internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
81
|
+
Object.defineProperty(exports, "ActivityCancellationType", { enumerable: true, get: function () { return internal_workflow_common_1.ActivityCancellationType; } });
|
|
82
|
+
Object.defineProperty(exports, "IllegalStateError", { enumerable: true, get: function () { return internal_workflow_common_1.IllegalStateError; } });
|
|
83
|
+
Object.defineProperty(exports, "ValueError", { enumerable: true, get: function () { return internal_workflow_common_1.ValueError; } });
|
|
84
|
+
Object.defineProperty(exports, "WorkflowIdReusePolicy", { enumerable: true, get: function () { return internal_workflow_common_1.WorkflowIdReusePolicy; } });
|
|
86
85
|
var cancellation_scope_1 = require("./cancellation-scope");
|
|
87
86
|
Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return cancellation_scope_1.AsyncLocalStorage; } });
|
|
88
|
-
Object.defineProperty(exports, "ROOT_SCOPE", { enumerable: true, get: function () { return cancellation_scope_1.ROOT_SCOPE; } });
|
|
89
87
|
Object.defineProperty(exports, "CancellationScope", { enumerable: true, get: function () { return cancellation_scope_1.CancellationScope; } });
|
|
88
|
+
Object.defineProperty(exports, "ROOT_SCOPE", { enumerable: true, get: function () { return cancellation_scope_1.ROOT_SCOPE; } });
|
|
89
|
+
__exportStar(require("./errors"), exports);
|
|
90
|
+
__exportStar(require("./interceptors"), exports);
|
|
91
|
+
var interfaces_1 = require("./interfaces");
|
|
92
|
+
Object.defineProperty(exports, "ChildWorkflowCancellationType", { enumerable: true, get: function () { return interfaces_1.ChildWorkflowCancellationType; } });
|
|
93
|
+
Object.defineProperty(exports, "ParentClosePolicy", { enumerable: true, get: function () { return interfaces_1.ParentClosePolicy; } });
|
|
94
|
+
Object.defineProperty(exports, "ContinueAsNew", { enumerable: true, get: function () { return interfaces_1.ContinueAsNew; } });
|
|
90
95
|
var trigger_1 = require("./trigger");
|
|
91
96
|
Object.defineProperty(exports, "Trigger", { enumerable: true, get: function () { return trigger_1.Trigger; } });
|
|
97
|
+
__exportStar(require("./workflow"), exports);
|
|
92
98
|
//# 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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;;;;;;;;;;;;;;;;;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,iFAW8C;AAV5C,oIAAA,wBAAwB,OAAA;AAIxB,6HAAA,iBAAiB,OAAA;AAEjB,sHAAA,UAAU,OAAA;AAEV,iIAAA,qBAAqB,OAAA;AAGvB,2DAAkH;AAAzG,uHAAA,iBAAiB,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAA4B,gHAAA,UAAU,OAAA;AACnF,2CAAyB;AACzB,iDAA+B;AAC/B,2CAOsB;AANpB,2HAAA,6BAA6B,OAAA;AAG7B,+GAAA,iBAAiB,OAAA;AAEjB,2GAAA,aAAa,OAAA;AAGf,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,6CAA2B"}
|
package/lib/interceptors.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
|
-
import {
|
|
8
|
+
import { WorkflowExecution } from '@temporalio/common';
|
|
9
|
+
import { ActivityOptions, Headers, Next } from '@temporalio/internal-workflow-common';
|
|
9
10
|
import type { coresdk } from '@temporalio/proto/lib/coresdk';
|
|
10
11
|
import { ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions } from './interfaces';
|
|
11
12
|
export { Next, Headers };
|
|
@@ -130,7 +131,7 @@ export interface ConcludeActivationInput {
|
|
|
130
131
|
export declare type ConcludeActivationOutput = ConcludeActivationInput;
|
|
131
132
|
/** Input for WorkflowInternalsInterceptor.activate */
|
|
132
133
|
export interface ActivateInput {
|
|
133
|
-
activation: coresdk.workflow_activation.
|
|
134
|
+
activation: coresdk.workflow_activation.IWorkflowActivation;
|
|
134
135
|
batchIndex: number;
|
|
135
136
|
}
|
|
136
137
|
/** Input for WorkflowInternalsInterceptor.dispose */
|
|
@@ -143,11 +144,11 @@ export interface DisposeInput {
|
|
|
143
144
|
*/
|
|
144
145
|
export interface WorkflowInternalsInterceptor {
|
|
145
146
|
/**
|
|
146
|
-
* Called when the Workflow runtime runs a
|
|
147
|
+
* Called when the Workflow runtime runs a WorkflowActivationJob.
|
|
147
148
|
*/
|
|
148
149
|
activate?(input: ActivateInput, next: Next<this, 'activate'>): Promise<void>;
|
|
149
150
|
/**
|
|
150
|
-
* Called after all `
|
|
151
|
+
* Called after all `WorkflowActivationJob`s have been processed for an activation.
|
|
151
152
|
*
|
|
152
153
|
* Can manipulate the commands generated by the Workflow
|
|
153
154
|
*/
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { coresdk } from '@temporalio/proto/lib/coresdk';
|
|
2
|
-
import { CommonWorkflowOptions } from '@temporalio/common';
|
|
2
|
+
import { CommonWorkflowOptions } from '@temporalio/internal-workflow-common';
|
|
3
3
|
/**
|
|
4
4
|
* Workflow execution information
|
|
5
5
|
*/
|
|
@@ -35,7 +35,7 @@ export interface WorkflowInfo {
|
|
|
35
35
|
*/
|
|
36
36
|
export declare class ContinueAsNew extends Error {
|
|
37
37
|
readonly command: coresdk.workflow_commands.IContinueAsNewWorkflowExecution;
|
|
38
|
-
readonly
|
|
38
|
+
readonly name = "ContinueAsNew";
|
|
39
39
|
constructor(command: coresdk.workflow_commands.IContinueAsNewWorkflowExecution);
|
|
40
40
|
}
|
|
41
41
|
/**
|
package/lib/interfaces.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ParentClosePolicy = exports.ChildWorkflowCancellationType = exports.ContinueAsNew = void 0;
|
|
4
|
-
const
|
|
4
|
+
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
5
5
|
/**
|
|
6
6
|
* Not an actual error, used by the Workflow runtime to abort execution when {@link continueAsNew} is called
|
|
7
7
|
*/
|
|
8
8
|
class ContinueAsNew extends Error {
|
|
9
9
|
constructor(command) {
|
|
10
|
-
super();
|
|
10
|
+
super('Workflow continued as new');
|
|
11
11
|
this.command = command;
|
|
12
|
-
this.
|
|
12
|
+
this.name = 'ContinueAsNew';
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
exports.ContinueAsNew = ContinueAsNew;
|
|
@@ -20,7 +20,7 @@ var ChildWorkflowCancellationType;
|
|
|
20
20
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["WAIT_CANCELLATION_COMPLETED"] = 2] = "WAIT_CANCELLATION_COMPLETED";
|
|
21
21
|
ChildWorkflowCancellationType[ChildWorkflowCancellationType["WAIT_CANCELLATION_REQUESTED"] = 3] = "WAIT_CANCELLATION_REQUESTED";
|
|
22
22
|
})(ChildWorkflowCancellationType = exports.ChildWorkflowCancellationType || (exports.ChildWorkflowCancellationType = {}));
|
|
23
|
-
(0,
|
|
23
|
+
(0, internal_workflow_common_1.checkExtends)();
|
|
24
24
|
var ParentClosePolicy;
|
|
25
25
|
(function (ParentClosePolicy) {
|
|
26
26
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_UNSPECIFIED"] = 0] = "PARENT_CLOSE_POLICY_UNSPECIFIED";
|
|
@@ -28,5 +28,5 @@ var ParentClosePolicy;
|
|
|
28
28
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_ABANDON"] = 2] = "PARENT_CLOSE_POLICY_ABANDON";
|
|
29
29
|
ParentClosePolicy[ParentClosePolicy["PARENT_CLOSE_POLICY_REQUEST_CANCEL"] = 3] = "PARENT_CLOSE_POLICY_REQUEST_CANCEL";
|
|
30
30
|
})(ParentClosePolicy = exports.ParentClosePolicy || (exports.ParentClosePolicy = {}));
|
|
31
|
-
(0,
|
|
31
|
+
(0, internal_workflow_common_1.checkExtends)();
|
|
32
32
|
//# sourceMappingURL=interfaces.js.map
|
package/lib/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAEA,
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAEA,mFAAoE;AAqCpE;;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,6BAKX;AALD,WAAY,6BAA6B;IACvC,uFAAW,CAAA;IACX,6FAAc,CAAA;IACd,+HAA+B,CAAA;IAC/B,+HAA+B,CAAA;AACjC,CAAC,EALW,6BAA6B,GAA7B,qCAA6B,KAA7B,qCAA6B,QAKxC;AAED,IAAA,uCAAY,GAAuF,CAAC;AAEpG,IAAY,iBAKX;AALD,WAAY,iBAAiB;IAC3B,+GAAmC,CAAA;IACnC,2GAAiC,CAAA;IACjC,uGAA+B,CAAA;IAC/B,qHAAsC,CAAA;AACxC,CAAC,EALW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAK5B;AAED,IAAA,uCAAY,GAA+D,CAAC"}
|
package/lib/internals.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PayloadConverter } from '@temporalio/common';
|
|
2
|
+
import { Workflow, WorkflowQueryType, WorkflowSignalType } from '@temporalio/internal-workflow-common';
|
|
2
3
|
import type { coresdk } from '@temporalio/proto/lib/coresdk';
|
|
3
4
|
import { RNG } from './alea';
|
|
4
|
-
import { WorkflowInfo } from './interfaces';
|
|
5
5
|
import { QueryInput, SignalInput, WorkflowExecuteInput, WorkflowInterceptors, WorkflowInterceptorsFactory } from './interceptors';
|
|
6
|
+
import { WorkflowInfo } from './interfaces';
|
|
6
7
|
import { SinkCall } from './sinks';
|
|
7
8
|
export declare type ResolveFunction<T = any> = (val: T) => any;
|
|
8
9
|
export declare type RejectFunction<E = any> = (val: E) => any;
|
|
@@ -14,9 +15,9 @@ export interface Condition {
|
|
|
14
15
|
fn(): boolean;
|
|
15
16
|
resolve(): void;
|
|
16
17
|
}
|
|
17
|
-
export declare type ActivationHandlerFunction<K extends keyof coresdk.workflow_activation.
|
|
18
|
+
export declare type ActivationHandlerFunction<K extends keyof coresdk.workflow_activation.IWorkflowActivationJob> = (activation: NonNullable<coresdk.workflow_activation.IWorkflowActivationJob[K]>) => Promise<void> | void;
|
|
18
19
|
export declare type ActivationHandler = {
|
|
19
|
-
[P in keyof coresdk.workflow_activation.
|
|
20
|
+
[P in keyof coresdk.workflow_activation.IWorkflowActivationJob]: ActivationHandlerFunction<P>;
|
|
20
21
|
};
|
|
21
22
|
export declare class Activator implements ActivationHandler {
|
|
22
23
|
workflowFunctionWasCalled: boolean;
|
|
@@ -145,7 +146,7 @@ export declare class State {
|
|
|
145
146
|
* Injected on isolate context startup
|
|
146
147
|
*/
|
|
147
148
|
importInterceptors?: InterceptorsImportFunc;
|
|
148
|
-
|
|
149
|
+
payloadConverter: PayloadConverter;
|
|
149
150
|
/**
|
|
150
151
|
* Patches we know the status of for this workflow, as in {@link patched}
|
|
151
152
|
*/
|
|
@@ -169,4 +170,7 @@ export declare const state: State;
|
|
|
169
170
|
* Used to handle any failure emitted by the Workflow.
|
|
170
171
|
*/
|
|
171
172
|
export declare function handleWorkflowFailure(error: unknown): Promise<void>;
|
|
173
|
+
/** Consume a completion if it exists in Workflow state */
|
|
174
|
+
export declare function maybeConsumeCompletion(type: keyof State['completions'], taskSeq: number): Completion | undefined;
|
|
175
|
+
/** Consume a completion if it exists in Workflow state, throws if it doesn't */
|
|
172
176
|
export declare function consumeCompletion(type: keyof State['completions'], taskSeq: number): Completion;
|
package/lib/internals.js
CHANGED
|
@@ -12,19 +12,19 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
12
12
|
};
|
|
13
13
|
var _State_now;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.consumeCompletion = exports.handleWorkflowFailure = exports.state = exports.State = exports.Activator = void 0;
|
|
15
|
+
exports.consumeCompletion = exports.maybeConsumeCompletion = exports.handleWorkflowFailure = exports.state = exports.State = exports.Activator = void 0;
|
|
16
16
|
const common_1 = require("@temporalio/common");
|
|
17
|
-
const
|
|
17
|
+
const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
|
|
18
18
|
const alea_1 = require("./alea");
|
|
19
|
-
const interfaces_1 = require("./interfaces");
|
|
20
|
-
const errors_1 = require("./errors");
|
|
21
19
|
const cancellation_scope_1 = require("./cancellation-scope");
|
|
20
|
+
const errors_1 = require("./errors");
|
|
21
|
+
const interfaces_1 = require("./interfaces");
|
|
22
22
|
var StartChildWorkflowExecutionFailedCause;
|
|
23
23
|
(function (StartChildWorkflowExecutionFailedCause) {
|
|
24
24
|
StartChildWorkflowExecutionFailedCause[StartChildWorkflowExecutionFailedCause["START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_UNSPECIFIED"] = 0] = "START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_UNSPECIFIED";
|
|
25
25
|
StartChildWorkflowExecutionFailedCause[StartChildWorkflowExecutionFailedCause["START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_EXISTS"] = 1] = "START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_EXISTS";
|
|
26
26
|
})(StartChildWorkflowExecutionFailedCause || (StartChildWorkflowExecutionFailedCause = {}));
|
|
27
|
-
(0,
|
|
27
|
+
(0, internal_workflow_common_1.checkExtends)();
|
|
28
28
|
class Activator {
|
|
29
29
|
constructor() {
|
|
30
30
|
this.workflowFunctionWasCalled = false;
|
|
@@ -32,7 +32,7 @@ class Activator {
|
|
|
32
32
|
async startWorkflowNextHandler({ args }) {
|
|
33
33
|
const { workflow } = exports.state;
|
|
34
34
|
if (workflow === undefined) {
|
|
35
|
-
throw new
|
|
35
|
+
throw new internal_workflow_common_1.IllegalStateError('Workflow uninitialized');
|
|
36
36
|
}
|
|
37
37
|
let promise;
|
|
38
38
|
try {
|
|
@@ -53,12 +53,12 @@ class Activator {
|
|
|
53
53
|
startWorkflow(activation) {
|
|
54
54
|
const { info } = exports.state;
|
|
55
55
|
if (info === undefined) {
|
|
56
|
-
throw new
|
|
56
|
+
throw new internal_workflow_common_1.IllegalStateError('Workflow has not been initialized');
|
|
57
57
|
}
|
|
58
|
-
const execute = (0,
|
|
58
|
+
const execute = (0, internal_workflow_common_1.composeInterceptors)(exports.state.interceptors.inbound, 'execute', this.startWorkflowNextHandler.bind(this));
|
|
59
59
|
execute({
|
|
60
60
|
headers: activation.headers ?? {},
|
|
61
|
-
args: (0, common_1.
|
|
61
|
+
args: (0, common_1.arrayFromPayloads)(exports.state.payloadConverter, activation.arguments),
|
|
62
62
|
})
|
|
63
63
|
.then(completeWorkflow)
|
|
64
64
|
.catch(handleWorkflowFailure);
|
|
@@ -68,8 +68,10 @@ class Activator {
|
|
|
68
68
|
cancellation_scope_1.ROOT_SCOPE.cancel();
|
|
69
69
|
}
|
|
70
70
|
fireTimer(activation) {
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
// Timers are a special case where their completion might not be in Workflow state,
|
|
72
|
+
// this is due to immediate timer cancellation that doesn't go wait for Core.
|
|
73
|
+
const completion = maybeConsumeCompletion('timer', getSeq(activation));
|
|
74
|
+
completion?.resolve(undefined);
|
|
73
75
|
}
|
|
74
76
|
async resolveActivity(activation) {
|
|
75
77
|
if (!activation.result) {
|
|
@@ -78,17 +80,17 @@ class Activator {
|
|
|
78
80
|
const { resolve, reject } = consumeCompletion('activity', getSeq(activation));
|
|
79
81
|
if (activation.result.completed) {
|
|
80
82
|
const completed = activation.result.completed;
|
|
81
|
-
const result = completed.result ? exports.state.
|
|
83
|
+
const result = completed.result ? exports.state.payloadConverter.fromPayload(completed.result) : undefined;
|
|
82
84
|
resolve(result);
|
|
83
85
|
}
|
|
84
86
|
else if (activation.result.failed) {
|
|
85
87
|
const { failure } = activation.result.failed;
|
|
86
|
-
const err =
|
|
88
|
+
const err = (0, common_1.optionalFailureToOptionalError)(failure, exports.state.payloadConverter);
|
|
87
89
|
reject(err);
|
|
88
90
|
}
|
|
89
91
|
else if (activation.result.cancelled) {
|
|
90
92
|
const { failure } = activation.result.cancelled;
|
|
91
|
-
const err =
|
|
93
|
+
const err = (0, common_1.optionalFailureToOptionalError)(failure, exports.state.payloadConverter);
|
|
92
94
|
reject(err);
|
|
93
95
|
}
|
|
94
96
|
}
|
|
@@ -100,7 +102,7 @@ class Activator {
|
|
|
100
102
|
else if (activation.failed) {
|
|
101
103
|
if (activation.failed.cause !==
|
|
102
104
|
StartChildWorkflowExecutionFailedCause.START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_EXISTS) {
|
|
103
|
-
throw new
|
|
105
|
+
throw new internal_workflow_common_1.IllegalStateError('Got unknown StartChildWorkflowExecutionFailedCause');
|
|
104
106
|
}
|
|
105
107
|
if (!(activation.seq && activation.failed.workflowId && activation.failed.workflowType)) {
|
|
106
108
|
throw new TypeError('Missing attributes in activation job');
|
|
@@ -111,7 +113,7 @@ class Activator {
|
|
|
111
113
|
if (!activation.cancelled.failure) {
|
|
112
114
|
throw new TypeError('Got no failure in cancelled variant');
|
|
113
115
|
}
|
|
114
|
-
reject(
|
|
116
|
+
reject((0, common_1.failureToError)(activation.cancelled.failure, exports.state.payloadConverter));
|
|
115
117
|
}
|
|
116
118
|
else {
|
|
117
119
|
throw new TypeError('Got ResolveChildWorkflowExecutionStart with no status');
|
|
@@ -124,7 +126,7 @@ class Activator {
|
|
|
124
126
|
const { resolve, reject } = consumeCompletion('childWorkflowComplete', getSeq(activation));
|
|
125
127
|
if (activation.result.completed) {
|
|
126
128
|
const completed = activation.result.completed;
|
|
127
|
-
const result = completed.result ?
|
|
129
|
+
const result = completed.result ? exports.state.payloadConverter.fromPayload(completed.result) : undefined;
|
|
128
130
|
resolve(result);
|
|
129
131
|
}
|
|
130
132
|
else if (activation.result.failed) {
|
|
@@ -132,14 +134,14 @@ class Activator {
|
|
|
132
134
|
if (failure === undefined || failure === null) {
|
|
133
135
|
throw new TypeError('Got failed result with no failure attribute');
|
|
134
136
|
}
|
|
135
|
-
reject(
|
|
137
|
+
reject((0, common_1.failureToError)(failure, exports.state.payloadConverter));
|
|
136
138
|
}
|
|
137
139
|
else if (activation.result.cancelled) {
|
|
138
140
|
const { failure } = activation.result.cancelled;
|
|
139
141
|
if (failure === undefined || failure === null) {
|
|
140
142
|
throw new TypeError('Got cancelled result with no failure attribute');
|
|
141
143
|
}
|
|
142
|
-
reject(
|
|
144
|
+
reject((0, common_1.failureToError)(failure, exports.state.payloadConverter));
|
|
143
145
|
}
|
|
144
146
|
}
|
|
145
147
|
async queryWorkflowNextHandler({ queryName, args }) {
|
|
@@ -163,17 +165,17 @@ class Activator {
|
|
|
163
165
|
if (!(queryType && queryId)) {
|
|
164
166
|
throw new TypeError('Missing query activation attributes');
|
|
165
167
|
}
|
|
166
|
-
const execute = (0,
|
|
168
|
+
const execute = (0, internal_workflow_common_1.composeInterceptors)(exports.state.interceptors.inbound, 'handleQuery', this.queryWorkflowNextHandler.bind(this));
|
|
167
169
|
execute({
|
|
168
170
|
queryName: queryType,
|
|
169
|
-
args: (0, common_1.
|
|
171
|
+
args: (0, common_1.arrayFromPayloads)(exports.state.payloadConverter, activation.arguments),
|
|
170
172
|
queryId,
|
|
171
173
|
}).then((result) => completeQuery(queryId, result), (reason) => failQuery(queryId, reason));
|
|
172
174
|
}
|
|
173
175
|
async signalWorkflowNextHandler({ signalName, args }) {
|
|
174
176
|
const fn = exports.state.signalHandlers.get(signalName);
|
|
175
177
|
if (fn === undefined) {
|
|
176
|
-
throw new
|
|
178
|
+
throw new internal_workflow_common_1.IllegalStateError(`No registered signal handler for signal ${signalName}`);
|
|
177
179
|
}
|
|
178
180
|
return fn(...args);
|
|
179
181
|
}
|
|
@@ -192,16 +194,16 @@ class Activator {
|
|
|
192
194
|
buffer.push(activation);
|
|
193
195
|
return;
|
|
194
196
|
}
|
|
195
|
-
const execute = (0,
|
|
197
|
+
const execute = (0, internal_workflow_common_1.composeInterceptors)(exports.state.interceptors.inbound, 'handleSignal', this.signalWorkflowNextHandler.bind(this));
|
|
196
198
|
execute({
|
|
197
|
-
args: (0, common_1.
|
|
199
|
+
args: (0, common_1.arrayFromPayloads)(exports.state.payloadConverter, activation.input),
|
|
198
200
|
signalName,
|
|
199
201
|
}).catch(handleWorkflowFailure);
|
|
200
202
|
}
|
|
201
203
|
async resolveSignalExternalWorkflow(activation) {
|
|
202
204
|
const { resolve, reject } = consumeCompletion('signalWorkflow', getSeq(activation));
|
|
203
205
|
if (activation.failure) {
|
|
204
|
-
reject(
|
|
206
|
+
reject((0, common_1.failureToError)(activation.failure, exports.state.payloadConverter));
|
|
205
207
|
}
|
|
206
208
|
else {
|
|
207
209
|
resolve(undefined);
|
|
@@ -210,7 +212,7 @@ class Activator {
|
|
|
210
212
|
async resolveRequestCancelExternalWorkflow(activation) {
|
|
211
213
|
const { resolve, reject } = consumeCompletion('cancelWorkflow', getSeq(activation));
|
|
212
214
|
if (activation.failure) {
|
|
213
|
-
reject(
|
|
215
|
+
reject((0, common_1.failureToError)(activation.failure, exports.state.payloadConverter));
|
|
214
216
|
}
|
|
215
217
|
else {
|
|
216
218
|
resolve(undefined);
|
|
@@ -229,7 +231,7 @@ class Activator {
|
|
|
229
231
|
exports.state.knownPresentPatches.add(activation.patchId);
|
|
230
232
|
}
|
|
231
233
|
removeFromCache() {
|
|
232
|
-
throw new
|
|
234
|
+
throw new internal_workflow_common_1.IllegalStateError('removeFromCache activation job should not reach workflow');
|
|
233
235
|
}
|
|
234
236
|
}
|
|
235
237
|
exports.Activator = Activator;
|
|
@@ -319,9 +321,9 @@ class State {
|
|
|
319
321
|
* A deterministic RNG, used by the isolate's overridden Math.random
|
|
320
322
|
*/
|
|
321
323
|
this.random = function () {
|
|
322
|
-
throw new
|
|
324
|
+
throw new internal_workflow_common_1.IllegalStateError('Tried to use Math.random before Workflow has been initialized');
|
|
323
325
|
};
|
|
324
|
-
this.
|
|
326
|
+
this.payloadConverter = common_1.defaultPayloadConverter;
|
|
325
327
|
/**
|
|
326
328
|
* Patches we know the status of for this workflow, as in {@link patched}
|
|
327
329
|
*/
|
|
@@ -334,7 +336,7 @@ class State {
|
|
|
334
336
|
}
|
|
335
337
|
get now() {
|
|
336
338
|
if (__classPrivateFieldGet(this, _State_now, "f") === undefined) {
|
|
337
|
-
throw new
|
|
339
|
+
throw new internal_workflow_common_1.IllegalStateError('Tried to get Date before Workflow has been initialized');
|
|
338
340
|
}
|
|
339
341
|
return __classPrivateFieldGet(this, _State_now, "f");
|
|
340
342
|
}
|
|
@@ -367,7 +369,7 @@ exports.state = new State();
|
|
|
367
369
|
function completeWorkflow(result) {
|
|
368
370
|
exports.state.pushCommand({
|
|
369
371
|
completeWorkflowExecution: {
|
|
370
|
-
result: exports.state.
|
|
372
|
+
result: exports.state.payloadConverter.toPayload(result),
|
|
371
373
|
},
|
|
372
374
|
}, true);
|
|
373
375
|
}
|
|
@@ -390,7 +392,7 @@ async function handleWorkflowFailure(error) {
|
|
|
390
392
|
}
|
|
391
393
|
exports.state.pushCommand({
|
|
392
394
|
failWorkflowExecution: {
|
|
393
|
-
failure:
|
|
395
|
+
failure: (0, common_1.errorToFailure)(error, exports.state.payloadConverter),
|
|
394
396
|
},
|
|
395
397
|
}, true);
|
|
396
398
|
}
|
|
@@ -398,20 +400,29 @@ async function handleWorkflowFailure(error) {
|
|
|
398
400
|
exports.handleWorkflowFailure = handleWorkflowFailure;
|
|
399
401
|
function completeQuery(queryId, result) {
|
|
400
402
|
exports.state.pushCommand({
|
|
401
|
-
respondToQuery: { queryId, succeeded: { response: exports.state.
|
|
403
|
+
respondToQuery: { queryId, succeeded: { response: exports.state.payloadConverter.toPayload(result) } },
|
|
402
404
|
});
|
|
403
405
|
}
|
|
404
406
|
async function failQuery(queryId, error) {
|
|
405
407
|
exports.state.pushCommand({
|
|
406
|
-
respondToQuery: { queryId, failed:
|
|
408
|
+
respondToQuery: { queryId, failed: (0, common_1.errorToFailure)((0, common_1.ensureTemporalFailure)(error), exports.state.payloadConverter) },
|
|
407
409
|
});
|
|
408
410
|
}
|
|
409
|
-
|
|
411
|
+
/** Consume a completion if it exists in Workflow state */
|
|
412
|
+
function maybeConsumeCompletion(type, taskSeq) {
|
|
410
413
|
const completion = exports.state.completions[type].get(taskSeq);
|
|
414
|
+
if (completion !== undefined) {
|
|
415
|
+
exports.state.completions[type].delete(taskSeq);
|
|
416
|
+
}
|
|
417
|
+
return completion;
|
|
418
|
+
}
|
|
419
|
+
exports.maybeConsumeCompletion = maybeConsumeCompletion;
|
|
420
|
+
/** Consume a completion if it exists in Workflow state, throws if it doesn't */
|
|
421
|
+
function consumeCompletion(type, taskSeq) {
|
|
422
|
+
const completion = maybeConsumeCompletion(type, taskSeq);
|
|
411
423
|
if (completion === undefined) {
|
|
412
|
-
throw new
|
|
424
|
+
throw new internal_workflow_common_1.IllegalStateError(`No completion for taskSeq ${taskSeq}`);
|
|
413
425
|
}
|
|
414
|
-
exports.state.completions[type].delete(taskSeq);
|
|
415
426
|
return completion;
|
|
416
427
|
}
|
|
417
428
|
exports.consumeCompletion = consumeCompletion;
|