@@ -68,6 +68,8 @@ import {
6868 DescribeWorkflowExecutionResponse ,
6969 encodeQueryRejectCondition ,
7070 GetWorkflowExecutionHistoryRequest ,
71+ InternalConnectionLike ,
72+ InternalConnectionLikeSymbol ,
7173 QueryRejectCondition ,
7274 RequestCancelWorkflowExecutionResponse ,
7375 StartWorkflowExecutionRequest ,
@@ -95,6 +97,7 @@ import {
9597import { mapAsyncIterable } from './iterators-utils' ;
9698import { WorkflowUpdateStage , encodeWorkflowUpdateStage } from './workflow-update-stage' ;
9799import { InternalWorkflowStartOptionsSymbol , InternalWorkflowStartOptions } from './internal' ;
100+ import { adaptWorkflowClientInterceptor } from './interceptor-adapters' ;
98101
99102const UpdateWorkflowExecutionLifecycleStage = temporal . api . enums . v1 . UpdateWorkflowExecutionLifecycleStage ;
100103
@@ -529,43 +532,8 @@ export class WorkflowClient extends BaseClient {
529532 assertRequiredWorkflowOptions ( options ) ;
530533 const compiledOptions = compileWorkflowOptions ( ensureArgs ( options ) ) ;
531534
532- // Adapt legacy `start` interceptors to the new `startWithDetails` interface.
533- const adaptedInterceptors : WorkflowClientInterceptor [ ] = interceptors . map ( ( i ) => {
534- // If it already has the new method, or doesn't have the legacy one, no adaptation is needed.
535- if ( i . startWithDetails || ! i . start ) {
536- return i ;
537- }
538-
539- // This interceptor has a legacy `start` but not `startWithDetails`. We'll adapt it.
540- return {
541- ...i ,
542- startWithDetails : async ( input , next ) : Promise < WorkflowStartOutput > => {
543- let downstreamOut : WorkflowStartOutput | undefined ;
544-
545- // Patched `next` for legacy `start` interceptors.
546- // Captures the full `WorkflowStartOutput` while returning `runId` as a string.
547- const patchedNext = async ( patchedInput : WorkflowStartInput ) : Promise < string > => {
548- downstreamOut = await next ( patchedInput ) ;
549- return downstreamOut . runId ;
550- } ;
551-
552- const runIdFromLegacyInterceptor = await i . start ! ( input , patchedNext ) ;
553-
554- // If the interceptor short-circuited (didn't call `next`), `downstreamOut` will be undefined.
555- // In that case, we can't have an eager start.
556- if ( downstreamOut === undefined ) {
557- return { runId : runIdFromLegacyInterceptor , eagerlyStarted : false } ;
558- }
559-
560- // If `next` was called, honor the `runId` from the legacy interceptor but preserve
561- // the `eagerlyStarted` status from the actual downstream call.
562- return { ...downstreamOut , runId : runIdFromLegacyInterceptor } ;
563- } ,
564- } ;
565- } ) ;
566-
567535 const startWithDetails = composeInterceptors (
568- adaptedInterceptors ,
536+ interceptors ,
569537 'startWithDetails' ,
570538 this . _startWorkflowHandler . bind ( this )
571539 ) ;
@@ -1326,8 +1294,10 @@ export class WorkflowClient extends BaseClient {
13261294 const { options : opts , workflowType, headers } = input ;
13271295 const { identity, namespace } = this . options ;
13281296 const internalOptions = ( opts as InternalWorkflowStartOptions ) [ InternalWorkflowStartOptionsSymbol ] ;
1297+ const supportsEagerStart = ( this . connection as InternalConnectionLike ) ?. [ InternalConnectionLikeSymbol ]
1298+ ?. supportsEagerStart ;
13291299
1330- if ( opts . requestEagerStart && ! ( ' supportsEagerStart' in this . connection && this . connection . supportsEagerStart ) ) {
1300+ if ( opts . requestEagerStart && ! supportsEagerStart ) {
13311301 throw new Error (
13321302 'Eager workflow start requires a NativeConnection shared between client and worker. ' +
13331303 'Pass a NativeConnection via ClientOptions.connection, or disable requestEagerStart.'
@@ -1681,7 +1651,11 @@ export class WorkflowClient extends BaseClient {
16811651 const factories = ( this . options . interceptors as WorkflowClientInterceptors ) . calls ?? [ ] ;
16821652 return factories . map ( ( ctor ) => ctor ( { workflowId, runId } ) ) ;
16831653 }
1684- return Array . isArray ( this . options . interceptors ) ? ( this . options . interceptors as WorkflowClientInterceptor [ ] ) : [ ] ;
1654+ const interceptors = Array . isArray ( this . options . interceptors )
1655+ ? ( this . options . interceptors as WorkflowClientInterceptor [ ] )
1656+ : [ ] ;
1657+ // Apply adapters to workflow client interceptors.
1658+ return interceptors . map ( ( i ) => adaptWorkflowClientInterceptor ( i ) ) ;
16851659 }
16861660}
16871661
0 commit comments