@visulima/pail 4.0.0-alpha.11 → 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 (127) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE.md +131 -900
  3. package/dist/error.d.ts +95 -96
  4. package/dist/error.js +5 -76
  5. package/dist/index.browser.d.ts +557 -47
  6. package/dist/index.browser.js +19 -1499
  7. package/dist/index.server.d.ts +722 -61
  8. package/dist/index.server.js +31 -2803
  9. package/dist/middleware/elysia.d.ts +65 -63
  10. package/dist/middleware/elysia.js +1 -70
  11. package/dist/middleware/express.d.ts +73 -71
  12. package/dist/middleware/express.js +1 -29
  13. package/dist/middleware/fastify.d.ts +69 -67
  14. package/dist/middleware/fastify.js +1 -46
  15. package/dist/middleware/hono.d.ts +74 -72
  16. package/dist/middleware/hono.js +1 -33
  17. package/dist/middleware/next/handler.d.ts +101 -34
  18. package/dist/middleware/next/handler.js +1 -53
  19. package/dist/middleware/sveltekit.d.ts +100 -98
  20. package/dist/middleware/sveltekit.js +1 -43
  21. package/dist/object-tree.d.ts +67 -70
  22. package/dist/object-tree.js +2 -89
  23. package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
  24. package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
  25. package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
  26. package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
  27. package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
  28. package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
  29. package/dist/packem_shared/abstract-json-reporter.d-Bz3lZEDi.d.ts +61 -0
  30. package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.js +33 -0
  31. package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
  32. package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
  33. package/dist/packem_shared/create-middleware-logger.d-DeNLii5l.d.ts +47 -0
  34. package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
  35. package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
  36. package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
  37. package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
  38. package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
  39. package/dist/packem_shared/types.d-ByY2ZuYG.d.ts +246 -0
  40. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  41. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  42. package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
  43. package/dist/packem_shared/wide-event.d-Ke44zirU.d.ts +704 -0
  44. package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
  45. package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
  46. package/dist/processor/caller/caller-processor.d.ts +49 -47
  47. package/dist/processor/caller/caller-processor.js +1 -59
  48. package/dist/processor/environment-processor.d.ts +113 -113
  49. package/dist/processor/environment-processor.js +1 -89
  50. package/dist/processor/message-formatter-processor.d.ts +51 -49
  51. package/dist/processor/message-formatter-processor.js +1 -715
  52. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  53. package/dist/processor/opentelemetry-processor.js +1 -52
  54. package/dist/processor/redact-processor.d.ts +60 -41
  55. package/dist/processor/redact-processor.js +1 -31
  56. package/dist/processor/sampling-processor.d.ts +102 -101
  57. package/dist/processor/sampling-processor.js +1 -59
  58. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  59. package/dist/reporter/file/json-file-reporter.js +2 -136
  60. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  61. package/dist/reporter/http/abstract-http-reporter.js +2 -432
  62. package/dist/reporter/http/http-reporter.d.ts +40 -36
  63. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  64. package/dist/reporter/http/http-reporter.edge-light.js +2 -728
  65. package/dist/reporter/http/http-reporter.js +1 -13
  66. package/dist/reporter/json/index.browser.d.ts +99 -3
  67. package/dist/reporter/json/index.browser.js +1 -2
  68. package/dist/reporter/json/index.d.ts +51 -3
  69. package/dist/reporter/json/index.js +1 -2
  70. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  71. package/dist/reporter/pretty/index.browser.js +1 -1
  72. package/dist/reporter/pretty/index.d.ts +186 -2
  73. package/dist/reporter/pretty/index.js +1 -1
  74. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  75. package/dist/reporter/simple/simple-reporter.server.js +8 -182
  76. package/dist/wide-event.d.ts +5 -300
  77. package/dist/wide-event.js +1 -284
  78. package/package.json +29 -30
  79. package/dist/constants.d.ts +0 -37
  80. package/dist/middleware/next/middleware.d.ts +0 -59
  81. package/dist/middleware/next/storage.d.ts +0 -14
  82. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  83. package/dist/middleware/shared/headers.d.ts +0 -14
  84. package/dist/middleware/shared/routes.d.ts +0 -30
  85. package/dist/middleware/shared/storage.d.ts +0 -29
  86. package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
  87. package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
  88. package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
  89. package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
  90. package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +0 -2720
  91. package/dist/packem_shared/PrettyReporter-BtTr13Ha.js +0 -213
  92. package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +0 -2635
  93. package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
  94. package/dist/packem_shared/constants-omsTHUWB.js +0 -119
  95. package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
  96. package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
  97. package/dist/packem_shared/index-Bx3-C0j9.js +0 -658
  98. package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
  99. package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
  100. package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
  101. package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
  102. package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
  103. package/dist/pail.browser.d.ts +0 -412
  104. package/dist/pail.server.d.ts +0 -158
  105. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  106. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  107. package/dist/reporter/http/utils/compression.d.ts +0 -7
  108. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  109. package/dist/reporter/http/utils/retry.d.ts +0 -27
  110. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  111. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  112. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  113. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  114. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  115. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  116. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  117. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  118. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  119. package/dist/reporter/utils/format-label.d.ts +0 -3
  120. package/dist/types.d.ts +0 -241
  121. package/dist/utils/arrayify.d.ts +0 -2
  122. package/dist/utils/get-longest-badge.d.ts +0 -4
  123. package/dist/utils/get-longest-label.d.ts +0 -4
  124. package/dist/utils/merge-types.d.ts +0 -4
  125. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  126. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  127. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,185 +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 W,u as G,i as H,O as K,b as Q,s as Z,o as d,c as J,a as N,p as C,d as U,B as X,R as S}from"../../packem_shared/abstract-pretty-reporter-BiHgKxG_.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 W{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={...G,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:$,repeated:M,scope:y,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),R=d(O);if(m){const s=d(m),r=Math.max(0,R-s);t.push(`${I(E(J(m,this.styles)))} `," ".repeat(r))}else t.push(" ".repeat(R+1));M&&t.push(`${te.white(`[${String(M)}x]`)} `),Array.isArray(y)&&y.length>0&&t.push(`${a(`[${y.join(" > ")}]`)} `),$&&t.push(`${a(`[${this.styles.underline.prefix?k($):$}]`)} `);const P=d(t.join(""));if(f!==N){const s=typeof f=="string"?f:C(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` ${C(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, { red, greenBright, cyan, green, grey, bold, bgGrey, underline, white } 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-CXAKYCb8.js';
