@zero-server/sdk 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +460 -437
  3. package/index.js +414 -412
  4. package/lib/app.js +1172 -1172
  5. package/lib/auth/authorize.js +399 -399
  6. package/lib/auth/enrollment.js +367 -367
  7. package/lib/auth/index.js +57 -57
  8. package/lib/auth/jwt.js +731 -731
  9. package/lib/auth/oauth.js +362 -362
  10. package/lib/auth/session.js +588 -588
  11. package/lib/auth/trustedDevice.js +409 -409
  12. package/lib/auth/twoFactor.js +1150 -1150
  13. package/lib/auth/webauthn.js +946 -946
  14. package/lib/body/index.js +14 -14
  15. package/lib/body/json.js +109 -109
  16. package/lib/body/multipart.js +440 -440
  17. package/lib/body/raw.js +71 -71
  18. package/lib/body/rawBuffer.js +160 -160
  19. package/lib/body/sendError.js +25 -25
  20. package/lib/body/text.js +75 -75
  21. package/lib/body/typeMatch.js +41 -41
  22. package/lib/body/urlencoded.js +235 -235
  23. package/lib/cli.js +845 -845
  24. package/lib/cluster.js +666 -666
  25. package/lib/debug.js +372 -372
  26. package/lib/env/index.js +460 -460
  27. package/lib/errors.js +683 -683
  28. package/lib/fetch/index.js +256 -256
  29. package/lib/grpc/balancer.js +378 -378
  30. package/lib/grpc/call.js +708 -708
  31. package/lib/grpc/client.js +764 -764
  32. package/lib/grpc/codec.js +1221 -1221
  33. package/lib/grpc/credentials.js +398 -398
  34. package/lib/grpc/frame.js +262 -262
  35. package/lib/grpc/health.js +287 -287
  36. package/lib/grpc/index.js +121 -121
  37. package/lib/grpc/metadata.js +461 -461
  38. package/lib/grpc/proto.js +821 -821
  39. package/lib/grpc/reflection.js +590 -590
  40. package/lib/grpc/server.js +445 -445
  41. package/lib/grpc/status.js +118 -118
  42. package/lib/grpc/watch.js +173 -173
  43. package/lib/http/index.js +10 -10
  44. package/lib/http/request.js +727 -727
  45. package/lib/http/response.js +799 -799
  46. package/lib/lifecycle.js +557 -557
  47. package/lib/middleware/compress.js +230 -230
  48. package/lib/middleware/cookieParser.js +237 -237
  49. package/lib/middleware/cors.js +93 -93
  50. package/lib/middleware/csrf.js +136 -136
  51. package/lib/middleware/errorHandler.js +101 -101
  52. package/lib/middleware/helmet.js +175 -175
  53. package/lib/middleware/index.js +19 -17
  54. package/lib/middleware/logger.js +74 -74
  55. package/lib/middleware/rateLimit.js +88 -88
  56. package/lib/middleware/requestId.js +53 -53
  57. package/lib/middleware/static.js +326 -326
  58. package/lib/middleware/timeout.js +71 -71
  59. package/lib/middleware/validator.js +254 -254
  60. package/lib/observe/health.js +326 -326
  61. package/lib/observe/index.js +50 -50
  62. package/lib/observe/logger.js +359 -359
  63. package/lib/observe/metrics.js +805 -805
  64. package/lib/observe/tracing.js +592 -592
  65. package/lib/orm/adapters/json.js +290 -290
  66. package/lib/orm/adapters/memory.js +764 -764
  67. package/lib/orm/adapters/mongo.js +764 -764
  68. package/lib/orm/adapters/mysql.js +933 -933
  69. package/lib/orm/adapters/postgres.js +1144 -1144
  70. package/lib/orm/adapters/redis.js +1534 -1534
  71. package/lib/orm/adapters/sql-base.js +212 -212
  72. package/lib/orm/adapters/sqlite.js +858 -858
  73. package/lib/orm/audit.js +649 -649
  74. package/lib/orm/cache.js +394 -394
  75. package/lib/orm/geo.js +387 -387
  76. package/lib/orm/index.js +784 -784
  77. package/lib/orm/migrate.js +432 -432
  78. package/lib/orm/model.js +1706 -1706
  79. package/lib/orm/plugin.js +375 -375
  80. package/lib/orm/procedures.js +836 -836
  81. package/lib/orm/profiler.js +233 -233
  82. package/lib/orm/query.js +1772 -1772
  83. package/lib/orm/replicas.js +241 -241
  84. package/lib/orm/schema.js +307 -307
  85. package/lib/orm/search.js +380 -380
  86. package/lib/orm/seed/data/commerce.js +136 -136
  87. package/lib/orm/seed/data/internet.js +111 -111
  88. package/lib/orm/seed/data/locations.js +204 -204
  89. package/lib/orm/seed/data/names.js +338 -338
  90. package/lib/orm/seed/data/person.js +128 -128
  91. package/lib/orm/seed/data/phone.js +211 -211
  92. package/lib/orm/seed/data/words.js +134 -134
  93. package/lib/orm/seed/factory.js +178 -178
  94. package/lib/orm/seed/fake.js +1186 -1186
  95. package/lib/orm/seed/index.js +18 -18
  96. package/lib/orm/seed/rng.js +70 -70
  97. package/lib/orm/seed/seeder.js +124 -124
  98. package/lib/orm/seed/unique.js +68 -68
  99. package/lib/orm/snapshot.js +366 -366
  100. package/lib/orm/tenancy.js +605 -605
  101. package/lib/orm/views.js +350 -350
  102. package/lib/router/index.js +436 -436
  103. package/lib/sse/index.js +8 -8
  104. package/lib/sse/stream.js +349 -349
  105. package/lib/ws/connection.js +451 -451
  106. package/lib/ws/handshake.js +125 -125
  107. package/lib/ws/index.js +14 -14
  108. package/lib/ws/room.js +223 -223
  109. package/package.json +73 -73
  110. package/types/app.d.ts +223 -223
  111. package/types/auth.d.ts +520 -520
  112. package/types/cluster.d.ts +75 -75
  113. package/types/env.d.ts +80 -80
  114. package/types/errors.d.ts +316 -316
  115. package/types/fetch.d.ts +43 -43
  116. package/types/grpc.d.ts +432 -432
  117. package/types/index.d.ts +384 -384
  118. package/types/lifecycle.d.ts +60 -60
  119. package/types/middleware.d.ts +320 -320
  120. package/types/observe.d.ts +304 -304
  121. package/types/orm.d.ts +1887 -1887
  122. package/types/request.d.ts +109 -109
  123. package/types/response.d.ts +157 -157
  124. package/types/router.d.ts +78 -78
  125. package/types/sse.d.ts +78 -78
  126. package/types/websocket.d.ts +126 -126
