@loggerjs/processors 0.5.2 → 0.5.4
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.cjs +36 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -20
- package/dist/index.js.map +1 -1
- package/dist/privacy-guard.d.ts +1 -1
- package/dist/privacy-guard.d.ts.map +1 -1
- package/dist/redact.d.ts +1 -1
- package/dist/redact.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -23,16 +23,25 @@ function dotPath(path, field) {
|
|
|
23
23
|
}
|
|
24
24
|
//#endregion
|
|
25
25
|
//#region src/redact.ts
|
|
26
|
+
function keyName$1(key) {
|
|
27
|
+
if (typeof key === "symbol") return key.description ?? key.toString();
|
|
28
|
+
return String(key);
|
|
29
|
+
}
|
|
30
|
+
function ownEnumerableEntries$1(value) {
|
|
31
|
+
return Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key)).map((key) => [key, value[key]]);
|
|
32
|
+
}
|
|
26
33
|
function matchesKey(key, path, value, matchers) {
|
|
34
|
+
const name = keyName$1(key);
|
|
27
35
|
return matchers.some((matcher) => {
|
|
28
|
-
if (typeof matcher === "
|
|
36
|
+
if (typeof matcher === "symbol") return matcher === key;
|
|
37
|
+
if (typeof matcher === "string") return matcher.toLowerCase() === name.toLowerCase();
|
|
29
38
|
if (matcher instanceof RegExp) {
|
|
30
39
|
matcher.lastIndex = 0;
|
|
31
|
-
const keyMatches = matcher.test(
|
|
40
|
+
const keyMatches = matcher.test(name);
|
|
32
41
|
matcher.lastIndex = 0;
|
|
33
42
|
return keyMatches || matcher.test(path);
|
|
34
43
|
}
|
|
35
|
-
return matcher(
|
|
44
|
+
return matcher(name, path, value);
|
|
36
45
|
});
|
|
37
46
|
}
|
|
38
47
|
function pathMatches(path, paths) {
|
|
@@ -54,7 +63,7 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
|
|
|
54
63
|
}
|
|
55
64
|
if (value instanceof Date) return value;
|
|
56
65
|
if (value instanceof Error) {
|
|
57
|
-
const entries =
|
|
66
|
+
const entries = ownEnumerableEntries$1(value);
|
|
58
67
|
const hiddenFields = hiddenErrorFields(value);
|
|
59
68
|
if (entries.length === 0 && hiddenFields.length === 0) return value;
|
|
60
69
|
const errorOut = Object.create(Object.getPrototypeOf(value));
|
|
@@ -72,7 +81,7 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
|
|
|
72
81
|
defineHidden(errorOut, field, redactValue(child, options, childPath, depth + 1, seen));
|
|
73
82
|
}
|
|
74
83
|
for (const [key, child] of entries) {
|
|
75
|
-
const childPath = dotPath(path, key);
|
|
84
|
+
const childPath = dotPath(path, keyName$1(key));
|
|
76
85
|
if (shouldRedact(key, childPath, child, options)) {
|
|
77
86
|
if (options.remove) continue;
|
|
78
87
|
errorOut[key] = options.replacement;
|
|
@@ -84,8 +93,8 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
|
|
|
84
93
|
const mapOut = /* @__PURE__ */ new Map();
|
|
85
94
|
seen.set(value, mapOut);
|
|
86
95
|
for (const [key, child] of value) {
|
|
87
|
-
if (typeof key === "string") {
|
|
88
|
-
const childPath = dotPath(path, key);
|
|
96
|
+
if (typeof key === "string" || typeof key === "symbol") {
|
|
97
|
+
const childPath = dotPath(path, keyName$1(key));
|
|
89
98
|
if (shouldRedact(key, childPath, child, options)) {
|
|
90
99
|
if (options.remove) continue;
|
|
91
100
|
mapOut.set(key, options.replacement);
|
|
@@ -108,11 +117,10 @@ function redactValue(value, options, path = "", depth = 0, seen = /* @__PURE__ *
|
|
|
108
117
|
}
|
|
109
118
|
return setOut;
|
|
110
119
|
}
|
|
111
|
-
const input = value;
|
|
112
120
|
const out = {};
|
|
113
121
|
seen.set(value, out);
|
|
114
|
-
for (const [key, child] of
|
|
115
|
-
const childPath = dotPath(path, key);
|
|
122
|
+
for (const [key, child] of ownEnumerableEntries$1(value)) {
|
|
123
|
+
const childPath = dotPath(path, keyName$1(key));
|
|
116
124
|
if (shouldRedact(key, childPath, child, options)) {
|
|
117
125
|
if (options.remove) continue;
|
|
118
126
|
out[key] = options.replacement;
|
|
@@ -1103,6 +1111,13 @@ function isAsciiAlphaNumeric(code) {
|
|
|
1103
1111
|
function hasChar(code, chars) {
|
|
1104
1112
|
return chars.includes(String.fromCharCode(code));
|
|
1105
1113
|
}
|
|
1114
|
+
function keyName(key) {
|
|
1115
|
+
if (typeof key === "symbol") return key.description ?? key.toString();
|
|
1116
|
+
return String(key);
|
|
1117
|
+
}
|
|
1118
|
+
function ownEnumerableEntries(value) {
|
|
1119
|
+
return Reflect.ownKeys(value).filter((key) => Object.prototype.propertyIsEnumerable.call(value, key)).map((key) => [key, value[key]]);
|
|
1120
|
+
}
|
|
1106
1121
|
function isEmailLocalChar(code) {
|
|
1107
1122
|
return isAsciiAlphaNumeric(code) || hasChar(code, "._%+-");
|
|
1108
1123
|
}
|
|
@@ -1168,12 +1183,14 @@ function redactEmailAddresses(input, path, options) {
|
|
|
1168
1183
|
};
|
|
1169
1184
|
}
|
|
1170
1185
|
function matcherMatches(matcher, key, path, value) {
|
|
1171
|
-
|
|
1186
|
+
const name = keyName(key);
|
|
1187
|
+
if (typeof matcher === "symbol") return matcher === key;
|
|
1188
|
+
if (typeof matcher === "string") return matcher.toLowerCase() === name.toLowerCase();
|
|
1172
1189
|
if (matcher instanceof RegExp) {
|
|
1173
1190
|
matcher.lastIndex = 0;
|
|
1174
|
-
return matcher.test(
|
|
1191
|
+
return matcher.test(name) || matcher.test(path);
|
|
1175
1192
|
}
|
|
1176
|
-
return matcher(
|
|
1193
|
+
return matcher(name, path, value);
|
|
1177
1194
|
}
|
|
1178
1195
|
function matchesAny(matchers, key, path, value) {
|
|
1179
1196
|
return matchers.some((matcher) => matcherMatches(matcher, key, path, value));
|
|
@@ -1246,7 +1263,7 @@ function guardValue(value, path, key, depth, options, seen) {
|
|
|
1246
1263
|
const message = guardErrorString(value.message, dotPath(path, "message"), options);
|
|
1247
1264
|
const stack = guardErrorString(value.stack, dotPath(path, "stack"), options);
|
|
1248
1265
|
const fieldChanged = message.changed || stack.changed;
|
|
1249
|
-
const entries =
|
|
1266
|
+
const entries = ownEnumerableEntries(value);
|
|
1250
1267
|
const hiddenFields = hiddenErrorFields(value);
|
|
1251
1268
|
if (entries.length === 0 && hiddenFields.length === 0 && !fieldChanged) return {
|
|
1252
1269
|
value,
|
|
@@ -1264,7 +1281,7 @@ function guardValue(value, path, key, depth, options, seen) {
|
|
|
1264
1281
|
changed ||= child.changed;
|
|
1265
1282
|
}
|
|
1266
1283
|
for (const [childKey, childValue] of entries) {
|
|
1267
|
-
const child = guardValue(childValue, dotPath(path, childKey), childKey, depth + 1, options, seen);
|
|
1284
|
+
const child = guardValue(childValue, dotPath(path, keyName(childKey)), childKey, depth + 1, options, seen);
|
|
1268
1285
|
errorOut[childKey] = child.value;
|
|
1269
1286
|
changed ||= child.changed;
|
|
1270
1287
|
}
|
|
@@ -1278,8 +1295,8 @@ function guardValue(value, path, key, depth, options, seen) {
|
|
|
1278
1295
|
seen.set(value, mapOut);
|
|
1279
1296
|
let changed = false;
|
|
1280
1297
|
for (const [mapKey, mapValue] of value) {
|
|
1281
|
-
const
|
|
1282
|
-
const child = guardValue(mapValue,
|
|
1298
|
+
const isNamedKey = typeof mapKey === "string" || typeof mapKey === "symbol";
|
|
1299
|
+
const child = guardValue(mapValue, isNamedKey ? dotPath(path, keyName(mapKey)) : path, isNamedKey ? mapKey : key, depth + 1, options, seen);
|
|
1283
1300
|
mapOut.set(mapKey, child.value);
|
|
1284
1301
|
changed ||= child.changed;
|
|
1285
1302
|
}
|
|
@@ -1318,12 +1335,11 @@ function guardValue(value, path, key, depth, options, seen) {
|
|
|
1318
1335
|
changed
|
|
1319
1336
|
};
|
|
1320
1337
|
}
|
|
1321
|
-
const input = value;
|
|
1322
1338
|
const out = {};
|
|
1323
1339
|
seen.set(value, out);
|
|
1324
1340
|
let changed = false;
|
|
1325
|
-
for (const [childKey, childValue] of
|
|
1326
|
-
const child = guardValue(childValue, dotPath(path, childKey), childKey, depth + 1, options, seen);
|
|
1341
|
+
for (const [childKey, childValue] of ownEnumerableEntries(value)) {
|
|
1342
|
+
const child = guardValue(childValue, dotPath(path, keyName(childKey)), childKey, depth + 1, options, seen);
|
|
1327
1343
|
out[childKey] = child.value;
|
|
1328
1344
|
changed ||= child.changed;
|
|
1329
1345
|
}
|