13
-
14
- const PAIL_DIST_REGEX = /[\\/]pail[\\/]dist/;
15
- const pailFileFilter = (line) => !PAIL_DIST_REGEX.test(line);
16
- class SimpleReporter extends AbstractPrettyReporter {
17
- #stdout;
18
- #stderr;
19
- #interactiveManager;
20
- #interactive = false;
21
- #inspectOptions;
22
- #errorOptions;
23
- constructor(options = {}) {
24
- const { error: errorOptions, inspect: inspectOptions, ...rest } = options;
25
- super({
26
- uppercase: {
27
- label: true,
28
- ...rest.uppercase
29
- },
30
- ...rest
31
- });
32
- this.#inspectOptions = { ...defaultInspectorConfig, indent: void 0, ...inspectOptions };
33
- this.#errorOptions = {
34
- ...errorOptions,
35
- color: {
36
- fileLine: green,
37
- hint: cyan,
38
- marker: red,
39
- message: red,
40
- method: greenBright,
41
- title: red
42
- }
43
- };
44
- this.#stdout = stdout;
45
- this.#stderr = stderr;
46
- }
47
- setStdout(stdout_) {
48
- this.#stdout = stdout_;
49
- }
50
- setStderr(stderr_) {
51
- this.#stderr = stderr_;
52
- }
53
- setInteractiveManager(manager) {
54
- this.#interactiveManager = manager;
55
- }
56
- setIsInteractive(interactive) {
57
- this.#interactive = interactive;
58
- }
59
- log(meta) {
60
- const message = this.formatMessage(meta);
61
- const logLevel = meta.type.level;
62
- const streamType = ["error", "trace", "warn"].includes(logLevel) ? "stderr" : "stdout";
63
- const stream = streamType === "stderr" ? this.#stderr : this.#stdout;
64
- if (this.#interactive && this.#interactiveManager !== void 0 && stream.isTTY) {
65
- this.#interactiveManager.update(streamType, message.split("\n"), 0);
66
- } else {
67
- writeStream(`${message}
68
- `, stream);
69
- }
70
- }
71
- // eslint-disable-next-line sonarjs/cognitive-complexity
72
- formatMessage(data) {
73
- const { columns } = terminalSize();
74
- let size = columns;
75
- if (typeof this.styles.messageLength === "number") {
76
- size = this.styles.messageLength;
77
- }
78
- const { badge, context, date, error, file, groups, label, message, prefix, repeated, scope, suffix, traceError, type } = data;
79
- const { color } = this.loggerTypes[type.name];
80
- const colorized = color ? colorize[color] : white;
81
- const groupSpaces = groups.map(() => " ").join("");
82
- const items = [];
83
- if (groups.length > 0) {
84
- items.push(`${groupSpaces + grey(`[${groups.at(-1) ?? ""}]`)} `);
85
- }
86
- if (date) {
87
- items.push(`${grey(this.styles.dateFormatter(typeof date === "string" ? new Date(date) : date))} `);
88
- }
89
- if (badge) {
90
- items.push(bold(colorized(badge)));
91
- } else {
92
- const longestBadge = getLongestBadge(this.loggerTypes);
93
- if (longestBadge.length > 0) {
94
- items.push(grey(" ".repeat(longestBadge.length)));
95
- }
96
- }
97
- const longestLabel = getLongestLabel(this.loggerTypes);
98
- const longestWidth = getStringWidth(longestLabel);
99
- if (label) {
100
- const labelWidth = getStringWidth(label);
101
- const pad = Math.max(0, longestWidth - labelWidth);
102
- items.push(`${bold(colorized(formatLabel(label, this.styles)))} `, " ".repeat(pad));
103
- } else {
104
- items.push(" ".repeat(longestWidth + 1));
105
- }
106
- if (repeated) {
107
- items.push(`${bgGrey.white(`[${String(repeated)}x]`)} `);
108
- }
109
- if (Array.isArray(scope) && scope.length > 0) {
110
- items.push(`${grey(`[${scope.join(" > ")}]`)} `);
111
- }
112
- if (prefix) {
113
- items.push(`${grey(`[${this.styles.underline.prefix ? underline(prefix) : prefix}]`)} `);
114
- }
115
- const titleSize = getStringWidth(items.join(""));
116
- if (message !== EMPTY_SYMBOL) {
117
- const formattedMessage = typeof message === "string" ? message : inspect(message, this.#inspectOptions);
118
- items.push(
119
- groupSpaces + wordWrap(formattedMessage, {
120
- trim: false,
121
- width: size - 3,
122
- wrapMode: WrapMode.STRICT_WIDTH
123
- })
124
- );
125
- }
126
- if (context) {
127
- let hasError = false;
128
- items.push(
129
- ...context.map((value) => {
130
- if (value instanceof Error) {
131
- hasError = true;
132
- return `
133
-
134
- ${renderError(value, {
135
- ...this.#errorOptions,
136
- filterStacktrace: pailFileFilter,
137
- prefix: groupSpaces
138
- })}`;
139
- }
140
- if (typeof value === "object") {
141
- return ` ${inspect(value, this.#inspectOptions)}`;
142
- }
143
- const newValue = (hasError ? "\n\n" : " ") + String(value);
144
- hasError = false;
145
- return newValue;
146
- })
147
- );
148
- }
149
- if (error) {
150
- items.push(
151
- renderError(error, {
152
- ...this.#errorOptions,
153
- filterStacktrace: pailFileFilter,
154
- prefix: groupSpaces
155
- })
156
- );
157
- }
158
- if (traceError) {
159
- items.push(
160
- `
161
-
162
- ${renderError(traceError, {
163
- ...this.#errorOptions,
164
- filterStacktrace: pailFileFilter,
165
- hideErrorCauseCodeView: true,
166
- hideErrorCodeView: true,
167
- hideErrorErrorsCodeView: true,
168
- hideMessage: true,
169
- prefix: groupSpaces
170
- })}`
171
- );
172
- }
173
- if (suffix) {
174
- items.push(` ${groupSpaces}${grey(this.styles.underline.suffix ? underline(suffix) : suffix)}`);
175
- }
176
- if (file) {
177
- const fileMessage = (file.name ?? "") + (file.line ? `:${String(file.line)}` : "");
178
- const callerPad = Math.max(0, titleSize - getStringWidth("Caller: "));
179
- items.push("\n", grey("Caller: "), " ".repeat(callerPad), fileMessage, "\n");
180
- }
181
- return items.join("");
182
- }
183
- }
184
-
185
- 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,300 +1,5 @@
1
- import type { PailBrowserImpl } from "./pail.d.ts";
2
- import type { DefaultLogTypes, LoggerFunction } from "./types.d.ts";
3
- /**
4
- * A pail instance with dynamically generated log methods.
5
- * This is the minimal interface WideEvent needs from a pail logger.
6
- */
7
- type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
8
- /**
9
- * Makes all properties in T optional recursively.
10
- */
11
- type DeepPartial<T> = {
12
- [K in keyof T]?: T[K] extends Record<string, unknown> ? DeepPartial<T[K]> : T[K];
13
- };
14
- /**
15
- * Severity levels for wide events.
16
- */
17
- export type WideEventLevel = "debug" | "error" | "info" | "warn";
18
- /**
19
- * An entry in the request lifecycle log.
20
- */
21
- export interface RequestLogEntry {
22
- /**
23
- * Additional structured context for this log entry.
24
- */
25
- context?: Record<string, unknown>;
26
- /**
27
- * Severity level of this entry.
28
- */
29
- level: WideEventLevel;
30
- /**
31
- * Human-readable message describing what happened.
32
- */
33
- message: string;
34
- /**
35
- * ISO 8601 timestamp of when this entry was recorded.
36
- */
37
- timestamp: string;
38
- }
39
- /**
40
- * Serialized error information included in the emitted wide event.
41
- */
42
- export interface SerializedError {
43
- cause?: SerializedError;
44
- data?: unknown;
45
- message: string;
46
- name: string;
47
- stack?: string;
48
- status?: number;
49
- }
50
- /**
51
- * Options for finishing a wide event with HTTP context.
52
- */
53
- export interface WideEventFinishOptions {
54
- /**
55
- * An error that occurred during the operation.
56
- * Will be serialized and included in the emitted event.
57
- */
58
- error?: Error;
59
- /**
60
- * HTTP response status code.
61
- */
62
- status?: number;
63
- }
64
- /**
65
- * Options for creating a WideEvent instance.
66
- * @template T - Custom logger type names
67
- */
68
- export interface WideEventOptions<T extends string = string> {
69
- /**
70
- * Auto-emit the event when disposed via `Symbol.dispose`.
71
- * Works with TC39 Explicit Resource Management (`using`).
72
- * @default true
73
- */
74
- autoEmit?: boolean;
75
- /**
76
- * Event name identifying this wide event, e.g. "api.checkout", "worker.send-email".
77
- */
78
- name: string;
79
- /**
80
- * The pail logger instance to use for emission.
81
- */
82
- pail: PailLike<T>;
83
- /**
84
- * Service name for this event. Overrides any service name from pail's scope.
85
- */
86
- service?: string;
87
- /**
88
- * Base log type to use when emitting. Defaults to "info".
89
- * The actual type may be escalated based on logged warnings/errors.
90
- */
91
- type?: DefaultLogTypes | T;
92
- }
93
- /**
94
- * A wide event logger that accumulates context incrementally and emits
95
- * a single comprehensive log event through pail.
96
- *
97
- * Instead of scattering multiple log calls throughout an operation,
98
- * use `set()` to build up context as information becomes available,
99
- * then emit once at the end. Lifecycle methods (`info()`, `warn()`, `error()`,
100
- * `debug()`) record timestamped entries in a `requestLogs` array and
101
- * automatically escalate the event's severity level.
102
- *
103
- * Implements `Disposable` for use with TC39 Explicit Resource Management.
104
- * @template TData - Shape of the accumulated event data
105
- * @template T - Custom logger type names from the pail instance
106
- * @example
107
- * ```typescript
108
- * // Manual finish
109
- * const ev = createWideEvent({ pail: logger, name: "api.checkout" });
110
- * ev.set({ user: { id: 1 } });
111
- * ev.info("Validated cart");
112
- * ev.set({ cart: { items: 3, total: 9999 } });
113
- * ev.finish({ status: 200 });
114
- *
115
- * // Auto-emit with Explicit Resource Management
116
- * using ev = createWideEvent({ pail: logger, name: "api.checkout" });
117
- * ev.set({ user: { id: 1 } });
118
- * // emits automatically when scope exits
119
- *
120
- * // Typed data shape
121
- * interface CheckoutData {
122
- * user: { id: number; plan: string };
123
- * cart: { items: number; total: number };
124
- * }
125
- * const ev = createWideEvent<CheckoutData>({ pail: logger, name: "api.checkout" });
126
- * ev.set({ user: { id: 1, plan: "pro" } }); // fully typed
127
- * ```
128
- */
129
- export declare class WideEvent<TData extends Record<string, unknown> = Record<string, unknown>, T extends string = string> implements Disposable {
130
- [Symbol.dispose]: () => void;
131
- readonly name: string;
132
- private readonly autoEmit;
133
- private data;
134
- private emitted;
135
- private attachedError?;
136
- private level;
137
- private readonly pail;
138
- private readonly requestLogs;
139
- private readonly service;
140
- private readonly startTime;
141
- private status;
142
- private readonly timestamp;
143
- private readonly _type;
144
- constructor(options: WideEventOptions<T>);
145
- /**
146
- * Record a debug-level lifecycle log entry.
147
- * Does not escalate the event level.
148
- * @param message Description of what happened
149
- * @param context Optional structured context
150
- * @returns `this` for chaining
151
- */
152
- debug(message: string, context?: Record<string, unknown>): this;
153
- /**
154
- * Emit the wide event through the pail logger. Can only be called once;
155
- * subsequent calls are no-ops.
156
- *
157
- * Automatically calculates duration, determines the log type based on
158
- * the highest severity level reached, and serializes any attached error.
159
- *
160
- * Prefer `finish()` for HTTP request contexts where you have a status code.
161
- * @param typeOverride Override the log type for this emission
162
- */
163
- emit(typeOverride?: DefaultLogTypes | T): void;
164
- /**
165
- * Record an error-level lifecycle log entry and attach the error.
166
- * Escalates the event level to "error".
167
- * @param message Description of what went wrong
168
- * @param error The error that occurred
169
- * @param context Optional structured context
170
- * @returns `this` for chaining
171
- */
172
- error(message: string, error?: Error, context?: Record<string, unknown>): this;
173
- /**
174
- * Finish and emit the wide event with HTTP context.
175
- * Sets the response status and optional error before emitting.
176
- * @example
177
- * ```typescript
178
- * ev.finish({ status: 200 });
179
- * ev.finish({ status: 500, error: new Error("DB timeout") });
180
- * ```
181
- * @param options Status code and/or error
182
- */
183
- finish(options?: WideEventFinishOptions): void;
184
- /**
185
- * Get a read-only snapshot of the accumulated data.
186
- */
187
- getData(): Readonly<TData>;
188
- /**
189
- * Get the current severity level of the event.
190
- * The level auto-escalates as `warn()` or `error()` entries are added.
191
- */
192
- getLevel(): WideEventLevel;
193
- /**
194
- * Get a read-only copy of the request lifecycle log entries.
195
- */
196
- getRequestLogs(): ReadonlyArray<RequestLogEntry>;
197
- /**
198
- * Record an info-level lifecycle log entry.
199
- * Does not escalate the event level.
200
- * @param message Description of what happened
201
- * @param context Optional structured context
202
- * @returns `this` for chaining
203
- */
204
- info(message: string, context?: Record<string, unknown>): this;
205
- /**
206
- * Accumulate context into the wide event via deep merge.
207
- * Call as many times as needed throughout the operation.
208
- * @example
209
- * ```typescript
210
- * ev.set({ user: { id: 1 } });
211
- * ev.set({ user: { plan: "pro" } });
212
- * // data = { user: { id: 1, plan: "pro" } }
213
- * ```
214
- * @param data Partial data to merge into the event
215
- * @returns `this` for chaining
216
- */
217
- set(data: DeepPartial<TData>): this;
218
- /**
219
- * Attach an error to the event. Automatically escalates the event
220
- * level to "error".
221
- * @param error The error to attach
222
- * @returns `this` for chaining
223
- */
224
- setError(error: Error): this;
225
- /**
226
- * Set the HTTP response status code.
227
- * @param status HTTP status code
228
- * @returns `this` for chaining
229
- */
230
- setStatus(status: number): this;
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: string, context?: Record<string, unknown>): this;
239
- /**
240
- * Disposable implementation. Auto-emits the event if `autoEmit` is true
241
- * and the event hasn't been manually emitted yet.
242
- *
243
- * Enables usage with TC39 Explicit Resource Management:
244
- * ```typescript
245
- * using ev = createWideEvent({ pail: logger, name: "api.checkout" });
246
- * ev.set({ user: { id: 1 } });
247
- * // auto-emits here when scope exits
248
- * ```
249
- */
250
- [Symbol.dispose](): void;
251
- /**
252
- * Add an entry to the request lifecycle log and escalate level if needed.
253
- */
254
- private addLogEntry;
255
- /**
256
- * Escalate the event level if the new level has higher severity.
257
- */
258
- private escalateLevel;
259
- }
260
- /**
261
- * Create a wide event logger that accumulates context and emits a single
262
- * comprehensive log event through pail.
263
- * @template TData - Shape of the accumulated event data
264
- * @template T - Custom logger type names from the pail instance
265
- * @param options Configuration options
266
- * @returns A new WideEvent instance
267
- * @example
268
- * ```typescript
269
- * import { createPail } from "@visulima/pail";
270
- * import { createWideEvent } from "@visulima/pail/wide-event";
271
- *
272
- * const logger = createPail();
273
- *
274
- * // In a request handler:
275
- * const ev = createWideEvent({ pail: logger, name: "api.checkout" });
276
- *
277
- * ev.set({ user: { id: 1, plan: "pro" } });
278
- * ev.info("Validated cart", { itemCount: 3 });
279
- * ev.set({ cart: { id: 42, items: 3, total: 9999 } });
280
- * ev.info("Payment processed");
281
- * ev.finish({ status: 200 });
282
- *
283
- * // Emits a single structured log:
284
- * // {
285
- * // event: "api.checkout",
286
- * // timestamp: "2025-01-24T10:23:45.612Z",
287
- * // duration: "127ms",
288
- * // duration_ms: 127,
289
- * // status: 200,
290
- * // user: { id: 1, plan: "pro" },
291
- * // cart: { id: 42, items: 3, total: 9999 },
292
- * // requestLogs: [
293
- * // { level: "info", message: "Validated cart", timestamp: "...", context: { itemCount: 3 } },
294
- * // { level: "info", message: "Payment processed", timestamp: "..." }
295
- * // ]
296
- * // }
297
- * ```
298
- */
299
- export declare const createWideEvent: <TData extends Record<string, unknown> = Record<string, unknown>, T extends string = string>(options: WideEventOptions<T>) => WideEvent<TData, T>;
300
- export {};
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-Ke44zirU.js";
2
+ import "./packem_shared/types.d-ByY2ZuYG.js";
3
+ import 'safe-stable-stringify';
4
+ import '@visulima/colorize';
5
+ import '@visulima/interactive-manager';