@visulima/pail 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE.md +346 -0
- package/MIGRATION-GUIDE.md +459 -0
- package/README.md +17 -0
- package/dist/error.d.ts +69 -69
- package/dist/index.browser.d.ts +446 -445
- package/dist/index.browser.js +17 -17
- package/dist/index.server.d.ts +582 -582
- package/dist/index.server.js +27 -27
- package/dist/middleware/elysia.d.ts +44 -42
- package/dist/middleware/elysia.js +1 -1
- package/dist/middleware/express.d.ts +58 -59
- package/dist/middleware/express.js +1 -1
- package/dist/middleware/fastify.d.ts +55 -56
- package/dist/middleware/fastify.js +1 -1
- package/dist/middleware/hono.d.ts +56 -57
- package/dist/middleware/hono.js +1 -1
- package/dist/middleware/next/handler.d.ts +67 -68
- package/dist/middleware/next/handler.js +1 -1
- package/dist/middleware/sveltekit.d.ts +72 -73
- package/dist/middleware/sveltekit.js +1 -1
- package/dist/object-tree.d.ts +44 -44
- package/dist/packem_shared/AbstractJsonReporter-BpWRnN0L.js +1 -0
- package/dist/packem_shared/AbstractJsonReporter-DxZwImm5.js +1 -0
- package/dist/packem_shared/JsonReporter-9IcELa1m.js +2 -0
- package/dist/packem_shared/JsonReporter-Dd3kuj8X.js +1 -0
- package/dist/packem_shared/{PrettyReporter-DsHfKOU7.js → PrettyReporter-BUWNEg3_.js} +1 -1
- package/dist/packem_shared/{PrettyReporter-CcDdPQSt.js → PrettyReporter-DbgD89ck.js} +56 -30
- package/dist/packem_shared/abstract-json-reporter.d-B6NoO-hG.d.ts +61 -0
- package/dist/packem_shared/{abstract-pretty-reporter-DrLBJ6ds.js → abstract-pretty-reporter-CyfTvmKf.js} +41 -39
- package/dist/packem_shared/create-middleware-logger.d-BRkkBMlk.d.ts +47 -0
- package/dist/packem_shared/headers-DI58djdG.js +1 -0
- package/dist/packem_shared/index-CbkPnylC.js +1 -0
- package/dist/packem_shared/serializeError-52C4oiKx-CrnRcq9R.js +1 -0
- package/dist/packem_shared/storage-DVcJumyk.js +1 -0
- package/dist/packem_shared/types.d-4ge_rME4.d.ts +246 -0
- package/dist/packem_shared/{types.d-Cz9S7jZh.d.ts → types.d-BW8kAXUv.d.ts} +95 -95
- package/dist/packem_shared/types.d-DGHeA2iJ.d.ts +194 -0
- package/dist/packem_shared/useLogger-7p55yvvc.js +1 -0
- package/dist/packem_shared/wide-event.d-BMLastMR.d.ts +716 -0
- package/dist/packem_shared/write-stream-ytl_vhg_.js +1 -0
- package/dist/processor/caller/caller-processor.d.ts +32 -33
- package/dist/processor/environment-processor.d.ts +83 -84
- package/dist/processor/message-formatter-processor.d.ts +40 -45
- package/dist/processor/message-formatter-processor.js +1 -1
- package/dist/processor/opentelemetry-processor.d.ts +51 -52
- package/dist/processor/redact-processor.d.ts +57 -65
- package/dist/processor/sampling-processor.d.ts +90 -91
- package/dist/reporter/file/json-file-reporter.d.ts +77 -78
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.d.ts +125 -121
- package/dist/reporter/http/abstract-http-reporter.js +2 -2
- package/dist/reporter/http/http-reporter.d.ts +33 -34
- package/dist/reporter/http/http-reporter.edge-light.d.ts +235 -230
- package/dist/reporter/http/http-reporter.edge-light.js +2 -2
- package/dist/reporter/json/index.browser.d.ts +62 -61
- package/dist/reporter/json/index.browser.js +1 -1
- package/dist/reporter/json/index.d.ts +36 -37
- package/dist/reporter/json/index.js +1 -1
- package/dist/reporter/pretty/index.browser.d.ts +57 -56
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.d.ts +133 -133
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.d.ts +91 -90
- package/dist/reporter/simple/simple-reporter.server.js +7 -7
- package/dist/wide-event.d.ts +2 -3
- package/dist/wide-event.js +1 -1
- package/package.json +58 -36
- package/dist/packem_shared/AbstractJsonReporter-Bp_JCrMQ.js +0 -1
- package/dist/packem_shared/AbstractJsonReporter-w_bGGiD-.js +0 -1
- package/dist/packem_shared/JsonReporter-Sd_lJGS-.js +0 -2
- package/dist/packem_shared/JsonReporter-bmem9lcg.js +0 -1
- package/dist/packem_shared/abstract-json-reporter.d-wfESoEa-.d.ts +0 -62
- package/dist/packem_shared/addKnownErrorConstructor-C1OJTj2D-0FlJMfXz.js +0 -25
- package/dist/packem_shared/create-middleware-logger.d-B-JmQ1Sl.d.ts +0 -47
- package/dist/packem_shared/headers-DH0H2s8W.js +0 -1
- package/dist/packem_shared/index-Q1764hvO.js +0 -1
- package/dist/packem_shared/serializeError-C-NFvZ8_-D0CA_Qlx.js +0 -1
- package/dist/packem_shared/storage-DaXAlpiO.js +0 -1
- package/dist/packem_shared/types.d-bWnqHJKL.d.ts +0 -211
- package/dist/packem_shared/types.d-xxE3FOD3.d.ts +0 -229
- package/dist/packem_shared/useLogger-DB34CuU5.js +0 -1
- package/dist/packem_shared/wide-event.d-D3ATYpoK.d.ts +0 -717
- package/dist/packem_shared/write-stream-C7jxLxIT.js +0 -1
|
@@ -1,84 +1,83 @@
|
|
|
1
|
-
import { W as WideEvent } from "../packem_shared/wide-event.d-
|
|
2
|
-
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-
|
|
1
|
+
import { W as WideEvent } from "../packem_shared/wide-event.d-BMLastMR.js";
|
|
2
|
+
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-BRkkBMlk.js";
|
|
3
3
|
import "../packem_shared/index.d-T71KjNAr.js";
|
|
4
|
-
import
|
|
5
|
-
import "../packem_shared/types.d-bWnqHJKL.js";
|
|
4
|
+
import "../packem_shared/types.d-4ge_rME4.js";
|
|
6
5
|
import '@visulima/colorize';
|
|
7
6
|
import '@visulima/interactive-manager';
|
|
8
7
|
/**
|
|
9
|
-
* A Fastify-like request object with the pail logger attached.
|
|
10
|
-
* Use this to type your route handlers when accessing `request.log`.
|
|
11
|
-
* @example
|
|
12
|
-
* ```typescript
|
|
13
|
-
* import type { PailFastifyRequest } from "@visulima/pail/middleware/fastify";
|
|
14
|
-
*
|
|
15
|
-
* app.get("/api/users", async (request: PailFastifyRequest, reply) => {
|
|
16
|
-
* request.log?.set({ user: { id: 1 } });
|
|
17
|
-
* });
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
8
|
+
* A Fastify-like request object with the pail logger attached.
|
|
9
|
+
* Use this to type your route handlers when accessing `request.log`.
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import type { PailFastifyRequest } from "@visulima/pail/middleware/fastify";
|
|
13
|
+
*
|
|
14
|
+
* app.get("/api/users", async (request: PailFastifyRequest, reply) => {
|
|
15
|
+
* request.log?.set({ user: { id: 1 } });
|
|
16
|
+
* });
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
20
19
|
interface PailFastifyRequest {
|
|
21
20
|
[key: string]: unknown;
|
|
22
21
|
headers: Record<string, string | string[] | undefined>;
|
|
23
22
|
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
* The request-scoped WideEvent logger, attached by pail plugin.
|
|
24
|
+
* Only present for non-excluded routes.
|
|
25
|
+
*/
|
|
27
26
|
log?: WideEvent;
|
|
28
27
|
method: string;
|
|
29
28
|
url: string;
|
|
30
29
|
}
|
|
31
30
|
/**
|
|
32
|
-
* A Fastify-like reply object.
|
|
33
|
-
*/
|
|
31
|
+
* A Fastify-like reply object.
|
|
32
|
+
*/
|
|
34
33
|
interface PailFastifyReply {
|
|
35
34
|
[key: string]: unknown;
|
|
36
35
|
statusCode: number;
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
|
-
* A Fastify-like instance that supports the hook registration API.
|
|
40
|
-
*/
|
|
38
|
+
* A Fastify-like instance that supports the hook registration API.
|
|
39
|
+
*/
|
|
41
40
|
interface PailFastifyInstance {
|
|
42
41
|
addHook: ((name: "onError", hook: (request: PailFastifyRequest, reply: PailFastifyReply, error: Error) => Promise<void>) => void) & ((name: "onRequest", hook: (request: PailFastifyRequest, reply: PailFastifyReply, done: () => void) => void) => void) & ((name: "onResponse", hook: (request: PailFastifyRequest, reply: PailFastifyReply) => Promise<void>) => void);
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
|
-
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
46
|
-
* Must be called within a request handled by the pail Fastify plugin.
|
|
47
|
-
* @returns The request-scoped WideEvent logger
|
|
48
|
-
* @throws Error if called outside of the plugin context
|
|
49
|
-
*/
|
|
44
|
+
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
45
|
+
* Must be called within a request handled by the pail Fastify plugin.
|
|
46
|
+
* @returns The request-scoped WideEvent logger
|
|
47
|
+
* @throws Error if called outside of the plugin context
|
|
48
|
+
*/
|
|
50
49
|
declare const useLogger: () => WideEvent;
|
|
51
50
|
/**
|
|
52
|
-
* Configuration options for the Fastify pail plugin.
|
|
53
|
-
* @template T - Custom logger type names from the pail instance
|
|
54
|
-
*/
|
|
51
|
+
* Configuration options for the Fastify pail plugin.
|
|
52
|
+
* @template T - Custom logger type names from the pail instance
|
|
53
|
+
*/
|
|
55
54
|
type FastifyPluginOptions<T extends string = string> = PailMiddlewareOptions<T>;
|
|
56
55
|
/**
|
|
57
|
-
* Register pail wide event logging as a Fastify plugin.
|
|
58
|
-
*
|
|
59
|
-
* Attaches a WideEvent logger to each request, accessible via:
|
|
60
|
-
* - `request.log` on the Fastify request object
|
|
61
|
-
* - `useLogger()` from anywhere in the async call stack
|
|
62
|
-
*
|
|
63
|
-
* The wide event is automatically emitted on response or error.
|
|
64
|
-
* @param fastify The Fastify instance
|
|
65
|
-
* @param options Plugin configuration
|
|
66
|
-
* @example
|
|
67
|
-
* ```typescript
|
|
68
|
-
* import Fastify from "fastify";
|
|
69
|
-
* import { createPail } from "@visulima/pail";
|
|
70
|
-
* import { pailPlugin, useLogger } from "@visulima/pail/middleware/fastify";
|
|
71
|
-
*
|
|
72
|
-
* const app = Fastify();
|
|
73
|
-
* const logger = createPail();
|
|
74
|
-
*
|
|
75
|
-
* pailPlugin(app, { pail: logger });
|
|
76
|
-
*
|
|
77
|
-
* app.get("/api/users", async (request, reply) => {
|
|
78
|
-
* request.log.set({ user: { id: 1 } });
|
|
79
|
-
* return { ok: true };
|
|
80
|
-
* });
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
56
|
+
* Register pail wide event logging as a Fastify plugin.
|
|
57
|
+
*
|
|
58
|
+
* Attaches a WideEvent logger to each request, accessible via:
|
|
59
|
+
* - `request.log` on the Fastify request object
|
|
60
|
+
* - `useLogger()` from anywhere in the async call stack
|
|
61
|
+
*
|
|
62
|
+
* The wide event is automatically emitted on response or error.
|
|
63
|
+
* @param fastify The Fastify instance
|
|
64
|
+
* @param options Plugin configuration
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import Fastify from "fastify";
|
|
68
|
+
* import { createPail } from "@visulima/pail";
|
|
69
|
+
* import { pailPlugin, useLogger } from "@visulima/pail/middleware/fastify";
|
|
70
|
+
*
|
|
71
|
+
* const app = Fastify();
|
|
72
|
+
* const logger = createPail();
|
|
73
|
+
*
|
|
74
|
+
* pailPlugin(app, { pail: logger });
|
|
75
|
+
*
|
|
76
|
+
* app.get("/api/users", async (request, reply) => {
|
|
77
|
+
* request.log.set({ user: { id: 1 } });
|
|
78
|
+
* return { ok: true };
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
83
82
|
declare const pailPlugin: <T extends string = string>(fastify: PailFastifyInstance, options: FastifyPluginOptions<T>) => void;
|
|
84
83
|
export { type FastifyPluginOptions, type PailFastifyInstance, type PailFastifyReply, type PailFastifyRequest, type WideEvent, pailPlugin, useLogger };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as h,c as f}from"../packem_shared/headers-DI58djdG.js";import{c as l}from"../packem_shared/storage-DVcJumyk.js";const i=l("Fastify middleware context. Make sure pail plugin is registered before your route handlers."),y=()=>i.useLogger(),w=(o,g)=>{const t=new WeakMap,s=new WeakSet;o.addHook("onRequest",(e,d,r)=>{const a=e.headers["x-request-id"]??crypto.randomUUID(),c=h(e.headers),{finish:u,logger:n,skipped:p}=f(g,{headers:c,method:e.method,path:e.url.split("?")[0],requestId:a});if(p){r();return}e.log=n,t.set(e,{finish:u}),i.storage.run(n,()=>{r()})}),o.addHook("onResponse",async(e,d)=>{const r=t.get(e);!r||s.has(e)||(s.add(e),r.finish({status:d.statusCode}))}),o.addHook("onError",async(e,d,r)=>{const a=t.get(e);!a||s.has(e)||(s.add(e),a.finish({error:r}))})};export{w as pailPlugin,y as useLogger};
|
|
@@ -1,24 +1,23 @@
|
|
|
1
|
-
import { W as WideEvent } from "../packem_shared/wide-event.d-
|
|
2
|
-
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-
|
|
1
|
+
import { W as WideEvent } from "../packem_shared/wide-event.d-BMLastMR.js";
|
|
2
|
+
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-BRkkBMlk.js";
|
|
3
3
|
import "../packem_shared/index.d-T71KjNAr.js";
|
|
4
|
-
import
|
|
5
|
-
import "../packem_shared/types.d-bWnqHJKL.js";
|
|
4
|
+
import "../packem_shared/types.d-4ge_rME4.js";
|
|
6
5
|
import '@visulima/colorize';
|
|
7
6
|
import '@visulima/interactive-manager';
|
|
8
7
|
/**
|
|
9
|
-
* A Hono-like context object with access to the pail logger.
|
|
10
|
-
*
|
|
11
|
-
* Use `c.get("log")` or `useLogger(c)` to access the WideEvent logger.
|
|
12
|
-
* @example
|
|
13
|
-
* ```typescript
|
|
14
|
-
* import type { PailHonoContext } from "@visulima/pail/middleware/hono";
|
|
15
|
-
*
|
|
16
|
-
* app.get("/api/users", (c: PailHonoContext) => {
|
|
17
|
-
* const log = c.get("log");
|
|
18
|
-
* log.set({ user: { id: 1 } });
|
|
19
|
-
* });
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
8
|
+
* A Hono-like context object with access to the pail logger.
|
|
9
|
+
*
|
|
10
|
+
* Use `c.get("log")` or `useLogger(c)` to access the WideEvent logger.
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import type { PailHonoContext } from "@visulima/pail/middleware/hono";
|
|
14
|
+
*
|
|
15
|
+
* app.get("/api/users", (c: PailHonoContext) => {
|
|
16
|
+
* const log = c.get("log");
|
|
17
|
+
* log.set({ user: { id: 1 } });
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
22
21
|
interface PailHonoContext {
|
|
23
22
|
[key: string]: unknown;
|
|
24
23
|
get: (key: string) => unknown;
|
|
@@ -36,53 +35,53 @@ interface PailHonoContext {
|
|
|
36
35
|
set: (key: string, value: unknown) => void;
|
|
37
36
|
}
|
|
38
37
|
/**
|
|
39
|
-
* Hono-compatible next function.
|
|
40
|
-
*/
|
|
38
|
+
* Hono-compatible next function.
|
|
39
|
+
*/
|
|
41
40
|
type PailHonoNext = () => Promise<void>;
|
|
42
41
|
/**
|
|
43
|
-
* The Hono middleware function signature returned by `pailMiddleware()`.
|
|
44
|
-
*/
|
|
42
|
+
* The Hono middleware function signature returned by `pailMiddleware()`.
|
|
43
|
+
*/
|
|
45
44
|
type PailHonoMiddleware = (c: PailHonoContext, next: PailHonoNext) => Promise<void>;
|
|
46
45
|
/**
|
|
47
|
-
* Configuration options for the Hono pail middleware.
|
|
48
|
-
* @template T - Custom logger type names from the pail instance
|
|
49
|
-
*/
|
|
46
|
+
* Configuration options for the Hono pail middleware.
|
|
47
|
+
* @template T - Custom logger type names from the pail instance
|
|
48
|
+
*/
|
|
50
49
|
type HonoMiddlewareOptions<T extends string = string> = PailMiddlewareOptions<T>;
|
|
51
50
|
/**
|
|
52
|
-
* Retrieve the WideEvent logger from Hono context.
|
|
53
|
-
* Must be called within a request handler where pail middleware is active.
|
|
54
|
-
* @param c The Hono context object
|
|
55
|
-
* @returns The request-scoped WideEvent logger
|
|
56
|
-
* @throws Error if the middleware is not registered
|
|
57
|
-
*/
|
|
51
|
+
* Retrieve the WideEvent logger from Hono context.
|
|
52
|
+
* Must be called within a request handler where pail middleware is active.
|
|
53
|
+
* @param c The Hono context object
|
|
54
|
+
* @returns The request-scoped WideEvent logger
|
|
55
|
+
* @throws Error if the middleware is not registered
|
|
56
|
+
*/
|
|
58
57
|
declare const useLogger: (c: PailHonoContext) => WideEvent;
|
|
59
58
|
/**
|
|
60
|
-
* Create Hono middleware that attaches a WideEvent logger to each request.
|
|
61
|
-
*
|
|
62
|
-
* The logger is available via:
|
|
63
|
-
* - `c.get("log")` on the Hono context
|
|
64
|
-
* - `useLogger(c)` helper function
|
|
65
|
-
*
|
|
66
|
-
* The wide event is automatically emitted when the handler completes or throws.
|
|
67
|
-
* @param options Middleware configuration
|
|
68
|
-
* @returns Hono middleware function
|
|
69
|
-
* @example
|
|
70
|
-
* ```typescript
|
|
71
|
-
* import { Hono } from "hono";
|
|
72
|
-
* import { createPail } from "@visulima/pail";
|
|
73
|
-
* import { pailMiddleware, useLogger } from "@visulima/pail/middleware/hono";
|
|
74
|
-
*
|
|
75
|
-
* const app = new Hono();
|
|
76
|
-
* const logger = createPail();
|
|
77
|
-
*
|
|
78
|
-
* app.use("*", pailMiddleware({ pail: logger }));
|
|
79
|
-
*
|
|
80
|
-
* app.get("/api/users", (c) => {
|
|
81
|
-
* const log = useLogger(c);
|
|
82
|
-
* log.set({ user: { id: 1 } });
|
|
83
|
-
* return c.json({ ok: true });
|
|
84
|
-
* });
|
|
85
|
-
* ```
|
|
86
|
-
*/
|
|
59
|
+
* Create Hono middleware that attaches a WideEvent logger to each request.
|
|
60
|
+
*
|
|
61
|
+
* The logger is available via:
|
|
62
|
+
* - `c.get("log")` on the Hono context
|
|
63
|
+
* - `useLogger(c)` helper function
|
|
64
|
+
*
|
|
65
|
+
* The wide event is automatically emitted when the handler completes or throws.
|
|
66
|
+
* @param options Middleware configuration
|
|
67
|
+
* @returns Hono middleware function
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { Hono } from "hono";
|
|
71
|
+
* import { createPail } from "@visulima/pail";
|
|
72
|
+
* import { pailMiddleware, useLogger } from "@visulima/pail/middleware/hono";
|
|
73
|
+
*
|
|
74
|
+
* const app = new Hono();
|
|
75
|
+
* const logger = createPail();
|
|
76
|
+
*
|
|
77
|
+
* app.use("*", pailMiddleware({ pail: logger }));
|
|
78
|
+
*
|
|
79
|
+
* app.get("/api/users", (c) => {
|
|
80
|
+
* const log = useLogger(c);
|
|
81
|
+
* log.set({ user: { id: 1 } });
|
|
82
|
+
* return c.json({ ok: true });
|
|
83
|
+
* });
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
87
86
|
declare const pailMiddleware: <T extends string = string>(options: HonoMiddlewareOptions<T>) => PailHonoMiddleware;
|
|
88
87
|
export { type HonoMiddlewareOptions, type PailHonoContext, type PailHonoMiddleware, type PailHonoNext, type WideEvent, pailMiddleware, useLogger };
|
package/dist/middleware/hono.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as c,c as g}from"../packem_shared/headers-
|
|
1
|
+
import{e as c,c as g}from"../packem_shared/headers-DI58djdG.js";const l=t=>{const r=t.get("log");if(!r)throw new Error("[pail] useLogger() called but pail middleware is not registered.");return r},p=t=>async(r,a)=>{const o=r.req.header("x-request-id")??crypto.randomUUID(),i=c(r.req.raw.headers),{finish:s,logger:d,skipped:n}=g(t,{headers:i,method:r.req.method,path:r.req.path,requestId:o});if(n){await a();return}r.set("log",d);try{await a(),s({status:r.res.status})}catch(e){throw s({error:e instanceof Error?e:new Error(String(e))}),e}};export{p as pailMiddleware,l as useLogger};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { P as PailMiddlewareOptions } from "../../packem_shared/create-middleware-logger.d-
|
|
2
|
-
import { W as WideEvent } from "../../packem_shared/wide-event.d-
|
|
1
|
+
import { P as PailMiddlewareOptions } from "../../packem_shared/create-middleware-logger.d-BRkkBMlk.js";
|
|
2
|
+
import { W as WideEvent } from "../../packem_shared/wide-event.d-BMLastMR.js";
|
|
3
3
|
import 'node:async_hooks';
|
|
4
|
-
import "../../packem_shared/types.d-
|
|
4
|
+
import "../../packem_shared/types.d-4ge_rME4.js";
|
|
5
5
|
import '@visulima/colorize';
|
|
6
6
|
import '@visulima/interactive-manager';
|
|
7
|
-
import 'type-fest';
|
|
8
7
|
import "../../packem_shared/index.d-T71KjNAr.js";
|
|
9
8
|
/**
|
|
10
|
-
* Minimal type definitions to avoid requiring next as a dependency.
|
|
11
|
-
*/
|
|
9
|
+
* Minimal type definitions to avoid requiring next as a dependency.
|
|
10
|
+
*/
|
|
12
11
|
interface NextRequest {
|
|
13
12
|
headers: Headers;
|
|
14
13
|
nextUrl: {
|
|
@@ -26,79 +25,79 @@ interface NextResponseConstructor {
|
|
|
26
25
|
}) => NextResponse;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
|
-
* Options for the Next.js pail middleware.
|
|
30
|
-
*/
|
|
28
|
+
* Options for the Next.js pail middleware.
|
|
29
|
+
*/
|
|
31
30
|
interface PailNextMiddlewareOptions {
|
|
32
31
|
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
32
|
+
* Glob patterns for paths to exclude from logging.
|
|
33
|
+
* Excluded paths won't get request IDs or timing headers.
|
|
34
|
+
* @example ["/_next/**", "/favicon.ico"]
|
|
35
|
+
*/
|
|
37
36
|
exclude?: string[];
|
|
38
37
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
* Glob patterns for paths to include in logging.
|
|
39
|
+
* If not set, all non-excluded paths are included.
|
|
40
|
+
*/
|
|
42
41
|
include?: string[];
|
|
43
42
|
}
|
|
44
43
|
/**
|
|
45
|
-
* Create a Next.js edge middleware that sets `x-request-id` and `x-pail-start`
|
|
46
|
-
* headers on the request for downstream use by `withPail()`.
|
|
47
|
-
*
|
|
48
|
-
* This middleware runs at the edge and prepares request metadata.
|
|
49
|
-
* The actual wide event logging happens in `withPail()`.
|
|
50
|
-
* @param NextResponseClass The NextResponse class from "next/server.js"
|
|
51
|
-
* @param options Middleware configuration
|
|
52
|
-
* @returns A middleware function
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* // middleware.ts
|
|
56
|
-
* import { NextResponse } from "next/server.js";
|
|
57
|
-
* import { pailMiddleware } from "@visulima/pail/middleware/next";
|
|
58
|
-
*
|
|
59
|
-
* const middleware = pailMiddleware(NextResponse, {
|
|
60
|
-
* exclude: ["/_next/**", "/favicon.ico"],
|
|
61
|
-
* });
|
|
62
|
-
*
|
|
63
|
-
* export default middleware;
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
44
|
+
* Create a Next.js edge middleware that sets `x-request-id` and `x-pail-start`
|
|
45
|
+
* headers on the request for downstream use by `withPail()`.
|
|
46
|
+
*
|
|
47
|
+
* This middleware runs at the edge and prepares request metadata.
|
|
48
|
+
* The actual wide event logging happens in `withPail()`.
|
|
49
|
+
* @param NextResponseClass The NextResponse class from "next/server.js"
|
|
50
|
+
* @param options Middleware configuration
|
|
51
|
+
* @returns A middleware function
|
|
52
|
+
* @example
|
|
53
|
+
* ```typescript
|
|
54
|
+
* // middleware.ts
|
|
55
|
+
* import { NextResponse } from "next/server.js";
|
|
56
|
+
* import { pailMiddleware } from "@visulima/pail/middleware/next";
|
|
57
|
+
*
|
|
58
|
+
* const middleware = pailMiddleware(NextResponse, {
|
|
59
|
+
* exclude: ["/_next/**", "/favicon.ico"],
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* export default middleware;
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
66
65
|
declare const pailMiddleware: (NextResponseClass: NextResponseConstructor, options?: PailNextMiddlewareOptions) => (request: NextRequest) => NextResponse;
|
|
67
66
|
/**
|
|
68
|
-
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
69
|
-
* Must be called within a `withPail()` wrapped handler or server action.
|
|
70
|
-
* @returns The request-scoped WideEvent logger
|
|
71
|
-
* @throws Error if called outside of a withPail context
|
|
72
|
-
*/
|
|
67
|
+
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
68
|
+
* Must be called within a `withPail()` wrapped handler or server action.
|
|
69
|
+
* @returns The request-scoped WideEvent logger
|
|
70
|
+
* @throws Error if called outside of a withPail context
|
|
71
|
+
*/
|
|
73
72
|
declare const useLogger: () => WideEvent;
|
|
74
73
|
type NextPailOptions<T extends string = string> = PailMiddlewareOptions<T>;
|
|
75
74
|
/**
|
|
76
|
-
* Create a `withPail` wrapper function for Next.js route handlers and server actions.
|
|
77
|
-
*
|
|
78
|
-
* Wraps handler execution in AsyncLocalStorage so that `useLogger()` works
|
|
79
|
-
* anywhere in the async call stack. The wide event is automatically emitted
|
|
80
|
-
* when the handler completes or throws.
|
|
81
|
-
* @param options Configuration options
|
|
82
|
-
* @returns A `withPail` wrapper function
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* // lib/pail.ts
|
|
86
|
-
* import { createPail } from "@visulima/pail";
|
|
87
|
-
* import { createWithPail } from "@visulima/pail/middleware/next";
|
|
88
|
-
*
|
|
89
|
-
* const logger = createPail();
|
|
90
|
-
* export const withPail = createWithPail({ pail: logger });
|
|
91
|
-
*
|
|
92
|
-
* // app/api/users/route.ts
|
|
93
|
-
* import { withPail } from "@/lib/pail";
|
|
94
|
-
* import { useLogger } from "@visulima/pail/middleware/next";
|
|
95
|
-
*
|
|
96
|
-
* export const GET = withPail(async (request: Request) => {
|
|
97
|
-
* const log = useLogger();
|
|
98
|
-
* log.set({ user: { id: 1 } });
|
|
99
|
-
* return Response.json({ ok: true });
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
75
|
+
* Create a `withPail` wrapper function for Next.js route handlers and server actions.
|
|
76
|
+
*
|
|
77
|
+
* Wraps handler execution in AsyncLocalStorage so that `useLogger()` works
|
|
78
|
+
* anywhere in the async call stack. The wide event is automatically emitted
|
|
79
|
+
* when the handler completes or throws.
|
|
80
|
+
* @param options Configuration options
|
|
81
|
+
* @returns A `withPail` wrapper function
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // lib/pail.ts
|
|
85
|
+
* import { createPail } from "@visulima/pail";
|
|
86
|
+
* import { createWithPail } from "@visulima/pail/middleware/next";
|
|
87
|
+
*
|
|
88
|
+
* const logger = createPail();
|
|
89
|
+
* export const withPail = createWithPail({ pail: logger });
|
|
90
|
+
*
|
|
91
|
+
* // app/api/users/route.ts
|
|
92
|
+
* import { withPail } from "@/lib/pail";
|
|
93
|
+
* import { useLogger } from "@visulima/pail/middleware/next";
|
|
94
|
+
*
|
|
95
|
+
* export const GET = withPail(async (request: Request) => {
|
|
96
|
+
* const log = useLogger();
|
|
97
|
+
* log.set({ user: { id: 1 } });
|
|
98
|
+
* return Response.json({ ok: true });
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
103
102
|
declare const createWithPail: <T extends string = string>(options: NextPailOptions<T>) => <TArgs extends unknown[], TReturn>(handler: (...args: TArgs) => Promise<TReturn> | TReturn) => (...args: TArgs) => Promise<TReturn>;
|
|
104
103
|
export { type NextPailOptions, type PailNextMiddlewareOptions, type WideEvent, createWithPail, pailMiddleware, useLogger };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{e as m,c as l}from"../../packem_shared/headers-
|
|
1
|
+
import{e as m,c as l}from"../../packem_shared/headers-DI58djdG.js";import{pailStorage as w}from"../../packem_shared/useLogger-7p55yvvc.js";import{useLogger as N}from"../../packem_shared/useLogger-7p55yvvc.js";import{pailMiddleware as S}from"../../packem_shared/pailMiddleware-B5DJoBYl.js";const q=u=>s=>async(...a)=>{const[o]=a,f=o instanceof Request;let n="UNKNOWN",i="/",c=crypto.randomUUID(),d={};if(f){const e=o,t=new URL(e.url);n=e.method,i=t.pathname,d=m(e.headers);const r=e.headers.get("x-request-id");r&&(c=r)}const{finish:p,logger:h,skipped:g}=l(u,{headers:d,method:n,path:i,requestId:c});if(g)return s(...a);try{const e=await w.run(h,()=>s(...a)),t=e instanceof Response?e.status:200;return p({status:t}),e}catch(e){const t=e instanceof Error?e:new Error(String(e)),r=t.status??t.statusCode??500;throw p({error:t,status:r}),e}};export{q as createWithPail,S as pailMiddleware,N as useLogger};
|
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import { W as WideEvent } from "../packem_shared/wide-event.d-
|
|
2
|
-
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-
|
|
1
|
+
import { W as WideEvent } from "../packem_shared/wide-event.d-BMLastMR.js";
|
|
2
|
+
import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-BRkkBMlk.js";
|
|
3
3
|
import "../packem_shared/index.d-T71KjNAr.js";
|
|
4
|
-
import
|
|
5
|
-
import "../packem_shared/types.d-bWnqHJKL.js";
|
|
4
|
+
import "../packem_shared/types.d-4ge_rME4.js";
|
|
6
5
|
import '@visulima/colorize';
|
|
7
6
|
import '@visulima/interactive-manager';
|
|
8
7
|
/**
|
|
9
|
-
* A SvelteKit-like event object with access to the pail logger via `locals.log`.
|
|
10
|
-
* @example
|
|
11
|
-
* ```typescript
|
|
12
|
-
* // In a SvelteKit load function or action:
|
|
13
|
-
* import type { PailSvelteKitEvent } from "@visulima/pail/middleware/sveltekit";
|
|
14
|
-
*
|
|
15
|
-
* export const load = async (event: PailSvelteKitEvent) => {
|
|
16
|
-
* event.locals.log?.set({ user: { id: 1 } });
|
|
17
|
-
* };
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
8
|
+
* A SvelteKit-like event object with access to the pail logger via `locals.log`.
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // In a SvelteKit load function or action:
|
|
12
|
+
* import type { PailSvelteKitEvent } from "@visulima/pail/middleware/sveltekit";
|
|
13
|
+
*
|
|
14
|
+
* export const load = async (event: PailSvelteKitEvent) => {
|
|
15
|
+
* event.locals.log?.set({ user: { id: 1 } });
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
20
19
|
interface PailSvelteKitEvent {
|
|
21
20
|
[key: string]: unknown;
|
|
22
21
|
locals: Record<string, unknown> & {
|
|
@@ -26,8 +25,8 @@ interface PailSvelteKitEvent {
|
|
|
26
25
|
url: URL;
|
|
27
26
|
}
|
|
28
27
|
/**
|
|
29
|
-
* Options passed to SvelteKit's resolve function.
|
|
30
|
-
*/
|
|
28
|
+
* Options passed to SvelteKit's resolve function.
|
|
29
|
+
*/
|
|
31
30
|
interface PailSvelteKitResolveOptions {
|
|
32
31
|
filterSerializedResponseHeaders?: (name: string) => boolean;
|
|
33
32
|
preload?: (input: {
|
|
@@ -38,23 +37,23 @@ interface PailSvelteKitResolveOptions {
|
|
|
38
37
|
}) => string;
|
|
39
38
|
}
|
|
40
39
|
/**
|
|
41
|
-
* SvelteKit resolve function type.
|
|
42
|
-
*/
|
|
40
|
+
* SvelteKit resolve function type.
|
|
41
|
+
*/
|
|
43
42
|
type PailSvelteKitResolve = (event: PailSvelteKitEvent, options?: PailSvelteKitResolveOptions) => Promise<Response>;
|
|
44
43
|
/**
|
|
45
|
-
* Input for the SvelteKit handle hook.
|
|
46
|
-
*/
|
|
44
|
+
* Input for the SvelteKit handle hook.
|
|
45
|
+
*/
|
|
47
46
|
interface PailSvelteKitHandleInput {
|
|
48
47
|
event: PailSvelteKitEvent;
|
|
49
48
|
resolve: PailSvelteKitResolve;
|
|
50
49
|
}
|
|
51
50
|
/**
|
|
52
|
-
* SvelteKit handle hook function type returned by `pailHandle()`.
|
|
53
|
-
*/
|
|
51
|
+
* SvelteKit handle hook function type returned by `pailHandle()`.
|
|
52
|
+
*/
|
|
54
53
|
type PailSvelteKitHandle = (input: PailSvelteKitHandleInput) => Promise<Response>;
|
|
55
54
|
/**
|
|
56
|
-
* Input for the SvelteKit handleError hook.
|
|
57
|
-
*/
|
|
55
|
+
* Input for the SvelteKit handleError hook.
|
|
56
|
+
*/
|
|
58
57
|
interface PailSvelteKitHandleErrorInput {
|
|
59
58
|
error: unknown;
|
|
60
59
|
event: PailSvelteKitEvent;
|
|
@@ -62,63 +61,63 @@ interface PailSvelteKitHandleErrorInput {
|
|
|
62
61
|
status: number;
|
|
63
62
|
}
|
|
64
63
|
/**
|
|
65
|
-
* SvelteKit handleError hook function type returned by `pailHandleError()`.
|
|
66
|
-
*/
|
|
64
|
+
* SvelteKit handleError hook function type returned by `pailHandleError()`.
|
|
65
|
+
*/
|
|
67
66
|
type PailSvelteKitHandleError = (input: PailSvelteKitHandleErrorInput) => void;
|
|
68
67
|
/**
|
|
69
|
-
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
70
|
-
* Must be called within a request handled by the pail SvelteKit handle hook.
|
|
71
|
-
* @returns The request-scoped WideEvent logger
|
|
72
|
-
* @throws Error if called outside of the hook context
|
|
73
|
-
*/
|
|
68
|
+
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
69
|
+
* Must be called within a request handled by the pail SvelteKit handle hook.
|
|
70
|
+
* @returns The request-scoped WideEvent logger
|
|
71
|
+
* @throws Error if called outside of the hook context
|
|
72
|
+
*/
|
|
74
73
|
declare const useLogger: () => WideEvent;
|
|
75
74
|
type SvelteKitHandleOptions<T extends string = string> = PailMiddlewareOptions<T>;
|
|
76
75
|
/**
|
|
77
|
-
* Create a SvelteKit `handle` hook that attaches a WideEvent logger to each request.
|
|
78
|
-
*
|
|
79
|
-
* The logger is available via:
|
|
80
|
-
* - `event.locals.log` in server load functions and actions
|
|
81
|
-
* - `useLogger()` from anywhere in the async call stack
|
|
82
|
-
*
|
|
83
|
-
* The wide event is automatically emitted when the response is sent or an error occurs.
|
|
84
|
-
* @param options Hook configuration
|
|
85
|
-
* @returns SvelteKit handle hook function
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* // src/hooks.server.ts
|
|
89
|
-
* import { createPail } from "@visulima/pail";
|
|
90
|
-
* import { pailHandle, pailHandleError } from "@visulima/pail/middleware/sveltekit";
|
|
91
|
-
*
|
|
92
|
-
* const logger = createPail();
|
|
93
|
-
*
|
|
94
|
-
* export const handle = pailHandle({ pail: logger });
|
|
95
|
-
* export const handleError = pailHandleError();
|
|
96
|
-
* ```
|
|
97
|
-
*/
|
|
76
|
+
* Create a SvelteKit `handle` hook that attaches a WideEvent logger to each request.
|
|
77
|
+
*
|
|
78
|
+
* The logger is available via:
|
|
79
|
+
* - `event.locals.log` in server load functions and actions
|
|
80
|
+
* - `useLogger()` from anywhere in the async call stack
|
|
81
|
+
*
|
|
82
|
+
* The wide event is automatically emitted when the response is sent or an error occurs.
|
|
83
|
+
* @param options Hook configuration
|
|
84
|
+
* @returns SvelteKit handle hook function
|
|
85
|
+
* @example
|
|
86
|
+
* ```typescript
|
|
87
|
+
* // src/hooks.server.ts
|
|
88
|
+
* import { createPail } from "@visulima/pail";
|
|
89
|
+
* import { pailHandle, pailHandleError } from "@visulima/pail/middleware/sveltekit";
|
|
90
|
+
*
|
|
91
|
+
* const logger = createPail();
|
|
92
|
+
*
|
|
93
|
+
* export const handle = pailHandle({ pail: logger });
|
|
94
|
+
* export const handleError = pailHandleError();
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
98
97
|
declare const pailHandle: <T extends string = string>(options: SvelteKitHandleOptions<T>) => PailSvelteKitHandle;
|
|
99
98
|
/**
|
|
100
|
-
* Create a SvelteKit `handleError` hook that captures errors into the WideEvent logger.
|
|
101
|
-
*
|
|
102
|
-
* Should be used alongside `pailHandle` to ensure errors are recorded in the wide event.
|
|
103
|
-
* @returns SvelteKit handleError hook function
|
|
104
|
-
*/
|
|
99
|
+
* Create a SvelteKit `handleError` hook that captures errors into the WideEvent logger.
|
|
100
|
+
*
|
|
101
|
+
* Should be used alongside `pailHandle` to ensure errors are recorded in the wide event.
|
|
102
|
+
* @returns SvelteKit handleError hook function
|
|
103
|
+
*/
|
|
105
104
|
declare const pailHandleError: () => PailSvelteKitHandleError;
|
|
106
105
|
/**
|
|
107
|
-
* Convenience function that returns both handle and handleError hooks.
|
|
108
|
-
* @param options Hook configuration
|
|
109
|
-
* @returns Object with `handle` and `handleError` hooks
|
|
110
|
-
* @example
|
|
111
|
-
* ```typescript
|
|
112
|
-
* // src/hooks.server.ts
|
|
113
|
-
* import { createPail } from "@visulima/pail";
|
|
114
|
-
* import { createPailHooks } from "@visulima/pail/middleware/sveltekit";
|
|
115
|
-
*
|
|
116
|
-
* const logger = createPail();
|
|
117
|
-
* const { handle, handleError } = createPailHooks({ pail: logger });
|
|
118
|
-
*
|
|
119
|
-
* export { handle, handleError };
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
106
|
+
* Convenience function that returns both handle and handleError hooks.
|
|
107
|
+
* @param options Hook configuration
|
|
108
|
+
* @returns Object with `handle` and `handleError` hooks
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* // src/hooks.server.ts
|
|
112
|
+
* import { createPail } from "@visulima/pail";
|
|
113
|
+
* import { createPailHooks } from "@visulima/pail/middleware/sveltekit";
|
|
114
|
+
*
|
|
115
|
+
* const logger = createPail();
|
|
116
|
+
* const { handle, handleError } = createPailHooks({ pail: logger });
|
|
117
|
+
*
|
|
118
|
+
* export { handle, handleError };
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
122
121
|
declare const createPailHooks: <T extends string = string>(options: SvelteKitHandleOptions<T>) => {
|
|
123
122
|
handle: PailSvelteKitHandle;
|
|
124
123
|
handleError: PailSvelteKitHandleError;
|