@loggerjs/processors 0.5.5 → 0.6.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/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <p align="center">
2
+ <a href="https://jskits.github.io/loggerjs/"><img src="https://raw.githubusercontent.com/jskits/loggerjs/main/docs/public/logo.png" alt="LoggerJS logo" width="64" height="64" /></a>
3
+ </p>
4
+
1
5
  # @loggerjs/processors
2
6
 
3
7
  > The composable middleware and processor toolbox for LoggerJS — redact, sample, dedupe, rate-limit, fingerprint, enrich, route, and buffer.
package/dist/index.cjs CHANGED
@@ -62,6 +62,17 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
62
62
  return out;
63
63
  }
64
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
+ }
65
76
  if (value instanceof Error) {
66
77
  const entries = ownEnumerableEntries$1(value);
67
78
  const hiddenFields = hiddenErrorFields(value);
@@ -1259,6 +1270,27 @@ function guardValue(value, path, key, depth, options, seen) {
1259
1270
  value,
1260
1271
  changed: false
1261
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
+ }
1262
1294
  if (value instanceof Error) {
1263
1295
  const message = guardErrorString(value.message, dotPath(path, "message"), options);
1264
1296
  const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);