@temporalio/activity 1.7.4 → 1.8.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.
package/lib/index.d.ts CHANGED
@@ -72,8 +72,10 @@
72
72
  /// <reference types="node" />
73
73
  import 'abort-controller/polyfill';
74
74
  import { AsyncLocalStorage } from 'node:async_hooks';
75
+ import { Logger, Duration } from '@temporalio/common';
75
76
  export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
76
77
  ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
78
+ declare const isCompleteAsyncError: unique symbol;
77
79
  /**
78
80
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
79
81
  *
@@ -94,8 +96,15 @@ ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/com
94
96
  export declare class CompleteAsyncError extends Error {
95
97
  readonly name: string;
96
98
  constructor();
99
+ /**
100
+ * Marker to determine whether an error is an instance of CompleteAsyncError.
101
+ */
102
+ protected readonly [isCompleteAsyncError] = true;
103
+ /**
104
+ * Instanceof check that works when multiple versions of @temporalio/activity are installed.
105
+ */
106
+ static is(error: unknown): error is CompleteAsyncError;
97
107
  }
98
- /** @ignore */
99
108
  export declare const asyncLocalStorage: AsyncLocalStorage<Context>;
100
109
  /**
101
110
  * Holds information about the current Activity Execution. Retrieved inside an Activity with `Context.current().info`.
@@ -144,10 +153,8 @@ export interface Info {
144
153
  scheduledTimestampMs: number;
145
154
  /**
146
155
  * Timeout for this Activity from schedule to close in milliseconds.
147
- *
148
- * Might be undefined for local activities.
149
156
  */
150
- scheduleToCloseTimeoutMs?: number;
157
+ scheduleToCloseTimeoutMs: number;
151
158
  /**
152
159
  * Timeout for this Activity from start to close in milliseconds
153
160
  */
