@temporalio/client 1.2.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/async-completion-client.d.ts +16 -4
- package/lib/async-completion-client.js +19 -2
- package/lib/async-completion-client.js.map +1 -1
- package/lib/client.d.ts +92 -0
- package/lib/client.js +77 -0
- package/lib/client.js.map +1 -0
- package/lib/connection.d.ts +11 -3
- package/lib/connection.js +10 -1
- package/lib/connection.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +9 -1
- package/lib/types.d.ts +15 -14
- package/lib/types.js +28 -4
- package/lib/types.js.map +1 -1
- package/lib/workflow-client.d.ts +24 -9
- package/lib/workflow-client.js +32 -29
- package/lib/workflow-client.js.map +1 -1
- package/lib/workflow-options.d.ts +14 -3
- package/lib/workflow-options.js +0 -26
- package/lib/workflow-options.js.map +1 -1
- package/package.json +9 -9
- package/src/async-completion-client.ts +28 -6
- package/src/client.ts +151 -0
- package/src/connection.ts +20 -2
- package/src/index.ts +1 -0
- package/src/interceptors.ts +10 -1
- package/src/types.ts +18 -14
- package/src/workflow-client.ts +53 -40
- package/src/workflow-options.ts +19 -29
package/src/connection.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { RPCImpl } from 'protobufjs';
|
|
|
5
5
|
import { isServerErrorResponse, ServiceError } from './errors';
|
|
6
6
|
import { defaultGrpcRetryOptions, makeGrpcRetryInterceptor } from './grpc-retry';
|
|
7
7
|
import pkg from './pkg';
|
|
8
|
-
import { CallContext, Metadata, OperatorService, WorkflowService } from './types';
|
|
8
|
+
import { CallContext, HealthService, Metadata, OperatorService, WorkflowService } from './types';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* gRPC and Temporal Server connection options
|
|
@@ -63,7 +63,7 @@ export interface ConnectionOptions {
|
|
|
63
63
|
* Used either when connecting eagerly with {@link Connection.connect} or
|
|
64
64
|
* calling {@link Connection.ensureConnected}.
|
|
65
65
|
*
|
|
66
|
-
* @format {@link https://www.npmjs.com/package/ms | ms
|
|
66
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
67
67
|
* @default 10 seconds
|
|
68
68
|
*/
|
|
69
69
|
connectTimeout?: number | string;
|
|
@@ -146,7 +146,14 @@ export interface ConnectionCtorOptions {
|
|
|
146
146
|
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
|
|
147
147
|
*/
|
|
148
148
|
readonly workflowService: WorkflowService;
|
|
149
|
+
/**
|
|
150
|
+
* Raw gRPC access to the Temporal {@link https://github.com/temporalio/api/blob/ddf07ab9933e8230309850e3c579e1ff34b03f53/temporal/api/operatorservice/v1/service.proto | operator service}.
|
|
151
|
+
*/
|
|
149
152
|
readonly operatorService: OperatorService;
|
|
153
|
+
/**
|
|
154
|
+
* Raw gRPC access to the standard gRPC {@link https://github.com/grpc/grpc/blob/92f58c18a8da2728f571138c37760a721c8915a2/doc/health-checking.md | health service}.
|
|
155
|
+
*/
|
|
156
|
+
readonly healthService: HealthService;
|
|
150
157
|
readonly callContextStorage: AsyncLocalStorage<CallContext>;
|
|
151
158
|
}
|
|
152
159
|
|
|
@@ -181,6 +188,7 @@ export class Connection {
|
|
|
181
188
|
* {@link https://github.com/temporalio/api/blob/master/temporal/api/operatorservice/v1/service.proto | Operator service}
|
|
182
189
|
*/
|
|
183
190
|
public readonly operatorService: OperatorService;
|
|
191
|
+
public readonly healthService: HealthService;
|
|
184
192
|
readonly callContextStorage: AsyncLocalStorage<CallContext>;
|
|
185
193
|
|
|
186
194
|
protected static createCtorOptions(options?: ConnectionOptions): ConnectionCtorOptions {
|
|
@@ -214,12 +222,20 @@ export class Connection {
|
|
|
214
222
|
interceptors: optionsWithDefaults?.interceptors,
|
|
215
223
|
});
|
|
216
224
|
const operatorService = OperatorService.create(operatorRpcImpl, false, false);
|
|
225
|
+
const healthRpcImpl = this.generateRPCImplementation({
|
|
226
|
+
serviceName: 'grpc.health.v1.Health',
|
|
227
|
+
client,
|
|
228
|
+
callContextStorage,
|
|
229
|
+
interceptors: optionsWithDefaults?.interceptors,
|
|
230
|
+
});
|
|
231
|
+
const healthService = HealthService.create(healthRpcImpl, false, false);
|
|
217
232
|
|
|
218
233
|
return {
|
|
219
234
|
client,
|
|
220
235
|
callContextStorage,
|
|
221
236
|
workflowService,
|
|
222
237
|
operatorService,
|
|
238
|
+
healthService,
|
|
223
239
|
options: optionsWithDefaults,
|
|
224
240
|
};
|
|
225
241
|
}
|
|
@@ -282,12 +298,14 @@ export class Connection {
|
|
|
282
298
|
client,
|
|
283
299
|
workflowService,
|
|
284
300
|
operatorService,
|
|
301
|
+
healthService,
|
|
285
302
|
callContextStorage,
|
|
286
303
|
}: ConnectionCtorOptions) {
|
|
287
304
|
this.options = options;
|
|
288
305
|
this.client = client;
|
|
289
306
|
this.workflowService = workflowService;
|
|
290
307
|
this.operatorService = operatorService;
|
|
308
|
+
this.healthService = healthService;
|
|
291
309
|
this.callContextStorage = callContextStorage;
|
|
292
310
|
}
|
|
293
311
|
|
package/src/index.ts
CHANGED
|
@@ -28,6 +28,7 @@ export * from '@temporalio/internal-workflow-common/lib/errors';
|
|
|
28
28
|
export * from '@temporalio/internal-workflow-common/lib/interfaces';
|
|
29
29
|
export * from '@temporalio/internal-workflow-common/lib/workflow-handle';
|
|
30
30
|
export * from './async-completion-client';
|
|
31
|
+
export * from './client';
|
|
31
32
|
export { Connection, ConnectionOptions, ConnectionOptionsWithDefaults, LOCAL_TARGET } from './connection';
|
|
32
33
|
export * from './errors';
|
|
33
34
|
export * from './grpc-retry';
|
package/src/interceptors.ts
CHANGED
|
@@ -112,7 +112,7 @@ export interface WorkflowClientCallsInterceptor {
|
|
|
112
112
|
describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
-
interface WorkflowClientCallsInterceptorFactoryInput {
|
|
115
|
+
export interface WorkflowClientCallsInterceptorFactoryInput {
|
|
116
116
|
workflowId: string;
|
|
117
117
|
runId?: string;
|
|
118
118
|
}
|
|
@@ -130,3 +130,12 @@ export interface WorkflowClientCallsInterceptorFactory {
|
|
|
130
130
|
export interface WorkflowClientInterceptors {
|
|
131
131
|
calls?: WorkflowClientCallsInterceptorFactory[];
|
|
132
132
|
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Interceptors for any high-level SDK client.
|
|
136
|
+
*
|
|
137
|
+
* NOTE: Currently only for {@link WorkflowClient}. More will be added later as needed.
|
|
138
|
+
*/
|
|
139
|
+
export interface ClientInterceptors {
|
|
140
|
+
workflow?: WorkflowClientInterceptors;
|
|
141
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import type { SearchAttributes } from '@temporalio/internal-workflow-common';
|
|
2
|
-
import
|
|
2
|
+
import * as proto from '@temporalio/proto';
|
|
3
3
|
import type * as grpc from '@grpc/grpc-js';
|
|
4
|
-
import Long from 'long';
|
|
5
4
|
|
|
6
5
|
export interface WorkflowExecution {
|
|
7
6
|
workflowId: string;
|
|
8
7
|
runId?: string;
|
|
9
8
|
}
|
|
10
|
-
export type StartWorkflowExecutionRequest = temporal.api.workflowservice.v1.IStartWorkflowExecutionRequest;
|
|
11
|
-
export type GetWorkflowExecutionHistoryRequest =
|
|
12
|
-
|
|
13
|
-
export type
|
|
9
|
+
export type StartWorkflowExecutionRequest = proto.temporal.api.workflowservice.v1.IStartWorkflowExecutionRequest;
|
|
10
|
+
export type GetWorkflowExecutionHistoryRequest =
|
|
11
|
+
proto.temporal.api.workflowservice.v1.IGetWorkflowExecutionHistoryRequest;
|
|
12
|
+
export type DescribeWorkflowExecutionResponse =
|
|
13
|
+
proto.temporal.api.workflowservice.v1.IDescribeWorkflowExecutionResponse;
|
|
14
|
+
export type TerminateWorkflowExecutionResponse =
|
|
15
|
+
proto.temporal.api.workflowservice.v1.ITerminateWorkflowExecutionResponse;
|
|
14
16
|
export type RequestCancelWorkflowExecutionResponse =
|
|
15
|
-
temporal.api.workflowservice.v1.IRequestCancelWorkflowExecutionResponse;
|
|
17
|
+
proto.temporal.api.workflowservice.v1.IRequestCancelWorkflowExecutionResponse;
|
|
16
18
|
|
|
17
19
|
export type WorkflowExecutionStatusName =
|
|
18
20
|
| 'UNSPECIFIED'
|
|
@@ -30,21 +32,23 @@ export interface WorkflowExecutionDescription {
|
|
|
30
32
|
workflowId: string;
|
|
31
33
|
runId: string;
|
|
32
34
|
taskQueue: string;
|
|
33
|
-
status: { code: temporal.api.enums.v1.WorkflowExecutionStatus; name: WorkflowExecutionStatusName };
|
|
34
|
-
historyLength:
|
|
35
|
+
status: { code: proto.temporal.api.enums.v1.WorkflowExecutionStatus; name: WorkflowExecutionStatusName };
|
|
36
|
+
historyLength: number;
|
|
35
37
|
startTime: Date;
|
|
36
38
|
executionTime?: Date;
|
|
37
39
|
closeTime?: Date;
|
|
38
40
|
memo?: Record<string, unknown>;
|
|
39
41
|
searchAttributes: SearchAttributes;
|
|
40
|
-
parentExecution?: Required<temporal.api.common.v1.IWorkflowExecution>;
|
|
42
|
+
parentExecution?: Required<proto.temporal.api.common.v1.IWorkflowExecution>;
|
|
41
43
|
raw: DescribeWorkflowExecutionResponse;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
export type WorkflowService = temporal.api.workflowservice.v1.WorkflowService;
|
|
45
|
-
export const { WorkflowService } = temporal.api.workflowservice.v1;
|
|
46
|
-
export type OperatorService = temporal.api.operatorservice.v1.OperatorService;
|
|
47
|
-
export const { OperatorService } = temporal.api.operatorservice.v1;
|
|
46
|
+
export type WorkflowService = proto.temporal.api.workflowservice.v1.WorkflowService;
|
|
47
|
+
export const { WorkflowService } = proto.temporal.api.workflowservice.v1;
|
|
48
|
+
export type OperatorService = proto.temporal.api.operatorservice.v1.OperatorService;
|
|
49
|
+
export const { OperatorService } = proto.temporal.api.operatorservice.v1;
|
|
50
|
+
export type HealthService = proto.grpc.health.v1.Health;
|
|
51
|
+
export const { Health: HealthService } = proto.grpc.health.v1;
|
|
48
52
|
|
|
49
53
|
/**
|
|
50
54
|
* Mapping of string to valid gRPC metadata value
|
package/src/workflow-client.ts
CHANGED
|
@@ -18,6 +18,8 @@ import {
|
|
|
18
18
|
decodeOptionalFailureToOptionalError,
|
|
19
19
|
encodeMapToPayloads,
|
|
20
20
|
encodeToPayloads,
|
|
21
|
+
filterNullAndUndefined,
|
|
22
|
+
isLoadedDataConverter,
|
|
21
23
|
loadDataConverter,
|
|
22
24
|
} from '@temporalio/internal-non-workflow-common';
|
|
23
25
|
import {
|
|
@@ -118,7 +120,17 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
|
|
|
118
120
|
terminate(reason?: string): Promise<TerminateWorkflowExecutionResponse>;
|
|
119
121
|
|
|
120
122
|
/**
|
|
121
|
-
* Cancel a running Workflow
|
|
123
|
+
* Cancel a running Workflow.
|
|
124
|
+
*
|
|
125
|
+
* When a Workflow is cancelled, the root scope throws {@link CancelledFailure} with `message: 'Workflow canceled'`.
|
|
126
|
+
* That means that all cancellable scopes will throw `CancelledFailure`.
|
|
127
|
+
*
|
|
128
|
+
* Cancellation may be propagated to Activities depending on {@link ActivityOptions#cancellationType}, after which
|
|
129
|
+
* Activity calls may throw an {@link ActivityFailure}, and `isCancellation(error)` will be true (see {@link isCancellation}).
|
|
130
|
+
*
|
|
131
|
+
* Cancellation may be propagated to Child Workflows depending on {@link ChildWorkflowOptions#cancellationType}, after
|
|
132
|
+
* which calls to {@link executeChild} and {@link ChildWorkflowHandle#result} will throw, and `isCancellation(error)`
|
|
133
|
+
* will be true (see {@link isCancellation}).
|
|
122
134
|
*/
|
|
123
135
|
cancel(): Promise<RequestCancelWorkflowExecutionResponse>;
|
|
124
136
|
|
|
@@ -160,9 +172,9 @@ export interface WorkflowHandleWithSignaledRunId<T extends Workflow = Workflow>
|
|
|
160
172
|
|
|
161
173
|
export interface WorkflowClientOptions {
|
|
162
174
|
/**
|
|
163
|
-
* {@link DataConverter} to use for serializing and deserializing payloads
|
|
175
|
+
* {@link DataConverter} or {@link LoadedDataConverter} to use for serializing and deserializing payloads
|
|
164
176
|
*/
|
|
165
|
-
dataConverter?: DataConverter;
|
|
177
|
+
dataConverter?: DataConverter | LoadedDataConverter;
|
|
166
178
|
|
|
167
179
|
/**
|
|
168
180
|
* Used to override and extend default Connection functionality
|
|
@@ -285,7 +297,10 @@ interface WorkflowHandleOptions extends GetWorkflowHandleOptions {
|
|
|
285
297
|
export type WorkflowStartOptions<T extends Workflow = Workflow> = WithWorkflowArgs<T, WorkflowOptions>;
|
|
286
298
|
|
|
287
299
|
/**
|
|
288
|
-
* Client for starting Workflow executions and creating Workflow handles
|
|
300
|
+
* Client for starting Workflow executions and creating Workflow handles.
|
|
301
|
+
*
|
|
302
|
+
* Typically this client should not be instantiated directly, instead create the high level {@link Client} and use
|
|
303
|
+
* {@link Client.workflow} to interact with Workflows.
|
|
289
304
|
*/
|
|
290
305
|
export class WorkflowClient {
|
|
291
306
|
public readonly options: LoadedWorkflowClientOptions;
|
|
@@ -293,22 +308,29 @@ export class WorkflowClient {
|
|
|
293
308
|
|
|
294
309
|
constructor(options?: WorkflowClientOptions) {
|
|
295
310
|
this.connection = options?.connection ?? Connection.lazy();
|
|
311
|
+
const dataConverter = options?.dataConverter;
|
|
312
|
+
const loadedDataConverter = isLoadedDataConverter(dataConverter) ? dataConverter : loadDataConverter(dataConverter);
|
|
296
313
|
this.options = {
|
|
297
314
|
...defaultWorkflowClientOptions(),
|
|
298
|
-
...options,
|
|
299
|
-
loadedDataConverter
|
|
315
|
+
...filterNullAndUndefined(options ?? {}),
|
|
316
|
+
loadedDataConverter,
|
|
300
317
|
};
|
|
301
318
|
}
|
|
302
319
|
|
|
303
320
|
/**
|
|
304
321
|
* Raw gRPC access to the Temporal service.
|
|
305
322
|
*
|
|
306
|
-
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made
|
|
323
|
+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
|
|
324
|
+
* object.
|
|
307
325
|
*/
|
|
308
326
|
get workflowService(): WorkflowService {
|
|
309
327
|
return this.connection.workflowService;
|
|
310
328
|
}
|
|
311
329
|
|
|
330
|
+
protected get dataConverter(): LoadedDataConverter {
|
|
331
|
+
return this.options.loadedDataConverter;
|
|
332
|
+
}
|
|
333
|
+
|
|
312
334
|
/**
|
|
313
335
|
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
314
336
|
*/
|
|
@@ -377,7 +399,7 @@ export class WorkflowClient {
|
|
|
377
399
|
headers: {},
|
|
378
400
|
workflowType,
|
|
379
401
|
signalName: typeof signal === 'string' ? signal : signal.name,
|
|
380
|
-
signalArgs,
|
|
402
|
+
signalArgs: signalArgs ?? [],
|
|
381
403
|
});
|
|
382
404
|
}
|
|
383
405
|
|
|
@@ -409,15 +431,15 @@ export class WorkflowClient {
|
|
|
409
431
|
}
|
|
410
432
|
|
|
411
433
|
/**
|
|
412
|
-
* Sends a
|
|
413
|
-
* Useful when you're unsure
|
|
434
|
+
* Sends a Signal to a running Workflow or starts a new one if not already running and immediately Signals it.
|
|
435
|
+
* Useful when you're unsure whether the Workflow has been started.
|
|
414
436
|
*
|
|
415
|
-
* @returns a WorkflowHandle to the started Workflow
|
|
437
|
+
* @returns a {@link WorkflowHandle} to the started Workflow
|
|
416
438
|
*/
|
|
417
|
-
public async signalWithStart<
|
|
418
|
-
workflowTypeOrFunc: string |
|
|
419
|
-
options: WithWorkflowArgs<
|
|
420
|
-
): Promise<WorkflowHandleWithSignaledRunId<
|
|
439
|
+
public async signalWithStart<WorkflowFn extends Workflow, SignalArgs extends any[] = []>(
|
|
440
|
+
workflowTypeOrFunc: string | WorkflowFn,
|
|
441
|
+
options: WithWorkflowArgs<WorkflowFn, WorkflowSignalWithStartOptions<SignalArgs>>
|
|
442
|
+
): Promise<WorkflowHandleWithSignaledRunId<WorkflowFn>> {
|
|
421
443
|
const { workflowId } = options;
|
|
422
444
|
const interceptors = (this.options.interceptors.calls ?? []).map((ctor) => ctor({ workflowId }));
|
|
423
445
|
const runId = await this._signalWithStart(workflowTypeOrFunc, options, interceptors);
|
|
@@ -430,7 +452,7 @@ export class WorkflowClient {
|
|
|
430
452
|
runIdForResult: runId,
|
|
431
453
|
interceptors,
|
|
432
454
|
followRuns: options.followRuns ?? true,
|
|
433
|
-
}) as WorkflowHandleWithSignaledRunId<
|
|
455
|
+
}) as WorkflowHandleWithSignaledRunId<WorkflowFn>; // Cast is safe because we know we add the signaledRunId below
|
|
434
456
|
(handle as any) /* readonly */.signaledRunId = runId;
|
|
435
457
|
return handle;
|
|
436
458
|
}
|
|
@@ -506,7 +528,7 @@ export class WorkflowClient {
|
|
|
506
528
|
// Note that we can only return one value from our workflow function in JS.
|
|
507
529
|
// Ignore any other payloads in result
|
|
508
530
|
const [result] = await decodeArrayFromPayloads(
|
|
509
|
-
this.
|
|
531
|
+
this.dataConverter,
|
|
510
532
|
ev.workflowExecutionCompletedEventAttributes.result?.payloads
|
|
511
533
|
);
|
|
512
534
|
return result as any;
|
|
@@ -519,14 +541,14 @@ export class WorkflowClient {
|
|
|
519
541
|
const { failure, retryState } = ev.workflowExecutionFailedEventAttributes;
|
|
520
542
|
throw new WorkflowFailedError(
|
|
521
543
|
'Workflow execution failed',
|
|
522
|
-
await decodeOptionalFailureToOptionalError(this.
|
|
544
|
+
await decodeOptionalFailureToOptionalError(this.dataConverter, failure),
|
|
523
545
|
retryState ?? RetryState.RETRY_STATE_UNSPECIFIED
|
|
524
546
|
);
|
|
525
547
|
} else if (ev.workflowExecutionCanceledEventAttributes) {
|
|
526
548
|
const failure = new CancelledFailure(
|
|
527
549
|
'Workflow canceled',
|
|
528
550
|
await decodeArrayFromPayloads(
|
|
529
|
-
this.
|
|
551
|
+
this.dataConverter,
|
|
530
552
|
ev.workflowExecutionCanceledEventAttributes.details?.payloads
|
|
531
553
|
)
|
|
532
554
|
);
|
|
@@ -606,7 +628,7 @@ export class WorkflowClient {
|
|
|
606
628
|
execution: input.workflowExecution,
|
|
607
629
|
query: {
|
|
608
630
|
queryType: input.queryType,
|
|
609
|
-
queryArgs: { payloads: await encodeToPayloads(this.
|
|
631
|
+
queryArgs: { payloads: await encodeToPayloads(this.dataConverter, ...input.args) },
|
|
610
632
|
header: { fields: input.headers },
|
|
611
633
|
},
|
|
612
634
|
});
|
|
@@ -626,7 +648,7 @@ export class WorkflowClient {
|
|
|
626
648
|
throw new TypeError('Invalid response from server');
|
|
627
649
|
}
|
|
628
650
|
// We ignore anything but the first result
|
|
629
|
-
return await decodeFromPayloadsAtIndex(this.
|
|
651
|
+
return await decodeFromPayloadsAtIndex(this.dataConverter, 0, response.queryResult?.payloads);
|
|
630
652
|
}
|
|
631
653
|
|
|
632
654
|
/**
|
|
@@ -644,7 +666,7 @@ export class WorkflowClient {
|
|
|
644
666
|
// control is unused,
|
|
645
667
|
signalName: input.signalName,
|
|
646
668
|
header: { fields: input.headers },
|
|
647
|
-
input: { payloads: await encodeToPayloads(this.
|
|
669
|
+
input: { payloads: await encodeToPayloads(this.dataConverter, ...input.args) },
|
|
648
670
|
});
|
|
649
671
|
} catch (err) {
|
|
650
672
|
this.rethrowGrpcError(err, input.workflowExecution, 'Failed to signal Workflow');
|
|
@@ -667,9 +689,9 @@ export class WorkflowClient {
|
|
|
667
689
|
workflowId: options.workflowId,
|
|
668
690
|
workflowIdReusePolicy: options.workflowIdReusePolicy,
|
|
669
691
|
workflowType: { name: workflowType },
|
|
670
|
-
input: { payloads: await encodeToPayloads(this.
|
|
692
|
+
input: { payloads: await encodeToPayloads(this.dataConverter, ...options.args) },
|
|
671
693
|
signalName,
|
|
672
|
-
signalInput: { payloads: await encodeToPayloads(this.
|
|
694
|
+
signalInput: { payloads: await encodeToPayloads(this.dataConverter, ...signalArgs) },
|
|
673
695
|
taskQueue: {
|
|
674
696
|
kind: temporal.api.enums.v1.TaskQueueKind.TASK_QUEUE_KIND_UNSPECIFIED,
|
|
675
697
|
name: options.taskQueue,
|
|
@@ -678,9 +700,7 @@ export class WorkflowClient {
|
|
|
678
700
|
workflowRunTimeout: options.workflowRunTimeout,
|
|
679
701
|
workflowTaskTimeout: options.workflowTaskTimeout,
|
|
680
702
|
retryPolicy: options.retry ? compileRetryPolicy(options.retry) : undefined,
|
|
681
|
-
memo: options.memo
|
|
682
|
-
? { fields: await encodeMapToPayloads(this.options.loadedDataConverter, options.memo) }
|
|
683
|
-
: undefined,
|
|
703
|
+
memo: options.memo ? { fields: await encodeMapToPayloads(this.dataConverter, options.memo) } : undefined,
|
|
684
704
|
searchAttributes: options.searchAttributes
|
|
685
705
|
? {
|
|
686
706
|
indexedFields: mapToPayloads(searchAttributePayloadConverter, options.searchAttributes),
|
|
@@ -710,7 +730,7 @@ export class WorkflowClient {
|
|
|
710
730
|
workflowId: opts.workflowId,
|
|
711
731
|
workflowIdReusePolicy: opts.workflowIdReusePolicy,
|
|
712
732
|
workflowType: { name: workflowType },
|
|
713
|
-
input: { payloads: await encodeToPayloads(this.
|
|
733
|
+
input: { payloads: await encodeToPayloads(this.dataConverter, ...opts.args) },
|
|
714
734
|
taskQueue: {
|
|
715
735
|
kind: temporal.api.enums.v1.TaskQueueKind.TASK_QUEUE_KIND_UNSPECIFIED,
|
|
716
736
|
name: opts.taskQueue,
|
|
@@ -719,7 +739,7 @@ export class WorkflowClient {
|
|
|
719
739
|
workflowRunTimeout: opts.workflowRunTimeout,
|
|
720
740
|
workflowTaskTimeout: opts.workflowTaskTimeout,
|
|
721
741
|
retryPolicy: opts.retry ? compileRetryPolicy(opts.retry) : undefined,
|
|
722
|
-
memo: opts.memo ? { fields: await encodeMapToPayloads(this.
|
|
742
|
+
memo: opts.memo ? { fields: await encodeMapToPayloads(this.dataConverter, opts.memo) } : undefined,
|
|
723
743
|
searchAttributes: opts.searchAttributes
|
|
724
744
|
? {
|
|
725
745
|
indexedFields: mapToPayloads(searchAttributePayloadConverter, opts.searchAttributes),
|
|
@@ -757,9 +777,7 @@ export class WorkflowClient {
|
|
|
757
777
|
identity: this.options.identity,
|
|
758
778
|
...input,
|
|
759
779
|
details: {
|
|
760
|
-
payloads: input.details
|
|
761
|
-
? await encodeToPayloads(this.options.loadedDataConverter, ...input.details)
|
|
762
|
-
: undefined,
|
|
780
|
+
payloads: input.details ? await encodeToPayloads(this.dataConverter, ...input.details) : undefined,
|
|
763
781
|
},
|
|
764
782
|
firstExecutionRunId: input.firstExecutionRunId,
|
|
765
783
|
});
|
|
@@ -853,17 +871,12 @@ export class WorkflowClient {
|
|
|
853
871
|
code: raw.workflowExecutionInfo!.status!,
|
|
854
872
|
name: workflowStatusCodeToName(raw.workflowExecutionInfo!.status!),
|
|
855
873
|
},
|
|
856
|
-
//
|
|
857
|
-
|
|
858
|
-
// Max history length is 50k, which is much less than Number.MAX_SAFE_INTEGER
|
|
859
|
-
historyLength: raw.workflowExecutionInfo!.historyLength!,
|
|
874
|
+
// Safe to convert to number, max history length is 50k, which is much less than Number.MAX_SAFE_INTEGER
|
|
875
|
+
historyLength: raw.workflowExecutionInfo!.historyLength!.toNumber(),
|
|
860
876
|
startTime: tsToDate(raw.workflowExecutionInfo!.startTime!),
|
|
861
877
|
executionTime: optionalTsToDate(raw.workflowExecutionInfo!.executionTime),
|
|
862
878
|
closeTime: optionalTsToDate(raw.workflowExecutionInfo!.closeTime),
|
|
863
|
-
memo: await decodeMapFromPayloads(
|
|
864
|
-
this.client.options.loadedDataConverter,
|
|
865
|
-
raw.workflowExecutionInfo!.memo?.fields
|
|
866
|
-
),
|
|
879
|
+
memo: await decodeMapFromPayloads(this.client.dataConverter, raw.workflowExecutionInfo!.memo?.fields),
|
|
867
880
|
searchAttributes: mapFromPayloads(
|
|
868
881
|
searchAttributePayloadConverter,
|
|
869
882
|
raw.workflowExecutionInfo!.searchAttributes?.indexedFields ?? {}
|
package/src/workflow-options.ts
CHANGED
|
@@ -37,40 +37,30 @@ export interface WorkflowOptions extends CommonWorkflowOptions {
|
|
|
37
37
|
followRuns?: boolean;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export
|
|
40
|
+
export type WorkflowSignalWithStartOptions<SignalArgs extends any[] = []> = SignalArgs extends [any, ...any[]]
|
|
41
|
+
? WorkflowSignalWithStartOptionsWithArgs<SignalArgs>
|
|
42
|
+
: WorkflowSignalWithStartOptionsWithoutArgs<SignalArgs>;
|
|
43
|
+
|
|
44
|
+
export interface WorkflowSignalWithStartOptionsWithoutArgs<SignalArgs extends any[]> extends WorkflowOptions {
|
|
41
45
|
/**
|
|
42
46
|
* SignalDefinition or name of signal
|
|
43
47
|
*/
|
|
44
|
-
signal: SignalDefinition
|
|
48
|
+
signal: SignalDefinition | string;
|
|
49
|
+
|
|
45
50
|
/**
|
|
46
51
|
* Arguments to invoke the signal handler with
|
|
47
52
|
*/
|
|
48
|
-
signalArgs
|
|
53
|
+
signalArgs?: SignalArgs;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
//
|
|
63
|
-
// /**
|
|
64
|
-
// * Adds default values to `workflowId` and `workflowIdReusePolicy` to given workflow options.
|
|
65
|
-
// */
|
|
66
|
-
// export function addDefaults<T extends Workflow>(
|
|
67
|
-
// opts: WithWorkflowArgs<T, WorkflowOptions>
|
|
68
|
-
// ): WorkflowOptionsWithDefaults<T> {
|
|
69
|
-
// const { workflowId, args, ...rest } = opts;
|
|
70
|
-
// return {
|
|
71
|
-
// followRuns: true,
|
|
72
|
-
// args: args ?? [],
|
|
73
|
-
// workflowId: workflowId ?? uuid4(),
|
|
74
|
-
// ...rest,
|
|
75
|
-
// };
|
|
76
|
-
// }
|
|
56
|
+
export interface WorkflowSignalWithStartOptionsWithArgs<SignalArgs extends any[]> extends WorkflowOptions {
|
|
57
|
+
/**
|
|
58
|
+
* SignalDefinition or name of signal
|
|
59
|
+
*/
|
|
60
|
+
signal: SignalDefinition<SignalArgs> | string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Arguments to invoke the signal handler with
|
|
64
|
+
*/
|
|
65
|
+
signalArgs: SignalArgs;
|
|
66
|
+
}
|