@temporalio/workflow 1.8.5 → 1.9.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/errors.d.ts +8 -0
- package/lib/errors.js +14 -1
- package/lib/errors.js.map +1 -1
- package/lib/global-attributes.d.ts +4 -0
- package/lib/global-attributes.js +21 -1
- package/lib/global-attributes.js.map +1 -1
- package/lib/index.d.ts +19 -8
- package/lib/index.js +15 -8
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +15 -0
- package/lib/interfaces.d.ts +40 -32
- package/lib/interfaces.js.map +1 -1
- package/lib/internals.d.ts +24 -13
- package/lib/internals.js +145 -41
- package/lib/internals.js.map +1 -1
- package/lib/logs.d.ts +50 -0
- package/lib/logs.js +84 -0
- package/lib/logs.js.map +1 -0
- package/lib/sinks.d.ts +29 -10
- package/lib/sinks.js +57 -0
- package/lib/sinks.js.map +1 -1
- package/lib/worker-interface.d.ts +2 -2
- package/lib/worker-interface.js +33 -22
- package/lib/worker-interface.js.map +1 -1
- package/lib/workflow.d.ts +23 -54
- package/lib/workflow.js +156 -141
- package/lib/workflow.js.map +1 -1
- package/package.json +4 -4
- package/src/errors.ts +11 -0
- package/src/global-attributes.ts +21 -0
- package/src/index.ts +24 -8
- package/src/interceptors.ts +18 -0
- package/src/interfaces.ts +44 -32
- package/src/internals.ts +175 -37
- package/src/logs.ts +118 -0
- package/src/sinks.ts +60 -9
- package/src/worker-interface.ts +28 -16
- package/src/workflow.ts +150 -128
package/lib/worker-interface.js
CHANGED
|
@@ -28,10 +28,10 @@ function overrideGlobals() {
|
|
|
28
28
|
if (args.length > 0) {
|
|
29
29
|
return new OriginalDate(...args);
|
|
30
30
|
}
|
|
31
|
-
return new OriginalDate((0,
|
|
31
|
+
return new OriginalDate((0, global_attributes_1.getActivator)().now);
|
|
32
32
|
};
|
|
33
33
|
global.Date.now = function () {
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, global_attributes_1.getActivator)().now;
|
|
35
35
|
};
|
|
36
36
|
global.Date.parse = OriginalDate.parse.bind(OriginalDate);
|
|
37
37
|
global.Date.UTC = OriginalDate.UTC.bind(OriginalDate);
|
|
@@ -40,7 +40,7 @@ function overrideGlobals() {
|
|
|
40
40
|
* @param ms sleep duration - number of milliseconds. If given a negative number, value will be set to 1.
|
|
41
41
|
*/
|
|
42
42
|
global.setTimeout = function (cb, ms, ...args) {
|
|
43
|
-
const activator = (0,
|
|
43
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
44
44
|
ms = Math.max(1, ms);
|
|
45
45
|
const seq = activator.nextSeqs.timer++;
|
|
46
46
|
// Create a Promise for AsyncLocalStorage to be able to track this completion using promise hooks.
|
|
@@ -56,7 +56,7 @@ function overrideGlobals() {
|
|
|
56
56
|
return seq;
|
|
57
57
|
};
|
|
58
58
|
global.clearTimeout = function (handle) {
|
|
59
|
-
const activator = (0,
|
|
59
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
60
60
|
activator.nextSeqs.timer++;
|
|
61
61
|
activator.completions.timer.delete(handle);
|
|
62
62
|
activator.pushCommand({
|
|
@@ -66,7 +66,7 @@ function overrideGlobals() {
|
|
|
66
66
|
});
|
|
67
67
|
};
|
|
68
68
|
// activator.random is mutable, don't hardcode its reference
|
|
69
|
-
Math.random = () => (0,
|
|
69
|
+
Math.random = () => (0, global_attributes_1.getActivator)().random();
|
|
70
70
|
}
|
|
71
71
|
exports.overrideGlobals = overrideGlobals;
|
|
72
72
|
/**
|
|
@@ -75,9 +75,13 @@ exports.overrideGlobals = overrideGlobals;
|
|
|
75
75
|
* Sets required internal state and instantiates the workflow and interceptors.
|
|
76
76
|
*/
|
|
77
77
|
function initRuntime(options) {
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
const activator = new internals_1.Activator({
|
|
79
|
+
...options,
|
|
80
|
+
info: fixPrototypes({
|
|
81
|
+
...options.info,
|
|
82
|
+
unsafe: { ...options.info.unsafe, now: OriginalDate.now },
|
|
83
|
+
}),
|
|
84
|
+
});
|
|
81
85
|
// There's on activator per workflow instance, set it globally on the context.
|
|
82
86
|
// We do this before importing any user code so user code can statically reference @temporalio/workflow functions
|
|
83
87
|
// as well as Date and Math.random.
|
|
@@ -114,7 +118,7 @@ function initRuntime(options) {
|
|
|
114
118
|
}
|
|
115
119
|
}
|
|
116
120
|
const mod = importWorkflows();
|
|
117
|
-
const workflowFn = mod[info.workflowType];
|
|
121
|
+
const workflowFn = mod[activator.info.workflowType];
|
|
118
122
|
const defaultWorkflowFn = mod['default'];
|
|
119
123
|
if (typeof workflowFn === 'function') {
|
|
120
124
|
activator.workflow = workflowFn;
|
|
@@ -126,7 +130,7 @@ function initRuntime(options) {
|
|
|
126
130
|
const details = workflowFn === undefined
|
|
127
131
|
? 'no such function is exported by the workflow bundle'
|
|
128
132
|
: `expected a function, but got: '${typeof workflowFn}'`;
|
|
129
|
-
throw new TypeError(`Failed to initialize workflow of type '${info.workflowType}': ${details}`);
|
|
133
|
+
throw new TypeError(`Failed to initialize workflow of type '${activator.info.workflowType}': ${details}`);
|
|
130
134
|
}
|
|
131
135
|
}
|
|
132
136
|
exports.initRuntime = initRuntime;
|
|
@@ -155,7 +159,7 @@ function fixPrototypes(obj) {
|
|
|
155
159
|
* @returns a boolean indicating whether job was processed or ignored
|
|
156
160
|
*/
|
|
157
161
|
function activate(activation, batchIndex) {
|
|
158
|
-
const activator = (0,
|
|
162
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
159
163
|
const intercept = (0, interceptors_1.composeInterceptors)(activator.interceptors.internals, 'activate', ({ activation, batchIndex }) => {
|
|
160
164
|
if (batchIndex === 0) {
|
|
161
165
|
if (!activation.jobs) {
|
|
@@ -166,12 +170,18 @@ function activate(activation, batchIndex) {
|
|
|
166
170
|
activator.now = (0, time_1.tsToMs)(activation.timestamp);
|
|
167
171
|
}
|
|
168
172
|
// The Rust Core ensures that these activation fields are not null
|
|
169
|
-
activator.info
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
activator.mutateWorkflowInfo((info) => ({
|
|
174
|
+
...info,
|
|
175
|
+
historyLength: activation.historyLength,
|
|
176
|
+
// Exact truncation for multi-petabyte histories
|
|
177
|
+
// historySize === 0 means WFT was generated by pre-1.20.0 server, and the history size is unknown
|
|
178
|
+
historySize: activation.historySizeBytes?.toNumber() || 0,
|
|
179
|
+
continueAsNewSuggested: activation.continueAsNewSuggested ?? false,
|
|
180
|
+
unsafe: {
|
|
181
|
+
...info.unsafe,
|
|
182
|
+
isReplaying: activation.isReplaying ?? false,
|
|
183
|
+
},
|
|
184
|
+
}));
|
|
175
185
|
}
|
|
176
186
|
// Cast from the interface to the class which has the `variant` attribute.
|
|
177
187
|
// This is safe because we know that activation is a proto class.
|
|
@@ -209,7 +219,8 @@ exports.activate = activate;
|
|
|
209
219
|
* Activation failures are handled in the main Node.js isolate.
|
|
210
220
|
*/
|
|
211
221
|
function concludeActivation() {
|
|
212
|
-
const activator = (0,
|
|
222
|
+
const activator = (0, global_attributes_1.getActivator)();
|
|
223
|
+
activator.rejectBufferedUpdates();
|
|
213
224
|
const intercept = (0, interceptors_1.composeInterceptors)(activator.interceptors.internals, 'concludeActivation', (input) => input);
|
|
214
225
|
const { info } = activator;
|
|
215
226
|
const { commands } = intercept({ commands: activator.getAndResetCommands() });
|
|
@@ -220,7 +231,7 @@ function concludeActivation() {
|
|
|
220
231
|
}
|
|
221
232
|
exports.concludeActivation = concludeActivation;
|
|
222
233
|
function getAndResetSinkCalls() {
|
|
223
|
-
return (0,
|
|
234
|
+
return (0, global_attributes_1.getActivator)().getAndResetSinkCalls();
|
|
224
235
|
}
|
|
225
236
|
exports.getAndResetSinkCalls = getAndResetSinkCalls;
|
|
226
237
|
/**
|
|
@@ -232,12 +243,12 @@ function tryUnblockConditions() {
|
|
|
232
243
|
let numUnblocked = 0;
|
|
233
244
|
for (;;) {
|
|
234
245
|
const prevUnblocked = numUnblocked;
|
|
235
|
-
for (const [seq, cond] of (0,
|
|
246
|
+
for (const [seq, cond] of (0, global_attributes_1.getActivator)().blockedConditions.entries()) {
|
|
236
247
|
if (cond.fn()) {
|
|
237
248
|
cond.resolve();
|
|
238
249
|
numUnblocked++;
|
|
239
250
|
// It is safe to delete elements during map iteration
|
|
240
|
-
(0,
|
|
251
|
+
(0, global_attributes_1.getActivator)().blockedConditions.delete(seq);
|
|
241
252
|
}
|
|
242
253
|
}
|
|
243
254
|
if (prevUnblocked === numUnblocked) {
|
|
@@ -255,7 +266,7 @@ function shouldUnblockConditions(job) {
|
|
|
255
266
|
}
|
|
256
267
|
exports.shouldUnblockConditions = shouldUnblockConditions;
|
|
257
268
|
function dispose() {
|
|
258
|
-
const dispose = (0, interceptors_1.composeInterceptors)((0,
|
|
269
|
+
const dispose = (0, interceptors_1.composeInterceptors)((0, global_attributes_1.getActivator)().interceptors.internals, 'dispose', async () => {
|
|
259
270
|
(0, cancellation_scope_1.disableStorage)();
|
|
260
271
|
});
|
|
261
272
|
dispose({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"worker-interface.js","sourceRoot":"","sources":["../src/worker-interface.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,+CAAuD;AACvD,sDAA6D;AAC7D,sEAA0E;AAE1E,6DAAsD;AACtD,qCAAqD;AAGrD,
|
|
1
|
+
{"version":3,"file":"worker-interface.js","sourceRoot":"","sources":["../src/worker-interface.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,+CAAuD;AACvD,sDAA6D;AAC7D,sEAA0E;AAE1E,6DAAsD;AACtD,qCAAqD;AAGrD,2CAAwC;AACxC,2DAAwE;AAMxE,MAAM,MAAM,GAAG,UAAiB,CAAC;AACjC,MAAM,YAAY,GAAG,UAAU,CAAC,IAAI,CAAC;AAErC,SAAgB,eAAe;IAC7B,0GAA0G;IAC1G,+EAA+E;IAC/E,MAAM,CAAC,OAAO,GAAG;QACf,MAA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FD,oDAEC;AAED;;;;GAIG;AACH,SAAgB,oBAAoB;IAClC,IAAI,YAAY,GAAG,CAAC,CAAC;IACrB,SAAS;QACP,MAAM,aAAa,GAAG,YAAY,CAAC;QACnC,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,IAAA,gCAAY,GAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,EAAE;YACpE,IAAI,IAAI,CAAC,EAAE,EAAE,EAAE;gBACb,IAAI,CAAC,OAAO,EAAE,CAAC;gBACf,YAAY,EAAE,CAAC;gBACf,qDAAqD;gBACrD,IAAA,gCAAY,GAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC9C;SACF;QACD,IAAI,aAAa,KAAK,YAAY,EAAE;YAClC,MAAM;SACP;KACF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAjBD,oDAiBC;AAED;;GAEG;AACH,SAAgB,uBAAuB,CAAC,GAAuD;IAC7F,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;AACnD,CAAC;AAFD,0DAEC;AAED,SAAgB,OAAO;IACrB,MAAM,OAAO,GAAG,IAAA,kCAAmB,EAAC,IAAA,gCAAY,GAAE,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE;QAC/F,IAAA,mCAAc,GAAE,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,EAAE,CAAC,CAAC;AACd,CAAC;AALD,0BAKC"}
|
package/lib/workflow.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/common';
|
|
1
|
+
import { ActivityFunction, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, UntypedActivities, UpdateDefinition, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/common';
|
|
2
2
|
import { Duration } from '@temporalio/common/lib/time';
|
|
3
|
-
import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, DefaultSignalHandler, EnhancedStackTrace, Handler, WorkflowInfo } from './interfaces';
|
|
4
|
-
import { LoggerSinks, Sinks } from './sinks';
|
|
3
|
+
import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, DefaultSignalHandler, EnhancedStackTrace, Handler, UpdateValidator, WorkflowInfo } from './interfaces';
|
|
5
4
|
import { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
|
|
6
5
|
/**
|
|
7
6
|
* Adds default values to `workflowId` and `workflowIdReusePolicy` to given workflow options.
|
|
@@ -207,9 +206,11 @@ export declare function executeChild<T extends () => WorkflowReturnType>(workflo
|
|
|
207
206
|
/**
|
|
208
207
|
* Get information about the current Workflow.
|
|
209
208
|
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
209
|
+
* WARNING: This function returns a frozen copy of WorkflowInfo, at the point where this method has been called.
|
|
210
|
+
* Changes happening at later point in workflow execution will not be reflected in the returned object.
|
|
211
|
+
*
|
|
212
|
+
* For this reason, we recommend calling `workflowInfo()` on every access to {@link WorkflowInfo}'s fields,
|
|
213
|
+
* rather than caching the `WorkflowInfo` object (or part of it) in a local variable. For example:
|
|
213
214
|
*
|
|
214
215
|
* ```ts
|
|
215
216
|
* // GOOD
|
|
@@ -220,6 +221,8 @@ export declare function executeChild<T extends () => WorkflowReturnType>(workflo
|
|
|
220
221
|
* }
|
|
221
222
|
* ```
|
|
222
223
|
*
|
|
224
|
+
* vs
|
|
225
|
+
*
|
|
223
226
|
* ```ts
|
|
224
227
|
* // BAD
|
|
225
228
|
* function myWorkflow() {
|
|
@@ -228,43 +231,13 @@ export declare function executeChild<T extends () => WorkflowReturnType>(workflo
|
|
|
228
231
|
* ...
|
|
229
232
|
* doSomethingElse(attributes)
|
|
230
233
|
* }
|
|
234
|
+
* ```
|
|
231
235
|
*/
|
|
232
236
|
export declare function workflowInfo(): WorkflowInfo;
|
|
233
237
|
/**
|
|
234
238
|
* Returns whether or not code is executing in workflow context
|
|
235
239
|
*/
|
|
236
240
|
export declare function inWorkflowContext(): boolean;
|
|
237
|
-
/**
|
|
238
|
-
* Get a reference to Sinks for exporting data out of the Workflow.
|
|
239
|
-
*
|
|
240
|
-
* These Sinks **must** be registered with the Worker in order for this
|
|
241
|
-
* mechanism to work.
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```ts
|
|
245
|
-
* import { proxySinks, Sinks } from '@temporalio/workflow';
|
|
246
|
-
*
|
|
247
|
-
* interface MySinks extends Sinks {
|
|
248
|
-
* logger: {
|
|
249
|
-
* info(message: string): void;
|
|
250
|
-
* error(message: string): void;
|
|
251
|
-
* };
|
|
252
|
-
* }
|
|
253
|
-
*
|
|
254
|
-
* const { logger } = proxySinks<MyDependencies>();
|
|
255
|
-
* logger.info('setting up');
|
|
256
|
-
*
|
|
257
|
-
* export function myWorkflow() {
|
|
258
|
-
* return {
|
|
259
|
-
* async execute() {
|
|
260
|
-
* logger.info("hey ho");
|
|
261
|
-
* logger.error("lets go");
|
|
262
|
-
* }
|
|
263
|
-
* };
|
|
264
|
-
* }
|
|
265
|
-
* ```
|
|
266
|
-
*/
|
|
267
|
-
export declare function proxySinks<T extends Sinks>(): T;
|
|
268
241
|
/**
|
|
269
242
|
* Returns a function `f` that will cause the current Workflow to ContinueAsNew when called.
|
|
270
243
|
*
|
|
@@ -346,6 +319,13 @@ export declare function condition(fn: () => boolean, timeout: Duration): Promise
|
|
|
346
319
|
* Returns a Promise that resolves when `fn` evaluates to `true`.
|
|
347
320
|
*/
|
|
348
321
|
export declare function condition(fn: () => boolean): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Define an update method for a Workflow.
|
|
324
|
+
*
|
|
325
|
+
* Definitions are used to register handler in the Workflow via {@link setHandler} and to update Workflows using a {@link WorkflowHandle}, {@link ChildWorkflowHandle} or {@link ExternalWorkflowHandle}.
|
|
326
|
+
* Definitions can be reused in multiple Workflows.
|
|
327
|
+
*/
|
|
328
|
+
export declare function defineUpdate<Ret, Args extends any[] = [], Name extends string = string>(name: Name): UpdateDefinition<Ret, Args, Name>;
|
|
349
329
|
/**
|
|
350
330
|
* Define a signal method for a Workflow.
|
|
351
331
|
*
|
|
@@ -361,14 +341,17 @@ export declare function defineSignal<Args extends any[] = [], Name extends strin
|
|
|
361
341
|
*/
|
|
362
342
|
export declare function defineQuery<Ret, Args extends any[] = [], Name extends string = string>(name: Name): QueryDefinition<Ret, Args, Name>;
|
|
363
343
|
/**
|
|
364
|
-
* Set a handler function for a Workflow
|
|
344
|
+
* Set a handler function for a Workflow update, signal, or query.
|
|
365
345
|
*
|
|
366
|
-
* If this function is called multiple times for a given signal or query name the last handler will overwrite any previous calls.
|
|
346
|
+
* If this function is called multiple times for a given update, signal, or query name the last handler will overwrite any previous calls.
|
|
367
347
|
*
|
|
368
|
-
* @param def
|
|
348
|
+
* @param def an {@link UpdateDefinition}, {@link SignalDefinition}, or {@link QueryDefinition} as returned by {@link defineUpdate}, {@link defineSignal}, or {@link defineQuery} respectively.
|
|
369
349
|
* @param handler a compatible handler function for the given definition or `undefined` to unset the handler.
|
|
370
350
|
*/
|
|
371
351
|
export declare function setHandler<Ret, Args extends any[], T extends SignalDefinition<Args> | QueryDefinition<Ret, Args>>(def: T, handler: Handler<Ret, Args, T> | undefined): void;
|
|
352
|
+
export declare function setHandler<Ret, Args extends any[], T extends UpdateDefinition<Ret, Args>>(def: T, handler: Handler<Ret, Args, T> | undefined, options?: {
|
|
353
|
+
validator: UpdateValidator<Args>;
|
|
354
|
+
}): void;
|
|
372
355
|
/**
|
|
373
356
|
* Set a signal handler function that will handle signals calls for non-registered signal names.
|
|
374
357
|
*
|
|
@@ -411,17 +394,3 @@ export declare function setDefaultSignalHandler(handler: DefaultSignalHandler |
|
|
|
411
394
|
export declare function upsertSearchAttributes(searchAttributes: SearchAttributes): void;
|
|
412
395
|
export declare const stackTraceQuery: QueryDefinition<string, [], string>;
|
|
413
396
|
export declare const enhancedStackTraceQuery: QueryDefinition<EnhancedStackTrace, [], string>;
|
|
414
|
-
/**
|
|
415
|
-
* Default workflow logger.
|
|
416
|
-
* This logger is replay-aware and will omit log messages on workflow replay.
|
|
417
|
-
* The messages emitted by this logger are funnelled to the worker's `defaultSinks`, which are installed by default.
|
|
418
|
-
*
|
|
419
|
-
* Note that since sinks are used to power this logger, any log attributes must be transferable via the
|
|
420
|
-
* {@link https://nodejs.org/api/worker_threads.html#worker_threads_port_postmessage_value_transferlist | postMessage}
|
|
421
|
-
* API.
|
|
422
|
-
*
|
|
423
|
-
* `defaultSinks` accepts a user logger and defaults to the `Runtime`'s logger.
|
|
424
|
-
*
|
|
425
|
-
* See the documentation for `WorkerOptions`, `defaultSinks`, and `Runtime` for more information.
|
|
426
|
-
*/
|
|
427
|
-
export declare const log: LoggerSinks['defaultWorkerLogger'];
|