@temporalio/client 1.11.2 → 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.
Files changed (60) hide show
  1. package/lib/async-completion-client.js +4 -4
  2. package/lib/async-completion-client.js.map +1 -1
  3. package/lib/base-client.d.ts +30 -7
  4. package/lib/base-client.js +26 -8
  5. package/lib/base-client.js.map +1 -1
  6. package/lib/build-id-types.js +1 -2
  7. package/lib/build-id-types.js.map +1 -1
  8. package/lib/client.d.ts +3 -4
  9. package/lib/client.js +1 -0
  10. package/lib/client.js.map +1 -1
  11. package/lib/connection.d.ts +26 -9
  12. package/lib/connection.js +35 -12
  13. package/lib/connection.js.map +1 -1
  14. package/lib/errors.d.ts +15 -0
  15. package/lib/errors.js +36 -2
  16. package/lib/errors.js.map +1 -1
  17. package/lib/grpc-retry.js +4 -5
  18. package/lib/grpc-retry.js.map +1 -1
  19. package/lib/helpers.js +2 -3
  20. package/lib/helpers.js.map +1 -1
  21. package/lib/iterators-utils.js +1 -2
  22. package/lib/iterators-utils.js.map +1 -1
  23. package/lib/schedule-client.d.ts +4 -0
  24. package/lib/schedule-client.js +8 -5
  25. package/lib/schedule-client.js.map +1 -1
  26. package/lib/schedule-helpers.d.ts +1 -3
  27. package/lib/schedule-helpers.js +14 -27
  28. package/lib/schedule-helpers.js.map +1 -1
  29. package/lib/schedule-types.d.ts +17 -14
  30. package/lib/schedule-types.js +27 -18
  31. package/lib/schedule-types.js.map +1 -1
  32. package/lib/task-queue-client.d.ts +12 -1
  33. package/lib/task-queue-client.js +23 -38
  34. package/lib/task-queue-client.js.map +1 -1
  35. package/lib/types.d.ts +36 -4
  36. package/lib/types.js +22 -1
  37. package/lib/types.js.map +1 -1
  38. package/lib/workflow-client.d.ts +6 -6
  39. package/lib/workflow-client.js +20 -36
  40. package/lib/workflow-client.js.map +1 -1
  41. package/lib/workflow-options.d.ts +2 -1
  42. package/lib/workflow-options.js +1 -2
  43. package/lib/workflow-options.js.map +1 -1
  44. package/lib/workflow-update-stage.d.ts +12 -8
  45. package/lib/workflow-update-stage.js +18 -17
  46. package/lib/workflow-update-stage.js.map +1 -1
  47. package/package.json +4 -4
  48. package/src/async-completion-client.ts +4 -5
  49. package/src/base-client.ts +32 -6
  50. package/src/client.ts +4 -4
  51. package/src/connection.ts +42 -10
  52. package/src/errors.ts +34 -1
  53. package/src/schedule-client.ts +12 -6
  54. package/src/schedule-helpers.ts +2 -17
  55. package/src/schedule-types.ts +35 -22
  56. package/src/task-queue-client.ts +37 -38
  57. package/src/types.ts +58 -3
  58. package/src/workflow-client.ts +36 -29
  59. package/src/workflow-options.ts +2 -1
  60. package/src/workflow-update-stage.ts +29 -21
@@ -1,6 +1,7 @@
1
1
  import { status } from '@grpc/grpc-js';
2
2
  import { filterNullAndUndefined } from '@temporalio/common/lib/internal-non-workflow';
3
3
  import { assertNever, SymbolBasedInstanceOfError, RequireAtLeastOne } from '@temporalio/common/lib/type-helpers';
4
+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow';
4
5
  import { temporal } from '@temporalio/proto';
5
6
  import { BaseClient, BaseClientOptions, defaultBaseClientOptions, LoadedWithDefaults } from './base-client';
6
7
  import { WorkflowService } from './types';
@@ -148,7 +149,7 @@ export class TaskQueueClient extends BaseClient {
148
149
  namespace: this.options.namespace,
149
150
  taskQueues: options.taskQueues,
150
151
  buildIds,
151
- reachability: reachabilityTypeToProto(options.reachability),
152
+ reachability: encodeTaskReachability(options.reachability),
152
153
  });
