@visulima/pail 3.1.0 → 3.2.0

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 (76) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/LICENSE.md +1 -408
  3. package/README.md +298 -0
  4. package/dist/index.browser.d.ts +3 -3
  5. package/dist/index.browser.js +12 -1
  6. package/dist/index.server.d.ts +8 -5
  7. package/dist/index.server.js +535 -2
  8. package/dist/interactive/index.js +2 -1
  9. package/dist/object-tree.js +89 -2
  10. package/dist/packem_shared/AbstractJsonReporter-intFdT_A.js +204 -0
  11. package/dist/packem_shared/InteractiveManager-CZ85hGNW.js +172 -0
  12. package/dist/packem_shared/InteractiveStreamHook-DiSubbJ1.js +21 -0
  13. package/dist/packem_shared/JsonReporter-BqWsVkHP.js +60 -0
  14. package/dist/packem_shared/JsonReporter-DcM2LBX9.js +28 -0
  15. package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +222 -0
  16. package/dist/packem_shared/PrettyReporter-CuLLKr6-.js +169 -0
  17. package/dist/packem_shared/{abstract-json-reporter-CPsNkpz8.d.ts → abstract-json-reporter-DiyVyU0j.d.ts} +1 -1
  18. package/dist/packem_shared/{abstract-pretty-reporter-DB2G-qlI.d.ts → abstract-pretty-reporter-BbOWXMCs.d.ts} +1 -1
  19. package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +50 -0
  20. package/dist/packem_shared/constants-DfDr4MHC.js +119 -0
  21. package/dist/packem_shared/format-label-Btft2KGP.js +1194 -0
  22. package/dist/packem_shared/get-longest-label-C9PWeyKq.js +9 -0
  23. package/dist/packem_shared/index-BomQ3E6J.js +650 -0
  24. package/dist/packem_shared/index-DqKWykfa.js +1146 -0
  25. package/dist/packem_shared/interactive-stream-hook-DG4BtN12.js +141 -0
  26. package/dist/packem_shared/{pail.browser-CmWcqnn9.d.ts → pail.browser-By9KjOH7.d.ts} +8 -3
  27. package/dist/packem_shared/pail.browser-CPDOE_d1.js +1427 -0
  28. package/dist/packem_shared/{types-DVzG8TWL.d.ts → types-D3ycu8-x.d.ts} +1 -1
  29. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +14 -0
  30. package/dist/packem_shared/write-stream-BG8fhcs3.js +6 -0
  31. package/dist/processor/caller/caller-processor.d.ts +1 -1
  32. package/dist/processor/caller/caller-processor.js +59 -1
  33. package/dist/processor/message-formatter-processor.d.ts +1 -1
  34. package/dist/processor/message-formatter-processor.js +67 -1
  35. package/dist/processor/opentelemetry-processor.d.ts +19 -0
  36. package/dist/processor/opentelemetry-processor.js +52 -0
  37. package/dist/processor/redact-processor.d.ts +1 -1
  38. package/dist/processor/redact-processor.js +30 -1
  39. package/dist/progress-bar.js +404 -1
  40. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  41. package/dist/reporter/file/json-file-reporter.js +136 -4
  42. package/dist/reporter/http/abstract-http-reporter.d.ts +102 -0
  43. package/dist/reporter/http/abstract-http-reporter.js +435 -0
  44. package/dist/reporter/http/http-reporter.d.ts +13 -0
  45. package/dist/reporter/http/http-reporter.edge-light.d.ts +168 -0
  46. package/dist/reporter/http/http-reporter.edge-light.js +651 -0
  47. package/dist/reporter/http/http-reporter.js +13 -0
  48. package/dist/reporter/json/index.browser.d.ts +2 -2
  49. package/dist/reporter/json/index.browser.js +2 -1
  50. package/dist/reporter/json/index.d.ts +2 -2
  51. package/dist/reporter/json/index.js +2 -1
  52. package/dist/reporter/pretty/index.browser.d.ts +2 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +2 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +2 -2
  57. package/dist/reporter/simple/simple-reporter.server.js +186 -8
  58. package/dist/spinner.js +2150 -1
  59. package/package.json +53 -3
  60. package/dist/packem_shared/AbstractJsonReporter-UftN6CIL.js +0 -1
  61. package/dist/packem_shared/InteractiveManager-CgmJyW9x.js +0 -3
  62. package/dist/packem_shared/InteractiveStreamHook-NtJu71aN.js +0 -1
  63. package/dist/packem_shared/JsonReporter-DTBtHNaD.js +0 -2
  64. package/dist/packem_shared/JsonReporter-Dl4m0xZe.js +0 -1
  65. package/dist/packem_shared/PrettyReporter-Bns0ZWLy.js +0 -12
  66. package/dist/packem_shared/PrettyReporter-CGKSTI7X.js +0 -5
  67. package/dist/packem_shared/abstract-pretty-reporter-CUtSm20r.js +0 -1
  68. package/dist/packem_shared/constants-DKfCaSUR.js +0 -1
  69. package/dist/packem_shared/format-label-CpyyTBom.js +0 -26
  70. package/dist/packem_shared/get-longest-label-B0NrI-o2.js +0 -1
  71. package/dist/packem_shared/index-CysYvHXs.js +0 -8
  72. package/dist/packem_shared/index-D9hWq9ka.js +0 -1
  73. package/dist/packem_shared/interactive-stream-hook-CeVo4Kth.js +0 -2
  74. package/dist/packem_shared/pail.browser-BmHoDvEA.js +0 -19
  75. package/dist/packem_shared/write-console-log-based-on-level-BP95fgQZ.js +0 -1
  76. package/dist/packem_shared/write-stream-CD8XFv1L.js +0 -1
