@visulima/pail 4.0.0-alpha.12 → 4.0.0-alpha.14

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 (85) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +4 -1
  3. package/dist/error.js +5 -76
  4. package/dist/index.browser.js +19 -1499
  5. package/dist/index.server.js +31 -2804
  6. package/dist/middleware/elysia.d.ts +3 -3
  7. package/dist/middleware/elysia.js +1 -70
  8. package/dist/middleware/express.d.ts +3 -3
  9. package/dist/middleware/express.js +1 -29
  10. package/dist/middleware/fastify.d.ts +3 -3
  11. package/dist/middleware/fastify.js +1 -46
  12. package/dist/middleware/hono.d.ts +3 -3
  13. package/dist/middleware/hono.js +1 -33
  14. package/dist/middleware/next/handler.d.ts +5 -5
  15. package/dist/middleware/next/handler.js +1 -53
  16. package/dist/middleware/sveltekit.d.ts +3 -3
  17. package/dist/middleware/sveltekit.js +1 -43
  18. package/dist/object-tree.js +2 -89
  19. package/dist/packem_shared/AbstractJsonReporter-D_Pb6kpB.js +1 -0
  20. package/dist/packem_shared/AbstractJsonReporter-PVC4ONf2.js +1 -0
  21. package/dist/packem_shared/JsonReporter-BEEmb0W4.js +2 -0
  22. package/dist/packem_shared/JsonReporter-CE-lw7R0.js +1 -0
  23. package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
  24. package/dist/packem_shared/PrettyReporter-N7FvHzl5.js +44 -0
  25. package/dist/packem_shared/{abstract-json-reporter.d-BAgznjyU.d.ts → abstract-json-reporter.d-Boj5w068.d.ts} +1 -1
  26. package/dist/packem_shared/abstract-pretty-reporter-Bag7lQKf.js +33 -0
  27. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  28. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  29. package/dist/packem_shared/{create-middleware-logger.d-DheMh8q4.d.ts → create-middleware-logger.d-CMQdVeVE.d.ts} +2 -2
  30. package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
  31. package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
  32. package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
  33. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
  34. package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
  35. package/dist/packem_shared/{types.d-BeLumqgD.d.ts → types.d-Ck_RSjLg.d.ts} +1 -1
  36. package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
  37. package/dist/packem_shared/{wide-event.d-B-t8ZnhI.d.ts → wide-event.d-DA-6dTPc.d.ts} +1 -1
  38. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
  39. package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
  40. package/dist/processor/caller/caller-processor.d.ts +1 -1
  41. package/dist/processor/caller/caller-processor.js +1 -59
  42. package/dist/processor/environment-processor.d.ts +1 -1
  43. package/dist/processor/environment-processor.js +1 -82
  44. package/dist/processor/message-formatter-processor.d.ts +1 -1
  45. package/dist/processor/message-formatter-processor.js +1 -715
  46. package/dist/processor/opentelemetry-processor.d.ts +1 -1
  47. package/dist/processor/opentelemetry-processor.js +1 -52
  48. package/dist/processor/redact-processor.d.ts +1 -1
  49. package/dist/processor/redact-processor.js +1 -31
  50. package/dist/processor/sampling-processor.d.ts +1 -1
  51. package/dist/processor/sampling-processor.js +1 -59
  52. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  53. package/dist/reporter/file/json-file-reporter.js +2 -136
  54. package/dist/reporter/http/abstract-http-reporter.d.ts +2 -2
  55. package/dist/reporter/http/abstract-http-reporter.js +2 -432
  56. package/dist/reporter/http/http-reporter.d.ts +2 -2
  57. package/dist/reporter/http/http-reporter.edge-light.js +2 -728
  58. package/dist/reporter/http/http-reporter.js +1 -13
  59. package/dist/reporter/json/index.browser.js +1 -2
  60. package/dist/reporter/json/index.d.ts +2 -2
  61. package/dist/reporter/json/index.js +1 -2
  62. package/dist/reporter/pretty/index.browser.js +1 -1
  63. package/dist/reporter/pretty/index.d.ts +1 -1
  64. package/dist/reporter/pretty/index.js +1 -1
  65. package/dist/reporter/simple/simple-reporter.server.js +8 -183
  66. package/dist/wide-event.d.ts +2 -2
  67. package/dist/wide-event.js +1 -284
  68. package/package.json +24 -24
  69. package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
  70. package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
  71. package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
  72. package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
  73. package/dist/packem_shared/PrettyReporter-CIbrmjUV.js +0 -213
  74. package/dist/packem_shared/PrettyReporter-CNJEO9g7.js +0 -2723
  75. package/dist/packem_shared/abstract-pretty-reporter-CkqCt5hg.js +0 -2637
  76. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  77. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  78. package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
  79. package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
  80. package/dist/packem_shared/index-6cG1Kp0t.js +0 -658
  81. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  82. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  83. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  84. package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
  85. package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
