Namespace: client
Client for communicating with the Temporal service.
Interact with workflows using WorkflowClient or call GRPC methods directly using Connection.workflowService.
Usage
import { Connection, WorkflowClient } from '@temporalio/client';
import { example } from './workflows';
import { nanoid } from 'nanoid';
async function run() {
const connection = await Connection.connect({
// // Connect to localhost with default ConnectionOptions.
// // In production, pass options to the Connection constructor to configure TLS and other settings:
// address: 'foo.bar.tmprl.cloud', // as provisioned
// tls: {} // as provisioned
});
const client = new WorkflowClient({
connection,
// namespace: 'default', // change if you have a different namespace
});
const handle = await client.start(example, {
args: ['Temporal'], // type inference works! args: [name: string]
taskQueue: 'hello-world',
// in practice, use a meaningful business id, eg customerId or transactionId
workflowId: 'workflow-' + nanoid(),
});
console.log(`Started workflow ${handle.workflowId}`);
// optional: wait for client result
console.log(await handle.result()); // Hello, Temporal!
}
run().catch((err) => {
console.error(err);
process.exit(1);
});
Enumerations
Classes
- ActivityCancelledError
- ActivityCompletionError
- ActivityFailure
- ActivityNotFoundError
- ApplicationFailure
- AsyncCompletionClient
- CancelledFailure
- ChildWorkflowFailure
- Connection
- IllegalStateError
- PayloadConverterError
- QueryRejectedError
- ServerFailure
- ServiceError
- TemporalFailure
- TerminatedFailure
- TimeoutFailure
- ValueError
- WorkflowClient
- WorkflowContinuedAsNewError
- WorkflowExecutionAlreadyStartedError
- WorkflowFailedError
- WorkflowNotFoundError
Interfaces
- AsyncCompletionClientOptions
- BaseWorkflowHandle
- BaseWorkflowOptions
- CallContext
- CompiledWorkflowOptions
- ConnectionLike
- ConnectionOptions
- FullActivityId
- GetWorkflowHandleOptions
- GrpcRetryOptions
- QueryDefinition
- RetryPolicy
- SignalDefinition
- TLSConfig
- WorkflowCancelInput
- WorkflowClientCallsInterceptor
- WorkflowClientCallsInterceptorFactory
- WorkflowClientInterceptors
- WorkflowClientOptions
- WorkflowDescribeInput
- WorkflowDurationOptions
- WorkflowExecution
- WorkflowExecutionDescription
- WorkflowHandle
- WorkflowHandleWithFirstExecutionRunId
- WorkflowHandleWithSignaledRunId
- WorkflowOptions
- WorkflowQueryInput
- WorkflowResultOptions
- WorkflowSignalInput
- WorkflowSignalWithStartInput
- WorkflowSignalWithStartOptions
- WorkflowStartInput
- WorkflowTerminateInput
References
DataConverter
Re-exports DataConverter
Headers
Re-exports Headers
Next
Re-exports Next
defaultPayloadConverter
Re-exports defaultPayloadConverter
Type aliases
AsyncCompletionClientOptionsWithDefaults
Ƭ AsyncCompletionClientOptionsWithDefaults: Replace
<Required
<AsyncCompletionClientOptions
>, { connection?
: ConnectionLike
}>
CommonWorkflowOptions
Ƭ CommonWorkflowOptions: BaseWorkflowOptions
& WorkflowDurationOptions
ConnectionOptionsWithDefaults
Ƭ ConnectionOptionsWithDefaults: Required
<Omit
<ConnectionOptions
, "tls"
| "connectTimeout"
>> & { connectTimeoutMs
: number
}
DescribeWorkflowExecutionResponse
Ƭ DescribeWorkflowExecutionResponse: IDescribeWorkflowExecutionResponse
GetWorkflowExecutionHistoryRequest
Ƭ GetWorkflowExecutionHistoryRequest: IGetWorkflowExecutionHistoryRequest
LoadedWorkflowClientOptions
Ƭ LoadedWorkflowClientOptions: WorkflowClientOptionsWithDefaults
& { loadedDataConverter
: LoadedDataConverter
}
Metadata
Ƭ Metadata: Record
<string
, grpc.MetadataValue
>
Mapping of string to valid gRPC metadata value
OperatorService
Ƭ OperatorService: OperatorService
Payload
Ƭ Payload: IPayload
ProtoFailure
Ƭ ProtoFailure: IFailure
RequestCancelWorkflowExecutionResponse
Ƭ RequestCancelWorkflowExecutionResponse: IRequestCancelWorkflowExecutionResponse
SearchAttributeValue
Ƭ SearchAttributeValue: string
[] | number
[] | boolean
[] | Date
[]
SearchAttributes
Ƭ SearchAttributes: Record
<string
, SearchAttributeValue
| undefined
>
If another SDK creates a Search Attribute that's not an array, we wrap it in an array.
Dates are serialized as ISO strings.
StartWorkflowExecutionRequest
Ƭ StartWorkflowExecutionRequest: IStartWorkflowExecutionRequest
TerminateWorkflowExecutionResponse
Ƭ TerminateWorkflowExecutionResponse: ITerminateWorkflowExecutionResponse
WithCompiledWorkflowOptions
Ƭ WithCompiledWorkflowOptions<T
>: Replace
<T
, { workflowExecutionTimeout?
: IDuration
; workflowRunTimeout?
: IDuration
; workflowTaskTimeout?
: IDuration
}>
Type parameters
Name | Type |
---|---|
T | extends CommonWorkflowOptions |
WithWorkflowArgs
Ƭ WithWorkflowArgs<W
, T
>: T
& Parameters
<W
> extends [any
, ...any[]] ? { args
: Parameters
<W
> } : { args?
: Parameters
<W
> }
Type parameters
Name | Type |
---|---|
W | extends Workflow |
T | T |
Workflow
Ƭ Workflow: (...args
: any
[]) => WorkflowReturnType
Type declaration
▸ (...args
): WorkflowReturnType
Broad Workflow function definition, specific Workflows will typically use a narrower type definition, e.g:
export async function myWorkflow(arg1: number, arg2: string): Promise<string>;
Parameters
Name | Type |
---|---|
...args | any [] |
Returns
WorkflowClientOptionsWithDefaults
Ƭ WorkflowClientOptionsWithDefaults: Replace
<Required
<WorkflowClientOptions
>, { connection?
: ConnectionLike
}>
WorkflowExecutionStatusName
Ƭ WorkflowExecutionStatusName: "UNSPECIFIED"
| "RUNNING"
| "COMPLETED"
| "FAILED"
| "CANCELLED"
| "TERMINATED"
| "CONTINUED_AS_NEW"
| "TIMED_OUT"
| "UNKNOWN"
WorkflowQueryType
Ƭ WorkflowQueryType: (...args
: any
[]) => any
Type declaration
▸ (...args
): any
Parameters
Name | Type |
---|---|
...args | any [] |
Returns
any
WorkflowResultType
Ƭ WorkflowResultType<W
>: ReturnType
<W
> extends Promise
<infer R> ? R
: never
Get the "unwrapped" return type (without Promise) of the execute handler from Workflow type W
Type parameters
Name | Type |
---|---|
W | extends Workflow |
WorkflowReturnType
Ƭ WorkflowReturnType: Promise
<any
>
Type that can be returned from a Workflow execute
function
WorkflowService
Ƭ WorkflowService: WorkflowService
WorkflowSignalType
Ƭ WorkflowSignalType: (...args
: any
[]) => Promise
<void
> | void
Type declaration
▸ (...args
): Promise
<void
> | void
Parameters
Name | Type |
---|---|
...args | any [] |
Returns
Promise
<void
> | void
WorkflowStartOptions
Ƭ WorkflowStartOptions<T
>: WithWorkflowArgs
<T
, WorkflowOptions
>
Options for starting a Workflow
Type parameters
Name | Type |
---|---|
T | extends Workflow = Workflow |
Variables
LOCAL_TARGET
• Const
LOCAL_TARGET: "127.0.0.1:7233"
OperatorService
• OperatorService: typeof OperatorService
WorkflowService
• WorkflowService: typeof WorkflowService
Functions
backOffAmount
▸ backOffAmount(attempt
): number
Return backoff amount in ms
Parameters
Name | Type |
---|---|
attempt | number |
Returns
number
compileWorkflowOptions
▸ compileWorkflowOptions<T
>(options
): WithCompiledWorkflowOptions
<T
>
Type parameters
Name | Type |
---|---|
T | extends CommonWorkflowOptions |
Parameters
Name | Type |
---|---|
options | T |
Returns
WithCompiledWorkflowOptions
<T
>
defaultAsyncCompletionClientOptions
▸ defaultAsyncCompletionClientOptions(): AsyncCompletionClientOptionsWithDefaults
Returns
AsyncCompletionClientOptionsWithDefaults
defaultGrpcRetryOptions
▸ defaultGrpcRetryOptions(): GrpcRetryOptions
Returns
defaultWorkflowClientOptions
▸ defaultWorkflowClientOptions(): WorkflowClientOptionsWithDefaults
Returns
WorkflowClientOptionsWithDefaults
errorCode
▸ errorCode(error
): string
| undefined
Get error code from an Error or return undefined
Parameters
Name | Type |
---|---|
error | unknown |
Returns
string
| undefined
errorMessage
▸ errorMessage(err
): string
| undefined
Get error message from an Error or string or return undefined
Parameters
Name | Type |
---|---|
err | unknown |
Returns
string
| undefined
isRetryableError
▸ isRetryableError(status
): boolean
Parameters
Name | Type |
---|---|
status | StatusObject |
Returns
boolean
isServerErrorResponse
▸ isServerErrorResponse(err
): err is ServerErrorResponse
Type assertion helper, assertion is mostly empty because any additional properties are optional.
Parameters
Name | Type |
---|---|
err | unknown |
Returns
err is ServerErrorResponse
makeGrpcRetryInterceptor
▸ makeGrpcRetryInterceptor(retryOptions
): Interceptor
Returns a GRPC interceptor that will perform automatic retries for some types of failed calls
Parameters
Name | Type | Description |
---|---|---|
retryOptions | GrpcRetryOptions | Options for the retry interceptor |
Returns
Interceptor