@visulima/pail 4.0.0-alpha.8 → 4.0.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 (145) hide show
  1. package/CHANGELOG.md +531 -0
  2. package/LICENSE.md +270 -166
  3. package/README.md +53 -24
  4. package/dist/error.d.ts +95 -96
  5. package/dist/error.js +5 -76
  6. package/dist/index.browser.d.ts +568 -47
  7. package/dist/index.browser.js +19 -1499
  8. package/dist/index.server.d.ts +749 -65
  9. package/dist/index.server.js +32 -3179
  10. package/dist/middleware/elysia.d.ts +66 -63
  11. package/dist/middleware/elysia.js +1 -70
  12. package/dist/middleware/express.d.ts +74 -71
  13. package/dist/middleware/express.js +1 -29
  14. package/dist/middleware/fastify.d.ts +70 -67
  15. package/dist/middleware/fastify.js +1 -46
  16. package/dist/middleware/hono.d.ts +75 -72
  17. package/dist/middleware/hono.js +1 -33
  18. package/dist/middleware/next/handler.d.ts +102 -34
  19. package/dist/middleware/next/handler.js +1 -53
  20. package/dist/middleware/sveltekit.d.ts +101 -98
  21. package/dist/middleware/sveltekit.js +1 -43
  22. package/dist/object-tree.d.ts +67 -70
  23. package/dist/object-tree.js +2 -89
  24. package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +1 -0
  25. package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +1 -0
  26. package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +2 -0
  27. package/dist/packem_shared/JsonReporter-bmem9lcg.js +1 -0
  28. package/dist/packem_shared/PailError-CbU1Ogfa.js +5 -0
  29. package/dist/packem_shared/PrettyReporter-CcDdPQSt.js +44 -0
  30. package/dist/packem_shared/PrettyReporter-DsHfKOU7.js +5 -0
  31. package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +62 -0
  32. package/dist/packem_shared/abstract-pretty-reporter-DrLBJ6ds.js +57 -0
  33. package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +25 -0
  34. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  35. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  36. package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +47 -0
  37. package/dist/packem_shared/headers-DH0H2s8W.js +1 -0
  38. package/dist/packem_shared/index-Q1764hvO.js +1 -0
  39. package/dist/packem_shared/index.d-T71KjNAr.d.ts +16 -0
  40. package/dist/packem_shared/pailMiddleware-B5DJoBYl.js +1 -0
  41. package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +1 -0
  42. package/dist/packem_shared/storage-DaXAlpiO.js +1 -0
  43. package/dist/packem_shared/types.d-Cz9S7jZh.d.ts +201 -0
  44. package/dist/packem_shared/types.d-bWnqHJKL.d.ts +211 -0
  45. package/dist/packem_shared/types.d-xxE3FOD3.d.ts +229 -0
  46. package/dist/packem_shared/useLogger-DB34CuU5.js +1 -0
  47. package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +717 -0
  48. package/dist/packem_shared/write-console-log-based-on-level-BqjxV016.js +1 -0
  49. package/dist/packem_shared/write-stream-C7jxLxIT.js +1 -0
  50. package/dist/processor/caller/caller-processor.d.ts +50 -47
  51. package/dist/processor/caller/caller-processor.js +1 -59
  52. package/dist/processor/environment-processor.d.ts +114 -113
  53. package/dist/processor/environment-processor.js +1 -78
  54. package/dist/processor/message-formatter-processor.d.ts +59 -49
  55. package/dist/processor/message-formatter-processor.js +1 -713
  56. package/dist/processor/opentelemetry-processor.d.ts +70 -66
  57. package/dist/processor/opentelemetry-processor.js +1 -52
  58. package/dist/processor/redact-processor.d.ts +99 -41
  59. package/dist/processor/redact-processor.js +1 -30
  60. package/dist/processor/sampling-processor.d.ts +103 -101
  61. package/dist/processor/sampling-processor.js +1 -59
  62. package/dist/reporter/file/json-file-reporter.d.ts +109 -42
  63. package/dist/reporter/file/json-file-reporter.js +2 -136
  64. package/dist/reporter/http/abstract-http-reporter.d.ts +256 -211
  65. package/dist/reporter/http/abstract-http-reporter.js +2 -435
  66. package/dist/reporter/http/http-reporter.d.ts +41 -36
  67. package/dist/reporter/http/http-reporter.edge-light.d.ts +487 -39
  68. package/dist/reporter/http/http-reporter.edge-light.js +2 -733
  69. package/dist/reporter/http/http-reporter.js +1 -13
  70. package/dist/reporter/json/index.browser.d.ts +98 -3
  71. package/dist/reporter/json/index.browser.js +1 -2
  72. package/dist/reporter/json/index.d.ts +53 -3
  73. package/dist/reporter/json/index.js +1 -2
  74. package/dist/reporter/pretty/index.browser.d.ts +105 -2
  75. package/dist/reporter/pretty/index.browser.js +1 -1
  76. package/dist/reporter/pretty/index.d.ts +270 -2
  77. package/dist/reporter/pretty/index.js +1 -1
  78. package/dist/reporter/simple/simple-reporter.server.d.ts +215 -18
  79. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  80. package/dist/wide-event.d.ts +6 -300
  81. package/dist/wide-event.js +1 -281
  82. package/package.json +23 -38
  83. package/dist/constants.d.ts +0 -37
  84. package/dist/interactive/index.d.ts +0 -2
  85. package/dist/interactive/index.js +0 -2
  86. package/dist/interactive/interactive-manager.d.ts +0 -108
  87. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  88. package/dist/middleware/next/middleware.d.ts +0 -59
  89. package/dist/middleware/next/storage.d.ts +0 -14
  90. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  91. package/dist/middleware/shared/headers.d.ts +0 -14
  92. package/dist/middleware/shared/routes.d.ts +0 -30
  93. package/dist/middleware/shared/storage.d.ts +0 -29
  94. package/dist/packem_shared/AbstractJsonReporter-CGKHS8_M.js +0 -286
  95. package/dist/packem_shared/AbstractJsonReporter-DDjDkciI.js +0 -286
  96. package/dist/packem_shared/InteractiveManager-Cd6A14ZK.js +0 -172
  97. package/dist/packem_shared/InteractiveStreamHook-ePIURL_U.js +0 -133
  98. package/dist/packem_shared/JsonReporter-B3XX8GHN.js +0 -58
  99. package/dist/packem_shared/JsonReporter-p_BXg6Sj.js +0 -28
  100. package/dist/packem_shared/PrettyReporter-BYL3NrdA.js +0 -214
  101. package/dist/packem_shared/PrettyReporter-CvBn-hxP.js +0 -1459
  102. package/dist/packem_shared/Spinner-DIdVcfWq.js +0 -2183
  103. package/dist/packem_shared/abstract-pretty-reporter-jU8WL_6c.js +0 -2602
  104. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  105. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  106. package/dist/packem_shared/createPailError-B11aRfrT.js +0 -76
  107. package/dist/packem_shared/getBarChar-BWj1UrH3.js +0 -404
  108. package/dist/packem_shared/headers-Cp4uLtr4.js +0 -123
  109. package/dist/packem_shared/index-DnkF86LQ.js +0 -658
  110. package/dist/packem_shared/index-frijFf5m.js +0 -1252
  111. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  112. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  113. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  114. package/dist/packem_shared/write-console-log-based-on-level-DBmRYXpj.js +0 -14
  115. package/dist/packem_shared/write-stream-BG8fhcs3.js +0 -6
  116. package/dist/pail.browser.d.ts +0 -412
  117. package/dist/pail.server.d.ts +0 -233
  118. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  119. package/dist/progress-bar.d.ts +0 -136
  120. package/dist/progress-bar.js +0 -404
  121. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  122. package/dist/reporter/http/utils/compression.d.ts +0 -7
  123. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  124. package/dist/reporter/http/utils/retry.d.ts +0 -27
  125. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  126. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  127. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  128. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  129. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  130. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  131. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  132. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  133. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  134. package/dist/reporter/utils/format-label.d.ts +0 -3
  135. package/dist/spinner.d.ts +0 -220
  136. package/dist/spinner.js +0 -2183
  137. package/dist/types.d.ts +0 -241
  138. package/dist/utils/ansi-escapes.d.ts +0 -4
  139. package/dist/utils/arrayify.d.ts +0 -2
  140. package/dist/utils/get-longest-badge.d.ts +0 -4
  141. package/dist/utils/get-longest-label.d.ts +0 -4
  142. package/dist/utils/merge-types.d.ts +0 -4
  143. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  144. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  145. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,46 +1,113 @@
