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

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 (86) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE.md +0 -27
  3. package/dist/error.js +5 -76
  4. package/dist/index.browser.js +19 -1499
  5. package/dist/index.server.js +31 -2804
  6. package/dist/middleware/elysia.d.ts +3 -3
  7. package/dist/middleware/elysia.js +1 -70
  8. package/dist/middleware/express.d.ts +3 -3
  9. package/dist/middleware/express.js +1 -29
  10. package/dist/middleware/fastify.d.ts +3 -3
  11. package/dist/middleware/fastify.js +1 -46
  12. package/dist/middleware/hono.d.ts +3 -3
  13. package/dist/middleware/hono.js +1 -33
  14. package/dist/middleware/next/handler.d.ts +5 -5
  15. package/dist/middleware/next/handler.js +1 -53
  16. package/dist/middleware/sveltekit.d.ts +3 -3
  17. package/dist/middleware/sveltekit.js +1 -43
  18. package/dist/object-tree.js +2 -89
  19. package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
  20. package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
  21. package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
  22. package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
  23. package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
  24. package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
  25. package/dist/packem_shared/{abstract-json-reporter.d-BAgznjyU.d.ts → abstract-json-reporter.d-Bz3lZEDi.d.ts} +1 -1
  26. package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.js +33 -0
  27. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  28. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  29. package/dist/packem_shared/{create-middleware-logger.d-DheMh8q4.d.ts → create-middleware-logger.d-DeNLii5l.d.ts} +2 -2
  30. package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
  31. package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
  32. package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
  33. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
  34. package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
  35. package/dist/packem_shared/{types.d-BeLumqgD.d.ts → types.d-ByY2ZuYG.d.ts} +1 -1
  36. package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
  37. package/dist/packem_shared/{wide-event.d-B-t8ZnhI.d.ts → wide-event.d-Ke44zirU.d.ts} +1 -1
  38. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
  39. package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
  40. package/dist/processor/caller/caller-processor.d.ts +1 -1
  41. package/dist/processor/caller/caller-processor.js +1 -59
  42. package/dist/processor/environment-processor.d.ts +1 -1
  43. package/dist/processor/environment-processor.js +1 -82
  44. package/dist/processor/message-formatter-processor.d.ts +1 -1
  45. package/dist/processor/message-formatter-processor.js +1 -715
  46. package/dist/processor/opentelemetry-processor.d.ts +1 -1
  47. package/dist/processor/opentelemetry-processor.js +1 -52
  48. package/dist/processor/redact-processor.d.ts +1 -1
  49. package/dist/processor/redact-processor.js +1 -31
  50. package/dist/processor/sampling-processor.d.ts +1 -1
  51. package/dist/processor/sampling-processor.js +1 -59
  52. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  53. package/dist/reporter/file/json-file-reporter.js +2 -136
  54. package/dist/reporter/http/abstract-http-reporter.d.ts +2 -2
  55. package/dist/reporter/http/abstract-http-reporter.js +2 -432
  56. package/dist/reporter/http/http-reporter.d.ts +2 -2
  57. package/dist/reporter/http/http-reporter.edge-light.js +2 -728
  58. package/dist/reporter/http/http-reporter.js +1 -13
  59. package/dist/reporter/json/index.browser.js +1 -2
  60. package/dist/reporter/json/index.d.ts +2 -2
  61. package/dist/reporter/json/index.js +1 -2
  62. package/dist/reporter/pretty/index.browser.js +1 -1
  63. package/dist/reporter/pretty/index.d.ts +3 -36
  64. package/dist/reporter/pretty/index.js +1 -1
  65. package/dist/reporter/simple/simple-reporter.server.d.ts +1 -1
  66. package/dist/reporter/simple/simple-reporter.server.js +8 -183
  67. package/dist/wide-event.d.ts +2 -2
  68. package/dist/wide-event.js +1 -284
  69. package/package.json +24 -24
  70. package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
  71. package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
  72. package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
  73. package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
  74. package/dist/packem_shared/PrettyReporter-CIbrmjUV.js +0 -213
  75. package/dist/packem_shared/PrettyReporter-CNJEO9g7.js +0 -2723
  76. package/dist/packem_shared/abstract-pretty-reporter-CkqCt5hg.js +0 -2637
  77. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  78. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  79. package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
  80. package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
  81. package/dist/packem_shared/index-6cG1Kp0t.js +0 -658
  82. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  83. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  84. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  85. package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
  86. package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
