@temporalio/activity 1.0.0-rc.1 → 1.1.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/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Temporal TypeScript SDK
2
2
 
3
3
  MIT License
4
4
 
5
- Copyright (c) 2021 Temporal Technologies, Inc. All Rights Reserved
5
+ Copyright (c) 2021 Temporal Technologies Inc. All Rights Reserved
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining a copy
8
8
  of this software and associated documentation files (the "Software"), to deal
package/lib/index.d.ts CHANGED
@@ -15,15 +15,19 @@
15
15
  *
16
16
  * ### Cancellation
17
17
  *
18
- * Activities may be cancelled only if they {@link Context.heartbeat | emit heartbeats}.
18
+ * Activity Cancellation serves three purposes:
19
+ *
20
+ * - It lets an Activity know it doesn't need to keep doing work.
21
+ * - It gives the Activity time to clean up any resources it has created.
22
+ *
23
+ * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
24
+ * (which can't heartbeat but receive Cancellation anyway).
19
25
  *
20
26
  * There are two ways to handle Activity cancellation:
21
27
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
22
- * {@link Context.sleep | `Context.current().sleep()`}, which each throw a
23
- * {@link CancelledFailure}.
28
+ * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
24
29
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
25
- * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
26
- * supports it.
30
+ * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
27
31
  *
28
32
  * ### Examples
29
33
  *
@@ -45,10 +49,9 @@
45
49
  /// <reference types="node" />
46
50
  import { AbortSignal } from 'abort-controller';
47
51
  import { AsyncLocalStorage } from 'async_hooks';
48
- export { CancelledFailure } from '@temporalio/common';
52
+ export { CancelledFailure, ApplicationFailure } from '@temporalio/common';
49
53
  export { ActivityFunction, ActivityInterface, // eslint-disable-line deprecation/deprecation
50
- UntypedActivities, } from '@temporalio/internal-workflow-common';
51
- export * from '@temporalio/internal-workflow-common/lib/errors';
54
+ UntypedActivities, errorMessage, errorCode, } from '@temporalio/internal-workflow-common';
52
55
  /**
53
56
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
54
57
  *
@@ -134,12 +137,15 @@ export interface Info {
134
137
  */
135
138
  heartbeatTimeoutMs?: number;
136
139
  /**
137
- * Hold the details supplied to the last heartbeat on previous attempts of this Activity.
138
- * Use this in order to resume your Activity from checkpoint.
140
+ * The {@link Context.heartbeat | details} from the last recorded heartbeat from the last attempt of this Activity.
141
+ *
142
+ * Use this to resume your Activity from a checkpoint.
139
143
  */
140
144
  heartbeatDetails: any;
141
145
  /**
142
- * Task queue the Activity is scheduled in, set to the Workflow's task queue in case of local Activity.
146
+ * Task Queue the Activity is scheduled in.
147
+ *
148
+ * For Local Activities, this is set to the Workflow's Task Queue.
143
149
  */
144
150
  taskQueue: string;
145
151
  }
@@ -199,7 +205,9 @@ export declare class Context {
199
205
  * attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
200
206
  * {@link TimeoutFailure.lastHeartbeatDetails}.
201
207
  *
202
- * Activities must heartbeat in order to receive cancellation.
208
+ * Calling `heartbeat()` from a Local Activity has no effect.
209
+ *
210
+ * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
203
211
  */
204
212
  heartbeat(details?: unknown): void;
205
213
  /**
package/lib/index.js CHANGED
@@ -16,15 +16,19 @@
16
16
  *
17
17
  * ### Cancellation
18
18
  *
19
- * Activities may be cancelled only if they {@link Context.heartbeat | emit heartbeats}.
19
+ * Activity Cancellation serves three purposes:
20
+ *
21
+ * - It lets an Activity know it doesn't need to keep doing work.
22
+ * - It gives the Activity time to clean up any resources it has created.
23
+ *
24
+ * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
25
+ * (which can't heartbeat but receive Cancellation anyway).
20
26
  *
21
27
  * There are two ways to handle Activity cancellation:
22
28
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
23
- * {@link Context.sleep | `Context.current().sleep()`}, which each throw a
24
- * {@link CancelledFailure}.
29
+ * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
25
30
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
26
- * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
27
- * supports it.
31
+ * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
28
32
  *
29
33
  * ### Examples
30
34
  *
@@ -43,27 +47,16 @@
43
47
  *
44
48
  * @module
45
49
  */
46
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
47
- if (k2 === undefined) k2 = k;
48
- var desc = Object.getOwnPropertyDescriptor(m, k);
49
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
50
- desc = { enumerable: true, get: function() { return m[k]; } };
51
- }
52
- Object.defineProperty(o, k2, desc);
53
- }) : (function(o, m, k, k2) {
54
- if (k2 === undefined) k2 = k;
55
- o[k2] = m[k];
56
- }));
57
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
58
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
59
- };
60
50
  Object.defineProperty(exports, "__esModule", { value: true });
