@temporalio/client 0.22.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.
- package/README.md +2 -2
- package/lib/async-completion-client.d.ts +12 -7
- package/lib/async-completion-client.js +16 -13
- package/lib/async-completion-client.js.map +1 -1
- package/lib/connection.d.ts +97 -47
- package/lib/connection.js +140 -25
- package/lib/connection.js.map +1 -1
- package/lib/index.d.ts +5 -3
- package/lib/index.js +8 -4
- package/lib/index.js.map +1 -1
- package/lib/pkg.d.ts +5 -0
- package/lib/pkg.js +12 -0
- package/lib/pkg.js.map +1 -0
- package/lib/types.d.ts +50 -2
- package/lib/types.js +4 -0
- package/lib/types.js.map +1 -1
- package/lib/workflow-client.d.ts +55 -15
- package/lib/workflow-client.js +73 -20
- package/lib/workflow-client.js.map +1 -1
- package/lib/workflow-options.d.ts +2 -2
- package/package.json +12 -11
- package/src/async-completion-client.ts +256 -0
- package/src/connection.ts +374 -0
- package/src/errors.ts +57 -0
- package/src/grpc-retry.ts +119 -0
- package/src/index.ts +37 -0
- package/src/interceptors.ts +132 -0
- package/src/pkg.ts +7 -0
- package/src/types.ts +88 -0
- package/src/workflow-client.ts +969 -0
- package/src/workflow-options.ts +76 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ServerErrorResponse } from '@grpc/grpc-js';
|
|
2
|
+
import { RetryState, TemporalFailure } from '@temporalio/common';
|
|
3
|
+
export { WorkflowExecutionAlreadyStartedError } from '@temporalio/common';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Generic Error class for errors coming from the service
|
|
7
|
+
*/
|
|
8
|
+
export class ServiceError extends Error {
|
|
9
|
+
public readonly name: string = 'ServiceError';
|
|
10
|
+
public readonly cause?: Error;
|
|
11
|
+
|
|
12
|
+
constructor(message: string, opts?: { cause: Error }) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.cause = opts?.cause;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Thrown by the client while waiting on Workflow execution result if execution
|
|
20
|
+
* completes with failure.
|
|
21
|
+
*
|
|
22
|
+
* The failure type will be set in the `cause` attribute.
|
|
23
|
+
*
|
|
24
|
+
* For example if the workflow is cancelled, `cause` will be set to
|
|
25
|
+
* {@link CancelledFailure}.
|
|
26
|
+
*/
|
|
27
|
+
export class WorkflowFailedError extends Error {
|
|
28
|
+
public readonly name: string = 'WorkflowFailedError';
|
|
29
|
+
public constructor(
|
|
30
|
+
message: string,
|
|
31
|
+
public readonly cause: TemporalFailure | undefined,
|
|
32
|
+
public readonly retryState: RetryState
|
|
33
|
+
) {
|
|
34
|
+
super(message);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Thrown the by client while waiting on Workflow execution result if Workflow
|
|
40
|
+
* continues as new.
|
|
41
|
+
*
|
|
42
|
+
* Only thrown if asked not to follow the chain of execution (see {@link WorkflowOptions.followRuns}).
|
|
43
|
+
*/
|
|
44
|
+
export class WorkflowContinuedAsNewError extends Error {
|
|
45
|
+
public readonly name: string = 'WorkflowExecutionContinuedAsNewError';
|
|
46
|
+
public constructor(message: string, public readonly newExecutionRunId: string) {
|
|
47
|
+
super(message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Type assertion helper, assertion is mostly empty because any additional
|
|
53
|
+
* properties are optional.
|
|
54
|
+
*/
|
|
55
|
+
export function isServerErrorResponse(err: unknown): err is ServerErrorResponse {
|
|
56
|
+
return err instanceof Error;
|
|
57
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InterceptingCall,
|
|
3
|
+
Interceptor,
|
|
4
|
+
ListenerBuilder,
|
|
5
|
+
Metadata,
|
|
6
|
+
RequesterBuilder,
|
|
7
|
+
StatusObject,
|
|
8
|
+
} from '@grpc/grpc-js';
|
|
9
|
+
import * as grpc from '@grpc/grpc-js';
|
|
10
|
+
|
|
11
|
+
export interface GrpcRetryOptions {
|
|
12
|
+
/** Maximum number of allowed retries. Defaults to 10. */
|
|
13
|
+
maxRetries: number;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A function which accepts the current retry attempt (starts at 0) and returns the millisecond
|
|
17
|
+
* delay that should be applied before the next retry.
|
|
18
|
+
*/
|
|
19
|
+
delayFunction: (attempt: number) => number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A function which accepts a failed status object and returns true if the call should be retried
|
|
23
|
+
*/
|
|
24
|
+
retryableDecider: (status: StatusObject) => boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function defaultGrpcRetryOptions(): GrpcRetryOptions {
|
|
28
|
+
return {
|
|
29
|
+
maxRetries: 10,
|
|
30
|
+
delayFunction: backOffAmount,
|
|
31
|
+
retryableDecider: isRetryableError,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const retryableCodes = new Set([
|
|
36
|
+
grpc.status.UNKNOWN,
|
|
37
|
+
grpc.status.RESOURCE_EXHAUSTED,
|
|
38
|
+
grpc.status.UNAVAILABLE,
|
|
39
|
+
grpc.status.ABORTED,
|
|
40
|
+
grpc.status.DATA_LOSS,
|
|
41
|
+
grpc.status.OUT_OF_RANGE,
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
export function isRetryableError(status: StatusObject): boolean {
|
|
45
|
+
return retryableCodes.has(status.code);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Return backoff amount in ms */
|
|
49
|
+
export function backOffAmount(attempt: number): number {
|
|
50
|
+
return 2 ** attempt * 20;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Returns a GRPC interceptor that will perform automatic retries for some types of failed calls
|
|
55
|
+
*
|
|
56
|
+
* @param retryOptions Options for the retry interceptor
|
|
57
|
+
*/
|
|
58
|
+
export function makeGrpcRetryInterceptor(retryOptions: GrpcRetryOptions): Interceptor {
|
|
59
|
+
return (options, nextCall) => {
|
|
60
|
+
let savedMetadata: Metadata;
|
|
61
|
+
let savedSendMessage: any;
|
|
62
|
+
let savedReceiveMessage: any;
|
|
63
|
+
let savedMessageNext: any;
|
|
64
|
+
const requester = new RequesterBuilder()
|
|
65
|
+
.withStart(function (metadata, _listener, next) {
|
|
66
|
+
savedMetadata = metadata;
|
|
67
|
+
const newListener = new ListenerBuilder()
|
|
68
|
+
.withOnReceiveMessage((message, next) => {
|
|
69
|
+
savedReceiveMessage = message;
|
|
70
|
+
savedMessageNext = next;
|
|
71
|
+
})
|
|
72
|
+
.withOnReceiveStatus((status, next) => {
|
|
73
|
+
let retries = 0;
|
|
74
|
+
const retry = (message: any, metadata: Metadata) => {
|
|
75
|
+
retries++;
|
|
76
|
+
const newCall = nextCall(options);
|
|
77
|
+
newCall.start(metadata, {
|
|
78
|
+
onReceiveMessage: (message) => {
|
|
79
|
+
savedReceiveMessage = message;
|
|
80
|
+
},
|
|
81
|
+
onReceiveStatus: (status) => {
|
|
82
|
+
if (retryOptions.retryableDecider(status)) {
|
|
83
|
+
if (retries <= retryOptions.maxRetries) {
|
|
84
|
+
setTimeout(() => retry(message, metadata), retryOptions.delayFunction(retries));
|
|
85
|
+
} else {
|
|
86
|
+
savedMessageNext(savedReceiveMessage);
|
|
87
|
+
next(status);
|
|
88
|
+
}
|
|
89
|
+
} else {
|
|
90
|
+
savedMessageNext(savedReceiveMessage);
|
|
91
|
+
// TODO: For reasons that are completely unclear to me, if you pass a handcrafted
|
|
92
|
+
// status object here, node will magically just exit at the end of this line.
|
|
93
|
+
// No warning, no nothing. Here be dragons.
|
|
94
|
+
next(status);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
newCall.sendMessage(message);
|
|
99
|
+
newCall.halfClose();
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
if (retryOptions.retryableDecider(status)) {
|
|
103
|
+
setTimeout(() => retry(savedSendMessage, savedMetadata), backOffAmount(retries));
|
|
104
|
+
} else {
|
|
105
|
+
savedMessageNext(savedReceiveMessage);
|
|
106
|
+
next(status);
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
.build();
|
|
110
|
+
next(metadata, newListener);
|
|
111
|
+
})
|
|
112
|
+
.withSendMessage((message, next) => {
|
|
113
|
+
savedSendMessage = message;
|
|
114
|
+
next(message);
|
|
115
|
+
})
|
|
116
|
+
.build();
|
|
117
|
+
return new InterceptingCall(nextCall(options), requester);
|
|
118
|
+
};
|
|
119
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client for communicating with Temporal Server.
|
|
3
|
+
*
|
|
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
|
+
*
|
|
6
|
+
* ### Usage
|
|
7
|
+
* <!--SNIPSTART typescript-hello-client-->
|
|
8
|
+
* <!--SNIPEND-->
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
ActivityFailure,
|
|
14
|
+
ApplicationFailure,
|
|
15
|
+
CancelledFailure,
|
|
16
|
+
ChildWorkflowFailure,
|
|
17
|
+
DataConverter,
|
|
18
|
+
defaultPayloadConverter,
|
|
19
|
+
ProtoFailure,
|
|
20
|
+
ServerFailure,
|
|
21
|
+
TemporalFailure,
|
|
22
|
+
TerminatedFailure,
|
|
23
|
+
TimeoutFailure,
|
|
24
|
+
} from '@temporalio/common';
|
|
25
|
+
export { TLSConfig } from '@temporalio/internal-non-workflow-common';
|
|
26
|
+
export { RetryPolicy } from '@temporalio/internal-workflow-common';
|
|
27
|
+
export * from '@temporalio/internal-workflow-common/lib/errors';
|
|
28
|
+
export * from '@temporalio/internal-workflow-common/lib/interfaces';
|
|
29
|
+
export * from '@temporalio/internal-workflow-common/lib/workflow-handle';
|
|
30
|
+
export * from './async-completion-client';
|
|
31
|
+
export { Connection, ConnectionOptions, ConnectionOptionsWithDefaults, LOCAL_TARGET } from './connection';
|
|
32
|
+
export * from './errors';
|
|
33
|
+
export * from './grpc-retry';
|
|
34
|
+
export * from './interceptors';
|
|
35
|
+
export * from './types';
|
|
36
|
+
export * from './workflow-client';
|
|
37
|
+
export * from './workflow-options';
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Definitions for Connection interceptors.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { Headers, Next } from '@temporalio/internal-workflow-common';
|
|
8
|
+
import { temporal } from '@temporalio/proto';
|
|
9
|
+
import {
|
|
10
|
+
DescribeWorkflowExecutionResponse,
|
|
11
|
+
RequestCancelWorkflowExecutionResponse,
|
|
12
|
+
TerminateWorkflowExecutionResponse,
|
|
13
|
+
WorkflowExecution,
|
|
14
|
+
} from './types';
|
|
15
|
+
import { CompiledWorkflowOptions } from './workflow-options';
|
|
16
|
+
|
|
17
|
+
export { Next, Headers };
|
|
18
|
+
|
|
19
|
+
/** Input for WorkflowClientCallsInterceptor.start */
|
|
20
|
+
export interface WorkflowStartInput {
|
|
21
|
+
/** Name of Workflow to start */
|
|
22
|
+
readonly workflowType: string;
|
|
23
|
+
readonly headers: Headers;
|
|
24
|
+
readonly options: CompiledWorkflowOptions;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Input for WorkflowClientCallsInterceptor.signal */
|
|
28
|
+
export interface WorkflowSignalInput {
|
|
29
|
+
readonly signalName: string;
|
|
30
|
+
readonly args: unknown[];
|
|
31
|
+
readonly workflowExecution: WorkflowExecution;
|
|
32
|
+
readonly headers: Headers;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Input for WorkflowClientCallsInterceptor.signalWithStart */
|
|
36
|
+
export interface WorkflowSignalWithStartInput {
|
|
37
|
+
readonly workflowType: string;
|
|
38
|
+
readonly signalName: string;
|
|
39
|
+
readonly signalArgs: unknown[];
|
|
40
|
+
readonly headers: Headers;
|
|
41
|
+
readonly options: CompiledWorkflowOptions;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** Input for WorkflowClientCallsInterceptor.query */
|
|
45
|
+
export interface WorkflowQueryInput {
|
|
46
|
+
readonly queryType: string;
|
|
47
|
+
readonly args: unknown[];
|
|
48
|
+
readonly workflowExecution: WorkflowExecution;
|
|
49
|
+
readonly queryRejectCondition?: temporal.api.enums.v1.QueryRejectCondition;
|
|
50
|
+
readonly headers: Headers;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Input for WorkflowClientCallsInterceptor.terminate */
|
|
54
|
+
export interface WorkflowTerminateInput {
|
|
55
|
+
readonly workflowExecution: WorkflowExecution;
|
|
56
|
+
readonly reason?: string;
|
|
57
|
+
readonly details?: unknown[];
|
|
58
|
+
readonly firstExecutionRunId?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Input for WorkflowClientCallsInterceptor.cancel */
|
|
62
|
+
export interface WorkflowCancelInput {
|
|
63
|
+
readonly workflowExecution: WorkflowExecution;
|
|
64
|
+
readonly firstExecutionRunId?: string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Input for WorkflowClientCallsInterceptor.describe */
|
|
68
|
+
export interface WorkflowDescribeInput {
|
|
69
|
+
readonly workflowExecution: WorkflowExecution;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Implement any of these methods to intercept WorkflowClient outbound calls
|
|
74
|
+
*/
|
|
75
|
+
export interface WorkflowClientCallsInterceptor {
|
|
76
|
+
/**
|
|
77
|
+
* Intercept a service call to startWorkflowExecution
|
|
78
|
+
*
|
|
79
|
+
* If you implement this method,
|
|
80
|
+
* {@link signalWithStart} most likely needs to be implemented too
|
|
81
|
+
*/
|
|
82
|
+
start?: (input: WorkflowStartInput, next: Next<this, 'start'>) => Promise<string /* runId */>;
|
|
83
|
+
/**
|
|
84
|
+
* Intercept a service call to signalWorkflowExecution
|
|
85
|
+
*
|
|
86
|
+
* If you implement this method,
|
|
87
|
+
* {@link signalWithStart} most likely needs to be implemented too
|
|
88
|
+
*/
|
|
89
|
+
signal?: (input: WorkflowSignalInput, next: Next<this, 'signal'>) => Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Intercept a service call to signalWithStartWorkflowExecution
|
|
92
|
+
*/
|
|
93
|
+
signalWithStart?: (input: WorkflowSignalWithStartInput, next: Next<this, 'signalWithStart'>) => Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Intercept a service call to queryWorkflow
|
|
96
|
+
*/
|
|
97
|
+
query?: (input: WorkflowQueryInput, next: Next<this, 'query'>) => Promise<unknown>;
|
|
98
|
+
/**
|
|
99
|
+
* Intercept a service call to terminateWorkflowExecution
|
|
100
|
+
*/
|
|
101
|
+
terminate?: (
|
|
102
|
+
input: WorkflowTerminateInput,
|
|
103
|
+
next: Next<this, 'terminate'>
|
|
104
|
+
) => Promise<TerminateWorkflowExecutionResponse>;
|
|
105
|
+
/**
|
|
106
|
+
* Intercept a service call to requestCancelWorkflowExecution
|
|
107
|
+
*/
|
|
108
|
+
cancel?: (input: WorkflowCancelInput, next: Next<this, 'cancel'>) => Promise<RequestCancelWorkflowExecutionResponse>;
|
|
109
|
+
/**
|
|
110
|
+
* Intercept a service call to describeWorkflowExecution
|
|
111
|
+
*/
|
|
112
|
+
describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
interface WorkflowClientCallsInterceptorFactoryInput {
|
|
116
|
+
workflowId: string;
|
|
117
|
+
runId?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* A function that takes {@link CompiledWorkflowOptions} and returns an interceptor
|
|
122
|
+
*/
|
|
123
|
+
export interface WorkflowClientCallsInterceptorFactory {
|
|
124
|
+
(input: WorkflowClientCallsInterceptorFactoryInput): WorkflowClientCallsInterceptor;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* A mapping of interceptor type of a list of factory functions
|
|
129
|
+
*/
|
|
130
|
+
export interface WorkflowClientInterceptors {
|
|
131
|
+
calls?: WorkflowClientCallsInterceptorFactory[];
|
|
132
|
+
}
|
package/src/pkg.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// ../package.json is outside of the TS project rootDir which causes TS to complain about this import.
|
|
2
|
+
// We do not want to change the rootDir because it messes up the output structure.
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
import pkg from '../package.json';
|
|
6
|
+
|
|
7
|
+
export default pkg as { name: string; version: string };
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import type { SearchAttributes } from '@temporalio/internal-workflow-common';
|
|
2
|
+
import { temporal } from '@temporalio/proto';
|
|
3
|
+
import type * as grpc from '@grpc/grpc-js';
|
|
4
|
+
|
|
5
|
+
export interface WorkflowExecution {
|
|
6
|
+
workflowId: string;
|
|
7
|
+
runId?: string;
|
|
8
|
+
}
|
|
9
|
+
export type StartWorkflowExecutionRequest = temporal.api.workflowservice.v1.IStartWorkflowExecutionRequest;
|
|
10
|
+
export type GetWorkflowExecutionHistoryRequest = temporal.api.workflowservice.v1.IGetWorkflowExecutionHistoryRequest;
|
|
11
|
+
export type DescribeWorkflowExecutionResponse = temporal.api.workflowservice.v1.IDescribeWorkflowExecutionResponse;
|
|
12
|
+
export type TerminateWorkflowExecutionResponse = temporal.api.workflowservice.v1.ITerminateWorkflowExecutionResponse;
|
|
13
|
+
export type RequestCancelWorkflowExecutionResponse =
|
|
14
|
+
temporal.api.workflowservice.v1.IRequestCancelWorkflowExecutionResponse;
|
|
15
|
+
|
|
16
|
+
export type WorkflowExecutionStatusName =
|
|
17
|
+
| 'UNSPECIFIED'
|
|
18
|
+
| 'RUNNING'
|
|
19
|
+
| 'COMPLETED'
|
|
20
|
+
| 'FAILED'
|
|
21
|
+
| 'CANCELLED'
|
|
22
|
+
| 'TERMINATED'
|
|
23
|
+
| 'CONTINUED_AS_NEW'
|
|
24
|
+
| 'TIMED_OUT'
|
|
25
|
+
| 'UNKNOWN'; // UNKNOWN is reserved for future enum values
|
|
26
|
+
|
|
27
|
+
export interface WorkflowExecutionDescription {
|
|
28
|
+
type: string;
|
|
29
|
+
workflowId: string;
|
|
30
|
+
runId: string;
|
|
31
|
+
taskQueue: string;
|
|
32
|
+
status: { code: temporal.api.enums.v1.WorkflowExecutionStatus; name: WorkflowExecutionStatusName };
|
|
33
|
+
historyLength: Long;
|
|
34
|
+
startTime: Date;
|
|
35
|
+
executionTime?: Date;
|
|
36
|
+
closeTime?: Date;
|
|
37
|
+
memo?: Record<string, unknown>;
|
|
38
|
+
searchAttributes: SearchAttributes;
|
|
39
|
+
parentExecution?: Required<temporal.api.common.v1.IWorkflowExecution>;
|
|
40
|
+
raw: DescribeWorkflowExecutionResponse;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type WorkflowService = temporal.api.workflowservice.v1.WorkflowService;
|
|
44
|
+
export const { WorkflowService } = temporal.api.workflowservice.v1;
|
|
45
|
+
export type OperatorService = temporal.api.operatorservice.v1.OperatorService;
|
|
46
|
+
export const { OperatorService } = temporal.api.operatorservice.v1;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Mapping of string to valid gRPC metadata value
|
|
50
|
+
*/
|
|
51
|
+
export type Metadata = Record<string, grpc.MetadataValue>;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* User defined context for gRPC client calls
|
|
55
|
+
*/
|
|
56
|
+
export interface CallContext {
|
|
57
|
+
/**
|
|
58
|
+
* {@link Deadline | https://grpc.io/blog/deadlines/} for gRPC client calls
|
|
59
|
+
*/
|
|
60
|
+
deadline?: number | Date;
|
|
61
|
+
/**
|
|
62
|
+
* Metadata to set on gRPC requests
|
|
63
|
+
*/
|
|
64
|
+
metadata?: Metadata;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Connection interface used by high level SDK clients.
|
|
69
|
+
*
|
|
70
|
+
* NOTE: Currently the SDK only supports grpc-js based connection but in the future
|
|
71
|
+
* we might support grpc-web and native Rust connections.
|
|
72
|
+
*/
|
|
73
|
+
export interface ConnectionLike {
|
|
74
|
+
workflowService: WorkflowService;
|
|
75
|
+
close(): Promise<void>;
|
|
76
|
+
ensureConnected(): Promise<void>;
|
|
77
|
+
/**
|
|
78
|
+
* Set the deadline for any service requests executed in `fn`'s scope.
|
|
79
|
+
*/
|
|
80
|
+
withDeadline<R>(deadline: number | Date, fn: () => Promise<R>): Promise<R>;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Set metadata for any service requests executed in `fn`'s scope.
|
|
84
|
+
*
|
|
85
|
+
* @returns returned value of `fn`
|
|
86
|
+
*/
|
|
87
|
+
withMetadata<R>(metadata: Metadata, fn: () => Promise<R>): Promise<R>;
|
|
88
|
+
}
|