@loggerjs/processors 0.5.6 → 0.7.0

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.
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
- import { createBoundContext, createMiddleware, eventToRecord, incrementLoggerMetaCounter, recordToEvent, toLevelName, toLevelValue, withLogEventRoute } from "@loggerjs/core";
1
+ import { createBoundContext, createMiddleware, eventToRecord, incrementLoggerMetaCounter, recordToEvent, toLevelName, toLevelValue } from "@loggerjs/core";
2
+ import { withLogEventRoute } from "@loggerjs/core/event-route";
2
3
  //#region src/error-fields.ts
3
4
  const NATIVE_ERROR_FIELDS = ["cause", "errors"];
4
5
  function hiddenErrorFields(value) {
@@ -61,6 +62,17 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
61
62
  return out;
62
63
  }
63
64
  if (value instanceof Date) return value;
65
+ const toJSON = value.toJSON;
66
+ if (typeof toJSON === "function") {
67
+ let serialized;
68
+ try {
69
+ serialized = toJSON.call(value, "");
70
+ } catch {
71
+ return options.replacement;
72
+ }
73
+ if (serialized === value) return value;
74
+ return redactValue(serialized, options, path, depth, seen);
75
+ }
64
76
  if (value instanceof Error) {
65
77
  const entries = ownEnumerableEntries$1(value);
66
78
  const hiddenFields = hiddenErrorFields(value);
@@ -1258,6 +1270,27 @@ function guardValue(value, path, key, depth, options, seen) {
1258
1270
  value,
1259
1271
  changed: false
1260
1272
  };
1273
+ const toJSON = value.toJSON;
1274
+ if (typeof toJSON === "function") {
1275
+ let serialized;
1276
+ try {
1277
+ serialized = toJSON.call(value, "");
1278
+ } catch {
1279
+ return {
1280
+ value: redact(path, "serialize-error", options),
1281
+ changed: true
1282
+ };
1283
+ }
1284
+ if (serialized === value) return {
1285
+ value,
1286
+ changed: false
1287
+ };
1288
+ const guarded = guardValue(serialized, path, key, depth, options, seen);
1289
+ return guarded.changed ? guarded : {
1290
+ value,
1291
+ changed: false
1292
+ };
1293
+ }
1261
1294
  if (value instanceof Error) {
1262
1295
  const message = guardErrorString(value.message, dotPath(path, "message"), options);
1263
1296
  const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);