@temporalio/client 1.0.0-rc.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.
@@ -2,15 +2,15 @@ import { DataConverter, LoadedDataConverter } from '@temporalio/common';
2
2
  import { Replace } from '@temporalio/internal-workflow-common';
3
3
  import { ConnectionLike, WorkflowService } from './types';
4
4
  /**
5
- * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
6
- * an Activity which does not exist in the system.
5
+ * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat an Activity that does not exist in the
6
+ * system.
7
7
  */
8
8
  export declare class ActivityNotFoundError extends Error {
9
9
  readonly name = "ActivityNotFoundError";
10
10
  }
11
11
  /**
12
12
  * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
13
- * an Activity for any reason apart from "not found".
13
+ * an Activity for any reason apart from {@link ActivityNotFoundError}.
14
14
  */
15
15
  export declare class ActivityCompletionError extends Error {
16
16
  readonly name = "ActivityCompletionError";
@@ -11,8 +11,8 @@ const os_1 = __importDefault(require("os"));
11
11
  const connection_1 = require("./connection");
12
12
  const errors_1 = require("./errors");
13
13
  /**
14
- * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
15
- * an Activity which does not exist in the system.
14
+ * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat an Activity that does not exist in the
15
+ * system.
16
16
  */
17
17
  class ActivityNotFoundError extends Error {
18
18
  constructor() {
@@ -23,7 +23,7 @@ class ActivityNotFoundError extends Error {
23
23
  exports.ActivityNotFoundError = ActivityNotFoundError;
24
24
  /**
25
25
  * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
26
- * an Activity for any reason apart from "not found".
26
+ * an Activity for any reason apart from {@link ActivityNotFoundError}.
27
27
  */
28
28
  class ActivityCompletionError extends Error {
29
29
  constructor() {
@@ -5,7 +5,7 @@ import { AsyncLocalStorage } from 'async_hooks';
5
5
  import type { RPCImpl } from 'protobufjs';
6
6
  import { CallContext, Metadata, OperatorService, WorkflowService } from './types';
7
7
  /**
8
- * GRPC + Temporal server connection options
8
+ * gRPC and Temporal Server connection options
9
9
  */
10
10
  export interface ConnectionOptions {
11
11
  /**
@@ -83,12 +83,15 @@ export interface ConnectionCtorOptions {
83
83
  readonly callContextStorage: AsyncLocalStorage<CallContext>;
84
84
  }
85
85
  /**
86
- * Client connection to the Temporal Service
86
+ * Client connection to the Temporal Server
87
87
  *
88
- * NOTE: Connections are expensive to construct and should be reused.
89
- * Make sure to `close()` any unused connections to avoid leaking resources.
88
+ * ⚠️ Connections are expensive to construct and should be reused. Make sure to {@link close} any unused connections to
89
+ * avoid leaking resources.
90
90
  */
91
91
  export declare class Connection {
92
+ /**
93
+ * @internal
94
+ */
92
95
  static readonly Client: grpc.ServiceClientConstructor;
93
96
  readonly options: ConnectionOptionsWithDefaults;
94
97
  protected readonly client: grpc.Client;
@@ -97,56 +100,65 @@ export declare class Connection {
97
100
  */
98
101
  protected connectPromise?: Promise<void>;
99
102
  /**
100
- * Raw gRPC access to the Temporal service.
103
+ * Raw gRPC access to Temporal Server's {@link
104
+ * https://github.com/temporalio/api/blob/master/temporal/api/workflowservice/v1/service.proto | Workflow service}
101
105
  */
102
106
  readonly workflowService: WorkflowService;
107
+ /**
108
+ * Raw gRPC access to Temporal Server's
109
+ * {@link https://github.com/temporalio/api/blob/master/temporal/api/operatorservice/v1/service.proto | Operator service}
110
+ */
103
111
  readonly operatorService: OperatorService;
104
112
  readonly callContextStorage: AsyncLocalStorage<CallContext>;
105
113
  protected static createCtorOptions(options?: ConnectionOptions): ConnectionCtorOptions;
106
114
  /**
107
115
  * Ensure connection can be established.
108
116
  *
117
+ * Does not need to be called if you use {@link connect}.
118
+ *
109
119
  * This method's result is memoized to ensure it runs only once.
110
120
  *
111
- * Calls WorkflowService.getSystemInfo internally.
121
+ * Calls {@link proto.temporal.api.workflowservice.v1.WorkflowService.getSystemInfo} internally.
112
122
  */
113
123
  ensureConnected(): Promise<void>;
114
124
  /**
115
- * Create a lazy Connection instance.
125
+ * Create a lazy `Connection` instance.
116
126
  *
117
- * This method does not verify connectivity with the server, it is recommended to use
118
- * {@link connect} instead.
127
+ * This method does not verify connectivity with the server. We recommend using {@link connect} instead.
119
128
  */
120
129
  static lazy(options?: ConnectionOptions): Connection;
121
130
  /**
122
- * Establish a connection with the server and return a Connection instance.
131
+ * Establish a connection with the server and return a `Connection` instance.
123
132
  *
124
- * This is the preferred method of creating connections as it verifies connectivity.
133
+ * This is the preferred method of creating connections as it verifies connectivity by calling
134
+ * {@link ensureConnected}.
125
135
  */
126
136
  static connect(options?: ConnectionOptions): Promise<Connection>;
127
137
  protected constructor({ options, client, workflowService, operatorService, callContextStorage, }: ConnectionCtorOptions);
128
138
  protected static generateRPCImplementation({ serviceName, client, callContextStorage, interceptors, }: RPCImplOptions): RPCImpl;
129
139
  /**
130
140
  * Set the deadline for any service requests executed in `fn`'s scope.
141
+ *
142
+ * @returns value returned from `fn`
131
143
  */
132
- withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
144
+ withDeadline<ReturnType>(deadline: number | Date, fn: () => Promise<ReturnType>): Promise<ReturnType>;
133
145
  /**
134
146
  * Set metadata for any service requests executed in `fn`'s scope.
135
147
  *
136
- * The provided metadata is merged on top of any existing metadata in current scope
137
- * including metadata provided in {@link ConnectionOptions.metadata}
148
+ * The provided metadata is merged on top of any existing metadata in current scope, including metadata provided in
149
+ * {@link ConnectionOptions.metadata}.
138
150
  *
139
- * @returns returned value of `fn`
151
+ * @returns value returned from `fn`
140
152
  *
141
153
  * @example
142
154
  *
143
- * ```ts
144
- * await conn.withMetadata({ apiKey: 'secret' }, () =>
145
- * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
146
- * );
147
- * ```
155
+ *```ts
156
+ *const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
157
+ * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
158
+ *);
159
+ *```
148
160
  */
149
- withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
161
+ withMetadata<ReturnType>(metadata: Metadata, fn: () => Promise<ReturnType>): Promise<ReturnType>;
150
162
  /**
151
163
  * Wait for successful connection to the server.
152
164
  *
package/lib/connection.js CHANGED
@@ -83,10 +83,10 @@ function normalizeGRPCConfig(options) {
83
83
  }
84
84
  }
85
85
  /**
86
- * Client connection to the Temporal Service
86
+ * Client connection to the Temporal Server
87
87
  *
88
- * NOTE: Connections are expensive to construct and should be reused.
89
- * Make sure to `close()` any unused connections to avoid leaking resources.
88
+ * ⚠️ Connections are expensive to construct and should be reused. Make sure to {@link close} any unused connections to
89
+ * avoid leaking resources.
90
90
  */
91
91
  class Connection {
92
92
  constructor({ options, client, workflowService, operatorService, callContextStorage, }) {
@@ -133,9 +133,11 @@ class Connection {
133
133
  /**
134
134
  * Ensure connection can be established.
135
135
  *
136
+ * Does not need to be called if you use {@link connect}.
137
+ *
136
138
  * This method's result is memoized to ensure it runs only once.
137
139
  *
138
- * Calls WorkflowService.getSystemInfo internally.
140
+ * Calls {@link proto.temporal.api.workflowservice.v1.WorkflowService.getSystemInfo} internally.
139
141
  */
140
142
  async ensureConnected() {
141
143
  if (this.connectPromise == null) {
@@ -161,18 +163,18 @@ class Connection {
161
163
  return this.connectPromise;
162
164
  }
163
165
  /**
164
- * Create a lazy Connection instance.
166
+ * Create a lazy `Connection` instance.
165
167
  *
166
- * This method does not verify connectivity with the server, it is recommended to use
167
- * {@link connect} instead.
168
+ * This method does not verify connectivity with the server. We recommend using {@link connect} instead.
168
169
  */
169
170
  static lazy(options) {
170
171
  return new this(this.createCtorOptions(options));
171
172
  }
172
173
  /**
173
- * Establish a connection with the server and return a Connection instance.
174
+ * Establish a connection with the server and return a `Connection` instance.
174
175
  *
175
- * This is the preferred method of creating connections as it verifies connectivity.
176
+ * This is the preferred method of creating connections as it verifies connectivity by calling
177
+ * {@link ensureConnected}.
176
178
  */
177
179
  static async connect(options) {
178
180
  const conn = this.lazy(options);
@@ -193,6 +195,8 @@ class Connection {
193
195
  }
194
196
  /**
195
197
  * Set the deadline for any service requests executed in `fn`'s scope.
198
+ *
199
+ * @returns value returned from `fn`
196
200
  */
197
201
  async withDeadline(deadline, fn) {
198
202
  const cc = this.callContextStorage.getStore();
@@ -201,18 +205,18 @@ class Connection {
201
205
  /**
202
206
  * Set metadata for any service requests executed in `fn`'s scope.
203
207
  *
204
- * The provided metadata is merged on top of any existing metadata in current scope
205
- * including metadata provided in {@link ConnectionOptions.metadata}
208
+ * The provided metadata is merged on top of any existing metadata in current scope, including metadata provided in
209
+ * {@link ConnectionOptions.metadata}.
206
210
  *
207
- * @returns returned value of `fn`
211
+ * @returns value returned from `fn`
208
212
  *
209
213
  * @example
210
214
  *
211
- * ```ts
212
- * await conn.withMetadata({ apiKey: 'secret' }, () =>
213
- * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
214
- * );
215
- * ```
215
+ *```ts
216
+ *const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
217
+ * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
218
+ *);
219
+ *```
216
220
  */
217
221
  async withMetadata(metadata, fn) {
218
222
  const cc = this.callContextStorage.getStore();
@@ -247,5 +251,8 @@ class Connection {
247
251
  }
248
252
  }
249
253
  exports.Connection = Connection;
254
+ /**
255
+ * @internal
256
+ */
250
257
  Connection.Client = grpc.makeGenericClientConstructor({}, 'WorkflowService', {});
251
258
  //# sourceMappingURL=connection.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AACtC,2FAAiH;AACjH,6CAAgD;AAEhD,qCAA+D;AAC/D,6CAAiF;AACjF,gDAAwB;AACxB,mCAAkF;AAoErE,QAAA,YAAY,GAAG,gBAAgB,CAAC;AAE7C,SAAgB,qBAAqB;IACnC,OAAO;QACL,OAAO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BACb;qBAAM;oBACL,OAAO,EAAE,CAAC;iBACX;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,+GAA+G;IAC/G;;;;OAIG;IACI,KAAK,CAAC,KAAK;QAChB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;;AA1NH,gCA2NC;AA1NC;;GAEG;AACoB,iBAAM,GAAG,IAAI,CAAC,4BAA4B,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
- * Client for communicating with the Temporal service.
2
+ * Client for communicating with Temporal Server.
3
3
  *
4
- * Interact with workflows using {@link WorkflowClient} or call GRPC methods directly using {@link Connection.workflowService}.
4
+ * Most functionality is available through {@link WorkflowClient}, but you can also call gRPC methods directly using {@link Connection.workflowService} and {@link Connection.operatorService}.
5
5
  *
6
6
  * ### Usage
7
7
  * <!--SNIPSTART typescript-hello-client-->
@@ -11,7 +11,9 @@
11
11
  export { ActivityFailure, ApplicationFailure, CancelledFailure, ChildWorkflowFailure, DataConverter, defaultPayloadConverter, ProtoFailure, ServerFailure, TemporalFailure, TerminatedFailure, TimeoutFailure, } from '@temporalio/common';
12
12
  export { TLSConfig } from '@temporalio/internal-non-workflow-common';
13
13
  export { RetryPolicy } from '@temporalio/internal-workflow-common';
14
+ export * from '@temporalio/internal-workflow-common/lib/errors';
14
15
  export * from '@temporalio/internal-workflow-common/lib/interfaces';
16
+ export * from '@temporalio/internal-workflow-common/lib/workflow-handle';
15
17
  export * from './async-completion-client';
16
18
  export { Connection, ConnectionOptions, ConnectionOptionsWithDefaults, LOCAL_TARGET } from './connection';
17
19
  export * from './errors';
package/lib/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /**
3
- * Client for communicating with the Temporal service.
3
+ * Client for communicating with Temporal Server.
4
4
  *
5
- * Interact with workflows using {@link WorkflowClient} or call GRPC methods directly using {@link Connection.workflowService}.
5
+ * Most functionality is available through {@link WorkflowClient}, but you can also call gRPC methods directly using {@link Connection.workflowService} and {@link Connection.operatorService}.
6
6
  *
7
7
  * ### Usage
8
8
  * <!--SNIPSTART typescript-hello-client-->
@@ -35,7 +35,9 @@ Object.defineProperty(exports, "ServerFailure", { enumerable: true, get: functio
35
35
  Object.defineProperty(exports, "TemporalFailure", { enumerable: true, get: function () { return common_1.TemporalFailure; } });
36
36
  Object.defineProperty(exports, "TerminatedFailure", { enumerable: true, get: function () { return common_1.TerminatedFailure; } });
37
37
  Object.defineProperty(exports, "TimeoutFailure", { enumerable: true, get: function () { return common_1.TimeoutFailure; } });
38
+ __exportStar(require("@temporalio/internal-workflow-common/lib/errors"), exports);
38
39
  __exportStar(require("@temporalio/internal-workflow-common/lib/interfaces"), exports);
40
+ __exportStar(require("@temporalio/internal-workflow-common/lib/workflow-handle"), exports);
39
41
  __exportStar(require("./async-completion-client"), exports);
40
42
  var connection_1 = require("./connection");
41
43
  Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } });
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;AAEH,6CAY4B;AAX1B,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AAEpB,iHAAA,uBAAuB,OAAA;AAEvB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAIhB,sFAAoE;AACpE,4DAA0C;AAC1C,2CAA0G;AAAjG,wGAAA,UAAU,OAAA;AAAoD,0GAAA,YAAY,OAAA;AACnF,2CAAyB;AACzB,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,oDAAkC;AAClC,qDAAmC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;;;;;;;;;;;;;;AAEH,6CAY4B;AAX1B,yGAAA,eAAe,OAAA;AACf,4GAAA,kBAAkB,OAAA;AAClB,0GAAA,gBAAgB,OAAA;AAChB,8GAAA,oBAAoB,OAAA;AAEpB,iHAAA,uBAAuB,OAAA;AAEvB,uGAAA,aAAa,OAAA;AACb,yGAAA,eAAe,OAAA;AACf,2GAAA,iBAAiB,OAAA;AACjB,wGAAA,cAAc,OAAA;AAIhB,kFAAgE;AAChE,sFAAoE;AACpE,2FAAyE;AACzE,4DAA0C;AAC1C,2CAA0G;AAAjG,wGAAA,UAAU,OAAA;AAAoD,0GAAA,YAAY,OAAA;AACnF,2CAAyB;AACzB,+CAA6B;AAC7B,iDAA+B;AAC/B,0CAAwB;AACxB,oDAAkC;AAClC,qDAAmC"}
@@ -290,9 +290,9 @@ export declare class WorkflowClient {
290
290
  * most recent Workflow Execution in the *Chain* that started with `firstExecutionRunId`.
291
291
  *
292
292
  * A *Chain* is a series of Workflow Executions that share the same Workflow ID and are connected by:
293
- * - Being part of the same [Cron](https://docs.temporal.io/typescript/clients#scheduling-cron-workflows)
294
- * - [Continue As New](https://docs.temporal.io/typescript/workflows#continueasnew)
295
- * - [Retries](https://typescript.temporal.io/api/interfaces/client.workflowoptions/#retry)
293
+ * - Being part of the same {@link https://docs.temporal.io/typescript/clients#scheduling-cron-workflows | Cron}
294
+ * - {@link https://docs.temporal.io/typescript/workflows#continueasnew | Continue As New}
295
+ * - {@link https://typescript.temporal.io/api/interfaces/client.workflowoptions/#retry | Retries}
296
296
  *
297
297
  * This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
298
298
  * methods like `handle.describe()` will throw a {@link WorkflowNotFoundError} error.
@@ -565,9 +565,9 @@ class WorkflowClient {
565
565
  * most recent Workflow Execution in the *Chain* that started with `firstExecutionRunId`.
566
566
  *
567
567
  * A *Chain* is a series of Workflow Executions that share the same Workflow ID and are connected by:
568
- * - Being part of the same [Cron](https://docs.temporal.io/typescript/clients#scheduling-cron-workflows)
569
- * - [Continue As New](https://docs.temporal.io/typescript/workflows#continueasnew)
570
- * - [Retries](https://typescript.temporal.io/api/interfaces/client.workflowoptions/#retry)
568
+ * - Being part of the same {@link https://docs.temporal.io/typescript/clients#scheduling-cron-workflows | Cron}
569
+ * - {@link https://docs.temporal.io/typescript/workflows#continueasnew | Continue As New}
570
+ * - {@link https://typescript.temporal.io/api/interfaces/client.workflowoptions/#retry | Retries}
571
571
  *
572
572
  * This method does not validate `workflowId`. If there is no Workflow Execution with the given `workflowId`, handle
573
573
  * methods like `handle.describe()` will throw a {@link WorkflowNotFoundError} error.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temporalio/client",
3
- "version": "1.0.0-rc.0",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "Temporal.io SDK Client sub-package",
5
5
  "main": "lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -13,24 +13,25 @@
13
13
  "author": "Roey Berman <roey@temporal.io>",
14
14
  "license": "MIT",
15
15
  "dependencies": {
16
- "@grpc/grpc-js": "^1.5.7",
17
- "@temporalio/common": "^1.0.0-rc.0",
18
- "@temporalio/internal-non-workflow-common": "^1.0.0-rc.0",
19
- "@temporalio/internal-workflow-common": "^1.0.0-rc.0",
20
- "@temporalio/proto": "^1.0.0-rc.0",
16
+ "@grpc/grpc-js": "^1.6.7",
17
+ "@temporalio/common": "^1.0.0-rc.1",
18
+ "@temporalio/internal-non-workflow-common": "^1.0.0-rc.1",
19
+ "@temporalio/internal-workflow-common": "^1.0.0-rc.1",
20
+ "@temporalio/proto": "^1.0.0-rc.1",
21
21
  "ms": "^2.1.3",
22
- "protobufjs": "^6.11.2",
22
+ "protobufjs": "6.11.2",
23
23
  "uuid": "^8.3.2"
24
24
  },
25
25
  "bugs": {
26
26
  "url": "https://github.com/temporalio/sdk-typescript/issues"
27
27
  },
28
28
  "homepage": "https://github.com/temporalio/sdk-typescript/tree/main/packages/client",
29
- "files": [
30
- "lib"
31
- ],
32
29
  "publishConfig": {
33
30
  "access": "public"
34
31
  },
35
- "gitHead": "c25e91309b980f2118df4048d760306982019871"
32
+ "files": [
33
+ "src",
34
+ "lib"
35
+ ],
36
+ "gitHead": "723de0fbc7a04e68084ec99453578e7027eb3803"
36
37
  }
@@ -0,0 +1,256 @@
1
+ import { Status } from '@grpc/grpc-js/build/src/constants';
2
+ import { DataConverter, ensureTemporalFailure, LoadedDataConverter } from '@temporalio/common';
3
+ import {
4
+ encodeErrorToFailure,
5
+ encodeToPayloads,
6
+ filterNullAndUndefined,
7
+ loadDataConverter,
8
+ } from '@temporalio/internal-non-workflow-common';
9
+ import { Replace } from '@temporalio/internal-workflow-common';
10
+ import os from 'os';
11
+ import { Connection } from './connection';
12
+ import { isServerErrorResponse } from './errors';
13
+ import { ConnectionLike, WorkflowService } from './types';
14
+
15
+ /**
16
+ * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat an Activity that does not exist in the
17
+ * system.
18
+ */
19
+ export class ActivityNotFoundError extends Error {
20
+ public readonly name = 'ActivityNotFoundError';
21
+ }
22
+
23
+ /**
24
+ * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
25
+ * an Activity for any reason apart from {@link ActivityNotFoundError}.
26
+ */
27
+ export class ActivityCompletionError extends Error {
28
+ public readonly name = 'ActivityCompletionError';
29
+ }
30
+
31
+ /**
32
+ * Thrown by {@link AsyncCompletionClient.heartbeat} when the Workflow has
33
+ * requested to cancel the reporting Activity.
34
+ */
35
+ export class ActivityCancelledError extends Error {
36
+ public readonly name = 'ActivityCancelledError';
37
+ }
38
+
39
+ /**
40
+ * Options used to configure {@link AsyncCompletionClient}
41
+ */
42
+ export interface AsyncCompletionClientOptions {
43
+ /**
44
+ * {@link DataConverter} to use for serializing and deserializing payloads
45
+ */
46
+ dataConverter?: DataConverter;
47
+
48
+ /**
49
+ * Identity to report to the server
50
+ *
51
+ * @default `${process.pid}@${os.hostname()}`
52
+ */
53
+ identity?: string;
54
+
55
+ connection?: ConnectionLike;
56
+
57
+ /**
58
+ * Server namespace
59
+ *
60
+ * @default default
61
+ */
62
+ namespace?: string;
63
+ }
64
+
65
+ export type AsyncCompletionClientOptionsWithDefaults = Replace<
66
+ Required<AsyncCompletionClientOptions>,
67
+ {
68
+ connection?: ConnectionLike;
69
+ }
70
+ >;
71
+
72
+ export function defaultAsyncCompletionClientOptions(): AsyncCompletionClientOptionsWithDefaults {
73
+ return {
74
+ dataConverter: {},
75
+ identity: `${process.pid}@${os.hostname()}`,
76
+ namespace: 'default',
77
+ };
78
+ }
79
+
80
+ /**
81
+ * A mostly unique Activity identifier including its scheduling workflow's ID
82
+ * and an optional runId.
83
+ *
84
+ * Activity IDs may be reused in a single Workflow run as long as a previous
85
+ * Activity with the same ID has completed already.
86
+ */
87
+ export interface FullActivityId {
88
+ workflowId: string;
89
+ runId?: string;
90
+ activityId: string;
91
+ }
92
+
93
+ /**
94
+ * A client for asynchronous completion and heartbeating of Activities.
95
+ */
96
+ export class AsyncCompletionClient {
97
+ public readonly options: AsyncCompletionClientOptionsWithDefaults;
98
+ protected readonly dataConverter: LoadedDataConverter;
99
+ public readonly connection: ConnectionLike;
100
+
101
+ constructor(options?: AsyncCompletionClientOptions) {
102
+ this.connection = options?.connection ?? Connection.lazy();
103
+ this.dataConverter = loadDataConverter(options?.dataConverter);
104
+ this.options = { ...defaultAsyncCompletionClientOptions(), ...filterNullAndUndefined(options ?? {}) };
105
+ }
106
+
107
+ get workflowService(): WorkflowService {
108
+ return this.connection.workflowService;
109
+ }
110
+
111
+ /**
112
+ * Transforms grpc errors into well defined TS errors.
113
+ */
114
+ protected handleError(err: unknown): never {
115
+ if (isServerErrorResponse(err)) {
116
+ if (err.code === Status.NOT_FOUND) {
117
+ throw new ActivityNotFoundError('Not found');
118
+ }
119
+ throw new ActivityCompletionError(err.details || err.message);
120
+ }
121
+ throw new ActivityCompletionError('Unexpected failure');
122
+ }
123
+
124
+ /**
125
+ * Complete an Activity by task token
126
+ */
127
+ async complete(taskToken: Uint8Array, result: unknown): Promise<void>;
128
+ /**
129
+ * Complete an Activity by full ID
130
+ */
131
+ async complete(fullActivityId: FullActivityId, result: unknown): Promise<void>;
132
+
133
+ async complete(taskTokenOrFullActivityId: Uint8Array | FullActivityId, result: unknown): Promise<void> {
134
+ try {
135
+ if (taskTokenOrFullActivityId instanceof Uint8Array) {
136
+ await this.workflowService.respondActivityTaskCompleted({
137
+ identity: this.options.identity,
138
+ namespace: this.options.namespace,
139
+ taskToken: taskTokenOrFullActivityId,
140
+ result: { payloads: await encodeToPayloads(this.dataConverter, result) },
141
+ });
142
+ } else {
143
+ await this.workflowService.respondActivityTaskCompletedById({
144
+ identity: this.options.identity,
145
+ namespace: this.options.namespace,
146
+ ...taskTokenOrFullActivityId,
147
+ result: { payloads: await encodeToPayloads(this.dataConverter, result) },
148
+ });
149
+ }
150
+ } catch (err) {
151
+ this.handleError(err);
152
+ }
153
+ }
154
+
155
+ /**
156
+ * Fail an Activity by task token
157
+ */
158
+ async fail(taskToken: Uint8Array, err: unknown): Promise<void>;
159
+ /**
160
+ * Fail an Activity by full ID
161
+ */
162
+ async fail(fullActivityId: FullActivityId, err: unknown): Promise<void>;
163
+
164
+ async fail(taskTokenOrFullActivityId: Uint8Array | FullActivityId, err: unknown): Promise<void> {
165
+ try {
166
+ if (taskTokenOrFullActivityId instanceof Uint8Array) {
167
+ await this.workflowService.respondActivityTaskFailed({
168
+ identity: this.options.identity,
169
+ namespace: this.options.namespace,
170
+ taskToken: taskTokenOrFullActivityId,
171
+ failure: await encodeErrorToFailure(this.dataConverter, ensureTemporalFailure(err)),
172
+ });
173
+ } else {
174
+ await this.workflowService.respondActivityTaskFailedById({
175
+ identity: this.options.identity,
176
+ namespace: this.options.namespace,
177
+ ...taskTokenOrFullActivityId,
178
+ failure: await encodeErrorToFailure(this.dataConverter, err),
179
+ });
180
+ }
181
+ } catch (err) {
182
+ this.handleError(err);
183
+ }
184
+ }
185
+
186
+ /**
187
+ * Report Activity cancellation by task token
188
+ */
189
+ reportCancellation(taskToken: Uint8Array, details?: unknown): Promise<void>;
190
+ /**
191
+ * Report Activity cancellation by full ID
192
+ */
193
+ reportCancellation(fullActivityId: FullActivityId, details?: unknown): Promise<void>;
194
+
195
+ async reportCancellation(taskTokenOrFullActivityId: Uint8Array | FullActivityId, details?: unknown): Promise<void> {
196
+ try {
197
+ if (taskTokenOrFullActivityId instanceof Uint8Array) {
198
+ await this.workflowService.respondActivityTaskCanceled({
199
+ identity: this.options.identity,
200
+ namespace: this.options.namespace,
201
+ taskToken: taskTokenOrFullActivityId,
202
+ details: { payloads: await encodeToPayloads(this.dataConverter, details) },
203
+ });
204
+ } else {
205
+ await this.workflowService.respondActivityTaskCanceledById({
206
+ identity: this.options.identity,
207
+ namespace: this.options.namespace,
208
+ ...taskTokenOrFullActivityId,
209
+ details: { payloads: await encodeToPayloads(this.dataConverter, details) },
210
+ });
211
+ }
212
+ } catch (err) {
213
+ this.handleError(err);
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Send Activity heartbeat by task token
219
+ */
220
+ heartbeat(taskToken: Uint8Array, details?: unknown): Promise<void>;
221
+ /**
222
+ * Send Activity heartbeat by full ID
223
+ */
224
+ heartbeat(fullActivityId: FullActivityId, details?: unknown): Promise<void>;
225
+
226
+ async heartbeat(taskTokenOrFullActivityId: Uint8Array | FullActivityId, details?: unknown): Promise<void> {
227
+ try {
228
+ if (taskTokenOrFullActivityId instanceof Uint8Array) {
229
+ const { cancelRequested } = await this.workflowService.recordActivityTaskHeartbeat({
230
+ identity: this.options.identity,
231
+ namespace: this.options.namespace,
232
+ taskToken: taskTokenOrFullActivityId,
233
+ details: { payloads: await encodeToPayloads(this.dataConverter, details) },
234
+ });
235
+ if (cancelRequested) {
236
+ throw new ActivityCancelledError('cancelled');
237
+ }
238
+ } else {
239
+ const { cancelRequested } = await this.workflowService.recordActivityTaskHeartbeatById({
240
+ identity: this.options.identity,
241
+ namespace: this.options.namespace,
242
+ ...taskTokenOrFullActivityId,
243
+ details: { payloads: await encodeToPayloads(this.dataConverter, details) },
244
+ });
245
+ if (cancelRequested) {
246
+ throw new ActivityCancelledError('cancelled');
247
+ }
248
+ }
249
+ } catch (err) {
250
+ if (err instanceof ActivityCancelledError) {
251
+ throw err;
252
+ }
253
+ this.handleError(err);
254
+ }
255
+ }
256
+ }