@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.
- package/CHANGELOG.md +33 -0
- package/LICENSE.md +131 -900
- package/dist/error.d.ts +95 -96
- package/dist/error.js +5 -76
- package/dist/index.browser.d.ts +557 -47
- package/dist/index.browser.js +19 -1499
- package/dist/index.server.d.ts +722 -61
- package/dist/index.server.js +31 -2803
- package/dist/middleware/elysia.d.ts +65 -63
- package/dist/middleware/elysia.js +1 -70
- package/dist/middleware/express.d.ts +73 -71
- package/dist/middleware/express.js +1 -29
- package/dist/middleware/fastify.d.ts +69 -67
- package/dist/middleware/fastify.js +1 -46
- package/dist/middleware/hono.d.ts +74 -72
- package/dist/middleware/hono.js +1 -33
- package/dist/middleware/next/handler.d.ts +101 -34
- package/dist/middleware/next/handler.js +1 -53
- package/dist/middleware/sveltekit.d.ts +100 -98
- package/dist/middleware/sveltekit.js +1 -43
- package/dist/object-tree.d.ts +67 -70
- package/dist/object-tree.js +2 -89
- package/dist/packem_shared/AbstractJsonReporter-BawNFYxI.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-Dt5-5x2R.js +1 -0
- package/dist/packem_shared/JsonReporter-15ln04rX.js +2 -0
- package/dist/packem_shared/JsonReporter-CerNvhg-.js +1 -0
- package/dist/packem_shared/PrettyReporter-Br5njEEy.js +5 -0
- package/dist/packem_shared/PrettyReporter-CgXnwIip.js +44 -0
- package/dist/packem_shared/abstract-json-reporter.d-Bz3lZEDi.d.ts +61 -0
- package/dist/packem_shared/abstract-pretty-reporter-BiHgKxG_.js +33 -0
- package/dist/packem_shared/constants-DKfCaSUR.js +1 -0
- package/dist/packem_shared/constants-ep2nsfdy.js +1 -0
- package/dist/packem_shared/create-middleware-logger.d-DeNLii5l.d.ts +47 -0
- package/dist/packem_shared/createPailError-53jAfQ-T.js +5 -0
- package/dist/packem_shared/headers-S8WyX-2m.js +1 -0
- package/dist/packem_shared/index-Bzp4LnJ5.js +1 -0
- package/dist/packem_shared/pailMiddleware-CWOJRmJq.js +1 -0
- package/dist/packem_shared/storage-DHM1EP2P.js +1 -0
- package/dist/packem_shared/types.d-ByY2ZuYG.d.ts +246 -0
- package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
- package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
- package/dist/packem_shared/useLogger-qyZrjy4D.js +1 -0
- package/dist/packem_shared/wide-event.d-Ke44zirU.d.ts +704 -0
- package/dist/packem_shared/write-console-log-based-on-level-DfD64owL.js +1 -0
- package/dist/packem_shared/write-stream-Dd4_PTcm.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +49 -47
- package/dist/processor/caller/caller-processor.js +1 -59
- package/dist/processor/environment-processor.d.ts +113 -113
- package/dist/processor/environment-processor.js +1 -89
- package/dist/processor/message-formatter-processor.d.ts +51 -49
- package/dist/processor/message-formatter-processor.js +1 -715
- package/dist/processor/opentelemetry-processor.d.ts +69 -66
- package/dist/processor/opentelemetry-processor.js +1 -52
- package/dist/processor/redact-processor.d.ts +60 -41
- package/dist/processor/redact-processor.js +1 -31
- package/dist/processor/sampling-processor.d.ts +102 -101
- package/dist/processor/sampling-processor.js +1 -59
- package/dist/reporter/file/json-file-reporter.d.ts +91 -42
- package/dist/reporter/file/json-file-reporter.js +2 -136
- package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
- package/dist/reporter/http/abstract-http-reporter.js +2 -432
- package/dist/reporter/http/http-reporter.d.ts +40 -36
- package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
- package/dist/reporter/http/http-reporter.edge-light.js +2 -728
- package/dist/reporter/http/http-reporter.js +1 -13
- package/dist/reporter/json/index.browser.d.ts +99 -3
- package/dist/reporter/json/index.browser.js +1 -2
- package/dist/reporter/json/index.d.ts +51 -3
- package/dist/reporter/json/index.js +1 -2
- package/dist/reporter/pretty/index.browser.d.ts +106 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +186 -2
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
- package/dist/reporter/simple/simple-reporter.server.js +8 -182
- package/dist/wide-event.d.ts +5 -300
- package/dist/wide-event.js +1 -284
- package/package.json +29 -30
- package/dist/constants.d.ts +0 -37
- package/dist/middleware/next/middleware.d.ts +0 -59
- package/dist/middleware/next/storage.d.ts +0 -14
- package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
- package/dist/middleware/shared/headers.d.ts +0 -14
- package/dist/middleware/shared/routes.d.ts +0 -30
- package/dist/middleware/shared/storage.d.ts +0 -29
- package/dist/packem_shared/AbstractJsonReporter-BO8Calb4.js +0 -284
- package/dist/packem_shared/AbstractJsonReporter-nOj0Ft1F.js +0 -284
- package/dist/packem_shared/JsonReporter-CCmj7oYL.js +0 -28
- package/dist/packem_shared/JsonReporter-Ck2PIAEw.js +0 -58
- package/dist/packem_shared/PrettyReporter-BCvyNzXO.js +0 -2720
- package/dist/packem_shared/PrettyReporter-BtTr13Ha.js +0 -213
- package/dist/packem_shared/abstract-pretty-reporter-CXAKYCb8.js +0 -2635
- package/dist/packem_shared/constants-B1RjD_ps.js +0 -99
- package/dist/packem_shared/constants-omsTHUWB.js +0 -119
- package/dist/packem_shared/createPailError-B_sgL0nF.js +0 -76
- package/dist/packem_shared/headers-BxHWM6KI.js +0 -127
- package/dist/packem_shared/index-Bx3-C0j9.js +0 -658
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +0 -24
- package/dist/packem_shared/storage-D0vqz8OX.js +0 -36
- package/dist/packem_shared/useLogger-D0rU3lcX.js +0 -33
- package/dist/packem_shared/write-console-log-based-on-level-ree2lDPw.js +0 -15
- package/dist/packem_shared/write-stream-MDqyXmc_.js +0 -6
- package/dist/pail.browser.d.ts +0 -412
- package/dist/pail.server.d.ts +0 -158
- package/dist/processor/caller/get-caller-filename.d.ts +0 -23
- package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
- package/dist/reporter/http/utils/compression.d.ts +0 -7
- package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
- package/dist/reporter/http/utils/retry.d.ts +0 -27
- package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
- package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
- package/dist/reporter/json/json-reporter.server.d.ts +0 -50
- package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
- package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
- package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
- package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
- package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
- package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
- package/dist/reporter/utils/format-label.d.ts +0 -3
- package/dist/types.d.ts +0 -241
- package/dist/utils/arrayify.d.ts +0 -2
- package/dist/utils/get-longest-badge.d.ts +0 -4
- package/dist/utils/get-longest-label.d.ts +0 -4
- package/dist/utils/merge-types.d.ts +0 -4
- package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
- package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
- package/dist/utils/write-stream.d.ts +0 -2
package/dist/error.d.ts
CHANGED
|
@@ -1,104 +1,103 @@
|
|
|
1
1
|
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
* Options for creating a PailError.
|
|
3
|
+
*
|
|
4
|
+
* Extends standard error properties with self-documenting fields
|
|
5
|
+
* that provide actionable context for debugging, particularly useful
|
|
6
|
+
* for AI-assisted log analysis.
|
|
7
|
+
*/
|
|
8
8
|
interface PailErrorOptions {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
9
|
+
/** The root cause of this error */
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
/** A suggested resolution or steps to fix the issue */
|
|
12
|
+
fix?: string;
|
|
13
|
+
/** A link to relevant documentation or issue tracker */
|
|
14
|
+
link?: string;
|
|
15
|
+
/** The error message */
|
|
16
|
+
message: string;
|
|
17
|
+
/** HTTP status code associated with this error */
|
|
18
|
+
status?: number;
|
|
19
|
+
/** An explanation of what caused the failure */
|
|
20
|
+
why?: string;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
23
|
+
* Self-documenting error class for structured logging.
|
|
24
|
+
*
|
|
25
|
+
* Inspired by evlog's structured error approach, PailError extends the native
|
|
26
|
+
* Error class with additional fields that make log entries immediately actionable:
|
|
27
|
+
* - `why`: Explains what caused the failure
|
|
28
|
+
* - `fix`: Suggests how to resolve the issue
|
|
29
|
+
* - `link`: Points to relevant documentation
|
|
30
|
+
* - `status`: HTTP status code for request-related errors
|
|
31
|
+
*
|
|
32
|
+
* These fields are preserved through the logging pipeline and displayed by reporters,
|
|
33
|
+
* making it easier for both humans and AI agents to understand and resolve issues.
|
|
34
|
+
* @example
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { PailError, createPailError } from "@visulima/pail/error";
|
|
37
|
+
*
|
|
38
|
+
* // Using the class directly
|
|
39
|
+
* throw new PailError({
|
|
40
|
+
* message: "Payment processing failed",
|
|
41
|
+
* status: 402,
|
|
42
|
+
* why: "The customer's card was declined by the payment provider",
|
|
43
|
+
* fix: "Retry with a different payment method or contact the card issuer",
|
|
44
|
+
* link: "https://docs.example.com/payments/declined",
|
|
45
|
+
* });
|
|
46
|
+
*
|
|
47
|
+
* // Using the factory function
|
|
48
|
+
* throw createPailError("Connection timeout");
|
|
49
|
+
*
|
|
50
|
+
* // With full options
|
|
51
|
+
* throw createPailError({
|
|
52
|
+
* message: "Database connection failed",
|
|
53
|
+
* why: "Connection pool exhausted after 30s timeout",
|
|
54
|
+
* fix: "Increase pool size or check for connection leaks",
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
58
|
declare class PailError extends Error {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
59
|
+
/** HTTP status code (defaults to 500) */
|
|
60
|
+
readonly status: number;
|
|
61
|
+
/** Explanation of what caused the failure */
|
|
62
|
+
readonly why: string | undefined;
|
|
63
|
+
/** Suggested resolution steps */
|
|
64
|
+
readonly fix: string | undefined;
|
|
65
|
+
/** Link to relevant documentation */
|
|
66
|
+
readonly link: string | undefined;
|
|
67
|
+
constructor(options: PailErrorOptions | string);
|
|
68
|
+
/**
|
|
69
|
+
* Converts the error to a JSON-serializable object.
|
|
70
|
+
*
|
|
71
|
+
* Includes all self-documenting fields in the output for structured logging.
|
|
72
|
+
* @returns A plain object representation of the error
|
|
73
|
+
*/
|
|
74
|
+
toJSON(): Record<string, unknown>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns a formatted string representation including self-documenting fields.
|
|
77
|
+
* @returns Formatted error string with why/fix/link context
|
|
78
|
+
*/
|
|
79
|
+
override toString(): string;
|
|
80
80
|
}
|
|
81
81
|
/**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
82
|
+
* Factory function for creating PailError instances.
|
|
83
|
+
*
|
|
84
|
+
* A convenient shorthand for creating PailError objects. Accepts either
|
|
85
|
+
* a string message or a full PailErrorOptions object.
|
|
86
|
+
* @param options Error message string or PailErrorOptions object
|
|
87
|
+
* @returns A new PailError instance
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { createPailError } from "@visulima/pail/error";
|
|
91
|
+
*
|
|
92
|
+
* throw createPailError("Something went wrong");
|
|
93
|
+
*
|
|
94
|
+
* throw createPailError({
|
|
95
|
+
* message: "Auth failed",
|
|
96
|
+
* status: 401,
|
|
97
|
+
* why: "Token expired",
|
|
98
|
+
* fix: "Refresh the authentication token",
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
102
|
declare const createPailError: (options: PailErrorOptions | string) => PailError;
|
|
103
|
-
export {
|
|
104
|
-
export type { PailErrorOptions };
|
|
103
|
+
export { PailError, type PailErrorOptions, createPailError };
|
package/dist/error.js
CHANGED
|
@@ -1,76 +1,5 @@
|
|
|
1
|
-
class
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** Suggested resolution steps */
|
|
7
|
-
fix;
|
|
8
|
-
/** Link to relevant documentation */
|
|
9
|
-
link;
|
|
10
|
-
constructor(options) {
|
|
11
|
-
const resolvedOptions = typeof options === "string" ? { message: options } : options;
|
|
12
|
-
super(resolvedOptions.message, resolvedOptions.cause === void 0 ? void 0 : { cause: resolvedOptions.cause });
|
|
13
|
-
this.name = "PailError";
|
|
14
|
-
this.status = resolvedOptions.status ?? 500;
|
|
15
|
-
this.why = resolvedOptions.why;
|
|
16
|
-
this.fix = resolvedOptions.fix;
|
|
17
|
-
this.link = resolvedOptions.link;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Converts the error to a JSON-serializable object.
|
|
21
|
-
*
|
|
22
|
-
* Includes all self-documenting fields in the output for structured logging.
|
|
23
|
-
* @returns A plain object representation of the error
|
|
24
|
-
*/
|
|
25
|
-
toJSON() {
|
|
26
|
-
const json = {
|
|
27
|
-
message: this.message,
|
|
28
|
-
name: this.name,
|
|
29
|
-
status: this.status
|
|
30
|
-
};
|
|
31
|
-
if (this.why) {
|
|
32
|
-
json.why = this.why;
|
|
33
|
-
}
|
|
34
|
-
if (this.fix) {
|
|
35
|
-
json.fix = this.fix;
|
|
36
|
-
}
|
|
37
|
-
if (this.link) {
|
|
38
|
-
json.link = this.link;
|
|
39
|
-
}
|
|
40
|
-
if (this.stack) {
|
|
41
|
-
json.stack = this.stack;
|
|
42
|
-
}
|
|
43
|
-
if (this.cause !== void 0) {
|
|
44
|
-
json.cause = this.cause instanceof Error ? { message: this.cause.message, name: this.cause.name, stack: this.cause.stack } : this.cause;
|
|
45
|
-
}
|
|
46
|
-
return json;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Returns a formatted string representation including self-documenting fields.
|
|
50
|
-
* @returns Formatted error string with why/fix/link context
|
|
51
|
-
*/
|
|
52
|
-
toString() {
|
|
53
|
-
let output = `${this.name} [${String(this.status)}]: ${this.message}`;
|
|
54
|
-
if (this.why) {
|
|
55
|
-
output += `
|
|
56
|
-
Why: ${this.why}`;
|
|
57
|
-
}
|
|
58
|
-
if (this.fix) {
|
|
59
|
-
output += `
|
|
60
|
-
Fix: ${this.fix}`;
|
|
61
|
-
}
|
|
62
|
-
if (this.link) {
|
|
63
|
-
output += `
|
|
64
|
-
Link: ${this.link}`;
|
|
65
|
-
}
|
|
66
|
-
if (this.cause !== void 0) {
|
|
67
|
-
const causeMessage = this.cause instanceof Error ? this.cause.message : String(this.cause);
|
|
68
|
-
output += `
|
|
69
|
-
Cause: ${causeMessage}`;
|
|
70
|
-
}
|
|
71
|
-
return output;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const createPailError = (options) => new PailError(options);
|
|
75
|
-
|
|
76
|
-
export { PailError, createPailError };
|
|
1
|
+
var h=Object.defineProperty;var e=(i,s)=>h(i,"name",{value:s,configurable:!0});var r=Object.defineProperty,a=e((i,s)=>r(i,"name",{value:s,configurable:!0}),"e");class n extends Error{static{e(this,"n")}static{a(this,"PailError")}status;why;fix;link;constructor(s){const t=typeof s=="string"?{message:s}:s;super(t.message,t.cause===void 0?void 0:{cause:t.cause}),this.name="PailError",this.status=t.status??500,this.why=t.why,this.fix=t.fix,this.link=t.link}toJSON(){const s={message:this.message,name:this.name,status:this.status};return this.why&&(s.why=this.why),this.fix&&(s.fix=this.fix),this.link&&(s.link=this.link),this.stack&&(s.stack=this.stack),this.cause!==void 0&&(s.cause=this.cause instanceof Error?{message:this.cause.message,name:this.cause.name,stack:this.cause.stack}:this.cause),s}toString(){let s=`${this.name} [${String(this.status)}]: ${this.message}`;if(this.why&&(s+=`
|
|
2
|
+
Why: ${this.why}`),this.fix&&(s+=`
|
|
3
|
+
Fix: ${this.fix}`),this.link&&(s+=`
|
|
4
|
+
Link: ${this.link}`),this.cause!==void 0){const t=this.cause instanceof Error?this.cause.message:String(this.cause);s+=`
|
|
5
|
+
Cause: ${t}`}return s}}const u=a(i=>new n(i),"createPailError");export{n as PailError,u as createPailError};
|