@visulima/pail 4.0.0-alpha.1 → 4.0.0-alpha.11

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +204 -0
  2. package/LICENSE.md +434 -52
  3. package/README.md +323 -0
  4. package/dist/error.d.ts +104 -0
  5. package/dist/error.js +76 -0
  6. package/dist/index.browser.d.ts +3 -1
  7. package/dist/index.browser.js +1490 -3
  8. package/dist/index.server.d.ts +3 -5
  9. package/dist/index.server.js +2380 -110
  10. package/dist/middleware/elysia.d.ts +71 -0
  11. package/dist/middleware/elysia.js +70 -0
  12. package/dist/middleware/express.d.ts +86 -0
  13. package/dist/middleware/express.js +29 -0
  14. package/dist/middleware/fastify.d.ts +81 -0
  15. package/dist/middleware/fastify.js +46 -0
  16. package/dist/middleware/hono.d.ts +85 -0
  17. package/dist/middleware/hono.js +33 -0
  18. package/dist/middleware/next/handler.d.ts +36 -0
  19. package/dist/middleware/next/handler.js +53 -0
  20. package/dist/middleware/next/middleware.d.ts +59 -0
  21. package/dist/middleware/next/storage.d.ts +14 -0
  22. package/dist/middleware/shared/create-middleware-logger.d.ts +82 -0
  23. package/dist/middleware/shared/headers.d.ts +14 -0
  24. package/dist/middleware/shared/routes.d.ts +30 -0
  25. package/dist/middleware/shared/storage.d.ts +29 -0
  26. package/dist/middleware/sveltekit.d.ts +123 -0
  27. package/dist/middleware/sveltekit.js +43 -0
  28. package/dist/object-tree.d.ts +2 -2
  29. package/dist/object-tree.js +7 -7
  30. package/dist/packem_shared/{AbstractJsonReporter-BaZ33PlE.js → AbstractJsonReporter-BO8Calb4.js} +112 -32
  31. package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +284 -0
  32. package/dist/packem_shared/{JsonReporter-BRw4skd5.js → JsonReporter-CCmj7oYL.js} +2 -2
  33. package/dist/packem_shared/{JsonReporter-VzgyLEYz.js → JsonReporter-Ck2PIAEw.js} +2 -2
  34. package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +2720 -0
  35. package/dist/packem_shared/{PrettyReporter-DySIXBjQ.js → PrettyReporter-BtTr13Ha.js} +55 -11
  36. package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +2635 -0
  37. package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
  38. package/dist/packem_shared/createPailError-B_sgL0nF.js +76 -0
  39. package/dist/packem_shared/headers-BxHWM6KI.js +127 -0
  40. package/dist/packem_shared/{index-BomQ3E6J.js → index-Bx3-C0j9.js} +29 -21
  41. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +24 -0
  42. package/dist/packem_shared/storage-D0vqz8OX.js +36 -0
  43. package/dist/packem_shared/{InteractiveStreamHook-DiSubbJ1.js → useLogger-D0rU3lcX.js} +13 -1
  44. package/dist/packem_shared/{write-console-log-based-on-level-DBmRYXpj.js → write-console-log-based-on-level-ree2lDPw.js} +5 -4
  45. package/dist/packem_shared/{write-stream-BG8fhcs3.js → write-stream-MDqyXmc_.js} +1 -1
  46. package/dist/pail.browser.d.ts +1 -1
  47. package/dist/pail.server.d.ts +1 -76
  48. package/dist/processor/caller/caller-processor.js +1 -1
  49. package/dist/processor/environment-processor.d.ts +124 -0
  50. package/dist/processor/environment-processor.js +89 -0
  51. package/dist/processor/message-formatter-processor.d.ts +2 -3
  52. package/dist/processor/message-formatter-processor.js +654 -5
  53. package/dist/processor/opentelemetry-processor.js +4 -4
  54. package/dist/processor/redact-processor.d.ts +1 -1
  55. package/dist/processor/redact-processor.js +2 -1
  56. package/dist/processor/sampling-processor.d.ts +111 -0
  57. package/dist/processor/sampling-processor.js +59 -0
  58. package/dist/reporter/file/json-file-reporter.js +1 -1
  59. package/dist/reporter/http/abstract-http-reporter.js +23 -26
  60. package/dist/reporter/http/http-reporter.edge-light.js +134 -57
  61. package/dist/reporter/json/abstract-json-reporter.d.ts +1 -1
  62. package/dist/reporter/json/index.browser.js +2 -2
  63. package/dist/reporter/json/index.js +2 -2
  64. package/dist/reporter/pretty/index.browser.js +1 -1
  65. package/dist/reporter/pretty/index.js +1 -1
  66. package/dist/reporter/pretty/pretty-reporter.server.d.ts +1 -1
  67. package/dist/reporter/raw/raw-reporter.server.d.ts +1 -1
  68. package/dist/reporter/simple/simple-reporter.server.d.ts +1 -1
  69. package/dist/reporter/simple/simple-reporter.server.js +8 -12
  70. package/dist/types.d.ts +4 -4
  71. package/dist/utils/write-console-log-based-on-level.d.ts +1 -1
  72. package/dist/wide-event.d.ts +300 -0
  73. package/dist/wide-event.js +284 -0
  74. package/package.json +73 -20
  75. package/dist/interactive/index.d.ts +0 -2
  76. package/dist/interactive/index.js +0 -2
  77. package/dist/interactive/interactive-manager.d.ts +0 -108
  78. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  79. package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +0 -172
  80. package/dist/packem_shared/PrettyReporter-DgZB2eBG.js +0 -222
  81. package/dist/packem_shared/abstract-pretty-reporter-Di_sdm2r.js +0 -50
  82. package/dist/packem_shared/format-label-De49vNPd.js +0 -1193
  83. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
  84. package/dist/packem_shared/index-DqKWykfa.js +0 -1146
  85. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +0 -141
  86. package/dist/packem_shared/pail.browser-u2CSR_af.js +0 -1427
  87. package/dist/progress-bar.d.ts +0 -136
  88. package/dist/progress-bar.js +0 -404
  89. package/dist/spinner.d.ts +0 -220
  90. package/dist/spinner.js +0 -2150
  91. package/dist/utils/ansi-escapes.d.ts +0 -4
