@@ -68,6 +68,8 @@ import {
6868 DescribeWorkflowExecutionResponse ,
6969 encodeQueryRejectCondition ,
7070 GetWorkflowExecutionHistoryRequest ,
71+ InternalConnectionLike ,
72+ InternalConnectionLikeSymbol ,
7173 QueryRejectCondition ,
7274 RequestCancelWorkflowExecutionResponse ,
7375 StartWorkflowExecutionRequest ,
@@ -94,6 +96,7 @@ import {
9496} from './base-client' ;
9597import { mapAsyncIterable } from './iterators-utils' ;
9698import { WorkflowUpdateStage , encodeWorkflowUpdateStage } from './workflow-update-stage' ;
99+ import { adaptWorkflowClientInterceptor } from './interceptor-adapters' ;
97100
98101const UpdateWorkflowExecutionLifecycleStage = temporal . api . enums . v1 . UpdateWorkflowExecutionLifecycleStage ;
99102
@@ -528,43 +531,8 @@ export class WorkflowClient extends BaseClient {
528531 assertRequiredWorkflowOptions ( options ) ;
529532 const compiledOptions = compileWorkflowOptions ( ensureArgs ( options ) ) ;
530533
531- // Adapt legacy `start` interceptors to the new `startWithDetails` interface.
532- const adaptedInterceptors : WorkflowClientInterceptor [ ] = interceptors . map ( ( i ) => {
533- // If it already has the new method, or doesn't have the legacy one, no adaptation is needed.
534- if ( i . startWithDetails || ! i . start ) {
535- return i ;
536- }
537-
538- // This interceptor has a legacy `start` but not `startWithDetails`. We'll adapt it.
539- return {
540- ...i ,
541- startWithDetails : async ( input , next ) : Promise < WorkflowStartOutput > => {
542- let downstreamOut : WorkflowStartOutput | undefined ;
543-
544- // Patched `next` for legacy `start` interceptors.
545- // Captures the full `WorkflowStartOutput` while returning `runId` as a string.
546- const patchedNext = async ( patchedInput : WorkflowStartInput ) : Promise < string > => {
547- downstreamOut = await next ( patchedInput ) ;
548- return downstreamOut . runId ;
549- } ;
550-
551- const runIdFromLegacyInterceptor = await i . start ! ( input , patchedNext ) ;
552-
553- // If the interceptor short-circuited (didn't call `next`), `downstreamOut` will be undefined.
554- // In that case, we can't have an eager start.
555- if ( downstreamOut === undefined ) {
556- return { runId : runIdFromLegacyInterceptor , eagerlyStarted : false } ;
557- }
558-
559- // If `next` was called, honor the `runId` from the legacy interceptor but preserve
560- // the `eagerlyStarted` status from the actual downstream call.
561- return { ...downstreamOut , runId : runIdFromLegacyInterceptor } ;
562- } ,
563- } ;
564- } ) ;
565-
566534 const startWithDetails = composeInterceptors (
567- adaptedInterceptors ,
535+ interceptors ,
568536 'startWithDetails' ,
569537 this . _startWorkflowHandler . bind ( this )
570538 ) ;
@@ -1320,8 +1288,10 @@ export class WorkflowClient extends BaseClient {
13201288 protected async createStartWorkflowRequest ( input : WorkflowStartInput ) : Promise < StartWorkflowExecutionRequest > {
13211289 const { options : opts , workflowType, headers } = input ;
13221290 const { identity, namespace } = this . options ;
1291+ const supportsEagerStart = ( this . connection as InternalConnectionLike ) ?. [ InternalConnectionLikeSymbol ]
1292+ ?. supportsEagerStart ;
13231293
1324- if ( opts . requestEagerStart && ! ( ' supportsEagerStart' in this . connection && this . connection . supportsEagerStart ) ) {
1294+ if ( opts . requestEagerStart && ! supportsEagerStart ) {
13251295 throw new Error (
13261296 'Eager workflow start requires a NativeConnection shared between client and worker. ' +
13271297 'Pass a NativeConnection via ClientOptions.connection, or disable requestEagerStart.'
@@ -1674,7 +1644,11 @@ export class WorkflowClient extends BaseClient {
16741644 const factories = ( this . options . interceptors as WorkflowClientInterceptors ) . calls ?? [ ] ;
16751645 return factories . map ( ( ctor ) => ctor ( { workflowId, runId } ) ) ;
16761646 }
1677- return Array . isArray ( this . options . interceptors ) ? ( this . options . interceptors as WorkflowClientInterceptor [ ] ) : [ ] ;
1647+ const interceptors = Array . isArray ( this . options . interceptors )
1648+ ? ( this . options . interceptors as WorkflowClientInterceptor [ ] )
1649+ : [ ] ;
1650+ // Apply adapters to workflow client interceptors.
1651+ return interceptors . map ( ( i ) => adaptWorkflowClientInterceptor ( i ) ) ;
16781652 }
16791653}
16801654
0 commit comments