@@ -25,6 +25,8 @@ import {
2525 ActivityCancellationType ,
2626 ApplicationFailure ,
2727 defineSearchAttributeKey ,
28+ encodingKeys ,
29+ METADATA_ENCODING_KEY ,
2830 RawValue ,
2931 SearchAttributePair ,
3032 SearchAttributeType ,
@@ -36,6 +38,7 @@ import {
3638 STACK_TRACE_QUERY_NAME ,
3739 ENHANCED_STACK_TRACE_QUERY_NAME ,
3840} from '@temporalio/common/lib/reserved' ;
41+ import { encode } from '@temporalio/common/lib/encoding' ;
3942import { signalSchedulingWorkflow } from './activities/helpers' ;
4043import { activityStartedSignal } from './workflows/definitions' ;
4144import * as workflows from './workflows' ;
@@ -1318,28 +1321,48 @@ test.serial('can register search attributes to dev server', async (t) => {
13181321 await env . teardown ( ) ;
13191322} ) ;
13201323
1321- export async function rawValueWorkflow ( value : unknown ) : Promise < RawValue > {
1324+ export async function rawValueWorkflow ( value : unknown , isPayload : boolean = false ) : Promise < RawValue > {
13221325 const { rawValueActivity } = workflow . proxyActivities ( { startToCloseTimeout : '10s' } ) ;
1323- return await rawValueActivity ( new RawValue ( value ) ) ;
1326+ const rv = isPayload
1327+ ? RawValue . fromPayload ( {
1328+ metadata : { [ METADATA_ENCODING_KEY ] : encodingKeys . METADATA_ENCODING_RAW } ,
1329+ data : value as Uint8Array ,
1330+ } )
1331+ : new RawValue ( value ) ;
1332+ return await rawValueActivity ( rv , isPayload ) ;
13241333}
13251334
13261335test ( 'workflow and activity can receive/return RawValue' , async ( t ) => {
13271336 const { executeWorkflow, createWorker } = helpers ( t ) ;
13281337 const worker = await createWorker ( {
13291338 activities : {
1330- async rawValueActivity ( value : unknown ) : Promise < RawValue > {
1331- return new RawValue ( value ) ;
1339+ async rawValueActivity ( value : unknown , isPayload : boolean = false ) : Promise < RawValue > {
1340+ const rv = isPayload
1341+ ? RawValue . fromPayload ( {
1342+ metadata : { [ METADATA_ENCODING_KEY ] : encodingKeys . METADATA_ENCODING_RAW } ,
1343+ data : value as Uint8Array ,
1344+ } )
1345+ : new RawValue ( value ) ;
1346+ return rv ;
13321347 } ,
13331348 } ,
13341349 } ) ;
13351350
13361351 await worker . runUntil ( async ( ) => {
13371352 const testValue = 'test' ;
13381353 const rawValue = new RawValue ( testValue ) ;
1354+ const rawValuePayload = RawValue . fromPayload ( {
1355+ metadata : { [ METADATA_ENCODING_KEY ] : encodingKeys . METADATA_ENCODING_RAW } ,
1356+ data : encode ( testValue ) ,
1357+ } ) ;
13391358 const res = await executeWorkflow ( rawValueWorkflow , {
13401359 args : [ rawValue ] ,
13411360 } ) ;
13421361 t . deepEqual ( res , testValue ) ;
1362+ const res2 = await executeWorkflow ( rawValueWorkflow , {
1363+ args : [ rawValuePayload , true ] ,
1364+ } ) ;
1365+ t . deepEqual ( res2 , encode ( testValue ) ) ;
13431366 } ) ;
13441367} ) ;
13451368
0 commit comments