lifecycleion 0.0.6 → 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.
@@ -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
  /**
@@ -928,6 +928,14 @@ function getPathParts(path) {
928
928
  return parts;
929
929
  }
930
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);
937
+ }
938
+
931
939
  // src/lib/curly-brackets.ts
932
940
  var PLACEHOLDER_PATTERN = /(?:\\)?{{(\s*[^{}]+?\s*)(?:\\)?\s*}}/g;
933
941
  var CurlyBrackets = function(str = "", locals = {}, fallback = "(null)") {
@@ -972,7 +980,7 @@ CurlyBrackets.compileTemplate = function(str, fallback = "(null)") {
972
980
  if (replacement === void 0 || replacement === null) {
973
981
  return fallback;
974
982
  }
975
- return String(replacement);
983
+ return stringifyTemplateValue(replacement);
976
984
  });
977
985
  };
978
986
  };
@@ -1348,14 +1356,17 @@ function applyRedaction(params, redactedKeys, redactFunction) {
1348
1356
  const redactedParams = deepClone(params);
1349
1357
  for (const key of redactedKeys) {
1350
1358
  if (key.includes(".") || key.includes("[")) {
1351
- const value = getNestedValue(redactedParams, key);
1359
+ const value = getNestedValue(params, key);
1352
1360
  if (value !== void 0) {
1353
- const redactedValue = redactFn(key, value);
1361
+ const redactedValue = redactFn(key, stringifyTemplateValue(value));
1354
1362
  setNestedValue(redactedParams, key, redactedValue);
1355
1363
  }
1356
1364
  } else {
1357
- if (key in redactedParams) {
1358
- redactedParams[key] = redactFn(key, redactedParams[key]);
1365
+ if (key in params) {
1366
+ redactedParams[key] = redactFn(
1367
+ key,
1368
+ stringifyTemplateValue(params[key])
1369
+ );
1359
1370
  }
1360
1371
  }
1361
1372
  }
@@ -2435,8 +2446,9 @@ var Logger = class _Logger extends EventEmitter {
2435
2446
  const params = options?.params;
2436
2447
  const tags = options?.tags;
2437
2448
  const redactedKeys = options?.redactedKeys;
2438
- const message = params ? CurlyBrackets(template, params) : template;
2439
- const redactedParams = params ? applyRedaction(params, redactedKeys, this.redactFunction) : void 0;
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;
2440
2452
  const entry = {
2441
2453
  timestamp,
2442
2454
  type,