Skip to main content

Namespace: client

Client for communicating with the Temporal service.

Interact with workflows using WorkflowClient or call GRPC methods directly using Connection.service.

Usage

import { Connection, WorkflowClient } from '@temporalio/client';
import { example } from './workflows';
import { nanoid } from 'nanoid';

async function run() {
const connection = new Connection({
// // 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.service, {
// 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

Interfaces

References

DataConverter

Re-exports DataConverter


Headers

Re-exports Headers


Next

Re-exports Next


defaultPayloadConverter

Re-exports defaultPayloadConverter

Type aliases

AsyncCompletionClientOptionsWithDefaults

Ƭ AsyncCompletionClientOptionsWithDefaults: Required<AsyncCompletionClientOptions>


CommonWorkflowOptions

Ƭ CommonWorkflowOptions: BaseWorkflowOptions & WorkflowDurationOptions


ConnectionOptionsWithDefaults

Ƭ ConnectionOptionsWithDefaults: Required<Omit<ConnectionOptions, "tls">>


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


ProtoFailure

Ƭ ProtoFailure: IFailure


RequestCancelWorkflowExecutionResponse

Ƭ RequestCancelWorkflowExecutionResponse: IRequestCancelWorkflowExecutionResponse


StartWorkflowExecutionRequest

Ƭ StartWorkflowExecutionRequest: IStartWorkflowExecutionRequest


TerminateWorkflowExecutionResponse

Ƭ TerminateWorkflowExecutionResponse: ITerminateWorkflowExecutionResponse


WithCompiledWorkflowDurationOptions

Ƭ WithCompiledWorkflowDurationOptions<T>: Replace<T, { workflowExecutionTimeout?: IDuration ; workflowRunTimeout?: IDuration ; workflowTaskTimeout?: IDuration }>

Type parameters

NameType
Textends WorkflowDurationOptions

WithWorkflowArgs

Ƭ WithWorkflowArgs<W, T>: T & Parameters<W> extends [any, ...any[]] ? { args: Parameters<W> } : { args?: Parameters<W> }

Type parameters

NameType
Wextends Workflow
TT

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
NameType
...argsany[]
Returns

WorkflowReturnType


WorkflowClientOptionsWithDefaults

Ƭ WorkflowClientOptionsWithDefaults: Required<WorkflowClientOptions>


WorkflowQueryType

Ƭ WorkflowQueryType: (...args: any[]) => any

Type declaration

▸ (...args): any

Parameters
NameType
...argsany[]
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

NameType
Wextends 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
NameType
...argsany[]
Returns

Promise<void> | void


WorkflowStartOptions

Ƭ WorkflowStartOptions<T>: WithWorkflowArgs<T, WorkflowOptions>

Options for starting a Workflow

Type parameters

NameType
Textends Workflow = Workflow

Variables

LOCAL_DOCKER_TARGET

Const LOCAL_DOCKER_TARGET: "127.0.0.1:7233"


WorkflowService

WorkflowService: typeof WorkflowService

Functions

backOffAmount

backOffAmount(attempt): number

Return backoff amount in ms

Parameters

NameType
attemptnumber

Returns

number


compileWorkflowOptions

compileWorkflowOptions<T>(options): WithCompiledWorkflowDurationOptions<T>

Type parameters

NameType
Textends WorkflowDurationOptions

Parameters

NameType
optionsT

Returns

WithCompiledWorkflowDurationOptions<T>


defaultAsyncCompletionClientOptions

defaultAsyncCompletionClientOptions(): AsyncCompletionClientOptionsWithDefaults

Returns

AsyncCompletionClientOptionsWithDefaults


defaultConnectionOpts

defaultConnectionOpts(): ConnectionOptionsWithDefaults

Returns

ConnectionOptionsWithDefaults


defaultGrpcRetryOptions

defaultGrpcRetryOptions(): GrpcRetryOptions

Returns

GrpcRetryOptions


defaultWorkflowClientOptions

defaultWorkflowClientOptions(): WorkflowClientOptionsWithDefaults

Returns

WorkflowClientOptionsWithDefaults


isRetryableError

isRetryableError(status): boolean

Parameters

NameType
statusStatusObject

Returns

boolean


isServerErrorResponse

isServerErrorResponse(err): err is ServerErrorResponse

Type assertion helper, assertion is mostly empty because any additional properties are optional.

Parameters

NameType
errunknown

Returns

err is ServerErrorResponse


makeGrpcRetryInterceptor

makeGrpcRetryInterceptor(retryOptions): Interceptor

Returns a GRPC interceptor that will perform automatic retries for some types of failed calls

Parameters

NameTypeDescription
retryOptionsGrpcRetryOptionsOptions for the retry interceptor

Returns

Interceptor