@@ -23,7 +23,9 @@ import {
2323 encodeWorkflowIdConflictPolicy ,
2424 WorkflowIdConflictPolicy ,
2525 compilePriority ,
26+ LoadedDataConverter ,
2627} from '@temporalio/common' ;
28+ import { withSerializationContext } from '@temporalio/common/lib/converter/serialization-context' ;
2729import { encodeUserMetadata } from '@temporalio/common/lib/internal-non-workflow/codec-helpers' ;
2830import { encodeUnifiedSearchAttributes } from '@temporalio/common/lib/converter/payload-search-attributes' ;
2931import { composeInterceptors } from '@temporalio/common/lib/interceptors' ;
@@ -523,6 +525,14 @@ export class WorkflowClient extends BaseClient {
523525 return this . connection . workflowService ;
524526 }
525527
528+ protected dataConverterWithWorkflowContext ( workflowId : string ) : LoadedDataConverter {
529+ return withSerializationContext ( this . dataConverter , {
530+ type : 'workflow' ,
531+ namespace : this . options . namespace ,
532+ workflowId,
533+ } ) ;
534+ }
535+
526536 protected async _start < T extends Workflow > (
527537 workflowTypeOrFunc : string | T ,
528538 options : WorkflowStartOptions < T > ,
@@ -789,6 +799,7 @@ export class WorkflowClient extends BaseClient {
789799 runId ?: string ,
790800 opts ?: WorkflowResultOptions
791801 ) : Promise < WorkflowResultType < T > > {
802+ const dataConverter = this . dataConverterWithWorkflowContext ( workflowId ) ;
792803 const followRuns = opts ?. followRuns ?? true ;
793804 const execution : temporal . api . common . v1 . IWorkflowExecution = { workflowId, runId } ;
794805 const req : GetWorkflowExecutionHistoryRequest = {
@@ -828,7 +839,7 @@ export class WorkflowClient extends BaseClient {
828839 // Note that we can only return one value from our workflow function in JS.
829840 // Ignore any other payloads in result
830841 const [ result ] = await decodeArrayFromPayloads (
831- this . dataConverter ,
842+ dataConverter ,
832843 ev . workflowExecutionCompletedEventAttributes . result ?. payloads
833844 ) ;
834845 return result as any ;
@@ -841,16 +852,13 @@ export class WorkflowClient extends BaseClient {
841852 const { failure, retryState } = ev . workflowExecutionFailedEventAttributes ;
842853 throw new WorkflowFailedError (
843854 'Workflow execution failed' ,
844- await decodeOptionalFailureToOptionalError ( this . dataConverter , failure ) ,
855+ await decodeOptionalFailureToOptionalError ( dataConverter , failure ) ,
845856 decodeRetryState ( retryState )
846857 ) ;
847858 } else if ( ev . workflowExecutionCanceledEventAttributes ) {
848859 const failure = new CancelledFailure (
849860 'Workflow canceled' ,
850- await decodeArrayFromPayloads (
851- this . dataConverter ,
852- ev . workflowExecutionCanceledEventAttributes . details ?. payloads
853- )
861+ await decodeArrayFromPayloads ( dataConverter , ev . workflowExecutionCanceledEventAttributes . details ?. payloads )
854862 ) ;
855863 failure . stack = '' ;
856864 throw new WorkflowFailedError ( 'Workflow execution cancelled' , failure , RetryState . NON_RETRYABLE_FAILURE ) ;
@@ -937,13 +945,14 @@ export class WorkflowClient extends BaseClient {
937945 * Used as the final function of the query interceptor chain
938946 */
939947 protected async _queryWorkflowHandler ( input : WorkflowQueryInput ) : Promise < unknown > {
948+ const dataConverter = this . dataConverterWithWorkflowContext ( input . workflowExecution . workflowId ! ) ;
940949 const req : temporal . api . workflowservice . v1 . IQueryWorkflowRequest = {
941950 queryRejectCondition : input . queryRejectCondition ,
942951 namespace : this . options . namespace ,
943952 execution : input . workflowExecution ,
944953 query : {
945954 queryType : input . queryType ,
946- queryArgs : { payloads : await encodeToPayloads ( this . dataConverter , ...input . args ) } ,
955+ queryArgs : { payloads : await encodeToPayloads ( dataConverter , ...input . args ) } ,
947956 header : { fields : input . headers } ,
948957 } ,
949958 } ;
@@ -969,13 +978,14 @@ export class WorkflowClient extends BaseClient {
969978 throw new TypeError ( 'Invalid response from server' ) ;
970979 }
971980 // We ignore anything but the first result
972- return await decodeFromPayloadsAtIndex ( this . dataConverter , 0 , response . queryResult ?. payloads ) ;
981+ return await decodeFromPayloadsAtIndex ( dataConverter , 0 , response . queryResult ?. payloads ) ;
973982 }
974983
975984 protected async _createUpdateWorkflowRequest (
976985 lifecycleStage : temporal . api . enums . v1 . UpdateWorkflowExecutionLifecycleStage ,
977986 input : WorkflowStartUpdateInput
978987 ) : Promise < temporal . api . workflowservice . v1 . IUpdateWorkflowExecutionRequest > {
988+ const dataConverter = this . dataConverterWithWorkflowContext ( input . workflowExecution . workflowId ! ) ;
979989 const updateId = input . options ?. updateId ?? uuid4 ( ) ;
980990 return {
981991 namespace : this . options . namespace ,
@@ -992,7 +1002,7 @@ export class WorkflowClient extends BaseClient {
9921002 input : {
9931003 header : { fields : input . headers } ,
9941004 name : input . updateName ,
995- args : { payloads : await encodeToPayloads ( this . dataConverter , ...input . args ) } ,
1005+ args : { payloads : await encodeToPayloads ( dataConverter , ...input . args ) } ,
9961006 } ,
9971007 } ,
9981008 } ;
@@ -1136,6 +1146,7 @@ export class WorkflowClient extends BaseClient {
11361146 workflowRunId ?: string ,
11371147 outcome ?: temporal . api . update . v1 . IOutcome
11381148 ) : WorkflowUpdateHandle < Ret > {
1149+ const dataConverter = this . dataConverterWithWorkflowContext ( workflowId ) ;
11391150 return {
11401151 updateId,
11411152 workflowId,
@@ -1146,10 +1157,10 @@ export class WorkflowClient extends BaseClient {
11461157 if ( completedOutcome . failure ) {
11471158 throw new WorkflowUpdateFailedError (
11481159 'Workflow Update failed' ,
1149- await decodeOptionalFailureToOptionalError ( this . dataConverter , completedOutcome . failure )
1160+ await decodeOptionalFailureToOptionalError ( dataConverter , completedOutcome . failure )
11501161 ) ;
11511162 } else {
1152- return await decodeFromPayloadsAtIndex < Ret > ( this . dataConverter , 0 , completedOutcome . success ?. payloads ) ;
1163+ return await decodeFromPayloadsAtIndex < Ret > ( dataConverter , 0 , completedOutcome . success ?. payloads ) ;
11531164 }
11541165 } ,
11551166 } ;
@@ -1190,6 +1201,7 @@ export class WorkflowClient extends BaseClient {
11901201 * Used as the final function of the signal interceptor chain
11911202 */
11921203 protected async _signalWorkflowHandler ( input : WorkflowSignalInput ) : Promise < void > {
1204+ const dataConverter = this . dataConverterWithWorkflowContext ( input . workflowExecution . workflowId ! ) ;
11931205 const req : temporal . api . workflowservice . v1 . ISignalWorkflowExecutionRequest = {
11941206 identity : this . options . identity ,
11951207 namespace : this . options . namespace ,
@@ -1198,7 +1210,7 @@ export class WorkflowClient extends BaseClient {
11981210 // control is unused,
11991211 signalName : input . signalName ,
12001212 header : { fields : input . headers } ,
1201- input : { payloads : await encodeToPayloads ( this . dataConverter , ...input . args ) } ,
1213+ input : { payloads : await encodeToPayloads ( dataConverter , ...input . args ) } ,
12021214 } ;
12031215 try {
12041216 await this . workflowService . signalWorkflowExecution ( req ) ;
@@ -1215,6 +1227,7 @@ export class WorkflowClient extends BaseClient {
12151227 protected async _signalWithStartWorkflowHandler ( input : WorkflowSignalWithStartInput ) : Promise < string > {
12161228 const { identity } = this . options ;
12171229 const { options, workflowType, signalName, signalArgs, headers } = input ;
1230+ const dataConverter = this . dataConverterWithWorkflowContext ( options . workflowId ) ;
12181231 const req : temporal . api . workflowservice . v1 . ISignalWithStartWorkflowExecutionRequest = {
12191232 namespace : this . options . namespace ,
12201233 identity,
@@ -1223,9 +1236,9 @@ export class WorkflowClient extends BaseClient {
12231236 workflowIdReusePolicy : encodeWorkflowIdReusePolicy ( options . workflowIdReusePolicy ) ,
12241237 workflowIdConflictPolicy : encodeWorkflowIdConflictPolicy ( options . workflowIdConflictPolicy ) ,
12251238 workflowType : { name : workflowType } ,
1226- input : { payloads : await encodeToPayloads ( this . dataConverter , ...options . args ) } ,
1239+ input : { payloads : await encodeToPayloads ( dataConverter , ...options . args ) } ,
12271240 signalName,
1228- signalInput : { payloads : await encodeToPayloads ( this . dataConverter , ...signalArgs ) } ,
1241+ signalInput : { payloads : await encodeToPayloads ( dataConverter , ...signalArgs ) } ,
12291242 taskQueue : {
12301243 kind : temporal . api . enums . v1 . TaskQueueKind . TASK_QUEUE_KIND_NORMAL ,
12311244 name : options . taskQueue ,
@@ -1235,7 +1248,7 @@ export class WorkflowClient extends BaseClient {
12351248 workflowTaskTimeout : options . workflowTaskTimeout ,
12361249 workflowStartDelay : options . startDelay ,
12371250 retryPolicy : options . retry ? compileRetryPolicy ( options . retry ) : undefined ,
1238- memo : options . memo ? { fields : await encodeMapToPayloads ( this . dataConverter , options . memo ) } : undefined ,
1251+ memo : options . memo ? { fields : await encodeMapToPayloads ( dataConverter , options . memo ) } : undefined ,
12391252 searchAttributes :
12401253 options . searchAttributes || options . typedSearchAttributes // eslint-disable-line @typescript-eslint/no-deprecated
12411254 ? {
@@ -1244,7 +1257,7 @@ export class WorkflowClient extends BaseClient {
12441257 : undefined ,
12451258 cronSchedule : options . cronSchedule ,
12461259 header : { fields : headers } ,
1247- userMetadata : await encodeUserMetadata ( this . dataConverter , options . staticSummary , options . staticDetails ) ,
1260+ userMetadata : await encodeUserMetadata ( dataConverter , options . staticSummary , options . staticDetails ) ,
12481261 priority : options . priority ? compilePriority ( options . priority ) : undefined ,
12491262 versioningOverride : options . versioningOverride ?? undefined ,
12501263 } ;
@@ -1295,6 +1308,7 @@ export class WorkflowClient extends BaseClient {
12951308 protected async createStartWorkflowRequest ( input : WorkflowStartInput ) : Promise < StartWorkflowExecutionRequest > {
12961309 const { options : opts , workflowType, headers } = input ;
12971310 const { identity, namespace } = this . options ;
1311+ const dataConverter = this . dataConverterWithWorkflowContext ( opts . workflowId ) ;
12981312 const internalOptions = ( opts as InternalWorkflowStartOptions ) [ InternalWorkflowStartOptionsSymbol ] ;
12991313 const supportsEagerStart = ( this . connection as InternalConnectionLike ) ?. [ InternalConnectionLikeSymbol ]
13001314 ?. supportsEagerStart ;
@@ -1314,7 +1328,7 @@ export class WorkflowClient extends BaseClient {
13141328 workflowIdReusePolicy : encodeWorkflowIdReusePolicy ( opts . workflowIdReusePolicy ) ,
13151329 workflowIdConflictPolicy : encodeWorkflowIdConflictPolicy ( opts . workflowIdConflictPolicy ) ,
13161330 workflowType : { name : workflowType } ,
1317- input : { payloads : await encodeToPayloads ( this . dataConverter , ...opts . args ) } ,
1331+ input : { payloads : await encodeToPayloads ( dataConverter , ...opts . args ) } ,
13181332 taskQueue : {
13191333 kind : temporal . api . enums . v1 . TaskQueueKind . TASK_QUEUE_KIND_NORMAL ,
13201334 name : opts . taskQueue ,
@@ -1324,7 +1338,7 @@ export class WorkflowClient extends BaseClient {
13241338 workflowTaskTimeout : opts . workflowTaskTimeout ,
13251339 workflowStartDelay : opts . startDelay ,
13261340 retryPolicy : opts . retry ? compileRetryPolicy ( opts . retry ) : undefined ,
1327- memo : opts . memo ? { fields : await encodeMapToPayloads ( this . dataConverter , opts . memo ) } : undefined ,
1341+ memo : opts . memo ? { fields : await encodeMapToPayloads ( dataConverter , opts . memo ) } : undefined ,
13281342 searchAttributes :
13291343 opts . searchAttributes || opts . typedSearchAttributes // eslint-disable-line @typescript-eslint/no-deprecated
13301344 ? {
@@ -1333,7 +1347,7 @@ export class WorkflowClient extends BaseClient {
13331347 : undefined ,
13341348 cronSchedule : opts . cronSchedule ,
13351349 header : { fields : headers } ,
1336- userMetadata : await encodeUserMetadata ( this . dataConverter , opts . staticSummary , opts . staticDetails ) ,
1350+ userMetadata : await encodeUserMetadata ( dataConverter , opts . staticSummary , opts . staticDetails ) ,
13371351 priority : opts . priority ? compilePriority ( opts . priority ) : undefined ,
13381352 versioningOverride : opts . versioningOverride ?? undefined ,
13391353 requestEagerExecution : opts . requestEagerStart ,
@@ -1349,12 +1363,13 @@ export class WorkflowClient extends BaseClient {
13491363 protected async _terminateWorkflowHandler (
13501364 input : WorkflowTerminateInput
13511365 ) : Promise < TerminateWorkflowExecutionResponse > {
1366+ const dataConverter = this . dataConverterWithWorkflowContext ( input . workflowExecution . workflowId ! ) ;
13521367 const req : temporal . api . workflowservice . v1 . ITerminateWorkflowExecutionRequest = {
13531368 namespace : this . options . namespace ,
13541369 identity : this . options . identity ,
13551370 ...input ,
13561371 details : {
1357- payloads : input . details ? await encodeToPayloads ( this . dataConverter , ...input . details ) : undefined ,
1372+ payloads : input . details ? await encodeToPayloads ( dataConverter , ...input . details ) : undefined ,
13581373 } ,
13591374 firstExecutionRunId : input . firstExecutionRunId ,
13601375 } ;
0 commit comments