@@ -1,4 +1,4 @@
1
- import { M as Meta, P as Processor } from "../packem_shared/types.d-BeLumqgD.js";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
2
2
  import '@visulima/colorize';
3
3
  import '@visulima/interactive-manager';
4
4
  /**
@@ -1,52 +1 @@
1
- import { trace, context, isSpanContextValid } from '@opentelemetry/api';
2
-
3
- class OpenTelemetryProcessor {
4
- /** Field name for trace ID */
5
- #traceIdField;
6
- /** Field name for span ID */
7
- #spanIdField;
8
- /** Field name for trace flags */
9
- #traceFlagsField;
10
- /** Optional field name to nest all trace fields under */
11
- #traceFieldName;
12
- /**
13
- * Creates a new OpenTelemetryProcessor instance.
14
- * @param options Configuration options for field names and nesting
15
- */
16
- constructor(options = {}) {
17
- this.#traceIdField = options.traceIdFieldName ?? "trace_id";
18
- this.#spanIdField = options.spanIdFieldName ?? "span_id";
19
- this.#traceFlagsField = options.traceFlagsFieldName ?? "trace_flags";
20
- this.#traceFieldName = options.traceFieldName;
21
- }
22
- /**
23
- * Processes log metadata to add OpenTelemetry trace context.
24
- *
25
- * Extracts trace information from the active OpenTelemetry span and adds it
26
- * to the log context. If no valid span is found, the metadata is returned unchanged.
27
- * @param meta The log metadata to process
28
- * @returns The processed metadata with trace context added
29
- */
30
- process(meta) {
31
- const span = trace.getSpan(context.active());
32
- if (!span) {
33
- return meta;
34
- }
35
- const spanContext = span.spanContext();
36
- if (!isSpanContextValid(spanContext)) {
37
- return meta;
38
- }
39
- const fields = {
40
- [this.#spanIdField]: spanContext.spanId,
41
- [this.#traceFlagsField]: `0${spanContext.traceFlags.toString(16)}`,
42
- [this.#traceIdField]: spanContext.traceId
43
- };
44
- const traceData = this.#traceFieldName ? {
45
- [this.#traceFieldName]: fields
46
- } : fields;
47
- meta.context = [...meta.context ?? [], traceData];
48
- return meta;
49
- }
50
- }
51
-
52
- export { OpenTelemetryProcessor };
1
+ var n=Object.defineProperty;var s=(e,t)=>n(e,"name",{value:t,configurable:!0});import{trace as o,context as l,isSpanContextValid as d}from"@opentelemetry/api";var p=Object.defineProperty,h=s((e,t)=>p(e,"name",{value:t,configurable:!0}),"i");class f{static{s(this,"OpenTelemetryProcessor")}static{h(this,"OpenTelemetryProcessor")}#e;#r;#s;#t;constructor(t={}){this.#e=t.traceIdFieldName??"trace_id",this.#r=t.spanIdFieldName??"span_id",this.#s=t.traceFlagsFieldName??"trace_flags",this.#t=t.traceFieldName}process(t){const a=o.getSpan(l.active());if(!a)return t;const r=a.spanContext();if(!d(r))return t;const i={[this.#r]:r.spanId,[this.#s]:`0${r.traceFlags.toString(16)}`,[this.#e]:r.traceId},c=this.#t?{[this.#t]:i}:i;return t.context=[...t.context??[],c],t}}export{f as OpenTelemetryProcessor};
@@ -1,4 +1,4 @@
1
- import { M as Meta, P as Processor } from "../packem_shared/types.d-BeLumqgD.js";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
2
2
  import '@visulima/colorize';
3
3
  import '@visulima/interactive-manager';
4
4
  type StringAnonymize = {
@@ -1,31 +1 @@
1
- import { redact, standardRules } from '@visulima/redact';
2
-
3
- class RedactProcessor {
4
- /** The redact function configured with custom rules and options */
5
- #redact;
6
- /**
7
- * Creates a new RedactProcessor instance.
8
- * @param rules Custom redaction rules (uses standardRules if not provided)
9
- * @param options Additional redaction options
10
- */
11
- constructor(rules, options) {
12
- const effectiveRules = rules ?? standardRules;
13
- this.#redact = (input) => redact(input, effectiveRules, options);
14
- }
15
- /**
16
- * Processes log metadata to redact sensitive information.
17
- *
18
- * Applies redaction rules to the message, context, and error properties
19
- * in the log metadata to prevent sensitive data from being logged.
20
- * @param meta The log metadata to process
21
- * @returns The processed metadata with sensitive data redacted
22
- */
23
- process(meta) {
24
- meta.message = this.#redact(meta.message);
25
- meta.context = this.#redact(meta.context);
26
- meta.error = this.#redact(meta.error);
27
- return meta;
28
- }
29
- }
30
-
31
- export { RedactProcessor as default };
1
+ var c=Object.defineProperty;var s=(r,t)=>c(r,"name",{value:t,configurable:!0});import{redact as i,standardRules as n}from"@visulima/redact";var u=Object.defineProperty,d=s((r,t)=>u(r,"name",{value:t,configurable:!0}),"t");class m{static{s(this,"l")}static{d(this,"RedactProcessor")}#t;constructor(t,e){const o=t??n;this.#t=a=>i(a,o,e)}process(t){return t.message=this.#t(t.message),t.context=this.#t(t.context),t.error=this.#t(t.error),t}}export{m as default};
@@ -1,4 +1,4 @@
1
- import { M as Meta, P as Processor } from "../packem_shared/types.d-BeLumqgD.js";
1
+ import { M as Meta, P as Processor } from "../packem_shared/types.d-ByY2ZuYG.js";
2
2
  import '@visulima/colorize';
3
3
  import '@visulima/interactive-manager';
4
4
  /**
@@ -1,59 +1 @@
1
- class SamplingProcessor {
2
- #headRates;
3
- #tailConditions;
4
- /**
5
- * Creates a new SamplingProcessor instance.
6
- * @param options Sampling configuration options
7
- */
8
- constructor(options = {}) {
9
- this.#headRates = options.head ?? {};
10
- this.#tailConditions = options.tail ?? [];
11
- }
12
- /**
13
- * Processes log metadata to apply sampling rules.
14
- *
15
- * First evaluates head sampling (random per-level), then checks tail
16
- * sampling conditions. If a log is dropped, the meta is marked with
17
- * `__dropped: true` so reporters can skip it.
18
- * @param meta The log metadata to process
19
- * @returns The processed metadata, potentially marked as dropped
20
- */
21
- process(meta) {
22
- const level = meta.type.level;
23
- if (this.#shouldDrop(level) && !this.#shouldForceKeep(meta)) {
24
- return { ...meta, dropped: true };
25
- }
26
- return meta;
27
- }
28
- /**
29
- * Evaluates head sampling for the given log level.
30
- * @returns true if the log should be dropped
31
- */
32
- #shouldDrop(level) {
33
- const rate = this.#headRates[level];
34
- if (rate === void 0) {
35
- return false;
36
- }
37
- if (rate <= 0) {
38
- return true;
39
- }
40
- if (rate >= 100) {
41
- return false;
42
- }
43
- return Math.random() * 100 >= rate;
44
- }
45
- /**
46
- * Evaluates tail sampling conditions.
47
- * @returns true if any condition forces keeping the log
48
- */
49
- #shouldForceKeep(meta) {
50
- for (let i = 0; i < this.#tailConditions.length; i += 1) {
51
- if (this.#tailConditions[i](meta)) {
52
- return true;
53
- }
54
- }
55
- return false;
56
- }
57
- }
58
-
59
- export { SamplingProcessor as default };
1
+ var a=Object.defineProperty;var s=(e,t)=>a(e,"name",{value:t,configurable:!0});var i=Object.defineProperty,n=s((e,t)=>i(e,"name",{value:t,configurable:!0}),"i");class l{static{s(this,"o")}static{n(this,"SamplingProcessor")}#r;#t;constructor(t={}){this.#r=t.head??{},this.#t=t.tail??[]}process(t){const r=t.type.level;return this.#e(r)&&!this.#s(t)?{...t,dropped:!0}:t}#e(t){const r=this.#r[t];return r===void 0?!1:r<=0?!0:r>=100?!1:Math.random()*100>=r}#s(t){for(let r=0;r<this.#t.length;r+=1)if(this.#t[r](t))return!0;return!1}}export{l as default};
@@ -1,7 +1,7 @@
1
1
  import { Options } from 'rotating-file-stream';
2
- import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-BAgznjyU.js";
2
+ import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-Bz3lZEDi.js";
3
3
  import 'safe-stable-stringify';
4
- import "../../packem_shared/types.d-BeLumqgD.js";
4
+ import "../../packem_shared/types.d-ByY2ZuYG.js";
5
5
  import '@visulima/colorize';
6
6
  import '@visulima/interactive-manager';
7
7
  /**
@@ -1,136 +1,2 @@
1
- import { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-nOj0Ft1F.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
+ var h=Object.defineProperty;var s=(e,t)=>h(e,"name",{value:t,configurable:!0});import{AbstractJsonReporter as n}from"../../packem_shared/AbstractJsonReporter-BawNFYxI.js";var o=Object.defineProperty,c=s((e,t)=>o(e,"name",{value:t,configurable:!0}),"e");class l{static{s(this,"n")}static{c(this,"SafeStreamHandler")}#t=!0;#e;#r;constructor(t,r){this.#e=t,this.#r=r}write(t){this.writeStream(t)}end(...t){this.#e.end(...t)}get isReady(){return this.#t}writeStream(t){if(!this.#t){console.warn(`Stream busy: ${this.#r}. Write will be dropped: "${t}"`);return}this.#t=!1,this.#e.on("error",r=>{throw r}),this.#e.on("drain",()=>{this.#t=!0}),this.#e.on("finish",()=>{this.#t=!0}),this.#t=this.#e.write(t,()=>{})}}var u=Object.defineProperty,m=s((e,t)=>u(e,"name",{value:t,configurable:!0}),"r$1");class d{static{s(this,"o")}static{m(this,"RotatingFileStream")}#t;#e;#r;#s;#i;constructor(t,r=!1,i={}){if(this.#t=t,this.#e=r,this.#s=i,!this.#e){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.#r=this.#i(this.#t,i)}}write(t){let r=this.#r;this.#e&&(r=this.#i(this.#t,this.#s));const i=new l(r,this.#t);i.write(t),this.#e&&i.end()}end(){this.#r!==void 0&&this.#r.end()}}var f=Object.defineProperty,p=s((e,t)=>f(e,"name",{value:t,configurable:!0}),"r");class v extends n{static{s(this,"JsonFileReporter")}static{p(this,"JsonFileReporter")}stream;constructor(t){super();const{filePath:r,writeImmediately:i=!1,...a}=t;this.stream=new d(r,i,{compress:"gzip",interval:"1d",size:"10M",...a})}_log(t){this.stream.write(`${t}
2
+ `)}}export{v as JsonFileReporter};
@@ -1,5 +1,5 @@
1
- import { E as ExtendedRfc5424LogLevels, L as LiteralUnion, S as StringifyAwareReporter } from "../../packem_shared/types.d-BeLumqgD.js";
2
- import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-BAgznjyU.js";
1
+ import { E as ExtendedRfc5424LogLevels, L as LiteralUnion, S as StringifyAwareReporter } from "../../packem_shared/types.d-ByY2ZuYG.js";
2
+ import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-Bz3lZEDi.js";
3
3
  import '@visulima/colorize';
4
4
  import '@visulima/interactive-manager';
5
5
  import 'safe-stable-stringify';