@@ -1,2 +1,535 @@
1
- var y=Object.defineProperty;var n=(e,t)=>y(e,"name",{value:t,configurable:!0});import{createRequire as M}from"node:module";import S from"./packem_shared/InteractiveManager-CgmJyW9x.js";import{t as d,c as g}from"./packem_shared/interactive-stream-hook-CeVo4Kth.js";import{a as b}from"./packem_shared/pail.browser-BmHoDvEA.js";import{applyStyleToOptions as v,ProgressBar as I,MultiProgressBar as E}from"./progress-bar.js";import{getBarChar as nt}from"./progress-bar.js";import{a as f}from"./packem_shared/format-label-CpyyTBom.js";import{E as L}from"./packem_shared/constants-DKfCaSUR.js";import{n as R}from"./packem_shared/write-stream-CD8XFv1L.js";import{Spinner as j,MultiSpinner as T}from"./spinner.js";import O from"./processor/message-formatter-processor.js";import{PrettyReporter as B}from"./packem_shared/PrettyReporter-Bns0ZWLy.js";const z=M(import.meta.url),P=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{stdout:w,stderr:m,env:o}=P;var C=Object.defineProperty,x=n((e,t)=>C(e,"name",{value:t,configurable:!0}),"c");class A{static{n(this,"v")}static{x(this,"RawReporter")}#t;#e;#r;#s=!1;#i;constructor(t={}){this.#t=w,this.#e=m,this.#i=t}setStdout(t){this.#t=t}setStderr(t){this.#e=t}setInteractiveManager(t){this.#r=t}setIsInteractive(t){this.#s=t}log(t){const{context:r,groups:c,message:i,type:h}=t,s=[];if(i!==L){const a=typeof i=="string"?i:f(i,this.#i);s.push(a)}r&&s.push(...r.map(a=>typeof a=="object"?` ${f(a,this.#i)}`:` ${a}`));const p=["error","trace","warn"].includes(h.level)?"stderr":"stdout",u=p==="stderr"?this.#e:this.#t,l=c.map(()=>" ").join("");this.#s&&this.#r!==void 0&&u.isTTY?this.#r.update(p,(l+s.join("")).split(`
2
- `),0):R(l+s.join(""),u)}}var N=Object.defineProperty,$=n((e,t)=>N(e,"name",{value:t,configurable:!0}),"a");class D extends b{static{n(this,"m")}constructor(t){const{interactive:r,rawReporter:c,reporters:i,stderr:h,stdout:s,...p}=t;super(p),this.options=t,this.interactive=r??!1,this.stdout=s,this.stderr=h,this.interactive&&(this.interactiveManager=new S(new d(this.stdout),new d(this.stderr))),Array.isArray(i)&&this.registerReporters(i),this.rawReporter=this.extendReporter(t.rawReporter??new A)}static{$(this,"PailServerImpl")}stdout;stderr;interactiveManager;interactive;scope(...t){if(t.length===0)throw new Error("No scope name was defined.");return this.scopeName=t.flat(),this}getInteractiveManager(){return this.interactiveManager}wrapStd(){this.#t(this.stdout,"log"),this.#t(this.stderr,"log")}restoreStd(){this.#e(this.stdout),this.#e(this.stderr)}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}createProgressBar(t){if(!this.interactiveManager)throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");const r=v(t);return new I(r,this.interactiveManager)}createMultiProgressBar(t={}){if(!this.interactiveManager)throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");const r=v(t);return new E(r,this.interactiveManager)}createSpinner(t={}){if(!this.interactiveManager)throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");return new j(t,this.interactiveManager)}createMultiSpinner(t={}){if(!this.interactiveManager)throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");return new T(t,this.interactiveManager)}clear(){this.stdout.write(g),this.stderr.write(g)}extendReporter(t){return typeof t.setStdout=="function"&&t.setStdout(this.stdout),typeof t.setStderr=="function"&&t.setStderr(this.stderr),typeof t.setLoggerTypes=="function"&&t.setLoggerTypes(this.types),typeof t.setStringify=="function"&&t.setStringify(this.stringify),typeof t.setIsInteractive=="function"&&t.setIsInteractive(this.interactive),this.interactive&&typeof t.setInteractiveManager=="function"&&t.setInteractiveManager(this.interactiveManager),t}#t(t,r){t&&(t.__write||(t.__write=t.write),t.write=c=>{this[r](String(c).trim())})}#e(t){t&&t.__write&&(t.write=t.__write,delete t.__write)}}const V=D;var q=Object.defineProperty,_=n((e,t)=>q(e,"name",{value:t,configurable:!0}),"o");const G=_(()=>o.NODE_ENV==="debug"||o.DEBUG!==void 0?"debug":o.NODE_ENV==="test"?"warning":"informational","getDefaultLogLevel"),Y=_(e=>{let t=G();return o.PAIL_LOG_LEVEL!==void 0&&(t=o.PAIL_LOG_LEVEL),new V({logLevel:t,processors:[new O],reporters:[new B],stderr:m,stdout:w,...e})},"createPail"),rt=Y();export{E as MultiProgressBar,T as MultiSpinner,I as ProgressBar,j as Spinner,Y as createPail,nt as getBarChar,rt as pail};
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 from './packem_shared/InteractiveManager-CZ85hGNW.js';
13
+ import { I as InteractiveStreamHook, c as clearTerminal } from './packem_shared/interactive-stream-hook-DG4BtN12.js';
14
+ import { a as PailBrowserImpl, m as mergeTypes, b as arrayify } from './packem_shared/pail.browser-CPDOE_d1.js';
15
+ import { ProgressBar, applyStyleToOptions, MultiProgressBar } from './progress-bar.js';
16
+ export { getBarChar } from './progress-bar.js';
17
+ import { i as inspect } from './packem_shared/format-label-Btft2KGP.js';
18
+ import { E as EMPTY_SYMBOL } from './packem_shared/constants-DfDr4MHC.js';
19
+ import { w as writeStream } from './packem_shared/write-stream-BG8fhcs3.js';
20
+ import { Spinner, MultiSpinner } from './spinner.js';
21
+ import { g as getLongestLabel } from './packem_shared/get-longest-label-C9PWeyKq.js';
22
+ import MessageFormatterProcessor from './processor/message-formatter-processor.js';
23
+ import { PrettyReporter } from './packem_shared/PrettyReporter-BFWaYP_J.js';
24
+
25
+ class RawReporter {
26
+ #stdout;
27
+ #stderr;
28
+ #interactiveManager;
29
+ #interactive = false;
30
+ #inspectOptions;
31
+ constructor(inspectOptions = {}) {
32
+ this.#stdout = stdout;
33
+ this.#stderr = stderr;
34
+ this.#inspectOptions = inspectOptions;
35
+ }
36
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
37
+ setStdout(stdout_) {
38
+ this.#stdout = stdout_;
39
+ }
40
+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
41
+ setStderr(stderr_) {
42
+ this.#stderr = stderr_;
43
+ }
44
+ setInteractiveManager(manager) {
45
+ this.#interactiveManager = manager;
46
+ }
47
+ setIsInteractive(interactive) {
48
+ this.#interactive = interactive;
49
+ }
50
+ log(meta) {
51
+ const { context, groups, message, type } = meta;
52
+ const items = [];
53
+ if (message !== EMPTY_SYMBOL) {
54
+ const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
55
+ items.push(formattedMessage);
56
+ }
57
+ if (context) {
58
+ items.push(
59
+ ...context.map((value) => {
60
+ if (typeof value === "object") {
61
+ return ` ${inspect(value, this.#inspectOptions)}`;
62
+ }
63
+ return ` ${value}`;
64
+ })
65
+ );
66
+ }
67
+ const streamType = ["error", "trace", "warn"].includes(type.level) ? "stderr" : "stdout";
68
+ const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
69
+ const groupSpaces = groups.map(() => " ").join("");
70
+ if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
71
+ this.#interactiveManager.update(streamType, (groupSpaces + items.join("")).split("\n"), 0);
72
+ } else {
73
+ writeStream(groupSpaces + items.join(""), stream);
74
+ }
75
+ }
76
+ }
77
+
78
+ class PailServerImpl extends PailBrowserImpl {
79
+ /**
80
+ * Creates a new Pail server logger instance.
81
+ *
82
+ * Initializes the server-compatible logger with streams, interactive support,
83
+ * and server-specific configuration options.
84
+ * @param options Server-specific configuration options
85
+ */
86
+ constructor(options) {
87
+ const parentStderr = options.parentStderr;
88
+ const parentStdout = options.parentStdout;
89
+ const { interactive, processors, rawReporter, reporters, stderr: optionsStderr, stdout: optionsStdout } = options;
90
+ const stderr = parentStderr ?? optionsStderr;
91
+ const stdout = parentStdout ?? optionsStdout;
92
+ const parentLongestLabel = options.parentLongestLabel;
93
+ const parentTypes = options.parentTypes;
94
+ const { parentLogLevels, parentMessages, parentStringify } = options;
95
+ const parentOptions = {
96
+ disabled: options.disabled,
97
+ logLevel: options.logLevel,
98
+ logLevels: options.logLevels,
99
+ messages: options.messages,
100
+ processors: [],
101
+ rawReporter: options.rawReporter,
102
+ reporters: [],
103
+ scope: options.scope,
104
+ throttle: options.throttle,
105
+ throttleMin: options.throttleMin
106
+ };
107
+ const hasTypesProperty = "types" in options;
108
+ if (parentTypes && parentLongestLabel && !hasTypesProperty) {
109
+ parentOptions.parentTypes = parentTypes;
110
+ parentOptions.parentLongestLabel = parentLongestLabel;
111
+ } else if (hasTypesProperty && options.types !== void 0) {
112
+ parentOptions.types = options.types;
113
+ }
114
+ if (parentStringify) {
115
+ parentOptions.parentStringify = parentStringify;
116
+ }
117
+ if (parentLogLevels && !options.logLevels) {
118
+ parentOptions.parentLogLevels = parentLogLevels;
119
+ }
120
+ if (parentMessages && !options.messages) {
121
+ parentOptions.parentMessages = parentMessages;
122
+ }
123
+ super(parentOptions);
124
+ this.options = options;
125
+ this.interactive = interactive ?? false;
126
+ this.stdout = stdout;
127
+ this.stderr = stderr;
128
+ if (this.interactive) {
129
+ this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));
130
+ }
131
+ if (Array.isArray(reporters)) {
132
+ this.registerReporters(reporters);
133
+ }
134
+ this.rawReporter = this.extendReporter(rawReporter ?? new RawReporter());
135
+ if (Array.isArray(processors)) {
136
+ this.registerProcessors(processors);
137
+ }
138
+ }
139
+ stdout;
140
+ stderr;
141
+ interactiveManager;
142
+ interactive;
143
+ // @ts-expect-error - this returns a different type
144
+ scope(...name) {
145
+ if (name.length === 0) {
146
+ throw new Error("No scope name was defined.");
147
+ }
148
+ this.scopeName = name.flat();
149
+ return this;
150
+ }
151
+ /**
152
+ * Creates a child logger that inherits settings from the parent.
153
+ *
154
+ * Returns a new logger instance that inherits all configuration from the parent
155
+ * (reporters, processors, types, log levels, throttle settings, etc.) while allowing
156
+ * you to override only what you need. Child loggers are independent instances with
157
+ * their own state (timers, counters, etc.).
158
+ * @template N - The new custom logger type names
159
+ * @template LC - The new log level types
160
+ * @param options Configuration options to override or extend parent settings
161
+ * @returns A new child logger instance
162
+ * @example
163
+ * ```typescript
164
+ * const parent = createPail({
165
+ * logLevel: "info",
166
+ * types: { http: { label: "HTTP", logLevel: "info" } },
167
+ * reporters: [new PrettyReporter()],
168
+ * });
169
+ *
170
+ * // Child inherits parent settings but overrides log level
171
+ * const child = parent.child({ logLevel: "debug" });
172
+ * child.info("This will be logged"); // Uses debug level from child
173
+ * child.http("GET /api 200"); // Inherits http type from parent
174
+ *
175
+ * // Child can add new types
176
+ * const childWithNewType = parent.child({
177
+ * types: { db: { label: "DB", logLevel: "info" } },
178
+ * });
179
+ * childWithNewType.db("Query executed"); // New type available
180
+ * ```
181
+ */
182
+ // @ts-expect-error - override signature differs due to server-specific options
183
+ child(options) {
184
+ const typesChanged = options?.types !== void 0 && options.types !== null;
185
+ const mergedTypes = typesChanged ? mergeTypes(this.types, options.types) : this.types;
186
+ const childReporters = options?.reporters ?? [];
187
+ const allReporters = childReporters.length > 0 ? [...this.reporters, ...childReporters] : [...this.reporters];
188
+ const childProcessors = options?.processors ?? [];
189
+ const allProcessors = childProcessors.length > 0 ? [...this.processors, ...childProcessors] : [...this.processors];
190
+ const mergedLogLevels = options?.logLevels ? { ...this.logLevels, ...options.logLevels } : this.logLevels;
191
+ let mergedScope;
192
+ if (options?.scope) {
193
+ const childScope = arrayify(options.scope).filter(Boolean);
194
+ mergedScope = this.scopeName.length > 0 ? [...this.scopeName, ...childScope] : childScope;
195
+ } else {
196
+ mergedScope = this.scopeName.length > 0 ? this.scopeName : [];
197
+ }
198
+ const mergedMessages = options?.messages ? {
199
+ timerEnd: this.endTimerMessage,
200
+ timerStart: this.startTimerMessage,
201
+ ...options.messages
202
+ } : {
203
+ timerEnd: this.endTimerMessage,
204
+ timerStart: this.startTimerMessage
205
+ };
206
+ const childOptions = {
207
+ disabled: options?.disabled ?? this.disabled,
208
+ interactive: options?.interactive ?? this.interactive,
209
+ logLevel: options?.logLevel ?? this.generalLogLevel,
210
+ logLevels: mergedLogLevels,
211
+ messages: mergedMessages,
212
+ processors: allProcessors,
213
+ rawReporter: options?.rawReporter ?? this.rawReporter,
214
+ reporters: allReporters,
215
+ scope: mergedScope,
216
+ stderr: options?.stderr ?? this.stderr,
217
+ stdout: options?.stdout ?? this.stdout,
218
+ throttle: options?.throttle ?? this.throttle,
219
+ throttleMin: options?.throttleMin ?? this.throttleMin
220
+ };
221
+ this.#assignParentValues(childOptions, options, typesChanged, mergedTypes);
222
+ return new PailServerImpl(childOptions);
223
+ }
224
+ /**
225
+ * Assigns parent values to child options for optimization.
226
+ *
227
+ * Reuses parent values when they haven't changed to avoid unnecessary recalculations.
228
+ */
229
+ /* eslint-disable no-param-reassign */
230
+ #assignParentValues(childOptions, options, typesChanged, mergedTypes) {
231
+ if (typesChanged) {
232
+ childOptions.parentTypes = mergedTypes;
233
+ childOptions.parentLongestLabel = getLongestLabel(mergedTypes);
234
+ } else {
235
+ childOptions.parentTypes = this.types;
236
+ childOptions.parentLongestLabel = this.longestLabel;
237
+ }
238
+ if (!options?.logLevels) {
239
+ childOptions.parentLogLevels = this.logLevels;
240
+ }
241
+ if (!options?.messages) {
242
+ childOptions.parentMessages = {
243
+ timerEnd: this.endTimerMessage,
244
+ timerStart: this.startTimerMessage
245
+ };
246
+ }
247
+ childOptions.parentStringify = this.stringify;
248
+ if (!options?.stdout) {
249
+ childOptions.parentStdout = this.stdout;
250
+ }
251
+ if (!options?.stderr) {
252
+ childOptions.parentStderr = this.stderr;
253
+ }
254
+ }
255
+ /* eslint-enable no-param-reassign */
256
+ /**
257
+ * Gets the interactive manager instance if interactive mode is enabled.
258
+ *
259
+ * Returns the InteractiveManager instance that handles interactive terminal
260
+ * features like progress bars and dynamic updates. Only available when
261
+ * interactive mode is enabled in the constructor options.
262
+ * @returns The interactive manager instance, or undefined if not in interactive mode
263
+ * @example
264
+ * ```typescript
265
+ * const logger = createPail({ interactive: true });
266
+ * const manager = logger.getInteractiveManager();
267
+ * if (manager) {
268
+ * manager.hook();
269
+ * // Use interactive features
270
+ * manager.unhook();
271
+ * }
272
+ * ```
273
+ */
274
+ getInteractiveManager() {
275
+ return this.interactiveManager;
276
+ }
277
+ /**
278
+ * Wraps stdout and stderr streams to redirect them through the logger.
279
+ *
280
+ * Intercepts writes to process.stdout and process.stderr, redirecting them
281
+ * through the logger instead of writing directly to the streams. This allows
282
+ * all output to be processed by the logging pipeline.
283
+ * @example
284
+ * ```typescript
285
+ * const logger = createPail();
286
+ * logger.wrapStd();
287
+ *
288
+ * console.log("This goes through logger");
289
+ * process.stdout.write("This too");
290
+ *
291
+ * logger.restoreStd(); // Restore original streams
292
+ * ```
293
+ */
294
+ wrapStd() {
295
+ this.#wrapStream(this.stdout, "log");
296
+ this.#wrapStream(this.stderr, "log");
297
+ }
298
+ /**
299
+ * Restores the original stdout and stderr streams.
300
+ *
301
+ * Removes the stream wrapping that was applied by wrapStd(),
302
+ * restoring the original stream write methods.
303
+ * @example
304
+ * ```typescript
305
+ * const logger = createPail();
306
+ * logger.wrapStd();
307
+ * // Streams are wrapped
308
+ * logger.restoreStd();
309
+ * // Streams are restored to original behavior
310
+ * ```
311
+ */
312
+ restoreStd() {
313
+ this.#restoreStream(this.stdout);
314
+ this.#restoreStream(this.stderr);
315
+ }
316
+ /**
317
+ * Wraps all output sources (console and streams).
318
+ *
319
+ * Convenience method that calls both wrapConsole() and wrapStd()
320
+ * to redirect all output through the logger.
321
+ * @example
322
+ * ```typescript
323
+ * const logger = createPail();
324
+ * logger.wrapAll(); // Wraps console and streams
325
+ *
326
+ * // All output now goes through logger
327
+ * console.log("Console output");
328
+ * process.stdout.write("Stream output");
329
+ *
330
+ * logger.restoreAll(); // Restore everything
331
+ * ```
332
+ */
333
+ wrapAll() {
334
+ this.wrapConsole();
335
+ this.wrapStd();
336
+ }
337
+ /**
338
+ * Restores all wrapped output sources.
339
+ *
340
+ * Convenience method that calls both restoreConsole() and restoreStd()
341
+ * to restore all original output behavior.
342
+ * @example
343
+ * ```typescript
344
+ * const logger = createPail();
345
+ * logger.wrapAll();
346
+ * // All output is wrapped
347
+ * logger.restoreAll();
348
+ * // All output sources are restored
349
+ * ```
350
+ */
351
+ restoreAll() {
352
+ this.restoreConsole();
353
+ this.restoreStd();
354
+ }
355
+ /**
356
+ * Creates a single progress bar.
357
+ * @param options Configuration options for the progress bar
358
+ * @returns A new ProgressBar instance
359
+ * @example
360
+ * ```typescript
361
+ * const logger = createPail({ interactive: true });
362
+ * const bar = logger.createProgressBar({
363
+ * total: 100,
364
+ * format: 'Downloading [{bar}] {percentage}% | ETA: {eta}s | {value}/{total}'
365
+ * });
366
+ *
367
+ * bar.start();
368
+ * // ... do work and update progress
369
+ * bar.update(50);
370
+ * bar.stop();
371
+ * ```
372
+ */
373
+ createProgressBar(options) {
374
+ if (!this.interactiveManager) {
375
+ throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
376
+ }
377
+ const styledOptions = applyStyleToOptions(options);
378
+ return new ProgressBar(styledOptions, this.interactiveManager);
379
+ }
380
+ /**
381
+ * Creates a multi-bar progress manager for displaying multiple progress bars.
382
+ * @param options Configuration options for the multi-bar manager
383
+ * @returns A new MultiProgressBar instance
384
+ * @example
385
+ * ```typescript
386
+ * const logger = createPail({ interactive: true });
387
+ * const multiBar = logger.createMultiProgressBar();
388
+ *
389
+ * const bar1 = multiBar.create(100);
390
+ * const bar2 = multiBar.create(200);
391
+ *
392
+ * bar1.start();
393
+ * bar2.start();
394
+ * // ... update bars as needed
395
+ * multiBar.stop();
396
+ * ```
397
+ */
398
+ createMultiProgressBar(options = {}) {
399
+ if (!this.interactiveManager) {
400
+ throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use progress bars.");
401
+ }
402
+ const styledOptions = applyStyleToOptions(options);
403
+ return new MultiProgressBar(styledOptions, this.interactiveManager);
404
+ }
405
+ /**
406
+ * Creates a single spinner.
407
+ * @param options Configuration options for the spinner
408
+ * @returns A new Spinner instance
409
+ * @example
410
+ * ```typescript
411
+ * const logger = createPail({ interactive: true });
412
+ * const spinner = logger.createSpinner({ name: 'dots' });
413
+ * spinner.start('Loading...');
414
+ * // ... do work
415
+ * spinner.succeed('Done');
416
+ * ```
417
+ */
418
+ createSpinner(options = {}) {
419
+ if (!this.interactiveManager) {
420
+ throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
421
+ }
422
+ return new Spinner(options, this.interactiveManager);
423
+ }
424
+ /**
425
+ * Creates a multi-spinner manager for displaying multiple spinners.
426
+ * @param options Configuration options for the multi-spinner manager
427
+ * @returns A new MultiSpinner instance
428
+ * @example
429
+ * ```typescript
430
+ * const logger = createPail({ interactive: true });
431
+ * const multiSpinner = logger.createMultiSpinner();
432
+ *
433
+ * const spinner1 = multiSpinner.create('Loading 1');
434
+ * const spinner2 = multiSpinner.create('Loading 2');
435
+ *
436
+ * spinner1.start();
437
+ * spinner2.start();
438
+ * // ... update spinners as needed
439
+ * multiSpinner.stop();
440
+ * ```
441
+ */
442
+ createMultiSpinner(options = {}) {
443
+ if (!this.interactiveManager) {
444
+ throw new Error("Interactive mode is not enabled. Create Pail with { interactive: true } to use spinners.");
445
+ }
446
+ return new MultiSpinner(options, this.interactiveManager);
447
+ }
448
+ /**
449
+ * Clears the terminal screen.
450
+ *
451
+ * Sends ANSI escape sequences to clear the terminal screen and move
452
+ * the cursor to the top-left position. This overrides the browser
453
+ * implementation to work with terminal streams.
454
+ * @example
455
+ * ```typescript
456
+ * const logger = createPail();
457
+ * logger.info("Some output");
458
+ * logger.clear(); // Clears the terminal screen
459
+ * ```
460
+ */
461
+ clear() {
462
+ this.stdout.write(clearTerminal);
463
+ this.stderr.write(clearTerminal);
464
+ }
465
+ extendReporter(reporter) {
466
+ if (typeof reporter.setStdout === "function") {
467
+ reporter.setStdout(this.stdout);
468
+ }
469
+ if (typeof reporter.setStderr === "function") {
470
+ reporter.setStderr(this.stderr);
471
+ }
472
+ if (typeof reporter.setLoggerTypes === "function") {
473
+ reporter.setLoggerTypes(this.types);
474
+ }
475
+ if (typeof reporter.setStringify === "function") {
476
+ reporter.setStringify(this.stringify);
477
+ }
478
+ if (typeof reporter.setIsInteractive === "function") {
479
+ reporter.setIsInteractive(this.interactive);
480
+ }
481
+ if (this.interactive && typeof reporter.setInteractiveManager === "function") {
482
+ reporter.setInteractiveManager(this.interactiveManager);
483
+ }
484
+ return reporter;
485
+ }
486
+ #wrapStream(stream, type) {
487
+ if (!stream) {
488
+ return;
489
+ }
490
+ if (!stream.__write) {
491
+ stream.__write = stream.write;
492
+ }
493
+ stream.write = (data) => {
494
+ this[type](String(data).trim());
495
+ };
496
+ }
497
+ // eslint-disable-next-line class-methods-use-this
498
+ #restoreStream(stream) {
499
+ if (!stream) {
500
+ return;
501
+ }
502
+ if (stream.__write) {
503
+ stream.write = stream.__write;
504
+ delete stream.__write;
505
+ }
506
+ }
507
+ }
508
+ const PailServer = PailServerImpl;
509
+
510
+ const getDefaultLogLevel = () => {
511
+ if (env.NODE_ENV === "debug" || env.DEBUG !== void 0) {
512
+ return "debug";
513
+ }
514
+ if (env.NODE_ENV === "test") {
515
+ return "warning";
516
+ }
517
+ return "informational";
518
+ };
519
+ const createPail = (options) => {
520
+ let logLevel = getDefaultLogLevel();
521
+ if (env.PAIL_LOG_LEVEL !== void 0) {
522
+ logLevel = env.PAIL_LOG_LEVEL;
523
+ }
524
+ return new PailServer({
525
+ logLevel,
526
+ processors: [new MessageFormatterProcessor()],
527
+ reporters: [new PrettyReporter()],
528
+ stderr,
529
+ stdout,
530
+ ...options
531
+ });
532
+ };
533
+ const pail = createPail();
534
+
535
+ export { MultiProgressBar, MultiSpinner, ProgressBar, Spinner, createPail, pail };
@@ -1 +1,2 @@
1
- import{default as a}from"../packem_shared/InteractiveManager-CgmJyW9x.js";import{t as o}from"../packem_shared/interactive-stream-hook-CeVo4Kth.js";export{a as InteractiveManager,o as InteractiveStreamHook};
1
+ export { default as InteractiveManager } from '../packem_shared/InteractiveManager-CZ85hGNW.js';
2
+ export { I as InteractiveStreamHook } from '../packem_shared/interactive-stream-hook-DG4BtN12.js';
@@ -1,2 +1,89 @@
1
- var O=Object.defineProperty;var y=(o,r)=>O(o,"name",{value:r,configurable:!0});var m=Object.defineProperty,a=y((o,r)=>m(o,"name",{value:r,configurable:!0}),"s");const j=a(o=>{const r={breakCircularWith:" (circular ref.)",joined:!0,keyNeighbour:"├─ ",keyNoNeighbour:"└─ ",renderFn:a(t=>{if(["boolean","number","string"].includes(typeof t))return String(t)},"renderFn"),separator:": ",sortFn:void 0,spacerNeighbour:"│ ",spacerNoNeighbour:" ",...o};if(typeof r.joined!="boolean")throw new TypeError('Option "joined" must be a boolean');if(typeof r.spacerNoNeighbour!="string")throw new TypeError('Option "spacerNoNeighbour" must be a string');if(typeof r.spacerNeighbour!="string")throw new TypeError('Option "spacerNeighbour" must be a string');if(typeof r.keyNoNeighbour!="string")throw new TypeError('Option "keyNoNeighbour" must be a string');if(typeof r.keyNeighbour!="string")throw new TypeError('Option "keyNeighbour" must be a string');if(typeof r.separator!="string")throw new TypeError('Option "separator" must be a string');if(typeof r.renderFn!="function")throw new TypeError('Option "renderFn" must be a function');if(r.sortFn!==void 0&&typeof r.sortFn!="function")throw new TypeError('Option "sortFn" must be a function or undefined');if(r.breakCircularWith!==null&&typeof r.breakCircularWith!="string")throw new TypeError('Option "breakCircularWith" must be a string or null');return r},"buildContext"),T=a((o,r)=>{const t=j(r),s=[],b=t.renderFn(o);b!==void 0&&s.push(String(b));const l=a(e=>t.sortFn===void 0?e:e.toSorted((n,u)=>t?.sortFn?.(u,n)??0),"sort"),p=[],i=l(Object.keys(o)).map(e=>[e]),h=[o];for(;i.length>0;){const e=i.pop()??[],n=h[e.length-1][e[e.length-1]??""],u=t.breakCircularWith!==null&&h.slice(0,e.length).includes(n);p[e.length-1]=i.length>0&&(i[i.length-1]?.length??0)===e.length;const f=p.slice(0,e.length-1).map(g=>g?t.spacerNeighbour:t.spacerNoNeighbour).join(""),d=p[e.length-1]?t.keyNeighbour:t.keyNoNeighbour,N=e[e.length-1],c=t.renderFn(n),w=c===void 0?"":`${t.separator}${c}`,k=u?t.breakCircularWith:"";s.push(`${f}${d}${N}${w}${k}`),n!==null&&typeof n=="object"&&!Array.isArray(n)&&!u&&(i.push(...l(Object.keys(n)).map(g=>[...e,g])),h[e.length]=n)}return t.joined===!0?s.join(`
2
- `):s},"renderObjectTree");export{T as default,T as renderObjectTree};
1
+ const buildContext = (options) => {
2
+ const context = {
3
+ breakCircularWith: " (circular ref.)",
4
+ joined: true,
5
+ keyNeighbour: "├─ ",
6
+ keyNoNeighbour: "└─ ",
7
+ renderFn: (node) => {
8
+ if (["boolean", "number", "string"].includes(typeof node)) {
9
+ return String(node);
10
+ }
11
+ return void 0;
12
+ },
13
+ separator: ": ",
14
+ sortFn: void 0,
15
+ spacerNeighbour: "│ ",
16
+ spacerNoNeighbour: " ",
17
+ ...options
18
+ };
19
+ if (typeof context.joined !== "boolean") {
20
+ throw new TypeError('Option "joined" must be a boolean');
21
+ }
22
+ if (typeof context.spacerNoNeighbour !== "string") {
23
+ throw new TypeError('Option "spacerNoNeighbour" must be a string');
24
+ }
25
+ if (typeof context.spacerNeighbour !== "string") {
26
+ throw new TypeError('Option "spacerNeighbour" must be a string');
27
+ }
28
+ if (typeof context.keyNoNeighbour !== "string") {
29
+ throw new TypeError('Option "keyNoNeighbour" must be a string');
30
+ }
31
+ if (typeof context.keyNeighbour !== "string") {
32
+ throw new TypeError('Option "keyNeighbour" must be a string');
33
+ }
34
+ if (typeof context.separator !== "string") {
35
+ throw new TypeError('Option "separator" must be a string');
36
+ }
37
+ if (typeof context.renderFn !== "function") {
38
+ throw new TypeError('Option "renderFn" must be a function');
39
+ }
40
+ if (context.sortFn !== void 0 && typeof context.sortFn !== "function") {
41
+ throw new TypeError('Option "sortFn" must be a function or undefined');
42
+ }
43
+ if (context.breakCircularWith !== null && typeof context.breakCircularWith !== "string") {
44
+ throw new TypeError('Option "breakCircularWith" must be a string or null');
45
+ }
46
+ return context;
47
+ };
48
+ const renderObjectTree = (tree, options) => {
49
+ const context = buildContext(options);
50
+ const result = [];
51
+ const rootRendered = context.renderFn(tree);
52
+ if (rootRendered !== void 0) {
53
+ result.push(String(rootRendered));
54
+ }
55
+ const sort = (input) => {
56
+ if (context.sortFn === void 0) {
57
+ return input;
58
+ }
59
+ return input.toSorted((a, b) => context?.sortFn?.(b, a) ?? 0);
60
+ };
61
+ const neighbours = [];
62
+ const keys = sort(Object.keys(tree)).map((k) => [k]);
63
+ const lookup = [tree];
64
+ while (keys.length > 0) {
65
+ const key = keys.pop() ?? [];
66
+ const node = lookup[key.length - 1][key[key.length - 1] ?? ""];
67
+ const isCircular = context.breakCircularWith !== null && lookup.slice(0, key.length).includes(node);
68
+ neighbours[key.length - 1] = keys.length > 0 && (keys[keys.length - 1]?.length ?? 0) === key.length;
69
+ const indent = neighbours.slice(0, key.length - 1).map((n) => {
70
+ if (n) {
71
+ return context.spacerNeighbour;
72
+ }
73
+ return context.spacerNoNeighbour;
74
+ }).join("");
75
+ const connector = neighbours[key.length - 1] ? context.keyNeighbour : context.keyNoNeighbour;
76
+ const keyName = key[key.length - 1];
77
+ const nodeRendered = context.renderFn(node);
78
+ const value = nodeRendered === void 0 ? "" : `${context.separator}${nodeRendered}`;
79
+ const circular = isCircular ? context.breakCircularWith : "";
80
+ result.push(`${indent}${connector}${keyName}${value}${circular}`);
81
+ if (node !== null && typeof node === "object" && !Array.isArray(node) && !isCircular) {
82
+ keys.push(...sort(Object.keys(node)).map((k) => [...key, k]));
83
+ lookup[key.length] = node;
84
+ }
85
+ }
86
+ return context.joined === true ? result.join("\n") : result;
87
+ };
88
+
89
+ export { renderObjectTree as default, renderObjectTree };