@nxtedition/lib 23.3.16 → 23.3.17

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/serializers.js +24 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.3.16",
3
+ "version": "23.3.17",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",
package/serializers.js CHANGED
@@ -214,6 +214,26 @@ Object.defineProperty(pinoErrProto, rawSymbol, {
214
214
  value: {},
215
215
  })
216
216
 
217
+ function copyAndReplaceBigInts(obj) {
218
+ if (typeof obj === 'bigint') {
219
+ return obj.toString()
220
+ }
221
+
222
+ if (Array.isArray(obj)) {
223
+ return obj.map(copyAndReplaceBigInts)
224
+ }
225
+
226
+ if (obj !== null && typeof obj === 'object') {
227
+ const dst = {}
228
+ for (const [key, value] of Object.entries(obj)) {
229
+ dst[key] = copyAndReplaceBigInts(value)
230
+ }
231
+ return dst
232
+ }
233
+
234
+ return obj
235
+ }
236
+
217
237
  function errSerializer(err) {
218
238
  if (Array.isArray(err)) {
219
239
  return err.length === 0 ? undefined : errSerializer({ message: '', errors: err })
@@ -251,14 +271,14 @@ function errSerializer(err) {
251
271
  } else if (typeof val === 'bigint') {
252
272
  _err[key] = `${val.toString()}`
253
273
  } else if (val != null && !/^[A-Z0-9_]+$/.test(key)) {
254
- _err[key] = val
274
+ _err[key] = copyAndReplaceBigInts(val)
255
275
  }
256
276
  }
257
277
  }
258
278
 
259
279
  if (_err.data != null && typeof _err.data !== 'string') {
260
280
  try {
261
- _err.data = JSON.stringify(_err.data, undefined, 2)
281
+ _err.data = JSON.stringify(_err.data, (k, v) => (typeof v === 'bigint' ? v.toString() : v), 2)
262
282
  } catch {
263
283
  // Do nothing...
264
284
  }
@@ -266,7 +286,7 @@ function errSerializer(err) {
266
286
 
267
287
  if (_err.body != null && typeof _err.body !== 'string') {
268
288
  try {
269
- _err.body = JSON.stringify(_err.body, undefined, 2)
289
+ _err.body = JSON.stringify(_err.body, (k, v) => (typeof v === 'bigint' ? v.toString() : v), 2)
270
290
  } catch {
271
291
  // Do nothing...
272
292
  }
@@ -274,7 +294,7 @@ function errSerializer(err) {
274
294
 
275
295
  if (_err.meta != null && typeof _err.meta !== 'string') {
276
296
  try {
277
- _err.meta = JSON.stringify(_err.meta, undefined, 2)
297
+ _err.meta = JSON.stringify(_err.meta, (k, v) => (typeof v === 'bigint' ? v.toString() : v), 2)
278
298
  } catch {
279
299
  // Do nothing...
280
300
  }