@temporalio/client 1.2.0 → 1.4.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/async-completion-client.d.ts +17 -5
- package/lib/async-completion-client.js +28 -11
- package/lib/async-completion-client.js.map +1 -1
- package/lib/client.d.ts +92 -0
- package/lib/client.js +77 -0
- package/lib/client.js.map +1 -0
- package/lib/connection.d.ts +12 -4
- package/lib/connection.js +13 -4
- package/lib/connection.js.map +1 -1
- package/lib/grpc-retry.d.ts +51 -8
- package/lib/grpc-retry.js +73 -46
- package/lib/grpc-retry.js.map +1 -1
- package/lib/index.d.ts +6 -6
- package/lib/index.js +4 -3
- package/lib/index.js.map +1 -1
- package/lib/interceptors.d.ts +10 -2
- package/lib/types.d.ts +16 -15
- package/lib/types.js +28 -4
- package/lib/types.js.map +1 -1
- package/lib/workflow-client.d.ts +26 -10
- package/lib/workflow-client.js +51 -45
- package/lib/workflow-client.js.map +1 -1
- package/lib/workflow-options.d.ts +16 -5
- package/lib/workflow-options.js +1 -27
- package/lib/workflow-options.js.map +1 -1
- package/package.json +7 -9
- package/src/async-completion-client.ts +30 -8
- package/src/client.ts +151 -0
- package/src/connection.ts +21 -3
- package/src/grpc-retry.ts +129 -56
- package/src/index.ts +6 -5
- package/src/interceptors.ts +11 -2
- package/src/types.ts +19 -15
- package/src/workflow-client.ts +65 -49
- package/src/workflow-options.ts +21 -35
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataConverter, LoadedDataConverter } from '@temporalio/common';
|
|
2
|
-
import { Replace } from '@temporalio/
|
|
2
|
+
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
3
3
|
import { ConnectionLike, WorkflowService } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat an Activity that does not exist in the
|
|
@@ -27,9 +27,9 @@ export declare class ActivityCancelledError extends Error {
|
|
|
27
27
|
*/
|
|
28
28
|
export interface AsyncCompletionClientOptions {
|
|
29
29
|
/**
|
|
30
|
-
* {@link DataConverter} to use for serializing and deserializing payloads
|
|
30
|
+
* {@link DataConverter} or {@link LoadedDataConverter} to use for serializing and deserializing payloads
|
|
31
31
|
*/
|
|
32
|
-
dataConverter?: DataConverter;
|
|
32
|
+
dataConverter?: DataConverter | LoadedDataConverter;
|
|
33
33
|
/**
|
|
34
34
|
* Identity to report to the server
|
|
35
35
|
*
|
|
@@ -47,6 +47,9 @@ export interface AsyncCompletionClientOptions {
|
|
|
47
47
|
export declare type AsyncCompletionClientOptionsWithDefaults = Replace<Required<AsyncCompletionClientOptions>, {
|
|
48
48
|
connection?: ConnectionLike;
|
|
49
49
|
}>;
|
|
50
|
+
export declare type LoadedAsyncCompletionClientOptions = AsyncCompletionClientOptionsWithDefaults & {
|
|
51
|
+
loadedDataConverter: LoadedDataConverter;
|
|
52
|
+
};
|
|
50
53
|
export declare function defaultAsyncCompletionClientOptions(): AsyncCompletionClientOptionsWithDefaults;
|
|
51
54
|
/**
|
|
52
55
|
* A mostly unique Activity identifier including its scheduling workflow's ID
|
|
@@ -62,13 +65,22 @@ export interface FullActivityId {
|
|
|
62
65
|
}
|
|
63
66
|
/**
|
|
64
67
|
* A client for asynchronous completion and heartbeating of Activities.
|
|
68
|
+
*
|
|
69
|
+
* Typically this client should not be instantiated directly, instead create the high level {@link Client} and use
|
|
70
|
+
* {@link Client.activity} to complete async activities.
|
|
65
71
|
*/
|
|
66
72
|
export declare class AsyncCompletionClient {
|
|
67
|
-
readonly options:
|
|
68
|
-
protected readonly dataConverter: LoadedDataConverter;
|
|
73
|
+
readonly options: LoadedAsyncCompletionClientOptions;
|
|
69
74
|
readonly connection: ConnectionLike;
|
|
70
75
|
constructor(options?: AsyncCompletionClientOptions);
|
|
76
|
+
/**
|
|
77
|
+
* Raw gRPC access to the Temporal service.
|
|
78
|
+
*
|
|
79
|
+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
|
|
80
|
+
* object.
|
|
81
|
+
*/
|
|
71
82
|
get workflowService(): WorkflowService;
|
|
83
|
+
protected get dataConverter(): LoadedDataConverter;
|
|
72
84
|
/**
|
|
73
85
|
* Transforms grpc errors into well defined TS errors.
|
|
74
86
|
*/
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.AsyncCompletionClient = exports.defaultAsyncCompletionClientOptions = exports.ActivityCancelledError = exports.ActivityCompletionError = exports.ActivityNotFoundError = void 0;
|
|
7
7
|
const constants_1 = require("@grpc/grpc-js/build/src/constants");
|
|
8
8
|
const common_1 = require("@temporalio/common");
|
|
9
|
-
const
|
|
9
|
+
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
|
|
10
10
|
const os_1 = __importDefault(require("os"));
|
|
11
11
|
const connection_1 = require("./connection");
|
|
12
12
|
const errors_1 = require("./errors");
|
|
@@ -53,16 +53,33 @@ function defaultAsyncCompletionClientOptions() {
|
|
|
53
53
|
exports.defaultAsyncCompletionClientOptions = defaultAsyncCompletionClientOptions;
|
|
54
54
|
/**
|
|
55
55
|
* A client for asynchronous completion and heartbeating of Activities.
|
|
56
|
+
*
|
|
57
|
+
* Typically this client should not be instantiated directly, instead create the high level {@link Client} and use
|
|
58
|
+
* {@link Client.activity} to complete async activities.
|
|
56
59
|
*/
|
|
57
60
|
class AsyncCompletionClient {
|
|
58
61
|
constructor(options) {
|
|
59
62
|
this.connection = options?.connection ?? connection_1.Connection.lazy();
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
const dataConverter = options?.dataConverter;
|
|
64
|
+
const loadedDataConverter = (0, internal_non_workflow_1.isLoadedDataConverter)(dataConverter) ? dataConverter : (0, internal_non_workflow_1.loadDataConverter)(dataConverter);
|
|
65
|
+
this.options = {
|
|
66
|
+
...defaultAsyncCompletionClientOptions(),
|
|
67
|
+
...(0, internal_non_workflow_1.filterNullAndUndefined)(options ?? {}),
|
|
68
|
+
loadedDataConverter,
|
|
69
|
+
};
|
|
62
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Raw gRPC access to the Temporal service.
|
|
73
|
+
*
|
|
74
|
+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
|
|
75
|
+
* object.
|
|
76
|
+
*/
|
|
63
77
|
get workflowService() {
|
|
64
78
|
return this.connection.workflowService;
|
|
65
79
|
}
|
|
80
|
+
get dataConverter() {
|
|
81
|
+
return this.options.loadedDataConverter;
|
|
82
|
+
}
|
|
66
83
|
/**
|
|
67
84
|
* Transforms grpc errors into well defined TS errors.
|
|
68
85
|
*/
|
|
@@ -82,7 +99,7 @@ class AsyncCompletionClient {
|
|
|
82
99
|
identity: this.options.identity,
|
|
83
100
|
namespace: this.options.namespace,
|
|
84
101
|
taskToken: taskTokenOrFullActivityId,
|
|
85
|
-
result: { payloads: await (0,
|
|
102
|
+
result: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, result) },
|
|
86
103
|
});
|
|
87
104
|
}
|
|
88
105
|
else {
|
|
@@ -90,7 +107,7 @@ class AsyncCompletionClient {
|
|
|
90
107
|
identity: this.options.identity,
|
|
91
108
|
namespace: this.options.namespace,
|
|
92
109
|
...taskTokenOrFullActivityId,
|
|
93
|
-
result: { payloads: await (0,
|
|
110
|
+
result: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, result) },
|
|
94
111
|
});
|
|
95
112
|
}
|
|
96
113
|
}
|
|
@@ -105,7 +122,7 @@ class AsyncCompletionClient {
|
|
|
105
122
|
identity: this.options.identity,
|
|
106
123
|
namespace: this.options.namespace,
|
|
107
124
|
taskToken: taskTokenOrFullActivityId,
|
|
108
|
-
failure: await (0,
|
|
125
|
+
failure: await (0, internal_non_workflow_1.encodeErrorToFailure)(this.dataConverter, (0, common_1.ensureTemporalFailure)(err)),
|
|
109
126
|
});
|
|
110
127
|
}
|
|
111
128
|
else {
|
|
@@ -113,7 +130,7 @@ class AsyncCompletionClient {
|
|
|
113
130
|
identity: this.options.identity,
|
|
114
131
|
namespace: this.options.namespace,
|
|
115
132
|
...taskTokenOrFullActivityId,
|
|
116
|
-
failure: await (0,
|
|
133
|
+
failure: await (0, internal_non_workflow_1.encodeErrorToFailure)(this.dataConverter, err),
|
|
117
134
|
});
|
|
118
135
|
}
|
|
119
136
|
}
|
|
@@ -128,7 +145,7 @@ class AsyncCompletionClient {
|
|
|
128
145
|
identity: this.options.identity,
|
|
129
146
|
namespace: this.options.namespace,
|
|
130
147
|
taskToken: taskTokenOrFullActivityId,
|
|
131
|
-
details: { payloads: await (0,
|
|
148
|
+
details: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, details) },
|
|
132
149
|
});
|
|
133
150
|
}
|
|
134
151
|
else {
|
|
@@ -136,7 +153,7 @@ class AsyncCompletionClient {
|
|
|
136
153
|
identity: this.options.identity,
|
|
137
154
|
namespace: this.options.namespace,
|
|
138
155
|
...taskTokenOrFullActivityId,
|
|
139
|
-
details: { payloads: await (0,
|
|
156
|
+
details: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, details) },
|
|
140
157
|
});
|
|
141
158
|
}
|
|
142
159
|
}
|
|
@@ -151,7 +168,7 @@ class AsyncCompletionClient {
|
|
|
151
168
|
identity: this.options.identity,
|
|
152
169
|
namespace: this.options.namespace,
|
|
153
170
|
taskToken: taskTokenOrFullActivityId,
|
|
154
|
-
details: { payloads: await (0,
|
|
171
|
+
details: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, details) },
|
|
155
172
|
});
|
|
156
173
|
if (cancelRequested) {
|
|
157
174
|
throw new ActivityCancelledError('cancelled');
|
|
@@ -162,7 +179,7 @@ class AsyncCompletionClient {
|
|
|
162
179
|
identity: this.options.identity,
|
|
163
180
|
namespace: this.options.namespace,
|
|
164
181
|
...taskTokenOrFullActivityId,
|
|
165
|
-
details: { payloads: await (0,
|
|
182
|
+
details: { payloads: await (0, internal_non_workflow_1.encodeToPayloads)(this.dataConverter, details) },
|
|
166
183
|
});
|
|
167
184
|
if (cancelRequested) {
|
|
168
185
|
throw new ActivityCancelledError('cancelled');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"async-completion-client.js","sourceRoot":"","sources":["../src/async-completion-client.ts"],"names":[],"mappings":";;;;;;AAAA,iEAA2D;AAC3D,+CAA+F;AAC/F,
|
|
1
|
+
{"version":3,"file":"async-completion-client.js","sourceRoot":"","sources":["../src/async-completion-client.ts"],"names":[],"mappings":";;;;;;AAAA,iEAA2D;AAC3D,+CAA+F;AAC/F,wFAMsD;AAEtD,4CAAoB;AACpB,6CAA0C;AAC1C,qCAAiD;AAGjD;;;GAGG;AACH,MAAa,qBAAsB,SAAQ,KAAK;IAAhD;;QACkB,SAAI,GAAG,uBAAuB,CAAC;IACjD,CAAC;CAAA;AAFD,sDAEC;AAED;;;GAGG;AACH,MAAa,uBAAwB,SAAQ,KAAK;IAAlD;;QACkB,SAAI,GAAG,yBAAyB,CAAC;IACnD,CAAC;CAAA;AAFD,0DAEC;AAED;;;GAGG;AACH,MAAa,sBAAuB,SAAQ,KAAK;IAAjD;;QACkB,SAAI,GAAG,wBAAwB,CAAC;IAClD,CAAC;CAAA;AAFD,wDAEC;AAuCD,SAAgB,mCAAmC;IACjD,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,IAAI,YAAE,CAAC,QAAQ,EAAE,EAAE;QAC3C,SAAS,EAAE,SAAS;KACrB,CAAC;AACJ,CAAC;AAND,kFAMC;AAeD;;;;;GAKG;AACH,MAAa,qBAAqB;IAIhC,YAAY,OAAsC;QAChD,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,uBAAU,CAAC,IAAI,EAAE,CAAC;QAC3D,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,CAAC;QAC7C,MAAM,mBAAmB,GAAG,IAAA,6CAAqB,EAAC,aAAa,CAAC,CAAC,CAAC,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sBAAsB,CAAC,WAAW,CAAC,CAAC;iBAC/C;aACF;iBAAM;gBACL,MAAM,EAAE,eAAe,EAAE,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,+BAA+B,CAAC;oBACrF,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;oBAC/B,SAAS,EAAE,IAAI,CAAC,OAAO,CAAC,SAAS;oBACjC,GAAG,yBAAyB;oBAC5B,OAAO,EAAE,EAAE,QAAQ,EAAE,MAAM,IAAA,wCAAgB,EAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,EAAE;iBAC3E,CAAC,CAAC;gBACH,IAAI,eAAe,EAAE;oBACnB,MAAM,IAAI,sBAAsB,CAAC,WAAW,CAAC,CAAC;iBAC/C;aACF;SACF;QAAC,OAAO,GAAG,EAAE;YACZ,IAAI,GAAG,YAAY,sBAAsB,EAAE;gBACzC,MAAM,GAAG,CAAC;aACX;YACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;SACvB;IACH,CAAC;CACF;AA9KD,sDA8KC"}
|
package/lib/client.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { DataConverter, LoadedDataConverter } from '@temporalio/common';
|
|
2
|
+
import { Replace } from '@temporalio/common/lib/type-helpers';
|
|
3
|
+
import { temporal } from '@temporalio/proto';
|
|
4
|
+
import { AsyncCompletionClient } from './async-completion-client';
|
|
5
|
+
import { ClientInterceptors } from './interceptors';
|
|
6
|
+
import { ConnectionLike, Metadata, WorkflowService } from './types';
|
|
7
|
+
import { WorkflowClient } from './workflow-client';
|
|
8
|
+
export interface ClientOptions {
|
|
9
|
+
/**
|
|
10
|
+
* {@link DataConverter} to use for serializing and deserializing payloads
|
|
11
|
+
*/
|
|
12
|
+
dataConverter?: DataConverter;
|
|
13
|
+
/**
|
|
14
|
+
* Used to override and extend default Connection functionality
|
|
15
|
+
*
|
|
16
|
+
* Useful for injecting auth headers and tracing Workflow executions
|
|
17
|
+
*/
|
|
18
|
+
interceptors?: ClientInterceptors;
|
|
19
|
+
/**
|
|
20
|
+
* Identity to report to the server
|
|
21
|
+
*
|
|
22
|
+
* @default `${process.pid}@${os.hostname()}`
|
|
23
|
+
*/
|
|
24
|
+
identity?: string;
|
|
25
|
+
/**
|
|
26
|
+
* Connection to use to communicate with the server.
|
|
27
|
+
*
|
|
28
|
+
* By default `WorkflowClient` connects to localhost.
|
|
29
|
+
*
|
|
30
|
+
* Connections are expensive to construct and should be reused.
|
|
31
|
+
*/
|
|
32
|
+
connection?: ConnectionLike;
|
|
33
|
+
/**
|
|
34
|
+
* Server namespace
|
|
35
|
+
*
|
|
36
|
+
* @default default
|
|
37
|
+
*/
|
|
38
|
+
namespace?: string;
|
|
39
|
+
workflow?: {
|
|
40
|
+
/**
|
|
41
|
+
* Should a query be rejected by closed and failed workflows
|
|
42
|
+
*
|
|
43
|
+
* @default QUERY_REJECT_CONDITION_UNSPECIFIED which means that closed and failed workflows are still queryable
|
|
44
|
+
*/
|
|
45
|
+
queryRejectCondition?: temporal.api.enums.v1.QueryRejectCondition;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export declare type ClientOptionsWithDefaults = Replace<Required<ClientOptions>, {
|
|
49
|
+
connection?: ConnectionLike;
|
|
50
|
+
}>;
|
|
51
|
+
export declare type LoadedClientOptions = ClientOptionsWithDefaults & {
|
|
52
|
+
loadedDataConverter: LoadedDataConverter;
|
|
53
|
+
};
|
|
54
|
+
export declare function defaultClientOptions(): ClientOptionsWithDefaults;
|
|
55
|
+
/**
|
|
56
|
+
* High level SDK client.
|
|
57
|
+
*/
|
|
58
|
+
export declare class Client {
|
|
59
|
+
/**
|
|
60
|
+
* Underlying gRPC connection to the Temporal service
|
|
61
|
+
*/
|
|
62
|
+
readonly connection: ConnectionLike;
|
|
63
|
+
readonly options: LoadedClientOptions;
|
|
64
|
+
/**
|
|
65
|
+
* Workflow sub-client - use to start and interact with Workflows
|
|
66
|
+
*/
|
|
67
|
+
readonly workflow: WorkflowClient;
|
|
68
|
+
/**
|
|
69
|
+
* (Async) Activity completion sub-client - use to manually manage Activities
|
|
70
|
+
*/
|
|
71
|
+
readonly activity: AsyncCompletionClient;
|
|
72
|
+
constructor(options?: ClientOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Raw gRPC access to the Temporal service.
|
|
75
|
+
*
|
|
76
|
+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
|
|
77
|
+
* object.
|
|
78
|
+
*/
|
|
79
|
+
get workflowService(): WorkflowService;
|
|
80
|
+
/**
|
|
81
|
+
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
82
|
+
*/
|
|
83
|
+
withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
|
|
84
|
+
/**
|
|
85
|
+
* Set metadata for any service requests executed in `fn`'s scope.
|
|
86
|
+
*
|
|
87
|
+
* @returns returned value of `fn`
|
|
88
|
+
*
|
|
89
|
+
* @see {@link Connection.withMetadata}
|
|
90
|
+
*/
|
|
91
|
+
withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
|
|
92
|
+
}
|
package/lib/client.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Client = exports.defaultClientOptions = void 0;
|
|
7
|
+
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
|
|
8
|
+
const proto_1 = require("@temporalio/proto");
|
|
9
|
+
const os_1 = __importDefault(require("os"));
|
|
10
|
+
const async_completion_client_1 = require("./async-completion-client");
|
|
11
|
+
const connection_1 = require("./connection");
|
|
12
|
+
const workflow_client_1 = require("./workflow-client");
|
|
13
|
+
function defaultClientOptions() {
|
|
14
|
+
return {
|
|
15
|
+
dataConverter: {},
|
|
16
|
+
identity: `${process.pid}@${os_1.default.hostname()}`,
|
|
17
|
+
interceptors: {},
|
|
18
|
+
namespace: 'default',
|
|
19
|
+
workflow: {
|
|
20
|
+
queryRejectCondition: proto_1.temporal.api.enums.v1.QueryRejectCondition.QUERY_REJECT_CONDITION_UNSPECIFIED,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.defaultClientOptions = defaultClientOptions;
|
|
25
|
+
/**
|
|
26
|
+
* High level SDK client.
|
|
27
|
+
*/
|
|
28
|
+
class Client {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
this.connection = options?.connection ?? connection_1.Connection.lazy();
|
|
31
|
+
this.options = {
|
|
32
|
+
...defaultClientOptions(),
|
|
33
|
+
...(0, internal_non_workflow_1.filterNullAndUndefined)(options ?? {}),
|
|
34
|
+
loadedDataConverter: (0, internal_non_workflow_1.loadDataConverter)(options?.dataConverter),
|
|
35
|
+
};
|
|
36
|
+
const { workflow, loadedDataConverter, interceptors, ...base } = this.options;
|
|
37
|
+
this.workflow = new workflow_client_1.WorkflowClient({
|
|
38
|
+
...base,
|
|
39
|
+
...workflow,
|
|
40
|
+
connection: this.connection,
|
|
41
|
+
dataConverter: loadedDataConverter,
|
|
42
|
+
interceptors: interceptors.workflow,
|
|
43
|
+
});
|
|
44
|
+
this.activity = new async_completion_client_1.AsyncCompletionClient({
|
|
45
|
+
...base,
|
|
46
|
+
connection: this.connection,
|
|
47
|
+
dataConverter: loadedDataConverter,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Raw gRPC access to the Temporal service.
|
|
52
|
+
*
|
|
53
|
+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
|
|
54
|
+
* object.
|
|
55
|
+
*/
|
|
56
|
+
get workflowService() {
|
|
57
|
+
return this.connection.workflowService;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
61
|
+
*/
|
|
62
|
+
async withDeadline(deadline, fn) {
|
|
63
|
+
return await this.connection.withDeadline(deadline, fn);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Set metadata for any service requests executed in `fn`'s scope.
|
|
67
|
+
*
|
|
68
|
+
* @returns returned value of `fn`
|
|
69
|
+
*
|
|
70
|
+
* @see {@link Connection.withMetadata}
|
|
71
|
+
*/
|
|
72
|
+
async withMetadata(metadata, fn) {
|
|
73
|
+
return await this.connection.withMetadata(metadata, fn);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Client = Client;
|
|
77
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;;;;AACA,wFAAyG;AAEzG,6CAA6C;AAC7C,4CAAoB;AACpB,uEAAkE;AAClE,6CAA0C;AAG1C,uDAAmD;AA2DnD,SAAgB,oBAAoB;IAClC,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,QAAQ,EAAE,GAAG,OAAO,CAAC,GAAG,IAAI,YAAE,CAAC,QAAQ,EAAE,EAAE;QAC3C,YAAY,EAAE,EAAE;QAChB,SAAS,EAAE,SAAS;QACpB,QAAQ,EAAE;YACR,oBAAoB,EAAE,gBAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAAC,kCAAkC;SACpG;KACF,CAAC;AACJ,CAAC;AAVD,oDAUC;AAED;;GAEG;AACH,MAAa,MAAM;IAejB,YAAY,OAAuB;QACjC,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,uBAAU,CAAC,IAAI,EAAE,CAAC;QAC3D,IAAI,CAAC,OAAO,GAAG;YACb,GAAG,oBAAoB,EAAE;YACzB,GAAG,IAAA,8CAAsB,EAAC,OAAO,IAAI,EAAE,CAAC;YACxC,mBAAmB,EAAE,IAAA,yCAAiB,EAAC,OAAO,EAAE,aAAa,CAAC;SAC/D,CAAC;QAEF,MAAM,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,OAAO,CAAC;QAE9E,IAAI,CAAC,QAAQ,GAAG,IAAI,gCAAc,CAAC;YACjC,GAAG,IAAI;YACP,GAAG,QAAQ;YACX,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,mBAAmB;YAClC,YAAY,EAAE,YAAY,CAAC,QAAQ;SACpC,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,GAAG,IAAI,+CAAqB,CAAC;YACxC,GAAG,IAAI;YACP,UAAU,EAAE,IAAI,CAAC,UAAU;YAC3B,aAAa,EAAE,mBAAmB;SACnC,CAAC,CAAC;IACL,CAAC;IAED;;;;;OAKG;IACH,IAAI,eAAe;QACjB,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,YAAY,CAAI,QAAuB,EAAE,EAAoB;QACjE,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,YAAY,CAAI,QAAkB,EAAE,EAAoB;QAC5D,OAAO,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;CACF;AAnED,wBAmEC"}
|
package/lib/connection.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import * as grpc from '@grpc/grpc-js';
|
|
3
|
-
import { TLSConfig } from '@temporalio/internal-non-workflow
|
|
3
|
+
import { TLSConfig } from '@temporalio/common/lib/internal-non-workflow';
|
|
4
4
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
5
5
|
import type { RPCImpl } from 'protobufjs';
|
|
6
|
-
import { CallContext, Metadata, OperatorService, WorkflowService } from './types';
|
|
6
|
+
import { CallContext, HealthService, Metadata, OperatorService, WorkflowService } from './types';
|
|
7
7
|
/**
|
|
8
8
|
* gRPC and Temporal Server connection options
|
|
9
9
|
*/
|
|
@@ -54,7 +54,7 @@ export interface ConnectionOptions {
|
|
|
54
54
|
* Used either when connecting eagerly with {@link Connection.connect} or
|
|
55
55
|
* calling {@link Connection.ensureConnected}.
|
|
56
56
|
*
|
|
57
|
-
* @format {@link https://www.npmjs.com/package/ms | ms
|
|
57
|
+
* @format number of milliseconds or {@link https://www.npmjs.com/package/ms | ms-formatted string}
|
|
58
58
|
* @default 10 seconds
|
|
59
59
|
*/
|
|
60
60
|
connectTimeout?: number | string;
|
|
@@ -79,7 +79,14 @@ export interface ConnectionCtorOptions {
|
|
|
79
79
|
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
|
|
80
80
|
*/
|
|
81
81
|
readonly workflowService: WorkflowService;
|
|
82
|
+
/**
|
|
83
|
+
* Raw gRPC access to the Temporal {@link https://github.com/temporalio/api/blob/ddf07ab9933e8230309850e3c579e1ff34b03f53/temporal/api/operatorservice/v1/service.proto | operator service}.
|
|
84
|
+
*/
|
|
82
85
|
readonly operatorService: OperatorService;
|
|
86
|
+
/**
|
|
87
|
+
* Raw gRPC access to the standard gRPC {@link https://github.com/grpc/grpc/blob/92f58c18a8da2728f571138c37760a721c8915a2/doc/health-checking.md | health service}.
|
|
88
|
+
*/
|
|
89
|
+
readonly healthService: HealthService;
|
|
83
90
|
readonly callContextStorage: AsyncLocalStorage<CallContext>;
|
|
84
91
|
}
|
|
85
92
|
/**
|
|
@@ -109,6 +116,7 @@ export declare class Connection {
|
|
|
109
116
|
* {@link https://github.com/temporalio/api/blob/master/temporal/api/operatorservice/v1/service.proto | Operator service}
|
|
110
117
|
*/
|
|
111
118
|
readonly operatorService: OperatorService;
|
|
119
|
+
readonly healthService: HealthService;
|
|
112
120
|
readonly callContextStorage: AsyncLocalStorage<CallContext>;
|
|
113
121
|
protected static createCtorOptions(options?: ConnectionOptions): ConnectionCtorOptions;
|
|
114
122
|
/**
|
|
@@ -134,7 +142,7 @@ export declare class Connection {
|
|
|
134
142
|
* {@link ensureConnected}.
|
|
135
143
|
*/
|
|
136
144
|
static connect(options?: ConnectionOptions): Promise<Connection>;
|
|
137
|
-
protected constructor({ options, client, workflowService, operatorService, callContextStorage, }: ConnectionCtorOptions);
|
|
145
|
+
protected constructor({ options, client, workflowService, operatorService, healthService, callContextStorage, }: ConnectionCtorOptions);
|
|
138
146
|
protected static generateRPCImplementation({ serviceName, client, callContextStorage, interceptors, }: RPCImplOptions): RPCImpl;
|
|
139
147
|
/**
|
|
140
148
|
* Set the deadline for any service requests executed in `fn`'s scope.
|
package/lib/connection.js
CHANGED
|
@@ -28,7 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.Connection = exports.defaultConnectionOpts = exports.LOCAL_TARGET = void 0;
|
|
30
30
|
const grpc = __importStar(require("@grpc/grpc-js"));
|
|
31
|
-
const
|
|
31
|
+
const internal_non_workflow_1 = require("@temporalio/common/lib/internal-non-workflow");
|
|
32
32
|
const async_hooks_1 = require("async_hooks");
|
|
33
33
|
const errors_1 = require("./errors");
|
|
34
34
|
const grpc_retry_1 = require("./grpc-retry");
|
|
@@ -63,7 +63,7 @@ function normalizeGRPCConfig(options) {
|
|
|
63
63
|
port = port || '7233';
|
|
64
64
|
rest.address = `${host}:${port}`;
|
|
65
65
|
}
|
|
66
|
-
const tls = (0,
|
|
66
|
+
const tls = (0, internal_non_workflow_1.normalizeTlsConfig)(tlsFromConfig);
|
|
67
67
|
if (tls) {
|
|
68
68
|
if (credentials) {
|
|
69
69
|
throw new TypeError('Both `tls` and `credentials` ConnectionOptions were provided');
|
|
@@ -93,18 +93,19 @@ function normalizeGRPCConfig(options) {
|
|
|
93
93
|
* avoid leaking resources.
|
|
94
94
|
*/
|
|
95
95
|
class Connection {
|
|
96
|
-
constructor({ options, client, workflowService, operatorService, callContextStorage, }) {
|
|
96
|
+
constructor({ options, client, workflowService, operatorService, healthService, callContextStorage, }) {
|
|
97
97
|
this.options = options;
|
|
98
98
|
this.client = client;
|
|
99
99
|
this.workflowService = workflowService;
|
|
100
100
|
this.operatorService = operatorService;
|
|
101
|
+
this.healthService = healthService;
|
|
101
102
|
this.callContextStorage = callContextStorage;
|
|
102
103
|
}
|
|
103
104
|
static createCtorOptions(options) {
|
|
104
105
|
var _a, _b;
|
|
105
106
|
const optionsWithDefaults = {
|
|
106
107
|
...defaultConnectionOpts(),
|
|
107
|
-
...(0,
|
|
108
|
+
...(0, internal_non_workflow_1.filterNullAndUndefined)(normalizeGRPCConfig(options)),
|
|
108
109
|
};
|
|
109
110
|
// Allow overriding this
|
|
110
111
|
(_a = optionsWithDefaults.metadata)['client-name'] ?? (_a['client-name'] = 'temporal-typescript');
|
|
@@ -126,11 +127,19 @@ class Connection {
|
|
|
126
127
|
interceptors: optionsWithDefaults?.interceptors,
|
|
127
128
|
});
|
|
128
129
|
const operatorService = types_1.OperatorService.create(operatorRpcImpl, false, false);
|
|
130
|
+
const healthRpcImpl = this.generateRPCImplementation({
|
|
131
|
+
serviceName: 'grpc.health.v1.Health',
|
|
132
|
+
client,
|
|
133
|
+
callContextStorage,
|
|
134
|
+
interceptors: optionsWithDefaults?.interceptors,
|
|
135
|
+
});
|
|
136
|
+
const healthService = types_1.HealthService.create(healthRpcImpl, false, false);
|
|
129
137
|
return {
|
|
130
138
|
client,
|
|
131
139
|
callContextStorage,
|
|
132
140
|
workflowService,
|
|
133
141
|
operatorService,
|
|
142
|
+
healthService,
|
|
134
143
|
options: optionsWithDefaults,
|
|
135
144
|
};
|
|
136
145
|
}
|
package/lib/connection.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":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AAQ,EAAE,GAAG,QAAQ,EAAE,CAAC;QAC5C,OAAO,MAAM,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC;IACrF,CAAC;IAED;;;;OAIG;IACO,KAAK,CAAC,UAAU,CAAC,QAAgB;QACzC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC3C,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,EAAE;gBACzC,IAAI,GAAG,EAAE;oBACP,MAAM,CAAC,GAAG,CAAC,CAAC;iBACb;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;;AArOH,gCAsOC;AArOC;;GAEG;AACoB,iBAAM,GAAG,IAAI,CAAC,4BAA4B,CAAC,EAAE,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC"}
|
package/lib/grpc-retry.d.ts
CHANGED
|
@@ -1,24 +1,67 @@
|
|
|
1
1
|
import { Interceptor, StatusObject } from '@grpc/grpc-js';
|
|
2
|
+
/**
|
|
3
|
+
* @experimental
|
|
4
|
+
*/
|
|
2
5
|
export interface GrpcRetryOptions {
|
|
3
|
-
/** Maximum number of allowed retries. Defaults to 10. */
|
|
4
|
-
maxRetries: number;
|
|
5
6
|
/**
|
|
6
|
-
* A function which accepts the current retry attempt (starts at
|
|
7
|
+
* A function which accepts the current retry attempt (starts at 1) and returns the millisecond
|
|
7
8
|
* delay that should be applied before the next retry.
|
|
8
9
|
*/
|
|
9
|
-
delayFunction: (attempt: number) => number;
|
|
10
|
+
delayFunction: (attempt: number, status: StatusObject) => number;
|
|
10
11
|
/**
|
|
11
12
|
* A function which accepts a failed status object and returns true if the call should be retried
|
|
12
13
|
*/
|
|
13
|
-
retryableDecider: (status: StatusObject) => boolean;
|
|
14
|
+
retryableDecider: (attempt: number, status: StatusObject) => boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for the backoff formula: `factor ^ attempt * initialIntervalMs(status) * jitter(maxJitter)`
|
|
18
|
+
*
|
|
19
|
+
* @experimental
|
|
20
|
+
*/
|
|
21
|
+
export interface BackoffOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Exponential backoff factor
|
|
24
|
+
*
|
|
25
|
+
* @default 2
|
|
26
|
+
*/
|
|
27
|
+
factor: number;
|
|
28
|
+
/**
|
|
29
|
+
* Maximum number of attempts
|
|
30
|
+
*
|
|
31
|
+
* @default 10
|
|
32
|
+
*/
|
|
33
|
+
maxAttempts: number;
|
|
34
|
+
/**
|
|
35
|
+
* Maximum amount of jitter to apply
|
|
36
|
+
*
|
|
37
|
+
* @default 0.1
|
|
38
|
+
*/
|
|
39
|
+
maxJitter: number;
|
|
40
|
+
/**
|
|
41
|
+
* Function that returns the "initial" backoff interval based on the returned status.
|
|
42
|
+
*
|
|
43
|
+
* The default is 1 second for RESOURCE_EXHAUSTED errors and 20 millis for other retryable errors.
|
|
44
|
+
*/
|
|
45
|
+
initialIntervalMs(status: StatusObject): number;
|
|
46
|
+
/**
|
|
47
|
+
* Function that returns the "maximum" backoff interval based on the returned status.
|
|
48
|
+
*
|
|
49
|
+
* The default is 10 seconds regardless of the status.
|
|
50
|
+
*/
|
|
51
|
+
maxIntervalMs(status: StatusObject): number;
|
|
14
52
|
}
|
|
15
|
-
|
|
53
|
+
/**
|
|
54
|
+
* Generates the default retry behavior based on given backoff options
|
|
55
|
+
*
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
export declare function defaultGrpcRetryOptions(options?: Partial<BackoffOptions>): GrpcRetryOptions;
|
|
16
59
|
export declare function isRetryableError(status: StatusObject): boolean;
|
|
17
|
-
/** Return backoff amount in ms */
|
|
18
|
-
export declare function backOffAmount(attempt: number): number;
|
|
19
60
|
/**
|
|
20
61
|
* Returns a GRPC interceptor that will perform automatic retries for some types of failed calls
|
|
21
62
|
*
|
|
22
63
|
* @param retryOptions Options for the retry interceptor
|
|
64
|
+
*
|
|
65
|
+
* @experimental
|
|
23
66
|
*/
|
|
24
67
|
export declare function makeGrpcRetryInterceptor(retryOptions: GrpcRetryOptions): Interceptor;
|