blaizejs 0.2.2 → 0.3.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/chunk-QQCQRHXJ.js +38 -0
- package/dist/chunk-QQCQRHXJ.js.map +1 -0
- package/dist/chunk-SRD3AB6T.js +38 -0
- package/dist/chunk-SRD3AB6T.js.map +1 -0
- package/dist/chunk-TCPQMZ23.js +148 -0
- package/dist/chunk-TCPQMZ23.js.map +1 -0
- package/dist/index.cjs +1747 -412
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1189 -143
- package/dist/index.d.ts +1189 -143
- package/dist/index.js +1471 -409
- package/dist/index.js.map +1 -1
- package/dist/internal-server-error-CVRDTBLL.js +16 -0
- package/dist/internal-server-error-CVRDTBLL.js.map +1 -0
- package/dist/payload-too-large-error-PAYLDBZT.js +29 -0
- package/dist/payload-too-large-error-PAYLDBZT.js.map +1 -0
- package/dist/unsupported-media-type-error-MQZD7YQJ.js +29 -0
- package/dist/unsupported-media-type-error-MQZD7YQJ.js.map +1 -0
- package/dist/validation-error-CM6IKIJU.js +16 -0
- package/dist/validation-error-CM6IKIJU.js.map +1 -0
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,57 +1,670 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
1
2
|
import http, { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
3
|
import http2, { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
|
|
4
|
+
import { WriteStream } from 'node:fs';
|
|
5
|
+
import { Readable } from 'node:stream';
|
|
3
6
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
4
|
-
import { z } from 'zod';
|
|
5
7
|
import { EventEmitter } from 'node:events';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
|
-
*
|
|
10
|
+
* Error type definitions and interfaces for the BlaizeJS framework
|
|
11
|
+
*
|
|
12
|
+
* This module contains all the type definitions used for error handling
|
|
13
|
+
* across the BlaizeJS framework, including server-side errors, client-side
|
|
14
|
+
* errors, and HTTP response formats.
|
|
9
15
|
*/
|
|
10
|
-
declare function compose(middlewareStack: Middleware[]): MiddlewareFunction;
|
|
11
|
-
|
|
12
16
|
/**
|
|
13
|
-
*
|
|
17
|
+
* Structure of error responses sent over HTTP
|
|
18
|
+
*
|
|
19
|
+
* This interface defines the JSON format used for all error responses
|
|
20
|
+
* from BlaizeJS servers. It matches the structure returned by BlaizeError.toJSON()
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```json
|
|
24
|
+
* {
|
|
25
|
+
* "type": "VALIDATION_ERROR",
|
|
26
|
+
* "title": "Request validation failed",
|
|
27
|
+
* "status": 400,
|
|
28
|
+
* "correlationId": "req_abc123",
|
|
29
|
+
* "timestamp": "2024-01-15T10:30:00.000Z",
|
|
30
|
+
* "details": {
|
|
31
|
+
* "fields": ["email", "password"]
|
|
32
|
+
* }
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
14
35
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
36
|
+
interface BlaizeErrorResponse {
|
|
37
|
+
/** Error type from the ErrorType enum */
|
|
38
|
+
type: ErrorType;
|
|
39
|
+
/** Human-readable error message */
|
|
40
|
+
title: string;
|
|
41
|
+
/** HTTP status code */
|
|
42
|
+
status: number;
|
|
43
|
+
/** Correlation ID for request tracing */
|
|
44
|
+
correlationId: string;
|
|
45
|
+
/** ISO timestamp when error occurred */
|
|
46
|
+
timestamp: string;
|
|
47
|
+
/** Optional error-specific details */
|
|
48
|
+
details?: unknown;
|
|
49
|
+
}
|
|
17
50
|
/**
|
|
18
|
-
*
|
|
51
|
+
* Context information for network-related errors
|
|
52
|
+
*
|
|
53
|
+
* Used by client-side error classes to provide additional context
|
|
54
|
+
* about network failures, timeouts, and connection issues.
|
|
19
55
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
56
|
+
interface NetworkErrorContext {
|
|
57
|
+
/** The URL that failed */
|
|
58
|
+
url: string;
|
|
59
|
+
/** HTTP method being attempted */
|
|
60
|
+
method: string;
|
|
61
|
+
/** Correlation ID for tracing */
|
|
62
|
+
correlationId: string;
|
|
63
|
+
/** Timeout value if applicable */
|
|
64
|
+
timeout?: number;
|
|
65
|
+
/** The original error that caused the network failure */
|
|
66
|
+
originalError: Error;
|
|
67
|
+
/** Additional network-specific details */
|
|
68
|
+
networkDetails?: {
|
|
69
|
+
/** Whether this was a connection timeout */
|
|
70
|
+
isTimeout?: boolean;
|
|
71
|
+
/** Whether this was a DNS resolution failure */
|
|
72
|
+
isDnsFailure?: boolean;
|
|
73
|
+
/** Whether this was a connection refused error */
|
|
74
|
+
isConnectionRefused?: boolean;
|
|
75
|
+
/** HTTP status code if received before failure */
|
|
76
|
+
statusCode?: number;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
22
79
|
/**
|
|
23
|
-
*
|
|
80
|
+
* Context information for request timeout errors
|
|
81
|
+
*
|
|
82
|
+
* Specialized context for timeout-specific errors with timing information.
|
|
24
83
|
*/
|
|
25
|
-
|
|
84
|
+
interface TimeoutErrorContext {
|
|
85
|
+
/** The URL that timed out */
|
|
86
|
+
url: string;
|
|
87
|
+
/** HTTP method being attempted */
|
|
88
|
+
method: string;
|
|
89
|
+
/** Correlation ID for tracing */
|
|
90
|
+
correlationId: string;
|
|
91
|
+
/** Configured timeout value in milliseconds */
|
|
92
|
+
timeoutMs: number;
|
|
93
|
+
/** Actual duration before timeout in milliseconds */
|
|
94
|
+
elapsedMs: number;
|
|
95
|
+
/** Type of timeout (request, connection, etc.) */
|
|
96
|
+
timeoutType: 'request' | 'connection' | 'response' | 'idle';
|
|
97
|
+
}
|
|
26
98
|
/**
|
|
27
|
-
*
|
|
99
|
+
* Context information for response parsing errors
|
|
100
|
+
*
|
|
101
|
+
* Used when the client receives a response but cannot parse it properly.
|
|
28
102
|
*/
|
|
29
|
-
|
|
103
|
+
interface ParseErrorContext {
|
|
104
|
+
/** The URL that returned unparseable content */
|
|
105
|
+
url: string;
|
|
106
|
+
/** HTTP method used */
|
|
107
|
+
method: string;
|
|
108
|
+
/** Correlation ID for tracing */
|
|
109
|
+
correlationId: string;
|
|
110
|
+
/** HTTP status code received */
|
|
111
|
+
statusCode: number;
|
|
112
|
+
/** Content-Type header if available */
|
|
113
|
+
contentType?: string;
|
|
114
|
+
/** Expected response format */
|
|
115
|
+
expectedFormat: 'json' | 'text' | 'binary';
|
|
116
|
+
/** Sample of the actual response content (truncated for safety) */
|
|
117
|
+
responseSample?: string;
|
|
118
|
+
/** The original parsing error */
|
|
119
|
+
originalError: Error;
|
|
120
|
+
}
|
|
30
121
|
/**
|
|
31
|
-
*
|
|
122
|
+
* Validation error field details
|
|
123
|
+
*
|
|
124
|
+
* Structure for field-level validation errors with multiple error messages
|
|
125
|
+
* per field.
|
|
32
126
|
*/
|
|
33
|
-
|
|
127
|
+
interface ValidationFieldError {
|
|
128
|
+
/** Field name or path (e.g., "email", "user.profile.name") */
|
|
129
|
+
field: string;
|
|
130
|
+
/** Array of error messages for this field */
|
|
131
|
+
messages: string[];
|
|
132
|
+
/** The invalid value that caused the error */
|
|
133
|
+
rejectedValue?: unknown;
|
|
134
|
+
/** Expected type or format */
|
|
135
|
+
expectedType?: string;
|
|
136
|
+
}
|
|
34
137
|
/**
|
|
35
|
-
*
|
|
138
|
+
* Validation error details structure
|
|
139
|
+
*
|
|
140
|
+
* Used by ValidationError to provide structured information about
|
|
141
|
+
* what fields failed validation and why.
|
|
36
142
|
*/
|
|
37
|
-
|
|
143
|
+
interface ValidationErrorDetails {
|
|
144
|
+
/** Array of field-level errors */
|
|
145
|
+
fields: ValidationFieldError[];
|
|
146
|
+
/** Total number of validation errors */
|
|
147
|
+
errorCount: number;
|
|
148
|
+
/** The section that failed validation */
|
|
149
|
+
section: 'params' | 'query' | 'body' | 'response';
|
|
150
|
+
/** Schema name if available */
|
|
151
|
+
schemaName?: string;
|
|
152
|
+
}
|
|
38
153
|
/**
|
|
39
|
-
*
|
|
154
|
+
* All available error types in the BlaizeJS framework
|
|
155
|
+
*
|
|
156
|
+
* This enum provides both compile-time type safety and runtime values
|
|
157
|
+
* for error type identification across server and client packages.
|
|
158
|
+
*
|
|
159
|
+
* @example Type-safe error handling:
|
|
160
|
+
* ```typescript
|
|
161
|
+
* function handleError(errorType: ErrorType) {
|
|
162
|
+
* switch (errorType) {
|
|
163
|
+
* case ErrorType.VALIDATION_ERROR:
|
|
164
|
+
* // Handle validation error
|
|
165
|
+
* break;
|
|
166
|
+
* case ErrorType.NOT_FOUND:
|
|
167
|
+
* // Handle not found error
|
|
168
|
+
* break;
|
|
169
|
+
* // TypeScript ensures all cases are covered
|
|
170
|
+
* }
|
|
171
|
+
* }
|
|
172
|
+
* ```
|
|
40
173
|
*/
|
|
41
|
-
declare
|
|
174
|
+
declare enum ErrorType {
|
|
175
|
+
/** Request validation failed (400) */
|
|
176
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
177
|
+
/** Resource not found (404) */
|
|
178
|
+
NOT_FOUND = "NOT_FOUND",
|
|
179
|
+
/** Authentication required (401) */
|
|
180
|
+
UNAUTHORIZED = "UNAUTHORIZED",
|
|
181
|
+
/** Access forbidden (403) */
|
|
182
|
+
FORBIDDEN = "FORBIDDEN",
|
|
183
|
+
/** Resource conflict (409) */
|
|
184
|
+
CONFLICT = "CONFLICT",
|
|
185
|
+
/** Rate limit exceeded (429) */
|
|
186
|
+
RATE_LIMITED = "RATE_LIMITED",
|
|
187
|
+
/** Internal server error (500) */
|
|
188
|
+
INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR",
|
|
189
|
+
/** File/Request Too Large (413) */
|
|
190
|
+
PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE",
|
|
191
|
+
/** Wrong Content Type (415) */
|
|
192
|
+
UNSUPPORTED_MEDIA_TYPE = "UNSUPPORTED_MEDIA_TYPE",
|
|
193
|
+
/** Upload Timeout (408) */
|
|
194
|
+
UPLOAD_TIMEOUT = "UPLOAD_TIMEOUT",
|
|
195
|
+
/** Valid Format Invalid Semantics (422) */
|
|
196
|
+
UNPROCESSABLE_ENTITY = "UNPROCESSABLE_ENTITY",
|
|
197
|
+
/** Network connectivity failure (0) */
|
|
198
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
199
|
+
/** Request or response timeout (0) */
|
|
200
|
+
TIMEOUT_ERROR = "TIMEOUT_ERROR",
|
|
201
|
+
/** Response parsing failure (0) */
|
|
202
|
+
PARSE_ERROR = "PARSE_ERROR",
|
|
203
|
+
/** Generic HTTP error (varies) */
|
|
204
|
+
HTTP_ERROR = "HTTP_ERROR"
|
|
205
|
+
}
|
|
42
206
|
/**
|
|
43
|
-
*
|
|
207
|
+
* Error severity levels for logging and monitoring
|
|
208
|
+
*
|
|
209
|
+
* Provides a way to categorize errors by their impact and urgency.
|
|
44
210
|
*/
|
|
45
|
-
declare
|
|
211
|
+
declare enum ErrorSeverity {
|
|
212
|
+
/** Low impact, often user errors */
|
|
213
|
+
LOW = "low",
|
|
214
|
+
/** Medium impact, application errors */
|
|
215
|
+
MEDIUM = "medium",
|
|
216
|
+
/** High impact, system errors */
|
|
217
|
+
HIGH = "high",
|
|
218
|
+
/** Critical impact, service disruption */
|
|
219
|
+
CRITICAL = "critical"
|
|
220
|
+
}
|
|
46
221
|
/**
|
|
47
|
-
*
|
|
222
|
+
* Abstract base class for all BlaizeJS errors
|
|
223
|
+
*
|
|
224
|
+
* This class provides the foundation for all error types in the BlaizeJS framework.
|
|
225
|
+
* It extends JavaScript's built-in Error class and adds framework-specific properties
|
|
226
|
+
* for consistent error handling across server and client.
|
|
227
|
+
*
|
|
228
|
+
* @example
|
|
229
|
+
* ```typescript
|
|
230
|
+
* import { ErrorType } from './types';
|
|
231
|
+
*
|
|
232
|
+
* class NotFoundError extends BlaizeError<{ resourceId: string }> {
|
|
233
|
+
* constructor(message = 'Resource not found', details?: { resourceId: string }) {
|
|
234
|
+
* super(ErrorType.NOT_FOUND, message, 404, getCurrentCorrelationId(), details);
|
|
235
|
+
* }
|
|
236
|
+
* }
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* @template TDetails - Type for error-specific details object
|
|
48
240
|
*/
|
|
49
|
-
declare
|
|
241
|
+
declare abstract class BlaizeError<TDetails = unknown> extends Error {
|
|
242
|
+
/**
|
|
243
|
+
* Error type identifier from the ErrorType enum
|
|
244
|
+
* Used for programmatic error handling and client-side error routing
|
|
245
|
+
*/
|
|
246
|
+
readonly type: ErrorType;
|
|
247
|
+
/**
|
|
248
|
+
* Human-readable error title/message
|
|
249
|
+
* Should be descriptive enough for debugging but safe for end users
|
|
250
|
+
*/
|
|
251
|
+
readonly title: string;
|
|
252
|
+
/**
|
|
253
|
+
* HTTP status code associated with this error
|
|
254
|
+
* Used by the error boundary to set appropriate response status
|
|
255
|
+
*/
|
|
256
|
+
readonly status: number;
|
|
257
|
+
/**
|
|
258
|
+
* Correlation ID for request tracing
|
|
259
|
+
* Links this error to the specific request that generated it
|
|
260
|
+
*/
|
|
261
|
+
readonly correlationId: string;
|
|
262
|
+
/**
|
|
263
|
+
* Timestamp when the error occurred
|
|
264
|
+
* Useful for debugging and log correlation
|
|
265
|
+
*/
|
|
266
|
+
readonly timestamp: Date;
|
|
267
|
+
/**
|
|
268
|
+
* Additional error-specific details
|
|
269
|
+
* Type-safe error context that varies by error type
|
|
270
|
+
*/
|
|
271
|
+
readonly details?: TDetails | undefined;
|
|
272
|
+
/**
|
|
273
|
+
* Creates a new BlaizeError instance
|
|
274
|
+
*
|
|
275
|
+
* @param type - Error type from the ErrorType enum
|
|
276
|
+
* @param title - Human-readable error message
|
|
277
|
+
* @param status - HTTP status code
|
|
278
|
+
* @param correlationId - Request correlation ID for tracing
|
|
279
|
+
* @param details - Optional error-specific details
|
|
280
|
+
*/
|
|
281
|
+
protected constructor(type: ErrorType, title: string, status: number, correlationId: string, details?: TDetails | undefined);
|
|
282
|
+
/**
|
|
283
|
+
* Serializes the error to a plain object suitable for HTTP responses
|
|
284
|
+
*
|
|
285
|
+
* @returns Object representation of the error
|
|
286
|
+
*/
|
|
287
|
+
toJSON(): {
|
|
288
|
+
type: ErrorType;
|
|
289
|
+
title: string;
|
|
290
|
+
status: number;
|
|
291
|
+
correlationId: string;
|
|
292
|
+
timestamp: string;
|
|
293
|
+
} | {
|
|
294
|
+
details: TDetails & ({} | null);
|
|
295
|
+
type: ErrorType;
|
|
296
|
+
title: string;
|
|
297
|
+
status: number;
|
|
298
|
+
correlationId: string;
|
|
299
|
+
timestamp: string;
|
|
300
|
+
};
|
|
301
|
+
/**
|
|
302
|
+
* Returns a string representation of the error
|
|
303
|
+
* Includes correlation ID for easier debugging
|
|
304
|
+
*/
|
|
305
|
+
toString(): string;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Interface for payload too large error details
|
|
309
|
+
*/
|
|
310
|
+
interface PayloadTooLargeErrorDetails {
|
|
311
|
+
fileCount?: number;
|
|
312
|
+
maxFiles?: number;
|
|
313
|
+
filename?: string;
|
|
314
|
+
field?: string;
|
|
315
|
+
contentType?: string;
|
|
316
|
+
currentSize?: number;
|
|
317
|
+
maxSize?: number;
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Interface for unsupported media type error details
|
|
321
|
+
*/
|
|
322
|
+
interface UnsupportedMediaTypeErrorDetails {
|
|
323
|
+
receivedMimeType?: string;
|
|
324
|
+
allowedMimeTypes?: string[];
|
|
325
|
+
filename?: string;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Interface for authentication error details
|
|
329
|
+
*/
|
|
330
|
+
interface UnauthorizedErrorDetails {
|
|
331
|
+
/** Reason for authentication failure */
|
|
332
|
+
reason?: 'missing_token' | 'invalid_token' | 'expired_token' | 'malformed_token' | 'insufficient_scope' | string;
|
|
333
|
+
/** Authentication scheme (Bearer, Basic, etc.) */
|
|
334
|
+
authScheme?: string;
|
|
335
|
+
/** Authentication realm */
|
|
336
|
+
realm?: string;
|
|
337
|
+
/** Detailed error description */
|
|
338
|
+
error_description?: string;
|
|
339
|
+
/** Required scopes or permissions */
|
|
340
|
+
requiredScopes?: string[];
|
|
341
|
+
/** Login URL for interactive authentication */
|
|
342
|
+
loginUrl?: string;
|
|
343
|
+
/** Additional context */
|
|
344
|
+
[key: string]: unknown;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Interface for authorization/permission error details
|
|
348
|
+
*/
|
|
349
|
+
interface ForbiddenErrorDetails {
|
|
350
|
+
/** Required permission or role */
|
|
351
|
+
requiredPermission?: string;
|
|
352
|
+
/** User's current permissions */
|
|
353
|
+
userPermissions?: string[];
|
|
354
|
+
/** Resource being accessed */
|
|
355
|
+
resource?: string;
|
|
356
|
+
/** Action being attempted */
|
|
357
|
+
action?: string;
|
|
358
|
+
/** Reason for access denial */
|
|
359
|
+
reason?: 'insufficient_permissions' | 'account_suspended' | 'resource_locked' | string;
|
|
360
|
+
/** Additional context */
|
|
361
|
+
[key: string]: unknown;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Interface for resource conflict error details
|
|
365
|
+
*/
|
|
366
|
+
interface ConflictErrorDetails {
|
|
367
|
+
/** Type of conflict */
|
|
368
|
+
conflictType?: 'duplicate_key' | 'version_mismatch' | 'concurrent_modification' | 'business_rule' | string;
|
|
369
|
+
/** Field that caused the conflict */
|
|
370
|
+
field?: string;
|
|
371
|
+
/** Existing value that conflicts */
|
|
372
|
+
existingValue?: unknown;
|
|
373
|
+
/** Provided value that conflicts */
|
|
374
|
+
providedValue?: unknown;
|
|
375
|
+
/** Resource that has the conflicting value */
|
|
376
|
+
conflictingResource?: string;
|
|
377
|
+
/** Current version/etag of the resource */
|
|
378
|
+
currentVersion?: string;
|
|
379
|
+
/** Expected version/etag */
|
|
380
|
+
expectedVersion?: string;
|
|
381
|
+
/** Suggested resolution */
|
|
382
|
+
resolution?: string;
|
|
383
|
+
/** Additional context */
|
|
384
|
+
[key: string]: unknown;
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Interface for rate limiting error details
|
|
388
|
+
*/
|
|
389
|
+
interface RateLimitErrorDetails {
|
|
390
|
+
/** Maximum requests allowed in the time window */
|
|
391
|
+
limit?: number;
|
|
392
|
+
/** Remaining requests in current window */
|
|
393
|
+
remaining?: number;
|
|
394
|
+
/** When the rate limit resets */
|
|
395
|
+
resetTime?: Date;
|
|
396
|
+
/** Seconds until the rate limit resets */
|
|
397
|
+
retryAfter?: number;
|
|
398
|
+
/** Time window for the rate limit */
|
|
399
|
+
window?: string;
|
|
400
|
+
/** Identifier used for rate limiting (IP, user ID, etc.) */
|
|
401
|
+
identifier?: string;
|
|
402
|
+
/** Type of rate limit hit */
|
|
403
|
+
limitType?: 'global' | 'per_user' | 'per_ip' | 'per_endpoint' | string;
|
|
404
|
+
/** Additional context */
|
|
405
|
+
[key: string]: unknown;
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Interface for internal server error details
|
|
409
|
+
*/
|
|
410
|
+
interface InternalServerErrorDetails {
|
|
411
|
+
/** Original error message (for debugging) */
|
|
412
|
+
originalError?: string;
|
|
413
|
+
/** Stack trace (for debugging) */
|
|
414
|
+
stackTrace?: string;
|
|
415
|
+
/** Component where the error occurred */
|
|
416
|
+
component?: string;
|
|
417
|
+
/** Operation being performed */
|
|
418
|
+
operation?: string;
|
|
419
|
+
/** Internal error code */
|
|
420
|
+
internalErrorCode?: string;
|
|
421
|
+
/** When the error occurred */
|
|
422
|
+
timestamp?: Date;
|
|
423
|
+
/** Whether this error should be retryable */
|
|
424
|
+
retryable?: boolean;
|
|
425
|
+
/** Additional debugging context */
|
|
426
|
+
[key: string]: unknown;
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Interface for NotFound error details
|
|
430
|
+
* Provides context about the missing resource
|
|
431
|
+
*/
|
|
432
|
+
interface NotFoundErrorDetails {
|
|
433
|
+
/** Type of resource that was not found */
|
|
434
|
+
resourceType?: string;
|
|
435
|
+
/** ID or identifier of the resource */
|
|
436
|
+
resourceId?: string;
|
|
437
|
+
/** Collection or table where the resource was searched */
|
|
438
|
+
collection?: string;
|
|
439
|
+
/** Search criteria that was used */
|
|
440
|
+
query?: Record<string, unknown>;
|
|
441
|
+
/** Search criteria that was used (for backward compatibility) */
|
|
442
|
+
searchCriteria?: Record<string, unknown>;
|
|
443
|
+
/** The path that was attempted */
|
|
444
|
+
path?: string;
|
|
445
|
+
/** HTTP method used (for API endpoints) */
|
|
446
|
+
method?: string;
|
|
447
|
+
/** The path that was attempted (for backward compatibility) */
|
|
448
|
+
attemptedPath?: string;
|
|
449
|
+
/** Parent resource information for nested resources */
|
|
450
|
+
parentResource?: {
|
|
451
|
+
type: string;
|
|
452
|
+
id: string;
|
|
453
|
+
};
|
|
454
|
+
/** Helpful suggestion for the user */
|
|
455
|
+
suggestion?: string;
|
|
456
|
+
/** Additional context */
|
|
457
|
+
[key: string]: unknown;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Interface for body parsing errors stored in context state
|
|
461
|
+
*/
|
|
462
|
+
interface BodyParseError {
|
|
463
|
+
/**
|
|
464
|
+
* Type of parsing error that occurred
|
|
465
|
+
*/
|
|
466
|
+
readonly type: 'json_parse_error' | 'form_parse_error' | 'multipart_parse_error' | 'body_read_error';
|
|
467
|
+
/**
|
|
468
|
+
* Human-readable error message
|
|
469
|
+
*/
|
|
470
|
+
readonly message: string;
|
|
471
|
+
/**
|
|
472
|
+
* Original error object or details
|
|
473
|
+
*/
|
|
474
|
+
readonly error: unknown;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* Type guard to check if an object is a BodyParseError
|
|
478
|
+
*/
|
|
479
|
+
declare function isBodyParseError(error: unknown): error is BodyParseError;
|
|
480
|
+
/**
|
|
481
|
+
* Context information for error transformation
|
|
482
|
+
*/
|
|
483
|
+
interface ErrorTransformContext {
|
|
484
|
+
url: string;
|
|
485
|
+
method: string;
|
|
486
|
+
correlationId: string;
|
|
487
|
+
timeoutMs?: number;
|
|
488
|
+
elapsedMs?: number;
|
|
489
|
+
statusCode?: number;
|
|
490
|
+
contentType?: string;
|
|
491
|
+
responseSample?: string;
|
|
492
|
+
[key: string]: unknown;
|
|
493
|
+
}
|
|
50
494
|
|
|
51
495
|
/**
|
|
52
|
-
*
|
|
496
|
+
* Represents an uploaded file in a multipart/form-data request
|
|
53
497
|
*/
|
|
54
|
-
|
|
498
|
+
interface UploadedFile {
|
|
499
|
+
/** Original filename provided by the client (may be undefined) */
|
|
500
|
+
readonly filename: string | undefined;
|
|
501
|
+
/** Form field name this file was uploaded under */
|
|
502
|
+
readonly fieldname: string;
|
|
503
|
+
/** MIME type of the uploaded file */
|
|
504
|
+
readonly mimetype: string;
|
|
505
|
+
/** Size of the file in bytes */
|
|
506
|
+
readonly size: number;
|
|
507
|
+
/** Stream containing the file data (always available) */
|
|
508
|
+
readonly stream: Readable;
|
|
509
|
+
/** Buffer containing file data (only available with 'memory' strategy) */
|
|
510
|
+
readonly buffer?: Buffer;
|
|
511
|
+
/** Path to temporary file (only available with 'temp' strategy) */
|
|
512
|
+
readonly tempPath?: string;
|
|
513
|
+
/** SHA-256 hash of file content (if computed) */
|
|
514
|
+
readonly hash?: string;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Complete multipart/form-data parsed content
|
|
518
|
+
*/
|
|
519
|
+
interface MultipartData {
|
|
520
|
+
/** Form fields (non-file inputs) */
|
|
521
|
+
readonly fields: Record<string, string | string[]>;
|
|
522
|
+
/** Uploaded files */
|
|
523
|
+
readonly files: Record<string, UploadedFile | UploadedFile[]>;
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Options for parsing multipart/form-data
|
|
527
|
+
*/
|
|
528
|
+
interface ParseOptions {
|
|
529
|
+
/** Maximum size for individual files in bytes (default: 10MB) */
|
|
530
|
+
readonly maxFileSize?: number;
|
|
531
|
+
/** Maximum number of files per request (default: 10) */
|
|
532
|
+
readonly maxFiles?: number;
|
|
533
|
+
/** Maximum size for form fields in bytes (default: 1MB) */
|
|
534
|
+
readonly maxFieldSize?: number;
|
|
535
|
+
/** Allowed MIME types (empty array = allow all) */
|
|
536
|
+
readonly allowedMimeTypes?: readonly string[];
|
|
537
|
+
/** Allowed file extensions (empty array = allow all) */
|
|
538
|
+
readonly allowedExtensions?: readonly string[];
|
|
539
|
+
/** Processing strategy for file data */
|
|
540
|
+
readonly strategy: 'memory' | 'stream' | 'temp';
|
|
541
|
+
/** Directory for temporary files (strategy: 'temp' only) */
|
|
542
|
+
readonly tempDir?: string;
|
|
543
|
+
/** Whether to compute SHA-256 hash of files */
|
|
544
|
+
readonly computeHash?: boolean;
|
|
545
|
+
}
|
|
546
|
+
/**
|
|
547
|
+
* Result of parsing multipart data with metadata
|
|
548
|
+
*/
|
|
549
|
+
interface ParseResult {
|
|
550
|
+
/** Parsed multipart data */
|
|
551
|
+
readonly data: MultipartData;
|
|
552
|
+
/** Parsing metadata */
|
|
553
|
+
readonly metadata: {
|
|
554
|
+
/** Total time spent parsing (milliseconds) */
|
|
555
|
+
readonly parseTime: number;
|
|
556
|
+
/** Total size of all uploaded content */
|
|
557
|
+
readonly totalSize: number;
|
|
558
|
+
/** Number of files processed */
|
|
559
|
+
readonly fileCount: number;
|
|
560
|
+
/** Number of fields processed */
|
|
561
|
+
readonly fieldCount: number;
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Error information for multipart parsing failures
|
|
566
|
+
*/
|
|
567
|
+
interface MultipartError {
|
|
568
|
+
/** Error type/code */
|
|
569
|
+
readonly type: 'boundary_missing' | 'size_exceeded' | 'file_limit_exceeded' | 'mime_type_forbidden' | 'extension_forbidden' | 'parse_error' | 'stream_error' | 'temp_file_error';
|
|
570
|
+
/** Human-readable error message */
|
|
571
|
+
readonly message: string;
|
|
572
|
+
/** Additional context (field name, file name, etc.) */
|
|
573
|
+
readonly context?: Record<string, unknown>;
|
|
574
|
+
/** Original error if available */
|
|
575
|
+
readonly cause?: Error;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Configuration for file upload validation
|
|
579
|
+
*/
|
|
580
|
+
interface ValidationConfig {
|
|
581
|
+
/** File size constraints */
|
|
582
|
+
readonly size?: {
|
|
583
|
+
readonly min?: number;
|
|
584
|
+
readonly max?: number;
|
|
585
|
+
};
|
|
586
|
+
/** File count constraints */
|
|
587
|
+
readonly count?: {
|
|
588
|
+
readonly min?: number;
|
|
589
|
+
readonly max?: number;
|
|
590
|
+
};
|
|
591
|
+
/** MIME type constraints */
|
|
592
|
+
readonly mimeTypes?: {
|
|
593
|
+
readonly allowed?: readonly string[];
|
|
594
|
+
readonly forbidden?: readonly string[];
|
|
595
|
+
};
|
|
596
|
+
/** File extension constraints */
|
|
597
|
+
readonly extensions?: {
|
|
598
|
+
readonly allowed?: readonly string[];
|
|
599
|
+
readonly forbidden?: readonly string[];
|
|
600
|
+
};
|
|
601
|
+
/** Custom validation function */
|
|
602
|
+
readonly custom?: (file: UploadedFile) => Promise<boolean> | boolean;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* File processing configuration
|
|
606
|
+
*/
|
|
607
|
+
interface ProcessingConfig {
|
|
608
|
+
/** Whether to process files concurrently */
|
|
609
|
+
readonly concurrent?: boolean;
|
|
610
|
+
/** Maximum concurrent processing operations */
|
|
611
|
+
readonly maxConcurrency?: number;
|
|
612
|
+
/** Processing timeout in milliseconds */
|
|
613
|
+
readonly timeout?: number;
|
|
614
|
+
/** Whether to preserve original files during processing */
|
|
615
|
+
readonly preserveOriginal?: boolean;
|
|
616
|
+
}
|
|
617
|
+
/**
|
|
618
|
+
* Upload progress information (for future streaming uploads)
|
|
619
|
+
*/
|
|
620
|
+
interface UploadProgress {
|
|
621
|
+
/** Bytes uploaded so far */
|
|
622
|
+
readonly bytesUploaded: number;
|
|
623
|
+
/** Total bytes to upload */
|
|
624
|
+
readonly totalBytes: number;
|
|
625
|
+
/** Upload percentage (0-100) */
|
|
626
|
+
readonly percentage: number;
|
|
627
|
+
/** Upload speed in bytes per second */
|
|
628
|
+
readonly speed: number;
|
|
629
|
+
/** Estimated time remaining in milliseconds */
|
|
630
|
+
readonly eta: number;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Internal state for multipart parser state machine
|
|
634
|
+
*/
|
|
635
|
+
interface ParserState {
|
|
636
|
+
boundary: Buffer;
|
|
637
|
+
options: Required<ParseOptions>;
|
|
638
|
+
fields: Map<string, string[]>;
|
|
639
|
+
files: Map<string, UploadedFile[]>;
|
|
640
|
+
buffer: Buffer;
|
|
641
|
+
stage: 'boundary' | 'headers' | 'content';
|
|
642
|
+
currentHeaders: string;
|
|
643
|
+
currentField: string | null;
|
|
644
|
+
currentFilename: string | undefined;
|
|
645
|
+
currentMimetype: string;
|
|
646
|
+
currentContentLength: number;
|
|
647
|
+
fileCount: number;
|
|
648
|
+
fieldCount: number;
|
|
649
|
+
currentBufferChunks: Buffer[];
|
|
650
|
+
currentStream: Readable | null;
|
|
651
|
+
currentTempPath: string | null;
|
|
652
|
+
currentWriteStream: WriteStream | null;
|
|
653
|
+
streamController: ReadableStreamDefaultController<Uint8Array> | null;
|
|
654
|
+
cleanupTasks: Array<() => Promise<void>>;
|
|
655
|
+
/**
|
|
656
|
+
* Whether we've found at least one valid boundary marker
|
|
657
|
+
*/
|
|
658
|
+
hasFoundValidBoundary: boolean;
|
|
659
|
+
/**
|
|
660
|
+
* Whether we've successfully processed at least one complete part (field or file)
|
|
661
|
+
*/
|
|
662
|
+
hasProcessedAnyPart: boolean;
|
|
663
|
+
/**
|
|
664
|
+
* Whether parsing has reached the end boundary
|
|
665
|
+
*/
|
|
666
|
+
isFinished: boolean;
|
|
667
|
+
}
|
|
55
668
|
|
|
56
669
|
/**
|
|
57
670
|
* Unified request type supporting both HTTP/1.1 and HTTP/2
|
|
@@ -87,6 +700,11 @@ interface StreamOptions {
|
|
|
87
700
|
*/
|
|
88
701
|
interface State {
|
|
89
702
|
[key: string]: unknown;
|
|
703
|
+
/**
|
|
704
|
+
* Body parsing error information
|
|
705
|
+
* Set when body parsing fails during request processing
|
|
706
|
+
*/
|
|
707
|
+
_bodyError?: BodyParseError;
|
|
90
708
|
}
|
|
91
709
|
interface ContextResponse<S extends State = State> {
|
|
92
710
|
raw: UnifiedResponse;
|
|
@@ -111,6 +729,16 @@ interface ContextRequest<TBody = unknown> {
|
|
|
111
729
|
protocol: string;
|
|
112
730
|
isHttp2: boolean;
|
|
113
731
|
body?: TBody;
|
|
732
|
+
/**
|
|
733
|
+
* Uploaded files from multipart/form-data requests
|
|
734
|
+
* Available when Content-Type is multipart/form-data
|
|
735
|
+
*/
|
|
736
|
+
files?: Record<string, UploadedFile | UploadedFile[]>;
|
|
737
|
+
/**
|
|
738
|
+
* Complete multipart data (files + fields)
|
|
739
|
+
* Available when Content-Type is multipart/form-data
|
|
740
|
+
*/
|
|
741
|
+
multipart?: MultipartData;
|
|
114
742
|
header: (name: string) => string | undefined;
|
|
115
743
|
headers: (names?: string[]) => Record<string, string | undefined>;
|
|
116
744
|
}
|
|
@@ -134,6 +762,12 @@ interface Context<S extends State = State, TBody = unknown, TQuery = QueryParams
|
|
|
134
762
|
*/
|
|
135
763
|
state: S;
|
|
136
764
|
}
|
|
765
|
+
type MultipartLimits = {
|
|
766
|
+
maxFileSize?: number;
|
|
767
|
+
maxTotalSize?: number;
|
|
768
|
+
maxFiles?: number;
|
|
769
|
+
maxFieldSize?: number;
|
|
770
|
+
};
|
|
137
771
|
/**
|
|
138
772
|
* Options for creating a context
|
|
139
773
|
*/
|
|
@@ -146,6 +780,16 @@ interface ContextOptions {
|
|
|
146
780
|
* Additional state to merge into the context
|
|
147
781
|
*/
|
|
148
782
|
initialState?: State;
|
|
783
|
+
/**
|
|
784
|
+
* Limits for various body types to prevent abuse
|
|
785
|
+
*/
|
|
786
|
+
bodyLimits?: {
|
|
787
|
+
json?: number;
|
|
788
|
+
form?: number;
|
|
789
|
+
text?: number;
|
|
790
|
+
multipart?: MultipartLimits;
|
|
791
|
+
raw?: number;
|
|
792
|
+
};
|
|
149
793
|
}
|
|
150
794
|
/**
|
|
151
795
|
* Function to get the current context from AsyncLocalStorage
|
|
@@ -207,7 +851,11 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
|
|
|
207
851
|
/**
|
|
208
852
|
* Schema for route validation with generic type parameters
|
|
209
853
|
*/
|
|
210
|
-
interface RouteSchema<P extends z.ZodType = z.ZodType<any>,
|
|
854
|
+
interface RouteSchema<P extends z.ZodType = z.ZodType<any>, // URL parameters schema
|
|
855
|
+
Q extends z.ZodType = z.ZodType<any>, // Query parameters schema
|
|
856
|
+
B extends z.ZodType = z.ZodType<any>, // Body schema
|
|
857
|
+
R extends z.ZodType = z.ZodType<any>, // Response schema
|
|
858
|
+
ED extends z.ZodType = z.ZodType<any>> {
|
|
211
859
|
/** Parameter schema for validation */
|
|
212
860
|
params?: P;
|
|
213
861
|
/** Query schema for validation */
|
|
@@ -216,6 +864,8 @@ interface RouteSchema<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType
|
|
|
216
864
|
body?: B;
|
|
217
865
|
/** Response schema for validation */
|
|
218
866
|
response?: R;
|
|
867
|
+
/** Error Response Details schema for validation */
|
|
868
|
+
errorResponseDetails?: ED;
|
|
219
869
|
}
|
|
220
870
|
/**
|
|
221
871
|
* Route handler function with strongly typed params and response
|
|
@@ -224,9 +874,9 @@ type RouteHandler<TParams = Record<string, string>, TQuery = Record<string, stri
|
|
|
224
874
|
/**
|
|
225
875
|
* Options for a route method with schema-based type inference
|
|
226
876
|
*/
|
|
227
|
-
interface RouteMethodOptions<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>> {
|
|
877
|
+
interface RouteMethodOptions<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>, ED extends z.ZodType = z.ZodType<any>> {
|
|
228
878
|
/** Schema for request/response validation */
|
|
229
|
-
schema?: RouteSchema<P, Q, B, R>;
|
|
879
|
+
schema?: RouteSchema<P, Q, B, R, ED>;
|
|
230
880
|
/** Handler function for the route */
|
|
231
881
|
handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, B extends z.ZodType ? Infer<B> : unknown, R extends z.ZodType ? Infer<R> : unknown>;
|
|
232
882
|
/** Middleware to apply to this route */
|
|
@@ -238,13 +888,13 @@ interface RouteMethodOptions<P extends z.ZodType = z.ZodType<any>, Q extends z.Z
|
|
|
238
888
|
* Route definition mapping HTTP methods to handlers
|
|
239
889
|
*/
|
|
240
890
|
interface RouteDefinition {
|
|
241
|
-
GET?: RouteMethodOptions<any, any, never, any>;
|
|
242
|
-
POST?: RouteMethodOptions<any, any, any, any>;
|
|
243
|
-
PUT?: RouteMethodOptions<any, any, any, any>;
|
|
244
|
-
DELETE?: RouteMethodOptions<any, any, never, any>;
|
|
245
|
-
PATCH?: RouteMethodOptions<any, any, any, any>;
|
|
246
|
-
HEAD?: RouteMethodOptions<any, any, never, any>;
|
|
247
|
-
OPTIONS?: RouteMethodOptions<any, any, never, any>;
|
|
891
|
+
GET?: RouteMethodOptions<any, any, never, any, any>;
|
|
892
|
+
POST?: RouteMethodOptions<any, any, any, any, any>;
|
|
893
|
+
PUT?: RouteMethodOptions<any, any, any, any, any>;
|
|
894
|
+
DELETE?: RouteMethodOptions<any, any, never, any, any>;
|
|
895
|
+
PATCH?: RouteMethodOptions<any, any, any, any, any>;
|
|
896
|
+
HEAD?: RouteMethodOptions<any, any, never, any, any>;
|
|
897
|
+
OPTIONS?: RouteMethodOptions<any, any, never, any, any>;
|
|
248
898
|
}
|
|
249
899
|
/**
|
|
250
900
|
* Route object with path
|
|
@@ -297,6 +947,12 @@ interface Router {
|
|
|
297
947
|
getRoutes: () => Route[];
|
|
298
948
|
/** Add a route programmatically */
|
|
299
949
|
addRoute: (route: Route) => void;
|
|
950
|
+
/** Add multiple routes programmatically with batch processing */
|
|
951
|
+
addRoutes: (routes: Route[]) => {
|
|
952
|
+
added: Route[];
|
|
953
|
+
removed: string[];
|
|
954
|
+
changed: Route[];
|
|
955
|
+
};
|
|
300
956
|
/** Add a route directory for plugins */
|
|
301
957
|
addRouteDirectory(directory: string, options?: {
|
|
302
958
|
prefix?: string;
|
|
@@ -306,6 +962,8 @@ interface Router {
|
|
|
306
962
|
path: string;
|
|
307
963
|
sources: string[];
|
|
308
964
|
}>;
|
|
965
|
+
/** Close watchers and cleanup resources */
|
|
966
|
+
close?: () => Promise<void>;
|
|
309
967
|
}
|
|
310
968
|
/**
|
|
311
969
|
* Route match result
|
|
@@ -339,6 +997,10 @@ interface Matcher {
|
|
|
339
997
|
method: HttpMethod;
|
|
340
998
|
params: Record<string, string>;
|
|
341
999
|
}[];
|
|
1000
|
+
/** Remove a route from the matcher (optional for compatibility) */
|
|
1001
|
+
remove: (path: string) => void;
|
|
1002
|
+
/** Clear all routes from the matcher (optional for compatibility) */
|
|
1003
|
+
clear: () => void;
|
|
342
1004
|
}
|
|
343
1005
|
interface ParsedRoute {
|
|
344
1006
|
filePath: string;
|
|
@@ -500,122 +1162,57 @@ type CreateOptionsRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.Zod
|
|
|
500
1162
|
OPTIONS: RouteMethodOptions<P, Q, never, R>;
|
|
501
1163
|
path: string;
|
|
502
1164
|
};
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
type ExtractResponse<T> = T extends RouteMethodOptions<any, any, any, infer R> ? R extends z.ZodType ? Infer<R> : unknown : never;
|
|
508
|
-
type ExtractMethod<T> = T extends {
|
|
509
|
-
GET: any;
|
|
510
|
-
} ? 'GET' : T extends {
|
|
511
|
-
POST: any;
|
|
512
|
-
} ? 'POST' : T extends {
|
|
513
|
-
PUT: any;
|
|
514
|
-
} ? 'PUT' : T extends {
|
|
515
|
-
DELETE: any;
|
|
516
|
-
} ? 'DELETE' : T extends {
|
|
517
|
-
PATCH: any;
|
|
518
|
-
} ? 'PATCH' : T extends {
|
|
519
|
-
HEAD: any;
|
|
520
|
-
} ? 'HEAD' : T extends {
|
|
521
|
-
OPTIONS: any;
|
|
522
|
-
} ? 'OPTIONS' : never;
|
|
523
|
-
type BuildRoutesRegistry<TRoutes extends Record<string, any>> = {
|
|
524
|
-
[Method in ExtractMethod<TRoutes[keyof TRoutes]> as `$${Lowercase<Method>}`]: {
|
|
525
|
-
[K in keyof TRoutes as ExtractMethod<TRoutes[K]> extends Method ? K : never]: TRoutes[K];
|
|
526
|
-
};
|
|
527
|
-
};
|
|
528
|
-
type GetRouteMethod<TRoute> = TRoute extends {
|
|
529
|
-
path: string;
|
|
530
|
-
} ? Omit<TRoute, 'path'>[keyof Omit<TRoute, 'path'>] : never;
|
|
531
|
-
type CreateClientMethod<TRoute> = GetRouteMethod<TRoute> extends RouteMethodOptions<any, any, any, any> ? (args?: {
|
|
532
|
-
params?: ExtractParams<GetRouteMethod<TRoute>>;
|
|
533
|
-
query?: ExtractQuery<GetRouteMethod<TRoute>>;
|
|
534
|
-
body?: ExtractBody<GetRouteMethod<TRoute>>;
|
|
535
|
-
}) => Promise<ExtractResponse<GetRouteMethod<TRoute>>> : never;
|
|
536
|
-
type CreateClient<TRoutes extends Record<string, Record<string, any>>> = {
|
|
537
|
-
[Method in keyof TRoutes]: {
|
|
538
|
-
[RouteName in keyof TRoutes[Method]]: CreateClientMethod<TRoutes[Method][RouteName]>;
|
|
539
|
-
};
|
|
540
|
-
};
|
|
541
|
-
interface ClientConfig {
|
|
542
|
-
baseUrl: string;
|
|
543
|
-
defaultHeaders?: Record<string, string>;
|
|
544
|
-
timeout?: number;
|
|
1165
|
+
interface FileCache {
|
|
1166
|
+
routes: Route[];
|
|
1167
|
+
timestamp: number;
|
|
1168
|
+
hash: string;
|
|
545
1169
|
}
|
|
546
|
-
interface
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
1170
|
+
interface ReloadMetrics {
|
|
1171
|
+
fileChanges: number;
|
|
1172
|
+
totalReloadTime: number;
|
|
1173
|
+
averageReloadTime: number;
|
|
1174
|
+
slowReloads: Array<{
|
|
1175
|
+
file: string;
|
|
1176
|
+
time: number;
|
|
1177
|
+
}>;
|
|
550
1178
|
}
|
|
551
|
-
interface
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
1179
|
+
interface WatchOptions {
|
|
1180
|
+
debounceMs?: number;
|
|
1181
|
+
/** Directories to ignore */
|
|
1182
|
+
ignore?: string[];
|
|
1183
|
+
/** Callback for new routes */
|
|
1184
|
+
onRouteAdded?: (filePath: string, routes: Route[]) => void;
|
|
1185
|
+
/** Callback for changed routes */
|
|
1186
|
+
onRouteChanged?: (filePath: string, routes: Route[]) => void;
|
|
1187
|
+
/** Callback for removed routes */
|
|
1188
|
+
onRouteRemoved?: (filePath: string, routes: Route[]) => void;
|
|
1189
|
+
/** Callback for errors */
|
|
1190
|
+
onError?: (error: Error) => void;
|
|
1191
|
+
}
|
|
1192
|
+
interface RouteRegistry {
|
|
1193
|
+
routesByPath: Map<string, Route>;
|
|
1194
|
+
routesByFile: Map<string, Set<string>>;
|
|
1195
|
+
pathToFile: Map<string, string>;
|
|
1196
|
+
}
|
|
1197
|
+
interface FindRouteFilesOptions {
|
|
1198
|
+
/** Directories to ignore */
|
|
1199
|
+
ignore?: string[] | undefined;
|
|
557
1200
|
}
|
|
558
1201
|
|
|
559
1202
|
/**
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
* Provides the plugin system for extending framework functionality.
|
|
1203
|
+
* Compose multiple middleware functions into a single middleware function
|
|
563
1204
|
*/
|
|
1205
|
+
declare function compose(middlewareStack: Middleware[]): MiddlewareFunction;
|
|
564
1206
|
|
|
565
1207
|
/**
|
|
566
|
-
*
|
|
1208
|
+
* Create a middleware
|
|
567
1209
|
*/
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
[key: string]: any;
|
|
571
|
-
}
|
|
1210
|
+
declare function create$2(handlerOrOptions: MiddlewareFunction | MiddlewareOptions): Middleware;
|
|
1211
|
+
|
|
572
1212
|
/**
|
|
573
|
-
*
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
/** Called when the plugin is registered */
|
|
577
|
-
register: (app: Server) => void | Promise<void>;
|
|
578
|
-
/** Called when the server is initialized */
|
|
579
|
-
initialize?: (app?: Server) => void | Promise<void>;
|
|
580
|
-
/** Called when the server is terminated */
|
|
581
|
-
terminate?: (app?: Server) => void | Promise<void>;
|
|
582
|
-
/** Called when the server starts */
|
|
583
|
-
onServerStart?: (server: any) => void | Promise<void>;
|
|
584
|
-
/** Called when the server stops */
|
|
585
|
-
onServerStop?: (server: any) => void | Promise<void>;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Plugin interface
|
|
589
|
-
*/
|
|
590
|
-
interface Plugin extends PluginHooks {
|
|
591
|
-
/** Plugin name */
|
|
592
|
-
name: string;
|
|
593
|
-
/** Plugin version */
|
|
594
|
-
version: string;
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Plugin factory function
|
|
598
|
-
*/
|
|
599
|
-
type PluginFactory<T = any> = (options?: T) => Plugin;
|
|
600
|
-
interface PluginLifecycleManager {
|
|
601
|
-
initializePlugins(server: Server): Promise<void>;
|
|
602
|
-
terminatePlugins(server: Server): Promise<void>;
|
|
603
|
-
onServerStart(server: Server, httpServer: any): Promise<void>;
|
|
604
|
-
onServerStop(server: Server, httpServer: any): Promise<void>;
|
|
605
|
-
}
|
|
606
|
-
interface PluginLifecycleOptions {
|
|
607
|
-
/** Continue initialization even if a plugin fails */
|
|
608
|
-
continueOnError?: boolean;
|
|
609
|
-
/** Log plugin lifecycle events */
|
|
610
|
-
debug?: boolean;
|
|
611
|
-
/** Custom error handler for plugin failures */
|
|
612
|
-
onError?: (plugin: Plugin, phase: string, error: Error) => void;
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
/**
|
|
616
|
-
* BlaizeJS Server Module
|
|
617
|
-
*
|
|
618
|
-
* Provides the core HTTP/2 server implementation with HTTP/1.1 fallback.
|
|
1213
|
+
* BlaizeJS Server Module
|
|
1214
|
+
*
|
|
1215
|
+
* Provides the core HTTP/2 server implementation with HTTP/1.1 fallback.
|
|
619
1216
|
*/
|
|
620
1217
|
|
|
621
1218
|
interface Http2Options {
|
|
@@ -716,6 +1313,454 @@ interface Server {
|
|
|
716
1313
|
}
|
|
717
1314
|
type RequestHandler = (req: http.IncomingMessage | http2.Http2ServerRequest, res: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
|
|
718
1315
|
|
|
1316
|
+
/**
|
|
1317
|
+
* BlaizeJS Plugin Module
|
|
1318
|
+
*
|
|
1319
|
+
* Provides the plugin system for extending framework functionality.
|
|
1320
|
+
*/
|
|
1321
|
+
|
|
1322
|
+
/**
|
|
1323
|
+
* Plugin options
|
|
1324
|
+
*/
|
|
1325
|
+
interface PluginOptions<_T = any> {
|
|
1326
|
+
/** Plugin configuration */
|
|
1327
|
+
[key: string]: any;
|
|
1328
|
+
}
|
|
1329
|
+
/**
|
|
1330
|
+
* Plugin lifecycle hooks
|
|
1331
|
+
*/
|
|
1332
|
+
interface PluginHooks {
|
|
1333
|
+
/** Called when the plugin is registered */
|
|
1334
|
+
register: (app: Server) => void | Promise<void>;
|
|
1335
|
+
/** Called when the server is initialized */
|
|
1336
|
+
initialize?: (app?: Server) => void | Promise<void>;
|
|
1337
|
+
/** Called when the server is terminated */
|
|
1338
|
+
terminate?: (app?: Server) => void | Promise<void>;
|
|
1339
|
+
/** Called when the server starts */
|
|
1340
|
+
onServerStart?: (server: any) => void | Promise<void>;
|
|
1341
|
+
/** Called when the server stops */
|
|
1342
|
+
onServerStop?: (server: any) => void | Promise<void>;
|
|
1343
|
+
}
|
|
1344
|
+
/**
|
|
1345
|
+
* Plugin interface
|
|
1346
|
+
*/
|
|
1347
|
+
interface Plugin extends PluginHooks {
|
|
1348
|
+
/** Plugin name */
|
|
1349
|
+
name: string;
|
|
1350
|
+
/** Plugin version */
|
|
1351
|
+
version: string;
|
|
1352
|
+
}
|
|
1353
|
+
/**
|
|
1354
|
+
* Plugin factory function
|
|
1355
|
+
*/
|
|
1356
|
+
type PluginFactory<T = any> = (options?: T) => Plugin;
|
|
1357
|
+
interface PluginLifecycleManager {
|
|
1358
|
+
initializePlugins(server: Server): Promise<void>;
|
|
1359
|
+
terminatePlugins(server: Server): Promise<void>;
|
|
1360
|
+
onServerStart(server: Server, httpServer: any): Promise<void>;
|
|
1361
|
+
onServerStop(server: Server, httpServer: any): Promise<void>;
|
|
1362
|
+
}
|
|
1363
|
+
interface PluginLifecycleOptions {
|
|
1364
|
+
/** Continue initialization even if a plugin fails */
|
|
1365
|
+
continueOnError?: boolean;
|
|
1366
|
+
/** Log plugin lifecycle events */
|
|
1367
|
+
debug?: boolean;
|
|
1368
|
+
/** Custom error handler for plugin failures */
|
|
1369
|
+
onError?: (plugin: Plugin, phase: string, error: Error) => void;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
/**
|
|
1373
|
+
* Create a plugin with the given name, version, and setup function
|
|
1374
|
+
*/
|
|
1375
|
+
declare function create$1<T = any>(name: string, version: string, setup: (app: Server, options: T) => void | Partial<PluginHooks> | Promise<void> | Promise<Partial<PluginHooks>>, defaultOptions?: Partial<T>): PluginFactory<T>;
|
|
1376
|
+
|
|
1377
|
+
/**
|
|
1378
|
+
* Create a GET route
|
|
1379
|
+
*/
|
|
1380
|
+
declare const createGetRoute: CreateGetRoute;
|
|
1381
|
+
/**
|
|
1382
|
+
* Create a POST route
|
|
1383
|
+
*/
|
|
1384
|
+
declare const createPostRoute: CreatePostRoute;
|
|
1385
|
+
/**
|
|
1386
|
+
* Create a PUT route
|
|
1387
|
+
*/
|
|
1388
|
+
declare const createPutRoute: CreatePutRoute;
|
|
1389
|
+
/**
|
|
1390
|
+
* Create a DELETE route
|
|
1391
|
+
*/
|
|
1392
|
+
declare const createDeleteRoute: CreateDeleteRoute;
|
|
1393
|
+
/**
|
|
1394
|
+
* Create a PATCH route
|
|
1395
|
+
*/
|
|
1396
|
+
declare const createPatchRoute: CreatePatchRoute;
|
|
1397
|
+
/**
|
|
1398
|
+
* Create a HEAD route (same signature as GET - no body)
|
|
1399
|
+
*/
|
|
1400
|
+
declare const createHeadRoute: CreateHeadRoute;
|
|
1401
|
+
/**
|
|
1402
|
+
* Create an OPTIONS route (same signature as GET - no body)
|
|
1403
|
+
*/
|
|
1404
|
+
declare const createOptionsRoute: CreateOptionsRoute;
|
|
1405
|
+
|
|
1406
|
+
/**
|
|
1407
|
+
* Creates a BlaizeJS server instance
|
|
1408
|
+
*/
|
|
1409
|
+
declare function create(options?: ServerOptionsInput): Server;
|
|
1410
|
+
|
|
1411
|
+
type ExtractParams<T> = T extends RouteMethodOptions<infer P, any, any, any> ? P extends z.ZodType ? Infer<P> : Record<string, string> : never;
|
|
1412
|
+
type ExtractQuery<T> = T extends RouteMethodOptions<any, infer Q, any, any> ? Q extends z.ZodType ? Infer<Q> : Record<string, string | string[] | undefined> : never;
|
|
1413
|
+
type ExtractBody<T> = T extends RouteMethodOptions<any, any, infer B, any> ? B extends z.ZodType ? Infer<B> : unknown : never;
|
|
1414
|
+
type ExtractResponse<T> = T extends RouteMethodOptions<any, any, any, infer R> ? R extends z.ZodType ? Infer<R> : unknown : never;
|
|
1415
|
+
type ExtractMethod<T> = T extends {
|
|
1416
|
+
GET: any;
|
|
1417
|
+
} ? 'GET' : T extends {
|
|
1418
|
+
POST: any;
|
|
1419
|
+
} ? 'POST' : T extends {
|
|
1420
|
+
PUT: any;
|
|
1421
|
+
} ? 'PUT' : T extends {
|
|
1422
|
+
DELETE: any;
|
|
1423
|
+
} ? 'DELETE' : T extends {
|
|
1424
|
+
PATCH: any;
|
|
1425
|
+
} ? 'PATCH' : T extends {
|
|
1426
|
+
HEAD: any;
|
|
1427
|
+
} ? 'HEAD' : T extends {
|
|
1428
|
+
OPTIONS: any;
|
|
1429
|
+
} ? 'OPTIONS' : never;
|
|
1430
|
+
type BuildRoutesRegistry<TRoutes extends Record<string, any>> = {
|
|
1431
|
+
[Method in ExtractMethod<TRoutes[keyof TRoutes]> as `$${Lowercase<Method>}`]: {
|
|
1432
|
+
[K in keyof TRoutes as ExtractMethod<TRoutes[K]> extends Method ? K : never]: TRoutes[K];
|
|
1433
|
+
};
|
|
1434
|
+
};
|
|
1435
|
+
type GetRouteMethod<TRoute> = TRoute extends {
|
|
1436
|
+
path: string;
|
|
1437
|
+
} ? Omit<TRoute, 'path'>[keyof Omit<TRoute, 'path'>] : never;
|
|
1438
|
+
type CreateClientMethod<TRoute> = GetRouteMethod<TRoute> extends RouteMethodOptions<any, any, any, any> ? (args?: {
|
|
1439
|
+
params?: ExtractParams<GetRouteMethod<TRoute>>;
|
|
1440
|
+
query?: ExtractQuery<GetRouteMethod<TRoute>>;
|
|
1441
|
+
body?: ExtractBody<GetRouteMethod<TRoute>>;
|
|
1442
|
+
}) => Promise<ExtractResponse<GetRouteMethod<TRoute>>> : never;
|
|
1443
|
+
type CreateClient<TRoutes extends Record<string, Record<string, any>>> = {
|
|
1444
|
+
[Method in keyof TRoutes]: {
|
|
1445
|
+
[RouteName in keyof TRoutes[Method]]: CreateClientMethod<TRoutes[Method][RouteName]>;
|
|
1446
|
+
};
|
|
1447
|
+
};
|
|
1448
|
+
interface ClientConfig {
|
|
1449
|
+
baseUrl: string;
|
|
1450
|
+
defaultHeaders?: Record<string, string>;
|
|
1451
|
+
timeout?: number;
|
|
1452
|
+
}
|
|
1453
|
+
interface RequestArgs {
|
|
1454
|
+
params?: Record<string, string>;
|
|
1455
|
+
query?: Record<string, any>;
|
|
1456
|
+
body?: unknown;
|
|
1457
|
+
}
|
|
1458
|
+
interface RequestOptions {
|
|
1459
|
+
method: string;
|
|
1460
|
+
url: string;
|
|
1461
|
+
headers: Record<string, string>;
|
|
1462
|
+
body?: string;
|
|
1463
|
+
timeout: number;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
/**
|
|
1467
|
+
* ValidationError class for request validation failures
|
|
1468
|
+
*
|
|
1469
|
+
* This error is thrown when request validation fails (params, query, body, or response).
|
|
1470
|
+
* It provides structured information about which fields failed validation and why.
|
|
1471
|
+
*/
|
|
1472
|
+
|
|
1473
|
+
/**
|
|
1474
|
+
* Error thrown when request validation fails
|
|
1475
|
+
*
|
|
1476
|
+
* Automatically sets HTTP status to 400 and provides structured
|
|
1477
|
+
* validation error information for better client debugging.
|
|
1478
|
+
*
|
|
1479
|
+
* @example Basic usage:
|
|
1480
|
+
* ```typescript
|
|
1481
|
+
* throw new ValidationError('Email is required');
|
|
1482
|
+
* ```
|
|
1483
|
+
*
|
|
1484
|
+
* @example With detailed field information:
|
|
1485
|
+
* ```typescript
|
|
1486
|
+
* throw new ValidationError('Validation failed', {
|
|
1487
|
+
* fields: [
|
|
1488
|
+
* {
|
|
1489
|
+
* field: 'email',
|
|
1490
|
+
* messages: ['Email is required', 'Email must be valid'],
|
|
1491
|
+
* rejectedValue: '',
|
|
1492
|
+
* expectedType: 'string'
|
|
1493
|
+
* }
|
|
1494
|
+
* ],
|
|
1495
|
+
* errorCount: 1,
|
|
1496
|
+
* section: 'body'
|
|
1497
|
+
* });
|
|
1498
|
+
* ```
|
|
1499
|
+
*/
|
|
1500
|
+
declare class ValidationError extends BlaizeError<ValidationErrorDetails> {
|
|
1501
|
+
/**
|
|
1502
|
+
* Creates a new ValidationError instance
|
|
1503
|
+
*
|
|
1504
|
+
* @param title - Human-readable error message
|
|
1505
|
+
* @param details - Optional structured validation details
|
|
1506
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1507
|
+
*/
|
|
1508
|
+
constructor(title: string, details?: ValidationErrorDetails | undefined, correlationId?: string | undefined);
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* NotFoundError class for resource not found errors
|
|
1513
|
+
*
|
|
1514
|
+
* This error is thrown when a requested resource cannot be found.
|
|
1515
|
+
* It provides context about what resource was being looked for and how.
|
|
1516
|
+
*/
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* Error thrown when a requested resource cannot be found
|
|
1520
|
+
*
|
|
1521
|
+
* Automatically sets HTTP status to 404 and provides context
|
|
1522
|
+
* about the missing resource for better debugging and user experience.
|
|
1523
|
+
*
|
|
1524
|
+
* @example Basic usage:
|
|
1525
|
+
* ```typescript
|
|
1526
|
+
* throw new NotFoundError('User not found');
|
|
1527
|
+
* ```
|
|
1528
|
+
*
|
|
1529
|
+
* @example With resource context:
|
|
1530
|
+
* ```typescript
|
|
1531
|
+
* throw new NotFoundError('User not found', {
|
|
1532
|
+
* resourceType: 'User',
|
|
1533
|
+
* resourceId: 'user-123',
|
|
1534
|
+
* suggestion: 'Check if the user ID is correct'
|
|
1535
|
+
* });
|
|
1536
|
+
* ```
|
|
1537
|
+
*
|
|
1538
|
+
* @example API endpoint not found:
|
|
1539
|
+
* ```typescript
|
|
1540
|
+
* throw new NotFoundError('Endpoint not found', {
|
|
1541
|
+
* path: '/api/v1/unknown',
|
|
1542
|
+
* method: 'GET',
|
|
1543
|
+
* suggestion: 'Check the API documentation'
|
|
1544
|
+
* });
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
declare class NotFoundError extends BlaizeError<NotFoundErrorDetails> {
|
|
1548
|
+
/**
|
|
1549
|
+
* Creates a new NotFoundError instance
|
|
1550
|
+
*
|
|
1551
|
+
* @param title - Human-readable error message
|
|
1552
|
+
* @param details - Optional context about the missing resource
|
|
1553
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1554
|
+
*/
|
|
1555
|
+
constructor(title: string, details?: NotFoundErrorDetails | undefined, correlationId?: string | undefined);
|
|
1556
|
+
}
|
|
1557
|
+
|
|
1558
|
+
/**
|
|
1559
|
+
* UnauthorizedError class for authentication failures
|
|
1560
|
+
*
|
|
1561
|
+
* This error is thrown when authentication is required or has failed.
|
|
1562
|
+
* It provides context about authentication requirements and failure reasons.
|
|
1563
|
+
*/
|
|
1564
|
+
|
|
1565
|
+
/**
|
|
1566
|
+
* Error thrown when authentication is required or has failed
|
|
1567
|
+
*
|
|
1568
|
+
* Automatically sets HTTP status to 401 and provides authentication context.
|
|
1569
|
+
*
|
|
1570
|
+
* @example Basic usage:
|
|
1571
|
+
* ```typescript
|
|
1572
|
+
* throw new UnauthorizedError('Authentication required');
|
|
1573
|
+
* ```
|
|
1574
|
+
*
|
|
1575
|
+
* @example With authentication details:
|
|
1576
|
+
* ```typescript
|
|
1577
|
+
* throw new UnauthorizedError('Token expired', {
|
|
1578
|
+
* reason: 'expired_token',
|
|
1579
|
+
* authScheme: 'Bearer',
|
|
1580
|
+
* loginUrl: '/auth/login'
|
|
1581
|
+
* });
|
|
1582
|
+
* ```
|
|
1583
|
+
*/
|
|
1584
|
+
declare class UnauthorizedError extends BlaizeError<UnauthorizedErrorDetails> {
|
|
1585
|
+
/**
|
|
1586
|
+
* Creates a new UnauthorizedError instance
|
|
1587
|
+
*
|
|
1588
|
+
* @param title - Human-readable error message
|
|
1589
|
+
* @param details - Optional authentication context
|
|
1590
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1591
|
+
*/
|
|
1592
|
+
constructor(title: string, details?: UnauthorizedErrorDetails | undefined, correlationId?: string | undefined);
|
|
1593
|
+
}
|
|
1594
|
+
|
|
1595
|
+
/**
|
|
1596
|
+
* ForbiddenError class for authorization failures
|
|
1597
|
+
*
|
|
1598
|
+
* This error is thrown when a user lacks permission to access a resource.
|
|
1599
|
+
* It provides context about required permissions and access control.
|
|
1600
|
+
*/
|
|
1601
|
+
|
|
1602
|
+
/**
|
|
1603
|
+
* Error thrown when user lacks permission to access a resource
|
|
1604
|
+
*
|
|
1605
|
+
* Automatically sets HTTP status to 403 and provides permission context.
|
|
1606
|
+
*
|
|
1607
|
+
* @example Basic usage:
|
|
1608
|
+
* ```typescript
|
|
1609
|
+
* throw new ForbiddenError('Access denied');
|
|
1610
|
+
* ```
|
|
1611
|
+
*
|
|
1612
|
+
* @example With permission details:
|
|
1613
|
+
* ```typescript
|
|
1614
|
+
* throw new ForbiddenError('Insufficient permissions', {
|
|
1615
|
+
* requiredPermission: 'admin:users:delete',
|
|
1616
|
+
* userPermissions: ['admin:users:read'],
|
|
1617
|
+
* resource: 'user-123',
|
|
1618
|
+
* action: 'delete'
|
|
1619
|
+
* });
|
|
1620
|
+
* ```
|
|
1621
|
+
*/
|
|
1622
|
+
declare class ForbiddenError extends BlaizeError<ForbiddenErrorDetails> {
|
|
1623
|
+
/**
|
|
1624
|
+
* Creates a new ForbiddenError instance
|
|
1625
|
+
*
|
|
1626
|
+
* @param title - Human-readable error message
|
|
1627
|
+
* @param details - Optional permission context
|
|
1628
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1629
|
+
*/
|
|
1630
|
+
constructor(title: string, details?: ForbiddenErrorDetails | undefined, correlationId?: string | undefined);
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
/**
|
|
1634
|
+
* ConflictError class for resource conflicts
|
|
1635
|
+
*
|
|
1636
|
+
* This error is thrown when a resource conflict occurs, such as duplicate keys,
|
|
1637
|
+
* version mismatches, or concurrent modifications.
|
|
1638
|
+
*/
|
|
1639
|
+
|
|
1640
|
+
/**
|
|
1641
|
+
* Error thrown when a resource conflict occurs
|
|
1642
|
+
*
|
|
1643
|
+
* Automatically sets HTTP status to 409 and provides conflict context.
|
|
1644
|
+
*
|
|
1645
|
+
* @example Basic usage:
|
|
1646
|
+
* ```typescript
|
|
1647
|
+
* throw new ConflictError('Email already exists');
|
|
1648
|
+
* ```
|
|
1649
|
+
*
|
|
1650
|
+
* @example With conflict details:
|
|
1651
|
+
* ```typescript
|
|
1652
|
+
* throw new ConflictError('Version conflict', {
|
|
1653
|
+
* conflictType: 'version_mismatch',
|
|
1654
|
+
* currentVersion: '2',
|
|
1655
|
+
* expectedVersion: '1',
|
|
1656
|
+
* resolution: 'Fetch the latest version and retry'
|
|
1657
|
+
* });
|
|
1658
|
+
* ```
|
|
1659
|
+
*/
|
|
1660
|
+
declare class ConflictError extends BlaizeError<ConflictErrorDetails> {
|
|
1661
|
+
/**
|
|
1662
|
+
* Creates a new ConflictError instance
|
|
1663
|
+
*
|
|
1664
|
+
* @param title - Human-readable error message
|
|
1665
|
+
* @param details - Optional conflict context
|
|
1666
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1667
|
+
*/
|
|
1668
|
+
constructor(title: string, details?: ConflictErrorDetails | undefined, correlationId?: string | undefined);
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
/**
|
|
1672
|
+
* RateLimitError class for rate limiting violations
|
|
1673
|
+
*
|
|
1674
|
+
* This error is thrown when rate limits are exceeded.
|
|
1675
|
+
* It provides context about the rate limit and when requests can resume.
|
|
1676
|
+
*/
|
|
1677
|
+
|
|
1678
|
+
/**
|
|
1679
|
+
* Error thrown when rate limits are exceeded
|
|
1680
|
+
*
|
|
1681
|
+
* Automatically sets HTTP status to 429 and provides rate limit context.
|
|
1682
|
+
*
|
|
1683
|
+
* @example Basic usage:
|
|
1684
|
+
* ```typescript
|
|
1685
|
+
* throw new RateLimitError('Too many requests');
|
|
1686
|
+
* ```
|
|
1687
|
+
*
|
|
1688
|
+
* @example With rate limit details:
|
|
1689
|
+
* ```typescript
|
|
1690
|
+
* throw new RateLimitError('Rate limit exceeded', {
|
|
1691
|
+
* limit: 100,
|
|
1692
|
+
* remaining: 0,
|
|
1693
|
+
* retryAfter: 3600,
|
|
1694
|
+
* window: 'hour',
|
|
1695
|
+
* identifier: 'user-123'
|
|
1696
|
+
* });
|
|
1697
|
+
* ```
|
|
1698
|
+
*/
|
|
1699
|
+
declare class RateLimitError extends BlaizeError<RateLimitErrorDetails> {
|
|
1700
|
+
/**
|
|
1701
|
+
* Creates a new RateLimitError instance
|
|
1702
|
+
*
|
|
1703
|
+
* @param title - Human-readable error message
|
|
1704
|
+
* @param details - Optional rate limit context
|
|
1705
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1706
|
+
*/
|
|
1707
|
+
constructor(title: string, details?: RateLimitErrorDetails | undefined, correlationId?: string | undefined);
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* InternalServerError class for server-side errors
|
|
1712
|
+
*
|
|
1713
|
+
* This error is thrown for unexpected server-side errors that are not
|
|
1714
|
+
* the client's fault. It provides debugging context while protecting
|
|
1715
|
+
* sensitive information in production.
|
|
1716
|
+
*/
|
|
1717
|
+
|
|
1718
|
+
/**
|
|
1719
|
+
* Error thrown for internal server errors
|
|
1720
|
+
*
|
|
1721
|
+
* Automatically sets HTTP status to 500 and provides debugging context.
|
|
1722
|
+
* Note: In production, sensitive details should be filtered by error boundary.
|
|
1723
|
+
*
|
|
1724
|
+
* @example Basic usage:
|
|
1725
|
+
* ```typescript
|
|
1726
|
+
* throw new InternalServerError('Something went wrong');
|
|
1727
|
+
* ```
|
|
1728
|
+
*
|
|
1729
|
+
* @example With debugging details:
|
|
1730
|
+
* ```typescript
|
|
1731
|
+
* throw new InternalServerError('Database error', {
|
|
1732
|
+
* originalError: error.message,
|
|
1733
|
+
* component: 'user-service',
|
|
1734
|
+
* operation: 'createUser',
|
|
1735
|
+
* retryable: true
|
|
1736
|
+
* });
|
|
1737
|
+
* ```
|
|
1738
|
+
*
|
|
1739
|
+
* @example Wrapping an existing error:
|
|
1740
|
+
* ```typescript
|
|
1741
|
+
* try {
|
|
1742
|
+
* await database.connect();
|
|
1743
|
+
* } catch (error) {
|
|
1744
|
+
* throw new InternalServerError('Database connection failed', {
|
|
1745
|
+
* originalError: error.message,
|
|
1746
|
+
* stackTrace: error.stack,
|
|
1747
|
+
* component: 'database',
|
|
1748
|
+
* retryable: true
|
|
1749
|
+
* });
|
|
1750
|
+
* }
|
|
1751
|
+
* ```
|
|
1752
|
+
*/
|
|
1753
|
+
declare class InternalServerError extends BlaizeError<InternalServerErrorDetails> {
|
|
1754
|
+
/**
|
|
1755
|
+
* Creates a new InternalServerError instance
|
|
1756
|
+
*
|
|
1757
|
+
* @param title - Human-readable error message
|
|
1758
|
+
* @param details - Optional debugging context
|
|
1759
|
+
* @param correlationId - Optional correlation ID (uses current context if not provided)
|
|
1760
|
+
*/
|
|
1761
|
+
constructor(title: string, details?: InternalServerErrorDetails | undefined, correlationId?: string | undefined);
|
|
1762
|
+
}
|
|
1763
|
+
|
|
719
1764
|
declare const VERSION = "0.1.0";
|
|
720
1765
|
declare const ServerAPI: {
|
|
721
1766
|
createServer: typeof create;
|
|
@@ -736,6 +1781,7 @@ declare const MiddlewareAPI: {
|
|
|
736
1781
|
declare const PluginsAPI: {
|
|
737
1782
|
createPlugin: typeof create$1;
|
|
738
1783
|
};
|
|
1784
|
+
|
|
739
1785
|
declare const Blaize: {
|
|
740
1786
|
createServer: typeof create;
|
|
741
1787
|
createMiddleware: typeof create$2;
|
|
@@ -762,4 +1808,4 @@ declare const Blaize: {
|
|
|
762
1808
|
VERSION: string;
|
|
763
1809
|
};
|
|
764
1810
|
|
|
765
|
-
export { Blaize, type BuildRoutesRegistry, type ClientConfig, type Context, type ContextOptions, type ContextRequest, type ContextResponse, type CreateClient, type CreateContextFn, type CreateDeleteRoute, type CreateGetRoute, type CreateHeadRoute, type CreateOptionsRoute, type CreatePatchRoute, type CreatePostRoute, type CreatePutRoute, type ErrorHandlerOptions, type ExtractBody, type ExtractMethod, type ExtractParams, type ExtractQuery, type ExtractResponse, type GetContextFn, type Http2Options, type HttpMethod, type Infer, type Matcher, type Middleware, MiddlewareAPI, type MiddlewareFunction, type MiddlewareOptions, type NextFunction, type ParsedRoute, type Plugin, type PluginFactory, type PluginHooks, type PluginLifecycleManager, type PluginLifecycleOptions, type PluginOptions, PluginsAPI, type ProcessResponseOptions, type QueryParams, type RequestArgs, type RequestHandler, type RequestOptions, type RequestParams, type Result, type Route, type RouteDefinition, type RouteEntry, type RouteHandler, type RouteMatch, type RouteMethodOptions, type RouteNode, type RouteOptions, type RouteSchema, type Router, RouterAPI, type RouterOptions, type Server, ServerAPI, type ServerOptions, type ServerOptionsInput, type StandardErrorResponse, type StartOptions, type State, type StopOptions, type StreamOptions, type UnifiedRequest, type UnifiedResponse, type UnknownFunction, VERSION, compose, createDeleteRoute, createGetRoute, createHeadRoute, create$2 as createMiddleware, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPostRoute, createPutRoute, create as createServer, Blaize as default };
|
|
1811
|
+
export { Blaize, BlaizeError, type BlaizeErrorResponse, type BodyParseError, type BuildRoutesRegistry, type ClientConfig, ConflictError, type ConflictErrorDetails, type Context, type ContextOptions, type ContextRequest, type ContextResponse, type CreateClient, type CreateContextFn, type CreateDeleteRoute, type CreateGetRoute, type CreateHeadRoute, type CreateOptionsRoute, type CreatePatchRoute, type CreatePostRoute, type CreatePutRoute, type ErrorHandlerOptions, ErrorSeverity, type ErrorTransformContext, ErrorType, type ExtractBody, type ExtractMethod, type ExtractParams, type ExtractQuery, type ExtractResponse, type FileCache, type FindRouteFilesOptions, ForbiddenError, type ForbiddenErrorDetails, type GetContextFn, type Http2Options, type HttpMethod, type Infer, InternalServerError, type InternalServerErrorDetails, type Matcher, type Middleware, MiddlewareAPI, type MiddlewareFunction, type MiddlewareOptions, type MultipartData, type MultipartError, type MultipartLimits, type NetworkErrorContext, type NextFunction, NotFoundError, type NotFoundErrorDetails, type ParseErrorContext, type ParseOptions, type ParseResult, type ParsedRoute, type ParserState, type PayloadTooLargeErrorDetails, type Plugin, type PluginFactory, type PluginHooks, type PluginLifecycleManager, type PluginLifecycleOptions, type PluginOptions, PluginsAPI, type ProcessResponseOptions, type ProcessingConfig, type QueryParams, RateLimitError, type RateLimitErrorDetails, type ReloadMetrics, type RequestArgs, type RequestHandler, type RequestOptions, type RequestParams, type Result, type Route, type RouteDefinition, type RouteEntry, type RouteHandler, type RouteMatch, type RouteMethodOptions, type RouteNode, type RouteOptions, type RouteRegistry, type RouteSchema, type Router, RouterAPI, type RouterOptions, type Server, ServerAPI, type ServerOptions, type ServerOptionsInput, type StandardErrorResponse, type StartOptions, type State, type StopOptions, type StreamOptions, type TimeoutErrorContext, UnauthorizedError, type UnauthorizedErrorDetails, type UnifiedRequest, type UnifiedResponse, type UnknownFunction, type UnsupportedMediaTypeErrorDetails, type UploadProgress, type UploadedFile, VERSION, type ValidationConfig, ValidationError, type ValidationErrorDetails, type ValidationFieldError, type WatchOptions, compose, createDeleteRoute, createGetRoute, createHeadRoute, create$2 as createMiddleware, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPostRoute, createPutRoute, create as createServer, Blaize as default, isBodyParseError };
|