@temporalio/workflow 0.8.0 → 0.12.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/internals.js CHANGED
@@ -46,15 +46,33 @@ const cancellation_scope_1 = require("./cancellation-scope");
46
46
  protobufjs.util.Long = long_1.default;
47
47
  protobufjs.configure();
48
48
  class Activator {
49
- async startWorkflowNextHandler() {
50
- if (exports.state.workflow === undefined) {
49
+ constructor() {
50
+ this.workflowFunctionWasCalled = false;
51
+ }
52
+ async startWorkflowNextHandler({ args }) {
53
+ const { workflow } = exports.state;
54
+ if (workflow === undefined) {
51
55
  throw new common_1.IllegalStateError('Workflow uninitialized');
52
56
  }
53
- return await exports.state.workflow.execute();
57
+ let promise;
58
+ try {
59
+ promise = workflow(...args);
60
+ }
61
+ finally {
62
+ // Guarantee this runs even if there was an exception when invoking the Workflow function
63
+ // Otherwise this Workflow will now be queryable.
64
+ this.workflowFunctionWasCalled = true;
65
+ // Empty the buffer
66
+ const buffer = exports.state.bufferedQueries.splice(0);
67
+ for (const activation of buffer) {
68
+ this.queryWorkflow(activation);
69
+ }
70
+ }
71
+ return await promise;
54
72
  }
55
73
  startWorkflow(activation) {
56
- const { require: req, info } = exports.state;
57
- if (req === undefined || info === undefined) {
74
+ const { info } = exports.state;
75
+ if (info === undefined) {
58
76
  throw new common_1.IllegalStateError('Workflow has not been initialized');
59
77
  }
60
78
  const execute = (0, common_1.composeInterceptors)(exports.state.interceptors.inbound, 'execute', this.startWorkflowNextHandler.bind(this));
@@ -145,19 +163,23 @@ class Activator {
145
163
  reject(await (0, common_1.failureToError)(failure, exports.state.dataConverter));
146
164
  }
147
165
  }
148
- async queryWorkflowNextHandler(input) {
149
- const fn = exports.state.workflow?.queries?.[input.queryName];
166
+ async queryWorkflowNextHandler({ queryName, args }) {
167
+ const fn = exports.state.queryListeners.get(queryName);
150
168
  if (fn === undefined) {
151
169
  // Fail the query
152
- throw new ReferenceError(`Workflow did not register a handler for ${input.queryName}`);
170
+ throw new ReferenceError(`Workflow did not register a handler for ${queryName}`);
153
171
  }
154
- const ret = fn(...input.args);
172
+ const ret = fn(...args);
155
173
  if (ret instanceof Promise) {
156
174
  throw new errors_1.DeterminismViolationError('Query handlers should not return a Promise');
157
175
  }
158
176
  return ret;
159
177
  }
160
178
  queryWorkflow(activation) {
179
+ if (!this.workflowFunctionWasCalled) {
180
+ exports.state.bufferedQueries.push(activation);
181
+ return;
182
+ }
161
183
  const { queryType, queryId } = activation;
162
184
  if (!(queryType && queryId)) {
163
185
  throw new TypeError('Missing query activation attributes');
@@ -169,20 +191,29 @@ class Activator {
169
191
  queryId,
170
192
  }).then((result) => completeQuery(queryId, result), (reason) => failQuery(queryId, reason));
171
193
  }
172
- async signalWorkflowNextHandler(fn, input) {
173
- return fn(...input.args);
194
+ async signalWorkflowNextHandler({ signalName, args }) {
195
+ const fn = exports.state.signalListeners.get(signalName);
196
+ if (fn === undefined) {
197
+ throw new common_1.IllegalStateError(`No registered signal listener for signal ${signalName}`);
198
+ }
199
+ return fn(...args);
174
200
  }
175
201
  signalWorkflow(activation) {
176
202
  const { signalName } = activation;
177
203
  if (!signalName) {
178
204
  throw new TypeError('Missing activation signalName');
179
205
  }
180
- const fn = exports.state.workflow?.signals?.[signalName];
206
+ const fn = exports.state.signalListeners.get(signalName);
181
207
  if (fn === undefined) {
182
- // Fail the activation
183
- throw new ReferenceError(`Workflow did not register a signal handler for ${signalName}`);
208
+ let buffer = exports.state.bufferedSignals.get(signalName);
209
+ if (buffer === undefined) {
210
+ buffer = [];
211
+ exports.state.bufferedSignals.set(signalName, buffer);
212
+ }
213
+ buffer.push(activation);
214
+ return;
184
215
  }
185
- const execute = (0, common_1.composeInterceptors)(exports.state.interceptors.inbound, 'handleSignal', this.signalWorkflowNextHandler.bind(this, fn));
216
+ const execute = (0, common_1.composeInterceptors)(exports.state.interceptors.inbound, 'handleSignal', this.signalWorkflowNextHandler.bind(this));
186
217
  execute({
187
218
  args: (0, common_1.arrayFromPayloadsSync)(exports.state.dataConverter, activation.input),
188
219
  signalName,
@@ -246,6 +277,26 @@ class State {
246
277
  signalWorkflow: new Map(),
247
278
  cancelWorkflow: new Map(),
248
279
  };
280
+ /**
281
+ * Holds buffered signal calls until a listener is registered
282
+ */
283
+ this.bufferedSignals = new Map();
284
+ /**
285
+ * Holds buffered query calls until a listener is registered.
286
+ *
287
+ * **IMPORTANT** queries are only buffered until workflow is started.
288
+ * This is required because async interceptors might block workflow function invocation
289
+ * which delays query handler registration.
290
+ */
291
+ this.bufferedQueries = Array();
292
+ /**
293
+ * Mapping of signal name to listener
294
+ */
295
+ this.signalListeners = new Map();
296
+ /**
297
+ * Mapping of signal name to listener
298
+ */
299
+ this.queryListeners = new Map();
249
300
  /**
250
301
  * Loaded in {@link initRuntime}
251
302
  */
@@ -255,9 +306,10 @@ class State {
255
306
  */
256
307
  this.commands = [];
257
308
  /**
258
- * Buffer containing external dependency calls which have not yet been transferred out of the isolate
309
+ /**
310
+ * Stores all {@link condition}s that haven't been unblocked yet
259
311
  */
260
- this.pendingExternalCalls = [];
312
+ this.blockedConditions = new Map();
261
313
  /**
262
314
  * Is this Workflow completed
263
315
  */
@@ -273,9 +325,9 @@ class State {
273
325
  timer: 1,
274
326
  activity: 1,
275
327
  childWorkflow: 1,
276
- dependency: 1,
277
328
  signalWorkflow: 1,
278
329
  cancelWorkflow: 1,
330
+ condition: 1,
279
331
  };
280
332
  /**
281
333
  * This is set every time the workflow executes an activation
@@ -287,7 +339,6 @@ class State {
287
339
  this.random = function () {
288
340
  throw new common_1.IllegalStateError('Tried to use Math.random before Workflow has been initialized');
289
341
  };
290
- this.dependencies = {};
291
342
  this.dataConverter = common_1.defaultDataConverter;
292
343
  /**
293
344
  * Patches we know the status of for this workflow, as in {@link patched}
@@ -297,6 +348,7 @@ class State {
297
348
  * Patches we sent to core {@link patched}
298
349
  */
299
350
  this.sentPatches = new Set();
351
+ this.externalCalls = Array();
300
352
  }
301
353
  get now() {
302
354
  if (__classPrivateFieldGet(this, _State_now, "f") === undefined) {
@@ -307,13 +359,10 @@ class State {
307
359
  set now(value) {
308
360
  __classPrivateFieldSet(this, _State_now, value, "f");
309
361
  }
310
- getAndResetPendingExternalCalls() {
311
- if (this.pendingExternalCalls.length > 0) {
312
- const ret = this.pendingExternalCalls;
313
- this.pendingExternalCalls = [];
314
- return ret;
315
- }
316
- return [];
362
+ getAndResetExternalCalls() {
363
+ const { externalCalls } = this;
364
+ this.externalCalls = [];
365
+ return externalCalls;
317
366
  }
318
367
  /**
319
368
  * Buffer a Workflow command to be collected at the end of the current activation.
@@ -1 +1 @@
1
- {"version":3,"file":"internals.js","sourceRoot":"","sources":["../src/internals.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gDAAwB;AACxB,+DAAiD;AACjD,+CAY4B;AAC5B,2DAAwD;AACxD,iCAAmC;AACnC,6CAA2D;AAE3D,qCAA2G;AAE3G,6DAAkD;AAUlD,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,cAAI,CAAC;AAC5B,UAAU,CAAC,SAAS,EAAE,CAAC;AAUvB,MAAa,SAAS;IACb,KAAK,CAAC,wBAAwB;QACnC,IAAI,aAAK,CAAC,QAAQ,KAAK,SAAS,EAAE;YAChC,MAAM,IAAI,0BAAiB,CAAC,wBAAwB,CAAC,CAAC;SACvD;QACD,OAAO,MAAM,aAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;IAEM,aAAa,CAAC,UAAsD;QACzE,MAAM,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,aAAK,CAAC;QACrC,IAAI,GAAG,KAAK,SAAS,IAAI,IAAI,KAAK,SAAS,EAAE;YAC3C,MAAM,IAAI,0BAAiB,CAAC,mCAAmC,CAAC,CAAC;SAClE;QACD,MAAM,OAAO,GAAG,IAAA,4BAAmB,EACjC,aAAK,CAAC,YAAY,CAAC,OAAO,EAC1B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,EAAE,EAAE,QAAQ,EAAE,aAAK,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,EAAE;KAChG,CAAC,CAAC;AACL,CAAC;AAED,KAAK,UAAU,SAAS,CAAC,OAAe,EAAE,KAAU;IAClD,aAAK,CAAC,WAAW,CAAC;QAChB,cAAc,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,IAAA,uBAAc,EAAC,IAAA,8BAAqB,EAAC,KAAK,CAAC,EAAE,aAAK,CAAC,aAAa,CAAC,EAAE;KAC7G,CAAC,CAAC;AACL,CAAC;AAED,SAAgB,iBAAiB,CAAC,IAAgC,EAAE,OAAe;IACjF,MAAM,UAAU,GAAG,aAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxD,IAAI,UAAU,KAAK,SAAS,EAAE;QAC5B,MAAM,IAAI,0BAAiB,CAAC,6BAA6B,OAAO,EAAE,CAAC,CAAC;KACrE;IACD,aAAK,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,UAAU,CAAC;AACpB,CAAC;AAPD,8CAOC;AAED,SAAS,MAAM,CAAoC,UAAa;IAC9D,MAAM,GAAG,GAAG,UAAU,CAAC,GAAG,CAAC;IAC3B,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE;QACrC,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;KAC7D;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
package/lib/trigger.d.ts CHANGED
@@ -4,12 +4,10 @@
4
4
  * Trigger is CancellationScope aware, it is linked to the current scope on
5
5
  * construction and throws when that scope is cancelled.
6
6
  *
7
- * Useful for e.g. waiting for a signal from Workflow `execute`
8
- * @example
9
- * <!--SNIPSTART nodejs-blocked-interface-->
10
- * <!--SNIPEND-->
7
+ * Useful for e.g. waiting for unblocking a Workflow from a signal.
11
8
  *
12
- * <!--SNIPSTART nodejs-blocked-workflow-->
9
+ * @example
10
+ * <!--SNIPSTART typescript-blocked-workflow-->
13
11
  * <!--SNIPEND-->
14
12
  */
15
13
  export declare class Trigger<T> implements PromiseLike<T> {
package/lib/trigger.js CHANGED
@@ -8,12 +8,10 @@ const cancellation_scope_1 = require("./cancellation-scope");
8
8
  * Trigger is CancellationScope aware, it is linked to the current scope on
9
9
  * construction and throws when that scope is cancelled.
10
10
  *
11
- * Useful for e.g. waiting for a signal from Workflow `execute`
12
- * @example
13
- * <!--SNIPSTART nodejs-blocked-interface-->
14
- * <!--SNIPEND-->
11
+ * Useful for e.g. waiting for unblocking a Workflow from a signal.
15
12
  *
16
- * <!--SNIPSTART nodejs-blocked-workflow-->
13
+ * @example
14
+ * <!--SNIPSTART typescript-blocked-workflow-->
17
15
  * <!--SNIPEND-->
18
16
  */
19
17
  class Trigger {
@@ -1 +1 @@
1
- {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAEzD;;;;;;;;;;;;;GAaG;AACH,MAAa,OAAO;IAclB;QACE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,sCAAiB,CAAC,OAAO,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,WAAW,EAAE;gBAClD,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;aACrC;YACD,6DAA6D;YAC7D,aAAa;YACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,6DAA6D;YAC7D,aAAa;YACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,6BAA6B;QAC7B,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AA/BD,0BA+BC"}
1
+ {"version":3,"file":"trigger.js","sourceRoot":"","sources":["../src/trigger.ts"],"names":[],"mappings":";;;AAAA,6DAAyD;AAEzD;;;;;;;;;;;GAWG;AACH,MAAa,OAAO;IAclB;QACE,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACjD,MAAM,KAAK,GAAG,sCAAiB,CAAC,OAAO,EAAE,CAAC;YAC1C,IAAI,KAAK,CAAC,mBAAmB,IAAI,KAAK,CAAC,WAAW,EAAE;gBAClD,KAAK,CAAC,eAAe,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;aACrC;YACD,6DAA6D;YAC7D,aAAa;YACb,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;YACvB,6DAA6D;YAC7D,aAAa;YACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,CAAC,CAAC,CAAC;QACH,6BAA6B;QAC7B,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;CACF;AA/BD,0BA+BC"}
@@ -1,45 +1,23 @@
1
- /**
2
- * Exported functions for the Worker to interact with the Workflow isolate
3
- *
4
- * @module
5
- */
6
- import ivm from 'isolated-vm';
7
1
  import { WorkflowInfo } from './interfaces';
8
2
  import { state } from './internals';
3
+ import { ExternalCall } from './dependencies';
9
4
  import { IsolateExtension } from './promise-hooks';
10
- import { ApplyMode, ExternalDependencyFunction, ExternalCall } from './dependencies';
11
5
  export declare function setRequireFunc(fn: Exclude<typeof state['require'], undefined>): void;
12
6
  export declare function overrideGlobals(): void;
13
- /** Mock DOM element for Webpack dynamic imports */
14
- export interface MockElement {
15
- getAttribute(name: string): unknown;
16
- setAttribute(name: string, value: unknown): void;
17
- }
18
- /** Mock document object for Webpack dynamic imports */
19
- export interface MockDocument {
20
- head: {
21
- appendChild(): void;
22
- };
23
- getElementsByTagName(): MockElement[];
24
- createElement(): MockElement;
25
- }
26
7
  /**
27
- * Create a mock document object with mimimal required attributes to support Webpack dynamic imports
8
+ * Initialize the isolate runtime.
9
+ *
10
+ * Sets required internal state and instantiates the workflow and interceptors.
28
11
  */
29
- export declare function mockBrowserDocumentForWebpack(): MockDocument;
30
- export declare function initRuntime(info: WorkflowInfo, interceptorModules: string[], randomnessSeed: number[], isolateExtension: IsolateExtension, encodedStartWorkflow: Uint8Array): Promise<void>;
12
+ export declare function initRuntime(info: WorkflowInfo, interceptorModules: string[], randomnessSeed: number[], now: number, isolateExtension: IsolateExtension): Promise<void>;
13
+ export interface ActivationResult {
14
+ numBlockedConditions: number;
15
+ }
31
16
  /**
32
17
  * Run a chunk of activation jobs
33
18
  * @returns a boolean indicating whether job was processed or ignored
34
19
  */
35
- export declare function activate(encodedActivation: Uint8Array, batchIndex: number): Promise<ExternalCall[]>;
36
- declare type ActivationConclusion = {
37
- type: 'pending';
38
- pendingExternalCalls: ExternalCall[];
39
- } | {
40
- type: 'complete';
41
- encoded: Uint8Array;
42
- };
20
+ export declare function activate(encodedActivation: Uint8Array, batchIndex: number): Promise<ActivationResult>;
43
21
  /**
44
22
  * Conclude a single activation.
45
23
  * Should be called after processing all activation jobs and queued microtasks.
@@ -47,20 +25,11 @@ declare type ActivationConclusion = {
47
25
  * Activation may be in either `complete` or `pending` state according to pending external dependency calls.
48
26
  * Activation failures are handled in the main Node.js isolate.
49
27
  */
50
- export declare function concludeActivation(): ActivationConclusion;
51
- export declare function getAndResetPendingExternalCalls(): ExternalCall[];
28
+ export declare function concludeActivation(): Uint8Array;
29
+ export declare function getAndResetExternalCalls(): ExternalCall[];
52
30
  /**
53
- * Inject an external dependency function into the Workflow via global state.
54
- * The injected function is available via {@link dependencies}.
55
- */
56
- export declare function inject(ifaceName: string, fnName: string, dependency: ivm.Reference<ExternalDependencyFunction>, applyMode: ApplyMode, transferOptions: ivm.TransferOptionsBidirectional): void;
57
- export interface ExternalDependencyResult {
58
- seq: number;
59
- result: any;
60
- error: any;
61
- }
62
- /**
63
- * Resolve external dependency function calls with given results.
31
+ * Loop through all blocked conditions, evaluate and unblock if possible.
32
+ *
33
+ * @returns number of unblocked conditions.
64
34
  */
65
- export declare function resolveExternalDependencies(results: ExternalDependencyResult[]): void;
66
- export {};
35
+ export declare function tryUnblockConditions(): number;
@@ -1,51 +1,61 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveExternalDependencies = exports.inject = exports.getAndResetPendingExternalCalls = exports.concludeActivation = exports.activate = exports.initRuntime = exports.mockBrowserDocumentForWebpack = exports.overrideGlobals = exports.setRequireFunc = void 0;
3
+ exports.tryUnblockConditions = exports.getAndResetExternalCalls = exports.concludeActivation = exports.activate = exports.initRuntime = exports.overrideGlobals = exports.setRequireFunc = void 0;
4
+ /**
5
+ * Exported functions for the Worker to interact with the Workflow isolate
6
+ *
7
+ * @module
8
+ */
4
9
  const common_1 = require("@temporalio/common");
5
10
  const coresdk_1 = require("@temporalio/proto/lib/coresdk");
6
11
  const internals_1 = require("./internals");
7
12
  const alea_1 = require("./alea");
8
- const promise_hooks_1 = require("./promise-hooks");
9
13
  const errors_1 = require("./errors");
10
- const dependencies_1 = require("./dependencies");
14
+ const promise_hooks_1 = require("./promise-hooks");
11
15
  function setRequireFunc(fn) {
12
16
  internals_1.state.require = fn;
13
17
  }
14
18
  exports.setRequireFunc = setRequireFunc;
15
19
  function overrideGlobals() {
16
20
  const global = globalThis;
17
- // Mock any weak reference holding structures because GC is non-deterministic.
21
+ // Mock any weak reference because GC is non-deterministic and the effect is observable from the Workflow.
18
22
  // WeakRef is implemented in V8 8.4 which is embedded in node >=14.6.0.
19
23
  // Workflow developer will get a meaningful exception if they try to use these.
20
- global.WeakMap = function () {
21
- throw new errors_1.DeterminismViolationError('WeakMap cannot be used in workflows because v8 GC is non-deterministic');
22
- };
23
- global.WeakSet = function () {
24
- throw new errors_1.DeterminismViolationError('WeakSet cannot be used in workflows because v8 GC is non-deterministic');
25
- };
26
24
  global.WeakRef = function () {
27
25
  throw new errors_1.DeterminismViolationError('WeakRef cannot be used in workflows because v8 GC is non-deterministic');
28
26
  };
27
+ global.FinalizationRegistry = function () {
28
+ throw new errors_1.DeterminismViolationError('FinalizationRegistry cannot be used in workflows because v8 GC is non-deterministic');
29
+ };
29
30
  const OriginalDate = globalThis.Date;
30
- global.Date = function () {
31
+ global.Date = function (...args) {
32
+ if (args.length > 0) {
33
+ return new OriginalDate(...args);
34
+ }
31
35
  return new OriginalDate(internals_1.state.now);
32
36
  };
33
37
  global.Date.now = function () {
34
38
  return internals_1.state.now;
35
39
  };
40
+ global.Date.parse = OriginalDate.parse.bind(OriginalDate);
41
+ global.Date.UTC = OriginalDate.UTC.bind(OriginalDate);
36
42
  global.Date.prototype = OriginalDate.prototype;
43
+ /**
44
+ * @param ms sleep duration - number of milliseconds. If given a negative number, value will be set to 1.
45
+ */
37
46
  global.setTimeout = function (cb, ms, ...args) {
47
+ ms = Math.max(1, ms);
38
48
  const seq = internals_1.state.nextSeqs.timer++;
39
- internals_1.state.completions.timer.set(seq, {
40
- resolve: () => cb(...args),
41
- reject: () => undefined /* ignore cancellation */,
42
- });
43
- internals_1.state.pushCommand({
44
- startTimer: {
45
- seq,
46
- startToFireTimeout: (0, common_1.msToTs)(ms),
47
- },
48
- });
49
+ // Create a Promise for AsyncLocalStorage to be able to track this completion using promise hooks.
50
+ new Promise((resolve, reject) => {
51
+ internals_1.state.completions.timer.set(seq, { resolve, reject });
52
+ internals_1.state.pushCommand({
53
+ startTimer: {
54
+ seq,
55
+ startToFireTimeout: (0, common_1.msToTs)(ms),
56
+ },
57
+ });
58
+ }).then(() => cb(...args), () => undefined /* ignore cancellation */);
49
59
  return seq;
50
60
  };
51
61
  global.clearTimeout = function (handle) {
@@ -62,44 +72,27 @@ function overrideGlobals() {
62
72
  }
63
73
  exports.overrideGlobals = overrideGlobals;
64
74
  /**
65
- * Create a mock document object with mimimal required attributes to support Webpack dynamic imports
75
+ * Initialize the isolate runtime.
76
+ *
77
+ * Sets required internal state and instantiates the workflow and interceptors.
66
78
  */
67
- function mockBrowserDocumentForWebpack() {
68
- const attrs = new Map();
69
- const el = {
70
- getAttribute: (name) => attrs.get(name),
71
- setAttribute: (name, value) => {
72
- attrs.set(name, value);
73
- },
74
- };
75
- return {
76
- head: {
77
- appendChild: () => undefined,
78
- },
79
- getElementsByTagName: () => {
80
- return [el];
81
- },
82
- createElement: () => {
83
- return el;
84
- },
85
- };
86
- }
87
- exports.mockBrowserDocumentForWebpack = mockBrowserDocumentForWebpack;
88
- async function initRuntime(info, interceptorModules, randomnessSeed, isolateExtension, encodedStartWorkflow) {
79
+ async function initRuntime(info, interceptorModules, randomnessSeed, now, isolateExtension) {
89
80
  // Globals are overridden while building the isolate before loading user code.
90
81
  // For some reason the `WeakRef` mock is not restored properly when creating an isolate from snapshot in node 14 (at least on ubuntu), override again.
91
82
  globalThis.WeakRef = function () {
92
83
  throw new errors_1.DeterminismViolationError('WeakRef cannot be used in workflows because v8 GC is non-deterministic');
93
84
  };
94
85
  internals_1.state.info = info;
86
+ internals_1.state.now = now;
95
87
  internals_1.state.random = (0, alea_1.alea)(randomnessSeed);
96
88
  promise_hooks_1.HookManager.instance.setIsolateExtension(isolateExtension);
97
89
  const { require: req } = internals_1.state;
98
90
  if (req === undefined) {
99
91
  throw new common_1.IllegalStateError('Workflow has not been initialized');
100
92
  }
101
- for (const mod of interceptorModules) {
102
- const factory = req(mod, 'interceptors');
93
+ for (const modName of interceptorModules) {
94
+ const mod = await req(modName);
95
+ const factory = mod.interceptors;
103
96
  if (factory !== undefined) {
104
97
  if (typeof factory !== 'function') {
105
98
  throw new TypeError(`interceptors must be a function, got: ${factory}`);
@@ -110,27 +103,21 @@ async function initRuntime(info, interceptorModules, randomnessSeed, isolateExte
110
103
  internals_1.state.interceptors.internals.push(...(interceptors.internals ?? []));
111
104
  }
112
105
  }
113
- const { headers, arguments: args } = coresdk_1.coresdk.workflow_activation.StartWorkflow.decodeDelimited(encodedStartWorkflow);
114
- const create = (0, common_1.composeInterceptors)(internals_1.state.interceptors.inbound, 'create', async ({ args }) => {
115
- let mod;
116
- try {
117
- mod = req(undefined, info.workflowType);
118
- if (typeof mod !== 'function') {
119
- throw new TypeError(`'${info.workflowType}' is not a function`);
120
- }
106
+ let workflow;
107
+ try {
108
+ const mod = await req(undefined);
109
+ workflow = mod[info.workflowType];
110
+ if (typeof workflow !== 'function') {
111
+ throw new TypeError(`'${info.workflowType}' is not a function`);
121
112
  }
122
- catch (err) {
123
- const failure = common_1.ApplicationFailure.nonRetryable((0, common_1.errorMessage)(err), 'ReferenceError');
124
- failure.stack = failure.stack?.split('\n')[0];
125
- throw failure;
126
- }
127
- return mod(...args);
128
- });
129
- internals_1.state.workflow =
130
- (await create({
131
- headers,
132
- args: (0, common_1.arrayFromPayloadsSync)(internals_1.state.dataConverter, args),
133
- }).catch(internals_1.handleWorkflowFailure)) ?? undefined;
113
+ }
114
+ catch (err) {
115
+ const failure = common_1.ApplicationFailure.nonRetryable((0, common_1.errorMessage)(err), 'ReferenceError');
116
+ failure.stack = failure.stack?.split('\n')[0];
117
+ (0, internals_1.handleWorkflowFailure)(failure);
118
+ return;
119
+ }
120
+ internals_1.state.workflow = workflow;
134
121
  }
135
122
  exports.initRuntime = initRuntime;
136
123
  /**
@@ -138,6 +125,7 @@ exports.initRuntime = initRuntime;
138
125
  * @returns a boolean indicating whether job was processed or ignored
139
126
  */
140
127
  async function activate(encodedActivation, batchIndex) {
128
+ const activation = coresdk_1.coresdk.workflow_activation.WFActivation.decodeDelimited(encodedActivation);
141
129
  const intercept = (0, common_1.composeInterceptors)(internals_1.state.interceptors.internals, 'activate', async ({ activation, batchIndex }) => {
142
130
  if (batchIndex === 0) {
143
131
  if (internals_1.state.info === undefined) {
@@ -170,13 +158,16 @@ async function activate(encodedActivation, batchIndex) {
170
158
  return;
171
159
  }
172
160
  await internals_1.state.activator[job.variant](variant /* TODO: TS is struggling with `true` and `{}` */);
161
+ tryUnblockConditions();
173
162
  }));
174
163
  });
175
164
  await intercept({
176
- activation: coresdk_1.coresdk.workflow_activation.WFActivation.decodeDelimited(encodedActivation),
165
+ activation,
177
166
  batchIndex,
178
167
  });
179
- return internals_1.state.getAndResetPendingExternalCalls();
168
+ return {
169
+ numBlockedConditions: internals_1.state.blockedConditions.size,
170
+ };
180
171
  }
181
172
  exports.activate = activate;
182
173
  /**
@@ -187,64 +178,42 @@ exports.activate = activate;
187
178
  * Activation failures are handled in the main Node.js isolate.
188
179
  */
189
180
  function concludeActivation() {
190
- const pendingExternalCalls = internals_1.state.getAndResetPendingExternalCalls();
191
- if (pendingExternalCalls.length > 0) {
192
- return { type: 'pending', pendingExternalCalls };
193
- }
194
181
  const intercept = (0, common_1.composeInterceptors)(internals_1.state.interceptors.internals, 'concludeActivation', (input) => input);
195
182
  const { info } = internals_1.state;
196
183
  const { commands } = intercept({ commands: internals_1.state.commands });
197
- const encoded = coresdk_1.coresdk.workflow_completion.WFActivationCompletion.encodeDelimited({
184
+ internals_1.state.commands = [];
185
+ return coresdk_1.coresdk.workflow_completion.WFActivationCompletion.encodeDelimited({
198
186
  runId: info?.runId,
199
187
  successful: { commands },
200
188
  }).finish();
201
- internals_1.state.commands = [];
202
- return { type: 'complete', encoded };
203
189
  }
204
190
  exports.concludeActivation = concludeActivation;
205
- function getAndResetPendingExternalCalls() {
206
- return internals_1.state.getAndResetPendingExternalCalls();
207
- }
208
- exports.getAndResetPendingExternalCalls = getAndResetPendingExternalCalls;
209
- /**
210
- * Inject an external dependency function into the Workflow via global state.
211
- * The injected function is available via {@link dependencies}.
212
- */
213
- function inject(ifaceName, fnName, dependency, applyMode, transferOptions) {
214
- if (internals_1.state.dependencies[ifaceName] === undefined) {
215
- internals_1.state.dependencies[ifaceName] = {};
216
- }
217
- if (applyMode === dependencies_1.ApplyMode.ASYNC) {
218
- internals_1.state.dependencies[ifaceName][fnName] = (...args) => new Promise((resolve, reject) => {
219
- const seq = internals_1.state.nextSeqs.dependency++;
220
- internals_1.state.completions.dependency.set(seq, {
221
- resolve,
222
- reject,
223
- });
224
- internals_1.state.pendingExternalCalls.push({ ifaceName, fnName, args, seq });
225
- });
226
- }
227
- else if (applyMode === dependencies_1.ApplyMode.ASYNC_IGNORED) {
228
- internals_1.state.dependencies[ifaceName][fnName] = (...args) => internals_1.state.pendingExternalCalls.push({ ifaceName, fnName, args });
229
- }
230
- else {
231
- internals_1.state.dependencies[ifaceName][fnName] = (...args) => dependency[applyMode](undefined, args, transferOptions);
232
- }
191
+ function getAndResetExternalCalls() {
192
+ return internals_1.state.getAndResetExternalCalls();
233
193
  }
234
- exports.inject = inject;
194
+ exports.getAndResetExternalCalls = getAndResetExternalCalls;
235
195
  /**
236
- * Resolve external dependency function calls with given results.
196
+ * Loop through all blocked conditions, evaluate and unblock if possible.
197
+ *
198
+ * @returns number of unblocked conditions.
237
199
  */
238
- function resolveExternalDependencies(results) {
239
- for (const { seq, result, error } of results) {
240
- const completion = (0, internals_1.consumeCompletion)('dependency', seq);
241
- if (error) {
242
- completion.reject(error);
200
+ function tryUnblockConditions() {
201
+ let numUnblocked = 0;
202
+ for (;;) {
203
+ const prevUnblocked = numUnblocked;
204
+ for (const [seq, cond] of internals_1.state.blockedConditions.entries()) {
205
+ if (cond.fn()) {
206
+ cond.resolve();
207
+ numUnblocked++;
208
+ // It is safe to delete elements during map iteration
209
+ internals_1.state.blockedConditions.delete(seq);
210
+ }
243
211
  }
244
- else {
245
- completion.resolve(result);
212
+ if (prevUnblocked === numUnblocked) {
213
+ break;
246
214
  }
247
215
  }
216
+ return numUnblocked;
248
217
  }
249
- exports.resolveExternalDependencies = resolveExternalDependencies;
218
+ exports.tryUnblockConditions = tryUnblockConditions;
250
219
  //# sourceMappingURL=worker-interface.js.map