nextrush 2.0.0 → 3.0.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/LICENSE +1 -1
- package/README.md +144 -1231
- package/dist/class.d.ts +3 -0
- package/dist/class.js +60 -0
- package/dist/class.js.map +1 -0
- package/dist/index.d.ts +56 -2283
- package/dist/index.js +58 -9049
- package/dist/index.js.map +1 -1
- package/package.json +68 -100
- package/dist/index.d.mts +0 -2316
- package/dist/index.mjs +0 -9016
- package/dist/index.mjs.map +0 -1
package/dist/index.d.mts
DELETED
|
@@ -1,2316 +0,0 @@
|
|
|
1
|
-
import { IncomingMessage, ServerResponse } from 'node:http';
|
|
2
|
-
import { ParsedUrlQuery } from 'node:querystring';
|
|
3
|
-
import { EventEmitter } from 'node:events';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Custom error classes for NextRush v2
|
|
7
|
-
*
|
|
8
|
-
* @packageDocumentation
|
|
9
|
-
*/
|
|
10
|
-
/**
|
|
11
|
-
* Base error class for NextRush v2
|
|
12
|
-
*/
|
|
13
|
-
declare class NextRushError extends Error {
|
|
14
|
-
readonly statusCode: number;
|
|
15
|
-
readonly code: string;
|
|
16
|
-
readonly isOperational: boolean;
|
|
17
|
-
readonly timestamp: Date;
|
|
18
|
-
constructor(message: string, statusCode?: number, code?: string, isOperational?: boolean);
|
|
19
|
-
/**
|
|
20
|
-
* Create error from HTTP status code
|
|
21
|
-
*/
|
|
22
|
-
static fromStatusCode(statusCode: number, message?: string): NextRushError;
|
|
23
|
-
/**
|
|
24
|
-
* Get error code from status code
|
|
25
|
-
*/
|
|
26
|
-
private static getErrorCode;
|
|
27
|
-
/**
|
|
28
|
-
* Convert error to JSON
|
|
29
|
-
*/
|
|
30
|
-
toJSON(): Record<string, unknown>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Bad Request Error (400)
|
|
34
|
-
*/
|
|
35
|
-
declare class BadRequestError extends NextRushError {
|
|
36
|
-
constructor(message?: string);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Unauthorized Error (401)
|
|
40
|
-
*/
|
|
41
|
-
declare class UnauthorizedError extends NextRushError {
|
|
42
|
-
constructor(message?: string);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Forbidden Error (403)
|
|
46
|
-
*/
|
|
47
|
-
declare class ForbiddenError extends NextRushError {
|
|
48
|
-
constructor(message?: string);
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Not Found Error (404)
|
|
52
|
-
*/
|
|
53
|
-
declare class NotFoundError extends NextRushError {
|
|
54
|
-
constructor(message?: string);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Method Not Allowed Error (405)
|
|
58
|
-
*/
|
|
59
|
-
declare class MethodNotAllowedError extends NextRushError {
|
|
60
|
-
constructor(message?: string);
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Conflict Error (409)
|
|
64
|
-
*/
|
|
65
|
-
declare class ConflictError extends NextRushError {
|
|
66
|
-
constructor(message?: string);
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Unprocessable Entity Error (422)
|
|
70
|
-
*/
|
|
71
|
-
declare class UnprocessableEntityError extends NextRushError {
|
|
72
|
-
constructor(message?: string);
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Too Many Requests Error (429)
|
|
76
|
-
*/
|
|
77
|
-
declare class TooManyRequestsError extends NextRushError {
|
|
78
|
-
constructor(message?: string);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Internal Server Error (500)
|
|
82
|
-
*/
|
|
83
|
-
declare class InternalServerError extends NextRushError {
|
|
84
|
-
constructor(message?: string);
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Service Unavailable Error (503)
|
|
88
|
-
*/
|
|
89
|
-
declare class ServiceUnavailableError extends NextRushError {
|
|
90
|
-
constructor(message?: string);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Validation Error (400)
|
|
94
|
-
*/
|
|
95
|
-
declare class ValidationError extends NextRushError {
|
|
96
|
-
readonly field: string;
|
|
97
|
-
readonly value: unknown;
|
|
98
|
-
constructor(message: string, field?: string, value?: unknown, statusCode?: number);
|
|
99
|
-
/**
|
|
100
|
-
* Create validation error for specific field
|
|
101
|
-
*/
|
|
102
|
-
static forField(field: string, message: string, value?: unknown): ValidationError;
|
|
103
|
-
/**
|
|
104
|
-
* Create validation error for multiple fields
|
|
105
|
-
*/
|
|
106
|
-
static forFields(errors: Array<{
|
|
107
|
-
field: string;
|
|
108
|
-
message: string;
|
|
109
|
-
value?: unknown;
|
|
110
|
-
}>): ValidationError;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Authentication Error (401)
|
|
114
|
-
*/
|
|
115
|
-
declare class AuthenticationError extends NextRushError {
|
|
116
|
-
constructor(message?: string);
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Authorization Error (403)
|
|
120
|
-
*/
|
|
121
|
-
declare class AuthorizationError extends NextRushError {
|
|
122
|
-
constructor(message?: string);
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Database Error (500)
|
|
126
|
-
*/
|
|
127
|
-
declare class DatabaseError extends NextRushError {
|
|
128
|
-
readonly operation: string;
|
|
129
|
-
readonly table: string | undefined;
|
|
130
|
-
constructor(message: string, operation?: string, table?: string, statusCode?: number);
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Network Error (502)
|
|
134
|
-
*/
|
|
135
|
-
declare class NetworkError extends NextRushError {
|
|
136
|
-
readonly host: string;
|
|
137
|
-
readonly port: number;
|
|
138
|
-
constructor(message: string, host: string, port: number);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Timeout Error (408)
|
|
142
|
-
*/
|
|
143
|
-
declare class TimeoutError extends NextRushError {
|
|
144
|
-
constructor(message?: string);
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Rate Limit Error (429)
|
|
148
|
-
*/
|
|
149
|
-
declare class RateLimitError extends NextRushError {
|
|
150
|
-
readonly retryAfter: number;
|
|
151
|
-
constructor(message?: string, retryAfter?: number);
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Error Factory for creating common errors
|
|
155
|
-
*/
|
|
156
|
-
declare class ErrorFactory {
|
|
157
|
-
/**
|
|
158
|
-
* Create validation error
|
|
159
|
-
*/
|
|
160
|
-
static validation(field: string, message: string, value?: unknown): ValidationError;
|
|
161
|
-
/**
|
|
162
|
-
* Create not found error
|
|
163
|
-
*/
|
|
164
|
-
static notFound(resource: string): NotFoundError;
|
|
165
|
-
/**
|
|
166
|
-
* Create unauthorized error
|
|
167
|
-
*/
|
|
168
|
-
static unauthorized(message?: string): AuthenticationError;
|
|
169
|
-
/**
|
|
170
|
-
* Create forbidden error
|
|
171
|
-
*/
|
|
172
|
-
static forbidden(message?: string): AuthorizationError;
|
|
173
|
-
/**
|
|
174
|
-
* Create bad request error
|
|
175
|
-
*/
|
|
176
|
-
static badRequest(message?: string): BadRequestError;
|
|
177
|
-
/**
|
|
178
|
-
* Create conflict error
|
|
179
|
-
*/
|
|
180
|
-
static conflict(message?: string): ConflictError;
|
|
181
|
-
/**
|
|
182
|
-
* Create internal server error
|
|
183
|
-
*/
|
|
184
|
-
static internal(message?: string): InternalServerError;
|
|
185
|
-
/**
|
|
186
|
-
* Create rate limit error
|
|
187
|
-
*/
|
|
188
|
-
static rateLimit(message?: string, retryAfter?: number): RateLimitError;
|
|
189
|
-
/**
|
|
190
|
-
* Create timeout error
|
|
191
|
-
*/
|
|
192
|
-
static timeout(message?: string): TimeoutError;
|
|
193
|
-
/**
|
|
194
|
-
* Create service unavailable error
|
|
195
|
-
*/
|
|
196
|
-
static serviceUnavailable(message?: string): ServiceUnavailableError;
|
|
197
|
-
/**
|
|
198
|
-
* Create database error
|
|
199
|
-
*/
|
|
200
|
-
static database(message: string, operation: string, table?: string): DatabaseError;
|
|
201
|
-
/**
|
|
202
|
-
* Create network error
|
|
203
|
-
*/
|
|
204
|
-
static network(message: string, host: string, port: number): NetworkError;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Exception Filter Interface (NestJS style)
|
|
208
|
-
*/
|
|
209
|
-
interface ExceptionFilter {
|
|
210
|
-
catch(error: Error, ctx: any): void | Promise<void>;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Global Exception Filter
|
|
214
|
-
*/
|
|
215
|
-
declare class GlobalExceptionFilter implements ExceptionFilter {
|
|
216
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Exception Filter for specific error types
|
|
220
|
-
*/
|
|
221
|
-
declare class ValidationExceptionFilter implements ExceptionFilter {
|
|
222
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Exception Filter for authentication errors
|
|
226
|
-
*/
|
|
227
|
-
declare class AuthenticationExceptionFilter implements ExceptionFilter {
|
|
228
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Exception Filter for authorization errors
|
|
232
|
-
*/
|
|
233
|
-
declare class AuthorizationExceptionFilter implements ExceptionFilter {
|
|
234
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Exception Filter for not found errors
|
|
238
|
-
*/
|
|
239
|
-
declare class NotFoundExceptionFilter implements ExceptionFilter {
|
|
240
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Exception Filter for rate limit errors
|
|
244
|
-
*/
|
|
245
|
-
declare class RateLimitExceptionFilter implements ExceptionFilter {
|
|
246
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 🔧 Enhanced parser configuration with enterprise-grade settings
|
|
251
|
-
*/
|
|
252
|
-
interface EnhancedBodyParserOptions {
|
|
253
|
-
/** Maximum body size in bytes (default: 10MB) */
|
|
254
|
-
maxSize?: number;
|
|
255
|
-
/** Request timeout in milliseconds (default: 5s) */
|
|
256
|
-
timeout?: number;
|
|
257
|
-
/** Enable streaming for large payloads (default: true) */
|
|
258
|
-
enableStreaming?: boolean;
|
|
259
|
-
/** Streaming threshold in bytes (default: 50MB) */
|
|
260
|
-
streamingThreshold?: number;
|
|
261
|
-
/** Buffer pool size for optimization (default: 100) */
|
|
262
|
-
poolSize?: number;
|
|
263
|
-
/** Enable fast validation (default: true) */
|
|
264
|
-
fastValidation?: boolean;
|
|
265
|
-
/** Auto-detect content type (default: true) */
|
|
266
|
-
autoDetectContentType?: boolean;
|
|
267
|
-
/** Strict content type checking (default: false) */
|
|
268
|
-
strictContentType?: boolean;
|
|
269
|
-
/** Enable metrics collection (default: true) */
|
|
270
|
-
enableMetrics?: boolean;
|
|
271
|
-
/** Encoding for text-based content (default: 'utf8') */
|
|
272
|
-
encoding?: BufferEncoding;
|
|
273
|
-
/** Custom error messages */
|
|
274
|
-
errorMessages?: {
|
|
275
|
-
maxSizeExceeded?: string;
|
|
276
|
-
timeoutError?: string;
|
|
277
|
-
invalidContentType?: string;
|
|
278
|
-
parseError?: string;
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Middleware Types for NextRush v2
|
|
284
|
-
*
|
|
285
|
-
* @packageDocumentation
|
|
286
|
-
*/
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* Standard middleware function signature
|
|
290
|
-
*/
|
|
291
|
-
type Middleware$1 = (ctx: Context, next: () => Promise<void>) => Promise<void>;
|
|
292
|
-
/**
|
|
293
|
-
* CORS middleware options
|
|
294
|
-
*/
|
|
295
|
-
interface CorsOptions {
|
|
296
|
-
/** Allowed origins */
|
|
297
|
-
origin?: string | string[] | boolean | ((origin: string) => boolean);
|
|
298
|
-
/** Allowed methods */
|
|
299
|
-
methods?: string[];
|
|
300
|
-
/** Allowed headers */
|
|
301
|
-
allowedHeaders?: string[];
|
|
302
|
-
/** Exposed headers */
|
|
303
|
-
exposedHeaders?: string[];
|
|
304
|
-
/** Allow credentials */
|
|
305
|
-
credentials?: boolean;
|
|
306
|
-
/** Max age for preflight */
|
|
307
|
-
maxAge?: number;
|
|
308
|
-
/** Preflight continue */
|
|
309
|
-
preflightContinue?: boolean;
|
|
310
|
-
/** Options success status */
|
|
311
|
-
optionsSuccessStatus?: number;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Helmet middleware options
|
|
315
|
-
*/
|
|
316
|
-
interface HelmetOptions {
|
|
317
|
-
/** Content Security Policy */
|
|
318
|
-
contentSecurityPolicy?: {
|
|
319
|
-
directives: Record<string, string[]>;
|
|
320
|
-
reportOnly?: boolean;
|
|
321
|
-
};
|
|
322
|
-
/** HTTP Strict Transport Security */
|
|
323
|
-
hsts?: {
|
|
324
|
-
maxAge: number;
|
|
325
|
-
includeSubDomains?: boolean;
|
|
326
|
-
preload?: boolean;
|
|
327
|
-
};
|
|
328
|
-
/** XSS Protection */
|
|
329
|
-
xssFilter?: boolean;
|
|
330
|
-
/** Content Type Options */
|
|
331
|
-
noSniff?: boolean;
|
|
332
|
-
/** Frame Options */
|
|
333
|
-
frameguard?: {
|
|
334
|
-
action: 'DENY' | 'SAMEORIGIN' | 'ALLOW-FROM';
|
|
335
|
-
domain?: string;
|
|
336
|
-
};
|
|
337
|
-
/** Referrer Policy */
|
|
338
|
-
referrerPolicy?: {
|
|
339
|
-
policy: string;
|
|
340
|
-
};
|
|
341
|
-
/** Hide X-Powered-By header */
|
|
342
|
-
hidePoweredBy?: boolean;
|
|
343
|
-
/** DNS Prefetch Control */
|
|
344
|
-
dnsPrefetchControl?: {
|
|
345
|
-
allow?: boolean;
|
|
346
|
-
};
|
|
347
|
-
/** IE No Open */
|
|
348
|
-
ieNoOpen?: boolean;
|
|
349
|
-
/** Permitted Cross Domain Policies */
|
|
350
|
-
permittedCrossDomainPolicies?: {
|
|
351
|
-
permittedPolicies?: string;
|
|
352
|
-
};
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Rate limiter options
|
|
356
|
-
*/
|
|
357
|
-
interface RateLimiterOptions {
|
|
358
|
-
/** Time window in milliseconds */
|
|
359
|
-
windowMs?: number;
|
|
360
|
-
/** Maximum requests per window */
|
|
361
|
-
max?: number;
|
|
362
|
-
/** Rate limit message */
|
|
363
|
-
message?: string;
|
|
364
|
-
/** Status code for rate limited requests */
|
|
365
|
-
statusCode?: number;
|
|
366
|
-
/** Include headers */
|
|
367
|
-
headers?: boolean;
|
|
368
|
-
/** Skip successful requests */
|
|
369
|
-
skipSuccessfulRequests?: boolean;
|
|
370
|
-
/** Skip failed requests */
|
|
371
|
-
skipFailedRequests?: boolean;
|
|
372
|
-
/** Key generator function */
|
|
373
|
-
keyGenerator?: (ctx: Context) => string;
|
|
374
|
-
/** Skip function */
|
|
375
|
-
skip?: (ctx: Context) => boolean;
|
|
376
|
-
/** Custom handler */
|
|
377
|
-
handler?: (ctx: Context) => void;
|
|
378
|
-
/** Store implementation */
|
|
379
|
-
store?: {
|
|
380
|
-
get(key: string): {
|
|
381
|
-
count: number;
|
|
382
|
-
resetTime: number;
|
|
383
|
-
} | null;
|
|
384
|
-
increment(key: string): {
|
|
385
|
-
count: number;
|
|
386
|
-
resetTime: number;
|
|
387
|
-
};
|
|
388
|
-
reset(key: string): void;
|
|
389
|
-
clear(): void;
|
|
390
|
-
};
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* Logger middleware options
|
|
394
|
-
*/
|
|
395
|
-
interface LoggerOptions {
|
|
396
|
-
/** Log format */
|
|
397
|
-
format?: 'simple' | 'detailed' | 'json' | 'combined';
|
|
398
|
-
/** Log level */
|
|
399
|
-
level?: 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
|
|
400
|
-
/** Colorize output */
|
|
401
|
-
colorize?: boolean;
|
|
402
|
-
/** Include timestamp */
|
|
403
|
-
timestamp?: boolean;
|
|
404
|
-
/** Show headers */
|
|
405
|
-
showHeaders?: boolean;
|
|
406
|
-
/** Show body */
|
|
407
|
-
showBody?: boolean;
|
|
408
|
-
/** Show query */
|
|
409
|
-
showQuery?: boolean;
|
|
410
|
-
/** Show response time */
|
|
411
|
-
showResponseTime?: boolean;
|
|
412
|
-
/** Show user agent */
|
|
413
|
-
showUserAgent?: boolean;
|
|
414
|
-
/** Show referer */
|
|
415
|
-
showReferer?: boolean;
|
|
416
|
-
/** Show IP */
|
|
417
|
-
showIP?: boolean;
|
|
418
|
-
/** Show method */
|
|
419
|
-
showMethod?: boolean;
|
|
420
|
-
/** Show URL */
|
|
421
|
-
showURL?: boolean;
|
|
422
|
-
/** Show status */
|
|
423
|
-
showStatus?: boolean;
|
|
424
|
-
/** Show response size */
|
|
425
|
-
showResponseSize?: boolean;
|
|
426
|
-
/** Custom format function */
|
|
427
|
-
customFormat?: (ctx: Context, duration: number) => string;
|
|
428
|
-
/** Filter function */
|
|
429
|
-
filter?: (ctx: Context) => boolean;
|
|
430
|
-
/** Output stream */
|
|
431
|
-
stream?: NodeJS.WritableStream;
|
|
432
|
-
}
|
|
433
|
-
/**
|
|
434
|
-
* Compression middleware options
|
|
435
|
-
*/
|
|
436
|
-
interface CompressionOptions {
|
|
437
|
-
/** Compression level (1-9) */
|
|
438
|
-
level?: number;
|
|
439
|
-
/** Minimum size to compress */
|
|
440
|
-
threshold?: number;
|
|
441
|
-
/** Filter function */
|
|
442
|
-
filter?: (ctx: Context) => boolean;
|
|
443
|
-
/** Content types to compress */
|
|
444
|
-
contentType?: string[];
|
|
445
|
-
/** Content types to exclude */
|
|
446
|
-
exclude?: string[];
|
|
447
|
-
/** Enable gzip */
|
|
448
|
-
gzip?: boolean;
|
|
449
|
-
/** Enable deflate */
|
|
450
|
-
deflate?: boolean;
|
|
451
|
-
/** Enable brotli */
|
|
452
|
-
brotli?: boolean;
|
|
453
|
-
/** Window size */
|
|
454
|
-
windowBits?: number;
|
|
455
|
-
/** Memory level */
|
|
456
|
-
memLevel?: number;
|
|
457
|
-
/** Strategy */
|
|
458
|
-
strategy?: number;
|
|
459
|
-
/** Chunk size */
|
|
460
|
-
chunkSize?: number;
|
|
461
|
-
/** Dictionary */
|
|
462
|
-
dictionary?: Buffer;
|
|
463
|
-
/** Enable adaptive compression based on CPU usage */
|
|
464
|
-
adaptive?: boolean;
|
|
465
|
-
/** Maximum CPU usage threshold for adaptive compression (percentage) */
|
|
466
|
-
maxCpuUsage?: number;
|
|
467
|
-
/** Backpressure threshold for skipping compression */
|
|
468
|
-
backpressureThreshold?: number;
|
|
469
|
-
}
|
|
470
|
-
/**
|
|
471
|
-
* Request ID middleware options
|
|
472
|
-
*/
|
|
473
|
-
interface RequestIdOptions {
|
|
474
|
-
/** Request ID header name */
|
|
475
|
-
headerName?: string;
|
|
476
|
-
/** Request ID generator function */
|
|
477
|
-
generator?: () => string;
|
|
478
|
-
/** Add to response headers */
|
|
479
|
-
addResponseHeader?: boolean;
|
|
480
|
-
/** Echo existing header */
|
|
481
|
-
echoHeader?: boolean;
|
|
482
|
-
/** Set in context */
|
|
483
|
-
setInContext?: boolean;
|
|
484
|
-
/** Include in logs */
|
|
485
|
-
includeInLogs?: boolean;
|
|
486
|
-
}
|
|
487
|
-
/**
|
|
488
|
-
* Timer middleware options
|
|
489
|
-
*/
|
|
490
|
-
interface TimerOptions {
|
|
491
|
-
/** Response time header name */
|
|
492
|
-
header?: string;
|
|
493
|
-
/** Number of decimal places */
|
|
494
|
-
digits?: number;
|
|
495
|
-
/** Time unit suffix */
|
|
496
|
-
suffix?: string;
|
|
497
|
-
/** Include start time */
|
|
498
|
-
includeStartTime?: boolean;
|
|
499
|
-
/** Include end time */
|
|
500
|
-
includeEndTime?: boolean;
|
|
501
|
-
/** Include duration */
|
|
502
|
-
includeDuration?: boolean;
|
|
503
|
-
/** Format type */
|
|
504
|
-
format?: 'milliseconds' | 'seconds' | 'microseconds' | 'nanoseconds';
|
|
505
|
-
/** Threshold for logging */
|
|
506
|
-
threshold?: number;
|
|
507
|
-
/** Log slow requests */
|
|
508
|
-
logSlow?: boolean;
|
|
509
|
-
/** Slow request threshold */
|
|
510
|
-
logSlowThreshold?: number;
|
|
511
|
-
/** Custom format function */
|
|
512
|
-
customFormat?: (duration: number) => string;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
/**
|
|
516
|
-
* Cookie options interface with security defaults
|
|
517
|
-
*/
|
|
518
|
-
interface CookieOptions {
|
|
519
|
-
/** Domain for the cookie */
|
|
520
|
-
domain?: string;
|
|
521
|
-
/** Expiration date */
|
|
522
|
-
expires?: Date;
|
|
523
|
-
/** HTTP Only flag (default: true for security) */
|
|
524
|
-
httpOnly?: boolean;
|
|
525
|
-
/** Max age in seconds */
|
|
526
|
-
maxAge?: number;
|
|
527
|
-
/** Path (default: '/') */
|
|
528
|
-
path?: string;
|
|
529
|
-
/** Priority (Low, Medium, High) */
|
|
530
|
-
priority?: 'Low' | 'Medium' | 'High';
|
|
531
|
-
/** SameSite attribute (default: 'Strict') */
|
|
532
|
-
sameSite?: 'Strict' | 'Lax' | 'None' | boolean;
|
|
533
|
-
/** Secure flag (default: true in production) */
|
|
534
|
-
secure?: boolean;
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
/**
|
|
538
|
-
* Application configuration options
|
|
539
|
-
*/
|
|
540
|
-
interface ApplicationOptions {
|
|
541
|
-
/** Port to listen on (default: 3000) */
|
|
542
|
-
port?: number;
|
|
543
|
-
/** Host to bind to (default: 'localhost') */
|
|
544
|
-
host?: string;
|
|
545
|
-
/** Enable debug mode */
|
|
546
|
-
debug?: boolean;
|
|
547
|
-
/** Trust proxy headers */
|
|
548
|
-
trustProxy?: boolean;
|
|
549
|
-
/** Maximum request body size in bytes */
|
|
550
|
-
maxBodySize?: number;
|
|
551
|
-
/** Request timeout in milliseconds */
|
|
552
|
-
timeout?: number;
|
|
553
|
-
/** Enable CORS by default */
|
|
554
|
-
cors?: boolean;
|
|
555
|
-
/** Static files directory */
|
|
556
|
-
static?: string;
|
|
557
|
-
/** Template engine configuration */
|
|
558
|
-
template?: {
|
|
559
|
-
engine: string;
|
|
560
|
-
directory: string;
|
|
561
|
-
};
|
|
562
|
-
/** HTTP keep-alive timeout in milliseconds */
|
|
563
|
-
keepAlive?: number;
|
|
564
|
-
}
|
|
565
|
-
/**
|
|
566
|
-
* Enhanced request object
|
|
567
|
-
*/
|
|
568
|
-
interface NextRushRequest extends IncomingMessage {
|
|
569
|
-
/** Request body */
|
|
570
|
-
body?: unknown;
|
|
571
|
-
/** Route parameters */
|
|
572
|
-
params: Record<string, string>;
|
|
573
|
-
/** Query parameters */
|
|
574
|
-
query: ParsedUrlQuery;
|
|
575
|
-
/** Request path */
|
|
576
|
-
path: string;
|
|
577
|
-
/** Client IP address */
|
|
578
|
-
ip: string;
|
|
579
|
-
/** Request protocol */
|
|
580
|
-
protocol: string;
|
|
581
|
-
/** Whether the request is secure */
|
|
582
|
-
secure: boolean;
|
|
583
|
-
/** Original request URL */
|
|
584
|
-
originalUrl: string;
|
|
585
|
-
}
|
|
586
|
-
/**
|
|
587
|
-
* Enhanced response object
|
|
588
|
-
*/
|
|
589
|
-
interface NextRushResponse$1 extends ServerResponse {
|
|
590
|
-
/** Set response status code */
|
|
591
|
-
status(code: number): NextRushResponse$1;
|
|
592
|
-
/** Send JSON response (fast by default) */
|
|
593
|
-
json(data: unknown): NextRushResponse$1;
|
|
594
|
-
/** Send HTML response */
|
|
595
|
-
html(data: string): NextRushResponse$1;
|
|
596
|
-
/** Send text response */
|
|
597
|
-
text(data: string): NextRushResponse$1;
|
|
598
|
-
/** Send CSV response */
|
|
599
|
-
csv(data: string): NextRushResponse$1;
|
|
600
|
-
/** Send XML response */
|
|
601
|
-
xml(data: string): NextRushResponse$1;
|
|
602
|
-
/** Send file response */
|
|
603
|
-
file(path: string, options?: {
|
|
604
|
-
root?: string;
|
|
605
|
-
}): NextRushResponse$1;
|
|
606
|
-
/** Send file response (alias) */
|
|
607
|
-
sendFile(path: string, options?: {
|
|
608
|
-
root?: string;
|
|
609
|
-
etag?: boolean;
|
|
610
|
-
}): NextRushResponse$1;
|
|
611
|
-
/** Send download response */
|
|
612
|
-
download(path: string, filename?: string): NextRushResponse$1;
|
|
613
|
-
/** Redirect response */
|
|
614
|
-
redirect(url: string, status?: number): NextRushResponse$1;
|
|
615
|
-
/** Set response header */
|
|
616
|
-
set(name: string, value: string | number | string[]): NextRushResponse$1;
|
|
617
|
-
/** Get response header */
|
|
618
|
-
get(name: string): string | number | string[] | undefined;
|
|
619
|
-
/** Remove response header */
|
|
620
|
-
remove(name: string): NextRushResponse$1;
|
|
621
|
-
/** Set response type */
|
|
622
|
-
type(type: string): NextRushResponse$1;
|
|
623
|
-
/** Set response length */
|
|
624
|
-
length(length: number): NextRushResponse$1;
|
|
625
|
-
/** Set response etag */
|
|
626
|
-
etag(etag: string): NextRushResponse$1;
|
|
627
|
-
/** Set response last modified */
|
|
628
|
-
lastModified(date: Date): NextRushResponse$1;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
/**
|
|
632
|
-
* Koa-style context types for NextRush v2
|
|
633
|
-
*
|
|
634
|
-
* @packageDocumentation
|
|
635
|
-
*/
|
|
636
|
-
|
|
637
|
-
/**
|
|
638
|
-
* WebSocket connection interface
|
|
639
|
-
*/
|
|
640
|
-
interface WSConnection {
|
|
641
|
-
/** Unique connection ID */
|
|
642
|
-
id: string;
|
|
643
|
-
/** WebSocket request URL */
|
|
644
|
-
url: string;
|
|
645
|
-
/** Connection alive status */
|
|
646
|
-
isAlive: boolean;
|
|
647
|
-
/** Last pong timestamp */
|
|
648
|
-
lastPong: number;
|
|
649
|
-
/** Send message to client */
|
|
650
|
-
send(data: string | Buffer): void;
|
|
651
|
-
/** Close connection */
|
|
652
|
-
close(code?: number, reason?: string): void;
|
|
653
|
-
/** Join a room */
|
|
654
|
-
join(room: string): void;
|
|
655
|
-
/** Leave a room */
|
|
656
|
-
leave(room: string): void;
|
|
657
|
-
/** Listen for incoming messages */
|
|
658
|
-
onMessage(listener: (data: string | Buffer) => void): void;
|
|
659
|
-
/** Listen for connection close */
|
|
660
|
-
onClose(listener: (code: number, reason: string) => void): void;
|
|
661
|
-
}
|
|
662
|
-
/**
|
|
663
|
-
* WebSocket route handler type
|
|
664
|
-
*/
|
|
665
|
-
type WSHandler = (socket: WSConnection, req: IncomingMessage) => void | Promise<void>;
|
|
666
|
-
/**
|
|
667
|
-
* WebSocket middleware type
|
|
668
|
-
*/
|
|
669
|
-
type WSMiddleware = (socket: WSConnection, req: IncomingMessage, next: () => void) => void | Promise<void>;
|
|
670
|
-
/**
|
|
671
|
-
* WebSocket plugin options
|
|
672
|
-
*/
|
|
673
|
-
interface WebSocketPluginOptions {
|
|
674
|
-
/** Accepted paths (exact or wildcard *) */
|
|
675
|
-
path?: string | string[];
|
|
676
|
-
/** Ping interval in milliseconds */
|
|
677
|
-
heartbeatMs?: number;
|
|
678
|
-
/** Close if no pong within this timeout */
|
|
679
|
-
pongTimeoutMs?: number;
|
|
680
|
-
/** Maximum concurrent connections */
|
|
681
|
-
maxConnections?: number;
|
|
682
|
-
/** Maximum message size in bytes */
|
|
683
|
-
maxMessageSize?: number;
|
|
684
|
-
/** Allowed origins for CORS */
|
|
685
|
-
allowOrigins?: (string | RegExp)[];
|
|
686
|
-
/** Custom client verification */
|
|
687
|
-
verifyClient?: (req: IncomingMessage) => Promise<boolean> | boolean;
|
|
688
|
-
/** Debug mode */
|
|
689
|
-
debug?: boolean;
|
|
690
|
-
}
|
|
691
|
-
/**
|
|
692
|
-
* Enhanced response object with Express-like methods
|
|
693
|
-
*/
|
|
694
|
-
interface NextRushResponse extends ServerResponse {
|
|
695
|
-
/** Send JSON response */
|
|
696
|
-
json(data: unknown): NextRushResponse;
|
|
697
|
-
/** Send HTML response */
|
|
698
|
-
html(data: string): NextRushResponse;
|
|
699
|
-
/** Send text response */
|
|
700
|
-
text(data: string): NextRushResponse;
|
|
701
|
-
/** Send CSV response */
|
|
702
|
-
csv(data: string): NextRushResponse;
|
|
703
|
-
/** Send XML response */
|
|
704
|
-
xml(data: string): NextRushResponse;
|
|
705
|
-
/** Send any data type response */
|
|
706
|
-
send(data: string | Buffer | object): void;
|
|
707
|
-
/** Stream response */
|
|
708
|
-
stream(stream: NodeJS.ReadableStream, contentType?: string): void;
|
|
709
|
-
/** Render HTML from a template string or a template name under viewsDir */
|
|
710
|
-
render(templateOrName: string, data?: Record<string, unknown>, options?: {
|
|
711
|
-
layout?: string;
|
|
712
|
-
}): Promise<void>;
|
|
713
|
-
/** Send file response (alias) */
|
|
714
|
-
file(path: string, options?: {
|
|
715
|
-
root?: string;
|
|
716
|
-
etag?: boolean;
|
|
717
|
-
}): NextRushResponse;
|
|
718
|
-
/** Send file response */
|
|
719
|
-
sendFile(path: string, options?: {
|
|
720
|
-
root?: string;
|
|
721
|
-
etag?: boolean;
|
|
722
|
-
}): NextRushResponse;
|
|
723
|
-
/** Send download response */
|
|
724
|
-
download(path: string, filename?: string): NextRushResponse;
|
|
725
|
-
/** Redirect response */
|
|
726
|
-
redirect(url: string, status?: number): NextRushResponse;
|
|
727
|
-
/** Permanent redirect (301) */
|
|
728
|
-
redirectPermanent(url: string): NextRushResponse;
|
|
729
|
-
/** Temporary redirect (307) */
|
|
730
|
-
redirectTemporary(url: string): NextRushResponse;
|
|
731
|
-
/** Set response status */
|
|
732
|
-
status(code: number): NextRushResponse;
|
|
733
|
-
/** Set response header */
|
|
734
|
-
set(name: string, value: string | number | string[]): NextRushResponse;
|
|
735
|
-
/** Set response header (alias) */
|
|
736
|
-
header(field: string, value: string): NextRushResponse;
|
|
737
|
-
/** Get response header */
|
|
738
|
-
get(name: string): string | number | string[] | undefined;
|
|
739
|
-
/** Remove response header */
|
|
740
|
-
remove(name: string): NextRushResponse;
|
|
741
|
-
/** Remove response header (implementation method) */
|
|
742
|
-
removeHeader(field: string): NextRushResponse;
|
|
743
|
-
/** Set response type */
|
|
744
|
-
type(type: string): NextRushResponse;
|
|
745
|
-
/** Set response length */
|
|
746
|
-
length(length: number): NextRushResponse;
|
|
747
|
-
/** Set response etag */
|
|
748
|
-
etag(etag: string): NextRushResponse;
|
|
749
|
-
/** Set response last modified */
|
|
750
|
-
lastModified(date: Date): NextRushResponse;
|
|
751
|
-
/** Set cookie */
|
|
752
|
-
cookie(name: string, value: string, options?: CookieOptions): NextRushResponse;
|
|
753
|
-
/** Clear cookie */
|
|
754
|
-
clearCookie(name: string, options?: CookieOptions): NextRushResponse;
|
|
755
|
-
/** Set cache headers */
|
|
756
|
-
cache(seconds: number): NextRushResponse;
|
|
757
|
-
/** Disable caching */
|
|
758
|
-
noCache(): NextRushResponse;
|
|
759
|
-
/** Set CORS headers */
|
|
760
|
-
cors(origin?: string): NextRushResponse;
|
|
761
|
-
/** Set security headers */
|
|
762
|
-
security(): NextRushResponse;
|
|
763
|
-
/** Enable compression hint */
|
|
764
|
-
compress(): NextRushResponse;
|
|
765
|
-
/** Send success response */
|
|
766
|
-
success(data: unknown, message?: string): void;
|
|
767
|
-
/** Send error response */
|
|
768
|
-
error(message: string, code?: number, details?: unknown): void;
|
|
769
|
-
/** Send paginated response */
|
|
770
|
-
paginate(data: unknown[], page: number, limit: number, total: number): void;
|
|
771
|
-
/** Get content type from file extension */
|
|
772
|
-
getContentTypeFromExtension(ext: string): string;
|
|
773
|
-
/** Get smart content type from file path */
|
|
774
|
-
getSmartContentType(filePath: string): string;
|
|
775
|
-
/** Generate ETag from stats */
|
|
776
|
-
generateETag(stats: unknown): string;
|
|
777
|
-
/** Convert data to CSV */
|
|
778
|
-
convertToCSV(data: unknown[]): string;
|
|
779
|
-
/** Add timing header */
|
|
780
|
-
time(label?: string): NextRushResponse;
|
|
781
|
-
/** Get nested value from object */
|
|
782
|
-
getNestedValue(obj: unknown, path: string): unknown;
|
|
783
|
-
/** Check if value is truthy */
|
|
784
|
-
isTruthy(value: unknown): boolean;
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
* Koa-style context interface
|
|
788
|
-
*/
|
|
789
|
-
interface Context {
|
|
790
|
-
/** Request object (Express-like) */
|
|
791
|
-
req: NextRushRequest;
|
|
792
|
-
/** Response object (Express-like) */
|
|
793
|
-
res: NextRushResponse;
|
|
794
|
-
/** Request body (Express-like) */
|
|
795
|
-
body: unknown;
|
|
796
|
-
/** Request method */
|
|
797
|
-
method: string;
|
|
798
|
-
/** Request URL */
|
|
799
|
-
url: string;
|
|
800
|
-
/** Request path */
|
|
801
|
-
path: string;
|
|
802
|
-
/** Request headers */
|
|
803
|
-
headers: IncomingMessage['headers'];
|
|
804
|
-
/** Query parameters */
|
|
805
|
-
query: ParsedUrlQuery;
|
|
806
|
-
/** Route parameters */
|
|
807
|
-
params: Record<string, string>;
|
|
808
|
-
/** Request ID for tracing */
|
|
809
|
-
id: string | undefined;
|
|
810
|
-
/** Request ID for logging (alternative to id) */
|
|
811
|
-
requestId?: string;
|
|
812
|
-
/** Request-specific logger */
|
|
813
|
-
logger?: {
|
|
814
|
-
log: (...args: unknown[]) => void;
|
|
815
|
-
error: (...args: unknown[]) => void;
|
|
816
|
-
warn: (...args: unknown[]) => void;
|
|
817
|
-
info: (...args: unknown[]) => void;
|
|
818
|
-
};
|
|
819
|
-
/** State object for middleware communication */
|
|
820
|
-
state: Record<string, unknown>;
|
|
821
|
-
/** Request start time */
|
|
822
|
-
startTime: number;
|
|
823
|
-
/** Get client IP */
|
|
824
|
-
ip: string;
|
|
825
|
-
/** Check if request is secure */
|
|
826
|
-
secure: boolean;
|
|
827
|
-
/** Request protocol */
|
|
828
|
-
protocol: string;
|
|
829
|
-
/** Request hostname */
|
|
830
|
-
hostname: string;
|
|
831
|
-
/** Request host */
|
|
832
|
-
host: string;
|
|
833
|
-
/** Request origin */
|
|
834
|
-
origin: string;
|
|
835
|
-
/** Request href */
|
|
836
|
-
href: string;
|
|
837
|
-
/** Request search */
|
|
838
|
-
search: string;
|
|
839
|
-
/** Request search params */
|
|
840
|
-
searchParams: URLSearchParams;
|
|
841
|
-
/** Response status */
|
|
842
|
-
status: number;
|
|
843
|
-
/** Response headers */
|
|
844
|
-
responseHeaders: Record<string, string | number | string[]>;
|
|
845
|
-
/** Throw an error */
|
|
846
|
-
throw(status: number, message?: string): never;
|
|
847
|
-
/** Assert a condition */
|
|
848
|
-
assert(condition: unknown, status: number, message?: string): asserts condition;
|
|
849
|
-
/** Check if response is fresh */
|
|
850
|
-
fresh(): boolean;
|
|
851
|
-
/** Check if response is stale */
|
|
852
|
-
stale(): boolean;
|
|
853
|
-
/** Check if request is idempotent */
|
|
854
|
-
idempotent(): boolean;
|
|
855
|
-
/** Check if request is cacheable */
|
|
856
|
-
cacheable(): boolean;
|
|
857
|
-
/** Set response header (Koa-style) */
|
|
858
|
-
set(name: string, value: string | number | string[]): void;
|
|
859
|
-
/** Send a file using the enhanced response */
|
|
860
|
-
sendFile(path: string, options?: {
|
|
861
|
-
root?: string;
|
|
862
|
-
etag?: boolean;
|
|
863
|
-
}): void;
|
|
864
|
-
/** Render HTML from a template string or a template name under viewsDir */
|
|
865
|
-
render(templateOrName: string, data?: Record<string, unknown>, options?: {
|
|
866
|
-
layout?: string;
|
|
867
|
-
}): Promise<void>;
|
|
868
|
-
/** Send JSON response (convenience for ctx.res.json) */
|
|
869
|
-
json(data: unknown): void;
|
|
870
|
-
/** Send response data (convenience for ctx.res.send) */
|
|
871
|
-
send(data: string | Buffer | object): void;
|
|
872
|
-
/** Redirect response (convenience for ctx.res.redirect) */
|
|
873
|
-
redirect(url: string, statusCode?: number): void;
|
|
874
|
-
/** Set cookie (convenience for ctx.res.cookie) */
|
|
875
|
-
cookie(name: string, value: string, options?: CookieOptions): NextRushResponse;
|
|
876
|
-
}
|
|
877
|
-
/**
|
|
878
|
-
* Next function for middleware
|
|
879
|
-
*/
|
|
880
|
-
type Next = () => Promise<void>;
|
|
881
|
-
/**
|
|
882
|
-
* Middleware function type
|
|
883
|
-
*/
|
|
884
|
-
type Middleware = (ctx: Context, next: Next) => Promise<void>;
|
|
885
|
-
/**
|
|
886
|
-
* Route handler function type
|
|
887
|
-
*/
|
|
888
|
-
type RouteHandler = (ctx: Context) => Promise<void> | void;
|
|
889
|
-
/** Dotfiles policy for static files */
|
|
890
|
-
type DotfilesPolicy = 'ignore' | 'deny' | 'allow';
|
|
891
|
-
/** Options for StaticFilesPlugin */
|
|
892
|
-
interface StaticFilesOptions {
|
|
893
|
-
/** Absolute directory to serve files from */
|
|
894
|
-
root: string;
|
|
895
|
-
/** URL prefix to mount under, e.g., "/static"; default: '' (root) */
|
|
896
|
-
prefix?: `/${string}` | '';
|
|
897
|
-
/** Default index file to serve for directories; set false to disable */
|
|
898
|
-
index?: string | false;
|
|
899
|
-
/** If true, call next() on 404 instead of sending 404; default: false */
|
|
900
|
-
fallthrough?: boolean;
|
|
901
|
-
/** If true, redirect directory request without trailing slash to slash; default: true */
|
|
902
|
-
redirect?: boolean;
|
|
903
|
-
/** Send Cache-Control max-age seconds; default: 0 (no explicit caching) */
|
|
904
|
-
maxAge?: number;
|
|
905
|
-
/** Add immutable directive to Cache-Control when maxAge > 0; default: false */
|
|
906
|
-
immutable?: boolean;
|
|
907
|
-
/** Control dotfiles serving; default: 'ignore' (404) */
|
|
908
|
-
dotfiles?: DotfilesPolicy;
|
|
909
|
-
/** Additional extensions to try when file not found (e.g., ['.html']); default: [] */
|
|
910
|
-
extensions?: string[];
|
|
911
|
-
/** Hook to customize headers */
|
|
912
|
-
setHeaders?: (ctx: Context, absolutePath: string, stat: StatsLike) => void;
|
|
913
|
-
}
|
|
914
|
-
/** Stats-like interface for static files */
|
|
915
|
-
interface StatsLike {
|
|
916
|
-
isFile(): boolean;
|
|
917
|
-
isDirectory(): boolean;
|
|
918
|
-
size: number;
|
|
919
|
-
mtime: Date;
|
|
920
|
-
}
|
|
921
|
-
/** Options for TemplatePlugin */
|
|
922
|
-
interface TemplatePluginOptions {
|
|
923
|
-
/** Directory containing template files */
|
|
924
|
-
viewsDir?: string;
|
|
925
|
-
/** Enable template caching; default: true */
|
|
926
|
-
cache?: boolean;
|
|
927
|
-
/** Custom helper functions */
|
|
928
|
-
helpers?: Record<string, (value: unknown, ...args: unknown[]) => unknown>;
|
|
929
|
-
/** Preloaded partial templates */
|
|
930
|
-
partials?: Record<string, string>;
|
|
931
|
-
/** Enable loading partials from viewsDir; default: true */
|
|
932
|
-
enableFilePartials?: boolean;
|
|
933
|
-
/** File extension for partials; default: '.html' */
|
|
934
|
-
partialExt?: string;
|
|
935
|
-
}
|
|
936
|
-
/** Template helper function type */
|
|
937
|
-
type TemplateHelper = (value: unknown, ...args: unknown[]) => unknown;
|
|
938
|
-
/** Template render options */
|
|
939
|
-
interface TemplateRenderOptions {
|
|
940
|
-
/** Layout template to wrap content in */
|
|
941
|
-
layout?: string;
|
|
942
|
-
}
|
|
943
|
-
/**
|
|
944
|
-
* Route configuration object (Fastify-style)
|
|
945
|
-
*/
|
|
946
|
-
interface RouteConfig {
|
|
947
|
-
/** Route handler */
|
|
948
|
-
handler: RouteHandler;
|
|
949
|
-
/** Route middleware */
|
|
950
|
-
middleware?: Middleware[];
|
|
951
|
-
/** Route schema validation */
|
|
952
|
-
schema?: {
|
|
953
|
-
body?: Record<string, unknown>;
|
|
954
|
-
query?: Record<string, unknown>;
|
|
955
|
-
params?: Record<string, unknown>;
|
|
956
|
-
response?: Record<string, unknown>;
|
|
957
|
-
};
|
|
958
|
-
/** Route options */
|
|
959
|
-
options?: {
|
|
960
|
-
/** Route name */
|
|
961
|
-
name?: string;
|
|
962
|
-
/** Route description */
|
|
963
|
-
description?: string;
|
|
964
|
-
/** Route tags */
|
|
965
|
-
tags?: string[];
|
|
966
|
-
/** Route version */
|
|
967
|
-
version?: string;
|
|
968
|
-
/** Route deprecated */
|
|
969
|
-
deprecated?: boolean;
|
|
970
|
-
/** Route summary */
|
|
971
|
-
summary?: string;
|
|
972
|
-
/** Route external docs */
|
|
973
|
-
externalDocs?: {
|
|
974
|
-
description: string;
|
|
975
|
-
url: string;
|
|
976
|
-
};
|
|
977
|
-
};
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* Route data with handler and middleware
|
|
981
|
-
*/
|
|
982
|
-
interface RouteData {
|
|
983
|
-
handler: RouteHandler;
|
|
984
|
-
middleware: Middleware[];
|
|
985
|
-
}
|
|
986
|
-
/**
|
|
987
|
-
* Router interface for modular routing
|
|
988
|
-
*/
|
|
989
|
-
interface Router {
|
|
990
|
-
/** Register GET route */
|
|
991
|
-
get(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
992
|
-
/** Register POST route */
|
|
993
|
-
post(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
994
|
-
/** Register PUT route */
|
|
995
|
-
put(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
996
|
-
/** Register DELETE route */
|
|
997
|
-
delete(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
998
|
-
/** Register PATCH route */
|
|
999
|
-
patch(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
1000
|
-
/** Register middleware */
|
|
1001
|
-
use(middleware: Middleware): Router;
|
|
1002
|
-
/** Register sub-router */
|
|
1003
|
-
use(prefix: string, router: Router): Router;
|
|
1004
|
-
/** Get router middleware */
|
|
1005
|
-
getMiddleware(): Middleware[];
|
|
1006
|
-
/** Get router routes */
|
|
1007
|
-
getRoutes(): Map<string, RouteData>;
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* Application interface (forward declaration)
|
|
1011
|
-
*/
|
|
1012
|
-
interface Application {
|
|
1013
|
-
/** Register GET route */
|
|
1014
|
-
get(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1015
|
-
/** Register POST route */
|
|
1016
|
-
post(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1017
|
-
/** Register PUT route */
|
|
1018
|
-
put(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1019
|
-
/** Register DELETE route */
|
|
1020
|
-
delete(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1021
|
-
/** Register PATCH route */
|
|
1022
|
-
patch(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1023
|
-
/** Register middleware */
|
|
1024
|
-
use(middleware: Middleware): Application;
|
|
1025
|
-
/** Register router */
|
|
1026
|
-
use(prefix: string, router: Router): Application;
|
|
1027
|
-
/** Create router */
|
|
1028
|
-
router(): Router;
|
|
1029
|
-
/** Start the server */
|
|
1030
|
-
listen(port?: number, callback?: () => void): unknown;
|
|
1031
|
-
listen(port?: number, host?: string, callback?: () => void): unknown;
|
|
1032
|
-
/** Get the underlying HTTP server */
|
|
1033
|
-
getServer(): unknown;
|
|
1034
|
-
/** Gracefully shutdown the application */
|
|
1035
|
-
shutdown(): Promise<void>;
|
|
1036
|
-
/** Create CORS middleware */
|
|
1037
|
-
cors(options?: CorsOptions): Middleware;
|
|
1038
|
-
/** Create helmet middleware */
|
|
1039
|
-
helmet(options?: HelmetOptions): Middleware;
|
|
1040
|
-
/** Create JSON body parser middleware */
|
|
1041
|
-
json(options?: EnhancedBodyParserOptions): Middleware;
|
|
1042
|
-
/** Create URL-encoded body parser middleware */
|
|
1043
|
-
urlencoded(options?: EnhancedBodyParserOptions): Middleware;
|
|
1044
|
-
/** Create text body parser middleware */
|
|
1045
|
-
text(options?: EnhancedBodyParserOptions): Middleware;
|
|
1046
|
-
/** Create rate limiter middleware */
|
|
1047
|
-
rateLimit(options?: RateLimiterOptions): Middleware;
|
|
1048
|
-
/** Create logger middleware */
|
|
1049
|
-
logger(options?: LoggerOptions): Middleware;
|
|
1050
|
-
/** Create compression middleware */
|
|
1051
|
-
compression(options?: CompressionOptions): Middleware;
|
|
1052
|
-
/** Create request ID middleware */
|
|
1053
|
-
requestId(options?: RequestIdOptions): Middleware;
|
|
1054
|
-
/** Create timer middleware */
|
|
1055
|
-
timer(options?: TimerOptions): Middleware;
|
|
1056
|
-
/** Create smart body parser middleware */
|
|
1057
|
-
smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
1058
|
-
/** Create exception filter middleware */
|
|
1059
|
-
exceptionFilter(filters?: ExceptionFilter[]): Middleware;
|
|
1060
|
-
/** Simple Events API for Express-style event handling */
|
|
1061
|
-
events: {
|
|
1062
|
-
/** Emit a simple string-based event */
|
|
1063
|
-
emit(eventName: string, data?: any): Promise<void>;
|
|
1064
|
-
/** Listen for a simple string-based event */
|
|
1065
|
-
on(eventName: string, handler: (data: any) => void | Promise<void>): () => void;
|
|
1066
|
-
/** Listen for a simple string-based event (once) */
|
|
1067
|
-
once(eventName: string, handler?: (data: any) => void | Promise<void>): Promise<any>;
|
|
1068
|
-
/** Remove all listeners for an event */
|
|
1069
|
-
off(eventName: string): void;
|
|
1070
|
-
/** Remove all listeners */
|
|
1071
|
-
removeAllListeners(): void;
|
|
1072
|
-
/** Get list of event names that have listeners */
|
|
1073
|
-
eventNames(): string[];
|
|
1074
|
-
/** Get number of listeners for an event */
|
|
1075
|
-
listenerCount(eventName: string): number;
|
|
1076
|
-
/** Get maximum number of listeners */
|
|
1077
|
-
getMaxListeners(): number;
|
|
1078
|
-
/** Set maximum number of listeners */
|
|
1079
|
-
setMaxListeners(n: number): any;
|
|
1080
|
-
};
|
|
1081
|
-
/** Advanced Event System for CQRS and Event Sourcing */
|
|
1082
|
-
eventSystem: {
|
|
1083
|
-
/** Emit events */
|
|
1084
|
-
emit(event: any): Promise<void>;
|
|
1085
|
-
/** Subscribe to events */
|
|
1086
|
-
subscribe(eventType: string, handler: (event: any) => void | Promise<void>): {
|
|
1087
|
-
unsubscribe(): void;
|
|
1088
|
-
};
|
|
1089
|
-
/** Additional advanced methods available but not typed here for brevity */
|
|
1090
|
-
[key: string]: any;
|
|
1091
|
-
};
|
|
1092
|
-
/** Logger instance (set by LoggerPlugin) - overrides logger method when plugin is installed */
|
|
1093
|
-
loggerInstance?: {
|
|
1094
|
-
error: (message: string, context?: Record<string, unknown>) => void;
|
|
1095
|
-
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
1096
|
-
info: (message: string, context?: Record<string, unknown>) => void;
|
|
1097
|
-
debug: (message: string, context?: Record<string, unknown>) => void;
|
|
1098
|
-
trace: (message: string, context?: Record<string, unknown>) => void;
|
|
1099
|
-
log: (message: string, context?: Record<string, unknown>) => void;
|
|
1100
|
-
};
|
|
1101
|
-
/** Register a WebSocket route (exact path or with trailing * wildcard) */
|
|
1102
|
-
ws?: (path: string, handler: WSHandler) => Application;
|
|
1103
|
-
/** Register a WebSocket middleware executed before the handler */
|
|
1104
|
-
wsUse?: (middleware: WSMiddleware) => Application;
|
|
1105
|
-
/** Broadcast a message to all sockets or a specific room */
|
|
1106
|
-
wsBroadcast?: (message: string, room?: string) => Application;
|
|
1107
|
-
/** Register a static files route */
|
|
1108
|
-
static?: (prefix: string, root: string, options?: StaticFilesOptions) => Application;
|
|
1109
|
-
/** Register template engine and view directory */
|
|
1110
|
-
setViewEngine?: (engine: string, viewsDir?: string, options?: TemplatePluginOptions) => Application;
|
|
1111
|
-
/** Add template helper */
|
|
1112
|
-
helper?: (name: string, fn: (value: unknown, ...args: unknown[]) => unknown) => Application;
|
|
1113
|
-
/** Add template partial */
|
|
1114
|
-
partial?: (name: string, template: string) => Application;
|
|
1115
|
-
}
|
|
1116
|
-
|
|
1117
|
-
/**
|
|
1118
|
-
* Base plugin class for NextRush v2
|
|
1119
|
-
*
|
|
1120
|
-
* @packageDocumentation
|
|
1121
|
-
*/
|
|
1122
|
-
|
|
1123
|
-
/**
|
|
1124
|
-
* Plugin interface
|
|
1125
|
-
*/
|
|
1126
|
-
interface Plugin {
|
|
1127
|
-
/** Plugin name */
|
|
1128
|
-
name: string;
|
|
1129
|
-
/** Plugin version */
|
|
1130
|
-
version: string;
|
|
1131
|
-
/** Plugin description */
|
|
1132
|
-
description?: string;
|
|
1133
|
-
/** Plugin author */
|
|
1134
|
-
author?: string;
|
|
1135
|
-
/** Plugin homepage */
|
|
1136
|
-
homepage?: string;
|
|
1137
|
-
/** Plugin license */
|
|
1138
|
-
license?: string;
|
|
1139
|
-
/** Plugin keywords */
|
|
1140
|
-
keywords?: string[];
|
|
1141
|
-
/** Install plugin on application */
|
|
1142
|
-
install(app: Application): void;
|
|
1143
|
-
/** Plugin initialization */
|
|
1144
|
-
init?(): void | Promise<void>;
|
|
1145
|
-
/** Plugin cleanup */
|
|
1146
|
-
cleanup?(): void | Promise<void>;
|
|
1147
|
-
/** Plugin configuration validation */
|
|
1148
|
-
validateConfig?(): boolean;
|
|
1149
|
-
/** Plugin health check */
|
|
1150
|
-
healthCheck?(): Promise<boolean>;
|
|
1151
|
-
}
|
|
1152
|
-
/**
|
|
1153
|
-
* Plugin metadata interface
|
|
1154
|
-
*/
|
|
1155
|
-
interface PluginMetadata {
|
|
1156
|
-
name: string;
|
|
1157
|
-
version: string;
|
|
1158
|
-
description?: string;
|
|
1159
|
-
author?: string;
|
|
1160
|
-
homepage?: string;
|
|
1161
|
-
license?: string;
|
|
1162
|
-
keywords?: string[];
|
|
1163
|
-
dependencies?: string[];
|
|
1164
|
-
conflicts?: string[];
|
|
1165
|
-
}
|
|
1166
|
-
/**
|
|
1167
|
-
* Base plugin class that all plugins should extend
|
|
1168
|
-
*
|
|
1169
|
-
* @example
|
|
1170
|
-
* ```typescript
|
|
1171
|
-
* import { BasePlugin } from 'nextrush-v2';
|
|
1172
|
-
* import type { Application } from 'nextrush-v2';
|
|
1173
|
-
*
|
|
1174
|
-
* export class MyPlugin extends BasePlugin {
|
|
1175
|
-
* name = 'MyPlugin';
|
|
1176
|
-
* version = '1.0.0';
|
|
1177
|
-
* description = 'A custom plugin';
|
|
1178
|
-
*
|
|
1179
|
-
* install(app: Application): void {
|
|
1180
|
-
* // Plugin installation logic
|
|
1181
|
-
* app.use((req, res, next) => {
|
|
1182
|
-
* // Middleware logic
|
|
1183
|
-
* next();
|
|
1184
|
-
* });
|
|
1185
|
-
* }
|
|
1186
|
-
*
|
|
1187
|
-
* async init(): Promise<void> {
|
|
1188
|
-
* // Plugin initialization
|
|
1189
|
-
* }
|
|
1190
|
-
*
|
|
1191
|
-
* async cleanup(): Promise<void> {
|
|
1192
|
-
* // Plugin cleanup
|
|
1193
|
-
* }
|
|
1194
|
-
* }
|
|
1195
|
-
* ```
|
|
1196
|
-
*/
|
|
1197
|
-
declare abstract class BasePlugin implements Plugin {
|
|
1198
|
-
abstract name: string;
|
|
1199
|
-
abstract version: string;
|
|
1200
|
-
abstract onInstall(app: Application): void;
|
|
1201
|
-
description?: string;
|
|
1202
|
-
author?: string;
|
|
1203
|
-
homepage?: string;
|
|
1204
|
-
license?: string;
|
|
1205
|
-
keywords?: string[];
|
|
1206
|
-
dependencies?: string[];
|
|
1207
|
-
conflicts?: string[];
|
|
1208
|
-
protected app?: Application;
|
|
1209
|
-
protected config: Record<string, unknown>;
|
|
1210
|
-
protected isInitialized: boolean;
|
|
1211
|
-
protected isInstalled: boolean;
|
|
1212
|
-
/**
|
|
1213
|
-
* Install the plugin on an application
|
|
1214
|
-
*/
|
|
1215
|
-
install(app: Application): void;
|
|
1216
|
-
/**
|
|
1217
|
-
* Abstract method that plugins must implement
|
|
1218
|
-
*/
|
|
1219
|
-
/**
|
|
1220
|
-
* Get plugin metadata
|
|
1221
|
-
*/
|
|
1222
|
-
getMetadata(): PluginMetadata;
|
|
1223
|
-
/**
|
|
1224
|
-
* Set plugin configuration
|
|
1225
|
-
*/
|
|
1226
|
-
setConfig(config: Record<string, unknown>): void;
|
|
1227
|
-
/**
|
|
1228
|
-
* Get plugin configuration
|
|
1229
|
-
*/
|
|
1230
|
-
getConfig(): Record<string, unknown>;
|
|
1231
|
-
/**
|
|
1232
|
-
* Get a specific configuration value
|
|
1233
|
-
*/
|
|
1234
|
-
getConfigValue<T>(key: string, defaultValue?: T): T | undefined;
|
|
1235
|
-
/**
|
|
1236
|
-
* Check if plugin is installed
|
|
1237
|
-
*/
|
|
1238
|
-
isPluginInstalled(): boolean;
|
|
1239
|
-
/**
|
|
1240
|
-
* Check if plugin is initialized
|
|
1241
|
-
*/
|
|
1242
|
-
isPluginInitialized(): boolean;
|
|
1243
|
-
/**
|
|
1244
|
-
* Register middleware with the application
|
|
1245
|
-
*/
|
|
1246
|
-
protected registerMiddleware(middleware: Middleware): void;
|
|
1247
|
-
/**
|
|
1248
|
-
* Log plugin message
|
|
1249
|
-
*/
|
|
1250
|
-
protected log(message: string): void;
|
|
1251
|
-
/**
|
|
1252
|
-
* Log plugin error
|
|
1253
|
-
*/
|
|
1254
|
-
protected logError(message: string, error?: Error): void;
|
|
1255
|
-
/**
|
|
1256
|
-
* Log plugin warning
|
|
1257
|
-
*/
|
|
1258
|
-
protected logWarning(message: string): void;
|
|
1259
|
-
/**
|
|
1260
|
-
* Log plugin debug message
|
|
1261
|
-
*/
|
|
1262
|
-
protected logDebug(message: string): void;
|
|
1263
|
-
/**
|
|
1264
|
-
* Emit plugin event
|
|
1265
|
-
*/
|
|
1266
|
-
protected emit(event: string, ...args: unknown[]): void;
|
|
1267
|
-
/**
|
|
1268
|
-
* Create a middleware that wraps the plugin's functionality
|
|
1269
|
-
*/
|
|
1270
|
-
protected createMiddleware(handler: (ctx: Context, next: () => Promise<void>) => void | Promise<void>): Middleware;
|
|
1271
|
-
/**
|
|
1272
|
-
* Create an async middleware that wraps the plugin's functionality
|
|
1273
|
-
*/
|
|
1274
|
-
protected createAsyncMiddleware(handler: (ctx: Context, next: () => Promise<void>) => Promise<void>): Middleware;
|
|
1275
|
-
/**
|
|
1276
|
-
* Validate plugin configuration
|
|
1277
|
-
*/
|
|
1278
|
-
validateConfig(): boolean;
|
|
1279
|
-
/**
|
|
1280
|
-
* Plugin health check
|
|
1281
|
-
*/
|
|
1282
|
-
healthCheck(): Promise<boolean>;
|
|
1283
|
-
/**
|
|
1284
|
-
* Get plugin status
|
|
1285
|
-
*/
|
|
1286
|
-
getStatus(): Record<string, unknown>;
|
|
1287
|
-
}
|
|
1288
|
-
|
|
1289
|
-
/**
|
|
1290
|
-
* Logger Types and Interfaces for NextRush v2
|
|
1291
|
-
*
|
|
1292
|
-
* @packageDocumentation
|
|
1293
|
-
*/
|
|
1294
|
-
declare enum LogLevel {
|
|
1295
|
-
ERROR = 0,
|
|
1296
|
-
WARN = 1,
|
|
1297
|
-
INFO = 2,
|
|
1298
|
-
DEBUG = 3,
|
|
1299
|
-
TRACE = 4
|
|
1300
|
-
}
|
|
1301
|
-
interface LogEntry {
|
|
1302
|
-
timestamp: Date | string;
|
|
1303
|
-
level: LogLevel | string;
|
|
1304
|
-
message: string;
|
|
1305
|
-
context?: Record<string, unknown>;
|
|
1306
|
-
error?: Error;
|
|
1307
|
-
}
|
|
1308
|
-
interface LoggerConfig extends Record<string, unknown> {
|
|
1309
|
-
level?: LogLevel;
|
|
1310
|
-
format?: 'json' | 'text' | 'simple';
|
|
1311
|
-
timestamp?: boolean;
|
|
1312
|
-
colors?: boolean;
|
|
1313
|
-
maxEntries?: number;
|
|
1314
|
-
flushInterval?: number;
|
|
1315
|
-
maxMemoryUsage?: number;
|
|
1316
|
-
asyncFlush?: boolean;
|
|
1317
|
-
transports?: Array<{
|
|
1318
|
-
type: 'console' | 'file' | 'stream';
|
|
1319
|
-
options?: Record<string, unknown>;
|
|
1320
|
-
}>;
|
|
1321
|
-
}
|
|
1322
|
-
/**
|
|
1323
|
-
* Transport interface
|
|
1324
|
-
*/
|
|
1325
|
-
interface Transport {
|
|
1326
|
-
name: string;
|
|
1327
|
-
level: string;
|
|
1328
|
-
write(entry: LogEntry): void | Promise<void>;
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
/**
|
|
1332
|
-
* Core Logger Plugin for NextRush v2
|
|
1333
|
-
*
|
|
1334
|
-
* @packageDocumentation
|
|
1335
|
-
*/
|
|
1336
|
-
|
|
1337
|
-
declare class LoggerPlugin extends BasePlugin {
|
|
1338
|
-
name: string;
|
|
1339
|
-
version: string;
|
|
1340
|
-
config: LoggerConfig;
|
|
1341
|
-
private entries;
|
|
1342
|
-
private flushTimer?;
|
|
1343
|
-
private _transports;
|
|
1344
|
-
private eventListeners;
|
|
1345
|
-
constructor(config?: LoggerConfig);
|
|
1346
|
-
onInstall(app: Application): void;
|
|
1347
|
-
private startFlushTimer;
|
|
1348
|
-
private stopFlushTimer;
|
|
1349
|
-
private addEntry;
|
|
1350
|
-
/**
|
|
1351
|
-
* Check memory usage and flush if necessary
|
|
1352
|
-
*/
|
|
1353
|
-
private checkMemoryUsage;
|
|
1354
|
-
private flush;
|
|
1355
|
-
private writeToTransport;
|
|
1356
|
-
/**
|
|
1357
|
-
* Write latest entry to all transports
|
|
1358
|
-
*/
|
|
1359
|
-
private writeToTransports;
|
|
1360
|
-
error(message: string, context?: Record<string, unknown>): void;
|
|
1361
|
-
warn(message: string, context?: Record<string, unknown>): void;
|
|
1362
|
-
info(message: string, context?: Record<string, unknown>): void;
|
|
1363
|
-
debug(message: string, context?: Record<string, unknown>): void;
|
|
1364
|
-
trace(message: string, context?: Record<string, unknown>): void;
|
|
1365
|
-
log(message: string, context?: Record<string, unknown>): void;
|
|
1366
|
-
getEntries(): LogEntry[];
|
|
1367
|
-
clear(): void;
|
|
1368
|
-
setLevel(level: LogLevel | string): void;
|
|
1369
|
-
/**
|
|
1370
|
-
* Add a transport
|
|
1371
|
-
*/
|
|
1372
|
-
addTransport(transport: Transport): void;
|
|
1373
|
-
/**
|
|
1374
|
-
* Remove a transport by name
|
|
1375
|
-
*/
|
|
1376
|
-
removeTransport(name: string): void;
|
|
1377
|
-
/**
|
|
1378
|
-
* Add event listener
|
|
1379
|
-
*/
|
|
1380
|
-
on(event: string, listener: (entry: LogEntry) => void): void;
|
|
1381
|
-
/**
|
|
1382
|
-
* Remove event listener
|
|
1383
|
-
*/
|
|
1384
|
-
off(event: string, listener: (entry: LogEntry) => void): void;
|
|
1385
|
-
/**
|
|
1386
|
-
* Log a message (internal method for testing)
|
|
1387
|
-
*/
|
|
1388
|
-
logMessage(level: LogLevel | string, message: string, context?: Record<string, unknown>): void;
|
|
1389
|
-
/**
|
|
1390
|
-
* Get transports (for testing)
|
|
1391
|
-
*/
|
|
1392
|
-
getTransports(): Transport[];
|
|
1393
|
-
/**
|
|
1394
|
-
* Get transports property (for testing)
|
|
1395
|
-
*/
|
|
1396
|
-
get transports(): Transport[];
|
|
1397
|
-
cleanup(): void;
|
|
1398
|
-
}
|
|
1399
|
-
|
|
1400
|
-
/**
|
|
1401
|
-
* Logger Factory Functions for NextRush v2
|
|
1402
|
-
*
|
|
1403
|
-
* @packageDocumentation
|
|
1404
|
-
*/
|
|
1405
|
-
|
|
1406
|
-
/**
|
|
1407
|
-
* Create minimal logger for testing
|
|
1408
|
-
*/
|
|
1409
|
-
declare function createMinimalLogger(): LoggerPlugin;
|
|
1410
|
-
/**
|
|
1411
|
-
* Create development logger
|
|
1412
|
-
*/
|
|
1413
|
-
declare function createDevLogger(): LoggerPlugin;
|
|
1414
|
-
/**
|
|
1415
|
-
* Create production logger
|
|
1416
|
-
*/
|
|
1417
|
-
declare function createProdLogger(): LoggerPlugin;
|
|
1418
|
-
|
|
1419
|
-
/**
|
|
1420
|
-
* Logger Transport implementations for NextRush v2
|
|
1421
|
-
*
|
|
1422
|
-
* @packageDocumentation
|
|
1423
|
-
*/
|
|
1424
|
-
|
|
1425
|
-
/**
|
|
1426
|
-
* Console Transport
|
|
1427
|
-
*/
|
|
1428
|
-
declare class ConsoleTransport implements Transport {
|
|
1429
|
-
name: string;
|
|
1430
|
-
private _level;
|
|
1431
|
-
private _levelString;
|
|
1432
|
-
constructor(level?: LogLevel | string);
|
|
1433
|
-
get levelString(): string;
|
|
1434
|
-
get level(): string;
|
|
1435
|
-
set level(value: LogLevel | string);
|
|
1436
|
-
write(entry: LogEntry): void;
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* File Transport
|
|
1440
|
-
*/
|
|
1441
|
-
declare class FileTransport implements Transport {
|
|
1442
|
-
name: string;
|
|
1443
|
-
private _level;
|
|
1444
|
-
private filePath;
|
|
1445
|
-
private _levelString;
|
|
1446
|
-
constructor(filePath: string, level?: LogLevel | string);
|
|
1447
|
-
get levelString(): string;
|
|
1448
|
-
get level(): string;
|
|
1449
|
-
set level(value: LogLevel | string);
|
|
1450
|
-
write(entry: LogEntry): Promise<void>;
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* HTTP Transport
|
|
1454
|
-
*/
|
|
1455
|
-
declare class HttpTransport implements Transport {
|
|
1456
|
-
name: string;
|
|
1457
|
-
private _level;
|
|
1458
|
-
private url;
|
|
1459
|
-
private _levelString;
|
|
1460
|
-
constructor(url: string, level?: LogLevel | string);
|
|
1461
|
-
get levelString(): string;
|
|
1462
|
-
get level(): string;
|
|
1463
|
-
set level(value: LogLevel | string);
|
|
1464
|
-
write(entry: LogEntry): Promise<void>;
|
|
1465
|
-
}
|
|
1466
|
-
/**
|
|
1467
|
-
* Stream Transport
|
|
1468
|
-
*/
|
|
1469
|
-
declare class StreamTransport implements Transport {
|
|
1470
|
-
name: string;
|
|
1471
|
-
private _level;
|
|
1472
|
-
private stream;
|
|
1473
|
-
private _levelString;
|
|
1474
|
-
constructor(stream: NodeJS.WritableStream, level?: LogLevel | string);
|
|
1475
|
-
get levelString(): string;
|
|
1476
|
-
get level(): string;
|
|
1477
|
-
set level(value: LogLevel | string);
|
|
1478
|
-
write(entry: LogEntry): void;
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
/**
|
|
1482
|
-
* Core Application class for NextRush v2
|
|
1483
|
-
*
|
|
1484
|
-
* @packageDocumentation
|
|
1485
|
-
*/
|
|
1486
|
-
|
|
1487
|
-
/**
|
|
1488
|
-
* Create a new NextRush application instance
|
|
1489
|
-
*
|
|
1490
|
-
* @param options - Application configuration options
|
|
1491
|
-
* @returns Application instance
|
|
1492
|
-
*
|
|
1493
|
-
* @example
|
|
1494
|
-
* ```typescript
|
|
1495
|
-
* import { createApp } from 'nextrush-v2';
|
|
1496
|
-
*
|
|
1497
|
-
* const app = createApp({
|
|
1498
|
-
* port: 3000,
|
|
1499
|
-
* host: 'localhost',
|
|
1500
|
-
* cors: true,
|
|
1501
|
-
* });
|
|
1502
|
-
*
|
|
1503
|
-
* app.use(app.cors());
|
|
1504
|
-
* app.use(app.helmet());
|
|
1505
|
-
*
|
|
1506
|
-
* app.get('/hello', (ctx) => {
|
|
1507
|
-
* ctx.res.json({ message: 'Hello, World!' });
|
|
1508
|
-
* });
|
|
1509
|
-
*
|
|
1510
|
-
* app.listen(3000, () => {
|
|
1511
|
-
* console.log('Server running on http://localhost:3000');
|
|
1512
|
-
* });
|
|
1513
|
-
* ```
|
|
1514
|
-
*/
|
|
1515
|
-
declare function createApp(options?: ApplicationOptions): Application;
|
|
1516
|
-
|
|
1517
|
-
/**
|
|
1518
|
-
* Context factory for NextRush v2
|
|
1519
|
-
*
|
|
1520
|
-
* @packageDocumentation
|
|
1521
|
-
*/
|
|
1522
|
-
|
|
1523
|
-
/**
|
|
1524
|
-
* Create a Koa-style context object with Express-like design
|
|
1525
|
-
*
|
|
1526
|
-
* @param req - HTTP request object
|
|
1527
|
-
* @param res - HTTP response object
|
|
1528
|
-
* @param options - Application options
|
|
1529
|
-
* @returns Enhanced context object
|
|
1530
|
-
*
|
|
1531
|
-
* @example
|
|
1532
|
-
* ```typescript
|
|
1533
|
-
* import { createContext } from '@/core/context';
|
|
1534
|
-
*
|
|
1535
|
-
* const ctx = createContext(req, res, options);
|
|
1536
|
-
* console.log(ctx.req.ip()); // Client IP
|
|
1537
|
-
* ctx.res.json({ message: 'Hello' });
|
|
1538
|
-
* ```
|
|
1539
|
-
*/
|
|
1540
|
-
declare function createContext(req: IncomingMessage | NextRushRequest, res: ServerResponse | NextRushResponse, _options: Required<ApplicationOptions>): Context;
|
|
1541
|
-
|
|
1542
|
-
/**
|
|
1543
|
-
* Static Files Plugin for NextRush v2
|
|
1544
|
-
*
|
|
1545
|
-
* Express/Koa/Fastify-inspired static file serving with strong DX and security.
|
|
1546
|
-
*
|
|
1547
|
-
* - Prefix-based mounting (virtual path)
|
|
1548
|
-
* - Safe path resolution (prevents traversal)
|
|
1549
|
-
* - ETag/Last-Modified + 304 handling
|
|
1550
|
-
* - Range requests (single range)
|
|
1551
|
-
* - Cache-Control with maxAge/immutable
|
|
1552
|
-
* - HEAD support
|
|
1553
|
-
* - Optional index.html serving and directory redirect
|
|
1554
|
-
* - Dotfiles policy (ignore/deny/allow)
|
|
1555
|
-
* - Optional custom header hook
|
|
1556
|
-
*
|
|
1557
|
-
* @packageDocumentation
|
|
1558
|
-
*/
|
|
1559
|
-
|
|
1560
|
-
/**
|
|
1561
|
-
* StaticFilesPlugin
|
|
1562
|
-
*/
|
|
1563
|
-
declare class StaticFilesPlugin extends BasePlugin {
|
|
1564
|
-
private readonly userOptions;
|
|
1565
|
-
name: string;
|
|
1566
|
-
version: string;
|
|
1567
|
-
description: string;
|
|
1568
|
-
private options;
|
|
1569
|
-
constructor(userOptions: StaticFilesOptions);
|
|
1570
|
-
onInstall(app: Application): void;
|
|
1571
|
-
private normalizeOptions;
|
|
1572
|
-
private createStaticMiddleware;
|
|
1573
|
-
private failOrNext;
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
/**
|
|
1577
|
-
* Template Plugin for NextRush v2
|
|
1578
|
-
*
|
|
1579
|
-
* Safe, minimal, helper-based HTML templating with auto-escaping.
|
|
1580
|
-
*
|
|
1581
|
-
* Features:
|
|
1582
|
-
* - Auto-escape by default; triple mustache {{{expr}}} to output raw
|
|
1583
|
-
* - Helpers: stripHTML, json, upper, lower, date, safe
|
|
1584
|
-
* - Partials: {{> partialName}} (inline or file-based when viewsDir is set)
|
|
1585
|
-
* - Nested path access: {{user.name}}, {{profile.bio}}
|
|
1586
|
-
* - File-based rendering when viewsDir provided; otherwise inline templates
|
|
1587
|
-
* - Simple cache of compiled templates (in-memory)
|
|
1588
|
-
* - Block syntax:
|
|
1589
|
-
* - Conditionals: {{#if cond}}...{{else}}...{{/if}}
|
|
1590
|
-
* - Loops: {{#each items}}...{{/each}} with {{this}}, {{@index}}, {{@key}}
|
|
1591
|
-
* - With: {{#with obj}}...{{/with}}
|
|
1592
|
-
* - Layouts (when viewsDir provided): render(template, data, { layout: 'layout.html' })
|
|
1593
|
-
*/
|
|
1594
|
-
|
|
1595
|
-
declare class TemplatePlugin extends BasePlugin {
|
|
1596
|
-
name: string;
|
|
1597
|
-
version: string;
|
|
1598
|
-
description: string;
|
|
1599
|
-
private engine;
|
|
1600
|
-
constructor(options?: TemplatePluginOptions);
|
|
1601
|
-
onInstall(app: Application): void;
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1604
|
-
declare class WSRoomManager extends EventEmitter {
|
|
1605
|
-
private rooms;
|
|
1606
|
-
add(socket: WSConnection, room: string): void;
|
|
1607
|
-
remove(socket: WSConnection, room: string): void;
|
|
1608
|
-
leaveAll(socket: WSConnection): void;
|
|
1609
|
-
broadcast(room: string, data: string | Buffer, exclude?: WSConnection): void;
|
|
1610
|
-
getRooms(): string[];
|
|
1611
|
-
}
|
|
1612
|
-
|
|
1613
|
-
/**
|
|
1614
|
-
* WebSocket Plugin Type Augmentation
|
|
1615
|
-
*
|
|
1616
|
-
* This file provides type-safe WebSocket functionality through smart type casting
|
|
1617
|
-
* and utility types for perfect TypeScript intelligence.
|
|
1618
|
-
*/
|
|
1619
|
-
|
|
1620
|
-
interface WebSocketApplication extends Application {
|
|
1621
|
-
ws: (path: string, handler: WSHandler) => WebSocketApplication;
|
|
1622
|
-
wsUse: (middleware: WSMiddleware) => WebSocketApplication;
|
|
1623
|
-
wsBroadcast: (message: string, room?: string) => WebSocketApplication;
|
|
1624
|
-
}
|
|
1625
|
-
declare function hasWebSocketSupport(app: Application): app is WebSocketApplication;
|
|
1626
|
-
declare function withWebSocket(app: Application): WebSocketApplication;
|
|
1627
|
-
|
|
1628
|
-
/**
|
|
1629
|
-
* WebSocket Plugin for NextRush v2 - Context-based Architecture
|
|
1630
|
-
* Provides WebSocket functionality through context enhancement
|
|
1631
|
-
*/
|
|
1632
|
-
|
|
1633
|
-
/**
|
|
1634
|
-
* Enhanced Context with WebSocket functionality
|
|
1635
|
-
*/
|
|
1636
|
-
interface WSContext extends Context {
|
|
1637
|
-
/** WebSocket connection (available when request is upgraded) */
|
|
1638
|
-
ws?: WSConnection;
|
|
1639
|
-
/** Check if request is WebSocket upgrade request */
|
|
1640
|
-
isWebSocket: boolean;
|
|
1641
|
-
/** WebSocket room manager */
|
|
1642
|
-
wsRooms: WSRoomManager;
|
|
1643
|
-
}
|
|
1644
|
-
/**
|
|
1645
|
-
* WebSocket Plugin for NextRush v2
|
|
1646
|
-
*
|
|
1647
|
-
* Enhances context with WebSocket functionality following v2 architecture patterns
|
|
1648
|
-
*/
|
|
1649
|
-
declare class WebSocketPlugin extends BasePlugin {
|
|
1650
|
-
name: string;
|
|
1651
|
-
version: string;
|
|
1652
|
-
description: string;
|
|
1653
|
-
private options;
|
|
1654
|
-
private roomManager;
|
|
1655
|
-
private connections;
|
|
1656
|
-
private routes;
|
|
1657
|
-
private middlewares;
|
|
1658
|
-
private heartbeatTimer;
|
|
1659
|
-
constructor(options?: WebSocketPluginOptions);
|
|
1660
|
-
/**
|
|
1661
|
-
* Install WebSocket plugin - adds WebSocket middleware to app
|
|
1662
|
-
*/
|
|
1663
|
-
onInstall(app: Application): void;
|
|
1664
|
-
/**
|
|
1665
|
-
* Start heartbeat timer for connection cleanup
|
|
1666
|
-
*/
|
|
1667
|
-
private startHeartbeat;
|
|
1668
|
-
/**
|
|
1669
|
-
* Cleanup plugin resources
|
|
1670
|
-
*/
|
|
1671
|
-
cleanup(): void;
|
|
1672
|
-
/**
|
|
1673
|
-
* Setup HTTP upgrade event handler
|
|
1674
|
-
*/
|
|
1675
|
-
private setupUpgradeHandler;
|
|
1676
|
-
/**
|
|
1677
|
-
* Handle HTTP to WebSocket upgrade
|
|
1678
|
-
*/
|
|
1679
|
-
private handleUpgrade;
|
|
1680
|
-
/**
|
|
1681
|
-
* Execute WebSocket middlewares
|
|
1682
|
-
*/
|
|
1683
|
-
private executeMiddlewares;
|
|
1684
|
-
/**
|
|
1685
|
-
* Handle WebSocket upgrade in middleware context
|
|
1686
|
-
*/
|
|
1687
|
-
private handleWebSocketUpgrade;
|
|
1688
|
-
/**
|
|
1689
|
-
* Verify WebSocket upgrade request
|
|
1690
|
-
*/
|
|
1691
|
-
private verifyUpgrade;
|
|
1692
|
-
/**
|
|
1693
|
-
* Perform WebSocket handshake
|
|
1694
|
-
*/
|
|
1695
|
-
private performHandshake;
|
|
1696
|
-
/**
|
|
1697
|
-
* Generate WebSocket accept key
|
|
1698
|
-
*/
|
|
1699
|
-
private generateAcceptKey;
|
|
1700
|
-
/**
|
|
1701
|
-
* Check if request is WebSocket upgrade request
|
|
1702
|
-
*/
|
|
1703
|
-
private isWebSocketRequest;
|
|
1704
|
-
/**
|
|
1705
|
-
* Check if path matches registered WebSocket routes
|
|
1706
|
-
*/
|
|
1707
|
-
private matchPath;
|
|
1708
|
-
/**
|
|
1709
|
-
* Reject WebSocket connection
|
|
1710
|
-
*/
|
|
1711
|
-
private rejectConnection;
|
|
1712
|
-
/**
|
|
1713
|
-
* Get all active connections
|
|
1714
|
-
*/
|
|
1715
|
-
getConnections(): WSConnection[];
|
|
1716
|
-
/**
|
|
1717
|
-
* Broadcast message to all connections
|
|
1718
|
-
*/
|
|
1719
|
-
broadcast(message: string, room?: string): void;
|
|
1720
|
-
/**
|
|
1721
|
-
* Get connection statistics
|
|
1722
|
-
*/
|
|
1723
|
-
getStats(): {
|
|
1724
|
-
totalConnections: number;
|
|
1725
|
-
rooms: string[];
|
|
1726
|
-
handlers: number;
|
|
1727
|
-
};
|
|
1728
|
-
}
|
|
1729
|
-
|
|
1730
|
-
/**
|
|
1731
|
-
* 🚀 Smart Body Parser Dispatcher - NextRush v2
|
|
1732
|
-
*
|
|
1733
|
-
* INTELLIGENT CONTENT-TYPE AWARE PARSER LOADER
|
|
1734
|
-
*
|
|
1735
|
-
* 🎯 **PERFORMANCE BREAKTHROUGH:**
|
|
1736
|
-
* - 🔥 Only loads the parser you need based on Content-Type
|
|
1737
|
-
* - ⚡ JSON request → Only loads JSON parser (~150 lines)
|
|
1738
|
-
* - 🌊 Multipart request → Only loads multipart parser (~200 lines)
|
|
1739
|
-
* - 🎭 Form request → Only loads URL-encoded parser (~150 lines)
|
|
1740
|
-
* - 📄 Text request → Only loads text parser (~100 lines)
|
|
1741
|
-
* - 💾 Raw request → Only loads raw parser (~100 lines)
|
|
1742
|
-
*
|
|
1743
|
-
* OLD WAY: Every request loads 1,032 lines ❌
|
|
1744
|
-
* NEW WAY: Each request loads only 100-200 lines ✅
|
|
1745
|
-
*
|
|
1746
|
-
* @author NextRush Framework Team
|
|
1747
|
-
* @version 2.0.0
|
|
1748
|
-
*/
|
|
1749
|
-
|
|
1750
|
-
/**
|
|
1751
|
-
* 🌍 Global smart parser instance (removed unused variable)
|
|
1752
|
-
*/
|
|
1753
|
-
/**
|
|
1754
|
-
* 🚀 Create smart body parser middleware
|
|
1755
|
-
*/
|
|
1756
|
-
declare function smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
1757
|
-
|
|
1758
|
-
/**
|
|
1759
|
-
* Compression middleware for NextRush v2
|
|
1760
|
-
*
|
|
1761
|
-
* @packageDocumentation
|
|
1762
|
-
*/
|
|
1763
|
-
|
|
1764
|
-
/**
|
|
1765
|
-
* Compression middleware factory
|
|
1766
|
-
*/
|
|
1767
|
-
declare function compression(options?: CompressionOptions): Middleware;
|
|
1768
|
-
|
|
1769
|
-
/**
|
|
1770
|
-
* CORS Middleware for NextRush v2
|
|
1771
|
-
*
|
|
1772
|
-
* High-performance CORS implementation with pre-computed headers
|
|
1773
|
-
* and optimized origin checking for enterprise applications.
|
|
1774
|
-
*
|
|
1775
|
-
* @packageDocumentation
|
|
1776
|
-
*/
|
|
1777
|
-
|
|
1778
|
-
/**
|
|
1779
|
-
* Create CORS middleware
|
|
1780
|
-
*
|
|
1781
|
-
* @param options - CORS configuration options
|
|
1782
|
-
* @returns CORS middleware function
|
|
1783
|
-
*
|
|
1784
|
-
* @example
|
|
1785
|
-
* ```typescript
|
|
1786
|
-
* import { createApp } from 'nextrush-v2';
|
|
1787
|
-
* import { cors } from '@/core/middleware';
|
|
1788
|
-
*
|
|
1789
|
-
* const app = createApp();
|
|
1790
|
-
*
|
|
1791
|
-
* // Basic CORS
|
|
1792
|
-
* app.use(cors());
|
|
1793
|
-
*
|
|
1794
|
-
* // Advanced CORS
|
|
1795
|
-
* app.use(cors({
|
|
1796
|
-
* origin: ['https://app.example.com', 'https://admin.example.com'],
|
|
1797
|
-
* credentials: true,
|
|
1798
|
-
* methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
1799
|
-
* allowedHeaders: ['Content-Type', 'Authorization', 'X-API-Key'],
|
|
1800
|
-
* }));
|
|
1801
|
-
* ```
|
|
1802
|
-
*/
|
|
1803
|
-
declare function cors(options?: CorsOptions): Middleware$1;
|
|
1804
|
-
|
|
1805
|
-
/**
|
|
1806
|
-
* Helmet Middleware for NextRush v2
|
|
1807
|
-
*
|
|
1808
|
-
* Provides security headers to protect against common vulnerabilities
|
|
1809
|
-
*
|
|
1810
|
-
* @packageDocumentation
|
|
1811
|
-
*/
|
|
1812
|
-
|
|
1813
|
-
/**
|
|
1814
|
-
* Create Helmet middleware for security headers
|
|
1815
|
-
*
|
|
1816
|
-
* @param options - Helmet configuration options
|
|
1817
|
-
* @returns Helmet middleware function
|
|
1818
|
-
*
|
|
1819
|
-
* @example
|
|
1820
|
-
* ```typescript
|
|
1821
|
-
* import { helmet } from '@/core/middleware/helmet';
|
|
1822
|
-
*
|
|
1823
|
-
* const app = createApp();
|
|
1824
|
-
* app.use(helmet());
|
|
1825
|
-
*
|
|
1826
|
-
* // With custom options
|
|
1827
|
-
* app.use(helmet({
|
|
1828
|
-
* contentSecurityPolicy: {
|
|
1829
|
-
* directives: {
|
|
1830
|
-
* defaultSrc: ["'self'"],
|
|
1831
|
-
* scriptSrc: ["'self'", "'unsafe-inline'"],
|
|
1832
|
-
* },
|
|
1833
|
-
* },
|
|
1834
|
-
* }));
|
|
1835
|
-
* ```
|
|
1836
|
-
*/
|
|
1837
|
-
declare function helmet(options?: HelmetOptions): Middleware$1;
|
|
1838
|
-
|
|
1839
|
-
/**
|
|
1840
|
-
* Logger Middleware for NextRush v2
|
|
1841
|
-
*
|
|
1842
|
-
* Provides request logging functionality
|
|
1843
|
-
*
|
|
1844
|
-
* @packageDocumentation
|
|
1845
|
-
*/
|
|
1846
|
-
|
|
1847
|
-
/**
|
|
1848
|
-
* Create logger middleware
|
|
1849
|
-
*
|
|
1850
|
-
* @param options - Logger configuration options
|
|
1851
|
-
* @returns Logger middleware function
|
|
1852
|
-
*
|
|
1853
|
-
* @example
|
|
1854
|
-
* ```typescript
|
|
1855
|
-
* import { logger } from '@/core/middleware/logger';
|
|
1856
|
-
*
|
|
1857
|
-
* const app = createApp();
|
|
1858
|
-
*
|
|
1859
|
-
* // Basic logging
|
|
1860
|
-
* app.use(logger());
|
|
1861
|
-
*
|
|
1862
|
-
* // Advanced logging
|
|
1863
|
-
* app.use(logger({
|
|
1864
|
-
* format: 'combined',
|
|
1865
|
-
* level: 'info',
|
|
1866
|
-
* colorize: true,
|
|
1867
|
-
* showResponseTime: true,
|
|
1868
|
-
* showUserAgent: true,
|
|
1869
|
-
* }));
|
|
1870
|
-
* ```
|
|
1871
|
-
*/
|
|
1872
|
-
declare function logger(options?: LoggerOptions): Middleware$1;
|
|
1873
|
-
|
|
1874
|
-
/**
|
|
1875
|
-
* Rate Limiter Middleware for NextRush v2
|
|
1876
|
-
*
|
|
1877
|
-
* Provides rate limiting functionality to prevent abuse
|
|
1878
|
-
*
|
|
1879
|
-
* @packageDocumentation
|
|
1880
|
-
*/
|
|
1881
|
-
|
|
1882
|
-
/**
|
|
1883
|
-
* Create rate limiter middleware
|
|
1884
|
-
*
|
|
1885
|
-
* @param options - Rate limiter configuration options
|
|
1886
|
-
* @returns Rate limiter middleware function
|
|
1887
|
-
*
|
|
1888
|
-
* @example
|
|
1889
|
-
* ```typescript
|
|
1890
|
-
* import { rateLimit } from '@/core/middleware/rate-limiter';
|
|
1891
|
-
*
|
|
1892
|
-
* const app = createApp();
|
|
1893
|
-
*
|
|
1894
|
-
* // Basic rate limiting
|
|
1895
|
-
* app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));
|
|
1896
|
-
*
|
|
1897
|
-
* // Advanced rate limiting
|
|
1898
|
-
* app.use(rateLimit({
|
|
1899
|
-
* windowMs: 15 * 60 * 1000,
|
|
1900
|
-
* max: 100,
|
|
1901
|
-
* message: 'Too many requests from this IP',
|
|
1902
|
-
* keyGenerator: (ctx) => ctx.ip,
|
|
1903
|
-
* skip: (ctx) => ctx.path.startsWith('/public'),
|
|
1904
|
-
* }));
|
|
1905
|
-
* ```
|
|
1906
|
-
*/
|
|
1907
|
-
declare function rateLimit(options?: RateLimiterOptions): Middleware$1;
|
|
1908
|
-
|
|
1909
|
-
/**
|
|
1910
|
-
* Request ID Middleware for NextRush v2
|
|
1911
|
-
*
|
|
1912
|
-
* Provides request ID generation and tracking functionality
|
|
1913
|
-
*
|
|
1914
|
-
* @packageDocumentation
|
|
1915
|
-
*/
|
|
1916
|
-
|
|
1917
|
-
/**
|
|
1918
|
-
* Create request ID middleware
|
|
1919
|
-
*
|
|
1920
|
-
* @param options - Request ID configuration options
|
|
1921
|
-
* @returns Request ID middleware function
|
|
1922
|
-
*
|
|
1923
|
-
* @example
|
|
1924
|
-
* ```typescript
|
|
1925
|
-
* import { requestId } from '@/core/middleware/request-id';
|
|
1926
|
-
*
|
|
1927
|
-
* const app = createApp();
|
|
1928
|
-
*
|
|
1929
|
-
* // Basic request ID
|
|
1930
|
-
* app.use(requestId());
|
|
1931
|
-
*
|
|
1932
|
-
* // Advanced request ID
|
|
1933
|
-
* app.use(requestId({
|
|
1934
|
-
* headerName: 'X-Correlation-ID',
|
|
1935
|
-
* generator: () => generateUUID(),
|
|
1936
|
-
* addResponseHeader: true,
|
|
1937
|
-
* echoHeader: true,
|
|
1938
|
-
* }));
|
|
1939
|
-
* ```
|
|
1940
|
-
*/
|
|
1941
|
-
declare function requestId(options?: RequestIdOptions): Middleware$1;
|
|
1942
|
-
|
|
1943
|
-
/**
|
|
1944
|
-
* Timer middleware for NextRush v2
|
|
1945
|
-
*
|
|
1946
|
-
* @packageDocumentation
|
|
1947
|
-
*/
|
|
1948
|
-
|
|
1949
|
-
/**
|
|
1950
|
-
* Create timer middleware
|
|
1951
|
-
*
|
|
1952
|
-
* @param options - Timer configuration options
|
|
1953
|
-
* @returns Timer middleware function
|
|
1954
|
-
*
|
|
1955
|
-
* @example
|
|
1956
|
-
* ```typescript
|
|
1957
|
-
* import { timer } from '@/core/middleware/timer';
|
|
1958
|
-
*
|
|
1959
|
-
* const app = createApp();
|
|
1960
|
-
*
|
|
1961
|
-
* // Basic timer
|
|
1962
|
-
* app.use(timer());
|
|
1963
|
-
*
|
|
1964
|
-
* // Advanced timer
|
|
1965
|
-
* app.use(timer({
|
|
1966
|
-
* header: 'X-Response-Time',
|
|
1967
|
-
* digits: 3,
|
|
1968
|
-
* suffix: 'ms',
|
|
1969
|
-
* logSlow: true,
|
|
1970
|
-
* logSlowThreshold: 1000,
|
|
1971
|
-
* }));
|
|
1972
|
-
* ```
|
|
1973
|
-
*/
|
|
1974
|
-
declare function timer(options?: TimerOptions): Middleware$1;
|
|
1975
|
-
|
|
1976
|
-
/**
|
|
1977
|
-
* Request Enhancer for NextRush v2
|
|
1978
|
-
*
|
|
1979
|
-
* @packageDocumentation
|
|
1980
|
-
*/
|
|
1981
|
-
|
|
1982
|
-
/**
|
|
1983
|
-
* Enhanced request interface with Express-like properties and methods
|
|
1984
|
-
*/
|
|
1985
|
-
interface EnhancedRequest extends IncomingMessage {
|
|
1986
|
-
params: Record<string, string>;
|
|
1987
|
-
query: ParsedUrlQuery;
|
|
1988
|
-
body: unknown;
|
|
1989
|
-
pathname: string;
|
|
1990
|
-
originalUrl: string;
|
|
1991
|
-
path: string;
|
|
1992
|
-
files: Record<string, unknown>;
|
|
1993
|
-
cookies: Record<string, string>;
|
|
1994
|
-
session: Record<string, unknown>;
|
|
1995
|
-
locals: Record<string, unknown>;
|
|
1996
|
-
startTime: number;
|
|
1997
|
-
fresh: boolean;
|
|
1998
|
-
stale: boolean;
|
|
1999
|
-
middlewareStack?: string[];
|
|
2000
|
-
param(name: string): string | undefined;
|
|
2001
|
-
header(name: string): string | undefined;
|
|
2002
|
-
get(name: string): string | undefined;
|
|
2003
|
-
sanitizeObject(obj: unknown, options?: unknown): unknown;
|
|
2004
|
-
getRequestTiming(): unknown;
|
|
2005
|
-
ip: string;
|
|
2006
|
-
secure: boolean;
|
|
2007
|
-
protocol: string;
|
|
2008
|
-
hostname(): string;
|
|
2009
|
-
fullUrl(): string;
|
|
2010
|
-
is(type: string): boolean;
|
|
2011
|
-
accepts(types: string | string[]): string | false;
|
|
2012
|
-
parseCookies(): Record<string, string>;
|
|
2013
|
-
validate(rules: unknown): unknown;
|
|
2014
|
-
sanitize(value: unknown, options?: unknown): unknown;
|
|
2015
|
-
isValidEmail(email: string): boolean;
|
|
2016
|
-
isValidUrl(url: string): boolean;
|
|
2017
|
-
sanitizeValue(value: unknown, rule: unknown): unknown;
|
|
2018
|
-
fingerprint(): string;
|
|
2019
|
-
userAgent(): {
|
|
2020
|
-
raw: string;
|
|
2021
|
-
browser: string;
|
|
2022
|
-
os: string;
|
|
2023
|
-
device: string;
|
|
2024
|
-
isMobile: boolean;
|
|
2025
|
-
isBot: boolean;
|
|
2026
|
-
};
|
|
2027
|
-
timing(): {
|
|
2028
|
-
start: number;
|
|
2029
|
-
duration: number;
|
|
2030
|
-
timestamp: string;
|
|
2031
|
-
};
|
|
2032
|
-
rateLimit(): {
|
|
2033
|
-
limit: number;
|
|
2034
|
-
remaining: number;
|
|
2035
|
-
reset: number;
|
|
2036
|
-
retryAfter: number;
|
|
2037
|
-
};
|
|
2038
|
-
parseBrowser(ua: string): string;
|
|
2039
|
-
parseOS(ua: string): string;
|
|
2040
|
-
parseDevice(ua: string): string;
|
|
2041
|
-
isBot(ua: string): boolean;
|
|
2042
|
-
isMobile(ua: string): boolean;
|
|
2043
|
-
}
|
|
2044
|
-
/**
|
|
2045
|
-
* Request Enhancer class for NextRush v2
|
|
2046
|
-
*
|
|
2047
|
-
* @example
|
|
2048
|
-
* ```typescript
|
|
2049
|
-
* import { RequestEnhancer } from '@/core/enhancers/request-enhancer';
|
|
2050
|
-
*
|
|
2051
|
-
* const enhancedReq = RequestEnhancer.enhance(req);
|
|
2052
|
-
* console.log(enhancedReq.ip()); // Client IP
|
|
2053
|
-
* console.log(enhancedReq.userAgent()); // User agent info
|
|
2054
|
-
* ```
|
|
2055
|
-
*/
|
|
2056
|
-
declare class RequestEnhancer {
|
|
2057
|
-
/**
|
|
2058
|
-
* Enhance a Node.js IncomingMessage with NextRush v2 features
|
|
2059
|
-
*
|
|
2060
|
-
* @param req - The original HTTP request
|
|
2061
|
-
* @returns Enhanced request with additional properties and methods
|
|
2062
|
-
*/
|
|
2063
|
-
static enhance(req: IncomingMessage): EnhancedRequest;
|
|
2064
|
-
}
|
|
2065
|
-
|
|
2066
|
-
/**
|
|
2067
|
-
* Response Enhancer for NextRush v2
|
|
2068
|
-
*
|
|
2069
|
-
* @packageDocumentation
|
|
2070
|
-
*/
|
|
2071
|
-
|
|
2072
|
-
/**
|
|
2073
|
-
* File options interface
|
|
2074
|
-
*/
|
|
2075
|
-
interface FileOptions {
|
|
2076
|
-
etag?: boolean;
|
|
2077
|
-
root?: string;
|
|
2078
|
-
}
|
|
2079
|
-
/**
|
|
2080
|
-
* Enhanced response interface with Express-like methods
|
|
2081
|
-
*/
|
|
2082
|
-
interface EnhancedResponse extends ServerResponse {
|
|
2083
|
-
locals: Record<string, unknown>;
|
|
2084
|
-
status(code: number): EnhancedResponse;
|
|
2085
|
-
json(data: unknown): void;
|
|
2086
|
-
send(data: string | Buffer | object): void;
|
|
2087
|
-
html(data: string): void;
|
|
2088
|
-
text(data: string): void;
|
|
2089
|
-
xml(data: string): void;
|
|
2090
|
-
csv(data: unknown[], filename?: string): void;
|
|
2091
|
-
stream(stream: NodeJS.ReadableStream, contentType?: string): void;
|
|
2092
|
-
sendFile(filePath: string, options?: FileOptions): void;
|
|
2093
|
-
file(filePath: string, options?: FileOptions): EnhancedResponse;
|
|
2094
|
-
download(filePath: string, filename?: string, options?: FileOptions): void;
|
|
2095
|
-
getSmartContentType(filePath: string): string;
|
|
2096
|
-
generateETag(stats: unknown): string;
|
|
2097
|
-
redirect(url: string, status?: number): void;
|
|
2098
|
-
redirectPermanent(url: string): void;
|
|
2099
|
-
redirectTemporary(url: string): void;
|
|
2100
|
-
set(field: string | Record<string, string>, value?: string): EnhancedResponse;
|
|
2101
|
-
header(field: string, value: string): EnhancedResponse;
|
|
2102
|
-
removeHeader(field: string): EnhancedResponse;
|
|
2103
|
-
remove(field: string): EnhancedResponse;
|
|
2104
|
-
get(field: string): string | undefined;
|
|
2105
|
-
type(type: string): EnhancedResponse;
|
|
2106
|
-
length(length: number): EnhancedResponse;
|
|
2107
|
-
etag(etag: string): EnhancedResponse;
|
|
2108
|
-
lastModified(date: Date): EnhancedResponse;
|
|
2109
|
-
cookie(name: string, value: string, options?: CookieOptions): EnhancedResponse;
|
|
2110
|
-
clearCookie(name: string, options?: CookieOptions): EnhancedResponse;
|
|
2111
|
-
render(template: string, data?: unknown): void;
|
|
2112
|
-
getNestedValue(obj: unknown, path: string): unknown;
|
|
2113
|
-
isTruthy(value: unknown): boolean;
|
|
2114
|
-
cache(seconds: number): EnhancedResponse;
|
|
2115
|
-
noCache(): EnhancedResponse;
|
|
2116
|
-
cors(origin?: string): EnhancedResponse;
|
|
2117
|
-
security(): EnhancedResponse;
|
|
2118
|
-
compress(): EnhancedResponse;
|
|
2119
|
-
success(data: unknown, message?: string): void;
|
|
2120
|
-
error(message: string, code?: number, details?: unknown): void;
|
|
2121
|
-
paginate(data: unknown[], page: number, limit: number, total: number): void;
|
|
2122
|
-
getContentTypeFromExtension(ext: string): string;
|
|
2123
|
-
convertToCSV(data: unknown[]): string;
|
|
2124
|
-
time(label?: string): EnhancedResponse;
|
|
2125
|
-
}
|
|
2126
|
-
/**
|
|
2127
|
-
* Response Enhancer class for NextRush v2
|
|
2128
|
-
*
|
|
2129
|
-
* @example
|
|
2130
|
-
* ```typescript
|
|
2131
|
-
* import { ResponseEnhancer } from '@/core/enhancers/response-enhancer';
|
|
2132
|
-
*
|
|
2133
|
-
* const enhancedRes = ResponseEnhancer.enhance(res);
|
|
2134
|
-
* enhancedRes.json({ message: 'Hello World' });
|
|
2135
|
-
* ```
|
|
2136
|
-
*/
|
|
2137
|
-
declare class ResponseEnhancer {
|
|
2138
|
-
/**
|
|
2139
|
-
* Enhance a Node.js ServerResponse with NextRush v2 features
|
|
2140
|
-
*
|
|
2141
|
-
* @param res - The original HTTP response
|
|
2142
|
-
* @returns Enhanced response with additional methods
|
|
2143
|
-
*/
|
|
2144
|
-
static enhance(res: ServerResponse): EnhancedResponse;
|
|
2145
|
-
}
|
|
2146
|
-
|
|
2147
|
-
/**
|
|
2148
|
-
* Optimized Radix Tree Router for NextRush v2
|
|
2149
|
-
*
|
|
2150
|
-
* High-performance router with O(k) lookup performance
|
|
2151
|
-
* where k is path length, not route count.
|
|
2152
|
-
*
|
|
2153
|
-
* Performance optimizations:
|
|
2154
|
-
* - Zero-copy path splitting
|
|
2155
|
-
* - LRU cache for frequent paths
|
|
2156
|
-
* - Iterative traversal (no recursion)
|
|
2157
|
-
* - Pre-allocated parameter objects
|
|
2158
|
-
* - Optimized parameter matching
|
|
2159
|
-
*
|
|
2160
|
-
* @packageDocumentation
|
|
2161
|
-
*/
|
|
2162
|
-
|
|
2163
|
-
/**
|
|
2164
|
-
* Route match result with pre-allocated parameter object
|
|
2165
|
-
*/
|
|
2166
|
-
interface OptimizedRouteMatch {
|
|
2167
|
-
handler: RouteHandler;
|
|
2168
|
-
middleware: Middleware[];
|
|
2169
|
-
params: Record<string, string>;
|
|
2170
|
-
path: string;
|
|
2171
|
-
compiled?: (ctx: any) => Promise<void>;
|
|
2172
|
-
}
|
|
2173
|
-
/**
|
|
2174
|
-
* Optimized Router class with performance improvements
|
|
2175
|
-
*/
|
|
2176
|
-
declare class OptimizedRouter implements Router {
|
|
2177
|
-
private root;
|
|
2178
|
-
private middleware;
|
|
2179
|
-
private prefix;
|
|
2180
|
-
private cache;
|
|
2181
|
-
private paramPool;
|
|
2182
|
-
private maxPoolSize;
|
|
2183
|
-
private poolHits;
|
|
2184
|
-
private poolMisses;
|
|
2185
|
-
private readonly staticRoutes;
|
|
2186
|
-
constructor(prefix?: string, cacheSize?: number);
|
|
2187
|
-
/**
|
|
2188
|
-
* Optimized parameter object management
|
|
2189
|
-
*/
|
|
2190
|
-
private getParamObject;
|
|
2191
|
-
/**
|
|
2192
|
-
* Get pool statistics for monitoring
|
|
2193
|
-
*/
|
|
2194
|
-
private getPoolStats;
|
|
2195
|
-
/**
|
|
2196
|
-
* Register a GET route
|
|
2197
|
-
*/
|
|
2198
|
-
get(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2199
|
-
/**
|
|
2200
|
-
* Register a POST route
|
|
2201
|
-
*/
|
|
2202
|
-
post(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2203
|
-
/**
|
|
2204
|
-
* Register a PUT route
|
|
2205
|
-
*/
|
|
2206
|
-
put(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2207
|
-
/**
|
|
2208
|
-
* Register a DELETE route
|
|
2209
|
-
*/
|
|
2210
|
-
delete(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2211
|
-
/**
|
|
2212
|
-
* Register a PATCH route
|
|
2213
|
-
*/
|
|
2214
|
-
patch(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2215
|
-
/**
|
|
2216
|
-
* Use middleware or create sub-router
|
|
2217
|
-
*/
|
|
2218
|
-
use(middlewareOrPrefix: string | Middleware, router?: Router): OptimizedRouter;
|
|
2219
|
-
/**
|
|
2220
|
-
* Get all registered routes for sub-router integration
|
|
2221
|
-
*/
|
|
2222
|
-
getRoutes(): Map<string, RouteData>;
|
|
2223
|
-
/**
|
|
2224
|
-
* Get router middleware
|
|
2225
|
-
*/
|
|
2226
|
-
getMiddleware(): Middleware[];
|
|
2227
|
-
/**
|
|
2228
|
-
* 🔥 Inject compiled handler for a route (used by compiler)
|
|
2229
|
-
* This allows the pre-compilation system to inject optimized handlers
|
|
2230
|
-
*/
|
|
2231
|
-
setCompiledHandler(method: string, pattern: string, compiledExecute: (ctx: any) => Promise<void>): void;
|
|
2232
|
-
/**
|
|
2233
|
-
* Get comprehensive cache and performance statistics
|
|
2234
|
-
*/
|
|
2235
|
-
getCacheStats(): {
|
|
2236
|
-
cache: {
|
|
2237
|
-
size: number;
|
|
2238
|
-
hitRate: number;
|
|
2239
|
-
hits: number;
|
|
2240
|
-
misses: number;
|
|
2241
|
-
};
|
|
2242
|
-
pool: {
|
|
2243
|
-
poolSize: number;
|
|
2244
|
-
maxSize: number;
|
|
2245
|
-
hits: number;
|
|
2246
|
-
misses: number;
|
|
2247
|
-
hitRate: number;
|
|
2248
|
-
};
|
|
2249
|
-
performance: {
|
|
2250
|
-
totalRoutes: number;
|
|
2251
|
-
pathCacheSize: number;
|
|
2252
|
-
};
|
|
2253
|
-
};
|
|
2254
|
-
/**
|
|
2255
|
-
* Get total number of registered routes
|
|
2256
|
-
*/
|
|
2257
|
-
private getTotalRoutes;
|
|
2258
|
-
/**
|
|
2259
|
-
* Clear the route cache
|
|
2260
|
-
*/
|
|
2261
|
-
clearCache(): void;
|
|
2262
|
-
/**
|
|
2263
|
-
* Ultra-fast route finder with aggressive optimizations
|
|
2264
|
-
*/
|
|
2265
|
-
find(method: string, path: string): OptimizedRouteMatch | null;
|
|
2266
|
-
/**
|
|
2267
|
-
* Hyper-optimized internal finder with minimal allocations
|
|
2268
|
-
*/
|
|
2269
|
-
private findInternalOptimized;
|
|
2270
|
-
/**
|
|
2271
|
-
* Optimized route registration with O(k) insertion
|
|
2272
|
-
*/
|
|
2273
|
-
private registerRoute;
|
|
2274
|
-
/**
|
|
2275
|
-
* Iteratively collect all routes from the tree (no recursion)
|
|
2276
|
-
*/
|
|
2277
|
-
private collectRoutesIterative;
|
|
2278
|
-
}
|
|
2279
|
-
/**
|
|
2280
|
-
* Create a new optimized router instance
|
|
2281
|
-
*
|
|
2282
|
-
* @param prefix - Optional route prefix
|
|
2283
|
-
* @param cacheSize - Optional cache size (default: 1000)
|
|
2284
|
-
* @returns OptimizedRouter instance
|
|
2285
|
-
*
|
|
2286
|
-
* @example
|
|
2287
|
-
* ```typescript
|
|
2288
|
-
* import { createOptimizedRouter } from 'nextrush-v2';
|
|
2289
|
-
*
|
|
2290
|
-
* const userRouter = createOptimizedRouter('/users', 2000);
|
|
2291
|
-
*
|
|
2292
|
-
* userRouter.get('/profile', async (ctx) => {
|
|
2293
|
-
* ctx.res.json({ user: 'profile' });
|
|
2294
|
-
* });
|
|
2295
|
-
*
|
|
2296
|
-
* app.use(userRouter);
|
|
2297
|
-
* ```
|
|
2298
|
-
*/
|
|
2299
|
-
declare function createOptimizedRouter(prefix?: string, cacheSize?: number): OptimizedRouter;
|
|
2300
|
-
|
|
2301
|
-
/**
|
|
2302
|
-
* NextRush v2 - Main Entry Point
|
|
2303
|
-
*
|
|
2304
|
-
* @packageDocumentation
|
|
2305
|
-
*/
|
|
2306
|
-
|
|
2307
|
-
declare const VERSION = "2.0.0-alpha.1";
|
|
2308
|
-
declare const NODE_VERSION = ">=18.0.0";
|
|
2309
|
-
|
|
2310
|
-
declare const _default: {
|
|
2311
|
-
readonly createApp: typeof createApp;
|
|
2312
|
-
readonly VERSION: "2.0.0-alpha.1";
|
|
2313
|
-
readonly NODE_VERSION: ">=18.0.0";
|
|
2314
|
-
};
|
|
2315
|
-
|
|
2316
|
-
export { type Application, AuthenticationError, AuthenticationExceptionFilter, AuthorizationError, AuthorizationExceptionFilter, BadRequestError, ConflictError, ConsoleTransport, type Context, DatabaseError, type DotfilesPolicy, ErrorFactory, type ExceptionFilter, FileTransport, ForbiddenError, GlobalExceptionFilter, HttpTransport, InternalServerError, type LogEntry, LogLevel, type LoggerConfig, LoggerPlugin, MethodNotAllowedError, type Middleware, NODE_VERSION, NetworkError, type Next, NextRushError, type NextRushRequest, type NextRushResponse$1 as NextRushResponse, NotFoundError, NotFoundExceptionFilter, RateLimitError, RateLimitExceptionFilter, RequestEnhancer, ResponseEnhancer, type RouteConfig, type RouteHandler, type Router, ServiceUnavailableError, type StaticFilesOptions, StaticFilesPlugin, type StatsLike, StreamTransport, type TemplateHelper, TemplatePlugin, type TemplatePluginOptions, type TemplateRenderOptions, TimeoutError, TooManyRequestsError, type Transport, UnauthorizedError, UnprocessableEntityError, VERSION, ValidationError, ValidationExceptionFilter, type WSConnection, type WSContext, type WSHandler, type WSMiddleware, type WebSocketApplication, WebSocketPlugin, type WebSocketPluginOptions, smartBodyParser as bodyParser, compression, cors, createApp, createContext, createDevLogger, createMinimalLogger, createProdLogger, createOptimizedRouter as createRouter, _default as default, hasWebSocketSupport, helmet, logger, rateLimit, requestId, timer, withWebSocket };
|