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

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 (106) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/LICENSE.md +143 -931
  3. package/dist/error.d.ts +95 -96
  4. package/dist/index.browser.d.ts +557 -47
  5. package/dist/index.browser.js +2 -2
  6. package/dist/index.server.d.ts +722 -65
  7. package/dist/index.server.js +27 -410
  8. package/dist/middleware/elysia.d.ts +65 -63
  9. package/dist/middleware/elysia.js +2 -2
  10. package/dist/middleware/express.d.ts +73 -71
  11. package/dist/middleware/express.js +1 -1
  12. package/dist/middleware/fastify.d.ts +69 -67
  13. package/dist/middleware/fastify.js +2 -2
  14. package/dist/middleware/hono.d.ts +74 -72
  15. package/dist/middleware/next/handler.d.ts +101 -34
  16. package/dist/middleware/sveltekit.d.ts +100 -98
  17. package/dist/object-tree.d.ts +67 -70
  18. package/dist/packem_shared/{AbstractJsonReporter-DlugSJpY.js → AbstractJsonReporter-BO8Calb4.js} +1 -5
  19. package/dist/packem_shared/{AbstractJsonReporter-CjtVgHbU.js → AbstractJsonReporter-nOj0Ft1F.js} +1 -5
  20. package/dist/packem_shared/{JsonReporter-Dbw82ewj.js → JsonReporter-CCmj7oYL.js} +1 -1
  21. package/dist/packem_shared/{JsonReporter-BgPvIyC2.js → JsonReporter-Ck2PIAEw.js} +2 -2
  22. package/dist/packem_shared/{PrettyReporter-C2dCzIaf.js → PrettyReporter-CIbrmjUV.js} +2 -4
  23. package/dist/packem_shared/{PrettyReporter-gMqa7j_m.js → PrettyReporter-CNJEO9g7.js} +1250 -15
  24. package/dist/packem_shared/abstract-json-reporter.d-BAgznjyU.d.ts +61 -0
  25. package/dist/packem_shared/{abstract-pretty-reporter-szQO-IgK.js → abstract-pretty-reporter-CkqCt5hg.js} +2300 -2298
  26. package/dist/packem_shared/create-middleware-logger.d-DheMh8q4.d.ts +47 -0
  27. package/dist/packem_shared/{index-Bx3-C0j9.js → index-6cG1Kp0t.js} +2 -2
  28. package/dist/packem_shared/types.d-BeLumqgD.d.ts +246 -0
  29. package/dist/packem_shared/types.d-C51XNfQz.d.ts +194 -0
  30. package/dist/packem_shared/types.d-CM5ie2qm.d.ts +236 -0
  31. package/dist/packem_shared/wide-event.d-B-t8ZnhI.d.ts +704 -0
  32. package/dist/packem_shared/{write-stream-BuFtjATz.js → write-stream-MDqyXmc_.js} +1 -1
  33. package/dist/processor/caller/caller-processor.d.ts +49 -47
  34. package/dist/processor/caller/caller-processor.js +1 -1
  35. package/dist/processor/environment-processor.d.ts +113 -113
  36. package/dist/processor/message-formatter-processor.d.ts +51 -49
  37. package/dist/processor/message-formatter-processor.js +2 -2
  38. package/dist/processor/opentelemetry-processor.d.ts +69 -66
  39. package/dist/processor/redact-processor.d.ts +60 -41
  40. package/dist/processor/sampling-processor.d.ts +102 -101
  41. package/dist/reporter/file/json-file-reporter.d.ts +91 -42
  42. package/dist/reporter/file/json-file-reporter.js +1 -1
  43. package/dist/reporter/http/abstract-http-reporter.d.ts +213 -211
  44. package/dist/reporter/http/abstract-http-reporter.js +1 -1
  45. package/dist/reporter/http/http-reporter.d.ts +40 -36
  46. package/dist/reporter/http/http-reporter.edge-light.d.ts +430 -38
  47. package/dist/reporter/http/http-reporter.edge-light.js +1 -5
  48. package/dist/reporter/json/index.browser.d.ts +99 -3
  49. package/dist/reporter/json/index.browser.js +2 -2
  50. package/dist/reporter/json/index.d.ts +51 -3
  51. package/dist/reporter/json/index.js +2 -2
  52. package/dist/reporter/pretty/index.browser.d.ts +106 -2
  53. package/dist/reporter/pretty/index.browser.js +1 -1
  54. package/dist/reporter/pretty/index.d.ts +219 -2
  55. package/dist/reporter/pretty/index.js +1 -1
  56. package/dist/reporter/simple/simple-reporter.server.d.ts +168 -18
  57. package/dist/reporter/simple/simple-reporter.server.js +3 -2
  58. package/dist/wide-event.d.ts +5 -300
  59. package/dist/wide-event.js +3 -2
  60. package/package.json +9 -21
  61. package/dist/constants.d.ts +0 -37
  62. package/dist/interactive/index.d.ts +0 -2
  63. package/dist/interactive/index.js +0 -2
  64. package/dist/interactive/interactive-manager.d.ts +0 -108
  65. package/dist/interactive/interactive-stream-hook.d.ts +0 -68
  66. package/dist/middleware/next/middleware.d.ts +0 -59
  67. package/dist/middleware/next/storage.d.ts +0 -14
  68. package/dist/middleware/shared/create-middleware-logger.d.ts +0 -82
  69. package/dist/middleware/shared/headers.d.ts +0 -14
  70. package/dist/middleware/shared/routes.d.ts +0 -30
  71. package/dist/middleware/shared/storage.d.ts +0 -29
  72. package/dist/packem_shared/InteractiveManager-CowYA3Hx.js +0 -178
  73. package/dist/packem_shared/InteractiveStreamHook-BypRlYTX.js +0 -133
  74. package/dist/packem_shared/Spinner-Cokext9b.js +0 -2183
  75. package/dist/packem_shared/getBarChar-D7JfmdTr.js +0 -459
  76. package/dist/packem_shared/index-BEfVUy9P.js +0 -1256
  77. package/dist/pail.browser.d.ts +0 -412
  78. package/dist/pail.server.d.ts +0 -233
  79. package/dist/processor/caller/get-caller-filename.d.ts +0 -23
  80. package/dist/progress-bar.d.ts +0 -145
  81. package/dist/progress-bar.js +0 -459
  82. package/dist/reporter/file/utils/rotating-file-stream.d.ts +0 -48
  83. package/dist/reporter/http/utils/compression.d.ts +0 -7
  84. package/dist/reporter/http/utils/log-size-error.d.ts +0 -30
  85. package/dist/reporter/http/utils/retry.d.ts +0 -27
  86. package/dist/reporter/json/abstract-json-reporter.d.ts +0 -61
  87. package/dist/reporter/json/json-reporter.browser.d.ts +0 -40
  88. package/dist/reporter/json/json-reporter.server.d.ts +0 -50
  89. package/dist/reporter/pretty/abstract-pretty-reporter.d.ts +0 -83
  90. package/dist/reporter/pretty/pretty-reporter.browser.d.ts +0 -36
  91. package/dist/reporter/pretty/pretty-reporter.server.d.ts +0 -70
  92. package/dist/reporter/raw/raw-reporter.browser.d.ts +0 -5
  93. package/dist/reporter/raw/raw-reporter.server.d.ts +0 -13
  94. package/dist/reporter/utils/default-inspector-config.d.ts +0 -3
  95. package/dist/reporter/utils/format-label.d.ts +0 -3
  96. package/dist/spinner.d.ts +0 -220
  97. package/dist/spinner.js +0 -2183
  98. package/dist/types.d.ts +0 -241
  99. package/dist/utils/ansi-escapes.d.ts +0 -4
  100. package/dist/utils/arrayify.d.ts +0 -2
  101. package/dist/utils/get-longest-badge.d.ts +0 -4
  102. package/dist/utils/get-longest-label.d.ts +0 -4
  103. package/dist/utils/merge-types.d.ts +0 -4
  104. package/dist/utils/stream/safe-stream-handler.d.ts +0 -21
  105. package/dist/utils/write-console-log-based-on-level.d.ts +0 -4
  106. package/dist/utils/write-stream.d.ts +0 -2