package/types/errors.d.ts CHANGED
@@ -1,316 +1,316 @@
1
- // --- Error Classes -----------------------------------------------
2
-
3
- export interface HttpErrorOptions {
4
- code?: string;
5
- details?: any;
6
- }
7
-
8
- export class HttpError extends Error {
9
- readonly statusCode: number;
10
- readonly code: string;
11
- readonly name: string;
12
- details?: any;
13
- constructor(statusCode: number, message?: string, opts?: HttpErrorOptions);
14
- toJSON(): { error: string; code: string; statusCode: number; details?: any };
15
- }
16
-
17
- export class BadRequestError extends HttpError {
18
- constructor(message?: string, opts?: HttpErrorOptions);
19
- }
20
-
21
- export class UnauthorizedError extends HttpError {
22
- constructor(message?: string, opts?: HttpErrorOptions);
23
- }
24
-
25
- export class ForbiddenError extends HttpError {
26
- constructor(message?: string, opts?: HttpErrorOptions);
27
- }
28
-
29
- export class NotFoundError extends HttpError {
30
- constructor(message?: string, opts?: HttpErrorOptions);
31
- }
32
-
33
- export class MethodNotAllowedError extends HttpError {
34
- constructor(message?: string, opts?: HttpErrorOptions);
35
- }
36
-
37
- export class ConflictError extends HttpError {
38
- constructor(message?: string, opts?: HttpErrorOptions);
39
- }
40
-
41
- export class GoneError extends HttpError {
42
- constructor(message?: string, opts?: HttpErrorOptions);
43
- }
44
-
45
- export class PayloadTooLargeError extends HttpError {
46
- constructor(message?: string, opts?: HttpErrorOptions);
47
- }
48
-
49
- export class UnprocessableEntityError extends HttpError {
50
- constructor(message?: string, opts?: HttpErrorOptions);
51
- }
52
-
53
- export class ValidationError extends HttpError {
54
- readonly errors: Record<string, string> | string[];
55
- constructor(message?: string, errors?: Record<string, string> | string[], opts?: HttpErrorOptions);
56
- }
57
-
58
- export class TooManyRequestsError extends HttpError {
59
- constructor(message?: string, opts?: HttpErrorOptions);
60
- }
61
-
62
- export class InternalError extends HttpError {
63
- constructor(message?: string, opts?: HttpErrorOptions);
64
- }
65
-
66
- export class NotImplementedError extends HttpError {
67
- constructor(message?: string, opts?: HttpErrorOptions);
68
- }
69
-
70
- export class BadGatewayError extends HttpError {
71
- constructor(message?: string, opts?: HttpErrorOptions);
72
- }
73
-
74
- export class ServiceUnavailableError extends HttpError {
75
- constructor(message?: string, opts?: HttpErrorOptions);
76
- }
77
-
78
- // --- Framework Error Classes -------------------------------------
79
-
80
- export interface DatabaseErrorOptions extends HttpErrorOptions {
81
- query?: string;
82
- adapter?: string;
83
- }
84
-
85
- export class DatabaseError extends HttpError {
86
- readonly query?: string;
87
- readonly adapter?: string;
88
- constructor(message?: string, opts?: DatabaseErrorOptions);
89
- }
90
-
91
- export interface ConfigurationErrorOptions extends HttpErrorOptions {
92
- setting?: string;
93
- }
94
-
95
- export class ConfigurationError extends HttpError {
96
- readonly setting?: string;
97
- constructor(message?: string, opts?: ConfigurationErrorOptions);
98
- }
99
-
100
- export interface MiddlewareErrorOptions extends HttpErrorOptions {
101
- middleware?: string;
102
- }
103
-
104
- export class MiddlewareError extends HttpError {
105
- readonly middleware?: string;
106
- constructor(message?: string, opts?: MiddlewareErrorOptions);
107
- }
108
-
109
- export interface RoutingErrorOptions extends HttpErrorOptions {
110
- path?: string;
111
- method?: string;
112
- }
113
-
114
- export class RoutingError extends HttpError {
115
- readonly path?: string;
116
- readonly method?: string;
117
- constructor(message?: string, opts?: RoutingErrorOptions);
118
- }
119
-
120
- export interface TimeoutErrorOptions extends HttpErrorOptions {
121
- timeout?: number;
122
- }
123
-
124
- export class TimeoutError extends HttpError {
125
- readonly timeout?: number;
126
- constructor(message?: string, opts?: TimeoutErrorOptions);
127
- }
128
-
129
- export function createError(statusCode: number, message?: string, opts?: HttpErrorOptions): HttpError;
130
- export function isHttpError(err: any): err is HttpError;
131
-
132
- // --- ORM Error Classes -------------------------------------------
133
-
134
- export interface ConnectionErrorOptions extends DatabaseErrorOptions {
135
- attempt?: number;
136
- maxRetries?: number;
137
- host?: string;
138
- port?: number;
139
- }
140
-
141
- export class ConnectionError extends DatabaseError {
142
- readonly attempt?: number;
143
- readonly maxRetries?: number;
144
- readonly host?: string;
145
- readonly port?: number;
146
- constructor(message?: string, opts?: ConnectionErrorOptions);
147
- }
148
-
149
- export interface MigrationErrorOptions extends DatabaseErrorOptions {
150
- migration?: string;
151
- direction?: 'up' | 'down';
152
- batch?: number;
153
- }
154
-
155
- export class MigrationError extends DatabaseError {
156
- readonly migration?: string;
157
- readonly direction?: 'up' | 'down';
158
- readonly batch?: number;
159
- constructor(message?: string, opts?: MigrationErrorOptions);
160
- }
161
-
162
- export interface TransactionErrorOptions extends DatabaseErrorOptions {
163
- phase?: 'begin' | 'commit' | 'rollback';
164
- }
165
-
166
- export class TransactionError extends DatabaseError {
167
- readonly phase?: 'begin' | 'commit' | 'rollback';
168
- constructor(message?: string, opts?: TransactionErrorOptions);
169
- }
170
-
171
- export interface QueryErrorOptions extends DatabaseErrorOptions {
172
- sql?: string;
173
- params?: any[];
174
- table?: string;
175
- }
176
-
177
- export class QueryError extends DatabaseError {
178
- readonly sql?: string;
179
- readonly params?: any[];
180
- readonly table?: string;
181
- constructor(message?: string, opts?: QueryErrorOptions);
182
- }
183
-
184
- export interface AdapterErrorOptions extends DatabaseErrorOptions {
185
- operation?: string;
186
- }
187
-
188
- export class AdapterError extends DatabaseError {
189
- readonly operation?: string;
190
- constructor(message?: string, opts?: AdapterErrorOptions);
191
- }
192
-
193
- export interface CacheErrorOptions extends HttpErrorOptions {
194
- operation?: string;
195
- key?: string;
196
- }
197
-
198
- export class CacheError extends HttpError {
199
- readonly operation?: string;
200
- readonly key?: string;
201
- constructor(message?: string, opts?: CacheErrorOptions);
202
- }
203
-
204
- // --- Phase 4 Error Classes ------------------------------------------
205
-
206
- export interface TenancyErrorOptions extends DatabaseErrorOptions {
207
- tenant?: string;
208
- strategy?: string;
209
- }
210
-
211
- export class TenancyError extends DatabaseError {
212
- readonly tenant?: string;
213
- readonly strategy?: string;
214
- constructor(message?: string, opts?: TenancyErrorOptions);
215
- }
216
-
217
- export interface AuditErrorOptions extends DatabaseErrorOptions {
218
- action?: string;
219
- table?: string;
220
- }
221
-
222
- export class AuditError extends DatabaseError {
223
- readonly action?: string;
224
- readonly table?: string;
225
- constructor(message?: string, opts?: AuditErrorOptions);
226
- }
227
-
228
- export interface PluginErrorOptions extends HttpErrorOptions {
229
- plugin?: string;
230
- phase?: string;
231
- }
232
-
233
- export class PluginError extends HttpError {
234
- readonly plugin?: string;
235
- readonly phase?: string;
236
- constructor(message?: string, opts?: PluginErrorOptions);
237
- }
238
-
239
- export interface ProcedureErrorOptions extends DatabaseErrorOptions {
240
- procedure?: string;
241
- operation?: string;
242
- }
243
-
244
- export class ProcedureError extends DatabaseError {
245
- readonly procedure?: string;
246
- readonly operation?: string;
247
- constructor(message?: string, opts?: ProcedureErrorOptions);
248
- }
249
-
250
- // --- Error Handler Middleware ------------------------------------
251
-
252
- import { Request } from './request';
253
- import { Response } from './response';
254
-
255
- export interface ErrorHandlerOptions {
256
- /** Include stack traces in responses (default: true when NODE_ENV !== 'production'). */
257
- stack?: boolean;
258
- /** Log errors to console (default: true). */
259
- log?: boolean;
260
- /** Custom log function (default: console.error). */
261
- logger?: (...args: any[]) => void;
262
- /** Custom response formatter: (err, req, isDev) => responseBody. */
263
- formatter?: (err: Error, req: Request, isDev: boolean) => any;
264
- /** Callback on every error. */
265
- onError?: (err: Error, req: Request, res: Response) => void;
266
- }
267
-
268
- export function errorHandler(opts?: ErrorHandlerOptions): (err: any, req: Request, res: Response, next: (err?: any) => void) => void;
269
-
270
- // --- Debug Logger ------------------------------------------------
271
-
272
- export interface DebugLogger {
273
- (...args: any[]): void;
274
- trace(...args: any[]): void;
275
- debug(...args: any[]): void;
276
- info(...args: any[]): void;
277
- warn(...args: any[]): void;
278
- error(...args: any[]): void;
279
- fatal(...args: any[]): void;
280
- readonly enabled: boolean;
281
- readonly namespace: string;
282
- }
283
-
284
- export interface DebugLevels {
285
- trace: 0;
286
- debug: 1;
287
- info: 2;
288
- warn: 3;
289
- error: 4;
290
- fatal: 5;
291
- silent: 6;
292
- }
293
-
294
- export interface Debug {
295
- (namespace: string): DebugLogger;
296
- /** Set minimum log level globally. */
297
- level(level: keyof DebugLevels | number): void;
298
- /** Enable/disable namespaces (same syntax as DEBUG env var). */
299
- enable(patterns: string): void;
300
- /** Disable all debug output. */
301
- disable(): void;
302
- /** Enable structured JSON output. */
303
- json(on?: boolean): void;
304
- /** Enable/disable timestamps. */
305
- timestamps(on?: boolean): void;
306
- /** Enable/disable colors. */
307
- colors(on?: boolean): void;
308
- /** Set custom output stream. */
309
- output(stream: { write(s: string): void }): void;
310
- /** Reset all settings to defaults. */
311
- reset(): void;
312
- /** Level constants. */
313
- readonly LEVELS: DebugLevels;
314
- }
315
-
316
- export const debug: Debug;
1
+ // --- Error Classes -----------------------------------------------
2
+
3
+ export interface HttpErrorOptions {
4
+ code?: string;
5
+ details?: any;
6
+ }
7
+
8
+ export class HttpError extends Error {
9
+ readonly statusCode: number;
10
+ readonly code: string;
11
+ readonly name: string;
12
+ details?: any;
13
+ constructor(statusCode: number, message?: string, opts?: HttpErrorOptions);
14
+ toJSON(): { error: string; code: string; statusCode: number; details?: any };
15
+ }
16
+
17
+ export class BadRequestError extends HttpError {
18
+ constructor(message?: string, opts?: HttpErrorOptions);
19
+ }
20
+
21
+ export class UnauthorizedError extends HttpError {
22
+ constructor(message?: string, opts?: HttpErrorOptions);
23
+ }
24
+
25
+ export class ForbiddenError extends HttpError {
26
+ constructor(message?: string, opts?: HttpErrorOptions);
27
+ }
28
+
29
+ export class NotFoundError extends HttpError {
30
+ constructor(message?: string, opts?: HttpErrorOptions);
31
+ }
32
+
33
+ export class MethodNotAllowedError extends HttpError {
34
+ constructor(message?: string, opts?: HttpErrorOptions);
35
+ }
36
+
37
+ export class ConflictError extends HttpError {
38
+ constructor(message?: string, opts?: HttpErrorOptions);
39
+ }
40
+
41
+ export class GoneError extends HttpError {
42
+ constructor(message?: string, opts?: HttpErrorOptions);
43
+ }
44
+
45
+ export class PayloadTooLargeError extends HttpError {
46
+ constructor(message?: string, opts?: HttpErrorOptions);
47
+ }
48
+
49
+ export class UnprocessableEntityError extends HttpError {
50
+ constructor(message?: string, opts?: HttpErrorOptions);
51
+ }
52
+
53
+ export class ValidationError extends HttpError {
54
+ readonly errors: Record<string, string> | string[];
55
+ constructor(message?: string, errors?: Record<string, string> | string[], opts?: HttpErrorOptions);
56
+ }
57
+
58
+ export class TooManyRequestsError extends HttpError {
59
+ constructor(message?: string, opts?: HttpErrorOptions);
60
+ }
61
+
62
+ export class InternalError extends HttpError {
63
+ constructor(message?: string, opts?: HttpErrorOptions);
64
+ }
65
+
66
+ export class NotImplementedError extends HttpError {
67
+ constructor(message?: string, opts?: HttpErrorOptions);
68
+ }
69
+
70
+ export class BadGatewayError extends HttpError {
71
+ constructor(message?: string, opts?: HttpErrorOptions);
72
+ }
73
+
74
+ export class ServiceUnavailableError extends HttpError {
75
+ constructor(message?: string, opts?: HttpErrorOptions);
76
+ }
77
+
78
+ // --- Framework Error Classes -------------------------------------
79
+
80
+ export interface DatabaseErrorOptions extends HttpErrorOptions {
81
+ query?: string;
82
+ adapter?: string;
83
+ }
84
+
85
+ export class DatabaseError extends HttpError {
86
+ readonly query?: string;
87
+ readonly adapter?: string;
88
+ constructor(message?: string, opts?: DatabaseErrorOptions);
89
+ }
90
+
91
+ export interface ConfigurationErrorOptions extends HttpErrorOptions {
92
+ setting?: string;
93
+ }
94
+
95
+ export class ConfigurationError extends HttpError {
96
+ readonly setting?: string;
97
+ constructor(message?: string, opts?: ConfigurationErrorOptions);
98
+ }
99
+
100
+ export interface MiddlewareErrorOptions extends HttpErrorOptions {
101
+ middleware?: string;
102
+ }
103
+
104
+ export class MiddlewareError extends HttpError {
105
+ readonly middleware?: string;
106
+ constructor(message?: string, opts?: MiddlewareErrorOptions);
107
+ }
108
+
109
+ export interface RoutingErrorOptions extends HttpErrorOptions {
110
+ path?: string;
111
+ method?: string;
112
+ }
113
+
114
+ export class RoutingError extends HttpError {
115
+ readonly path?: string;
116
+ readonly method?: string;
117
+ constructor(message?: string, opts?: RoutingErrorOptions);
118
+ }
119
+
120
+ export interface TimeoutErrorOptions extends HttpErrorOptions {
121
+ timeout?: number;
122
+ }
123
+
124
+ export class TimeoutError extends HttpError {
125
+ readonly timeout?: number;
126
+ constructor(message?: string, opts?: TimeoutErrorOptions);
127
+ }
128
+
129
+ export function createError(statusCode: number, message?: string, opts?: HttpErrorOptions): HttpError;
130
+ export function isHttpError(err: any): err is HttpError;
131
+
132
+ // --- ORM Error Classes -------------------------------------------
133
+
134
+ export interface ConnectionErrorOptions extends DatabaseErrorOptions {
135
+ attempt?: number;
136
+ maxRetries?: number;
137
+ host?: string;
138
+ port?: number;
139
+ }
140
+
141
+ export class ConnectionError extends DatabaseError {
142
+ readonly attempt?: number;
143
+ readonly maxRetries?: number;
144
+ readonly host?: string;
145
+ readonly port?: number;
146
+ constructor(message?: string, opts?: ConnectionErrorOptions);
147
+ }
148
+
149
+ export interface MigrationErrorOptions extends DatabaseErrorOptions {
150
+ migration?: string;
151
+ direction?: 'up' | 'down';
152
+ batch?: number;
153
+ }
154
+
155
+ export class MigrationError extends DatabaseError {
156
+ readonly migration?: string;
157
+ readonly direction?: 'up' | 'down';
158
+ readonly batch?: number;
159
+ constructor(message?: string, opts?: MigrationErrorOptions);
160
+ }
161
+
162
+ export interface TransactionErrorOptions extends DatabaseErrorOptions {
163
+ phase?: 'begin' | 'commit' | 'rollback';
164
+ }
165
+
166
+ export class TransactionError extends DatabaseError {
167
+ readonly phase?: 'begin' | 'commit' | 'rollback';
168
+ constructor(message?: string, opts?: TransactionErrorOptions);
169
+ }
170
+
171
+ export interface QueryErrorOptions extends DatabaseErrorOptions {
172
+ sql?: string;
173
+ params?: any[];
174
+ table?: string;
175
+ }
176
+
177
+ export class QueryError extends DatabaseError {
178
+ readonly sql?: string;
179
+ readonly params?: any[];
180
+ readonly table?: string;
181
+ constructor(message?: string, opts?: QueryErrorOptions);
182
+ }
183
+
184
+ export interface AdapterErrorOptions extends DatabaseErrorOptions {
185
+ operation?: string;
186
+ }
187
+
188
+ export class AdapterError extends DatabaseError {
189
+ readonly operation?: string;
190
+ constructor(message?: string, opts?: AdapterErrorOptions);
191
+ }
192
+
193
+ export interface CacheErrorOptions extends HttpErrorOptions {
194
+ operation?: string;
195
+ key?: string;
196
+ }
197
+
198
+ export class CacheError extends HttpError {
199
+ readonly operation?: string;
200
+ readonly key?: string;
201
+ constructor(message?: string, opts?: CacheErrorOptions);
202
+ }
203
+
204
+ // --- Phase 4 Error Classes ------------------------------------------
205
+
206
+ export interface TenancyErrorOptions extends DatabaseErrorOptions {
207
+ tenant?: string;
208
+ strategy?: string;
209
+ }
210
+
211
+ export class TenancyError extends DatabaseError {
212
+ readonly tenant?: string;
213
+ readonly strategy?: string;
214
+ constructor(message?: string, opts?: TenancyErrorOptions);
215
+ }
216
+
217
+ export interface AuditErrorOptions extends DatabaseErrorOptions {
218
+ action?: string;
219
+ table?: string;
220
+ }
221
+
222
+ export class AuditError extends DatabaseError {
223
+ readonly action?: string;
224
+ readonly table?: string;
225
+ constructor(message?: string, opts?: AuditErrorOptions);
226
+ }
227
+
228
+ export interface PluginErrorOptions extends HttpErrorOptions {
229
+ plugin?: string;
230
+ phase?: string;
231
+ }
232
+
233
+ export class PluginError extends HttpError {
234
+ readonly plugin?: string;
235
+ readonly phase?: string;
236
+ constructor(message?: string, opts?: PluginErrorOptions);
237
+ }
238
+
239
+ export interface ProcedureErrorOptions extends DatabaseErrorOptions {
240
+ procedure?: string;
241
+ operation?: string;
242
+ }
243
+
244
+ export class ProcedureError extends DatabaseError {
245
+ readonly procedure?: string;
246
+ readonly operation?: string;
247
+ constructor(message?: string, opts?: ProcedureErrorOptions);
248
+ }
249
+
250
+ // --- Error Handler Middleware ------------------------------------
251
+
252
+ import { Request } from './request';
253
+ import { Response } from './response';
254
+
255
+ export interface ErrorHandlerOptions {
256
+ /** Include stack traces in responses (default: true when NODE_ENV !== 'production'). */
257
+ stack?: boolean;
258
+ /** Log errors to console (default: true). */
259
+ log?: boolean;
260
+ /** Custom log function (default: console.error). */
261
+ logger?: (...args: any[]) => void;
262
+ /** Custom response formatter: (err, req, isDev) => responseBody. */
263
+ formatter?: (err: Error, req: Request, isDev: boolean) => any;
264
+ /** Callback on every error. */
265
+ onError?: (err: Error, req: Request, res: Response) => void;
266
+ }
267
+
268
+ export function errorHandler(opts?: ErrorHandlerOptions): (err: any, req: Request, res: Response, next: (err?: any) => void) => void;
269
+
270
+ // --- Debug Logger ------------------------------------------------
271
+
272
+ export interface DebugLogger {
273
+ (...args: any[]): void;
274
+ trace(...args: any[]): void;
275
+ debug(...args: any[]): void;
276
+ info(...args: any[]): void;
277
+ warn(...args: any[]): void;
278
+ error(...args: any[]): void;
279
+ fatal(...args: any[]): void;
280
+ readonly enabled: boolean;
281
+ readonly namespace: string;
282
+ }
283
+
284
+ export interface DebugLevels {
285
+ trace: 0;
286
+ debug: 1;
287
+ info: 2;
288
+ warn: 3;
289
+ error: 4;
290
+ fatal: 5;
291
+ silent: 6;
292
+ }
293
+
294
+ export interface Debug {
295
+ (namespace: string): DebugLogger;
296
+ /** Set minimum log level globally. */
297
+ level(level: keyof DebugLevels | number): void;
298
+ /** Enable/disable namespaces (same syntax as DEBUG env var). */
299
+ enable(patterns: string): void;
300
+ /** Disable all debug output. */
301
+ disable(): void;
302
+ /** Enable structured JSON output. */
303
+ json(on?: boolean): void;
304
+ /** Enable/disable timestamps. */
305
+ timestamps(on?: boolean): void;
306
+ /** Enable/disable colors. */
307
+ colors(on?: boolean): void;
308
+ /** Set custom output stream. */
309
+ output(stream: { write(s: string): void }): void;
310
+ /** Reset all settings to defaults. */
311
+ reset(): void;
312
+ /** Level constants. */
313
+ readonly LEVELS: DebugLevels;
314
+ }
315
+
316
+ export const debug: Debug;