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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/LICENSE.md +4 -1
  3. package/dist/error.js +5 -76
  4. package/dist/index.browser.js +19 -1499
  5. package/dist/index.server.js +31 -2804
  6. package/dist/middleware/elysia.d.ts +3 -3
  7. package/dist/middleware/elysia.js +1 -70
  8. package/dist/middleware/express.d.ts +3 -3
  9. package/dist/middleware/express.js +1 -29
  10. package/dist/middleware/fastify.d.ts +3 -3
  11. package/dist/middleware/fastify.js +1 -46
  12. package/dist/middleware/hono.d.ts +3 -3
  13. package/dist/middleware/hono.js +1 -33
  14. package/dist/middleware/next/handler.d.ts +5 -5
  15. package/dist/middleware/next/handler.js +1 -53
  16. package/dist/middleware/sveltekit.d.ts +3 -3
  17. package/dist/middleware/sveltekit.js +1 -43
  18. package/dist/object-tree.js +2 -89
  19. package/dist/packem_shared/AbstractJsonReporter-D_Pb6kpB.js +1 -0
  20. package/dist/packem_shared/AbstractJsonReporter-PVC4ONf2.js +1 -0
  21. package/dist/packem_shared/JsonReporter-BEEmb0W4.js +2 -0
  22. package/dist/packem_shared/JsonReporter-CE-lw7R0.js +1 -0
  23. package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
  24. package/dist/packem_shared/PrettyReporter-N7FvHzl5.js +44 -0
  25. package/dist/packem_shared/{abstract-json-reporter.d-BAgznjyU.d.ts → abstract-json-reporter.d-Boj5w068.d.ts} +1 -1
  26. package/dist/packem_shared/abstract-pretty-reporter-Bag7lQKf.js +33 -0
  27. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  28. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  29. package/dist/packem_shared/{create-middleware-logger.d-DheMh8q4.d.ts → create-middleware-logger.d-CMQdVeVE.d.ts} +2 -2
  30. package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
  31. package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
  32. package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
  33. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
  34. package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
  35. package/dist/packem_shared/{types.d-BeLumqgD.d.ts → types.d-Ck_RSjLg.d.ts} +1 -1
  36. package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
  37. package/dist/packem_shared/{wide-event.d-B-t8ZnhI.d.ts → wide-event.d-DA-6dTPc.d.ts} +1 -1
  38. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
  39. package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
  40. package/dist/processor/caller/caller-processor.d.ts +1 -1
  41. package/dist/processor/caller/caller-processor.js +1 -59
  42. package/dist/processor/environment-processor.d.ts +1 -1
  43. package/dist/processor/environment-processor.js +1 -82
  44. package/dist/processor/message-formatter-processor.d.ts +1 -1
  45. package/dist/processor/message-formatter-processor.js +1 -715
  46. package/dist/processor/opentelemetry-processor.d.ts +1 -1
  47. package/dist/processor/opentelemetry-processor.js +1 -52
  48. package/dist/processor/redact-processor.d.ts +1 -1
  49. package/dist/processor/redact-processor.js +1 -31
  50. package/dist/processor/sampling-processor.d.ts +1 -1
  51. package/dist/processor/sampling-processor.js +1 -59
  52. package/dist/reporter/file/json-file-reporter.d.ts +2 -2
  53. package/dist/reporter/file/json-file-reporter.js +2 -136
  54. package/dist/reporter/http/abstract-http-reporter.d.ts +2 -2
  55. package/dist/reporter/http/abstract-http-reporter.js +2 -432
  56. package/dist/reporter/http/http-reporter.d.ts +2 -2
  57. package/dist/reporter/http/http-reporter.edge-light.js +2 -728
  58. package/dist/reporter/http/http-reporter.js +1 -13
  59. package/dist/reporter/json/index.browser.js +1 -2
  60. package/dist/reporter/json/index.d.ts +2 -2
  61. package/dist/reporter/json/index.js +1 -2
  62. package/dist/reporter/pretty/index.browser.js +1 -1
  63. package/dist/reporter/pretty/index.d.ts +1 -1
  64. package/dist/reporter/pretty/index.js +1 -1
  65. package/dist/reporter/simple/simple-reporter.server.js +8 -183
  66. package/dist/wide-event.d.ts +2 -2
  67. package/dist/wide-event.js +1 -284
  68. package/package.json +24 -24
  69. package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
  70. package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
  71. package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
  72. package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
  73. package/dist/packem_shared/PrettyReporter-CIbrmjUV.js +0 -213
  74. package/dist/packem_shared/PrettyReporter-CNJEO9g7.js +0 -2723
  75. package/dist/packem_shared/abstract-pretty-reporter-CkqCt5hg.js +0 -2637
  76. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  77. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  78. package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
  79. package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
  80. package/dist/packem_shared/index-6cG1Kp0t.js +0 -658
  81. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  82. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  83. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  84. package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
  85. package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