@@ -0,0 +1,99 @@
1
+ const LOG_TYPES = {
2
+ alert: {
3
+ color: "red",
4
+ label: "alert",
5
+ logLevel: "alert"
6
+ },
7
+ await: {
8
+ color: "blue",
9
+ label: "awaiting",
10
+ logLevel: "informational"
11
+ },
12
+ complete: {
13
+ color: "cyan",
14
+ label: "complete",
15
+ logLevel: "informational"
16
+ },
17
+ critical: {
18
+ color: "redBright",
19
+ label: "critical",
20
+ logLevel: "critical"
21
+ },
22
+ debug: {
23
+ color: "gray",
24
+ label: "debug",
25
+ logLevel: "debug"
26
+ },
27
+ emergency: {
28
+ color: "redBright",
29
+ label: "emergency",
30
+ logLevel: "emergency"
31
+ },
32
+ error: {
33
+ color: "red",
34
+ label: "error",
35
+ logLevel: "error"
36
+ },
37
+ info: {
38
+ color: "blueBright",
39
+ label: "info",
40
+ logLevel: "informational"
41
+ },
42
+ log: {
43
+ label: "",
44
+ logLevel: "informational"
45
+ },
46
+ notice: {
47
+ color: "magentaBright",
48
+ label: "notice",
49
+ logLevel: "notice"
50
+ },
51
+ pending: {
52
+ color: "magenta",
53
+ label: "pending",
54
+ logLevel: "informational"
55
+ },
56
+ start: {
57
+ color: "greenBright",
58
+ label: "start",
59
+ logLevel: "informational"
60
+ },
61
+ stop: {
62
+ color: "red",
63
+ label: "stop",
64
+ logLevel: "informational"
65
+ },
66
+ success: {
67
+ color: "green",
68
+ label: "success",
69
+ logLevel: "informational"
70
+ },
71
+ trace: {
72
+ color: "cyanBright",
73
+ label: "trace",
74
+ logLevel: "trace"
75
+ },
76
+ wait: {
77
+ color: "blue",
78
+ label: "waiting",
79
+ logLevel: "informational"
80
+ },
81
+ warn: {
82
+ color: "yellow",
83
+ label: "warning",
84
+ logLevel: "warning"
85
+ },
86
+ warning: {
87
+ color: "yellow",
88
+ label: "warning",
89
+ logLevel: "warning"
90
+ },
91
+ watch: {
92
+ color: "yellowBright",
93
+ label: "watching",
94
+ logLevel: "informational"
95
+ }
96
+ };
97
+ const EMPTY_SYMBOL = /* @__PURE__ */ Symbol("EMPTY");
98
+
99
+ export { EMPTY_SYMBOL as E, LOG_TYPES as L };
@@ -0,0 +1,76 @@
1
+ class PailError extends Error {
2
+ /** HTTP status code (defaults to 500) */
3
+ status;
4
+ /** Explanation of what caused the failure */
5
+ why;
6
+ /** Suggested resolution steps */
7
+ fix;
8
+ /** Link to relevant documentation */
9
+ link;
10
+ constructor(options) {
11
+ const resolvedOptions = typeof options === "string" ? { message: options } : options;
12
+ super(resolvedOptions.message, resolvedOptions.cause === void 0 ? void 0 : { cause: resolvedOptions.cause });
13
+ this.name = "PailError";
14
+ this.status = resolvedOptions.status ?? 500;
15
+ this.why = resolvedOptions.why;
16
+ this.fix = resolvedOptions.fix;
17
+ this.link = resolvedOptions.link;
18
+ }
19
+ /**
20
+ * Converts the error to a JSON-serializable object.
21
+ *
22
+ * Includes all self-documenting fields in the output for structured logging.
23
+ * @returns A plain object representation of the error
24
+ */
25
+ toJSON() {
26
+ const json = {
27
+ message: this.message,
28
+ name: this.name,
29
+ status: this.status
30
+ };
31
+ if (this.why) {
32
+ json.why = this.why;
33
+ }
34
+ if (this.fix) {
35
+ json.fix = this.fix;
36
+ }
37
+ if (this.link) {
38
+ json.link = this.link;
39
+ }
40
+ if (this.stack) {
41
+ json.stack = this.stack;
42
+ }
43
+ if (this.cause !== void 0) {
44
+ json.cause = this.cause instanceof Error ? { message: this.cause.message, name: this.cause.name, stack: this.cause.stack } : this.cause;
45
+ }
46
+ return json;
47
+ }
48
+ /**
49
+ * Returns a formatted string representation including self-documenting fields.
50
+ * @returns Formatted error string with why/fix/link context
51
+ */
52
+ toString() {
53
+ let output = `${this.name} [${String(this.status)}]: ${this.message}`;
54
+ if (this.why) {
55
+ output += `
56
+ Why: ${this.why}`;
57
+ }
58
+ if (this.fix) {
59
+ output += `
60
+ Fix: ${this.fix}`;
61
+ }
62
+ if (this.link) {
63
+ output += `
64
+ Link: ${this.link}`;
65
+ }
66
+ if (this.cause !== void 0) {
67
+ const causeMessage = this.cause instanceof Error ? this.cause.message : String(this.cause);
68
+ output += `
69
+ Cause: ${causeMessage}`;
70
+ }
71
+ return output;
72
+ }
73
+ }
74
+ const createPailError = (options) => new PailError(options);
75
+
76
+ export { PailError, createPailError };
@@ -0,0 +1,127 @@
1
+ import { WideEvent } from '../wide-event.js';
2
+
3
+ const patternToRegex = (pattern) => {
4
+ let regex = "^";
5
+ let index = 0;
6
+ while (index < pattern.length) {
7
+ const char = pattern[index];
8
+ if (char === "*" && pattern[index + 1] === "*") {
9
+ index += 2;
10
+ if (pattern[index] === "/") {
11
+ index += 1;
12
+ }
13
+ if (index >= pattern.length && regex.endsWith("/")) {
14
+ regex = `${regex.slice(0, -1)}(/.*)?`;
15
+ } else if (index >= pattern.length) {
16
+ regex += ".*";
17
+ } else {
18
+ regex += "(.*/)?";
19
+ }
20
+ } else {
21
+ switch (char) {
22
+ case "*": {
23
+ regex += "[^/]*";
24
+ index += 1;
25
+ break;
26
+ }
27
+ case ".": {
28
+ regex += String.raw`\.`;
29
+ index += 1;
30
+ break;
31
+ }
32
+ case "?": {
33
+ regex += "[^/]";
34
+ index += 1;
35
+ break;
36
+ }
37
+ default: {
38
+ regex += char;
39
+ index += 1;
40
+ }
41
+ }
42
+ }
43
+ }
44
+ regex += "$";
45
+ return new RegExp(regex);
46
+ };
47
+ const matchesPattern = (path, pattern) => patternToRegex(pattern).test(path);
48
+ const shouldLog = (path, include, exclude) => {
49
+ if (exclude?.some((pattern) => matchesPattern(path, pattern))) {
50
+ return false;
51
+ }
52
+ if (!include?.length) {
53
+ return true;
54
+ }
55
+ return include.some((pattern) => matchesPattern(path, pattern));
56
+ };
57
+ const getServiceForPath = (path, routes) => {
58
+ if (!routes) {
59
+ return void 0;
60
+ }
61
+ const entries = Object.entries(routes);
62
+ for (let i = 0; i < entries.length; i += 1) {
63
+ const [pattern, config] = entries[i];
64
+ if (matchesPattern(path, pattern)) {
65
+ return config.service;
66
+ }
67
+ }
68
+ return void 0;
69
+ };
70
+
71
+ const createMiddlewareLogger = (options, request) => {
72
+ const { exclude, include, pail, routes, service } = options;
73
+ const { headers, method, path, requestId } = request;
74
+ if (!shouldLog(path, include, exclude)) {
75
+ const noopLogger = new WideEvent({ autoEmit: false, name: `${method} ${path}`, pail });
76
+ return {
77
+ finish: () => {
78
+ },
79
+ logger: noopLogger,
80
+ skipped: true
81
+ };
82
+ }
83
+ const routeService = getServiceForPath(path, routes) ?? service;
84
+ const logger = new WideEvent({
85
+ name: `${method} ${path}`,
86
+ pail,
87
+ service: routeService
88
+ });
89
+ logger.set({
90
+ method,
91
+ path,
92
+ requestId,
93
+ ...headers ? { headers } : {}
94
+ });
95
+ const finish = (finishOptions) => {
96
+ logger.finish(finishOptions);
97
+ };
98
+ return {
99
+ finish,
100
+ logger,
101
+ skipped: false
102
+ };
103
+ };
104
+
105
+ const SENSITIVE_HEADERS = /* @__PURE__ */ new Set(["authorization", "cookie", "proxy-authorization", "set-cookie", "x-api-key", "x-auth-token"]);
106
+ const extractSafeHeaders = (headers) => {
107
+ const safe = {};
108
+ headers.forEach((value, key) => {
109
+ if (!SENSITIVE_HEADERS.has(key.toLowerCase())) {
110
+ safe[key.toLowerCase()] = value;
111
+ }
112
+ });
113
+ return safe;
114
+ };
115
+ const extractSafeNodeHeaders = (headers) => {
116
+ const safe = {};
117
+ const entries = Object.entries(headers);
118
+ for (let i = 0; i < entries.length; i += 1) {
119
+ const [key, value] = entries[i];
120
+ if (!SENSITIVE_HEADERS.has(key.toLowerCase()) && value !== void 0) {
121
+ safe[key.toLowerCase()] = Array.isArray(value) ? value.join(", ") : value;
122
+ }
123
+ }
124
+ return safe;
125
+ };
126
+
127
+ export { extractSafeHeaders as a, createMiddlewareLogger as c, extractSafeNodeHeaders as e };
@@ -1,3 +1,11 @@
1
+ const getLongestLabel = (types) => {
2
+ const labels = Object.keys(types).map((x) => types[x].label ?? "");
3
+ if (labels.length === 0) {
4
+ return "";
5
+ }
6
+ return labels.reduce((x, y) => x.length > y.length ? x : y, "");
7
+ };
8
+
1
9
  const colorKeywords = /* @__PURE__ */ new Map([
2
10
  ["aliceblue", "#f0f8ff"],
3
11
  ["antiquewhite", "#faebd7"],
@@ -163,7 +171,7 @@ const getDefaultCss = () => {
163
171
  textDecorationLine: []
164
172
  };
165
173
  };
166
- const SPACE_PATTERN = /\s+/g;
174
+ const SPACE_PATTERN = /\s+/;
167
175
  const parseCssColor = (colorString) => {
168
176
  if (colorKeywords.has(colorString)) {
169
177
  colorString = colorKeywords.get(colorString);
@@ -229,10 +237,10 @@ const parseCss = (cssString) => {
229
237
  let currentPart = "";
230
238
  for (const c of cssString) {
231
239
  if (c === "(") {
232
- parenthesesDepth++;
240
+ parenthesesDepth += 1;
233
241
  } else if (parenthesesDepth > 0) {
234
242
  if (c === ")") {
235
- parenthesesDepth--;
243
+ parenthesesDepth -= 1;
236
244
  }
237
245
  } else if (inValue) {
238
246
  if (c === ";") {
@@ -365,14 +373,14 @@ const cssToAnsi = (css, previousCss = null) => {
365
373
  default: {
366
374
  if (Array.isArray(css.backgroundColor)) {
367
375
  const { 0: r, 1: g, 2: b } = css.backgroundColor;
368
- ansi += `\x1B[48;2;${r};${g};${b}m`;
376
+ ansi += `\x1B[48;2;${String(r)};${String(g)};${String(b)}m`;
369
377
  } else {
370
378
  const parsed = parseCssColor(css.backgroundColor);
371
379
  if (parsed === null) {
372
380
  ansi += "\x1B[49m";
373
381
  } else {
374
382
  const { 0: r, 1: g, 2: b } = parsed;
375
- ansi += `\x1B[48;2;${r};${g};${b}m`;
383
+ ansi += `\x1B[48;2;${String(r)};${String(g)};${String(b)}m`;
376
384
  }
377
385
  }
378
386
  }
@@ -419,14 +427,14 @@ const cssToAnsi = (css, previousCss = null) => {
419
427
  default: {
420
428
  if (Array.isArray(css.color)) {
421
429
  const { 0: r, 1: g, 2: b } = css.color;
422
- ansi += `\x1B[38;2;${r};${g};${b}m`;
430
+ ansi += `\x1B[38;2;${String(r)};${String(g)};${String(b)}m`;
423
431
  } else {
424
432
  const parsed = parseCssColor(css.color);
425
433
  if (parsed === null) {
426
434
  ansi += "\x1B[39m";
427
435
  } else {
428
436
  const { 0: r, 1: g, 2: b } = parsed;
429
- ansi += `\x1B[38;2;${r};${g};${b}m`;
437
+ ansi += `\x1B[38;2;${String(r)};${String(g)};${String(b)}m`;
430
438
  }
431
439
  }
432
440
  }
@@ -444,7 +452,7 @@ const cssToAnsi = (css, previousCss = null) => {
444
452
  ansi += "\x1B[59m";
445
453
  } else {
446
454
  const { 0: r, 1: g, 2: b } = css.textDecorationColor;
447
- ansi += `\x1B[58;2;${r};${g};${b}m`;
455
+ ansi += `\x1B[58;2;${String(r)};${String(g)};${String(b)}m`;
448
456
  }
449
457
  }
450
458
  if (css.textDecorationLine.includes("line-through") !== previousCss.textDecorationLine.includes("line-through")) {
@@ -487,7 +495,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
487
495
  }
488
496
  const objects = Array.from({ length: argumentsLength });
489
497
  objects[0] = stringify(fmt);
490
- for (let index = 1; index < argumentsLength; index++) {
498
+ for (let index = 1; index < argumentsLength; index += 1) {
491
499
  objects[index] = stringify(arguments_[index - offset]);
492
500
  }
493
501
  return objects.join(" ");
@@ -505,7 +513,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
505
513
  lastPosition = lastPosition > -1 ? lastPosition : 0;
506
514
  const c = fmt.codePointAt(index + 1);
507
515
  if (c === void 0) {
508
- ++a;
516
+ a += 1;
509
517
  break;
510
518
  }
511
519
  switch (c) {
@@ -522,7 +530,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
522
530
  }
523
531
  }
524
532
  lastPosition = index + 2;
525
- index++;
533
+ index += 1;
526
534
  break;
527
535
  }
528
536
  case CHAR_d:
@@ -535,7 +543,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
535
543
  }
536
544
  result += Number(arguments_[a]).toString();
537
545
  lastPosition = index + 2;
538
- index++;
546
+ index += 1;
539
547
  break;
540
548
  }
541
549
  case CHAR_i: {
@@ -547,7 +555,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
547
555
  }
548
556
  result += Math.floor(Number(arguments_[a])).toString();
549
557
  lastPosition = index + 2;
550
- index++;
558
+ index += 1;
551
559
  break;
552
560
  }
553
561
  case CHAR_j:
@@ -573,7 +581,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
573
581
  }
574
582
  result += stringify(temporaryArgument);
575
583
  lastPosition = index + 2;
576
- index++;
584
+ index += 1;
577
585
  break;
578
586
  }
579
587
  case CHAR_PERCENT: {
@@ -582,8 +590,8 @@ const format = (fmt, arguments_ = [], options = {}) => {
582
590
  }
583
591
  result += "%";
584
592
  lastPosition = index + 2;
585
- index++;
586
- a--;
593
+ index += 1;
594
+ a -= 1;
587
595
  break;
588
596
  }
589
597
  case CHAR_s: {
@@ -595,7 +603,7 @@ const format = (fmt, arguments_ = [], options = {}) => {
595
603
  }
596
604
  result += typeof arguments_[a] === "object" ? stringify(arguments_[a]) : String(arguments_[a]);
597
605
  lastPosition = index + 2;
598
- index++;
606
+ index += 1;
599
607
  break;
600
608
  }
601
609
  default: {
@@ -605,13 +613,13 @@ const format = (fmt, arguments_ = [], options = {}) => {
605
613
  }
606
614
  result += options.formatters[c](arguments_[a]);
607
615
  lastPosition = index + 2;
608
- index++;
616
+ index += 1;
609
617
  }
610
618
  }
611
619
  }
