@logtape/elysia 2.2.0-dev.696 → 2.2.0-dev.700

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/dist/mod.cjs CHANGED
@@ -263,44 +263,74 @@ function getErrorStatus(code, error, setStatus) {
263
263
  if (code in errorCodeToStatus) return errorCodeToStatus[code];
264
264
  return setStatus;
265
265
  }
266
+ const elysiaRouteMethods = [
267
+ "all",
268
+ "connect",
269
+ "delete",
270
+ "get",
271
+ "head",
272
+ "options",
273
+ "patch",
274
+ "post",
275
+ "put"
276
+ ];
277
+ function getElysiaRouteEntries(plugin) {
278
+ if (plugin == null || typeof plugin !== "object") return [];
279
+ const routePlugin = plugin;
280
+ const history = routePlugin.router?.history;
281
+ const entries = Array.isArray(history) ? history : history == null ? [] : Object.values(history);
282
+ return entries.concat(getElysiaRouteEntries(routePlugin.default));
283
+ }
266
284
  /**
267
- * Check whether an Elysia route path matches a request path.
285
+ * Wrap routes registered on a local plugin with implicit LogTape context.
268
286
  */
269
- function routePathMatches(routePath, requestPath) {
270
- if (routePath === requestPath) return true;
271
- const routeSegments = routePath.split("/");
272
- const requestSegments = requestPath.split("/");
273
- const segmentCount = Math.max(routeSegments.length, requestSegments.length);
274
- for (let index = 0; index < segmentCount; index++) {
275
- const routeSegment = routeSegments[index];
276
- const requestSegment = requestSegments[index];
277
- if (routeSegment == null) return false;
278
- if (routeSegment === "*") return true;
279
- if (requestSegment == null) {
280
- if (routeSegment.startsWith(":") && routeSegment.endsWith("?")) continue;
281
- return false;
287
+ function wrapLocalRouteHandlers(plugin, buildAndStoreRequestContext, applyRequestContextToSet) {
288
+ const wrappedHandlers = /* @__PURE__ */ new WeakSet();
289
+ const wrappedHandlerCache = /* @__PURE__ */ new WeakMap();
290
+ const wrapHandler = (handler) => {
291
+ if (typeof handler !== "function") return handler;
292
+ const routeHandler = handler;
293
+ if (wrappedHandlers.has(routeHandler)) return handler;
294
+ const cached = wrappedHandlerCache.get(routeHandler);
295
+ if (cached != null) return cached;
296
+ const wrapped = async function(ctx) {
297
+ const requestContext = await buildAndStoreRequestContext(ctx.request);
298
+ ctx.store.startTime = requestContext?.startTime ?? performance.now();
299
+ applyRequestContextToSet(ctx.set, requestContext);
300
+ return await (0, __logtape_logtape.withContext)(requestContext?.context ?? {}, () => routeHandler.call(this, ctx));
301
+ };
302
+ wrappedHandlers.add(wrapped);
303
+ wrappedHandlerCache.set(routeHandler, wrapped);
304
+ return wrapped;
305
+ };
306
+ const wrapRouteEntries = (routePlugin) => {
307
+ const restore = [];
308
+ for (const route$1 of getElysiaRouteEntries(routePlugin)) {
309
+ const handler = route$1.handler;
310
+ const wrappedHandler = wrapHandler(handler);
311
+ if (wrappedHandler === handler) continue;
312
+ route$1.handler = wrappedHandler;
313
+ restore.push(() => {
314
+ route$1.handler = handler;
315
+ });
282
316
  }
283
- if (routeSegment === requestSegment || routeSegment.startsWith(":")) continue;
284
- return false;
317
+ return restore;
318
+ };
319
+ for (const method of elysiaRouteMethods) {
320
+ const register = plugin[method].bind(plugin);
321
+ plugin[method] = (path, handler, hook) => register(path, wrapHandler(handler), hook);
285
322
  }
286
- return true;
287
- }
288
- /**
289
- * Check whether an Elysia route method can handle a request method.
290
- */
291
- function routeMethodMatches(routeMethod, requestMethod) {
292
- return routeMethod === requestMethod || routeMethod === "ALL" || routeMethod === "GET" && requestMethod === "HEAD";
293
- }
294
- /**
295
- * Check whether a request belongs to routes defined on the local plugin.
296
- */
297
- function isLocalPluginRoute(plugin, request) {
298
- const path = getPath(request);
299
- const httpRouter = plugin.router?.http;
300
- if (httpRouter?.find(request.method, path) != null) return true;
301
- if (httpRouter?.find("ALL", path) != null) return true;
302
- if (request.method === "HEAD" && httpRouter?.find("GET", path) != null) return true;
303
- return plugin.routes?.some((route) => routeMethodMatches(route.method, request.method) && routePathMatches(route.path, path)) ?? false;
323
+ const route = plugin.route.bind(plugin);
324
+ plugin.route = (method, path, handler, hook) => route(method, path, wrapHandler(handler), hook);
325
+ const use = plugin.use.bind(plugin);
326
+ plugin.use = (childPlugin, ...options) => {
327
+ const restore = wrapRouteEntries(childPlugin);
328
+ try {
329
+ return use(childPlugin, ...options);
330
+ } finally {
331
+ for (const restoreRouteHandler of restore) restoreRouteHandler();
332
+ }
333
+ };
304
334
  }
305
335
  /**
306
336
  * Creates Elysia plugin for HTTP request logging using LogTape.
@@ -392,9 +422,9 @@ function elysiaLogger(options = {}) {
392
422
  name: "@logtape/elysia",
393
423
  seed: options
394
424
  });
395
- if (shouldWrapContext) plugin = plugin.wrap((handle) => {
425
+ if (shouldWrapContext && scope === "local") wrapLocalRouteHandlers(plugin, buildAndStoreRequestContext, applyRequestContextToSet);
426
+ else if (shouldWrapContext) plugin = plugin.wrap((handle) => {
396
427
  return async (request) => {
397
- if (scope === "local" && !isLocalPluginRoute(plugin, request)) return await handle(request);
398
428
  const requestContext = await buildAndStoreRequestContext(request);
399
429
  return await (0, __logtape_logtape.withContext)(requestContext?.context ?? {}, () => handle(request));
400
430
  };
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.cts","names":[],"sources":["../src/mod.ts"],"sourcesContent":[],"mappings":";;;;;;AASA;;;AAKa,UALI,aAAA,CAKJ;EAAM,OAAA,EAJR,OAIQ;EAQP,IAAA,EAAA,MAAA;EAMA,GAAA,EAAA;IAUA,MAAA,EAAA,MAAc;IAAA,OAAA,EAxBb,MAwBa,CAAA,MAAA,EAAA,MAAA,GAAA,SAAA,CAAA;EAAA,CAAA;;AAGN;AAMpB;AAyBA;AAaA;AAqCiB,KApGL,WAAA,GAoGK,QAAqB,GAAA,QAAA,GAAA,OAAA;;;;;AAkB/B,KAhHK,gBAAA,GAgHL,UAAA,GAAA,QAAA,GAAA,KAAA,GAAA,OAAA,GAAA,MAAA;;;AAAiC;AAOxC;;;;;AAyCwB,KAtJZ,cAAA,GAsJY,CAAA,GAAA,EArJjB,aAqJiB,EAAA,YAAA,EAAA,MAAA,EAAA,GAAA,MAAA,GAnJV,MAmJU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;;;;;;;;mBAWE;;;;;;;;;;;;;;oBAeC,mBAAmB;;;;;;;;;;;;;;wBAef;;;;;;;;;;;;;;;;;;;;mBAsBL;;;;;;;;;;;;+BAaY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA4kBf,YAAA,WAAsB,uBAA4B"}
package/dist/mod.js CHANGED
@@ -262,44 +262,74 @@ function getErrorStatus(code, error, setStatus) {
262
262
  if (code in errorCodeToStatus) return errorCodeToStatus[code];
263
263
  return setStatus;
264
264
  }
265
+ const elysiaRouteMethods = [
266
+ "all",
267
+ "connect",
268
+ "delete",
269
+ "get",
270
+ "head",
271
+ "options",
272
+ "patch",
273
+ "post",
274
+ "put"
275
+ ];
276
+ function getElysiaRouteEntries(plugin) {
277
+ if (plugin == null || typeof plugin !== "object") return [];
278
+ const routePlugin = plugin;
279
+ const history = routePlugin.router?.history;
280
+ const entries = Array.isArray(history) ? history : history == null ? [] : Object.values(history);
281
+ return entries.concat(getElysiaRouteEntries(routePlugin.default));
282
+ }
265
283
  /**
266
- * Check whether an Elysia route path matches a request path.
284
+ * Wrap routes registered on a local plugin with implicit LogTape context.
267
285
  */
268
- function routePathMatches(routePath, requestPath) {
269
- if (routePath === requestPath) return true;
270
- const routeSegments = routePath.split("/");
271
- const requestSegments = requestPath.split("/");
272
- const segmentCount = Math.max(routeSegments.length, requestSegments.length);
273
- for (let index = 0; index < segmentCount; index++) {
274
- const routeSegment = routeSegments[index];
275
- const requestSegment = requestSegments[index];
276
- if (routeSegment == null) return false;
277
- if (routeSegment === "*") return true;
278
- if (requestSegment == null) {
279
- if (routeSegment.startsWith(":") && routeSegment.endsWith("?")) continue;
280
- return false;
286
+ function wrapLocalRouteHandlers(plugin, buildAndStoreRequestContext, applyRequestContextToSet) {
287
+ const wrappedHandlers = /* @__PURE__ */ new WeakSet();
288
+ const wrappedHandlerCache = /* @__PURE__ */ new WeakMap();
289
+ const wrapHandler = (handler) => {
290
+ if (typeof handler !== "function") return handler;
291
+ const routeHandler = handler;
292
+ if (wrappedHandlers.has(routeHandler)) return handler;
293
+ const cached = wrappedHandlerCache.get(routeHandler);
294
+ if (cached != null) return cached;
295
+ const wrapped = async function(ctx) {
296
+ const requestContext = await buildAndStoreRequestContext(ctx.request);
297
+ ctx.store.startTime = requestContext?.startTime ?? performance.now();
298
+ applyRequestContextToSet(ctx.set, requestContext);
299
+ return await withContext(requestContext?.context ?? {}, () => routeHandler.call(this, ctx));
300
+ };
301
+ wrappedHandlers.add(wrapped);
302
+ wrappedHandlerCache.set(routeHandler, wrapped);
303
+ return wrapped;
304
+ };
305
+ const wrapRouteEntries = (routePlugin) => {
306
+ const restore = [];
307
+ for (const route$1 of getElysiaRouteEntries(routePlugin)) {
308
+ const handler = route$1.handler;
309
+ const wrappedHandler = wrapHandler(handler);
310
+ if (wrappedHandler === handler) continue;
311
+ route$1.handler = wrappedHandler;
312
+ restore.push(() => {
313
+ route$1.handler = handler;
314
+ });
281
315
  }
282
- if (routeSegment === requestSegment || routeSegment.startsWith(":")) continue;
283
- return false;
316
+ return restore;
317
+ };
318
+ for (const method of elysiaRouteMethods) {
319
+ const register = plugin[method].bind(plugin);
320
+ plugin[method] = (path, handler, hook) => register(path, wrapHandler(handler), hook);
284
321
  }
285
- return true;
286
- }
287
- /**
288
- * Check whether an Elysia route method can handle a request method.
289
- */
290
- function routeMethodMatches(routeMethod, requestMethod) {
291
- return routeMethod === requestMethod || routeMethod === "ALL" || routeMethod === "GET" && requestMethod === "HEAD";
292
- }
293
- /**
294
- * Check whether a request belongs to routes defined on the local plugin.
295
- */
296
- function isLocalPluginRoute(plugin, request) {
297
- const path = getPath(request);
298
- const httpRouter = plugin.router?.http;
299
- if (httpRouter?.find(request.method, path) != null) return true;
300
- if (httpRouter?.find("ALL", path) != null) return true;
301
- if (request.method === "HEAD" && httpRouter?.find("GET", path) != null) return true;
302
- return plugin.routes?.some((route) => routeMethodMatches(route.method, request.method) && routePathMatches(route.path, path)) ?? false;
322
+ const route = plugin.route.bind(plugin);
323
+ plugin.route = (method, path, handler, hook) => route(method, path, wrapHandler(handler), hook);
324
+ const use = plugin.use.bind(plugin);
325
+ plugin.use = (childPlugin, ...options) => {
326
+ const restore = wrapRouteEntries(childPlugin);
327
+ try {
328
+ return use(childPlugin, ...options);
329
+ } finally {
330
+ for (const restoreRouteHandler of restore) restoreRouteHandler();
331
+ }
332
+ };
303
333
  }
304
334
  /**
305
335
  * Creates Elysia plugin for HTTP request logging using LogTape.
@@ -391,9 +421,9 @@ function elysiaLogger(options = {}) {
391
421
  name: "@logtape/elysia",
392
422
  seed: options
393
423
  });
394
- if (shouldWrapContext) plugin = plugin.wrap((handle) => {
424
+ if (shouldWrapContext && scope === "local") wrapLocalRouteHandlers(plugin, buildAndStoreRequestContext, applyRequestContextToSet);
425
+ else if (shouldWrapContext) plugin = plugin.wrap((handle) => {
395
426
  return async (request) => {
396
- if (scope === "local" && !isLocalPluginRoute(plugin, request)) return await handle(request);
397
427
  const requestContext = await buildAndStoreRequestContext(request);
398
428
  return await withContext(requestContext?.context ?? {}, () => handle(request));
399
429
  };
package/dist/mod.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.js","names":["options: boolean | RequestContextOptions | undefined","options: boolean | RequestIdOptions | undefined","value: string","request: Request","options: RequestIdOptions","responseHeader","resolvedRequestId:\n | { readonly property: string; readonly value: string }\n | undefined","include: readonly RequestContextField[]","context: Record<string, unknown>","options: RequestContextOptions","set: ElysiaContext[\"set\"] | undefined","headers: Record<string, string | undefined>","ctx: ElysiaContext","responseTime: number","result: string | Record<string, unknown>","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","errorCodeToStatus: Record<string, number>","code: string | number","error: unknown","setStatus: number","routePath: string","requestPath: string","routeMethod: string","requestMethod: string","plugin: ElysiaRouteMatcher","options: ElysiaLogTapeOptions","formatFn: FormatFunction","set: ElysiaContext[\"set\"]","requestContext: ElysiaRequestContextState | undefined","plugin: Elysia<any, any, any, any, any, any, any>"],"sources":["../src/mod.ts"],"sourcesContent":["import { Elysia } from \"elysia\";\nimport { getLogger, type LogLevel, withContext } from \"@logtape/logtape\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Minimal Elysia Context interface for compatibility.\n * @since 2.0.0\n */\nexport interface ElysiaContext {\n request: Request;\n path: string;\n set: {\n status: number;\n headers: Record<string, string | undefined>;\n };\n}\n\n/**\n * Plugin scope options for controlling hook propagation.\n * @since 2.0.0\n */\nexport type PluginScope = \"global\" | \"scoped\" | \"local\";\n\n/**\n * Predefined log format names compatible with Morgan.\n * @since 2.0.0\n */\nexport type PredefinedFormat = \"combined\" | \"common\" | \"dev\" | \"short\" | \"tiny\";\n\n/**\n * Custom format function for request logging.\n *\n * @param ctx The Elysia context object.\n * @param responseTime The response time in milliseconds.\n * @returns A string message or an object with structured properties.\n * @since 2.0.0\n */\nexport type FormatFunction = (\n ctx: ElysiaContext,\n responseTime: number,\n) => string | Record<string, unknown>;\n\n/**\n * Structured log properties for HTTP requests.\n * @since 2.0.0\n */\nexport interface RequestLogProperties {\n /** HTTP request method */\n method: string;\n /** Request URL */\n url: string;\n /** Request path */\n path: string;\n /** HTTP response status code */\n status: number;\n /** Response time in milliseconds */\n responseTime: number;\n /** Response content-length header value */\n contentLength: string | undefined;\n /** Remote client address (from X-Forwarded-For header) */\n remoteAddr: string | undefined;\n /** User-Agent header value */\n userAgent: string | undefined;\n /** Referrer header value */\n referrer: string | undefined;\n}\n\n/**\n * Request fields that can be added to the implicit request context.\n * @since 2.2.0\n */\nexport type RequestContextField =\n | \"requestId\"\n | \"method\"\n | \"url\"\n | \"path\"\n | \"userAgent\"\n | \"remoteAddr\"\n | \"referrer\";\n\n/**\n * Options for extracting, generating, and propagating a request ID.\n * @since 2.2.0\n */\nexport interface RequestIdOptions {\n /**\n * The property name used in implicit context and request log records.\n * @default \"requestId\"\n */\n readonly property?: string;\n\n /**\n * Incoming request headers to inspect in order.\n * @default [\"x-request-id\"]\n */\n readonly headerNames?: readonly string[];\n\n /**\n * Response header that receives the resolved request ID.\n * Set to `false` to disable response header propagation.\n * @default \"x-request-id\"\n */\n readonly responseHeader?: string | false;\n\n /**\n * Generates a request ID when no incoming header is present.\n * @default crypto.randomUUID()\n */\n readonly generate?: () => string;\n\n /**\n * Normalizes an incoming request ID. Return `null` to reject the value and\n * keep looking for another header or generate a new ID.\n */\n readonly normalize?: (value: string) => string | null;\n}\n\n/**\n * Options for request-scoped implicit context.\n * @since 2.2.0\n */\nexport interface RequestContextOptions {\n /**\n * Enables request ID extraction, generation, and response propagation.\n * @default true\n */\n readonly requestId?: boolean | RequestIdOptions;\n\n /**\n * Fields to add to the implicit context.\n * @default [\"requestId\"]\n */\n readonly include?: readonly RequestContextField[];\n\n /**\n * Adds application-specific fields to the implicit request context.\n */\n readonly enrich?: (\n ctx: ElysiaContext,\n ) => Record<string, unknown> | Promise<Record<string, unknown>>;\n}\n\n/**\n * Options for configuring the Elysia LogTape middleware.\n * @since 2.0.0\n */\nexport interface ElysiaLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"elysia\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The log level to use for request logging.\n * @default \"info\"\n */\n readonly level?: LogLevel;\n\n /**\n * The format for log output.\n * Can be a predefined format name or a custom format function.\n *\n * Predefined formats:\n * - `\"combined\"` - Apache Combined Log Format (structured, default)\n * - `\"common\"` - Apache Common Log Format (structured, no referrer/userAgent)\n * - `\"dev\"` - Concise colored output for development (string)\n * - `\"short\"` - Shorter than common (string)\n * - `\"tiny\"` - Minimal output (string)\n *\n * @default \"combined\"\n */\n readonly format?: PredefinedFormat | FormatFunction;\n\n /**\n * Function to determine whether logging should be skipped.\n * Return `true` to skip logging for a request.\n *\n * @example Skip logging for health check endpoint\n * ```typescript\n * app.use(elysiaLogger({\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (ctx: ElysiaContext) => boolean;\n\n /**\n * If `true`, logs are written immediately when the request is received.\n * If `false` (default), logs are written after the response is sent.\n *\n * Note: When `logRequest` is `true`, response-related properties\n * (status, responseTime, contentLength) will not be available.\n *\n * @default false\n */\n readonly logRequest?: boolean;\n\n /**\n * The plugin scope for controlling how lifecycle hooks are propagated.\n *\n * - `\"global\"` - Hooks apply to all routes in the application\n * - `\"scoped\"` - Hooks apply to the parent instance where the plugin is used\n * - `\"local\"` - Hooks only apply within the plugin itself\n *\n * @default \"global\"\n */\n readonly scope?: PluginScope;\n\n /**\n * Enables request-scoped implicit context and request ID correlation.\n *\n * When set to `true`, the plugin reads the `x-request-id` header, generates\n * one when it is absent, writes it to the `x-request-id` response header,\n * and adds `requestId` to all LogTape records emitted while handling the\n * request.\n *\n * @default false\n * @since 2.2.0\n */\n readonly context?: boolean | RequestContextOptions;\n}\n\nconst defaultRequestIdHeader = \"x-request-id\";\n\n/**\n * Per-request context state stored outside Elysia's shared store.\n */\ninterface ElysiaRequestContextState {\n readonly context: Record<string, unknown>;\n readonly startTime?: number;\n readonly responseHeader?: {\n readonly name: string;\n readonly value: string;\n };\n readonly set?: ElysiaContext[\"set\"];\n}\n\n/**\n * Normalize request context options.\n */\nfunction normalizeRequestContextOptions(\n options: boolean | RequestContextOptions | undefined,\n): RequestContextOptions | undefined {\n if (options === true) return {};\n if (options === false || options == null) return undefined;\n return options;\n}\n\n/**\n * Normalize request ID options.\n */\nfunction normalizeRequestIdOptions(\n options: boolean | RequestIdOptions | undefined,\n): RequestIdOptions | undefined {\n if (options === false) return undefined;\n if (options === true || options == null) return {};\n return options;\n}\n\n/**\n * Generate a request ID with Web Crypto when possible.\n */\nfunction generateRequestId(): string {\n if (typeof globalThis.crypto?.randomUUID === \"function\") {\n return globalThis.crypto.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\n/**\n * Normalize an incoming request ID.\n */\nfunction defaultNormalizeRequestId(value: string): string | null {\n const trimmed = value.trim();\n return trimmed === \"\" ? null : trimmed;\n}\n\n/**\n * Resolve a request path from a request URL.\n */\nfunction getPath(request: Request): string {\n return new URL(request.url, \"http://localhost\").pathname;\n}\n\n/**\n * Resolve the request ID for a request.\n */\nfunction resolveRequestId(\n request: Request,\n options: RequestIdOptions,\n): {\n readonly property: string;\n readonly value: string;\n readonly responseHeader?: string;\n} {\n const property = options.property ?? \"requestId\";\n const normalize = options.normalize ?? defaultNormalizeRequestId;\n const headerNames = options.headerNames ?? [defaultRequestIdHeader];\n for (const headerName of headerNames) {\n const headerValue = request.headers.get(headerName);\n if (headerValue == null) continue;\n const normalized = normalize(headerValue);\n if (normalized != null) {\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: normalized,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n }\n }\n const generated = (options.generate ?? generateRequestId)();\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: generated,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n}\n\n/**\n * Get referrer from request headers.\n */\nfunction getReferrer(request: Request): string | undefined {\n return request.headers.get(\"referrer\") ??\n request.headers.get(\"referer\") ??\n undefined;\n}\n\n/**\n * Get user agent from request headers.\n */\nfunction getUserAgent(request: Request): string | undefined {\n return request.headers.get(\"user-agent\") ?? undefined;\n}\n\n/**\n * Get remote address from X-Forwarded-For header.\n */\nfunction getRemoteAddr(request: Request): string | undefined {\n const forwarded = request.headers.get(\"x-forwarded-for\");\n if (forwarded) {\n // X-Forwarded-For can contain multiple IPs, take the first one\n const firstIp = forwarded.split(\",\")[0].trim();\n return firstIp || undefined;\n }\n return undefined;\n}\n\n/**\n * Build request context fields from a request.\n */\nfunction buildIncludedContext(\n request: Request,\n resolvedRequestId:\n | { readonly property: string; readonly value: string }\n | undefined,\n include: readonly RequestContextField[],\n): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n for (const field of include) {\n switch (field) {\n case \"requestId\":\n if (resolvedRequestId != null) {\n context[resolvedRequestId.property] = resolvedRequestId.value;\n }\n break;\n case \"method\":\n context.method = request.method;\n break;\n case \"url\":\n context.url = request.url;\n break;\n case \"path\":\n context.path = getPath(request);\n break;\n case \"userAgent\":\n context.userAgent = getUserAgent(request);\n break;\n case \"remoteAddr\":\n context.remoteAddr = getRemoteAddr(request);\n break;\n case \"referrer\":\n context.referrer = getReferrer(request);\n break;\n }\n }\n return context;\n}\n\n/**\n * Build the implicit context for a request.\n */\nasync function buildRequestContext(\n request: Request,\n options: RequestContextOptions,\n): Promise<ElysiaRequestContextState> {\n const requestIdOptions = normalizeRequestIdOptions(options.requestId);\n const resolvedRequestId = requestIdOptions == null\n ? undefined\n : resolveRequestId(request, requestIdOptions);\n const include = options.include ??\n (resolvedRequestId == null ? [] : [\"requestId\"] as const);\n const context = buildIncludedContext(request, resolvedRequestId, include);\n let set: ElysiaContext[\"set\"] | undefined;\n if (options.enrich != null) {\n set = { status: 200, headers: {} };\n Object.assign(\n context,\n await options.enrich({\n request,\n path: getPath(request),\n set,\n }),\n );\n }\n const responseHeader = resolvedRequestId?.responseHeader == null\n ? undefined\n : {\n name: resolvedRequestId.responseHeader,\n value: resolvedRequestId.value,\n };\n return { context, responseHeader, set };\n}\n\n/**\n * Get content length from response headers.\n */\nfunction getContentLength(\n headers: Record<string, string | undefined>,\n): string | undefined {\n const contentLength = headers[\"content-length\"];\n if (contentLength === undefined || contentLength === null) return undefined;\n return contentLength;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n ctx: ElysiaContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: ctx.request.method,\n url: ctx.request.url,\n path: ctx.path,\n status: ctx.set.status,\n responseTime,\n contentLength: getContentLength(ctx.set.headers),\n remoteAddr: getRemoteAddr(ctx.request),\n userAgent: getUserAgent(ctx.request),\n referrer: getReferrer(ctx.request),\n };\n}\n\n/**\n * Add request context fields to a request log result.\n */\nfunction withRequestLogContext(\n result: string | Record<string, unknown>,\n context: Record<string, unknown>,\n): string | Record<string, unknown> {\n if (typeof result === \"string\") return result;\n return { ...result, ...context };\n}\n\n/**\n * Combined format (Apache Combined Log Format).\n * Returns all structured properties.\n */\nfunction formatCombined(\n ctx: ElysiaContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(ctx, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n ctx: ElysiaContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(ctx, responseTime);\n const { referrer: _referrer, userAgent: _userAgent, ...rest } = props;\n return rest;\n}\n\n/**\n * Dev format (colored output for development).\n * :method :path :status :response-time ms - :res[content-length]\n */\nfunction formatDev(ctx: ElysiaContext, responseTime: number): string {\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${ctx.request.method} ${ctx.path} ${ctx.set.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :remote-addr :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(ctx: ElysiaContext, responseTime: number): string {\n const remoteAddr = getRemoteAddr(ctx.request) ?? \"-\";\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${remoteAddr} ${ctx.request.method} ${ctx.request.url} ${ctx.set.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Tiny format (minimal output).\n * :method :path :status :res[content-length] - :response-time ms\n */\nfunction formatTiny(ctx: ElysiaContext, responseTime: number): string {\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${ctx.request.method} ${ctx.path} ${ctx.set.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Map of predefined format functions.\n */\nconst predefinedFormats: Record<PredefinedFormat, FormatFunction> = {\n combined: formatCombined,\n common: formatCommon,\n dev: formatDev,\n short: formatShort,\n tiny: formatTiny,\n};\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Mapping of Elysia error codes to HTTP status codes.\n */\nconst errorCodeToStatus: Record<string, number> = {\n NOT_FOUND: 404,\n VALIDATION: 422,\n PARSE: 400,\n INTERNAL_SERVER_ERROR: 500,\n INVALID_COOKIE_SIGNATURE: 400,\n UNKNOWN: 500,\n};\n\n/**\n * Get the HTTP status code from an error context.\n * Checks error.status first, then falls back to error code mapping.\n */\nfunction getErrorStatus(\n code: string | number,\n error: unknown,\n setStatus: number,\n): number {\n // If code is already a number, use it as status\n if (typeof code === \"number\") {\n return code;\n }\n // Check if error has a status property (Elysia custom errors)\n if (\n error != null &&\n typeof error === \"object\" &&\n \"status\" in error &&\n typeof error.status === \"number\"\n ) {\n return error.status;\n }\n // Fall back to error code mapping\n if (code in errorCodeToStatus) {\n return errorCodeToStatus[code];\n }\n // Use set.status as last resort\n return setStatus;\n}\n\n/**\n * Internal store type for timing.\n */\ninterface LoggerStore {\n startTime: number;\n}\n\n/**\n * Minimal shape of Elysia's internal route matcher.\n */\ninterface ElysiaRouteMatcher {\n readonly router?: {\n readonly http?: {\n find(method: string, path: string): unknown;\n };\n };\n readonly routes?: readonly {\n readonly method: string;\n readonly path: string;\n }[];\n}\n\n/**\n * Check whether an Elysia route path matches a request path.\n */\nfunction routePathMatches(routePath: string, requestPath: string): boolean {\n if (routePath === requestPath) return true;\n const routeSegments = routePath.split(\"/\");\n const requestSegments = requestPath.split(\"/\");\n const segmentCount = Math.max(routeSegments.length, requestSegments.length);\n for (let index = 0; index < segmentCount; index++) {\n const routeSegment = routeSegments[index];\n const requestSegment = requestSegments[index];\n if (routeSegment == null) return false;\n if (routeSegment === \"*\") return true;\n if (requestSegment == null) {\n if (routeSegment.startsWith(\":\") && routeSegment.endsWith(\"?\")) {\n continue;\n }\n return false;\n }\n if (routeSegment === requestSegment || routeSegment.startsWith(\":\")) {\n continue;\n }\n return false;\n }\n return true;\n}\n\n/**\n * Check whether an Elysia route method can handle a request method.\n */\nfunction routeMethodMatches(\n routeMethod: string,\n requestMethod: string,\n): boolean {\n return routeMethod === requestMethod || routeMethod === \"ALL\" ||\n (routeMethod === \"GET\" && requestMethod === \"HEAD\");\n}\n\n/**\n * Check whether a request belongs to routes defined on the local plugin.\n */\nfunction isLocalPluginRoute(\n plugin: ElysiaRouteMatcher,\n request: Request,\n): boolean {\n const path = getPath(request);\n const httpRouter = plugin.router?.http;\n if (httpRouter?.find(request.method, path) != null) return true;\n if (httpRouter?.find(\"ALL\", path) != null) return true;\n if (request.method === \"HEAD\" && httpRouter?.find(\"GET\", path) != null) {\n return true;\n }\n return plugin.routes?.some((route) =>\n routeMethodMatches(route.method, request.method) &&\n routePathMatches(route.path, path)\n ) ?? false;\n}\n\n/**\n * Creates Elysia plugin for HTTP request logging using LogTape.\n *\n * This plugin provides Morgan-compatible request logging with LogTape\n * as the backend, supporting structured logging and customizable formats.\n *\n * @example Basic usage\n * ```typescript\n * import { Elysia } from \"elysia\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { elysiaLogger } from \"@logtape/elysia\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"elysia\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Elysia()\n * .use(elysiaLogger())\n * .get(\"/\", () => ({ hello: \"world\" }))\n * .listen(3000);\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(elysiaLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (ctx) => ctx.path === \"/health\",\n * scope: \"scoped\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(elysiaLogger({\n * format: (ctx, responseTime) => ({\n * method: ctx.request.method,\n * path: ctx.path,\n * status: ctx.set.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the plugin.\n * @returns Elysia plugin instance.\n * @since 2.0.0\n */\n// deno-lint-ignore no-explicit-any\nexport function elysiaLogger(options: ElysiaLogTapeOptions = {}): Elysia<any> {\n const category = normalizeCategory(options.category ?? [\"elysia\"]);\n const logger = getLogger(category);\n const level = options.level ?? \"info\";\n const formatOption = options.format ?? \"combined\";\n const skip = options.skip ?? (() => false);\n const logRequest = options.logRequest ?? false;\n const scope = options.scope ?? \"global\";\n const contextOptions = normalizeRequestContextOptions(options.context);\n const requestContextStates = new WeakMap<\n Request,\n ElysiaRequestContextState\n >();\n const shouldWrapContext = contextOptions != null;\n const shouldWrapAllRoutes = contextOptions != null && scope !== \"local\";\n\n // Resolve format function\n const formatFn: FormatFunction = typeof formatOption === \"string\"\n ? predefinedFormats[formatOption]\n : formatOption;\n\n const logMethod = logger[level].bind(logger);\n const errorLogMethod = logger.error.bind(logger);\n\n const buildAndStoreRequestContext = async (\n request: Request,\n ): Promise<ElysiaRequestContextState | undefined> => {\n if (contextOptions == null) return undefined;\n const existingContext = requestContextStates.get(request);\n if (existingContext != null) return existingContext;\n const startTime = performance.now();\n const requestContext = {\n ...await buildRequestContext(request, contextOptions),\n startTime,\n };\n requestContextStates.set(request, requestContext);\n return requestContext;\n };\n\n const applyRequestContextToSet = (\n set: ElysiaContext[\"set\"],\n requestContext: ElysiaRequestContextState | undefined,\n ): void => {\n if (requestContext?.responseHeader != null) {\n set.headers[requestContext.responseHeader.name] =\n requestContext.responseHeader.value;\n }\n if (requestContext?.set != null) {\n if (requestContext.set.status !== 200) {\n set.status = requestContext.set.status;\n }\n Object.assign(set.headers, requestContext.set.headers);\n }\n };\n\n // deno-lint-ignore no-explicit-any\n let plugin: Elysia<any, any, any, any, any, any, any> = new Elysia({\n name: \"@logtape/elysia\",\n seed: options,\n });\n\n if (shouldWrapContext) {\n // Elysia lifecycle hooks cannot wrap downstream handlers, so use wrap()\n // to keep AsyncLocalStorage active for the whole route execution.\n plugin = plugin.wrap((handle) => {\n return async (request: Request) => {\n if (scope === \"local\" && !isLocalPluginRoute(plugin, request)) {\n return await handle(request);\n }\n const requestContext = await buildAndStoreRequestContext(request);\n return await withContext(\n requestContext?.context ?? {},\n () => handle(request),\n );\n };\n });\n }\n\n plugin = plugin\n .state(\"startTime\", 0)\n .onRequest(async ({ request, set, store }) => {\n let requestContext = requestContextStates.get(request);\n if (requestContext == null && shouldWrapAllRoutes) {\n requestContext = await buildAndStoreRequestContext(request);\n }\n (store as LoggerStore).startTime = requestContext?.startTime ??\n performance.now();\n applyRequestContextToSet(set, requestContext);\n });\n\n if (scope === \"local\" && (contextOptions != null || logRequest)) {\n plugin = plugin.onBeforeHandle(async (ctx) => {\n const requestContext = await buildAndStoreRequestContext(ctx.request);\n (ctx.store as LoggerStore).startTime = requestContext?.startTime ??\n performance.now();\n applyRequestContextToSet(ctx.set, requestContext);\n if (logRequest && !skip(ctx as unknown as ElysiaContext)) {\n const context = requestContext?.context ?? {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, 0),\n context,\n );\n if (typeof result === \"string\") {\n logMethod(result, context);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n });\n }\n\n if (logRequest) {\n // Log immediately when request arrives\n if (scope !== \"local\") {\n plugin = plugin.onRequest((ctx) => {\n if (!skip(ctx as unknown as ElysiaContext)) {\n const requestContext =\n requestContextStates.get(ctx.request)?.context ??\n {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, 0),\n requestContext,\n );\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n });\n }\n } else {\n // Log after handler completes\n plugin = plugin.onAfterHandle((ctx) => {\n if (skip(ctx as unknown as ElysiaContext)) return;\n\n const store = ctx.store as LoggerStore;\n const responseTime = performance.now() - store.startTime;\n const requestContext = requestContextStates.get(ctx.request)?.context ??\n {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, responseTime),\n requestContext,\n );\n\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url} {status} - {responseTime} ms\", result);\n }\n });\n }\n\n // Add error logging\n plugin = plugin.onError((ctx) => {\n const store = ctx.store as LoggerStore;\n const responseTime = performance.now() - store.startTime;\n const elysiaCtx = ctx as unknown as ElysiaContext;\n\n if (skip(elysiaCtx)) return;\n\n const props = buildProperties(elysiaCtx, responseTime);\n const requestContext = requestContextStates.get(ctx.request)?.context ?? {};\n // Get the correct HTTP status code from error context\n const status = getErrorStatus(ctx.code, ctx.error, elysiaCtx.set.status);\n // Extract error message safely\n const error = ctx.error as { message?: string } | undefined;\n const errorMessage = error?.message ?? \"Unknown error\";\n errorLogMethod(\n \"Error: {method} {url} {status} - {responseTime} ms - {errorMessage}\",\n {\n ...props,\n ...requestContext,\n status,\n errorMessage,\n errorCode: ctx.code,\n },\n );\n });\n\n // Apply scope\n if (scope === \"global\") {\n // deno-lint-ignore no-explicit-any\n return plugin.as(\"global\") as unknown as Elysia<any>;\n } else if (scope === \"scoped\") {\n // deno-lint-ignore no-explicit-any\n return plugin.as(\"scoped\") as unknown as Elysia<any>;\n }\n\n // deno-lint-ignore no-explicit-any\n return plugin as unknown as Elysia<any>;\n}\n"],"mappings":";;;;AAkOA,MAAM,yBAAyB;;;;AAkB/B,SAAS,+BACPA,SACmC;AACnC,KAAI,YAAY,KAAM,QAAO,CAAE;AAC/B,KAAI,YAAY,SAAS,WAAW,KAAM;AAC1C,QAAO;AACR;;;;AAKD,SAAS,0BACPC,SAC8B;AAC9B,KAAI,YAAY,MAAO;AACvB,KAAI,YAAY,QAAQ,WAAW,KAAM,QAAO,CAAE;AAClD,QAAO;AACR;;;;AAKD,SAAS,oBAA4B;AACnC,YAAW,WAAW,QAAQ,eAAe,WAC3C,QAAO,WAAW,OAAO,YAAY;AAEvC,SAAQ,EAAE,KAAK,KAAK,CAAC,SAAS,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC;AAC1E;;;;AAKD,SAAS,0BAA0BC,OAA8B;CAC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U,SAEZ,QAAO,OAAO,GAAG,SAAS;UACjB,UAAU,SAEnB,QAAO,OAAO,GAAG,SAAS;AAI5B,QAAO;AACR"}
1
+ {"version":3,"file":"mod.js","names":["options: boolean | RequestContextOptions | undefined","options: boolean | RequestIdOptions | undefined","value: string","request: Request","options: RequestIdOptions","responseHeader","resolvedRequestId:\n | { readonly property: string; readonly value: string }\n | undefined","include: readonly RequestContextField[]","context: Record<string, unknown>","options: RequestContextOptions","set: ElysiaContext[\"set\"] | undefined","headers: Record<string, string | undefined>","ctx: ElysiaContext","responseTime: number","result: string | Record<string, unknown>","predefinedFormats: Record<PredefinedFormat, FormatFunction>","category: string | readonly string[]","errorCodeToStatus: Record<string, number>","code: string | number","error: unknown","setStatus: number","elysiaRouteMethods: readonly ElysiaRouteMethod[]","plugin: unknown","plugin: ElysiaRoutePlugin","buildAndStoreRequestContext: (\n request: Request,\n ) => Promise<ElysiaRequestContextState | undefined>","applyRequestContextToSet: (\n set: ElysiaContext[\"set\"],\n requestContext: ElysiaRequestContextState | undefined,\n ) => void","handler: unknown","ctx: ElysiaRouteContext","routePlugin: unknown","restore: (() => void)[]","route","path: string","hook?: unknown","method: string","childPlugin: unknown","options: ElysiaLogTapeOptions","formatFn: FormatFunction","set: ElysiaContext[\"set\"]","requestContext: ElysiaRequestContextState | undefined","plugin: Elysia<any, any, any, any, any, any, any>"],"sources":["../src/mod.ts"],"sourcesContent":["import { Elysia } from \"elysia\";\nimport { getLogger, type LogLevel, withContext } from \"@logtape/logtape\";\n\nexport type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Minimal Elysia Context interface for compatibility.\n * @since 2.0.0\n */\nexport interface ElysiaContext {\n request: Request;\n path: string;\n set: {\n status: number;\n headers: Record<string, string | undefined>;\n };\n}\n\n/**\n * Plugin scope options for controlling hook propagation.\n * @since 2.0.0\n */\nexport type PluginScope = \"global\" | \"scoped\" | \"local\";\n\n/**\n * Predefined log format names compatible with Morgan.\n * @since 2.0.0\n */\nexport type PredefinedFormat = \"combined\" | \"common\" | \"dev\" | \"short\" | \"tiny\";\n\n/**\n * Custom format function for request logging.\n *\n * @param ctx The Elysia context object.\n * @param responseTime The response time in milliseconds.\n * @returns A string message or an object with structured properties.\n * @since 2.0.0\n */\nexport type FormatFunction = (\n ctx: ElysiaContext,\n responseTime: number,\n) => string | Record<string, unknown>;\n\n/**\n * Structured log properties for HTTP requests.\n * @since 2.0.0\n */\nexport interface RequestLogProperties {\n /** HTTP request method */\n method: string;\n /** Request URL */\n url: string;\n /** Request path */\n path: string;\n /** HTTP response status code */\n status: number;\n /** Response time in milliseconds */\n responseTime: number;\n /** Response content-length header value */\n contentLength: string | undefined;\n /** Remote client address (from X-Forwarded-For header) */\n remoteAddr: string | undefined;\n /** User-Agent header value */\n userAgent: string | undefined;\n /** Referrer header value */\n referrer: string | undefined;\n}\n\n/**\n * Request fields that can be added to the implicit request context.\n * @since 2.2.0\n */\nexport type RequestContextField =\n | \"requestId\"\n | \"method\"\n | \"url\"\n | \"path\"\n | \"userAgent\"\n | \"remoteAddr\"\n | \"referrer\";\n\n/**\n * Options for extracting, generating, and propagating a request ID.\n * @since 2.2.0\n */\nexport interface RequestIdOptions {\n /**\n * The property name used in implicit context and request log records.\n * @default \"requestId\"\n */\n readonly property?: string;\n\n /**\n * Incoming request headers to inspect in order.\n * @default [\"x-request-id\"]\n */\n readonly headerNames?: readonly string[];\n\n /**\n * Response header that receives the resolved request ID.\n * Set to `false` to disable response header propagation.\n * @default \"x-request-id\"\n */\n readonly responseHeader?: string | false;\n\n /**\n * Generates a request ID when no incoming header is present.\n * @default crypto.randomUUID()\n */\n readonly generate?: () => string;\n\n /**\n * Normalizes an incoming request ID. Return `null` to reject the value and\n * keep looking for another header or generate a new ID.\n */\n readonly normalize?: (value: string) => string | null;\n}\n\n/**\n * Options for request-scoped implicit context.\n * @since 2.2.0\n */\nexport interface RequestContextOptions {\n /**\n * Enables request ID extraction, generation, and response propagation.\n * @default true\n */\n readonly requestId?: boolean | RequestIdOptions;\n\n /**\n * Fields to add to the implicit context.\n * @default [\"requestId\"]\n */\n readonly include?: readonly RequestContextField[];\n\n /**\n * Adds application-specific fields to the implicit request context.\n */\n readonly enrich?: (\n ctx: ElysiaContext,\n ) => Record<string, unknown> | Promise<Record<string, unknown>>;\n}\n\n/**\n * Options for configuring the Elysia LogTape middleware.\n * @since 2.0.0\n */\nexport interface ElysiaLogTapeOptions {\n /**\n * The LogTape category to use for logging.\n * @default [\"elysia\"]\n */\n readonly category?: string | readonly string[];\n\n /**\n * The log level to use for request logging.\n * @default \"info\"\n */\n readonly level?: LogLevel;\n\n /**\n * The format for log output.\n * Can be a predefined format name or a custom format function.\n *\n * Predefined formats:\n * - `\"combined\"` - Apache Combined Log Format (structured, default)\n * - `\"common\"` - Apache Common Log Format (structured, no referrer/userAgent)\n * - `\"dev\"` - Concise colored output for development (string)\n * - `\"short\"` - Shorter than common (string)\n * - `\"tiny\"` - Minimal output (string)\n *\n * @default \"combined\"\n */\n readonly format?: PredefinedFormat | FormatFunction;\n\n /**\n * Function to determine whether logging should be skipped.\n * Return `true` to skip logging for a request.\n *\n * @example Skip logging for health check endpoint\n * ```typescript\n * app.use(elysiaLogger({\n * skip: (ctx) => ctx.path === \"/health\",\n * }));\n * ```\n *\n * @default () => false\n */\n readonly skip?: (ctx: ElysiaContext) => boolean;\n\n /**\n * If `true`, logs are written immediately when the request is received.\n * If `false` (default), logs are written after the response is sent.\n *\n * Note: When `logRequest` is `true`, response-related properties\n * (status, responseTime, contentLength) will not be available.\n *\n * @default false\n */\n readonly logRequest?: boolean;\n\n /**\n * The plugin scope for controlling how lifecycle hooks are propagated.\n *\n * - `\"global\"` - Hooks apply to all routes in the application\n * - `\"scoped\"` - Hooks apply to the parent instance where the plugin is used\n * - `\"local\"` - Hooks only apply within the plugin itself\n *\n * @default \"global\"\n */\n readonly scope?: PluginScope;\n\n /**\n * Enables request-scoped implicit context and request ID correlation.\n *\n * When set to `true`, the plugin reads the `x-request-id` header, generates\n * one when it is absent, writes it to the `x-request-id` response header,\n * and adds `requestId` to all LogTape records emitted while handling the\n * request.\n *\n * @default false\n * @since 2.2.0\n */\n readonly context?: boolean | RequestContextOptions;\n}\n\nconst defaultRequestIdHeader = \"x-request-id\";\n\n/**\n * Per-request context state stored outside Elysia's shared store.\n */\ninterface ElysiaRequestContextState {\n readonly context: Record<string, unknown>;\n readonly startTime?: number;\n readonly responseHeader?: {\n readonly name: string;\n readonly value: string;\n };\n readonly set?: ElysiaContext[\"set\"];\n}\n\n/**\n * Normalize request context options.\n */\nfunction normalizeRequestContextOptions(\n options: boolean | RequestContextOptions | undefined,\n): RequestContextOptions | undefined {\n if (options === true) return {};\n if (options === false || options == null) return undefined;\n return options;\n}\n\n/**\n * Normalize request ID options.\n */\nfunction normalizeRequestIdOptions(\n options: boolean | RequestIdOptions | undefined,\n): RequestIdOptions | undefined {\n if (options === false) return undefined;\n if (options === true || options == null) return {};\n return options;\n}\n\n/**\n * Generate a request ID with Web Crypto when possible.\n */\nfunction generateRequestId(): string {\n if (typeof globalThis.crypto?.randomUUID === \"function\") {\n return globalThis.crypto.randomUUID();\n }\n return `${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;\n}\n\n/**\n * Normalize an incoming request ID.\n */\nfunction defaultNormalizeRequestId(value: string): string | null {\n const trimmed = value.trim();\n return trimmed === \"\" ? null : trimmed;\n}\n\n/**\n * Resolve a request path from a request URL.\n */\nfunction getPath(request: Request): string {\n return new URL(request.url, \"http://localhost\").pathname;\n}\n\n/**\n * Resolve the request ID for a request.\n */\nfunction resolveRequestId(\n request: Request,\n options: RequestIdOptions,\n): {\n readonly property: string;\n readonly value: string;\n readonly responseHeader?: string;\n} {\n const property = options.property ?? \"requestId\";\n const normalize = options.normalize ?? defaultNormalizeRequestId;\n const headerNames = options.headerNames ?? [defaultRequestIdHeader];\n for (const headerName of headerNames) {\n const headerValue = request.headers.get(headerName);\n if (headerValue == null) continue;\n const normalized = normalize(headerValue);\n if (normalized != null) {\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: normalized,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n }\n }\n const generated = (options.generate ?? generateRequestId)();\n const responseHeader = options.responseHeader ?? defaultRequestIdHeader;\n return {\n property,\n value: generated,\n responseHeader: responseHeader === false ? undefined : responseHeader,\n };\n}\n\n/**\n * Get referrer from request headers.\n */\nfunction getReferrer(request: Request): string | undefined {\n return request.headers.get(\"referrer\") ??\n request.headers.get(\"referer\") ??\n undefined;\n}\n\n/**\n * Get user agent from request headers.\n */\nfunction getUserAgent(request: Request): string | undefined {\n return request.headers.get(\"user-agent\") ?? undefined;\n}\n\n/**\n * Get remote address from X-Forwarded-For header.\n */\nfunction getRemoteAddr(request: Request): string | undefined {\n const forwarded = request.headers.get(\"x-forwarded-for\");\n if (forwarded) {\n // X-Forwarded-For can contain multiple IPs, take the first one\n const firstIp = forwarded.split(\",\")[0].trim();\n return firstIp || undefined;\n }\n return undefined;\n}\n\n/**\n * Build request context fields from a request.\n */\nfunction buildIncludedContext(\n request: Request,\n resolvedRequestId:\n | { readonly property: string; readonly value: string }\n | undefined,\n include: readonly RequestContextField[],\n): Record<string, unknown> {\n const context: Record<string, unknown> = {};\n for (const field of include) {\n switch (field) {\n case \"requestId\":\n if (resolvedRequestId != null) {\n context[resolvedRequestId.property] = resolvedRequestId.value;\n }\n break;\n case \"method\":\n context.method = request.method;\n break;\n case \"url\":\n context.url = request.url;\n break;\n case \"path\":\n context.path = getPath(request);\n break;\n case \"userAgent\":\n context.userAgent = getUserAgent(request);\n break;\n case \"remoteAddr\":\n context.remoteAddr = getRemoteAddr(request);\n break;\n case \"referrer\":\n context.referrer = getReferrer(request);\n break;\n }\n }\n return context;\n}\n\n/**\n * Build the implicit context for a request.\n */\nasync function buildRequestContext(\n request: Request,\n options: RequestContextOptions,\n): Promise<ElysiaRequestContextState> {\n const requestIdOptions = normalizeRequestIdOptions(options.requestId);\n const resolvedRequestId = requestIdOptions == null\n ? undefined\n : resolveRequestId(request, requestIdOptions);\n const include = options.include ??\n (resolvedRequestId == null ? [] : [\"requestId\"] as const);\n const context = buildIncludedContext(request, resolvedRequestId, include);\n let set: ElysiaContext[\"set\"] | undefined;\n if (options.enrich != null) {\n set = { status: 200, headers: {} };\n Object.assign(\n context,\n await options.enrich({\n request,\n path: getPath(request),\n set,\n }),\n );\n }\n const responseHeader = resolvedRequestId?.responseHeader == null\n ? undefined\n : {\n name: resolvedRequestId.responseHeader,\n value: resolvedRequestId.value,\n };\n return { context, responseHeader, set };\n}\n\n/**\n * Get content length from response headers.\n */\nfunction getContentLength(\n headers: Record<string, string | undefined>,\n): string | undefined {\n const contentLength = headers[\"content-length\"];\n if (contentLength === undefined || contentLength === null) return undefined;\n return contentLength;\n}\n\n/**\n * Build structured log properties from context.\n */\nfunction buildProperties(\n ctx: ElysiaContext,\n responseTime: number,\n): RequestLogProperties {\n return {\n method: ctx.request.method,\n url: ctx.request.url,\n path: ctx.path,\n status: ctx.set.status,\n responseTime,\n contentLength: getContentLength(ctx.set.headers),\n remoteAddr: getRemoteAddr(ctx.request),\n userAgent: getUserAgent(ctx.request),\n referrer: getReferrer(ctx.request),\n };\n}\n\n/**\n * Add request context fields to a request log result.\n */\nfunction withRequestLogContext(\n result: string | Record<string, unknown>,\n context: Record<string, unknown>,\n): string | Record<string, unknown> {\n if (typeof result === \"string\") return result;\n return { ...result, ...context };\n}\n\n/**\n * Combined format (Apache Combined Log Format).\n * Returns all structured properties.\n */\nfunction formatCombined(\n ctx: ElysiaContext,\n responseTime: number,\n): Record<string, unknown> {\n return { ...buildProperties(ctx, responseTime) };\n}\n\n/**\n * Common format (Apache Common Log Format).\n * Like combined but without referrer and userAgent.\n */\nfunction formatCommon(\n ctx: ElysiaContext,\n responseTime: number,\n): Record<string, unknown> {\n const props = buildProperties(ctx, responseTime);\n const { referrer: _referrer, userAgent: _userAgent, ...rest } = props;\n return rest;\n}\n\n/**\n * Dev format (colored output for development).\n * :method :path :status :response-time ms - :res[content-length]\n */\nfunction formatDev(ctx: ElysiaContext, responseTime: number): string {\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${ctx.request.method} ${ctx.path} ${ctx.set.status} ${\n responseTime.toFixed(3)\n } ms - ${contentLength}`;\n}\n\n/**\n * Short format.\n * :remote-addr :method :url :status :res[content-length] - :response-time ms\n */\nfunction formatShort(ctx: ElysiaContext, responseTime: number): string {\n const remoteAddr = getRemoteAddr(ctx.request) ?? \"-\";\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${remoteAddr} ${ctx.request.method} ${ctx.request.url} ${ctx.set.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Tiny format (minimal output).\n * :method :path :status :res[content-length] - :response-time ms\n */\nfunction formatTiny(ctx: ElysiaContext, responseTime: number): string {\n const contentLength = getContentLength(ctx.set.headers) ?? \"-\";\n return `${ctx.request.method} ${ctx.path} ${ctx.set.status} ${contentLength} - ${\n responseTime.toFixed(3)\n } ms`;\n}\n\n/**\n * Map of predefined format functions.\n */\nconst predefinedFormats: Record<PredefinedFormat, FormatFunction> = {\n combined: formatCombined,\n common: formatCommon,\n dev: formatDev,\n short: formatShort,\n tiny: formatTiny,\n};\n\n/**\n * Normalize category to array format.\n */\nfunction normalizeCategory(\n category: string | readonly string[],\n): readonly string[] {\n return typeof category === \"string\" ? [category] : category;\n}\n\n/**\n * Mapping of Elysia error codes to HTTP status codes.\n */\nconst errorCodeToStatus: Record<string, number> = {\n NOT_FOUND: 404,\n VALIDATION: 422,\n PARSE: 400,\n INTERNAL_SERVER_ERROR: 500,\n INVALID_COOKIE_SIGNATURE: 400,\n UNKNOWN: 500,\n};\n\n/**\n * Get the HTTP status code from an error context.\n * Checks error.status first, then falls back to error code mapping.\n */\nfunction getErrorStatus(\n code: string | number,\n error: unknown,\n setStatus: number,\n): number {\n // If code is already a number, use it as status\n if (typeof code === \"number\") {\n return code;\n }\n // Check if error has a status property (Elysia custom errors)\n if (\n error != null &&\n typeof error === \"object\" &&\n \"status\" in error &&\n typeof error.status === \"number\"\n ) {\n return error.status;\n }\n // Fall back to error code mapping\n if (code in errorCodeToStatus) {\n return errorCodeToStatus[code];\n }\n // Use set.status as last resort\n return setStatus;\n}\n\n/**\n * Internal store type for timing.\n */\ninterface LoggerStore {\n startTime: number;\n}\n\ntype ElysiaRouteContext = ElysiaContext & {\n readonly store: LoggerStore;\n};\n\ntype ElysiaRouteHandler = (\n this: unknown,\n context: ElysiaRouteContext,\n) => unknown;\n\ntype ElysiaRouteRegistrar = (\n path: string,\n handler: unknown,\n hook?: unknown,\n) => unknown;\n\ntype ElysiaUseRegistrar = (\n plugin: unknown,\n ...options: unknown[]\n) => unknown;\n\ntype ElysiaRouteMethod =\n | \"all\"\n | \"connect\"\n | \"delete\"\n | \"get\"\n | \"head\"\n | \"options\"\n | \"patch\"\n | \"post\"\n | \"put\";\n\nconst elysiaRouteMethods: readonly ElysiaRouteMethod[] = [\n \"all\",\n \"connect\",\n \"delete\",\n \"get\",\n \"head\",\n \"options\",\n \"patch\",\n \"post\",\n \"put\",\n];\n\ntype ElysiaRoutePlugin = Record<ElysiaRouteMethod, ElysiaRouteRegistrar> & {\n readonly router?: {\n readonly history?: Record<string, ElysiaRouteEntry> | ElysiaRouteEntry[];\n };\n route: (\n method: string,\n path: string,\n handler: unknown,\n hook?: unknown,\n ) => unknown;\n use: ElysiaUseRegistrar;\n};\n\ninterface ElysiaRouteEntry {\n handler?: unknown;\n}\n\nfunction getElysiaRouteEntries(plugin: unknown): ElysiaRouteEntry[] {\n if (plugin == null || typeof plugin !== \"object\") return [];\n const routePlugin = plugin as {\n readonly default?: unknown;\n readonly router?: {\n readonly history?: Record<string, ElysiaRouteEntry> | ElysiaRouteEntry[];\n };\n };\n const history = routePlugin.router?.history;\n const entries = Array.isArray(history)\n ? history\n : history == null\n ? []\n : Object.values(history);\n return entries.concat(getElysiaRouteEntries(routePlugin.default));\n}\n\n/**\n * Wrap routes registered on a local plugin with implicit LogTape context.\n */\nfunction wrapLocalRouteHandlers(\n plugin: ElysiaRoutePlugin,\n buildAndStoreRequestContext: (\n request: Request,\n ) => Promise<ElysiaRequestContextState | undefined>,\n applyRequestContextToSet: (\n set: ElysiaContext[\"set\"],\n requestContext: ElysiaRequestContextState | undefined,\n ) => void,\n): void {\n const wrappedHandlers = new WeakSet<ElysiaRouteHandler>();\n const wrappedHandlerCache = new WeakMap<\n ElysiaRouteHandler,\n ElysiaRouteHandler\n >();\n const wrapHandler = (handler: unknown): unknown => {\n if (typeof handler !== \"function\") return handler;\n const routeHandler = handler as ElysiaRouteHandler;\n if (wrappedHandlers.has(routeHandler)) return handler;\n const cached = wrappedHandlerCache.get(routeHandler);\n if (cached != null) return cached;\n const wrapped = async function (\n this: unknown,\n ctx: ElysiaRouteContext,\n ): Promise<unknown> {\n const requestContext = await buildAndStoreRequestContext(ctx.request);\n ctx.store.startTime = requestContext?.startTime ??\n performance.now();\n applyRequestContextToSet(ctx.set, requestContext);\n return await withContext(\n requestContext?.context ?? {},\n () => routeHandler.call(this, ctx),\n );\n };\n wrappedHandlers.add(wrapped);\n wrappedHandlerCache.set(routeHandler, wrapped);\n return wrapped;\n };\n\n const wrapRouteEntries = (routePlugin: unknown): (() => void)[] => {\n const restore: (() => void)[] = [];\n for (const route of getElysiaRouteEntries(routePlugin)) {\n const handler = route.handler;\n const wrappedHandler = wrapHandler(handler);\n if (wrappedHandler === handler) continue;\n route.handler = wrappedHandler;\n restore.push(() => {\n route.handler = handler;\n });\n }\n return restore;\n };\n\n for (const method of elysiaRouteMethods) {\n const register = plugin[method].bind(plugin);\n plugin[method] = ((path: string, handler: unknown, hook?: unknown) =>\n register(path, wrapHandler(handler), hook)) as ElysiaRouteRegistrar;\n }\n\n const route = plugin.route.bind(plugin);\n plugin.route = ((\n method: string,\n path: string,\n handler: unknown,\n hook?: unknown,\n ) => route(method, path, wrapHandler(handler), hook)) as ElysiaRoutePlugin[\n \"route\"\n ];\n\n const use = plugin.use.bind(plugin);\n plugin.use = ((childPlugin: unknown, ...options: unknown[]) => {\n const restore = wrapRouteEntries(childPlugin);\n try {\n return use(childPlugin, ...options);\n } finally {\n for (const restoreRouteHandler of restore) restoreRouteHandler();\n }\n }) as ElysiaUseRegistrar;\n}\n\n/**\n * Creates Elysia plugin for HTTP request logging using LogTape.\n *\n * This plugin provides Morgan-compatible request logging with LogTape\n * as the backend, supporting structured logging and customizable formats.\n *\n * @example Basic usage\n * ```typescript\n * import { Elysia } from \"elysia\";\n * import { configure, getConsoleSink } from \"@logtape/logtape\";\n * import { elysiaLogger } from \"@logtape/elysia\";\n *\n * await configure({\n * sinks: { console: getConsoleSink() },\n * loggers: [\n * { category: [\"elysia\"], sinks: [\"console\"], lowestLevel: \"info\" }\n * ],\n * });\n *\n * const app = new Elysia()\n * .use(elysiaLogger())\n * .get(\"/\", () => ({ hello: \"world\" }))\n * .listen(3000);\n * ```\n *\n * @example With custom options\n * ```typescript\n * app.use(elysiaLogger({\n * category: [\"myapp\", \"http\"],\n * level: \"debug\",\n * format: \"dev\",\n * skip: (ctx) => ctx.path === \"/health\",\n * scope: \"scoped\",\n * }));\n * ```\n *\n * @example With custom format function\n * ```typescript\n * app.use(elysiaLogger({\n * format: (ctx, responseTime) => ({\n * method: ctx.request.method,\n * path: ctx.path,\n * status: ctx.set.status,\n * duration: responseTime,\n * }),\n * }));\n * ```\n *\n * @param options Configuration options for the plugin.\n * @returns Elysia plugin instance.\n * @since 2.0.0\n */\n// deno-lint-ignore no-explicit-any\nexport function elysiaLogger(options: ElysiaLogTapeOptions = {}): Elysia<any> {\n const category = normalizeCategory(options.category ?? [\"elysia\"]);\n const logger = getLogger(category);\n const level = options.level ?? \"info\";\n const formatOption = options.format ?? \"combined\";\n const skip = options.skip ?? (() => false);\n const logRequest = options.logRequest ?? false;\n const scope = options.scope ?? \"global\";\n const contextOptions = normalizeRequestContextOptions(options.context);\n const requestContextStates = new WeakMap<\n Request,\n ElysiaRequestContextState\n >();\n const shouldWrapContext = contextOptions != null;\n const shouldWrapAllRoutes = contextOptions != null && scope !== \"local\";\n\n // Resolve format function\n const formatFn: FormatFunction = typeof formatOption === \"string\"\n ? predefinedFormats[formatOption]\n : formatOption;\n\n const logMethod = logger[level].bind(logger);\n const errorLogMethod = logger.error.bind(logger);\n\n const buildAndStoreRequestContext = async (\n request: Request,\n ): Promise<ElysiaRequestContextState | undefined> => {\n if (contextOptions == null) return undefined;\n const existingContext = requestContextStates.get(request);\n if (existingContext != null) return existingContext;\n const startTime = performance.now();\n const requestContext = {\n ...await buildRequestContext(request, contextOptions),\n startTime,\n };\n requestContextStates.set(request, requestContext);\n return requestContext;\n };\n\n const applyRequestContextToSet = (\n set: ElysiaContext[\"set\"],\n requestContext: ElysiaRequestContextState | undefined,\n ): void => {\n if (requestContext?.responseHeader != null) {\n set.headers[requestContext.responseHeader.name] =\n requestContext.responseHeader.value;\n }\n if (requestContext?.set != null) {\n if (requestContext.set.status !== 200) {\n set.status = requestContext.set.status;\n }\n Object.assign(set.headers, requestContext.set.headers);\n }\n };\n\n // deno-lint-ignore no-explicit-any\n let plugin: Elysia<any, any, any, any, any, any, any> = new Elysia({\n name: \"@logtape/elysia\",\n seed: options,\n });\n\n if (shouldWrapContext && scope === \"local\") {\n wrapLocalRouteHandlers(\n plugin as unknown as ElysiaRoutePlugin,\n buildAndStoreRequestContext,\n applyRequestContextToSet,\n );\n } else if (shouldWrapContext) {\n // Elysia lifecycle hooks cannot wrap downstream handlers, so use wrap()\n // to keep AsyncLocalStorage active for the whole route execution.\n plugin = plugin.wrap((handle) => {\n return async (request: Request) => {\n const requestContext = await buildAndStoreRequestContext(request);\n return await withContext(\n requestContext?.context ?? {},\n () => handle(request),\n );\n };\n });\n }\n\n plugin = plugin\n .state(\"startTime\", 0)\n .onRequest(async ({ request, set, store }) => {\n let requestContext = requestContextStates.get(request);\n if (requestContext == null && shouldWrapAllRoutes) {\n requestContext = await buildAndStoreRequestContext(request);\n }\n (store as LoggerStore).startTime = requestContext?.startTime ??\n performance.now();\n applyRequestContextToSet(set, requestContext);\n });\n\n if (scope === \"local\" && (contextOptions != null || logRequest)) {\n plugin = plugin.onBeforeHandle(async (ctx) => {\n const requestContext = await buildAndStoreRequestContext(ctx.request);\n (ctx.store as LoggerStore).startTime = requestContext?.startTime ??\n performance.now();\n applyRequestContextToSet(ctx.set, requestContext);\n if (logRequest && !skip(ctx as unknown as ElysiaContext)) {\n const context = requestContext?.context ?? {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, 0),\n context,\n );\n if (typeof result === \"string\") {\n logMethod(result, context);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n });\n }\n\n if (logRequest) {\n // Log immediately when request arrives\n if (scope !== \"local\") {\n plugin = plugin.onRequest((ctx) => {\n if (!skip(ctx as unknown as ElysiaContext)) {\n const requestContext =\n requestContextStates.get(ctx.request)?.context ??\n {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, 0),\n requestContext,\n );\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url}\", result);\n }\n }\n });\n }\n } else {\n // Log after handler completes\n plugin = plugin.onAfterHandle((ctx) => {\n if (skip(ctx as unknown as ElysiaContext)) return;\n\n const store = ctx.store as LoggerStore;\n const responseTime = performance.now() - store.startTime;\n const requestContext = requestContextStates.get(ctx.request)?.context ??\n {};\n const result = withRequestLogContext(\n formatFn(ctx as unknown as ElysiaContext, responseTime),\n requestContext,\n );\n\n if (typeof result === \"string\") {\n logMethod(result, requestContext);\n } else {\n logMethod(\"{method} {url} {status} - {responseTime} ms\", result);\n }\n });\n }\n\n // Add error logging\n plugin = plugin.onError((ctx) => {\n const store = ctx.store as LoggerStore;\n const responseTime = performance.now() - store.startTime;\n const elysiaCtx = ctx as unknown as ElysiaContext;\n\n if (skip(elysiaCtx)) return;\n\n const props = buildProperties(elysiaCtx, responseTime);\n const requestContext = requestContextStates.get(ctx.request)?.context ?? {};\n // Get the correct HTTP status code from error context\n const status = getErrorStatus(ctx.code, ctx.error, elysiaCtx.set.status);\n // Extract error message safely\n const error = ctx.error as { message?: string } | undefined;\n const errorMessage = error?.message ?? \"Unknown error\";\n errorLogMethod(\n \"Error: {method} {url} {status} - {responseTime} ms - {errorMessage}\",\n {\n ...props,\n ...requestContext,\n status,\n errorMessage,\n errorCode: ctx.code,\n },\n );\n });\n\n // Apply scope\n if (scope === \"global\") {\n // deno-lint-ignore no-explicit-any\n return plugin.as(\"global\") as unknown as Elysia<any>;\n } else if (scope === \"scoped\") {\n // deno-lint-ignore no-explicit-any\n return plugin.as(\"scoped\") as unknown as Elysia<any>;\n }\n\n // deno-lint-ignore no-explicit-any\n return plugin as unknown as Elysia<any>;\n}\n"],"mappings":";;;;AAkOA,MAAM,yBAAyB;;;;AAkB/B,SAAS,+BACPA,SACmC;AACnC,KAAI,YAAY,KAAM,QAAO,CAAE;AAC/B,KAAI,YAAY,SAAS,WAAW,KAAM;AAC1C,QAAO;AACR;;;;AAKD,SAAS,0BACPC,SAC8B;AAC9B,KAAI,YAAY,MAAO;AACvB,KAAI,YAAY,QAAQ,WAAW,KAAM,QAAO,CAAE;AAClD,QAAO;AACR;;;;AAKD,SAAS,oBAA4B;AACnC,YAAW,WAAW,QAAQ,eAAe,WAC3C,QAAO,WAAW,OAAO,YAAY;AAEvC,SAAQ,EAAE,KAAK,KAAK,CAAC,SAAS,GAAG,CAAC,GAAG,KAAK,QAAQ,CAAC,SAAS,GAAG,CAAC,MAAM,EAAE,CAAC;AAC1E;;;;AAKD,SAAS,0BAA0BC,OAA8B;CAC/D,MAAM,UAAU,MAAM,MAAM;AAC5B,QAAO,YAAY,KAAK,OAAO;AAChC;;;;AAKD,SAAS,QAAQC,SAA0B;AACzC,QAAO,IAAI,IAAI,QAAQ,KAAK,oBAAoB;AACjD;;;;AAKD,SAAS,iBACPA,SACAC,SAKA;CACA,MAAM,WAAW,QAAQ,YAAY;CACrC,MAAM,YAAY,QAAQ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/B,MAAM,QAAQ,IAAI;EAClB,MAAM,eAAe,YAAY,KAAK,GAAG,MAAM;EAC/C,MAAM,YAAY;AAElB,MAAI,KAAK,UAAU,CAAE;EAErB,MAAM,QAAQ,gBAAgB,WAAW,aAAa;EACtD,MAAM,iBAAiB,qBAAqB,IAAI,IAAI,QAAQ,EAAE,WAAW,CAAE;EAE3E,MAAM,SAAS,eAAe,IAAI,MAAM,IAAI,OAAO,UAAU,IAAI,OAAO;EAExE,MAAM,QAAQ,IAAI;EAClB,MAAM,eAAe,OAAO,WAAW;AACvC,iBACE,uEACA;GACE,GAAG;GACH,GAAG;GACH;GACA;GACA,WAAW,IAAI;EAChB,EACF;CACF,EAAC;AAGF,KAAI,UAAU,SAEZ,QAAO,OAAO,GAAG,SAAS;UACjB,UAAU,SAEnB,QAAO,OAAO,GAAG,SAAS;AAI5B,QAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/elysia",
3
- "version": "2.2.0-dev.696+d5e33229",
3
+ "version": "2.2.0-dev.700+748dd292",
4
4
  "description": "Elysia adapter for LogTape logging library",
5
5
  "keywords": [
6
6
  "logging",
@@ -54,7 +54,7 @@
54
54
  ],
55
55
  "peerDependencies": {
56
56
  "elysia": "^1.4.0",
57
- "@logtape/logtape": "^2.2.0-dev.696+d5e33229"
57
+ "@logtape/logtape": "^2.2.0-dev.700+748dd292"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@alinea/suite": "^0.6.3",