@temporalio/client 1.4.3 → 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
package/src/interceptors.ts
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { Headers, Next } from '@temporalio/common';
|
|
8
8
|
import { temporal } from '@temporalio/proto';
|
|
9
|
+
import { CompiledScheduleOptions } from './schedule-types';
|
|
9
10
|
import {
|
|
10
11
|
DescribeWorkflowExecutionResponse,
|
|
11
12
|
RequestCancelWorkflowExecutionResponse,
|
|
@@ -16,7 +17,7 @@ import { CompiledWorkflowOptions } from './workflow-options';
|
|
|
16
17
|
|
|
17
18
|
export { Next, Headers };
|
|
18
19
|
|
|
19
|
-
/** Input for
|
|
20
|
+
/** Input for WorkflowClientInterceptor.start */
|
|
20
21
|
export interface WorkflowStartInput {
|
|
21
22
|
/** Name of Workflow to start */
|
|
22
23
|
readonly workflowType: string;
|
|
@@ -24,7 +25,7 @@ export interface WorkflowStartInput {
|
|
|
24
25
|
readonly options: CompiledWorkflowOptions;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
/** Input for
|
|
28
|
+
/** Input for WorkflowClientInterceptor.signal */
|
|
28
29
|
export interface WorkflowSignalInput {
|
|
29
30
|
readonly signalName: string;
|
|
30
31
|
readonly args: unknown[];
|
|
@@ -32,7 +33,7 @@ export interface WorkflowSignalInput {
|
|
|
32
33
|
readonly headers: Headers;
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
/** Input for
|
|
36
|
+
/** Input for WorkflowClientInterceptor.signalWithStart */
|
|
36
37
|
export interface WorkflowSignalWithStartInput {
|
|
37
38
|
readonly workflowType: string;
|
|
38
39
|
readonly signalName: string;
|
|
@@ -41,7 +42,7 @@ export interface WorkflowSignalWithStartInput {
|
|
|
41
42
|
readonly options: CompiledWorkflowOptions;
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
/** Input for
|
|
45
|
+
/** Input for WorkflowClientInterceptor.query */
|
|
45
46
|
export interface WorkflowQueryInput {
|
|
46
47
|
readonly queryType: string;
|
|
47
48
|
readonly args: unknown[];
|
|
@@ -50,7 +51,7 @@ export interface WorkflowQueryInput {
|
|
|
50
51
|
readonly headers: Headers;
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
/** Input for
|
|
54
|
+
/** Input for WorkflowClientInterceptor.terminate */
|
|
54
55
|
export interface WorkflowTerminateInput {
|
|
55
56
|
readonly workflowExecution: WorkflowExecution;
|
|
56
57
|
readonly reason?: string;
|
|
@@ -58,13 +59,13 @@ export interface WorkflowTerminateInput {
|
|
|
58
59
|
readonly firstExecutionRunId?: string;
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
/** Input for
|
|
62
|
+
/** Input for WorkflowClientInterceptor.cancel */
|
|
62
63
|
export interface WorkflowCancelInput {
|
|
63
64
|
readonly workflowExecution: WorkflowExecution;
|
|
64
65
|
readonly firstExecutionRunId?: string;
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
/** Input for
|
|
68
|
+
/** Input for WorkflowClientInterceptor.describe */
|
|
68
69
|
export interface WorkflowDescribeInput {
|
|
69
70
|
readonly workflowExecution: WorkflowExecution;
|
|
70
71
|
}
|
|
@@ -72,7 +73,7 @@ export interface WorkflowDescribeInput {
|
|
|
72
73
|
/**
|
|
73
74
|
* Implement any of these methods to intercept WorkflowClient outbound calls
|
|
74
75
|
*/
|
|
75
|
-
export interface
|
|
76
|
+
export interface WorkflowClientInterceptor {
|
|
76
77
|
/**
|
|
77
78
|
* Intercept a service call to startWorkflowExecution
|
|
78
79
|
*
|
|
@@ -112,6 +113,10 @@ export interface WorkflowClientCallsInterceptor {
|
|
|
112
113
|
describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
/** @deprecated: Use WorkflowClientInterceptor instead */
|
|
117
|
+
export type WorkflowClientCallsInterceptor = WorkflowClientInterceptor;
|
|
118
|
+
|
|
119
|
+
/** @deprecated */
|
|
115
120
|
export interface WorkflowClientCallsInterceptorFactoryInput {
|
|
116
121
|
workflowId: string;
|
|
117
122
|
runId?: string;
|
|
@@ -119,23 +124,62 @@ export interface WorkflowClientCallsInterceptorFactoryInput {
|
|
|
119
124
|
|
|
120
125
|
/**
|
|
121
126
|
* A function that takes {@link CompiledWorkflowOptions} and returns an interceptor
|
|
127
|
+
*
|
|
128
|
+
* @deprecated: Please define interceptors directly, without factory
|
|
122
129
|
*/
|
|
123
130
|
export interface WorkflowClientCallsInterceptorFactory {
|
|
131
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
124
132
|
(input: WorkflowClientCallsInterceptorFactoryInput): WorkflowClientCallsInterceptor;
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
/**
|
|
128
136
|
* A mapping of interceptor type of a list of factory functions
|
|
137
|
+
*
|
|
138
|
+
* @deprecated: Please define interceptors directly, without factory
|
|
129
139
|
*/
|
|
130
140
|
export interface WorkflowClientInterceptors {
|
|
141
|
+
/** @deprecated */
|
|
142
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
131
143
|
calls?: WorkflowClientCallsInterceptorFactory[];
|
|
132
144
|
}
|
|
133
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Implement any of these methods to intercept ScheduleClient outbound calls
|
|
148
|
+
*
|
|
149
|
+
* @experimental
|
|
150
|
+
*/
|
|
151
|
+
export interface ScheduleClientInterceptor {
|
|
152
|
+
/**
|
|
153
|
+
* Intercept a service call to CreateSchedule
|
|
154
|
+
*/
|
|
155
|
+
create?: (input: CreateScheduleInput, next: Next<this, 'create'>) => Promise<CreateScheduleOutput>;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Input for {@link ScheduleClientInterceptor.create}
|
|
160
|
+
*
|
|
161
|
+
* @experimental
|
|
162
|
+
*/
|
|
163
|
+
export interface CreateScheduleInput {
|
|
164
|
+
readonly headers: Headers;
|
|
165
|
+
readonly options: CompiledScheduleOptions;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export type CreateScheduleOutput = {
|
|
169
|
+
readonly conflictToken: Uint8Array;
|
|
170
|
+
};
|
|
171
|
+
|
|
134
172
|
/**
|
|
135
173
|
* Interceptors for any high-level SDK client.
|
|
136
174
|
*
|
|
137
|
-
* NOTE: Currently only for {@link WorkflowClient}. More will be added later as needed.
|
|
175
|
+
* NOTE: Currently only for {@link WorkflowClient} and {@link ScheduleClient}. More will be added later as needed.
|
|
138
176
|
*/
|
|
139
177
|
export interface ClientInterceptors {
|
|
140
|
-
|
|
178
|
+
// eslint-disable-next-line deprecation/deprecation
|
|
179
|
+
workflow?: WorkflowClientInterceptors | WorkflowClientInterceptor[];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @experimental
|
|
183
|
+
*/
|
|
184
|
+
schedule?: ScheduleClientInterceptor[];
|
|
141
185
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { EventEmitter, on, once } from 'node:events';
|
|
2
|
+
import { AbortController } from 'abort-controller';
|
|
3
|
+
|
|
4
|
+
export interface MapAsyncOptions {
|
|
5
|
+
/**
|
|
6
|
+
* How many items to map concurrently. If set to less than 2 (or not set), then items are not mapped concurrently.
|
|
7
|
+
*
|
|
8
|
+
* When items are mapped concurrently, mapped items are returned by the resulting iterator in the order they complete
|
|
9
|
+
* mapping, not the order in which the corresponding source items were obtained from the source iterator.
|
|
10
|
+
*
|
|
11
|
+
* @default 1 (ie. items are not mapped concurrently)
|
|
12
|
+
*/
|
|
13
|
+
concurrency?: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Maximum number of mapped items to keep in buffer, ready for consumption.
|
|
17
|
+
*
|
|
18
|
+
* Ignored unless `concurrency > 1`. No limit applies if set to `undefined`.
|
|
19
|
+
*
|
|
20
|
+
* @default unlimited
|
|
21
|
+
*/
|
|
22
|
+
bufferLimit?: number | undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function toAsyncIterator<A>(iterable: AsyncIterable<A>): AsyncIterator<A> {
|
|
26
|
+
return iterable[Symbol.asyncIterator]();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Return an async iterable that transforms items from a source iterable by mapping each item
|
|
31
|
+
* through a mapping function.
|
|
32
|
+
*
|
|
33
|
+
* If `concurrency > 1`, then up to `concurrency` items may be mapped concurrently. In that case,
|
|
34
|
+
* items are returned by the resulting iterator in the order they complete processing, not the order
|
|
35
|
+
* in which the corresponding source items were obtained from the source iterator.
|
|
36
|
+
*
|
|
37
|
+
* @param source the source async iterable
|
|
38
|
+
* @param mapFn a mapping function to apply on every item of the source iterable
|
|
39
|
+
*/
|
|
40
|
+
export async function* mapAsyncIterable<A, B>(
|
|
41
|
+
source: AsyncIterable<A>,
|
|
42
|
+
mapFn: (val: A) => Promise<B>,
|
|
43
|
+
options?: MapAsyncOptions
|
|
44
|
+
): AsyncIterable<B> {
|
|
45
|
+
const { concurrency, bufferLimit } = options ?? {};
|
|
46
|
+
|
|
47
|
+
if (!concurrency || concurrency < 2) {
|
|
48
|
+
for await (const x of source) {
|
|
49
|
+
yield mapFn(x);
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const sourceIterator = toAsyncIterator(source);
|
|
55
|
+
|
|
56
|
+
const emitter = new EventEmitter();
|
|
57
|
+
const controller = new AbortController();
|
|
58
|
+
const emitterEventsIterable: AsyncIterable<[B]> = on(emitter, 'result', { signal: controller.signal });
|
|
59
|
+
const emitterError: Promise<unknown[]> = once(emitter, 'error');
|
|
60
|
+
|
|
61
|
+
const bufferLimitSemaphore =
|
|
62
|
+
typeof bufferLimit === 'number'
|
|
63
|
+
? (() => {
|
|
64
|
+
const releaseEvents: AsyncIterator<void> = toAsyncIterator(
|
|
65
|
+
on(emitter, 'released', { signal: controller.signal })
|
|
66
|
+
);
|
|
67
|
+
let value = bufferLimit + concurrency;
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
acquire: async () => {
|
|
71
|
+
while (value <= 0) {
|
|
72
|
+
await Promise.race([releaseEvents.next(), emitterError]);
|
|
73
|
+
}
|
|
74
|
+
value--;
|
|
75
|
+
},
|
|
76
|
+
release: () => {
|
|
77
|
+
value++;
|
|
78
|
+
emitter.emit('released');
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
})()
|
|
82
|
+
: undefined;
|
|
83
|
+
|
|
84
|
+
const mapper = async () => {
|
|
85
|
+
for (;;) {
|
|
86
|
+
await bufferLimitSemaphore?.acquire();
|
|
87
|
+
const val = await Promise.race([sourceIterator.next(), emitterError]);
|
|
88
|
+
|
|
89
|
+
if (Array.isArray(val)) return;
|
|
90
|
+
if ((val as IteratorResult<[B]>)?.done) return;
|
|
91
|
+
|
|
92
|
+
emitter.emit('result', await mapFn(val.value));
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const mappers = Array(concurrency)
|
|
97
|
+
.fill(mapper)
|
|
98
|
+
.map((f: typeof mapper) => f());
|
|
99
|
+
|
|
100
|
+
Promise.all(mappers).then(
|
|
101
|
+
() => controller.abort(),
|
|
102
|
+
(err) => emitter.emit('error', err)
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
for await (const [res] of emitterEventsIterable) {
|
|
107
|
+
bufferLimitSemaphore?.release();
|
|
108
|
+
yield res;
|
|
109
|
+
}
|
|
110
|
+
} catch (err: unknown) {
|
|
111
|
+
if ((err as Error)?.name === 'AbortError') {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|