@visulima/pail 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## @visulima/pail [1.1.1](https://github.com/visulima/visulima/compare/@visulima/pail@1.1.0...@visulima/pail@1.1.1) (2024-03-07)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * fixed logger function type, for better input typing ([f08bbd4](https://github.com/visulima/visulima/commit/f08bbd44b33e62dc0f04fb516557541abaec6863))
7
+
1
8
  ## @visulima/pail [1.1.0](https://github.com/visulima/visulima/compare/@visulima/pail@1.0.0...@visulima/pail@1.1.0) (2024-03-04)
2
9
 
3
10
 
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'safe-stable-stringify';
2
- import { h as StringifyAwareReporter, g as ReadonlyMeta, e as LiteralUnion, E as ExtendedRfc5424LogLevels, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes } from './types-Eye5gXn9.js';
2
+ import { h as StringifyAwareReporter, g as ReadonlyMeta, e as LiteralUnion, E as ExtendedRfc5424LogLevels, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes } from './types--_CcxoUw.js';
3
3
 
4
4
  declare abstract class AbstractJsonReporter<L extends string = never> implements StringifyAwareReporter<L> {
5
5
  protected _stringify: typeof stringify | undefined;
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'safe-stable-stringify';
2
- import { h as StringifyAwareReporter, g as ReadonlyMeta, e as LiteralUnion, E as ExtendedRfc5424LogLevels, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes } from './types-Eye5gXn9.cjs';
2
+ import { h as StringifyAwareReporter, g as ReadonlyMeta, e as LiteralUnion, E as ExtendedRfc5424LogLevels, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, a as DefaultLogTypes } from './types--_CcxoUw.cjs';
3
3
 
4
4
  declare abstract class AbstractJsonReporter<L extends string = never> implements StringifyAwareReporter<L> {
5
5
  protected _stringify: typeof stringify | undefined;
@@ -1,10 +1,10 @@
1
- import { P as PailBrowserType } from './pail.browser-yTupUnZE.cjs';
2
- import { C as ConstructorOptions } from './types-Eye5gXn9.cjs';
3
- export { a as DefaultLogTypes, D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, b as LoggerFunction, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, R as Reporter, S as StreamAwareReporter } from './types-Eye5gXn9.cjs';
1
+ import { P as PailBrowserType } from './pail.browser-qG_FNUeK.cjs';
2
+ import { C as ConstructorOptions } from './types--_CcxoUw.cjs';
3
+ export { a as DefaultLogTypes, D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, b as LoggerFunction, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, R as Reporter, S as StreamAwareReporter } from './types--_CcxoUw.cjs';
4
4
  import 'safe-stable-stringify';
5
5
  import '@visulima/colorize';
6
6
 
7
- declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L> | undefined) => PailBrowserType<T, L>;
7
+ declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>) => PailBrowserType<T, L>;
8
8
  declare const pail: PailBrowserType<never, never>;
9
9
 
10
10
  export { ConstructorOptions, PailBrowserType as Pail, createPail, pail };
@@ -1,10 +1,10 @@
1
- import { P as PailBrowserType } from './pail.browser-8eK5giTJ.js';
2
- import { C as ConstructorOptions } from './types-Eye5gXn9.js';
3
- export { a as DefaultLogTypes, D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, b as LoggerFunction, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, R as Reporter, S as StreamAwareReporter } from './types-Eye5gXn9.js';
1
+ import { P as PailBrowserType } from './pail.browser-0Ej0KEkV.js';
2
+ import { C as ConstructorOptions } from './types--_CcxoUw.js';
3
+ export { a as DefaultLogTypes, D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, b as LoggerFunction, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, R as Reporter, S as StreamAwareReporter } from './types--_CcxoUw.js';
4
4
  import 'safe-stable-stringify';
5
5
  import '@visulima/colorize';
6
6
 
7
- declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L> | undefined) => PailBrowserType<T, L>;
7
+ declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>) => PailBrowserType<T, L>;
8
8
  declare const pail: PailBrowserType<never, never>;
9
9
 
10
10
  export { ConstructorOptions, PailBrowserType as Pail, createPail, pail };
@@ -1,6 +1,6 @@
1
- import { a as DefaultLogTypes, b as LoggerFunction, f as ServerConstructorOptions, I as InteractiveManager, R as Reporter, C as ConstructorOptions } from './types-Eye5gXn9.cjs';
2
- export { D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, S as StreamAwareReporter } from './types-Eye5gXn9.cjs';
3
- import { a as PailBrowserImpl } from './pail.browser-yTupUnZE.cjs';
1
+ import { a as DefaultLogTypes, b as LoggerFunction, f as ServerConstructorOptions, I as InteractiveManager, R as Reporter, C as ConstructorOptions } from './types--_CcxoUw.cjs';
2
+ export { D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, S as StreamAwareReporter } from './types--_CcxoUw.cjs';
3
+ import { a as PailBrowserImpl } from './pail.browser-qG_FNUeK.cjs';
4
4
  import '@visulima/colorize';
5
5
  import 'safe-stable-stringify';
6
6
 
@@ -24,7 +24,7 @@ declare class PailServerImpl<T extends string = never, L extends string = never>
24
24
  }
25
25
  type PailServerType<T extends string = never, L extends string = never> = PailServerImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & (new <TC extends string = never, LC extends string = never>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>);
26
26
 
27
- declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L> | undefined) => PailServerType<T, L>;
27
+ declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>) => PailServerType<T, L>;
28
28
  declare const pail: PailServerType<never, never>;
29
29
 
30
30
  export { ConstructorOptions, DefaultLogTypes, LoggerFunction, type PailServerType as Pail, Reporter, createPail, pail };
@@ -1,6 +1,6 @@
1
- import { a as DefaultLogTypes, b as LoggerFunction, f as ServerConstructorOptions, I as InteractiveManager, R as Reporter, C as ConstructorOptions } from './types-Eye5gXn9.js';
2
- export { D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, S as StreamAwareReporter } from './types-Eye5gXn9.js';
3
- import { a as PailBrowserImpl } from './pail.browser-8eK5giTJ.js';
1
+ import { a as DefaultLogTypes, b as LoggerFunction, f as ServerConstructorOptions, I as InteractiveManager, R as Reporter, C as ConstructorOptions } from './types--_CcxoUw.js';
2
+ export { D as DefaultLoggerTypes, E as ExtendedRfc5424LogLevels, L as LoggerConfiguration, c as LoggerTypesAwareReporter, d as LoggerTypesConfig, P as Processor, S as StreamAwareReporter } from './types--_CcxoUw.js';
3
+ import { a as PailBrowserImpl } from './pail.browser-0Ej0KEkV.js';
4
4
  import '@visulima/colorize';
5
5
  import 'safe-stable-stringify';
6
6
 
@@ -24,7 +24,7 @@ declare class PailServerImpl<T extends string = never, L extends string = never>
24
24
  }
25
25
  type PailServerType<T extends string = never, L extends string = never> = PailServerImpl<T, L> & Record<DefaultLogTypes, LoggerFunction> & Record<T, LoggerFunction> & (new <TC extends string = never, LC extends string = never>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>);
26
26
 
27
- declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L> | undefined) => PailServerType<T, L>;
27
+ declare const createPail: <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>) => PailServerType<T, L>;
28
28
  declare const pail: PailServerType<never, never>;
29
29
 
30
30
  export { ConstructorOptions, DefaultLogTypes, LoggerFunction, type PailServerType as Pail, Reporter, createPail, pail };
@@ -6,7 +6,7 @@ import './chunk-ZB7IIFHO.js';
6
6
  import './chunk-NF47XQ47.js';
7
7
  import C from 'terminal-size';
8
8
  import P from 'wrap-ansi';
9
- import { StringDecoder } from 'string_decoder';
9
+ import { StringDecoder } from 'node:string_decoder';
10
10
 
