@temporalio/workflow 0.22.0 → 1.0.0-rc.1

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.
@@ -0,0 +1,272 @@
1
+ import { RetryPolicy, TemporalFailure } from '@temporalio/common';
2
+ import { checkExtends, CommonWorkflowOptions, SearchAttributes } from '@temporalio/internal-workflow-common';
3
+ import type { coresdk } from '@temporalio/proto';
4
+
5
+ /**
6
+ * Workflow Execution information
7
+ */
8
+ export interface WorkflowInfo {
9
+ /**
10
+ * ID of the Workflow, this can be set by the client during Workflow creation.
11
+ * A single Workflow may run multiple times e.g. when scheduled with cron.
12
+ */
13
+ workflowId: string;
14
+
15
+ /**
16
+ * ID of a single Workflow run
17
+ */
18
+ runId: string;
19
+
20
+ /**
21
+ * Workflow function's name
22
+ */
23
+ workflowType: string;
24
+
25
+ /**
26
+ * Indexed information attached to the Workflow Execution
27
+ */
28
+ searchAttributes: SearchAttributes;
29
+
30
+ /**
31
+ * Non-indexed information attached to the Workflow Execution
32
+ */
33
+ memo?: Record<string, unknown>;
34
+
35
+ /**
36
+ * Parent Workflow info (present if this is a Child Workflow)
37
+ */
38
+ parent?: ParentWorkflowInfo;
39
+
40
+ /**
41
+ * Result from the previous Run (present if this is a Cron Workflow or was Continued As New).
42
+ *
43
+ * An array of values, since other SDKs may return multiple values from a Workflow.
44
+ */
45
+ lastResult?: unknown;
46
+
47
+ /**
48
+ * Failure from the previous Run (present when this Run is a retry, or the last Run of a Cron Workflow failed)
49
+ */
50
+ lastFailure?: TemporalFailure;
51
+
52
+ /**
53
+ * Task queue this Workflow is executing on
54
+ */
55
+ taskQueue: string;
56
+
57
+ /**
58
+ * Namespace this Workflow is executing in
59
+ */
60
+ namespace: string;
61
+
62
+ /**
63
+ * Run Id of the first Run in this Execution Chain
64
+ */
65
+ firstExecutionRunId: string;
66
+
67
+ /**
68
+ * The last Run Id in this Execution Chain
69
+ */
70
+ continuedFromExecutionRunId?: string;
71
+
72
+ // TODO expose from Core
73
+ /**
74
+ * Time at which the Workflow Run started
75
+ */
76
+ // startTime: Date;
77
+
78
+ /**
79
+ * Milliseconds after which the Workflow Execution is automatically terminated by Temporal Server. Set via {@link WorkflowOptions.workflowExecutionTimeout}.
80
+ */
81
+ executionTimeoutMs?: number;
82
+
83
+ /**
84
+ * Time at which the Workflow Execution expires
85
+ */
86
+ executionExpirationTime?: Date;
87
+
88
+ /**
89
+ * Milliseconds after which the Workflow Run is automatically terminated by Temporal Server. Set via {@link WorkflowOptions.workflowRunTimeout}.
90
+ */
91
+ runTimeoutMs?: number;
92
+
93
+ /**
94
+ * Maximum execution time of a Workflow Task in milliseconds. Set via {@link WorkflowOptions.workflowTaskTimeout}.
95
+ */
96
+ taskTimeoutMs: number;
97
+
98
+ /**
99
+ * Retry Policy for this Execution. Set via {@link WorkflowOptions.retry}.
100
+ */
101
+ retryPolicy?: RetryPolicy;
102
+
103
+ /**
104
+ * Starts at 1 and increments for every retry if there is a `retryPolicy`
105
+ */
106
+ attempt: number;
107
+
108
+ /**
109
+ * Cron Schedule for this Execution. Set via {@link WorkflowOptions.cronSchedule}.
110
+ */
111
+ cronSchedule?: string;
112
+
113
+ /**
114
+ * Milliseconds between Cron Runs
115
+ */
116
+ cronScheduleToScheduleInterval?: number;
117
+ }
118
+
119
+ export interface ParentWorkflowInfo {
120
+ workflowId: string;
121
+ runId: string;
122
+ namespace: string;
123
+ }
124
+
125
+ /**
126
+ * Not an actual error, used by the Workflow runtime to abort execution when {@link continueAsNew} is called
127
+ */
128
+ export class ContinueAsNew extends Error {
129
+ public readonly name = 'ContinueAsNew';
130
+
131
+ constructor(public readonly command: coresdk.workflow_commands.IContinueAsNewWorkflowExecution) {
132
+ super('Workflow continued as new');
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Options for continuing a Workflow as new
138
+ */
139
+ export interface ContinueAsNewOptions {
140
+ /**
141
+ * A string representing the Workflow type name, e.g. the filename in the Node.js SDK or class name in Java
142
+ */
143
+ workflowType?: string;
144
+ /**
145
+ * Task queue to continue the Workflow in
146
+ */
147
+ taskQueue?: string;
148
+ /**
149
+ * Timeout for the entire Workflow run
150
+ * @format {@link https://www.npmjs.com/package/ms | ms} formatted string
151
+ */
152
+ workflowRunTimeout?: string;
153
+ /**
154
+ * Timeout for a single Workflow task
155
+ * @format {@link https://www.npmjs.com/package/ms | ms} formatted string
156
+ */
157
+ workflowTaskTimeout?: string;
158
+ /**
159
+ * Non-searchable attributes to attach to next Workflow run
160
+ */
161
+ memo?: Record<string, any>;
162
+ /**
163
+ * Searchable attributes to attach to next Workflow run
164
+ */
165
+ searchAttributes?: SearchAttributes;
166
+ }
167
+
168
+ /**
169
+ * Specifies:
170
+ * - whether cancellation requests are sent to the Child
171
+ * - whether and when a {@link CanceledFailure} is thrown from {@link executeChild} or
172
+ * {@link ChildWorkflowHandle.result}
173
+ *
174
+ * @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
175
+ */
176
+ export enum ChildWorkflowCancellationType {
177
+ /**
178
+ * Don't send a cancellation request to the Child.
179
+ */
180
+ ABANDON = 0,
181
+
182
+ /**
183
+ * Send a cancellation request to the Child. Immediately throw the error.
184
+ */
185
+ TRY_CANCEL = 1,
186
+
187
+ /**
188
+ * Send a cancellation request to the Child. The Child may respect cancellation, in which case an error will be thrown
189
+ * when cancellation has completed, and {@link isCancellation}(error) will be true. On the other hand, the Child may
190
+ * ignore the cancellation request, in which case an error might be thrown with a different cause, or the Child may
191
+ * complete successfully.
192
+ *
193
+ * @default
194
+ */
195
+ WAIT_CANCELLATION_COMPLETED = 2,
196
+
197
+ /**
198
+ * Send a cancellation request to the Child. Throw the error once the Server receives the Child cancellation request.
199
+ */
200
+ WAIT_CANCELLATION_REQUESTED = 3,
201
+ }
202
+
203
+ checkExtends<coresdk.child_workflow.ChildWorkflowCancellationType, ChildWorkflowCancellationType>();
204
+
205
+ /**
206
+ * How a Child Workflow reacts to the Parent Workflow reaching a Closed state.
207
+ *
208
+ * @see {@link https://docs.temporal.io/concepts/what-is-a-parent-close-policy/ | Parent Close Policy}
209
+ */
210
+ export enum ParentClosePolicy {
211
+ /**
212
+ * If a `ParentClosePolicy` is set to this, or is not set at all, the server default value will be used.
213
+ */
214
+ PARENT_CLOSE_POLICY_UNSPECIFIED = 0,
215
+
216
+ /**
217
+ * When the Parent is Closed, the Child is Terminated.
218
+ *
219
+ * @default
220
+ */
221
+ PARENT_CLOSE_POLICY_TERMINATE = 1,
222
+
223
+ /**
224
+ * When the Parent is Closed, nothing is done to the Child.
225
+ */
226
+ PARENT_CLOSE_POLICY_ABANDON = 2,
227
+
228
+ /**
229
+ * When the Parent is Closed, the Child is Cancelled.
230
+ */
231
+ PARENT_CLOSE_POLICY_REQUEST_CANCEL = 3,
232
+ }
233
+
234
+ checkExtends<coresdk.child_workflow.ParentClosePolicy, ParentClosePolicy>();
235
+
236
+ export interface ChildWorkflowOptions extends CommonWorkflowOptions {
237
+ /**
238
+ * Workflow id to use when starting. If not specified a UUID is generated. Note that it is
239
+ * dangerous as in case of client side retries no deduplication will happen based on the
240
+ * generated id. So prefer assigning business meaningful ids if possible.
241
+ */
242
+ workflowId?: string;
243
+
244
+ /**
245
+ * Task queue to use for Workflow tasks. It should match a task queue specified when creating a
246
+ * `Worker` that hosts the Workflow code.
247
+ */
248
+ taskQueue?: string;
249
+
250
+ /**
251
+ * Specifies:
252
+ * - whether cancellation requests are sent to the Child
253
+ * - whether and when an error is thrown from {@link executeChild} or
254
+ * {@link ChildWorkflowHandle.result}
255
+ *
256
+ * @default {@link ChildWorkflowCancellationType.WAIT_CANCELLATION_COMPLETED}
257
+ */
258
+ cancellationType?: ChildWorkflowCancellationType;
259
+
260
+ /**
261
+ * Specifies how the Child reacts to the Parent Workflow reaching a Closed state.
262
+ *
263
+ * @default {@link ParentClosePolicy.PARENT_CLOSE_POLICY_TERMINATE}
264
+ */
265
+ parentClosePolicy?: ParentClosePolicy;
266
+ }
267
+
268
+ export type RequiredChildWorkflowOptions = Required<Pick<ChildWorkflowOptions, 'workflowId' | 'cancellationType'>> & {
269
+ args: unknown[];
270
+ };
271
+
272
+ export type ChildWorkflowOptionsWithDefaults = ChildWorkflowOptions & RequiredChildWorkflowOptions;