@@ -1,13 +1 @@
1
- import { AbstractHttpReporter } from './abstract-http-reporter.js';
2
-
3
- class HttpReporter extends AbstractHttpReporter {
4
- /**
5
- * Creates a new HTTP Reporter instance.
6
- * @param options Configuration options for HTTP reporting
7
- */
8
- constructor(options) {
9
- super(options);
10
- }
11
- }
12
-
13
- export { HttpReporter as default };
1
+ var a=Object.defineProperty;var r=(e,t)=>a(e,"name",{value:t,configurable:!0});import{AbstractHttpReporter as s}from"./abstract-http-reporter.js";var o=Object.defineProperty,p=r((e,t)=>o(e,"name",{value:t,configurable:!0}),"e");class i extends s{static{r(this,"s")}static{p(this,"HttpReporter")}constructor(t){super(t)}}export{i as default};
@@ -1,2 +1 @@
1
- export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-BO8Calb4.js';
2
- export { default as JsonReporter } from '../../packem_shared/JsonReporter-CCmj7oYL.js';
1
+ import{AbstractJsonReporter as e}from"../../packem_shared/AbstractJsonReporter-D_Pb6kpB.js";import{default as p}from"../../packem_shared/JsonReporter-CE-lw7R0.js";export{e as AbstractJsonReporter,p as JsonReporter};
@@ -1,5 +1,5 @@
1
- import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-BAgznjyU.js";
2
- import { E as ExtendedRfc5424LogLevels, L as LiteralUnion, a as StreamAwareReporter } from "../../packem_shared/types.d-BeLumqgD.js";
1
+ import { A as AbstractJsonReporterOptions, a as AbstractJsonReporter } from "../../packem_shared/abstract-json-reporter.d-Boj5w068.js";
2
+ import { E as ExtendedRfc5424LogLevels, L as LiteralUnion, S as StreamAwareReporter } from "../../packem_shared/types.d-Ck_RSjLg.js";
3
3
  import 'safe-stable-stringify';
4
4
  import '@visulima/colorize';
5
5
  import '@visulima/interactive-manager';
@@ -1,2 +1 @@
1
- export { AbstractJsonReporter } from '../../packem_shared/AbstractJsonReporter-nOj0Ft1F.js';
2
- export { default as JsonReporter } from '../../packem_shared/JsonReporter-Ck2PIAEw.js';
1
+ import{AbstractJsonReporter as e}from"../../packem_shared/AbstractJsonReporter-PVC4ONf2.js";import{default as p}from"../../packem_shared/JsonReporter-BEEmb0W4.js";export{e as AbstractJsonReporter,p as JsonReporter};
@@ -1 +1 @@
1
- export { default as PrettyReporter } from '../../packem_shared/PrettyReporter-CIbrmjUV.js';
1
+ import{default as t}from"../../packem_shared/PrettyReporter-Br5njEEy.js";export{t as PrettyReporter};
@@ -1,5 +1,5 @@
1
1
  import { InteractiveManager } from '@visulima/interactive-manager';
2
- import { D as DefaultLogTypes, L as LiteralUnion$1, c as LoggerTypesConfig, R as ReadonlyMeta, f as LoggerTypesAwareReporter, E as ExtendedRfc5424LogLevels, I as InteractiveStreamReporter } from "../../packem_shared/types.d-BeLumqgD.js";
2
+ import { D as DefaultLogTypes, L as LiteralUnion$1, c as LoggerTypesConfig, R as ReadonlyMeta, f as LoggerTypesAwareReporter, E as ExtendedRfc5424LogLevels, I as InteractiveStreamReporter } from "../../packem_shared/types.d-Ck_RSjLg.js";
3
3
  import '@visulima/colorize';
4
4
  type ColorizeMethod = (value: string) => string;
