@temporalio/workflow 1.11.3 → 1.11.4

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/src/interfaces.ts CHANGED
@@ -11,7 +11,8 @@ import {
11
11
  Duration,
12
12
  VersioningIntent,
13
13
  } from '@temporalio/common';
14
- import { checkExtends, SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
14
+ import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
15
+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow/enums-helpers';
15
16
  import type { coresdk } from '@temporalio/proto';
16
17
 
17
18
  /**
@@ -273,16 +274,18 @@ export interface ContinueAsNewOptions {
273
274
  *
274
275
  * @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
275
276
  */
276
- export enum ChildWorkflowCancellationType {
277
+ export type ChildWorkflowCancellationType =
278
+ (typeof ChildWorkflowCancellationType)[keyof typeof ChildWorkflowCancellationType];
279
+ export const ChildWorkflowCancellationType = {
277
280
  /**
278
281
  * Don't send a cancellation request to the Child.
279
282
  */
280
- ABANDON = 0,
283
+ ABANDON: 'ABANDON',
281
284
 
282
285
  /**
283
286
  * Send a cancellation request to the Child. Immediately throw the error.
284
287
  */
285
- TRY_CANCEL = 1,
288
+ TRY_CANCEL: 'TRY_CANCEL',
286
289
 
287
290
  /**
288
291
  * Send a cancellation request to the Child. The Child may respect cancellation, in which case an error will be thrown
@@ -292,48 +295,102 @@ export enum ChildWorkflowCancellationType {
292
295
  *
293
296
  * @default
294
297
  */
295
- WAIT_CANCELLATION_COMPLETED = 2,
298
+ WAIT_CANCELLATION_COMPLETED: 'WAIT_CANCELLATION_COMPLETED',
296
299
 
297
300
  /**
298
301
  * Send a cancellation request to the Child. Throw the error once the Server receives the Child cancellation request.
299
302
  */
300
- WAIT_CANCELLATION_REQUESTED = 3,
301
- }
302
-
303
- checkExtends<coresdk.child_workflow.ChildWorkflowCancellationType, ChildWorkflowCancellationType>();
304
- checkExtends<ChildWorkflowCancellationType, coresdk.child_workflow.ChildWorkflowCancellationType>();
303
+ WAIT_CANCELLATION_REQUESTED: 'WAIT_CANCELLATION_REQUESTED',
304
+ } as const;
305
+
306
+ // ts-prune-ignore-next
307
+ export const [encodeChildWorkflowCancellationType, decodeChildWorkflowCancellationType] = makeProtoEnumConverters<
308
+ coresdk.child_workflow.ChildWorkflowCancellationType,
309
+ typeof coresdk.child_workflow.ChildWorkflowCancellationType,
310
+ keyof typeof coresdk.child_workflow.ChildWorkflowCancellationType,
311
+ typeof ChildWorkflowCancellationType,
312
+ ''
313
+ >(
314
+ {
315
+ [ChildWorkflowCancellationType.ABANDON]: 0,
316
+ [ChildWorkflowCancellationType.TRY_CANCEL]: 1,
317
+ [ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED]: 2,
318
+ [ChildWorkflowCancellationType.WAIT_CANCELLATION_REQUESTED]: 3,
319
+ } as const,
320
+ ''
321
+ );
305
322
 
306
323
  /**
307
324
  * How a Child Workflow reacts to the Parent Workflow reaching a Closed state.
308
325
  *
309
326
  * @see {@link https://docs.temporal.io/concepts/what-is-a-parent-close-policy/ | Parent Close Policy}
310
327
  */
311
- export enum ParentClosePolicy {
328
+ export type ParentClosePolicy = (typeof ParentClosePolicy)[keyof typeof ParentClosePolicy];
329
+ export const ParentClosePolicy = {
330
+ /**
331
+ * When the Parent is Closed, the Child is Terminated.
332
+ *
333
+ * @default
334
+ */
335
+ TERMINATE: 'TERMINATE',
336
+
337
+ /**
338
+ * When the Parent is Closed, nothing is done to the Child.
339
+ */
340
+ ABANDON: 'ABANDON',
341
+
342
+ /**
343
+ * When the Parent is Closed, the Child is Cancelled.
344
+ */
345
+ REQUEST_CANCEL: 'REQUEST_CANCEL',
346
+
347
+ /// Anything below this line has been deprecated
348
+
312
349
  /**
313
350
  * If a `ParentClosePolicy` is set to this, or is not set at all, the server default value will be used.
351
+ *
352
+ * @deprecated Either leave property `undefined`, or set an explicit policy instead.
314
353
  */
315
- PARENT_CLOSE_POLICY_UNSPECIFIED = 0,
354
+ PARENT_CLOSE_POLICY_UNSPECIFIED: undefined, // eslint-disable-line deprecation/deprecation
316
355
 
317
356
  /**
318
357
  * When the Parent is Closed, the Child is Terminated.
319
358
  *
320
- * @default
359
+ * @deprecated Use {@link ParentClosePolicy.TERMINATE} instead.
321
360
  */
322
- PARENT_CLOSE_POLICY_TERMINATE = 1,
361
+ PARENT_CLOSE_POLICY_TERMINATE: 'TERMINATE', // eslint-disable-line deprecation/deprecation
323
362
 
324
363
  /**
325
364
  * When the Parent is Closed, nothing is done to the Child.
365
+ *
366
+ * @deprecated Use {@link ParentClosePolicy.ABANDON} instead.
326
367
  */
327
- PARENT_CLOSE_POLICY_ABANDON = 2,
368
+ PARENT_CLOSE_POLICY_ABANDON: 'ABANDON', // eslint-disable-line deprecation/deprecation
328
369
 
329
370
  /**
330
371
  * When the Parent is Closed, the Child is Cancelled.
331
- */
332
- PARENT_CLOSE_POLICY_REQUEST_CANCEL = 3,
333
- }
334
-
335
- checkExtends<coresdk.child_workflow.ParentClosePolicy, ParentClosePolicy>();
336
- checkExtends<ParentClosePolicy, coresdk.child_workflow.ParentClosePolicy>();
372
+ *
373
+ * @deprecated Use {@link ParentClosePolicy.REQUEST_CANCEL} instead.
374
+ */
375
+ PARENT_CLOSE_POLICY_REQUEST_CANCEL: 'REQUEST_CANCEL', // eslint-disable-line deprecation/deprecation
376
+ } as const;
377
+
378
+ // ts-prune-ignore-next
379
+ export const [encodeParentClosePolicy, decodeParentClosePolicy] = makeProtoEnumConverters<
380
+ coresdk.child_workflow.ParentClosePolicy,
381
+ typeof coresdk.child_workflow.ParentClosePolicy,
382
+ keyof typeof coresdk.child_workflow.ParentClosePolicy,
383
+ typeof ParentClosePolicy,
384
+ 'PARENT_CLOSE_POLICY_'
385
+ >(
386
+ {
387
+ [ParentClosePolicy.TERMINATE]: 1,
388
+ [ParentClosePolicy.ABANDON]: 2,
389
+ [ParentClosePolicy.REQUEST_CANCEL]: 3,
390
+ UNSPECIFIED: 0,
391
+ } as const,
392
+ 'PARENT_CLOSE_POLICY_'
393
+ );
337
394
 
338
395
  export interface ChildWorkflowOptions extends CommonWorkflowOptions {
339
396
  /**
@@ -346,6 +403,8 @@ export interface ChildWorkflowOptions extends CommonWorkflowOptions {
346
403
  /**
347
404
  * Task queue to use for Workflow tasks. It should match a task queue specified when creating a
348
405
  * `Worker` that hosts the Workflow code.
406
+ *
407
+ * By default, a child is scheduled on the same Task Queue as the parent.
349
408
  */
350
409
  taskQueue?: string;
351
410
 
package/src/internals.ts CHANGED
@@ -24,7 +24,7 @@ import {
24
24
  SearchAttributes,
25
25
  } from '@temporalio/common';
26
26
  import { composeInterceptors } from '@temporalio/common/lib/interceptors';
27
- import { checkExtends } from '@temporalio/common/lib/type-helpers';
27
+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow';
28
28
  import type { coresdk, temporal } from '@temporalio/proto';
29
29
  import { alea, RNG } from './alea';
30
30
  import { RootCancellationScope } from './cancellation-scope';
@@ -48,13 +48,26 @@ import pkg from './pkg';
48
48
  import { SdkFlag, assertValidFlag } from './flags';
49
49
  import { executeWithLifecycleLogging, log } from './logs';
50
50
 
51
- enum StartChildWorkflowExecutionFailedCause {
52
- START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_UNSPECIFIED = 0,
53
- START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_EXISTS = 1,
54
- }
55
-
56
- checkExtends<coresdk.child_workflow.StartChildWorkflowExecutionFailedCause, StartChildWorkflowExecutionFailedCause>();
57
- checkExtends<StartChildWorkflowExecutionFailedCause, coresdk.child_workflow.StartChildWorkflowExecutionFailedCause>();
51
+ const StartChildWorkflowExecutionFailedCause = {
52
+ WORKFLOW_ALREADY_EXISTS: 'WORKFLOW_ALREADY_EXISTS',
53
+ } as const;
54
+ type StartChildWorkflowExecutionFailedCause =
55
+ (typeof StartChildWorkflowExecutionFailedCause)[keyof typeof StartChildWorkflowExecutionFailedCause];
56
+
57
+ const [_encodeStartChildWorkflowExecutionFailedCause, decodeStartChildWorkflowExecutionFailedCause] =
58
+ makeProtoEnumConverters<
59
+ coresdk.child_workflow.StartChildWorkflowExecutionFailedCause,
60
+ typeof coresdk.child_workflow.StartChildWorkflowExecutionFailedCause,
61
+ keyof typeof coresdk.child_workflow.StartChildWorkflowExecutionFailedCause,
62
+ typeof StartChildWorkflowExecutionFailedCause,
63
+ 'START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_'
64
+ >(
65
+ {
66
+ [StartChildWorkflowExecutionFailedCause.WORKFLOW_ALREADY_EXISTS]: 1,
67
+ UNSPECIFIED: 0,
68
+ } as const,
69
+ 'START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_'
70
+ );
58
71
 
59
72
  export interface Stack {
60
73
  formatted: string;
@@ -517,10 +530,7 @@ export class Activator implements ActivationHandler {
517
530
  if (activation.succeeded) {
518
531
  resolve(activation.succeeded.runId);
519
532
  } else if (activation.failed) {
520
- if (
521
- activation.failed.cause !==
522
- StartChildWorkflowExecutionFailedCause.START_CHILD_WORKFLOW_EXECUTION_FAILED_CAUSE_WORKFLOW_ALREADY_EXISTS
523
- ) {
533
+ if (decodeStartChildWorkflowExecutionFailedCause(activation.failed.cause) !== 'WORKFLOW_ALREADY_EXISTS') {
524
534
  throw new IllegalStateError('Got unknown StartChildWorkflowExecutionFailedCause');
525
535
  }
526
536
  if (!(activation.seq && activation.failed.workflowId && activation.failed.workflowType)) {
@@ -38,14 +38,14 @@ export function initRuntime(options: WorkflowCreateOptionsInternal): void {
38
38
  setActivatorUntyped(activator);
39
39
 
40
40
  // webpack alias to payloadConverterPath
41
- // eslint-disable-next-line @typescript-eslint/no-var-requires
41
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
42
42
  const customPayloadConverter = require('__temporal_custom_payload_converter').payloadConverter;
43
43
  // The `payloadConverter` export is validated in the Worker
44
44
  if (customPayloadConverter != null) {
45
45
  activator.payloadConverter = customPayloadConverter;
46
46
  }
47
47
  // webpack alias to failureConverterPath
48
- // eslint-disable-next-line @typescript-eslint/no-var-requires
48
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
49
49
  const customFailureConverter = require('__temporal_custom_failure_converter').failureConverter;
50
50
  // The `failureConverter` export is validated in the Worker
51
51
  if (customFailureConverter != null) {
package/src/workflow.ts CHANGED
@@ -2,6 +2,8 @@ import {
2
2
  ActivityFunction,
3
3
  ActivityOptions,
4
4
  compileRetryPolicy,
5
+ encodeActivityCancellationType,
6
+ encodeWorkflowIdReusePolicy,
5
7
  extractWorkflowType,
6
8
  HandlerUnfinishedPolicy,
7
9
  LocalActivityOptions,
@@ -46,6 +48,8 @@ import {
46
48
  UpdateHandlerOptions,
47
49
  WorkflowInfo,
48
50
  UpdateInfo,
51
+ encodeChildWorkflowCancellationType,
52
+ encodeParentClosePolicy,
49
53
  } from './interfaces';
50
54
  import { LocalActivityDoBackoff } from './errors';
51
55
  import { assertInWorkflowContext, getActivator, maybeGetActivator } from './global-attributes';
@@ -179,7 +183,7 @@ function scheduleActivityNextHandler({ options, args, headers, seq, activityType
179
183
  startToCloseTimeout: msOptionalToTs(options.startToCloseTimeout),
180
184
  scheduleToStartTimeout: msOptionalToTs(options.scheduleToStartTimeout),
181
185
  headers,
182
- cancellationType: options.cancellationType,
186
+ cancellationType: encodeActivityCancellationType(options.cancellationType),
183
187
  doNotEagerlyExecute: !(options.allowEagerDispatch ?? true),
184
188
  versioningIntent: versioningIntentToProto(options.versioningIntent),
185
189
  },
@@ -246,7 +250,7 @@ async function scheduleLocalActivityNextHandler({
246
250
  scheduleToStartTimeout: msOptionalToTs(options.scheduleToStartTimeout),
247
251
  localRetryThreshold: msOptionalToTs(options.localRetryThreshold),
248
252
  headers,
249
- cancellationType: options.cancellationType,
253
+ cancellationType: encodeActivityCancellationType(options.cancellationType),
250
254
  },
251
255
  });
252
256
  activator.completions.activity.set(seq, {
@@ -372,9 +376,9 @@ function startChildWorkflowExecutionNextHandler({
372
376
  workflowTaskTimeout: msOptionalToTs(options.workflowTaskTimeout),
373
377
  namespace: activator.info.namespace, // Not configurable
374
378
  headers,
375
- cancellationType: options.cancellationType,
376
- workflowIdReusePolicy: options.workflowIdReusePolicy,
377
- parentClosePolicy: options.parentClosePolicy,
379
+ cancellationType: encodeChildWorkflowCancellationType(options.cancellationType),
380
+ workflowIdReusePolicy: encodeWorkflowIdReusePolicy(options.workflowIdReusePolicy),
381
+ parentClosePolicy: encodeParentClosePolicy(options.parentClosePolicy),
378
382
  cronSchedule: options.cronSchedule,
379
383
  searchAttributes: options.searchAttributes
380
384
  ? mapToPayloads(searchAttributePayloadConverter, options.searchAttributes)