@@ -1,86 +1,88 @@
1
- import type { WideEvent } from "../wide-event.d.ts";
2
- import type { PailMiddlewareOptions } from "./shared/create-middleware-logger.d.ts";
1
+ import { W as WideEvent } from "../packem_shared/wide-event.d-B-t8ZnhI.js";
2
+ import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-DheMh8q4.js";
3
+ import 'safe-stable-stringify';
4
+ import "../packem_shared/types.d-BeLumqgD.js";
5
+ import '@visulima/colorize';
6
+ import '@visulima/interactive-manager';
3
7
  /**
4
- * An Express-like request object with the pail logger attached.
5
- * Use this to type your route handlers when accessing `req.log`.
6
- * @example
7
- * ```typescript
8
- * import type { PailRequest } from "@visulima/pail/middleware/express";
9
- *
10
- * app.get("/api/users", (req: PailRequest, res) => {
11
- * req.log?.set({ user: { id: 1 } });
12
- * });
13
- * ```
14
- */
8
+ * An Express-like request object with the pail logger attached.
9
+ * Use this to type your route handlers when accessing `req.log`.
10
+ * @example
11
+ * ```typescript
12
+ * import type { PailRequest } from "@visulima/pail/middleware/express";
13
+ *
14
+ * app.get("/api/users", (req: PailRequest, res) => {
15
+ * req.log?.set({ user: { id: 1 } });
16
+ * });
17
+ * ```
18
+ */
15
19
  interface PailRequest {
16
- [key: string]: unknown;
17
- headers: Record<string, string | string[] | undefined>;
18
- /**
19
- * The request-scoped WideEvent logger, attached by pail middleware.
20
- * Only present for non-excluded routes.
21
- */
22
- log?: WideEvent;
23
- method: string;
24
- originalUrl?: string;
25
- path: string;
20
+ [key: string]: unknown;
21
+ headers: Record<string, string | string[] | undefined>;
22
+ /**
23
+ * The request-scoped WideEvent logger, attached by pail middleware.
24
+ * Only present for non-excluded routes.
25
+ */
26
+ log?: WideEvent;
27
+ method: string;
28
+ originalUrl?: string;
29
+ path: string;
26
30
  }