5
5
  type CodeFrameOptions = {
@@ -1 +1 @@
1
- export { PrettyReporter } from '../../packem_shared/PrettyReporter-CNJEO9g7.js';
1
+ import{PrettyReporter as t}from"../../packem_shared/PrettyReporter-N7FvHzl5.js";export{t as PrettyReporter};
@@ -1,186 +1,11 @@
1
- import { createRequire as __cjs_createRequire } from "node:module";
1
+ var F=Object.defineProperty;var x=(o,e)=>F(o,"name",{value:e,configurable:!0});import{createRequire as V}from"node:module";import A from"@visulima/colorize";import{A as G,u as W,i as H,O as K,b as Q,s as Z,o as d,c as J,a as N,p as R,d as U,B as X,G as S}from"../../packem_shared/abstract-pretty-reporter-Bag7lQKf.js";const le=V(import.meta.url),Y=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,{stdout:z,stderr:D}=Y;var ee=Object.defineProperty,B=x((o,e)=>ee(o,"name",{value:e,configurable:!0}),"b");const{bgGrey:te,bold:I,cyan:se,green:re,greenBright:ie,grey:a,red:T,underline:k,white:ae}=A,oe=/[\\/]pail[\\/]dist/,_=B(o=>!oe.test(o),"pailFileFilter");class ue extends G{static{x(this,"SimpleReporter")}static{B(this,"SimpleReporter")}#t;#s;#r;#a=!1;#i;#e;constructor(e={}){const{error:n,inspect:p,...i}=e;super({uppercase:{label:!0,...i.uppercase},...i}),this.#i={...W,indent:void 0,...p},this.#e={...n,color:{fileLine:re,hint:se,marker:T,message:T,method:ie,title:T}},this.#t=z,this.#s=D}setStdout(e){this.#t=e}setStderr(e){this.#s=e}setInteractiveManager(e){this.#r=e}setIsInteractive(e){this.#a=e}log(e){const n=this.formatMessage(e),p=e.type.level,i=["error","trace","warn"].includes(p)?"stderr":"stdout",h=i==="stderr"?this.#s:this.#t;this.#a&&this.#r!==void 0&&h.isTTY?this.#r.update(i,n.split(`
2
+ `),0):H(`${n}
3
+ `,h)}formatMessage(e){const{columns:n}=K();let p=n;typeof this.styles.messageLength=="number"&&(p=this.styles.messageLength);const{badge:i,context:h,date:c,error:j,file:u,groups:g,label:m,message:f,prefix:y,repeated:M,scope:$,suffix:b,traceError:v,type:L}=e,{color:w}=this.loggerTypes[L.name],E=w?A[w]:ae,l=g.map(()=>" ").join(""),t=[];if(g.length>0&&t.push(`${l+a(`[${g.at(-1)??""}]`)} `),c&&t.push(`${a(this.styles.dateFormatter(typeof c=="string"?new Date(c):c))} `),i)t.push(I(E(i)));else{const s=Q(this.loggerTypes);s.length>0&&t.push(a(" ".repeat(s.length)))}const O=Z(this.loggerTypes),C=d(O);if(m){const s=d(m),r=Math.max(0,C-s);t.push(`${I(E(J(m,this.styles)))} `," ".repeat(r))}else t.push(" ".repeat(C+1));M&&t.push(`${te.white(`[${String(M)}x]`)} `),Array.isArray($)&&$.length>0&&t.push(`${a(`[${$.join(" > ")}]`)} `),y&&t.push(`${a(`[${this.styles.underline.prefix?k(y):y}]`)} `);const P=d(t.join(""));if(f!==N){const s=typeof f=="string"?f:R(f,this.#i);t.push(l+U(s,{trim:!1,width:p-3,wrapMode:X.STRICT_WIDTH}))}if(h){let s=!1;t.push(...h.map(r=>{if(r instanceof Error)return s=!0,`
2
4
 
3
- const __cjs_require = __cjs_createRequire(import.meta.url);
5
+ ${S(r,{...this.#e,filterStacktrace:_,prefix:l})}`;if(typeof r=="object")return` ${R(r,this.#i)}`;const q=(s?`
4
6
 
5
- const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
7
+ `:" ")+String(r);return s=!1,q}))}if(j&&t.push(S(j,{...this.#e,filterStacktrace:_,prefix:l})),v&&t.push(`
6
8
 
7
- const {
8
- stdout,
9
- stderr
10
- } = __cjs_getProcess;
11
- import colorize from '@visulima/colorize';
12
- import { A as AbstractPrettyReporter, d as defaultInspectorConfig, w as writeStream, t as terminalSize, b as getLongestBadge, g as getLongestLabel, c as getStringWidth, f as formatLabel, a as EMPTY_SYMBOL, i as inspect, e as wordWrap, r as renderError, W as WrapMode } from '../../packem_shared/abstract-pretty-reporter-CkqCt5hg.js';
13
-
14
- const { bgGrey, bold, cyan, green, greenBright, grey, red, underline, white } = colorize;
15
- const PAIL_DIST_REGEX = /[\\/]pail[\\/]dist/;
16
- const pailFileFilter = (line) => !PAIL_DIST_REGEX.test(line);
17
- class SimpleReporter extends AbstractPrettyReporter {
18
- #stdout;
19
- #stderr;
20
- #interactiveManager;
21
- #interactive = false;
22
- #inspectOptions;
23
- #errorOptions;
24
- constructor(options = {}) {
25
- const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
26
- super({
27
- uppercase: {
28
- label: true,
29
- ...rest.uppercase
30
- },
31
- ...rest
32
- });
33
- this.#inspectOptions = { ...defaultInspectorConfig, indent: void 0, ...inspectOptions };
34
- this.#errorOptions = {
35
- ...errorOptions,
36
- color: {
37
- fileLine: green,
38
- hint: cyan,
39
- marker: red,
40
- message: red,
41
- method: greenBright,
42
- title: red
43
- }
44
- };
45
- this.#stdout = stdout;
46
- this.#stderr = stderr;
47
- }
48
- setStdout(stdout_) {
49
- this.#stdout = stdout_;
50
- }
51
- setStderr(stderr_) {
52
- this.#stderr = stderr_;
53
- }
54
- setInteractiveManager(manager) {
55
- this.#interactiveManager = manager;
56
- }
57
- setIsInteractive(interactive) {
58
- this.#interactive = interactive;
59
- }
60
- log(meta) {
61
- const message = this.formatMessage(meta);
62
- const logLevel = meta.type.level;
63
- const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
64
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
65
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
66
- this.#interactiveManager.update(streamType, message.split("\n"), 0);
67
- } else {
68
- writeStream(`${message}
69
- `, stream);
70
- }
71
- }
72
- // eslint-disable-next-line sonarjs/cognitive-complexity
73
- formatMessage(data) {
74
- const { columns } = terminalSize();
75
- let size = columns;
76
- if (typeof this.styles.messageLength === "number") {
77
- size = this.styles.messageLength;
78
- }
79
- const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
80
- const { color } = this.loggerTypes[type.name];
81
- const colorized = color ? colorize[color] : white;
82
- const groupSpaces = groups.map(() => " ").join("");
83
- const items = [];
84
- if (groups.length > 0) {
85
- items.push(`${groupSpaces + grey(`[${groups.at(-1) ?? ""}]`)} `);
86
- }
87
- if (date) {
88
- items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
89
- }
90
- if (badge) {
91
- items.push(bold(colorized(badge)));
92
- } else {
93
- const longestBadge = getLongestBadge(this.loggerTypes);
94
- if (longestBadge.length > 0) {
95
- items.push(grey(" ".repeat(longestBadge.length)));
96
- }
97
- }
98
- const longestLabel = getLongestLabel(this.loggerTypes);
99
- const longestWidth = getStringWidth(longestLabel);
100
- if (label) {
101
- const labelWidth = getStringWidth(label);
102
- const pad = Math.max(0, longestWidth - labelWidth);
103
- items.push(`${bold(colorized(formatLabel(label, this.styles)))} `, " ".repeat(pad));
104
- } else {
105
- items.push(" ".repeat(longestWidth + 1));
106
- }
107
- if (repeated) {
108
- items.push(`${bgGrey.white(`[${String(repeated)}x]`)} `);
109
- }
110
- if (Array.isArray(scope) && scope.length > 0) {
111
- items.push(`${grey(`[${scope.join(" > ")}]`)} `);
112
- }
113
- if (prefix) {
114
- items.push(`${grey(`[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `);
115
- }
116
- const titleSize = getStringWidth(items.join(""));
117
- if (message !== EMPTY_SYMBOL) {
118
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
119
- items.push(
120
- groupSpaces + wordWrap(formattedMessage, {
121
- trim: false,
122
- width: size - 3,
123
- wrapMode: WrapMode.STRICT_WIDTH
124
- })
125
- );
126
- }
127
- if (context) {
128
- let hasError = false;
129
- items.push(
130
- ...context.map((value) => {
131
- if (value instanceof Error) {
132
- hasError = true;
133
- return `
134
-
135
- ${renderError(value, {
136
- ...this.#errorOptions,
137
- filterStacktrace: pailFileFilter,
138
- prefix: groupSpaces
139
- })}`;
140
- }
141
- if (typeof value === "object") {
142
- return ` ${inspect(value, this.#inspectOptions)}`;
143
- }
144
- const newValue = (hasError ? "\n\n" : " ") + String(value);
145
- hasError = false;
146
- return newValue;
147
- })
148
- );
149
- }
150
- if (error) {
151
- items.push(
152
- renderError(error, {
153
- ...this.#errorOptions,
154
- filterStacktrace: pailFileFilter,
155
- prefix: groupSpaces
156
- })
157
- );
158
- }
159
- if (traceError) {
160
- items.push(
161
- `
162
-
163
- ${renderError(traceError, {
164
- ...this.#errorOptions,
165
- filterStacktrace: pailFileFilter,
166
- hideErrorCauseCodeView: true,
167
- hideErrorCodeView: true,
168
- hideErrorErrorsCodeView: true,
169
- hideMessage: true,
170
- prefix: groupSpaces
171
- })}`
172
- );
173
- }
174
- if (suffix) {
175
- items.push(` ${groupSpaces}${grey(this.styles.underline.suffix ? underline(suffix) : suffix)}`);
176
- }
177
- if (file) {
178
- const fileMessage = (file.name ?? "") + (file.line ? `:${String(file.line)}` : "");
179
- const callerPad = Math.max(0, titleSize - getStringWidth("Caller: "));
180
- items.push("\n", grey("Caller: "), " ".repeat(callerPad), fileMessage, "\n");
181
- }
182
- return items.join("");
183
- }
184
- }
185
-
186
- export { SimpleReporter };
9
+ ${S(v,{...this.#e,filterStacktrace:_,hideErrorCauseCodeView:!0,hideErrorCodeView:!0,hideErrorErrorsCodeView:!0,hideMessage:!0,prefix:l})}`),b&&t.push(` ${l}${a(this.styles.underline.suffix?k(b):b)}`),u){const s=(u.name??"")+(u.line?`:${String(u.line)}`:""),r=Math.max(0,P-d("Caller: "));t.push(`
10
+ `,a("Caller: ")," ".repeat(r),s,`
11
+ `)}return t.join("")}}export{ue as SimpleReporter};
@@ -1,5 +1,5 @@
1
- export { R as RequestLogEntry, S as SerializedError, W as WideEvent, a as WideEventFinishOptions, b as WideEventLevel, c as WideEventOptions, d as createWideEvent } from "./packem_shared/wide-event.d-B-t8ZnhI.js";
2
- import "./packem_shared/types.d-BeLumqgD.js";
1
+ export { R as RequestLogEntry, S as SerializedError, W as WideEvent, a as WideEventFinishOptions, b as WideEventLevel, c as WideEventOptions, d as createWideEvent } from "./packem_shared/wide-event.d-DA-6dTPc.js";
2
+ import "./packem_shared/types.d-Ck_RSjLg.js";
3
3
  import 'safe-stable-stringify';
4
4
  import '@visulima/colorize';
5
5
  import '@visulima/interactive-manager';
@@ -1,284 +1 @@
1
- const LEVEL_PRIORITY = {
2
- debug: 0,
3
- error: 3,
4
- info: 1,
5
- warn: 2
6
- };
7
- const LEVEL_TO_LOG_TYPE = {
8
- debug: "debug",
9
- error: "error",
10
- info: "info",
11
- warn: "warn"
12
- };
13
- const deepMerge = (target, source) => {
14
- const result = { ...target };
15
- const keys = Object.keys(source);
16
- for (let i = 0; i < keys.length; i += 1) {
17
- const key = keys[i];
18
- const sourceValue = source[key];
19
- const targetValue = result[key];
20
- if (sourceValue !== null && typeof sourceValue === "object" && !Array.isArray(sourceValue) && targetValue !== null && typeof targetValue === "object" && !Array.isArray(targetValue)) {
21
- result[key] = deepMerge(targetValue, sourceValue);
22
- } else {
23
- result[key] = sourceValue;
24
- }
25
- }
26
- return result;
27
- };
28
- const formatDuration = (ms) => {
29
- if (ms < 1e3) {
30
- return `${String(ms)}ms`;
31
- }
32
- return `${(ms / 1e3).toFixed(2)}s`;
33
- };
34
- const serializeError = (error) => {
35
- const serialized = {
36
- message: error.message,
37
- name: error.name
38
- };
39
- if (error.stack) {
40
- serialized.stack = error.stack;
41
- }
42
- const errorWithStatus = error;
43
- if (errorWithStatus.status !== void 0) {
44
- serialized.status = errorWithStatus.status;
45
- } else if (errorWithStatus.statusCode !== void 0) {
46
- serialized.status = errorWithStatus.statusCode;
47
- }
48
- if (errorWithStatus.data !== void 0) {
49
- serialized.data = errorWithStatus.data;
50
- }
51
- if (error.cause instanceof Error) {
52
- serialized.cause = serializeError(error.cause);
53
- }
54
- return serialized;
55
- };
56
- class WideEvent {
57
- name;
58
- autoEmit;
59
- data;
60
- emitted;
61
- attachedError;
62
- level;
63
- pail;
64
- requestLogs;
65
- service;
66
- startTime;
67
- status;
68
- timestamp;
69
- // @ts-expect-error TS6133 -- preserved for future use (richer event categorization)
70
- _type;
71
- constructor(options) {
72
- this.name = options.name;
73
- this.pail = options.pail;
74
- this.data = {};
75
- this.startTime = performance.now();
76
- this.timestamp = (/* @__PURE__ */ new Date()).toISOString();
77
- this.emitted = false;
78
- this.autoEmit = options.autoEmit ?? true;
79
- this._type = options.type ?? "info";
80
- this.level = "info";
81
- this.requestLogs = [];
82
- this.service = options.service;
83
- }
84
- /**
85
- * Record a debug-level lifecycle log entry.
86
- * Does not escalate the event level.
87
- * @param message Description of what happened
88
- * @param context Optional structured context
89
- * @returns `this` for chaining
90
- */
91
- debug(message, context) {
92
- return this.addLogEntry("debug", message, context);
93
- }
94
- /**
95
- * Emit the wide event through the pail logger. Can only be called once;
96
- * subsequent calls are no-ops.
97
- *
98
- * Automatically calculates duration, determines the log type based on
99
- * the highest severity level reached, and serializes any attached error.
100
- *
101
- * Prefer `finish()` for HTTP request contexts where you have a status code.
102
- * @param typeOverride Override the log type for this emission
103
- */
104
- emit(typeOverride) {
105
- if (this.emitted) {
106
- return;
107
- }
108
- this.emitted = true;
109
- const durationMs = Math.round(performance.now() - this.startTime);
110
- const resolvedLevel = this.attachedError ? "error" : this.level;
111
- const type = typeOverride ?? LEVEL_TO_LOG_TYPE[resolvedLevel];
112
- const payload = {
113
- duration: formatDuration(durationMs),
114
- duration_ms: durationMs,
115
- event: this.name,
116
- timestamp: this.timestamp,
117
- ...this.data
118
- };
119
- if (this.service) {
120
- payload.service = this.service;
121
- }
122
- if (this.status !== void 0) {
123
- payload.status = this.status;
124
- }
125
- if (this.attachedError) {
126
- payload.error = serializeError(this.attachedError);
127
- }
128
- if (this.requestLogs.length > 0) {
129
- payload.requestLogs = this.requestLogs;
130
- }
131
- const logFunction = this.pail[type];
132
- logFunction({ message: payload });
133
- }
134
- /**
135
- * Record an error-level lifecycle log entry and attach the error.
136
- * Escalates the event level to "error".
137
- * @param message Description of what went wrong
138
- * @param error The error that occurred
139
- * @param context Optional structured context
140
- * @returns `this` for chaining
141
- */
142
- error(message, error, context) {
143
- if (error) {
144
- this.attachedError = error;
145
- }
146
- return this.addLogEntry("error", message, context);
147
- }
148
- /**
149
- * Finish and emit the wide event with HTTP context.
150
- * Sets the response status and optional error before emitting.
151
- * @example
152
- * ```typescript
153
- * ev.finish({ status: 200 });
154
- * ev.finish({ status: 500, error: new Error("DB timeout") });
155
- * ```
156
- * @param options Status code and/or error
157
- */
158
- finish(options) {
159
- if (options?.status !== void 0) {
160
- this.status = options.status;
161
- }
162
- if (options?.error) {
163
- this.attachedError = options.error;
164
- }
165
- this.emit();
166
- }
167
- /**
168
- * Get a read-only snapshot of the accumulated data.
169
- */
170
- getData() {
171
- return this.data;
172
- }
173
- /**
174
- * Get the current severity level of the event.
175
- * The level auto-escalates as `warn()` or `error()` entries are added.
176
- */
177
- getLevel() {
178
- return this.attachedError ? "error" : this.level;
179
- }
180
- /**
181
- * Get a read-only copy of the request lifecycle log entries.
182
- */
183
- getRequestLogs() {
184
- return this.requestLogs;
185
- }
186
- /**
187
- * Record an info-level lifecycle log entry.
188
- * Does not escalate the event level.
189
- * @param message Description of what happened
190
- * @param context Optional structured context
191
- * @returns `this` for chaining
192
- */
193
- info(message, context) {
194
- return this.addLogEntry("info", message, context);
195
- }
196
- /**
197
- * Accumulate context into the wide event via deep merge.
198
- * Call as many times as needed throughout the operation.
199
- * @example
200
- * ```typescript
201
- * ev.set({ user: { id: 1 } });
202
- * ev.set({ user: { plan: "pro" } });
203
- * // data = { user: { id: 1, plan: "pro" } }
204
- * ```
205
- * @param data Partial data to merge into the event
206
- * @returns `this` for chaining
207
- */
208
- set(data) {
209
- this.data = deepMerge(this.data, data);
210
- return this;
211
- }
212
- /**
213
- * Attach an error to the event. Automatically escalates the event
214
- * level to "error".
215
- * @param error The error to attach
216
- * @returns `this` for chaining
217
- */
218
- setError(error) {
219
- this.attachedError = error;
220
- return this;
221
- }
222
- /**
223
- * Set the HTTP response status code.
224
- * @param status HTTP status code
225
- * @returns `this` for chaining
226
- */
227
- setStatus(status) {
228
- this.status = status;
229
- return this;
230
- }
231
- /**
232
- * Record a warn-level lifecycle log entry.
233
- * Escalates the event level to "warn" (unless already "error").
234
- * @param message Description of the warning
235
- * @param context Optional structured context
236
- * @returns `this` for chaining
237
- */
238
- warn(message, context) {
239
- return this.addLogEntry("warn", message, context);
240
- }
241
- /**
242
- * Disposable implementation. Auto-emits the event if `autoEmit` is true
243
- * and the event hasn't been manually emitted yet.
244
- *
245
- * Enables usage with TC39 Explicit Resource Management:
246
- * ```typescript
247
- * using ev = createWideEvent({ pail: logger, name: "api.checkout" });
248
- * ev.set({ user: { id: 1 } });
249
- * // auto-emits here when scope exits
250
- * ```
251
- */
252
- [Symbol.dispose]() {
253
- if (this.autoEmit && !this.emitted) {
254
- this.emit();
255
- }
256
- }
257
- /**
258
- * Add an entry to the request lifecycle log and escalate level if needed.
259
- */
260
- addLogEntry(level, message, context) {
261
- const entry = {
262
- level,
263
- message,
264
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
265
- };
266
- if (context) {
267
- entry.context = context;
268
- }
269
- this.requestLogs.push(entry);
270
- this.escalateLevel(level);
271
- return this;
272
- }
273
- /**
274
- * Escalate the event level if the new level has higher severity.
275
- */
276
- escalateLevel(level) {
277
- if ((LEVEL_PRIORITY[level] ?? 0) > (LEVEL_PRIORITY[this.level] ?? 0)) {
278
- this.level = level;
279
- }
280
- }
281
- }
282
- const createWideEvent = (options) => new WideEvent(options);
283
-
284
- export { WideEvent, createWideEvent };
1
+ var l=Object.defineProperty;var u=(s,t)=>l(s,"name",{value:t,configurable:!0});var g=Object.defineProperty,n=u((s,t)=>g(s,"name",{value:t,configurable:!0}),"o");const d={debug:0,error:3,info:1,warn:2},v={debug:"debug",error:"error",info:"info",warn:"warn"},c=n((s,t)=>{const e={...s},a=Object.keys(t);for(let i=0;i<a.length;i+=1){const r=a[i],o=t[r],h=e[r];o!==null&&typeof o=="object"&&!Array.isArray(o)&&h!==null&&typeof h=="object"&&!Array.isArray(h)?e[r]=c(h,o):e[r]=o}return e},"deepMerge"),E=n(s=>s<1e3?`${String(s)}ms`:`${(s/1e3).toFixed(2)}s`,"formatDuration"),m=n(s=>{const t={message:s.message,name:s.name};s.stack&&(t.stack=s.stack);const e=s;return e.status!==void 0?t.status=e.status:e.statusCode!==void 0&&(t.status=e.statusCode),e.data!==void 0&&(t.data=e.data),s.cause instanceof Error&&(t.cause=m(s.cause)),t},"serializeError");class p{static{u(this,"WideEvent")}static{n(this,"WideEvent")}name;autoEmit;data;emitted;attachedError;level;pail;requestLogs;service;startTime;status;timestamp;_type;constructor(t){this.name=t.name,this.pail=t.pail,this.data={},this.startTime=performance.now(),this.timestamp=new Date().toISOString(),this.emitted=!1,this.autoEmit=t.autoEmit??!0,this._type=t.type??"info",this.level="info",this.requestLogs=[],this.service=t.service}debug(t,e){return this.addLogEntry("debug",t,e)}emit(t){if(this.emitted)return;this.emitted=!0;const e=Math.round(performance.now()-this.startTime),a=this.attachedError?"error":this.level,i=t??v[a],r={duration:E(e),duration_ms:e,event:this.name,timestamp:this.timestamp,...this.data};this.service&&(r.service=this.service),this.status!==void 0&&(r.status=this.status),this.attachedError&&(r.error=m(this.attachedError)),this.requestLogs.length>0&&(r.requestLogs=this.requestLogs);const o=this.pail[i];o({message:r})}error(t,e,a){return e&&(this.attachedError=e),this.addLogEntry("error",t,a)}finish(t){t?.status!==void 0&&(this.status=t.status),t?.error&&(this.attachedError=t.error),this.emit()}getData(){return this.data}getLevel(){return this.attachedError?"error":this.level}getRequestLogs(){return this.requestLogs}info(t,e){return this.addLogEntry("info",t,e)}set(t){return this.data=c(this.data,t),this}setError(t){return this.attachedError=t,this}setStatus(t){return this.status=t,this}warn(t,e){return this.addLogEntry("warn",t,e)}[Symbol.dispose](){this.autoEmit&&!this.emitted&&this.emit()}addLogEntry(t,e,a){const i={level:t,message:e,timestamp:new Date().toISOString()};return a&&(i.context=a),this.requestLogs.push(i),this.escalateLevel(t),this}escalateLevel(t){(d[t]??0)>(d[this.level]??0)&&(this.level=t)}}const y=n(s=>new p(s),"createWideEvent");export{p as WideEvent,y as createWideEvent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/pail",
3
- "version": "4.0.0-alpha.12",
3
+ "version": "4.0.0-alpha.14",
4
4
  "description": "Highly configurable Logger for Node.js, Edge and Browser.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -59,6 +59,12 @@
59
59
  "bugs": {
60
60
  "url": "https://github.com/visulima/visulima/issues"
61
61
  },
62
+ "license": "MIT",
63
+ "author": {
64
+ "name": "Daniel Bannert",
65
+ "email": "d.bannert@anolilab.de",
66
+ "url": "https://danielbannert.com"
67
+ },
62
68
  "repository": {
63
69
  "type": "git",
64
70
  "url": "git+https://github.com/visulima/visulima.git",
@@ -74,14 +80,19 @@
74
80
  "url": "https://anolilab.com/support"
75
81
  }
76
82
  ],
77
- "license": "MIT",
78
- "author": {
79
- "name": "Daniel Bannert",
80
- "email": "d.bannert@anolilab.de",
81
- "url": "https://danielbannert.com"
82
- },
83
- "sideEffects": false,
83
+ "files": [
84
+ "dist/**",
85
+ "README.md",
86
+ "CHANGELOG.md",
87
+ "LICENSE.md"
88
+ ],
89
+ "os": [
90
+ "darwin",
91
+ "linux",
92
+ "win32"
93
+ ],
84
94
  "type": "module",
95
+ "sideEffects": false,
85
96
  "exports": {
86
97
  ".": {
87
98
  "browser": "./dist/index.browser.js",
@@ -224,18 +235,16 @@
224
235
  },
225
236
  "./package.json": "./package.json"
226
237
  },
227
- "files": [
228
- "dist/**",
229
- "README.md",
230
- "CHANGELOG.md",
231
- "LICENSE.md"
232
- ],
238
+ "publishConfig": {
239
+ "access": "public",
240
+ "provenance": true
241
+ },
233
242
  "dependencies": {
234
243
  "@visulima/colorize": "2.0.0-alpha.10",
235
244
  "@visulima/interactive-manager": "1.0.0-alpha.2"
236
245
  },
237
246
  "peerDependencies": {
238
- "@opentelemetry/api": "1.9.1",
247
+ "@opentelemetry/api": "^1.9.0",
239
248
  "@sveltejs/kit": ">=2.0",
240
249
  "@visulima/redact": "3.0.0-alpha.10",
241
250
  "elysia": ">=1.0",
@@ -276,14 +285,5 @@
276
285
  },
277
286
  "engines": {
278
287
  "node": "^22.14.0 || >=24.10.0"
279
- },
280
- "os": [
281
- "darwin",
282
- "linux",
283
- "win32"
284
- ],
285
- "publishConfig": {
286
- "access": "public",
287
- "provenance": true
288
288
  }
289
289
  }