@temporalio/workflow 1.12.3 → 1.13.0

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/lib/errors.js CHANGED
@@ -47,6 +47,7 @@ exports.LocalActivityDoBackoff = LocalActivityDoBackoff = __decorate([
47
47
  */
48
48
  function isCancellation(err) {
49
49
  return (err instanceof common_1.CancelledFailure ||
50
- ((err instanceof common_1.ActivityFailure || err instanceof common_1.ChildWorkflowFailure) && err.cause instanceof common_1.CancelledFailure));
50
+ ((err instanceof common_1.ActivityFailure || err instanceof common_1.ChildWorkflowFailure || err instanceof common_1.NexusOperationFailure) &&
51
+ err.cause instanceof common_1.CancelledFailure));
51
52
  }
52
53
  //# sourceMappingURL=errors.js.map
package/lib/errors.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;;;;AA6BA,wCAKC;AAlCD,+CAA6F;AAC7F,sEAAiF;AAGjF;;GAEG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,KAAK;CAAG,CAAA;AAA9B,sCAAa;wBAAb,aAAa;IADzB,IAAA,yCAA0B,EAAC,eAAe,CAAC;GAC/B,aAAa,CAAiB;AAE3C;;GAEG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,aAAa;CAAG,CAAA;AAAlD,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,yCAA0B,EAAC,2BAA2B,CAAC;GAC3C,yBAAyB,CAAyB;AAE/D;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,KAAK;IACnB;IAA5B,YAA4B,OAA2C;QACrE,KAAK,EAAE,CAAC;QADkB,YAAO,GAAP,OAAO,CAAoC;IAEvE,CAAC;CACF,CAAA;AAJY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,yCAA0B,EAAC,wBAAwB,CAAC;GACxC,sBAAsB,CAIlC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,OAAO,CACL,GAAG,YAAY,yBAAgB;QAC/B,CAAC,CAAC,GAAG,YAAY,wBAAe,IAAI,GAAG,YAAY,6BAAoB,CAAC,IAAI,GAAG,CAAC,KAAK,YAAY,yBAAgB,CAAC,CACnH,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;;;;;;;AA6BA,wCAMC;AAnCD,+CAAoH;AACpH,sEAAiF;AAGjF;;GAEG;AAEI,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,KAAK;CAAG,CAAA;AAA9B,sCAAa;wBAAb,aAAa;IADzB,IAAA,yCAA0B,EAAC,eAAe,CAAC;GAC/B,aAAa,CAAiB;AAE3C;;GAEG;AAEI,IAAM,yBAAyB,GAA/B,MAAM,yBAA0B,SAAQ,aAAa;CAAG,CAAA;AAAlD,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,yCAA0B,EAAC,2BAA2B,CAAC;GAC3C,yBAAyB,CAAyB;AAE/D;;GAEG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAuB,SAAQ,KAAK;IACnB;IAA5B,YAA4B,OAA2C;QACrE,KAAK,EAAE,CAAC;QADkB,YAAO,GAAP,OAAO,CAAoC;IAEvE,CAAC;CACF,CAAA;AAJY,wDAAsB;iCAAtB,sBAAsB;IADlC,IAAA,yCAA0B,EAAC,wBAAwB,CAAC;GACxC,sBAAsB,CAIlC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,GAAY;IACzC,OAAO,CACL,GAAG,YAAY,yBAAgB;QAC/B,CAAC,CAAC,GAAG,YAAY,wBAAe,IAAI,GAAG,YAAY,6BAAoB,IAAI,GAAG,YAAY,8BAAqB,CAAC;YAC9G,GAAG,CAAC,KAAK,YAAY,yBAAgB,CAAC,CACzC,CAAC;AACJ,CAAC"}
package/lib/index.d.ts CHANGED
@@ -66,6 +66,7 @@ export { Trigger } from './trigger';
66
66
  export * from './workflow';
67
67
  export { ChildWorkflowHandle, ExternalWorkflowHandle } from './workflow-handle';
68
68
  export { metricMeter } from './metrics';
69
+ export { createNexusClient, NexusClientOptions, NexusClient, NexusOperationHandle } from './nexus';
69
70
  export {
70
71
  /**
71
72
  * @deprecated Do not use LoggerSinks directly. To log from Workflow code, use the `log` object
package/lib/index.js CHANGED
@@ -64,7 +64,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
64
64
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
65
65
  };
66
66
  Object.defineProperty(exports, "__esModule", { value: true });
67
- exports.metricMeter = exports.Trigger = exports.log = exports.proxySinks = exports.ParentClosePolicy = exports.ContinueAsNew = exports.ChildWorkflowCancellationType = exports.CancellationScope = exports.AsyncLocalStorage = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.rootCause = exports.defaultPayloadConverter = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = exports.ActivityCancellationType = void 0;
67
+ exports.createNexusClient = exports.metricMeter = exports.Trigger = exports.log = exports.proxySinks = exports.ParentClosePolicy = exports.ContinueAsNew = exports.ChildWorkflowCancellationType = exports.CancellationScope = exports.AsyncLocalStorage = exports.TimeoutFailure = exports.TerminatedFailure = exports.TemporalFailure = exports.ServerFailure = exports.rootCause = exports.defaultPayloadConverter = exports.ChildWorkflowFailure = exports.CancelledFailure = exports.ApplicationFailure = exports.ActivityFailure = exports.ActivityCancellationType = void 0;
68
68
  var common_1 = require("@temporalio/common");
69
69
  Object.defineProperty(exports, "ActivityCancellationType", { enumerable: true, get: function () { return common_1.ActivityCancellationType; } });
70
70
  Object.defineProperty(exports, "ActivityFailure", { enumerable: true, get: function () { return common_1.ActivityFailure; } });
@@ -98,4 +98,6 @@ Object.defineProperty(exports, "Trigger", { enumerable: true, get: function () {
98
98
  __exportStar(require("./workflow"), exports);
99
99
  var metrics_1 = require("./metrics");
100
100
  Object.defineProperty(exports, "metricMeter", { enumerable: true, get: function () { return metrics_1.metricMeter; } });
101
+ var nexus_1 = require("./nexus");
102
+ Object.defineProperty(exports, "createNexusClient", { enumerable: true, get: function () { return nexus_1.createNexusClient; } });
101
103
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;;;;;;;;;;;;;;;;;AAEH,6CAiB4B;AAhB1B,kHAAA,wBAAwB,OAAA;AACxB,yGAAA,eAAe,OAAA;AAEf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AACpB,iHAAA,uBAAuB,OAAA;AAGvB,mGAAA,SAAS,OAAA;AAGT,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAEhB,gEAA8C;AAc9C,yEAAuD;AACvD,0EAAwD;AACxD,2DAAsG;AAA7F,uHAAA,iBAAiB,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAC7C,2CAAyB;AACzB,iDAA+B;AAC/B,2CAesB;AAdpB,2HAAA,6BAA6B,OAAA;AAE7B,2GAAA,aAAa,OAAA;AAKb,+GAAA,iBAAiB,OAAA;AAQnB,iCAA0E;AAAjE,mGAAA,UAAU,OAAA;AACnB,+BAA6B;AAApB,2FAAA,GAAG,OAAA;AACZ,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,6CAA2B;AAE3B,qCAAwC;AAA/B,sGAAA,WAAW,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;;;;;;;;;;;;;;;;;AAEH,6CAiB4B;AAhB1B,kHAAA,wBAAwB,OAAA;AACxB,yGAAA,eAAe,OAAA;AAEf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AACpB,iHAAA,uBAAuB,OAAA;AAGvB,mGAAA,SAAS,OAAA;AAGT,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAEhB,gEAA8C;AAc9C,yEAAuD;AACvD,0EAAwD;AACxD,2DAAsG;AAA7F,uHAAA,iBAAiB,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAC7C,2CAAyB;AACzB,iDAA+B;AAC/B,2CAesB;AAdpB,2HAAA,6BAA6B,OAAA;AAE7B,2GAAA,aAAa,OAAA;AAKb,+GAAA,iBAAiB,OAAA;AAQnB,iCAA0E;AAAjE,mGAAA,UAAU,OAAA;AACnB,+BAA6B;AAApB,2FAAA,GAAG,OAAA;AACZ,qCAAoC;AAA3B,kGAAA,OAAO,OAAA;AAChB,6CAA2B;AAE3B,qCAAwC;AAA/B,sGAAA,WAAW,OAAA;AAEpB,iCAAmG;AAA1F,0GAAA,iBAAiB,OAAA"}
@@ -1,34 +1,96 @@
1
1
  /**
2
- * Type definitions and generic helpers for interceptors.
3
- *
4
- * The Workflow specific interceptors are defined here.
2
+ * Type definitions for Workflow interceptors.
5
3
  *
6
4
  * @module
7
5
  */
8
- import { ActivityOptions, Headers, LocalActivityOptions, MetricTags, Next, Timestamp, WorkflowExecution } from '@temporalio/common';
6
+ import { ActivityOptions, Duration, Headers, LocalActivityOptions, MetricTags, Next, Timestamp, WorkflowExecution } from '@temporalio/common';
9
7
  import type { coresdk } from '@temporalio/proto';
10
8
  import { ChildWorkflowOptionsWithDefaults, ContinueAsNewOptions } from './interfaces';
11
9
  export { Next, Headers };
12
- /** Input for WorkflowInboundCallsInterceptor.execute */
10
+ /**
11
+ * A function that instantiates {@link WorkflowInterceptors}.
12
+ *
13
+ * Workflow interceptor modules should export an `interceptors` function of this type.
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * export function interceptors(): WorkflowInterceptors {
19
+ * return {
20
+ * inbound: [], // Populate with list of inbound interceptor implementations
21
+ * outbound: [], // Populate with list of outbound interceptor implementations
22
+ * internals: [], // Populate with list of internals interceptor implementations
23
+ * };
24
+ * }
25
+ * ```
26
+ */
27
+ export type WorkflowInterceptorsFactory = () => WorkflowInterceptors;
28
+ /**
29
+ * A mapping from interceptor type to an optional list of interceptor implementations
30
+ */
31
+ export interface WorkflowInterceptors {
32
+ inbound?: WorkflowInboundCallsInterceptor[];
33
+ outbound?: WorkflowOutboundCallsInterceptor[];
34
+ internals?: WorkflowInternalsInterceptor[];
35
+ }
36
+ /**
37
+ * Implement any of these methods to intercept Workflow inbound calls like execution, and signal and query handling.
38
+ */
39
+ export interface WorkflowInboundCallsInterceptor {
40
+ /**
41
+ * Called when Workflow execute method is called
42
+ *
43
+ * @return result of the Workflow execution
44
+ */
45
+ execute?: (input: WorkflowExecuteInput, next: Next<WorkflowInboundCallsInterceptor, 'execute'>) => Promise<unknown>;
46
+ /**
47
+ * Called when Update handler is called
48
+ *
49
+ * @return result of the Update
50
+ */
51
+ handleUpdate?: (input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'handleUpdate'>) => Promise<unknown>;
52
+ /**
53
+ * Called when update validator called
54
+ */
55
+ validateUpdate?: (input: UpdateInput, next: Next<WorkflowInboundCallsInterceptor, 'validateUpdate'>) => void;
56
+ /**
57
+ * Called when signal is delivered to a Workflow execution
58
+ */
59
+ handleSignal?: (input: SignalInput, next: Next<WorkflowInboundCallsInterceptor, 'handleSignal'>) => Promise<void>;
60
+ /**
61
+ * Called when a Workflow is queried
62
+ *
63
+ * @return result of the query
64
+ */
65
+ handleQuery?: (input: QueryInput, next: Next<WorkflowInboundCallsInterceptor, 'handleQuery'>) => Promise<unknown>;
66
+ }
67
+ /**
68
+ * Input for {@link WorkflowInboundCallsInterceptor.execute}.
69
+ */
13
70
  export interface WorkflowExecuteInput {
14
71
  readonly args: unknown[];
15
72
  readonly headers: Headers;
16
73
  }
17
- /** Input for WorkflowInboundCallsInterceptor.handleUpdate and
18
- * WorkflowInboundCallsInterceptor.validateUpdate */
74
+ /**
75
+ * Input for {@link WorkflowInboundCallsInterceptor.handleUpdate} and {@link WorkflowInboundCallsInterceptor.validateUpdate}.
76
+ */
19
77
  export interface UpdateInput {
20
78
  readonly updateId: string;
21
79
  readonly name: string;
22
80
  readonly args: unknown[];
23
81
  readonly headers: Headers;
24
82
  }
25
- /** Input for WorkflowInboundCallsInterceptor.handleSignal */
83
+ /**
84
+ * Input for {@link WorkflowInboundCallsInterceptor.handleSignal}.
85
+ */
26
86
  export interface SignalInput {
27
87
  readonly signalName: string;
28
88
  readonly args: unknown[];
29
89
  readonly headers: Headers;
30
90
  }
31
- /** Input for WorkflowInboundCallsInterceptor.handleQuery */
91
+ /**
92
+ * Input for {@link WorkflowInboundCallsInterceptor.handleQuery}.
93
+ */
32
94
  export interface QueryInput {
33
95
  readonly queryId: string;
34
96
  readonly queryName: string;
@@ -36,32 +98,85 @@ export interface QueryInput {
36
98
  readonly headers: Headers;
37
99
  }
38
100
  /**
39
- * Implement any of these methods to intercept Workflow inbound calls like execution, and signal and query handling.
101
+ * Implement any of these methods to intercept Workflow code calls to the Temporal APIs, like scheduling an activity
102
+ * and starting a timer.
40
103
  */
41
- export interface WorkflowInboundCallsInterceptor {
104
+ export interface WorkflowOutboundCallsInterceptor {
42
105
  /**
43
- * Called when Workflow execute method is called
106
+ * Called when Workflow starts a timer.
107
+ */
108
+ startTimer?: (input: TimerInput, next: Next<WorkflowOutboundCallsInterceptor, 'startTimer'>) => Promise<void>;
109
+ /**
110
+ * Called when Workflow schedules an Activity.
44
111
  *
45
- * @return result of the Workflow execution
112
+ * @return result of the activity execution
46
113
  */
47
- execute?: (input: WorkflowExecuteInput, next: Next<this, 'execute'>) => Promise<unknown>;
48
- /** Called when Update handler is called
114
+ scheduleActivity?: (input: ActivityInput, next: Next<WorkflowOutboundCallsInterceptor, 'scheduleActivity'>) => Promise<unknown>;
115
+ /**
116
+ * Called when Workflow schedules a local Activity.
49
117
  *
50
- * @return result of the Update
118
+ * @return result of the activity execution
51
119
  */
52
- handleUpdate?: (input: UpdateInput, next: Next<this, 'handleUpdate'>) => Promise<unknown>;
53
- /** Called when update validator called */
54
- validateUpdate?: (input: UpdateInput, next: Next<this, 'validateUpdate'>) => void;
55
- /** Called when signal is delivered to a Workflow execution */
56
- handleSignal?: (input: SignalInput, next: Next<this, 'handleSignal'>) => Promise<void>;
120
+ scheduleLocalActivity?: (input: LocalActivityInput, next: Next<WorkflowOutboundCallsInterceptor, 'scheduleLocalActivity'>) => Promise<unknown>;
57
121
  /**
58
- * Called when a Workflow is queried
122
+ * Called when Workflow starts a Nexus Operation.
59
123
  *
60
- * @return result of the query
124
+ * @experimental Nexus support in Temporal SDK is experimental.
61
125
  */
62
- handleQuery?: (input: QueryInput, next: Next<this, 'handleQuery'>) => Promise<unknown>;
126
+ startNexusOperation?: (input: StartNexusOperationInput, next: Next<WorkflowOutboundCallsInterceptor, 'startNexusOperation'>) => Promise<StartNexusOperationOutput>;
127
+ /**
128
+ * Called when Workflow starts a child workflow execution.
129
+ *
130
+ * The interceptor function returns 2 promises:
131
+ * - The first resolves with the `runId` when the child workflow has started or rejects if failed to start.
132
+ * - The second resolves with the workflow result when the child workflow completes or rejects on failure.
133
+ */
134
+ startChildWorkflowExecution?: (input: StartChildWorkflowExecutionInput, next: Next<WorkflowOutboundCallsInterceptor, 'startChildWorkflowExecution'>) => Promise<[Promise<string>, Promise<unknown>]>;
135
+ /**
136
+ * Called when Workflow signals a child or external Workflow.
137
+ */
138
+ signalWorkflow?: (input: SignalWorkflowInput, next: Next<WorkflowOutboundCallsInterceptor, 'signalWorkflow'>) => Promise<void>;
139
+ /**
140
+ * Called when Workflow calls continueAsNew.
141
+ */
142
+ continueAsNew?: (input: ContinueAsNewInput, next: Next<WorkflowOutboundCallsInterceptor, 'continueAsNew'>) => Promise<never>;
143
+ /**
144
+ * Called on each invocation of the `workflow.log` methods.
145
+ *
146
+ * The attributes returned in this call are attached to every log message.
147
+ */
148
+ getLogAttributes?: (input: GetLogAttributesInput, next: Next<WorkflowOutboundCallsInterceptor, 'getLogAttributes'>) => Record<string, unknown>;
149
+ /**
150
+ * Called once every time a metric is emitted from a Workflow metric (ie. a metric created
151
+ * from {@link workflow.metricMeter}).
152
+ *
153
+ * Tags returned by this hook are _prepended_ to tags defined at the metric level and tags
154
+ * defined on the emitter function itself.
155
+ */
156
+ getMetricTags?: (input: GetMetricTagsInput, next: Next<WorkflowOutboundCallsInterceptor, 'getMetricTags'>) => MetricTags;
157
+ }
158
+ /**
159
+ * Input for {@link WorkflowOutboundCallsInterceptor.startTimer}
160
+ */
161
+ export interface TimerInput {
162
+ readonly durationMs: number;
163
+ readonly seq: number;
164
+ readonly options?: TimerOptions;
165
+ }
166
+ /**
167
+ * Options for starting a timer (i.e. sleep)
168
+ */
169
+ export interface TimerOptions {
170
+ /**
171
+ * A fixed, single line summary of the command's purpose
172
+ *
173
+ * @experimental User metadata is a new API and susceptible to change.
174
+ */
175
+ readonly summary?: string;
63
176
  }
64
- /** Input for WorkflowOutboundCallsInterceptor.scheduleActivity */
177
+ /**
178
+ * Input for {@link WorkflowOutboundCallsInterceptor.scheduleActivity}.
179
+ */
65
180
  export interface ActivityInput {
66
181
  readonly activityType: string;
67
182
  readonly args: unknown[];
@@ -69,7 +184,9 @@ export interface ActivityInput {
69
184
  readonly headers: Headers;
70
185
  readonly seq: number;
71
186
  }
72
- /** Input for WorkflowOutboundCallsInterceptor.scheduleLocalActivity */
187
+ /**
188
+ * Input for {@link WorkflowOutboundCallsInterceptor.scheduleLocalActivity}.
189
+ */
73
190
  export interface LocalActivityInput {
74
191
  readonly activityType: string;
75
192
  readonly args: unknown[];
@@ -79,35 +196,71 @@ export interface LocalActivityInput {
79
196
  readonly originalScheduleTime?: Timestamp;
80
197
  readonly attempt: number;
81
198
  }
82
- /** Input for WorkflowOutboundCallsInterceptor.startChildWorkflowExecution */
83
- export interface StartChildWorkflowExecutionInput {
84
- readonly workflowType: string;
85
- readonly options: ChildWorkflowOptionsWithDefaults;
86
- readonly headers: Headers;
87
- readonly seq: number;
88
- }
89
- /** Input for WorkflowOutboundCallsInterceptor.startTimer */
90
- export interface TimerInput {
91
- readonly durationMs: number;
199
+ /**
200
+ * Input for {@link WorkflowOutboundCallsInterceptor.startNexusOperation}.
201
+ *
202
+ * @experimental Nexus support in Temporal SDK is experimental.
203
+ */
204
+ export interface StartNexusOperationInput {
205
+ readonly input: unknown;
206
+ readonly endpoint: string;
207
+ readonly service: string;
208
+ readonly options: StartNexusOperationOptions;
209
+ readonly operation: string;
92
210
  readonly seq: number;
93
- readonly options?: TimerOptions;
211
+ readonly headers: Record<string, string>;
94
212
  }
95
- /** Options for starting a timer (i.e. sleep) */
96
- export interface TimerOptions {
97
- /** @experimental A fixed, single line summary of the command's purpose */
213
+ /**
214
+ * Options for starting a Nexus Operation.
215
+ *
216
+ * @experimental Nexus support in Temporal SDK is experimental.
217
+ */
218
+ export interface StartNexusOperationOptions {
219
+ /**
220
+ * The end to end timeout for the Nexus Operation.
221
+ *
222
+ * Optional: defaults to the maximum allowed by the Temporal server.
223
+ */
224
+ readonly scheduleToCloseTimeout?: Duration;
225
+ /**
226
+ * A fixed, single-line summary for this Nexus Operation that may appear in the UI/CLI.
227
+ * This can be in single-line Temporal markdown format.
228
+ *
229
+ * @experimental User metadata is a new API and susceptible to change.
230
+ */
98
231
  readonly summary?: string;
99
232
  }
100
233
  /**
101
- * Same as ContinueAsNewOptions but workflowType must be defined
234
+ * Output for {@link WorkflowOutboundCallsInterceptor.startNexusOperation}.
235
+ *
236
+ * @experimental Nexus support in Temporal SDK is experimental.
102
237
  */
103
- export type ContinueAsNewInputOptions = ContinueAsNewOptions & Required<Pick<ContinueAsNewOptions, 'workflowType'>>;
104
- /** Input for WorkflowOutboundCallsInterceptor.continueAsNew */
105
- export interface ContinueAsNewInput {
106
- readonly args: unknown[];
238
+ export interface StartNexusOperationOutput {
239
+ /**
240
+ * The token for the Nexus Operation.
241
+ *
242
+ * Undefined if the Nexus Operation completed synchronously, in which case the {@link result}
243
+ * will be immediately resolved.
244
+ */
245
+ readonly token?: string;
246
+ /**
247
+ * A promise that will resolve when the Nexus Operation completes, either with the result of the
248
+ * Operation if it completed successfully, or a failure if the Nexus Operation failed.
249
+ */
250
+ readonly result: Promise<unknown>;
251
+ }
252
+ /**
253
+ * Input for {@link WorkflowOutboundCallsInterceptor.startChildWorkflowExecution}.
254
+ */
255
+ export interface StartChildWorkflowExecutionInput {
256
+ readonly workflowType: string;
257
+ readonly options: ChildWorkflowOptionsWithDefaults;
107
258
  readonly headers: Headers;
108
- readonly options: ContinueAsNewInputOptions;
259
+ readonly seq: number;
109
260
  }
110
- /** Input for WorkflowOutboundCallsInterceptor.signalWorkflow */
261
+ /**
262
+ * Input for {@link WorkflowOutboundCallsInterceptor.signalWorkflow}.
263
+ */
111
264
  export interface SignalWorkflowInput {
112
265
  readonly seq: number;
113
266
  readonly signalName: string;
@@ -121,74 +274,26 @@ export interface SignalWorkflowInput {
121
274
  readonly childWorkflowId: string;
122
275
  };
123
276
  }
124
- /** Input for WorkflowOutboundCallsInterceptor.getLogAttributes */
125
- export type GetLogAttributesInput = Record<string, unknown>;
126
- /** Input for WorkflowOutboundCallsInterceptor.getMetricTags */
127
- export type GetMetricTagsInput = MetricTags;
128
277
  /**
129
- * Implement any of these methods to intercept Workflow code calls to the Temporal APIs, like scheduling an activity and starting a timer
278
+ * Input for {@link WorkflowOutboundCallsInterceptor.continueAsNew}.
130
279
  */
131
- export interface WorkflowOutboundCallsInterceptor {
132
- /**
133
- * Called when Workflow schedules an Activity
134
- *
135
- * @return result of the activity execution
136
- */
137
- scheduleActivity?: (input: ActivityInput, next: Next<this, 'scheduleActivity'>) => Promise<unknown>;
138
- /**
139
- * Called when Workflow schedules a local Activity
140
- *
141
- * @return result of the activity execution
142
- */
143
- scheduleLocalActivity?: (input: LocalActivityInput, next: Next<this, 'scheduleLocalActivity'>) => Promise<unknown>;
144
- /**
145
- * Called when Workflow starts a timer
146
- */
147
- startTimer?: (input: TimerInput, next: Next<this, 'startTimer'>) => Promise<void>;
148
- /**
149
- * Called when Workflow calls continueAsNew
150
- */
151
- continueAsNew?: (input: ContinueAsNewInput, next: Next<this, 'continueAsNew'>) => Promise<never>;
152
- /**
153
- * Called when Workflow signals a child or external Workflow
154
- */
155
- signalWorkflow?: (input: SignalWorkflowInput, next: Next<this, 'signalWorkflow'>) => Promise<void>;
156
- /**
157
- * Called when Workflow starts a child workflow execution, the interceptor function returns 2 promises:
158
- *
159
- * - The first resolves with the `runId` when the child workflow has started or rejects if failed to start.
160
- * - The second resolves with the workflow result when the child workflow completes or rejects on failure.
161
- */
162
- startChildWorkflowExecution?: (input: StartChildWorkflowExecutionInput, next: Next<this, 'startChildWorkflowExecution'>) => Promise<[Promise<string>, Promise<unknown>]>;
163
- /**
164
- * Called on each invocation of the `workflow.log` methods.
165
- *
166
- * The attributes returned in this call are attached to every log message.
167
- */
168
- getLogAttributes?: (input: GetLogAttributesInput, next: Next<this, 'getLogAttributes'>) => Record<string, unknown>;
169
- /**
170
- * Called once every time a metric is emitted from a Workflow metric (ie. a metric created
171
- * from {@link workflow.metricMeter}).
172
- *
173
- * Tags returned by this hook are _prepended_ to tags defined at the metric level and tags
174
- * defined on the emitter function itself.
175
- */
176
- getMetricTags?: (input: GetMetricTagsInput, next: Next<this, 'getMetricTags'>) => MetricTags;
177
- }
178
- /** Input for WorkflowInternalsInterceptor.concludeActivation */
179
- export interface ConcludeActivationInput {
180
- commands: coresdk.workflow_commands.IWorkflowCommand[];
181
- }
182
- /** Output for WorkflowInternalsInterceptor.concludeActivation */
183
- export type ConcludeActivationOutput = ConcludeActivationInput;
184
- /** Input for WorkflowInternalsInterceptor.activate */
185
- export interface ActivateInput {
186
- activation: coresdk.workflow_activation.IWorkflowActivation;
187
- batchIndex: number;
188
- }
189
- /** Input for WorkflowInternalsInterceptor.dispose */
190
- export interface DisposeInput {
280
+ export interface ContinueAsNewInput {
281
+ readonly args: unknown[];
282
+ readonly headers: Headers;
283
+ readonly options: ContinueAsNewInputOptions;
191
284
  }
285
+ /**
286
+ * Input for {@link WorkflowOutboundCallsInterceptor.continueAsNew}.
287
+ */
288
+ export type ContinueAsNewInputOptions = ContinueAsNewOptions & Required<Pick<ContinueAsNewOptions, 'workflowType'>>;
289
+ /**
290
+ * Input for {@link WorkflowOutboundCallsInterceptor.getLogAttributes}.
291
+ */
292
+ export type GetLogAttributesInput = Record<string, unknown>;
293
+ /**
294
+ * Input for {@link WorkflowOutboundCallsInterceptor.getMetricTags}.
295
+ */
296
+ export type GetMetricTagsInput = MetricTags;
192
297
  /**
193
298
  * Interceptor for the internals of the Workflow runtime.
194
299
  *
@@ -215,28 +320,24 @@ export interface WorkflowInternalsInterceptor {
215
320
  dispose?(input: DisposeInput, next: Next<this, 'dispose'>): void;
216
321
  }
217
322
  /**
218
- * A mapping from interceptor type to an optional list of interceptor implementations
323
+ * Input for {@link WorkflowInternalsInterceptor.activate}
219
324
  */
220
- export interface WorkflowInterceptors {
221
- inbound?: WorkflowInboundCallsInterceptor[];
222
- outbound?: WorkflowOutboundCallsInterceptor[];
223
- internals?: WorkflowInternalsInterceptor[];
325
+ export interface ActivateInput {
326
+ readonly activation: coresdk.workflow_activation.IWorkflowActivation;
327
+ readonly batchIndex: number;
224
328
  }
225
329
  /**
226
- * A function that returns {@link WorkflowInterceptors} and takes no arguments.
227
- *
228
- * Workflow interceptor modules should export an `interceptors` function of this type.
229
- *
230
- * @example
231
- *
232
- * ```ts
233
- * export function interceptors(): WorkflowInterceptors {
234
- * return {
235
- * inbound: [], // Populate with list of interceptor implementations
236
- * outbound: [], // Populate with list of interceptor implementations
237
- * internals: [], // Populate with list of interceptor implementations
238
- * };
239
- * }
240
- * ```
330
+ * Input for {@link WorkflowInternalsInterceptor.dispose}
241
331
  */
242
- export type WorkflowInterceptorsFactory = () => WorkflowInterceptors;
332
+ export interface DisposeInput {
333
+ }
334
+ /**
335
+ * Input for {@link WorkflowInternalsInterceptor.concludeActivation}
336
+ */
337
+ export interface ConcludeActivationInput {
338
+ readonly commands: coresdk.workflow_commands.IWorkflowCommand[];
339
+ }
340
+ /**
341
+ * Output for {@link WorkflowInternalsInterceptor.concludeActivation}
342
+ */
343
+ export type ConcludeActivationOutput = ConcludeActivationInput;
@@ -1,8 +1,6 @@
1
1
  "use strict";
2
2
  /**
3
- * Type definitions and generic helpers for interceptors.
4
- *
5
- * The Workflow specific interceptors are defined here.
3
+ * Type definitions for Workflow interceptors.
6
4
  *
7
5
  * @module
8
6
  */
@@ -1 +1 @@
1
- {"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
1
+ {"version":3,"file":"interceptors.js","sourceRoot":"","sources":["../src/interceptors.ts"],"names":[],"mappings":";AAAA;;;;GAIG"}
@@ -3,7 +3,7 @@ import { FailureConverter, PayloadConverter, HandlerUnfinishedPolicy, Workflow,
3
3
  import type { coresdk } from '@temporalio/proto';
4
4
  import { RNG } from './alea';
5
5
  import { RootCancellationScope } from './cancellation-scope';
6
- import { QueryInput, SignalInput, UpdateInput, WorkflowExecuteInput, WorkflowInterceptors } from './interceptors';
6
+ import { QueryInput, SignalInput, StartNexusOperationOutput, UpdateInput, WorkflowExecuteInput, WorkflowInterceptors } from './interceptors';
7
7
  import { DefaultSignalHandler, StackTraceFileLocation, WorkflowInfo, WorkflowCreateOptionsInternal, ActivationCompletion, DefaultUpdateHandler, DefaultQueryHandler } from './interfaces';
8
8
  import { type SinkCall } from './sinks';
9
9
  import { SdkFlag } from './flags';
@@ -18,9 +18,9 @@ export interface PromiseStackStore {
18
18
  childToParent: Map<Promise<unknown>, Set<Promise<unknown>>>;
19
19
  promiseToStack: Map<Promise<unknown>, Stack>;
20
20
  }
21
- export interface Completion {
22
- resolve(val: unknown): unknown;
23
- reject(reason: unknown): unknown;
21
+ export interface Completion<Success> {
22
+ resolve(val: Success): void;
23
+ reject(reason: Error): void;
24
24
  }
25
25
  export interface Condition {
26
26
  fn(): boolean;
@@ -68,12 +68,14 @@ export declare class Activator implements ActivationHandler {
68
68
  * Map of task sequence to a Completion
69
69
  */
70
70
  readonly completions: {
71
- timer: Map<number, Completion>;
72
- activity: Map<number, Completion>;
73
- childWorkflowStart: Map<number, Completion>;
74
- childWorkflowComplete: Map<number, Completion>;
75
- signalWorkflow: Map<number, Completion>;
76
- cancelWorkflow: Map<number, Completion>;
71
+ timer: Map<number, Completion<void>>;
72
+ activity: Map<number, Completion<unknown>>;
73
+ nexusOperationStart: Map<number, Completion<StartNexusOperationOutput>>;
74
+ nexusOperationComplete: Map<number, Completion<unknown>>;
75
+ childWorkflowStart: Map<number, Completion<string>>;
76
+ childWorkflowComplete: Map<number, Completion<unknown>>;
77
+ signalWorkflow: Map<number, Completion<void>>;
78
+ cancelWorkflow: Map<number, Completion<void>>;
77
79
  };
78
80
  /**
79
81
  * Holds buffered Update calls until a handler is registered
@@ -193,6 +195,7 @@ export declare class Activator implements ActivationHandler {
193
195
  signalWorkflow: number;
194
196
  cancelWorkflow: number;
195
197
  condition: number;
198
+ nexusOperation: number;
196
199
  stack: number;
197
200
  };
198
201
  /**
@@ -263,8 +266,8 @@ export declare class Activator implements ActivationHandler {
263
266
  resolveActivity(activation: coresdk.workflow_activation.IResolveActivity): void;
264
267
  resolveChildWorkflowExecutionStart(activation: coresdk.workflow_activation.IResolveChildWorkflowExecutionStart): void;
265
268
  resolveChildWorkflowExecution(activation: coresdk.workflow_activation.IResolveChildWorkflowExecution): void;
266
- resolveNexusOperationStart(_: coresdk.workflow_activation.IResolveNexusOperationStart): void;
267
- resolveNexusOperation(_: coresdk.workflow_activation.IResolveNexusOperation): void;
269
+ resolveNexusOperationStart(activation: coresdk.workflow_activation.IResolveNexusOperationStart): void;
270
+ resolveNexusOperation(activation: coresdk.workflow_activation.IResolveNexusOperation): void;
268
271
  protected queryWorkflowNextHandler({ queryName, args }: QueryInput): Promise<unknown>;
269
272
  queryWorkflow(activation: coresdk.workflow_activation.IQueryWorkflow): void;
270
273
  doUpdate(activation: coresdk.workflow_activation.IDoUpdate): void;