@punks/backend-core 0.0.48 → 0.0.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@ export declare const buildObject: <T>(...props: {
8
8
  }[]) => T;
9
9
  export declare const mergeDeep: <T>(a: any, b: any) => T;
10
10
  export declare const jsonSerialize: (obj: any, options?: {
11
+ removeNonSerializableObjects?: boolean;
11
12
  removeCircularReferences?: boolean;
12
13
  stripBinaryData?: boolean;
13
14
  maxStringsLength?: number;
package/dist/esm/index.js CHANGED
@@ -287,9 +287,22 @@ const mergeDeep = (a, b) => {
287
287
  }
288
288
  return c;
289
289
  };
290
+ const isSerializable = (obj) => {
291
+ try {
292
+ JSON.stringify(obj);
293
+ return true;
294
+ }
295
+ catch (e) {
296
+ return false;
297
+ }
298
+ };
290
299
  const jsonSerialize = (obj, options) => {
291
- const { removeCircularReferences = true, stripBinaryData = true, prettify = false, maxStringsLength, } = options ?? {};
300
+ const { removeNonSerializableObjects = true, removeCircularReferences = true, stripBinaryData = true, prettify = false, maxStringsLength, } = options ?? {};
292
301
  const replacer = (key, value) => {
302
+ // remove non serializable objects
303
+ if (removeNonSerializableObjects && !isSerializable(value)) {
304
+ return `<non serializable property ${typeof value}>`;
305
+ }
293
306
  // remove circular references
294
307
  const seen = new WeakSet();
295
308
  if (removeCircularReferences &&
@@ -28483,16 +28496,18 @@ class InternalLogger {
28483
28496
  }
28484
28497
  }
28485
28498
  serializeMeta(meta) {
28486
- const serializedMeta = jsonSerialize(meta, {
28487
- prettify: true,
28488
- stripBinaryData: true,
28489
- });
28499
+ const serializedMeta = meta
28500
+ ? jsonSerialize(meta, {
28501
+ prettify: true,
28502
+ stripBinaryData: true,
28503
+ })
28504
+ : undefined;
28490
28505
  switch (this.options.serialization) {
28491
28506
  case MetaSerializationType.JSON:
28492
28507
  return serializedMeta;
28493
28508
  case MetaSerializationType.None:
28494
28509
  default:
28495
- return JSON.parse(serializedMeta);
28510
+ return serializedMeta ? JSON.parse(serializedMeta) : undefined;
28496
28511
  }
28497
28512
  }
28498
28513
  }