@temporalio/activity 1.12.3 → 1.13.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
@@ -69,8 +69,9 @@
69
69
  * @module
70
70
  */
71
71
  import { AsyncLocalStorage } from 'node:async_hooks';
72
- import { Logger, Duration, MetricMeter, Priority, ActivityCancellationDetails } from '@temporalio/common';
72
+ import { Logger, Duration, MetricMeter, Priority, ActivityCancellationDetails, RetryPolicy } from '@temporalio/common';
73
73
  import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
74
+ import { Client } from '@temporalio/client';
74
75
  export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
75
76
  ApplicationFailure, CancelledFailure, UntypedActivities, } from '@temporalio/common';
76
77
  /**
@@ -184,6 +185,14 @@ export interface Info {
184
185
  * Priority of this activity
185
186
  */
186
187
  readonly priority?: Priority;
188
+ /**
189
+ * The retry policy of this activity.
190
+ *
191
+ * Note that the server may have set a different policy than the one provided when scheduling the activity.
192
+ * If the value is undefined, it means the server didn't send information about retry policy (e.g. due to old server
193
+ * version), but it may still be defined server-side.
194
+ */
195
+ readonly retryPolicy?: RetryPolicy;
187
196
  }
188
197
  /**
189
198
  * Activity Context, used to:
@@ -196,12 +205,6 @@ export interface Info {
196
205
  * Call `Context.current()` from Activity code in order to get the current Activity's Context.
197
206
  */
