lifecycleion 0.0.4 → 0.0.6
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 +45 -3
- package/dist/lib/curly-brackets.cjs.map +1 -1
- package/dist/lib/curly-brackets.js +43 -3
- package/dist/lib/curly-brackets.js.map +1 -1
- package/dist/lib/logger/index.cjs +56 -7
- package/dist/lib/logger/index.cjs.map +1 -1
- package/dist/lib/logger/index.js +56 -7
- package/dist/lib/logger/index.js.map +1 -1
- package/package.json +1 -1
package/dist/lib/logger/index.js
CHANGED
|
@@ -891,7 +891,45 @@ function ms() {
|
|
|
891
891
|
return Date.now();
|
|
892
892
|
}
|
|
893
893
|
|
|
894
|
+
// src/lib/internal/path-utils.ts
|
|
895
|
+
var PATH_SEGMENT_PATTERN = /(\w+)|\[(\d+)\]|\["((?:[^"\\]|\\.)*)"\]|\['((?:[^'\\]|\\.)*)'\]/y;
|
|
896
|
+
function unescapeQuotedPathPart(value) {
|
|
897
|
+
return value.replace(/\\(["'\\])/g, "$1");
|
|
898
|
+
}
|
|
899
|
+
function getPathParts(path) {
|
|
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
|
+
|
|
894
931
|
// src/lib/curly-brackets.ts
|
|
932
|
+
var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s*[^{}]+?\s*)(?:\\)?\s*}}/g;
|
|
895
933
|
var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
|
|
896
934
|
if (!str.includes("{{")) {
|
|
897
935
|
return str;
|
|
@@ -900,9 +938,8 @@ var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
|
|
|
900
938
|
return compiled(locals);
|
|
901
939
|
};
|
|
902
940
|
CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
903
|
-
const pattern = /(?:\\)?{{(\s*[\w.]+?)(?:\\)?\s*}}/g;
|
|
904
941
|
return (locals) => {
|
|
905
|
-
return str.replace(
|
|
942
|
+
return str.replace(PLACEHOLDER_PATTERN, (match, p1) => {
|
|
906
943
|
if (typeof p1 !== "string") {
|
|
907
944
|
return match;
|
|
908
945
|
}
|
|
@@ -919,7 +956,10 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
|
|
|
919
956
|
return "{{" + p1.trim() + "}}";
|
|
920
957
|
}
|
|
921
958
|
const key = p1.trim();
|
|
922
|
-
const parts = key
|
|
959
|
+
const parts = getPathParts(key);
|
|
960
|
+
if (!parts || parts.length === 0) {
|
|
961
|
+
return match;
|
|
962
|
+
}
|
|
923
963
|
let replacement = locals;
|
|
924
964
|
for (const part of parts) {
|
|
925
965
|
if (replacement !== void 0 && replacement !== null && typeof replacement === "object" && part in replacement) {
|
|
@@ -1265,10 +1305,16 @@ var defaultRedactFunction = (_keyName, value) => {
|
|
|
1265
1305
|
return "***REDACTED***";
|
|
1266
1306
|
};
|
|
1267
1307
|
function setNestedValue(obj, path, value) {
|
|
1268
|
-
const parts = path
|
|
1308
|
+
const parts = getPathParts(path);
|
|
1309
|
+
if (!parts || parts.length === 0) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1269
1312
|
let current = obj;
|
|
1270
1313
|
for (let i = 0; i < parts.length - 1; i++) {
|
|
1271
1314
|
const part = parts[i];
|
|
1315
|
+
if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
|
|
1316
|
+
return;
|
|
1317
|
+
}
|
|
1272
1318
|
const next = current[part];
|
|
1273
1319
|
if (next === void 0 || next === null || typeof next !== "object") {
|
|
1274
1320
|
return;
|
|
@@ -1276,12 +1322,15 @@ function setNestedValue(obj, path, value) {
|
|
|
1276
1322
|
current = next;
|
|
1277
1323
|
}
|
|
1278
1324
|
const lastPart = parts[parts.length - 1];
|
|
1279
|
-
if (lastPart !== void 0 && lastPart in current) {
|
|
1325
|
+
if (lastPart !== void 0 && current !== void 0 && current !== null && typeof current === "object" && lastPart in current) {
|
|
1280
1326
|
current[lastPart] = value;
|
|
1281
1327
|
}
|
|
1282
1328
|
}
|
|
1283
1329
|
function getNestedValue(obj, path) {
|
|
1284
|
-
const parts = path
|
|
1330
|
+
const parts = getPathParts(path);
|
|
1331
|
+
if (!parts || parts.length === 0) {
|
|
1332
|
+
return void 0;
|
|
1333
|
+
}
|
|
1285
1334
|
let current = obj;
|
|
1286
1335
|
for (const part of parts) {
|
|
1287
1336
|
if (current === void 0 || current === null || typeof current !== "object" || !(part in current)) {
|
|
@@ -1298,7 +1347,7 @@ function applyRedaction(params, redactedKeys, redactFunction) {
|
|
|
1298
1347
|
const redactFn = redactFunction || defaultRedactFunction;
|
|
1299
1348
|
const redactedParams = deepClone(params);
|
|
1300
1349
|
for (const key of redactedKeys) {
|
|
1301
|
-
if (key.includes(".")) {
|
|
1350
|
+
if (key.includes(".") || key.includes("[")) {
|
|
1302
1351
|
const value = getNestedValue(redactedParams, key);
|
|
1303
1352
|
if (value !== void 0) {
|
|
1304
1353
|
const redactedValue = redactFn(key, value);
|