11
11
  var v=class{#e;#t=!1;#i=!1;#r=0;#s=0;constructor(t,e){this.#e={stderr:e,stdout:t};}get lastLength(){return this.#r}get outside(){return this.#s}get isHooked(){return this.#t}get isSuspended(){return this.#i}erase(t,e=this.#r){if(this.#e[t]===void 0)throw new TypeError(`Stream "${t}" is not available`);this.#e[t].erase(e);}hook(){return this.#t||(Object.values(this.#e).forEach(t=>t.active()),this._clear(!0)),this.#t}resume(t,e){this.#i&&(this.#i=!1,e&&this.erase(t,e),this.#r=0,Object.values(this.#e).forEach(r=>r.active()));}suspend(t,e=!0){this.#i||(this.#i=!0,e&&this.erase(t),Object.values(this.#e).forEach(r=>r.renew()));}unhook(t=!0){return this.#t&&(Object.values(this.#e).forEach(e=>e.inactive(t)),this._clear()),!this.#t}update(t,e,r=0){if(e.length>0){if(this.#e[t]===void 0)throw new TypeError(`Stream "${t}" is not available`);let o=this.#e[t],{columns:u,rows:i}=C(),c=r>i?i-1:Math.max(0,Math.min(i-1,r)),n=this.lastLength-c,d=Math.max(n-i,this.outside),p=e.reduce((l,E)=>[...l,P(E,u,{hard:!0,trim:!1,wordWrap:!0})],[]);i<=n?(o.erase(i),c<d&&(p=p.slice(d-c+1))):n&&o.erase(n),o.write(p.join(`
12
12
  `)+`
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/interactive/interactive-manager.ts","../src/interactive/interactive-stream-hook.ts","../src/util/ansi-escapes.ts","../src/reporter/raw/raw.server.ts","../src/pail.server.ts","../src/index.server.ts"],"names":["terminalSize","wrapAnsi","InteractiveManager","#stream","#isActive","#isSuspended","#lastLength","#outside","stdout","stderr","stream","count","hook","eraseRowCount","erase","separateHistory","rows","from","width","height","position","actualLength","outside","output","accumulator","row","status","StringDecoder","ESC","eraseScreen","eraseLine","cursorLeft","cursorUp","clearTerminal","cursorHide","cursorShow","eraseLines","clear","index","InteractiveStreamHook","_InteractiveStreamHook","#decoder","#history","#method","data","arguments_","callback","element","message","RawReporter","#stringify","#stdout","#stderr","#interactiveManager","#interactive","function_","manager","interactive","meta","context","groups","type","items","formattedMessage","value","streamType","groupSpaces","writeStream","PailServerImpl","PailBrowserImpl","options","rawReporter","reporters","rest","name","reporter","PailServer","_getDefaultLogLevel","createPail","MessageFormatterProcessor","ErrorProcessor","PrettyReporter","pail"],"mappings":"0NAAA,OAAOA,MAAkB,gBACzB,OAAOC,MAAc,YAMd,IAAMC,EAAN,KAAyB,CACnBC,GAKTC,GAAY,GAEZC,GAAe,GAEfC,GAAc,EAEdC,GAAW,EAEJ,YAAYC,EAA+BC,EAA+B,CAC7E,KAAKN,GAAU,CACX,OAAAM,EACA,OAAAD,CACJ,CACJ,CAKA,IAAW,YAAqB,CAC5B,OAAO,KAAKF,EAChB,CAKA,IAAW,SAAkB,CACzB,OAAO,KAAKC,EAChB,CAKA,IAAW,UAAoB,CAC3B,OAAO,KAAKH,EAChB,CAKA,IAAW,aAAuB,CAC9B,OAAO,KAAKC,EAChB,CAQO,MAAMK,EAAoBC,EAAQ,KAAKL,GAAmB,CAE7D,GAAI,KAAKH,GAAQO,CAAM,IAAM,OACzB,MAAM,IAAI,UAAU,WAAWA,CAAM,oBAAoB,EAI7D,KAAKP,GAAQO,CAAM,EAAE,MAAMC,CAAK,CACpC,CAMO,MAAgB,CACnB,OAAK,KAAKP,KACN,OAAO,OAAO,KAAKD,EAAO,EAAE,QAASS,GAASA,EAAK,OAAO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,QAOJ,gBAGEC,EAAkER,GAC3E,IAAIM,EAAiB,CACjB,SAAUC,EAAoB,EAC9B,WAAY,CAAC,IAAIE,EAAgC,IAAIC,CAAmB,EACxE,UAAW,CAAC,IAAIC,CAAgB,EAChC,OAAQ,QAAQ,OAChB,OAAQ,QAAQ,OAChB,GAAGX,CACP,CAAC,EAEQY,GAAOJ,EAAW","sourcesContent":["import terminalSize from \"terminal-size\";\nimport wrapAnsi from \"wrap-ansi\";\n\nimport type { InteractiveStreamHook } from \"./interactive-stream-hook\";\n\ntype StreamType = \"stderr\" | \"stdout\";\n\nexport class InteractiveManager {\n readonly #stream: {\n stderr: InteractiveStreamHook;\n stdout: InteractiveStreamHook;\n };\n\n #isActive = false;\n\n #isSuspended = false;\n\n #lastLength = 0;\n\n #outside = 0;\n\n public constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook) {\n this.#stream = {\n stderr,\n stdout,\n };\n }\n\n /**\n * Last printed rows count\n */\n public get lastLength(): number {\n return this.#lastLength;\n }\n\n /**\n * Rows count outside editable area\n */\n public get outside(): number {\n return this.#outside;\n }\n\n /**\n * Hook activity status\n */\n public get isHooked(): boolean {\n return this.#isActive;\n }\n\n /**\n * Suspend status for active hooks\n */\n public get isSuspended(): boolean {\n return this.#isSuspended;\n }\n\n /**\n * Removes from the bottom of output up the specified count of lines\n *\n * @param stream - Stream to remove lines from\n * @param count - lines count to remove\n */\n public erase(stream: StreamType, count = this.#lastLength): void {\n // eslint-disable-next-line security/detect-object-injection,@typescript-eslint/no-unnecessary-condition\n if (this.#stream[stream] === undefined) {\n throw new TypeError(`Stream \"${stream}\" is not available`);\n }\n\n // eslint-disable-next-line security/detect-object-injection\n this.#stream[stream].erase(count);\n }\n\n /**\n * Hook stdout and stderr streams\n * @returns Success status\n */\n public hook(): boolean {\n if (!this.#isActive) {\n Object.values(this.#stream).forEach((hook) => hook.active());\n\n this._clear(true);\n }\n\n return this.#isActive;\n }\n\n /**\n * Resume suspend hooks\n *\n * @param stream - Stream to resume\n * @param eraseRowCount - erase output rows count\n */\n public resume(stream: StreamType, eraseRowCount?: number): void {\n if (this.#isSuspended) {\n this.#isSuspended = false;\n\n if (eraseRowCount) {\n this.erase(stream, eraseRowCount);\n }\n\n this.#lastLength = 0;\n\n Object.values(this.#stream).forEach((hook) => hook.active());\n }\n }\n\n /**\n * Suspend active hooks for external output\n *\n * @param stream - Stream to suspend\n * @param erase - erase output\n */\n public suspend(stream: StreamType, erase = true): void {\n if (!this.#isSuspended) {\n this.#isSuspended = true;\n\n if (erase) {\n this.erase(stream);\n }\n\n Object.values(this.#stream).forEach((hook) => hook.renew());\n }\n }\n\n /**\n * Unhooks both stdout and stderr streams and print their story of logs\n *\n * @param separateHistory - If `true`, will add an empty line to the history output for individual recorded lines and console logs\n *\n * @returns Success status\n */\n public unhook(separateHistory = true): boolean {\n if (this.#isActive) {\n Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));\n\n this._clear();\n }\n\n return !this.#isActive;\n }\n\n /**\n * Update output\n *\n * @param stream - Stream to write to\n * @param rows - Text lines to write to standard output\n * @param from - Index of the line starting from which the contents of the terminal are being overwritten\n */\n public update(stream: StreamType, rows: string[], from = 0): void {\n if (rows.length > 0) {\n // eslint-disable-next-line security/detect-object-injection,@typescript-eslint/no-unnecessary-condition\n if (this.#stream[stream] === undefined) {\n throw new TypeError(`Stream \"${stream}\" is not available`);\n }\n\n // eslint-disable-next-line security/detect-object-injection\n const hook = this.#stream[stream];\n\n const { columns: width, rows: height } = terminalSize();\n\n const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));\n const actualLength = this.lastLength - position;\n const outside = Math.max(actualLength - height, this.outside);\n\n // eslint-disable-next-line unicorn/no-array-reduce\n let output = rows.reduce<string[]>(\n (accumulator, row) => [\n ...accumulator,\n wrapAnsi(row, width, {\n hard: true,\n trim: false,\n wordWrap: true,\n }),\n ],\n [],\n );\n\n if (height <= actualLength) {\n hook.erase(height);\n\n if (position < outside) {\n output = output.slice(outside - position + 1);\n }\n } else if (actualLength) {\n hook.erase(actualLength);\n }\n\n hook.write(output.join(\"\\n\") + \"\\n\");\n\n this.#lastLength = outside ? outside + output.length + 1 : output.length;\n this.#outside = Math.max(this.lastLength - height, this.outside);\n }\n }\n\n private _clear(status = false): void {\n this.#isActive = status;\n this.#lastLength = 0;\n this.#outside = 0;\n }\n}\n","import { StringDecoder } from \"node:string_decoder\";\n\nimport { cursorHide, cursorShow, eraseLines } from \"../util/ansi-escapes\";\n\nexport class InteractiveStreamHook {\n public static readonly DRAIN = true;\n\n readonly #decoder = new StringDecoder();\n\n #history: string[] = [];\n\n readonly #method: NodeJS.WriteStream[\"write\"];\n\n readonly #stream: NodeJS.WriteStream;\n\n public constructor(stream: NodeJS.WriteStream) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#method = stream.write;\n this.#stream = stream;\n }\n\n public active(): void {\n this.write(cursorHide as string);\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment,@typescript-eslint/prefer-ts-expect-error\n // @ts-ignore - We are modifying the write method\n this.#stream.write = (data: Uint8Array | string, ...arguments_: [((error?: Error) => void)?] | [(string | undefined)?, ((error?: Error) => void)?]) => {\n const callback = arguments_.at(-1);\n\n this.#history.push(\n this.#decoder.write(\n typeof data === \"string\"\n ? Buffer.from(data, typeof arguments_[0] === \"string\" ? (arguments_[0] as BufferEncoding) : undefined)\n : Buffer.from(data),\n ),\n );\n\n if (typeof callback === \"function\") {\n callback();\n }\n\n return InteractiveStreamHook.DRAIN;\n };\n }\n\n public erase(count: number): void {\n if (count > 0) {\n this.write(eraseLines(count + 1) as string);\n }\n }\n\n public inactive(separateHistory = false): void {\n if (this.#history.length > 0) {\n if (separateHistory) {\n this.write(\"\\n\");\n }\n\n this.#history.forEach((element) => {\n this.write(element);\n });\n this.#history = [];\n }\n\n this.renew();\n }\n\n public renew(): void {\n this.#stream.write = this.#method;\n this.write(cursorShow as string);\n }\n\n public write(message: string): void {\n this.#method.apply(this.#stream, [message]);\n }\n}\n","const ESC = \"\\u001B[\";\n\nconst eraseScreen = ESC + \"2J\";\nconst eraseLine = ESC + \"2K\";\n\nconst cursorLeft = ESC + \"G\";\nconst cursorUp = (count = 1) => ESC + count + \"A\";\n\nexport const clearTerminal: string =\n process.platform === \"win32\"\n ? `${eraseScreen}${ESC}0f`\n : // 1. Erases the screen (Only done in case `2` is not supported)\n // 2. Erases the whole screen including scrollback buffer\n // 3. Moves cursor to the top-left position\n // More info: https://www.real-world-systems.com/docs/ANSIcode.html\n `${eraseScreen}${ESC}3J${ESC}H`;\n\nexport const cursorHide: string = ESC + \"?25l\";\nexport const cursorShow: string = ESC + \"?25h\";\n\nexport const eraseLines = (count: number): string => {\n let clear = \"\";\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0; index < count; index++) {\n clear += eraseLine + (index < count - 1 ? cursorUp() : \"\");\n }\n\n if (count) {\n clear += cursorLeft;\n }\n\n return clear;\n};\n","import type { stringify } from \"safe-stable-stringify\";\n\nimport type { InteractiveManager } from \"../../interactive/interactive-manager\";\nimport type { ReadonlyMeta, StreamAwareReporter, StringifyAwareReporter } from \"../../types\";\nimport { writeStream } from \"../../util/write-stream\";\n\nexport class RawReporter<L extends string = never> implements StreamAwareReporter<L>, StringifyAwareReporter<L> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n #stringify: typeof stringify | undefined;\n\n #stdout: NodeJS.WriteStream;\n\n #stderr: NodeJS.WriteStream;\n\n #interactiveManager: InteractiveManager | undefined;\n\n #interactive = false;\n\n public constructor() {\n this.#stdout = process.stdout;\n this.#stderr = process.stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStdout(stdout: NodeJS.WriteStream) {\n this.#stdout = stdout;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStderr(stderr: NodeJS.WriteStream) {\n this.#stderr = stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n public setStringify(function_: any): void {\n this.#stringify = function_;\n }\n\n public setInteractiveManager(manager?: InteractiveManager): void {\n this.#interactiveManager = manager;\n }\n\n public setIsInteractive(interactive: boolean): void {\n this.#interactive = interactive;\n }\n\n public log(meta: ReadonlyMeta<L>): void {\n const { context, groups, message, type } = meta;\n\n const items: string[] = [];\n\n const formattedMessage: string | undefined = typeof message === \"string\" ? message : (this.#stringify as typeof stringify)(message);\n\n items.push(formattedMessage + \"\");\n\n if (context) {\n items.push(\n ...context.map((value) => {\n if (typeof value === \"object\") {\n return \" \" + (this.#stringify as typeof stringify)(value);\n }\n\n return \" \" + value;\n }),\n );\n }\n\n const streamType = [\"error\", \"trace\", \"warn\"].includes(type.level as string) ? \"stderr\" : \"stdout\";\n const stream = streamType === \"stderr\" ? this.#stderr : this.#stdout;\n const groupSpaces: string = groups.map(() => \" \").join(\"\");\n\n if (this.#interactive && this.#interactiveManager !== undefined && stream.isTTY) {\n this.#interactiveManager.update(streamType, (groupSpaces + items.join(\"\")).split(\"\\n\"), 0);\n } else {\n writeStream(groupSpaces + items.join(\"\"), stream);\n }\n }\n}\n","import { InteractiveManager } from \"./interactive/interactive-manager\";\nimport { InteractiveStreamHook } from \"./interactive/interactive-stream-hook\";\nimport { PailBrowserImpl } from \"./pail.browser\";\nimport { RawReporter } from \"./reporter/raw/raw.server\";\nimport type {\n ConstructorOptions,\n DefaultLogTypes,\n InteractiveStreamReporter,\n LiteralUnion,\n LoggerFunction,\n LoggerTypesAwareReporter,\n Reporter,\n ServerConstructorOptions,\n StreamAwareReporter,\n StringifyAwareReporter,\n} from \"./types\";\nimport { clearTerminal } from \"./util/ansi-escapes\";\n\nclass PailServerImpl<T extends string = never, L extends string = never> extends PailBrowserImpl<T, L> {\n protected readonly stdout: NodeJS.WriteStream;\n\n protected readonly stderr: NodeJS.WriteStream;\n\n protected interactiveManager: InteractiveManager | undefined;\n\n protected readonly interactive: boolean;\n\n public constructor(public readonly options: ServerConstructorOptions<T, L> = {}) {\n const { interactive, rawReporter, reporters, stderr, stdout, ...rest } = options;\n\n super(rest as ConstructorOptions<T, L>);\n\n this.interactive = interactive ?? false;\n\n this.stdout = stdout as NodeJS.WriteStream;\n this.stderr = stderr as NodeJS.WriteStream;\n\n if (this.interactive) {\n this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));\n }\n\n if (Array.isArray(reporters)) {\n this.registerReporters(reporters);\n }\n\n this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter<L>());\n }\n\n public override scope<N extends string = T>(...name: string[]): PailServerType<N, L> {\n if (name.length === 0) {\n throw new Error(\"No scope name was defined.\");\n }\n\n this.scopeName = name.flat();\n\n return this as unknown as PailServerType<N, L>;\n }\n\n public getInteractiveManager(): InteractiveManager | undefined {\n return this.interactiveManager;\n }\n\n public wrapStd() {\n this._wrapStream(this.stdout, \"log\");\n this._wrapStream(this.stderr, \"log\");\n }\n\n public restoreStd() {\n this._restoreStream(this.stdout);\n this._restoreStream(this.stderr);\n }\n\n public wrapAll(): void {\n this.wrapConsole();\n this.wrapStd();\n }\n\n public restoreAll(): void {\n this.restoreConsole();\n this.restoreStd();\n }\n\n public override clear(): void {\n this.stdout.write(clearTerminal as string);\n this.stderr.write(clearTerminal as string);\n }\n\n protected override extendReporter(reporter: Reporter<L>): Reporter<L> {\n if (typeof (reporter as StreamAwareReporter<L>).setStdout === \"function\") {\n (reporter as StreamAwareReporter<L>).setStdout(this.stdout);\n }\n\n if (typeof (reporter as StreamAwareReporter<L>).setStderr === \"function\") {\n (reporter as StreamAwareReporter<L>).setStderr(this.stderr);\n }\n\n if (typeof (reporter as LoggerTypesAwareReporter<T, L>).setLoggerTypes === \"function\") {\n (reporter as LoggerTypesAwareReporter<T, L>).setLoggerTypes(this.types);\n }\n\n if (typeof (reporter as StringifyAwareReporter<L>).setStringify === \"function\") {\n (reporter as StringifyAwareReporter<L>).setStringify(this.stringify);\n }\n\n if (typeof (reporter as InteractiveStreamReporter<L>).setIsInteractive === \"function\") {\n (reporter as InteractiveStreamReporter<L>).setIsInteractive(this.interactive);\n }\n\n if (this.interactive && typeof (reporter as InteractiveStreamReporter<L>).setInteractiveManager === \"function\") {\n (reporter as InteractiveStreamReporter<L>).setInteractiveManager(this.interactiveManager);\n }\n\n return reporter;\n }\n\n private _wrapStream(stream: NodeJS.WriteStream | undefined, type: LiteralUnion<DefaultLogTypes, L>) {\n if (!stream) {\n return;\n }\n\n // Backup original value\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!(stream as any).__write) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign,@typescript-eslint/unbound-method\n (stream as any).__write = stream.write;\n }\n\n // Override\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n (stream as any).write = (data: any): void => {\n // @TODO: Fix typings\n // @ts-expect-error - dynamic property\n // eslint-disable-next-line security/detect-object-injection\n (this as unknown as PailServerImpl)[type].log(String(data).trim());\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n private _restoreStream(stream?: NodeJS.WriteStream): void {\n if (!stream) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((stream as any).__write) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n stream.write = (stream as any).__write;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n delete (stream as any).__write;\n }\n }\n}\n\nexport type PailServerType<T extends string = never, L extends string = never> = PailServerImpl<T, L> &\n Record<DefaultLogTypes, LoggerFunction> &\n Record<T, LoggerFunction> &\n (new<TC extends string = never, LC extends string = never>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>);\n\nexport type PailConstructor<T extends string = never, L extends string = never> = new (options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;\n\nexport const PailServer = PailServerImpl as unknown as PailServerType;\n","import type { PailServerType } from \"./pail.server\";\nimport { PailServer } from \"./pail.server\";\nimport { ErrorProcessor } from \"./processor/error/error-processor\";\nimport { MessageFormatterProcessor } from \"./processor/message-formatter-processor\";\nimport { PrettyReporter } from \"./reporter/pretty/pretty.server\";\nimport type { ConstructorOptions, ExtendedRfc5424LogLevels } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst _getDefaultLogLevel = (): ExtendedRfc5424LogLevels => {\n if (process.env[\"NODE_ENV\"] === \"debug\" || process.env[\"DEBUG\"] !== undefined) {\n return \"debug\";\n }\n\n if (process.env[\"NODE_ENV\"] === \"test\") {\n return \"warning\";\n }\n\n return \"informational\";\n};\n\nexport const createPail = <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>): PailServerType<T, L> =>\n new PailServer<T, L>({\n logLevel: _getDefaultLogLevel(),\n processors: [new MessageFormatterProcessor<L>(), new ErrorProcessor<L>()],\n reporters: [new PrettyReporter()],\n stderr: process.stderr,\n stdout: process.stdout,\n ...options,\n });\n\nexport const pail = createPail();\n\nexport type { PailServerType as Pail } from \"./pail.server\";\nexport type {\n ConstructorOptions,\n DefaultLoggerTypes,\n DefaultLogTypes,\n ExtendedRfc5424LogLevels,\n LoggerConfiguration,\n LoggerFunction,\n LoggerTypesAwareReporter,\n LoggerTypesConfig,\n Processor,\n Reporter,\n StreamAwareReporter,\n} from \"./shared\";\n"]}
1
+ {"version":3,"sources":["../src/interactive/interactive-manager.ts","../src/interactive/interactive-stream-hook.ts","../src/util/ansi-escapes.ts","../src/reporter/raw/raw.server.ts","../src/pail.server.ts","../src/index.server.ts"],"names":["terminalSize","wrapAnsi","InteractiveManager","#stream","#isActive","#isSuspended","#lastLength","#outside","stdout","stderr","stream","count","hook","eraseRowCount","erase","separateHistory","rows","from","width","height","position","actualLength","outside","output","accumulator","row","status","StringDecoder","ESC","eraseScreen","eraseLine","cursorLeft","cursorUp","clearTerminal","cursorHide","cursorShow","eraseLines","clear","index","InteractiveStreamHook","_InteractiveStreamHook","#decoder","#history","#method","data","arguments_","callback","element","message","RawReporter","#stringify","#stdout","#stderr","#interactiveManager","#interactive","function_","manager","interactive","meta","context","groups","type","items","formattedMessage","value","streamType","groupSpaces","writeStream","PailServerImpl","PailBrowserImpl","options","rawReporter","reporters","rest","name","reporter","PailServer","_getDefaultLogLevel","createPail","MessageFormatterProcessor","ErrorProcessor","PrettyReporter","pail"],"mappings":"0NAAA,OAAOA,MAAkB,gBACzB,OAAOC,MAAc,YAMd,IAAMC,EAAN,KAAyB,CACnBC,GAKTC,GAAY,GAEZC,GAAe,GAEfC,GAAc,EAEdC,GAAW,EAEJ,YAAYC,EAA+BC,EAA+B,CAC7E,KAAKN,GAAU,CACX,OAAAM,EACA,OAAAD,CACJ,CACJ,CAKA,IAAW,YAAqB,CAC5B,OAAO,KAAKF,EAChB,CAKA,IAAW,SAAkB,CACzB,OAAO,KAAKC,EAChB,CAKA,IAAW,UAAoB,CAC3B,OAAO,KAAKH,EAChB,CAKA,IAAW,aAAuB,CAC9B,OAAO,KAAKC,EAChB,CAQO,MAAMK,EAAoBC,EAAQ,KAAKL,GAAmB,CAE7D,GAAI,KAAKH,GAAQO,CAAM,IAAM,OACzB,MAAM,IAAI,UAAU,WAAWA,CAAM,oBAAoB,EAI7D,KAAKP,GAAQO,CAAM,EAAE,MAAMC,CAAK,CACpC,CAMO,MAAgB,CACnB,OAAK,KAAKP,KACN,OAAO,OAAO,KAAKD,EAAO,EAAE,QAASS,GAASA,EAAK,OAAO,CAAC,EAE3D,KAAK,OAAO,EAAI,GAGb,KAAKR,EAChB,CAQO,OAAOM,EAAoBG,EAA8B,CACxD,KAAKR,KACL,KAAKA,GAAe,GAEhBQ,GACA,KAAK,MAAMH,EAAQG,CAAa,EAGpC,KAAKP,GAAc,EAEnB,OAAO,OAAO,KAAKH,EAAO,EAAE,QAASS,GAASA,EAAK,OAAO,CAAC,EAEnE,CAQO,QAAQF,EAAoBI,EAAQ,GAAY,CAC9C,KAAKT,KACN,KAAKA,GAAe,GAEhBS,GACA,KAAK,MAAMJ,CAAM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B,CAEgB,OAAc,CAC1B,KAAK,OAAO,MAAMzC,CAAuB,EACzC,KAAK,OAAO,MAAMA,CAAuB,CAC7C,CAEmB,eAAe0C,EAAoC,CAClE,OAAI,OAAQA,EAAoC,WAAc,YACzDA,EAAoC,UAAU,KAAK,MAAM,EAG1D,OAAQA,EAAoC,WAAc,YACzDA,EAAoC,UAAU,KAAK,MAAM,EAG1D,OAAQA,EAA4C,gBAAmB,YACtEA,EAA4C,eAAe,KAAK,KAAK,EAGtE,OAAQA,EAAuC,cAAiB,YAC/DA,EAAuC,aAAa,KAAK,SAAS,EAGnE,OAAQA,EAA0C,kBAAqB,YACtEA,EAA0C,iBAAiB,KAAK,WAAW,EAG5E,KAAK,aAAe,OAAQA,EAA0C,uBAA0B,YAC/FA,EAA0C,sBAAsB,KAAK,kBAAkB,EAGrFA,CACX,CAEQ,YAAYjE,EAAwCmD,EAAwC,CAC3FnD,IAMCA,EAAe,UAEhBA,EAAe,QAAUA,EAAO,OAKpCA,EAAe,MAASkC,GAAoB,CAIxC,KAAmCiB,CAAI,EAAE,IAAI,OAAOjB,CAAI,EAAE,KAAK,CAAC,CACrE,EACJ,CAGQ,eAAelC,EAAmC,CACjDA,GAKAA,EAAe,UAEhBA,EAAO,MAASA,EAAe,QAG/B,OAAQA,EAAe,QAE/B,CACJ,EASakE,EAAaR,ECzJ1B,IAAMS,EAAsB,IACmB,QAAQ,IAAI,QAAa,OACzD,QAOJ,gBAGEC,EAAkER,GAC3E,IAAIM,EAAiB,CACjB,SAAUC,EAAoB,EAC9B,WAAY,CAAC,IAAIE,EAAgC,IAAIC,CAAmB,EACxE,UAAW,CAAC,IAAIC,CAAgB,EAChC,OAAQ,QAAQ,OAChB,OAAQ,QAAQ,OAChB,GAAGX,CACP,CAAC,EAEQY,GAAOJ,EAAW","sourcesContent":["import terminalSize from \"terminal-size\";\nimport wrapAnsi from \"wrap-ansi\";\n\nimport type { InteractiveStreamHook } from \"./interactive-stream-hook\";\n\ntype StreamType = \"stderr\" | \"stdout\";\n\nexport class InteractiveManager {\n readonly #stream: {\n stderr: InteractiveStreamHook;\n stdout: InteractiveStreamHook;\n };\n\n #isActive = false;\n\n #isSuspended = false;\n\n #lastLength = 0;\n\n #outside = 0;\n\n public constructor(stdout: InteractiveStreamHook, stderr: InteractiveStreamHook) {\n this.#stream = {\n stderr,\n stdout,\n };\n }\n\n /**\n * Last printed rows count\n */\n public get lastLength(): number {\n return this.#lastLength;\n }\n\n /**\n * Rows count outside editable area\n */\n public get outside(): number {\n return this.#outside;\n }\n\n /**\n * Hook activity status\n */\n public get isHooked(): boolean {\n return this.#isActive;\n }\n\n /**\n * Suspend status for active hooks\n */\n public get isSuspended(): boolean {\n return this.#isSuspended;\n }\n\n /**\n * Removes from the bottom of output up the specified count of lines\n *\n * @param stream - Stream to remove lines from\n * @param count - lines count to remove\n */\n public erase(stream: StreamType, count = this.#lastLength): void {\n // eslint-disable-next-line security/detect-object-injection,@typescript-eslint/no-unnecessary-condition\n if (this.#stream[stream] === undefined) {\n throw new TypeError(`Stream \"${stream}\" is not available`);\n }\n\n // eslint-disable-next-line security/detect-object-injection\n this.#stream[stream].erase(count);\n }\n\n /**\n * Hook stdout and stderr streams\n * @returns Success status\n */\n public hook(): boolean {\n if (!this.#isActive) {\n Object.values(this.#stream).forEach((hook) => hook.active());\n\n this._clear(true);\n }\n\n return this.#isActive;\n }\n\n /**\n * Resume suspend hooks\n *\n * @param stream - Stream to resume\n * @param eraseRowCount - erase output rows count\n */\n public resume(stream: StreamType, eraseRowCount?: number): void {\n if (this.#isSuspended) {\n this.#isSuspended = false;\n\n if (eraseRowCount) {\n this.erase(stream, eraseRowCount);\n }\n\n this.#lastLength = 0;\n\n Object.values(this.#stream).forEach((hook) => hook.active());\n }\n }\n\n /**\n * Suspend active hooks for external output\n *\n * @param stream - Stream to suspend\n * @param erase - erase output\n */\n public suspend(stream: StreamType, erase = true): void {\n if (!this.#isSuspended) {\n this.#isSuspended = true;\n\n if (erase) {\n this.erase(stream);\n }\n\n Object.values(this.#stream).forEach((hook) => hook.renew());\n }\n }\n\n /**\n * Unhooks both stdout and stderr streams and print their story of logs\n *\n * @param separateHistory - If `true`, will add an empty line to the history output for individual recorded lines and console logs\n *\n * @returns Success status\n */\n public unhook(separateHistory = true): boolean {\n if (this.#isActive) {\n Object.values(this.#stream).forEach((hook) => hook.inactive(separateHistory));\n\n this._clear();\n }\n\n return !this.#isActive;\n }\n\n /**\n * Update output\n *\n * @param stream - Stream to write to\n * @param rows - Text lines to write to standard output\n * @param from - Index of the line starting from which the contents of the terminal are being overwritten\n */\n public update(stream: StreamType, rows: string[], from = 0): void {\n if (rows.length > 0) {\n // eslint-disable-next-line security/detect-object-injection,@typescript-eslint/no-unnecessary-condition\n if (this.#stream[stream] === undefined) {\n throw new TypeError(`Stream \"${stream}\" is not available`);\n }\n\n // eslint-disable-next-line security/detect-object-injection\n const hook = this.#stream[stream];\n\n const { columns: width, rows: height } = terminalSize();\n\n const position = from > height ? height - 1 : Math.max(0, Math.min(height - 1, from));\n const actualLength = this.lastLength - position;\n const outside = Math.max(actualLength - height, this.outside);\n\n // eslint-disable-next-line unicorn/no-array-reduce\n let output = rows.reduce<string[]>(\n (accumulator, row) => [\n ...accumulator,\n wrapAnsi(row, width, {\n hard: true,\n trim: false,\n wordWrap: true,\n }),\n ],\n [],\n );\n\n if (height <= actualLength) {\n hook.erase(height);\n\n if (position < outside) {\n output = output.slice(outside - position + 1);\n }\n } else if (actualLength) {\n hook.erase(actualLength);\n }\n\n hook.write(output.join(\"\\n\") + \"\\n\");\n\n this.#lastLength = outside ? outside + output.length + 1 : output.length;\n this.#outside = Math.max(this.lastLength - height, this.outside);\n }\n }\n\n private _clear(status = false): void {\n this.#isActive = status;\n this.#lastLength = 0;\n this.#outside = 0;\n }\n}\n","import { StringDecoder } from \"node:string_decoder\";\n\nimport { cursorHide, cursorShow, eraseLines } from \"../util/ansi-escapes\";\n\nexport class InteractiveStreamHook {\n public static readonly DRAIN = true;\n\n readonly #decoder = new StringDecoder();\n\n #history: string[] = [];\n\n readonly #method: NodeJS.WriteStream[\"write\"];\n\n readonly #stream: NodeJS.WriteStream;\n\n public constructor(stream: NodeJS.WriteStream) {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n this.#method = stream.write;\n this.#stream = stream;\n }\n\n public active(): void {\n this.write(cursorHide as string);\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment,@typescript-eslint/prefer-ts-expect-error\n // @ts-ignore - We are modifying the write method\n this.#stream.write = (data: Uint8Array | string, ...arguments_: [((error?: Error) => void)?] | [(string | undefined)?, ((error?: Error) => void)?]) => {\n const callback = arguments_.at(-1);\n\n this.#history.push(\n this.#decoder.write(\n typeof data === \"string\"\n ? Buffer.from(data, typeof arguments_[0] === \"string\" ? (arguments_[0] as BufferEncoding) : undefined)\n : Buffer.from(data),\n ),\n );\n\n if (typeof callback === \"function\") {\n callback();\n }\n\n return InteractiveStreamHook.DRAIN;\n };\n }\n\n public erase(count: number): void {\n if (count > 0) {\n this.write(eraseLines(count + 1) as string);\n }\n }\n\n public inactive(separateHistory = false): void {\n if (this.#history.length > 0) {\n if (separateHistory) {\n this.write(\"\\n\");\n }\n\n this.#history.forEach((element) => {\n this.write(element);\n });\n this.#history = [];\n }\n\n this.renew();\n }\n\n public renew(): void {\n this.#stream.write = this.#method;\n this.write(cursorShow as string);\n }\n\n public write(message: string): void {\n this.#method.apply(this.#stream, [message]);\n }\n}\n","const ESC = \"\\u001B[\";\n\nconst eraseScreen = ESC + \"2J\";\nconst eraseLine = ESC + \"2K\";\n\nconst cursorLeft = ESC + \"G\";\nconst cursorUp = (count = 1) => ESC + count + \"A\";\n\nexport const clearTerminal: string =\n process.platform === \"win32\"\n ? `${eraseScreen}${ESC}0f`\n : // 1. Erases the screen (Only done in case `2` is not supported)\n // 2. Erases the whole screen including scrollback buffer\n // 3. Moves cursor to the top-left position\n // More info: https://www.real-world-systems.com/docs/ANSIcode.html\n `${eraseScreen}${ESC}3J${ESC}H`;\n\nexport const cursorHide: string = ESC + \"?25l\";\nexport const cursorShow: string = ESC + \"?25h\";\n\nexport const eraseLines = (count: number): string => {\n let clear = \"\";\n\n // eslint-disable-next-line no-loops/no-loops,no-plusplus\n for (let index = 0; index < count; index++) {\n clear += eraseLine + (index < count - 1 ? cursorUp() : \"\");\n }\n\n if (count) {\n clear += cursorLeft;\n }\n\n return clear;\n};\n","import type { stringify } from \"safe-stable-stringify\";\n\nimport type { InteractiveManager } from \"../../interactive/interactive-manager\";\nimport type { ReadonlyMeta, StreamAwareReporter, StringifyAwareReporter } from \"../../types\";\nimport { writeStream } from \"../../util/write-stream\";\n\nexport class RawReporter<L extends string = never> implements StreamAwareReporter<L>, StringifyAwareReporter<L> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n #stringify: typeof stringify | undefined;\n\n #stdout: NodeJS.WriteStream;\n\n #stderr: NodeJS.WriteStream;\n\n #interactiveManager: InteractiveManager | undefined;\n\n #interactive = false;\n\n public constructor() {\n this.#stdout = process.stdout;\n this.#stderr = process.stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStdout(stdout: NodeJS.WriteStream) {\n this.#stdout = stdout;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStderr(stderr: NodeJS.WriteStream) {\n this.#stderr = stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n public setStringify(function_: any): void {\n this.#stringify = function_;\n }\n\n public setInteractiveManager(manager?: InteractiveManager): void {\n this.#interactiveManager = manager;\n }\n\n public setIsInteractive(interactive: boolean): void {\n this.#interactive = interactive;\n }\n\n public log(meta: ReadonlyMeta<L>): void {\n const { context, groups, message, type } = meta;\n\n const items: string[] = [];\n\n const formattedMessage: string | undefined = typeof message === \"string\" ? message : (this.#stringify as typeof stringify)(message);\n\n items.push(formattedMessage + \"\");\n\n if (context) {\n items.push(\n ...context.map((value) => {\n if (typeof value === \"object\") {\n return \" \" + (this.#stringify as typeof stringify)(value);\n }\n\n return \" \" + value;\n }),\n );\n }\n\n const streamType = [\"error\", \"trace\", \"warn\"].includes(type.level as string) ? \"stderr\" : \"stdout\";\n const stream = streamType === \"stderr\" ? this.#stderr : this.#stdout;\n const groupSpaces: string = groups.map(() => \" \").join(\"\");\n\n if (this.#interactive && this.#interactiveManager !== undefined && stream.isTTY) {\n this.#interactiveManager.update(streamType, (groupSpaces + items.join(\"\")).split(\"\\n\"), 0);\n } else {\n writeStream(groupSpaces + items.join(\"\"), stream);\n }\n }\n}\n","import { InteractiveManager } from \"./interactive/interactive-manager\";\nimport { InteractiveStreamHook } from \"./interactive/interactive-stream-hook\";\nimport { PailBrowserImpl } from \"./pail.browser\";\nimport { RawReporter } from \"./reporter/raw/raw.server\";\nimport type {\n ConstructorOptions,\n DefaultLogTypes,\n InteractiveStreamReporter,\n LiteralUnion,\n LoggerFunction,\n LoggerTypesAwareReporter,\n Reporter,\n ServerConstructorOptions,\n StreamAwareReporter,\n StringifyAwareReporter,\n} from \"./types\";\nimport { clearTerminal } from \"./util/ansi-escapes\";\n\nclass PailServerImpl<T extends string = never, L extends string = never> extends PailBrowserImpl<T, L> {\n protected readonly stdout: NodeJS.WriteStream;\n\n protected readonly stderr: NodeJS.WriteStream;\n\n protected interactiveManager: InteractiveManager | undefined;\n\n protected readonly interactive: boolean;\n\n public constructor(public readonly options: ServerConstructorOptions<T, L> = {}) {\n const { interactive, rawReporter, reporters, stderr, stdout, ...rest } = options;\n\n super(rest as ConstructorOptions<T, L>);\n\n this.interactive = interactive ?? false;\n\n this.stdout = stdout as NodeJS.WriteStream;\n this.stderr = stderr as NodeJS.WriteStream;\n\n if (this.interactive) {\n this.interactiveManager = new InteractiveManager(new InteractiveStreamHook(this.stdout), new InteractiveStreamHook(this.stderr));\n }\n\n if (Array.isArray(reporters)) {\n this.registerReporters(reporters);\n }\n\n this.rawReporter = this.extendReporter(options.rawReporter ?? new RawReporter<L>());\n }\n\n public override scope<N extends string = T>(...name: string[]): PailServerType<N, L> {\n if (name.length === 0) {\n throw new Error(\"No scope name was defined.\");\n }\n\n this.scopeName = name.flat();\n\n return this as unknown as PailServerType<N, L>;\n }\n\n public getInteractiveManager(): InteractiveManager | undefined {\n return this.interactiveManager;\n }\n\n public wrapStd() {\n this._wrapStream(this.stdout, \"log\");\n this._wrapStream(this.stderr, \"log\");\n }\n\n public restoreStd() {\n this._restoreStream(this.stdout);\n this._restoreStream(this.stderr);\n }\n\n public wrapAll(): void {\n this.wrapConsole();\n this.wrapStd();\n }\n\n public restoreAll(): void {\n this.restoreConsole();\n this.restoreStd();\n }\n\n public override clear(): void {\n this.stdout.write(clearTerminal as string);\n this.stderr.write(clearTerminal as string);\n }\n\n protected override extendReporter(reporter: Reporter<L>): Reporter<L> {\n if (typeof (reporter as StreamAwareReporter<L>).setStdout === \"function\") {\n (reporter as StreamAwareReporter<L>).setStdout(this.stdout);\n }\n\n if (typeof (reporter as StreamAwareReporter<L>).setStderr === \"function\") {\n (reporter as StreamAwareReporter<L>).setStderr(this.stderr);\n }\n\n if (typeof (reporter as LoggerTypesAwareReporter<T, L>).setLoggerTypes === \"function\") {\n (reporter as LoggerTypesAwareReporter<T, L>).setLoggerTypes(this.types);\n }\n\n if (typeof (reporter as StringifyAwareReporter<L>).setStringify === \"function\") {\n (reporter as StringifyAwareReporter<L>).setStringify(this.stringify);\n }\n\n if (typeof (reporter as InteractiveStreamReporter<L>).setIsInteractive === \"function\") {\n (reporter as InteractiveStreamReporter<L>).setIsInteractive(this.interactive);\n }\n\n if (this.interactive && typeof (reporter as InteractiveStreamReporter<L>).setInteractiveManager === \"function\") {\n (reporter as InteractiveStreamReporter<L>).setInteractiveManager(this.interactiveManager);\n }\n\n return reporter;\n }\n\n private _wrapStream(stream: NodeJS.WriteStream | undefined, type: LiteralUnion<DefaultLogTypes, L>) {\n if (!stream) {\n return;\n }\n\n // Backup original value\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if (!(stream as any).__write) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign,@typescript-eslint/unbound-method\n (stream as any).__write = stream.write;\n }\n\n // Override\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n (stream as any).write = (data: any): void => {\n // @TODO: Fix typings\n // @ts-expect-error - dynamic property\n // eslint-disable-next-line security/detect-object-injection\n (this as unknown as PailServerImpl)[type].log(String(data).trim());\n };\n }\n\n // eslint-disable-next-line class-methods-use-this\n private _restoreStream(stream?: NodeJS.WriteStream): void {\n if (!stream) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n if ((stream as any).__write) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n stream.write = (stream as any).__write;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any,no-param-reassign\n delete (stream as any).__write;\n }\n }\n}\n\nexport type PailServerType<T extends string = never, L extends string = never> = PailServerImpl<T, L> &\n Record<DefaultLogTypes, LoggerFunction> &\n Record<T, LoggerFunction> &\n (new<TC extends string = never, LC extends string = never>(options?: ServerConstructorOptions<TC, LC>) => PailServerType<TC, LC>);\n\nexport type PailConstructor<T extends string = never, L extends string = never> = new (options?: ServerConstructorOptions<T, L>) => PailServerType<T, L>;\n\nexport const PailServer = PailServerImpl as unknown as PailServerType;\n","import type { PailServerType } from \"./pail.server\";\nimport { PailServer } from \"./pail.server\";\nimport { ErrorProcessor } from \"./processor/error/error-processor\";\nimport { MessageFormatterProcessor } from \"./processor/message-formatter-processor\";\nimport { PrettyReporter } from \"./reporter/pretty/pretty.server\";\nimport type { ConstructorOptions, ExtendedRfc5424LogLevels } from \"./types\";\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\nconst _getDefaultLogLevel = (): ExtendedRfc5424LogLevels => {\n if (process.env[\"NODE_ENV\"] === \"debug\" || process.env[\"DEBUG\"] !== undefined) {\n return \"debug\";\n }\n\n if (process.env[\"NODE_ENV\"] === \"test\") {\n return \"warning\";\n }\n\n return \"informational\";\n};\n\nexport const createPail = <T extends string = never, L extends string = never>(options?: ConstructorOptions<T, L>): PailServerType<T, L> =>\n new PailServer<T, L>({\n logLevel: _getDefaultLogLevel(),\n processors: [new MessageFormatterProcessor<L>(), new ErrorProcessor<L>()],\n reporters: [new PrettyReporter()],\n stderr: process.stderr,\n stdout: process.stdout,\n ...options,\n });\n\nexport const pail = createPail();\n\nexport type { PailServerType as Pail } from \"./pail.server\";\nexport type {\n ConstructorOptions,\n DefaultLoggerTypes,\n DefaultLogTypes,\n ExtendedRfc5424LogLevels,\n LoggerConfiguration,\n LoggerFunction,\n LoggerTypesAwareReporter,\n LoggerTypesConfig,\n Processor,\n Reporter,\n StreamAwareReporter,\n} from \"./shared\";\n"]}
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'safe-stable-stringify';
2
- import { a as DefaultLogTypes, b as LoggerFunction, C as ConstructorOptions, M as Meta, d as LoggerTypesConfig, e as LiteralUnion, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter } from './types-Eye5gXn9.js';
2
+ import { a as DefaultLogTypes, b as LoggerFunction, C as ConstructorOptions, M as Meta, d as LoggerTypesConfig, e as LiteralUnion, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter } from './types--_CcxoUw.js';
3
3
 
4
4
  declare class PailBrowserImpl<T extends string = never, L extends string = never> {
5
5
  protected timersMap: Map<string, number>;
@@ -1,5 +1,5 @@
1
1
  import { stringify } from 'safe-stable-stringify';
2
- import { a as DefaultLogTypes, b as LoggerFunction, C as ConstructorOptions, M as Meta, d as LoggerTypesConfig, e as LiteralUnion, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter } from './types-Eye5gXn9.cjs';
2
+ import { a as DefaultLogTypes, b as LoggerFunction, C as ConstructorOptions, M as Meta, d as LoggerTypesConfig, e as LiteralUnion, P as Processor, E as ExtendedRfc5424LogLevels, R as Reporter } from './types--_CcxoUw.cjs';
3
3
 
4
4
  declare class PailBrowserImpl<T extends string = never, L extends string = never> {
5
5
  protected timersMap: Map<string, number>;
@@ -1,5 +1,5 @@
1
1
  import { FormatterFunction } from '@visulima/fmt';
2
- import { j as StringifyAwareProcessor, M as Meta } from './types-Eye5gXn9.cjs';
2
+ import { j as StringifyAwareProcessor, M as Meta } from './types--_CcxoUw.cjs';
3
3
  import '@visulima/colorize';
4
4
 
5
5
  declare class MessageFormatterProcessor<L extends string = string> implements StringifyAwareProcessor<L> {
@@ -1,5 +1,5 @@
1
1
  import { FormatterFunction } from '@visulima/fmt';
2
- import { j as StringifyAwareProcessor, M as Meta } from './types-Eye5gXn9.js';
2
+ import { j as StringifyAwareProcessor, M as Meta } from './types--_CcxoUw.js';
3
3
  import '@visulima/colorize';
4
4
 
5
5
  declare class MessageFormatterProcessor<L extends string = string> implements StringifyAwareProcessor<L> {
@@ -1,4 +1,4 @@
1
- import { P as Processor, M as Meta } from './types-Eye5gXn9.cjs';
1
+ import { P as Processor, M as Meta } from './types--_CcxoUw.cjs';
2
2
  export { MessageFormatterProcessor } from './processor.browser.cjs';
3
3
  import '@visulima/colorize';
4
4
  import '@visulima/fmt';
@@ -1,4 +1,4 @@
1
- import { P as Processor, M as Meta } from './types-Eye5gXn9.js';
1
+ import { P as Processor, M as Meta } from './types--_CcxoUw.js';
2
2
  export { MessageFormatterProcessor } from './processor.browser.js';
3
3
  import '@visulima/colorize';
4
4
  import '@visulima/fmt';
@@ -1,5 +1,5 @@
1
- import { e as LiteralUnion, E as ExtendedRfc5424LogLevels, g as ReadonlyMeta } from './types-Eye5gXn9.cjs';
2
- import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter--LLgYlnT.cjs';
1
+ import { e as LiteralUnion, E as ExtendedRfc5424LogLevels, g as ReadonlyMeta } from './types--_CcxoUw.cjs';
2
+ import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-SBWxNXW5.cjs';
3
3
  import '@visulima/colorize';
4
4
  import 'safe-stable-stringify';
5
5
 
@@ -1,5 +1,5 @@
1
- import { e as LiteralUnion, E as ExtendedRfc5424LogLevels, g as ReadonlyMeta } from './types-Eye5gXn9.js';
2
- import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-OoXjZn2H.js';
1
+ import { e as LiteralUnion, E as ExtendedRfc5424LogLevels, g as ReadonlyMeta } from './types--_CcxoUw.js';
2
+ import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-L82dKD7X.js';
3
3
  import '@visulima/colorize';
4
4
  import 'safe-stable-stringify';
5
5
 
@@ -1,6 +1,6 @@
1
1
  import { Options as Options$1 } from 'rotating-file-stream';
2
- import { R as Reporter, g as ReadonlyMeta, M as Meta, S as StreamAwareReporter, e as LiteralUnion, E as ExtendedRfc5424LogLevels, i as InteractiveStreamReporter, I as InteractiveManager } from './types-Eye5gXn9.cjs';
3
- import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter--LLgYlnT.cjs';
2
+ import { R as Reporter, g as ReadonlyMeta, M as Meta, S as StreamAwareReporter, e as LiteralUnion, E as ExtendedRfc5424LogLevels, i as InteractiveStreamReporter, I as InteractiveManager } from './types--_CcxoUw.cjs';
3
+ import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-SBWxNXW5.cjs';
4
4
  import '@visulima/colorize';
5
5
  import 'safe-stable-stringify';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { Options as Options$1 } from 'rotating-file-stream';
2
- import { R as Reporter, g as ReadonlyMeta, M as Meta, S as StreamAwareReporter, e as LiteralUnion, E as ExtendedRfc5424LogLevels, i as InteractiveStreamReporter, I as InteractiveManager } from './types-Eye5gXn9.js';
3
- import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-OoXjZn2H.js';
2
+ import { R as Reporter, g as ReadonlyMeta, M as Meta, S as StreamAwareReporter, e as LiteralUnion, E as ExtendedRfc5424LogLevels, i as InteractiveStreamReporter, I as InteractiveManager } from './types--_CcxoUw.js';
3
+ import { A as AbstractJsonReporter, a as AbstractPrettyReporter, P as PrettyStyleOptions } from './abstract-pretty-reporter-L82dKD7X.js';
4
4
  import '@visulima/colorize';
5
5
  import 'safe-stable-stringify';
6
6
 
@@ -4,7 +4,7 @@ import { a } from './chunk-TAH23BHM.js';
4
4
  import './chunk-ZB7IIFHO.js';
5
5
  import './chunk-NF47XQ47.js';
6
6
  import { createStream } from 'rotating-file-stream';
7
- import h from 'process';
7
+ import h from 'node:process';
8
8
 
9
9
  var n=class{_ready=!0;_stream;_name;constructor(t,r){this._stream=t,this._name=r;}write(t){this.writeStream(t);}end(...t){this._stream.end(...t);}writeStream(t){if(!this._ready){console.warn("Stream busy: "+this._name+'. Write will be dropped: "'+t+'"');return}this._ready=!1,this._stream.on("error",r=>{throw r}),this._stream.on("drain",()=>{this._ready=!0;}),this._stream.on("finish",()=>{this._ready=!0;}),this._ready=this._stream.write(t,()=>{});}};var p=class{_filePath;_immediate;_stream;_options;constructor(t,r=!1,e={}){this._filePath=t,this._immediate=r,this._options=e,this._immediate||(this._stream=createStream(this._filePath,e));}write(t){let r=this._stream;this._immediate&&(r=createStream(this._filePath,this._options));let e=new n(r,this._filePath);e.write(t),this._immediate&&e.end();}end(){this._stream!==void 0&&this._stream.end();}};var o=class{_stream;constructor(t){let{filePath:r,writeImmediately:e=!1,...y}=t;this._stream=new p(r,e,y);}log(t){this._stream.write(this._formatMessage(t)+`
10
10
  `);}};var m=class extends o{#t;constructor(t){super({compress:"gzip",interval:"1d",size:"10M",...t});}setStringify(t){this.#t=t;}_formatMessage(t){let{type:r,...e}=t;return e.label&&(e.label=e.label.trim()),e.file&&(e.file=e.file.name+":"+e.file.line+(e.file.column?":"+e.file.column:"")),this.#t(e)}};var l=class extends a{#t;#e;constructor(){super(),this.#t=h.stdout,this.#e=h.stderr;}setStdout(t){this.#t=t;}setStderr(t){this.#e=t;}_log(t,r){let e=["error","warn"].includes(r)?this.#e:this.#t;a$1(t+`
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/util/rotating-file-stream.ts","../src/util/safe-stream-handler.ts","../src/reporter/file/abstract-file-reporter.ts","../src/reporter/file/json-file-reporter.ts","../src/reporter/json/json.server.ts"],"names":["createRfsStream","SafeStreamHandler","stream","name","message","arguments_","error","RotatingFileStream","filePath","writeImmediately","options","fileStream","AbstractFileReporter","rfsOptions","meta","JsonFileReporter","#stringify","function_","type","rest","process","JsonReporter","AbstractJsonReporter","#stdout","#stderr","stdout","stderr","logLevel","writeStream"],"mappings":"+IAGA,OAAS,gBAAgBA,MAAuB,uBCGzC,IAAMC,EAAN,KAAwB,CACpB,OAAS,GAEN,QAEA,MAEH,YAAYC,EAAkBC,EAAc,CAC/C,KAAK,QAAUD,EACf,KAAK,MAAQC,CACjB,CAMO,MAAMC,EAAuB,CAChC,KAAK,YAAYA,CAAO,CAC5B,CAMO,OAAOC,EAAyB,CACnC,KAAK,QAAQ,IAAI,GAAGA,CAAU,CAClC,CAEU,YAAYD,EAAuB,CACzC,GAAI,CAAC,KAAK,OAAQ,CAEd,QAAQ,KAAK,gBAAkB,KAAK,MAAQ,6BAA+BA,EAAU,GAAG,EACxF,MACJ,CACA,KAAK,OAAS,GAEd,KAAK,QAAQ,GAAG,QAAUE,GAAU,CAChC,MAAMA,CACV,CAAC,EACD,KAAK,QAAQ,GAAG,QAAS,IAAM,CAC3B,KAAK,OAAS,EAClB,CAAC,EACD,KAAK,QAAQ,GAAG,SAAU,IAAM,CAC5B,KAAK,OAAS,EAClB,CAAC,EACD,KAAK,OAAS,KAAK,QAAQ,MAAMF,EAAS,IAAM,CAAC,CAAC,CACtD,CACJ,ED1CO,IAAMG,EAAN,KAAyB,CACX,UAEA,WAEA,QAEA,SAEV,YAAYC,EAAkBC,EAAmB,GAAOC,EAA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AAN,cAAqDC,CAA0D,CAClHC,GAEAC,GAEO,aAAc,CACjB,MAAM,EAEN,KAAKD,GAAUH,EAAQ,OACvB,KAAKI,GAAUJ,EAAQ,MAC3B,CAGO,UAAUK,EAA4B,CACzC,KAAKF,GAAUE,CACnB,CAGO,UAAUC,EAA4B,CACzC,KAAKF,GAAUE,CACnB,CAEmB,KAAKtB,EAAiBuB,EAA2D,CAChG,IAAMzB,EAAS,CAAC,QAAS,MAAM,EAAE,SAASyB,CAAkB,EAAI,KAAKH,GAAU,KAAKD,GAEpFK,EAAYxB,EAAU;AAAA,EAAMF,CAAM,CACtC,CACJ","sourcesContent":["import type { Writable } from \"node:stream\";\n\nimport type { Options as RfsOptions } from \"rotating-file-stream\";\nimport { createStream as createRfsStream } from \"rotating-file-stream\";\n\nimport { SafeStreamHandler } from \"./safe-stream-handler\";\n\n/**\n * A wrapper for the `rfs` module that will optionally write to disk immediately\n * by creating and closing a new stream on each write.\n */\nexport class RotatingFileStream {\n private readonly _filePath: string;\n\n private readonly _immediate: boolean;\n\n private readonly _stream: Writable | undefined;\n\n private readonly _options: RfsOptions;\n\n public constructor(filePath: string, writeImmediately = false, options: RfsOptions = {}) {\n this._filePath = filePath;\n this._immediate = writeImmediately;\n this._options = options;\n\n if (!this._immediate) {\n this._stream = createRfsStream(this._filePath, options);\n }\n }\n\n /**\n * Writes `message` to the instance's internal _stream\n * @param message Message to write\n */\n public write(message: string): void {\n let fileStream = this._stream;\n\n if (this._immediate) {\n fileStream = createRfsStream(this._filePath, this._options);\n }\n\n const stream = new SafeStreamHandler(fileStream as Writable, this._filePath);\n\n stream.write(message);\n\n if (this._immediate) {\n stream.end();\n }\n }\n\n /**\n * Ends the instance's internal _stream\n *\n * When `immediate` is not `true`, a call to `write` after calling this method\n * will throw an error.\n */\n public end(): void {\n if (this._stream !== undefined) {\n this._stream.end();\n }\n }\n}\n","import type { Writable } from \"node:stream\";\n\n/**\n * A handler for writable streams that only writes if the stream has finished\n * processing or draining\n */\nexport class SafeStreamHandler {\n public _ready = true;\n\n protected _stream: Writable;\n\n protected _name: string;\n\n public constructor(stream: Writable, name: string) {\n this._stream = stream;\n this._name = name;\n }\n\n /**\n * Writes `message` to the instance's internal stream\n * @param message Message to write\n */\n public write(message: string): void {\n this.writeStream(message);\n }\n\n /**\n * Calls `end` on this instance's internal stream\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public end(...arguments_: any[]): void {\n this._stream.end(...arguments_);\n }\n\n protected writeStream(message: string): void {\n if (!this._ready) {\n // eslint-disable-next-line no-console\n console.warn(\"Stream busy: \" + this._name + '. Write will be dropped: \"' + message + '\"');\n return;\n }\n this._ready = false;\n\n this._stream.on(\"error\", (error) => {\n throw error;\n });\n this._stream.on(\"drain\", () => {\n this._ready = true;\n });\n this._stream.on(\"finish\", () => {\n this._ready = true;\n });\n this._ready = this._stream.write(message, () => {});\n }\n}\n","import type { Options as RfsOptions } from \"rotating-file-stream\";\n\nimport type { ReadonlyMeta, Reporter } from \"../../types\";\nimport { RotatingFileStream } from \"../../util/rotating-file-stream\";\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type Options = RfsOptions & {\n filePath: string;\n writeImmediately?: boolean;\n};\n\nexport abstract class AbstractFileReporter<L extends string = never> implements Reporter<L> {\n protected _stream: RotatingFileStream;\n\n protected constructor(options: Options) {\n const { filePath, writeImmediately = false, ...rfsOptions } = options;\n\n this._stream = new RotatingFileStream(filePath, writeImmediately, rfsOptions);\n }\n\n public log(meta: ReadonlyMeta<L>): void {\n this._stream.write(this._formatMessage(meta as ReadonlyMeta<L>) + \"\\n\");\n }\n\n protected abstract _formatMessage(data: ReadonlyMeta<L>): string;\n}\n","import type { stringify } from \"safe-stable-stringify\";\n\nimport type { Meta } from \"../../types\";\nimport type { Options as FileReporterOptions } from \"./abstract-file-reporter\";\nimport { AbstractFileReporter } from \"./abstract-file-reporter\";\n\nexport class JsonFileReporter<L extends string = never> extends AbstractFileReporter<L> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n #stringify: typeof stringify | undefined;\n\n public constructor(options: FileReporterOptions) {\n super({\n compress: \"gzip\", // compress rotated files\n interval: \"1d\", // rotate daily\n size: \"10M\", // rotate every 10 MegaBytes written\n ...options,\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n public setStringify(function_: any): void {\n this.#stringify = function_;\n }\n\n protected _formatMessage(meta: Meta<L>): string {\n const { type, ...rest } = meta;\n\n if (rest.label) {\n rest.label = rest.label.trim();\n }\n\n if (rest.file) {\n // This is a hack to make the file property a string\n (rest as unknown as Omit<Meta<L>, \"file\"> & { file: string }).file =\n rest.file.name + \":\" + rest.file.line + (rest.file.column ? \":\" + rest.file.column : \"\");\n }\n\n return (this.#stringify as typeof stringify)(rest) as string;\n }\n}\n","import process from \"node:process\";\n\nimport type { ExtendedRfc5424LogLevels, LiteralUnion, StreamAwareReporter } from \"../../types\";\nimport { writeStream } from \"../../util/write-stream\";\nimport { AbstractJsonReporter } from \"./abstract-json-reporter\";\n\nexport class JsonReporter<L extends string = never> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {\n #stdout: NodeJS.WriteStream;\n\n #stderr: NodeJS.WriteStream;\n\n public constructor() {\n super();\n\n this.#stdout = process.stdout;\n this.#stderr = process.stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStdout(stdout: NodeJS.WriteStream) {\n this.#stdout = stdout;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStderr(stderr: NodeJS.WriteStream) {\n this.#stderr = stderr;\n }\n\n protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void {\n const stream = [\"error\", \"warn\"].includes(logLevel as string) ? this.#stderr : this.#stdout;\n\n writeStream(message + \"\\n\", stream);\n }\n}\n"]}
1
+ {"version":3,"sources":["../src/util/rotating-file-stream.ts","../src/util/safe-stream-handler.ts","../src/reporter/file/abstract-file-reporter.ts","../src/reporter/file/json-file-reporter.ts","../src/reporter/json/json.server.ts"],"names":["createRfsStream","SafeStreamHandler","stream","name","message","arguments_","error","RotatingFileStream","filePath","writeImmediately","options","fileStream","AbstractFileReporter","rfsOptions","meta","JsonFileReporter","#stringify","function_","type","rest","process","JsonReporter","AbstractJsonReporter","#stdout","#stderr","stdout","stderr","logLevel","writeStream"],"mappings":"+IAGA,OAAS,gBAAgBA,MAAuB,uBCGzC,IAAMC,EAAN,KAAwB,CACpB,OAAS,GAEN,QAEA,MAEH,YAAYC,EAAkBC,EAAc,CAC/C,KAAK,QAAUD,EACf,KAAK,MAAQC,CACjB,CAMO,MAAMC,EAAuB,CAChC,KAAK,YAAYA,CAAO,CAC5B,CAMO,OAAOC,EAAyB,CACnC,KAAK,QAAQ,IAAI,GAAGA,CAAU,CAClC,CAEU,YAAYD,EAAuB,CACzC,GAAI,CAAC,KAAK,OAAQ,CAEd,QAAQ,KAAK,gBAAkB,KAAK,MAAQ,6BAA+BA,EAAU,GAAG,EACxF,MACJ,CACA,KAAK,OAAS,GAEd,KAAK,QAAQ,GAAG,QAAUE,GAAU,CAChC,MAAMA,CACV,CAAC,EACD,KAAK,QAAQ,GAAG,QAAS,IAAM,CAC3B,KAAK,OAAS,EAClB,CAAC,EACD,KAAK,QAAQ,GAAG,SAAU,IAAM,CAC5B,KAAK,OAAS,EAClB,CAAC,EACD,KAAK,OAAS,KAAK,QAAQ,MAAMF,EAAS,IAAM,CAAC,CAAC,CACtD,CACJ,ED1CO,IAAMG,EAAN,KAAyB,CACX,UAEA,WAEA,QAEA,SAEV,YAAYC,EAAkBC,EAAmB,GAAOC,EAAsB,CAAC,EAAG,CACrF,KAAK,UAAYF,EACjB,KAAK,WAAaC,EAClB,KAAK,SAAWC,EAEX,KAAK,aACN,KAAK,QAAUV,EAAgB,KAAK,UAAWU,CAAO,EAE9D,CAMO,MAAMN,EAAuB,CAChC,IAAIO,EAAa,KAAK,QAElB,KAAK,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,KAAKF,GAAUE,CACnB,CAEmB,KAAKtB,EAAiBuB,EAA2D,CAChG,IAAMzB,EAAS,CAAC,QAAS,MAAM,EAAE,SAASyB,CAAkB,EAAI,KAAKH,GAAU,KAAKD,GAEpFK,EAAYxB,EAAU;AAAA,EAAMF,CAAM,CACtC,CACJ","sourcesContent":["import type { Writable } from \"node:stream\";\n\nimport type { Options as RfsOptions } from \"rotating-file-stream\";\nimport { createStream as createRfsStream } from \"rotating-file-stream\";\n\nimport { SafeStreamHandler } from \"./safe-stream-handler\";\n\n/**\n * A wrapper for the `rfs` module that will optionally write to disk immediately\n * by creating and closing a new stream on each write.\n */\nexport class RotatingFileStream {\n private readonly _filePath: string;\n\n private readonly _immediate: boolean;\n\n private readonly _stream: Writable | undefined;\n\n private readonly _options: RfsOptions;\n\n public constructor(filePath: string, writeImmediately = false, options: RfsOptions = {}) {\n this._filePath = filePath;\n this._immediate = writeImmediately;\n this._options = options;\n\n if (!this._immediate) {\n this._stream = createRfsStream(this._filePath, options);\n }\n }\n\n /**\n * Writes `message` to the instance's internal _stream\n * @param message Message to write\n */\n public write(message: string): void {\n let fileStream = this._stream;\n\n if (this._immediate) {\n fileStream = createRfsStream(this._filePath, this._options);\n }\n\n const stream = new SafeStreamHandler(fileStream as Writable, this._filePath);\n\n stream.write(message);\n\n if (this._immediate) {\n stream.end();\n }\n }\n\n /**\n * Ends the instance's internal _stream\n *\n * When `immediate` is not `true`, a call to `write` after calling this method\n * will throw an error.\n */\n public end(): void {\n if (this._stream !== undefined) {\n this._stream.end();\n }\n }\n}\n","import type { Writable } from \"node:stream\";\n\n/**\n * A handler for writable streams that only writes if the stream has finished\n * processing or draining\n */\nexport class SafeStreamHandler {\n public _ready = true;\n\n protected _stream: Writable;\n\n protected _name: string;\n\n public constructor(stream: Writable, name: string) {\n this._stream = stream;\n this._name = name;\n }\n\n /**\n * Writes `message` to the instance's internal stream\n * @param message Message to write\n */\n public write(message: string): void {\n this.writeStream(message);\n }\n\n /**\n * Calls `end` on this instance's internal stream\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n public end(...arguments_: any[]): void {\n this._stream.end(...arguments_);\n }\n\n protected writeStream(message: string): void {\n if (!this._ready) {\n // eslint-disable-next-line no-console\n console.warn(\"Stream busy: \" + this._name + '. Write will be dropped: \"' + message + '\"');\n return;\n }\n this._ready = false;\n\n this._stream.on(\"error\", (error) => {\n throw error;\n });\n this._stream.on(\"drain\", () => {\n this._ready = true;\n });\n this._stream.on(\"finish\", () => {\n this._ready = true;\n });\n this._ready = this._stream.write(message, () => {});\n }\n}\n","import type { Options as RfsOptions } from \"rotating-file-stream\";\n\nimport type { ReadonlyMeta, Reporter } from \"../../types\";\nimport { RotatingFileStream } from \"../../util/rotating-file-stream\";\n\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type Options = RfsOptions & {\n filePath: string;\n writeImmediately?: boolean;\n};\n\nexport abstract class AbstractFileReporter<L extends string = never> implements Reporter<L> {\n protected _stream: RotatingFileStream;\n\n protected constructor(options: Options) {\n const { filePath, writeImmediately = false, ...rfsOptions } = options;\n\n this._stream = new RotatingFileStream(filePath, writeImmediately, rfsOptions);\n }\n\n public log(meta: ReadonlyMeta<L>): void {\n this._stream.write(this._formatMessage(meta as ReadonlyMeta<L>) + \"\\n\");\n }\n\n protected abstract _formatMessage(data: ReadonlyMeta<L>): string;\n}\n","import type { stringify } from \"safe-stable-stringify\";\n\nimport type { Meta } from \"../../types\";\nimport type { Options as FileReporterOptions } from \"./abstract-file-reporter\";\nimport { AbstractFileReporter } from \"./abstract-file-reporter\";\n\nexport class JsonFileReporter<L extends string = never> extends AbstractFileReporter<L> {\n // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\n #stringify: typeof stringify | undefined;\n\n public constructor(options: FileReporterOptions) {\n super({\n compress: \"gzip\", // compress rotated files\n interval: \"1d\", // rotate daily\n size: \"10M\", // rotate every 10 MegaBytes written\n ...options,\n });\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any\n public setStringify(function_: any): void {\n this.#stringify = function_;\n }\n\n protected _formatMessage(meta: Meta<L>): string {\n const { type, ...rest } = meta;\n\n if (rest.label) {\n rest.label = rest.label.trim();\n }\n\n if (rest.file) {\n // This is a hack to make the file property a string\n (rest as unknown as Omit<Meta<L>, \"file\"> & { file: string }).file =\n rest.file.name + \":\" + rest.file.line + (rest.file.column ? \":\" + rest.file.column : \"\");\n }\n\n return (this.#stringify as typeof stringify)(rest) as string;\n }\n}\n","import process from \"node:process\";\n\nimport type { ExtendedRfc5424LogLevels, LiteralUnion, StreamAwareReporter } from \"../../types\";\nimport { writeStream } from \"../../util/write-stream\";\nimport { AbstractJsonReporter } from \"./abstract-json-reporter\";\n\nexport class JsonReporter<L extends string = never> extends AbstractJsonReporter<L> implements StreamAwareReporter<L> {\n #stdout: NodeJS.WriteStream;\n\n #stderr: NodeJS.WriteStream;\n\n public constructor() {\n super();\n\n this.#stdout = process.stdout;\n this.#stderr = process.stderr;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStdout(stdout: NodeJS.WriteStream) {\n this.#stdout = stdout;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n public setStderr(stderr: NodeJS.WriteStream) {\n this.#stderr = stderr;\n }\n\n protected override _log(message: string, logLevel: LiteralUnion<ExtendedRfc5424LogLevels, L>): void {\n const stream = [\"error\", \"warn\"].includes(logLevel as string) ? this.#stderr : this.#stdout;\n\n writeStream(message + \"\\n\", stream);\n }\n}\n"]}
@@ -56,7 +56,10 @@ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
56
56
  }
57
57
  type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
58
58
  type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "watch";
59
- type LoggerFunction = (...message: any[]) => void;
59
+ interface LoggerFunction {
60
+ (...message: any[]): void;
61
+ (message: Message): void;
62
+ }
60
63
  interface LoggerConfiguration<L extends string = never> {
61
64
  badge?: string;
62
65
  color?: AnsiColors | undefined;
@@ -110,5 +113,11 @@ interface ServerConstructorOptions<T extends string = never, L extends string =
110
113
  stderr?: NodeJS.WriteStream;
111
114
  stdout?: NodeJS.WriteStream;
112
115
  }
116
+ type Message = {
117
+ context?: any[] | undefined;
118
+ message: Primitive | ReadonlyArray<unknown> | undefined;
119
+ prefix?: string;
120
+ suffix?: string;
121
+ };
113
122
 
114
123
  export { type ConstructorOptions as C, type DefaultLoggerTypes as D, type ExtendedRfc5424LogLevels as E, InteractiveManager as I, type LoggerConfiguration as L, type Meta as M, type Processor as P, type Reporter as R, type StreamAwareReporter as S, type DefaultLogTypes as a, type LoggerFunction as b, type LoggerTypesAwareReporter as c, type LoggerTypesConfig as d, type LiteralUnion as e, type ServerConstructorOptions as f, type ReadonlyMeta as g, type StringifyAwareReporter as h, type InteractiveStreamReporter as i, type StringifyAwareProcessor as j };
@@ -56,7 +56,10 @@ interface Meta<L> extends VisulimaPail.CustomMeta<L> {
56
56
  }
57
57
  type ExtendedRfc5424LogLevels = "alert" | "critical" | "debug" | "emergency" | "error" | "informational" | "notice" | "trace" | "warning";
58
58
  type DefaultLogTypes = "alert" | "await" | "complete" | "critical" | "debug" | "emergency" | "error" | "info" | "log" | "notice" | "pending" | "start" | "stop" | "success" | "trace" | "wait" | "warn" | "watch";
59
- type LoggerFunction = (...message: any[]) => void;
59
+ interface LoggerFunction {
60
+ (...message: any[]): void;
61
+ (message: Message): void;
62
+ }
60
63
  interface LoggerConfiguration<L extends string = never> {
61
64
  badge?: string;
62
65
  color?: AnsiColors | undefined;
@@ -110,5 +113,11 @@ interface ServerConstructorOptions<T extends string = never, L extends string =
110
113
  stderr?: NodeJS.WriteStream;
111
114
  stdout?: NodeJS.WriteStream;
112
115
  }
116
+ type Message = {
117
+ context?: any[] | undefined;
118
+ message: Primitive | ReadonlyArray<unknown> | undefined;
119
+ prefix?: string;
120
+ suffix?: string;
121
+ };
113
122
 
114
123
  export { type ConstructorOptions as C, type DefaultLoggerTypes as D, type ExtendedRfc5424LogLevels as E, InteractiveManager as I, type LoggerConfiguration as L, type Meta as M, type Processor as P, type Reporter as R, type StreamAwareReporter as S, type DefaultLogTypes as a, type LoggerFunction as b, type LoggerTypesAwareReporter as c, type LoggerTypesConfig as d, type LiteralUnion as e, type ServerConstructorOptions as f, type ReadonlyMeta as g, type StringifyAwareReporter as h, type InteractiveStreamReporter as i, type StringifyAwareProcessor as j };
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@visulima/pail",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Find a file or directory by walking up parent directories.",
5
5
  "keywords": [
6
6
  "anolilab",
7
- "box",
8
- "boxen",
9
7
  "browser",
10
8
  "browser-logger",
11
9
  "callsite",
@@ -166,7 +164,7 @@
166
164
  ],
167
165
  "scripts": {
168
166
  "build": "cross-env NODE_ENV=development tsup",
169
- "build:prod": "cross-env NODE_ENV=production tsup",
167
+ "build:prod": "node ./scripts/wait.js && cross-env NODE_ENV=production tsup",
170
168
  "clean": "rimraf node_modules dist .eslintcache",
171
169
  "dev": "pnpm run build --watch",
172
170
  "lint:eslint": "eslint . --ext js,cjs,mjs,jsx,ts,tsx,json,yaml,yml,md,mdx --max-warnings=0 --config .eslintrc.cjs",
@@ -214,7 +212,7 @@
214
212
  "semantic-release": "^23.0.2",
215
213
  "sort-package-json": "^2.8.0",
216
214
  "tsup": "^8.0.2",
217
- "typescript": "^5.3.3",
215
+ "typescript": "^5.4.2",
218
216
  "vitest": "^1.3.1"
219
217
  },
220
218
  "peerDependencies": {