logixlysia 6.9.3 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -110,6 +110,8 @@ type RequestInfo = Request;
110
110
  type LogLevel = "DEBUG" | "INFO" | "WARNING" | "ERROR";
111
111
  interface StoreData {
112
112
  beforeTime: bigint;
113
+ /** The status the client received, when the caller resolved it. `handleHttpError` prefers it over the thrown value. */
114
+ status?: number;
113
115
  }
114
116
  interface LogixlysiaStore {
115
117
  beforeTime?: bigint;
@@ -242,7 +244,7 @@ type LogPreset = "dev" | "prod" | "json";
242
244
  /** Context passed to {@link Options.config.onError} when a sink fails. */
243
245
  interface SinkErrorContext {
244
246
  error: unknown;
245
- sink: "enricher" | "file" | "rotation" | "shutdown" | "transport";
247
+ sink: "enricher" | "file" | "format" | "rotation" | "shutdown" | "transport";
246
248
  }
247
249
  interface RequestIdConfig {
248
250
  /**
@@ -312,9 +314,11 @@ interface OutputConfig {
312
314
  logFilePath?: string;
313
315
  logRotation?: LogRotationConfig;
314
316
  /**
315
- * Called when a sink (transport, file, rotation) or an enricher fails.
316
- * Errors thrown by the hook itself are swallowed. When absent, failures go
317
- * to stderr (rate-limited for transports and enrichers).
317
+ * Called when a sink (transport, file, rotation) or an enricher fails, or
318
+ * when building or printing a log record fails (`sink: 'format'`). Errors
319
+ * thrown by the hook itself are swallowed. When absent, failures go to
320
+ * stderr (rate-limited for transports, file writes, rotation, enrichers
321
+ * and formatting).
318
322
  */
319
323
  onError?: (context: SinkErrorContext) => void;
320
324
  transports?: Transport[];
@@ -372,7 +376,8 @@ interface RequestTrackingConfig {
372
376
  requestId?: boolean | RequestIdConfig;
373
377
  /**
374
378
  * Enable request-scoped logger propagation via AsyncLocalStorage.
375
- * When enabled, a request-scoped logger `log` is also derived on the Elysia context.
379
+ * When enabled, `useLogger()` returns the current request's logger anywhere in the request's async call chain.
380
+ * The handler context's `log` is available either way.
376
381
  * @default false
377
382
  */
378
383
  useAsyncLocalStorage?: boolean;
@@ -420,14 +425,15 @@ interface WebSocketLike {
420
425
  };
421
426
  };
422
427
  readonly id?: string;
428
+ readonly raw?: object;
423
429
  }
424
430
  interface WsHandlerHooks<
425
431
  TMessage = unknown,
426
432
  TWs extends WebSocketLike = WebSocketLike
427
433
  > {
428
- close?: (ws: TWs, code?: number, reason?: string) => void;
429
- message?: (ws: TWs, message: TMessage) => void;
430
- open?: (ws: TWs) => void;
434
+ close?: (ws: TWs, code?: number, reason?: string) => unknown;
435
+ message?: (ws: TWs, message: TMessage) => unknown;
436
+ open?: (ws: TWs) => unknown;
431
437
  }
432
438
  declare const createWsHandlerWrapper: (options: Options, logger: Logger, contextStore: RequestContextStore) => <
433
439
  TMessage,
@@ -451,6 +457,7 @@ interface ResolvedRequestIdConfig {
451
457
  enabled: boolean;
452
458
  generator: () => string;
453
459
  header: string;
460
+ onError?: (context: SinkErrorContext) => void;
454
461
  }
455
462
  /**
456
463
  * Normalises the `requestId` option into a concrete config object.
@@ -459,7 +466,7 @@ interface ResolvedRequestIdConfig {
459
466
  * - `true` → default config
460
467
  * - `RequestIdConfig` → merged with defaults; `enabled: false` inside the object disables the feature
461
468
  */
462
- declare const resolveRequestIdConfig: (raw?: boolean | RequestIdConfig) => ResolvedRequestIdConfig | null;
469
+ declare const resolveRequestIdConfig: (raw?: boolean | RequestIdConfig, onError?: (context: SinkErrorContext) => void) => ResolvedRequestIdConfig | null;
463
470
  /**
464
471
  * Reads an existing request ID from the incoming request header, or generates a
465
472
  * new one using the configured generator.
@@ -468,6 +475,10 @@ declare const resolveRequestIdConfig: (raw?: boolean | RequestIdConfig) => Resol
468
475
  * `.`, `_`, `-`, 1-128 chars) before being trusted — request IDs flow into log
469
476
  * lines, response headers, and context trees, so malformed or oversized
470
477
  * values are replaced with a freshly generated one rather than echoed back.
478
+ *
479
+ * Generated values must pass the same check. This runs in `onRequest`, where
480
+ * a throw would log an error for every request, so a generator that throws
481
+ * or returns an invalid id is reported and replaced with a random UUID.
471
482
  */
472
483
  declare const getOrCreateRequestId: (request: Request, config: ResolvedRequestIdConfig) => string;
473
484
  /**
@@ -550,4 +561,4 @@ declare const flushLogixlysia: (options: Options, { close }?: {
550
561
  close?: boolean;
551
562
  }) => Promise<void>;
552
563
  declare const logixlysia: typeof createLogixlysiaPlugin;
553
- export { useLogger, resolveSampling, resolveRequestIdConfig, resolveOptions, logixlysia, getOrCreateRequestId, flushLogixlysia, createLogixlysiaPlugin as default, createWsHandlerWrapper, createPluginLogger, createLogger, WsHandlerHooks, Transport, TailSamplingConfig, StoreData, SamplingRuntime, SamplingDecision, SamplingConfig, ResolvedRequestIdConfig, RequestScopedLogger, RequestOutcome, RequestIdConfig, Pino, Options, LogixlysiaStore, LogixlysiaSingleton, LogixlysiaPlugin, LogixlysiaContext, Logixlysia, Logger, LogPreset, LogLevel, LogFields, HttpErrorPayload, HttpErrorInit, HttpError, HeadSamplingConfig, EnricherResponseInput, EnricherLike, EnricherFields, Enricher, EmptyElysiaSlot };
564
+ export { useLogger, resolveSampling, resolveRequestIdConfig, resolveOptions, logixlysia, getOrCreateRequestId, flushLogixlysia, createLogixlysiaPlugin as default, createWsHandlerWrapper, createPluginLogger, createLogger, WsHandlerHooks, WebSocketLike, Transport, TailSamplingConfig, StoreData, SinkErrorContext, SamplingRuntime, SamplingDecision, SamplingConfig, ResolvedRequestIdConfig, RequestScopedLogger, RequestOutcome, RequestIdConfig, Pino, Options, LogixlysiaStore, LogixlysiaSingleton, LogixlysiaPlugin, LogixlysiaContext, LogixlysiaConfig, Logixlysia, Logger, LogRotationConfig, LogPreset, LogLevel, LogFilter, LogFields, HttpErrorPayload, HttpErrorInit, HttpError, HeadSamplingConfig, EnricherResponseInput, EnricherLike, EnricherFields, Enricher, EmptyElysiaSlot };