@temporalio/workflow 0.23.0 → 1.0.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.
@@ -30,7 +30,6 @@ exports.errorToFailure = exports.dispose = exports.tryUnblockConditions = export
30
30
  * @module
31
31
  */
32
32
  const common_1 = require("@temporalio/common");
33
- const wrapped_payload_converter_1 = require("@temporalio/common/lib/converter/wrapped-payload-converter");
34
33
  const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
35
34
  const alea_1 = require("./alea");
36
35
  const cancellation_scope_1 = require("./cancellation-scope");
@@ -101,19 +100,21 @@ exports.overrideGlobals = overrideGlobals;
101
100
  *
102
101
  * Sets required internal state and instantiates the workflow and interceptors.
103
102
  */
104
- async function initRuntime({ info, randomnessSeed, now, patches }) {
103
+ async function initRuntime({ info, randomnessSeed, now, patches, isReplaying, historyLength, }) {
104
+ const global = globalThis;
105
105
  // Set the runId globally on the context so it can be retrieved in the case
106
106
  // of an unhandled promise rejection.
107
- globalThis.__TEMPORAL__.runId = info.runId;
108
- // Globals are overridden while building the isolate before loading user code.
109
- // 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.
110
- globalThis.WeakRef = function () {
111
- throw new errors_1.DeterminismViolationError('WeakRef cannot be used in Workflows because v8 GC is non-deterministic');
107
+ global.__TEMPORAL__.runId = info.runId;
108
+ // Set the promiseStackStore so promises can be tracked
109
+ global.__TEMPORAL__.promiseStackStore = {
110
+ promiseToStack: new Map(),
111
+ childToParent: new Map(),
112
112
  };
113
113
  internals_1.state.info = info;
114
114
  internals_1.state.now = now;
115
115
  internals_1.state.random = (0, alea_1.alea)(randomnessSeed);
116
- if (info.isReplaying) {
116
+ internals_1.state.historyLength = historyLength;
117
+ if (isReplaying) {
117
118
  for (const patch of patches) {
118
119
  internals_1.state.knownPresentPatches.add(patch);
119
120
  }
@@ -124,7 +125,7 @@ async function initRuntime({ info, randomnessSeed, now, patches }) {
124
125
  const customPayloadConverter = (await Promise.resolve().then(() => __importStar(require('__temporal_custom_payload_converter')))).payloadConverter;
125
126
  // The `payloadConverter` export is validated in the Worker
126
127
  if (customPayloadConverter !== undefined) {
127
- internals_1.state.payloadConverter = new wrapped_payload_converter_1.WrappedPayloadConverter(customPayloadConverter);
128
+ internals_1.state.payloadConverter = customPayloadConverter;
128
129
  }
129
130
  const { importWorkflows, importInterceptors } = internals_1.state;
130
131
  if (importWorkflows === undefined || importInterceptors === undefined) {
@@ -155,8 +156,8 @@ exports.initRuntime = initRuntime;
155
156
  * Run a chunk of activation jobs
156
157
  * @returns a boolean indicating whether job was processed or ignored
157
158
  */
158
- async function activate(activation, batchIndex) {
159
- const intercept = (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.internals, 'activate', async ({ activation, batchIndex }) => {
159
+ function activate(activation, batchIndex) {
160
+ const intercept = (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.internals, 'activate', ({ activation, batchIndex }) => {
160
161
  if (batchIndex === 0) {
161
162
  if (internals_1.state.info === undefined) {
162
163
  throw new internal_workflow_common_1.IllegalStateError('Workflow has not been initialized');
@@ -168,7 +169,11 @@ async function activate(activation, batchIndex) {
168
169
  // timestamp will not be updated for activation that contain only queries
169
170
  internals_1.state.now = (0, internal_workflow_common_1.tsToMs)(activation.timestamp);
170
171
  }
171
- internals_1.state.info.isReplaying = activation.isReplaying ?? false;
172
+ if (activation.historyLength == null) {
173
+ throw new TypeError('Got activation with no historyLength');
174
+ }
175
+ internals_1.state.isReplaying = activation.isReplaying ?? false;
176
+ internals_1.state.historyLength = activation.historyLength;
172
177
  }
173
178
  // Cast from the interface to the class which has the `variant` attribute.
174
179
  // This is safe because we know that activation is a proto class.
@@ -191,7 +196,7 @@ async function activate(activation, batchIndex) {
191
196
  tryUnblockConditions();
192
197
  }
193
198
  });
194
- await intercept({
199
+ intercept({
195
200
  activation,
196
201
  batchIndex,
197
202
  });
@@ -1 +1 @@
1
-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AAI,aAAa,KAAK,YAAY,EAAE;YAClC,MAAM;SACP;KACF;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAjBD,oDAiBC;AAEM,KAAK,UAAU,OAAO;IAC3B,MAAM,OAAO,GAAG,IAAA,8CAAmB,EAAC,iBAAK,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,KAAK,IAAI,EAAE;QACtF,4BAAO,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,CAAC,EAAE,CAAC,CAAC;AACpB,CAAC;AALD,0BAKC;AAED,SAAgB,cAAc,CAAC,GAAY;IACzC,OAAO,IAAA,uBAAe,EAAC,GAAG,EAAE,iBAAK,CAAC,gBAAgB,CAAC,CAAC;AACtD,CAAC;AAFD,wCAEC"}
@@ -54,5 +54,5 @@ export interface ChildWorkflowHandle<T extends Workflow> extends BaseWorkflowHan
54
54
  /**
55
55
  * The runId of the initial run of the bound Workflow
56
56
  */
57
- readonly originalRunId: string;
57
+ readonly firstExecutionRunId: string;
58
58
  }
package/lib/workflow.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ActivityFunction, ActivityInterface, ActivityOptions, LocalActivityOptions, QueryDefinition, SignalDefinition, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/internal-workflow-common';
1
+ import { ActivityFunction, ActivityInterface, ActivityOptions, LocalActivityOptions, QueryDefinition, SearchAttributes, SignalDefinition, WithWorkflowArgs, Workflow, WorkflowResultType, WorkflowReturnType } from '@temporalio/internal-workflow-common';
2
2
  import { ChildWorkflowOptions, ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions, WorkflowInfo } from './interfaces';
3
3
  import { Sinks } from './sinks';
4
4
  import { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
@@ -11,8 +11,8 @@ export declare function addDefaultWorkflowOptions<T extends Workflow>(opts: With
11
11
  *
12
12
  * Schedules a timer on the Temporal service.
13
13
  *
14
- * @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds. If given a negative number, value will be set to 1.
15
- *
14
+ * @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds.
15
+ * If given a negative number or 0, value will be set to 1.
16
16
  */
17
17
  export declare function sleep(ms: number | string): Promise<void>;
18
18
  export interface ActivityInfo {
@@ -20,10 +20,6 @@ export interface ActivityInfo {
20
20
  type: string;
21
21
  }
22
22
  export declare type InternalActivityFunction<P extends any[], R> = ActivityFunction<P, R> & ActivityInfo;
23
- /**
24
- * @hidden
25
- */
26
- export declare function validateActivityOptions(options: ActivityOptions): void;
27
23
  /**
28
24
  * Schedule an activity and run outbound interceptors
29
25
  * @hidden
@@ -261,7 +257,7 @@ export declare function uuid4(): string;
261
257
  /**
262
258
  * Patch or upgrade workflow code by checking or stating that this workflow has a certain patch.
263
259
  *
264
- * See [docs page](https://docs.temporal.io/docs/typescript/versioning) for info.
260
+ * See [docs page](https://docs.temporal.io/typescript/versioning) for info.
265
261
  *
266
262
  * If the workflow is replaying an existing history, then this function returns true if that
267
263
  * history was produced by a worker which also had a `patched` call with the same `patchId`.
@@ -279,7 +275,7 @@ export declare function patched(patchId: string): boolean;
279
275
  /**
280
276
  * Indicate that a patch is being phased out.
281
277
  *
282
- * See [docs page](https://docs.temporal.io/docs/typescript/versioning) for info.
278
+ * See [docs page](https://docs.temporal.io/typescript/versioning) for info.
283
279
  *
284
280
  * Workflows with this call may be deployed alongside workflows with a {@link patched} call, but
285
281
  * they must *not* be deployed while any workers still exist running old code without a
@@ -333,3 +329,62 @@ export declare type Handler<Ret, Args extends any[], T extends SignalDefinition<
333
329
  * @param handler a compatible handler function for the given definition or `undefined` to unset the handler.
334
330
  */
335
331
  export declare function setHandler<Ret, Args extends any[], T extends SignalDefinition<Args> | QueryDefinition<Ret, Args>>(def: T, handler: Handler<Ret, Args, T> | undefined): void;
332
+ /**
333
+ * Updates this Workflow's Search Attributes by merging the provided `searchAttributes` with the existing Search
334
+ * Attributes, `workflowInfo().searchAttributes`.
335
+ *
336
+ * For example, this Workflow code:
337
+ *
338
+ * ```ts
339
+ * upsertSearchAttributes({
340
+ * CustomIntField: [1, 2, 3],
341
+ * CustomBoolField: [true]
342
+ * });
343
+ * upsertSearchAttributes({
344
+ * CustomIntField: [42],
345
+ * CustomKeywordField: ['durable code', 'is great']
346
+ * });
347
+ * ```
348
+ *
349
+ * would result in the Workflow having these Search Attributes:
350
+ *
351
+ * ```ts
352
+ * {
353
+ * CustomIntField: [42],
354
+ * CustomBoolField: [true],
355
+ * CustomKeywordField: ['durable code', 'is great']
356
+ * }
357
+ * ```
358
+ *
359
+ * @param searchAttributes The Record to merge. Use a value of `[]` to clear a Search Attribute.
360
+ */
361
+ export declare function upsertSearchAttributes(searchAttributes: SearchAttributes): void;
362
+ /**
363
+ * Unsafe information about the currently executing Workflow Task.
364
+ *
365
+ * Never rely on this information in Workflow logic as it will cause non-deterministic behavior.
366
+ */
367
+ export interface UnsafeTaskInfo {
368
+ isReplaying: boolean;
369
+ }
370
+ /**
371
+ * Information about the currently executing Workflow Task.
372
+ *
373
+ * Meant for advanced usage.
374
+ */
375
+ export interface TaskInfo {
376
+ /**
377
+ * Length of Workflow history up until the current Workflow Task.
378
+ *
379
+ * You may safely use this information to decide when to {@link continueAsNew}.
380
+ */
381
+ historyLength: number;
382
+ unsafe: UnsafeTaskInfo;
383
+ }
384
+ /**
385
+ * Get information about the currently executing Workflow Task.
386
+ *
387
+ * See {@link TaskInfo}
388
+ */
389
+ export declare function taskInfo(): TaskInfo;
390
+ export declare const stackTraceQuery: QueryDefinition<string, []>;
package/lib/workflow.js CHANGED
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setHandler = exports.defineQuery = exports.defineSignal = exports.condition = exports.deprecatePatch = exports.patched = exports.uuid4 = exports.continueAsNew = exports.makeContinueAsNewFunc = exports.proxySinks = exports.inWorkflowContext = exports.workflowInfo = exports.executeChild = exports.startChild = exports.getExternalWorkflowHandle = exports.proxyLocalActivities = exports.proxyActivities = exports.scheduleLocalActivity = exports.scheduleActivity = exports.validateActivityOptions = exports.sleep = exports.addDefaultWorkflowOptions = void 0;
3
+ exports.stackTraceQuery = exports.taskInfo = exports.upsertSearchAttributes = exports.setHandler = exports.defineQuery = exports.defineSignal = exports.condition = exports.deprecatePatch = exports.patched = exports.uuid4 = exports.continueAsNew = exports.makeContinueAsNewFunc = exports.proxySinks = exports.inWorkflowContext = exports.workflowInfo = exports.executeChild = exports.startChild = exports.getExternalWorkflowHandle = exports.proxyLocalActivities = exports.proxyActivities = exports.scheduleLocalActivity = exports.scheduleActivity = exports.sleep = exports.addDefaultWorkflowOptions = void 0;
4
4
  const common_1 = require("@temporalio/common");
5
5
  const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
6
6
  const cancellation_scope_1 = require("./cancellation-scope");
7
7
  const interfaces_1 = require("./interfaces");
8
8
  const internals_1 = require("./internals");
9
+ const stack_helpers_1 = require("./stack-helpers");
9
10
  // Avoid a circular dependency
10
11
  (0, cancellation_scope_1.registerSleepImplementation)(sleep);
11
12
  /**
@@ -28,11 +29,11 @@ function timerNextHandler(input) {
28
29
  return new Promise((resolve, reject) => {
29
30
  const scope = cancellation_scope_1.CancellationScope.current();
30
31
  if (scope.consideredCancelled) {
31
- scope.cancelRequested.catch(reject);
32
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
32
33
  return;
33
34
  }
34
35
  if (scope.cancellable) {
35
- scope.cancelRequested.catch((err) => {
36
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch((err) => {
36
37
  if (!internals_1.state.completions.timer.delete(input.seq)) {
37
38
  return; // Already resolved or never scheduled
38
39
  }
@@ -42,7 +43,7 @@ function timerNextHandler(input) {
42
43
  },
43
44
  });
44
45
  reject(err);
45
- });
46
+ }));
46
47
  }
47
48
  internals_1.state.pushCommand({
48
49
  startTimer: {
@@ -61,28 +62,24 @@ function timerNextHandler(input) {
61
62
  *
62
63
  * Schedules a timer on the Temporal service.
63
64
  *
64
- * @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds. If given a negative number, value will be set to 1.
65
- *
65
+ * @param ms sleep duration - {@link https://www.npmjs.com/package/ms | ms} formatted string or number of milliseconds.
66
+ * If given a negative number or 0, value will be set to 1.
66
67
  */
67
68
  function sleep(ms) {
68
69
  const seq = internals_1.state.nextSeqs.timer++;
69
- const execute = (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.outbound, 'startTimer', timerNextHandler);
70
70
  const durationMs = Math.max(1, (0, internal_workflow_common_1.msToNumber)(ms));
71
+ const execute = (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.outbound, 'startTimer', timerNextHandler);
71
72
  return execute({
72
73
  durationMs,
73
74
  seq,
74
75
  });
75
76
  }
76
77
  exports.sleep = sleep;
77
- /**
78
- * @hidden
79
- */
80
78
  function validateActivityOptions(options) {
81
79
  if (options.scheduleToCloseTimeout === undefined && options.startToCloseTimeout === undefined) {
82
80
  throw new TypeError('Required either scheduleToCloseTimeout or startToCloseTimeout');
83
81
  }
84
82
  }
85
- exports.validateActivityOptions = validateActivityOptions;
86
83
  // Use same validation we use for normal activities
87
84
  const validateLocalActivityOptions = validateActivityOptions;
88
85
  /**
@@ -93,16 +90,16 @@ const validateLocalActivityOptions = validateActivityOptions;
93
90
  /**
94
91
  * Push a scheduleActivity command into state accumulator and register completion
95
92
  */
96
- async function scheduleActivityNextHandler({ options, args, headers, seq, activityType, }) {
93
+ function scheduleActivityNextHandler({ options, args, headers, seq, activityType }) {
97
94
  validateActivityOptions(options);
98
95
  return new Promise((resolve, reject) => {
99
96
  const scope = cancellation_scope_1.CancellationScope.current();
100
97
  if (scope.consideredCancelled) {
101
- scope.cancelRequested.catch(reject);
98
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
102
99
  return;
103
100
  }
104
101
  if (scope.cancellable) {
105
- scope.cancelRequested.catch(() => {
102
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(() => {
106
103
  if (!internals_1.state.completions.activity.has(seq)) {
107
104
  return; // Already resolved or never scheduled
108
105
  }
@@ -111,7 +108,7 @@ async function scheduleActivityNextHandler({ options, args, headers, seq, activi
111
108
  seq,
112
109
  },
113
110
  });
114
- });
111
+ }));
115
112
  }
116
113
  internals_1.state.pushCommand({
117
114
  scheduleActivity: {
@@ -143,11 +140,11 @@ async function scheduleLocalActivityNextHandler({ options, args, headers, seq, a
143
140
  return new Promise((resolve, reject) => {
144
141
  const scope = cancellation_scope_1.CancellationScope.current();
145
142
  if (scope.consideredCancelled) {
146
- scope.cancelRequested.catch(reject);
143
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
147
144
  return;
148
145
  }
149
146
  if (scope.cancellable) {
150
- scope.cancelRequested.catch(() => {
147
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(() => {
151
148
  if (!internals_1.state.completions.activity.has(seq)) {
152
149
  return; // Already resolved or never scheduled
153
150
  }
@@ -156,7 +153,7 @@ async function scheduleLocalActivityNextHandler({ options, args, headers, seq, a
156
153
  seq,
157
154
  },
158
155
  });
159
- });
156
+ }));
160
157
  }
161
158
  internals_1.state.pushCommand({
162
159
  scheduleLocalActivity: {
@@ -241,16 +238,16 @@ async function scheduleLocalActivity(activityType, args, options) {
241
238
  }
242
239
  }
243
240
  exports.scheduleLocalActivity = scheduleLocalActivity;
244
- async function startChildWorkflowExecutionNextHandler({ options, headers, workflowType, seq, }) {
241
+ function startChildWorkflowExecutionNextHandler({ options, headers, workflowType, seq, }) {
245
242
  const workflowId = options.workflowId ?? uuid4();
246
243
  const startPromise = new Promise((resolve, reject) => {
247
244
  const scope = cancellation_scope_1.CancellationScope.current();
248
245
  if (scope.consideredCancelled) {
249
- scope.cancelRequested.catch(reject);
246
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
250
247
  return;
251
248
  }
252
249
  if (scope.cancellable) {
253
- scope.cancelRequested.catch(() => {
250
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(() => {
254
251
  const complete = !internals_1.state.completions.childWorkflowComplete.has(seq);
255
252
  const started = !internals_1.state.completions.childWorkflowStart.has(seq);
256
253
  if (started && !complete) {
@@ -270,7 +267,7 @@ async function startChildWorkflowExecutionNextHandler({ options, headers, workfl
270
267
  });
271
268
  }
272
269
  // Nothing to cancel otherwise
273
- });
270
+ }));
274
271
  }
275
272
  internals_1.state.pushCommand({
276
273
  startChildWorkflowExecution: {
@@ -304,15 +301,19 @@ async function startChildWorkflowExecutionNextHandler({ options, headers, workfl
304
301
  // if the Workflow code will await it to capture the result in case it does.
305
302
  const completePromise = new Promise((resolve, reject) => {
306
303
  // Chain start Promise rejection to the complete Promise.
307
- startPromise.catch(reject);
304
+ (0, stack_helpers_1.untrackPromise)(startPromise.catch(reject));
308
305
  internals_1.state.completions.childWorkflowComplete.set(seq, {
309
306
  resolve,
310
307
  reject,
311
308
  });
312
309
  });
310
+ (0, stack_helpers_1.untrackPromise)(startPromise);
311
+ (0, stack_helpers_1.untrackPromise)(completePromise);
313
312
  // Prevent unhandled rejection because the completion might not be awaited
314
- completePromise.catch(() => undefined);
315
- return [startPromise, completePromise];
313
+ (0, stack_helpers_1.untrackPromise)(completePromise.catch(() => undefined));
314
+ const ret = new Promise((resolve) => resolve([startPromise, completePromise]));
315
+ (0, stack_helpers_1.untrackPromise)(ret);
316
+ return ret;
316
317
  }
317
318
  function signalWorkflowNextHandler({ seq, signalName, args, target, headers }) {
318
319
  return new Promise((resolve, reject) => {
@@ -321,16 +322,16 @@ function signalWorkflowNextHandler({ seq, signalName, args, target, headers }) {
321
322
  }
322
323
  const scope = cancellation_scope_1.CancellationScope.current();
323
324
  if (scope.consideredCancelled) {
324
- scope.cancelRequested.catch(reject);
325
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
325
326
  return;
326
327
  }
327
328
  if (scope.cancellable) {
328
- scope.cancelRequested.catch(() => {
329
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(() => {
329
330
  if (!internals_1.state.completions.signalWorkflow.has(seq)) {
330
331
  return;
331
332
  }
332
333
  internals_1.state.pushCommand({ cancelSignalWorkflow: { seq } });
333
- });
334
+ }));
334
335
  }
335
336
  internals_1.state.pushCommand({
336
337
  signalExternalWorkflowExecution: {
@@ -404,7 +405,7 @@ function proxyActivities(options) {
404
405
  if (typeof activityType !== 'string') {
405
406
  throw new TypeError(`Only strings are supported for Activity types, got: ${String(activityType)}`);
406
407
  }
407
- return (...args) => {
408
+ return function activityProxyFunction(...args) {
408
409
  return scheduleActivity(activityType, args, options);
409
410
  };
410
411
  },
@@ -436,7 +437,7 @@ function proxyLocalActivities(options) {
436
437
  if (typeof activityType !== 'string') {
437
438
  throw new TypeError(`Only strings are supported for Activity types, got: ${String(activityType)}`);
438
439
  }
439
- return (...args) => {
440
+ return function localActivityProxyFunction(...args) {
440
441
  return scheduleLocalActivity(activityType, args, options);
441
442
  };
442
443
  },
@@ -467,11 +468,11 @@ function getExternalWorkflowHandle(workflowId, runId) {
467
468
  // histories unless strictly required.
468
469
  const scope = cancellation_scope_1.CancellationScope.current();
469
470
  if (scope.cancellable) {
470
- scope.cancelRequested.catch((err) => {
471
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch((err) => {
471
472
  if (patched(EXTERNAL_WF_CANCEL_PATCH)) {
472
473
  reject(err);
473
474
  }
474
- });
475
+ }));
475
476
  }
476
477
  if (scope.consideredCancelled) {
477
478
  if (patched(EXTERNAL_WF_CANCEL_PATCH)) {
@@ -492,7 +493,7 @@ function getExternalWorkflowHandle(workflowId, runId) {
492
493
  internals_1.state.completions.cancelWorkflow.set(seq, { resolve, reject });
493
494
  });
494
495
  },
495
- async signal(def, ...args) {
496
+ signal(def, ...args) {
496
497
  return (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.outbound, 'signalWorkflow', signalWorkflowNextHandler)({
497
498
  seq: internals_1.state.nextSeqs.signalWorkflow++,
498
499
  signalName: typeof def === 'string' ? def : def.name,
@@ -517,12 +518,12 @@ async function startChild(workflowTypeOrFunc, options) {
517
518
  headers: {},
518
519
  workflowType,
519
520
  });
520
- const originalRunId = await started;
521
+ const firstExecutionRunId = await started;
521
522
  return {
522
523
  workflowId: optionsWithDefaults.workflowId,
523
- originalRunId,
524
- result() {
525
- return completed;
524
+ firstExecutionRunId,
525
+ async result() {
526
+ return (await completed);
526
527
  },
527
528
  async signal(def, ...args) {
528
529
  return (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.outbound, 'signalWorkflow', signalWorkflowNextHandler)({
@@ -543,13 +544,16 @@ async function executeChild(workflowTypeOrFunc, options) {
543
544
  const optionsWithDefaults = addDefaultWorkflowOptions(options ?? {});
544
545
  const workflowType = typeof workflowTypeOrFunc === 'string' ? workflowTypeOrFunc : workflowTypeOrFunc.name;
545
546
  const execute = (0, internal_workflow_common_1.composeInterceptors)(internals_1.state.interceptors.outbound, 'startChildWorkflowExecution', startChildWorkflowExecutionNextHandler);
546
- const [_started, completed] = await execute({
547
+ const execPromise = execute({
547
548
  seq: internals_1.state.nextSeqs.childWorkflow++,
548
549
  options: optionsWithDefaults,
549
550
  headers: {},
550
551
  workflowType,
551
552
  });
552
- return (await completed);
553
+ (0, stack_helpers_1.untrackPromise)(execPromise);
554
+ const completedPromise = execPromise.then(([_started, completed]) => completed);
555
+ (0, stack_helpers_1.untrackPromise)(completedPromise);
556
+ return completedPromise;
553
557
  }
554
558
  exports.executeChild = executeChild;
555
559
  /**
@@ -654,7 +658,9 @@ function makeContinueAsNewFunc(options) {
654
658
  headers,
655
659
  taskQueue: options.taskQueue,
656
660
  memo: options.memo,
657
- searchAttributes: options.searchAttributes,
661
+ searchAttributes: options.searchAttributes
662
+ ? (0, common_1.mapToPayloads)(common_1.searchAttributePayloadConverter, options.searchAttributes)
663
+ : undefined,
658
664
  workflowRunTimeout: (0, internal_workflow_common_1.msOptionalToTs)(options.workflowRunTimeout),
659
665
  workflowTaskTimeout: (0, internal_workflow_common_1.msOptionalToTs)(options.workflowTaskTimeout),
660
666
  });
@@ -718,7 +724,7 @@ exports.uuid4 = uuid4;
718
724
  /**
719
725
  * Patch or upgrade workflow code by checking or stating that this workflow has a certain patch.
720
726
  *
721
- * See [docs page](https://docs.temporal.io/docs/typescript/versioning) for info.
727
+ * See [docs page](https://docs.temporal.io/typescript/versioning) for info.
722
728
  *
723
729
  * If the workflow is replaying an existing history, then this function returns true if that
724
730
  * history was produced by a worker which also had a `patched` call with the same `patchId`.
@@ -739,7 +745,7 @@ exports.patched = patched;
739
745
  /**
740
746
  * Indicate that a patch is being phased out.
741
747
  *
742
- * See [docs page](https://docs.temporal.io/docs/typescript/versioning) for info.
748
+ * See [docs page](https://docs.temporal.io/typescript/versioning) for info.
743
749
  *
744
750
  * Workflows with this call may be deployed alongside workflows with a {@link patched} call, but
745
751
  * they must *not* be deployed while any workers still exist running old code without a
@@ -760,11 +766,10 @@ exports.deprecatePatch = deprecatePatch;
760
766
  function patchInternal(patchId, deprecated) {
761
767
  // Patch operation does not support interception at the moment, if it did,
762
768
  // this would be the place to start the interception chain
763
- const { isReplaying } = workflowInfo();
764
769
  if (internals_1.state.workflow === undefined) {
765
770
  throw new internal_workflow_common_1.IllegalStateError('Patches cannot be used before Workflow starts');
766
771
  }
767
- const usePatch = !isReplaying || internals_1.state.knownPresentPatches.has(patchId);
772
+ const usePatch = !internals_1.state.isReplaying || internals_1.state.knownPresentPatches.has(patchId);
768
773
  // Avoid sending commands for patches core already knows about.
769
774
  // This optimization enables development of automatic patching tools.
770
775
  if (usePatch && !internals_1.state.sentPatches.has(patchId)) {
@@ -777,7 +782,7 @@ function patchInternal(patchId, deprecated) {
777
782
  }
778
783
  async function condition(fn, timeout) {
779
784
  if (timeout) {
780
- return await cancellation_scope_1.CancellationScope.cancellable(async () => {
785
+ return cancellation_scope_1.CancellationScope.cancellable(async () => {
781
786
  try {
782
787
  return await Promise.race([sleep(timeout).then(() => false), conditionInner(fn).then(() => true)]);
783
788
  }
@@ -793,15 +798,15 @@ function conditionInner(fn) {
793
798
  return new Promise((resolve, reject) => {
794
799
  const scope = cancellation_scope_1.CancellationScope.current();
795
800
  if (scope.consideredCancelled) {
796
- scope.cancelRequested.catch(reject);
801
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch(reject));
797
802
  return;
798
803
  }
799
804
  const seq = internals_1.state.nextSeqs.condition++;
800
805
  if (scope.cancellable) {
801
- scope.cancelRequested.catch((err) => {
806
+ (0, stack_helpers_1.untrackPromise)(scope.cancelRequested.catch((err) => {
802
807
  internals_1.state.blockedConditions.delete(seq);
803
808
  reject(err);
804
- });
809
+ }));
805
810
  }
806
811
  // Eager evaluation
807
812
  if (fn()) {
@@ -864,4 +869,68 @@ function setHandler(def, handler) {
864
869
  }
865
870
  }
866
871
  exports.setHandler = setHandler;
872
+ /**
873
+ * Updates this Workflow's Search Attributes by merging the provided `searchAttributes` with the existing Search
874
+ * Attributes, `workflowInfo().searchAttributes`.
875
+ *
876
+ * For example, this Workflow code:
877
+ *
878
+ * ```ts
879
+ * upsertSearchAttributes({
880
+ * CustomIntField: [1, 2, 3],
881
+ * CustomBoolField: [true]
882
+ * });
883
+ * upsertSearchAttributes({
884
+ * CustomIntField: [42],
885
+ * CustomKeywordField: ['durable code', 'is great']
886
+ * });
887
+ * ```
888
+ *
889
+ * would result in the Workflow having these Search Attributes:
890
+ *
891
+ * ```ts
892
+ * {
893
+ * CustomIntField: [42],
894
+ * CustomBoolField: [true],
895
+ * CustomKeywordField: ['durable code', 'is great']
896
+ * }
897
+ * ```
898
+ *
899
+ * @param searchAttributes The Record to merge. Use a value of `[]` to clear a Search Attribute.
900
+ */
901
+ function upsertSearchAttributes(searchAttributes) {
902
+ if (!internals_1.state.info) {
903
+ throw new internal_workflow_common_1.IllegalStateError('`state.info` should be defined');
904
+ }
905
+ const mergedSearchAttributes = { ...internals_1.state.info.searchAttributes, ...searchAttributes };
906
+ if (!mergedSearchAttributes) {
907
+ throw new Error('searchAttributes must be a non-null SearchAttributes');
908
+ }
909
+ internals_1.state.pushCommand({
910
+ upsertWorkflowSearchAttributes: {
911
+ searchAttributes: (0, common_1.mapToPayloads)(common_1.searchAttributePayloadConverter, searchAttributes),
912
+ },
913
+ });
914
+ internals_1.state.info.searchAttributes = mergedSearchAttributes;
915
+ }
916
+ exports.upsertSearchAttributes = upsertSearchAttributes;
917
+ /**
918
+ * Get information about the currently executing Workflow Task.
919
+ *
920
+ * See {@link TaskInfo}
921
+ */
922
+ function taskInfo() {
923
+ const { isReplaying, historyLength } = internals_1.state;
924
+ if (isReplaying == null || historyLength == null) {
925
+ throw new internal_workflow_common_1.IllegalStateError('Workflow uninitialized');
926
+ }
927
+ return {
928
+ historyLength,
929
+ unsafe: {
930
+ isReplaying,
931
+ },
932
+ };
933
+ }
934
+ exports.taskInfo = taskInfo;
935
+ exports.stackTraceQuery = defineQuery('__stack_trace');
867
936
  //# sourceMappingURL=workflow.js.map