@@ -1,2804 +1,31 @@
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 {
8
- stdout,
9
- stderr,
10
- env
11
- } = __cjs_getProcess;
12
- import { InteractiveManager, InteractiveStreamHook } from '@visulima/interactive-manager';
13
- import { g as getLongestLabel, E as EXTENDED_RFC_5424_LOG_LEVELS, a as EMPTY_SYMBOL, L as LOG_TYPES, i as inspect, w as writeStream, A as AbstractPrettyReporter, d as defaultInspectorConfig, t as terminalSize, b as getLongestBadge, c as getStringWidth, f as formatLabel, e as wordWrap, r as renderError, W as WrapMode } from './packem_shared/abstract-pretty-reporter-CkqCt5hg.js';
14
- import colorize from '@visulima/colorize';
15
- export { PailError, createPailError } from './packem_shared/createPailError-B_sgL0nF.js';
16
-
17
- const ESC = "\x1B";
18
- const CSI = `${ESC}[`;
19
-
20
- const isBrowser = typeof globalThis !== "undefined" && typeof globalThis.window === "object" && globalThis.window.document !== void 0;
21
- const OSTYPE_REGEX = /^(?:msys|cygwin)$/;
22
- const isWindows = !isBrowser && (process.platform === "win32" || OSTYPE_REGEX.test(process.env.OSTYPE));
23
-
24
- var EraseDisplayMode = /* @__PURE__ */ ((EraseDisplayMode2) => {
25
- EraseDisplayMode2[EraseDisplayMode2["ToEnd"] = 0] = "ToEnd";
26
- EraseDisplayMode2[EraseDisplayMode2["ToBeginning"] = 1] = "ToBeginning";
27
- EraseDisplayMode2[EraseDisplayMode2["EntireScreen"] = 2] = "EntireScreen";
28
- EraseDisplayMode2[EraseDisplayMode2["EntireScreenAndScrollback"] = 3] = "EntireScreenAndScrollback";
29
- return EraseDisplayMode2;
30
- })(EraseDisplayMode || {});
31
- const eraseDisplay = (mode) => {
32
- const validMode = mode >= 0 && mode <= 3 ? mode : 0;
33
- return `${CSI}${validMode === 0 ? "" : String(validMode)}J`;
34
- };
35
-
36
- const resetTerminal = isWindows ? `${eraseDisplay(EraseDisplayMode.EntireScreen)}${CSI}0f` : `${eraseDisplay(EraseDisplayMode.EntireScreen)}${eraseDisplay(EraseDisplayMode.EntireScreenAndScrollback)}${CSI}H${ESC}c`;
37
-
38
- function getDefaultExportFromCjs(x) {
39
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
40
- }
41
-
42
- var safeStableStringify = {exports: {}};
43
-
44
- var hasRequiredSafeStableStringify;
45
-
46
- function requireSafeStableStringify () {
47
- if (hasRequiredSafeStableStringify) return safeStableStringify.exports;
48
- hasRequiredSafeStableStringify = 1;
49
- (function (module, exports$1) {
50
- const { hasOwnProperty } = Object.prototype;
51
- const stringify = configure();
52
- stringify.configure = configure;
53
- stringify.stringify = stringify;
54
- stringify.default = stringify;
55
- exports$1.stringify = stringify;
56
- exports$1.configure = configure;
57
- module.exports = stringify;
58
- const strEscapeSequencesRegExp = /[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;
59
- function strEscape(str) {
60
- if (str.length < 5e3 && !strEscapeSequencesRegExp.test(str)) {
61
- return `"${str}"`;
62
- }
63
- return JSON.stringify(str);
64
- }
65
- function sort(array, comparator) {
66
- if (array.length > 200 || comparator) {
67
- return array.sort(comparator);
68
- }
69
- for (let i = 1; i < array.length; i++) {
70
- const currentValue = array[i];
71
- let position = i;
72
- while (position !== 0 && array[position - 1] > currentValue) {
73
- array[position] = array[position - 1];
74
- position--;
75
- }
76
- array[position] = currentValue;
77
- }
78
- return array;
79
- }
80
- const typedArrayPrototypeGetSymbolToStringTag = Object.getOwnPropertyDescriptor(
81
- Object.getPrototypeOf(
82
- Object.getPrototypeOf(
83
- new Int8Array()
84
- )
85
- ),
86
- Symbol.toStringTag
87
- ).get;
88
- function isTypedArrayWithEntries(value) {
89
- return typedArrayPrototypeGetSymbolToStringTag.call(value) !== void 0 && value.length !== 0;
90
- }
91
- function stringifyTypedArray(array, separator, maximumBreadth) {
92
- if (array.length < maximumBreadth) {
93
- maximumBreadth = array.length;
94
- }
95
- const whitespace = separator === "," ? "" : " ";
96
- let res = `"0":${whitespace}${array[0]}`;
97
- for (let i = 1; i < maximumBreadth; i++) {
98
- res += `${separator}"${i}":${whitespace}${array[i]}`;
99
- }
100
- return res;
101
- }
102
- function getCircularValueOption(options) {
103
- if (hasOwnProperty.call(options, "circularValue")) {
104
- const circularValue = options.circularValue;
105
- if (typeof circularValue === "string") {
106
- return `"${circularValue}"`;
107
- }
108
- if (circularValue == null) {
109
- return circularValue;
110
- }
111
- if (circularValue === Error || circularValue === TypeError) {
112
- return {
113
- toString() {
114
- throw new TypeError("Converting circular structure to JSON");
115
- }
116
- };
117
- }
118
- throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined');
119
- }
120
- return '"[Circular]"';
121
- }
122
- function getDeterministicOption(options) {
123
- let value;
124
- if (hasOwnProperty.call(options, "deterministic")) {
125
- value = options.deterministic;
126
- if (typeof value !== "boolean" && typeof value !== "function") {
127
- throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');
128
- }
129
- }
130
- return value === void 0 ? true : value;
131
- }
132
- function getBooleanOption(options, key) {
133
- let value;
134
- if (hasOwnProperty.call(options, key)) {
135
- value = options[key];
136
- if (typeof value !== "boolean") {
137
- throw new TypeError(`The "${key}" argument must be of type boolean`);
138
- }
139
- }
140
- return value === void 0 ? true : value;
141
- }
142
- function getPositiveIntegerOption(options, key) {
143
- let value;
144
- if (hasOwnProperty.call(options, key)) {
145
- value = options[key];
146
- if (typeof value !== "number") {
147
- throw new TypeError(`The "${key}" argument must be of type number`);
148
- }
149
- if (!Number.isInteger(value)) {
150
- throw new TypeError(`The "${key}" argument must be an integer`);
151
- }
152
- if (value < 1) {
153
- throw new RangeError(`The "${key}" argument must be >= 1`);
154
- }
155
- }
156
- return value === void 0 ? Infinity : value;
157
- }
158
- function getItemCount(number) {
159
- if (number === 1) {
160
- return "1 item";
161
- }
162
- return `${number} items`;
163
- }
164
- function getUniqueReplacerSet(replacerArray) {
165
- const replacerSet = /* @__PURE__ */ new Set();
166
- for (const value of replacerArray) {
167
- if (typeof value === "string" || typeof value === "number") {
168
- replacerSet.add(String(value));
169
- }
170
- }
171
- return replacerSet;
172
- }
173
- function getStrictOption(options) {
174
- if (hasOwnProperty.call(options, "strict")) {
175
- const value = options.strict;
176
- if (typeof value !== "boolean") {
177
- throw new TypeError('The "strict" argument must be of type boolean');
178
- }
179
- if (value) {
180
- return (value2) => {
181
- let message = `Object can not safely be stringified. Received type ${typeof value2}`;
182
- if (typeof value2 !== "function") message += ` (${value2.toString()})`;
183
- throw new Error(message);
184
- };
185
- }
186
- }
187
- }
188
- function configure(options) {
189
- options = { ...options };
190
- const fail = getStrictOption(options);
191
- if (fail) {
192
- if (options.bigint === void 0) {
193
- options.bigint = false;
194
- }
195
- if (!("circularValue" in options)) {
196
- options.circularValue = Error;
197
- }
198
- }
199
- const circularValue = getCircularValueOption(options);
200
- const bigint = getBooleanOption(options, "bigint");
201
- const deterministic = getDeterministicOption(options);
202
- const comparator = typeof deterministic === "function" ? deterministic : void 0;
203
- const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
204
- const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
205
- function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
206
- let value = parent[key];
207
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
208
- value = value.toJSON(key);
209
- }
210
- value = replacer.call(parent, key, value);
211
- switch (typeof value) {
212
- case "string":
213
- return strEscape(value);
214
- case "object": {
215
- if (value === null) {
216
- return "null";
217
- }
218
- if (stack.indexOf(value) !== -1) {
219
- return circularValue;
220
- }
221
- let res = "";
222
- let join = ",";
223
- const originalIndentation = indentation;
224
- if (Array.isArray(value)) {
225
- if (value.length === 0) {
226
- return "[]";
227
- }
228
- if (maximumDepth < stack.length + 1) {
229
- return '"[Array]"';
230
- }
231
- stack.push(value);
232
- if (spacer !== "") {
233
- indentation += spacer;
234
- res += `
235
- ${indentation}`;
236
- join = `,
237
- ${indentation}`;
238
- }
239
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
240
- let i = 0;
241
- for (; i < maximumValuesToStringify - 1; i++) {
242
- const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
243
- res += tmp2 !== void 0 ? tmp2 : "null";
244
- res += join;
245
- }
246
- const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
247
- res += tmp !== void 0 ? tmp : "null";
248
- if (value.length - 1 > maximumBreadth) {
249
- const removedKeys = value.length - maximumBreadth - 1;
250
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
251
- }
252
- if (spacer !== "") {
253
- res += `
254
- ${originalIndentation}`;
255
- }
256
- stack.pop();
257
- return `[${res}]`;
258
- }
259
- let keys = Object.keys(value);
260
- const keyLength = keys.length;
261
- if (keyLength === 0) {
262
- return "{}";
263
- }
264
- if (maximumDepth < stack.length + 1) {
265
- return '"[Object]"';
266
- }
267
- let whitespace = "";
268
- let separator = "";
269
- if (spacer !== "") {
270
- indentation += spacer;
271
- join = `,
272
- ${indentation}`;
273
- whitespace = " ";
274
- }
275
- const maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
276
- if (deterministic && !isTypedArrayWithEntries(value)) {
277
- keys = sort(keys, comparator);
278
- }
279
- stack.push(value);
280
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
281
- const key2 = keys[i];
282
- const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
283
- if (tmp !== void 0) {
284
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
285
- separator = join;
286
- }
287
- }
288
- if (keyLength > maximumBreadth) {
289
- const removedKeys = keyLength - maximumBreadth;
290
- res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
291
- separator = join;
292
- }
293
- if (spacer !== "" && separator.length > 1) {
294
- res = `
295
- ${indentation}${res}
296
- ${originalIndentation}`;
297
- }
298
- stack.pop();
299
- return `{${res}}`;
300
- }
301
- case "number":
302
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
303
- case "boolean":
304
- return value === true ? "true" : "false";
305
- case "undefined":
306
- return void 0;
307
- case "bigint":
308
- if (bigint) {
309
- return String(value);
310
- }
311
- // fallthrough
312
- default:
313
- return fail ? fail(value) : void 0;
314
- }
315
- }
316
- function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
317
- if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
318
- value = value.toJSON(key);
319
- }
320
- switch (typeof value) {
321
- case "string":
322
- return strEscape(value);
323
- case "object": {
324
- if (value === null) {
325
- return "null";
326
- }
327
- if (stack.indexOf(value) !== -1) {
328
- return circularValue;
329
- }
330
- const originalIndentation = indentation;
331
- let res = "";
332
- let join = ",";
333
- if (Array.isArray(value)) {
334
- if (value.length === 0) {
335
- return "[]";
336
- }
337
- if (maximumDepth < stack.length + 1) {
338
- return '"[Array]"';
339
- }
340
- stack.push(value);
341
- if (spacer !== "") {
342
- indentation += spacer;
343
- res += `
344
- ${indentation}`;
345
- join = `,
346
- ${indentation}`;
347
- }
348
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
349
- let i = 0;
350
- for (; i < maximumValuesToStringify - 1; i++) {
351
- const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
352
- res += tmp2 !== void 0 ? tmp2 : "null";
353
- res += join;
354
- }
355
- const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
356
- res += tmp !== void 0 ? tmp : "null";
357
- if (value.length - 1 > maximumBreadth) {
358
- const removedKeys = value.length - maximumBreadth - 1;
359
- res += `${join}"... ${getItemCount(removedKeys)} not stringified"`;
360
- }
361
- if (spacer !== "") {
362
- res += `
363
- ${originalIndentation}`;
364
- }
365
- stack.pop();
366
- return `[${res}]`;
367
- }
368
- stack.push(value);
369
- let whitespace = "";
370
- if (spacer !== "") {
371
- indentation += spacer;
372
- join = `,
373
- ${indentation}`;
374
- whitespace = " ";
375
- }
376
- let separator = "";
377
- for (const key2 of replacer) {
378
- const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
379
- if (tmp !== void 0) {
380
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
381
- separator = join;
382
- }
383
- }
384
- if (spacer !== "" && separator.length > 1) {
385
- res = `
386
- ${indentation}${res}
387
- ${originalIndentation}`;
388
- }
389
- stack.pop();
390
- return `{${res}}`;
391
- }
392
- case "number":
393
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
394
- case "boolean":
395
- return value === true ? "true" : "false";
396
- case "undefined":
397
- return void 0;
398
- case "bigint":
399
- if (bigint) {
400
- return String(value);
401
- }
402
- // fallthrough
403
- default:
404
- return fail ? fail(value) : void 0;
405
- }
406
- }
407
- function stringifyIndent(key, value, stack, spacer, indentation) {
408
- switch (typeof value) {
409
- case "string":
410
- return strEscape(value);
411
- case "object": {
412
- if (value === null) {
413
- return "null";
414
- }
415
- if (typeof value.toJSON === "function") {
416
- value = value.toJSON(key);
417
- if (typeof value !== "object") {
418
- return stringifyIndent(key, value, stack, spacer, indentation);
419
- }
420
- if (value === null) {
421
- return "null";
422
- }
423
- }
424
- if (stack.indexOf(value) !== -1) {
425
- return circularValue;
426
- }
427
- const originalIndentation = indentation;
428
- if (Array.isArray(value)) {
429
- if (value.length === 0) {
430
- return "[]";
431
- }
432
- if (maximumDepth < stack.length + 1) {
433
- return '"[Array]"';
434
- }
435
- stack.push(value);
436
- indentation += spacer;
437
- let res2 = `
438
- ${indentation}`;
439
- const join2 = `,
440
- ${indentation}`;
441
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
442
- let i = 0;
443
- for (; i < maximumValuesToStringify - 1; i++) {
444
- const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
445
- res2 += tmp2 !== void 0 ? tmp2 : "null";
446
- res2 += join2;
447
- }
448
- const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
449
- res2 += tmp !== void 0 ? tmp : "null";
450
- if (value.length - 1 > maximumBreadth) {
451
- const removedKeys = value.length - maximumBreadth - 1;
452
- res2 += `${join2}"... ${getItemCount(removedKeys)} not stringified"`;
453
- }
454
- res2 += `
455
- ${originalIndentation}`;
456
- stack.pop();
457
- return `[${res2}]`;
458
- }
459
- let keys = Object.keys(value);
460
- const keyLength = keys.length;
461
- if (keyLength === 0) {
462
- return "{}";
463
- }
464
- if (maximumDepth < stack.length + 1) {
465
- return '"[Object]"';
466
- }
467
- indentation += spacer;
468
- const join = `,
469
- ${indentation}`;
470
- let res = "";
471
- let separator = "";
472
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
473
- if (isTypedArrayWithEntries(value)) {
474
- res += stringifyTypedArray(value, join, maximumBreadth);
475
- keys = keys.slice(value.length);
476
- maximumPropertiesToStringify -= value.length;
477
- separator = join;
478
- }
479
- if (deterministic) {
480
- keys = sort(keys, comparator);
481
- }
482
- stack.push(value);
483
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
484
- const key2 = keys[i];
485
- const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
486
- if (tmp !== void 0) {
487
- res += `${separator}${strEscape(key2)}: ${tmp}`;
488
- separator = join;
489
- }
490
- }
491
- if (keyLength > maximumBreadth) {
492
- const removedKeys = keyLength - maximumBreadth;
493
- res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
494
- separator = join;
495
- }
496
- if (separator !== "") {
497
- res = `
498
- ${indentation}${res}
499
- ${originalIndentation}`;
500
- }
501
- stack.pop();
502
- return `{${res}}`;
503
- }
504
- case "number":
505
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
506
- case "boolean":
507
- return value === true ? "true" : "false";
508
- case "undefined":
509
- return void 0;
510
- case "bigint":
511
- if (bigint) {
512
- return String(value);
513
- }
514
- // fallthrough
515
- default:
516
- return fail ? fail(value) : void 0;
517
- }
518
- }
519
- function stringifySimple(key, value, stack) {
520
- switch (typeof value) {
521
- case "string":
522
- return strEscape(value);
523
- case "object": {
524
- if (value === null) {
525
- return "null";
526
- }
527
- if (typeof value.toJSON === "function") {
528
- value = value.toJSON(key);
529
- if (typeof value !== "object") {
530
- return stringifySimple(key, value, stack);
531
- }
532
- if (value === null) {
533
- return "null";
534
- }
535
- }
536
- if (stack.indexOf(value) !== -1) {
537
- return circularValue;
538
- }
539
- let res = "";
540
- const hasLength = value.length !== void 0;
541
- if (hasLength && Array.isArray(value)) {
542
- if (value.length === 0) {
543
- return "[]";
544
- }
545
- if (maximumDepth < stack.length + 1) {
546
- return '"[Array]"';
547
- }
548
- stack.push(value);
549
- const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
550
- let i = 0;
551
- for (; i < maximumValuesToStringify - 1; i++) {
552
- const tmp2 = stringifySimple(String(i), value[i], stack);
553
- res += tmp2 !== void 0 ? tmp2 : "null";
554
- res += ",";
555
- }
556
- const tmp = stringifySimple(String(i), value[i], stack);
557
- res += tmp !== void 0 ? tmp : "null";
558
- if (value.length - 1 > maximumBreadth) {
559
- const removedKeys = value.length - maximumBreadth - 1;
560
- res += `,"... ${getItemCount(removedKeys)} not stringified"`;
561
- }
562
- stack.pop();
563
- return `[${res}]`;
564
- }
565
- let keys = Object.keys(value);
566
- const keyLength = keys.length;
567
- if (keyLength === 0) {
568
- return "{}";
569
- }
570
- if (maximumDepth < stack.length + 1) {
571
- return '"[Object]"';
572
- }
573
- let separator = "";
574
- let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
575
- if (hasLength && isTypedArrayWithEntries(value)) {
576
- res += stringifyTypedArray(value, ",", maximumBreadth);
577
- keys = keys.slice(value.length);
578
- maximumPropertiesToStringify -= value.length;
579
- separator = ",";
580
- }
581
- if (deterministic) {
582
- keys = sort(keys, comparator);
583
- }
584
- stack.push(value);
585
- for (let i = 0; i < maximumPropertiesToStringify; i++) {
586
- const key2 = keys[i];
587
- const tmp = stringifySimple(key2, value[key2], stack);
588
- if (tmp !== void 0) {
589
- res += `${separator}${strEscape(key2)}:${tmp}`;
590
- separator = ",";
591
- }
592
- }
593
- if (keyLength > maximumBreadth) {
594
- const removedKeys = keyLength - maximumBreadth;
595
- res += `${separator}"...":"${getItemCount(removedKeys)} not stringified"`;
596
- }
597
- stack.pop();
598
- return `{${res}}`;
599
- }
600
- case "number":
601
- return isFinite(value) ? String(value) : fail ? fail(value) : "null";
602
- case "boolean":
603
- return value === true ? "true" : "false";
604
- case "undefined":
605
- return void 0;
606
- case "bigint":
607
- if (bigint) {
608
- return String(value);
609
- }
610
- // fallthrough
611
- default:
612
- return fail ? fail(value) : void 0;
613
- }
614
- }
615
- function stringify2(value, replacer, space) {
616
- if (arguments.length > 1) {
617
- let spacer = "";
618
- if (typeof space === "number") {
619
- spacer = " ".repeat(Math.min(space, 10));
620
- } else if (typeof space === "string") {
621
- spacer = space.slice(0, 10);
622
- }
623
- if (replacer != null) {
624
- if (typeof replacer === "function") {
625
- return stringifyFnReplacer("", { "": value }, [], replacer, spacer, "");
626
- }
627
- if (Array.isArray(replacer)) {
628
- return stringifyArrayReplacer("", value, [], getUniqueReplacerSet(replacer), spacer, "");
629
- }
630
- }
631
- if (spacer.length !== 0) {
632
- return stringifyIndent("", value, [], spacer, "");
633
- }
634
- }
635
- return stringifySimple("", value, []);
636
- }
637
- return stringify2;
638
- }
639
- } (safeStableStringify, safeStableStringify.exports));
640
- return safeStableStringify.exports;
641
- }
642
-
643
- var safeStableStringifyExports = requireSafeStableStringify();
644
- const cjsModule = /*@__PURE__*/getDefaultExportFromCjs(safeStableStringifyExports);
645
-
646
- const configure = cjsModule.configure;
647
-
648
- const writeConsoleLogBasedOnLevel = (level) => {
649
- const c = console;
650
- if (level === "error") {
651
- return c.__error ?? console.error;
652
- }
653
- if (level === "warn") {
654
- return c.__warn ?? console.warn;
655
- }
656
- if (level === "trace") {
657
- return c.__trace ?? console.trace;
658
- }
659
- return c.__log ?? console.log;
660
- };
661
-
662
- let RawReporter$1 = class RawReporter {
663
- // eslint-disable-next-line class-methods-use-this
664
- log(meta) {
665
- const { context = [], message, type } = meta;
666
- const consoleLogFunction = writeConsoleLogBasedOnLevel(type.level);
667
- consoleLogFunction(message, ...context);
668
- }
669
- };
670
-
671
- const arrayify = (x) => {
672
- if (x === void 0) {
673
- return [];
674
- }
675
- return Array.isArray(x) ? x : [x];
676
- };
677
-
678
- const mergeTypes = (standard, custom) => {
679
- const types = { ...standard };
680
- Object.keys(custom).forEach((type) => {
681
- types[type] = { ...types[type], ...custom[type] };
682
- });
683
- return types;
684
- };
685
-
686
- const preventLoop = (function_) => {
687
- let doing = false;
688
- return function(...args) {
689
- if (doing) {
690
- return void 0;
691
- }
692
- doing = true;
693
- try {
694
- const result = function_.apply(this, args);
695
- doing = false;
696
- return result;
697
- } catch (error) {
698
- doing = false;
699
- throw error;
700
- }
701
- };
702
- };
703
- class PailBrowserImpl {
704
- timersMap;
705
- countMap;
706
- seqTimers;
707
- lastLog;
708
- logLevels;
709
- disabled;
710
- paused;
711
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
712
- messageQueue;
713
- scopeName;
714
- types;
715
- longestLabel;
716
- processors;
717
- generalLogLevel;
718
- reporters;
719
- throttle;
720
- throttleMin;
721
- stringify;
722
- groups;
723
- startTimerMessage;
724
- endTimerMessage;
725
- rawReporter;
726
- force = {};
727
- /**
728
- * Creates a new Pail browser logger instance.
729
- *
730
- * Initializes the logger with the provided configuration options,
731
- * setting up reporters, processors, log levels, and other internal state.
732
- * @param options Configuration options for the logger
733
- */
734
- constructor(options) {
735
- this.throttle = options.throttle ?? 1e3;
736
- this.throttleMin = options.throttleMin ?? 5;
737
- const parentLongestLabel = options.parentLongestLabel;
738
- const parentTypes = options.parentTypes;
739
- const parentStringify = options.parentStringify;
740
- const parentLogLevels = options.parentLogLevels;
741
- this.stringify = parentStringify ?? configure({
742
- strict: true
743
- });
744
- this.startTimerMessage = options.messages?.timerStart ?? "Initialized timer...";
745
- this.endTimerMessage = options.messages?.timerEnd ?? "Timer run for:";
746
- if (parentTypes && parentLongestLabel) {
747
- this.types = parentTypes;
748
- this.longestLabel = parentLongestLabel;
749
- } else {
750
- this.types = mergeTypes(LOG_TYPES, options.types ?? {});
751
- this.longestLabel = getLongestLabel(this.types);
752
- }
753
- this.logLevels = parentLogLevels && !options.logLevels ? parentLogLevels : { ...EXTENDED_RFC_5424_LOG_LEVELS, ...options.logLevels };
754
- this.generalLogLevel = this.#normalizeLogLevel(options.logLevel);
755
- this.reporters = /* @__PURE__ */ new Set();
756
- this.processors = /* @__PURE__ */ new Set();
757
- this.disabled = options.disabled ?? false;
758
- this.paused = false;
759
- this.messageQueue = [];
760
- this.scopeName = arrayify(options.scope).filter(Boolean);
761
- this.timersMap = /* @__PURE__ */ new Map();
762
- this.countMap = /* @__PURE__ */ new Map();
763
- this.groups = [];
764
- this.seqTimers = /* @__PURE__ */ new Set();
765
- this.lastLog = {};
766
- this.logger = preventLoop(this.logger.bind(this));
767
- this.#initializeBoundMethods();
768
- if (Array.isArray(options.reporters)) {
769
- this.registerReporters(options.reporters);
770
- }
771
- this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter$1());
772
- if (Array.isArray(options.processors)) {
773
- this.registerProcessors(options.processors);
774
- }
775
- }
776
- /**
777
- * Initializes bound methods for all logger types.
778
- *
779
- * Creates bound methods for both regular and force logging methods.
780
- * This is separated to allow reuse when types haven't changed.
781
- */
782
- #initializeBoundMethods() {
783
- for (const type in this.types) {
784
- this[type] = this.logger.bind(this, type, false, false);
785
- }
786
- for (const type in this.types) {
787
- this.force[type] = this.logger.bind(this, type, false, true);
788
- }
789
- }
790
- /**
791
- * Wraps the global console methods to redirect them through the logger.
792
- *
793
- * This method replaces console methods (log, info, warn, error, etc.) with
794
- * calls to the corresponding logger methods. The original console methods
795
- * are backed up and can be restored using restoreConsole().
796
- * @example
797
- * ```typescript
798
- * const logger = createPail();
799
- * logger.wrapConsole();
800
- *
801
- * console.log("This will go through the logger");
802
- * console.error("This too!");
803
- *
804
- * logger.restoreConsole(); // Restore original console methods
805
- * ```
806
- */
807
- wrapConsole() {
808
- for (const type in this.types) {
809
- if (!console[`__${type}`]) {
810
- console[`__${type}`] = console[type];
811
- }
812
- console[type] = this[type];
813
- }
814
- }
815
- /**
816
- * Restores the original global console methods.
817
- *
818
- * This method restores the console methods that were backed up by wrapConsole().
819
- * After calling this, console methods will work as they did before wrapping.
820
- * @example
821
- * ```typescript
822
- * const logger = createPail();
823
- * logger.wrapConsole();
824
- *
825
- * // Console methods are now wrapped
826
- * logger.restoreConsole();
827
- * // Console methods are restored to original behavior
828
- * ```
829
- */
830
- restoreConsole() {
831
- for (const type in this.types) {
832
- if (console[`__${type}`]) {
833
- console[type] = console[`__${type}`];
834
- delete console[`__${type}`];
835
- }
836
- }
837
- }
838
- /**
839
- * Wraps uncaught exception and unhandled rejection handlers.
840
- *
841
- * This method sets up global error handlers that will log uncaught exceptions
842
- * and unhandled promise rejections through the logger. This is useful for
843
- * capturing and logging application crashes.
844
- * @example
845
- * ```typescript
846
- * const logger = createPail();
847
- * logger.wrapException();
848
- *
849
- * // Now uncaught errors will be logged
850
- * throw new Error("This will be logged");
851
- * ```
852
- */
853
- wrapException() {
854
- {
855
- process.on("uncaughtException", (error) => {
856
- this.error(error);
857
- });
858
- process.on("unhandledRejection", (error) => {
859
- this.error(error);
860
- });
861
- }
862
- }
863
- /**
864
- * Disables all logging output.
865
- *
866
- * When disabled, all log calls will be silently ignored and no output
867
- * will be produced by any reporters. This can be useful for temporarily
868
- * suppressing log output in production or during testing.
869
- * @example
870
- * ```typescript
871
- * const logger = createPail();
872
- * logger.disable();
873
- * logger.info("This won't be logged"); // Silent
874
- * logger.enable();
875
- * logger.info("This will be logged"); // Output produced
876
- * ```
877
- */
878
- disable() {
879
- this.disabled = true;
880
- }
881
- /**
882
- * Enables logging output.
883
- *
884
- * Re-enables logging after it has been disabled. All subsequent log calls
885
- * will produce output according to the configured reporters.
886
- * @example
887
- * ```typescript
888
- * const logger = createPail();
889
- * logger.disable();
890
- * logger.info("This won't be logged");
891
- * logger.enable(); // Re-enable logging
892
- * logger.info("This will be logged");
893
- * ```
894
- */
895
- enable() {
896
- this.disabled = false;
897
- }
898
- /**
899
- * Checks if logging is currently enabled.
900
- *
901
- * Returns true if logging is enabled and false if it has been disabled.
902
- * @returns True if logging is enabled, false if disabled
903
- * @example
904
- * ```typescript
905
- * const logger = createPail();
906
- * console.log(logger.isEnabled()); // true
907
- * logger.disable();
908
- * console.log(logger.isEnabled()); // false
909
- * ```
910
- */
911
- isEnabled() {
912
- return !this.disabled;
913
- }
914
- /**
915
- * Pauses logging and starts queuing messages.
916
- *
917
- * When paused, all log calls will be queued instead of being output immediately.
918
- * The queued messages will be processed when resume() is called. This is useful
919
- * for temporarily buffering log output during critical operations.
920
- * @example
921
- * ```typescript
922
- * const logger = createPail();
923
- * logger.pause();
924
- * logger.info("This will be queued"); // Queued, not output yet
925
- * logger.warn("This too"); // Also queued
926
- * logger.resume(); // Now both messages are output
927
- * ```
928
- */
929
- pause() {
930
- this.paused = true;
931
- }
932
- /**
933
- * Resumes logging and flushes all queued messages.
934
- *
935
- * Processes all messages that were queued during the pause period and
936
- * resumes normal logging behavior. Messages are output in the order
937
- * they were originally called.
938
- * @example
939
- * ```typescript
940
- * const logger = createPail();
941
- * logger.pause();
942
- * logger.info("Message 1"); // Queued
943
- * logger.info("Message 2"); // Queued
944
- * logger.resume(); // Both messages are now output in order
945
- * logger.info("Message 3"); // Output immediately
946
- * ```
947
- */
948
- resume() {
949
- this.paused = false;
950
- const queue = this.messageQueue.splice(0);
951
- for (let i = 0; i < queue.length; i += 1) {
952
- const { messageObject, raw, type } = queue[i];
953
- this.logger(type, raw, false, ...messageObject);
954
- }
955
- }
956
- /**
957
- * Creates a scoped logger instance.
958
- *
959
- * Returns a new logger instance that inherits all configuration but adds
960
- * the specified scope names to all log messages. This is useful for
961
- * categorizing logs by component, module, or feature.
962
- * @template N - The new custom logger type names
963
- * @param name Scope names to apply to all log messages
964
- * @returns A new scoped logger instance
965
- * @throws {Error} If no scope name is provided
966
- * @example
967
- * ```typescript
968
- * const logger = createPail();
969
- * const scopedLogger = logger.scope("auth", "login");
970
- * scopedLogger.info("User logged in"); // Will include scope: ["auth", "login"]
971
- * ```
972
- */
973
- scope(...name) {
974
- if (name.length === 0) {
975
- throw new Error("No scope name was defined.");
976
- }
977
- this.scopeName = name.flat();
978
- return this;
979
- }
980
- /**
981
- * Removes the current scope from the logger.
982
- *
983
- * Clears all scope names that were set by previous scope() calls.
984
- * After calling this, log messages will no longer include scope information.
985
- * @example
986
- * ```typescript
987
- * const logger = createPail();
988
- * const scopedLogger = logger.scope("auth");
989
- * scopedLogger.info("Scoped message"); // Has scope
990
- * scopedLogger.unscope();
991
- * scopedLogger.info("Unscoped message"); // No scope
992
- * ```
993
- */
994
- unscope() {
995
- this.scopeName = [];
996
- }
997
- /**
998
- * Creates a child logger that inherits settings from the parent.
999
- *
1000
- * Returns a new logger instance that inherits all configuration from the parent
1001
- * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
1002
- * you to override only what you need. Child loggers are independent instances with
1003
- * their own state (timers, counters, etc.).
1004
- * @template N - The new custom logger type names
1005
- * @template LC - The new log level types
1006
- * @param options Configuration options to override or extend parent settings
1007
- * @returns A new child logger instance
1008
- * @example
1009
- * ```typescript
1010
- * const parent = createPail({
1011
- * logLevel: "info",
1012
- * types: { http: { label: "HTTP", logLevel: "info" } },
1013
- * reporters: [new PrettyReporter()],
1014
- * });
1015
- *
1016
- * // Child inherits parent settings but overrides log level
1017
- * const child = parent.child({ logLevel: "debug" });
1018
- * child.info("This will be logged"); // Uses debug level from child
1019
- * child.http("GET /api 200"); // Inherits http type from parent
1020
- *
1021
- * // Child can add new types
1022
- * const childWithNewType = parent.child({
1023
- * types: { db: { label: "DB", logLevel: "info" } },
1024
- * });
1025
- * childWithNewType.db("Query executed"); // New type available
1026
- * ```
1027
- */
1028
- child(options) {
1029
- const typesChanged = options?.types !== void 0;
1030
- const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
1031
- const childReporters = options?.reporters ?? [];
1032
- const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
1033
- const childProcessors = options?.processors ?? [];
1034
- const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
1035
- const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
1036
- let mergedScope;
1037
- if (options?.scope) {
1038
- const childScope = arrayify(options.scope).filter(Boolean);
1039
- mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
1040
- } else {
1041
- mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
1042
- }
1043
- const mergedMessages = options?.messages ? {
1044
- timerEnd: this.endTimerMessage,
1045
- timerStart: this.startTimerMessage,
1046
- ...options.messages
1047
- } : {
1048
- timerEnd: this.endTimerMessage,
1049
- timerStart: this.startTimerMessage
1050
- };
1051
- const childOptions = {
1052
- disabled: options?.disabled ?? this.disabled,
1053
- logLevel: options?.logLevel ?? this.generalLogLevel,
1054
- logLevels: mergedLogLevels,
1055
- messages: mergedMessages,
1056
- processors: allProcessors,
1057
- rawReporter: options?.rawReporter ?? this.rawReporter,
1058
- reporters: allReporters,
1059
- scope: mergedScope,
1060
- throttle: options?.throttle ?? this.throttle,
1061
- throttleMin: options?.throttleMin ?? this.throttleMin
1062
- };
1063
- if (typesChanged) {
1064
- childOptions.parentTypes = mergedTypes;
1065
- childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
1066
- } else {
1067
- childOptions.parentTypes = this.types;
1068
- childOptions.parentLongestLabel = this.longestLabel;
1069
- }
1070
- if (!options?.logLevels) {
1071
- childOptions.parentLogLevels = this.logLevels;
1072
- }
1073
- if (!options?.messages) {
1074
- childOptions.parentMessages = {
1075
- timerEnd: this.endTimerMessage,
1076
- timerStart: this.startTimerMessage
1077
- };
1078
- }
1079
- childOptions.parentStringify = this.stringify;
1080
- return new PailBrowserImpl(childOptions);
1081
- }
1082
- /**
1083
- * Starts a timer with the specified label.
1084
- *
1085
- * Records the current timestamp and associates it with the given label.
1086
- * Multiple timers can be active simultaneously with different labels.
1087
- * @param label The timer label (defaults to "default")
1088
- * @example
1089
- * ```typescript
1090
- * const logger = createPail();
1091
- * logger.time("operation");
1092
- * // ... some operation ...
1093
- * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
1094
- * ```
1095
- */
1096
- time(label = "default") {
1097
- if (this.seqTimers.has(label)) {
1098
- this.logger("warn", false, false, {
1099
- message: `Timer '${label}' already exists`,
1100
- prefix: label
1101
- });
1102
- } else {
1103
- this.seqTimers.add(label);
1104
- this.timersMap.set(label, Date.now());
1105
- this.logger("start", false, false, {
1106
- message: this.startTimerMessage,
1107
- prefix: label
1108
- });
1109
- }
1110
- }
1111
- /**
1112
- * Logs the current elapsed time for a timer without stopping it.
1113
- *
1114
- * Calculates and logs the time elapsed since the timer was started,
1115
- * but keeps the timer running. If no label is provided, uses the
1116
- * most recently started timer.
1117
- * @param label The timer label (uses last timer if not specified)
1118
- * @param data Additional data to include in the log message
1119
- * @example
1120
- * ```typescript
1121
- * const logger = createPail();
1122
- * logger.time("task");
1123
- * // ... some work ...
1124
- * logger.timeLog("task"); // Logs current elapsed time
1125
- * // ... more work ...
1126
- * logger.timeEnd("task"); // Logs final time and stops timer
1127
- * ```
1128
- */
1129
- timeLog(label, ...data) {
1130
- if (!label && this.seqTimers.size > 0) {
1131
- label = [...this.seqTimers].pop();
1132
- }
1133
- if (label && this.timersMap.has(label)) {
1134
- const span = Date.now() - this.timersMap.get(label);
1135
- this.logger("info", false, false, {
1136
- context: data,
1137
- message: span < 1e3 ? `${String(span)} ms` : `${(span / 1e3).toFixed(2)} s`,
1138
- prefix: label
1139
- });
1140
- } else {
1141
- this.logger("warn", false, false, {
1142
- context: data,
1143
- message: "Timer not found",
1144
- prefix: label
1145
- });
1146
- }
1147
- }
1148
- /**
1149
- * Stops a timer and logs the final elapsed time.
1150
- *
1151
- * Calculates the total time elapsed since the timer was started,
1152
- * logs the result, and removes the timer. If no label is provided,
1153
- * uses the most recently started timer.
1154
- * @param label The timer label (uses last timer if not specified)
1155
- * @example
1156
- * ```typescript
1157
- * const logger = createPail();
1158
- * logger.time("operation");
1159
- * // ... perform operation ...
1160
- * logger.timeEnd("operation"); // Logs: "Timer run for: X ms"
1161
- * ```
1162
- */
1163
- timeEnd(label) {
1164
- if (!label && this.seqTimers.size > 0) {
1165
- label = [...this.seqTimers].pop();
1166
- }
1167
- if (label && this.timersMap.has(label)) {
1168
- const span = Date.now() - this.timersMap.get(label);
1169
- this.timersMap.delete(label);
1170
- this.logger("stop", false, false, {
1171
- message: `${this.endTimerMessage} ${span < 1e3 ? `${String(span)} ms` : `${(span / 1e3).toFixed(2)} s`}`,
1172
- prefix: label
1173
- });
1174
- } else {
1175
- this.logger("warn", false, false, {
1176
- message: "Timer not found",
1177
- prefix: label
1178
- });
1179
- }
1180
- }
1181
- /**
1182
- * Starts a log group with the specified label.
1183
- *
1184
- * Groups related log messages together. In browser environments,
1185
- * this uses the native console.group() functionality. In other
1186
- * environments, it tracks group nesting internally.
1187
- * @param label The group label (defaults to "console.group")
1188
- * @example
1189
- * ```typescript
1190
- * const logger = createPail();
1191
- * logger.group("Database Operations");
1192
- * logger.info("Connecting to database");
1193
- * logger.info("Running migration");
1194
- * logger.groupEnd(); // End the group
1195
- * ```
1196
- */
1197
- group(label = "console.group") {
1198
- if (globalThis.window === void 0) {
1199
- this.groups.push(label);
1200
- } else {
1201
- console.group(label);
1202
- }
1203
- }
1204
- /**
1205
- * Ends the current log group.
1206
- *
1207
- * Closes the most recently opened log group. In browser environments,
1208
- * this uses the native console.groupEnd() functionality.
1209
- * @example
1210
- * ```typescript
1211
- * const logger = createPail();
1212
- * logger.group("Processing");
1213
- * logger.info("Step 1");
1214
- * logger.info("Step 2");
1215
- * logger.groupEnd(); // Closes the "Processing" group
1216
- * ```
1217
- */
1218
- groupEnd() {
1219
- if (globalThis.window === void 0) {
1220
- this.groups.pop();
1221
- } else {
1222
- console.groupEnd();
1223
- }
1224
- }
1225
- /**
1226
- * Increments and logs a counter with the specified label.
1227
- *
1228
- * Maintains an internal counter for each label and logs the current count
1229
- * each time it's called. Useful for tracking how many times certain
1230
- * code paths are executed.
1231
- * @param label The counter label (defaults to "default")
1232
- * @example
1233
- * ```typescript
1234
- * const logger = createPail();
1235
- * logger.count("requests"); // Logs: "requests: 1"
1236
- * logger.count("requests"); // Logs: "requests: 2"
1237
- * logger.count("errors"); // Logs: "errors: 1"
1238
- * ```
1239
- */
1240
- count(label = "default") {
1241
- const current = this.countMap.get(label) ?? 0;
1242
- this.countMap.set(label, current + 1);
1243
- this.logger("log", false, false, {
1244
- message: `${label}: ${String(current + 1)}`,
1245
- prefix: label
1246
- });
1247
- }
1248
- /**
1249
- * Resets a counter to zero.
1250
- *
1251
- * Removes the counter with the specified label, effectively resetting
1252
- * it to zero. If the counter doesn't exist, logs a warning.
1253
- * @param label The counter label to reset (defaults to "default")
1254
- * @example
1255
- * ```typescript
1256
- * const logger = createPail();
1257
- * logger.count("requests"); // Logs: "requests: 1"
1258
- * logger.countReset("requests"); // Resets counter
1259
- * logger.count("requests"); // Logs: "requests: 1" (starts over)
1260
- * ```
1261
- */
1262
- countReset(label = "default") {
1263
- if (this.countMap.has(label)) {
1264
- this.countMap.delete(label);
1265
- } else {
1266
- this.logger("warn", false, false, {
1267
- message: `Count for ${label} does not exist`,
1268
- prefix: label
1269
- });
1270
- }
1271
- }
1272
- /**
1273
- * Clears the console output.
1274
- *
1275
- * Calls the native console.clear() method to clear all output from
1276
- * the console. This is a convenience method that wraps the native
1277
- * console.clear() functionality.
1278
- * @example
1279
- * ```typescript
1280
- * const logger = createPail();
1281
- * logger.info("Some message");
1282
- * logger.clear(); // Clears the console
1283
- * ```
1284
- */
1285
- // eslint-disable-next-line class-methods-use-this
1286
- clear() {
1287
- console.clear();
1288
- }
1289
- /**
1290
- * Logs a raw message bypassing normal processing.
1291
- *
1292
- * Sends a message directly to the raw reporter without going through
1293
- * the normal logging pipeline (processors, throttling, etc.). This is
1294
- * useful for logging that needs to bypass all formatting and processing.
1295
- * @param message The raw message to log
1296
- * @param arguments_ Additional arguments to include
1297
- * @example
1298
- * ```typescript
1299
- * const logger = createPail();
1300
- * logger.raw("Direct message", { data: "value" });
1301
- * ```
1302
- */
1303
- raw(message, ...arguments_) {
1304
- if (this.disabled) {
1305
- return;
1306
- }
1307
- this.logger("log", true, false, {
1308
- context: arguments_,
1309
- message
1310
- });
1311
- }
1312
- extendReporter(reporter) {
1313
- if (typeof reporter.setLoggerTypes === "function") {
1314
- reporter.setLoggerTypes(this.types);
1315
- }
1316
- if (typeof reporter.setStringify === "function") {
1317
- reporter.setStringify(this.stringify);
1318
- }
1319
- return reporter;
1320
- }
1321
- registerReporters(reporters) {
1322
- for (let i = 0; i < reporters.length; i += 1) {
1323
- this.reporters.add(this.extendReporter(reporters[i]));
1324
- }
1325
- }
1326
- registerProcessors(processors) {
1327
- for (let i = 0; i < processors.length; i += 1) {
1328
- const processor = processors[i];
1329
- if (typeof processor.setStringify === "function") {
1330
- processor.setStringify(this.stringify);
1331
- }
1332
- this.processors.add(processor);
1333
- }
1334
- }
1335
- #report(meta, raw) {
1336
- if (raw) {
1337
- this.rawReporter.log(Object.freeze(meta));
1338
- } else {
1339
- for (const reporter of this.reporters) {
1340
- reporter.log(Object.freeze(meta));
1341
- }
1342
- }
1343
- }
1344
- #normalizeLogLevel(level) {
1345
- return level && this.logLevels[level] ? level : "debug";
1346
- }
1347
- // eslint-disable-next-line sonarjs/cognitive-complexity
1348
- #buildMeta(typeName, type, ...arguments_) {
1349
- const meta = {
1350
- badge: void 0,
1351
- context: void 0,
1352
- error: void 0,
1353
- label: void 0,
1354
- message: EMPTY_SYMBOL,
1355
- prefix: void 0,
1356
- repeated: void 0,
1357
- scope: void 0,
1358
- suffix: void 0
1359
- };
1360
- meta.type = {
1361
- level: type.logLevel,
1362
- name: typeName
1363
- };
1364
- meta.groups = this.groups;
1365
- meta.scope = this.scopeName;
1366
- meta.date = /* @__PURE__ */ new Date();
1367
- if (arguments_.length > 0 && arguments_[0] instanceof Error) {
1368
- meta.error = arguments_[0];
1369
- if (arguments_.length > 1) {
1370
- meta.context = arguments_.slice(1);
1371
- }
1372
- } else if (arguments_.length > 0 && typeof arguments_[0] === "object" && arguments_[0] !== null && "message" in arguments_[0]) {
1373
- const { context, message, prefix, suffix } = arguments_[0];
1374
- if (context) {
1375
- meta.context = context;
1376
- }
1377
- if (prefix) {
1378
- meta.prefix = prefix;
1379
- }
1380
- if (suffix) {
1381
- meta.suffix = suffix;
1382
- }
1383
- meta.message = message;
1384
- if (arguments_.length > 1) {
1385
- const additionalContext = arguments_.slice(1);
1386
- if (meta.context) {
1387
- meta.context = Array.isArray(meta.context) ? [...meta.context, ...additionalContext] : [meta.context, ...additionalContext];
1388
- } else {
1389
- meta.context = additionalContext;
1390
- }
1391
- }
1392
- } else if (arguments_.length > 1) {
1393
- meta.message = arguments_[0];
1394
- meta.context = arguments_.slice(1);
1395
- } else if (arguments_.length === 1) {
1396
- meta.message = arguments_[0];
1397
- } else {
1398
- meta.message = void 0;
1399
- }
1400
- if (type.logLevel === "trace") {
1401
- meta.traceError = new Error("Trace");
1402
- }
1403
- if (type.badge) {
1404
- meta.badge = type.badge;
1405
- }
1406
- if (type.label) {
1407
- meta.label = type.label;
1408
- }
1409
- return meta;
1410
- }
1411
- // eslint-disable-next-line sonarjs/cognitive-complexity
1412
- logger(type, raw, force, ...messageObject) {
1413
- if (this.disabled) {
1414
- return;
1415
- }
1416
- if (this.paused) {
1417
- this.messageQueue.push({ messageObject, raw, type });
1418
- return;
1419
- }
1420
- const typeConfig = this.types[type];
1421
- const logLevel = this.#normalizeLogLevel(typeConfig.logLevel);
1422
- if (force || this.logLevels[logLevel] >= this.logLevels[this.generalLogLevel]) {
1423
- let meta = this.#buildMeta(type, typeConfig, ...messageObject);
1424
- const resolveLog = (newLog = false) => {
1425
- const repeated = (this.lastLog.count ?? 0) - this.throttleMin;
1426
- if (this.lastLog.object && repeated > 0) {
1427
- const lastMeta = { ...this.lastLog.object };
1428
- if (repeated > 1) {
1429
- lastMeta.repeated = repeated;
1430
- }
1431
- this.#report(lastMeta, raw);
1432
- this.lastLog.count = 1;
1433
- }
1434
- if (newLog) {
1435
- for (const processor of this.processors) {
1436
- meta = { ...processor.process(meta) };
1437
- }
1438
- this.lastLog.object = meta;
1439
- this.#report(meta, raw);
1440
- }
1441
- };
1442
- clearTimeout(this.lastLog.timeout);
1443
- const diffTime = this.lastLog.time && meta.date ? new Date(meta.date).getTime() - this.lastLog.time.getTime() : 0;
1444
- this.lastLog.time = new Date(meta.date);
1445
- if (diffTime < this.throttle) {
1446
- try {
1447
- const isSameLog = this.lastLog.object && JSON.stringify([meta.label, meta.scope, meta.type, meta.message, meta.prefix, meta.suffix, meta.context]) === JSON.stringify([
1448
- this.lastLog.object.label,
1449
- this.lastLog.object.scope,
1450
- this.lastLog.object.type,
1451
- this.lastLog.object.message,
1452
- this.lastLog.object.prefix,
1453
- this.lastLog.object.suffix,
1454
- this.lastLog.object.context
1455
- ]);
1456
- if (isSameLog) {
1457
- this.lastLog.count = (this.lastLog.count ?? 0) + 1;
1458
- if (this.lastLog.count > this.throttleMin) {
1459
- this.lastLog.timeout = setTimeout(resolveLog, this.throttle);
1460
- return;
1461
- }
1462
- }
1463
- } catch {
1464
- }
1465
- }
1466
- resolveLog(true);
1467
- }
1468
- }
1469
- }
1470
-
1471
- class RawReporter {
1472
- #stdout;
1473
- #stderr;
1474
- #interactiveManager;
1475
- #interactive = false;
1476
- #inspectOptions;
1477
- constructor(inspectOptions = {}) {
1478
- this.#stdout = stdout;
1479
- this.#stderr = stderr;
1480
- this.#inspectOptions = inspectOptions;
1481
- }
1482
- setStdout(stdout_) {
1483
- this.#stdout = stdout_;
1484
- }
1485
- setStderr(stderr_) {
1486
- this.#stderr = stderr_;
1487
- }
1488
- setInteractiveManager(manager) {
1489
- this.#interactiveManager = manager;
1490
- }
1491
- setIsInteractive(interactive) {
1492
- this.#interactive = interactive;
1493
- }
1494
- log(meta) {
1495
- const { context, groups, message, type } = meta;
1496
- const items = [];
1497
- if (message !== EMPTY_SYMBOL) {
1498
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
1499
- items.push(formattedMessage);
1500
- }
1501
- if (context) {
1502
- items.push(
1503
- ...context.map((value) => {
1504
- if (typeof value === "object") {
1505
- return ` ${inspect(value, this.#inspectOptions)}`;
1506
- }
1507
- return ` ${String(value)}`;
1508
- })
1509
- );
1510
- }
1511
- const streamType = ["error", "trace", "warn"].includes(type.level) ? "stderr" : "stdout";
1512
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
1513
- const groupSpaces = groups.map(() => " ").join("");
1514
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
1515
- this.#interactiveManager.update(streamType, (groupSpaces + items.join("")).split("\n"), 0);
1516
- } else {
1517
- writeStream(groupSpaces + items.join(""), stream);
1518
- }
1519
- }
1520
- }
1521
-
1522
- class PailServerImpl extends PailBrowserImpl {
1523
- /**
1524
- * Creates a new Pail server logger instance.
1525
- *
1526
- * Initializes the server-compatible logger with streams, interactive support,
1527
- * and server-specific configuration options.
1528
- * @param options Server-specific configuration options
1529
- */
1530
- constructor(options) {
1531
- const parentStderr = options.parentStderr;
1532
- const parentStdout = options.parentStdout;
1533
- const { interactive, processors, rawReporter, reporters, stderr: optionsStderr, stdout: optionsStdout } = options;
1534
- const stderr = parentStderr ?? optionsStderr;
1535
- const stdout = parentStdout ?? optionsStdout;
1536
- const parentLongestLabel = options.parentLongestLabel;
1537
- const parentTypes = options.parentTypes;
1538
- const { parentLogLevels, parentMessages, parentStringify } = options;
1539
- const parentOptions = {
1540
- disabled: options.disabled,
1541
- logLevel: options.logLevel,
1542
- logLevels: options.logLevels,
1543
- messages: options.messages,
1544
- processors: [],
1545
- rawReporter: options.rawReporter,
1546
- reporters: [],
1547
- scope: options.scope,
1548
- throttle: options.throttle,
1549
- throttleMin: options.throttleMin
1550
- };
1551
- const hasTypesProperty = "types" in options;
1552
- if (parentTypes && parentLongestLabel && !hasTypesProperty) {
1553
- parentOptions.parentTypes = parentTypes;
1554
- parentOptions.parentLongestLabel = parentLongestLabel;
1555
- } else if (hasTypesProperty && options.types !== void 0) {
1556
- parentOptions.types = options.types;
1557
- }
1558
- if (parentStringify) {
1559
- parentOptions.parentStringify = parentStringify;
1560
- }
1561
- if (parentLogLevels && !options.logLevels) {
1562
- parentOptions.parentLogLevels = parentLogLevels;
1563
- }
1564
- if (parentMessages && !options.messages) {
1565
- parentOptions.parentMessages = parentMessages;
1566
- }
1567
- super(parentOptions);
1568
- this.options = options;
1569
- this.interactive = interactive ?? false;
1570
- this.stdout = stdout;
1571
- this.stderr = stderr;
1572
- if (this.interactive) {
1573
- this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));
1574
- }
1575
- if (Array.isArray(reporters)) {
1576
- this.registerReporters(reporters);
1577
- }
1578
- this.rawReporter = this.extendReporter(rawReporter ?? new RawReporter());
1579
- if (Array.isArray(processors)) {
1580
- this.registerProcessors(processors);
1581
- }
1582
- }
1583
- options;
1584
- stdout;
1585
- stderr;
1586
- interactiveManager;
1587
- interactive;
1588
- // @ts-expect-error - this returns a different type
1589
- scope(...name) {
1590
- if (name.length === 0) {
1591
- throw new Error("No scope name was defined.");
1592
- }
1593
- this.scopeName = name.flat();
1594
- return this;
1595
- }
1596
- /**
1597
- * Creates a child logger that inherits settings from the parent.
1598
- *
1599
- * Returns a new logger instance that inherits all configuration from the parent
1600
- * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
1601
- * you to override only what you need. Child loggers are independent instances with
1602
- * their own state (timers, counters, etc.).
1603
- * @template N - The new custom logger type names
1604
- * @template LC - The new log level types
1605
- * @param options Configuration options to override or extend parent settings
1606
- * @returns A new child logger instance
1607
- * @example
1608
- * ```typescript
1609
- * const parent = createPail({
1610
- * logLevel: "info",
1611
- * types: { http: { label: "HTTP", logLevel: "info" } },
1612
- * reporters: [new PrettyReporter()],
1613
- * });
1614
- *
1615
- * // Child inherits parent settings but overrides log level
1616
- * const child = parent.child({ logLevel: "debug" });
1617
- * child.info("This will be logged"); // Uses debug level from child
1618
- * child.http("GET /api 200"); // Inherits http type from parent
1619
- *
1620
- * // Child can add new types
1621
- * const childWithNewType = parent.child({
1622
- * types: { db: { label: "DB", logLevel: "info" } },
1623
- * });
1624
- * childWithNewType.db("Query executed"); // New type available
1625
- * ```
1626
- */
1627
- // @ts-expect-error - override signature differs due to server-specific options
1628
- child(options) {
1629
- const typesChanged = options?.types !== void 0;
1630
- const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
1631
- const childReporters = options?.reporters ?? [];
1632
- const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
1633
- const childProcessors = options?.processors ?? [];
1634
- const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
1635
- const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
1636
- let mergedScope;
1637
- if (options?.scope) {
1638
- const childScope = arrayify(options.scope).filter(Boolean);
1639
- mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
1640
- } else {
1641
- mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
1642
- }
1643
- const mergedMessages = options?.messages ? {
1644
- timerEnd: this.endTimerMessage,
1645
- timerStart: this.startTimerMessage,
1646
- ...options.messages
1647
- } : {
1648
- timerEnd: this.endTimerMessage,
1649
- timerStart: this.startTimerMessage
1650
- };
1651
- const childOptions = {
1652
- disabled: options?.disabled ?? this.disabled,
1653
- interactive: options?.interactive ?? this.interactive,
1654
- logLevel: options?.logLevel ?? this.generalLogLevel,
1655
- logLevels: mergedLogLevels,
1656
- messages: mergedMessages,
1657
- processors: allProcessors,
1658
- rawReporter: options?.rawReporter ?? this.rawReporter,
1659
- reporters: allReporters,
1660
- scope: mergedScope,
1661
- stderr: options?.stderr ?? this.stderr,
1662
- stdout: options?.stdout ?? this.stdout,
1663
- throttle: options?.throttle ?? this.throttle,
1664
- throttleMin: options?.throttleMin ?? this.throttleMin
1665
- };
1666
- this.#assignParentValues(childOptions, options, typesChanged, mergedTypes);
1667
- return new PailServerImpl(childOptions);
1668
- }
1669
- /**
1670
- * Assigns parent values to child options for optimization.
1671
- *
1672
- * Reuses parent values when they haven't changed to avoid unnecessary recalculations.
1673
- */
1674
- /* eslint-disable no-param-reassign */
1675
- #assignParentValues(childOptions, options, typesChanged, mergedTypes) {
1676
- if (typesChanged) {
1677
- childOptions.parentTypes = mergedTypes;
1678
- childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
1679
- } else {
1680
- childOptions.parentTypes = this.types;
1681
- childOptions.parentLongestLabel = this.longestLabel;
1682
- }
1683
- if (!options?.logLevels) {
1684
- childOptions.parentLogLevels = this.logLevels;
1685
- }
1686
- if (!options?.messages) {
1687
- childOptions.parentMessages = {
1688
- timerEnd: this.endTimerMessage,
1689
- timerStart: this.startTimerMessage
1690
- };
1691
- }
1692
- childOptions.parentStringify = this.stringify;
1693
- if (!options?.stdout) {
1694
- childOptions.parentStdout = this.stdout;
1695
- }
1696
- if (!options?.stderr) {
1697
- childOptions.parentStderr = this.stderr;
1698
- }
1699
- }
1700
- /* eslint-enable no-param-reassign */
1701
- /**
1702
- * Gets the interactive manager instance if interactive mode is enabled.
1703
- *
1704
- * Returns the InteractiveManager instance that handles interactive terminal
1705
- * features like progress bars and dynamic updates. Only available when
1706
- * interactive mode is enabled in the constructor options.
1707
- * @returns The interactive manager instance, or undefined if not in interactive mode
1708
- * @example
1709
- * ```typescript
1710
- * const logger = createPail({ interactive: true });
1711
- * const manager = logger.getInteractiveManager();
1712
- * if (manager) {
1713
- * manager.hook();
1714
- * // Use interactive features
1715
- * manager.unhook();
1716
- * }
1717
- * ```
1718
- */
1719
- getInteractiveManager() {
1720
- return this.interactiveManager;
1721
- }
1722
- /**
1723
- * Wraps stdout and stderr streams to redirect them through the logger.
1724
- *
1725
- * Intercepts writes to process.stdout and process.stderr, redirecting them
1726
- * through the logger instead of writing directly to the streams. This allows
1727
- * all output to be processed by the logging pipeline.
1728
- * @example
1729
- * ```typescript
1730
- * const logger = createPail();
1731
- * logger.wrapStd();
1732
- *
1733
- * console.log("This goes through logger");
1734
- * process.stdout.write("This too");
1735
- *
1736
- * logger.restoreStd(); // Restore original streams
1737
- * ```
1738
- */
1739
- wrapStd() {
1740
- this.#wrapStream(this.stdout, "log");
1741
- this.#wrapStream(this.stderr, "log");
1742
- }
1743
- /**
1744
- * Restores the original stdout and stderr streams.
1745
- *
1746
- * Removes the stream wrapping that was applied by wrapStd(),
1747
- * restoring the original stream write methods.
1748
- * @example
1749
- * ```typescript
1750
- * const logger = createPail();
1751
- * logger.wrapStd();
1752
- * // Streams are wrapped
1753
- * logger.restoreStd();
1754
- * // Streams are restored to original behavior
1755
- * ```
1756
- */
1757
- restoreStd() {
1758
- this.#restoreStream(this.stdout);
1759
- this.#restoreStream(this.stderr);
1760
- }
1761
- /**
1762
- * Wraps all output sources (console and streams).
1763
- *
1764
- * Convenience method that calls both wrapConsole() and wrapStd()
1765
- * to redirect all output through the logger.
1766
- * @example
1767
- * ```typescript
1768
- * const logger = createPail();
1769
- * logger.wrapAll(); // Wraps console and streams
1770
- *
1771
- * // All output now goes through logger
1772
- * console.log("Console output");
1773
- * process.stdout.write("Stream output");
1774
- *
1775
- * logger.restoreAll(); // Restore everything
1776
- * ```
1777
- */
1778
- wrapAll() {
1779
- this.wrapConsole();
1780
- this.wrapStd();
1781
- }
1782
- /**
1783
- * Restores all wrapped output sources.
1784
- *
1785
- * Convenience method that calls both restoreConsole() and restoreStd()
1786
- * to restore all original output behavior.
1787
- * @example
1788
- * ```typescript
1789
- * const logger = createPail();
1790
- * logger.wrapAll();
1791
- * // All output is wrapped
1792
- * logger.restoreAll();
1793
- * // All output sources are restored
1794
- * ```
1795
- */
1796
- restoreAll() {
1797
- this.restoreConsole();
1798
- this.restoreStd();
1799
- }
1800
- /**
1801
- * Clears the terminal screen.
1802
- *
1803
- * Sends ANSI escape sequences to clear the terminal screen and move
1804
- * the cursor to the top-left position. This overrides the browser
1805
- * implementation to work with terminal streams.
1806
- * @example
1807
- * ```typescript
1808
- * const logger = createPail();
1809
- * logger.info("Some output");
1810
- * logger.clear(); // Clears the terminal screen
1811
- * ```
1812
- */
1813
- clear() {
1814
- this.stdout.write(resetTerminal);
1815
- this.stderr.write(resetTerminal);
1816
- }
1817
- extendReporter(reporter) {
1818
- if (typeof reporter.setStdout === "function") {
1819
- reporter.setStdout(this.stdout);
1820
- }
1821
- if (typeof reporter.setStderr === "function") {
1822
- reporter.setStderr(this.stderr);
1823
- }
1824
- if (typeof reporter.setLoggerTypes === "function") {
1825
- reporter.setLoggerTypes(this.types);
1826
- }
1827
- if (typeof reporter.setStringify === "function") {
1828
- reporter.setStringify(this.stringify);
1829
- }
1830
- if (typeof reporter.setIsInteractive === "function") {
1831
- reporter.setIsInteractive(this.interactive);
1832
- }
1833
- if (this.interactive && typeof reporter.setInteractiveManager === "function") {
1834
- reporter.setInteractiveManager(this.interactiveManager);
1835
- }
1836
- return reporter;
1837
- }
1838
- #wrapStream(stream, type) {
1839
- if (!stream) {
1840
- return;
1841
- }
1842
- if (!stream.__write) {
1843
- stream.__write = stream.write;
1844
- }
1845
- stream.write = (data) => {
1846
- this[type](String(data).trim());
1847
- };
1848
- }
1849
- // eslint-disable-next-line class-methods-use-this
1850
- #restoreStream(stream) {
1851
- if (!stream) {
1852
- return;
1853
- }
1854
- if (stream.__write) {
1855
- stream.write = stream.__write;
1856
- delete stream.__write;
1857
- }
1858
- }
1859
- }
1860
- const PailServer = PailServerImpl;
1861
-
1862
- const colorKeywords = /* @__PURE__ */ new Map([
1863
- ["aliceblue", "#f0f8ff"],
1864
- ["antiquewhite", "#faebd7"],
1865
- ["aqua", "#00ffff"],
1866
- ["aquamarine", "#7fffd4"],
1867
- ["azure", "#f0ffff"],
1868
- ["beige", "#f5f5dc"],
1869
- ["bisque", "#ffe4c4"],
1870
- ["black", "#000000"],
1871
- ["blanchedalmond", "#ffebcd"],
1872
- ["blue", "#0000ff"],
1873
- ["blueviolet", "#8a2be2"],
1874
- ["brown", "#a52a2a"],
1875
- ["burlywood", "#deb887"],
1876
- ["cadetblue", "#5f9ea0"],
1877
- ["chartreuse", "#7fff00"],
1878
- ["chocolate", "#d2691e"],
1879
- ["coral", "#ff7f50"],
1880
- ["cornflowerblue", "#6495ed"],
1881
- ["cornsilk", "#fff8dc"],
1882
- ["crimson", "#dc143c"],
1883
- ["cyan", "#00ffff"],
1884
- ["darkblue", "#00008b"],
1885
- ["darkcyan", "#008b8b"],
1886
- ["darkgoldenrod", "#b8860b"],
1887
- ["darkgray", "#a9a9a9"],
1888
- ["darkgreen", "#006400"],
1889
- ["darkgrey", "#a9a9a9"],
1890
- ["darkkhaki", "#bdb76b"],
1891
- ["darkmagenta", "#8b008b"],
1892
- ["darkolivegreen", "#556b2f"],
1893
- ["darkorange", "#ff8c00"],
1894
- ["darkorchid", "#9932cc"],
1895
- ["darkred", "#8b0000"],
1896
- ["darksalmon", "#e9967a"],
1897
- ["darkseagreen", "#8fbc8f"],
1898
- ["darkslateblue", "#483d8b"],
1899
- ["darkslategray", "#2f4f4f"],
1900
- ["darkslategrey", "#2f4f4f"],
1901
- ["darkturquoise", "#00ced1"],
1902
- ["darkviolet", "#9400d3"],
1903
- ["deeppink", "#ff1493"],
1904
- ["deepskyblue", "#00bfff"],
1905
- ["dimgray", "#696969"],
1906
- ["dimgrey", "#696969"],
1907
- ["dodgerblue", "#1e90ff"],
1908
- ["firebrick", "#b22222"],
1909
- ["floralwhite", "#fffaf0"],
1910
- ["forestgreen", "#228b22"],
1911
- ["fuchsia", "#ff00ff"],
1912
- ["gainsboro", "#dcdcdc"],
1913
- ["ghostwhite", "#f8f8ff"],
1914
- ["gold", "#ffd700"],
1915
- ["goldenrod", "#daa520"],
1916
- ["gray", "#808080"],
1917
- ["green", "#008000"],
1918
- ["greenyellow", "#adff2f"],
1919
- ["grey", "#808080"],
1920
- ["honeydew", "#f0fff0"],
1921
- ["hotpink", "#ff69b4"],
1922
- ["indianred", "#cd5c5c"],
1923
- ["indigo", "#4b0082"],
1924
- ["ivory", "#fffff0"],
1925
- ["khaki", "#f0e68c"],
1926
- ["lavender", "#e6e6fa"],
1927
- ["lavenderblush", "#fff0f5"],
1928
- ["lawngreen", "#7cfc00"],
1929
- ["lemonchiffon", "#fffacd"],
1930
- ["lightblue", "#add8e6"],
1931
- ["lightcoral", "#f08080"],
1932
- ["lightcyan", "#e0ffff"],
1933
- ["lightgoldenrodyellow", "#fafad2"],
1934
- ["lightgray", "#d3d3d3"],
1935
- ["lightgreen", "#90ee90"],
1936
- ["lightgrey", "#d3d3d3"],
1937
- ["lightpink", "#ffb6c1"],
1938
- ["lightsalmon", "#ffa07a"],
1939
- ["lightseagreen", "#20b2aa"],
1940
- ["lightskyblue", "#87cefa"],
1941
- ["lightslategray", "#778899"],
1942
- ["lightslategrey", "#778899"],
1943
- ["lightsteelblue", "#b0c4de"],
1944
- ["lightyellow", "#ffffe0"],
1945
- ["lime", "#00ff00"],
1946
- ["limegreen", "#32cd32"],
1947
- ["linen", "#faf0e6"],
1948
- ["magenta", "#ff00ff"],
1949
- ["maroon", "#800000"],
1950
- ["mediumaquamarine", "#66cdaa"],
1951
- ["mediumblue", "#0000cd"],
1952
- ["mediumorchid", "#ba55d3"],
1953
- ["mediumpurple", "#9370db"],
1954
- ["mediumseagreen", "#3cb371"],
1955
- ["mediumslateblue", "#7b68ee"],
1956
- ["mediumspringgreen", "#00fa9a"],
1957
- ["mediumturquoise", "#48d1cc"],
1958
- ["mediumvioletred", "#c71585"],
1959
- ["midnightblue", "#191970"],
1960
- ["mintcream", "#f5fffa"],
1961
- ["mistyrose", "#ffe4e1"],
1962
- ["moccasin", "#ffe4b5"],
1963
- ["navajowhite", "#ffdead"],
1964
- ["navy", "#000080"],
1965
- ["oldlace", "#fdf5e6"],
1966
- ["olive", "#808000"],
1967
- ["olivedrab", "#6b8e23"],
1968
- ["orange", "#ffa500"],
1969
- ["orangered", "#ff4500"],
1970
- ["orchid", "#da70d6"],
1971
- ["palegoldenrod", "#eee8aa"],
1972
- ["palegreen", "#98fb98"],
1973
- ["paleturquoise", "#afeeee"],
1974
- ["palevioletred", "#db7093"],
1975
- ["papayawhip", "#ffefd5"],
1976
- ["peachpuff", "#ffdab9"],
1977
- ["peru", "#cd853f"],
1978
- ["pink", "#ffc0cb"],
1979
- ["plum", "#dda0dd"],
1980
- ["powderblue", "#b0e0e6"],
1981
- ["purple", "#800080"],
1982
- ["rebeccapurple", "#663399"],
1983
- ["red", "#ff0000"],
1984
- ["rosybrown", "#bc8f8f"],
1985
- ["royalblue", "#4169e1"],
1986
- ["saddlebrown", "#8b4513"],
1987
- ["salmon", "#fa8072"],
1988
- ["sandybrown", "#f4a460"],
1989
- ["seagreen", "#2e8b57"],
1990
- ["seashell", "#fff5ee"],
1991
- ["sienna", "#a0522d"],
1992
- ["silver", "#c0c0c0"],
1993
- ["skyblue", "#87ceeb"],
1994
- ["slateblue", "#6a5acd"],
1995
- ["slategray", "#708090"],
1996
- ["slategrey", "#708090"],
1997
- ["snow", "#fffafa"],
1998
- ["springgreen", "#00ff7f"],
1999
- ["steelblue", "#4682b4"],
2000
- ["tan", "#d2b48c"],
2001
- ["teal", "#008080"],
2002
- ["thistle", "#d8bfd8"],
2003
- ["tomato", "#ff6347"],
2004
- ["turquoise", "#40e0d0"],
2005
- ["violet", "#ee82ee"],
2006
- ["wheat", "#f5deb3"],
2007
- ["white", "#ffffff"],
2008
- ["whitesmoke", "#f5f5f5"],
2009
- ["yellow", "#ffff00"],
2010
- ["yellowgreen", "#9acd32"]
2011
- ]);
2012
- const HASH_PATTERN = /^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i;
2013
- const SMALL_HASH_PATTERN = /^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i;
2014
- const RGB_PATTERN = /^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/;
2015
- const HSL_PATTERN = /^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/;
2016
- const getDefaultCss = () => {
2017
- return {
2018
- __proto__: null,
2019
- backgroundColor: null,
2020
- color: null,
2021
- fontStyle: null,
2022
- fontWeight: null,
2023
- textDecorationColor: null,
2024
- textDecorationLine: []
2025
- };
2026
- };
2027
- const SPACE_PATTERN = /\s+/;
2028
- const parseCssColor = (colorString) => {
2029
- if (colorKeywords.has(colorString)) {
2030
- colorString = colorKeywords.get(colorString);
2031
- }
2032
- const hashMatch = HASH_PATTERN.exec(colorString);
2033
- if (hashMatch) {
2034
- return [Number.parseInt(hashMatch[1], 16), Number.parseInt(hashMatch[2], 16), Number.parseInt(hashMatch[3], 16)];
2035
- }
2036
- const smallHashMatch = SMALL_HASH_PATTERN.exec(colorString);
2037
- if (smallHashMatch) {
2038
- return [
2039
- Number.parseInt(`${smallHashMatch[1]}${smallHashMatch[1]}`, 16),
2040
- Number.parseInt(`${smallHashMatch[2]}${smallHashMatch[2]}`, 16),
2041
- Number.parseInt(`${smallHashMatch[3]}${smallHashMatch[3]}`, 16)
2042
- ];
2043
- }
2044
- const rgbMatch = RGB_PATTERN.exec(colorString);
2045
- if (rgbMatch) {
2046
- return [
2047
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[1])))),
2048
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[2])))),
2049
- Math.round(Math.max(0, Math.min(255, Number(rgbMatch[3]))))
2050
- ];
2051
- }
2052
- const hslMatch = HSL_PATTERN.exec(colorString);
2053
- if (hslMatch) {
2054
- let h = Number(hslMatch[1]) % 360;
2055
- if (h < 0) {
2056
- h += 360;
2057
- }
2058
- const s = Math.max(0, Math.min(100, Number(hslMatch[2]))) / 100;
2059
- const l = Math.max(0, Math.min(100, Number(hslMatch[3]))) / 100;
2060
- const c = (1 - Math.abs(2 * l - 1)) * s;
2061
- const x = c * (1 - Math.abs(h / 60 % 2 - 1));
2062
- const m = l - c / 2;
2063
- let r_;
2064
- let g_;
2065
- let b_;
2066
- if (h < 60) {
2067
- ({ 0: r_, 1: g_, 2: b_ } = [c, x, 0]);
2068
- } else if (h < 120) {
2069
- ({ 0: r_, 1: g_, 2: b_ } = [x, c, 0]);
2070
- } else if (h < 180) {
2071
- ({ 0: r_, 1: g_, 2: b_ } = [0, c, x]);
2072
- } else if (h < 240) {
2073
- ({ 0: r_, 1: g_, 2: b_ } = [0, x, c]);
2074
- } else if (h < 300) {
2075
- ({ 0: r_, 1: g_, 2: b_ } = [x, 0, c]);
2076
- } else {
2077
- ({ 0: r_, 1: g_, 2: b_ } = [c, 0, x]);
2078
- }
2079
- return [Math.round((r_ + m) * 255), Math.round((g_ + m) * 255), Math.round((b_ + m) * 255)];
2080
- }
2081
- return null;
2082
- };
2083
- const colorEquals = (color1, color2) => color1?.[0] === color2?.[0] && color1?.[1] === color2?.[1] && color1?.[2] === color2?.[2];
2084
- const parseCss = (cssString) => {
2085
- const css = getDefaultCss();
2086
- const rawEntries = [];
2087
- let inValue = false;
2088
- let currentKey = null;
2089
- let parenthesesDepth = 0;
2090
- let currentPart = "";
2091
- for (const c of cssString) {
2092
- if (c === "(") {
2093
- parenthesesDepth += 1;
2094
- } else if (parenthesesDepth > 0) {
2095
- if (c === ")") {
2096
- parenthesesDepth -= 1;
2097
- }
2098
- } else if (inValue) {
2099
- if (c === ";") {
2100
- const value = currentPart.trim();
2101
- if (value !== "") {
2102
- rawEntries.push([currentKey, value]);
2103
- }
2104
- currentKey = null;
2105
- currentPart = "";
2106
- inValue = false;
2107
- continue;
2108
- }
2109
- } else if (c === ":") {
2110
- currentKey = currentPart.trim();
2111
- currentPart = "";
2112
- inValue = true;
2113
- continue;
2114
- }
2115
- currentPart += c;
2116
- }
2117
- if (inValue && parenthesesDepth === 0) {
2118
- const value = currentPart.trim();
2119
- if (value !== "") {
2120
- rawEntries.push([currentKey, value]);
2121
- }
2122
- currentKey = null;
2123
- currentPart = "";
2124
- }
2125
- for (const { 0: key, 1: value } of rawEntries) {
2126
- switch (key) {
2127
- case "background-color": {
2128
- if (value != void 0) {
2129
- css.backgroundColor = value;
2130
- }
2131
- break;
2132
- }
2133
- case "color": {
2134
- if (value != void 0) {
2135
- css.color = value;
2136
- }
2137
- break;
2138
- }
2139
- case "font-style": {
2140
- if (["italic", "oblique", "oblique 14deg"].includes(value)) {
2141
- css.fontStyle = "italic";
2142
- }
2143
- break;
2144
- }
2145
- case "font-weight": {
2146
- if (value === "bold") {
2147
- css.fontWeight = value;
2148
- }
2149
- break;
2150
- }
2151
- case "text-decoration": {
2152
- css.textDecorationColor = null;
2153
- css.textDecorationLine = [];
2154
- const arguments_ = value.split(SPACE_PATTERN);
2155
- for (const argument of arguments_) {
2156
- const maybeColor = parseCssColor(argument);
2157
- if (maybeColor != void 0) {
2158
- css.textDecorationColor = maybeColor;
2159
- } else if (["line-through", "overline", "underline"].includes(argument)) {
2160
- css.textDecorationLine.push(argument);
2161
- }
2162
- }
2163
- break;
2164
- }
2165
- case "text-decoration-color": {
2166
- const color = parseCssColor(value);
2167
- if (color != void 0) {
2168
- css.textDecorationColor = color;
2169
- }
2170
- break;
2171
- }
2172
- case "text-decoration-line": {
2173
- css.textDecorationLine = [];
2174
- const lineTypes = value.split(SPACE_PATTERN);
2175
- for (const lineType of lineTypes) {
2176
- if (["line-through", "overline", "underline"].includes(lineType)) {
2177
- css.textDecorationLine.push(lineType);
2178
- }
2179
- }
2180
- break;
2181
- }
2182
- }
2183
- }
2184
- return css;
2185
- };
2186
- const cssToAnsi = (css, previousCss) => {
2187
- previousCss = previousCss ?? getDefaultCss();
2188
- let ansi = "";
2189
- if (!colorEquals(css.backgroundColor, previousCss.backgroundColor)) {
2190
- if (css.backgroundColor == void 0) {
2191
- ansi += "\x1B[49m";
2192
- } else {
2193
- switch (css.backgroundColor) {
2194
- case "black": {
2195
- ansi += "\x1B[40m";
2196
- break;
2197
- }
2198
- case "blue": {
2199
- ansi += "\x1B[44m";
2200
- break;
2201
- }
2202
- case "cyan": {
2203
- ansi += "\x1B[46m";
2204
- break;
2205
- }
2206
- case "green": {
2207
- ansi += "\x1B[42m";
2208
- break;
2209
- }
2210
- case "magenta": {
2211
- ansi += "\x1B[45m";
2212
- break;
2213
- }
2214
- case "red": {
2215
- ansi += "\x1B[41m";
2216
- break;
2217
- }
2218
- case "white": {
2219
- ansi += "\x1B[47m";
2220
- break;
2221
- }
2222
- case "yellow": {
2223
- ansi += "\x1B[43m";
2224
- break;
2225
- }
2226
- default: {
2227
- if (Array.isArray(css.backgroundColor)) {
2228
- const { 0: r, 1: g, 2: b } = css.backgroundColor;
2229
- ansi += `\x1B[48;2;${String(r)};${String(g)};${String(b)}m`;
2230
- } else {
2231
- const parsed = parseCssColor(css.backgroundColor);
2232
- if (parsed === null) {
2233
- ansi += "\x1B[49m";
2234
- } else {
2235
- const { 0: r, 1: g, 2: b } = parsed;
2236
- ansi += `\x1B[48;2;${String(r)};${String(g)};${String(b)}m`;
2237
- }
2238
- }
2239
- }
2240
- }
2241
- }
2242
- }
2243
- if (!colorEquals(css.color, previousCss.color)) {
2244
- if (css.color == void 0) {
2245
- ansi += "\x1B[39m";
2246
- } else {
2247
- switch (css.color) {
2248
- case "black": {
2249
- ansi += "\x1B[30m";
2250
- break;
2251
- }
2252
- case "blue": {
2253
- ansi += "\x1B[34m";
2254
- break;
2255
- }
2256
- case "cyan": {
2257
- ansi += "\x1B[36m";
2258
- break;
2259
- }
2260
- case "green": {
2261
- ansi += "\x1B[32m";
2262
- break;
2263
- }
2264
- case "magenta": {
2265
- ansi += "\x1B[35m";
2266
- break;
2267
- }
2268
- case "red": {
2269
- ansi += "\x1B[31m";
2270
- break;
2271
- }
2272
- case "white": {
2273
- ansi += "\x1B[37m";
2274
- break;
2275
- }
2276
- case "yellow": {
2277
- ansi += "\x1B[33m";
2278
- break;
2279
- }
2280
- default: {
2281
- if (Array.isArray(css.color)) {
2282
- const { 0: r, 1: g, 2: b } = css.color;
2283
- ansi += `\x1B[38;2;${String(r)};${String(g)};${String(b)}m`;
2284
- } else {
2285
- const parsed = parseCssColor(css.color);
2286
- if (parsed === null) {
2287
- ansi += "\x1B[39m";
2288
- } else {
2289
- const { 0: r, 1: g, 2: b } = parsed;
2290
- ansi += `\x1B[38;2;${String(r)};${String(g)};${String(b)}m`;
2291
- }
2292
- }
2293
- }
2294
- }
2295
- }
2296
- }
2297
- if (css.fontWeight !== previousCss.fontWeight) {
2298
- ansi += css.fontWeight === "bold" ? "\x1B[1m" : "\x1B[22m";
2299
- }
2300
- if (css.fontStyle !== previousCss.fontStyle) {
2301
- ansi += css.fontStyle === "italic" ? "\x1B[3m" : "\x1B[23m";
2302
- }
2303
- if (!colorEquals(css.textDecorationColor, previousCss.textDecorationColor)) {
2304
- if (css.textDecorationColor == void 0) {
2305
- ansi += "\x1B[59m";
2306
- } else {
2307
- const { 0: r, 1: g, 2: b } = css.textDecorationColor;
2308
- ansi += `\x1B[58;2;${String(r)};${String(g)};${String(b)}m`;
2309
- }
2310
- }
2311
- if (css.textDecorationLine.includes("line-through") !== previousCss.textDecorationLine.includes("line-through")) {
2312
- ansi += css.textDecorationLine.includes("line-through") ? "\x1B[9m" : "\x1B[29m";
2313
- }
2314
- if (css.textDecorationLine.includes("overline") !== previousCss.textDecorationLine.includes("overline")) {
2315
- ansi += css.textDecorationLine.includes("overline") ? "\x1B[53m" : "\x1B[55m";
2316
- }
2317
- if (css.textDecorationLine.includes("underline") !== previousCss.textDecorationLine.includes("underline")) {
2318
- ansi += css.textDecorationLine.includes("underline") ? "\x1B[4m" : "\x1B[24m";
2319
- }
2320
- return ansi;
2321
- };
2322
- const tryStringify = (o) => {
2323
- try {
2324
- return JSON.stringify(o);
2325
- } catch {
2326
- return '"[Circular]"';
2327
- }
2328
- };
2329
- const CHAR_PERCENT = "%".codePointAt(0);
2330
- const CHAR_s = "s".codePointAt(0);
2331
- const CHAR_d = "d".codePointAt(0);
2332
- const CHAR_f = "f".codePointAt(0);
2333
- const CHAR_i = "i".codePointAt(0);
2334
- const CHAR_O = "O".codePointAt(0);
2335
- const CHAR_o = "o".codePointAt(0);
2336
- const CHAR_j = "j".codePointAt(0);
2337
- const CHAR_c = "c".codePointAt(0);
2338
- const format = (fmt, arguments_ = [], options = {}) => {
2339
- if (typeof fmt !== "string" && typeof fmt !== "object" || fmt === null) {
2340
- throw new TypeError(`fmt must be a string or object, got ${fmt === null ? "null" : typeof fmt}`);
2341
- }
2342
- const stringify = options.stringify ?? tryStringify;
2343
- const offset = 1;
2344
- if (typeof fmt === "object") {
2345
- const argumentsLength = arguments_.length + offset;
2346
- if (argumentsLength === 1) {
2347
- return "{}";
2348
- }
2349
- const objects = Array.from({ length: argumentsLength });
2350
- objects[0] = stringify(fmt);
2351
- for (let index = 1; index < argumentsLength; index += 1) {
2352
- objects[index] = stringify(arguments_[index - offset]);
2353
- }
2354
- return objects.join(" ");
2355
- }
2356
- if (arguments_.length === 0) {
2357
- return fmt;
2358
- }
2359
- let result = "";
2360
- let a = 1 - offset;
2361
- let lastPosition = -1;
2362
- let usedStyle = false;
2363
- let previousCss;
2364
- for (let index = 0; index < fmt.length; ) {
2365
- if (fmt.codePointAt(index) === CHAR_PERCENT && index + 1 < fmt.length) {
2366
- lastPosition = lastPosition > -1 ? lastPosition : 0;
2367
- const c = fmt.codePointAt(index + 1);
2368
- if (c === void 0) {
2369
- a += 1;
2370
- break;
2371
- }
2372
- switch (c) {
2373
- case CHAR_c: {
2374
- if (globalThis.window === void 0) {
2375
- const css = parseCss(arguments_[a]);
2376
- if (lastPosition < index) {
2377
- result += fmt.slice(lastPosition, index);
2378
- }
2379
- result += cssToAnsi(css, previousCss);
2380
- if (result !== "") {
2381
- usedStyle = true;
2382
- previousCss = css;
2383
- }
2384
- }
2385
- lastPosition = index + 2;
2386
- index += 1;
2387
- break;
2388
- }
2389
- case CHAR_d:
2390
- case CHAR_f: {
2391
- if (a >= arguments_.length || arguments_[a] == void 0) {
2392
- break;
2393
- }
2394
- if (lastPosition < index) {
2395
- result += fmt.slice(lastPosition, index);
2396
- }
2397
- result += Number(arguments_[a]).toString();
2398
- lastPosition = index + 2;
2399
- index += 1;
2400
- break;
2401
- }
2402
- case CHAR_i: {
2403
- if (a >= arguments_.length || arguments_[a] == void 0) {
2404
- break;
2405
- }
2406
- if (lastPosition < index) {
2407
- result += fmt.slice(lastPosition, index);
2408
- }
2409
- result += Math.floor(Number(arguments_[a])).toString();
2410
- lastPosition = index + 2;
2411
- index += 1;
2412
- break;
2413
- }
2414
- case CHAR_j:
2415
- case CHAR_O:
2416
- case CHAR_o: {
2417
- if (a >= arguments_.length || arguments_[a] === void 0) {
2418
- break;
2419
- }
2420
- if (lastPosition < index) {
2421
- result += fmt.slice(lastPosition, index);
2422
- }
2423
- const temporaryArgument = arguments_[a];
2424
- const type = typeof temporaryArgument;
2425
- if (type === "string") {
2426
- result += `'${temporaryArgument}'`;
2427
- lastPosition = index + 2;
2428
- break;
2429
- }
2430
- if (type === "function") {
2431
- result += temporaryArgument.name ? `[Function: ${temporaryArgument.name}]` : "[Function: <anonymous>]";
2432
- lastPosition = index + 2;
2433
- break;
2434
- }
2435
- result += stringify(temporaryArgument);
2436
- lastPosition = index + 2;
2437
- index += 1;
2438
- break;
2439
- }
2440
- case CHAR_PERCENT: {
2441
- if (lastPosition < index) {
2442
- result += fmt.slice(lastPosition, index);
2443
- }
2444
- result += "%";
2445
- lastPosition = index + 2;
2446
- index += 1;
2447
- a -= 1;
2448
- break;
2449
- }
2450
- case CHAR_s: {
2451
- if (a >= arguments_.length) {
2452
- break;
2453
- }
2454
- if (lastPosition < index) {
2455
- result += fmt.slice(lastPosition, index);
2456
- }
2457
- result += typeof arguments_[a] === "object" ? stringify(arguments_[a]) : String(arguments_[a]);
2458
- lastPosition = index + 2;
2459
- index += 1;
2460
- break;
2461
- }
2462
- default: {
2463
- if (typeof options.formatters?.[c] === "function") {
2464
- if (lastPosition < index) {
2465
- result += fmt.slice(lastPosition, index);
2466
- }
2467
- result += options.formatters[c](arguments_[a]);
2468
- lastPosition = index + 2;
2469
- index += 1;
2470
- }
2471
- }
2472
- }
2473
- a += 1;
2474
- }
2475
- index += 1;
2476
- }
2477
- if (lastPosition === -1) {
2478
- return fmt;
2479
- }
2480
- if (lastPosition < fmt.length) {
2481
- result += fmt.slice(lastPosition);
2482
- }
2483
- if (usedStyle) {
2484
- result += "\x1B[0m";
2485
- }
2486
- return result;
2487
- };
2488
- const build = (options = {}) => {
2489
- const formatters = {};
2490
- if (typeof options.formatters === "object") {
2491
- Object.entries(options.formatters).forEach(([key, formatterFunction]) => {
2492
- if (key.length === 0) {
2493
- throw new Error(`Formatter %${key} has no characters`);
2494
- }
2495
- if (key.length > 1) {
2496
- throw new Error(`Formatter %${key} has more than one character`);
2497
- }
2498
- if (typeof formatterFunction !== "function") {
2499
- throw new TypeError(`Formatter for %${key} is not a function`);
2500
- }
2501
- const c = key.codePointAt(0);
2502
- if (c === void 0) {
2503
- throw new Error(`${key}.codePointAt(0) failed to return a value, please report this issue`);
2504
- }
2505
- formatters[c] = formatterFunction;
2506
- });
2507
- }
2508
- return (f, arguments_ = [], formatOptions = {}) => format(f, arguments_, { ...formatOptions, formatters });
2509
- };
2510
-
2511
- class MessageFormatterProcessor {
2512
- /** Custom stringify function for object serialization */
2513
- #stringify;
2514
- /** Custom formatters for message interpolation */
2515
- #formatters;
2516
- /**
2517
- * Creates a new MessageFormatterProcessor instance.
2518
- * @param options Configuration options
2519
- * @param options.formatters Custom formatters for message interpolation
2520
- */
2521
- constructor(options = {}) {
2522
- this.#formatters = options.formatters;
2523
- }
2524
- /**
2525
- * Sets the stringify function for object serialization.
2526
- * @param function_ The stringify function to use for serializing objects
2527
- */
2528
- setStringify(function_) {
2529
- this.#stringify = function_;
2530
- }
2531
- /**
2532
- * Processes log metadata to format messages.
2533
- *
2534
- * Applies string interpolation and custom formatters to the message
2535
- * and contextual data in the log metadata.
2536
- * @param meta The log metadata to process
2537
- * @returns The processed metadata with formatted messages
2538
- */
2539
- process(meta) {
2540
- const formatter = build({
2541
- formatters: this.#formatters});
2542
- if (meta.message !== void 0) {
2543
- meta.message = this.#format(formatter, meta.message, meta.context ?? []);
2544
- }
2545
- return meta;
2546
- }
2547
- /**
2548
- * Recursively formats data using the formatter.
2549
- *
2550
- * Applies string interpolation and formatting to strings, arrays, and objects.
2551
- * @param formatter The formatter function to use
2552
- * @param data The data to format (string, array, or object)
2553
- * @param arguments_ Additional arguments for formatting
2554
- * @returns The formatted data
2555
- * @private
2556
- */
2557
- #format(formatter, data, arguments_ = []) {
2558
- if (typeof data === "string") {
2559
- return formatter(data, arguments_);
2560
- }
2561
- if (typeof data === "object" && data !== null) {
2562
- const record = data;
2563
- const keys = Object.keys(record);
2564
- for (let i = 0; i < keys.length; i += 1) {
2565
- const index = keys[i];
2566
- const value = record[index];
2567
- if (typeof value === "string" || Array.isArray(value) || typeof value === "object") {
2568
- record[index] = this.#format(formatter, value, arguments_);
2569
- }
2570
- }
2571
- }
2572
- return data;
2573
- }
2574
- }
2575
-
2576
- const { bgGrey, cyan, green, greenBright, grey, red, underline, white } = colorize;
2577
- const PAIL_DIST_REGEX = /[\\/]pail[\\/]dist/;
2578
- const pailFileFilter = (line) => !PAIL_DIST_REGEX.test(line);
2579
- class PrettyReporter extends AbstractPrettyReporter {
2580
- #stdout;
2581
- #stderr;
2582
- #interactiveManager;
2583
- #interactive = false;
2584
- #inspectOptions;
2585
- #errorOptions;
2586
- /**
2587
- * Creates a new Server Pretty Reporter instance.
2588
- * @param options Configuration options for styling, error rendering, and object inspection
2589
- */
2590
- constructor(options = {}) {
2591
- const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
2592
- super({
2593
- uppercase: {
2594
- label: true,
2595
- ...rest.uppercase
2596
- },
2597
- ...rest
2598
- });
2599
- this.#inspectOptions = { ...defaultInspectorConfig, ...inspectOptions };
2600
- this.#errorOptions = {
2601
- ...errorOptions,
2602
- color: {
2603
- fileLine: green,
2604
- hint: cyan,
2605
- marker: red,
2606
- message: red,
2607
- method: greenBright,
2608
- title: red
2609
- }
2610
- };
2611
- this.#stdout = stdout;
2612
- this.#stderr = stderr;
2613
- }
2614
- /**
2615
- * Sets the stdout stream for the reporter.
2616
- * @param stdout_ The writable stream to use for standard output
2617
- */
2618
- setStdout(stdout_) {
2619
- this.#stdout = stdout_;
2620
- }
2621
- /**
2622
- * Sets the stderr stream for the reporter.
2623
- * @param stderr_ The writable stream to use for error output
2624
- */
2625
- setStderr(stderr_) {
2626
- this.#stderr = stderr_;
2627
- }
2628
- /**
2629
- * Sets the interactive manager for handling interactive output.
2630
- * @param manager The interactive manager instance, or undefined to disable
2631
- */
2632
- setInteractiveManager(manager) {
2633
- this.#interactiveManager = manager;
2634
- }
2635
- /**
2636
- * Enables or disables interactive mode.
2637
- * @param interactive Whether to enable interactive terminal features
2638
- */
2639
- setIsInteractive(interactive) {
2640
- this.#interactive = interactive;
2641
- }
2642
- log(meta) {
2643
- this._log(this._formatMessage(meta), meta.type.level);
2644
- }
2645
- // eslint-disable-next-line sonarjs/cognitive-complexity, no-underscore-dangle
2646
- _formatMessage(data) {
2647
- const { columns } = terminalSize();
2648
- let size = columns;
2649
- if (typeof this.styles.messageLength === "number") {
2650
- size = this.styles.messageLength;
2651
- }
2652
- const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
2653
- const { color } = this.loggerTypes[type.name];
2654
- const colorized = color ? colorize[color] : white;
2655
- const groupSpaces = groups.map(() => " ").join("");
2656
- const items = [];
2657
- if (groups.length > 0) {
2658
- items.push(`${groupSpaces + grey(`[${groups.at(-1) ?? ""}]`)} `);
2659
- }
2660
- if (date) {
2661
- items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
2662
- }
2663
- if (badge) {
2664
- items.push(colorized(badge));
2665
- } else {
2666
- const longestBadge = getLongestBadge(this.loggerTypes);
2667
- if (longestBadge.length > 0) {
2668
- items.push(`${grey(".".repeat(longestBadge.length))} `);
2669
- }
2670
- }
2671
- const longestLabel = getLongestLabel(this.loggerTypes);
2672
- if (label) {
2673
- const longestLabelWidth = getStringWidth(longestLabel);
2674
- const labelWidth = getStringWidth(label);
2675
- items.push(`${colorized(formatLabel(label, this.styles))} `, grey(".".repeat(Math.max(0, longestLabelWidth - labelWidth))));
2676
- } else {
2677
- items.push(grey(".".repeat(longestLabel.length + 2)));
2678
- }
2679
- if (repeated) {
2680
- items.push(`${bgGrey.white(`[${String(repeated)}x]`)} `);
2681
- }
2682
- if (Array.isArray(scope) && scope.length > 0) {
2683
- items.push(` ${grey(`[${scope.join(" > ")}]`)} `);
2684
- }
2685
- if (prefix) {
2686
- items.push(`${grey(`${Array.isArray(scope) && scope.length > 0 ? ". " : " "}[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `);
2687
- }
2688
- const titleSize = getStringWidth(items.join(" "));
2689
- if (file) {
2690
- const fileMessage = (file.name ?? "") + (file.line ? `:${String(file.line)}` : "");
2691
- const fileMessageSize = getStringWidth(fileMessage);
2692
- if (fileMessageSize + titleSize + 2 > size) {
2693
- items.push(grey(` ${fileMessage}`));
2694
- } else {
2695
- const dots = Math.max(0, size - titleSize - fileMessageSize - 2);
2696
- items.push(grey(`${".".repeat(dots)} ${fileMessage}`));
2697
- }
2698
- } else {
2699
- items.push(grey(".".repeat(Math.max(0, size - titleSize - 1))));
2700
- }
2701
- if (items.length > 0) {
2702
- items.push("\n\n");
2703
- }
2704
- if (message !== EMPTY_SYMBOL) {
2705
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
2706
- items.push(
2707
- groupSpaces + wordWrap(formattedMessage, {
2708
- trim: false,
2709
- width: size - 3,
2710
- wrapMode: WrapMode.STRICT_WIDTH
2711
- })
2712
- );
2713
- }
2714
- if (context) {
2715
- let hasError = false;
2716
- items.push(
2717
- ...context.map((value) => {
2718
- if (value instanceof Error) {
2719
- hasError = true;
2720
- return `
2721
-
2722
- ${renderError(value, {
2723
- ...this.#errorOptions,
2724
- filterStacktrace: pailFileFilter,
2725
- prefix: groupSpaces
2726
- })}`;
2727
- }
2728
- if (typeof value === "object") {
2729
- return ` ${inspect(value, this.#inspectOptions)}`;
2730
- }
2731
- const newValue = (hasError ? "\n\n" : " ") + String(value);
2732
- hasError = false;
2733
- return newValue;
2734
- })
2735
- );
2736
- }
2737
- if (error) {
2738
- items.push(
2739
- renderError(error, {
2740
- ...this.#errorOptions,
2741
- filterStacktrace: pailFileFilter,
2742
- prefix: groupSpaces
2743
- })
2744
- );
2745
- }
2746
- if (traceError) {
2747
- items.push(
2748
- `
2749
-
2750
- ${renderError(traceError, {
2751
- ...this.#errorOptions,
2752
- filterStacktrace: pailFileFilter,
2753
- hideErrorCauseCodeView: true,
2754
- hideErrorCodeView: true,
2755
- hideErrorErrorsCodeView: true,
2756
- hideMessage: true,
2757
- prefix: groupSpaces
2758
- })}`
2759
- );
2760
- }
2761
- if (suffix) {
2762
- items.push("\n", groupSpaces + grey(this.styles.underline.suffix ? underline(suffix) : suffix));
2763
- }
2764
- return items.join("");
2765
- }
2766
- // eslint-disable-next-line no-underscore-dangle
2767
- _log(message, logLevel) {
2768
- const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
2769
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
2770
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
2771
- this.#interactiveManager.update(streamType, message.split("\n"), 0);
2772
- } else {
2773
- writeStream(`${message}
2774
- `, stream);
2775
- }
2776
- }
2777
- }
2778
-
2779
- const getDefaultLogLevel = () => {
2780
- if (env.NODE_ENV === "debug" || env.DEBUG !== void 0) {
2781
- return "debug";
2782
- }
2783
- if (env.NODE_ENV === "test") {
2784
- return "warning";
2785
- }
2786
- return "informational";
2787
- };
2788
- const createPail = (options) => {
2789
- let logLevel = getDefaultLogLevel();
2790
- if (env.PAIL_LOG_LEVEL !== void 0) {
2791
- logLevel = env.PAIL_LOG_LEVEL;
2792
- }
2793
- return new PailServer({
2794
- logLevel,
2795
- processors: [new MessageFormatterProcessor()],
2796
- reporters: [new PrettyReporter()],
2797
- stderr,
2798
- stdout,
2799
- ...options
2800
- });
2801
- };
2802
- const pail = createPail();
2803
-
2804
- export { createPail, pail };
1
+ var Ge=Object.defineProperty;var p=(t,e)=>Ge(t,"name",{value:e,configurable:!0});import{createRequire as ze}from"node:module";import{InteractiveManager as We,InteractiveStreamHook as Me}from"@visulima/interactive-manager";import{L as Ue,s as le,E as Ye,a as Se,p as ce,i as _e,A as Qe,u as Ke,O as Xe,b as Ze,o as ne,c as et,d as tt,B as rt,G as ge}from"./packem_shared/abstract-pretty-reporter-Bag7lQKf.js";import De from"@visulima/colorize";import{PailError as Vr,createPailError as Gr}from"./packem_shared/createPailError-53jAfQ-T.js";const Br=ze(import.meta.url),He=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{stdout:$e,stderr:ve,env:se}=He,st="\x1B",M="\x1B[",Ce=";";var it=Object.defineProperty,ot=p((t,e)=>it(t,"name",{value:e,configurable:!0}),"t$3"),nt=Object.defineProperty,at=ot((t,e)=>nt(t,"name",{value:e,configurable:!0}),"t");const lt=typeof globalThis<"u"&&typeof globalThis.window=="object"&&globalThis.window.document!==void 0,ct=/^(?:msys|cygwin)$/,ft=!lt&&(process.platform==="win32"||ct.test(process.env.OSTYPE));var ut=Object.defineProperty,D=at((t,e)=>ut(t,"name",{value:e,configurable:!0}),"n");const gt=D((t=1)=>`${M}${String(t)}D`,"cursorBackward");D((t=1)=>`${M}${String(t)}B`,"cursorDown");D((t=1)=>`${M}${String(t)}C`,"cursorForward");const ht=`${M}G`;D((t=1)=>gt(t),"cursorLeft");const dt=D((t=1)=>`${M}${String(t)}G`,"cursorHorizontalAbsolute");D((t,e)=>{let r="";return t<0?r+=`${M}${String(-t)}D`:t>0&&(r+=`${M}${String(t)}C`),e<0?r+=`${M}${String(-e)}A`:e>0&&(r+=`${M}${String(e)}B`),r},"cursorMove");D((t=1)=>`${M}${String(t)}E`,"cursorNextLine");D((t=1)=>`${M}${String(t)}F`,"cursorPreviousLine");const pt=D((t,e)=>e===void 0?dt(t+1):`${M}${String(e+1)}${Ce}${String(t+1)}H`,"cursorTo");D((t,e)=>e===void 0?`${M}${String(t)}H`:`${M}${String(t)}${Ce}${String(e)}H`,"cursorPosition");D((t=1)=>`${M}${String(t)}I`,"cursorHorizontalForwardTab");D((t=1)=>`${M}${String(t)}Z`,"cursorBackwardTab");D((t=1)=>`${M}${String(t)}X`,"eraseCharacter");D((t=1)=>`${M}${String(t)}d`,"cursorVerticalAbsolute");const mt=D((t=1)=>`${M}${String(t)}A`,"cursorUp");var bt=(t=>(t[t.Default=0]="Default",t[t.BlinkingBlock=1]="BlinkingBlock",t[t.SteadyBlock=2]="SteadyBlock",t[t.BlinkingUnderline=3]="BlinkingUnderline",t[t.SteadyUnderline=4]="SteadyUnderline",t[t.BlinkingBar=5]="BlinkingBar",t[t.SteadyBar=6]="SteadyBar",t))(bt||{});D(t=>`${M}${String(t)} q`,"setCursorStyle");var yt=Object.defineProperty,$t=p((t,e)=>yt(t,"name",{value:e,configurable:!0}),"o$3"),vt=Object.defineProperty,St=$t((t,e)=>vt(t,"name",{value:e,configurable:!0}),"s"),wt=Object.defineProperty,we=St((t,e)=>wt(t,"name",{value:e,configurable:!0}),"o"),Z=(t=>(t[t.ToEnd=0]="ToEnd",t[t.ToBeginning=1]="ToBeginning",t[t.EntireScreen=2]="EntireScreen",t[t.EntireScreenAndScrollback=3]="EntireScreenAndScrollback",t))(Z||{});const U=we(t=>{const e=t>=0&&t<=3?t:0;return`${M}${e===0?"":String(e)}J`},"eraseDisplay");var Re=(t=>(t[t.ToEnd=0]="ToEnd",t[t.ToBeginning=1]="ToBeginning",t[t.EntireLine=2]="EntireLine",t))(Re||{});const ue=we(t=>{const e=t>=0&&t<=2?t:0;return`${M}${e===0?"":String(e)}K`},"eraseInLine");U(0);const xt=ue(2);ue(0);ue(1);we(t=>{if(t<=0)return"";let e="";for(let r=0;r<t;r+=1)e+=xt,r<t-1&&(e+=mt());return e+=ht,e},"eraseLines");U(2);U(1);U(3);pt(0,0)+U(Z.ToEnd);`${ue(Re.EntireLine)}${M}`;`${M}${U(Z.EntireScreen)}`;const Oe=ft?`${U(Z.EntireScreen)}${M}0f`:`${U(Z.EntireScreen)}${U(Z.EntireScreenAndScrollback)}${M}H${st}c`;var Lt=Object.defineProperty,ee=p((t,e)=>Lt(t,"name",{value:e,configurable:!0}),"t$2");function Ie(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}p(Ie,"getDefaultExportFromCjs");ee(Ie,"getDefaultExportFromCjs");function Tt(t){return t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}p(Tt,"getDefaultExportFromNamespaceIfPresent");ee(Tt,"getDefaultExportFromNamespaceIfPresent");function kt(t){return t&&Object.prototype.hasOwnProperty.call(t,"default")&&Object.keys(t).length===1?t.default:t}p(kt,"getDefaultExportFromNamespaceIfNotNamed");ee(kt,"getDefaultExportFromNamespaceIfNotNamed");function Mt(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if(typeof e=="function"){var r=ee(p(function s(){var i=!1;try{i=this instanceof s}catch{}return i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)},"a"),"a");r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(s){var i=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(r,s,i.get?i:{enumerable:!0,get:ee(function(){return t[s]},"get")})}),r}p(Mt,"getAugmentedNamespace");ee(Mt,"getAugmentedNamespace");var ae={exports:{}},je;function Ot(){return je||(je=1,(function(t,e){var r=Object.defineProperty,s=p((f,l)=>r(f,"name",{value:l,configurable:!0}),"$");const{hasOwnProperty:i}=Object.prototype,a=Q();a.configure=Q,a.stringify=a,a.default=a,e.stringify=a,e.configure=Q,t.exports=a;const u=/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/;function n(f){return f.length<5e3&&!u.test(f)?`"${f}"`:JSON.stringify(f)}p(n,"strEscape"),s(n,"strEscape");function g(f,l){if(f.length>200||l)return f.sort(l);for(let $=1;$<f.length;$++){const N=f[$];let T=$;for(;T!==0&&f[T-1]>N;)f[T]=f[T-1],T--;f[T]=N}return f}p(g,"sort"),s(g,"sort");const y=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Object.getPrototypeOf(new Int8Array)),Symbol.toStringTag).get;function c(f){return y.call(f)!==void 0&&f.length!==0}p(c,"isTypedArrayWithEntries"),s(c,"isTypedArrayWithEntries");function d(f,l,$){f.length<$&&($=f.length);const N=l===","?"":" ";let T=`"0":${N}${f[0]}`;for(let P=1;P<$;P++)T+=`${l}"${P}":${N}${f[P]}`;return T}p(d,"stringifyTypedArray"),s(d,"stringifyTypedArray");function b(f){if(i.call(f,"circularValue")){const l=f.circularValue;if(typeof l=="string")return`"${l}"`;if(l==null)return l;if(l===Error||l===TypeError)return{toString(){throw new TypeError("Converting circular structure to JSON")}};throw new TypeError('The "circularValue" argument must be of type string or the value null or undefined')}return'"[Circular]"'}p(b,"getCircularValueOption"),s(b,"getCircularValueOption");function A(f){let l;if(i.call(f,"deterministic")&&(l=f.deterministic,typeof l!="boolean"&&typeof l!="function"))throw new TypeError('The "deterministic" argument must be of type boolean or comparator function');return l===void 0?!0:l}p(A,"getDeterministicOption"),s(A,"getDeterministicOption");function q(f,l){let $;if(i.call(f,l)&&($=f[l],typeof $!="boolean"))throw new TypeError(`The "${l}" argument must be of type boolean`);return $===void 0?!0:$}p(q,"getBooleanOption"),s(q,"getBooleanOption");function z(f,l){let $;if(i.call(f,l)){if($=f[l],typeof $!="number")throw new TypeError(`The "${l}" argument must be of type number`);if(!Number.isInteger($))throw new TypeError(`The "${l}" argument must be an integer`);if($<1)throw new RangeError(`The "${l}" argument must be >= 1`)}return $===void 0?1/0:$}p(z,"getPositiveIntegerOption"),s(z,"getPositiveIntegerOption");function R(f){return f===1?"1 item":`${f} items`}p(R,"getItemCount"),s(R,"getItemCount");function F(f){const l=new Set;for(const $ of f)(typeof $=="string"||typeof $=="number")&&l.add(String($));return l}p(F,"getUniqueReplacerSet"),s(F,"getUniqueReplacerSet");function Y(f){if(i.call(f,"strict")){const l=f.strict;if(typeof l!="boolean")throw new TypeError('The "strict" argument must be of type boolean');if(l)return $=>{let N=`Object can not safely be stringified. Received type ${typeof $}`;throw typeof $!="function"&&(N+=` (${$.toString()})`),new Error(N)}}}p(Y,"getStrictOption"),s(Y,"getStrictOption");function Q(f){f={...f};const l=Y(f);l&&(f.bigint===void 0&&(f.bigint=!1),"circularValue"in f||(f.circularValue=Error));const $=b(f),N=q(f,"bigint"),T=A(f),P=typeof T=="function"?T:void 0,J=z(f,"maximumDepth"),O=z(f,"maximumBreadth");function te(_,o,h,w,v,x){let m=o[_];switch(typeof m=="object"&&m!==null&&typeof m.toJSON=="function"&&(m=m.toJSON(_)),m=w.call(o,_,m),typeof m){case"string":return n(m);case"object":{if(m===null)return"null";if(h.indexOf(m)!==-1)return $;let S="",j=",";const E=x;if(Array.isArray(m)){if(m.length===0)return"[]";if(J<h.length+1)return'"[Array]"';h.push(m),v!==""&&(x+=v,S+=`
2
+ ${x}`,j=`,
3
+ ${x}`);const I=Math.min(m.length,O);let H=0;for(;H<I-1;H++){const oe=te(String(H),m,h,w,v,x);S+=oe!==void 0?oe:"null",S+=j}const W=te(String(H),m,h,w,v,x);if(S+=W!==void 0?W:"null",m.length-1>O){const oe=m.length-O-1;S+=`${j}"... ${R(oe)} not stringified"`}return v!==""&&(S+=`
4
+ ${E}`),h.pop(),`[${S}]`}let k=Object.keys(m);const B=k.length;if(B===0)return"{}";if(J<h.length+1)return'"[Object]"';let L="",C="";v!==""&&(x+=v,j=`,
5
+ ${x}`,L=" ");const V=Math.min(B,O);T&&!c(m)&&(k=g(k,P)),h.push(m);for(let I=0;I<V;I++){const H=k[I],W=te(H,m,h,w,v,x);W!==void 0&&(S+=`${C}${n(H)}:${L}${W}`,C=j)}if(B>O){const I=B-O;S+=`${C}"...":${L}"${R(I)} not stringified"`,C=j}return v!==""&&C.length>1&&(S=`
6
+ ${x}${S}
7
+ ${E}`),h.pop(),`{${S}}`}case"number":return isFinite(m)?String(m):l?l(m):"null";case"boolean":return m===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(m);default:return l?l(m):void 0}}p(te,"J"),s(te,"stringifyFnReplacer");function re(_,o,h,w,v,x){switch(typeof o=="object"&&o!==null&&typeof o.toJSON=="function"&&(o=o.toJSON(_)),typeof o){case"string":return n(o);case"object":{if(o===null)return"null";if(h.indexOf(o)!==-1)return $;const m=x;let S="",j=",";if(Array.isArray(o)){if(o.length===0)return"[]";if(J<h.length+1)return'"[Array]"';h.push(o),v!==""&&(x+=v,S+=`
8
+ ${x}`,j=`,
9
+ ${x}`);const B=Math.min(o.length,O);let L=0;for(;L<B-1;L++){const V=re(String(L),o[L],h,w,v,x);S+=V!==void 0?V:"null",S+=j}const C=re(String(L),o[L],h,w,v,x);if(S+=C!==void 0?C:"null",o.length-1>O){const V=o.length-O-1;S+=`${j}"... ${R(V)} not stringified"`}return v!==""&&(S+=`
10
+ ${m}`),h.pop(),`[${S}]`}h.push(o);let E="";v!==""&&(x+=v,j=`,
11
+ ${x}`,E=" ");let k="";for(const B of w){const L=re(B,o[B],h,w,v,x);L!==void 0&&(S+=`${k}${n(B)}:${E}${L}`,k=j)}return v!==""&&k.length>1&&(S=`
12
+ ${x}${S}
13
+ ${m}`),h.pop(),`{${S}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(o);default:return l?l(o):void 0}}p(re,"I"),s(re,"stringifyArrayReplacer");function K(_,o,h,w,v){switch(typeof o){case"string":return n(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(_),typeof o!="object")return K(_,o,h,w,v);if(o===null)return"null"}if(h.indexOf(o)!==-1)return $;const x=v;if(Array.isArray(o)){if(o.length===0)return"[]";if(J<h.length+1)return'"[Array]"';h.push(o),v+=w;let L=`
14
+ ${v}`;const C=`,
15
+ ${v}`,V=Math.min(o.length,O);let I=0;for(;I<V-1;I++){const W=K(String(I),o[I],h,w,v);L+=W!==void 0?W:"null",L+=C}const H=K(String(I),o[I],h,w,v);if(L+=H!==void 0?H:"null",o.length-1>O){const W=o.length-O-1;L+=`${C}"... ${R(W)} not stringified"`}return L+=`
16
+ ${x}`,h.pop(),`[${L}]`}let m=Object.keys(o);const S=m.length;if(S===0)return"{}";if(J<h.length+1)return'"[Object]"';v+=w;const j=`,
17
+ ${v}`;let E="",k="",B=Math.min(S,O);c(o)&&(E+=d(o,j,O),m=m.slice(o.length),B-=o.length,k=j),T&&(m=g(m,P)),h.push(o);for(let L=0;L<B;L++){const C=m[L],V=K(C,o[C],h,w,v);V!==void 0&&(E+=`${k}${n(C)}: ${V}`,k=j)}if(S>O){const L=S-O;E+=`${k}"...": "${R(L)} not stringified"`,k=j}return k!==""&&(E=`
18
+ ${v}${E}
19
+ ${x}`),h.pop(),`{${E}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(o);default:return l?l(o):void 0}}p(K,"V"),s(K,"stringifyIndent");function X(_,o,h){switch(typeof o){case"string":return n(o);case"object":{if(o===null)return"null";if(typeof o.toJSON=="function"){if(o=o.toJSON(_),typeof o!="object")return X(_,o,h);if(o===null)return"null"}if(h.indexOf(o)!==-1)return $;let w="";const v=o.length!==void 0;if(v&&Array.isArray(o)){if(o.length===0)return"[]";if(J<h.length+1)return'"[Array]"';h.push(o);const E=Math.min(o.length,O);let k=0;for(;k<E-1;k++){const L=X(String(k),o[k],h);w+=L!==void 0?L:"null",w+=","}const B=X(String(k),o[k],h);if(w+=B!==void 0?B:"null",o.length-1>O){const L=o.length-O-1;w+=`,"... ${R(L)} not stringified"`}return h.pop(),`[${w}]`}let x=Object.keys(o);const m=x.length;if(m===0)return"{}";if(J<h.length+1)return'"[Object]"';let S="",j=Math.min(m,O);v&&c(o)&&(w+=d(o,",",O),x=x.slice(o.length),j-=o.length,S=","),T&&(x=g(x,P)),h.push(o);for(let E=0;E<j;E++){const k=x[E],B=X(k,o[k],h);B!==void 0&&(w+=`${S}${n(k)}:${B}`,S=",")}if(m>O){const E=m-O;w+=`${S}"...":"${R(E)} not stringified"`}return h.pop(),`{${w}}`}case"number":return isFinite(o)?String(o):l?l(o):"null";case"boolean":return o===!0?"true":"false";case"undefined":return;case"bigint":if(N)return String(o);default:return l?l(o):void 0}}p(X,"N"),s(X,"stringifySimple");function ke(_,o,h){if(arguments.length>1){let w="";if(typeof h=="number"?w=" ".repeat(Math.min(h,10)):typeof h=="string"&&(w=h.slice(0,10)),o!=null){if(typeof o=="function")return te("",{"":_},[],o,w,"");if(Array.isArray(o))return re("",_,[],F(o),w,"")}if(w.length!==0)return K("",_,[],w,"")}return X("",_,[])}return p(ke,"M"),s(ke,"stringify"),ke}p(Q,"configure"),s(Q,"configure")})(ae,ae.exports)),ae.exports}p(Ot,"requireSafeStableStringify");var jt=Ot();const Et=Ie(jt),At=Et.configure;var Pt=Object.defineProperty,Bt=p((t,e)=>Pt(t,"name",{value:e,configurable:!0}),"o$1");const Nt=Bt(t=>{const e=console;return t==="error"?e.__error??console.error:t==="warn"?e.__warn??console.warn:t==="trace"?e.__trace??console.trace:e.__log??console.log},"writeConsoleLogBasedOnLevel");var _t=Object.defineProperty,Dt=p((t,e)=>_t(t,"name",{value:e,configurable:!0}),"t");let Ct=class{static{p(this,"a")}static{Dt(this,"RawReporter")}log(e){const{context:r=[],message:s,type:i}=e;Nt(i.level)(s,...r)}};var Rt=Object.defineProperty,It=p((t,e)=>Rt(t,"name",{value:e,configurable:!0}),"a");const me=It(t=>t===void 0?[]:Array.isArray(t)?t:[t],"arrayify");var Ft=Object.defineProperty,qt=p((t,e)=>Ft(t,"name",{value:e,configurable:!0}),"g$3");const be=qt((t,e)=>{const r={...t};return Object.keys(e).forEach(s=>{r[s]={...r[s],...e[s]}}),r},"mergeTypes");var Jt=Object.defineProperty,ye=p((t,e)=>Jt(t,"name",{value:e,configurable:!0}),"d");const Vt=ye(t=>{let e=!1;return function(...r){if(!e){e=!0;try{const s=t.apply(this,r);return e=!1,s}catch(s){throw e=!1,s}}}},"preventLoop");class xe{static{p(this,"PailBrowserImpl")}static{ye(this,"PailBrowserImpl")}timersMap;countMap;seqTimers;lastLog;logLevels;disabled;paused;messageQueue;scopeName;types;longestLabel;processors;generalLogLevel;reporters;throttle;throttleMin;stringify;groups;startTimerMessage;endTimerMessage;rawReporter;force={};constructor(e){this.throttle=e.throttle??1e3,this.throttleMin=e.throttleMin??5;const r=e.parentLongestLabel,s=e.parentTypes,i=e.parentStringify,a=e.parentLogLevels;this.stringify=i??At({strict:!0}),this.startTimerMessage=e.messages?.timerStart??"Initialized timer...",this.endTimerMessage=e.messages?.timerEnd??"Timer run for:",s&&r?(this.types=s,this.longestLabel=r):(this.types=be(Ue,e.types??{}),this.longestLabel=le(this.types)),this.logLevels=a&&!e.logLevels?a:{...Ye,...e.logLevels},this.generalLogLevel=this.#t(e.logLevel),this.reporters=new Set,this.processors=new Set,this.disabled=e.disabled??!1,this.paused=!1,this.messageQueue=[],this.scopeName=me(e.scope).filter(Boolean),this.timersMap=new Map,this.countMap=new Map,this.groups=[],this.seqTimers=new Set,this.lastLog={},this.logger=Vt(this.logger.bind(this)),this.#r(),Array.isArray(e.reporters)&&this.registerReporters(e.reporters),this.rawReporter=this.extendReporter(e.rawReporter??new Ct),Array.isArray(e.processors)&&this.registerProcessors(e.processors)}#r(){for(const e in this.types)this[e]=this.logger.bind(this,e,!1,!1);for(const e in this.types)this.force[e]=this.logger.bind(this,e,!1,!0)}wrapConsole(){for(const e in this.types)console[`__${e}`]||(console[`__${e}`]=console[e]),console[e]=this[e]}restoreConsole(){for(const e in this.types)console[`__${e}`]&&(console[e]=console[`__${e}`],delete console[`__${e}`])}wrapException(){process.on("uncaughtException",e=>{this.error(e)}),process.on("unhandledRejection",e=>{this.error(e)})}disable(){this.disabled=!0}enable(){this.disabled=!1}isEnabled(){return!this.disabled}pause(){this.paused=!0}resume(){this.paused=!1;const e=this.messageQueue.splice(0);for(let r=0;r<e.length;r+=1){const{messageObject:s,raw:i,type:a}=e[r];this.logger(a,i,!1,...s)}}scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.scopeName=e.flat(),this}unscope(){this.scopeName=[]}child(e){const r=e?.types!==void 0,s=r?be(this.types,e.types):this.types,i=e?.reporters??[],a=i.length>0?[...this.reporters,...i]:[...this.reporters],u=e?.processors??[],n=u.length>0?[...this.processors,...u]:[...this.processors],g=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let y;if(e?.scope){const b=me(e.scope).filter(Boolean);y=this.scopeName.length>0?[...this.scopeName,...b]:b}else y=this.scopeName.length>0?this.scopeName:[];const c=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},d={disabled:e?.disabled??this.disabled,logLevel:e?.logLevel??this.generalLogLevel,logLevels:g,messages:c,processors:n,rawReporter:e?.rawReporter??this.rawReporter,reporters:a,scope:y,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return r?(d.parentTypes=s,d.parentLongestLabel=le(s)):(d.parentTypes=this.types,d.parentLongestLabel=this.longestLabel),e?.logLevels||(d.parentLogLevels=this.logLevels),e?.messages||(d.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),d.parentStringify=this.stringify,new xe(d)}time(e="default"){this.seqTimers.has(e)?this.logger("warn",!1,!1,{message:`Timer '${e}' already exists`,prefix:e}):(this.seqTimers.add(e),this.timersMap.set(e,Date.now()),this.logger("start",!1,!1,{message:this.startTimerMessage,prefix:e}))}timeLog(e,...r){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const s=Date.now()-this.timersMap.get(e);this.logger("info",!1,!1,{context:r,message:s<1e3?`${String(s)} ms`:`${(s/1e3).toFixed(2)} s`,prefix:e})}else this.logger("warn",!1,!1,{context:r,message:"Timer not found",prefix:e})}timeEnd(e){if(!e&&this.seqTimers.size>0&&(e=[...this.seqTimers].pop()),e&&this.timersMap.has(e)){const r=Date.now()-this.timersMap.get(e);this.timersMap.delete(e),this.logger("stop",!1,!1,{message:`${this.endTimerMessage} ${r<1e3?`${String(r)} ms`:`${(r/1e3).toFixed(2)} s`}`,prefix:e})}else this.logger("warn",!1,!1,{message:"Timer not found",prefix:e})}group(e="console.group"){globalThis.window===void 0?this.groups.push(e):console.group(e)}groupEnd(){globalThis.window===void 0?this.groups.pop():console.groupEnd()}count(e="default"){const r=this.countMap.get(e)??0;this.countMap.set(e,r+1),this.logger("log",!1,!1,{message:`${e}: ${String(r+1)}`,prefix:e})}countReset(e="default"){this.countMap.has(e)?this.countMap.delete(e):this.logger("warn",!1,!1,{message:`Count for ${e} does not exist`,prefix:e})}clear(){console.clear()}raw(e,...r){this.disabled||this.logger("log",!0,!1,{context:r,message:e})}extendReporter(e){return typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),e}registerReporters(e){for(let r=0;r<e.length;r+=1)this.reporters.add(this.extendReporter(e[r]))}registerProcessors(e){for(let r=0;r<e.length;r+=1){const s=e[r];typeof s.setStringify=="function"&&s.setStringify(this.stringify),this.processors.add(s)}}#e(e,r){if(r)this.rawReporter.log(Object.freeze(e));else for(const s of this.reporters)s.log(Object.freeze(e))}#t(e){return e&&this.logLevels[e]?e:"debug"}#s(e,r,...s){const i={badge:void 0,context:void 0,error:void 0,label:void 0,message:Se,prefix:void 0,repeated:void 0,scope:void 0,suffix:void 0};if(i.type={level:r.logLevel,name:e},i.groups=this.groups,i.scope=this.scopeName,i.date=new Date,s.length>0&&s[0]instanceof Error)i.error=s[0],s.length>1&&(i.context=s.slice(1));else if(s.length>0&&typeof s[0]=="object"&&s[0]!==null&&"message"in s[0]){const{context:a,message:u,prefix:n,suffix:g}=s[0];if(a&&(i.context=a),n&&(i.prefix=n),g&&(i.suffix=g),i.message=u,s.length>1){const y=s.slice(1);i.context?i.context=Array.isArray(i.context)?[...i.context,...y]:[i.context,...y]:i.context=y}}else s.length>1?(i.message=s[0],i.context=s.slice(1)):s.length===1?i.message=s[0]:i.message=void 0;return r.logLevel==="trace"&&(i.traceError=new Error("Trace")),r.badge&&(i.badge=r.badge),r.label&&(i.label=r.label),i}logger(e,r,s,...i){if(this.disabled)return;if(this.paused){this.messageQueue.push({messageObject:i,raw:r,type:e});return}const a=this.types[e],u=this.#t(a.logLevel);if(s||this.logLevels[u]>=this.logLevels[this.generalLogLevel]){let n=this.#s(e,a,...i);const g=ye((c=!1)=>{const d=(this.lastLog.count??0)-this.throttleMin;if(this.lastLog.object&&d>0){const b={...this.lastLog.object};d>1&&(b.repeated=d),this.#e(b,r),this.lastLog.count=1}if(c){for(const b of this.processors)n={...b.process(n)};this.lastLog.object=n,this.#e(n,r)}},"resolveLog");clearTimeout(this.lastLog.timeout);const y=this.lastLog.time&&n.date?new Date(n.date).getTime()-this.lastLog.time.getTime():0;if(this.lastLog.time=new Date(n.date),y<this.throttle)try{if(this.lastLog.object&&JSON.stringify([n.label,n.scope,n.type,n.message,n.prefix,n.suffix,n.context])===JSON.stringify([this.lastLog.object.label,this.lastLog.object.scope,this.lastLog.object.type,this.lastLog.object.message,this.lastLog.object.prefix,this.lastLog.object.suffix,this.lastLog.object.context])&&(this.lastLog.count=(this.lastLog.count??0)+1,this.lastLog.count>this.throttleMin)){this.lastLog.timeout=setTimeout(g,this.throttle);return}}catch{}g(!0)}}}var Gt=Object.defineProperty,zt=p((t,e)=>Gt(t,"name",{value:e,configurable:!0}),"c$1");let Ht=class{static{p(this,"v")}static{zt(this,"RawReporter")}#r;#e;#t;#s=!1;#i;constructor(e={}){this.#r=$e,this.#e=ve,this.#i=e}setStdout(e){this.#r=e}setStderr(e){this.#e=e}setInteractiveManager(e){this.#t=e}setIsInteractive(e){this.#s=e}log(e){const{context:r,groups:s,message:i,type:a}=e,u=[];if(i!==Se){const c=typeof i=="string"?i:ce(i,this.#i);u.push(c)}r&&u.push(...r.map(c=>typeof c=="object"?` ${ce(c,this.#i)}`:` ${String(c)}`));const n=["error","trace","warn"].includes(a.level)?"stderr":"stdout",g=n==="stderr"?this.#e:this.#r,y=s.map(()=>" ").join("");this.#s&&this.#t!==void 0&&g.isTTY?this.#t.update(n,(y+u.join("")).split(`
20
+ `),0):_e(y+u.join(""),g)}};var Wt=Object.defineProperty,Ut=p((t,e)=>Wt(t,"name",{value:e,configurable:!0}),"m$1");class Le extends xe{static{p(this,"c")}constructor(e){const r=e.parentStderr,s=e.parentStdout,{interactive:i,processors:a,rawReporter:u,reporters:n,stderr:g,stdout:y}=e,c=r??g,d=s??y,b=e.parentLongestLabel,A=e.parentTypes,{parentLogLevels:q,parentMessages:z,parentStringify:R}=e,F={disabled:e.disabled,logLevel:e.logLevel,logLevels:e.logLevels,messages:e.messages,processors:[],rawReporter:e.rawReporter,reporters:[],scope:e.scope,throttle:e.throttle,throttleMin:e.throttleMin},Y="types"in e;A&&b&&!Y?(F.parentTypes=A,F.parentLongestLabel=b):Y&&e.types!==void 0&&(F.types=e.types),R&&(F.parentStringify=R),q&&!e.logLevels&&(F.parentLogLevels=q),z&&!e.messages&&(F.parentMessages=z),super(F),this.options=e,this.interactive=i??!1,this.stdout=d,this.stderr=c,this.interactive&&(this.interactiveManager=new We(new Me(this.stdout),new Me(this.stderr))),Array.isArray(n)&&this.registerReporters(n),this.rawReporter=this.extendReporter(u??new Ht),Array.isArray(a)&&this.registerProcessors(a)}options;static{Ut(this,"PailServerImpl")}stdout;stderr;interactiveManager;interactive;scope(...e){if(e.length===0)throw new Error("No scope name was defined.");return this.scopeName=e.flat(),this}child(e){const r=e?.types!==void 0,s=r?be(this.types,e.types):this.types,i=e?.reporters??[],a=i.length>0?[...this.reporters,...i]:[...this.reporters],u=e?.processors??[],n=u.length>0?[...this.processors,...u]:[...this.processors],g=e?.logLevels?{...this.logLevels,...e.logLevels}:this.logLevels;let y;if(e?.scope){const b=me(e.scope).filter(Boolean);y=this.scopeName.length>0?[...this.scopeName,...b]:b}else y=this.scopeName.length>0?this.scopeName:[];const c=e?.messages?{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage,...e.messages}:{timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage},d={disabled:e?.disabled??this.disabled,interactive:e?.interactive??this.interactive,logLevel:e?.logLevel??this.generalLogLevel,logLevels:g,messages:c,processors:n,rawReporter:e?.rawReporter??this.rawReporter,reporters:a,scope:y,stderr:e?.stderr??this.stderr,stdout:e?.stdout??this.stdout,throttle:e?.throttle??this.throttle,throttleMin:e?.throttleMin??this.throttleMin};return this.#r(d,e,r,s),new Le(d)}#r(e,r,s,i){s?(e.parentTypes=i,e.parentLongestLabel=le(i)):(e.parentTypes=this.types,e.parentLongestLabel=this.longestLabel),r?.logLevels||(e.parentLogLevels=this.logLevels),r?.messages||(e.parentMessages={timerEnd:this.endTimerMessage,timerStart:this.startTimerMessage}),e.parentStringify=this.stringify,r?.stdout||(e.parentStdout=this.stdout),r?.stderr||(e.parentStderr=this.stderr)}getInteractiveManager(){return this.interactiveManager}wrapStd(){this.#e(this.stdout,"log"),this.#e(this.stderr,"log")}restoreStd(){this.#t(this.stdout),this.#t(this.stderr)}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}clear(){this.stdout.write(Oe),this.stderr.write(Oe)}extendReporter(e){return typeof e.setStdout=="function"&&e.setStdout(this.stdout),typeof e.setStderr=="function"&&e.setStderr(this.stderr),typeof e.setLoggerTypes=="function"&&e.setLoggerTypes(this.types),typeof e.setStringify=="function"&&e.setStringify(this.stringify),typeof e.setIsInteractive=="function"&&e.setIsInteractive(this.interactive),this.interactive&&typeof e.setInteractiveManager=="function"&&e.setInteractiveManager(this.interactiveManager),e}#e(e,r){e&&(e.__write||(e.__write=e.write),e.write=s=>{this[r](String(s).trim())})}#t(e){e&&e.__write&&(e.write=e.__write,delete e.__write)}}const Yt=Le;var Qt=Object.defineProperty,Kt=p((t,e)=>Qt(t,"name",{value:e,configurable:!0}),"x"),Xt=Object.defineProperty,Fe=Kt((t,e)=>Xt(t,"name",{value:e,configurable:!0}),"h"),Zt=Object.defineProperty,ie=Fe((t,e)=>Zt(t,"name",{value:e,configurable:!0}),"g$1");const Ee=new Map([["aliceblue","#f0f8ff"],["antiquewhite","#faebd7"],["aqua","#00ffff"],["aquamarine","#7fffd4"],["azure","#f0ffff"],["beige","#f5f5dc"],["bisque","#ffe4c4"],["black","#000000"],["blanchedalmond","#ffebcd"],["blue","#0000ff"],["blueviolet","#8a2be2"],["brown","#a52a2a"],["burlywood","#deb887"],["cadetblue","#5f9ea0"],["chartreuse","#7fff00"],["chocolate","#d2691e"],["coral","#ff7f50"],["cornflowerblue","#6495ed"],["cornsilk","#fff8dc"],["crimson","#dc143c"],["cyan","#00ffff"],["darkblue","#00008b"],["darkcyan","#008b8b"],["darkgoldenrod","#b8860b"],["darkgray","#a9a9a9"],["darkgreen","#006400"],["darkgrey","#a9a9a9"],["darkkhaki","#bdb76b"],["darkmagenta","#8b008b"],["darkolivegreen","#556b2f"],["darkorange","#ff8c00"],["darkorchid","#9932cc"],["darkred","#8b0000"],["darksalmon","#e9967a"],["darkseagreen","#8fbc8f"],["darkslateblue","#483d8b"],["darkslategray","#2f4f4f"],["darkslategrey","#2f4f4f"],["darkturquoise","#00ced1"],["darkviolet","#9400d3"],["deeppink","#ff1493"],["deepskyblue","#00bfff"],["dimgray","#696969"],["dimgrey","#696969"],["dodgerblue","#1e90ff"],["firebrick","#b22222"],["floralwhite","#fffaf0"],["forestgreen","#228b22"],["fuchsia","#ff00ff"],["gainsboro","#dcdcdc"],["ghostwhite","#f8f8ff"],["gold","#ffd700"],["goldenrod","#daa520"],["gray","#808080"],["green","#008000"],["greenyellow","#adff2f"],["grey","#808080"],["honeydew","#f0fff0"],["hotpink","#ff69b4"],["indianred","#cd5c5c"],["indigo","#4b0082"],["ivory","#fffff0"],["khaki","#f0e68c"],["lavender","#e6e6fa"],["lavenderblush","#fff0f5"],["lawngreen","#7cfc00"],["lemonchiffon","#fffacd"],["lightblue","#add8e6"],["lightcoral","#f08080"],["lightcyan","#e0ffff"],["lightgoldenrodyellow","#fafad2"],["lightgray","#d3d3d3"],["lightgreen","#90ee90"],["lightgrey","#d3d3d3"],["lightpink","#ffb6c1"],["lightsalmon","#ffa07a"],["lightseagreen","#20b2aa"],["lightskyblue","#87cefa"],["lightslategray","#778899"],["lightslategrey","#778899"],["lightsteelblue","#b0c4de"],["lightyellow","#ffffe0"],["lime","#00ff00"],["limegreen","#32cd32"],["linen","#faf0e6"],["magenta","#ff00ff"],["maroon","#800000"],["mediumaquamarine","#66cdaa"],["mediumblue","#0000cd"],["mediumorchid","#ba55d3"],["mediumpurple","#9370db"],["mediumseagreen","#3cb371"],["mediumslateblue","#7b68ee"],["mediumspringgreen","#00fa9a"],["mediumturquoise","#48d1cc"],["mediumvioletred","#c71585"],["midnightblue","#191970"],["mintcream","#f5fffa"],["mistyrose","#ffe4e1"],["moccasin","#ffe4b5"],["navajowhite","#ffdead"],["navy","#000080"],["oldlace","#fdf5e6"],["olive","#808000"],["olivedrab","#6b8e23"],["orange","#ffa500"],["orangered","#ff4500"],["orchid","#da70d6"],["palegoldenrod","#eee8aa"],["palegreen","#98fb98"],["paleturquoise","#afeeee"],["palevioletred","#db7093"],["papayawhip","#ffefd5"],["peachpuff","#ffdab9"],["peru","#cd853f"],["pink","#ffc0cb"],["plum","#dda0dd"],["powderblue","#b0e0e6"],["purple","#800080"],["rebeccapurple","#663399"],["red","#ff0000"],["rosybrown","#bc8f8f"],["royalblue","#4169e1"],["saddlebrown","#8b4513"],["salmon","#fa8072"],["sandybrown","#f4a460"],["seagreen","#2e8b57"],["seashell","#fff5ee"],["sienna","#a0522d"],["silver","#c0c0c0"],["skyblue","#87ceeb"],["slateblue","#6a5acd"],["slategray","#708090"],["slategrey","#708090"],["snow","#fffafa"],["springgreen","#00ff7f"],["steelblue","#4682b4"],["tan","#d2b48c"],["teal","#008080"],["thistle","#d8bfd8"],["tomato","#ff6347"],["turquoise","#40e0d0"],["violet","#ee82ee"],["wheat","#f5deb3"],["white","#ffffff"],["whitesmoke","#f5f5f5"],["yellow","#ffff00"],["yellowgreen","#9acd32"]]),er=/^#([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})([\dA-F]{2})?$/i,tr=/^#([\dA-F])([\dA-F])([\dA-F])([\dA-F])?$/i,rr=/^rgba?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,sr=/^hsla?\(\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))%\s*(,\s*([+-]?(?:\d+(?:\.\d+)?|\.\d+))\s*)?\)$/,qe=ie(()=>({__proto__:null,backgroundColor:null,color:null,fontStyle:null,fontWeight:null,textDecorationColor:null,textDecorationLine:[]}),"getDefaultCss"),Ae=/\s+/,fe=ie(t=>{Ee.has(t)&&(t=Ee.get(t));const e=er.exec(t);if(e)return[Number.parseInt(e[1],16),Number.parseInt(e[2],16),Number.parseInt(e[3],16)];const r=tr.exec(t);if(r)return[Number.parseInt(`${r[1]}${r[1]}`,16),Number.parseInt(`${r[2]}${r[2]}`,16),Number.parseInt(`${r[3]}${r[3]}`,16)];const s=rr.exec(t);if(s)return[Math.round(Math.max(0,Math.min(255,Number(s[1])))),Math.round(Math.max(0,Math.min(255,Number(s[2])))),Math.round(Math.max(0,Math.min(255,Number(s[3]))))];const i=sr.exec(t);if(i){let a=Number(i[1])%360;a<0&&(a+=360);const u=Math.max(0,Math.min(100,Number(i[2])))/100,n=Math.max(0,Math.min(100,Number(i[3])))/100,g=(1-Math.abs(2*n-1))*u,y=g*(1-Math.abs(a/60%2-1)),c=n-g/2;let d,b,A;return a<60?{0:d,1:b,2:A}=[g,y,0]:a<120?{0:d,1:b,2:A}=[y,g,0]:a<180?{0:d,1:b,2:A}=[0,g,y]:a<240?{0:d,1:b,2:A}=[0,y,g]:a<300?{0:d,1:b,2:A}=[y,0,g]:{0:d,1:b,2:A}=[g,0,y],[Math.round((d+c)*255),Math.round((b+c)*255),Math.round((A+c)*255)]}return null},"parseCssColor"),he=ie((t,e)=>t?.[0]===e?.[0]&&t?.[1]===e?.[1]&&t?.[2]===e?.[2],"colorEquals"),ir=ie(t=>{const e=qe(),r=[];let s=!1,i=null,a=0,u="";for(const n of t){if(n==="(")a+=1;else if(a>0)n===")"&&(a-=1);else if(s){if(n===";"){const g=u.trim();g!==""&&r.push([i,g]),i=null,u="",s=!1;continue}}else if(n===":"){i=u.trim(),u="",s=!0;continue}u+=n}if(s&&a===0){const n=u.trim();n!==""&&r.push([i,n]),i=null,u=""}for(const{0:n,1:g}of r)switch(n){case"background-color":{g!=null&&(e.backgroundColor=g);break}case"color":{g!=null&&(e.color=g);break}case"font-style":{["italic","oblique","oblique 14deg"].includes(g)&&(e.fontStyle="italic");break}case"font-weight":{g==="bold"&&(e.fontWeight=g);break}case"text-decoration":{e.textDecorationColor=null,e.textDecorationLine=[];const y=g.split(Ae);for(const c of y){const d=fe(c);d!=null?e.textDecorationColor=d:["line-through","overline","underline"].includes(c)&&e.textDecorationLine.push(c)}break}case"text-decoration-color":{const y=fe(g);y!=null&&(e.textDecorationColor=y);break}case"text-decoration-line":{e.textDecorationLine=[];const y=g.split(Ae);for(const c of y)["line-through","overline","underline"].includes(c)&&e.textDecorationLine.push(c);break}}return e},"parseCss"),or=ie((t,e)=>{e=e??qe();let r="";if(!he(t.backgroundColor,e.backgroundColor))if(t.backgroundColor==null)r+="\x1B[49m";else switch(t.backgroundColor){case"black":{r+="\x1B[40m";break}case"blue":{r+="\x1B[44m";break}case"cyan":{r+="\x1B[46m";break}case"green":{r+="\x1B[42m";break}case"magenta":{r+="\x1B[45m";break}case"red":{r+="\x1B[41m";break}case"white":{r+="\x1B[47m";break}case"yellow":{r+="\x1B[43m";break}default:if(Array.isArray(t.backgroundColor)){const{0:s,1:i,2:a}=t.backgroundColor;r+=`\x1B[48;2;${String(s)};${String(i)};${String(a)}m`}else{const s=fe(t.backgroundColor);if(s===null)r+="\x1B[49m";else{const{0:i,1:a,2:u}=s;r+=`\x1B[48;2;${String(i)};${String(a)};${String(u)}m`}}}if(!he(t.color,e.color))if(t.color==null)r+="\x1B[39m";else switch(t.color){case"black":{r+="\x1B[30m";break}case"blue":{r+="\x1B[34m";break}case"cyan":{r+="\x1B[36m";break}case"green":{r+="\x1B[32m";break}case"magenta":{r+="\x1B[35m";break}case"red":{r+="\x1B[31m";break}case"white":{r+="\x1B[37m";break}case"yellow":{r+="\x1B[33m";break}default:if(Array.isArray(t.color)){const{0:s,1:i,2:a}=t.color;r+=`\x1B[38;2;${String(s)};${String(i)};${String(a)}m`}else{const s=fe(t.color);if(s===null)r+="\x1B[39m";else{const{0:i,1:a,2:u}=s;r+=`\x1B[38;2;${String(i)};${String(a)};${String(u)}m`}}}if(t.fontWeight!==e.fontWeight&&(r+=t.fontWeight==="bold"?"\x1B[1m":"\x1B[22m"),t.fontStyle!==e.fontStyle&&(r+=t.fontStyle==="italic"?"\x1B[3m":"\x1B[23m"),!he(t.textDecorationColor,e.textDecorationColor))if(t.textDecorationColor==null)r+="\x1B[59m";else{const{0:s,1:i,2:a}=t.textDecorationColor;r+=`\x1B[58;2;${String(s)};${String(i)};${String(a)}m`}return t.textDecorationLine.includes("line-through")!==e.textDecorationLine.includes("line-through")&&(r+=t.textDecorationLine.includes("line-through")?"\x1B[9m":"\x1B[29m"),t.textDecorationLine.includes("overline")!==e.textDecorationLine.includes("overline")&&(r+=t.textDecorationLine.includes("overline")?"\x1B[53m":"\x1B[55m"),t.textDecorationLine.includes("underline")!==e.textDecorationLine.includes("underline")&&(r+=t.textDecorationLine.includes("underline")?"\x1B[4m":"\x1B[24m"),r},"cssToAnsi");var nr=Object.defineProperty,Te=Fe((t,e)=>nr(t,"name",{value:e,configurable:!0}),"y");const ar=Te(t=>{try{return JSON.stringify(t)}catch{return'"[Circular]"'}},"tryStringify"),Pe="%".codePointAt(0),lr="s".codePointAt(0),cr="d".codePointAt(0),fr="f".codePointAt(0),ur="i".codePointAt(0),gr="O".codePointAt(0),hr="o".codePointAt(0),dr="j".codePointAt(0),pr="c".codePointAt(0),mr=Te((t,e=[],r={})=>{if(typeof t!="string"&&typeof t!="object"||t===null)throw new TypeError(`fmt must be a string or object, got ${t===null?"null":typeof t}`);const s=r.stringify??ar,i=1;if(typeof t=="object"){const c=e.length+i;if(c===1)return"{}";const d=Array.from({length:c});d[0]=s(t);for(let b=1;b<c;b+=1)d[b]=s(e[b-i]);return d.join(" ")}if(e.length===0)return t;let a="",u=1-i,n=-1,g=!1,y;for(let c=0;c<t.length;){if(t.codePointAt(c)===Pe&&c+1<t.length){n=n>-1?n:0;const d=t.codePointAt(c+1);if(d===void 0){u+=1;break}switch(d){case pr:{if(globalThis.window===void 0){const b=ir(e[u]);n<c&&(a+=t.slice(n,c)),a+=or(b,y),a!==""&&(g=!0,y=b)}n=c+2,c+=1;break}case cr:case fr:{if(u>=e.length||e[u]==null)break;n<c&&(a+=t.slice(n,c)),a+=Number(e[u]).toString(),n=c+2,c+=1;break}case ur:{if(u>=e.length||e[u]==null)break;n<c&&(a+=t.slice(n,c)),a+=Math.floor(Number(e[u])).toString(),n=c+2,c+=1;break}case dr:case gr:case hr:{if(u>=e.length||e[u]===void 0)break;n<c&&(a+=t.slice(n,c));const b=e[u],A=typeof b;if(A==="string"){a+=`'${b}'`,n=c+2;break}if(A==="function"){a+=b.name?`[Function: ${b.name}]`:"[Function: <anonymous>]",n=c+2;break}a+=s(b),n=c+2,c+=1;break}case Pe:{n<c&&(a+=t.slice(n,c)),a+="%",n=c+2,c+=1,u-=1;break}case lr:{if(u>=e.length)break;n<c&&(a+=t.slice(n,c)),a+=typeof e[u]=="object"?s(e[u]):String(e[u]),n=c+2,c+=1;break}default:typeof r.formatters?.[d]=="function"&&(n<c&&(a+=t.slice(n,c)),a+=r.formatters[d](e[u]),n=c+2,c+=1)}u+=1}c+=1}return n===-1?t:(n<t.length&&(a+=t.slice(n)),g&&(a+="\x1B[0m"),a)},"format"),br=Te((t={})=>{const e={};return typeof t.formatters=="object"&&Object.entries(t.formatters).forEach(([r,s])=>{if(r.length===0)throw new Error(`Formatter %${r} has no characters`);if(r.length>1)throw new Error(`Formatter %${r} has more than one character`);if(typeof s!="function")throw new TypeError(`Formatter for %${r} is not a function`);const i=r.codePointAt(0);if(i===void 0)throw new Error(`${r}.codePointAt(0) failed to return a value, please report this issue`);e[i]=s}),(r,s=[],i={})=>mr(r,s,{...i,formatters:e})},"build");var yr=Object.defineProperty,Be=p((t,e)=>yr(t,"name",{value:e,configurable:!0}),"i$1");let $r=class{static{p(this,"g")}static{Be(this,"MessageFormatterProcessor")}#r;#e;constructor(e={}){this.#e=e.formatters}setStringify(e){this.#r=e}process(e){const r=br({formatters:this.#e,stringify:Be(s=>this.#r?this.#r(s):JSON.stringify(s),"stringify")});return e.message!==void 0&&(e.message=this.#t(r,e.message,e.context??[])),e}#t(e,r,s=[]){if(typeof r=="string")return e(r,s);if(typeof r=="object"&&r!==null){const i=r,a=Object.keys(i);for(let u=0;u<a.length;u+=1){const n=a[u],g=i[n];(typeof g=="string"||Array.isArray(g)||typeof g=="object")&&(i[n]=this.#t(e,g,s))}}return r}};var vr=Object.defineProperty,Je=p((t,e)=>vr(t,"name",{value:e,configurable:!0}),"M");const{bgGrey:Sr,cyan:wr,green:xr,greenBright:Lr,grey:G,red:de,underline:Ne,white:Tr}=De,kr=/[\\/]pail[\\/]dist/,pe=Je(t=>!kr.test(t),"pailFileFilter");class Mr extends Qe{static{p(this,"PrettyReporter")}static{Je(this,"PrettyReporter")}#r;#e;#t;#s=!1;#i;#o;constructor(e={}){const{error:r,inspect:s,...i}=e;super({uppercase:{label:!0,...i.uppercase},...i}),this.#i={...Ke,...s},this.#o={...r,color:{fileLine:xr,hint:wr,marker:de,message:de,method:Lr,title:de}},this.#r=$e,this.#e=ve}setStdout(e){this.#r=e}setStderr(e){this.#e=e}setInteractiveManager(e){this.#t=e}setIsInteractive(e){this.#s=e}log(e){this._log(this._formatMessage(e),e.type.level)}_formatMessage(e){const{columns:r}=Xe();let s=r;typeof this.styles.messageLength=="number"&&(s=this.styles.messageLength);const{badge:i,context:a,date:u,error:n,file:g,groups:y,label:c,message:d,prefix:b,repeated:A,scope:q,suffix:z,traceError:R,type:F}=e,{color:Y}=this.loggerTypes[F.name],Q=Y?De[Y]:Tr,f=y.map(()=>" ").join(""),l=[];if(y.length>0&&l.push(`${f+G(`[${y.at(-1)??""}]`)} `),u&&l.push(`${G(this.styles.dateFormatter(typeof u=="string"?new Date(u):u))} `),i)l.push(Q(i));else{const T=Ze(this.loggerTypes);T.length>0&&l.push(`${G(".".repeat(T.length))} `)}const $=le(this.loggerTypes);if(c){const T=ne($),P=ne(c);l.push(`${Q(et(c,this.styles))} `,G(".".repeat(Math.max(0,T-P))))}else l.push(G(".".repeat($.length+2)));A&&l.push(`${Sr.white(`[${String(A)}x]`)} `),Array.isArray(q)&&q.length>0&&l.push(` ${G(`[${q.join(" > ")}]`)} `),b&&l.push(`${G(`${Array.isArray(q)&&q.length>0?". ":" "}[${this.styles.underline.prefix?Ne(b):b}]`)} `);const N=ne(l.join(" "));if(g){const T=(g.name??"")+(g.line?`:${String(g.line)}`:""),P=ne(T);if(P+N+2>s)l.push(G(` ${T}`));else{const J=Math.max(0,s-N-P-2);l.push(G(`${".".repeat(J)} ${T}`))}}else l.push(G(".".repeat(Math.max(0,s-N-1))));if(l.length>0&&l.push(`
21
+
22
+ `),d!==Se){const T=typeof d=="string"?d:ce(d,this.#i);l.push(f+tt(T,{trim:!1,width:s-3,wrapMode:rt.STRICT_WIDTH}))}if(a){let T=!1;l.push(...a.map(P=>{if(P instanceof Error)return T=!0,`
23
+
24
+ ${ge(P,{...this.#o,filterStacktrace:pe,prefix:f})}`;if(typeof P=="object")return` ${ce(P,this.#i)}`;const J=(T?`
25
+
26
+ `:" ")+String(P);return T=!1,J}))}return n&&l.push(ge(n,{...this.#o,filterStacktrace:pe,prefix:f})),R&&l.push(`
27
+
28
+ ${ge(R,{...this.#o,filterStacktrace:pe,hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0,hideMessage:!0,prefix:f})}`),z&&l.push(`
29
+ `,f+G(this.styles.underline.suffix?Ne(z):z)),l.join("")}_log(e,r){const s=["error","trace","warn"].includes(r)?"stderr":"stdout",i=s==="stderr"?this.#e:this.#r;this.#s&&this.#t!==void 0&&i.isTTY?this.#t.update(s,e.split(`
30
+ `),0):_e(`${e}
31
+ `,i)}}var Or=Object.defineProperty,Ve=p((t,e)=>Or(t,"name",{value:e,configurable:!0}),"o");const jr=Ve(()=>se.NODE_ENV==="debug"||se.DEBUG!==void 0?"debug":se.NODE_ENV==="test"?"warning":"informational","getDefaultLogLevel"),Er=Ve(t=>{let e=jr();return se.PAIL_LOG_LEVEL!==void 0&&(e=se.PAIL_LOG_LEVEL),new Yt({logLevel:e,processors:[new $r],reporters:[new Mr],stderr:ve,stdout:$e,...t})},"createPail"),Fr=Er();export{Vr as PailError,Er as createPail,Gr as createPailError,Fr as pail};