612
- ++a;
620
+ a += 1;
613
621
  }
614
- ++index;
622
+ index += 1;
615
623
  }
616
624
  if (lastPosition === -1) {
617
625
  return fmt;
@@ -647,4 +655,4 @@ const build = (options = {}) => {
647
655
  return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
648
656
  };
649
657
 
650
- export { build as b, format as f };
658
+ export { build as b, format as f, getLongestLabel as g };
@@ -0,0 +1,24 @@
1
+ const GLOB_STRIP_RE = /\*+/g;
2
+ const pailMiddleware = (NextResponseClass, options) => {
3
+ const { exclude, include } = options ?? {};
4
+ return (request) => {
5
+ const path = request.nextUrl.pathname;
6
+ if (exclude?.some((p) => path.startsWith(p.replaceAll(GLOB_STRIP_RE, "")))) {
7
+ return NextResponseClass.next();
8
+ }
9
+ if (include?.length && !include.some((p) => path.startsWith(p.replaceAll(GLOB_STRIP_RE, "")))) {
10
+ return NextResponseClass.next();
11
+ }
12
+ const requestId = request.headers.get("x-request-id") ?? crypto.randomUUID();
13
+ const requestHeaders = new Headers(request.headers);
14
+ requestHeaders.set("x-request-id", requestId);
15
+ requestHeaders.set("x-pail-start", String(Date.now()));
16
+ const response = NextResponseClass.next({
17
+ request: { headers: requestHeaders }
18
+ });
19
+ response.headers.set("x-request-id", requestId);
20
+ return response;
21
+ };
22
+ };
23
+
24
+ export { pailMiddleware };
@@ -0,0 +1,36 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ AsyncLocalStorage
22
+ } = __cjs_getBuiltinModule("node:async_hooks");
23
+
24
+ const createLoggerStorage = (contextHint) => {
25
+ const storage = new AsyncLocalStorage();
26
+ const useLogger = () => {
27
+ const logger = storage.getStore();
28
+ if (!logger) {
29
+ throw new Error(`[pail] useLogger() called outside of ${contextHint}`);
30
+ }
31
+ return logger;
32
+ };
33
+ return { storage, useLogger };
34
+ };
35
+
36
+ export { createLoggerStorage as c };
@@ -17,5 +17,17 @@ const __cjs_getBuiltinModule = (module) => {
17
17
  return __cjs_require(module);
18
18
  };