1
- import type { Options as RfsOptions } from "rotating-file-stream";
2
- import type { AbstractJsonReporterOptions } from "../json/abstract-json-reporter.d.ts";
3
- import { AbstractJsonReporter } from "../json/abstract-json-reporter.d.ts";
4
- import RotatingFileStream from "./utils/rotating-file-stream.d.ts";
1
+ import { Options } from 'rotating-file-stream';
2
+ import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-wfESoEa-.js";
3
+ import "../../packem_shared/index.d-T71KjNAr.js";
4
+ import 'type-fest';
5
+ import "../../packem_shared/types.d-bWnqHJKL.js";
6
+ import '@visulima/colorize';
7
+ import '@visulima/interactive-manager';
5
8
  /**
6
- * Options for configuring the JsonFileReporter.
7
- */
8
- export type FileReporterOptions = AbstractJsonReporterOptions & RfsOptions & {
9
- /** Path to the log file */
10
- filePath: string;
11
- /** Whether to write immediately to disk instead of buffering */
12
- writeImmediately?: boolean;
9
+ * Rotating File Stream.
10
+ *
11
+ * A wrapper for the `rotating-file-stream` module that provides optional immediate
12
+ * writing to disk by creating and closing a new stream on each write operation.
13
+ * This is useful for ensuring log messages are written immediately rather than buffered.
14
+ * @example
15
+ * ```typescript
16
+ * // Buffered writing (default)
17
+ * const bufferedStream = new RotatingFileStream("/var/log/app.log", false, {
18
+ * interval: "1d",
19
+ * size: "10M"
20
+ * });
21
+ *
22
+ * // Immediate writing
23
+ * const immediateStream = new RotatingFileStream("/var/log/app.log", true, {
24
+ * interval: "1d"
25
+ * });
26
+ * ```
27
+ */
28
+ declare class RotatingFileStream {
29
+ #private;
30
+ /**
31
+ * Creates a new RotatingFileStream instance.
32
+ * @param filePath Path to the log file
33
+ * @param writeImmediately Whether to write immediately or buffer writes
34
+ * @param options Options for the rotating file stream
35
+ * @throws {Error} If the 'rotating-file-stream' package is not installed
36
+ */
37
+ constructor(filePath: string, writeImmediately?: boolean, options?: Options);
38
+ /**
39
+ * Writes a message to the rotating file stream.
40
+ *
41
+ * If writeImmediately was set to true in the constructor, a new stream
42
+ * is created for each write operation. Otherwise, uses the buffered stream.
43
+ * @param message The message to write to the file
44
+ */
45
+ write(message: string): void;
46
+ /**
47
+ * Ends the rotating file stream.
48
+ *
49
+ * Closes the underlying stream. When `writeImmediately` is not `true`,
50
+ * calling `write` after calling this method will throw an error.
51
+ */
52
+ end(): void;
53
+ }
54
+ /**
55
+ * Options for configuring the JsonFileReporter.
56
+ */
57
+ type FileReporterOptions = AbstractJsonReporterOptions & Options & {
58
+ /** Path to the log file */
59
+ filePath: string;
60
+ /** Whether to write immediately to disk instead of buffering */
61
+ writeImmediately?: boolean;
13
62
  };
14
63
  /**
15
- * JSON File Reporter.
16
- *
17
- * A reporter that writes structured JSON log entries to rotating files on disk.
18
- * Supports automatic file rotation based on size, time intervals, and compression.
19
- * @template L - The log level type
20
- * @example
21
- * ```typescript
22
- * const reporter = new JsonFileReporter({
23
- * filePath: "/var/log/app.log",
24
- * interval: "1d", // Rotate daily
25
- * size: "10M", // Rotate when file reaches 10MB
26
- * compress: "gzip"
27
- * });
28
- *
29
- * logger.registerReporters([reporter]);
30
- * ```
31
- */
32
- export declare class JsonFileReporter<L extends string = string> extends AbstractJsonReporter<L> {
33
- /** The rotating file stream instance */
34
- protected stream: RotatingFileStream;
35
- /**
36
- * Creates a new JsonFileReporter instance.
37
- * @param options Configuration options for file rotation and JSON formatting
38
- */
39
- constructor(options: FileReporterOptions);
40
- /**
41
- * Writes a JSON message to the rotating file stream.
42
- * @param message The JSON-formatted log message to write
43
- * @protected
44
- */
45
- protected _log(message: string): void;
64
+ * JSON File Reporter.
65
+ *
66
+ * A reporter that writes structured JSON log entries to rotating files on disk.
67
+ * Supports automatic file rotation based on size, time intervals, and compression.
68
+ * @template L - The log level type
69
+ * @example
70
+ * ```typescript
71
+ * const reporter = new JsonFileReporter({
72
+ * filePath: "/var/log/app.log",
73
+ * interval: "1d", // Rotate daily
74
+ * size: "10M", // Rotate when file reaches 10MB
75
+ * compress: "gzip"
76
+ * });
77
+ *
78
+ * logger.registerReporters([reporter]);
79
+ * ```
80
+ */
81
+ declare class JsonFileReporter<L extends string = string> extends AbstractJsonReporter<L> {
82
+ /** The rotating file stream instance */
83
+ protected stream: RotatingFileStream;
84
+ /**
85
+ * Creates a new JsonFileReporter instance.
86
+ * @param options Configuration options for file rotation and JSON formatting
87
+ */
88
+ constructor(options: FileReporterOptions);
89
+ /**
90
+ * Closes the underlying rotating file stream.
91
+ *
92
+ * Ends the buffered stream so any queued writes are flushed to disk before the
93
+ * process exits. Without this the tail of the log can be lost on a short-lived
94
+ * process. After calling `close()` no further writes should be made (unless
95
+ * `writeImmediately` was enabled, in which case each write owns its own stream).
96
+ * @example
97
+ * ```typescript
98
+ * process.on("beforeExit", () => reporter.close());
99
+ * ```
100
+ */
101
+ close(): void;
102
+ /**
103
+ * Alias for {@link close} to match common transport `dispose` conventions.
104
+ */
105
+ dispose(): void;
106
+ /**
107
+ * Writes a JSON message to the rotating file stream.
108
+ * @param message The JSON-formatted log message to write
109
+ * @protected
110
+ */
111
+ protected override _log(message: string): void;
46
112
  }
113
+ export { FileReporterOptions, JsonFileReporter };
@@ -1,136 +1,2 @@
1
- import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-CGKHS8_M.js';
2
-
3
- class SafeStreamHandler {
4
- #ready = true;
5
- #stream;
6
- #name;
7
- constructor(stream, name) {
8
- this.#stream = stream;
9
- this.#name = name;
10
- }
11
- /**
12
- * Writes `message` to the instance's internal stream.
13
- * @param message Message to write
14
- */
15
- write(message) {
16
- this.writeStream(message);
17
- }
18
- /**
19
- * Calls `end` on this instance's internal stream
20
- */
21
- end(...arguments_) {
22
- this.#stream.end(...arguments_);
23
- }
24
- get isReady() {
25
- return this.#ready;
26
- }
27
- writeStream(message) {
28
- if (!this.#ready) {
29
- console.warn(`Stream busy: ${this.#name}. Write will be dropped: "${message}"`);
30
- return;
31
- }
32
- this.#ready = false;
33
- this.#stream.on("error", (error) => {
34
- throw error;
35
- });
36
- this.#stream.on("drain", () => {
37
- this.#ready = true;
38
- });
39
- this.#stream.on("finish", () => {
40
- this.#ready = true;
41
- });
42
- this.#ready = this.#stream.write(message, () => {
43
- });
44
- }
45
- }
46
-
47
- class RotatingFileStream {
48
- #filePath;
49
- #immediate;
50
- #stream;
51
- #options;
52
- #createRfsStream;
53
- /**
54
- * Creates a new RotatingFileStream instance.
55
- * @param filePath Path to the log file
56
- * @param writeImmediately Whether to write immediately or buffer writes
57
- * @param options Options for the rotating file stream
58
- * @throws {Error} If the 'rotating-file-stream' package is not installed
59
- */
60
- constructor(filePath, writeImmediately = false, options = {}) {
61
- this.#filePath = filePath;
62
- this.#immediate = writeImmediately;
63
- this.#options = options;
64
- if (!this.#immediate) {
65
- try {
66
- this.#createRfsStream = require("rotating-file-stream").createStream;
67
- } catch {
68
- throw new Error("The 'rotating-file-stream' package is missing. Make sure to install the 'rotating-file-stream' package.");
69
- }
70
- this.#stream = this.#createRfsStream(this.#filePath, options);
71
- }
72
- }
73
- /**
74
- * Writes a message to the rotating file stream.
75
- *
76
- * If writeImmediately was set to true in the constructor, a new stream
77
- * is created for each write operation. Otherwise, uses the buffered stream.
78
- * @param message The message to write to the file
79
- */
80
- write(message) {
81
- let fileStream = this.#stream;
82
- if (this.#immediate) {
83
- fileStream = this.#createRfsStream(this.#filePath, this.#options);
84
- }
85
- const stream = new SafeStreamHandler(fileStream, this.#filePath);
86
- stream.write(message);
87
- if (this.#immediate) {
88
- stream.end();
89
- }
90
- }
91
- /**
92
- * Ends the rotating file stream.
93
- *
94
- * Closes the underlying stream. When `writeImmediately` is not `true`,
95
- * calling `write` after calling this method will throw an error.
96
- */
97
- end() {
98
- if (this.#stream !== void 0) {
99
- this.#stream.end();
100
- }
101
- }
102
- }
103
-
104
- class JsonFileReporter extends AbstractJsonReporter {
105
- /** The rotating file stream instance */
106
- stream;
107
- /**
108
- * Creates a new JsonFileReporter instance.
109
- * @param options Configuration options for file rotation and JSON formatting
110
- */
111
- constructor(options) {
112
- super();
113
- const { filePath, writeImmediately = false, ...rfsOptions } = options;
114
- this.stream = new RotatingFileStream(filePath, writeImmediately, {
115
- compress: "gzip",
116
- // compress rotated files
117
- interval: "1d",
118
- // rotate daily
119
- size: "10M",
120
- // rotate every 10 MegaBytes written,
121
- ...rfsOptions
122
- });
123
- }
124
- /**
125
- * Writes a JSON message to the rotating file stream.
126
- * @param message The JSON-formatted log message to write
127
- * @protected
128
- */
129
- // eslint-disable-next-line no-underscore-dangle
130
- _log(message) {
131
- this.stream.write(`${message}
132
- `);
133
- }
134
- }
135
-
136
- export { JsonFileReporter };
1
+ import{AbstractJsonReporter as a}from"../../packem_shared/AbstractJsonReporter-w_bGGiD-.js";class r{#t=!0;#s;#e;constructor(t,e){this.#s=t,this.#e=e,this.#s.on("error",s=>{throw s}),this.#s.on("drain",()=>{this.#t=!0}),this.#s.on("finish",()=>{this.#t=!0})}write(t){this.writeStream(t)}end(...t){this.#s.end(...t)}get isReady(){return this.#t}writeStream(t){if(!this.#t){console.warn(`Stream busy: ${this.#e}. Write will be dropped: "${t}"`);return}this.#t=!1,this.#t=this.#s.write(t,()=>{})}}class o{#t;#s;#e;#r;#i;#h;constructor(t,e=!1,s={}){this.#t=t,this.#s=e,this.#r=s;try{this.#i=require("rotating-file-stream").createStream}catch{throw new Error("The 'rotating-file-stream' package is missing. Make sure to install the 'rotating-file-stream' package.")}this.#s||(this.#e=this.#i(this.#t,s),this.#h=new r(this.#e,this.#t))}write(t){if(this.#s){const e=this.#i(this.#t,this.#r),s=new r(e,this.#t);s.write(t),s.end();return}this.#h.write(t)}end(){this.#e!==void 0&&this.#e.end()}}class c extends a{stream;constructor(t){super();const{filePath:e,writeImmediately:s=!1,...h}=t;this.stream=new o(e,s,{compress:"gzip",interval:"1d",size:"10M",...h})}close(){this.stream.end()}dispose(){this.close()}_log(t){this.stream.write(`${t}
2
+ `)}}export{c as JsonFileReporter};