@@ -271,7 +271,7 @@ export async function createPacketAttributes(
271271
272272      try  { 
273273        const  parsed  =  parse ( packet . data )  as  any ; 
274-         const  jsonified  =  JSON . parse ( JSON . stringify ( parsed ,  safeReplacer ) ) ; 
274+         const  jsonified  =  JSON . parse ( JSON . stringify ( parsed ,  makeSafeReplacer ( ) ) ) ; 
275275
276276        const  result  =  { 
277277          ...flattenAttributes ( jsonified ,  dataKey ) , 
@@ -319,7 +319,7 @@ export async function createPacketAttributesAsJson(
319319      const  {  deserialize }  =  await  loadSuperJSON ( ) ; 
320320
321321      const  deserialized  =  deserialize ( data )  as  any ; 
322-       const  jsonify  =  safeJsonParse ( JSON . stringify ( deserialized ,  safeReplacer ) ) ; 
322+       const  jsonify  =  safeJsonParse ( JSON . stringify ( deserialized ,  makeSafeReplacer ( ) ) ) ; 
323323
324324      return  imposeAttributeLimits ( flattenAttributes ( jsonify ,  undefined ) ) ; 
325325    case  "application/store" :
@@ -329,7 +329,11 @@ export async function createPacketAttributesAsJson(
329329  } 
330330} 
331331
332- export  async  function  prettyPrintPacket ( rawData : any ,  dataType ?: string ) : Promise < string >  { 
332+ export  async  function  prettyPrintPacket ( 
333+   rawData : any , 
334+   dataType ?: string , 
335+   options ?: ReplacerOptions 
336+ ) : Promise < string >  { 
333337  if  ( rawData  ===  undefined )  { 
334338    return  "" ; 
335339  } 
@@ -347,42 +351,53 @@ export async function prettyPrintPacket(rawData: any, dataType?: string): Promis
347351    if  ( typeof  rawData  ===  "string" )  { 
348352      rawData  =  safeJsonParse ( rawData ) ; 
349353    } 
350-     return  JSON . stringify ( rawData ,  safeReplacer ,  2 ) ; 
354+     return  JSON . stringify ( rawData ,  makeSafeReplacer ( options ) ,  2 ) ; 
351355  } 
352356
353357  if  ( typeof  rawData  ===  "string" )  { 
354358    return  rawData ; 
355359  } 
356360
357-   return  JSON . stringify ( rawData ,  safeReplacer ,  2 ) ; 
361+   return  JSON . stringify ( rawData ,  makeSafeReplacer ( options ) ,  2 ) ; 
358362} 
359363
360- function  safeReplacer ( key : string ,  value : any )  { 
361-   // If it is a BigInt 
362-   if  ( typeof  value  ===  "bigint" )  { 
363-     return  value . toString ( ) ;  // Convert to string 
364-   } 
364+ interface  ReplacerOptions  { 
365+   filteredKeys ?: string [ ] ; 
366+ } 
365367
366-   // if it is a Regex 
367-   if  ( value  instanceof  RegExp )  { 
368-     return  value . toString ( ) ;  // Convert to string 
369-   } 
368+ function  makeSafeReplacer ( options ?: ReplacerOptions )  { 
369+   return  function  replacer ( key : string ,  value : any )  { 
370+     // Check if the key should be filtered out 
371+     if  ( options ?. filteredKeys ?. includes ( key ) )  { 
372+       return  undefined ; 
373+     } 
370374
371-   // if  it is a Set  
372-   if  ( value  instanceof   Set )  { 
373-     return  Array . from ( value ) ;   // Convert to array 
374-   } 
375+      // If  it is a BigInt  
376+      if  ( typeof   value  ===   "bigint" )  { 
377+        return  value . toString ( ) ; 
378+      } 
375379
376-   // if it is a Map, convert it to an object 
377-   if  ( value  instanceof  Map )  { 
378-     const  obj : Record < string ,  any >  =  { } ; 
379-     value . forEach ( ( v ,  k )  =>  { 
380-       obj [ k ]  =  v ; 
381-     } ) ; 
382-     return  obj ; 
383-   } 
380+     // if it is a Regex 
381+     if  ( value  instanceof  RegExp )  { 
382+       return  value . toString ( ) ; 
383+     } 
384+ 
385+     // if it is a Set 
386+     if  ( value  instanceof  Set )  { 
387+       return  Array . from ( value ) ; 
388+     } 
384389
385-   return  value ;  // Otherwise return the value as is 
390+     // if it is a Map, convert it to an object 
391+     if  ( value  instanceof  Map )  { 
392+       const  obj : Record < string ,  any >  =  { } ; 
393+       value . forEach ( ( v ,  k )  =>  { 
394+         obj [ k ]  =  v ; 
395+       } ) ; 
396+       return  obj ; 
397+     } 
398+ 
399+     return  value ; 
400+   } ; 
386401} 
387402
388403function  getPacketExtension ( outputType : string ) : string  { 
0 commit comments