@@ -18,6 +18,7 @@ import {
18
18
type VirtualObjectDefinitionFrom ,
19
19
type Serde ,
20
20
serde ,
21
+ type JournalValueCodec ,
21
22
} from "@restatedev/restate-sdk-core" ;
22
23
import type {
23
24
ConnectionOpts ,
@@ -147,7 +148,8 @@ const doComponentInvocation = async <I, O>(
147
148
148
149
const { body, contentType } = serializeBodyWithContentType (
149
150
params . parameter ,
150
- inputSerde
151
+ inputSerde ,
152
+ opts . journalValueCodec
151
153
) ;
152
154
//
153
155
// headers
@@ -201,12 +203,15 @@ const doComponentInvocation = async <I, O>(
201
203
`Request failed: ${ httpResponse . status } \n${ body } `
202
204
) ;
203
205
}
204
- const responseBuf = await httpResponse . arrayBuffer ( ) ;
206
+ const responseBuf = new Uint8Array ( await httpResponse . arrayBuffer ( ) ) ;
205
207
if ( ! params . send ) {
208
+ const decodedBuf = opts . journalValueCodec
209
+ ? await opts . journalValueCodec . decode ( responseBuf )
210
+ : responseBuf ;
206
211
const outputSerde = params . opts ?. opts . output ?? serde . json ;
207
- return outputSerde . deserialize ( new Uint8Array ( responseBuf ) ) as O ;
212
+ return outputSerde . deserialize ( decodedBuf ) as O ;
208
213
}
209
- const json = serde . json . deserialize ( new Uint8Array ( responseBuf ) ) as O ;
214
+ const json = serde . json . deserialize ( responseBuf ) as O ;
210
215
return { ...json , attachable } ;
211
216
} ;
212
217
@@ -252,8 +257,11 @@ const doWorkflowHandleCall = async <O>(
252
257
signal,
253
258
} ) ;
254
259
if ( httpResponse . ok ) {
255
- const responseBuf = await httpResponse . arrayBuffer ( ) ;
256
- return outputSerde . deserialize ( new Uint8Array ( responseBuf ) ) as O ;
260
+ const responseBuf = new Uint8Array ( await httpResponse . arrayBuffer ( ) ) ;
261
+ const decodedBuf = opts . journalValueCodec
262
+ ? await opts . journalValueCodec . decode ( responseBuf )
263
+ : responseBuf ;
264
+ return outputSerde . deserialize ( decodedBuf ) as O ;
257
265
}
258
266
const body = await httpResponse . text ( ) ;
259
267
throw new HttpCallError (
@@ -412,7 +420,8 @@ class HttpIngress implements Ingress {
412
420
const url = `${ this . opts . url } /restate/a/${ id } /resolve` ;
413
421
const { body, contentType } = serializeBodyWithContentType (
414
422
payload ,
415
- payloadSerde ?? serde . json
423
+ payloadSerde ?? serde . json ,
424
+ this . opts . journalValueCodec
416
425
) ;
417
426
const headers = {
418
427
...( this . opts . headers ?? { } ) ,
@@ -481,9 +490,11 @@ class HttpIngress implements Ingress {
481
490
headers,
482
491
} ) ;
483
492
if ( httpResponse . ok ) {
484
- const responseBuf = await httpResponse . arrayBuffer ( ) ;
485
- const ser = resultSerde ?? serde . json ;
486
- return ser . deserialize ( new Uint8Array ( responseBuf ) ) as T ;
493
+ const responseBuf = new Uint8Array ( await httpResponse . arrayBuffer ( ) ) ;
494
+ const decodedBuf = this . opts . journalValueCodec
495
+ ? await this . opts . journalValueCodec . decode ( responseBuf )
496
+ : responseBuf ;
497
+ return ( resultSerde ?? serde . json ) . deserialize ( decodedBuf ) as T ;
487
498
}
488
499
const body = await httpResponse . text ( ) ;
489
500
throw new HttpCallError (
@@ -504,15 +515,19 @@ function computeDelayAsIso(opts: SendOpts): string {
504
515
505
516
function serializeBodyWithContentType (
506
517
body : unknown ,
507
- serde : Serde < unknown >
518
+ serde : Serde < unknown > ,
519
+ journalValueCodec ?: JournalValueCodec
508
520
) : {
509
521
body ?: Uint8Array ;
510
522
contentType ?: string ;
511
523
} {
512
524
if ( body === undefined ) {
513
525
return { } ;
514
526
}
515
- const buffer = serde . serialize ( body ) ;
527
+ let buffer = serde . serialize ( body ) ;
528
+ if ( journalValueCodec ) {
529
+ buffer = journalValueCodec . encode ( buffer ) ;
530
+ }
516
531
return {
517
532
body : buffer ,
518
533
contentType : serde . contentType ,
0 commit comments