@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/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.
@@ -1,4 +1,5 @@
1
- import { type EnabledLogLevelName, type LogEvent, type LogEventRoute, type LoggerLevel, type Processor, type ProcessorContext, type Tags } from "@loggerjs/core";
1
+ import { type EnabledLogLevelName, type LogEvent, type LoggerLevel, type Processor, type ProcessorContext, type Tags } from "@loggerjs/core";
2
+ import { type LogEventRoute } from "@loggerjs/core/event-route";
2
3
  export type EventStringMatcher = string | RegExp | ((value: string | undefined, event: LogEvent) => boolean);
3
4
  export interface EventMatch {
4
5
  when?: (event: LogEvent, context: ProcessorContext) => boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"filter-route.d.ts","sourceRoot":"","sources":["../src/filter-route.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,QAAQ,EACb,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,IAAI,EACV,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,kBAAkB,GAC1B,MAAM,GACN,MAAM,GACN,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,C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C,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,KAAK,OAAO,CAAC;AAEtF,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,MAAM,CAAC,EAAE,YAAY,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IAC7B,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAED,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG,SAAS,UAAU,EAAE,GAAG,aAAa,CAAC;AAElF,MAAM,WAAW,SAAU,SAAQ,UAAU,EAAE,aAAa;CAAG;AAE/D,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,SAAS,SAAS,EAAE,CAAC;IAC5B,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAED,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,SAAS,SAAS,EAAE,GAAG,YAAY,CAAC;AA2E7E,wBAAgB,eAAe,CAAC,KAAK,EAAE,WAAW,GAAG,SAAS,CAiB7D;AAqBD,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAiB3D"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _loggerjs_core = require("@loggerjs/core");
3
+ let _loggerjs_core_event_route = require("@loggerjs/core/event-route");
3
4
  //#region src/error-fields.ts
4
5
  const NATIVE_ERROR_FIELDS = ["cause", "errors"];
5
6
  function hiddenErrorFields(value) {
@@ -62,6 +63,17 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
62
63
  return out;
63
64
  }
64
65
  if (value instanceof Date) return value;
66
+ const toJSON = value.toJSON;
67
+ if (typeof toJSON === "function") {
68
+ let serialized;
69
+ try {
70
+ serialized = toJSON.call(value, "");
71
+ } catch {
72
+ return options.replacement;
73
+ }
74
+ if (serialized === value) return value;
75
+ return redactValue(serialized, options, path, depth, seen);
76
+ }
65
77
  if (value instanceof Error) {
66
78
  const entries = ownEnumerableEntries$1(value);
67
79
  const hiddenFields = hiddenErrorFields(value);
@@ -758,15 +770,15 @@ function isRouteRuleArray(input) {
758
770
  return Array.isArray(input);
759
771
  }
760
772
  function routeProcessor(input) {
761
- if (!isRouteRuleArray(input) && !isRouteOptions(input)) return (event) => hasRoute(input) ? (0, _loggerjs_core.withLogEventRoute)(event, input) : event;
773
+ if (!isRouteRuleArray(input) && !isRouteOptions(input)) return (event) => hasRoute(input) ? (0, _loggerjs_core_event_route.withLogEventRoute)(event, input) : event;
762
774
  const rules = isRouteRuleArray(input) ? input : input.rules;
763
775
  const defaultRoute = isRouteRuleArray(input) ? void 0 : input.defaultRoute;
764
776
  return (event, context) => {
765
777
  for (const rule of rules) if (matchesEvent(event, context, rule)) {
766
778
  const route = routeFromRule(rule);
767
- return hasRoute(route) ? (0, _loggerjs_core.withLogEventRoute)(event, route) : event;
779
+ return hasRoute(route) ? (0, _loggerjs_core_event_route.withLogEventRoute)(event, route) : event;
768
780
  }
769
- return hasRoute(defaultRoute) ? (0, _loggerjs_core.withLogEventRoute)(event, defaultRoute) : event;
781
+ return hasRoute(defaultRoute) ? (0, _loggerjs_core_event_route.withLogEventRoute)(event, defaultRoute) : event;
770
782
  };
771
783
  }
772
784
  //#endregion
@@ -1259,6 +1271,27 @@ function guardValue(value, path, key, depth, options, seen) {
1259
1271
  value,
1260
1272
  changed: false
1261
1273
  };
1274
+ const toJSON = value.toJSON;
1275
+ if (typeof toJSON === "function") {
1276
+ let serialized;
1277
+ try {
1278
+ serialized = toJSON.call(value, "");
1279
+ } catch {
1280
+ return {
1281
+ value: redact(path, "serialize-error", options),
1282
+ changed: true
1283
+ };
1284
+ }
1285
+ if (serialized === value) return {
1286
+ value,
1287
+ changed: false
1288
+ };
1289
+ const guarded = guardValue(serialized, path, key, depth, options, seen);
1290
+ return guarded.changed ? guarded : {
1291
+ value,
1292
+ changed: false
1293
+ };
1294
+ }
1262
1295
  if (value instanceof Error) {
1263
1296
  const message = guardErrorString(value.message, dotPath(path, "message"), options);
1264
1297
  const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);