27
31
  /**
28
- * An Express-like response object.
29
- */
32
+ * An Express-like response object.
33
+ */
30
34
  interface PailResponse {
31
- [key: string]: unknown;
32
- on: (event: string, listener: () => void) => void;
33
- statusCode: number;
35
+ [key: string]: unknown;
36
+ on: (event: string, listener: () => void) => void;
37
+ statusCode: number;
34
38
  }
35
39
  /**
36
- * Express-compatible next function.
37
- */
40
+ * Express-compatible next function.
41
+ */
38
42
  type PailNextFunction = (error?: unknown) => void;
39
43
  /**
40
- * The Express middleware function signature returned by `pailMiddleware()`.
41
- */
44
+ * The Express middleware function signature returned by `pailMiddleware()`.
45
+ */
42
46
  type PailExpressMiddleware = (request: PailRequest, response: PailResponse, next: PailNextFunction) => void;
43
47
  /**
44
- * Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
45
- * Must be called within a request handled by the pail Express middleware.
46
- * @returns The request-scoped WideEvent logger
47
- * @throws Error if called outside of the middleware context
48
- */
48
+ * Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
49
+ * Must be called within a request handled by the pail Express middleware.
50
+ * @returns The request-scoped WideEvent logger
51
+ * @throws Error if called outside of the middleware context
52
+ */
49
53
  declare const useLogger: () => WideEvent;
50
54
  /**
51
- * Configuration options for the Express pail middleware.
52
- * @template T - Custom logger type names from the pail instance
53
- */
55
+ * Configuration options for the Express pail middleware.
56
+ * @template T - Custom logger type names from the pail instance
57
+ */
54
58
  type ExpressMiddlewareOptions<T extends string = string> = PailMiddlewareOptions<T>;
