lifecycleion 0.0.5 → 0.0.7
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 +1 -1
- package/dist/lib/curly-brackets.cjs +46 -7
- package/dist/lib/curly-brackets.cjs.map +1 -1
- package/dist/lib/curly-brackets.js +46 -7
- package/dist/lib/curly-brackets.js.map +1 -1
- package/dist/lib/logger/index.cjs +62 -13
- package/dist/lib/logger/index.cjs.map +1 -1
- package/dist/lib/logger/index.d.cts +3 -1
- package/dist/lib/logger/index.d.ts +3 -1
- package/dist/lib/logger/index.js +62 -13
- package/dist/lib/logger/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -67,7 +67,9 @@ interface BeforeExitResult {
|
|
|
67
67
|
action: 'proceed' | 'wait';
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Redaction function type
|
|
70
|
+
* Redaction function type.
|
|
71
|
+
*
|
|
72
|
+
* Values are stringified before they are passed to the redaction function.
|
|
71
73
|
*/
|
|
72
74
|
type RedactFunction = (keyName: string, value: unknown) => unknown;
|
|
73
75
|
/**
|
|
@@ -67,7 +67,9 @@ interface BeforeExitResult {
|
|
|
67
67
|
action: 'proceed' | 'wait';
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
* Redaction function type
|
|
70
|
+
* Redaction function type.
|
|
71
|
+
*
|
|
72
|
+
* Values are stringified before they are passed to the redaction function.
|
|
71
73
|
*/
|
|
72
74
|
type RedactFunction = (keyName: string, value: unknown) => unknown;
|
|
73
75
|
/**
|
package/dist/lib/logger/index.js
CHANGED
|
@@ -892,16 +892,52 @@ function ms() {
|
|
|
892
892
|
}
|
|
893
893
|
|
|
894
894
|
// src/lib/internal/path-utils.ts
|
|
895
|
-
var PATH_SEGMENT_PATTERN =
|
|
895
|
+
var PATH_SEGMENT_PATTERN = /(\w+)|\[(\d+)\]|\["((?:[^"\\]|\\.)*)"\]|\['((?:[^'\\]|\\.)*)'\]/y;
|
|
896
|
+
function unescapeQuotedPathPart(value) {
|
|
897
|
+
return value.replace(/\\(["'\\])/g, "$1");
|
|
898
|
+
}
|
|
896
899
|
function getPathParts(path) {
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
900
|
+
const parts = [];
|
|
901
|
+
let index = 0;
|
|
902
|
+
while (index < path.length) {
|
|
903
|
+
if (path[index] === ".") {
|
|
904
|
+
index++;
|
|
905
|
+
if (index >= path.length) {
|
|
906
|
+
return null;
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
PATH_SEGMENT_PATTERN.lastIndex = index;
|
|
910
|
+
const match = PATH_SEGMENT_PATTERN.exec(path);
|
|
911
|
+
if (!match) {
|
|
912
|
+
return null;
|
|
913
|
+
}
|
|
914
|
+
if (match[1] !== void 0) {
|
|
915
|
+
parts.push(match[1]);
|
|
916
|
+
} else if (match[2] !== void 0) {
|
|
917
|
+
parts.push(match[2]);
|
|
918
|
+
} else if (match[3] !== void 0) {
|
|
919
|
+
parts.push(unescapeQuotedPathPart(match[3]));
|
|
920
|
+
} else if (match[4] !== void 0) {
|
|
921
|
+
parts.push(unescapeQuotedPathPart(match[4]));
|
|
922
|
+
}
|
|
923
|
+
index = PATH_SEGMENT_PATTERN.lastIndex;
|
|
924
|
+
if (index < path.length && path[index] !== "." && path[index] !== "[") {
|
|
925
|
+
return null;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return parts;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// src/lib/internal/stringify-template-value.ts
|
|
932
|
+
function stringifyTemplateValue(value) {
|
|
933
|
+
if (typeof value === "string") {
|
|
934
|
+
return value;
|
|
935
|
+
}
|
|
936
|
+
return String(value);
|
|
901
937
|
}
|
|
902
938
|
|
|
903
939
|
// src/lib/curly-brackets.ts
|
|
904
|
-
var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s
|
|
940
|
+
var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s*[^{}]+?\s*)(?:\\)?\s*}}/g;
|
|
905
941
|
var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
|
|
906
942
|
if (!str.includes("{{")) {
|
|
907
943
|
return str;
|
|
@@ -929,6 +965,9 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
|
929
965
|
}
|
|
930
966
|
const key = p1.trim();
|
|
931
967
|
const parts = getPathParts(key);
|
|
968
|
+
if (!parts || parts.length === 0) {
|
|
969
|
+
return match;
|
|
970
|
+
}
|
|
932
971
|
let replacement = locals;
|
|
933
972
|
for (const part of parts) {
|
|
934
973
|
if (replacement !== void 0 && replacement !== null && typeof replacement === "object" && part in replacement) {
|
|
@@ -941,7 +980,7 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
|
941
980
|
if (replacement === void 0 || replacement === null) {
|
|
942
981
|
return fallback;
|
|
943
982
|
}
|
|
944
|
-
return
|
|
983
|
+
return stringifyTemplateValue(replacement);
|
|
945
984
|
});
|
|
946
985
|
};
|
|
947
986
|
};
|
|
@@ -1275,6 +1314,9 @@ var defaultRedactFunction = (_keyName, value) => {
|
|
|
1275
1314
|
};
|
|
1276
1315
|
function setNestedValue(obj, path, value) {
|
|
1277
1316
|
const parts = getPathParts(path);
|
|
1317
|
+
if (!parts || parts.length === 0) {
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1278
1320
|
let current = obj;
|
|
1279
1321
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
1280
1322
|
const part = parts[i];
|
|
@@ -1294,6 +1336,9 @@ function setNestedValue(obj, path, value) {
|
|
|
1294
1336
|
}
|
|
1295
1337
|
function getNestedValue(obj, path) {
|
|
1296
1338
|
const parts = getPathParts(path);
|
|
1339
|
+
if (!parts || parts.length === 0) {
|
|
1340
|
+
return void 0;
|
|
1341
|
+
}
|
|
1297
1342
|
let current = obj;
|
|
1298
1343
|
for (const part of parts) {
|
|
1299
1344
|
if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
|
|
@@ -1311,14 +1356,17 @@ function applyRedaction(params, redactedKeys, redactFunction) {
|
|
|
1311
1356
|
const redactedParams = deepClone(params);
|
|
1312
1357
|
for (const key of redactedKeys) {
|
|
1313
1358
|
if (key.includes(".") || key.includes("[")) {
|
|
1314
|
-
const value = getNestedValue(
|
|
1359
|
+
const value = getNestedValue(params, key);
|
|
1315
1360
|
if (value !== void 0) {
|
|
1316
|
-
const redactedValue = redactFn(key, value);
|
|
1361
|
+
const redactedValue = redactFn(key, stringifyTemplateValue(value));
|
|
1317
1362
|
setNestedValue(redactedParams, key, redactedValue);
|
|
1318
1363
|
}
|
|
1319
1364
|
} else {
|
|
1320
|
-
if (key in
|
|
1321
|
-
redactedParams[key] = redactFn(
|
|
1365
|
+
if (key in params) {
|
|
1366
|
+
redactedParams[key] = redactFn(
|
|
1367
|
+
key,
|
|
1368
|
+
stringifyTemplateValue(params[key])
|
|
1369
|
+
);
|
|
1322
1370
|
}
|
|
1323
1371
|
}
|
|
1324
1372
|
}
|
|
@@ -2398,8 +2446,9 @@ var Logger = class _Logger extends EventEmitter {
|
|
|
2398
2446
|
const params = options?.params;
|
|
2399
2447
|
const tags = options?.tags;
|
|
2400
2448
|
const redactedKeys = options?.redactedKeys;
|
|
2401
|
-
const
|
|
2402
|
-
const
|
|
2449
|
+
const redactedParams = params && redactedKeys && redactedKeys.length > 0 ? applyRedaction(params, redactedKeys, this.redactFunction) : void 0;
|
|
2450
|
+
const messageParams = redactedParams ?? params;
|
|
2451
|
+
const message = messageParams ? CurlyBrackets(template, messageParams) : template;
|
|
2403
2452
|
const entry = {
|
|
2404
2453
|
timestamp,
|
|
2405
2454
|
type,
|