11// eslint-disable-next-line @typescript-eslint/no-explicit-any
2- export function bufferReviver ( _ : string , value : any ) : any {
2+ export function bufferAndMapReviver ( _ : string , value : any ) : any {
33 if ( value && typeof value === 'object' && typeof value . $binary === 'string' ) {
44 return Buffer . from ( value . $binary , 'base64' ) ;
55 }
6+ if (
7+ value &&
8+ typeof value === 'object' &&
9+ typeof value . $map === 'object' &&
10+ ! ! value . $map
11+ ) {
12+ return new Map (
13+ Object . entries ( value . $map ) . map ( ( [ key , value ] ) => {
14+ const revivedValue = bufferAndMapReviver ( '' , value ) ;
15+ return [ key , revivedValue ] ;
16+ } ) ,
17+ ) ;
18+ }
619 return value ;
720}
821// eslint-disable-next-line @typescript-eslint/no-explicit-any
9- export function bufferReplacer ( _ : string , value : any ) : any {
22+ export function bufferAndMapReplacer ( _ : string , value : any ) : any {
1023 if ( Buffer . isBuffer ( value ) ) {
1124 return {
1225 $binary : value . toString ( 'base64' ) ,
@@ -22,5 +35,15 @@ export function bufferReplacer(_: string, value: any): any {
2235 $binary : Buffer . from ( value . data ) . toString ( 'base64' ) ,
2336 } ;
2437 }
38+ if ( value && typeof value === 'object' && value instanceof Map ) {
39+ return {
40+ $map : Object . fromEntries (
41+ Array . from ( value . entries ( ) ) . map ( ( [ key , value ] ) => {
42+ const replacedValue = bufferAndMapReplacer ( '' , value ) ;
43+ return [ key , replacedValue ] ;
44+ } ) ,
45+ ) ,
46+ } ;
47+ }
2548 return value ;
2649}
0 commit comments