1
- import { CommonWorkflowOptions , SignalDefinition , WithWorkflowArgs , Workflow } from '@temporalio/common' ;
1
+ import {
2
+ CommonWorkflowOptions ,
3
+ SignalDefinition ,
4
+ WithWorkflowArgs ,
5
+ Workflow ,
6
+ VersioningOverride ,
7
+ toCanonicalString ,
8
+ } from '@temporalio/common' ;
2
9
import { Duration , msOptionalToTs } from '@temporalio/common/lib/time' ;
3
10
import { Replace } from '@temporalio/common/lib/type-helpers' ;
4
- import { google } from '@temporalio/proto' ;
11
+ import { google , temporal } from '@temporalio/proto' ;
5
12
6
13
export * from '@temporalio/common/lib/workflow-options' ;
7
14
@@ -38,9 +45,15 @@ export interface WorkflowOptions extends CommonWorkflowOptions {
38
45
39
46
/**
40
47
* Amount of time to wait before starting the workflow.
41
- *
42
48
*/
43
49
startDelay ?: Duration ;
50
+
51
+ /**
52
+ * Override the versioning behavior of the Workflow that is about to be started.
53
+ *
54
+ * @experimental Deployment based versioning is experimental and may change in the future.
55
+ */
56
+ versioningOverride ?: VersioningOverride ;
44
57
}
45
58
46
59
export type WithCompiledWorkflowOptions < T extends WorkflowOptions > = Replace <
@@ -50,18 +63,21 @@ export type WithCompiledWorkflowOptions<T extends WorkflowOptions> = Replace<
50
63
workflowRunTimeout ?: google . protobuf . IDuration ;
51
64
workflowTaskTimeout ?: google . protobuf . IDuration ;
52
65
startDelay ?: google . protobuf . IDuration ;
66
+ versioningOverride ?: temporal . api . workflow . v1 . IVersioningOverride ;
53
67
}
54
68
> ;
55
69
56
70
export function compileWorkflowOptions < T extends WorkflowOptions > ( options : T ) : WithCompiledWorkflowOptions < T > {
57
- const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, startDelay, ...rest } = options ;
71
+ const { workflowExecutionTimeout, workflowRunTimeout, workflowTaskTimeout, startDelay, versioningOverride, ...rest } =
72
+ options ;
58
73
59
74
return {
60
75
...rest ,
61
76
workflowExecutionTimeout : msOptionalToTs ( workflowExecutionTimeout ) ,
62
77
workflowRunTimeout : msOptionalToTs ( workflowRunTimeout ) ,
63
78
workflowTaskTimeout : msOptionalToTs ( workflowTaskTimeout ) ,
64
79
startDelay : msOptionalToTs ( startDelay ) ,
80
+ versioningOverride : versioningOverrideToProto ( versioningOverride ) ,
65
81
} ;
66
82
}
67
83
@@ -109,3 +125,19 @@ export interface WorkflowSignalWithStartOptionsWithArgs<SignalArgs extends any[]
109
125
* Options for starting a Workflow
110
126
*/
111
127
export type WorkflowStartOptions < T extends Workflow = Workflow > = WithWorkflowArgs < T , WorkflowOptions > ;
128
+
129
+ function versioningOverrideToProto (
130
+ vo : VersioningOverride | undefined
131
+ ) : temporal . api . workflow . v1 . IVersioningOverride | undefined {
132
+ if ( ! vo ) return undefined ;
133
+ // TODO: Remove deprecated field assignments when versioning is non-experimental
134
+ if ( vo === 'AUTO_UPGRADE' ) {
135
+ return {
136
+ behavior : temporal . api . enums . v1 . VersioningBehavior . VERSIONING_BEHAVIOR_AUTO_UPGRADE ,
137
+ } ;
138
+ }
139
+ return {
140
+ behavior : temporal . api . enums . v1 . VersioningBehavior . VERSIONING_BEHAVIOR_PINNED ,
141
+ pinnedVersion : toCanonicalString ( vo . version ) ,
142
+ } ;
143
+ }
0 commit comments