19
19
 
20
+ const {
21
+ AsyncLocalStorage
22
+ } = __cjs_getBuiltinModule("node:async_hooks");
20
23
 
21
- export { I as default } from './interactive-stream-hook-DG4BtN12.js';
24
+ const pailStorage = new AsyncLocalStorage();
25
+ const useLogger = () => {
26
+ const logger = pailStorage.getStore();
27
+ if (!logger) {
28
+ throw new Error("[pail] useLogger() called outside of withPail() context. Wrap your route handler or server action with withPail().");
29
+ }
30
+ return logger;
31
+ };
32
+
33
+ export { pailStorage, useLogger };
@@ -1,14 +1,15 @@
1
1
  const writeConsoleLogBasedOnLevel = (level) => {
2
+ const c = console;
2
3
  if (level === "error") {
3
- return console.__error ?? console.error;
4
+ return c.__error ?? console.error;
4
5
  }
5
6
  if (level === "warn") {
6
- return console.__warn ?? console.warn;
7
+ return c.__warn ?? console.warn;
7
8
  }
8
9
  if (level === "trace") {
9
- return console.__trace ?? console.trace;
10
+ return c.__trace ?? console.trace;
10
11
  }
11
- return console.__log ?? console.log;
12
+ return c.__log ?? console.log;
12
13
  };