153
154
  } catch (e) {
154
155
  this.rethrowGrpcError(e, 'Unexpected error fetching Build Id reachability');
@@ -173,6 +174,20 @@ export class TaskQueueClient extends BaseClient {
173
174
  */
174
175
  export type ReachabilityOptions = RequireAtLeastOne<BaseReachabilityOptions, 'buildIds' | 'taskQueues'>;
175
176
 
177
+ export const ReachabilityType = {
178
+ /** The Build Id might be used by new workflows. */
179
+ NEW_WORKFLOWS: 'NEW_WORKFLOWS',
180
+
181
+ /** The Build Id might be used by open workflows and/or closed workflows. */
182
+ EXISTING_WORKFLOWS: 'EXISTING_WORKFLOWS',
183
+
184
+ /** The Build Id might be used by open workflows. */
185
+ OPEN_WORKFLOWS: 'OPEN_WORKFLOWS',
186
+
187
+ /** The Build Id might be used by closed workflows. */
188
+ CLOSED_WORKFLOWS: 'CLOSED_WORKFLOWS',
189
+ } as const;
190
+
176
191
  /**
177
192
  * There are different types of reachability:
178
193
  * - `NEW_WORKFLOWS`: The Build Id might be used by new workflows
@@ -180,7 +195,24 @@ export type ReachabilityOptions = RequireAtLeastOne<BaseReachabilityOptions, 'bu
180
195
  * - `OPEN_WORKFLOWS` The Build Id might be used by open workflows
181
196
  * - `CLOSED_WORKFLOWS` The Build Id might be used by closed workflows
182
197
  */
183
- export type ReachabilityType = 'NEW_WORKFLOWS' | 'EXISTING_WORKFLOWS' | 'OPEN_WORKFLOWS' | 'CLOSED_WORKFLOWS';
198
+ export type ReachabilityType = (typeof ReachabilityType)[keyof typeof ReachabilityType];
199
+
200
+ export const [encodeTaskReachability, decodeTaskReachability] = makeProtoEnumConverters<
201
+ temporal.api.enums.v1.TaskReachability,
202
+ typeof temporal.api.enums.v1.TaskReachability,
203
+ keyof typeof temporal.api.enums.v1.TaskReachability,
204
+ typeof ReachabilityType,
205
+ 'TASK_REACHABILITY_'
206
+ >(
207
+ {
208
+ [ReachabilityType.NEW_WORKFLOWS]: 1,
209
+ [ReachabilityType.EXISTING_WORKFLOWS]: 2,
210
+ [ReachabilityType.OPEN_WORKFLOWS]: 3,
211
+ [ReachabilityType.CLOSED_WORKFLOWS]: 4,
212
+ UNSPECIFIED: 0,
213
+ } as const,
214
+ 'TASK_REACHABILITY_'
215
+ );
184
216
 
185
217
  /**
186
218
  * See {@link ReachabilityOptions}
@@ -215,24 +247,6 @@ export interface BuildIdReachability {
215
247
  taskQueueReachability: Record<string, ReachabilityTypeResponse[]>;
216
248
  }
217
249
 
218
- function reachabilityTypeToProto(type: ReachabilityType | undefined | null): temporal.api.enums.v1.TaskReachability {
219
- switch (type) {
220
- case null:
221
- case undefined:
222
- return temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_UNSPECIFIED;
223
- case 'NEW_WORKFLOWS':
224
- return temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_NEW_WORKFLOWS;
225
- case 'EXISTING_WORKFLOWS':
226
- return temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_EXISTING_WORKFLOWS;
227
- case 'OPEN_WORKFLOWS':
228
- return temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_OPEN_WORKFLOWS;
229
- case 'CLOSED_WORKFLOWS':
230
- return temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_CLOSED_WORKFLOWS;
231
- default:
232
- assertNever('Unknown Build Id reachability operation', type);
233
- }
234
- }
235
-
236
250
  export function reachabilityResponseFromProto(resp: GetWorkerTaskReachabilityResponse): ReachabilityResponse {
237
251
  return {
238
252
  buildIdReachability: Object.fromEntries(
@@ -247,7 +261,9 @@ export function reachabilityResponseFromProto(resp: GetWorkerTaskReachabilityRes
247
261
  taskQueueReachability[tqr.taskQueue] = [];
248
262
  continue;
249
263
  }
250
- taskQueueReachability[tqr.taskQueue] = tqr.reachability.map(reachabilityTypeFromProto);
264
+ taskQueueReachability[tqr.taskQueue] = tqr.reachability.map(
265
+ (x) => decodeTaskReachability(x) ?? 'NOT_FETCHED'
266
+ );
251
267
  }
252
268
  }
253
269
  let bid: string | UnversionedBuildIdType;
@@ -262,23 +278,6 @@ export function reachabilityResponseFromProto(resp: GetWorkerTaskReachabilityRes
262
278
  };
263
279
  }
264
280
 
265
- function reachabilityTypeFromProto(rtype: temporal.api.enums.v1.TaskReachability): ReachabilityTypeResponse {
266
- switch (rtype) {
267
- case temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_UNSPECIFIED:
268
- return 'NOT_FETCHED';
269
- case temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_NEW_WORKFLOWS:
270
- return 'NEW_WORKFLOWS';
271
- case temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_EXISTING_WORKFLOWS:
272
- return 'EXISTING_WORKFLOWS';
273
- case temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_OPEN_WORKFLOWS:
274
- return 'OPEN_WORKFLOWS';
275
- case temporal.api.enums.v1.TaskReachability.TASK_REACHABILITY_CLOSED_WORKFLOWS:
276
- return 'CLOSED_WORKFLOWS';
277
- default:
278
- return assertNever('Unknown Build Id reachability operation', rtype);
279
- }
280
- }
281
-
282
281
  /**
283
282
  * Thrown when one or more Build Ids are not found while using the {@link TaskQueueClient}.
284
283
  *
package/src/types.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type * as grpc from '@grpc/grpc-js';
2
2
  import type { SearchAttributes } from '@temporalio/common';
3
+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow';
3
4
  import * as proto from '@temporalio/proto';
4
5
  import { Replace } from '@temporalio/common/lib/type-helpers';
5
6
 
@@ -96,8 +97,24 @@ export interface ConnectionLike {
96
97
  workflowService: WorkflowService;
97
98
  close(): Promise<void>;
98
99
  ensureConnected(): Promise<void>;
100
+
99
101
  /**
100
- * Set the deadline for any service requests executed in `fn`'s scope.
102
+ * Set a deadline for any service requests executed in `fn`'s scope.
103
+ *
104
+ * The deadline is a point in time after which any pending gRPC request will be considered as failed;
105
+ * this will locally result in the request call throwing a {@link grpc.ServiceError|ServiceError}
106
+ * with code {@link grpc.status.DEADLINE_EXCEEDED|DEADLINE_EXCEEDED}; see {@link isGrpcDeadlineError}.
107
+ *
108
+ * It is stronly recommended to explicitly set deadlines. If no deadline is set, then it is
109
+ * possible for the client to end up waiting forever for a response.
110
+ *
111
+ * This method is only a convenience wrapper around {@link Connection.withDeadline}.
112
+ *
113
+ * @param deadline a point in time after which the request will be considered as failed; either a
114
+ * Date object, or a number of milliseconds since the Unix epoch (UTC).
115
+ * @returns the value returned from `fn`
116
+ *
117
+ * @see https://grpc.io/docs/guides/deadlines/
101
118
  */
102
119
  withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
103
120
 
@@ -109,10 +126,48 @@ export interface ConnectionLike {
109
126
  withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
110
127
 
111
128
  /**
112
- * Set an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that, when aborted,
113
- * cancels any ongoing requests executed in `fn`'s scope.
129
+ * Set an {@link AbortSignal} that, when aborted, cancels any ongoing service requests executed in
130
+ * `fn`'s scope. This will locally result in the request call throwing a {@link grpc.ServiceError|ServiceError}
131
+ * with code {@link grpc.status.CANCELLED|CANCELLED}; see {@link isGrpcCancelledError}.
114
132
  *
115
133
  * @returns value returned from `fn`
134
+ *
135
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal
116
136
  */
117
137
  withAbortSignal<R>(abortSignal: AbortSignal, fn: () => Promise<R>): Promise<R>;
118
138
  }
139
+
140
+ export const QueryRejectCondition = {
141
+ NONE: 'NONE',
142
+ NOT_OPEN: 'NOT_OPEN',
143
+ NOT_COMPLETED_CLEANLY: 'NOT_COMPLETED_CLEANLY',
144
+
145
+ /** @deprecated Use {@link NONE} instead. */
146
+ QUERY_REJECT_CONDITION_NONE: 'NONE', // eslint-disable-line deprecation/deprecation
147
+
148
+ /** @deprecated Use {@link NOT_OPEN} instead. */
149
+ QUERY_REJECT_CONDITION_NOT_OPEN: 'NOT_OPEN', // eslint-disable-line deprecation/deprecation
150
+
151
+ /** @deprecated Use {@link NOT_COMPLETED_CLEANLY} instead. */
152
+ QUERY_REJECT_CONDITION_NOT_COMPLETED_CLEANLY: 'NOT_COMPLETED_CLEANLY', // eslint-disable-line deprecation/deprecation
153
+
154
+ /** @deprecated Use `undefined` instead. */
155
+ QUERY_REJECT_CONDITION_UNSPECIFIED: undefined, // eslint-disable-line deprecation/deprecation
156
+ } as const;
157
+ export type QueryRejectCondition = (typeof QueryRejectCondition)[keyof typeof QueryRejectCondition];
158
+
159
+ export const [encodeQueryRejectCondition, decodeQueryRejectCondition] = makeProtoEnumConverters<
160
+ proto.temporal.api.enums.v1.QueryRejectCondition,
161
+ typeof proto.temporal.api.enums.v1.QueryRejectCondition,
162
+ keyof typeof proto.temporal.api.enums.v1.QueryRejectCondition,
163
+ typeof QueryRejectCondition,
164
+ 'QUERY_REJECT_CONDITION_'
165
+ >(
166
+ {
167
+ [QueryRejectCondition.NONE]: 1,
168
+ [QueryRejectCondition.NOT_OPEN]: 2,
169
+ [QueryRejectCondition.NOT_COMPLETED_CLEANLY]: 3,
170
+ UNSPECIFIED: 0,
171
+ } as const,
172
+ 'QUERY_REJECT_CONDITION_'
173
+ );
@@ -20,6 +20,9 @@ import {
20
20
  WorkflowNotFoundError,
21
21
  WorkflowResultType,
22
22
  extractWorkflowType,
23
+ encodeWorkflowIdReusePolicy,
24
+ decodeRetryState,
25
+ encodeWorkflowIdConflictPolicy,
23
26
  } from '@temporalio/common';
24
27
  import { composeInterceptors } from '@temporalio/common/lib/interceptors';
25
28
  import { History } from '@temporalio/common/lib/proto-utils';
@@ -56,7 +59,9 @@ import {
56
59
  } from './interceptors';
57
60
  import {
58
61
  DescribeWorkflowExecutionResponse,
62
+ encodeQueryRejectCondition,
59
63
  GetWorkflowExecutionHistoryRequest,
64
+ QueryRejectCondition,
60
65
  RequestCancelWorkflowExecutionResponse,
61
66
  StartWorkflowExecutionRequest,
62
67
  TerminateWorkflowExecutionResponse,
@@ -81,8 +86,9 @@ import {
81
86
  WithDefaults,
82
87
  } from './base-client';
83
88
  import { mapAsyncIterable } from './iterators-utils';
84
- import { WorkflowUpdateStage } from './workflow-update-stage';
85
- import * as workflowUpdateStage from './workflow-update-stage';
89
+ import { WorkflowUpdateStage, encodeWorkflowUpdateStage } from './workflow-update-stage';
90
+
91
+ const UpdateWorkflowExecutionLifecycleStage = temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage;
86
92
 
87
93
  /**
88
94
  * A client side handle to a single Workflow instance.
@@ -168,7 +174,7 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
168
174
  * ```ts
169
175
  * const updateHandle = await handle.startUpdate(incrementAndGetValueUpdate, {
170
176
  * args: [2],
171
- * waitForStage: WorkflowUpdateStage.ACCEPTED,
177
+ * waitForStage: 'ACCEPTED',
172
178
  * });
173
179
  * const updateResult = await updateHandle.result();
174
180
  * ```
@@ -177,7 +183,7 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
177
183
  def: UpdateDefinition<Ret, Args, Name> | string,
178
184
  options: WorkflowUpdateOptions & {
179
185
  args: Args;
180
- waitForStage: WorkflowUpdateStage.ACCEPTED;
186
+ waitForStage: 'ACCEPTED';
181
187
  }
182
188
  ): Promise<WorkflowUpdateHandle<Ret>>;
183
189
 
@@ -185,7 +191,7 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
185
191
  def: UpdateDefinition<Ret, Args, Name> | string,
186
192
  options: WorkflowUpdateOptions & {
187
193
  args?: Args;
188
- waitForStage: WorkflowUpdateStage.ACCEPTED;
194
+ waitForStage: typeof WorkflowUpdateStage.ACCEPTED;
189
195
  }
190
196
  ): Promise<WorkflowUpdateHandle<Ret>>;
191
197
 
@@ -280,9 +286,9 @@ export interface WorkflowClientOptions extends BaseClientOptions {
280
286
  /**
281
287
  * Should a query be rejected by closed and failed workflows
282
288
  *
283
- * @default QUERY_REJECT_CONDITION_UNSPECIFIED which means that closed and failed workflows are still queryable
289
+ * @default `undefined` which means that closed and failed workflows are still queryable
284
290
  */
285
- queryRejectCondition?: temporal.api.enums.v1.QueryRejectCondition;
291
+ queryRejectCondition?: QueryRejectCondition;
286
292
  }
287
293
 
288
294
  export type LoadedWorkflowClientOptions = LoadedWithDefaults<WorkflowClientOptions>;
@@ -291,7 +297,7 @@ function defaultWorkflowClientOptions(): WithDefaults<WorkflowClientOptions> {
291
297
  return {
292
298
  ...defaultBaseClientOptions(),
293
299
  interceptors: [],
294
- queryRejectCondition: temporal.api.enums.v1.QueryRejectCondition.QUERY_REJECT_CONDITION_UNSPECIFIED,
300
+ queryRejectCondition: 'NONE',
295
301
  };
296
302
  }
297
303
 
@@ -308,7 +314,7 @@ function ensureArgs<W extends Workflow, T extends WorkflowStartOptions<W>>(
308
314
  opts: T
309
315
  ): Omit<T, 'args'> & { args: unknown[] } {
310
316
  const { args, ...rest } = opts;
311
- return { args: args ?? [], ...rest };
317
+ return { args: (args as unknown[]) ?? [], ...rest };
312
318
  }
313
319
 
314
320
  /**
@@ -659,7 +665,7 @@ export class WorkflowClient extends BaseClient {
659
665
  throw new WorkflowFailedError(
660
666
  'Workflow execution failed',
661
667
  await decodeOptionalFailureToOptionalError(this.dataConverter, failure),
662
- retryState ?? RetryState.RETRY_STATE_UNSPECIFIED
668
+ decodeRetryState(retryState)
663
669
  );
664
670
  } else if (ev.workflowExecutionCanceledEventAttributes) {
665
671
  const failure = new CancelledFailure(
@@ -670,11 +676,7 @@ export class WorkflowClient extends BaseClient {
670
676
  )
671
677
  );
672
678
  failure.stack = '';
673
- throw new WorkflowFailedError(
674
- 'Workflow execution cancelled',
675
- failure,
676
- RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE
677
- );
679
+ throw new WorkflowFailedError('Workflow execution cancelled', failure, RetryState.NON_RETRYABLE_FAILURE);
678
680
  } else if (ev.workflowExecutionTerminatedEventAttributes) {
679
681
  const failure = new TerminatedFailure(
680
682
  ev.workflowExecutionTerminatedEventAttributes.reason || 'Workflow execution terminated'
@@ -683,7 +685,7 @@ export class WorkflowClient extends BaseClient {
683
685
  throw new WorkflowFailedError(
684
686
  ev.workflowExecutionTerminatedEventAttributes.reason || 'Workflow execution terminated',
685
687
  failure,
686
- RetryState.RETRY_STATE_NON_RETRYABLE_FAILURE
688
+ RetryState.NON_RETRYABLE_FAILURE
687
689
  );
688
690
  } else if (ev.workflowExecutionTimedOutEventAttributes) {
689
691
  if (followRuns && ev.workflowExecutionTimedOutEventAttributes.newExecutionRunId) {
@@ -691,16 +693,12 @@ export class WorkflowClient extends BaseClient {
691
693
  req.nextPageToken = undefined;
692
694
  continue;
693
695
  }
694
- const failure = new TimeoutFailure(
695
- 'Workflow execution timed out',
696
- undefined,
697
- TimeoutType.TIMEOUT_TYPE_START_TO_CLOSE
698
- );
696
+ const failure = new TimeoutFailure('Workflow execution timed out', undefined, TimeoutType.START_TO_CLOSE);
699
697
  failure.stack = '';
700
698
  throw new WorkflowFailedError(
701
699
  'Workflow execution timed out',
702
700
  failure,
703
- ev.workflowExecutionTimedOutEventAttributes.retryState || 0
701
+ decodeRetryState(ev.workflowExecutionTimedOutEventAttributes.retryState)
704
702
  );
705
703
  } else if (ev.workflowExecutionContinuedAsNewEventAttributes) {
706
704
  const { newExecutionRunId } = ev.workflowExecutionContinuedAsNewEventAttributes;
@@ -806,8 +804,15 @@ export class WorkflowClient extends BaseClient {
806
804
  waitForStage: WorkflowUpdateStage,
807
805
  input: WorkflowStartUpdateInput
808
806
  ): Promise<WorkflowStartUpdateOutput> {
809
- waitForStage = waitForStage >= WorkflowUpdateStage.ACCEPTED ? waitForStage : WorkflowUpdateStage.ACCEPTED;
810
- const waitForStageProto = workflowUpdateStage.toProtoEnum(waitForStage);
807
+ let waitForStageProto: temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage =
808
+ encodeWorkflowUpdateStage(waitForStage) ??
809
+ UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED;
810
+
811
+ waitForStageProto =
812
+ waitForStageProto >= UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED
813
+ ? waitForStageProto
814
+ : UpdateWorkflowExecutionLifecycleStage.UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_ACCEPTED;
815
+
811
816
  const updateId = input.options?.updateId ?? uuid4();
812
817
  const req: temporal.api.workflowservice.v1.IUpdateWorkflowExecutionRequest = {
813
818
  namespace: this.options.namespace,
@@ -886,7 +891,7 @@ export class WorkflowClient extends BaseClient {
886
891
  updateRef: { workflowExecution, updateId },
887
892
  identity: this.options.identity,
888
893
  waitPolicy: {
889
- lifecycleStage: workflowUpdateStage.toProtoEnum(WorkflowUpdateStage.COMPLETED),
894
+ lifecycleStage: encodeWorkflowUpdateStage(WorkflowUpdateStage.COMPLETED),
890
895
  },
891
896
  };
892
897
  for (;;) {
@@ -938,7 +943,8 @@ export class WorkflowClient extends BaseClient {
938
943
  identity,
939
944
  requestId: uuid4(),
940
945
  workflowId: options.workflowId,
941
- workflowIdReusePolicy: options.workflowIdReusePolicy,
946
+ workflowIdReusePolicy: encodeWorkflowIdReusePolicy(options.workflowIdReusePolicy),
947
+ workflowIdConflictPolicy: encodeWorkflowIdConflictPolicy(options.workflowIdConflictPolicy),
942
948
  workflowType: { name: workflowType },
943
949
  input: { payloads: await encodeToPayloads(this.dataConverter, ...options.args) },
944
950
  signalName,
@@ -988,7 +994,8 @@ export class WorkflowClient extends BaseClient {
988
994
  identity,
989
995
  requestId: uuid4(),
990
996
  workflowId: opts.workflowId,
991
- workflowIdReusePolicy: opts.workflowIdReusePolicy,
997
+ workflowIdReusePolicy: encodeWorkflowIdReusePolicy(opts.workflowIdReusePolicy),
998
+ workflowIdConflictPolicy: encodeWorkflowIdConflictPolicy(opts.workflowIdConflictPolicy),
992
999
  workflowType: { name: workflowType },
993
1000
  input: { payloads: await encodeToPayloads(this.dataConverter, ...opts.args) },
994
1001
  taskQueue: {
@@ -1178,7 +1185,7 @@ export class WorkflowClient extends BaseClient {
1178
1185
  def: UpdateDefinition<Ret, Args> | string,
1179
1186
  options: WorkflowUpdateOptions & {
1180
1187
  args?: Args;
1181
- waitForStage: WorkflowUpdateStage.ACCEPTED;
1188
+ waitForStage: typeof WorkflowUpdateStage.ACCEPTED;
1182
1189
  }
1183
1190
  ): Promise<WorkflowUpdateHandle<Ret>> {
1184
1191
  return await _startUpdate(def, options.waitForStage, options);
@@ -1208,7 +1215,7 @@ export class WorkflowClient extends BaseClient {
1208
1215
  const fn = composeInterceptors(interceptors, 'query', next);
1209
1216
  return fn({
1210
1217
  workflowExecution: { workflowId, runId },
1211
- queryRejectCondition: this.client.options.queryRejectCondition,
1218
+ queryRejectCondition: encodeQueryRejectCondition(this.client.options.queryRejectCondition),
1212
1219
  queryType: typeof def === 'string' ? def : def.name,
1213
1220
  args,
1214
1221
  headers: {},
@@ -15,7 +15,8 @@ export interface WorkflowOptions extends CommonWorkflowOptions {
15
15
  *
16
16
  * Assign a meaningful business id.
17
17
  * This ID can be used to ensure starting Workflows is idempotent.
18
- * Workflow IDs are unique, see also {@link WorkflowOptions.workflowIdReusePolicy}
18
+ * Workflow IDs are unique: see {@link WorkflowOptions.workflowIdReusePolicy}
19
+ * and {@link WorkflowOptions.workflowIdConflictPolicy}.
19
20
  */
20
21
  workflowId: string;
21
22
 
@@ -1,33 +1,41 @@
1
1
  import { temporal } from '@temporalio/proto';
2
- import { checkExtends } from '@temporalio/common/lib/type-helpers';
2
+ import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow';
3
3
 
4
- export enum WorkflowUpdateStage {
5
- /** This is not an allowed value. */
6
- UNSPECIFIED = 0,
4
+ export const WorkflowUpdateStage = {
7
5
  /** Admitted stage. This stage is reached when the server accepts the update request. It is not
8
6
  * allowed to wait for this stage when using startUpdate, since the update request has not yet
9
7
  * been durably persisted at this stage. */
10
- ADMITTED = 1,
8
+ ADMITTED: 'ADMITTED',
9
+
11
10
  /** Accepted stage. This stage is reached when a workflow has received the update and either
12
11
  * accepted it (i.e. it has passed validation, or there was no validator configured on the update
13
12
  * handler) or rejected it. This is currently the only allowed value when using startUpdate. */
14
- ACCEPTED = 2,
13
+ ACCEPTED: 'ACCEPTED',
14
+
15
15
  /** Completed stage. This stage is reached when a workflow has completed processing the
16
16
  * update with either a success or failure. */
17
- COMPLETED = 3,
18
- }
17
+ COMPLETED: 'COMPLETED',
19
18
 
20
- checkExtends<
21
- `UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_${keyof typeof WorkflowUpdateStage}`,
22
- keyof typeof temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage
23
- >();
24
- checkExtends<
25
- keyof typeof temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage,
26
- `UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_${keyof typeof WorkflowUpdateStage}`
27
- >();
19
+ /**
20
+ * This is not an allowed value.
21
+ * @deprecated
22
+ */
23
+ UNSPECIFIED: undefined, // eslint-disable-line deprecation/deprecation
24
+ } as const;
25
+ export type WorkflowUpdateStage = (typeof WorkflowUpdateStage)[keyof typeof WorkflowUpdateStage];
28
26
 
29
- export function toProtoEnum(stage: WorkflowUpdateStage): temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage {
30
- return temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage[
31
- `UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_${WorkflowUpdateStage[stage] as keyof typeof WorkflowUpdateStage}`
32
- ];
33
- }
27
+ export const [encodeWorkflowUpdateStage] = makeProtoEnumConverters<
28
+ temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage,
29
+ typeof temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage,
30
+ keyof typeof temporal.api.enums.v1.UpdateWorkflowExecutionLifecycleStage,
31
+ typeof WorkflowUpdateStage,
32
+ 'UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_'
33
+ >(
34
+ {
35
+ [WorkflowUpdateStage.ADMITTED]: 1,
36
+ [WorkflowUpdateStage.ACCEPTED]: 2,
37
+ [WorkflowUpdateStage.COMPLETED]: 3,
38
+ UNSPECIFIED: 0,
39
+ } as const,
40
+ 'UPDATE_WORKFLOW_EXECUTION_LIFECYCLE_STAGE_'
41
+ );