55
59
  /**
56
- * Create Express middleware that attaches a WideEvent logger to each request.
57
- *
58
- * The logger is available via:
59
- * - `req.log` on the request object
60
- * - `useLogger()` from anywhere in the async call stack
61
- *
62
- * The wide event is automatically emitted when the response finishes.
63
- * @param options Middleware configuration
64
- * @returns Express middleware function
65
- * @example
66
- * ```typescript
67
- * import express from "express";
68
- * import { createPail } from "@visulima/pail";
69
- * import { pailMiddleware, useLogger } from "@visulima/pail/middleware/express";
70
- *
71
- * const app = express();
72
- * const logger = createPail();
73
- *
74
- * app.use(pailMiddleware({ pail: logger }));
75
- *
76
- * app.get("/api/users", (req, res) => {
77
- * req.log.set({ user: { id: 1 } });
78
- * // or: useLogger().set({ user: { id: 1 } });
79
- * res.json({ ok: true });
80
- * });
81
- * ```
82
- */
83
- export declare const pailMiddleware: <T extends string = string>(options: ExpressMiddlewareOptions<T>) => PailExpressMiddleware;
84
- export { useLogger };
85
- export type { ExpressMiddlewareOptions, PailExpressMiddleware, PailNextFunction, PailRequest, PailResponse };
86
- export type { WideEvent } from "../wide-event.d.ts";
60
+ * Create Express middleware that attaches a WideEvent logger to each request.
61
+ *
62
+ * The logger is available via:
63
+ * - `req.log` on the request object
64
+ * - `useLogger()` from anywhere in the async call stack
65
+ *
66
+ * The wide event is automatically emitted when the response finishes.
67
+ * @param options Middleware configuration
68
+ * @returns Express middleware function
69
+ * @example
70
+ * ```typescript
71
+ * import express from "express";
72
+ * import { createPail } from "@visulima/pail";
73
+ * import { pailMiddleware, useLogger } from "@visulima/pail/middleware/express";
74
+ *
75
+ * const app = express();
76
+ * const logger = createPail();
77
+ *
78
+ * app.use(pailMiddleware({ pail: logger }));
79
+ *
80
+ * app.get("/api/users", (req, res) => {
81
+ * req.log.set({ user: { id: 1 } });
82
+ * // or: useLogger().set({ user: { id: 1 } });
83
+ * res.json({ ok: true });
84
+ * });
85
+ * ```
86
+ */
87
+ declare const pailMiddleware: <T extends string = string>(options: ExpressMiddlewareOptions<T>) => PailExpressMiddleware;
88
+ export { type ExpressMiddlewareOptions, type PailExpressMiddleware, type PailNextFunction, type PailRequest, type PailResponse, type WideEvent, pailMiddleware, useLogger };
@@ -5,7 +5,7 @@ const loggerStorage = createLoggerStorage("Express middleware context. Make sure
5
5
  const useLogger = () => loggerStorage.useLogger();
6
6
  const pailMiddleware = (options) => (request, response, next) => {
7
7
  const requestId = request.headers["x-request-id"] ?? crypto.randomUUID();
8
- const path = request.originalUrl;
8
+ const path = request.originalUrl ?? request.url ?? "/";
9
9
  const safeHeaders = extractSafeNodeHeaders(request.headers);
10
10
  const { finish, logger, skipped } = createMiddlewareLogger(options, {
11
11
  headers: safeHeaders,
@@ -1,81 +1,83 @@
1
- import type { WideEvent } from "../wide-event.d.ts";
2
- import type { PailMiddlewareOptions } from "./shared/create-middleware-logger.d.ts";
1
+ import { W as WideEvent } from "../packem_shared/wide-event.d-B-t8ZnhI.js";
2
+ import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-DheMh8q4.js";
3
+ import 'safe-stable-stringify';
4
+ import "../packem_shared/types.d-BeLumqgD.js";
5
+ import '@visulima/colorize';
6
+ import '@visulima/interactive-manager';
3
7
  /**
4
- * A Fastify-like request object with the pail logger attached.
5
- * Use this to type your route handlers when accessing `request.log`.
6
- * @example
7
- * ```typescript
8
- * import type { PailFastifyRequest } from "@visulima/pail/middleware/fastify";
9
- *
10
- * app.get("/api/users", async (request: PailFastifyRequest, reply) => {
11
- * request.log?.set({ user: { id: 1 } });
12
- * });
13
- * ```
14
- */
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
+ */
15
19
  interface PailFastifyRequest {
16
- [key: string]: unknown;
17
- headers: Record<string, string | string[] | undefined>;
18
- /**
19
- * The request-scoped WideEvent logger, attached by pail plugin.
20
- * Only present for non-excluded routes.
21
- */
22
- log?: WideEvent;
23
- method: string;
24
- url: string;
20
+ [key: string]: unknown;
21
+ headers: Record<string, string | string[] | undefined>;
22
+ /**
23
+ * The request-scoped WideEvent logger, attached by pail plugin.
24
+ * Only present for non-excluded routes.
25
+ */
26
+ log?: WideEvent;
27
+ method: string;
28
+ url: string;
25
29
  }
26
30
  /**
27
- * A Fastify-like reply object.
28
- */
31
+ * A Fastify-like reply object.
32
+ */
29
33
  interface PailFastifyReply {
30
- [key: string]: unknown;
31
- statusCode: number;
34
+ [key: string]: unknown;
35
+ statusCode: number;
32
36
  }
33
37
  /**
34
- * A Fastify-like instance that supports the hook registration API.
35
- */
38
+ * A Fastify-like instance that supports the hook registration API.
39
+ */
36
40
  interface PailFastifyInstance {
37
- 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);
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);
38
42
  }
39
43
  /**
40
- * Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
41
- * Must be called within a request handled by the pail Fastify plugin.
42
- * @returns The request-scoped WideEvent logger
43
- * @throws Error if called outside of the plugin context
44
- */
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
+ */
45
49
  declare const useLogger: () => WideEvent;
46
50
  /**
47
- * Configuration options for the Fastify pail plugin.
48
- * @template T - Custom logger type names from the pail instance
49
- */
51
+ * Configuration options for the Fastify pail plugin.
52
+ * @template T - Custom logger type names from the pail instance
53
+ */
50
54
  type FastifyPluginOptions<T extends string = string> = PailMiddlewareOptions<T>;
51
55
  /**
52
- * Register pail wide event logging as a Fastify plugin.
53
- *
54
- * Attaches a WideEvent logger to each request, accessible via:
55
- * - `request.log` on the Fastify request object
56
- * - `useLogger()` from anywhere in the async call stack
57
- *
58
- * The wide event is automatically emitted on response or error.
59
- * @param fastify The Fastify instance
60
- * @param options Plugin configuration
61
- * @example
62
- * ```typescript
63
- * import Fastify from "fastify";
64
- * import { createPail } from "@visulima/pail";
65
- * import { pailPlugin, useLogger } from "@visulima/pail/middleware/fastify";
66
- *
67
- * const app = Fastify();
68
- * const logger = createPail();
69
- *
70
- * pailPlugin(app, { pail: logger });
71
- *
72
- * app.get("/api/users", async (request, reply) => {
73
- * request.log.set({ user: { id: 1 } });
74
- * return { ok: true };
75
- * });
76
- * ```
77
- */
78
- export declare const pailPlugin: <T extends string = string>(fastify: PailFastifyInstance, options: FastifyPluginOptions<T>) => void;
79
- export { useLogger };
80
- export type { FastifyPluginOptions, PailFastifyInstance, PailFastifyReply, PailFastifyRequest };
81
- export type { WideEvent } from "../wide-event.d.ts";
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
+ */
82
+ declare const pailPlugin: <T extends string = string>(fastify: PailFastifyInstance, options: FastifyPluginOptions<T>) => void;
83
+ export { type FastifyPluginOptions, type PailFastifyInstance, type PailFastifyReply, type PailFastifyRequest, type WideEvent, pailPlugin, useLogger };
@@ -25,7 +25,7 @@ const pailPlugin = (fastify, options) => {
25
25
  done();
26
26
  });
27
27
  });
