@@ -38,7 +38,7 @@ import { Connection } from './connection';
38
38
import { isServerErrorResponse , ServiceError , WorkflowContinuedAsNewError , WorkflowFailedError } from './errors' ;
39
39
import {
40
40
WorkflowCancelInput ,
41
- WorkflowClientCallsInterceptor ,
41
+ WorkflowClientInterceptor ,
42
42
WorkflowClientInterceptors ,
43
43
WorkflowDescribeInput ,
44
44
WorkflowQueryInput ,
@@ -175,7 +175,8 @@ export interface WorkflowClientOptions {
175
175
*
176
176
* Useful for injecting auth headers and tracing Workflow executions
177
177
*/
178
- interceptors ?: WorkflowClientInterceptors ;
178
+ // eslint-disable-next-line deprecation/deprecation
179
+ interceptors ?: WorkflowClientInterceptors | WorkflowClientInterceptor [ ] ;
179
180
180
181
/**
181
182
* Identity to report to the server
@@ -223,7 +224,7 @@ export function defaultWorkflowClientOptions(): WorkflowClientOptionsWithDefault
223
224
dataConverter : { } ,
224
225
// The equivalent in Java is ManagementFactory.getRuntimeMXBean().getName()
225
226
identity : `${ process . pid } @${ os . hostname ( ) } ` ,
226
- interceptors : { } ,
227
+ interceptors : [ ] ,
227
228
namespace : 'default' ,
228
229
queryRejectCondition : temporal . api . enums . v1 . QueryRejectCondition . QUERY_REJECT_CONDITION_UNSPECIFIED ,
229
230
} ;
@@ -274,7 +275,7 @@ export interface GetWorkflowHandleOptions extends WorkflowResultOptions {
274
275
interface WorkflowHandleOptions extends GetWorkflowHandleOptions {
275
276
workflowId : string ;
276
277
runId ?: string ;
277
- interceptors : WorkflowClientCallsInterceptor [ ] ;
278
+ interceptors : WorkflowClientInterceptor [ ] ;
278
279
/**
279
280
* A runId to use for getting the workflow's result.
280
281
*
@@ -362,7 +363,7 @@ export class WorkflowClient {
362
363
protected async _start < T extends Workflow > (
363
364
workflowTypeOrFunc : string | T ,
364
365
options : WithWorkflowArgs < T , WorkflowOptions > ,
365
- interceptors : WorkflowClientCallsInterceptor [ ]
366
+ interceptors : WorkflowClientInterceptor [ ]
366
367
) : Promise < string > {
367
368
const workflowType = typeof workflowTypeOrFunc === 'string' ? workflowTypeOrFunc : workflowTypeOrFunc . name ;
368
369
assertRequiredWorkflowOptions ( options ) ;
@@ -386,7 +387,7 @@ export class WorkflowClient {
386
387
protected async _signalWithStart < T extends Workflow , SA extends any [ ] > (
387
388
workflowTypeOrFunc : string | T ,
388
389
options : WithWorkflowArgs < T , WorkflowSignalWithStartOptions < SA > > ,
389
- interceptors : WorkflowClientCallsInterceptor [ ]
390
+ interceptors : WorkflowClientInterceptor [ ]
390
391
) : Promise < string > {
391
392
const workflowType = typeof workflowTypeOrFunc === 'string' ? workflowTypeOrFunc : workflowTypeOrFunc . name ;
392
393
const { signal, signalArgs, ...rest } = options ;
@@ -418,8 +419,7 @@ export class WorkflowClient {
418
419
options : WorkflowStartOptions < T >
419
420
) : Promise < WorkflowHandleWithFirstExecutionRunId < T > > {
420
421
const { workflowId } = options ;
421
- // Cast is needed because it's impossible to deduce the type in this situation
422
- const interceptors = ( this . options . interceptors . calls ?? [ ] ) . map ( ( ctor ) => ctor ( { workflowId } ) ) ;
422
+ const interceptors = this . getOrMakeInterceptors ( workflowId ) ;
423
423
const runId = await this . _start ( workflowTypeOrFunc , { ...options , workflowId } , interceptors ) ;
424
424
// runId is not used in handles created with `start*` calls because these
425
425
// handles should allow interacting with the workflow if it continues as new.
@@ -446,7 +446,7 @@ export class WorkflowClient {
446
446
options : WithWorkflowArgs < WorkflowFn , WorkflowSignalWithStartOptions < SignalArgs > >
447
447
) : Promise < WorkflowHandleWithSignaledRunId < WorkflowFn > > {
448
448
const { workflowId } = options ;
449
- const interceptors = ( this . options . interceptors . calls ?? [ ] ) . map ( ( ctor ) => ctor ( { workflowId } ) ) ;
449
+ const interceptors = this . getOrMakeInterceptors ( workflowId ) ;
450
450
const runId = await this . _signalWithStart ( workflowTypeOrFunc , options , interceptors ) ;
451
451
// runId is not used in handles created with `start*` calls because these
452
452
// handles should allow interacting with the workflow if it continues as new.
@@ -472,7 +472,7 @@ export class WorkflowClient {
472
472
options : WorkflowStartOptions < T >
473
473
) : Promise < WorkflowResultType < T > > {
474
474
const { workflowId } = options ;
475
- const interceptors = ( this . options . interceptors . calls ?? [ ] ) . map ( ( ctor ) => ctor ( { workflowId } ) ) ;
475
+ const interceptors = this . getOrMakeInterceptors ( workflowId ) ;
476
476
await this . _start ( workflowTypeOrFunc , options , interceptors ) ;
477
477
return await this . result ( workflowId , undefined , {
478
478
...options ,
@@ -912,7 +912,7 @@ export class WorkflowClient {
912
912
runId ?: string ,
913
913
options ?: GetWorkflowHandleOptions
914
914
) : WorkflowHandle < T > {
915
- const interceptors = ( this . options . interceptors . calls ?? [ ] ) . map ( ( ctor ) => ctor ( { workflowId, runId } ) ) ;
915
+ const interceptors = this . getOrMakeInterceptors ( workflowId , runId ) ;
916
916
917
917
return this . _createWorkflowHandle ( {
918
918
workflowId,
@@ -951,6 +951,15 @@ export class WorkflowClient {
951
951
if ( nextPageToken == null || nextPageToken . length == 0 ) break ;
952
952
}
953
953
}
954
+
955
+ protected getOrMakeInterceptors ( workflowId : string , runId ?: string ) : WorkflowClientInterceptor [ ] {
956
+ if ( typeof this . options . interceptors === 'object' && 'calls' in this . options . interceptors ) {
957
+ // eslint-disable-next-line deprecation/deprecation
958
+ const factories = ( this . options . interceptors as WorkflowClientInterceptors ) . calls ?? [ ] ;
959
+ return factories . map ( ( ctor ) => ctor ( { workflowId, runId } ) ) ;
960
+ }
961
+ return Array . isArray ( this . options . interceptors ) ? ( this . options . interceptors as WorkflowClientInterceptor [ ] ) : [ ] ;
962
+ }
954
963
}
955
964
956
965
export class QueryRejectedError extends Error {
0 commit comments