198
207
  export declare class Context {
199
- /**
200
- * Gets the context of the current Activity.
201
- *
202
- * Uses {@link https://nodejs.org/docs/latest-v16.x/api/async_context.html#class-asynclocalstorage | AsyncLocalStorage} under the hood to make it accessible in nested callbacks and promises.
203
- */
204
- static current(): Context;
205
208
  /**
206
209
  * Holds information about the current executing Activity.
207
210
  */
@@ -234,6 +237,10 @@ export declare class Context {
234
237
  * The heartbeat implementation, injected via the constructor.
235
238
  */
236
239
  protected readonly heartbeatFn: (details?: any) => void;
240
+ /**
241
+ * The Worker's client, passed down through Activity context.
242
+ */
243
+ protected readonly _client: Client | undefined;
237
244
  /**
238
245
  * The logger for this Activity.
239
246
  *
@@ -260,13 +267,82 @@ export declare class Context {
260
267
  /**
261
268
  * Holder object for activity cancellation details
262
269
  */
263
- private readonly _cancellationDetails;
270
+ protected readonly _cancellationDetails: ActivityCancellationDetailsHolder;
271
+ /**
272
+ * Gets the context of the current Activity.
273
+ *
274
+ * Uses {@link https://nodejs.org/docs/latest-v16.x/api/async_context.html#class-asynclocalstorage | AsyncLocalStorage} under the hood to make it accessible in nested callbacks and promises.
275
+ */
276
+ static current(): Context;
264
277
  /**
265
278
  * **Not** meant to instantiated by Activity code, used by the worker.
266
279
  *
267
280
  * @ignore
268
281
  */
269
- constructor(info: Info, cancelled: Promise<never>, cancellationSignal: AbortSignal, heartbeat: (details?: any) => void, log: Logger, metricMeter: MetricMeter, details: ActivityCancellationDetailsHolder);
282
+ constructor(
283
+ /**
284
+ * Holds information about the current executing Activity.
285
+ */
286
+ info: Info,
287
+ /**
288
+ * A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
289
+ * is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
290
+ *
291
+ * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
292
+ *
293
+ * @see [Cancellation](/api/namespaces/activity#cancellation)
294
+ */
295
+ cancelled: Promise<never>,
296
+ /**
297
+ * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
298
+ * Activity cancellation.
299
+ *
300
+ * This can be passed in to libraries such as
301
+ * {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
302
+ * in-progress request and
303
+ * {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
304
+ * to abort a child process, as well as other built-in node modules and modules found on npm.
305
+ *
306
+ * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
307
+ *
308
+ * @see [Cancellation](/api/namespaces/activity#cancellation)
309
+ */
310
+ cancellationSignal: AbortSignal,
311
+ /**
312
+ * The heartbeat implementation, injected via the constructor.
313
+ */
314
+ heartbeatFn: (details?: any) => void,
315
+ /**
316
+ * The Worker's client, passed down through Activity context.
317
+ */
318
+ _client: Client | undefined,
319
+ /**
320
+ * The logger for this Activity.
321
+ *
322
+ * This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
323
+ * are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
324
+ * added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
325
+ *
326
+ * To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
327
+ * `getLogAttributes()` method.
328
+ *
329
+ * Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
330
+ * with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
331
+ * through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
332
+ * {@link Runtime.logger} property instead.
333
+ */
334
+ log: Logger,
335
+ /**
336
+ * Get the metric meter for this activity with activity-specific tags.
337
+ *
338
+ * To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
339
+ * intercepts the `getMetricTags()` method.
340
+ */
341
+ metricMeter: MetricMeter,
342
+ /**
343
+ * Holder object for activity cancellation details
344
+ */
345
+ _cancellationDetails: ActivityCancellationDetailsHolder);
270
346
  /**
271
347
  * Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
272
348
  *
@@ -289,6 +365,17 @@ export declare class Context {
289
365
  * subscribe to cancellation notifications.
290
366
  */
291
367
  readonly heartbeat: (details?: unknown) => void;
368
+ /**
369
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
370
+ *
371
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
372
+ * that was created without a Client.
373
+ *
374
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
375
+ * incomplete or different from what would be observed using a {@link Connection}
376
+ * instead. Client doesn't support cancellation through a Signal.
377
+ */
378
+ get client(): Client;
292
379
  /**
293
380
  * Helper function for sleeping in an Activity.
294
381
  * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
@@ -368,6 +455,19 @@ export declare function cancellationDetails(): ActivityCancellationDetails | und
368
455
  * This is a shortcut for `Context.current().cancellationSignal` (see {@link Context.cancellationSignal}).
369
456
  */
370
457
  export declare function cancellationSignal(): AbortSignal;
458
+ /**
459
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
460
+ *
461
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
462
+ * that was created without a Client.
463
+ *
464
+ * This is a shortcut for `Context.current().client` (see {@link Context.client}).
465
+ *
466
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
467
+ * incomplete or different from what would be observed using a {@link Connection}
468
+ * instead. Client doesn't support cancellation through a Signal.
469
+ */
470
+ export declare function getClient(): Client;
371
471
  /**
372
472
  * Get the metric meter for the current activity, with activity-specific tags.
373
473
  *
package/lib/index.js CHANGED
@@ -83,12 +83,14 @@ exports.heartbeat = heartbeat;
83
83
  exports.cancelled = cancelled;
84
84
  exports.cancellationDetails = cancellationDetails;
85
85
  exports.cancellationSignal = cancellationSignal;
86
+ exports.getClient = getClient;
86
87
  const node_async_hooks_1 = require("node:async_hooks");
88
+ const common_1 = require("@temporalio/common");
87
89
  const time_1 = require("@temporalio/common/lib/time");
88
90
  const type_helpers_1 = require("@temporalio/common/lib/type-helpers");
89
- var common_1 = require("@temporalio/common");
90
- Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
91
- Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
91
+ var common_2 = require("@temporalio/common");
92
+ Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_2.ApplicationFailure; } });
93
+ Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_2.CancelledFailure; } });
92
94
  /**
93
95
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
94
96
  *
@@ -129,6 +131,14 @@ exports.asyncLocalStorage = globalThis[asyncLocalStorageSymbol];
129
131
  * Call `Context.current()` from Activity code in order to get the current Activity's Context.
130
132
  */
131
133
  class Context {
134
+ info;
135
+ cancelled;
136
+ cancellationSignal;
137
+ heartbeatFn;
138
+ _client;
139
+ log;
140
+ metricMeter;
141
+ _cancellationDetails;
132
142
  /**
133
143
  * Gets the context of the current Activity.
134
144
  *
@@ -141,10 +151,16 @@ class Context {
141
151
  }
142
152
  return store;
143
153
  }
154
+ /**
155
+ * **Not** meant to instantiated by Activity code, used by the worker.
156
+ *
157
+ * @ignore
158
+ */
159
+ constructor(
144
160
  /**
145
161
  * Holds information about the current executing Activity.
146
162
  */
147
- info;
163
+ info,
148
164
  /**
149
165
  * A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
150
166
  * is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
@@ -153,7 +169,7 @@ class Context {
153
169
  *
154
170
  * @see [Cancellation](/api/namespaces/activity#cancellation)
155
171
  */
156
- cancelled;
172
+ cancelled,
157
173
  /**
158
174
  * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
159
175
  * Activity cancellation.
@@ -168,11 +184,15 @@ class Context {
168
184
  *
169
185
  * @see [Cancellation](/api/namespaces/activity#cancellation)
170
186
  */
171
- cancellationSignal;
187
+ cancellationSignal,
172
188
  /**
173
189
  * The heartbeat implementation, injected via the constructor.
174
190
  */
175
- heartbeatFn;
191
+ heartbeatFn,
192
+ /**
193
+ * The Worker's client, passed down through Activity context.
194
+ */
195
+ _client,
176
196
  /**
177
197
  * The logger for this Activity.
178
198
  *
@@ -188,31 +208,26 @@ class Context {
188
208
  * through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
189
209
  * {@link Runtime.logger} property instead.
190
210
  */
191
- log;
211
+ log,
192
212
  /**
193
213
  * Get the metric meter for this activity with activity-specific tags.
194
214
  *
195
215
  * To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
196
216
  * intercepts the `getMetricTags()` method.
197
217
  */
198
- metricMeter;
218
+ metricMeter,
199
219
  /**
200
220
  * Holder object for activity cancellation details
201
221
  */
202
- _cancellationDetails;
203
- /**
204
- * **Not** meant to instantiated by Activity code, used by the worker.
205
- *
206
- * @ignore
207
- */
208
- constructor(info, cancelled, cancellationSignal, heartbeat, log, metricMeter, details) {
222
+ _cancellationDetails) {
209
223
  this.info = info;
210
224
  this.cancelled = cancelled;
211
225
  this.cancellationSignal = cancellationSignal;
212
- this.heartbeatFn = heartbeat;
226
+ this.heartbeatFn = heartbeatFn;
227
+ this._client = _client;
213
228
  this.log = log;
214
229
  this.metricMeter = metricMeter;
215
- this._cancellationDetails = details;
230
+ this._cancellationDetails = _cancellationDetails;
216
231
  }
217
232
  /**
218
233
  * Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
@@ -238,6 +253,22 @@ class Context {
238
253
  heartbeat = (details) => {
239
254
  this.heartbeatFn(details);
240
255
  };
256
+ /**
257
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
258
+ *
259
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
260
+ * that was created without a Client.
261
+ *
262
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
263
+ * incomplete or different from what would be observed using a {@link Connection}
264
+ * instead. Client doesn't support cancellation through a Signal.
265
+ */
266
+ get client() {
267
+ if (this._client === undefined) {
268
+ throw new common_1.IllegalStateError('No Client available. This may be a MockActivityEnvironment that was created without a Client.');
269
+ }
270
+ return this._client;
271
+ }
241
272
  /**
242
273
  * Helper function for sleeping in an Activity.
243
274
  * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
@@ -360,6 +391,21 @@ function cancellationDetails() {
360
391
  function cancellationSignal() {
361
392
  return Context.current().cancellationSignal;
362
393
  }
394
+ /**
395
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
396
+ *
397
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
398
+ * that was created without a Client.
399
+ *
400
+ * This is a shortcut for `Context.current().client` (see {@link Context.client}).
401
+ *
402
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
403
+ * incomplete or different from what would be observed using a {@link Connection}
404
+ * instead. Client doesn't support cancellation through a Signal.
405
+ */
406
+ function getClient() {
407
+ return Context.current().client;
408
+ }
363
409
  /**
364
410
  * Get the metric meter for the current activity, with activity-specific tags.
365
411
  *
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqEG;;;;;;;;;AAuTH,oCAGC;AAsCD,sBAEC;AAeD,8BAEC;AAWD,8BAEC;AAQD,kDAEC;AAgBD,gDAEC;AA1ZD,uDAAqD;AAUrD,sDAAyD;AACzD,sEAAiF;AAGjF,6CAM4B;AAH1B,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAIlB;;;;;;;;;;;;;;;;GAgBG;AAEI,IAAM,kBAAkB,GAAxB,MAAM,kBAAmB,SAAQ,KAAK;CAAG,CAAA;AAAnC,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,yCAA0B,EAAC,oBAAoB,CAAC;GACpC,kBAAkB,CAAiB;AAEhD,6EAA6E;AAC7E,MAAM,uBAAuB,GAAG,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AACpF,IAAI,CAAE,UAAkB,CAAC,uBAAuB,CAAC,EAAE,CAAC;IACjD,UAAkB,CAAC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,EAAE,CAAC,MAAM,CAAC;AAClC,CAAC;AAED;;;;;;;GAOG;AACU,QAAA,WAAW,GAAgB;IACtC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW;QACnC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC9E,CAAC;IACD,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW;QACxD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IAC3F,CAAC;IACD,WAAW,CAAC,IAAI,EAAE,SAAS,GAAG,KAAK,EAAE,IAAI,EAAE,WAAW;QACpD,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;IACvF,CAAC;IACD,QAAQ,CAAC,IAAI;QACX,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/activity",
3
- "version": "1.12.3",
3
+ "version": "1.13.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,8 @@
13
13
  "author": "Temporal Technologies Inc. <sdk@temporal.io>",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@temporalio/common": "1.12.3",
16
+ "@temporalio/client": "1.13.1",
17
+ "@temporalio/common": "1.13.1",
17
18
  "abort-controller": "^3.0.0"
18
19
  },
19
20
  "engines": {
@@ -35,5 +36,5 @@
35
36
  "src",
36
37
  "lib"
37
38
  ],
38
- "gitHead": "e25f1d5ddaf0b5c755457b1cc1dde7c6e089a63b"
39
+ "gitHead": "7904e19bc72dcdf9eb0275ecaa585a2ff2fec072"
39
40
  }
package/src/index.ts CHANGED
@@ -78,10 +78,13 @@ import {
78
78
  MetricMeter,
79
79
  Priority,
80
80
  ActivityCancellationDetails,
81
+ IllegalStateError,
82
+ RetryPolicy,
81
83
  } from '@temporalio/common';
82
84
  import { msToNumber } from '@temporalio/common/lib/time';
83
85
  import { SymbolBasedInstanceOfError } from '@temporalio/common/lib/type-helpers';
84
86
  import { ActivityCancellationDetailsHolder } from '@temporalio/common/lib/activity-cancellation-details';
87
+ import { Client } from '@temporalio/client';
85
88
 
86
89
  export {
87
90
  ActivityFunction,
@@ -211,6 +214,14 @@ export interface Info {
211
214
  * Priority of this activity
212
215
  */
213
216
  readonly priority?: Priority;
217
+ /**
218
+ * The retry policy of this activity.
219
+ *
220
+ * Note that the server may have set a different policy than the one provided when scheduling the activity.
221
+ * If the value is undefined, it means the server didn't send information about retry policy (e.g. due to old server
222
+ * version), but it may still be defined server-side.
223
+ */
224
+ readonly retryPolicy?: RetryPolicy;
214
225
  }
215
226
 
216
227
  /**
@@ -238,93 +249,82 @@ export class Context {
238
249
  }
239
250
 
240
251
  /**
241
- * Holds information about the current executing Activity.
242
- */
243
- public readonly info: Info;
244
-
245
- /**
246
- * A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
247
- * is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
248
- *
249
- * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
252
+ * **Not** meant to instantiated by Activity code, used by the worker.
250
253
  *
251
- * @see [Cancellation](/api/namespaces/activity#cancellation)
254
+ * @ignore
252
255
  */
253
- public readonly cancelled: Promise<never>;
256
+ constructor(
257
+ /**
258
+ * Holds information about the current executing Activity.
259
+ */
260
+ public readonly info: Info,
254
261
 
255
- /**
256
- * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
257
- * Activity cancellation.
258
- *
259
- * This can be passed in to libraries such as
260
- * {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
261
- * in-progress request and
262
- * {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
263
- * to abort a child process, as well as other built-in node modules and modules found on npm.
264
- *
265
- * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
266
- *
267
- * @see [Cancellation](/api/namespaces/activity#cancellation)
268
- */
269
- public readonly cancellationSignal: AbortSignal;
262
+ /**
263
+ * A Promise that fails with a {@link CancelledFailure} when cancellation of this activity is requested. The promise
264
+ * is guaranteed to never successfully resolve. Await this promise in an Activity to get notified of cancellation.
265
+ *
266
+ * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
267
+ *
268
+ * @see [Cancellation](/api/namespaces/activity#cancellation)
269
+ */
270
+ public readonly cancelled: Promise<never>,
270
271
 
271
- /**
272
- * The heartbeat implementation, injected via the constructor.
273
- */
274
- protected readonly heartbeatFn: (details?: any) => void;
272
+ /**
273
+ * An {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} that can be used to react to
274
+ * Activity cancellation.
275
+ *
276
+ * This can be passed in to libraries such as
277
+ * {@link https://www.npmjs.com/package/node-fetch#request-cancellation-with-abortsignal | fetch} to abort an
278
+ * in-progress request and
279
+ * {@link https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options child_process}
280
+ * to abort a child process, as well as other built-in node modules and modules found on npm.
281
+ *
282
+ * Note that to get notified of cancellation, an activity must _also_ {@link Context.heartbeat}.
283
+ *
284
+ * @see [Cancellation](/api/namespaces/activity#cancellation)
285
+ */
286
+ public readonly cancellationSignal: AbortSignal,
275
287
 
276
- /**
277
- * The logger for this Activity.
278
- *
279
- * This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
280
- * are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
281
- * added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
282
- *
283
- * To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
284
- * `getLogAttributes()` method.
285
- *
286
- * Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
287
- * with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
288
- * through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
289
- * {@link Runtime.logger} property instead.
290
- */
291
- public log: Logger;
288
+ /**
289
+ * The heartbeat implementation, injected via the constructor.
290
+ */
291
+ protected readonly heartbeatFn: (details?: any) => void,
292
292
 
293
- /**
294
- * Get the metric meter for this activity with activity-specific tags.
295
- *
296
- * To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
297
- * intercepts the `getMetricTags()` method.
298
- */
299
- public readonly metricMeter: MetricMeter;
293
+ /**
294
+ * The Worker's client, passed down through Activity context.
295
+ */
296
+ protected readonly _client: Client | undefined,
300
297
 
301
- /**
302
- * Holder object for activity cancellation details
303
- */
304
- private readonly _cancellationDetails: ActivityCancellationDetailsHolder;
298
+ /**
299
+ * The logger for this Activity.
300
+ *
301
+ * This defaults to the `Runtime`'s Logger (see {@link Runtime.logger}). Attributes from the current Activity context
302
+ * are automatically included as metadata on every log entries. An extra `sdkComponent` metadata attribute is also
303
+ * added, with value `activity`; this can be used for fine-grained filtering of log entries further downstream.
304
+ *
305
+ * To customize log attributes, register a {@link ActivityOutboundCallsInterceptor} that intercepts the
306
+ * `getLogAttributes()` method.
307
+ *
308
+ * Modifying the context logger (eg. `context.log = myCustomLogger` or by an {@link ActivityInboundLogInterceptor}
309
+ * with a custom logger as argument) is deprecated. Doing so will prevent automatic inclusion of custom log attributes
310
+ * through the `getLogAttributes()` interceptor. To customize _where_ log messages are sent, set the
311
+ * {@link Runtime.logger} property instead.
312
+ */
313
+ public log: Logger,
305
314
 
306
- /**
307
- * **Not** meant to instantiated by Activity code, used by the worker.
308
- *
309
- * @ignore
310
- */
311
- constructor(
312
- info: Info,
313
- cancelled: Promise<never>,
314
- cancellationSignal: AbortSignal,
315
- heartbeat: (details?: any) => void,
316
- log: Logger,
317
- metricMeter: MetricMeter,
318
- details: ActivityCancellationDetailsHolder
319
- ) {
320
- this.info = info;
321
- this.cancelled = cancelled;
322
- this.cancellationSignal = cancellationSignal;
323
- this.heartbeatFn = heartbeat;
324
- this.log = log;
325
- this.metricMeter = metricMeter;
326
- this._cancellationDetails = details;
327
- }
315
+ /**
316
+ * Get the metric meter for this activity with activity-specific tags.
317
+ *
318
+ * To add custom tags, register a {@link ActivityOutboundCallsInterceptor} that
319
+ * intercepts the `getMetricTags()` method.
320
+ */
321
+ public readonly metricMeter: MetricMeter,
322
+
323
+ /**
324
+ * Holder object for activity cancellation details
325
+ */
326
+ protected readonly _cancellationDetails: ActivityCancellationDetailsHolder
327
+ ) {}
328
328
 
329
329
  /**
330
330
  * Send a {@link https://docs.temporal.io/concepts/what-is-an-activity-heartbeat | heartbeat} from an Activity.
@@ -351,6 +351,25 @@ export class Context {
351
351
  this.heartbeatFn(details);
352
352
  };
353
353
 
354
+ /**
355
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
356
+ *
357
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
358
+ * that was created without a Client.
359
+ *
360
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
361
+ * incomplete or different from what would be observed using a {@link Connection}
362
+ * instead. Client doesn't support cancellation through a Signal.
363
+ */
364
+ public get client(): Client {
365
+ if (this._client === undefined) {
366
+ throw new IllegalStateError(
367
+ 'No Client available. This may be a MockActivityEnvironment that was created without a Client.'
368
+ );
369
+ }
370
+ return this._client;
371
+ }
372
+
354
373
  /**
355
374
  * Helper function for sleeping in an Activity.
356
375
  * @param ms Sleep duration: number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
@@ -481,6 +500,22 @@ export function cancellationSignal(): AbortSignal {
481
500
  return Context.current().cancellationSignal;
482
501
  }
483
502
 
503
+ /**
504
+ * A Temporal Client, bound to the same Temporal Namespace as the Worker executing this Activity.
505
+ *
506
+ * May throw an {@link IllegalStateError} if the Activity is running inside a `MockActivityEnvironment`
507
+ * that was created without a Client.
508
+ *
509
+ * This is a shortcut for `Context.current().client` (see {@link Context.client}).
510
+ *
511
+ * @experimental Client support over `NativeConnection` is experimental. Error handling may be
512
+ * incomplete or different from what would be observed using a {@link Connection}
513
+ * instead. Client doesn't support cancellation through a Signal.
514
+ */
515
+ export function getClient(): Client {
516
+ return Context.current().client;
517
+ }
518
+
484
519
  /**
485
520
  * Get the metric meter for the current activity, with activity-specific tags.
486
521
  *