28
- fastify.addHook("onResponse", (request, reply) => {
28
+ fastify.addHook("onResponse", async (request, reply) => {
29
29
  const state = requestState.get(request);
30
30
  if (!state || emitted.has(request)) {
31
31
  return;
@@ -33,7 +33,7 @@ const pailPlugin = (fastify, options) => {
33
33
  emitted.add(request);
34
34
  state.finish({ status: reply.statusCode });
35
35
  });
36
- fastify.addHook("onError", (request, _reply, error) => {
36
+ fastify.addHook("onError", async (request, _reply, error) => {
37
37
  const state = requestState.get(request);
38
38
  if (!state || emitted.has(request)) {
39
39
  return;
@@ -1,85 +1,87 @@
1
- import type { WideEvent } from "../wide-event.d.ts";
2
- import type { PailMiddlewareOptions } from "./shared/create-middleware-logger.d.ts";
1
+ import { W as WideEvent } from "../packem_shared/wide-event.d-B-t8ZnhI.js";
2
+ import { P as PailMiddlewareOptions } from "../packem_shared/create-middleware-logger.d-DheMh8q4.js";
3
+ import 'safe-stable-stringify';
4
+ import "../packem_shared/types.d-BeLumqgD.js";
5
+ import '@visulima/colorize';
6
+ import '@visulima/interactive-manager';
3
7
  /**
4
- * A Hono-like context object with access to the pail logger.
5
- *
6
- * Use `c.get("log")` or `useLogger(c)` to access the WideEvent logger.
7
- * @example
8
- * ```typescript
9
- * import type { PailHonoContext } from "@visulima/pail/middleware/hono";
10
- *
11
- * app.get("/api/users", (c: PailHonoContext) => {
12
- * const log = c.get("log");
13
- * log.set({ user: { id: 1 } });
14
- * });
15
- * ```
16
- */
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
+ */
17
21
  interface PailHonoContext {
18
- [key: string]: unknown;
19
- get: (key: string) => unknown;
20
- req: {
21
- header: (name: string) => string | undefined;
22
- method: string;
23
- path: string;
24
- raw: {
25
- headers: Headers;
26
- };
22
+ [key: string]: unknown;
23
+ get: (key: string) => unknown;
24
+ req: {
25
+ header: (name: string) => string | undefined;
26
+ method: string;
27
+ path: string;
28
+ raw: {
29
+ headers: Headers;
27
30
  };
28
- res: {
29
- status: number;
30
- };
31
- set: (key: string, value: unknown) => void;
31
+ };
32
+ res: {
33
+ status: number;
34
+ };
35
+ set: (key: string, value: unknown) => void;
32
36
  }
33
37
  /**
34
- * Hono-compatible next function.
35
- */
38
+ * Hono-compatible next function.
39
+ */
36
40
  type PailHonoNext = () => Promise<void>;
37
41
  /**
38
- * The Hono middleware function signature returned by `pailMiddleware()`.
39
- */
42
+ * The Hono middleware function signature returned by `pailMiddleware()`.
43
+ */
40
44
  type PailHonoMiddleware = (c: PailHonoContext, next: PailHonoNext) => Promise<void>;
41
45
  /**
42
- * Configuration options for the Hono pail middleware.
43
- * @template T - Custom logger type names from the pail instance
44
- */
46
+ * Configuration options for the Hono pail middleware.
47
+ * @template T - Custom logger type names from the pail instance
48
+ */
45
49
  type HonoMiddlewareOptions<T extends string = string> = PailMiddlewareOptions<T>;
46
50
  /**
47
- * Retrieve the WideEvent logger from Hono context.
48
- * Must be called within a request handler where pail middleware is active.
49
- * @param c The Hono context object
50
- * @returns The request-scoped WideEvent logger
51
- * @throws Error if the middleware is not registered
52
- */
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
+ */
53
57
  declare const useLogger: (c: PailHonoContext) => WideEvent;
54
58
  /**
55
- * Create Hono middleware that attaches a WideEvent logger to each request.
56
- *
57
- * The logger is available via:
58
- * - `c.get("log")` on the Hono context
59
- * - `useLogger(c)` helper function
60
- *
61
- * The wide event is automatically emitted when the handler completes or throws.
62
- * @param options Middleware configuration
63
- * @returns Hono middleware function
64
- * @example
65
- * ```typescript
66
- * import { Hono } from "hono";
67
- * import { createPail } from "@visulima/pail";
68
- * import { pailMiddleware, useLogger } from "@visulima/pail/middleware/hono";
69
- *
70
- * const app = new Hono();
71
- * const logger = createPail();
72
- *
73
- * app.use("*", pailMiddleware({ pail: logger }));
74
- *
75
- * app.get("/api/users", (c) => {
76
- * const log = useLogger(c);
77
- * log.set({ user: { id: 1 } });
78
- * return c.json({ ok: true });
79
- * });
80
- * ```
81
- */
82
- export declare const pailMiddleware: <T extends string = string>(options: HonoMiddlewareOptions<T>) => PailHonoMiddleware;
83
- export { useLogger };
84
- export type { HonoMiddlewareOptions, PailHonoContext, PailHonoMiddleware, PailHonoNext };
85
- export type { WideEvent } from "../wide-event.d.ts";
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
+ */
86
+ declare const pailMiddleware: <T extends string = string>(options: HonoMiddlewareOptions<T>) => PailHonoMiddleware;
87
+ export { type HonoMiddlewareOptions, type PailHonoContext, type PailHonoMiddleware, type PailHonoNext, type WideEvent, pailMiddleware, useLogger };
@@ -1,36 +1,103 @@
1
- import type { PailMiddlewareOptions } from "../shared/create-middleware-logger.d.ts";
1
+ import { P as PailMiddlewareOptions } from "../../packem_shared/create-middleware-logger.d-DheMh8q4.js";
2
+ import { W as WideEvent } from "../../packem_shared/wide-event.d-B-t8ZnhI.js";
3
+ import 'node:async_hooks';
4
+ import "../../packem_shared/types.d-BeLumqgD.js";
5
+ import '@visulima/colorize';
6
+ import '@visulima/interactive-manager';
7
+ import 'safe-stable-stringify';
8
+ /**
9
+ * Minimal type definitions to avoid requiring next as a dependency.
10
+ */
11
+ interface NextRequest {
12
+ headers: Headers;
13
+ nextUrl: {
14
+ pathname: string;
15
+ };
16
+ }
17
+ interface NextResponse {
18
+ headers: Headers;
19
+ }
20
+ interface NextResponseConstructor {
21
+ next: (options?: {
22
+ request?: {
23
+ headers?: Headers;
24
+ };
25
+ }) => NextResponse;
26
+ }
27
+ /**
28
+ * Options for the Next.js pail middleware.
29
+ */
30
+ interface PailNextMiddlewareOptions {
31
+ /**
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
+ */
36
+ exclude?: string[];
37
+ /**
38
+ * Glob patterns for paths to include in logging.
39
+ * If not set, all non-excluded paths are included.
40
+ */
41
+ include?: string[];
42
+ }
43
+ /**
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
+ */
65
+ declare const pailMiddleware: (NextResponseClass: NextResponseConstructor, options?: PailNextMiddlewareOptions) => (request: NextRequest) => NextResponse;
66
+ /**
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
+ */
72
+ declare const useLogger: () => WideEvent;
2
73
  type NextPailOptions<T extends string = string> = PailMiddlewareOptions<T>;
3
74
  /**
4
- * Create a `withPail` wrapper function for Next.js route handlers and server actions.
5
- *
6
- * Wraps handler execution in AsyncLocalStorage so that `useLogger()` works
7
- * anywhere in the async call stack. The wide event is automatically emitted
8
- * when the handler completes or throws.
9
- * @param options Configuration options
10
- * @returns A `withPail` wrapper function
11
- * @example
12
- * ```typescript
13
- * // lib/pail.ts
14
- * import { createPail } from "@visulima/pail";
15
- * import { createWithPail } from "@visulima/pail/middleware/next";
16
- *
17
- * const logger = createPail();
18
- * export const withPail = createWithPail({ pail: logger });
19
- *
20
- * // app/api/users/route.ts
21
- * import { withPail } from "@/lib/pail";
22
- * import { useLogger } from "@visulima/pail/middleware/next";
23
- *
24
- * export const GET = withPail(async (request: Request) => {
25
- * const log = useLogger();
26
- * log.set({ user: { id: 1 } });
27
- * return Response.json({ ok: true });
28
- * });
29
- * ```
30
- */
31
- export declare const createWithPail: <T extends string = string>(options: NextPailOptions<T>) => <TArgs extends unknown[], TReturn>(handler: (...args: TArgs) => Promise<TReturn> | TReturn) => (...args: TArgs) => Promise<TReturn>;
32
- export type { NextPailOptions };
33
- export type { WideEvent } from "../../wide-event.d.ts";
34
- export type { PailNextMiddlewareOptions } from "./middleware/next/middleware.d.ts";
35
- export { pailMiddleware } from "./middleware/next/middleware.d.ts";
36
- export { useLogger } from "./storage.d.ts";
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
+ */
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>;
103
+ export { type NextPailOptions, type PailNextMiddlewareOptions, type WideEvent, createWithPail, pailMiddleware, useLogger };