13
14
 
14
15
  export { writeConsoleLogBasedOnLevel as w };
@@ -1,5 +1,5 @@
1
1
  const writeStream = (data, stream) => {
2
- const write = stream.__write ?? stream.write;
2
+ const write = stream["__write"] ?? stream.write.bind(stream);
3
3
  return write.call(stream, data);
4
4
  };
5
5
 
@@ -403,7 +403,7 @@ export declare class PailBrowserImpl<T extends string = string, L extends string
403
403
  protected extendReporter(reporter: Reporter<L>): Reporter<L>;
404
404
  protected registerReporters(reporters: Reporter<L>[]): void;
405
405
  protected registerProcessors(processors: Processor<L>[]): void;
406
- protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: any[]): void;
406
+ protected logger(type: LiteralUnion<DefaultLogTypes, T>, raw: boolean, force: boolean, ...messageObject: unknown[]): void;
407
407
  }
408
408
  export type PailBrowserType<T extends string = string, L extends string = string> = Console & (new <TC extends string = string, LC extends string = string>(options?: ConstructorOptions<TC, LC>) => PailBrowserType<TC, LC>) & PailBrowserImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & {
409
409
  force: Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction>;
@@ -1,9 +1,5 @@
1
- import InteractiveManager from "./interactive/interactive-manager.d.ts";
1
+ import { InteractiveManager } from "@visulima/interactive-manager";
2
2
  import { PailBrowserImpl } from "./pail.d.ts";
3
- import type { MultiBarOptions, SingleBarOptions } from "./progress-bar.d.ts";
4
- import { MultiProgressBar, ProgressBar } from "./progress-bar.d.ts";
5
- import type { SpinnerOptions } from "./spinner.d.ts";
6
- import { MultiSpinner, Spinner } from "./spinner.d.ts";
7
3
  import type { ConstructorOptions, DefaultLogTypes, LoggerFunction, Reporter, ServerConstructorOptions } from "./types.d.ts";
8
4
  declare class PailServerImpl<T extends string = string, L extends string = string> extends PailBrowserImpl<T, L> {
9
5
  #private;
@@ -138,77 +134,6 @@ declare class PailServerImpl<T extends string = string, L extends string = strin
138
134
  * ```
139
135
  */
140
136
  restoreAll(): void;
141
- /**
142
- * Creates a single progress bar.
143
- * @param options Configuration options for the progress bar
144
- * @returns A new ProgressBar instance
145
- * @example
146
- * ```typescript
147
- * const logger = createPail({ interactive: true });
148
- * const bar = logger.createProgressBar({
149
- * total: 100,
150
- * format: 'Downloading [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}'
151
- * });
152
- *
153
- * bar.start();
154
- * // ... do work and update progress
155
- * bar.update(50);
156
- * bar.stop();
157
- * ```
158
- */
159
- createProgressBar(options: SingleBarOptions): ProgressBar;
160
- /**
161
- * Creates a multi-bar progress manager for displaying multiple progress bars.
162
- * @param options Configuration options for the multi-bar manager
163
- * @returns A new MultiProgressBar instance
164
- * @example
165
- * ```typescript
166
- * const logger = createPail({ interactive: true });
167
- * const multiBar = logger.createMultiProgressBar();
168
- *
169
- * const bar1 = multiBar.create(100);
170
- * const bar2 = multiBar.create(200);
171
- *
172
- * bar1.start();
173
- * bar2.start();
174
- * // ... update bars as needed
175
- * multiBar.stop();
176
- * ```
177
- */
178
- createMultiProgressBar(options?: MultiBarOptions): MultiProgressBar;
179
- /**
180
- * Creates a single spinner.
181
- * @param options Configuration options for the spinner
182
- * @returns A new Spinner instance
183
- * @example
184
- * ```typescript
185
- * const logger = createPail({ interactive: true });
186
- * const spinner = logger.createSpinner({ name: 'dots' });
187
- * spinner.start('Loading...');
188
- * // ... do work
189
- * spinner.succeed('Done');
190
- * ```
191
- */
192
- createSpinner(options?: SpinnerOptions): Spinner;
193
- /**
194
- * Creates a multi-spinner manager for displaying multiple spinners.
195
- * @param options Configuration options for the multi-spinner manager
196
- * @returns A new MultiSpinner instance
197
- * @example
198
- * ```typescript
199
- * const logger = createPail({ interactive: true });
200
- * const multiSpinner = logger.createMultiSpinner();
201
- *
202
- * const spinner1 = multiSpinner.create('Loading 1');
203
- * const spinner2 = multiSpinner.create('Loading 2');
204
- *
205
- * spinner1.start();
206
- * spinner2.start();
207
- * // ... update spinners as needed
208
- * multiSpinner.stop();
209
- * ```
210
- */
211
- createMultiSpinner(options?: SpinnerOptions): MultiSpinner;
212
137
  /**
213
138
  * Clears the terminal screen.
214
139
  *
@@ -18,7 +18,7 @@ const getCallerFilename = () => {
18
18
  });
19
19
  return accumulator;
20
20
  }, []);
21
- const firstExternalFilePath = callers[0];
21
+ const firstExternalFilePath = callers.at(0);
22
22
  if (firstExternalFilePath) {
23
23
  return {
24
24
  columnNumber: firstExternalFilePath.columnNumber ?? void 0,