61
- exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.CancelledFailure = void 0;
51
+ exports.Context = exports.asyncLocalStorage = exports.CompleteAsyncError = exports.errorCode = exports.errorMessage = exports.ApplicationFailure = exports.CancelledFailure = void 0;
62
52
  const internal_workflow_common_1 = require("@temporalio/internal-workflow-common");
63
53
  const async_hooks_1 = require("async_hooks");
64
54
  var common_1 = require("@temporalio/common");
65
55
  Object.defineProperty(exports, "CancelledFailure", { enumerable: true, get: function () { return common_1.CancelledFailure; } });
66
- __exportStar(require("@temporalio/internal-workflow-common/lib/errors"), exports);
56
+ Object.defineProperty(exports, "ApplicationFailure", { enumerable: true, get: function () { return common_1.ApplicationFailure; } });
57
+ var internal_workflow_common_2 = require("@temporalio/internal-workflow-common");
58
+ Object.defineProperty(exports, "errorMessage", { enumerable: true, get: function () { return internal_workflow_common_2.errorMessage; } });
59
+ Object.defineProperty(exports, "errorCode", { enumerable: true, get: function () { return internal_workflow_common_2.errorCode; } });
67
60
  /**
68
61
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
69
62
  *
@@ -123,7 +116,9 @@ class Context {
123
116
  * attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
124
117
  * {@link TimeoutFailure.lastHeartbeatDetails}.
125
118
  *
126
- * Activities must heartbeat in order to receive cancellation.
119
+ * Calling `heartbeat()` from a Local Activity has no effect.
120
+ *
121
+ * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
127
122
  */
128
123
  heartbeat(details) {
129
124
  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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;;;;;;;;;;;;;;;;;AAEH,mFAAkE;AAElE,6CAAgD;AAChD,6CAAsD;AAA7C,0GAAA,gBAAgB,OAAA;AAMzB,kFAAgE;AAEhE;;;;;;;;;;;;;;;;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,+BAAiB,EAAW,CAAC;AA2ElE;;;;;;;;;GASG;AACH,MAAa,OAAO;IA8BlB;;;;OAIG;IACH,YACE,IAAU,EACV,SAAyB,EACzB,kBAA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AAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;IACnF,CAAC;CACF;AA3FD,0BA2FC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/activity",
3
- "version": "1.0.0-rc.1",
3
+ "version": "1.1.0",
4
4
  "description": "Temporal.io SDK Activity sub-package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -10,11 +10,11 @@
10
10
  "worker",
11
11
  "activity"
12
12
  ],
13
- "author": "Roey Berman <roey@temporal.io>",
13
+ "author": "Temporal Technologies Inc. <sdk@temporal.io>",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@temporalio/common": "^1.0.0-rc.1",
17
- "@temporalio/internal-workflow-common": "^1.0.0-rc.1",
16
+ "@temporalio/common": "^1.1.0",
17
+ "@temporalio/internal-workflow-common": "^1.1.0",
18
18
  "abort-controller": "^3.0.0"
19
19
  },
