@temporalio/workflow 1.17.3 → 1.17.5
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/package.json +3 -3
- package/src/flags.ts +1 -1
- package/src/global-overrides.ts +2 -3
- package/src/index.ts +2 -4
- package/src/interfaces.ts +4 -5
- package/src/internals.ts +55 -213
- package/src/logs.ts +1 -1
- package/src/metrics.ts +1 -1
- package/src/nexus.ts +3 -8
- package/src/worker-interface.ts +1 -3
- package/src/workflow.ts +54 -99
- package/src/current-random.ts +0 -5
- package/src/interceptor-composition.ts +0 -31
- package/src/random-helpers.ts +0 -21
- package/src/random-stream-seed.ts +0 -18
- package/src/random-streams.ts +0 -132
package/src/logs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
|
|
1
2
|
import { SdkComponent } from '@temporalio/common';
|
|
2
|
-
import { composeInterceptors } from './interceptor-composition';
|
|
3
3
|
import { untrackPromise } from './stack-helpers';
|
|
4
4
|
import { type Sink, type Sinks, proxySinks } from './sinks';
|
|
5
5
|
import { isCancellation } from './errors';
|
package/src/metrics.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
NumericMetricValueType,
|
|
8
8
|
} from '@temporalio/common';
|
|
9
9
|
import { MetricMeterWithComposedTags } from '@temporalio/common';
|
|
10
|
-
import { composeInterceptors } from '
|
|
10
|
+
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
|
|
11
11
|
import type { Sink, Sinks } from './sinks';
|
|
12
12
|
import { proxySinks } from './sinks';
|
|
13
13
|
import { workflowInfo } from './workflow';
|
package/src/nexus.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type * as nexus from 'nexus-rpc';
|
|
2
2
|
import { msOptionalToTs } from '@temporalio/common/lib/time';
|
|
3
3
|
import { userMetadataToPayload } from '@temporalio/common/lib/user-metadata';
|
|
4
|
+
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
|
|
4
5
|
import { makeProtoEnumConverters } from '@temporalio/common/lib/internal-workflow/enums-helpers';
|
|
5
6
|
import type { coresdk } from '@temporalio/proto';
|
|
6
7
|
import { CancellationScope } from './cancellation-scope';
|
|
7
8
|
import { getActivator } from './global-attributes';
|
|
8
|
-
import { composeInterceptors } from './interceptor-composition';
|
|
9
9
|
import { untrackPromise } from './stack-helpers';
|
|
10
10
|
import type { StartNexusOperationInput, StartNexusOperationOutput, StartNexusOperationOptions } from './interceptors';
|
|
11
11
|
|
|
@@ -191,11 +191,6 @@ function startNexusOperationNextHandler({
|
|
|
191
191
|
headers,
|
|
192
192
|
}: StartNexusOperationInput): Promise<StartNexusOperationOutput> {
|
|
193
193
|
const activator = getActivator();
|
|
194
|
-
const context = {
|
|
195
|
-
type: 'workflow' as const,
|
|
196
|
-
namespace: activator.info.namespace,
|
|
197
|
-
workflowId: activator.info.workflowId,
|
|
198
|
-
};
|
|
199
194
|
|
|
200
195
|
return new Promise<StartNexusOperationOutput>((resolve, reject) => {
|
|
201
196
|
const scope = CancellationScope.current();
|
|
@@ -228,13 +223,13 @@ function startNexusOperationNextHandler({
|
|
|
228
223
|
service,
|
|
229
224
|
operation,
|
|
230
225
|
nexusHeader: headers,
|
|
231
|
-
input: activator.payloadConverter.toPayload(input
|
|
226
|
+
input: activator.payloadConverter.toPayload(input),
|
|
232
227
|
scheduleToCloseTimeout: msOptionalToTs(options?.scheduleToCloseTimeout),
|
|
233
228
|
scheduleToStartTimeout: msOptionalToTs(options?.scheduleToStartTimeout),
|
|
234
229
|
startToCloseTimeout: msOptionalToTs(options?.startToCloseTimeout),
|
|
235
230
|
cancellationType: encodeNexusOperationCancellationType(options?.cancellationType),
|
|
236
231
|
},
|
|
237
|
-
userMetadata: userMetadataToPayload(activator.payloadConverter, options?.summary, undefined
|
|
232
|
+
userMetadata: userMetadataToPayload(activator.payloadConverter, options?.summary, undefined),
|
|
238
233
|
});
|
|
239
234
|
|
|
240
235
|
activator.completions.nexusOperationStart.set(seq, {
|
package/src/worker-interface.ts
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { WorkflowFunctionWithOptions } from '@temporalio/common';
|
|
7
7
|
import { encodeVersioningBehavior, IllegalStateError } from '@temporalio/common';
|
|
8
|
+
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
|
|
8
9
|
import type { coresdk } from '@temporalio/proto';
|
|
9
10
|
import type { WorkflowInterceptorsFactory } from './interceptors';
|
|
10
11
|
import type { WorkflowCreateOptionsInternal } from './interfaces';
|
|
11
12
|
import { Activator } from './internals';
|
|
12
|
-
import { composeInterceptors } from './interceptor-composition';
|
|
13
13
|
import { setActivator, getActivator, maybeGetActivator } from './global-attributes';
|
|
14
14
|
|
|
15
15
|
// Export the type for use on the "worker" side
|
|
@@ -91,8 +91,6 @@ export function initRuntime(options: WorkflowCreateOptionsInternal): void {
|
|
|
91
91
|
if (isWorkflowFunctionWithOptions(activator.workflow)) {
|
|
92
92
|
if (typeof activator.workflow.workflowDefinitionOptions === 'object') {
|
|
93
93
|
activator.versioningBehavior = activator.workflow.workflowDefinitionOptions.versioningBehavior;
|
|
94
|
-
activator.workflowDefinitionFailureExceptionTypes =
|
|
95
|
-
activator.workflow.workflowDefinitionOptions.failureExceptionTypes;
|
|
96
94
|
} else {
|
|
97
95
|
activator.workflowDefinitionOptionsGetter = activator.workflow.workflowDefinitionOptions;
|
|
98
96
|
}
|
package/src/workflow.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
ActivityFunction,
|
|
3
|
-
ActivitySerializationContext,
|
|
4
3
|
ActivityOptions,
|
|
5
4
|
LocalActivityOptions,
|
|
6
5
|
QueryDefinition,
|
|
@@ -11,7 +10,6 @@ import type {
|
|
|
11
10
|
UpdateDefinition,
|
|
12
11
|
WithWorkflowArgs,
|
|
13
12
|
Workflow,
|
|
14
|
-
WorkflowSerializationContext,
|
|
15
13
|
WorkflowResultType,
|
|
16
14
|
WorkflowReturnType,
|
|
17
15
|
WorkflowUpdateValidatorType,
|
|
@@ -26,9 +24,9 @@ import {
|
|
|
26
24
|
extractWorkflowType,
|
|
27
25
|
HandlerUnfinishedPolicy,
|
|
28
26
|
mapToPayloads,
|
|
29
|
-
|
|
30
|
-
toPayloadsWithContext,
|
|
27
|
+
toPayloads,
|
|
31
28
|
TypedSearchAttributes,
|
|
29
|
+
encodeInitialVersioningBehavior,
|
|
32
30
|
} from '@temporalio/common';
|
|
33
31
|
import { userMetadataToPayload } from '@temporalio/common/lib/user-metadata';
|
|
34
32
|
import {
|
|
@@ -38,11 +36,11 @@ import {
|
|
|
38
36
|
import { versioningIntentToProto } from '@temporalio/common/lib/versioning-intent-enum';
|
|
39
37
|
import type { Duration } from '@temporalio/common/lib/time';
|
|
40
38
|
import { msOptionalToTs, msToNumber, msToTs, requiredTsToMs } from '@temporalio/common/lib/time';
|
|
39
|
+
import { composeInterceptors } from '@temporalio/common/lib/interceptors';
|
|
41
40
|
import type { temporal } from '@temporalio/proto';
|
|
42
41
|
import { deepMerge } from '@temporalio/common/lib/internal-workflow';
|
|
43
42
|
import { throwIfReservedName } from '@temporalio/common/lib/reserved';
|
|
44
43
|
import { CancellationScope, registerSleepImplementation } from './cancellation-scope';
|
|
45
|
-
import { composeInterceptors } from './interceptor-composition';
|
|
46
44
|
import { UpdateScope } from './update-scope';
|
|
47
45
|
import type {
|
|
48
46
|
ActivityInput,
|
|
@@ -75,43 +73,12 @@ import {
|
|
|
75
73
|
} from './interfaces';
|
|
76
74
|
import { LocalActivityDoBackoff } from './errors';
|
|
77
75
|
import { assertInWorkflowContext, getActivator, maybeGetActivator } from './global-attributes';
|
|
78
|
-
import { uuid4FromRandom } from './random-helpers';
|
|
79
76
|
import { untrackPromise } from './stack-helpers';
|
|
80
77
|
import type { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
|
|
81
78
|
|
|
82
79
|
// Avoid a circular dependency
|
|
83
80
|
registerSleepImplementation(sleep);
|
|
84
81
|
|
|
85
|
-
function currentWorkflowSerializationContext(info: WorkflowInfo): WorkflowSerializationContext {
|
|
86
|
-
return {
|
|
87
|
-
type: 'workflow',
|
|
88
|
-
namespace: info.namespace,
|
|
89
|
-
workflowId: info.workflowId,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function targetWorkflowSerializationContext(info: WorkflowInfo, workflowId: string): WorkflowSerializationContext {
|
|
94
|
-
return {
|
|
95
|
-
type: 'workflow',
|
|
96
|
-
namespace: info.namespace,
|
|
97
|
-
workflowId,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function activitySerializationContext(
|
|
102
|
-
info: WorkflowInfo,
|
|
103
|
-
activityId: string | undefined,
|
|
104
|
-
isLocal: boolean
|
|
105
|
-
): ActivitySerializationContext {
|
|
106
|
-
return {
|
|
107
|
-
type: 'activity',
|
|
108
|
-
namespace: info.namespace,
|
|
109
|
-
activityId,
|
|
110
|
-
workflowId: info.workflowId,
|
|
111
|
-
isLocal,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
82
|
/**
|
|
116
83
|
* Adds default values of `workflowId` and `cancellationType` to given workflow options.
|
|
117
84
|
*/
|
|
@@ -132,7 +99,6 @@ export function addDefaultWorkflowOptions<T extends Workflow>(
|
|
|
132
99
|
*/
|
|
133
100
|
function timerNextHandler({ seq, durationMs, options }: TimerInput) {
|
|
134
101
|
const activator = getActivator();
|
|
135
|
-
const context = currentWorkflowSerializationContext(activator.info);
|
|
136
102
|
return new Promise<void>((resolve, reject) => {
|
|
137
103
|
const scope = CancellationScope.current();
|
|
138
104
|
if (scope.consideredCancelled) {
|
|
@@ -159,7 +125,7 @@ function timerNextHandler({ seq, durationMs, options }: TimerInput) {
|
|
|
159
125
|
seq,
|
|
160
126
|
startToFireTimeout: msToTs(durationMs),
|
|
161
127
|
},
|
|
162
|
-
userMetadata: userMetadataToPayload(activator.payloadConverter, options?.summary, undefined
|
|
128
|
+
userMetadata: userMetadataToPayload(activator.payloadConverter, options?.summary, undefined),
|
|
163
129
|
});
|
|
164
130
|
activator.completions.timer.set(seq, {
|
|
165
131
|
resolve,
|
|
@@ -207,8 +173,6 @@ const validateLocalActivityOptions = validateActivityOptions;
|
|
|
207
173
|
function scheduleActivityNextHandler({ options, args, headers, seq, activityType }: ActivityInput): Promise<unknown> {
|
|
208
174
|
const activator = getActivator();
|
|
209
175
|
validateActivityOptions(options);
|
|
210
|
-
const activityId = options.activityId ?? `${seq}`;
|
|
211
|
-
const context = activitySerializationContext(activator.info, activityId, false);
|
|
212
176
|
return new Promise((resolve, reject) => {
|
|
213
177
|
const scope = CancellationScope.current();
|
|
214
178
|
if (scope.consideredCancelled) {
|
|
@@ -232,9 +196,9 @@ function scheduleActivityNextHandler({ options, args, headers, seq, activityType
|
|
|
232
196
|
activator.pushCommand({
|
|
233
197
|
scheduleActivity: {
|
|
234
198
|
seq,
|
|
235
|
-
activityId
|
|
199
|
+
activityId: options.activityId ?? `${seq}`,
|
|
236
200
|
activityType,
|
|
237
|
-
arguments:
|
|
201
|
+
arguments: toPayloads(activator.payloadConverter, ...args),
|
|
238
202
|
retryPolicy: options.retry ? compileRetryPolicy(options.retry) : undefined,
|
|
239
203
|
taskQueue: options.taskQueue || activator.info.taskQueue,
|
|
240
204
|
heartbeatTimeout: msOptionalToTs(options.heartbeatTimeout),
|
|
@@ -244,15 +208,14 @@ function scheduleActivityNextHandler({ options, args, headers, seq, activityType
|
|
|
244
208
|
headers,
|
|
245
209
|
cancellationType: encodeActivityCancellationType(options.cancellationType),
|
|
246
210
|
doNotEagerlyExecute: !(options.allowEagerDispatch ?? true),
|
|
247
|
-
versioningIntent: versioningIntentToProto(options.versioningIntent),
|
|
211
|
+
versioningIntent: versioningIntentToProto(options.versioningIntent), // eslint-disable-line @typescript-eslint/no-deprecated
|
|
248
212
|
priority: options.priority ? compilePriority(options.priority) : undefined,
|
|
249
213
|
},
|
|
250
|
-
userMetadata: userMetadataToPayload(activator.payloadConverter, options.summary, undefined
|
|
214
|
+
userMetadata: userMetadataToPayload(activator.payloadConverter, options.summary, undefined),
|
|
251
215
|
});
|
|
252
216
|
activator.completions.activity.set(seq, {
|
|
253
217
|
resolve,
|
|
254
218
|
reject,
|
|
255
|
-
context,
|
|
256
219
|
});
|
|
257
220
|
});
|
|
258
221
|
}
|
|
@@ -270,8 +233,6 @@ async function scheduleLocalActivityNextHandler({
|
|
|
270
233
|
originalScheduleTime,
|
|
271
234
|
}: LocalActivityInput): Promise<unknown> {
|
|
272
235
|
const activator = getActivator();
|
|
273
|
-
const activityId = `${seq}`;
|
|
274
|
-
const context = activitySerializationContext(activator.info, activityId, true);
|
|
275
236
|
// Eagerly fail the local activity (which will in turn fail the workflow task.
|
|
276
237
|
// Do not fail on replay where the local activities may not be registered on the replay worker.
|
|
277
238
|
if (!activator.info.unsafe.isReplaying && !activator.registeredActivityNames.has(activityType)) {
|
|
@@ -304,9 +265,10 @@ async function scheduleLocalActivityNextHandler({
|
|
|
304
265
|
seq,
|
|
305
266
|
attempt,
|
|
306
267
|
originalScheduleTime,
|
|
307
|
-
activityId
|
|
268
|
+
// Intentionally not exposing activityId as an option
|
|
269
|
+
activityId: `${seq}`,
|
|
308
270
|
activityType,
|
|
309
|
-
arguments:
|
|
271
|
+
arguments: toPayloads(activator.payloadConverter, ...args),
|
|
310
272
|
retryPolicy: options.retry ? compileRetryPolicy(options.retry) : undefined,
|
|
311
273
|
scheduleToCloseTimeout: msOptionalToTs(options.scheduleToCloseTimeout),
|
|
312
274
|
startToCloseTimeout: msOptionalToTs(options.startToCloseTimeout),
|
|
@@ -315,12 +277,11 @@ async function scheduleLocalActivityNextHandler({
|
|
|
315
277
|
headers,
|
|
316
278
|
cancellationType: encodeActivityCancellationType(options.cancellationType),
|
|
317
279
|
},
|
|
318
|
-
userMetadata: userMetadataToPayload(activator.payloadConverter, options.summary, undefined
|
|
280
|
+
userMetadata: userMetadataToPayload(activator.payloadConverter, options.summary, undefined),
|
|
319
281
|
});
|
|
320
282
|
activator.completions.activity.set(seq, {
|
|
321
283
|
resolve,
|
|
322
284
|
reject,
|
|
323
|
-
context,
|
|
324
285
|
});
|
|
325
286
|
});
|
|
326
287
|
}
|
|
@@ -408,7 +369,6 @@ function startChildWorkflowExecutionNextHandler({
|
|
|
408
369
|
}: StartChildWorkflowExecutionInput): Promise<[Promise<string>, Promise<unknown>]> {
|
|
409
370
|
const activator = getActivator();
|
|
410
371
|
const workflowId = options.workflowId ?? uuid4();
|
|
411
|
-
const context = targetWorkflowSerializationContext(activator.info, workflowId);
|
|
412
372
|
const startPromise = new Promise<string>((resolve, reject) => {
|
|
413
373
|
const scope = CancellationScope.current();
|
|
414
374
|
if (scope.consideredCancelled) {
|
|
@@ -434,7 +394,7 @@ function startChildWorkflowExecutionNextHandler({
|
|
|
434
394
|
seq,
|
|
435
395
|
workflowId,
|
|
436
396
|
workflowType,
|
|
437
|
-
input:
|
|
397
|
+
input: toPayloads(activator.payloadConverter, ...options.args),
|
|
438
398
|
retryPolicy: options.retry ? compileRetryPolicy(options.retry) : undefined,
|
|
439
399
|
taskQueue: options.taskQueue || activator.info.taskQueue,
|
|
440
400
|
workflowExecutionTimeout: msOptionalToTs(options.workflowExecutionTimeout),
|
|
@@ -447,24 +407,18 @@ function startChildWorkflowExecutionNextHandler({
|
|
|
447
407
|
parentClosePolicy: encodeParentClosePolicy(options.parentClosePolicy),
|
|
448
408
|
cronSchedule: options.cronSchedule,
|
|
449
409
|
searchAttributes:
|
|
450
|
-
options.searchAttributes || options.typedSearchAttributes
|
|
451
|
-
? { indexedFields: encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes) }
|
|
410
|
+
options.searchAttributes || options.typedSearchAttributes // eslint-disable-line @typescript-eslint/no-deprecated
|
|
411
|
+
? { indexedFields: encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes) } // eslint-disable-line @typescript-eslint/no-deprecated
|
|
452
412
|
: undefined,
|
|
453
|
-
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo
|
|
454
|
-
versioningIntent: versioningIntentToProto(options.versioningIntent),
|
|
413
|
+
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo),
|
|
414
|
+
versioningIntent: versioningIntentToProto(options.versioningIntent), // eslint-disable-line @typescript-eslint/no-deprecated
|
|
455
415
|
priority: options.priority ? compilePriority(options.priority) : undefined,
|
|
456
416
|
},
|
|
457
|
-
userMetadata: userMetadataToPayload(
|
|
458
|
-
activator.payloadConverter,
|
|
459
|
-
options?.staticSummary,
|
|
460
|
-
options?.staticDetails,
|
|
461
|
-
context
|
|
462
|
-
),
|
|
417
|
+
userMetadata: userMetadataToPayload(activator.payloadConverter, options?.staticSummary, options?.staticDetails),
|
|
463
418
|
});
|
|
464
419
|
activator.completions.childWorkflowStart.set(seq, {
|
|
465
420
|
resolve,
|
|
466
421
|
reject,
|
|
467
|
-
context,
|
|
468
422
|
});
|
|
469
423
|
});
|
|
470
424
|
|
|
@@ -476,7 +430,6 @@ function startChildWorkflowExecutionNextHandler({
|
|
|
476
430
|
activator.completions.childWorkflowComplete.set(seq, {
|
|
477
431
|
resolve,
|
|
478
432
|
reject,
|
|
479
|
-
context,
|
|
480
433
|
});
|
|
481
434
|
});
|
|
482
435
|
untrackPromise(startPromise);
|
|
@@ -490,8 +443,6 @@ function startChildWorkflowExecutionNextHandler({
|
|
|
490
443
|
|
|
491
444
|
function signalWorkflowNextHandler({ seq, signalName, args, target, headers }: SignalWorkflowInput) {
|
|
492
445
|
const activator = getActivator();
|
|
493
|
-
const targetWorkflowId = target.type === 'external' ? target.workflowExecution.workflowId : target.childWorkflowId;
|
|
494
|
-
const context = targetWorkflowSerializationContext(activator.info, targetWorkflowId!);
|
|
495
446
|
return new Promise<any>((resolve, reject) => {
|
|
496
447
|
const scope = CancellationScope.current();
|
|
497
448
|
if (scope.consideredCancelled) {
|
|
@@ -512,7 +463,7 @@ function signalWorkflowNextHandler({ seq, signalName, args, target, headers }: S
|
|
|
512
463
|
activator.pushCommand({
|
|
513
464
|
signalExternalWorkflowExecution: {
|
|
514
465
|
seq,
|
|
515
|
-
args:
|
|
466
|
+
args: toPayloads(activator.payloadConverter, ...args),
|
|
516
467
|
headers,
|
|
517
468
|
signalName,
|
|
518
469
|
...(target.type === 'external'
|
|
@@ -528,7 +479,7 @@ function signalWorkflowNextHandler({ seq, signalName, args, target, headers }: S
|
|
|
528
479
|
},
|
|
529
480
|
});
|
|
530
481
|
|
|
531
|
-
activator.completions.signalWorkflow.set(seq, { resolve, reject
|
|
482
|
+
activator.completions.signalWorkflow.set(seq, { resolve, reject });
|
|
532
483
|
});
|
|
533
484
|
}
|
|
534
485
|
|
|
@@ -575,7 +526,7 @@ export type ActivityFunctionWithOptions<T extends ActivityFunction> = T & {
|
|
|
575
526
|
* provided options.
|
|
576
527
|
*
|
|
577
528
|
* @param options ActivityOptions
|
|
578
|
-
* @param args list of arguments
|
|
529
|
+
* @param args: list of arguments
|
|
579
530
|
* @returns return value of the activity
|
|
580
531
|
*
|
|
581
532
|
* @experimental executeWithOptions is a new method to provide call-site options and is subject to change
|
|
@@ -596,7 +547,7 @@ export type LocalActivityFunctionWithOptions<T extends ActivityFunction> = T & {
|
|
|
596
547
|
* provided options.
|
|
597
548
|
*
|
|
598
549
|
* @param options LocalActivityOptions
|
|
599
|
-
* @param args list of arguments
|
|
550
|
+
* @param args: list of arguments
|
|
600
551
|
* @returns return value of the activity
|
|
601
552
|
*
|
|
602
553
|
* @experimental executeWithOptions is a new method to provide call-site options and is subject to change
|
|
@@ -784,11 +735,7 @@ export function getExternalWorkflowHandle(workflowId: string, runId?: string): E
|
|
|
784
735
|
},
|
|
785
736
|
},
|
|
786
737
|
});
|
|
787
|
-
activator.completions.cancelWorkflow.set(seq, {
|
|
788
|
-
resolve,
|
|
789
|
-
reject,
|
|
790
|
-
context: targetWorkflowSerializationContext(activator.info, workflowId),
|
|
791
|
-
});
|
|
738
|
+
activator.completions.cancelWorkflow.set(seq, { resolve, reject });
|
|
792
739
|
});
|
|
793
740
|
},
|
|
794
741
|
signal<Args extends any[]>(def: SignalDefinition<Args> | string, ...args: Args): Promise<void> {
|
|
@@ -1068,22 +1015,21 @@ export function makeContinueAsNewFunc<F extends Workflow>(
|
|
|
1068
1015
|
};
|
|
1069
1016
|
|
|
1070
1017
|
return (...args: Parameters<F>): Promise<never> => {
|
|
1071
|
-
const context = currentWorkflowSerializationContext(info);
|
|
1072
1018
|
const fn = composeInterceptors(activator.interceptors.outbound, 'continueAsNew', async (input) => {
|
|
1073
1019
|
const { headers, args, options } = input;
|
|
1074
1020
|
throw new ContinueAsNew({
|
|
1075
1021
|
workflowType: options.workflowType,
|
|
1076
|
-
arguments:
|
|
1022
|
+
arguments: toPayloads(activator.payloadConverter, ...args),
|
|
1077
1023
|
headers,
|
|
1078
1024
|
taskQueue: options.taskQueue,
|
|
1079
|
-
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo
|
|
1025
|
+
memo: options.memo && mapToPayloads(activator.payloadConverter, options.memo),
|
|
1080
1026
|
searchAttributes:
|
|
1081
|
-
options.searchAttributes || options.typedSearchAttributes
|
|
1082
|
-
? { indexedFields: encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes) }
|
|
1027
|
+
options.searchAttributes || options.typedSearchAttributes // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1028
|
+
? { indexedFields: encodeUnifiedSearchAttributes(options.searchAttributes, options.typedSearchAttributes) } // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1083
1029
|
: undefined,
|
|
1084
1030
|
workflowRunTimeout: msOptionalToTs(options.workflowRunTimeout),
|
|
1085
1031
|
workflowTaskTimeout: msOptionalToTs(options.workflowTaskTimeout),
|
|
1086
|
-
versioningIntent: versioningIntentToProto(options.versioningIntent),
|
|
1032
|
+
versioningIntent: versioningIntentToProto(options.versioningIntent), // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1087
1033
|
initialVersioningBehavior: encodeInitialVersioningBehavior(options.initialVersioningBehavior),
|
|
1088
1034
|
});
|
|
1089
1035
|
});
|
|
@@ -1096,7 +1042,7 @@ export function makeContinueAsNewFunc<F extends Workflow>(
|
|
|
1096
1042
|
}
|
|
1097
1043
|
|
|
1098
1044
|
/**
|
|
1099
|
-
* {@link https://docs.temporal.io/
|
|
1045
|
+
* {@link https://docs.temporal.io/concepts/what-is-continue-as-new/ | Continues-As-New} the current Workflow Execution
|
|
1100
1046
|
* with default options.
|
|
1101
1047
|
*
|
|
1102
1048
|
* Shorthand for `makeContinueAsNewFunc<F>()(...args)`. (See: {@link makeContinueAsNewFunc}.)
|
|
@@ -1124,8 +1070,24 @@ export function continueAsNew<F extends Workflow>(...args: Parameters<F>): Promi
|
|
|
1124
1070
|
* See the {@link https://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid | stackoverflow discussion}.
|
|
1125
1071
|
*/
|
|
1126
1072
|
export function uuid4(): string {
|
|
1127
|
-
|
|
1128
|
-
|
|
1073
|
+
// Return the hexadecimal text representation of number `n`, padded with zeroes to be of length `p`
|
|
1074
|
+
const ho = (n: number, p: number) => n.toString(16).padStart(p, '0');
|
|
1075
|
+
// Create a view backed by a 16-byte buffer
|
|
1076
|
+
const view = new DataView(new ArrayBuffer(16));
|
|
1077
|
+
// Fill buffer with random values
|
|
1078
|
+
view.setUint32(0, (Math.random() * 0x100000000) >>> 0);
|
|
1079
|
+
view.setUint32(4, (Math.random() * 0x100000000) >>> 0);
|
|
1080
|
+
view.setUint32(8, (Math.random() * 0x100000000) >>> 0);
|
|
1081
|
+
view.setUint32(12, (Math.random() * 0x100000000) >>> 0);
|
|
1082
|
+
// Patch the 6th byte to reflect a version 4 UUID
|
|
1083
|
+
view.setUint8(6, (view.getUint8(6) & 0xf) | 0x40);
|
|
1084
|
+
// Patch the 8th byte to reflect a variant 1 UUID (version 4 UUIDs are)
|
|
1085
|
+
view.setUint8(8, (view.getUint8(8) & 0x3f) | 0x80);
|
|
1086
|
+
// Compile the canonical textual form from the array data
|
|
1087
|
+
return `${ho(view.getUint32(0), 8)}-${ho(view.getUint16(4), 4)}-${ho(view.getUint16(6), 4)}-${ho(
|
|
1088
|
+
view.getUint16(8),
|
|
1089
|
+
4
|
|
1090
|
+
)}-${ho(view.getUint32(10), 8)}${ho(view.getUint16(14), 4)}`;
|
|
1129
1091
|
}
|
|
1130
1092
|
|
|
1131
1093
|
/**
|
|
@@ -1554,6 +1516,7 @@ export function setDefaultQueryHandler(handler: DefaultQueryHandler | undefined)
|
|
|
1554
1516
|
* If using SearchAttributeUpdatePair[] (preferred), set a value to null to remove the search attribute.
|
|
1555
1517
|
* If using SearchAttributes (deprecated), set a value to undefined or an empty list to remove the search attribute.
|
|
1556
1518
|
*/
|
|
1519
|
+
// eslint-disable-next-line @typescript-eslint/no-deprecated
|
|
1557
1520
|
export function upsertSearchAttributes(searchAttributes: SearchAttributes | SearchAttributeUpdatePair[]): void {
|
|
1558
1521
|
const activator = assertInWorkflowContext(
|
|
1559
1522
|
'Workflow.upsertSearchAttributes(...) may only be used from a Workflow Execution.'
|
|
@@ -1575,7 +1538,7 @@ export function upsertSearchAttributes(searchAttributes: SearchAttributes | Sear
|
|
|
1575
1538
|
|
|
1576
1539
|
activator.mutateWorkflowInfo((info: WorkflowInfo): WorkflowInfo => {
|
|
1577
1540
|
// Create a copy of the current state.
|
|
1578
|
-
const newSearchAttributes: SearchAttributes = { ...info.searchAttributes };
|
|
1541
|
+
const newSearchAttributes: SearchAttributes = { ...info.searchAttributes }; // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1579
1542
|
for (const pair of searchAttributes) {
|
|
1580
1543
|
if (pair.value == null) {
|
|
1581
1544
|
// If the value is null, remove the search attribute.
|
|
@@ -1584,7 +1547,7 @@ export function upsertSearchAttributes(searchAttributes: SearchAttributes | Sear
|
|
|
1584
1547
|
} else {
|
|
1585
1548
|
newSearchAttributes[pair.key.name] = Array.isArray(pair.value)
|
|
1586
1549
|
? pair.value
|
|
1587
|
-
: ([pair.value] as SearchAttributeValue);
|
|
1550
|
+
: ([pair.value] as SearchAttributeValue); // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1588
1551
|
}
|
|
1589
1552
|
}
|
|
1590
1553
|
return {
|
|
@@ -1607,7 +1570,7 @@ export function upsertSearchAttributes(searchAttributes: SearchAttributes | Sear
|
|
|
1607
1570
|
activator.mutateWorkflowInfo((info: WorkflowInfo): WorkflowInfo => {
|
|
1608
1571
|
// Create a new copy of the current state.
|
|
1609
1572
|
let typedSearchAttributes = info.typedSearchAttributes.updateCopy([]);
|
|
1610
|
-
const newSearchAttributes: SearchAttributes = { ...info.searchAttributes };
|
|
1573
|
+
const newSearchAttributes: SearchAttributes = { ...info.searchAttributes }; // eslint-disable-line @typescript-eslint/no-deprecated
|
|
1611
1574
|
|
|
1612
1575
|
// Upsert legacy search attributes into typedSearchAttributes.
|
|
1613
1576
|
for (const [k, v] of Object.entries(searchAttributes)) {
|
|
@@ -1712,7 +1675,6 @@ export function upsertSearchAttributes(searchAttributes: SearchAttributes | Sear
|
|
|
1712
1675
|
*/
|
|
1713
1676
|
export function upsertMemo(memo: Record<string, unknown>): void {
|
|
1714
1677
|
const activator = assertInWorkflowContext('Workflow.upsertMemo(...) may only be used from a Workflow Execution.');
|
|
1715
|
-
const context = currentWorkflowSerializationContext(activator.info);
|
|
1716
1678
|
|
|
1717
1679
|
if (memo == null) {
|
|
1718
1680
|
throw new Error('memo must be a non-null Record');
|
|
@@ -1724,8 +1686,7 @@ export function upsertMemo(memo: Record<string, unknown>): void {
|
|
|
1724
1686
|
fields: mapToPayloads(
|
|
1725
1687
|
activator.payloadConverter,
|
|
1726
1688
|
// Convert null to undefined
|
|
1727
|
-
Object.fromEntries(Object.entries(memo).map(([k, v]) => [k, v ?? undefined]))
|
|
1728
|
-
context
|
|
1689
|
+
Object.fromEntries(Object.entries(memo).map(([k, v]) => [k, v ?? undefined]))
|
|
1729
1690
|
),
|
|
1730
1691
|
},
|
|
1731
1692
|
},
|
|
@@ -1767,10 +1728,7 @@ export function allHandlersFinished(): boolean {
|
|
|
1767
1728
|
* @example
|
|
1768
1729
|
* For example:
|
|
1769
1730
|
* ```ts
|
|
1770
|
-
* setWorkflowOptions({
|
|
1771
|
-
* versioningBehavior: 'PINNED',
|
|
1772
|
-
* failureExceptionTypes: [CustomWorkflowError]
|
|
1773
|
-
* }, myWorkflow);
|
|
1731
|
+
* setWorkflowOptions({ versioningBehavior: 'PINNED' }, myWorkflow);
|
|
1774
1732
|
* export async function myWorkflow(): Promise<string> {
|
|
1775
1733
|
* // Workflow code here
|
|
1776
1734
|
* return "hi";
|
|
@@ -1784,10 +1742,7 @@ export function allHandlersFinished(): boolean {
|
|
|
1784
1742
|
* // Workflow code here
|
|
1785
1743
|
* return "hi";
|
|
1786
1744
|
* }
|
|
1787
|
-
* setWorkflowOptions({
|
|
1788
|
-
* versioningBehavior: 'PINNED',
|
|
1789
|
-
* failureExceptionTypes: [CustomWorkflowError]
|
|
1790
|
-
* }, module.exports.default);
|
|
1745
|
+
* setWorkflowOptions({ versioningBehavior: 'PINNED' }, module.exports.default);
|
|
1791
1746
|
* ```
|
|
1792
1747
|
*
|
|
1793
1748
|
* @param options Options for the workflow defintion, or a function that returns options. If a
|
package/src/current-random.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { composeInterceptorsWith, type Next } from '@temporalio/common/lib/interceptors';
|
|
2
|
-
import { getActivator } from './global-attributes';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Compose workflow interceptors while making every `next(...)` continuation re-enter
|
|
6
|
-
* the workflow-random scope that was current when that continuation was created.
|
|
7
|
-
*
|
|
8
|
-
* This is intentionally a thin wrapper over the shared interceptor composition helper
|
|
9
|
-
* in `packages/common`. The shared helper owns the actual chain-construction algorithm,
|
|
10
|
-
* ordering, and `next(...)` wiring so workflow code cannot silently drift away from the
|
|
11
|
-
* semantics used by the rest of the SDK.
|
|
12
|
-
*
|
|
13
|
-
* The workflow-specific behavior lives entirely in the `wrapNext` hook we pass into that
|
|
14
|
-
* shared helper. Each `next(...)` continuation handed to a workflow interceptor is wrapped
|
|
15
|
-
* with `Activator.bindCurrentRandom(...)`, which captures the currently active workflow
|
|
16
|
-
* random scope, including the absence of any scoped override. When the interceptor later
|
|
17
|
-
* calls `next(...)`, the wrapper restores that captured scope before entering the rest of
|
|
18
|
-
* the interceptor chain or the base workflow/runtime handler.
|
|
19
|
-
*
|
|
20
|
-
* That is the behavior we need for `WorkflowRandomStream.with(...)`: a temporary
|
|
21
|
-
* plugin/interceptor scope should apply to the plugin's own code, but it must not
|
|
22
|
-
* leak through `next(...)` into downstream workflow code unless that downstream code
|
|
23
|
-
* explicitly establishes its own scope.
|
|
24
|
-
*/
|
|
25
|
-
export function composeInterceptors<I, M extends keyof I>(interceptors: I[], method: M, next: Next<I, M>): Next<I, M> {
|
|
26
|
-
const activator = getActivator();
|
|
27
|
-
return composeInterceptorsWith(interceptors, method, next, ((wrappedNext) =>
|
|
28
|
-
activator.bindCurrentRandom(wrappedNext as any)) as <F extends (...args: any[]) => any>(
|
|
29
|
-
next: F
|
|
30
|
-
) => F) as unknown as Next<I, M>;
|
|
31
|
-
}
|
package/src/random-helpers.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export function fillWithRandom(random: () => number, bytes: Uint8Array): Uint8Array {
|
|
2
|
-
for (let i = 0; i < bytes.length; ++i) {
|
|
3
|
-
bytes[i] = Math.floor(random() * 0x100);
|
|
4
|
-
}
|
|
5
|
-
return bytes;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function uuid4FromRandom(random: () => number): string {
|
|
9
|
-
const ho = (n: number, p: number) => n.toString(16).padStart(p, '0');
|
|
10
|
-
const view = new DataView(new ArrayBuffer(16));
|
|
11
|
-
view.setUint32(0, (random() * 0x100000000) >>> 0);
|
|
12
|
-
view.setUint32(4, (random() * 0x100000000) >>> 0);
|
|
13
|
-
view.setUint32(8, (random() * 0x100000000) >>> 0);
|
|
14
|
-
view.setUint32(12, (random() * 0x100000000) >>> 0);
|
|
15
|
-
view.setUint8(6, (view.getUint8(6) & 0xf) | 0x40);
|
|
16
|
-
view.setUint8(8, (view.getUint8(8) & 0x3f) | 0x80);
|
|
17
|
-
return `${ho(view.getUint32(0), 8)}-${ho(view.getUint16(4), 4)}-${ho(view.getUint16(6), 4)}-${ho(
|
|
18
|
-
view.getUint16(8),
|
|
19
|
-
4
|
|
20
|
-
)}-${ho(view.getUint32(10), 8)}${ho(view.getUint16(14), 4)}`;
|
|
21
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { encode } from '@temporalio/common/lib/encoding';
|
|
2
|
-
|
|
3
|
-
const RANDOM_STREAM_SEED_PREFIX = Array.from(encode('temporal-workflow-random-stream-v1'));
|
|
4
|
-
|
|
5
|
-
function encodeU32(value: number): number[] {
|
|
6
|
-
return [(value >>> 24) & 0xff, (value >>> 16) & 0xff, (value >>> 8) & 0xff, value & 0xff];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function deriveAleaSeed(seed: number[], namespace: string): number[] {
|
|
10
|
-
const namespaceBytes = Array.from(encode(namespace));
|
|
11
|
-
return [
|
|
12
|
-
...RANDOM_STREAM_SEED_PREFIX,
|
|
13
|
-
...encodeU32(seed.length),
|
|
14
|
-
...seed,
|
|
15
|
-
...encodeU32(namespaceBytes.length),
|
|
16
|
-
...namespaceBytes,
|
|
17
|
-
];
|
|
18
|
-
}
|