@temporalio/workflow 1.11.8 → 1.12.0-rc.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/alea.js +5 -3
- package/lib/alea.js.map +1 -1
- package/lib/cancellation-scope.js +36 -18
- package/lib/cancellation-scope.js.map +1 -1
- package/lib/errors.js +1 -0
- package/lib/errors.js.map +1 -1
- package/lib/flags.js +1 -1
- package/lib/flags.js.map +1 -1
- package/lib/index.d.ts +6 -3
- package/lib/index.js +3 -1
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +11 -1
- package/lib/interfaces.d.ts +68 -5
- package/lib/interfaces.js +1 -0
- package/lib/interfaces.js.map +1 -1
- package/lib/internals.d.ts +55 -7
- package/lib/internals.js +323 -201
- package/lib/internals.js.map +1 -1
- package/lib/logs.js +11 -1
- package/lib/logs.js.map +1 -1
- package/lib/metrics.d.ts +32 -0
- package/lib/metrics.js +118 -0
- package/lib/metrics.js.map +1 -0
- package/lib/trigger.js +8 -0
- package/lib/trigger.js.map +1 -1
- package/lib/update-scope.js +8 -0
- package/lib/update-scope.js.map +1 -1
- package/lib/worker-interface.d.ts +6 -1
- package/lib/worker-interface.js +165 -103
- package/lib/worker-interface.js.map +1 -1
- package/lib/workflow.d.ts +75 -17
- package/lib/workflow.js +204 -31
- package/lib/workflow.js.map +1 -1
- package/package.json +7 -4
- package/src/flags.ts +1 -1
- package/src/index.ts +4 -2
- package/src/interceptors.ts +21 -1
- package/src/interfaces.ts +81 -7
- package/src/internals.ts +133 -33
- package/src/logs.ts +11 -1
- package/src/metrics.ts +191 -0
- package/src/worker-interface.ts +164 -107
- package/src/workflow.ts +229 -35
package/lib/worker-interface.js
CHANGED
|
@@ -36,51 +36,65 @@ function initRuntime(options) {
|
|
|
36
36
|
// We do this before importing any user code so user code can statically reference @temporalio/workflow functions
|
|
37
37
|
// as well as Date and Math.random.
|
|
38
38
|
(0, global_attributes_1.setActivatorUntyped)(activator);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
39
|
+
activator.rethrowSynchronously = true;
|
|
40
|
+
try {
|
|
41
|
+
// webpack alias to payloadConverterPath
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
43
|
+
const customPayloadConverter = require('__temporal_custom_payload_converter').payloadConverter;
|
|
44
|
+
// The `payloadConverter` export is validated in the Worker
|
|
45
|
+
if (customPayloadConverter != null) {
|
|
46
|
+
activator.payloadConverter = customPayloadConverter;
|
|
47
|
+
}
|
|
48
|
+
// webpack alias to failureConverterPath
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
50
|
+
const customFailureConverter = require('__temporal_custom_failure_converter').failureConverter;
|
|
51
|
+
// The `failureConverter` export is validated in the Worker
|
|
52
|
+
if (customFailureConverter != null) {
|
|
53
|
+
activator.failureConverter = customFailureConverter;
|
|
54
|
+
}
|
|
55
|
+
const { importWorkflows, importInterceptors } = global.__TEMPORAL__;
|
|
56
|
+
if (importWorkflows === undefined || importInterceptors === undefined) {
|
|
57
|
+
throw new common_1.IllegalStateError('Workflow bundle did not register import hooks');
|
|
58
|
+
}
|
|
59
|
+
const interceptors = importInterceptors();
|
|
60
|
+
for (const mod of interceptors) {
|
|
61
|
+
const factory = mod.interceptors;
|
|
62
|
+
if (factory !== undefined) {
|
|
63
|
+
if (typeof factory !== 'function') {
|
|
64
|
+
throw new TypeError(`Failed to initialize workflows interceptors: expected a function, but got: '${factory}'`);
|
|
65
|
+
}
|
|
66
|
+
const interceptors = factory();
|
|
67
|
+
activator.interceptors.inbound.push(...(interceptors.inbound ?? []));
|
|
68
|
+
activator.interceptors.outbound.push(...(interceptors.outbound ?? []));
|
|
69
|
+
activator.interceptors.internals.push(...(interceptors.internals ?? []));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const mod = importWorkflows();
|
|
73
|
+
const workflowFn = mod[activator.info.workflowType];
|
|
74
|
+
const defaultWorkflowFn = mod['default'];
|
|
75
|
+
if (typeof workflowFn === 'function') {
|
|
76
|
+
activator.workflow = workflowFn;
|
|
77
|
+
}
|
|
78
|
+
else if (typeof defaultWorkflowFn === 'function') {
|
|
79
|
+
activator.workflow = defaultWorkflowFn;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
const details = workflowFn === undefined
|
|
83
|
+
? 'no such function is exported by the workflow bundle'
|
|
84
|
+
: `expected a function, but got: '${typeof workflowFn}'`;
|
|
85
|
+
throw new TypeError(`Failed to initialize workflow of type '${activator.info.workflowType}': ${details}`);
|
|
86
|
+
}
|
|
87
|
+
if (isWorkflowFunctionWithOptions(activator.workflow)) {
|
|
88
|
+
if (typeof activator.workflow.workflowDefinitionOptions === 'object') {
|
|
89
|
+
activator.versioningBehavior = activator.workflow.workflowDefinitionOptions.versioningBehavior;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
activator.workflowDefinitionOptionsGetter = activator.workflow.workflowDefinitionOptions;
|
|
63
93
|
}
|
|
64
|
-
const interceptors = factory();
|
|
65
|
-
activator.interceptors.inbound.push(...(interceptors.inbound ?? []));
|
|
66
|
-
activator.interceptors.outbound.push(...(interceptors.outbound ?? []));
|
|
67
|
-
activator.interceptors.internals.push(...(interceptors.internals ?? []));
|
|
68
94
|
}
|
|
69
95
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const defaultWorkflowFn = mod['default'];
|
|
73
|
-
if (typeof workflowFn === 'function') {
|
|
74
|
-
activator.workflow = workflowFn;
|
|
75
|
-
}
|
|
76
|
-
else if (typeof defaultWorkflowFn === 'function') {
|
|
77
|
-
activator.workflow = defaultWorkflowFn;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const details = workflowFn === undefined
|
|
81
|
-
? 'no such function is exported by the workflow bundle'
|
|
82
|
-
: `expected a function, but got: '${typeof workflowFn}'`;
|
|
83
|
-
throw new TypeError(`Failed to initialize workflow of type '${activator.info.workflowType}': ${details}`);
|
|
96
|
+
finally {
|
|
97
|
+
activator.rethrowSynchronously = false;
|
|
84
98
|
}
|
|
85
99
|
}
|
|
86
100
|
/**
|
|
@@ -107,46 +121,64 @@ function fixPrototypes(obj) {
|
|
|
107
121
|
* Initialize the workflow. Or to be exact, _complete_ initialization, as most part has been done in constructor).
|
|
108
122
|
*/
|
|
109
123
|
function initialize(initializeWorkflowJob) {
|
|
110
|
-
(0, global_attributes_1.getActivator)()
|
|
124
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
125
|
+
activator.rethrowSynchronously = true;
|
|
126
|
+
try {
|
|
127
|
+
activator.initializeWorkflow(initializeWorkflowJob);
|
|
128
|
+
}
|
|
129
|
+
finally {
|
|
130
|
+
activator.rethrowSynchronously = false;
|
|
131
|
+
}
|
|
111
132
|
}
|
|
112
133
|
/**
|
|
113
|
-
* Run a chunk of activation jobs
|
|
134
|
+
* Run a chunk of activation jobs.
|
|
135
|
+
*
|
|
136
|
+
* Notice that this function is not async and runs _inside_ the VM context. Therefore, no microtask
|
|
137
|
+
* will get executed _while_ this function is active; they will however get executed _after_ this
|
|
138
|
+
* function returns (i.e. all outstanding microtasks in the VM will get executed before execution
|
|
139
|
+
* resumes out of the VM, in `vm-shared.ts:activate()`).
|
|
114
140
|
*/
|
|
115
141
|
function activate(activation, batchIndex = 0) {
|
|
116
142
|
const activator = (0, global_attributes_1.getActivator)();
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
143
|
+
activator.rethrowSynchronously = true;
|
|
144
|
+
try {
|
|
145
|
+
const intercept = (0, interceptors_1.composeInterceptors)(activator.interceptors.internals, 'activate', ({ activation }) => {
|
|
146
|
+
// Cast from the interface to the class which has the `variant` attribute.
|
|
147
|
+
// This is safe because we know that activation is a proto class.
|
|
148
|
+
const jobs = activation.jobs;
|
|
149
|
+
// Initialization will have been handled already, but we might still need to start the workflow function
|
|
150
|
+
const startWorkflowJob = jobs[0].variant === 'initializeWorkflow' ? jobs.shift()?.initializeWorkflow : undefined;
|
|
151
|
+
for (const job of jobs) {
|
|
152
|
+
if (job.variant === undefined)
|
|
153
|
+
throw new TypeError('Expected job.variant to be defined');
|
|
154
|
+
const variant = job[job.variant];
|
|
155
|
+
if (!variant)
|
|
156
|
+
throw new TypeError(`Expected job.${job.variant} to be set`);
|
|
157
|
+
activator[job.variant](variant /* TS can't infer this type */);
|
|
158
|
+
if (job.variant !== 'queryWorkflow')
|
|
159
|
+
tryUnblockConditions();
|
|
160
|
+
}
|
|
161
|
+
if (startWorkflowJob) {
|
|
162
|
+
const safeJobTypes = [
|
|
163
|
+
'initializeWorkflow',
|
|
164
|
+
'signalWorkflow',
|
|
165
|
+
'doUpdate',
|
|
166
|
+
'cancelWorkflow',
|
|
167
|
+
'updateRandomSeed',
|
|
168
|
+
];
|
|
169
|
+
if (jobs.some((job) => !safeJobTypes.includes(job.variant))) {
|
|
170
|
+
throw new TypeError('Received both initializeWorkflow and non-signal/non-update jobs in the same activation: ' +
|
|
171
|
+
JSON.stringify(jobs.map((job) => job.variant)));
|
|
172
|
+
}
|
|
173
|
+
activator.startWorkflow(startWorkflowJob);
|
|
131
174
|
tryUnblockConditions();
|
|
132
|
-
}
|
|
133
|
-
if (startWorkflowJob) {
|
|
134
|
-
const safeJobTypes = [
|
|
135
|
-
'initializeWorkflow',
|
|
136
|
-
'signalWorkflow',
|
|
137
|
-
'doUpdate',
|
|
138
|
-
'cancelWorkflow',
|
|
139
|
-
'updateRandomSeed',
|
|
140
|
-
];
|
|
141
|
-
if (jobs.some((job) => !safeJobTypes.includes(job.variant))) {
|
|
142
|
-
throw new TypeError('Received both initializeWorkflow and non-signal/non-update jobs in the same activation: ' +
|
|
143
|
-
JSON.stringify(jobs.map((job) => job.variant)));
|
|
144
175
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
176
|
+
});
|
|
177
|
+
intercept({ activation, batchIndex });
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
activator.rethrowSynchronously = false;
|
|
181
|
+
}
|
|
150
182
|
}
|
|
151
183
|
/**
|
|
152
184
|
* Conclude a single activation.
|
|
@@ -156,17 +188,27 @@ function activate(activation, batchIndex = 0) {
|
|
|
156
188
|
*/
|
|
157
189
|
function concludeActivation() {
|
|
158
190
|
const activator = (0, global_attributes_1.getActivator)();
|
|
159
|
-
activator.
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
191
|
+
activator.rethrowSynchronously = true;
|
|
192
|
+
try {
|
|
193
|
+
activator.rejectBufferedUpdates();
|
|
194
|
+
const intercept = (0, interceptors_1.composeInterceptors)(activator.interceptors.internals, 'concludeActivation', (input) => input);
|
|
195
|
+
const activationCompletion = activator.concludeActivation();
|
|
196
|
+
const { commands } = intercept({ commands: activationCompletion.commands });
|
|
197
|
+
if (activator.completed) {
|
|
198
|
+
activator.warnIfUnfinishedHandlers();
|
|
199
|
+
}
|
|
200
|
+
return {
|
|
201
|
+
runId: activator.info.runId,
|
|
202
|
+
successful: {
|
|
203
|
+
...activationCompletion,
|
|
204
|
+
commands,
|
|
205
|
+
versioningBehavior: (0, common_1.encodeVersioningBehavior)(activationCompletion.versioningBehavior),
|
|
206
|
+
},
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
activator.rethrowSynchronously = false;
|
|
165
211
|
}
|
|
166
|
-
return {
|
|
167
|
-
runId: activator.info.runId,
|
|
168
|
-
successful: { ...activationCompletion, commands },
|
|
169
|
-
};
|
|
170
212
|
}
|
|
171
213
|
/**
|
|
172
214
|
* Loop through all blocked conditions, evaluate and unblock if possible.
|
|
@@ -174,28 +216,48 @@ function concludeActivation() {
|
|
|
174
216
|
* @returns number of unblocked conditions.
|
|
175
217
|
*/
|
|
176
218
|
function tryUnblockConditions() {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
219
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
220
|
+
activator.rethrowSynchronously = true;
|
|
221
|
+
try {
|
|
222
|
+
let numUnblocked = 0;
|
|
223
|
+
for (;;) {
|
|
224
|
+
activator.maybeRethrowWorkflowTaskError();
|
|
225
|
+
const prevUnblocked = numUnblocked;
|
|
226
|
+
for (const [seq, cond] of activator.blockedConditions.entries()) {
|
|
227
|
+
if (cond.fn()) {
|
|
228
|
+
cond.resolve();
|
|
229
|
+
numUnblocked++;
|
|
230
|
+
// It is safe to delete elements during map iteration
|
|
231
|
+
activator.blockedConditions.delete(seq);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (prevUnblocked === numUnblocked) {
|
|
235
|
+
break;
|
|
186
236
|
}
|
|
187
237
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
238
|
+
return numUnblocked;
|
|
239
|
+
}
|
|
240
|
+
finally {
|
|
241
|
+
activator.rethrowSynchronously = false;
|
|
191
242
|
}
|
|
192
|
-
return numUnblocked;
|
|
193
243
|
}
|
|
194
244
|
function dispose() {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
245
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
246
|
+
activator.rethrowSynchronously = true;
|
|
247
|
+
try {
|
|
248
|
+
const dispose = (0, interceptors_1.composeInterceptors)(activator.interceptors.internals, 'dispose', async () => {
|
|
249
|
+
(0, cancellation_scope_1.disableStorage)();
|
|
250
|
+
(0, update_scope_1.disableUpdateStorage)();
|
|
251
|
+
});
|
|
252
|
+
dispose({});
|
|
253
|
+
}
|
|
254
|
+
finally {
|
|
255
|
+
activator.rethrowSynchronously = false;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function isWorkflowFunctionWithOptions(obj) {
|
|
259
|
+
if (obj == null)
|
|
260
|
+
return false;
|
|
261
|
+
return Object.hasOwn(obj, 'workflowDefinitionOptions');
|
|
200
262
|
}
|
|
201
263
|
//# sourceMappingURL=worker-interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-interface.js","sourceRoot":"","sources":["../src/worker-interface.ts"],"names":[],"mappings":";;AA0BA,
|
|
1
|
+
{"version":3,"file":"worker-interface.js","sourceRoot":"","sources":["../src/worker-interface.ts"],"names":[],"mappings":";;AA0BA,kCA4EC;AAwBD,gCAQC;AAUD,4BA+CC;AAQD,gDAsBC;AAOD,oDAwBC;AAED,0BAYC;AA1QD;;;;GAIG;AACH,+CAA8G;AAC9G,sEAA0E;AAE1E,6DAAsD;AACtD,iDAAsD;AAGtD,2CAAwC;AACxC,2DAAwE;AAKxE,MAAM,MAAM,GAAG,UAAiB,CAAC;AACjC,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC;AAErC;;;;GAIG;AACH,SAAgB,WAAW,CAAC,OAAsC;IAChE,MAAM,SAAS,GAAG,IAAI,qBAAS,CAAC;QAC9B,GAAG,OAAO;QACV,IAAI,EAAE,aAAa,CAAC;YAClB,GAAG,OAAO,CAAC,IAAI;YACf,MAAM,EAAE,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,YAAY,CAAC,GAAG,EAAE;SAC1D,CAAC;KACH,CAAC,CAAC;IACH,+EAA+E;IAC/E,iHAAiH;IACjH,mCAAm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AAC;IACzC,CAAC;AACH,CAAC;AAED,SAAS,6BAA6B,CAAC,GAAQ;IAC7C,IAAI,GAAG,IAAI,IAAI;QAAE,OAAO,KAAK,CAAC;IAC9B,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,2BAA2B,CAAC,CAAC;AACzD,CAAC"}
|
package/lib/workflow.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, UpdateDefinition, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/common';
|
|
1
|
+
import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, UpdateDefinition, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType, SearchAttributeUpdatePair, WorkflowDefinitionOptionsOrGetter } from '@temporalio/common';
|
|
2
2
|
import { Duration } from '@temporalio/common/lib/time';
|
|
3
3
|
import { temporal } from '@temporalio/proto';
|
|
4
|
-
import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, DefaultSignalHandler, EnhancedStackTrace, Handler, QueryHandlerOptions, SignalHandlerOptions, UpdateHandlerOptions, WorkflowInfo, UpdateInfo } from './interfaces';
|
|
4
|
+
import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, DefaultSignalHandler, EnhancedStackTrace, Handler, QueryHandlerOptions, SignalHandlerOptions, UpdateHandlerOptions, WorkflowInfo, UpdateInfo, DefaultUpdateHandler, DefaultQueryHandler } from './interfaces';
|
|
5
5
|
import { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
|
|
6
6
|
/**
|
|
7
7
|
* Adds default values of `workflowId` and `cancellationType` to given workflow options.
|
|
@@ -262,14 +262,15 @@ export declare function makeContinueAsNewFunc<F extends Workflow>(options?: Cont
|
|
|
262
262
|
*
|
|
263
263
|
* @example
|
|
264
264
|
*
|
|
265
|
-
|
|
265
|
+
* ```ts
|
|
266
266
|
*import { continueAsNew } from '@temporalio/workflow';
|
|
267
|
+
import { SearchAttributeType } from '@temporalio/common';
|
|
267
268
|
*
|
|
268
269
|
*export async function myWorkflow(n: number): Promise<void> {
|
|
269
270
|
* // ... Workflow logic
|
|
270
271
|
* await continueAsNew<typeof myWorkflow>(n + 1);
|
|
271
272
|
*}
|
|
272
|
-
|
|
273
|
+
* ```
|
|
273
274
|
*/
|
|
274
275
|
export declare function continueAsNew<F extends Workflow>(...args: Parameters<F>): Promise<never>;
|
|
275
276
|
/**
|
|
@@ -365,29 +366,55 @@ export declare function setHandler<Ret, Args extends any[], T extends UpdateDefi
|
|
|
365
366
|
*
|
|
366
367
|
* Signals are dispatched to the default signal handler in the order that they were accepted by the server.
|
|
367
368
|
*
|
|
368
|
-
* If this function is called multiple times for a given signal
|
|
369
|
+
* If this function is called multiple times for a given signal name the last handler will overwrite any previous calls.
|
|
369
370
|
*
|
|
370
371
|
* @param handler a function that will handle signals for non-registered signal names, or `undefined` to unset the handler.
|
|
371
372
|
*/
|
|
372
373
|
export declare function setDefaultSignalHandler(handler: DefaultSignalHandler | undefined): void;
|
|
374
|
+
/**
|
|
375
|
+
* Set a update handler function that will handle updates calls for non-registered update names.
|
|
376
|
+
*
|
|
377
|
+
* Updates are dispatched to the default update handler in the order that they were accepted by the server.
|
|
378
|
+
*
|
|
379
|
+
* If this function is called multiple times for a given update name the last handler will overwrite any previous calls.
|
|
380
|
+
*
|
|
381
|
+
* @param handler a function that will handle updates for non-registered update names, or `undefined` to unset the handler.
|
|
382
|
+
*/
|
|
383
|
+
export declare function setDefaultUpdateHandler(handler: DefaultUpdateHandler | undefined): void;
|
|
384
|
+
/**
|
|
385
|
+
* Set a query handler function that will handle query calls for non-registered query names.
|
|
386
|
+
*
|
|
387
|
+
* Queries are dispatched to the default query handler in the order that they were accepted by the server.
|
|
388
|
+
*
|
|
389
|
+
* If this function is called multiple times for a given query name the last handler will overwrite any previous calls.
|
|
390
|
+
*
|
|
391
|
+
* @param handler a function that will handle queries for non-registered query names, or `undefined` to unset the handler.
|
|
392
|
+
*/
|
|
393
|
+
export declare function setDefaultQueryHandler(handler: DefaultQueryHandler | undefined): void;
|
|
373
394
|
/**
|
|
374
395
|
* Updates this Workflow's Search Attributes by merging the provided `searchAttributes` with the existing Search
|
|
375
396
|
* Attributes, `workflowInfo().searchAttributes`.
|
|
376
397
|
*
|
|
377
|
-
*
|
|
398
|
+
* Search attributes can be upserted using either SearchAttributes (deprecated) or SearchAttributeUpdatePair[] (preferred)
|
|
399
|
+
*
|
|
400
|
+
* Upserting a workflow's search attributes using SearchAttributeUpdatePair[]:
|
|
378
401
|
*
|
|
379
402
|
* ```ts
|
|
380
|
-
*
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
* upsertSearchAttributes(
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
403
|
+
* const intKey = defineSearchKey('CustomIntField', 'INT');
|
|
404
|
+
* const boolKey = defineSearchKey('CustomBoolField', 'BOOL');
|
|
405
|
+
* const keywordListKey = defineSearchKey('CustomKeywordField', 'KEYWORD_LIST');
|
|
406
|
+
*
|
|
407
|
+
* upsertSearchAttributes([
|
|
408
|
+
* defineSearchAttribute(intKey, 1),
|
|
409
|
+
* defineSearchAttribute(boolKey, true)
|
|
410
|
+
* ]);
|
|
411
|
+
* upsertSearchAttributes([
|
|
412
|
+
* defineSearchAttribute(intKey, 42),
|
|
413
|
+
* defineSearchAttribute(keywordListKey, ['durable code', 'is great'])
|
|
414
|
+
* ]);
|
|
388
415
|
* ```
|
|
389
416
|
*
|
|
390
|
-
*
|
|
417
|
+
* Would result in the Workflow having these Search Attributes:
|
|
391
418
|
*
|
|
392
419
|
* ```ts
|
|
393
420
|
* {
|
|
@@ -397,9 +424,11 @@ export declare function setDefaultSignalHandler(handler: DefaultSignalHandler |
|
|
|
397
424
|
* }
|
|
398
425
|
* ```
|
|
399
426
|
*
|
|
400
|
-
* @param searchAttributes The Record to merge.
|
|
427
|
+
* @param searchAttributes The Record to merge.
|
|
428
|
+
* If using SearchAttributeUpdatePair[] (preferred), set a value to null to remove the search attribute.
|
|
429
|
+
* If using SearchAttributes (deprecated), set a value to undefined or an empty list to remove the search attribute.
|
|
401
430
|
*/
|
|
402
|
-
export declare function upsertSearchAttributes(searchAttributes: SearchAttributes): void;
|
|
431
|
+
export declare function upsertSearchAttributes(searchAttributes: SearchAttributes | SearchAttributeUpdatePair[]): void;
|
|
403
432
|
/**
|
|
404
433
|
* Updates this Workflow's Memos by merging the provided `memo` with existing
|
|
405
434
|
* Memos (as returned by `workflowInfo().memo`).
|
|
@@ -450,6 +479,35 @@ export declare function upsertMemo(memo: Record<string, unknown>): void;
|
|
|
450
479
|
* @returns true if there are no in-progress update or signal handler executions.
|
|
451
480
|
*/
|
|
452
481
|
export declare function allHandlersFinished(): boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Can be used to alter workflow functions with certain options specified at definition time.
|
|
484
|
+
*
|
|
485
|
+
* @example
|
|
486
|
+
* For example:
|
|
487
|
+
* ```ts
|
|
488
|
+
* setWorkflowOptions({ versioningBehavior: 'PINNED' }, myWorkflow);
|
|
489
|
+
* export async function myWorkflow(): Promise<string> {
|
|
490
|
+
* // Workflow code here
|
|
491
|
+
* return "hi";
|
|
492
|
+
* }
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* @example
|
|
496
|
+
* To annotate a default or dynamic workflow:
|
|
497
|
+
* ```ts
|
|
498
|
+
* export default async function (): Promise<string> {
|
|
499
|
+
* // Workflow code here
|
|
500
|
+
* return "hi";
|
|
501
|
+
* }
|
|
502
|
+
* setWorkflowOptions({ versioningBehavior: 'PINNED' }, module.exports.default);
|
|
503
|
+
* ```
|
|
504
|
+
*
|
|
505
|
+
* @param options Options for the workflow defintion, or a function that returns options. If a
|
|
506
|
+
* function is provided, it will be called once just before the workflow function is called for the
|
|
507
|
+
* first time. It is safe to call {@link workflowInfo} inside such a function.
|
|
508
|
+
* @param fn The workflow function.
|
|
509
|
+
*/
|
|
510
|
+
export declare function setWorkflowOptions<A extends any[], RT>(options: WorkflowDefinitionOptionsOrGetter, fn: (...args: A) => Promise<RT>): void;
|
|
453
511
|
export declare const stackTraceQuery: QueryDefinition<string, [], string>;
|
|
454
512
|
export declare const enhancedStackTraceQuery: QueryDefinition<EnhancedStackTrace, [], string>;
|
|
455
513
|
export declare const workflowMetadataQuery: QueryDefinition<temporal.api.sdk.v1.IWorkflowMetadata, [], string>;
|