20
20
  "bugs": {
@@ -28,5 +28,5 @@
28
28
  "src",
29
29
  "lib"
30
30
  ],
31
- "gitHead": "723de0fbc7a04e68084ec99453578e7027eb3803"
31
+ "gitHead": "132f23a47a93fecf3f39836b31f08ea837b30320"
32
32
  }
package/src/index.ts CHANGED
@@ -15,15 +15,19 @@
15
15
  *
16
16
  * ### Cancellation
17
17
  *
18
- * Activities may be cancelled only if they {@link Context.heartbeat | emit heartbeats}.
18
+ * Activity Cancellation serves three purposes:
19
+ *
20
+ * - It lets an Activity know it doesn't need to keep doing work.
21
+ * - It gives the Activity time to clean up any resources it has created.
22
+ *
23
+ * Activities may receive Cancellation only if they {@link Context.heartbeat | emit heartbeats} or are Local Activities
24
+ * (which can't heartbeat but receive Cancellation anyway).
19
25
  *
20
26
  * There are two ways to handle Activity cancellation:
21
27
  * 1. await on {@link Context.cancelled | `Context.current().cancelled`} or
22
- * {@link Context.sleep | `Context.current().sleep()`}, which each throw a
23
- * {@link CancelledFailure}.
28
+ * {@link Context.sleep | `Context.current().sleep()`}, which each throw a {@link CancelledFailure}.
24
29
  * 1. Pass the context's {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal | `AbortSignal`} at
25
- * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that
26
- * supports it.
30
+ * {@link Context.cancellationSignal | `Context.current().cancellationSignal`} to a library that supports it.
27
31
  *
28
32
  * ### Examples
29
33
  *
@@ -46,13 +50,14 @@
46
50
  import { msToNumber } from '@temporalio/internal-workflow-common';
47
51
  import { AbortSignal } from 'abort-controller';
48
52
  import { AsyncLocalStorage } from 'async_hooks';
49
- export { CancelledFailure } from '@temporalio/common';
53
+ export { CancelledFailure, ApplicationFailure } from '@temporalio/common';
50
54
  export {
51
55
  ActivityFunction,
52
56
  ActivityInterface, // eslint-disable-line deprecation/deprecation
53
57
  UntypedActivities,
58
+ errorMessage,
59
+ errorCode,
54
60
  } from '@temporalio/internal-workflow-common';
55
- export * from '@temporalio/internal-workflow-common/lib/errors';
56
61
 
57
62
  /**
58
63
  * Throw this error from an Activity in order to make the Worker forget about this Activity.
@@ -144,13 +149,16 @@ export interface Info {
144
149
  */
145
150
  heartbeatTimeoutMs?: number;
146
151
  /**
147
- * Hold the details supplied to the last heartbeat on previous attempts of this Activity.
148
- * Use this in order to resume your Activity from checkpoint.
152
+ * The {@link Context.heartbeat | details} from the last recorded heartbeat from the last attempt of this Activity.
153
+ *
154
+ * Use this to resume your Activity from a checkpoint.
149
155
  */
150
156
  heartbeatDetails: any;
151
157
 
152
158
  /**
153
- * Task queue the Activity is scheduled in, set to the Workflow's task queue in case of local Activity.
159
+ * Task Queue the Activity is scheduled in.
160
+ *
161
+ * For Local Activities, this is set to the Workflow's Task Queue.
154
162
  */
155
163
  taskQueue: string;
156
164
  }
@@ -223,7 +231,9 @@ export class Context {
223
231
  * attribute set to a {@link TimeoutFailure}, which has the last value of `details` available at
224
232
  * {@link TimeoutFailure.lastHeartbeatDetails}.
225
233
  *
226
- * Activities must heartbeat in order to receive cancellation.
234
+ * Calling `heartbeat()` from a Local Activity has no effect.
235
+ *
236
+ * Activities must heartbeat in order to receive Cancellation (unless they're Local Activities, which don't need to).
227
237
  */
228
238
  public heartbeat(details?: unknown): void {
229
239
  this.heartbeatFn(details);