@temporalio/client 0.23.0 → 1.0.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/README.md CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  [![NPM](https://img.shields.io/npm/v/@temporalio/client?style=for-the-badge)](https://www.npmjs.com/package/@temporalio/client)
4
4
 
5
- Part of [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/docs/typescript/introduction/).
5
+ Part of [Temporal](https://temporal.io)'s [TypeScript SDK](https://docs.temporal.io/typescript/introduction/).
6
6
 
7
- - [Client docs](https://docs.temporal.io/docs/typescript/clients)
7
+ - [Client docs](https://docs.temporal.io/typescript/clients)
8
8
  - [API reference](https://typescript.temporal.io/api/namespaces/client)
9
9
  - [Sample projects](https://github.com/temporalio/samples-typescript)
@@ -1,15 +1,16 @@
1
1
  import { DataConverter, LoadedDataConverter } from '@temporalio/common';
2
- import { WorkflowService } from './connection';
2
+ import { Replace } from '@temporalio/internal-workflow-common';
3
+ import { ConnectionLike, WorkflowService } from './types';
3
4
  /**
4
- * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
5
- * 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.
6
7
  */
7
8
  export declare class ActivityNotFoundError extends Error {
8
9
  readonly name = "ActivityNotFoundError";
9
10
  }
10
11
  /**
11
12
  * Thrown by {@link AsyncCompletionClient} when trying to complete or heartbeat
12
- * an Activity for any reason apart from "not found".
13
+ * an Activity for any reason apart from {@link ActivityNotFoundError}.
13
14
  */
14
15
  export declare class ActivityCompletionError extends Error {
15
16
  readonly name = "ActivityCompletionError";
@@ -35,6 +36,7 @@ export interface AsyncCompletionClientOptions {
35
36
  * @default `${process.pid}@${os.hostname()}`
36
37
  */
37
38
  identity?: string;
39
+ connection?: ConnectionLike;
38
40
  /**
39
41
  * Server namespace
40
42
  *
@@ -42,7 +44,9 @@ export interface AsyncCompletionClientOptions {
42
44
  */
43
45
  namespace?: string;
44
46
  }
45
- export declare type AsyncCompletionClientOptionsWithDefaults = Required<AsyncCompletionClientOptions>;
47
+ export declare type AsyncCompletionClientOptionsWithDefaults = Replace<Required<AsyncCompletionClientOptions>, {
48
+ connection?: ConnectionLike;
49
+ }>;
46
50
  export declare function defaultAsyncCompletionClientOptions(): AsyncCompletionClientOptionsWithDefaults;
47
51
  /**
48
52
  * A mostly unique Activity identifier including its scheduling workflow's ID
@@ -60,10 +64,11 @@ export interface FullActivityId {
60
64
  * A client for asynchronous completion and heartbeating of Activities.
61
65
  */
62
66
  export declare class AsyncCompletionClient {
63
- readonly service: WorkflowService;
64
67
  readonly options: AsyncCompletionClientOptionsWithDefaults;
65
68
  protected readonly dataConverter: LoadedDataConverter;
66
- constructor(service?: WorkflowService, options?: AsyncCompletionClientOptions);
69
+ readonly connection: ConnectionLike;
70
+ constructor(options?: AsyncCompletionClientOptions);
71
+ get workflowService(): WorkflowService;
67
72
  /**
68
73
  * Transforms grpc errors into well defined TS errors.
69
74
  */
@@ -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() {
@@ -55,11 +55,14 @@ exports.defaultAsyncCompletionClientOptions = defaultAsyncCompletionClientOption
55
55
  * A client for asynchronous completion and heartbeating of Activities.
56
56
  */
57
57
  class AsyncCompletionClient {
58
- constructor(service = new connection_1.Connection().service, options) {
59
- this.service = service;
58
+ constructor(options) {
59
+ this.connection = options?.connection ?? connection_1.Connection.lazy();
60
60
  this.dataConverter = (0, internal_non_workflow_common_1.loadDataConverter)(options?.dataConverter);
61
61
  this.options = { ...defaultAsyncCompletionClientOptions(), ...(0, internal_non_workflow_common_1.filterNullAndUndefined)(options ?? {}) };
62
62
  }
63
+ get workflowService() {
64
+ return this.connection.workflowService;
65
+ }
63
66
  /**
64
67
  * Transforms grpc errors into well defined TS errors.
65
68
  */
@@ -75,7 +78,7 @@ class AsyncCompletionClient {
75
78
  async complete(taskTokenOrFullActivityId, result) {
76
79
  try {
77
80
  if (taskTokenOrFullActivityId instanceof Uint8Array) {
78
- await this.service.respondActivityTaskCompleted({
81
+ await this.workflowService.respondActivityTaskCompleted({
79
82
  identity: this.options.identity,
80
83
  namespace: this.options.namespace,
81
84
  taskToken: taskTokenOrFullActivityId,
@@ -83,7 +86,7 @@ class AsyncCompletionClient {
83
86
  });
84
87
  }
85
88
  else {
86
- await this.service.respondActivityTaskCompletedById({
89
+ await this.workflowService.respondActivityTaskCompletedById({
87
90
  identity: this.options.identity,
88
91
  namespace: this.options.namespace,
89
92
  ...taskTokenOrFullActivityId,
@@ -98,7 +101,7 @@ class AsyncCompletionClient {
98
101
  async fail(taskTokenOrFullActivityId, err) {
99
102
  try {
100
103
  if (taskTokenOrFullActivityId instanceof Uint8Array) {
101
- await this.service.respondActivityTaskFailed({
104
+ await this.workflowService.respondActivityTaskFailed({
102
105
  identity: this.options.identity,
103
106
  namespace: this.options.namespace,
104
107
  taskToken: taskTokenOrFullActivityId,
@@ -106,7 +109,7 @@ class AsyncCompletionClient {
106
109
  });
107
110
  }
108
111
  else {
109
- await this.service.respondActivityTaskFailedById({
112
+ await this.workflowService.respondActivityTaskFailedById({
110
113
  identity: this.options.identity,
111
114
  namespace: this.options.namespace,
112
115
  ...taskTokenOrFullActivityId,
@@ -121,7 +124,7 @@ class AsyncCompletionClient {
121
124
  async reportCancellation(taskTokenOrFullActivityId, details) {
122
125
  try {
123
126
  if (taskTokenOrFullActivityId instanceof Uint8Array) {
124
- await this.service.respondActivityTaskCanceled({
127
+ await this.workflowService.respondActivityTaskCanceled({
125
128
  identity: this.options.identity,
126
129
  namespace: this.options.namespace,
127
130
  taskToken: taskTokenOrFullActivityId,
@@ -129,7 +132,7 @@ class AsyncCompletionClient {
129
132
  });
130
133
  }
131
134
  else {
132
- await this.service.respondActivityTaskCanceledById({
135
+ await this.workflowService.respondActivityTaskCanceledById({
133
136
  identity: this.options.identity,
134
137
  namespace: this.options.namespace,
135
138
  ...taskTokenOrFullActivityId,
@@ -144,7 +147,7 @@ class AsyncCompletionClient {
144
147
  async heartbeat(taskTokenOrFullActivityId, details) {
145
148
  try {
146
149
  if (taskTokenOrFullActivityId instanceof Uint8Array) {
147
- const { cancelRequested } = await this.service.recordActivityTaskHeartbeat({
150
+ const { cancelRequested } = await this.workflowService.recordActivityTaskHeartbeat({
148
151
  identity: this.options.identity,
149
152
  namespace: this.options.namespace,
150
153
  taskToken: taskTokenOrFullActivityId,
@@ -155,7 +158,7 @@ class AsyncCompletionClient {
155
158
  }
156
159
  }
157
160
  else {
158
- const { cancelRequested } = await this.service.recordActivityTaskHeartbeatById({
161
+ const { cancelRequested } = await this.workflowService.recordActivityTaskHeartbeatById({
159
162
  identity: this.options.identity,
160
163
  namespace: this.options.namespace,
161
164
  ...taskTokenOrFullActivityId,
@@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,EAAE;gBACzC,MAAM,GAAG,CAAC;aACX;YACD,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;SACvB;IACH,CAAC;CACF;AA7JD,sDA6JC"}
1
+ {"version":3,"file":"async-completion-client.js","sourceRoot":"","sources":["../src/async-completion-client.ts"],"names":[],"mappings":";;;;;;AAAA,iEAA2D;AAC3D,+CAA+F;AAC/F,2FAKkD;AAElD,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;AAmCD,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;;GAEG;AACH,MAAa,qBAAqB;IAKhC,YAAY,OAAsC;QAChD,IAAI,CAAC,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,uBAAU,CAAC,IAAI,EAAE,CAAC;QAC3D,IAAI,CAAC,aAAa,GAAG,IAAA,gDAAiB,EAAC,OAAO,EAAE,aAAa,CAAC,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,mCAAmC,EAAE,EAAE,GAAG,IAAA,qDAAsB,EAAC,OAAO,IAAI,EAAE,CAAC,EAAE,CAAC;IACxG,CAAC;IAED,IAAI,eAAe;QACjB,O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a,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;AAhKD,sDAgKC"}
@@ -1,13 +1,11 @@
1
1
  /// <reference types="node" />
2
2
  import * as grpc from '@grpc/grpc-js';
3
3
  import { TLSConfig } from '@temporalio/internal-non-workflow-common';
4
- import { temporal } from '@temporalio/proto';
5
4
  import { AsyncLocalStorage } from 'async_hooks';
6
5
  import type { RPCImpl } from 'protobufjs';
7
- export declare type WorkflowService = temporal.api.workflowservice.v1.WorkflowService;
8
- export declare const WorkflowService: typeof temporal.api.workflowservice.v1.WorkflowService;
6
+ import { CallContext, Metadata, OperatorService, WorkflowService } from './types';
9
7
  /**
10
- * GRPC + Temporal server connection options
8
+ * gRPC and Temporal Server connection options
11
9
  */
12
10
  export interface ConnectionOptions {
13
11
  /**
@@ -44,32 +42,35 @@ export interface ConnectionOptions {
44
42
  * interceptors).
45
43
  */
46
44
  interceptors?: grpc.Interceptor[];
47
- }
48
- export declare type ConnectionOptionsWithDefaults = Required<Omit<ConnectionOptions, 'tls'>>;
49
- export declare const LOCAL_DOCKER_TARGET = "127.0.0.1:7233";
50
- export declare function defaultConnectionOpts(): ConnectionOptionsWithDefaults;
51
- /**
52
- * Mapping of string to valid gRPC metadata value
53
- */
54
- export declare type Metadata = Record<string, grpc.MetadataValue>;
55
- /**
56
- * User defined context for gRPC client calls
57
- */
58
- export interface CallContext {
59
45
  /**
60
- * {@link Deadline | https://grpc.io/blog/deadlines/} for gRPC client calls
46
+ * Optional mapping of gRPC metadata (HTTP headers) to send with each request to the server.
47
+ *
48
+ * In order to dynamically set metadata, use {@link Connection.withMetadata}
61
49
  */
62
- deadline?: number | Date;
50
+ metadata?: Metadata;
63
51
  /**
64
- * Metadata to set on gRPC requests
52
+ * Milliseconds to wait until establishing a connection with the server.
53
+ *
54
+ * Used either when connecting eagerly with {@link Connection.connect} or
55
+ * calling {@link Connection.ensureConnected}.
56
+ *
57
+ * @format {@link https://www.npmjs.com/package/ms | ms} formatted string
58
+ * @default 10 seconds
65
59
  */
66
- metadata?: Metadata;
60
+ connectTimeout?: number | string;
67
61
  }
68
- /**
69
- * Client connection to the Temporal Service
70
- */
71
- export declare class Connection {
72
- static readonly Client: grpc.ServiceClientConstructor;
62
+ export declare type ConnectionOptionsWithDefaults = Required<Omit<ConnectionOptions, 'tls' | 'connectTimeout'>> & {
63
+ connectTimeoutMs: number;
64
+ };
65
+ export declare const LOCAL_TARGET = "127.0.0.1:7233";
66
+ export declare function defaultConnectionOpts(): ConnectionOptionsWithDefaults;
67
+ export interface RPCImplOptions {
68
+ serviceName: string;
69
+ client: grpc.Client;
70
+ callContextStorage: AsyncLocalStorage<CallContext>;
71
+ interceptors?: grpc.Interceptor[];
72
+ }
73
+ export interface ConnectionCtorOptions {
73
74
  readonly options: ConnectionOptionsWithDefaults;
74
75
  readonly client: grpc.Client;
75
76
  /**
@@ -77,48 +78,97 @@ export declare class Connection {
77
78
  *
78
79
  * **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
79
80
  */
80
- readonly service: WorkflowService;
81
+ readonly workflowService: WorkflowService;
82
+ readonly operatorService: OperatorService;
81
83
  readonly callContextStorage: AsyncLocalStorage<CallContext>;
82
- constructor(options?: ConnectionOptions);
83
- protected generateRPCImplementation(serviceName: string): RPCImpl;
84
+ }
85
+ /**
86
+ * Client connection to the Temporal Server
87
+ *
88
+ * ⚠️ Connections are expensive to construct and should be reused. Make sure to {@link close} any unused connections to
89
+ * avoid leaking resources.
90
+ */
91
+ export declare class Connection {
84
92
  /**
85
- * Set the deadline for any service requests executed in `fn`'s scope.
93
+ * @internal
86
94
  */
87
- withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
95
+ static readonly Client: grpc.ServiceClientConstructor;
96
+ readonly options: ConnectionOptionsWithDefaults;
97
+ protected readonly client: grpc.Client;
88
98
  /**
89
- * Set metadata for any service requests executed in `fn`'s scope.
99
+ * Used to ensure `ensureConnected` is called once.
100
+ */
101
+ protected connectPromise?: Promise<void>;
102
+ /**
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}
105
+ */
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
+ */
111
+ readonly operatorService: OperatorService;
112
+ readonly callContextStorage: AsyncLocalStorage<CallContext>;
113
+ protected static createCtorOptions(options?: ConnectionOptions): ConnectionCtorOptions;
114
+ /**
115
+ * Ensure connection can be established.
116
+ *
117
+ * Does not need to be called if you use {@link connect}.
118
+ *
119
+ * This method's result is memoized to ensure it runs only once.
90
120
  *
91
- * @returns returned value of `fn`
121
+ * Calls {@link proto.temporal.api.workflowservice.v1.WorkflowService.getSystemInfo} internally.
92
122
  */
93
- withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
123
+ ensureConnected(): Promise<void>;
94
124
  /**
95
- * Set metadata for any service requests executed in `fn`'s scope.
125
+ * Create a lazy `Connection` instance.
96
126
  *
97
- * @param metadataFn function that gets current context metadata and returns new metadata
127
+ * This method does not verify connectivity with the server. We recommend using {@link connect} instead.
128
+ */
129
+ static lazy(options?: ConnectionOptions): Connection;
130
+ /**
131
+ * Establish a connection with the server and return a `Connection` instance.
98
132
  *
99
- * @returns returned value of `fn`
133
+ * This is the preferred method of creating connections as it verifies connectivity by calling
134
+ * {@link ensureConnected}.
100
135
  */
101
- withMetadata<R>(metadataFn: (meta: Metadata) => Metadata, fn: () => Promise<R>): Promise<R>;
136
+ static connect(options?: ConnectionOptions): Promise<Connection>;
137
+ protected constructor({ options, client, workflowService, operatorService, callContextStorage, }: ConnectionCtorOptions);
138
+ protected static generateRPCImplementation({ serviceName, client, callContextStorage, interceptors, }: RPCImplOptions): RPCImpl;
102
139
  /**
103
- * Set the {@link CallContext} for any service requests executed in `fn`'s scope.
140
+ * Set the deadline for any service requests executed in `fn`'s scope.
104
141
  *
105
- * @returns returned value of `fn`
142
+ * @returns value returned from `fn`
106
143
  */
107
- withCallContext<R>(cx: CallContext, fn: () => Promise<R>): Promise<R>;
144
+ withDeadline<ReturnType>(deadline: number | Date, fn: () => Promise<ReturnType>): Promise<ReturnType>;
108
145
  /**
109
- * Set the {@link CallContext} for any service requests executed in `fn`'s scope.
146
+ * Set metadata for any service requests executed in `fn`'s scope.
147
+ *
148
+ * The provided metadata is merged on top of any existing metadata in current scope, including metadata provided in
149
+ * {@link ConnectionOptions.metadata}.
110
150
  *
111
- * @param cxFn function that gets current context and returns new context
151
+ * @returns value returned from `fn`
112
152
  *
113
- * @returns returned value of `fn`
153
+ * @example
154
+ *
155
+ *```ts
156
+ *const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
157
+ * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
158
+ *);
159
+ *```
114
160
  */
115
- withCallContext<R>(cxFn: (cx?: CallContext) => CallContext, fn: () => Promise<R>): Promise<R>;
161
+ withMetadata<ReturnType>(metadata: Metadata, fn: () => Promise<ReturnType>): Promise<ReturnType>;
116
162
  /**
117
163
  * Wait for successful connection to the server.
118
164
  *
119
- * @param waitTimeMs milliseconds to wait before giving up.
120
- *
121
165
  * @see https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor
122
166
  */
123
- untilReady(waitTimeMs?: number): Promise<void>;
167
+ protected untilReady(deadline: number): Promise<void>;
168
+ /**
169
+ * Close the underlying gRPC client.
170
+ *
171
+ * Make sure to call this method to ensure proper resource cleanup.
172
+ */
173
+ close(): Promise<void>;
124
174
  }
package/lib/connection.js CHANGED
@@ -22,21 +22,27 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Connection = exports.defaultConnectionOpts = exports.LOCAL_DOCKER_TARGET = exports.WorkflowService = void 0;
29
+ exports.Connection = exports.defaultConnectionOpts = exports.LOCAL_TARGET = void 0;
27
30
  const grpc = __importStar(require("@grpc/grpc-js"));
28
31
  const internal_non_workflow_common_1 = require("@temporalio/internal-non-workflow-common");
29
- const proto_1 = require("@temporalio/proto");
30
32
  const async_hooks_1 = require("async_hooks");
33
+ const errors_1 = require("./errors");
31
34
  const grpc_retry_1 = require("./grpc-retry");
32
- exports.WorkflowService = proto_1.temporal.api.workflowservice.v1.WorkflowService;
33
- exports.LOCAL_DOCKER_TARGET = '127.0.0.1:7233';
35
+ const pkg_1 = __importDefault(require("./pkg"));
36
+ const types_1 = require("./types");
37
+ exports.LOCAL_TARGET = '127.0.0.1:7233';
34
38
  function defaultConnectionOpts() {
35
39
  return {
36
- address: exports.LOCAL_DOCKER_TARGET,
40
+ address: exports.LOCAL_TARGET,
37
41
  credentials: grpc.credentials.createInsecure(),
38
42
  channelArgs: {},
39
43
  interceptors: [(0, grpc_retry_1.makeGrpcRetryInterceptor)((0, grpc_retry_1.defaultGrpcRetryOptions)())],
44
+ metadata: {},
45
+ connectTimeoutMs: 10000,
40
46
  };
41
47
  }
42
48
  exports.defaultConnectionOpts = defaultConnectionOpts;
@@ -77,57 +83,154 @@ function normalizeGRPCConfig(options) {
77
83
  }
78
84
  }
79
85
  /**
80
- * Client connection to the Temporal Service
86
+ * Client connection to the Temporal Server
87
+ *
88
+ * ⚠️ Connections are expensive to construct and should be reused. Make sure to {@link close} any unused connections to
89
+ * avoid leaking resources.
81
90
  */
82
91
  class Connection {
83
- constructor(options) {
84
- this.callContextStorage = new async_hooks_1.AsyncLocalStorage();
85
- this.options = {
92
+ constructor({ options, client, workflowService, operatorService, callContextStorage, }) {
93
+ this.options = options;
94
+ this.client = client;
95
+ this.workflowService = workflowService;
96
+ this.operatorService = operatorService;
97
+ this.callContextStorage = callContextStorage;
98
+ }
99
+ static createCtorOptions(options) {
100
+ var _a, _b;
101
+ const optionsWithDefaults = {
86
102
  ...defaultConnectionOpts(),
87
- ...normalizeGRPCConfig(options),
103
+ ...(0, internal_non_workflow_common_1.filterNullAndUndefined)(normalizeGRPCConfig(options)),
104
+ };
105
+ // Allow overriding this
106
+ (_a = optionsWithDefaults.metadata)['client-name'] ?? (_a['client-name'] = 'temporal-typescript');
107
+ (_b = optionsWithDefaults.metadata)['client-version'] ?? (_b['client-version'] = pkg_1.default.version);
108
+ const client = new this.Client(optionsWithDefaults.address, optionsWithDefaults.credentials, optionsWithDefaults.channelArgs);
109
+ const callContextStorage = new async_hooks_1.AsyncLocalStorage();
110
+ callContextStorage.enterWith({ metadata: optionsWithDefaults.metadata });
111
+ const workflowRpcImpl = this.generateRPCImplementation({
112
+ serviceName: 'temporal.api.workflowservice.v1.WorkflowService',
113
+ client,
114
+ callContextStorage,
115
+ interceptors: optionsWithDefaults?.interceptors,
116
+ });
117
+ const workflowService = types_1.WorkflowService.create(workflowRpcImpl, false, false);
118
+ const operatorRpcImpl = this.generateRPCImplementation({
119
+ serviceName: 'temporal.api.operatorservice.v1.OperatorService',
120
+ client,
121
+ callContextStorage,
122
+ interceptors: optionsWithDefaults?.interceptors,
123
+ });
124
+ const operatorService = types_1.OperatorService.create(operatorRpcImpl, false, false);
125
+ return {
126
+ client,
127
+ callContextStorage,
128
+ workflowService,
129
+ operatorService,
130
+ options: optionsWithDefaults,
88
131
  };
89
- this.client = new Connection.Client(this.options.address, this.options.credentials, this.options.channelArgs);
90
- const rpcImpl = this.generateRPCImplementation('temporal.api.workflowservice.v1.WorkflowService');
91
- this.service = exports.WorkflowService.create(rpcImpl, false, false);
92
132
  }
93
- generateRPCImplementation(serviceName) {
133
+ /**
134
+ * Ensure connection can be established.
135
+ *
136
+ * Does not need to be called if you use {@link connect}.
137
+ *
138
+ * This method's result is memoized to ensure it runs only once.
139
+ *
140
+ * Calls {@link proto.temporal.api.workflowservice.v1.WorkflowService.getSystemInfo} internally.
141
+ */
142
+ async ensureConnected() {
143
+ if (this.connectPromise == null) {
144
+ const deadline = Date.now() + this.options.connectTimeoutMs;
145
+ this.connectPromise = (async () => {
146
+ await this.untilReady(deadline);
147
+ try {
148
+ await this.withDeadline(deadline, () => this.workflowService.getSystemInfo({}));
149
+ }
150
+ catch (err) {
151
+ if ((0, errors_1.isServerErrorResponse)(err)) {
152
+ // Ignore old servers
153
+ if (err.code !== grpc.status.UNIMPLEMENTED) {
154
+ throw new errors_1.ServiceError('Failed to connect to Temporal server', { cause: err });
155
+ }
156
+ }
157
+ else {
158
+ throw err;
159
+ }
160
+ }
161
+ })();
162
+ }
163
+ return this.connectPromise;
164
+ }
165
+ /**
166
+ * Create a lazy `Connection` instance.
167
+ *
168
+ * This method does not verify connectivity with the server. We recommend using {@link connect} instead.
169
+ */
170
+ static lazy(options) {
171
+ return new this(this.createCtorOptions(options));
172
+ }
173
+ /**
174
+ * Establish a connection with the server and return a `Connection` instance.
175
+ *
176
+ * This is the preferred method of creating connections as it verifies connectivity by calling
177
+ * {@link ensureConnected}.
178
+ */
179
+ static async connect(options) {
180
+ const conn = this.lazy(options);
181
+ await conn.ensureConnected();
182
+ return conn;
183
+ }
184
+ static generateRPCImplementation({ serviceName, client, callContextStorage, interceptors, }) {
94
185
  return (method, requestData, callback) => {
95
186
  const metadataContainer = new grpc.Metadata();
96
- const { metadata, deadline } = this.callContextStorage.getStore() ?? {};
187
+ const { metadata, deadline } = callContextStorage.getStore() ?? {};
97
188
  if (metadata != null) {
98
189
  for (const [k, v] of Object.entries(metadata)) {
99
190
  metadataContainer.set(k, v);
100
191
  }
101
192
  }
102
- return this.client.makeUnaryRequest(`/${serviceName}/${method.name}`, (arg) => arg, (arg) => arg, requestData, metadataContainer, { interceptors: this.options.interceptors, deadline }, callback);
193
+ return client.makeUnaryRequest(`/${serviceName}/${method.name}`, (arg) => arg, (arg) => arg, requestData, metadataContainer, { interceptors, deadline }, callback);
103
194
  };
104
195
  }
105
196
  /**
106
197
  * Set the deadline for any service requests executed in `fn`'s scope.
198
+ *
199
+ * @returns value returned from `fn`
107
200
  */
108
201
  async withDeadline(deadline, fn) {
109
202
  const cc = this.callContextStorage.getStore();
110
203
  return await this.callContextStorage.run({ deadline, metadata: cc?.metadata }, fn);
111
204
  }
205
+ /**
206
+ * Set metadata for any service requests executed in `fn`'s scope.
207
+ *
208
+ * The provided metadata is merged on top of any existing metadata in current scope, including metadata provided in
209
+ * {@link ConnectionOptions.metadata}.
210
+ *
211
+ * @returns value returned from `fn`
212
+ *
213
+ * @example
214
+ *
215
+ *```ts
216
+ *const workflowHandle = await conn.withMetadata({ apiKey: 'secret' }, () =>
217
+ * conn.withMetadata({ otherKey: 'set' }, () => client.start(options)))
218
+ *);
219
+ *```
220
+ */
112
221
  async withMetadata(metadata, fn) {
113
222
  const cc = this.callContextStorage.getStore();
114
- metadata = typeof metadata === 'function' ? metadata(cc?.metadata ?? {}) : metadata;
223
+ metadata = { ...cc?.metadata, ...metadata };
115
224
  return await this.callContextStorage.run({ metadata, deadline: cc?.deadline }, fn);
116
225
  }
117
- async withCallContext(cx, fn) {
118
- cx = typeof cx === 'function' ? cx(this.callContextStorage.getStore()) : cx;
119
- return await this.callContextStorage.run(cx, fn);
120
- }
121
226
  /**
122
227
  * Wait for successful connection to the server.
123
228
  *
124
- * @param waitTimeMs milliseconds to wait before giving up.
125
- *
126
229
  * @see https://grpc.github.io/grpc/node/grpc.Client.html#waitForReady__anchor
127
230
  */
128
- async untilReady(waitTimeMs = 5000) {
231
+ async untilReady(deadline) {
129
232
  return new Promise((resolve, reject) => {
130
- this.client.waitForReady(Date.now() + waitTimeMs, (err) => {
233
+ this.client.waitForReady(deadline, (err) => {
131
234
  if (err) {
132
235
  reject(err);
133
236
  }
@@ -137,7 +240,19 @@ class Connection {
137
240
  });
138
241
  });
139
242
  }
243
+ // This method is async for uniformity with NativeConnection which could be used in the future to power clients
244
+ /**
245
+ * Close the underlying gRPC client.
246
+ *
247
+ * Make sure to call this method to ensure proper resource cleanup.
248
+ */
249
+ async close() {
250
+ this.client.close();
251
+ }
140
252
  }
141
253
  exports.Connection = Connection;
254
+ /**
255
+ * @internal
256
+ */
142
257
  Connection.Client = grpc.makeGenericClientConstructor({}, 'WorkflowService', {});
143
258
  //# sourceMappingURL=connection.js.map