@temporalio/client 1.4.4 → 1.5.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/lib/async-completion-client.d.ts +5 -32
- package/lib/async-completion-client.js +6 -20
- package/lib/async-completion-client.js.map +1 -1
- package/lib/base-client.d.ts +53 -0
- package/lib/base-client.js +45 -0
- package/lib/base-client.js.map +1 -0
- package/lib/client.d.ts +12 -52
- package/lib/client.js +30 -49
- package/lib/client.js.map +1 -1
- package/lib/connection.d.ts +9 -9
- package/lib/connection.js +4 -3
- package/lib/connection.js.map +1 -1
- package/lib/errors.d.ts +0 -1
- package/lib/errors.js +1 -3
- package/lib/errors.js.map +1 -1
- package/lib/helpers.d.ts +3 -0
- package/lib/helpers.js +63 -0
- package/lib/helpers.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +46 -10
- package/lib/iterators-utils.d.ts +31 -0
- package/lib/iterators-utils.js +80 -0
- package/lib/iterators-utils.js.map +1 -0
- package/lib/schedule-client.d.ts +175 -0
- package/lib/schedule-client.js +383 -0
- package/lib/schedule-client.js.map +1 -0
- package/lib/schedule-helpers.d.ts +20 -0
- package/lib/schedule-helpers.js +290 -0
- package/lib/schedule-helpers.js.map +1 -0
- package/lib/schedule-types.d.ts +691 -0
- package/lib/schedule-types.js +74 -0
- package/lib/schedule-types.js.map +1 -0
- package/lib/types.d.ts +8 -3
- package/lib/types.js.map +1 -1
- package/lib/workflow-client.d.ts +76 -59
- package/lib/workflow-client.js +87 -101
- package/lib/workflow-client.js.map +1 -1
- package/lib/workflow-options.d.ts +5 -1
- package/lib/workflow-options.js.map +1 -1
- package/package.json +7 -5
- package/src/async-completion-client.ts +16 -55
- package/src/base-client.ts +84 -0
- package/src/client.ts +41 -93
- package/src/connection.ts +12 -11
- package/src/errors.ts +0 -1
- package/src/helpers.ts +75 -0
- package/src/index.ts +2 -0
- package/src/interceptors.ts +54 -10
- package/src/iterators-utils.ts +116 -0
- package/src/schedule-client.ts +541 -0
- package/src/schedule-helpers.ts +414 -0
- package/src/schedule-types.ts +866 -0
- package/src/types.ts +12 -3
- package/src/workflow-client.ts +178 -180
- package/src/workflow-options.ts +12 -1
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScheduleOverlapPolicy = exports.DAYS_OF_WEEK = exports.MONTHS = void 0;
|
|
4
|
+
const type_helpers_1 = require("@temporalio/common/lib/type-helpers");
|
|
5
|
+
// Invariant: An existing ScheduleDescription can be used as template to create a new Schedule
|
|
6
|
+
(0, type_helpers_1.checkExtends)();
|
|
7
|
+
// Invariant: An existing ScheduleDescription can be used as template to update that Schedule
|
|
8
|
+
(0, type_helpers_1.checkExtends)();
|
|
9
|
+
// Invariant: An existing ScheduleSpec can be used as is to create or update a Schedule
|
|
10
|
+
(0, type_helpers_1.checkExtends)();
|
|
11
|
+
/** @experimental */
|
|
12
|
+
exports.MONTHS = [
|
|
13
|
+
'JANUARY',
|
|
14
|
+
'FEBRUARY',
|
|
15
|
+
'MARCH',
|
|
16
|
+
'APRIL',
|
|
17
|
+
'MAY',
|
|
18
|
+
'JUNE',
|
|
19
|
+
'JULY',
|
|
20
|
+
'AUGUST',
|
|
21
|
+
'SEPTEMBER',
|
|
22
|
+
'OCTOBER',
|
|
23
|
+
'NOVEMBER',
|
|
24
|
+
'DECEMBER',
|
|
25
|
+
];
|
|
26
|
+
/** @experimental */
|
|
27
|
+
exports.DAYS_OF_WEEK = ['SUNDAY', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY'];
|
|
28
|
+
// Invariant: an existing ScheduleDescriptionAction can be used as is to create or update a schedule
|
|
29
|
+
(0, type_helpers_1.checkExtends)();
|
|
30
|
+
/**
|
|
31
|
+
* Policy for overlapping Actions.
|
|
32
|
+
*
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
var ScheduleOverlapPolicy;
|
|
36
|
+
(function (ScheduleOverlapPolicy) {
|
|
37
|
+
/**
|
|
38
|
+
* Use server default (currently SKIP).
|
|
39
|
+
*
|
|
40
|
+
* FIXME: remove this field if this issue is implemented: https://github.com/temporalio/temporal/issues/3240
|
|
41
|
+
*/
|
|
42
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["UNSPECIFIED"] = 0] = "UNSPECIFIED";
|
|
43
|
+
/**
|
|
44
|
+
* Don't start a new Action.
|
|
45
|
+
*/
|
|
46
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["SKIP"] = 1] = "SKIP";
|
|
47
|
+
/**
|
|
48
|
+
* Start another Action as soon as the current Action completes, but only buffer one Action in this way. If another
|
|
49
|
+
* Action is supposed to start, but one Action is running and one is already buffered, then only the buffered one will
|
|
50
|
+
* be started after the running Action finishes.
|
|
51
|
+
*/
|
|
52
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["BUFFER_ONE"] = 2] = "BUFFER_ONE";
|
|
53
|
+
/**
|
|
54
|
+
* Allows an unlimited number of Actions to buffer. They are started sequentially.
|
|
55
|
+
*/
|
|
56
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["BUFFER_ALL"] = 3] = "BUFFER_ALL";
|
|
57
|
+
/**
|
|
58
|
+
* Cancels the running Action, and then starts the new Action once the cancelled one completes.
|
|
59
|
+
*/
|
|
60
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["CANCEL_OTHER"] = 4] = "CANCEL_OTHER";
|
|
61
|
+
/**
|
|
62
|
+
* Terminate the running Action and start the new Action immediately.
|
|
63
|
+
*/
|
|
64
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["TERMINATE_OTHER"] = 5] = "TERMINATE_OTHER";
|
|
65
|
+
/**
|
|
66
|
+
* Allow any number of Actions to start immediately.
|
|
67
|
+
*
|
|
68
|
+
* This is the only policy under which multiple Actions can run concurrently.
|
|
69
|
+
*/
|
|
70
|
+
ScheduleOverlapPolicy[ScheduleOverlapPolicy["ALLOW_ALL"] = 6] = "ALLOW_ALL";
|
|
71
|
+
})(ScheduleOverlapPolicy = exports.ScheduleOverlapPolicy || (exports.ScheduleOverlapPolicy = {}));
|
|
72
|
+
(0, type_helpers_1.checkExtends)();
|
|
73
|
+
(0, type_helpers_1.checkExtends)();
|
|
74
|
+
//# sourceMappingURL=schedule-types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schedule-types.js","sourceRoot":"","sources":["../src/schedule-types.ts"],"names":[],"mappings":";;;AAAA,sEAA+F;AAoU/F,8FAA8F;AAC9F,IAAA,2BAAY,GAAwC,CAAC;AAErD,6FAA6F;AAC7F,IAAA,2BAAY,GAA8C,CAAC;AAyI3D,uFAAuF;AACvF,IAAA,2BAAY,GAAyC,CAAC;AAwOtD,oBAAoB;AACP,QAAA,MAAM,GAAG;IACpB,SAAS;IACT,UAAU;IACV,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,MAAM;IACN,QAAQ;IACR,WAAW;IACX,SAAS;IACT,UAAU;IACV,UAAU;CACF,CAAC;AAKX,oBAAoB;AACP,QAAA,YAAY,GAAG,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAU,CAAC;AA0DpH,oGAAoG;AACpG,IAAA,2BAAY,GAAoD,CAAC;AAWjE;;;;GAIG;AACH,IAAY,qBAyCX;AAzCD,WAAY,qBAAqB;IAC/B;;;;OAIG;IACH,+EAAe,CAAA;IAEf;;OAEG;IACH,iEAAI,CAAA;IAEJ;;;;OAIG;IACH,6EAAU,CAAA;IAEV;;OAEG;IACH,6EAAU,CAAA;IAEV;;OAEG;IACH,iFAAY,CAAA;IAEZ;;OAEG;IACH,uFAAe,CAAA;IAEf;;;;OAIG;IACH,2EAAS,CAAA;AACX,CAAC,EAzCW,qBAAqB,GAArB,6BAAqB,KAArB,6BAAqB,QAyChC;AAID,IAAA,2BAAY,GAGT,CAAC;AACJ,IAAA,2BAAY,GAGT,CAAC"}
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type * as grpc from '@grpc/grpc-js';
|
|
1
2
|
import type { SearchAttributes } from '@temporalio/common';
|
|
2
3
|
import * as proto from '@temporalio/proto';
|
|
3
|
-
import
|
|
4
|
+
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
4
5
|
export interface WorkflowExecution {
|
|
5
6
|
workflowId: string;
|
|
6
7
|
runId?: string;
|
|
@@ -8,10 +9,11 @@ export interface WorkflowExecution {
|
|
|
8
9
|
export declare type StartWorkflowExecutionRequest = proto.temporal.api.workflowservice.v1.IStartWorkflowExecutionRequest;
|
|
9
10
|
export declare type GetWorkflowExecutionHistoryRequest = proto.temporal.api.workflowservice.v1.IGetWorkflowExecutionHistoryRequest;
|
|
10
11
|
export declare type DescribeWorkflowExecutionResponse = proto.temporal.api.workflowservice.v1.IDescribeWorkflowExecutionResponse;
|
|
12
|
+
export declare type RawWorkflowExecutionInfo = proto.temporal.api.workflow.v1.IWorkflowExecutionInfo;
|
|
11
13
|
export declare type TerminateWorkflowExecutionResponse = proto.temporal.api.workflowservice.v1.ITerminateWorkflowExecutionResponse;
|
|
12
14
|
export declare type RequestCancelWorkflowExecutionResponse = proto.temporal.api.workflowservice.v1.IRequestCancelWorkflowExecutionResponse;
|
|
13
15
|
export declare type WorkflowExecutionStatusName = 'UNSPECIFIED' | 'RUNNING' | 'COMPLETED' | 'FAILED' | 'CANCELLED' | 'TERMINATED' | 'CONTINUED_AS_NEW' | 'TIMED_OUT' | 'UNKNOWN';
|
|
14
|
-
export interface
|
|
16
|
+
export interface WorkflowExecutionInfo {
|
|
15
17
|
type: string;
|
|
16
18
|
workflowId: string;
|
|
17
19
|
runId: string;
|
|
@@ -27,8 +29,11 @@ export interface WorkflowExecutionDescription {
|
|
|
27
29
|
memo?: Record<string, unknown>;
|
|
28
30
|
searchAttributes: SearchAttributes;
|
|
29
31
|
parentExecution?: Required<proto.temporal.api.common.v1.IWorkflowExecution>;
|
|
30
|
-
raw:
|
|
32
|
+
raw: RawWorkflowExecutionInfo;
|
|
31
33
|
}
|
|
34
|
+
export declare type WorkflowExecutionDescription = Replace<WorkflowExecutionInfo, {
|
|
35
|
+
raw: DescribeWorkflowExecutionResponse;
|
|
36
|
+
}>;
|
|
32
37
|
export declare type WorkflowService = proto.temporal.api.workflowservice.v1.WorkflowService;
|
|
33
38
|
export declare const WorkflowService: typeof proto.temporal.api.workflowservice.v1.WorkflowService;
|
|
34
39
|
export declare type OperatorService = proto.temporal.api.operatorservice.v1.OperatorService;
|
package/lib/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,yDAA2C;AAqD5B,uBAAe,GAAK,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,iBAAC;AAE1D,uBAAe,GAAK,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,iBAAC;AAElD,qBAAa,GAAK,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAC"}
|
package/lib/workflow-client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { status as grpcStatus } from '@grpc/grpc-js';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
2
|
+
import { BaseWorkflowHandle, HistoryAndWorkflowId, QueryDefinition, WithWorkflowArgs, Workflow, WorkflowResultType } from '@temporalio/common';
|
|
3
|
+
import { History } from '@temporalio/common/lib/proto-utils';
|
|
5
4
|
import { temporal } from '@temporalio/proto';
|
|
6
|
-
import { WorkflowCancelInput,
|
|
7
|
-
import {
|
|
8
|
-
import { WorkflowOptions, WorkflowSignalWithStartOptions } from './workflow-options';
|
|
5
|
+
import { WorkflowCancelInput, WorkflowClientInterceptor, WorkflowClientInterceptors, WorkflowDescribeInput, WorkflowQueryInput, WorkflowSignalInput, WorkflowSignalWithStartInput, WorkflowStartInput, WorkflowTerminateInput } from './interceptors';
|
|
6
|
+
import { DescribeWorkflowExecutionResponse, RequestCancelWorkflowExecutionResponse, TerminateWorkflowExecutionResponse, WorkflowExecution, WorkflowExecutionDescription, WorkflowExecutionInfo, WorkflowService } from './types';
|
|
7
|
+
import { WorkflowOptions, WorkflowSignalWithStartOptions, WorkflowStartOptions } from './workflow-options';
|
|
8
|
+
import { BaseClient, BaseClientOptions, LoadedWithDefaults } from './base-client';
|
|
9
9
|
/**
|
|
10
10
|
* A client side handle to a single Workflow instance.
|
|
11
11
|
* It can be used to start, signal, query, wait for completion, terminate and cancel a Workflow execution.
|
|
@@ -67,6 +67,10 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
|
|
|
67
67
|
* Describe the current workflow execution
|
|
68
68
|
*/
|
|
69
69
|
describe(): Promise<WorkflowExecutionDescription>;
|
|
70
|
+
/**
|
|
71
|
+
* Return a workflow execution's history
|
|
72
|
+
*/
|
|
73
|
+
fetchHistory(): Promise<History>;
|
|
70
74
|
/**
|
|
71
75
|
* Readonly accessor to the underlying WorkflowClient
|
|
72
76
|
*/
|
|
@@ -95,37 +99,13 @@ export interface WorkflowHandleWithSignaledRunId<T extends Workflow = Workflow>
|
|
|
95
99
|
*/
|
|
96
100
|
readonly signaledRunId: string;
|
|
97
101
|
}
|
|
98
|
-
export interface WorkflowClientOptions {
|
|
99
|
-
/**
|
|
100
|
-
* {@link DataConverter} or {@link LoadedDataConverter} to use for serializing and deserializing payloads
|
|
101
|
-
*/
|
|
102
|
-
dataConverter?: DataConverter | LoadedDataConverter;
|
|
102
|
+
export interface WorkflowClientOptions extends BaseClientOptions {
|
|
103
103
|
/**
|
|
104
104
|
* Used to override and extend default Connection functionality
|
|
105
105
|
*
|
|
106
106
|
* Useful for injecting auth headers and tracing Workflow executions
|
|
107
107
|
*/
|
|
108
|
-
interceptors?: WorkflowClientInterceptors;
|
|
109
|
-
/**
|
|
110
|
-
* Identity to report to the server
|
|
111
|
-
*
|
|
112
|
-
* @default `${process.pid}@${os.hostname()}`
|
|
113
|
-
*/
|
|
114
|
-
identity?: string;
|
|
115
|
-
/**
|
|
116
|
-
* Connection to use to communicate with the server.
|
|
117
|
-
*
|
|
118
|
-
* By default `WorkflowClient` connects to localhost.
|
|
119
|
-
*
|
|
120
|
-
* Connections are expensive to construct and should be reused.
|
|
121
|
-
*/
|
|
122
|
-
connection?: ConnectionLike;
|
|
123
|
-
/**
|
|
124
|
-
* Server namespace
|
|
125
|
-
*
|
|
126
|
-
* @default default
|
|
127
|
-
*/
|
|
128
|
-
namespace?: string;
|
|
108
|
+
interceptors?: WorkflowClientInterceptors | WorkflowClientInterceptor[];
|
|
129
109
|
/**
|
|
130
110
|
* Should a query be rejected by closed and failed workflows
|
|
131
111
|
*
|
|
@@ -133,13 +113,7 @@ export interface WorkflowClientOptions {
|
|
|
133
113
|
*/
|
|
134
114
|
queryRejectCondition?: temporal.api.enums.v1.QueryRejectCondition;
|
|
135
115
|
}
|
|
136
|
-
export declare type
|
|
137
|
-
connection?: ConnectionLike;
|
|
138
|
-
}>;
|
|
139
|
-
export declare type LoadedWorkflowClientOptions = WorkflowClientOptionsWithDefaults & {
|
|
140
|
-
loadedDataConverter: LoadedDataConverter;
|
|
141
|
-
};
|
|
142
|
-
export declare function defaultWorkflowClientOptions(): WorkflowClientOptionsWithDefaults;
|
|
116
|
+
export declare type LoadedWorkflowClientOptions = LoadedWithDefaults<WorkflowClientOptions>;
|
|
143
117
|
/**
|
|
144
118
|
* Options for getting a result of a Workflow execution.
|
|
145
119
|
*/
|
|
@@ -167,7 +141,7 @@ export interface GetWorkflowHandleOptions extends WorkflowResultOptions {
|
|
|
167
141
|
interface WorkflowHandleOptions extends GetWorkflowHandleOptions {
|
|
168
142
|
workflowId: string;
|
|
169
143
|
runId?: string;
|
|
170
|
-
interceptors:
|
|
144
|
+
interceptors: WorkflowClientInterceptor[];
|
|
171
145
|
/**
|
|
172
146
|
* A runId to use for getting the workflow's result.
|
|
173
147
|
*
|
|
@@ -178,18 +152,63 @@ interface WorkflowHandleOptions extends GetWorkflowHandleOptions {
|
|
|
178
152
|
runIdForResult?: string;
|
|
179
153
|
}
|
|
180
154
|
/**
|
|
181
|
-
*
|
|
155
|
+
* An iterable list of WorkflowExecution, as returned by {@link WorkflowClient.list}.
|
|
182
156
|
*/
|
|
183
|
-
|
|
157
|
+
interface AsyncWorkflowListIterable extends AsyncIterable<WorkflowExecutionInfo> {
|
|
158
|
+
/**
|
|
159
|
+
* Return an iterable of histories corresponding to this iterable's WorkflowExecutions.
|
|
160
|
+
* Workflow histories will be fetched concurrently.
|
|
161
|
+
*
|
|
162
|
+
* Useful in batch replaying
|
|
163
|
+
*/
|
|
164
|
+
intoHistories: (intoHistoriesOptions?: IntoHistoriesOptions) => AsyncIterable<HistoryAndWorkflowId>;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Options for {@link WorkflowClient.list}
|
|
168
|
+
*/
|
|
169
|
+
export interface ListOptions {
|
|
170
|
+
/**
|
|
171
|
+
* Maximum number of results to fetch per page.
|
|
172
|
+
*
|
|
173
|
+
* @default depends on server config, typically 1000
|
|
174
|
+
*/
|
|
175
|
+
pageSize?: number;
|
|
176
|
+
/**
|
|
177
|
+
* Query string for matching and ordering the results
|
|
178
|
+
*/
|
|
179
|
+
query?: string;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Options for {@link WorkflowClient.list().intoHistories()}
|
|
183
|
+
*/
|
|
184
|
+
export interface IntoHistoriesOptions {
|
|
185
|
+
/**
|
|
186
|
+
* Maximum number of workflow histories to download concurrently.
|
|
187
|
+
*
|
|
188
|
+
* @default 5
|
|
189
|
+
*/
|
|
190
|
+
concurrency?: number;
|
|
191
|
+
/**
|
|
192
|
+
* Maximum number of workflow histories to buffer ahead, ready for consumption.
|
|
193
|
+
*
|
|
194
|
+
* It is recommended to set `bufferLimit` to a rasonnably low number if it is expected that the
|
|
195
|
+
* iterable may be stopped before reaching completion (for example, when implementing a fail fast
|
|
196
|
+
* bach replay test).
|
|
197
|
+
*
|
|
198
|
+
* Ignored unless `concurrency > 1`. No limit applies if set to `undefined`.
|
|
199
|
+
*
|
|
200
|
+
* @default unlimited
|
|
201
|
+
*/
|
|
202
|
+
bufferLimit?: number;
|
|
203
|
+
}
|
|
184
204
|
/**
|
|
185
205
|
* Client for starting Workflow executions and creating Workflow handles.
|
|
186
206
|
*
|
|
187
207
|
* Typically this client should not be instantiated directly, instead create the high level {@link Client} and use
|
|
188
208
|
* {@link Client.workflow} to interact with Workflows.
|
|
189
209
|
*/
|
|
190
|
-
export declare class WorkflowClient {
|
|
210
|
+
export declare class WorkflowClient extends BaseClient {
|
|
191
211
|
readonly options: LoadedWorkflowClientOptions;
|
|
192
|
-
readonly connection: ConnectionLike;
|
|
193
212
|
constructor(options?: WorkflowClientOptions);
|
|
194
213
|
/**
|
|
195
214
|
* Raw gRPC access to the Temporal service.
|
|
@@ -198,32 +217,19 @@ export declare class WorkflowClient {
|
|
|
198
217
|
* object.
|
|
199
218
|
*/
|
|
200
219
|
get workflowService(): WorkflowService;
|
|
201
|
-
protected get dataConverter(): LoadedDataConverter;
|
|
202
|
-
/**
|
|
203
|
-
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
204
|
-
*/
|
|
205
|
-
withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
|
|
206
|
-
/**
|
|
207
|
-
* Set metadata for any service requests executed in `fn`'s scope.
|
|
208
|
-
*
|
|
209
|
-
* @returns returned value of `fn`
|
|
210
|
-
*
|
|
211
|
-
* @see {@link Connection.withMetadata}
|
|
212
|
-
*/
|
|
213
|
-
withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
|
|
214
220
|
/**
|
|
215
221
|
* Start a new Workflow execution.
|
|
216
222
|
*
|
|
217
223
|
* @returns the execution's `runId`.
|
|
218
224
|
*/
|
|
219
|
-
protected _start<T extends Workflow>(workflowTypeOrFunc: string | T, options: WithWorkflowArgs<T, WorkflowOptions>, interceptors:
|
|
225
|
+
protected _start<T extends Workflow>(workflowTypeOrFunc: string | T, options: WithWorkflowArgs<T, WorkflowOptions>, interceptors: WorkflowClientInterceptor[]): Promise<string>;
|
|
220
226
|
/**
|
|
221
227
|
* Sends a signal to a running Workflow or starts a new one if not already running and immediately signals it.
|
|
222
228
|
* Useful when you're unsure of the Workflows' run state.
|
|
223
229
|
*
|
|
224
230
|
* @returns the runId of the Workflow
|
|
225
231
|
*/
|
|
226
|
-
protected _signalWithStart<T extends Workflow, SA extends any[]>(workflowTypeOrFunc: string | T, options: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SA>>, interceptors:
|
|
232
|
+
protected _signalWithStart<T extends Workflow, SA extends any[]>(workflowTypeOrFunc: string | T, options: WithWorkflowArgs<T, WorkflowSignalWithStartOptions<SA>>, interceptors: WorkflowClientInterceptor[]): Promise<string>;
|
|
227
233
|
/**
|
|
228
234
|
* Start a new Workflow execution.
|
|
229
235
|
*
|
|
@@ -315,6 +321,17 @@ export declare class WorkflowClient {
|
|
|
315
321
|
* methods like `handle.describe()` will throw a {@link WorkflowNotFoundError} error.
|
|
316
322
|
*/
|
|
317
323
|
getHandle<T extends Workflow>(workflowId: string, runId?: string, options?: GetWorkflowHandleOptions): WorkflowHandle<T>;
|
|
324
|
+
protected _list(options?: ListOptions): AsyncIterable<WorkflowExecutionInfo>;
|
|
325
|
+
/**
|
|
326
|
+
* List workflows by given `query`.
|
|
327
|
+
*
|
|
328
|
+
* ⚠️ To use advanced query functionality, as of the 1.18 server release, you must use Elasticsearch based visibility.
|
|
329
|
+
*
|
|
330
|
+
* More info on the concept of "visibility" and the query syntax on the Temporal documentation site:
|
|
331
|
+
* https://docs.temporal.io/visibility
|
|
332
|
+
*/
|
|
333
|
+
list(options?: ListOptions): AsyncWorkflowListIterable;
|
|
334
|
+
protected getOrMakeInterceptors(workflowId: string, runId?: string): WorkflowClientInterceptor[];
|
|
318
335
|
}
|
|
319
336
|
export declare class QueryRejectedError extends Error {
|
|
320
337
|
readonly status: temporal.api.enums.v1.WorkflowExecutionStatus;
|
package/lib/workflow-client.js
CHANGED
|
@@ -1,32 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.QueryNotRegisteredError = exports.QueryRejectedError = exports.WorkflowClient =
|
|
3
|
+
exports.QueryNotRegisteredError = exports.QueryRejectedError = exports.WorkflowClient = void 0;
|
|
7
4
|
const grpc_js_1 = require("@grpc/grpc-js");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
8
6
|
const common_1 = require("@temporalio/common");
|
|
9
|
-
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
|
|
10
|
-
const common_2 = require("@temporalio/common");
|
|
11
|
-
const time_1 = require("@temporalio/common/lib/time");
|
|
12
7
|
const interceptors_1 = require("@temporalio/common/lib/interceptors");
|
|
8
|
+
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
|
|
13
9
|
const proto_1 = require("@temporalio/proto");
|
|
14
|
-
const os_1 = __importDefault(require("os"));
|
|
15
|
-
const uuid_1 = require("uuid");
|
|
16
|
-
const connection_1 = require("./connection");
|
|
17
10
|
const errors_1 = require("./errors");
|
|
18
11
|
const workflow_options_1 = require("./workflow-options");
|
|
12
|
+
const helpers_1 = require("./helpers");
|
|
13
|
+
const base_client_1 = require("./base-client");
|
|
14
|
+
const iterators_utils_1 = require("./iterators-utils");
|
|
19
15
|
function defaultWorkflowClientOptions() {
|
|
20
16
|
return {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
identity: `${process.pid}@${os_1.default.hostname()}`,
|
|
24
|
-
interceptors: {},
|
|
25
|
-
namespace: 'default',
|
|
17
|
+
...(0, base_client_1.defaultBaseClientOptions)(),
|
|
18
|
+
interceptors: [],
|
|
26
19
|
queryRejectCondition: proto_1.temporal.api.enums.v1.QueryRejectCondition.QUERY_REJECT_CONDITION_UNSPECIFIED,
|
|
27
20
|
};
|
|
28
21
|
}
|
|
29
|
-
exports.defaultWorkflowClientOptions = defaultWorkflowClientOptions;
|
|
30
22
|
function assertRequiredWorkflowOptions(opts) {
|
|
31
23
|
if (!opts.taskQueue) {
|
|
32
24
|
throw new TypeError('Missing WorkflowOptions.taskQueue');
|
|
@@ -45,15 +37,13 @@ function ensureArgs(opts) {
|
|
|
45
37
|
* Typically this client should not be instantiated directly, instead create the high level {@link Client} and use
|
|
46
38
|
* {@link Client.workflow} to interact with Workflows.
|
|
47
39
|
*/
|
|
48
|
-
class WorkflowClient {
|
|
40
|
+
class WorkflowClient extends base_client_1.BaseClient {
|
|
49
41
|
constructor(options) {
|
|
50
|
-
|
|
51
|
-
const dataConverter = options?.dataConverter;
|
|
52
|
-
const loadedDataConverter = (0, internal_non_workflow_1.isLoadedDataConverter)(dataConverter) ? dataConverter : (0, internal_non_workflow_1.loadDataConverter)(dataConverter);
|
|
42
|
+
super(options);
|
|
53
43
|
this.options = {
|
|
54
44
|
...defaultWorkflowClientOptions(),
|
|
55
45
|
...(0, internal_non_workflow_1.filterNullAndUndefined)(options ?? {}),
|
|
56
|
-
loadedDataConverter,
|
|
46
|
+
loadedDataConverter: this.dataConverter,
|
|
57
47
|
};
|
|
58
48
|
}
|
|
59
49
|
/**
|
|
@@ -65,25 +55,6 @@ class WorkflowClient {
|
|
|
65
55
|
get workflowService() {
|
|
66
56
|
return this.connection.workflowService;
|
|
67
57
|
}
|
|
68
|
-
get dataConverter() {
|
|
69
|
-
return this.options.loadedDataConverter;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
73
|
-
*/
|
|
74
|
-
async withDeadline(deadline, fn) {
|
|
75
|
-
return await this.connection.withDeadline(deadline, fn);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Set metadata for any service requests executed in `fn`'s scope.
|
|
79
|
-
*
|
|
80
|
-
* @returns returned value of `fn`
|
|
81
|
-
*
|
|
82
|
-
* @see {@link Connection.withMetadata}
|
|
83
|
-
*/
|
|
84
|
-
async withMetadata(metadata, fn) {
|
|
85
|
-
return await this.connection.withMetadata(metadata, fn);
|
|
86
|
-
}
|
|
87
58
|
/**
|
|
88
59
|
* Start a new Workflow execution.
|
|
89
60
|
*
|
|
@@ -127,8 +98,7 @@ class WorkflowClient {
|
|
|
127
98
|
*/
|
|
128
99
|
async start(workflowTypeOrFunc, options) {
|
|
129
100
|
const { workflowId } = options;
|
|
130
|
-
|
|
131
|
-
const interceptors = (this.options.interceptors.calls ?? []).map((ctor) => ctor({ workflowId }));
|
|
101
|
+
const interceptors = this.getOrMakeInterceptors(workflowId);
|
|
132
102
|
const runId = await this._start(workflowTypeOrFunc, { ...options, workflowId }, interceptors);
|
|
133
103
|
// runId is not used in handles created with `start*` calls because these
|
|
134
104
|
// handles should allow interacting with the workflow if it continues as new.
|
|
@@ -151,7 +121,7 @@ class WorkflowClient {
|
|
|
151
121
|
*/
|
|
152
122
|
async signalWithStart(workflowTypeOrFunc, options) {
|
|
153
123
|
const { workflowId } = options;
|
|
154
|
-
const interceptors =
|
|
124
|
+
const interceptors = this.getOrMakeInterceptors(workflowId);
|
|
155
125
|
const runId = await this._signalWithStart(workflowTypeOrFunc, options, interceptors);
|
|
156
126
|
// runId is not used in handles created with `start*` calls because these
|
|
157
127
|
// handles should allow interacting with the workflow if it continues as new.
|
|
@@ -173,7 +143,7 @@ class WorkflowClient {
|
|
|
173
143
|
*/
|
|
174
144
|
async execute(workflowTypeOrFunc, options) {
|
|
175
145
|
const { workflowId } = options;
|
|
176
|
-
const interceptors =
|
|
146
|
+
const interceptors = this.getOrMakeInterceptors(workflowId);
|
|
177
147
|
await this._start(workflowTypeOrFunc, options, interceptors);
|
|
178
148
|
return await this.result(workflowId, undefined, {
|
|
179
149
|
...options,
|
|
@@ -270,7 +240,7 @@ class WorkflowClient {
|
|
|
270
240
|
rethrowGrpcError(err, workflowExecution, fallbackMessage) {
|
|
271
241
|
if ((0, errors_1.isServerErrorResponse)(err)) {
|
|
272
242
|
if (err.code === grpc_js_1.status.NOT_FOUND) {
|
|
273
|
-
throw new
|
|
243
|
+
throw new common_1.WorkflowNotFoundError(err.details ?? 'Workflow not found', workflowExecution.workflowId, workflowExecution.runId);
|
|
274
244
|
}
|
|
275
245
|
throw new errors_1.ServiceError(fallbackMessage, { cause: err });
|
|
276
246
|
}
|
|
@@ -361,7 +331,7 @@ class WorkflowClient {
|
|
|
361
331
|
workflowExecutionTimeout: options.workflowExecutionTimeout,
|
|
362
332
|
workflowRunTimeout: options.workflowRunTimeout,
|
|
363
333
|
workflowTaskTimeout: options.workflowTaskTimeout,
|
|
364
|
-
retryPolicy: options.retry ? (0,
|
|
334
|
+
retryPolicy: options.retry ? (0, common_1.compileRetryPolicy)(options.retry) : undefined,
|
|
365
335
|
memo: options.memo ? { fields: await (0, internal_non_workflow_1.encodeMapToPayloads)(this.dataConverter, options.memo) } : undefined,
|
|
366
336
|
searchAttributes: options.searchAttributes
|
|
367
337
|
? {
|
|
@@ -400,7 +370,7 @@ class WorkflowClient {
|
|
|
400
370
|
workflowExecutionTimeout: opts.workflowExecutionTimeout,
|
|
401
371
|
workflowRunTimeout: opts.workflowRunTimeout,
|
|
402
372
|
workflowTaskTimeout: opts.workflowTaskTimeout,
|
|
403
|
-
retryPolicy: opts.retry ? (0,
|
|
373
|
+
retryPolicy: opts.retry ? (0, common_1.compileRetryPolicy)(opts.retry) : undefined,
|
|
404
374
|
memo: opts.memo ? { fields: await (0, internal_non_workflow_1.encodeMapToPayloads)(this.dataConverter, opts.memo) } : undefined,
|
|
405
375
|
searchAttributes: opts.searchAttributes
|
|
406
376
|
? {
|
|
@@ -416,7 +386,7 @@ class WorkflowClient {
|
|
|
416
386
|
}
|
|
417
387
|
catch (err) {
|
|
418
388
|
if (err.code === grpc_js_1.status.ALREADY_EXISTS) {
|
|
419
|
-
throw new
|
|
389
|
+
throw new common_1.WorkflowExecutionAlreadyStartedError('Workflow execution already started', opts.workflowId, workflowType);
|
|
420
390
|
}
|
|
421
391
|
this.rethrowGrpcError(err, { workflowId: opts.workflowId }, 'Failed to start Workflow');
|
|
422
392
|
}
|
|
@@ -510,32 +480,25 @@ class WorkflowClient {
|
|
|
510
480
|
const raw = await fn({
|
|
511
481
|
workflowExecution: { workflowId, runId },
|
|
512
482
|
});
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
? {
|
|
533
|
-
workflowId: raw.workflowExecutionInfo.parentExecution.workflowId,
|
|
534
|
-
runId: raw.workflowExecutionInfo.parentExecution.runId,
|
|
535
|
-
}
|
|
536
|
-
: undefined,
|
|
537
|
-
raw,
|
|
538
|
-
};
|
|
483
|
+
const info = await (0, helpers_1.executionInfoFromRaw)(raw.workflowExecutionInfo ?? {}, this.client.dataConverter);
|
|
484
|
+
info.raw = raw;
|
|
485
|
+
return info;
|
|
486
|
+
},
|
|
487
|
+
async fetchHistory() {
|
|
488
|
+
let nextPageToken = undefined;
|
|
489
|
+
const events = Array();
|
|
490
|
+
for (;;) {
|
|
491
|
+
const response = await this.client.workflowService.getWorkflowExecutionHistory({
|
|
492
|
+
nextPageToken,
|
|
493
|
+
namespace: this.client.options.namespace,
|
|
494
|
+
execution: { workflowId, runId },
|
|
495
|
+
});
|
|
496
|
+
events.push(...(response.history?.events ?? []));
|
|
497
|
+
nextPageToken = response.nextPageToken;
|
|
498
|
+
if (nextPageToken == null || nextPageToken.length === 0)
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
return proto_1.temporal.api.history.v1.History.create({ events });
|
|
539
502
|
},
|
|
540
503
|
async signal(def, ...args) {
|
|
541
504
|
const next = this.client._signalWorkflowHandler.bind(this.client);
|
|
@@ -579,7 +542,7 @@ class WorkflowClient {
|
|
|
579
542
|
* methods like `handle.describe()` will throw a {@link WorkflowNotFoundError} error.
|
|
580
543
|
*/
|
|
581
544
|
getHandle(workflowId, runId, options) {
|
|
582
|
-
const interceptors =
|
|
545
|
+
const interceptors = this.getOrMakeInterceptors(workflowId, runId);
|
|
583
546
|
return this._createWorkflowHandle({
|
|
584
547
|
workflowId,
|
|
585
548
|
runId,
|
|
@@ -589,6 +552,55 @@ class WorkflowClient {
|
|
|
589
552
|
followRuns: options?.followRuns ?? true,
|
|
590
553
|
});
|
|
591
554
|
}
|
|
555
|
+
async *_list(options) {
|
|
556
|
+
let nextPageToken = Buffer.alloc(0);
|
|
557
|
+
for (;;) {
|
|
558
|
+
const response = await this.workflowService.listWorkflowExecutions({
|
|
559
|
+
namespace: this.options.namespace,
|
|
560
|
+
query: options?.query,
|
|
561
|
+
nextPageToken,
|
|
562
|
+
pageSize: options?.pageSize,
|
|
563
|
+
});
|
|
564
|
+
// Not decoding memo payloads concurrently even though we could have to keep the lazy nature of this iterator.
|
|
565
|
+
// Decoding is done for `memo` fields which tend to be small.
|
|
566
|
+
// We might decide to change that based on user feedback.
|
|
567
|
+
for (const raw of response.executions) {
|
|
568
|
+
yield await (0, helpers_1.executionInfoFromRaw)(raw, this.dataConverter);
|
|
569
|
+
}
|
|
570
|
+
nextPageToken = response.nextPageToken;
|
|
571
|
+
if (nextPageToken == null || nextPageToken.length === 0)
|
|
572
|
+
break;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* List workflows by given `query`.
|
|
577
|
+
*
|
|
578
|
+
* ⚠️ To use advanced query functionality, as of the 1.18 server release, you must use Elasticsearch based visibility.
|
|
579
|
+
*
|
|
580
|
+
* More info on the concept of "visibility" and the query syntax on the Temporal documentation site:
|
|
581
|
+
* https://docs.temporal.io/visibility
|
|
582
|
+
*/
|
|
583
|
+
list(options) {
|
|
584
|
+
return {
|
|
585
|
+
[Symbol.asyncIterator]: () => this._list(options)[Symbol.asyncIterator](),
|
|
586
|
+
intoHistories: (intoHistoriesOptions) => {
|
|
587
|
+
return (0, iterators_utils_1.mapAsyncIterable)(this._list(options), async ({ workflowId, runId }) => ({
|
|
588
|
+
workflowId,
|
|
589
|
+
history: await this.getHandle(workflowId, runId)
|
|
590
|
+
.fetchHistory()
|
|
591
|
+
.catch((_) => undefined),
|
|
592
|
+
}), { concurrency: intoHistoriesOptions?.concurrency ?? 5 });
|
|
593
|
+
},
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
getOrMakeInterceptors(workflowId, runId) {
|
|
597
|
+
if (typeof this.options.interceptors === 'object' && 'calls' in this.options.interceptors) {
|
|
598
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
599
|
+
const factories = this.options.interceptors.calls ?? [];
|
|
600
|
+
return factories.map((ctor) => ctor({ workflowId, runId }));
|
|
601
|
+
}
|
|
602
|
+
return Array.isArray(this.options.interceptors) ? this.options.interceptors : [];
|
|
603
|
+
}
|
|
592
604
|
}
|
|
593
605
|
exports.WorkflowClient = WorkflowClient;
|
|
594
606
|
class QueryRejectedError extends Error {
|
|
@@ -607,30 +619,4 @@ class QueryNotRegisteredError extends Error {
|
|
|
607
619
|
}
|
|
608
620
|
}
|
|
609
621
|
exports.QueryNotRegisteredError = QueryNotRegisteredError;
|
|
610
|
-
function workflowStatusCodeToName(code) {
|
|
611
|
-
return workflowStatusCodeToNameInternal(code) ?? 'UNKNOWN';
|
|
612
|
-
}
|
|
613
|
-
/**
|
|
614
|
-
* Intentionally leave out `default` branch to get compilation errors when new values are added
|
|
615
|
-
*/
|
|
616
|
-
function workflowStatusCodeToNameInternal(code) {
|
|
617
|
-
switch (code) {
|
|
618
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_UNSPECIFIED:
|
|
619
|
-
return 'UNSPECIFIED';
|
|
620
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_RUNNING:
|
|
621
|
-
return 'RUNNING';
|
|
622
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_FAILED:
|
|
623
|
-
return 'FAILED';
|
|
624
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TIMED_OUT:
|
|
625
|
-
return 'TIMED_OUT';
|
|
626
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CANCELED:
|
|
627
|
-
return 'CANCELLED';
|
|
628
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_TERMINATED:
|
|
629
|
-
return 'TERMINATED';
|
|
630
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_COMPLETED:
|
|
631
|
-
return 'COMPLETED';
|
|
632
|
-
case proto_1.temporal.api.enums.v1.WorkflowExecutionStatus.WORKFLOW_EXECUTION_STATUS_CONTINUED_AS_NEW:
|
|
633
|
-
return 'CONTINUED_AS_NEW';
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
622
|
//# sourceMappingURL=workflow-client.js.map
|