@visulima/pail 3.2.2 → 4.0.0-alpha.10
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 +188 -0
- package/LICENSE.md +434 -6
- package/README.md +355 -24
- package/dist/error.d.ts +104 -0
- package/dist/error.js +76 -0
- package/dist/index.browser.d.ts +3 -1
- package/dist/index.browser.js +1490 -3
- package/dist/index.server.d.ts +3 -1
- package/dist/index.server.js +2668 -14
- package/dist/interactive/index.js +2 -2
- package/dist/middleware/elysia.d.ts +71 -0
- package/dist/middleware/elysia.js +70 -0
- package/dist/middleware/express.d.ts +86 -0
- package/dist/middleware/express.js +29 -0
- package/dist/middleware/fastify.d.ts +81 -0
- package/dist/middleware/fastify.js +46 -0
- package/dist/middleware/hono.d.ts +85 -0
- package/dist/middleware/hono.js +33 -0
- package/dist/middleware/next/handler.d.ts +36 -0
- package/dist/middleware/next/handler.js +53 -0
- package/dist/middleware/next/middleware.d.ts +59 -0
- package/dist/middleware/next/storage.d.ts +14 -0
- package/dist/middleware/shared/create-middleware-logger.d.ts +82 -0
- package/dist/middleware/shared/headers.d.ts +14 -0
- package/dist/middleware/shared/routes.d.ts +30 -0
- package/dist/middleware/shared/storage.d.ts +29 -0
- package/dist/middleware/sveltekit.d.ts +123 -0
- package/dist/middleware/sveltekit.js +43 -0
- package/dist/object-tree.d.ts +2 -2
- package/dist/object-tree.js +7 -7
- package/dist/packem_shared/{AbstractJsonReporter-intFdT_A.js → AbstractJsonReporter-CjtVgHbU.js} +112 -28
- package/dist/packem_shared/AbstractJsonReporter-DlugSJpY.js +288 -0
- package/dist/packem_shared/{InteractiveManager-CZ85hGNW.js → InteractiveManager-CowYA3Hx.js} +17 -11
- package/dist/packem_shared/{interactive-stream-hook-DG4BtN12.js → InteractiveStreamHook-BypRlYTX.js} +3 -11
- package/dist/packem_shared/{JsonReporter-C0AXk99i.js → JsonReporter-BgPvIyC2.js} +2 -2
- package/dist/packem_shared/{JsonReporter-DcM2LBX9.js → JsonReporter-Dbw82ewj.js} +2 -2
- package/dist/packem_shared/{PrettyReporter-CuLLKr6-.js → PrettyReporter-C2dCzIaf.js} +54 -8
- package/dist/packem_shared/{format-label-Btft2KGP.js → PrettyReporter-gMqa7j_m.js} +372 -78
- package/dist/packem_shared/Spinner-Cokext9b.js +2183 -0
- package/dist/packem_shared/abstract-pretty-reporter-szQO-IgK.js +2635 -0
- package/dist/packem_shared/constants-B1RjD_ps.js +99 -0
- package/dist/packem_shared/{constants-DfDr4MHC.js → constants-omsTHUWB.js} +1 -1
- package/dist/packem_shared/createPailError-B_sgL0nF.js +76 -0
- package/dist/packem_shared/getBarChar-D7JfmdTr.js +459 -0
- package/dist/packem_shared/headers-BxHWM6KI.js +127 -0
- package/dist/packem_shared/{index-DqKWykfa.js → index-BEfVUy9P.js} +174 -64
- package/dist/packem_shared/{index-BomQ3E6J.js → index-Bx3-C0j9.js} +29 -21
- package/dist/packem_shared/pailMiddleware-Ci88geIF.js +24 -0
- package/dist/packem_shared/storage-D0vqz8OX.js +36 -0
- package/dist/packem_shared/{InteractiveStreamHook-DiSubbJ1.js → useLogger-D0rU3lcX.js} +13 -1
- package/dist/packem_shared/{write-console-log-based-on-level-DBmRYXpj.js → write-console-log-based-on-level-ree2lDPw.js} +5 -4
- package/dist/packem_shared/{write-stream-BG8fhcs3.js → write-stream-BuFtjATz.js} +1 -1
- package/dist/pail.browser.d.ts +1 -1
- package/dist/processor/environment-processor.d.ts +124 -0
- package/dist/processor/environment-processor.js +82 -0
- package/dist/processor/message-formatter-processor.d.ts +2 -2
- package/dist/processor/message-formatter-processor.js +654 -6
- package/dist/processor/opentelemetry-processor.js +4 -4
- package/dist/processor/redact-processor.d.ts +1 -1
- package/dist/processor/redact-processor.js +2 -1
- package/dist/processor/sampling-processor.d.ts +111 -0
- package/dist/processor/sampling-processor.js +59 -0
- package/dist/progress-bar.d.ts +10 -1
- package/dist/progress-bar.js +75 -20
- package/dist/reporter/file/json-file-reporter.js +1 -1
- package/dist/reporter/http/abstract-http-reporter.js +23 -26
- package/dist/reporter/http/http-reporter.edge-light.js +134 -53
- package/dist/reporter/json/abstract-json-reporter.d.ts +1 -1
- package/dist/reporter/json/index.browser.js +2 -2
- package/dist/reporter/json/index.js +2 -2
- package/dist/reporter/pretty/index.browser.js +1 -1
- package/dist/reporter/pretty/index.js +1 -1
- package/dist/reporter/simple/simple-reporter.server.js +8 -12
- package/dist/spinner.js +37 -4
- package/dist/types.d.ts +4 -4
- package/dist/wide-event.d.ts +300 -0
- package/dist/wide-event.js +283 -0
- package/package.json +73 -8
- package/dist/packem_shared/PrettyReporter-BFWaYP_J.js +0 -222
- package/dist/packem_shared/abstract-pretty-reporter-DMPDCslJ.js +0 -50
- package/dist/packem_shared/get-longest-label-C9PWeyKq.js +0 -9
- package/dist/packem_shared/pail.browser-CPjQrsyy.js +0 -1427
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { PailBrowserImpl } from "../../pail.d.ts";
|
|
2
|
+
import type { DefaultLogTypes, LoggerFunction } from "../../types.d.ts";
|
|
3
|
+
import type { WideEventFinishOptions } from "../../wide-event.d.ts";
|
|
4
|
+
import { WideEvent } from "../../wide-event.d.ts";
|
|
5
|
+
import type { RouteConfig } from "./routes.d.ts";
|
|
6
|
+
/**
|
|
7
|
+
* A pail instance with dynamically generated log methods.
|
|
8
|
+
*/
|
|
9
|
+
type PailLike<T extends string = string> = PailBrowserImpl<T> & Record<DefaultLogTypes | T, LoggerFunction>;
|
|
10
|
+
/**
|
|
11
|
+
* Base options shared by all framework middleware adapters.
|
|
12
|
+
* @template T - Custom logger type names from the pail instance
|
|
13
|
+
*/
|
|
14
|
+
export interface PailMiddlewareOptions<T extends string = string> {
|
|
15
|
+
/**
|
|
16
|
+
* Glob patterns for paths to exclude from logging.
|
|
17
|
+
* Exclusions take precedence over inclusions.
|
|
18
|
+
* @example ["/health", "/api/_internal/**"]
|
|
19
|
+
*/
|
|
20
|
+
exclude?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Glob patterns for paths to include in logging.
|
|
23
|
+
* If not set, all non-excluded paths are logged.
|
|
24
|
+
* @example ["/api/**"]
|
|
25
|
+
*/
|
|
26
|
+
include?: string[];
|
|
27
|
+
/**
|
|
28
|
+
* The pail logger instance to use for wide event emission.
|
|
29
|
+
*/
|
|
30
|
+
pail: PailLike<T>;
|
|
31
|
+
/**
|
|
32
|
+
* Route-specific configuration. Maps glob patterns to config.
|
|
33
|
+
* First matching route wins.
|
|
34
|
+
* @example { "/api/auth/**": { service: "auth-service" } }
|
|
35
|
+
*/
|
|
36
|
+
routes?: Record<string, RouteConfig>;
|
|
37
|
+
/**
|
|
38
|
+
* Default service name for all wide events.
|
|
39
|
+
* Can be overridden per-route via `routes`.
|
|
40
|
+
*/
|
|
41
|
+
service?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Result of creating a middleware logger for a request.
|
|
45
|
+
*/
|
|
46
|
+
export interface MiddlewareLoggerResult {
|
|
47
|
+
/**
|
|
48
|
+
* Finalize and emit the wide event. Sets status/error before emitting.
|
|
49
|
+
* Safe to call multiple times — only the first call emits.
|
|
50
|
+
*/
|
|
51
|
+
finish: (options?: WideEventFinishOptions) => void;
|
|
52
|
+
/**
|
|
53
|
+
* The request-scoped WideEvent logger.
|
|
54
|
+
* Use `set()`, `info()`, `warn()`, `error()`, `debug()` to accumulate context.
|
|
55
|
+
*/
|
|
56
|
+
logger: WideEvent;
|
|
57
|
+
/**
|
|
58
|
+
* Whether this request was skipped (excluded from logging).
|
|
59
|
+
* When true, `logger` and `finish` should not be used.
|
|
60
|
+
*/
|
|
61
|
+
skipped: boolean;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Core factory function used by all framework middleware adapters.
|
|
65
|
+
*
|
|
66
|
+
* Creates a WideEvent for the given request, checks route inclusion/exclusion,
|
|
67
|
+
* resolves the service name, and returns a logger + finish callback.
|
|
68
|
+
* @param options Middleware options including pail instance and route config
|
|
69
|
+
* @param request Request metadata for the current HTTP request
|
|
70
|
+
* @param request.headers Safe headers extracted from the request
|
|
71
|
+
* @param request.method The HTTP method (GET, POST, etc.)
|
|
72
|
+
* @param request.path The URL path of the request
|
|
73
|
+
* @param request.requestId A unique identifier for this request
|
|
74
|
+
* @returns A result object with logger, finish callback, and skipped flag
|
|
75
|
+
*/
|
|
76
|
+
export declare const createMiddlewareLogger: <T extends string = string>(options: PailMiddlewareOptions<T>, request: {
|
|
77
|
+
headers?: Record<string, string>;
|
|
78
|
+
method: string;
|
|
79
|
+
path: string;
|
|
80
|
+
requestId: string;
|
|
81
|
+
}) => MiddlewareLoggerResult;
|
|
82
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract safe headers from a Web API Headers object, filtering out
|
|
3
|
+
* sensitive headers like Authorization, Cookie, and API keys.
|
|
4
|
+
* @param headers Web API Headers object
|
|
5
|
+
* @returns Plain object of safe header key-value pairs
|
|
6
|
+
*/
|
|
7
|
+
export declare const extractSafeHeaders: (headers: Headers) => Record<string, string>;
|
|
8
|
+
/**
|
|
9
|
+
* Extract safe headers from a Node.js IncomingHttpHeaders object,
|
|
10
|
+
* filtering out sensitive headers.
|
|
11
|
+
* @param headers Node.js IncomingHttpHeaders-like object
|
|
12
|
+
* @returns Plain object of safe header key-value pairs
|
|
13
|
+
*/
|
|
14
|
+
export declare const extractSafeNodeHeaders: (headers: Record<string, string | string[] | undefined>) => Record<string, string>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a path matches a glob pattern.
|
|
3
|
+
*/
|
|
4
|
+
export declare const matchesPattern: (path: string, pattern: string) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Route configuration for a specific path pattern.
|
|
7
|
+
*/
|
|
8
|
+
export interface RouteConfig {
|
|
9
|
+
/** Override the service name for requests matching this route. */
|
|
10
|
+
service?: string;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Determine whether a request path should be logged based on include/exclude patterns.
|
|
14
|
+
*
|
|
15
|
+
* - Exclusions take precedence over inclusions.
|
|
16
|
+
* - If no include patterns are provided, all non-excluded paths are logged.
|
|
17
|
+
* @param path The request path
|
|
18
|
+
* @param include Glob patterns of paths to include
|
|
19
|
+
* @param exclude Glob patterns of paths to exclude
|
|
20
|
+
* @returns Whether the path should be logged
|
|
21
|
+
*/
|
|
22
|
+
export declare const shouldLog: (path: string, include?: string[], exclude?: string[]) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Get the service name override for a given path based on route configuration.
|
|
25
|
+
* Returns the first matching route's service name, or undefined if no match.
|
|
26
|
+
* @param path The request path
|
|
27
|
+
* @param routes Route configuration map (pattern → config)
|
|
28
|
+
* @returns The service name override, or undefined
|
|
29
|
+
*/
|
|
30
|
+
export declare const getServiceForPath: (path: string, routes?: Record<string, RouteConfig>) => string | undefined;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import type { WideEvent } from "../../wide-event.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* Create an isolated AsyncLocalStorage instance and a `useLogger` accessor
|
|
5
|
+
* for retrieving the request-scoped WideEvent from anywhere in the call stack.
|
|
6
|
+
*
|
|
7
|
+
* Each framework adapter should call this once at module level to get its own
|
|
8
|
+
* isolated storage instance.
|
|
9
|
+
* @param contextHint A description of the expected context, used in the
|
|
10
|
+
* error message when `useLogger` is called outside of a request scope.
|
|
11
|
+
* @returns An object with `storage` and `useLogger`
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const { storage, useLogger } = createLoggerStorage(
|
|
15
|
+
* "Express middleware context. Make sure evlog middleware is registered."
|
|
16
|
+
* );
|
|
17
|
+
*
|
|
18
|
+
* // In middleware:
|
|
19
|
+
* storage.run(wideEvent, () => next());
|
|
20
|
+
*
|
|
21
|
+
* // In handler:
|
|
22
|
+
* const log = useLogger();
|
|
23
|
+
* log.set({ user: { id: 1 } });
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare const createLoggerStorage: (contextHint: string) => {
|
|
27
|
+
storage: AsyncLocalStorage<WideEvent>;
|
|
28
|
+
useLogger: () => WideEvent;
|
|
29
|
+
};
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { WideEvent } from "../wide-event.d.ts";
|
|
2
|
+
import type { PailMiddlewareOptions } from "./shared/create-middleware-logger.d.ts";
|
|
3
|
+
/**
|
|
4
|
+
* A SvelteKit-like event object with access to the pail logger via `locals.log`.
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* // In a SvelteKit load function or action:
|
|
8
|
+
* import type { PailSvelteKitEvent } from "@visulima/pail/middleware/sveltekit";
|
|
9
|
+
*
|
|
10
|
+
* export const load = async (event: PailSvelteKitEvent) => {
|
|
11
|
+
* event.locals.log?.set({ user: { id: 1 } });
|
|
12
|
+
* };
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
interface PailSvelteKitEvent {
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
locals: Record<string, unknown> & {
|
|
18
|
+
log?: WideEvent;
|
|
19
|
+
};
|
|
20
|
+
request: Request;
|
|
21
|
+
url: URL;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Options passed to SvelteKit's resolve function.
|
|
25
|
+
*/
|
|
26
|
+
interface PailSvelteKitResolveOptions {
|
|
27
|
+
filterSerializedResponseHeaders?: (name: string) => boolean;
|
|
28
|
+
preload?: (input: {
|
|
29
|
+
type: string;
|
|
30
|
+
}) => boolean;
|
|
31
|
+
transformPageChunk?: (input: {
|
|
32
|
+
html: string;
|
|
33
|
+
}) => string;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* SvelteKit resolve function type.
|
|
37
|
+
*/
|
|
38
|
+
type PailSvelteKitResolve = (event: PailSvelteKitEvent, options?: PailSvelteKitResolveOptions) => Promise<Response>;
|
|
39
|
+
/**
|
|
40
|
+
* Input for the SvelteKit handle hook.
|
|
41
|
+
*/
|
|
42
|
+
interface PailSvelteKitHandleInput {
|
|
43
|
+
event: PailSvelteKitEvent;
|
|
44
|
+
resolve: PailSvelteKitResolve;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* SvelteKit handle hook function type returned by `pailHandle()`.
|
|
48
|
+
*/
|
|
49
|
+
type PailSvelteKitHandle = (input: PailSvelteKitHandleInput) => Promise<Response>;
|
|
50
|
+
/**
|
|
51
|
+
* Input for the SvelteKit handleError hook.
|
|
52
|
+
*/
|
|
53
|
+
interface PailSvelteKitHandleErrorInput {
|
|
54
|
+
error: unknown;
|
|
55
|
+
event: PailSvelteKitEvent;
|
|
56
|
+
message: string;
|
|
57
|
+
status: number;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* SvelteKit handleError hook function type returned by `pailHandleError()`.
|
|
61
|
+
*/
|
|
62
|
+
type PailSvelteKitHandleError = (input: PailSvelteKitHandleErrorInput) => void;
|
|
63
|
+
/**
|
|
64
|
+
* Retrieve the request-scoped WideEvent logger from AsyncLocalStorage.
|
|
65
|
+
* Must be called within a request handled by the pail SvelteKit handle hook.
|
|
66
|
+
* @returns The request-scoped WideEvent logger
|
|
67
|
+
* @throws Error if called outside of the hook context
|
|
68
|
+
*/
|
|
69
|
+
declare const useLogger: () => WideEvent;
|
|
70
|
+
type SvelteKitHandleOptions<T extends string = string> = PailMiddlewareOptions<T>;
|
|
71
|
+
/**
|
|
72
|
+
* Create a SvelteKit `handle` hook that attaches a WideEvent logger to each request.
|
|
73
|
+
*
|
|
74
|
+
* The logger is available via:
|
|
75
|
+
* - `event.locals.log` in server load functions and actions
|
|
76
|
+
* - `useLogger()` from anywhere in the async call stack
|
|
77
|
+
*
|
|
78
|
+
* The wide event is automatically emitted when the response is sent or an error occurs.
|
|
79
|
+
* @param options Hook configuration
|
|
80
|
+
* @returns SvelteKit handle hook function
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // src/hooks.server.ts
|
|
84
|
+
* import { createPail } from "@visulima/pail";
|
|
85
|
+
* import { pailHandle, pailHandleError } from "@visulima/pail/middleware/sveltekit";
|
|
86
|
+
*
|
|
87
|
+
* const logger = createPail();
|
|
88
|
+
*
|
|
89
|
+
* export const handle = pailHandle({ pail: logger });
|
|
90
|
+
* export const handleError = pailHandleError();
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export declare const pailHandle: <T extends string = string>(options: SvelteKitHandleOptions<T>) => PailSvelteKitHandle;
|
|
94
|
+
/**
|
|
95
|
+
* Create a SvelteKit `handleError` hook that captures errors into the WideEvent logger.
|
|
96
|
+
*
|
|
97
|
+
* Should be used alongside `pailHandle` to ensure errors are recorded in the wide event.
|
|
98
|
+
* @returns SvelteKit handleError hook function
|
|
99
|
+
*/
|
|
100
|
+
export declare const pailHandleError: () => PailSvelteKitHandleError;
|
|
101
|
+
/**
|
|
102
|
+
* Convenience function that returns both handle and handleError hooks.
|
|
103
|
+
* @param options Hook configuration
|
|
104
|
+
* @returns Object with `handle` and `handleError` hooks
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* // src/hooks.server.ts
|
|
108
|
+
* import { createPail } from "@visulima/pail";
|
|
109
|
+
* import { createPailHooks } from "@visulima/pail/middleware/sveltekit";
|
|
110
|
+
*
|
|
111
|
+
* const logger = createPail();
|
|
112
|
+
* const { handle, handleError } = createPailHooks({ pail: logger });
|
|
113
|
+
*
|
|
114
|
+
* export { handle, handleError };
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
export declare const createPailHooks: <T extends string = string>(options: SvelteKitHandleOptions<T>) => {
|
|
118
|
+
handle: PailSvelteKitHandle;
|
|
119
|
+
handleError: PailSvelteKitHandleError;
|
|
120
|
+
};
|
|
121
|
+
export { useLogger };
|
|
122
|
+
export type { PailSvelteKitEvent, PailSvelteKitHandle, PailSvelteKitHandleError, PailSvelteKitHandleErrorInput, PailSvelteKitHandleInput, PailSvelteKitResolve, PailSvelteKitResolveOptions, SvelteKitHandleOptions, };
|
|
123
|
+
export type { WideEvent } from "../wide-event.d.ts";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { a as extractSafeHeaders, c as createMiddlewareLogger } from '../packem_shared/headers-BxHWM6KI.js';
|
|
2
|
+
import { c as createLoggerStorage } from '../packem_shared/storage-D0vqz8OX.js';
|
|
3
|
+
|
|
4
|
+
const loggerStorage = createLoggerStorage("SvelteKit handle hook context. Make sure pailHandle is added to your hooks.server.ts.");
|
|
5
|
+
const useLogger = () => loggerStorage.useLogger();
|
|
6
|
+
const pailHandle = (options) => async ({ event, resolve }) => {
|
|
7
|
+
const requestId = event.request.headers.get("x-request-id") ?? crypto.randomUUID();
|
|
8
|
+
const safeHeaders = extractSafeHeaders(event.request.headers);
|
|
9
|
+
const { finish, logger, skipped } = createMiddlewareLogger(options, {
|
|
10
|
+
headers: safeHeaders,
|
|
11
|
+
method: event.request.method,
|
|
12
|
+
path: event.url.pathname,
|
|
13
|
+
requestId
|
|
14
|
+
});
|
|
15
|
+
if (skipped) {
|
|
16
|
+
return resolve(event);
|
|
17
|
+
}
|
|
18
|
+
event.locals.log = logger;
|
|
19
|
+
return loggerStorage.storage.run(logger, async () => {
|
|
20
|
+
try {
|
|
21
|
+
const response = await resolve(event);
|
|
22
|
+
finish({ status: response.status });
|
|
23
|
+
return response;
|
|
24
|
+
} catch (error) {
|
|
25
|
+
finish({ error: error instanceof Error ? error : new Error(String(error)) });
|
|
26
|
+
throw error;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
const pailHandleError = () => ({ error, event }) => {
|
|
31
|
+
const logger = event.locals.log;
|
|
32
|
+
if (logger && error instanceof Error) {
|
|
33
|
+
logger.error(error.message, error);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const createPailHooks = (options) => {
|
|
37
|
+
return {
|
|
38
|
+
handle: pailHandle(options),
|
|
39
|
+
handleError: pailHandleError()
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { createPailHooks, pailHandle, pailHandleError, useLogger };
|
package/dist/object-tree.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export type TreeSortFunction = (a: string, b: string) => number;
|
|
|
16
16
|
*/
|
|
17
17
|
export interface ObjectTreeOptions {
|
|
18
18
|
/** Text to display for circular references (default: " (circular ref.)") */
|
|
19
|
-
breakCircularWith?: string | null
|
|
19
|
+
breakCircularWith?: string | null;
|
|
20
20
|
/** Whether to return as single string or array of lines (default: true) */
|
|
21
21
|
joined?: boolean;
|
|
22
22
|
/** Connector for neighbor keys (default: "├─ ") */
|
|
@@ -28,7 +28,7 @@ export interface ObjectTreeOptions {
|
|
|
28
28
|
/** Separator between key and value (default: ": ") */
|
|
29
29
|
separator?: string;
|
|
30
30
|
/** Function to sort object keys (default: natural order) */
|
|
31
|
-
sortFn?: TreeSortFunction
|
|
31
|
+
sortFn?: TreeSortFunction;
|
|
32
32
|
/** Spacer for neighbor branches (default: "│ ") */
|
|
33
33
|
spacerNeighbour?: string;
|
|
34
34
|
/** Spacer for non-neighbor branches (default: " ") */
|
package/dist/object-tree.js
CHANGED
|
@@ -50,22 +50,22 @@ const renderObjectTree = (tree, options) => {
|
|
|
50
50
|
const result = [];
|
|
51
51
|
const rootRendered = context.renderFn(tree);
|
|
52
52
|
if (rootRendered !== void 0) {
|
|
53
|
-
result.push(
|
|
53
|
+
result.push(rootRendered);
|
|
54
54
|
}
|
|
55
55
|
const sort = (input) => {
|
|
56
56
|
if (context.sortFn === void 0) {
|
|
57
57
|
return input;
|
|
58
58
|
}
|
|
59
|
-
return input.toSorted((a, b) => context
|
|
59
|
+
return input.toSorted((a, b) => context.sortFn?.(b, a) ?? 0);
|
|
60
60
|
};
|
|
61
61
|
const neighbours = [];
|
|
62
62
|
const keys = sort(Object.keys(tree)).map((k) => [k]);
|
|
63
63
|
const lookup = [tree];
|
|
64
64
|
while (keys.length > 0) {
|
|
65
65
|
const key = keys.pop() ?? [];
|
|
66
|
-
const node = lookup[key.length - 1][key
|
|
66
|
+
const node = lookup[key.length - 1][key.at(-1) ?? ""];
|
|
67
67
|
const isCircular = context.breakCircularWith !== null && lookup.slice(0, key.length).includes(node);
|
|
68
|
-
neighbours[key.length - 1] = keys.length > 0 && (keys
|
|
68
|
+
neighbours[key.length - 1] = keys.length > 0 && (keys.at(-1)?.length ?? 0) === key.length;
|
|
69
69
|
const indent = neighbours.slice(0, key.length - 1).map((n) => {
|
|
70
70
|
if (n) {
|
|
71
71
|
return context.spacerNeighbour;
|
|
@@ -73,17 +73,17 @@ const renderObjectTree = (tree, options) => {
|
|
|
73
73
|
return context.spacerNoNeighbour;
|
|
74
74
|
}).join("");
|
|
75
75
|
const connector = neighbours[key.length - 1] ? context.keyNeighbour : context.keyNoNeighbour;
|
|
76
|
-
const keyName = key
|
|
76
|
+
const keyName = key.at(-1) ?? "";
|
|
77
77
|
const nodeRendered = context.renderFn(node);
|
|
78
78
|
const value = nodeRendered === void 0 ? "" : `${context.separator}${nodeRendered}`;
|
|
79
|
-
const circular = isCircular ? context.breakCircularWith : "";
|
|
79
|
+
const circular = isCircular ? context.breakCircularWith ?? "" : "";
|
|
80
80
|
result.push(`${indent}${connector}${keyName}${value}${circular}`);
|
|
81
81
|
if (node !== null && typeof node === "object" && !Array.isArray(node) && !isCircular) {
|
|
82
82
|
keys.push(...sort(Object.keys(node)).map((k) => [...key, k]));
|
|
83
83
|
lookup[key.length] = node;
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
|
-
return context.joined
|
|
86
|
+
return context.joined ? result.join("\n") : result;
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
export { renderObjectTree as default, renderObjectTree };
|
package/dist/packem_shared/{AbstractJsonReporter-intFdT_A.js → AbstractJsonReporter-CjtVgHbU.js}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { E as EMPTY_SYMBOL } from './constants-
|
|
1
|
+
import { E as EMPTY_SYMBOL } from './constants-B1RjD_ps.js';
|
|
2
2
|
|
|
3
3
|
function isPlainObject(value) {
|
|
4
4
|
if (typeof value !== "object" || value === null) {
|
|
@@ -12,7 +12,7 @@ const ErrorProto = Object.create(
|
|
|
12
12
|
{},
|
|
13
13
|
{
|
|
14
14
|
cause: {
|
|
15
|
-
enumerable:
|
|
15
|
+
enumerable: false,
|
|
16
16
|
value: void 0,
|
|
17
17
|
writable: true
|
|
18
18
|
},
|
|
@@ -22,62 +22,89 @@ const ErrorProto = Object.create(
|
|
|
22
22
|
writable: true
|
|
23
23
|
},
|
|
24
24
|
errors: {
|
|
25
|
-
enumerable:
|
|
25
|
+
enumerable: false,
|
|
26
26
|
value: void 0,
|
|
27
27
|
writable: true
|
|
28
28
|
},
|
|
29
29
|
message: {
|
|
30
|
-
enumerable:
|
|
30
|
+
enumerable: false,
|
|
31
31
|
value: void 0,
|
|
32
32
|
writable: true
|
|
33
33
|
},
|
|
34
34
|
name: {
|
|
35
|
-
enumerable:
|
|
35
|
+
enumerable: false,
|
|
36
36
|
value: void 0,
|
|
37
37
|
writable: true
|
|
38
38
|
},
|
|
39
39
|
stack: {
|
|
40
|
-
enumerable:
|
|
40
|
+
enumerable: false,
|
|
41
41
|
value: void 0,
|
|
42
42
|
writable: true
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
45
|
);
|
|
46
46
|
const toJsonWasCalled = /* @__PURE__ */ new WeakSet();
|
|
47
|
+
const makePropertiesEnumerable = (object) => {
|
|
48
|
+
const props = Object.getOwnPropertyNames(object);
|
|
49
|
+
for (const prop of props) {
|
|
50
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, prop);
|
|
51
|
+
if (descriptor) {
|
|
52
|
+
if (!descriptor.enumerable) {
|
|
53
|
+
Object.defineProperty(object, prop, {
|
|
54
|
+
...descriptor,
|
|
55
|
+
enumerable: true
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (descriptor.value && typeof descriptor.value === "object" && !Array.isArray(descriptor.value) && (Object.getPrototypeOf(descriptor.value) === Object.prototype || Object.getPrototypeOf(descriptor.value) === null)) {
|
|
59
|
+
makePropertiesEnumerable(descriptor.value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
};
|
|
47
64
|
const toJSON = (from) => {
|
|
48
65
|
toJsonWasCalled.add(from);
|
|
49
66
|
const json = from.toJSON();
|
|
50
67
|
toJsonWasCalled.delete(from);
|
|
68
|
+
if (
|
|
69
|
+
// Only make properties enumerable if the object is extensible
|
|
70
|
+
// Non-extensible objects (like when toJSON returns 'this') should preserve original enumerability
|
|
71
|
+
Object.isExtensible(json)
|
|
72
|
+
) {
|
|
73
|
+
makePropertiesEnumerable(json);
|
|
74
|
+
}
|
|
51
75
|
return json;
|
|
52
76
|
};
|
|
53
77
|
const serializeValue = (value, seen, depth, options) => {
|
|
54
78
|
if (value && value instanceof Uint8Array && value.constructor.name === "Buffer") {
|
|
55
79
|
return "[object Buffer]";
|
|
56
80
|
}
|
|
57
|
-
if (value !== null && typeof value === "object" && typeof value.pipe === "function") {
|
|
81
|
+
if (value !== null && typeof value === "object" && "pipe" in value && typeof value.pipe === "function") {
|
|
58
82
|
return "[object Stream]";
|
|
59
83
|
}
|
|
60
84
|
if (value instanceof Error) {
|
|
61
|
-
if (seen.
|
|
85
|
+
if (seen.has(value)) {
|
|
62
86
|
return "[Circular]";
|
|
63
87
|
}
|
|
64
88
|
depth += 1;
|
|
65
89
|
return _serialize(value, options, seen, depth);
|
|
66
90
|
}
|
|
67
|
-
if (options.useToJSON && typeof value.toJSON === "function") {
|
|
91
|
+
if (options.useToJSON && value !== null && typeof value === "object" && "toJSON" in value && typeof value.toJSON === "function") {
|
|
68
92
|
return value.toJSON();
|
|
69
93
|
}
|
|
70
|
-
if (
|
|
94
|
+
if (value instanceof Date) {
|
|
71
95
|
return value.toISOString();
|
|
72
96
|
}
|
|
73
97
|
if (typeof value === "function") {
|
|
74
98
|
return `[Function: ${value.name || "anonymous"}]`;
|
|
75
99
|
}
|
|
100
|
+
if (typeof value === "bigint") {
|
|
101
|
+
return `${String(value)}n`;
|
|
102
|
+
}
|
|
76
103
|
if (isPlainObject(value)) {
|
|
77
|
-
depth
|
|
78
|
-
if (options.maxDepth && depth >= options.maxDepth) {
|
|
104
|
+
if (options.maxDepth !== void 0 && options.maxDepth !== Number.POSITIVE_INFINITY && depth + 1 >= options.maxDepth) {
|
|
79
105
|
return {};
|
|
80
106
|
}
|
|
107
|
+
depth += 1;
|
|
81
108
|
const plainObject = {};
|
|
82
109
|
for (const key in value) {
|
|
83
110
|
plainObject[key] = serializeValue(value[key], seen, depth, options);
|
|
@@ -91,7 +118,7 @@ const serializeValue = (value, seen, depth, options) => {
|
|
|
91
118
|
}
|
|
92
119
|
};
|
|
93
120
|
const _serialize = (error, options, seen, depth) => {
|
|
94
|
-
seen.
|
|
121
|
+
seen.add(error);
|
|
95
122
|
if (options.maxDepth === 0) {
|
|
96
123
|
return {};
|
|
97
124
|
}
|
|
@@ -99,31 +126,88 @@ const _serialize = (error, options, seen, depth) => {
|
|
|
99
126
|
return toJSON(error);
|
|
100
127
|
}
|
|
101
128
|
const protoError = Object.create(ErrorProto);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
129
|
+
Object.defineProperty(protoError, "name", {
|
|
130
|
+
configurable: true,
|
|
131
|
+
enumerable: true,
|
|
132
|
+
value: Object.prototype.toString.call(error.constructor) === "[object Function]" ? error.constructor.name : error.name,
|
|
133
|
+
writable: true
|
|
134
|
+
});
|
|
135
|
+
Object.defineProperty(protoError, "message", {
|
|
136
|
+
configurable: true,
|
|
137
|
+
enumerable: true,
|
|
138
|
+
value: error.message,
|
|
139
|
+
writable: true
|
|
140
|
+
});
|
|
141
|
+
Object.defineProperty(protoError, "stack", {
|
|
142
|
+
configurable: true,
|
|
143
|
+
enumerable: true,
|
|
144
|
+
value: error.stack,
|
|
145
|
+
writable: true
|
|
146
|
+
});
|
|
105
147
|
if (Array.isArray(error.errors)) {
|
|
106
148
|
const aggregateErrors = [];
|
|
107
149
|
for (const aggregateError of error.errors) {
|
|
108
150
|
if (!(aggregateError instanceof Error)) {
|
|
109
151
|
throw new TypeError("All errors in the 'errors' property must be instances of Error");
|
|
110
152
|
}
|
|
111
|
-
if (seen.
|
|
112
|
-
protoError
|
|
153
|
+
if (seen.has(aggregateError)) {
|
|
154
|
+
Object.defineProperty(protoError, "errors", {
|
|
155
|
+
configurable: true,
|
|
156
|
+
enumerable: true,
|
|
157
|
+
value: [],
|
|
158
|
+
writable: true
|
|
159
|
+
});
|
|
113
160
|
return protoError;
|
|
114
161
|
}
|
|
115
162
|
aggregateErrors.push(_serialize(aggregateError, options, seen, depth));
|
|
116
163
|
}
|
|
117
|
-
protoError
|
|
164
|
+
Object.defineProperty(protoError, "errors", {
|
|
165
|
+
configurable: true,
|
|
166
|
+
enumerable: true,
|
|
167
|
+
value: aggregateErrors,
|
|
168
|
+
writable: true
|
|
169
|
+
});
|
|
118
170
|
}
|
|
119
|
-
|
|
120
|
-
|
|
171
|
+
const causeValue = error.cause;
|
|
172
|
+
if (causeValue !== void 0 && causeValue !== null) {
|
|
173
|
+
if (causeValue instanceof Error) {
|
|
174
|
+
if (seen.has(causeValue)) {
|
|
175
|
+
Object.defineProperty(protoError, "cause", {
|
|
176
|
+
configurable: true,
|
|
177
|
+
enumerable: true,
|
|
178
|
+
value: "[Circular]",
|
|
179
|
+
writable: true
|
|
180
|
+
});
|
|
181
|
+
} else {
|
|
182
|
+
Object.defineProperty(protoError, "cause", {
|
|
183
|
+
configurable: true,
|
|
184
|
+
enumerable: true,
|
|
185
|
+
value: _serialize(causeValue, options, seen, depth),
|
|
186
|
+
writable: true
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
const serializedCause = serializeValue(causeValue, seen, depth, options);
|
|
191
|
+
Object.defineProperty(protoError, "cause", {
|
|
192
|
+
configurable: true,
|
|
193
|
+
enumerable: true,
|
|
194
|
+
value: serializedCause,
|
|
195
|
+
writable: true
|
|
196
|
+
});
|
|
197
|
+
}
|
|
121
198
|
}
|
|
122
199
|
for (const key in error) {
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
protoError[key] = serializeValue(value, seen, depth, options);
|
|
200
|
+
if (key === "name" || key === "message" || key === "stack" || key === "cause" || key === "errors") {
|
|
201
|
+
continue;
|
|
126
202
|
}
|
|
203
|
+
const value = error[key];
|
|
204
|
+
const serializedValue = serializeValue(value, seen, depth, options);
|
|
205
|
+
Object.defineProperty(protoError, key, {
|
|
206
|
+
configurable: true,
|
|
207
|
+
enumerable: true,
|
|
208
|
+
value: serializedValue,
|
|
209
|
+
writable: true
|
|
210
|
+
});
|
|
127
211
|
}
|
|
128
212
|
if (Array.isArray(options.exclude) && options.exclude.length > 0) {
|
|
129
213
|
for (const key of options.exclude) {
|
|
@@ -142,7 +226,7 @@ const serialize = (error, options = {}) => _serialize(
|
|
|
142
226
|
maxDepth: options.maxDepth ?? Number.POSITIVE_INFINITY,
|
|
143
227
|
useToJSON: options.useToJSON ?? false
|
|
144
228
|
},
|
|
145
|
-
|
|
229
|
+
/* @__PURE__ */ new Set(),
|
|
146
230
|
0
|
|
147
231
|
);
|
|
148
232
|
|
|
@@ -162,7 +246,6 @@ class AbstractJsonReporter {
|
|
|
162
246
|
* Sets a custom stringify function for object serialization.
|
|
163
247
|
* @param function_ The stringify function to use for serialization
|
|
164
248
|
*/
|
|
165
|
-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
166
249
|
setStringify(function_) {
|
|
167
250
|
this.stringify = function_;
|
|
168
251
|
}
|
|
@@ -173,7 +256,7 @@ class AbstractJsonReporter {
|
|
|
173
256
|
rest.label = rest.label.trim();
|
|
174
257
|
}
|
|
175
258
|
if (file) {
|
|
176
|
-
rest.file = `${file.name}:${file.line}${file.column ? `:${file.column}` : ""}`;
|
|
259
|
+
rest.file = `${file.name ?? ""}:${String(file.line)}${file.column ? `:${String(file.column)}` : ""}`;
|
|
177
260
|
}
|
|
178
261
|
if (message === EMPTY_SYMBOL) {
|
|
179
262
|
rest.message = void 0;
|
|
@@ -185,7 +268,8 @@ class AbstractJsonReporter {
|
|
|
185
268
|
}
|
|
186
269
|
if (context) {
|
|
187
270
|
const newContext = [];
|
|
188
|
-
for (
|
|
271
|
+
for (let i = 0; i < context.length; i += 1) {
|
|
272
|
+
const item = context[i];
|
|
189
273
|
if (item === EMPTY_SYMBOL) {
|
|
190
274
|
continue;
|
|
191
275
|
}
|