@pori15/logixlysia 6.0.1 → 6.0.3

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
@@ -36,10 +36,87 @@ declare class ProblemError extends Error {
36
36
  constructor(type: string | undefined, title: string, status: number, detail?: string, instance?: string, extensions?: Record<string, unknown>);
37
37
  toJSON(): ProblemDocument;
38
38
  }
39
- declare const HttpError: {};
39
+ declare class BadRequest extends ProblemError {
40
+ constructor(detail?: string, extensions?: Record<string, any>);
41
+ }
42
+ declare class Unauthorized extends ProblemError {
43
+ constructor(detail?: string, extensions?: Record<string, any>);
44
+ }
45
+ declare class Forbidden extends ProblemError {
46
+ constructor(detail?: string, extensions?: Record<string, any>);
47
+ }
48
+ declare class NotFound extends ProblemError {
49
+ constructor(detail?: string, extensions?: Record<string, any>);
50
+ }
51
+ declare class Conflict extends ProblemError {
52
+ constructor(detail?: string, extensions?: Record<string, any>);
53
+ }
54
+ declare class PaymentRequired extends ProblemError {
55
+ constructor(detail?: string, extensions?: Record<string, any>);
56
+ }
57
+ declare class MethodNotAllowed extends ProblemError {
58
+ constructor(detail?: string, extensions?: Record<string, any>);
59
+ }
60
+ declare class NotAcceptable extends ProblemError {
61
+ constructor(detail?: string, extensions?: Record<string, any>);
62
+ }
63
+ declare class InternalServerError extends ProblemError {
64
+ constructor(detail?: string, extensions?: Record<string, any>);
65
+ }
66
+ declare class NotImplemented extends ProblemError {
67
+ constructor(detail?: string, extensions?: Record<string, any>);
68
+ }
69
+ declare class BadGateway extends ProblemError {
70
+ constructor(detail?: string, extensions?: Record<string, any>);
71
+ }
72
+ declare class ServiceUnavailable extends ProblemError {
73
+ constructor(detail?: string, extensions?: Record<string, any>);
74
+ }
75
+ declare class GatewayTimeout extends ProblemError {
76
+ constructor(detail?: string, extensions?: Record<string, any>);
77
+ }
78
+ interface HttpErrorConstructor {
79
+ BadRequest: typeof BadRequest;
80
+ Unauthorized: typeof Unauthorized;
81
+ PaymentRequired: typeof PaymentRequired;
82
+ Forbidden: typeof Forbidden;
83
+ NotFound: typeof NotFound;
84
+ MethodNotAllowed: typeof MethodNotAllowed;
85
+ NotAcceptable: typeof NotAcceptable;
86
+ Conflict: typeof Conflict;
87
+ InternalServerError: typeof InternalServerError;
88
+ NotImplemented: typeof NotImplemented;
89
+ BadGateway: typeof BadGateway;
90
+ ServiceUnavailable: typeof ServiceUnavailable;
91
+ GatewayTimeout: typeof GatewayTimeout;
92
+ }
93
+ declare const HttpError: HttpErrorConstructor;
40
94
  type Code = number | "PROBLEM_ERROR" | "UNKNOWN" | "VALIDATION" | "NOT_FOUND" | "PARSE" | "INTERNAL_SERVER_ERROR" | "INVALID_COOKIE_SIGNATURE" | "INVALID_FILE_TYPE";
95
+ interface ErrorContext {
96
+ request: Request;
97
+ path: string;
98
+ code: string | number;
99
+ error: unknown;
100
+ }
101
+ interface HttpProblemJsonOptions {
102
+ /**
103
+ * 自定义错误类型的 Base URL
104
+ * @example "https://api.mysite.com/errors"
105
+ */
106
+ typeBaseUrl?: string;
107
+ /**
108
+ * 🪝 Transform Hook
109
+ * 将未知错误转换为 HttpError。
110
+ * 返回 undefined/null 表示不处理(走默认逻辑)。
111
+ */
112
+ transform?: (error: unknown, context: ErrorContext) => ProblemError | undefined | null;
113
+ /**
114
+ * 📢 Listen Hook
115
+ * 在响应发送前触发(用于日志)。
116
+ */
117
+ onBeforeRespond?: (problem: ProblemError, context: ErrorContext) => void | Promise<void>;
118
+ }
41
119
  type Pino = PinoLogger<never, boolean>;
42
- type Request2 = Request2;
43
120
  type LogLevel = "DEBUG" | "INFO" | "WARNING" | "ERROR";
44
121
  interface StoreData {
45
122
  beforeTime: bigint;
@@ -103,23 +180,25 @@ interface Options {
103
180
  };
104
181
  };
105
182
  transform?: (error: unknown, context: {
106
- request: Request2;
183
+ request: Request;
107
184
  code: Code;
185
+ path: string;
108
186
  }) => ProblemError | unknown;
109
187
  }
110
188
  interface Logger {
111
189
  pino: Pino;
112
- log: (level: LogLevel, request: Request2, data: Record<string, unknown>, store: StoreData) => void;
113
- handleHttpError: (request: Request2, error: ProblemError, store: StoreData, options: Options) => void;
114
- debug: (request: Request2, message: string, context?: Record<string, unknown>) => void;
115
- info: (request: Request2, message: string, context?: Record<string, unknown>) => void;
116
- warn: (request: Request2, message: string, context?: Record<string, unknown>) => void;
117
- error: (request: Request2, message: string, context?: Record<string, unknown>) => void;
190
+ log: (level: LogLevel, request: Request, data: Record<string, unknown>, store: StoreData) => void;
191
+ handleHttpError: (request: Request, error: ProblemError, store: StoreData, options: Options) => void;
192
+ debug: (request: Request, message: string, context?: Record<string, unknown>) => void;
193
+ info: (request: Request, message: string, context?: Record<string, unknown>) => void;
194
+ warn: (request: Request, message: string, context?: Record<string, unknown>) => void;
195
+ error: (request: Request, message: string, context?: Record<string, unknown>) => void;
118
196
  }
119
197
  interface LogixlysiaContext {
120
- request: Request2;
198
+ request: Request;
121
199
  store: LogixlysiaStore;
122
200
  }
201
+ declare const normalizeToProblem: (error: any, code: Code, path: string, typeBaseUrl?: string) => ProblemError;
123
202
  interface ProblemJson {
124
203
  type?: string;
125
204
  title: string;
@@ -156,4 +235,4 @@ type Logixlysia = Elysia<"Logixlysia", SingletonBase & {
156
235
  store: LogixlysiaStore;
157
236
  }>;
158
237
  declare const logixlysia: (options?: Options) => Logixlysia;
159
- export { toProblemJson, logixlysia, formatProblemJsonLog, logixlysia as default, Transport, StoreData, ProblemJson, Pino, Options, LogixlysiaStore, LogixlysiaContext, Logixlysia, Logger, LogLevel, HttpError };
238
+ export { toProblemJson, normalizeToProblem, logixlysia, formatProblemJsonLog, logixlysia as default, Transport, StoreData, ProblemJsonOptions, ProblemJson, ProblemError, ProblemDocument, Pino, Options, LogixlysiaStore, LogixlysiaContext, Logixlysia, Logger, LogLevel, HttpProblemJsonOptions, HttpErrorConstructor, HttpError, ErrorContext, Code };