@@ -198,10 +205,11 @@ export declare class Context {
198
205
  * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
199
206
  * Activity cancellation.
200
207
  *
201
- * Used by {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
208
+ * This can be passed in to libraries such as
209
+ * {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
202
210
  * in-progress request and
203
211
  * {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
204
- * to abort a child process, and is supported by some other libraries as well.
212
+ * to abort a child process, as well as other built-in node modules and modules found on npm.
205
213
  *
206
214
  * @see [Cancellation](/api/namespaces/activity#cancellation)
207
215
  */
@@ -210,12 +218,25 @@ export declare class Context {
210
218
  * The heartbeat implementation, injected via the constructor.
211
219
  */
212
220
  protected readonly heartbeatFn: (details?: any) => void;
221
+ /**
222
+ * The logger for this Activity.
223
+ *
224
+ * This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). If the {@link ActivityInboundLogInterceptor}
225
+ * is installed (by default, it is; see {@link WorkerOptions.interceptors}), then various attributes from the current
226
+ * Activity context will automatically be included as metadata on every log entries, and some key events of the
227
+ * Activity's life cycle will automatically be logged (at 'DEBUG' level for most messages; 'WARN' for failures).
228
+ *
229
+ * To use a different Logger, either overwrite this property from an Activity Interceptor, or explicitly register the
230
+ * `ActivityInboundLogInterceptor` with your custom Logger. You may also subclass `ActivityInboundLogInterceptor` to
231
+ * customize attributes that are emitted as metadata.
232
+ */
233
+ log: Logger;
213
234
  /**
214
235
  * **Not** meant to instantiated by Activity code, used by the worker.
215
236
  *
216
237
  * @ignore
217
238
  */
218
- constructor(info: Info, cancelled: Promise<never>, cancellationSignal: AbortSignal, heartbeat: (details?: any) => void);
239
+ constructor(info: Info, cancelled: Promise<never>, cancellationSignal: AbortSignal, heartbeat: (details?: any) => void, logger: Logger);
219
240
  /**
220
241
  * Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
221
242
  *
@@ -229,7 +250,13 @@ export declare class Context {
229
250
  *
230
251
  * Calling `heartbeat()` from a Local Activity has no effect.
231
252
  *
253
+ * The SDK automatically throttles heartbeat calls to the server with a duration of 80% of the specified activity
254
+ * heartbeat timeout. Throttling behavior may be customized with the `{@link maxHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#maxheartbeatthrottleinterval} and {@link defaultHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#defaultheartbeatthrottleinterval} worker options.
255
+ *
232
256
  * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
257
+ *
258
+ * :warning: Cancellation is not propagated from this function, use {@link cancelled} or {@link cancellationSignal} to
259
+ * subscribe to cancellation notifications.
233
260
  */
234
261
  heartbeat(details?: unknown): void;
235
262
  /**
@@ -243,5 +270,5 @@ export declare class Context {
243
270
  * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
244
271
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
245
272
  */
246
- sleep(ms: number | string): Promise<void>;
273
+ sleep(ms: Duration): Promise<void>;
247
274
  }
package/lib/index.js CHANGED
@@ -69,6 +69,7 @@
69
69
  *
70
70
  * @module
71
71
  */
72
+ var _a;
72
73
  Object.defineProperty(exports, "__esModule", { value: true });
73
74
  exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.CancelledFailure = exports.ApplicationFailure = void 0;
74
75
  require("abort-controller/polyfill"); // eslint-disable-line import/no-unassigned-import
@@ -77,6 +78,7 @@ const time_1 = require("@temporalio/common/lib/time");
77
78
  var common_1 = require("@temporalio/common");
78
79
  Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
79
80
  Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
81
+ const isCompleteAsyncError = Symbol.for('__temporal_isCompleteAsyncError');
80
82
  /**
81
83
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
82
84
  *
@@ -98,11 +100,26 @@ class CompleteAsyncError extends Error {
98
100
  constructor() {
99
101
  super();
100
102
  this.name = 'CompleteAsyncError';
103
+ /**
104
+ * Marker to determine whether an error is an instance of CompleteAsyncError.
105
+ */
106
+ this[_a] = true;
107
+ }
108
+ /**
109
+ * Instanceof check that works when multiple versions of @temporalio/activity are installed.
110
+ */
111
+ static is(error) {
112
+ return error instanceof CompleteAsyncError || error?.[isCompleteAsyncError] === true;
101
113
  }
102
114
  }
103
115
  exports.CompleteAsyncError = CompleteAsyncError;
104
- /** @ignore */
105
- exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
116
+ _a = isCompleteAsyncError;
117
+ // Make it safe to use @temporalio/activity with multiple versions installed.
118
+ const asyncLocalStorageSymbol = Symbol.for('__temporal_activity_context_storage__');
119
+ if (!globalThis[asyncLocalStorageSymbol]) {
120
+ globalThis[asyncLocalStorageSymbol] = new node_async_hooks_1.AsyncLocalStorage();
121
+ }
122
+ exports.asyncLocalStorage = globalThis[asyncLocalStorageSymbol];
106
123
  /**
107
124
  * Activity Context, used to:
108
125
  *
@@ -119,11 +136,12 @@ class Context {
119
136
  *
120
137
  * @ignore
121
138
  */
122
- constructor(info, cancelled, cancellationSignal, heartbeat) {
139
+ constructor(info, cancelled, cancellationSignal, heartbeat, logger) {
123
140
  this.info = info;
124
141
  this.cancelled = cancelled;
125
142
  this.cancellationSignal = cancellationSignal;
126
143
  this.heartbeatFn = heartbeat;
144
+ this.log = logger;
127
145
  }
128
146
  /**
129
147
  * Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
@@ -138,7 +156,13 @@ class Context {
138
156
  *
139
157
  * Calling `heartbeat()` from a Local Activity has no effect.
140
158
  *
159
+ * The SDK automatically throttles heartbeat calls to the server with a duration of 80% of the specified activity
160
+ * heartbeat timeout. Throttling behavior may be customized with the `{@link maxHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#maxheartbeatthrottleinterval} and {@link defaultHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#defaultheartbeatthrottleinterval} worker options.
161
+ *
141
162
  * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
163
+ *
164
+ * :warning: Cancellation is not propagated from this function, use {@link cancelled} or {@link cancellationSignal} to
165
+ * subscribe to cancellation notifications.
142
166
  */
143
167
  heartbeat(details) {
144
168
  this.heartbeatFn(details);
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;AAEH,qCAAmC,CAAC,kDAAkD;AACtF,uDAAqD;AACrD,sDAAyD;AAEzD,6CAM4B;AAH1B,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAIlB;;;;;;;;;;;;;;;;GAgBG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAG3C;QACE,KAAK,EAAE,CAAC;QAHM,SAAI,GAAW,oBAAoB,CAAC;IAIpD,CAAC;CACF;AAND,gDAMC;AAED,cAAc;AACD,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAW,CAAC;AA8ElE;;;;;;;;;GASG;AACH,MAAa,OAAO;IA8BlB;;;;OAIG;IACH,YACE,IAAU,EACV,SAAyB,EACzB,kBAA+B,EAC/B,SAAkC;QAElC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;QAC7C,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACI,SAAS,CAAC,OAAiB;QAChC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,O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C,MAAM,GAAG,UAAU,CAAC,OAAO,EAAE,IAAA,iBAAU,EAAC,EAAE,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;QACH,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACnF,CAAC;CACF;AAjHD,0BAiHC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/activity",
3
- "version": "1.7.4",
3
+ "version": "1.8.1",
4
4
  "description": "Temporal.io SDK Activity sub-package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@temporalio/common": "1.7.4",
16
+ "@temporalio/common": "1.8.1",
17
17
  "abort-controller": "^3.0.0"
18
18
  },
19
19
  "bugs": {
@@ -32,5 +32,5 @@
32
32
  "src",
33
33
  "lib"
34
34
  ],
35
- "gitHead": "fb4088a8174b60b7a3fc7763ed39dbfc514a3e56"
35
+ "gitHead": "97808111bbec478260e915726bb9730a489f8fa4"
36
36
  }
package/src/index.ts CHANGED
@@ -71,6 +71,7 @@
71
71
 
72
72
  import 'abort-controller/polyfill'; // eslint-disable-line import/no-unassigned-import
73
73
  import { AsyncLocalStorage } from 'node:async_hooks';
74
+ import { Logger, Duration } from '@temporalio/common';
74
75
  import { msToNumber } from '@temporalio/common/lib/time';
75
76
 
76
77
  export {
@@ -81,6 +82,8 @@ export {
81
82
  UntypedActivities,
82
83
  } from '@temporalio/common';
83
84
 
85
+ const isCompleteAsyncError = Symbol.for('__temporal_isCompleteAsyncError');
86
+
84
87
  /**
85
88
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
86
89
  *
@@ -104,10 +107,27 @@ export class CompleteAsyncError extends Error {
104
107
  constructor() {
105
108
  super();
106
109
  }
110
+
111
+ /**
112
+ * Marker to determine whether an error is an instance of CompleteAsyncError.
113
+ */
114
+ protected readonly [isCompleteAsyncError] = true;
115
+
116
+ /**
117
+ * Instanceof check that works when multiple versions of @temporalio/activity are installed.
118
+ */
119
+ static is(error: unknown): error is CompleteAsyncError {
120
+ return error instanceof CompleteAsyncError || (error as any)?.[isCompleteAsyncError] === true;
121
+ }
107
122
  }
108
123
 
109
- /** @ignore */
110
- export const asyncLocalStorage = new AsyncLocalStorage<Context>();
124
+ // Make it safe to use @temporalio/activity with multiple versions installed.
125
+ const asyncLocalStorageSymbol = Symbol.for('__temporal_activity_context_storage__');
126
+ if (!(globalThis as any)[asyncLocalStorageSymbol]) {
127
+ (globalThis as any)[asyncLocalStorageSymbol] = new AsyncLocalStorage<Context>();
128
+ }
129
+
130
+ export const asyncLocalStorage: AsyncLocalStorage<Context> = (globalThis as any)[asyncLocalStorageSymbol];
111
131
 
112
132
  /**
113
133
  * Holds information about the current Activity Execution. Retrieved inside an Activity with `Context.current().info`.
@@ -156,10 +176,8 @@ export interface Info {
156
176
  scheduledTimestampMs: number;
157
177
  /**
158
178
  * Timeout for this Activity from schedule to close in milliseconds.
159
- *
160
- * Might be undefined for local activities.
161
179
  */
162
- scheduleToCloseTimeoutMs?: number;
180
+ scheduleToCloseTimeoutMs: number;
163
181
  /**
164
182
  * Timeout for this Activity from start to close in milliseconds
165
183
  */
@@ -212,10 +230,11 @@ export class Context {
212
230
  * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
213
231
  * Activity cancellation.
214
232
  *
215
- * Used by {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
233
+ * This can be passed in to libraries such as
234
+ * {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
216
235
  * in-progress request and
217
236
  * {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
218
- * to abort a child process, and is supported by some other libraries as well.
237
+ * to abort a child process, as well as other built-in node modules and modules found on npm.
219
238
  *
220
239
  * @see [Cancellation](/api/namespaces/activity#cancellation)
221
240
  */
@@ -224,6 +243,19 @@ export class Context {
224
243
  * The heartbeat implementation, injected via the constructor.
225
244
  */
226
245
  protected readonly heartbeatFn: (details?: any) => void;
246
+ /**
247
+ * The logger for this Activity.
248
+ *
249
+ * This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). If the {@link ActivityInboundLogInterceptor}
250
+ * is installed (by default, it is; see {@link WorkerOptions.interceptors}), then various attributes from the current
251
+ * Activity context will automatically be included as metadata on every log entries, and some key events of the
252
+ * Activity's life cycle will automatically be logged (at 'DEBUG' level for most messages; 'WARN' for failures).
253
+ *
254
+ * To use a different Logger, either overwrite this property from an Activity Interceptor, or explicitly register the
255
+ * `ActivityInboundLogInterceptor` with your custom Logger. You may also subclass `ActivityInboundLogInterceptor` to
256
+ * customize attributes that are emitted as metadata.
257
+ */
258
+ public log: Logger;
227
259
 
228
260
  /**
229
261
  * **Not** meant to instantiated by Activity code, used by the worker.
@@ -234,12 +266,14 @@ export class Context {
234
266
  info: Info,
235
267
  cancelled: Promise<never>,
236
268
  cancellationSignal: AbortSignal,
237
- heartbeat: (details?: any) => void
269
+ heartbeat: (details?: any) => void,
270
+ logger: Logger
238
271
  ) {
239
272
  this.info = info;
240
273
  this.cancelled = cancelled;
241
274
  this.cancellationSignal = cancellationSignal;
242
275
  this.heartbeatFn = heartbeat;
276
+ this.log = logger;
243
277
  }
244
278
 
245
279
  /**
@@ -255,7 +289,13 @@ export class Context {
255
289
  *
256
290
  * Calling `heartbeat()` from a Local Activity has no effect.
257
291
  *
292
+ * The SDK automatically throttles heartbeat calls to the server with a duration of 80% of the specified activity
293
+ * heartbeat timeout. Throttling behavior may be customized with the `{@link maxHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#maxheartbeatthrottleinterval} and {@link defaultHeartbeatThrottleInterval | https://typescript.temporal.io/api/interfaces/worker.WorkerOptions#defaultheartbeatthrottleinterval} worker options.
294
+ *
258
295
  * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
296
+ *
297
+ * :warning: Cancellation is not propagated from this function, use {@link cancelled} or {@link cancellationSignal} to
298
+ * subscribe to cancellation notifications.
259
299
  */
260
300
  public heartbeat(details?: unknown): void {
261
301
  this.heartbeatFn(details);
@@ -279,7 +319,7 @@ export class Context {
279
319
  * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
280
320
  * @returns A Promise that either resolves when `ms` is reached or rejects when the Activity is cancelled
281
321
  */
282
- public sleep(ms: number | string): Promise<void> {
322
+ public sleep(ms: Duration): Promise<void> {
283
323
  let handle: NodeJS.Timeout;
284
324
  const timer = new Promise<void>((resolve) => {
285
325
  handle = setTimeout(resolve, msToNumber(ms));