nextrush 2.0.1 → 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 -1265
- 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 -3011
- package/dist/index.js +58 -9046
- package/dist/index.js.map +1 -1
- package/package.json +68 -101
- package/dist/index.d.mts +0 -3044
- package/dist/index.mjs +0 -9012
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3044 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export { Application, ApplicationOptions, ComposedMiddleware, compose, createApp } from '@nextrush/core';
|
|
2
|
+
export { Router, RouterOptions, createRouter } from '@nextrush/router';
|
|
3
|
+
export { ServeOptions, ServerInstance, createHandler, listen, serve } from '@nextrush/adapter-node';
|
|
4
|
+
export { BadGatewayError, BadRequestError, ConflictError, ErrorHandlerOptions, ForbiddenError, GatewayTimeoutError, HttpError, HttpErrorOptions, InternalServerError, MethodNotAllowedError, NextRushError, NotFoundError, NotImplementedError, ServiceUnavailableError, TooManyRequestsError, UnauthorizedError, UnprocessableEntityError, catchAsync, createError, errorHandler, isHttpError, notFoundHandler } from '@nextrush/errors';
|
|
5
|
+
export { ContentType, Context, HttpMethod, HttpStatus, HttpStatusCode, Middleware, Next, Plugin, RouteHandler, Runtime } from '@nextrush/types';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
|
-
*
|
|
8
|
+
* NextRush - Minimal, Modular, Blazing Fast Node.js Framework
|
|
8
9
|
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
readonly statusCode: number;
|
|
16
|
-
readonly code: string;
|
|
17
|
-
readonly isOperational: boolean;
|
|
18
|
-
readonly timestamp: Date;
|
|
19
|
-
constructor(message: string, statusCode?: number, code?: string, isOperational?: boolean);
|
|
20
|
-
/**
|
|
21
|
-
* Create error from HTTP status code
|
|
22
|
-
*/
|
|
23
|
-
static fromStatusCode(statusCode: number, message?: string): NextRushError;
|
|
24
|
-
/**
|
|
25
|
-
* Get error code from status code
|
|
26
|
-
*/
|
|
27
|
-
private static getErrorCode;
|
|
28
|
-
/**
|
|
29
|
-
* Convert error to JSON
|
|
30
|
-
*/
|
|
31
|
-
toJSON(): Record<string, unknown>;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Bad Request Error (400)
|
|
35
|
-
*/
|
|
36
|
-
declare class BadRequestError extends NextRushError {
|
|
37
|
-
constructor(message?: string);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Unauthorized Error (401)
|
|
41
|
-
*/
|
|
42
|
-
declare class UnauthorizedError extends NextRushError {
|
|
43
|
-
constructor(message?: string);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Forbidden Error (403)
|
|
47
|
-
*/
|
|
48
|
-
declare class ForbiddenError extends NextRushError {
|
|
49
|
-
constructor(message?: string);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Not Found Error (404)
|
|
53
|
-
*/
|
|
54
|
-
declare class NotFoundError extends NextRushError {
|
|
55
|
-
constructor(message?: string);
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Method Not Allowed Error (405)
|
|
59
|
-
*/
|
|
60
|
-
declare class MethodNotAllowedError extends NextRushError {
|
|
61
|
-
constructor(message?: string);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Conflict Error (409)
|
|
65
|
-
*/
|
|
66
|
-
declare class ConflictError extends NextRushError {
|
|
67
|
-
constructor(message?: string);
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Unprocessable Entity Error (422)
|
|
71
|
-
*/
|
|
72
|
-
declare class UnprocessableEntityError extends NextRushError {
|
|
73
|
-
constructor(message?: string);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Too Many Requests Error (429)
|
|
77
|
-
*/
|
|
78
|
-
declare class TooManyRequestsError extends NextRushError {
|
|
79
|
-
constructor(message?: string);
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Internal Server Error (500)
|
|
83
|
-
*/
|
|
84
|
-
declare class InternalServerError extends NextRushError {
|
|
85
|
-
constructor(message?: string);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Service Unavailable Error (503)
|
|
89
|
-
*/
|
|
90
|
-
declare class ServiceUnavailableError extends NextRushError {
|
|
91
|
-
constructor(message?: string);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Validation Error (400)
|
|
95
|
-
*/
|
|
96
|
-
declare class ValidationError extends NextRushError {
|
|
97
|
-
readonly field: string;
|
|
98
|
-
readonly value: unknown;
|
|
99
|
-
constructor(message: string, field?: string, value?: unknown, statusCode?: number);
|
|
100
|
-
/**
|
|
101
|
-
* Create validation error for specific field
|
|
102
|
-
*/
|
|
103
|
-
static forField(field: string, message: string, value?: unknown): ValidationError;
|
|
104
|
-
/**
|
|
105
|
-
* Create validation error for multiple fields
|
|
106
|
-
*/
|
|
107
|
-
static forFields(errors: Array<{
|
|
108
|
-
field: string;
|
|
109
|
-
message: string;
|
|
110
|
-
value?: unknown;
|
|
111
|
-
}>): ValidationError;
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Authentication Error (401)
|
|
115
|
-
*/
|
|
116
|
-
declare class AuthenticationError extends NextRushError {
|
|
117
|
-
constructor(message?: string);
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Authorization Error (403)
|
|
121
|
-
*/
|
|
122
|
-
declare class AuthorizationError extends NextRushError {
|
|
123
|
-
constructor(message?: string);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Database Error (500)
|
|
127
|
-
*/
|
|
128
|
-
declare class DatabaseError extends NextRushError {
|
|
129
|
-
readonly operation: string;
|
|
130
|
-
readonly table: string | undefined;
|
|
131
|
-
constructor(message: string, operation?: string, table?: string, statusCode?: number);
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Network Error (502)
|
|
135
|
-
*/
|
|
136
|
-
declare class NetworkError extends NextRushError {
|
|
137
|
-
readonly host: string;
|
|
138
|
-
readonly port: number;
|
|
139
|
-
constructor(message: string, host: string, port: number);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Timeout Error (408)
|
|
143
|
-
*/
|
|
144
|
-
declare class TimeoutError extends NextRushError {
|
|
145
|
-
constructor(message?: string);
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Rate Limit Error (429)
|
|
149
|
-
*/
|
|
150
|
-
declare class RateLimitError extends NextRushError {
|
|
151
|
-
readonly retryAfter: number;
|
|
152
|
-
constructor(message?: string, retryAfter?: number);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Error Factory for creating common errors
|
|
156
|
-
*/
|
|
157
|
-
declare class ErrorFactory {
|
|
158
|
-
/**
|
|
159
|
-
* Create validation error
|
|
160
|
-
*/
|
|
161
|
-
static validation(field: string, message: string, value?: unknown): ValidationError;
|
|
162
|
-
/**
|
|
163
|
-
* Create not found error
|
|
164
|
-
*/
|
|
165
|
-
static notFound(resource: string): NotFoundError;
|
|
166
|
-
/**
|
|
167
|
-
* Create unauthorized error
|
|
168
|
-
*/
|
|
169
|
-
static unauthorized(message?: string): AuthenticationError;
|
|
170
|
-
/**
|
|
171
|
-
* Create forbidden error
|
|
172
|
-
*/
|
|
173
|
-
static forbidden(message?: string): AuthorizationError;
|
|
174
|
-
/**
|
|
175
|
-
* Create bad request error
|
|
176
|
-
*/
|
|
177
|
-
static badRequest(message?: string): BadRequestError;
|
|
178
|
-
/**
|
|
179
|
-
* Create conflict error
|
|
180
|
-
*/
|
|
181
|
-
static conflict(message?: string): ConflictError;
|
|
182
|
-
/**
|
|
183
|
-
* Create internal server error
|
|
184
|
-
*/
|
|
185
|
-
static internal(message?: string): InternalServerError;
|
|
186
|
-
/**
|
|
187
|
-
* Create rate limit error
|
|
188
|
-
*/
|
|
189
|
-
static rateLimit(message?: string, retryAfter?: number): RateLimitError;
|
|
190
|
-
/**
|
|
191
|
-
* Create timeout error
|
|
192
|
-
*/
|
|
193
|
-
static timeout(message?: string): TimeoutError;
|
|
194
|
-
/**
|
|
195
|
-
* Create service unavailable error
|
|
196
|
-
*/
|
|
197
|
-
static serviceUnavailable(message?: string): ServiceUnavailableError;
|
|
198
|
-
/**
|
|
199
|
-
* Create database error
|
|
200
|
-
*/
|
|
201
|
-
static database(message: string, operation: string, table?: string): DatabaseError;
|
|
202
|
-
/**
|
|
203
|
-
* Create network error
|
|
204
|
-
*/
|
|
205
|
-
static network(message: string, host: string, port: number): NetworkError;
|
|
206
|
-
}
|
|
207
|
-
/**
|
|
208
|
-
* Exception Filter Interface (NestJS style)
|
|
209
|
-
*/
|
|
210
|
-
interface ExceptionFilter {
|
|
211
|
-
catch(error: Error, ctx: any): void | Promise<void>;
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* Global Exception Filter
|
|
215
|
-
*/
|
|
216
|
-
declare class GlobalExceptionFilter implements ExceptionFilter {
|
|
217
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
218
|
-
}
|
|
219
|
-
/**
|
|
220
|
-
* Exception Filter for specific error types
|
|
221
|
-
*/
|
|
222
|
-
declare class ValidationExceptionFilter implements ExceptionFilter {
|
|
223
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Exception Filter for authentication errors
|
|
227
|
-
*/
|
|
228
|
-
declare class AuthenticationExceptionFilter implements ExceptionFilter {
|
|
229
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Exception Filter for authorization errors
|
|
233
|
-
*/
|
|
234
|
-
declare class AuthorizationExceptionFilter implements ExceptionFilter {
|
|
235
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Exception Filter for not found errors
|
|
239
|
-
*/
|
|
240
|
-
declare class NotFoundExceptionFilter implements ExceptionFilter {
|
|
241
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Exception Filter for rate limit errors
|
|
245
|
-
*/
|
|
246
|
-
declare class RateLimitExceptionFilter implements ExceptionFilter {
|
|
247
|
-
catch(error: Error, ctx: any): Promise<void>;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* 🔧 Enhanced parser configuration with enterprise-grade settings
|
|
252
|
-
*/
|
|
253
|
-
interface EnhancedBodyParserOptions {
|
|
254
|
-
/** Maximum body size in bytes (default: 10MB) */
|
|
255
|
-
maxSize?: number;
|
|
256
|
-
/** Request timeout in milliseconds (default: 5s) */
|
|
257
|
-
timeout?: number;
|
|
258
|
-
/** Enable streaming for large payloads (default: true) */
|
|
259
|
-
enableStreaming?: boolean;
|
|
260
|
-
/** Streaming threshold in bytes (default: 50MB) */
|
|
261
|
-
streamingThreshold?: number;
|
|
262
|
-
/** Buffer pool size for optimization (default: 100) */
|
|
263
|
-
poolSize?: number;
|
|
264
|
-
/** Enable fast validation (default: true) */
|
|
265
|
-
fastValidation?: boolean;
|
|
266
|
-
/** Auto-detect content type (default: true) */
|
|
267
|
-
autoDetectContentType?: boolean;
|
|
268
|
-
/** Strict content type checking (default: false) */
|
|
269
|
-
strictContentType?: boolean;
|
|
270
|
-
/** Enable metrics collection (default: true) */
|
|
271
|
-
enableMetrics?: boolean;
|
|
272
|
-
/** Encoding for text-based content (default: 'utf8') */
|
|
273
|
-
encoding?: BufferEncoding;
|
|
274
|
-
/** Custom error messages */
|
|
275
|
-
errorMessages?: {
|
|
276
|
-
maxSizeExceeded?: string;
|
|
277
|
-
timeoutError?: string;
|
|
278
|
-
invalidContentType?: string;
|
|
279
|
-
parseError?: string;
|
|
280
|
-
};
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Middleware Types for NextRush v2
|
|
285
|
-
*
|
|
286
|
-
* @packageDocumentation
|
|
287
|
-
*/
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Standard middleware function signature
|
|
291
|
-
*/
|
|
292
|
-
type Middleware$1 = (ctx: Context, next: () => Promise<void>) => Promise<void>;
|
|
293
|
-
/**
|
|
294
|
-
* CORS middleware options
|
|
295
|
-
*/
|
|
296
|
-
interface CorsOptions {
|
|
297
|
-
/** Allowed origins */
|
|
298
|
-
origin?: string | string[] | boolean | ((origin: string) => boolean);
|
|
299
|
-
/** Allowed methods */
|
|
300
|
-
methods?: string[];
|
|
301
|
-
/** Allowed headers */
|
|
302
|
-
allowedHeaders?: string[];
|
|
303
|
-
/** Exposed headers */
|
|
304
|
-
exposedHeaders?: string[];
|
|
305
|
-
/** Allow credentials */
|
|
306
|
-
credentials?: boolean;
|
|
307
|
-
/** Max age for preflight */
|
|
308
|
-
maxAge?: number;
|
|
309
|
-
/** Preflight continue */
|
|
310
|
-
preflightContinue?: boolean;
|
|
311
|
-
/** Options success status */
|
|
312
|
-
optionsSuccessStatus?: number;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Helmet middleware options
|
|
316
|
-
*/
|
|
317
|
-
interface HelmetOptions {
|
|
318
|
-
/** Content Security Policy */
|
|
319
|
-
contentSecurityPolicy?: {
|
|
320
|
-
directives: Record<string, string[]>;
|
|
321
|
-
reportOnly?: boolean;
|
|
322
|
-
};
|
|
323
|
-
/** HTTP Strict Transport Security */
|
|
324
|
-
hsts?: {
|
|
325
|
-
maxAge: number;
|
|
326
|
-
includeSubDomains?: boolean;
|
|
327
|
-
preload?: boolean;
|
|
328
|
-
};
|
|
329
|
-
/** XSS Protection */
|
|
330
|
-
xssFilter?: boolean;
|
|
331
|
-
/** Content Type Options */
|
|
332
|
-
noSniff?: boolean;
|
|
333
|
-
/** Frame Options */
|
|
334
|
-
frameguard?: {
|
|
335
|
-
action: 'DENY' | 'SAMEORIGIN' | 'ALLOW-FROM';
|
|
336
|
-
domain?: string;
|
|
337
|
-
};
|
|
338
|
-
/** Referrer Policy */
|
|
339
|
-
referrerPolicy?: {
|
|
340
|
-
policy: string;
|
|
341
|
-
};
|
|
342
|
-
/** Hide X-Powered-By header */
|
|
343
|
-
hidePoweredBy?: boolean;
|
|
344
|
-
/** DNS Prefetch Control */
|
|
345
|
-
dnsPrefetchControl?: {
|
|
346
|
-
allow?: boolean;
|
|
347
|
-
};
|
|
348
|
-
/** IE No Open */
|
|
349
|
-
ieNoOpen?: boolean;
|
|
350
|
-
/** Permitted Cross Domain Policies */
|
|
351
|
-
permittedCrossDomainPolicies?: {
|
|
352
|
-
permittedPolicies?: string;
|
|
353
|
-
};
|
|
354
|
-
}
|
|
355
|
-
/**
|
|
356
|
-
* Rate limiter options
|
|
357
|
-
*/
|
|
358
|
-
interface RateLimiterOptions {
|
|
359
|
-
/** Time window in milliseconds */
|
|
360
|
-
windowMs?: number;
|
|
361
|
-
/** Maximum requests per window */
|
|
362
|
-
max?: number;
|
|
363
|
-
/** Rate limit message */
|
|
364
|
-
message?: string;
|
|
365
|
-
/** Status code for rate limited requests */
|
|
366
|
-
statusCode?: number;
|
|
367
|
-
/** Include headers */
|
|
368
|
-
headers?: boolean;
|
|
369
|
-
/** Skip successful requests */
|
|
370
|
-
skipSuccessfulRequests?: boolean;
|
|
371
|
-
/** Skip failed requests */
|
|
372
|
-
skipFailedRequests?: boolean;
|
|
373
|
-
/** Key generator function */
|
|
374
|
-
keyGenerator?: (ctx: Context) => string;
|
|
375
|
-
/** Skip function */
|
|
376
|
-
skip?: (ctx: Context) => boolean;
|
|
377
|
-
/** Custom handler */
|
|
378
|
-
handler?: (ctx: Context) => void;
|
|
379
|
-
/** Store implementation */
|
|
380
|
-
store?: {
|
|
381
|
-
get(key: string): {
|
|
382
|
-
count: number;
|
|
383
|
-
resetTime: number;
|
|
384
|
-
} | null;
|
|
385
|
-
increment(key: string): {
|
|
386
|
-
count: number;
|
|
387
|
-
resetTime: number;
|
|
388
|
-
};
|
|
389
|
-
reset(key: string): void;
|
|
390
|
-
clear(): void;
|
|
391
|
-
};
|
|
392
|
-
}
|
|
393
|
-
/**
|
|
394
|
-
* Logger middleware options
|
|
395
|
-
*/
|
|
396
|
-
interface LoggerOptions {
|
|
397
|
-
/** Log format */
|
|
398
|
-
format?: 'simple' | 'detailed' | 'json' | 'combined';
|
|
399
|
-
/** Log level */
|
|
400
|
-
level?: 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
|
|
401
|
-
/** Colorize output */
|
|
402
|
-
colorize?: boolean;
|
|
403
|
-
/** Include timestamp */
|
|
404
|
-
timestamp?: boolean;
|
|
405
|
-
/** Show headers */
|
|
406
|
-
showHeaders?: boolean;
|
|
407
|
-
/** Show body */
|
|
408
|
-
showBody?: boolean;
|
|
409
|
-
/** Show query */
|
|
410
|
-
showQuery?: boolean;
|
|
411
|
-
/** Show response time */
|
|
412
|
-
showResponseTime?: boolean;
|
|
413
|
-
/** Show user agent */
|
|
414
|
-
showUserAgent?: boolean;
|
|
415
|
-
/** Show referer */
|
|
416
|
-
showReferer?: boolean;
|
|
417
|
-
/** Show IP */
|
|
418
|
-
showIP?: boolean;
|
|
419
|
-
/** Show method */
|
|
420
|
-
showMethod?: boolean;
|
|
421
|
-
/** Show URL */
|
|
422
|
-
showURL?: boolean;
|
|
423
|
-
/** Show status */
|
|
424
|
-
showStatus?: boolean;
|
|
425
|
-
/** Show response size */
|
|
426
|
-
showResponseSize?: boolean;
|
|
427
|
-
/** Custom format function */
|
|
428
|
-
customFormat?: (ctx: Context, duration: number) => string;
|
|
429
|
-
/** Filter function */
|
|
430
|
-
filter?: (ctx: Context) => boolean;
|
|
431
|
-
/** Output stream */
|
|
432
|
-
stream?: NodeJS.WritableStream;
|
|
433
|
-
}
|
|
434
|
-
/**
|
|
435
|
-
* Compression middleware options
|
|
436
|
-
*/
|
|
437
|
-
interface CompressionOptions {
|
|
438
|
-
/** Compression level (1-9) */
|
|
439
|
-
level?: number;
|
|
440
|
-
/** Minimum size to compress */
|
|
441
|
-
threshold?: number;
|
|
442
|
-
/** Filter function */
|
|
443
|
-
filter?: (ctx: Context) => boolean;
|
|
444
|
-
/** Content types to compress */
|
|
445
|
-
contentType?: string[];
|
|
446
|
-
/** Content types to exclude */
|
|
447
|
-
exclude?: string[];
|
|
448
|
-
/** Enable gzip */
|
|
449
|
-
gzip?: boolean;
|
|
450
|
-
/** Enable deflate */
|
|
451
|
-
deflate?: boolean;
|
|
452
|
-
/** Enable brotli */
|
|
453
|
-
brotli?: boolean;
|
|
454
|
-
/** Window size */
|
|
455
|
-
windowBits?: number;
|
|
456
|
-
/** Memory level */
|
|
457
|
-
memLevel?: number;
|
|
458
|
-
/** Strategy */
|
|
459
|
-
strategy?: number;
|
|
460
|
-
/** Chunk size */
|
|
461
|
-
chunkSize?: number;
|
|
462
|
-
/** Dictionary */
|
|
463
|
-
dictionary?: Buffer;
|
|
464
|
-
/** Enable adaptive compression based on CPU usage */
|
|
465
|
-
adaptive?: boolean;
|
|
466
|
-
/** Maximum CPU usage threshold for adaptive compression (percentage) */
|
|
467
|
-
maxCpuUsage?: number;
|
|
468
|
-
/** Backpressure threshold for skipping compression */
|
|
469
|
-
backpressureThreshold?: number;
|
|
470
|
-
}
|
|
471
|
-
/**
|
|
472
|
-
* Request ID middleware options
|
|
473
|
-
*/
|
|
474
|
-
interface RequestIdOptions {
|
|
475
|
-
/** Request ID header name */
|
|
476
|
-
headerName?: string;
|
|
477
|
-
/** Request ID generator function */
|
|
478
|
-
generator?: () => string;
|
|
479
|
-
/** Add to response headers */
|
|
480
|
-
addResponseHeader?: boolean;
|
|
481
|
-
/** Echo existing header */
|
|
482
|
-
echoHeader?: boolean;
|
|
483
|
-
/** Set in context */
|
|
484
|
-
setInContext?: boolean;
|
|
485
|
-
/** Include in logs */
|
|
486
|
-
includeInLogs?: boolean;
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Timer middleware options
|
|
490
|
-
*/
|
|
491
|
-
interface TimerOptions {
|
|
492
|
-
/** Response time header name */
|
|
493
|
-
header?: string;
|
|
494
|
-
/** Number of decimal places */
|
|
495
|
-
digits?: number;
|
|
496
|
-
/** Time unit suffix */
|
|
497
|
-
suffix?: string;
|
|
498
|
-
/** Include start time */
|
|
499
|
-
includeStartTime?: boolean;
|
|
500
|
-
/** Include end time */
|
|
501
|
-
includeEndTime?: boolean;
|
|
502
|
-
/** Include duration */
|
|
503
|
-
includeDuration?: boolean;
|
|
504
|
-
/** Format type */
|
|
505
|
-
format?: 'milliseconds' | 'seconds' | 'microseconds' | 'nanoseconds';
|
|
506
|
-
/** Threshold for logging */
|
|
507
|
-
threshold?: number;
|
|
508
|
-
/** Log slow requests */
|
|
509
|
-
logSlow?: boolean;
|
|
510
|
-
/** Slow request threshold */
|
|
511
|
-
logSlowThreshold?: number;
|
|
512
|
-
/** Custom format function */
|
|
513
|
-
customFormat?: (duration: number) => string;
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
/**
|
|
517
|
-
* Cookie options interface with security defaults
|
|
518
|
-
*/
|
|
519
|
-
interface CookieOptions {
|
|
520
|
-
/** Domain for the cookie */
|
|
521
|
-
domain?: string;
|
|
522
|
-
/** Expiration date */
|
|
523
|
-
expires?: Date;
|
|
524
|
-
/** HTTP Only flag (default: true for security) */
|
|
525
|
-
httpOnly?: boolean;
|
|
526
|
-
/** Max age in seconds */
|
|
527
|
-
maxAge?: number;
|
|
528
|
-
/** Path (default: '/') */
|
|
529
|
-
path?: string;
|
|
530
|
-
/** Priority (Low, Medium, High) */
|
|
531
|
-
priority?: 'Low' | 'Medium' | 'High';
|
|
532
|
-
/** SameSite attribute (default: 'Strict') */
|
|
533
|
-
sameSite?: 'Strict' | 'Lax' | 'None' | boolean;
|
|
534
|
-
/** Secure flag (default: true in production) */
|
|
535
|
-
secure?: boolean;
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* Application configuration options
|
|
540
|
-
*/
|
|
541
|
-
interface ApplicationOptions {
|
|
542
|
-
/** Port to listen on (default: 3000) */
|
|
543
|
-
port?: number;
|
|
544
|
-
/** Host to bind to (default: 'localhost') */
|
|
545
|
-
host?: string;
|
|
546
|
-
/** Enable debug mode */
|
|
547
|
-
debug?: boolean;
|
|
548
|
-
/** Trust proxy headers */
|
|
549
|
-
trustProxy?: boolean;
|
|
550
|
-
/** Maximum request body size in bytes */
|
|
551
|
-
maxBodySize?: number;
|
|
552
|
-
/** Request timeout in milliseconds */
|
|
553
|
-
timeout?: number;
|
|
554
|
-
/** Enable CORS by default */
|
|
555
|
-
cors?: boolean;
|
|
556
|
-
/** Static files directory */
|
|
557
|
-
static?: string;
|
|
558
|
-
/** Template engine configuration */
|
|
559
|
-
template?: {
|
|
560
|
-
engine: string;
|
|
561
|
-
directory: string;
|
|
562
|
-
};
|
|
563
|
-
/** HTTP keep-alive timeout in milliseconds */
|
|
564
|
-
keepAlive?: number;
|
|
565
|
-
}
|
|
566
|
-
/**
|
|
567
|
-
* Enhanced request object
|
|
568
|
-
*/
|
|
569
|
-
interface NextRushRequest extends IncomingMessage {
|
|
570
|
-
/** Request body */
|
|
571
|
-
body?: unknown;
|
|
572
|
-
/** Route parameters */
|
|
573
|
-
params: Record<string, string>;
|
|
574
|
-
/** Query parameters */
|
|
575
|
-
query: ParsedUrlQuery;
|
|
576
|
-
/** Request path */
|
|
577
|
-
path: string;
|
|
578
|
-
/** Client IP address */
|
|
579
|
-
ip: string;
|
|
580
|
-
/** Request protocol */
|
|
581
|
-
protocol: string;
|
|
582
|
-
/** Whether the request is secure */
|
|
583
|
-
secure: boolean;
|
|
584
|
-
/** Original request URL */
|
|
585
|
-
originalUrl: string;
|
|
586
|
-
}
|
|
587
|
-
/**
|
|
588
|
-
* Enhanced response object
|
|
589
|
-
*/
|
|
590
|
-
interface NextRushResponse$1 extends ServerResponse {
|
|
591
|
-
/** Set response status code */
|
|
592
|
-
status(code: number): NextRushResponse$1;
|
|
593
|
-
/** Send JSON response (fast by default) */
|
|
594
|
-
json(data: unknown): NextRushResponse$1;
|
|
595
|
-
/** Send HTML response */
|
|
596
|
-
html(data: string): NextRushResponse$1;
|
|
597
|
-
/** Send text response */
|
|
598
|
-
text(data: string): NextRushResponse$1;
|
|
599
|
-
/** Send CSV response */
|
|
600
|
-
csv(data: string): NextRushResponse$1;
|
|
601
|
-
/** Send XML response */
|
|
602
|
-
xml(data: string): NextRushResponse$1;
|
|
603
|
-
/** Send file response */
|
|
604
|
-
file(path: string, options?: {
|
|
605
|
-
root?: string;
|
|
606
|
-
}): NextRushResponse$1;
|
|
607
|
-
/** Send file response (alias) */
|
|
608
|
-
sendFile(path: string, options?: {
|
|
609
|
-
root?: string;
|
|
610
|
-
etag?: boolean;
|
|
611
|
-
}): NextRushResponse$1;
|
|
612
|
-
/** Send download response */
|
|
613
|
-
download(path: string, filename?: string): NextRushResponse$1;
|
|
614
|
-
/** Redirect response */
|
|
615
|
-
redirect(url: string, status?: number): NextRushResponse$1;
|
|
616
|
-
/** Set response header */
|
|
617
|
-
set(name: string, value: string | number | string[]): NextRushResponse$1;
|
|
618
|
-
/** Get response header */
|
|
619
|
-
get(name: string): string | number | string[] | undefined;
|
|
620
|
-
/** Remove response header */
|
|
621
|
-
remove(name: string): NextRushResponse$1;
|
|
622
|
-
/** Set response type */
|
|
623
|
-
type(type: string): NextRushResponse$1;
|
|
624
|
-
/** Set response length */
|
|
625
|
-
length(length: number): NextRushResponse$1;
|
|
626
|
-
/** Set response etag */
|
|
627
|
-
etag(etag: string): NextRushResponse$1;
|
|
628
|
-
/** Set response last modified */
|
|
629
|
-
lastModified(date: Date): NextRushResponse$1;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
/**
|
|
633
|
-
* WebSocket connection interface
|
|
634
|
-
*/
|
|
635
|
-
interface WSConnection {
|
|
636
|
-
/** Unique connection ID */
|
|
637
|
-
id: string;
|
|
638
|
-
/** WebSocket request URL */
|
|
639
|
-
url: string;
|
|
640
|
-
/** Connection alive status */
|
|
641
|
-
isAlive: boolean;
|
|
642
|
-
/** Last pong timestamp */
|
|
643
|
-
lastPong: number;
|
|
644
|
-
/** Send message to client */
|
|
645
|
-
send(data: string | Buffer): void;
|
|
646
|
-
/** Close connection */
|
|
647
|
-
close(code?: number, reason?: string): void;
|
|
648
|
-
/** Join a room */
|
|
649
|
-
join(room: string): void;
|
|
650
|
-
/** Leave a room */
|
|
651
|
-
leave(room: string): void;
|
|
652
|
-
/** Listen for incoming messages */
|
|
653
|
-
onMessage(listener: (data: string | Buffer) => void): void;
|
|
654
|
-
/** Listen for connection close */
|
|
655
|
-
onClose(listener: (code: number, reason: string) => void): void;
|
|
656
|
-
}
|
|
657
|
-
/**
|
|
658
|
-
* WebSocket route handler type
|
|
659
|
-
*/
|
|
660
|
-
type WSHandler = (socket: WSConnection, req: IncomingMessage) => void | Promise<void>;
|
|
661
|
-
/**
|
|
662
|
-
* WebSocket middleware type
|
|
663
|
-
*/
|
|
664
|
-
type WSMiddleware = (socket: WSConnection, req: IncomingMessage, next: () => void) => void | Promise<void>;
|
|
665
|
-
/**
|
|
666
|
-
* WebSocket plugin options
|
|
667
|
-
*/
|
|
668
|
-
interface WebSocketPluginOptions {
|
|
669
|
-
/** Accepted paths (exact or wildcard *) */
|
|
670
|
-
path?: string | string[];
|
|
671
|
-
/** Ping interval in milliseconds */
|
|
672
|
-
heartbeatMs?: number;
|
|
673
|
-
/** Close if no pong within this timeout */
|
|
674
|
-
pongTimeoutMs?: number;
|
|
675
|
-
/** Maximum concurrent connections */
|
|
676
|
-
maxConnections?: number;
|
|
677
|
-
/** Maximum message size in bytes */
|
|
678
|
-
maxMessageSize?: number;
|
|
679
|
-
/** Allowed origins for CORS */
|
|
680
|
-
allowOrigins?: (string | RegExp)[];
|
|
681
|
-
/** Custom client verification */
|
|
682
|
-
verifyClient?: (req: IncomingMessage) => Promise<boolean> | boolean;
|
|
683
|
-
/** Debug mode */
|
|
684
|
-
debug?: boolean;
|
|
685
|
-
}
|
|
686
|
-
/**
|
|
687
|
-
* Enhanced response object with Express-like methods
|
|
688
|
-
*/
|
|
689
|
-
interface NextRushResponse extends ServerResponse {
|
|
690
|
-
/** Send JSON response */
|
|
691
|
-
json(data: unknown): NextRushResponse;
|
|
692
|
-
/** Send HTML response */
|
|
693
|
-
html(data: string): NextRushResponse;
|
|
694
|
-
/** Send text response */
|
|
695
|
-
text(data: string): NextRushResponse;
|
|
696
|
-
/** Send CSV response */
|
|
697
|
-
csv(data: string): NextRushResponse;
|
|
698
|
-
/** Send XML response */
|
|
699
|
-
xml(data: string): NextRushResponse;
|
|
700
|
-
/** Send any data type response */
|
|
701
|
-
send(data: string | Buffer | object): void;
|
|
702
|
-
/** Stream response */
|
|
703
|
-
stream(stream: NodeJS.ReadableStream, contentType?: string): void;
|
|
704
|
-
/** Render HTML from a template string or a template name under viewsDir */
|
|
705
|
-
render(templateOrName: string, data?: Record<string, unknown>, options?: {
|
|
706
|
-
layout?: string;
|
|
707
|
-
}): Promise<void>;
|
|
708
|
-
/** Send file response (alias) */
|
|
709
|
-
file(path: string, options?: {
|
|
710
|
-
root?: string;
|
|
711
|
-
etag?: boolean;
|
|
712
|
-
}): NextRushResponse;
|
|
713
|
-
/** Send file response */
|
|
714
|
-
sendFile(path: string, options?: {
|
|
715
|
-
root?: string;
|
|
716
|
-
etag?: boolean;
|
|
717
|
-
}): NextRushResponse;
|
|
718
|
-
/** Send download response */
|
|
719
|
-
download(path: string, filename?: string): NextRushResponse;
|
|
720
|
-
/** Redirect response */
|
|
721
|
-
redirect(url: string, status?: number): NextRushResponse;
|
|
722
|
-
/** Permanent redirect (301) */
|
|
723
|
-
redirectPermanent(url: string): NextRushResponse;
|
|
724
|
-
/** Temporary redirect (307) */
|
|
725
|
-
redirectTemporary(url: string): NextRushResponse;
|
|
726
|
-
/** Set response status */
|
|
727
|
-
status(code: number): NextRushResponse;
|
|
728
|
-
/** Set response header */
|
|
729
|
-
set(name: string, value: string | number | string[]): NextRushResponse;
|
|
730
|
-
/** Set response header (alias) */
|
|
731
|
-
header(field: string, value: string): NextRushResponse;
|
|
732
|
-
/** Get response header */
|
|
733
|
-
get(name: string): string | number | string[] | undefined;
|
|
734
|
-
/** Remove response header */
|
|
735
|
-
remove(name: string): NextRushResponse;
|
|
736
|
-
/** Remove response header (implementation method) */
|
|
737
|
-
removeHeader(field: string): NextRushResponse;
|
|
738
|
-
/** Set response type */
|
|
739
|
-
type(type: string): NextRushResponse;
|
|
740
|
-
/** Set response length */
|
|
741
|
-
length(length: number): NextRushResponse;
|
|
742
|
-
/** Set response etag */
|
|
743
|
-
etag(etag: string): NextRushResponse;
|
|
744
|
-
/** Set response last modified */
|
|
745
|
-
lastModified(date: Date): NextRushResponse;
|
|
746
|
-
/** Set cookie */
|
|
747
|
-
cookie(name: string, value: string, options?: CookieOptions): NextRushResponse;
|
|
748
|
-
/** Clear cookie */
|
|
749
|
-
clearCookie(name: string, options?: CookieOptions): NextRushResponse;
|
|
750
|
-
/** Set cache headers */
|
|
751
|
-
cache(seconds: number): NextRushResponse;
|
|
752
|
-
/** Disable caching */
|
|
753
|
-
noCache(): NextRushResponse;
|
|
754
|
-
/** Set CORS headers */
|
|
755
|
-
cors(origin?: string): NextRushResponse;
|
|
756
|
-
/** Set security headers */
|
|
757
|
-
security(): NextRushResponse;
|
|
758
|
-
/** Enable compression hint */
|
|
759
|
-
compress(): NextRushResponse;
|
|
760
|
-
/** Send success response */
|
|
761
|
-
success(data: unknown, message?: string): void;
|
|
762
|
-
/** Send error response */
|
|
763
|
-
error(message: string, code?: number, details?: unknown): void;
|
|
764
|
-
/** Send paginated response */
|
|
765
|
-
paginate(data: unknown[], page: number, limit: number, total: number): void;
|
|
766
|
-
/** Get content type from file extension */
|
|
767
|
-
getContentTypeFromExtension(ext: string): string;
|
|
768
|
-
/** Get smart content type from file path */
|
|
769
|
-
getSmartContentType(filePath: string): string;
|
|
770
|
-
/** Generate ETag from stats */
|
|
771
|
-
generateETag(stats: unknown): string;
|
|
772
|
-
/** Convert data to CSV */
|
|
773
|
-
convertToCSV(data: unknown[]): string;
|
|
774
|
-
/** Add timing header */
|
|
775
|
-
time(label?: string): NextRushResponse;
|
|
776
|
-
/** Get nested value from object */
|
|
777
|
-
getNestedValue(obj: unknown, path: string): unknown;
|
|
778
|
-
/** Check if value is truthy */
|
|
779
|
-
isTruthy(value: unknown): boolean;
|
|
780
|
-
}
|
|
781
|
-
/**
|
|
782
|
-
* Koa-style context interface
|
|
783
|
-
*/
|
|
784
|
-
interface Context {
|
|
785
|
-
/** Request object (Express-like) */
|
|
786
|
-
req: NextRushRequest;
|
|
787
|
-
/** Response object (Express-like) */
|
|
788
|
-
res: NextRushResponse;
|
|
789
|
-
/** Request body (Express-like) */
|
|
790
|
-
body: unknown;
|
|
791
|
-
/** Request method */
|
|
792
|
-
method: string;
|
|
793
|
-
/** Request URL */
|
|
794
|
-
url: string;
|
|
795
|
-
/** Request path */
|
|
796
|
-
path: string;
|
|
797
|
-
/** Request headers */
|
|
798
|
-
headers: IncomingMessage['headers'];
|
|
799
|
-
/** Query parameters */
|
|
800
|
-
query: ParsedUrlQuery;
|
|
801
|
-
/** Route parameters */
|
|
802
|
-
params: Record<string, string>;
|
|
803
|
-
/** Request ID for tracing */
|
|
804
|
-
id: string | undefined;
|
|
805
|
-
/** Request ID for logging (alternative to id) */
|
|
806
|
-
requestId?: string;
|
|
807
|
-
/** Request-specific logger */
|
|
808
|
-
logger?: {
|
|
809
|
-
log: (...args: unknown[]) => void;
|
|
810
|
-
error: (...args: unknown[]) => void;
|
|
811
|
-
warn: (...args: unknown[]) => void;
|
|
812
|
-
info: (...args: unknown[]) => void;
|
|
813
|
-
};
|
|
814
|
-
/** State object for middleware communication */
|
|
815
|
-
state: Record<string, unknown>;
|
|
816
|
-
/** Request start time */
|
|
817
|
-
startTime: number;
|
|
818
|
-
/** Get client IP */
|
|
819
|
-
ip: string;
|
|
820
|
-
/** Check if request is secure */
|
|
821
|
-
secure: boolean;
|
|
822
|
-
/** Request protocol */
|
|
823
|
-
protocol: string;
|
|
824
|
-
/** Request hostname */
|
|
825
|
-
hostname: string;
|
|
826
|
-
/** Request host */
|
|
827
|
-
host: string;
|
|
828
|
-
/** Request origin */
|
|
829
|
-
origin: string;
|
|
830
|
-
/** Request href */
|
|
831
|
-
href: string;
|
|
832
|
-
/** Request search */
|
|
833
|
-
search: string;
|
|
834
|
-
/** Request search params */
|
|
835
|
-
searchParams: URLSearchParams;
|
|
836
|
-
/** Response status */
|
|
837
|
-
status: number;
|
|
838
|
-
/** Response headers */
|
|
839
|
-
responseHeaders: Record<string, string | number | string[]>;
|
|
840
|
-
/** Throw an error */
|
|
841
|
-
throw(status: number, message?: string): never;
|
|
842
|
-
/** Assert a condition */
|
|
843
|
-
assert(condition: unknown, status: number, message?: string): asserts condition;
|
|
844
|
-
/** Check if response is fresh */
|
|
845
|
-
fresh(): boolean;
|
|
846
|
-
/** Check if response is stale */
|
|
847
|
-
stale(): boolean;
|
|
848
|
-
/** Check if request is idempotent */
|
|
849
|
-
idempotent(): boolean;
|
|
850
|
-
/** Check if request is cacheable */
|
|
851
|
-
cacheable(): boolean;
|
|
852
|
-
/** Set response header (Koa-style) */
|
|
853
|
-
set(name: string, value: string | number | string[]): void;
|
|
854
|
-
/** Send a file using the enhanced response */
|
|
855
|
-
sendFile(path: string, options?: {
|
|
856
|
-
root?: string;
|
|
857
|
-
etag?: boolean;
|
|
858
|
-
}): void;
|
|
859
|
-
/** Render HTML from a template string or a template name under viewsDir */
|
|
860
|
-
render(templateOrName: string, data?: Record<string, unknown>, options?: {
|
|
861
|
-
layout?: string;
|
|
862
|
-
}): Promise<void>;
|
|
863
|
-
/** Send JSON response (convenience for ctx.res.json) */
|
|
864
|
-
json(data: unknown): void;
|
|
865
|
-
/** Send response data (convenience for ctx.res.send) */
|
|
866
|
-
send(data: string | Buffer | object): void;
|
|
867
|
-
/** Redirect response (convenience for ctx.res.redirect) */
|
|
868
|
-
redirect(url: string, statusCode?: number): void;
|
|
869
|
-
/** Set cookie (convenience for ctx.res.cookie) */
|
|
870
|
-
cookie(name: string, value: string, options?: CookieOptions): NextRushResponse;
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
* Next function for middleware
|
|
874
|
-
*/
|
|
875
|
-
type Next = () => Promise<void>;
|
|
876
|
-
/**
|
|
877
|
-
* Middleware function type
|
|
878
|
-
*/
|
|
879
|
-
type Middleware = (ctx: Context, next: Next) => Promise<void>;
|
|
880
|
-
/**
|
|
881
|
-
* Route handler function type
|
|
882
|
-
*/
|
|
883
|
-
type RouteHandler = (ctx: Context) => Promise<void> | void;
|
|
884
|
-
/** Dotfiles policy for static files */
|
|
885
|
-
type DotfilesPolicy = 'ignore' | 'deny' | 'allow';
|
|
886
|
-
/** Options for StaticFilesPlugin */
|
|
887
|
-
interface StaticFilesOptions {
|
|
888
|
-
/** Absolute directory to serve files from */
|
|
889
|
-
root: string;
|
|
890
|
-
/** URL prefix to mount under, e.g., "/static"; default: '' (root) */
|
|
891
|
-
prefix?: `/${string}` | '';
|
|
892
|
-
/** Default index file to serve for directories; set false to disable */
|
|
893
|
-
index?: string | false;
|
|
894
|
-
/** If true, call next() on 404 instead of sending 404; default: false */
|
|
895
|
-
fallthrough?: boolean;
|
|
896
|
-
/** If true, redirect directory request without trailing slash to slash; default: true */
|
|
897
|
-
redirect?: boolean;
|
|
898
|
-
/** Send Cache-Control max-age seconds; default: 0 (no explicit caching) */
|
|
899
|
-
maxAge?: number;
|
|
900
|
-
/** Add immutable directive to Cache-Control when maxAge > 0; default: false */
|
|
901
|
-
immutable?: boolean;
|
|
902
|
-
/** Control dotfiles serving; default: 'ignore' (404) */
|
|
903
|
-
dotfiles?: DotfilesPolicy;
|
|
904
|
-
/** Additional extensions to try when file not found (e.g., ['.html']); default: [] */
|
|
905
|
-
extensions?: string[];
|
|
906
|
-
/** Hook to customize headers */
|
|
907
|
-
setHeaders?: (ctx: Context, absolutePath: string, stat: StatsLike) => void;
|
|
908
|
-
}
|
|
909
|
-
/** Stats-like interface for static files */
|
|
910
|
-
interface StatsLike {
|
|
911
|
-
isFile(): boolean;
|
|
912
|
-
isDirectory(): boolean;
|
|
913
|
-
size: number;
|
|
914
|
-
mtime: Date;
|
|
915
|
-
}
|
|
916
|
-
/** Options for TemplatePlugin */
|
|
917
|
-
interface TemplatePluginOptions {
|
|
918
|
-
/** Directory containing template files */
|
|
919
|
-
viewsDir?: string;
|
|
920
|
-
/** Enable template caching; default: true */
|
|
921
|
-
cache?: boolean;
|
|
922
|
-
/** Custom helper functions */
|
|
923
|
-
helpers?: Record<string, (value: unknown, ...args: unknown[]) => unknown>;
|
|
924
|
-
/** Preloaded partial templates */
|
|
925
|
-
partials?: Record<string, string>;
|
|
926
|
-
/** Enable loading partials from viewsDir; default: true */
|
|
927
|
-
enableFilePartials?: boolean;
|
|
928
|
-
/** File extension for partials; default: '.html' */
|
|
929
|
-
partialExt?: string;
|
|
930
|
-
}
|
|
931
|
-
/** Template helper function type */
|
|
932
|
-
type TemplateHelper = (value: unknown, ...args: unknown[]) => unknown;
|
|
933
|
-
/** Template render options */
|
|
934
|
-
interface TemplateRenderOptions {
|
|
935
|
-
/** Layout template to wrap content in */
|
|
936
|
-
layout?: string;
|
|
937
|
-
}
|
|
938
|
-
/**
|
|
939
|
-
* Route configuration object (Fastify-style)
|
|
940
|
-
*/
|
|
941
|
-
interface RouteConfig {
|
|
942
|
-
/** Route handler */
|
|
943
|
-
handler: RouteHandler;
|
|
944
|
-
/** Route middleware */
|
|
945
|
-
middleware?: Middleware[];
|
|
946
|
-
/** Route schema validation */
|
|
947
|
-
schema?: {
|
|
948
|
-
body?: Record<string, unknown>;
|
|
949
|
-
query?: Record<string, unknown>;
|
|
950
|
-
params?: Record<string, unknown>;
|
|
951
|
-
response?: Record<string, unknown>;
|
|
952
|
-
};
|
|
953
|
-
/** Route options */
|
|
954
|
-
options?: {
|
|
955
|
-
/** Route name */
|
|
956
|
-
name?: string;
|
|
957
|
-
/** Route description */
|
|
958
|
-
description?: string;
|
|
959
|
-
/** Route tags */
|
|
960
|
-
tags?: string[];
|
|
961
|
-
/** Route version */
|
|
962
|
-
version?: string;
|
|
963
|
-
/** Route deprecated */
|
|
964
|
-
deprecated?: boolean;
|
|
965
|
-
/** Route summary */
|
|
966
|
-
summary?: string;
|
|
967
|
-
/** Route external docs */
|
|
968
|
-
externalDocs?: {
|
|
969
|
-
description: string;
|
|
970
|
-
url: string;
|
|
971
|
-
};
|
|
972
|
-
};
|
|
973
|
-
}
|
|
974
|
-
/**
|
|
975
|
-
* Route data with handler and middleware
|
|
976
|
-
*/
|
|
977
|
-
interface RouteData {
|
|
978
|
-
handler: RouteHandler;
|
|
979
|
-
middleware: Middleware[];
|
|
980
|
-
}
|
|
981
|
-
/**
|
|
982
|
-
* Router interface for modular routing
|
|
983
|
-
*/
|
|
984
|
-
interface Router {
|
|
985
|
-
/** Register GET route */
|
|
986
|
-
get(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
987
|
-
/** Register POST route */
|
|
988
|
-
post(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
989
|
-
/** Register PUT route */
|
|
990
|
-
put(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
991
|
-
/** Register DELETE route */
|
|
992
|
-
delete(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
993
|
-
/** Register PATCH route */
|
|
994
|
-
patch(path: string, handler: RouteHandler | RouteConfig): Router;
|
|
995
|
-
/** Register middleware */
|
|
996
|
-
use(middleware: Middleware): Router;
|
|
997
|
-
/** Register sub-router */
|
|
998
|
-
use(prefix: string, router: Router): Router;
|
|
999
|
-
/** Get router middleware */
|
|
1000
|
-
getMiddleware(): Middleware[];
|
|
1001
|
-
/** Get router routes */
|
|
1002
|
-
getRoutes(): Map<string, RouteData>;
|
|
1003
|
-
}
|
|
1004
|
-
/**
|
|
1005
|
-
* Application interface (forward declaration)
|
|
1006
|
-
*/
|
|
1007
|
-
interface Application {
|
|
1008
|
-
/** Register GET route */
|
|
1009
|
-
get(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1010
|
-
/** Register POST route */
|
|
1011
|
-
post(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1012
|
-
/** Register PUT route */
|
|
1013
|
-
put(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1014
|
-
/** Register DELETE route */
|
|
1015
|
-
delete(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1016
|
-
/** Register PATCH route */
|
|
1017
|
-
patch(path: string, handler: RouteHandler | RouteConfig): Application;
|
|
1018
|
-
/** Register middleware */
|
|
1019
|
-
use(middleware: Middleware): Application;
|
|
1020
|
-
/** Register router */
|
|
1021
|
-
use(prefix: string, router: Router): Application;
|
|
1022
|
-
/** Create router */
|
|
1023
|
-
router(): Router;
|
|
1024
|
-
/** Start the server */
|
|
1025
|
-
listen(port?: number, callback?: () => void): unknown;
|
|
1026
|
-
listen(port?: number, host?: string, callback?: () => void): unknown;
|
|
1027
|
-
/** Get the underlying HTTP server */
|
|
1028
|
-
getServer(): http.Server;
|
|
1029
|
-
/** Gracefully shutdown the application */
|
|
1030
|
-
shutdown(): Promise<void>;
|
|
1031
|
-
/** Create CORS middleware */
|
|
1032
|
-
cors(options?: CorsOptions): Middleware;
|
|
1033
|
-
/** Create helmet middleware */
|
|
1034
|
-
helmet(options?: HelmetOptions): Middleware;
|
|
1035
|
-
/** Create JSON body parser middleware */
|
|
1036
|
-
json(options?: EnhancedBodyParserOptions): Middleware;
|
|
1037
|
-
/** Create URL-encoded body parser middleware */
|
|
1038
|
-
urlencoded(options?: EnhancedBodyParserOptions): Middleware;
|
|
1039
|
-
/** Create text body parser middleware */
|
|
1040
|
-
text(options?: EnhancedBodyParserOptions): Middleware;
|
|
1041
|
-
/** Create rate limiter middleware */
|
|
1042
|
-
rateLimit(options?: RateLimiterOptions): Middleware;
|
|
1043
|
-
/** Create logger middleware */
|
|
1044
|
-
logger(options?: LoggerOptions): Middleware;
|
|
1045
|
-
/** Create compression middleware */
|
|
1046
|
-
compression(options?: CompressionOptions): Middleware;
|
|
1047
|
-
/** Create request ID middleware */
|
|
1048
|
-
requestId(options?: RequestIdOptions): Middleware;
|
|
1049
|
-
/** Create timer middleware */
|
|
1050
|
-
timer(options?: TimerOptions): Middleware;
|
|
1051
|
-
/** Create smart body parser middleware */
|
|
1052
|
-
smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
1053
|
-
/** Create exception filter middleware */
|
|
1054
|
-
exceptionFilter(filters?: ExceptionFilter[]): Middleware;
|
|
1055
|
-
/** Simple Events API for Express-style event handling */
|
|
1056
|
-
events: {
|
|
1057
|
-
/** Emit a simple string-based event */
|
|
1058
|
-
emit(eventName: string, data?: any): Promise<void>;
|
|
1059
|
-
/** Listen for a simple string-based event */
|
|
1060
|
-
on(eventName: string, handler: (data: any) => void | Promise<void>): () => void;
|
|
1061
|
-
/** Listen for a simple string-based event (once) */
|
|
1062
|
-
once(eventName: string, handler?: (data: any) => void | Promise<void>): Promise<any>;
|
|
1063
|
-
/** Remove all listeners for an event */
|
|
1064
|
-
off(eventName: string): void;
|
|
1065
|
-
/** Remove all listeners */
|
|
1066
|
-
removeAllListeners(): void;
|
|
1067
|
-
/** Get list of event names that have listeners */
|
|
1068
|
-
eventNames(): string[];
|
|
1069
|
-
/** Get number of listeners for an event */
|
|
1070
|
-
listenerCount(eventName: string): number;
|
|
1071
|
-
/** Get maximum number of listeners */
|
|
1072
|
-
getMaxListeners(): number;
|
|
1073
|
-
/** Set maximum number of listeners */
|
|
1074
|
-
setMaxListeners(n: number): any;
|
|
1075
|
-
};
|
|
1076
|
-
/** Advanced Event System for CQRS and Event Sourcing */
|
|
1077
|
-
eventSystem: {
|
|
1078
|
-
/** Emit events */
|
|
1079
|
-
emit(event: any): Promise<void>;
|
|
1080
|
-
/** Subscribe to events */
|
|
1081
|
-
subscribe(eventType: string, handler: (event: any) => void | Promise<void>): {
|
|
1082
|
-
unsubscribe(): void;
|
|
1083
|
-
};
|
|
1084
|
-
/** Additional advanced methods available but not typed here for brevity */
|
|
1085
|
-
[key: string]: any;
|
|
1086
|
-
};
|
|
1087
|
-
/** Logger instance (set by LoggerPlugin) - overrides logger method when plugin is installed */
|
|
1088
|
-
loggerInstance?: {
|
|
1089
|
-
error: (message: string, context?: Record<string, unknown>) => void;
|
|
1090
|
-
warn: (message: string, context?: Record<string, unknown>) => void;
|
|
1091
|
-
info: (message: string, context?: Record<string, unknown>) => void;
|
|
1092
|
-
debug: (message: string, context?: Record<string, unknown>) => void;
|
|
1093
|
-
trace: (message: string, context?: Record<string, unknown>) => void;
|
|
1094
|
-
log: (message: string, context?: Record<string, unknown>) => void;
|
|
1095
|
-
};
|
|
1096
|
-
/** Register a WebSocket route (exact path or with trailing * wildcard) */
|
|
1097
|
-
ws?: (path: string, handler: WSHandler) => Application;
|
|
1098
|
-
/** Register a WebSocket middleware executed before the handler */
|
|
1099
|
-
wsUse?: (middleware: WSMiddleware) => Application;
|
|
1100
|
-
/** Broadcast a message to all sockets or a specific room */
|
|
1101
|
-
wsBroadcast?: (message: string, room?: string) => Application;
|
|
1102
|
-
/** Register a static files route */
|
|
1103
|
-
static?: (prefix: string, root: string, options?: StaticFilesOptions) => Application;
|
|
1104
|
-
/** Register template engine and view directory */
|
|
1105
|
-
setViewEngine?: (engine: string, viewsDir?: string, options?: TemplatePluginOptions) => Application;
|
|
1106
|
-
/** Add template helper */
|
|
1107
|
-
helper?: (name: string, fn: (value: unknown, ...args: unknown[]) => unknown) => Application;
|
|
1108
|
-
/** Add template partial */
|
|
1109
|
-
partial?: (name: string, template: string) => Application;
|
|
1110
|
-
}
|
|
1111
|
-
|
|
1112
|
-
/**
|
|
1113
|
-
* Base plugin class for NextRush v2
|
|
1114
|
-
*
|
|
1115
|
-
* @packageDocumentation
|
|
1116
|
-
*/
|
|
1117
|
-
|
|
1118
|
-
/**
|
|
1119
|
-
* Plugin interface
|
|
1120
|
-
*/
|
|
1121
|
-
interface Plugin {
|
|
1122
|
-
/** Plugin name */
|
|
1123
|
-
name: string;
|
|
1124
|
-
/** Plugin version */
|
|
1125
|
-
version: string;
|
|
1126
|
-
/** Plugin description */
|
|
1127
|
-
description?: string;
|
|
1128
|
-
/** Plugin author */
|
|
1129
|
-
author?: string;
|
|
1130
|
-
/** Plugin homepage */
|
|
1131
|
-
homepage?: string;
|
|
1132
|
-
/** Plugin license */
|
|
1133
|
-
license?: string;
|
|
1134
|
-
/** Plugin keywords */
|
|
1135
|
-
keywords?: string[];
|
|
1136
|
-
/** Install plugin on application */
|
|
1137
|
-
install(app: Application): void;
|
|
1138
|
-
/** Plugin initialization */
|
|
1139
|
-
init?(): void | Promise<void>;
|
|
1140
|
-
/** Plugin cleanup */
|
|
1141
|
-
cleanup?(): void | Promise<void>;
|
|
1142
|
-
/** Plugin configuration validation */
|
|
1143
|
-
validateConfig?(): boolean;
|
|
1144
|
-
/** Plugin health check */
|
|
1145
|
-
healthCheck?(): Promise<boolean>;
|
|
1146
|
-
}
|
|
1147
|
-
/**
|
|
1148
|
-
* Plugin metadata interface
|
|
1149
|
-
*/
|
|
1150
|
-
interface PluginMetadata {
|
|
1151
|
-
name: string;
|
|
1152
|
-
version: string;
|
|
1153
|
-
description?: string;
|
|
1154
|
-
author?: string;
|
|
1155
|
-
homepage?: string;
|
|
1156
|
-
license?: string;
|
|
1157
|
-
keywords?: string[];
|
|
1158
|
-
dependencies?: string[];
|
|
1159
|
-
conflicts?: string[];
|
|
1160
|
-
}
|
|
1161
|
-
/**
|
|
1162
|
-
* Base plugin class that all plugins should extend
|
|
1163
|
-
*
|
|
1164
|
-
* @example
|
|
1165
|
-
* ```typescript
|
|
1166
|
-
* import { BasePlugin } from 'nextrush-v2';
|
|
1167
|
-
* import type { Application } from 'nextrush-v2';
|
|
1168
|
-
*
|
|
1169
|
-
* export class MyPlugin extends BasePlugin {
|
|
1170
|
-
* name = 'MyPlugin';
|
|
1171
|
-
* version = '1.0.0';
|
|
1172
|
-
* description = 'A custom plugin';
|
|
1173
|
-
*
|
|
1174
|
-
* install(app: Application): void {
|
|
1175
|
-
* // Plugin installation logic
|
|
1176
|
-
* app.use((req, res, next) => {
|
|
1177
|
-
* // Middleware logic
|
|
1178
|
-
* next();
|
|
1179
|
-
* });
|
|
1180
|
-
* }
|
|
10
|
+
* This meta package provides the **functional** API for building Node.js APIs:
|
|
11
|
+
* - Application creation (createApp)
|
|
12
|
+
* - Routing (createRouter)
|
|
13
|
+
* - Server start (listen)
|
|
14
|
+
* - HTTP errors
|
|
15
|
+
* - Essential types
|
|
1181
16
|
*
|
|
1182
|
-
*
|
|
1183
|
-
*
|
|
1184
|
-
* }
|
|
17
|
+
* For the class-based paradigm (DI, decorators, controllers),
|
|
18
|
+
* import from `nextrush/class` instead.
|
|
1185
19
|
*
|
|
1186
|
-
*
|
|
1187
|
-
*
|
|
1188
|
-
*
|
|
1189
|
-
*
|
|
1190
|
-
*
|
|
1191
|
-
|
|
1192
|
-
declare abstract class BasePlugin implements Plugin {
|
|
1193
|
-
abstract name: string;
|
|
1194
|
-
abstract version: string;
|
|
1195
|
-
abstract onInstall(app: Application): void;
|
|
1196
|
-
description?: string;
|
|
1197
|
-
author?: string;
|
|
1198
|
-
homepage?: string;
|
|
1199
|
-
license?: string;
|
|
1200
|
-
keywords?: string[];
|
|
1201
|
-
dependencies?: string[];
|
|
1202
|
-
conflicts?: string[];
|
|
1203
|
-
protected app?: Application;
|
|
1204
|
-
protected config: Record<string, unknown>;
|
|
1205
|
-
protected isInitialized: boolean;
|
|
1206
|
-
protected isInstalled: boolean;
|
|
1207
|
-
/**
|
|
1208
|
-
* Install the plugin on an application
|
|
1209
|
-
*/
|
|
1210
|
-
install(app: Application): void;
|
|
1211
|
-
/**
|
|
1212
|
-
* Abstract method that plugins must implement
|
|
1213
|
-
*/
|
|
1214
|
-
/**
|
|
1215
|
-
* Get plugin metadata
|
|
1216
|
-
*/
|
|
1217
|
-
getMetadata(): PluginMetadata;
|
|
1218
|
-
/**
|
|
1219
|
-
* Set plugin configuration
|
|
1220
|
-
*/
|
|
1221
|
-
setConfig(config: Record<string, unknown>): void;
|
|
1222
|
-
/**
|
|
1223
|
-
* Get plugin configuration
|
|
1224
|
-
*/
|
|
1225
|
-
getConfig(): Record<string, unknown>;
|
|
1226
|
-
/**
|
|
1227
|
-
* Get a specific configuration value
|
|
1228
|
-
*/
|
|
1229
|
-
getConfigValue<T>(key: string, defaultValue?: T): T | undefined;
|
|
1230
|
-
/**
|
|
1231
|
-
* Check if plugin is installed
|
|
1232
|
-
*/
|
|
1233
|
-
isPluginInstalled(): boolean;
|
|
1234
|
-
/**
|
|
1235
|
-
* Check if plugin is initialized
|
|
1236
|
-
*/
|
|
1237
|
-
isPluginInitialized(): boolean;
|
|
1238
|
-
/**
|
|
1239
|
-
* Register middleware with the application
|
|
1240
|
-
*/
|
|
1241
|
-
protected registerMiddleware(middleware: Middleware): void;
|
|
1242
|
-
/**
|
|
1243
|
-
* Log plugin message
|
|
1244
|
-
*/
|
|
1245
|
-
protected log(message: string): void;
|
|
1246
|
-
/**
|
|
1247
|
-
* Log plugin error
|
|
1248
|
-
*/
|
|
1249
|
-
protected logError(message: string, error?: Error): void;
|
|
1250
|
-
/**
|
|
1251
|
-
* Log plugin warning
|
|
1252
|
-
*/
|
|
1253
|
-
protected logWarning(message: string): void;
|
|
1254
|
-
/**
|
|
1255
|
-
* Log plugin debug message
|
|
1256
|
-
*/
|
|
1257
|
-
protected logDebug(message: string): void;
|
|
1258
|
-
/**
|
|
1259
|
-
* Emit plugin event
|
|
1260
|
-
*/
|
|
1261
|
-
protected emit(event: string, ...args: unknown[]): void;
|
|
1262
|
-
/**
|
|
1263
|
-
* Create a middleware that wraps the plugin's functionality
|
|
1264
|
-
*/
|
|
1265
|
-
protected createMiddleware(handler: (ctx: Context, next: () => Promise<void>) => void | Promise<void>): Middleware;
|
|
1266
|
-
/**
|
|
1267
|
-
* Create an async middleware that wraps the plugin's functionality
|
|
1268
|
-
*/
|
|
1269
|
-
protected createAsyncMiddleware(handler: (ctx: Context, next: () => Promise<void>) => Promise<void>): Middleware;
|
|
1270
|
-
/**
|
|
1271
|
-
* Validate plugin configuration
|
|
1272
|
-
*/
|
|
1273
|
-
validateConfig(): boolean;
|
|
1274
|
-
/**
|
|
1275
|
-
* Plugin health check
|
|
1276
|
-
*/
|
|
1277
|
-
healthCheck(): Promise<boolean>;
|
|
1278
|
-
/**
|
|
1279
|
-
* Get plugin status
|
|
1280
|
-
*/
|
|
1281
|
-
getStatus(): Record<string, unknown>;
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
/**
|
|
1285
|
-
* Logger Types and Interfaces for NextRush v2
|
|
1286
|
-
*
|
|
1287
|
-
* @packageDocumentation
|
|
1288
|
-
*/
|
|
1289
|
-
declare enum LogLevel {
|
|
1290
|
-
ERROR = 0,
|
|
1291
|
-
WARN = 1,
|
|
1292
|
-
INFO = 2,
|
|
1293
|
-
DEBUG = 3,
|
|
1294
|
-
TRACE = 4
|
|
1295
|
-
}
|
|
1296
|
-
interface LogEntry {
|
|
1297
|
-
timestamp: Date | string;
|
|
1298
|
-
level: LogLevel | string;
|
|
1299
|
-
message: string;
|
|
1300
|
-
context?: Record<string, unknown>;
|
|
1301
|
-
error?: Error;
|
|
1302
|
-
}
|
|
1303
|
-
interface LoggerConfig extends Record<string, unknown> {
|
|
1304
|
-
level?: LogLevel;
|
|
1305
|
-
format?: 'json' | 'text' | 'simple';
|
|
1306
|
-
timestamp?: boolean;
|
|
1307
|
-
colors?: boolean;
|
|
1308
|
-
maxEntries?: number;
|
|
1309
|
-
flushInterval?: number;
|
|
1310
|
-
maxMemoryUsage?: number;
|
|
1311
|
-
asyncFlush?: boolean;
|
|
1312
|
-
transports?: Array<{
|
|
1313
|
-
type: 'console' | 'file' | 'stream';
|
|
1314
|
-
options?: Record<string, unknown>;
|
|
1315
|
-
}>;
|
|
1316
|
-
}
|
|
1317
|
-
/**
|
|
1318
|
-
* Transport interface
|
|
1319
|
-
*/
|
|
1320
|
-
interface Transport {
|
|
1321
|
-
name: string;
|
|
1322
|
-
level: string;
|
|
1323
|
-
write(entry: LogEntry): void | Promise<void>;
|
|
1324
|
-
}
|
|
1325
|
-
|
|
1326
|
-
/**
|
|
1327
|
-
* Core Logger Plugin for NextRush v2
|
|
1328
|
-
*
|
|
1329
|
-
* @packageDocumentation
|
|
1330
|
-
*/
|
|
1331
|
-
|
|
1332
|
-
declare class LoggerPlugin extends BasePlugin {
|
|
1333
|
-
name: string;
|
|
1334
|
-
version: string;
|
|
1335
|
-
config: LoggerConfig;
|
|
1336
|
-
private entries;
|
|
1337
|
-
private flushTimer?;
|
|
1338
|
-
private _transports;
|
|
1339
|
-
private eventListeners;
|
|
1340
|
-
constructor(config?: LoggerConfig);
|
|
1341
|
-
onInstall(app: Application): void;
|
|
1342
|
-
private startFlushTimer;
|
|
1343
|
-
private stopFlushTimer;
|
|
1344
|
-
private addEntry;
|
|
1345
|
-
/**
|
|
1346
|
-
* Check memory usage and flush if necessary
|
|
1347
|
-
*/
|
|
1348
|
-
private checkMemoryUsage;
|
|
1349
|
-
private flush;
|
|
1350
|
-
private writeToTransport;
|
|
1351
|
-
/**
|
|
1352
|
-
* Write latest entry to all transports
|
|
1353
|
-
*/
|
|
1354
|
-
private writeToTransports;
|
|
1355
|
-
error(message: string, context?: Record<string, unknown>): void;
|
|
1356
|
-
warn(message: string, context?: Record<string, unknown>): void;
|
|
1357
|
-
info(message: string, context?: Record<string, unknown>): void;
|
|
1358
|
-
debug(message: string, context?: Record<string, unknown>): void;
|
|
1359
|
-
trace(message: string, context?: Record<string, unknown>): void;
|
|
1360
|
-
log(message: string, context?: Record<string, unknown>): void;
|
|
1361
|
-
getEntries(): LogEntry[];
|
|
1362
|
-
clear(): void;
|
|
1363
|
-
setLevel(level: LogLevel | string): void;
|
|
1364
|
-
/**
|
|
1365
|
-
* Add a transport
|
|
1366
|
-
*/
|
|
1367
|
-
addTransport(transport: Transport): void;
|
|
1368
|
-
/**
|
|
1369
|
-
* Remove a transport by name
|
|
1370
|
-
*/
|
|
1371
|
-
removeTransport(name: string): void;
|
|
1372
|
-
/**
|
|
1373
|
-
* Add event listener
|
|
1374
|
-
*/
|
|
1375
|
-
on(event: string, listener: (entry: LogEntry) => void): void;
|
|
1376
|
-
/**
|
|
1377
|
-
* Remove event listener
|
|
1378
|
-
*/
|
|
1379
|
-
off(event: string, listener: (entry: LogEntry) => void): void;
|
|
1380
|
-
/**
|
|
1381
|
-
* Log a message (internal method for testing)
|
|
1382
|
-
*/
|
|
1383
|
-
logMessage(level: LogLevel | string, message: string, context?: Record<string, unknown>): void;
|
|
1384
|
-
/**
|
|
1385
|
-
* Get transports (for testing)
|
|
1386
|
-
*/
|
|
1387
|
-
getTransports(): Transport[];
|
|
1388
|
-
/**
|
|
1389
|
-
* Get transports property (for testing)
|
|
1390
|
-
*/
|
|
1391
|
-
get transports(): Transport[];
|
|
1392
|
-
cleanup(): void;
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
/**
|
|
1396
|
-
* Logger Factory Functions for NextRush v2
|
|
20
|
+
* For middleware, install separately:
|
|
21
|
+
* - @nextrush/cors
|
|
22
|
+
* - @nextrush/helmet
|
|
23
|
+
* - @nextrush/body-parser
|
|
24
|
+
* - @nextrush/rate-limit
|
|
25
|
+
* - @nextrush/logger
|
|
1397
26
|
*
|
|
1398
|
-
*
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
* Create minimal logger for testing
|
|
1403
|
-
*/
|
|
1404
|
-
declare function createMinimalLogger(): LoggerPlugin;
|
|
1405
|
-
/**
|
|
1406
|
-
* Create development logger
|
|
1407
|
-
*/
|
|
1408
|
-
declare function createDevLogger(): LoggerPlugin;
|
|
1409
|
-
/**
|
|
1410
|
-
* Create production logger
|
|
1411
|
-
*/
|
|
1412
|
-
declare function createProdLogger(): LoggerPlugin;
|
|
1413
|
-
|
|
1414
|
-
/**
|
|
1415
|
-
* Logger Transport implementations for NextRush v2
|
|
27
|
+
* For other runtimes, install the appropriate adapter:
|
|
28
|
+
* - @nextrush/adapter-bun
|
|
29
|
+
* - @nextrush/adapter-deno
|
|
30
|
+
* - @nextrush/adapter-edge
|
|
1416
31
|
*
|
|
1417
32
|
* @packageDocumentation
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
/**
|
|
1421
|
-
* Console Transport
|
|
1422
|
-
*/
|
|
1423
|
-
declare class ConsoleTransport implements Transport {
|
|
1424
|
-
name: string;
|
|
1425
|
-
private _level;
|
|
1426
|
-
private _levelString;
|
|
1427
|
-
constructor(level?: LogLevel | string);
|
|
1428
|
-
get levelString(): string;
|
|
1429
|
-
get level(): string;
|
|
1430
|
-
set level(value: LogLevel | string);
|
|
1431
|
-
write(entry: LogEntry): void;
|
|
1432
|
-
}
|
|
1433
|
-
/**
|
|
1434
|
-
* File Transport
|
|
1435
|
-
*/
|
|
1436
|
-
declare class FileTransport implements Transport {
|
|
1437
|
-
name: string;
|
|
1438
|
-
private _level;
|
|
1439
|
-
private filePath;
|
|
1440
|
-
private _levelString;
|
|
1441
|
-
constructor(filePath: string, level?: LogLevel | string);
|
|
1442
|
-
get levelString(): string;
|
|
1443
|
-
get level(): string;
|
|
1444
|
-
set level(value: LogLevel | string);
|
|
1445
|
-
write(entry: LogEntry): Promise<void>;
|
|
1446
|
-
}
|
|
1447
|
-
/**
|
|
1448
|
-
* HTTP Transport
|
|
1449
|
-
*/
|
|
1450
|
-
declare class HttpTransport implements Transport {
|
|
1451
|
-
name: string;
|
|
1452
|
-
private _level;
|
|
1453
|
-
private url;
|
|
1454
|
-
private _levelString;
|
|
1455
|
-
constructor(url: string, level?: LogLevel | string);
|
|
1456
|
-
get levelString(): string;
|
|
1457
|
-
get level(): string;
|
|
1458
|
-
set level(value: LogLevel | string);
|
|
1459
|
-
write(entry: LogEntry): Promise<void>;
|
|
1460
|
-
}
|
|
1461
|
-
/**
|
|
1462
|
-
* Stream Transport
|
|
1463
|
-
*/
|
|
1464
|
-
declare class StreamTransport implements Transport {
|
|
1465
|
-
name: string;
|
|
1466
|
-
private _level;
|
|
1467
|
-
private stream;
|
|
1468
|
-
private _levelString;
|
|
1469
|
-
constructor(stream: NodeJS.WritableStream, level?: LogLevel | string);
|
|
1470
|
-
get levelString(): string;
|
|
1471
|
-
get level(): string;
|
|
1472
|
-
set level(value: LogLevel | string);
|
|
1473
|
-
write(entry: LogEntry): void;
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
/**
|
|
1477
|
-
* NextRush v2 Event System Types
|
|
1478
|
-
*
|
|
1479
|
-
* Comprehensive type-safe event system with CQRS patterns,
|
|
1480
|
-
* event sourcing, and pipeline processing capabilities.
|
|
1481
|
-
*
|
|
1482
|
-
* @version 2.0.0
|
|
1483
|
-
* @author NextRush Core Team
|
|
1484
|
-
*/
|
|
1485
|
-
|
|
1486
|
-
/**
|
|
1487
|
-
* Base metadata for all events
|
|
1488
|
-
*/
|
|
1489
|
-
interface BaseEventMetadata {
|
|
1490
|
-
/** Unique event ID */
|
|
1491
|
-
readonly id: string;
|
|
1492
|
-
/** Event timestamp in milliseconds */
|
|
1493
|
-
readonly timestamp: number;
|
|
1494
|
-
/** Event correlation ID for tracing */
|
|
1495
|
-
readonly correlationId?: string;
|
|
1496
|
-
/** User/system that triggered the event */
|
|
1497
|
-
readonly source: string;
|
|
1498
|
-
/** Event version for evolution */
|
|
1499
|
-
readonly version: number;
|
|
1500
|
-
/** Additional custom metadata */
|
|
1501
|
-
readonly [key: string]: unknown;
|
|
1502
|
-
}
|
|
1503
|
-
/**
|
|
1504
|
-
* Generic Event interface with full type safety
|
|
1505
|
-
*
|
|
1506
|
-
* @template TType - Event type identifier
|
|
1507
|
-
* @template TData - Event payload data
|
|
1508
|
-
* @template TMetadata - Additional event metadata
|
|
1509
|
-
*/
|
|
1510
|
-
interface Event<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> {
|
|
1511
|
-
/** Event type identifier */
|
|
1512
|
-
readonly type: TType;
|
|
1513
|
-
/** Event payload data */
|
|
1514
|
-
readonly data: TData;
|
|
1515
|
-
/** Event metadata */
|
|
1516
|
-
readonly metadata: TMetadata;
|
|
1517
|
-
}
|
|
1518
|
-
/**
|
|
1519
|
-
* Command interface for CQRS pattern
|
|
1520
|
-
* Commands represent intent to change state
|
|
1521
|
-
*/
|
|
1522
|
-
interface Command<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1523
|
-
/** Command should be processed exactly once */
|
|
1524
|
-
readonly idempotencyKey?: string;
|
|
1525
|
-
/** Command execution timeout in milliseconds */
|
|
1526
|
-
readonly timeout?: number;
|
|
1527
|
-
}
|
|
1528
|
-
/**
|
|
1529
|
-
* Query interface for CQRS pattern
|
|
1530
|
-
* Queries represent intent to read state
|
|
1531
|
-
*/
|
|
1532
|
-
interface Query<TType extends string = string, TData = unknown, TResult = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1533
|
-
/** Expected result type (for type inference) */
|
|
1534
|
-
readonly _resultType?: TResult;
|
|
1535
|
-
}
|
|
1536
|
-
/**
|
|
1537
|
-
* Domain Event for business logic events
|
|
1538
|
-
*/
|
|
1539
|
-
interface DomainEvent<TType extends string = string, TData = unknown, TMetadata extends BaseEventMetadata = BaseEventMetadata> extends Event<TType, TData, TMetadata> {
|
|
1540
|
-
/** Aggregate ID that produced this event */
|
|
1541
|
-
readonly aggregateId: string;
|
|
1542
|
-
/** Aggregate type */
|
|
1543
|
-
readonly aggregateType: string;
|
|
1544
|
-
/** Event sequence number for ordering */
|
|
1545
|
-
readonly sequenceNumber: number;
|
|
1546
|
-
}
|
|
1547
|
-
/**
|
|
1548
|
-
* Event handler function type
|
|
1549
|
-
*/
|
|
1550
|
-
type EventHandler<T extends Event = Event> = (event: T, context?: Context) => Promise<void> | void;
|
|
1551
|
-
/**
|
|
1552
|
-
* Event handler with metadata
|
|
1553
|
-
*/
|
|
1554
|
-
interface EventHandlerDefinition<T extends Event = Event> {
|
|
1555
|
-
/** Handler function */
|
|
1556
|
-
readonly handler: EventHandler<T>;
|
|
1557
|
-
/** Handler priority (lower = higher priority) */
|
|
1558
|
-
readonly priority?: number;
|
|
1559
|
-
/** Handler should run only once */
|
|
1560
|
-
readonly once?: boolean;
|
|
1561
|
-
/** Handler timeout in milliseconds */
|
|
1562
|
-
readonly timeout?: number;
|
|
1563
|
-
/** Handler retry configuration */
|
|
1564
|
-
readonly retry?: {
|
|
1565
|
-
readonly maxAttempts: number;
|
|
1566
|
-
readonly delay: number;
|
|
1567
|
-
readonly backoffMultiplier?: number;
|
|
1568
|
-
};
|
|
1569
|
-
}
|
|
1570
|
-
/**
|
|
1571
|
-
* Event pipeline middleware function
|
|
1572
|
-
*/
|
|
1573
|
-
type EventPipelineMiddleware<T extends Event = Event> = (event: T, next: () => Promise<void>) => Promise<void> | void;
|
|
1574
|
-
/**
|
|
1575
|
-
* Event transformer function
|
|
1576
|
-
*/
|
|
1577
|
-
type EventTransformer<TInput extends Event, TOutput extends Event> = (event: TInput) => Promise<TOutput> | TOutput;
|
|
1578
|
-
/**
|
|
1579
|
-
* Event filter predicate
|
|
1580
|
-
*/
|
|
1581
|
-
type EventFilter<T extends Event = Event> = (event: T) => boolean | Promise<boolean>;
|
|
1582
|
-
/**
|
|
1583
|
-
* Event pipeline stage
|
|
1584
|
-
*/
|
|
1585
|
-
interface EventPipelineStage<T extends Event = Event> {
|
|
1586
|
-
/** Stage name */
|
|
1587
|
-
readonly name: string;
|
|
1588
|
-
/** Stage middleware */
|
|
1589
|
-
readonly middleware?: EventPipelineMiddleware<T>[];
|
|
1590
|
-
/** Event transformers */
|
|
1591
|
-
readonly transformers?: EventTransformer<T, T>[];
|
|
1592
|
-
/** Event filters */
|
|
1593
|
-
readonly filters?: EventFilter<T>[];
|
|
1594
|
-
/** Stage timeout in milliseconds */
|
|
1595
|
-
readonly timeout?: number;
|
|
1596
|
-
}
|
|
1597
|
-
/**
|
|
1598
|
-
* Event pipeline configuration
|
|
1599
|
-
*/
|
|
1600
|
-
interface EventPipelineConfig<T extends Event = Event> {
|
|
1601
|
-
/** Pipeline name */
|
|
1602
|
-
readonly name: string;
|
|
1603
|
-
/** Pipeline stages */
|
|
1604
|
-
readonly stages: EventPipelineStage<T>[];
|
|
1605
|
-
/** Error handling strategy */
|
|
1606
|
-
readonly errorHandling?: 'stop' | 'continue' | 'retry';
|
|
1607
|
-
/** Pipeline timeout in milliseconds */
|
|
1608
|
-
readonly timeout?: number;
|
|
1609
|
-
/** Enable performance monitoring */
|
|
1610
|
-
readonly monitoring?: boolean;
|
|
1611
|
-
}
|
|
1612
|
-
/**
|
|
1613
|
-
* Event subscription handle
|
|
1614
|
-
*/
|
|
1615
|
-
interface EventSubscription {
|
|
1616
|
-
/** Subscription ID */
|
|
1617
|
-
readonly id: string;
|
|
1618
|
-
/** Unsubscribe from events */
|
|
1619
|
-
unsubscribe(): Promise<void>;
|
|
1620
|
-
/** Check if subscription is active */
|
|
1621
|
-
isActive(): boolean;
|
|
1622
|
-
}
|
|
1623
|
-
/**
|
|
1624
|
-
* Event store statistics
|
|
1625
|
-
*/
|
|
1626
|
-
interface EventStoreStats {
|
|
1627
|
-
/** Total events stored */
|
|
1628
|
-
readonly totalEvents: number;
|
|
1629
|
-
/** Events by type */
|
|
1630
|
-
readonly eventsByType: Record<string, number>;
|
|
1631
|
-
/** Storage size in bytes */
|
|
1632
|
-
readonly storageSize: number;
|
|
1633
|
-
/** Last event timestamp */
|
|
1634
|
-
readonly lastEventTimestamp?: number;
|
|
1635
|
-
}
|
|
1636
|
-
/**
|
|
1637
|
-
* Event processing metrics
|
|
1638
|
-
*/
|
|
1639
|
-
interface EventMetrics {
|
|
1640
|
-
/** Events emitted by type */
|
|
1641
|
-
readonly eventsEmitted: Record<string, number>;
|
|
1642
|
-
/** Events processed by type */
|
|
1643
|
-
readonly eventsProcessed: Record<string, number>;
|
|
1644
|
-
/** Processing errors by type */
|
|
1645
|
-
readonly processingErrors: Record<string, number>;
|
|
1646
|
-
/** Average processing time by type (ms) */
|
|
1647
|
-
readonly averageProcessingTime: Record<string, number>;
|
|
1648
|
-
/** Pipeline execution stats */
|
|
1649
|
-
readonly pipelineStats: Record<string, PipelineStats>;
|
|
1650
|
-
/** Memory usage stats */
|
|
1651
|
-
readonly memoryUsage: {
|
|
1652
|
-
readonly heapUsed: number;
|
|
1653
|
-
readonly heapTotal: number;
|
|
1654
|
-
readonly external: number;
|
|
1655
|
-
};
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* Pipeline execution statistics
|
|
1659
|
-
*/
|
|
1660
|
-
interface PipelineStats {
|
|
1661
|
-
/** Pipeline executions count */
|
|
1662
|
-
readonly executions: number;
|
|
1663
|
-
/** Average execution time (ms) */
|
|
1664
|
-
readonly averageExecutionTime: number;
|
|
1665
|
-
/** Successful executions */
|
|
1666
|
-
readonly successes: number;
|
|
1667
|
-
/** Failed executions */
|
|
1668
|
-
readonly failures: number;
|
|
1669
|
-
/** Stage execution stats */
|
|
1670
|
-
readonly stageStats: Record<string, {
|
|
1671
|
-
readonly executions: number;
|
|
1672
|
-
readonly averageTime: number;
|
|
1673
|
-
readonly failures: number;
|
|
1674
|
-
}>;
|
|
1675
|
-
}
|
|
1676
|
-
|
|
1677
|
-
/**
|
|
1678
|
-
* Command handler type
|
|
1679
|
-
*/
|
|
1680
|
-
type CommandHandler<TCommand extends Command, TResult = void> = (command: TCommand) => Promise<TResult> | TResult;
|
|
1681
|
-
/**
|
|
1682
|
-
* Query handler type
|
|
1683
|
-
*/
|
|
1684
|
-
type QueryHandler<TQuery extends Query, TResult = unknown> = (query: TQuery) => Promise<TResult> | TResult;
|
|
1685
|
-
/**
|
|
1686
|
-
* Event system configuration
|
|
1687
|
-
*/
|
|
1688
|
-
interface EventSystemConfig {
|
|
1689
|
-
/** Enable event store persistence */
|
|
1690
|
-
readonly enableEventStore?: boolean;
|
|
1691
|
-
/** Event store type */
|
|
1692
|
-
readonly eventStoreType?: 'memory' | 'persistent';
|
|
1693
|
-
/** Maximum events for in-memory store */
|
|
1694
|
-
readonly maxStoredEvents?: number;
|
|
1695
|
-
/** Enable performance monitoring */
|
|
1696
|
-
readonly enableMonitoring?: boolean;
|
|
1697
|
-
/** Default event handler timeout */
|
|
1698
|
-
readonly defaultTimeout?: number;
|
|
1699
|
-
/** Maximum concurrent event processing */
|
|
1700
|
-
readonly maxConcurrency?: number;
|
|
1701
|
-
}
|
|
1702
|
-
/**
|
|
1703
|
-
* Complete event system with CQRS and Event Sourcing
|
|
1704
|
-
*/
|
|
1705
|
-
declare class NextRushEventSystem {
|
|
1706
|
-
private readonly eventEmitter;
|
|
1707
|
-
private readonly eventStore?;
|
|
1708
|
-
private readonly commandHandlers;
|
|
1709
|
-
private readonly queryHandlers;
|
|
1710
|
-
private readonly config;
|
|
1711
|
-
private systemSubscriptions;
|
|
1712
|
-
constructor(config?: EventSystemConfig);
|
|
1713
|
-
/**
|
|
1714
|
-
* Emit an event
|
|
1715
|
-
*/
|
|
1716
|
-
emit<T extends Event>(event: T): Promise<void>;
|
|
1717
|
-
/**
|
|
1718
|
-
* Create and emit an event
|
|
1719
|
-
*/
|
|
1720
|
-
emitEvent<T extends Event>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): Promise<void>;
|
|
1721
|
-
/**
|
|
1722
|
-
* Create and emit a domain event
|
|
1723
|
-
*/
|
|
1724
|
-
emitDomainEvent<T extends DomainEvent>(type: T['type'], data: T['data'], aggregateId: string, aggregateType: string, sequenceNumber: number, metadata?: Partial<BaseEventMetadata>): Promise<void>;
|
|
1725
|
-
/**
|
|
1726
|
-
* Subscribe to events
|
|
1727
|
-
*/
|
|
1728
|
-
subscribe<T extends Event>(eventType: string, handler: EventHandler<T>): EventSubscription;
|
|
1729
|
-
/**
|
|
1730
|
-
* Subscribe with options
|
|
1731
|
-
*/
|
|
1732
|
-
subscribeWithOptions<T extends Event>(eventType: string, definition: EventHandlerDefinition<T>): EventSubscription;
|
|
1733
|
-
/**
|
|
1734
|
-
* Unsubscribe from events
|
|
1735
|
-
*/
|
|
1736
|
-
unsubscribeAll(eventType: string): Promise<void>;
|
|
1737
|
-
/**
|
|
1738
|
-
* Add event pipeline
|
|
1739
|
-
*/
|
|
1740
|
-
addPipeline<T extends Event>(eventType: string, pipeline: EventPipelineConfig<T>): void;
|
|
1741
|
-
/**
|
|
1742
|
-
* Remove event pipeline
|
|
1743
|
-
*/
|
|
1744
|
-
removePipeline(eventType: string, pipelineName: string): void;
|
|
1745
|
-
/**
|
|
1746
|
-
* Get pipeline names
|
|
1747
|
-
*/
|
|
1748
|
-
getPipelineNames(eventType: string): string[];
|
|
1749
|
-
/**
|
|
1750
|
-
* Register command handler
|
|
1751
|
-
*/
|
|
1752
|
-
registerCommandHandler<TCommand extends Command, TResult = void>(commandType: string, handler: CommandHandler<TCommand, TResult>): void;
|
|
1753
|
-
/**
|
|
1754
|
-
* Execute command
|
|
1755
|
-
*/
|
|
1756
|
-
executeCommand<TCommand extends Command, TResult = void>(command: TCommand): Promise<TResult>;
|
|
1757
|
-
/**
|
|
1758
|
-
* Register query handler
|
|
1759
|
-
*/
|
|
1760
|
-
registerQueryHandler<TQuery extends Query, TResult = unknown>(queryType: string, handler: QueryHandler<TQuery, TResult>): void;
|
|
1761
|
-
/**
|
|
1762
|
-
* Execute query
|
|
1763
|
-
*/
|
|
1764
|
-
executeQuery<TQuery extends Query, TResult = unknown>(query: TQuery): Promise<TResult>;
|
|
1765
|
-
/**
|
|
1766
|
-
* Load events for aggregate
|
|
1767
|
-
*/
|
|
1768
|
-
loadAggregateEvents<T extends DomainEvent>(aggregateId: string, options?: {
|
|
1769
|
-
readonly afterSequence?: number;
|
|
1770
|
-
readonly limit?: number;
|
|
1771
|
-
}): Promise<T[]>;
|
|
1772
|
-
/**
|
|
1773
|
-
* Load events by correlation ID
|
|
1774
|
-
*/
|
|
1775
|
-
loadCorrelatedEvents<T extends Event>(correlationId: string, options?: {
|
|
1776
|
-
readonly limit?: number;
|
|
1777
|
-
readonly offset?: number;
|
|
1778
|
-
}): Promise<T[]>;
|
|
1779
|
-
/**
|
|
1780
|
-
* Load events by type
|
|
1781
|
-
*/
|
|
1782
|
-
loadEventsByType<T extends Event>(eventType: string, options?: {
|
|
1783
|
-
readonly after?: Date;
|
|
1784
|
-
readonly before?: Date;
|
|
1785
|
-
readonly limit?: number;
|
|
1786
|
-
readonly offset?: number;
|
|
1787
|
-
}): Promise<T[]>;
|
|
1788
|
-
/**
|
|
1789
|
-
* Get event metrics
|
|
1790
|
-
*/
|
|
1791
|
-
getMetrics(): EventMetrics;
|
|
1792
|
-
/**
|
|
1793
|
-
* Get event store statistics
|
|
1794
|
-
*/
|
|
1795
|
-
getEventStoreStats(): Promise<EventStoreStats>;
|
|
1796
|
-
/**
|
|
1797
|
-
* Get subscription count
|
|
1798
|
-
*/
|
|
1799
|
-
getSubscriptionCount(eventType?: string): number;
|
|
1800
|
-
/**
|
|
1801
|
-
* Enable/disable monitoring
|
|
1802
|
-
*/
|
|
1803
|
-
setMonitoring(enabled: boolean): void;
|
|
1804
|
-
/**
|
|
1805
|
-
* Clear all events and subscriptions
|
|
1806
|
-
*/
|
|
1807
|
-
clear(): Promise<void>;
|
|
1808
|
-
/**
|
|
1809
|
-
* Shutdown the event system
|
|
1810
|
-
*/
|
|
1811
|
-
shutdown(): Promise<void>;
|
|
1812
|
-
/**
|
|
1813
|
-
* Create event with metadata
|
|
1814
|
-
*/
|
|
1815
|
-
createEvent<T extends Event>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1816
|
-
/**
|
|
1817
|
-
* Create command with metadata
|
|
1818
|
-
*/
|
|
1819
|
-
createCommand<T extends Command>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1820
|
-
/**
|
|
1821
|
-
* Create query with metadata
|
|
1822
|
-
*/
|
|
1823
|
-
createQuery<T extends Query>(type: T['type'], data: T['data'], metadata?: Partial<BaseEventMetadata>): T;
|
|
1824
|
-
/**
|
|
1825
|
-
* Create domain event with aggregate info
|
|
1826
|
-
*/
|
|
1827
|
-
createDomainEvent<T extends DomainEvent>(type: T['type'], data: T['data'], aggregateId: string, aggregateType: string, sequenceNumber: number, metadata?: Partial<BaseEventMetadata>): T;
|
|
1828
|
-
/**
|
|
1829
|
-
* Emit system event
|
|
1830
|
-
*/
|
|
1831
|
-
private emitSystemEvent;
|
|
1832
|
-
/**
|
|
1833
|
-
* Auto-persist events to store
|
|
1834
|
-
*/
|
|
1835
|
-
private persistEventHandler;
|
|
1836
|
-
/**
|
|
1837
|
-
* Generic dispatch method for commands, queries, or events
|
|
1838
|
-
* This provides a unified interface for different operation types
|
|
1839
|
-
*/
|
|
1840
|
-
dispatch<T = any>(operation: Command | Query | Event): Promise<T>;
|
|
1841
|
-
}
|
|
1842
|
-
|
|
1843
|
-
/**
|
|
1844
|
-
* Simple Events API Facade for NextRush v2
|
|
1845
|
-
*
|
|
1846
|
-
* Provides a simple string-based event API that bridges to the sophisticated
|
|
1847
|
-
* CQRS/Event Sourcing implementation underneath.
|
|
1848
|
-
*
|
|
1849
|
-
* @version 2.0.0
|
|
1850
|
-
* @author NextRush Core Team
|
|
1851
|
-
*/
|
|
1852
|
-
|
|
1853
|
-
/**
|
|
1854
|
-
* Simple event handler type for string-based events
|
|
1855
|
-
*/
|
|
1856
|
-
type SimpleEventHandler = (data: any) => void | Promise<void>;
|
|
1857
|
-
/**
|
|
1858
|
-
* Simple Events API Facade
|
|
33
|
+
* @module nextrush
|
|
1859
34
|
*
|
|
1860
|
-
*
|
|
1861
|
-
* the sophisticated CQRS implementation underneath.
|
|
1862
|
-
*/
|
|
1863
|
-
declare class SimpleEventsAPI {
|
|
1864
|
-
private eventSystem;
|
|
1865
|
-
private listeners;
|
|
1866
|
-
constructor(eventSystem: NextRushEventSystem);
|
|
1867
|
-
/**
|
|
1868
|
-
* Emit a simple string-based event
|
|
1869
|
-
*
|
|
1870
|
-
* @param eventName - Event name
|
|
1871
|
-
* @param data - Event data
|
|
1872
|
-
* @returns Promise that resolves when event is processed
|
|
1873
|
-
*
|
|
1874
|
-
* @example
|
|
1875
|
-
* ```typescript
|
|
1876
|
-
* app.events.emit('user.created', { userId: '123', name: 'John' });
|
|
1877
|
-
* ```
|
|
1878
|
-
*/
|
|
1879
|
-
emit(eventName: string, data?: any): Promise<void>;
|
|
1880
|
-
/**
|
|
1881
|
-
* Listen for a simple string-based event
|
|
1882
|
-
*
|
|
1883
|
-
* @param eventName - Event name to listen for
|
|
1884
|
-
* @param handler - Handler function
|
|
1885
|
-
* @returns Unsubscribe function
|
|
1886
|
-
*
|
|
1887
|
-
* @example
|
|
1888
|
-
* ```typescript
|
|
1889
|
-
* const unsubscribe = app.events.on('user.created', (data) => {
|
|
1890
|
-
* console.log('User created:', data.userId);
|
|
1891
|
-
* });
|
|
1892
|
-
* ```
|
|
1893
|
-
*/
|
|
1894
|
-
on(eventName: string, handler: SimpleEventHandler): () => void;
|
|
1895
|
-
/**
|
|
1896
|
-
* Listen for a simple string-based event (once)
|
|
1897
|
-
*
|
|
1898
|
-
* @param eventName - Event name to listen for
|
|
1899
|
-
* @param handler - Handler function
|
|
1900
|
-
* @returns Promise that resolves with event data
|
|
1901
|
-
*
|
|
1902
|
-
* @example
|
|
1903
|
-
* ```typescript
|
|
1904
|
-
* const data = await app.events.once('user.created');
|
|
1905
|
-
* console.log('User created:', data.userId);
|
|
1906
|
-
* ```
|
|
1907
|
-
*/
|
|
1908
|
-
once(eventName: string, handler?: SimpleEventHandler): Promise<any>;
|
|
1909
|
-
/**
|
|
1910
|
-
* Remove all listeners for an event
|
|
1911
|
-
*
|
|
1912
|
-
* @param eventName - Event name
|
|
1913
|
-
*
|
|
1914
|
-
* @example
|
|
1915
|
-
* ```typescript
|
|
1916
|
-
* app.events.off('user.created');
|
|
1917
|
-
* ```
|
|
1918
|
-
*/
|
|
1919
|
-
off(eventName: string): void;
|
|
1920
|
-
/**
|
|
1921
|
-
* Remove all listeners
|
|
1922
|
-
*
|
|
1923
|
-
* @example
|
|
1924
|
-
* ```typescript
|
|
1925
|
-
* app.events.removeAllListeners();
|
|
1926
|
-
* ```
|
|
1927
|
-
*/
|
|
1928
|
-
removeAllListeners(): void;
|
|
1929
|
-
/**
|
|
1930
|
-
* Get list of event names that have listeners
|
|
1931
|
-
*
|
|
1932
|
-
* @returns Array of event names
|
|
1933
|
-
*/
|
|
1934
|
-
eventNames(): string[];
|
|
1935
|
-
/**
|
|
1936
|
-
* Get number of listeners for an event
|
|
1937
|
-
*
|
|
1938
|
-
* @param eventName - Event name
|
|
1939
|
-
* @returns Number of listeners
|
|
1940
|
-
*/
|
|
1941
|
-
listenerCount(eventName: string): number;
|
|
1942
|
-
/**
|
|
1943
|
-
* Get maximum number of listeners (for compatibility)
|
|
1944
|
-
* Returns Infinity as we don't impose limits
|
|
1945
|
-
*/
|
|
1946
|
-
getMaxListeners(): number;
|
|
1947
|
-
/**
|
|
1948
|
-
* Set maximum number of listeners (for compatibility)
|
|
1949
|
-
* No-op as we don't impose limits
|
|
1950
|
-
*/
|
|
1951
|
-
setMaxListeners(_n: number): this;
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
/**
|
|
1955
|
-
* Core Application class for NextRush v2
|
|
1956
|
-
*
|
|
1957
|
-
* @packageDocumentation
|
|
1958
|
-
*/
|
|
1959
|
-
|
|
1960
|
-
/**
|
|
1961
|
-
* NextRush Application class with Koa-style middleware and Express-like design
|
|
1962
|
-
*
|
|
1963
|
-
* @example
|
|
35
|
+
* @example Quick Start (Functional)
|
|
1964
36
|
* ```typescript
|
|
1965
|
-
* import { createApp } from 'nextrush
|
|
1966
|
-
*
|
|
1967
|
-
* const app = createApp({ port: 3000 });
|
|
1968
|
-
*
|
|
1969
|
-
* app.use(async (ctx, next) => {
|
|
1970
|
-
* console.log(`${ctx.method} ${ctx.path}`);
|
|
1971
|
-
* await next();
|
|
1972
|
-
* });
|
|
1973
|
-
*
|
|
1974
|
-
* app.get('/hello', async (ctx) => {
|
|
1975
|
-
* ctx.res.json({ message: 'Hello, World!' });
|
|
1976
|
-
* });
|
|
1977
|
-
*
|
|
1978
|
-
* app.listen(3000, () => {
|
|
1979
|
-
* console.log('Server running on http://localhost:3000');
|
|
1980
|
-
* });
|
|
1981
|
-
* ```
|
|
1982
|
-
*/
|
|
1983
|
-
declare class NextRushApplication extends EventEmitter implements Application {
|
|
1984
|
-
private server;
|
|
1985
|
-
private middleware;
|
|
1986
|
-
private internalRouter;
|
|
1987
|
-
private options;
|
|
1988
|
-
private isShuttingDown;
|
|
1989
|
-
private container;
|
|
1990
|
-
private middlewareFactory;
|
|
1991
|
-
private compiler;
|
|
1992
|
-
private cachedExceptionFilter;
|
|
1993
|
-
private static readonly EXCEPTION_FILTER_MARK;
|
|
1994
|
-
private _eventSystem;
|
|
1995
|
-
private _simpleEvents;
|
|
1996
|
-
constructor(options?: ApplicationOptions);
|
|
1997
|
-
/**
|
|
1998
|
-
* Create HTTP server
|
|
1999
|
-
*/
|
|
2000
|
-
private createServer;
|
|
2001
|
-
/**
|
|
2002
|
-
* Setup event handlers
|
|
2003
|
-
*/
|
|
2004
|
-
private setupEventHandlers;
|
|
2005
|
-
/**
|
|
2006
|
-
* Get cached exception filter or scan once and cache it
|
|
2007
|
-
*/
|
|
2008
|
-
private getOrFindExceptionFilter;
|
|
2009
|
-
/**
|
|
2010
|
-
* Handle incoming requests
|
|
2011
|
-
*/
|
|
2012
|
-
private handleRequest;
|
|
2013
|
-
/**
|
|
2014
|
-
* Execute middleware stack.
|
|
2015
|
-
* - Production: run directly on ctx for maximum performance.
|
|
2016
|
-
* - Debug mode: wrap with SafeContext for diagnostics.
|
|
2017
|
-
*/
|
|
2018
|
-
private executeMiddlewareWithBoundary;
|
|
2019
|
-
/**
|
|
2020
|
-
* Execute route handler with high-performance direct execution
|
|
2021
|
-
*/
|
|
2022
|
-
private executeRouteWithBoundary;
|
|
2023
|
-
/**
|
|
2024
|
-
* Register GET route
|
|
2025
|
-
*/
|
|
2026
|
-
get(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2027
|
-
/**
|
|
2028
|
-
* Register POST route
|
|
2029
|
-
*/
|
|
2030
|
-
post(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2031
|
-
/**
|
|
2032
|
-
* Register PUT route
|
|
2033
|
-
*/
|
|
2034
|
-
put(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2035
|
-
/**
|
|
2036
|
-
* Register DELETE route
|
|
2037
|
-
*/
|
|
2038
|
-
delete(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2039
|
-
/**
|
|
2040
|
-
* Register PATCH route
|
|
2041
|
-
*/
|
|
2042
|
-
patch(path: string, handler: RouteHandler | RouteConfig): this;
|
|
2043
|
-
/**
|
|
2044
|
-
* Register middleware or sub-router
|
|
2045
|
-
*/
|
|
2046
|
-
use(middleware: Middleware): this;
|
|
2047
|
-
use(prefix: string, router: Router): this;
|
|
2048
|
-
/**
|
|
2049
|
-
* Create router instance
|
|
2050
|
-
*/
|
|
2051
|
-
router(): Router;
|
|
2052
|
-
/**
|
|
2053
|
-
* Register a route with the router
|
|
2054
|
-
*/
|
|
2055
|
-
private registerRoute;
|
|
2056
|
-
/**
|
|
2057
|
-
* Start the server
|
|
2058
|
-
*/
|
|
2059
|
-
listen(port?: number, callback?: () => void): Server;
|
|
2060
|
-
listen(port?: number, host?: string, callback?: () => void): Server;
|
|
2061
|
-
/**
|
|
2062
|
-
* Get the underlying HTTP server
|
|
2063
|
-
*/
|
|
2064
|
-
getServer(): Server;
|
|
2065
|
-
/**
|
|
2066
|
-
* Get simple events API for Express-style event handling
|
|
2067
|
-
*
|
|
2068
|
-
* @example
|
|
2069
|
-
* ```typescript
|
|
2070
|
-
* app.events.emit('user.created', { userId: '123' });
|
|
2071
|
-
* app.events.on('user.created', (data) => console.log(data));
|
|
2072
|
-
* ```
|
|
2073
|
-
*/
|
|
2074
|
-
get events(): SimpleEventsAPI;
|
|
2075
|
-
/**
|
|
2076
|
-
* Get advanced event system for CQRS and Event Sourcing
|
|
2077
|
-
*
|
|
2078
|
-
* @example
|
|
2079
|
-
* ```typescript
|
|
2080
|
-
* app.eventSystem.dispatch(new CreateUserCommand({ name: 'John' }));
|
|
2081
|
-
* app.eventSystem.subscribe(UserCreatedEvent, handler);
|
|
2082
|
-
* ```
|
|
2083
|
-
*/
|
|
2084
|
-
get eventSystem(): NextRushEventSystem;
|
|
2085
|
-
/**
|
|
2086
|
-
* Gracefully shutdown the application
|
|
2087
|
-
*/
|
|
2088
|
-
shutdown(): Promise<void>;
|
|
2089
|
-
/**
|
|
2090
|
-
* Create CORS middleware - now delegated to middleware factory
|
|
2091
|
-
*/
|
|
2092
|
-
cors(options?: CorsOptions): Middleware;
|
|
2093
|
-
/**
|
|
2094
|
-
* Create helmet middleware - now delegated to middleware factory
|
|
2095
|
-
*/
|
|
2096
|
-
helmet(options?: HelmetOptions): Middleware;
|
|
2097
|
-
/**
|
|
2098
|
-
* Create JSON body parser middleware - now delegated to middleware factory
|
|
2099
|
-
*/
|
|
2100
|
-
json(options?: EnhancedBodyParserOptions): Middleware;
|
|
2101
|
-
/**
|
|
2102
|
-
* Create URL-encoded body parser middleware - now delegated to middleware factory
|
|
2103
|
-
*/
|
|
2104
|
-
urlencoded(options?: EnhancedBodyParserOptions): Middleware;
|
|
2105
|
-
/**
|
|
2106
|
-
* Create text body parser middleware - now delegated to middleware factory
|
|
2107
|
-
*/
|
|
2108
|
-
text(options?: EnhancedBodyParserOptions): Middleware;
|
|
2109
|
-
/**
|
|
2110
|
-
* Create rate limiter middleware - now delegated to middleware factory
|
|
2111
|
-
*/
|
|
2112
|
-
rateLimit(options?: RateLimiterOptions): Middleware;
|
|
2113
|
-
/**
|
|
2114
|
-
* Create logger middleware - now delegated to middleware factory
|
|
2115
|
-
*/
|
|
2116
|
-
logger(options?: LoggerOptions): Middleware;
|
|
2117
|
-
/**
|
|
2118
|
-
* Create compression middleware - now delegated to middleware factory
|
|
2119
|
-
*/
|
|
2120
|
-
compression(options?: CompressionOptions): Middleware;
|
|
2121
|
-
/**
|
|
2122
|
-
* Create request ID middleware - now delegated to middleware factory
|
|
2123
|
-
*/
|
|
2124
|
-
requestId(options?: RequestIdOptions): Middleware;
|
|
2125
|
-
/**
|
|
2126
|
-
* Create timer middleware - now delegated to middleware factory
|
|
2127
|
-
*/
|
|
2128
|
-
timer(options?: TimerOptions): Middleware;
|
|
2129
|
-
/**
|
|
2130
|
-
* Create smart body parser middleware - now delegated to middleware factory
|
|
2131
|
-
*/
|
|
2132
|
-
smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
2133
|
-
/**
|
|
2134
|
-
* Create exception filter middleware
|
|
2135
|
-
*
|
|
2136
|
-
* Provides NestJS-style exception handling with custom error classes
|
|
2137
|
-
* and automatic error response formatting.
|
|
2138
|
-
*
|
|
2139
|
-
* @param filters - Array of exception filters to use
|
|
2140
|
-
* @returns Exception filter middleware function
|
|
2141
|
-
*
|
|
2142
|
-
* @example
|
|
2143
|
-
* ```typescript
|
|
2144
|
-
* const app = createApp();
|
|
2145
|
-
*
|
|
2146
|
-
* // Global exception filter
|
|
2147
|
-
* app.use(app.exceptionFilter());
|
|
2148
|
-
*
|
|
2149
|
-
* // With custom filters
|
|
2150
|
-
* app.use(app.exceptionFilter([
|
|
2151
|
-
* new ValidationExceptionFilter(),
|
|
2152
|
-
* new AuthenticationExceptionFilter(),
|
|
2153
|
-
* new GlobalExceptionFilter()
|
|
2154
|
-
* ]));
|
|
2155
|
-
* ```
|
|
2156
|
-
*/
|
|
2157
|
-
exceptionFilter(filters?: ExceptionFilter[]): Middleware;
|
|
2158
|
-
/**
|
|
2159
|
-
* Create advanced logger plugin
|
|
2160
|
-
*
|
|
2161
|
-
* Provides comprehensive logging capabilities similar to Winston/Pino
|
|
2162
|
-
* with multiple transports, structured logging, and performance optimization.
|
|
2163
|
-
*
|
|
2164
|
-
* @param config - Logger configuration options
|
|
2165
|
-
* @returns Logger plugin instance
|
|
2166
|
-
*
|
|
2167
|
-
* @example
|
|
2168
|
-
* ```typescript
|
|
2169
|
-
* const app = createApp();
|
|
2170
|
-
*
|
|
2171
|
-
* // Development logger
|
|
2172
|
-
* const logger = app.createLogger({
|
|
2173
|
-
* level: 'debug',
|
|
2174
|
-
* requestLogging: true,
|
|
2175
|
-
* performance: true
|
|
2176
|
-
* });
|
|
2177
|
-
* logger.install(app);
|
|
2178
|
-
*
|
|
2179
|
-
* // Use logger in routes
|
|
2180
|
-
* app.get('/users', ctx => {
|
|
2181
|
-
* app.logger.info('Fetching users', { userId: ctx.params.id });
|
|
2182
|
-
* ctx.res.json({ users: [] });
|
|
2183
|
-
* });
|
|
2184
|
-
* ```
|
|
2185
|
-
*/
|
|
2186
|
-
createLogger(config?: {
|
|
2187
|
-
level?: 'error' | 'warn' | 'info' | 'http' | 'verbose' | 'debug' | 'silly';
|
|
2188
|
-
transports?: any[];
|
|
2189
|
-
format?: 'json' | 'text' | 'combined';
|
|
2190
|
-
colorize?: boolean;
|
|
2191
|
-
timestamp?: boolean;
|
|
2192
|
-
context?: string;
|
|
2193
|
-
requestLogging?: boolean;
|
|
2194
|
-
performance?: boolean;
|
|
2195
|
-
structured?: boolean;
|
|
2196
|
-
}): LoggerPlugin;
|
|
2197
|
-
private convertLogLevel;
|
|
2198
|
-
/**
|
|
2199
|
-
* Create development logger
|
|
2200
|
-
*
|
|
2201
|
-
* Optimized for development with debug level, colors, and detailed logging.
|
|
2202
|
-
*
|
|
2203
|
-
* @returns Development logger plugin
|
|
2204
|
-
*/
|
|
2205
|
-
createDevLogger(): LoggerPlugin;
|
|
2206
|
-
/**
|
|
2207
|
-
* Create production logger
|
|
2208
|
-
*
|
|
2209
|
-
* Optimized for production with info level, JSON format, and file logging.
|
|
2210
|
-
*
|
|
2211
|
-
* @returns Production logger plugin
|
|
2212
|
-
*/
|
|
2213
|
-
createProdLogger(): LoggerPlugin;
|
|
2214
|
-
}
|
|
2215
|
-
/**
|
|
2216
|
-
* Create a new NextRush application instance
|
|
2217
|
-
*
|
|
2218
|
-
* @param options - Application configuration options
|
|
2219
|
-
* @returns Application instance
|
|
37
|
+
* import { createApp, createRouter, listen } from 'nextrush';
|
|
2220
38
|
*
|
|
2221
|
-
*
|
|
2222
|
-
*
|
|
2223
|
-
* import { createApp } from 'nextrush-v2';
|
|
2224
|
-
*
|
|
2225
|
-
* const app = createApp({
|
|
2226
|
-
* port: 3000,
|
|
2227
|
-
* host: 'localhost',
|
|
2228
|
-
* cors: true,
|
|
2229
|
-
* });
|
|
2230
|
-
*
|
|
2231
|
-
* app.use(app.cors());
|
|
2232
|
-
* app.use(app.helmet());
|
|
2233
|
-
*
|
|
2234
|
-
* app.get('/hello', (ctx) => {
|
|
2235
|
-
* ctx.res.json({ message: 'Hello, World!' });
|
|
2236
|
-
* });
|
|
39
|
+
* const app = createApp();
|
|
40
|
+
* const router = createRouter();
|
|
2237
41
|
*
|
|
2238
|
-
*
|
|
2239
|
-
*
|
|
42
|
+
* router.get('/', (ctx) => {
|
|
43
|
+
* ctx.json({ message: 'Hello NextRush!' });
|
|
2240
44
|
* });
|
|
2241
|
-
* ```
|
|
2242
|
-
*/
|
|
2243
|
-
declare function createApp(options?: ApplicationOptions): Application;
|
|
2244
|
-
|
|
2245
|
-
/**
|
|
2246
|
-
* Context factory for NextRush v2
|
|
2247
|
-
*
|
|
2248
|
-
* @packageDocumentation
|
|
2249
|
-
*/
|
|
2250
|
-
|
|
2251
|
-
/**
|
|
2252
|
-
* Create a Koa-style context object with Express-like design
|
|
2253
|
-
*
|
|
2254
|
-
* @param req - HTTP request object
|
|
2255
|
-
* @param res - HTTP response object
|
|
2256
|
-
* @param options - Application options
|
|
2257
|
-
* @returns Enhanced context object
|
|
2258
|
-
*
|
|
2259
|
-
* @example
|
|
2260
|
-
* ```typescript
|
|
2261
|
-
* import { createContext } from '@/core/context';
|
|
2262
45
|
*
|
|
2263
|
-
*
|
|
2264
|
-
*
|
|
2265
|
-
* ctx.res.json({ message: 'Hello' });
|
|
46
|
+
* app.route('/', router);
|
|
47
|
+
* listen(app, 3000);
|
|
2266
48
|
* ```
|
|
2267
|
-
*/
|
|
2268
|
-
declare function createContext(req: IncomingMessage | NextRushRequest, res: ServerResponse | NextRushResponse, _options: Required<ApplicationOptions>): Context;
|
|
2269
|
-
|
|
2270
|
-
/**
|
|
2271
|
-
* Static Files Plugin for NextRush v2
|
|
2272
|
-
*
|
|
2273
|
-
* Express/Koa/Fastify-inspired static file serving with strong DX and security.
|
|
2274
|
-
*
|
|
2275
|
-
* - Prefix-based mounting (virtual path)
|
|
2276
|
-
* - Safe path resolution (prevents traversal)
|
|
2277
|
-
* - ETag/Last-Modified + 304 handling
|
|
2278
|
-
* - Range requests (single range)
|
|
2279
|
-
* - Cache-Control with maxAge/immutable
|
|
2280
|
-
* - HEAD support
|
|
2281
|
-
* - Optional index.html serving and directory redirect
|
|
2282
|
-
* - Dotfiles policy (ignore/deny/allow)
|
|
2283
|
-
* - Optional custom header hook
|
|
2284
|
-
*
|
|
2285
|
-
* @packageDocumentation
|
|
2286
|
-
*/
|
|
2287
|
-
|
|
2288
|
-
/**
|
|
2289
|
-
* StaticFilesPlugin
|
|
2290
|
-
*/
|
|
2291
|
-
declare class StaticFilesPlugin extends BasePlugin {
|
|
2292
|
-
private readonly userOptions;
|
|
2293
|
-
name: string;
|
|
2294
|
-
version: string;
|
|
2295
|
-
description: string;
|
|
2296
|
-
private options;
|
|
2297
|
-
constructor(userOptions: StaticFilesOptions);
|
|
2298
|
-
onInstall(app: Application): void;
|
|
2299
|
-
private normalizeOptions;
|
|
2300
|
-
private createStaticMiddleware;
|
|
2301
|
-
private failOrNext;
|
|
2302
|
-
}
|
|
2303
|
-
|
|
2304
|
-
/**
|
|
2305
|
-
* Template Plugin for NextRush v2
|
|
2306
|
-
*
|
|
2307
|
-
* Safe, minimal, helper-based HTML templating with auto-escaping.
|
|
2308
|
-
*
|
|
2309
|
-
* Features:
|
|
2310
|
-
* - Auto-escape by default; triple mustache {{{expr}}} to output raw
|
|
2311
|
-
* - Helpers: stripHTML, json, upper, lower, date, safe
|
|
2312
|
-
* - Partials: {{> partialName}} (inline or file-based when viewsDir is set)
|
|
2313
|
-
* - Nested path access: {{user.name}}, {{profile.bio}}
|
|
2314
|
-
* - File-based rendering when viewsDir provided; otherwise inline templates
|
|
2315
|
-
* - Simple cache of compiled templates (in-memory)
|
|
2316
|
-
* - Block syntax:
|
|
2317
|
-
* - Conditionals: {{#if cond}}...{{else}}...{{/if}}
|
|
2318
|
-
* - Loops: {{#each items}}...{{/each}} with {{this}}, {{@index}}, {{@key}}
|
|
2319
|
-
* - With: {{#with obj}}...{{/with}}
|
|
2320
|
-
* - Layouts (when viewsDir provided): render(template, data, { layout: 'layout.html' })
|
|
2321
|
-
*/
|
|
2322
|
-
|
|
2323
|
-
declare class TemplatePlugin extends BasePlugin {
|
|
2324
|
-
name: string;
|
|
2325
|
-
version: string;
|
|
2326
|
-
description: string;
|
|
2327
|
-
private engine;
|
|
2328
|
-
constructor(options?: TemplatePluginOptions);
|
|
2329
|
-
onInstall(app: Application): void;
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
declare class WSRoomManager extends EventEmitter {
|
|
2333
|
-
private rooms;
|
|
2334
|
-
add(socket: WSConnection, room: string): void;
|
|
2335
|
-
remove(socket: WSConnection, room: string): void;
|
|
2336
|
-
leaveAll(socket: WSConnection): void;
|
|
2337
|
-
broadcast(room: string, data: string | Buffer, exclude?: WSConnection): void;
|
|
2338
|
-
getRooms(): string[];
|
|
2339
|
-
}
|
|
2340
|
-
|
|
2341
|
-
/**
|
|
2342
|
-
* WebSocket Plugin Type Augmentation
|
|
2343
|
-
*
|
|
2344
|
-
* This file provides type-safe WebSocket functionality through smart type casting
|
|
2345
|
-
* and utility types for perfect TypeScript intelligence.
|
|
2346
|
-
*/
|
|
2347
|
-
|
|
2348
|
-
interface WebSocketApplication extends Application {
|
|
2349
|
-
ws: (path: string, handler: WSHandler) => WebSocketApplication;
|
|
2350
|
-
wsUse: (middleware: WSMiddleware) => WebSocketApplication;
|
|
2351
|
-
wsBroadcast: (message: string, room?: string) => WebSocketApplication;
|
|
2352
|
-
}
|
|
2353
|
-
declare function hasWebSocketSupport(app: Application): app is WebSocketApplication;
|
|
2354
|
-
declare function withWebSocket(app: Application): WebSocketApplication;
|
|
2355
|
-
|
|
2356
|
-
/**
|
|
2357
|
-
* WebSocket Plugin for NextRush v2 - Context-based Architecture
|
|
2358
|
-
* Provides WebSocket functionality through context enhancement
|
|
2359
|
-
*/
|
|
2360
|
-
|
|
2361
|
-
/**
|
|
2362
|
-
* Enhanced Context with WebSocket functionality
|
|
2363
|
-
*/
|
|
2364
|
-
interface WSContext extends Context {
|
|
2365
|
-
/** WebSocket connection (available when request is upgraded) */
|
|
2366
|
-
ws?: WSConnection;
|
|
2367
|
-
/** Check if request is WebSocket upgrade request */
|
|
2368
|
-
isWebSocket: boolean;
|
|
2369
|
-
/** WebSocket room manager */
|
|
2370
|
-
wsRooms: WSRoomManager;
|
|
2371
|
-
}
|
|
2372
|
-
/**
|
|
2373
|
-
* WebSocket Plugin for NextRush v2
|
|
2374
|
-
*
|
|
2375
|
-
* Enhances context with WebSocket functionality following v2 architecture patterns
|
|
2376
|
-
*/
|
|
2377
|
-
declare class WebSocketPlugin extends BasePlugin {
|
|
2378
|
-
name: string;
|
|
2379
|
-
version: string;
|
|
2380
|
-
description: string;
|
|
2381
|
-
private options;
|
|
2382
|
-
private roomManager;
|
|
2383
|
-
private connections;
|
|
2384
|
-
private routes;
|
|
2385
|
-
private middlewares;
|
|
2386
|
-
private heartbeatTimer;
|
|
2387
|
-
constructor(options?: WebSocketPluginOptions);
|
|
2388
|
-
/**
|
|
2389
|
-
* Install WebSocket plugin - adds WebSocket middleware to app
|
|
2390
|
-
*/
|
|
2391
|
-
onInstall(app: Application): void;
|
|
2392
|
-
/**
|
|
2393
|
-
* Start heartbeat timer for connection cleanup
|
|
2394
|
-
*/
|
|
2395
|
-
private startHeartbeat;
|
|
2396
|
-
/**
|
|
2397
|
-
* Cleanup plugin resources
|
|
2398
|
-
*/
|
|
2399
|
-
cleanup(): void;
|
|
2400
|
-
/**
|
|
2401
|
-
* Setup HTTP upgrade event handler
|
|
2402
|
-
*/
|
|
2403
|
-
private setupUpgradeHandler;
|
|
2404
|
-
/**
|
|
2405
|
-
* Handle HTTP to WebSocket upgrade
|
|
2406
|
-
*/
|
|
2407
|
-
private handleUpgrade;
|
|
2408
|
-
/**
|
|
2409
|
-
* Execute WebSocket middlewares
|
|
2410
|
-
*/
|
|
2411
|
-
private executeMiddlewares;
|
|
2412
|
-
/**
|
|
2413
|
-
* Handle WebSocket upgrade in middleware context
|
|
2414
|
-
*/
|
|
2415
|
-
private handleWebSocketUpgrade;
|
|
2416
|
-
/**
|
|
2417
|
-
* Verify WebSocket upgrade request
|
|
2418
|
-
*/
|
|
2419
|
-
private verifyUpgrade;
|
|
2420
|
-
/**
|
|
2421
|
-
* Perform WebSocket handshake
|
|
2422
|
-
*/
|
|
2423
|
-
private performHandshake;
|
|
2424
|
-
/**
|
|
2425
|
-
* Generate WebSocket accept key
|
|
2426
|
-
*/
|
|
2427
|
-
private generateAcceptKey;
|
|
2428
|
-
/**
|
|
2429
|
-
* Check if request is WebSocket upgrade request
|
|
2430
|
-
*/
|
|
2431
|
-
private isWebSocketRequest;
|
|
2432
|
-
/**
|
|
2433
|
-
* Check if path matches registered WebSocket routes
|
|
2434
|
-
*/
|
|
2435
|
-
private matchPath;
|
|
2436
|
-
/**
|
|
2437
|
-
* Reject WebSocket connection
|
|
2438
|
-
*/
|
|
2439
|
-
private rejectConnection;
|
|
2440
|
-
/**
|
|
2441
|
-
* Get all active connections
|
|
2442
|
-
*/
|
|
2443
|
-
getConnections(): WSConnection[];
|
|
2444
|
-
/**
|
|
2445
|
-
* Broadcast message to all connections
|
|
2446
|
-
*/
|
|
2447
|
-
broadcast(message: string, room?: string): void;
|
|
2448
|
-
/**
|
|
2449
|
-
* Get connection statistics
|
|
2450
|
-
*/
|
|
2451
|
-
getStats(): {
|
|
2452
|
-
totalConnections: number;
|
|
2453
|
-
rooms: string[];
|
|
2454
|
-
handlers: number;
|
|
2455
|
-
};
|
|
2456
|
-
}
|
|
2457
|
-
|
|
2458
|
-
/**
|
|
2459
|
-
* 🚀 Smart Body Parser Dispatcher - NextRush v2
|
|
2460
|
-
*
|
|
2461
|
-
* INTELLIGENT CONTENT-TYPE AWARE PARSER LOADER
|
|
2462
|
-
*
|
|
2463
|
-
* 🎯 **PERFORMANCE BREAKTHROUGH:**
|
|
2464
|
-
* - 🔥 Only loads the parser you need based on Content-Type
|
|
2465
|
-
* - ⚡ JSON request → Only loads JSON parser (~150 lines)
|
|
2466
|
-
* - 🌊 Multipart request → Only loads multipart parser (~200 lines)
|
|
2467
|
-
* - 🎭 Form request → Only loads URL-encoded parser (~150 lines)
|
|
2468
|
-
* - 📄 Text request → Only loads text parser (~100 lines)
|
|
2469
|
-
* - 💾 Raw request → Only loads raw parser (~100 lines)
|
|
2470
|
-
*
|
|
2471
|
-
* OLD WAY: Every request loads 1,032 lines ❌
|
|
2472
|
-
* NEW WAY: Each request loads only 100-200 lines ✅
|
|
2473
|
-
*
|
|
2474
|
-
* @author NextRush Framework Team
|
|
2475
|
-
* @version 2.0.0
|
|
2476
|
-
*/
|
|
2477
|
-
|
|
2478
|
-
/**
|
|
2479
|
-
* 🌍 Global smart parser instance (removed unused variable)
|
|
2480
|
-
*/
|
|
2481
|
-
/**
|
|
2482
|
-
* 🚀 Create smart body parser middleware
|
|
2483
|
-
*/
|
|
2484
|
-
declare function smartBodyParser(options?: EnhancedBodyParserOptions): Middleware;
|
|
2485
|
-
|
|
2486
|
-
/**
|
|
2487
|
-
* Compression middleware for NextRush v2
|
|
2488
|
-
*
|
|
2489
|
-
* @packageDocumentation
|
|
2490
|
-
*/
|
|
2491
|
-
|
|
2492
|
-
/**
|
|
2493
|
-
* Compression middleware factory
|
|
2494
|
-
*/
|
|
2495
|
-
declare function compression(options?: CompressionOptions): Middleware;
|
|
2496
|
-
|
|
2497
|
-
/**
|
|
2498
|
-
* CORS Middleware for NextRush v2
|
|
2499
|
-
*
|
|
2500
|
-
* High-performance CORS implementation with pre-computed headers
|
|
2501
|
-
* and optimized origin checking for enterprise applications.
|
|
2502
|
-
*
|
|
2503
|
-
* @packageDocumentation
|
|
2504
|
-
*/
|
|
2505
|
-
|
|
2506
|
-
/**
|
|
2507
|
-
* Create CORS middleware
|
|
2508
|
-
*
|
|
2509
|
-
* @param options - CORS configuration options
|
|
2510
|
-
* @returns CORS middleware function
|
|
2511
49
|
*
|
|
2512
|
-
* @example
|
|
50
|
+
* @example With Middleware (install separately)
|
|
2513
51
|
* ```typescript
|
|
2514
|
-
* import { createApp } from 'nextrush
|
|
2515
|
-
* import { cors } from '
|
|
52
|
+
* import { createApp, listen } from 'nextrush';
|
|
53
|
+
* import { cors } from '@nextrush/cors';
|
|
54
|
+
* import { json } from '@nextrush/body-parser';
|
|
2516
55
|
*
|
|
2517
56
|
* const app = createApp();
|
|
2518
|
-
*
|
|
2519
|
-
* // Basic CORS
|
|
2520
57
|
* app.use(cors());
|
|
58
|
+
* app.use(json());
|
|
2521
59
|
*
|
|
2522
|
-
*
|
|
2523
|
-
* app.use(cors({
|
|
2524
|
-
* origin: ['https://app.example.com', 'https://admin.example.com'],
|
|
2525
|
-
* credentials: true,
|
|
2526
|
-
* methods: ['GET', 'POST', 'PUT', 'DELETE'],
|
|
2527
|
-
* allowedHeaders: ['Content-Type', 'Authorization', 'X-API-Key'],
|
|
2528
|
-
* }));
|
|
60
|
+
* listen(app, 3000);
|
|
2529
61
|
* ```
|
|
2530
|
-
*/
|
|
2531
|
-
declare function cors(options?: CorsOptions): Middleware$1;
|
|
2532
|
-
|
|
2533
|
-
/**
|
|
2534
|
-
* Helmet Middleware for NextRush v2
|
|
2535
62
|
*
|
|
2536
|
-
*
|
|
2537
|
-
*
|
|
2538
|
-
* @packageDocumentation
|
|
2539
|
-
*/
|
|
2540
|
-
|
|
2541
|
-
/**
|
|
2542
|
-
* Create Helmet middleware for security headers
|
|
2543
|
-
*
|
|
2544
|
-
* @param options - Helmet configuration options
|
|
2545
|
-
* @returns Helmet middleware function
|
|
2546
|
-
*
|
|
2547
|
-
* @example
|
|
63
|
+
* @example Class-Based (import from nextrush/class)
|
|
2548
64
|
* ```typescript
|
|
2549
|
-
* import {
|
|
2550
|
-
*
|
|
2551
|
-
* const app = createApp();
|
|
2552
|
-
* app.use(helmet());
|
|
2553
|
-
*
|
|
2554
|
-
* // With custom options
|
|
2555
|
-
* app.use(helmet({
|
|
2556
|
-
* contentSecurityPolicy: {
|
|
2557
|
-
* directives: {
|
|
2558
|
-
* defaultSrc: ["'self'"],
|
|
2559
|
-
* scriptSrc: ["'self'", "'unsafe-inline'"],
|
|
2560
|
-
* },
|
|
2561
|
-
* },
|
|
2562
|
-
* }));
|
|
2563
|
-
* ```
|
|
2564
|
-
*/
|
|
2565
|
-
declare function helmet(options?: HelmetOptions): Middleware$1;
|
|
2566
|
-
|
|
2567
|
-
/**
|
|
2568
|
-
* Logger Middleware for NextRush v2
|
|
65
|
+
* import { createApp, listen } from 'nextrush';
|
|
66
|
+
* import { Controller, Get, Service, controllersPlugin } from 'nextrush/class';
|
|
2569
67
|
*
|
|
2570
|
-
*
|
|
2571
|
-
*
|
|
2572
|
-
*
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
/**
|
|
2576
|
-
* Create logger middleware
|
|
2577
|
-
*
|
|
2578
|
-
* @param options - Logger configuration options
|
|
2579
|
-
* @returns Logger middleware function
|
|
2580
|
-
*
|
|
2581
|
-
* @example
|
|
2582
|
-
* ```typescript
|
|
2583
|
-
* import { logger } from '@/core/middleware/logger';
|
|
2584
|
-
*
|
|
2585
|
-
* const app = createApp();
|
|
2586
|
-
*
|
|
2587
|
-
* // Basic logging
|
|
2588
|
-
* app.use(logger());
|
|
2589
|
-
*
|
|
2590
|
-
* // Advanced logging
|
|
2591
|
-
* app.use(logger({
|
|
2592
|
-
* format: 'combined',
|
|
2593
|
-
* level: 'info',
|
|
2594
|
-
* colorize: true,
|
|
2595
|
-
* showResponseTime: true,
|
|
2596
|
-
* showUserAgent: true,
|
|
2597
|
-
* }));
|
|
2598
|
-
* ```
|
|
2599
|
-
*/
|
|
2600
|
-
declare function logger(options?: LoggerOptions): Middleware$1;
|
|
2601
|
-
|
|
2602
|
-
/**
|
|
2603
|
-
* Rate Limiter Middleware for NextRush v2
|
|
2604
|
-
*
|
|
2605
|
-
* Provides rate limiting functionality to prevent abuse
|
|
2606
|
-
*
|
|
2607
|
-
* @packageDocumentation
|
|
2608
|
-
*/
|
|
2609
|
-
|
|
2610
|
-
/**
|
|
2611
|
-
* Create rate limiter middleware
|
|
2612
|
-
*
|
|
2613
|
-
* @param options - Rate limiter configuration options
|
|
2614
|
-
* @returns Rate limiter middleware function
|
|
2615
|
-
*
|
|
2616
|
-
* @example
|
|
2617
|
-
* ```typescript
|
|
2618
|
-
* import { rateLimit } from '@/core/middleware/rate-limiter';
|
|
2619
|
-
*
|
|
2620
|
-
* const app = createApp();
|
|
2621
|
-
*
|
|
2622
|
-
* // Basic rate limiting
|
|
2623
|
-
* app.use(rateLimit({ windowMs: 15 * 60 * 1000, max: 100 }));
|
|
2624
|
-
*
|
|
2625
|
-
* // Advanced rate limiting
|
|
2626
|
-
* app.use(rateLimit({
|
|
2627
|
-
* windowMs: 15 * 60 * 1000,
|
|
2628
|
-
* max: 100,
|
|
2629
|
-
* message: 'Too many requests from this IP',
|
|
2630
|
-
* keyGenerator: (ctx) => ctx.ip,
|
|
2631
|
-
* skip: (ctx) => ctx.path.startsWith('/public'),
|
|
2632
|
-
* }));
|
|
2633
|
-
* ```
|
|
2634
|
-
*/
|
|
2635
|
-
declare function rateLimit(options?: RateLimiterOptions): Middleware$1;
|
|
2636
|
-
|
|
2637
|
-
/**
|
|
2638
|
-
* Request ID Middleware for NextRush v2
|
|
2639
|
-
*
|
|
2640
|
-
* Provides request ID generation and tracking functionality
|
|
2641
|
-
*
|
|
2642
|
-
* @packageDocumentation
|
|
2643
|
-
*/
|
|
2644
|
-
|
|
2645
|
-
/**
|
|
2646
|
-
* Create request ID middleware
|
|
2647
|
-
*
|
|
2648
|
-
* @param options - Request ID configuration options
|
|
2649
|
-
* @returns Request ID middleware function
|
|
2650
|
-
*
|
|
2651
|
-
* @example
|
|
2652
|
-
* ```typescript
|
|
2653
|
-
* import { requestId } from '@/core/middleware/request-id';
|
|
2654
|
-
*
|
|
2655
|
-
* const app = createApp();
|
|
2656
|
-
*
|
|
2657
|
-
* // Basic request ID
|
|
2658
|
-
* app.use(requestId());
|
|
2659
|
-
*
|
|
2660
|
-
* // Advanced request ID
|
|
2661
|
-
* app.use(requestId({
|
|
2662
|
-
* headerName: 'X-Correlation-ID',
|
|
2663
|
-
* generator: () => generateUUID(),
|
|
2664
|
-
* addResponseHeader: true,
|
|
2665
|
-
* echoHeader: true,
|
|
2666
|
-
* }));
|
|
2667
|
-
* ```
|
|
2668
|
-
*/
|
|
2669
|
-
declare function requestId(options?: RequestIdOptions): Middleware$1;
|
|
2670
|
-
|
|
2671
|
-
/**
|
|
2672
|
-
* Timer middleware for NextRush v2
|
|
2673
|
-
*
|
|
2674
|
-
* @packageDocumentation
|
|
2675
|
-
*/
|
|
2676
|
-
|
|
2677
|
-
/**
|
|
2678
|
-
* Create timer middleware
|
|
68
|
+
* @Service()
|
|
69
|
+
* class UserService {
|
|
70
|
+
* findAll() { return [{ id: 1, name: 'Alice' }]; }
|
|
71
|
+
* }
|
|
2679
72
|
*
|
|
2680
|
-
* @
|
|
2681
|
-
*
|
|
73
|
+
* @Controller('/users')
|
|
74
|
+
* class UserController {
|
|
75
|
+
* constructor(private users: UserService) {}
|
|
2682
76
|
*
|
|
2683
|
-
*
|
|
2684
|
-
*
|
|
2685
|
-
*
|
|
77
|
+
* @Get()
|
|
78
|
+
* findAll() { return this.users.findAll(); }
|
|
79
|
+
* }
|
|
2686
80
|
*
|
|
2687
81
|
* const app = createApp();
|
|
2688
|
-
*
|
|
2689
|
-
*
|
|
2690
|
-
* app.use(timer());
|
|
2691
|
-
*
|
|
2692
|
-
* // Advanced timer
|
|
2693
|
-
* app.use(timer({
|
|
2694
|
-
* header: 'X-Response-Time',
|
|
2695
|
-
* digits: 3,
|
|
2696
|
-
* suffix: 'ms',
|
|
2697
|
-
* logSlow: true,
|
|
2698
|
-
* logSlowThreshold: 1000,
|
|
2699
|
-
* }));
|
|
82
|
+
* app.plugin(controllersPlugin({ root: './src' }));
|
|
83
|
+
* listen(app, 3000);
|
|
2700
84
|
* ```
|
|
2701
85
|
*/
|
|
2702
|
-
declare function timer(options?: TimerOptions): Middleware$1;
|
|
2703
|
-
|
|
2704
|
-
/**
|
|
2705
|
-
* Request Enhancer for NextRush v2
|
|
2706
|
-
*
|
|
2707
|
-
* @packageDocumentation
|
|
2708
|
-
*/
|
|
2709
|
-
|
|
2710
|
-
/**
|
|
2711
|
-
* Enhanced request interface with Express-like properties and methods
|
|
2712
|
-
*/
|
|
2713
|
-
interface EnhancedRequest extends IncomingMessage {
|
|
2714
|
-
params: Record<string, string>;
|
|
2715
|
-
query: ParsedUrlQuery;
|
|
2716
|
-
body: unknown;
|
|
2717
|
-
pathname: string;
|
|
2718
|
-
originalUrl: string;
|
|
2719
|
-
path: string;
|
|
2720
|
-
files: Record<string, unknown>;
|
|
2721
|
-
cookies: Record<string, string>;
|
|
2722
|
-
session: Record<string, unknown>;
|
|
2723
|
-
locals: Record<string, unknown>;
|
|
2724
|
-
startTime: number;
|
|
2725
|
-
fresh: boolean;
|
|
2726
|
-
stale: boolean;
|
|
2727
|
-
middlewareStack?: string[];
|
|
2728
|
-
param(name: string): string | undefined;
|
|
2729
|
-
header(name: string): string | undefined;
|
|
2730
|
-
get(name: string): string | undefined;
|
|
2731
|
-
sanitizeObject(obj: unknown, options?: unknown): unknown;
|
|
2732
|
-
getRequestTiming(): unknown;
|
|
2733
|
-
ip: string;
|
|
2734
|
-
secure: boolean;
|
|
2735
|
-
protocol: string;
|
|
2736
|
-
hostname(): string;
|
|
2737
|
-
fullUrl(): string;
|
|
2738
|
-
is(type: string): boolean;
|
|
2739
|
-
accepts(types: string | string[]): string | false;
|
|
2740
|
-
parseCookies(): Record<string, string>;
|
|
2741
|
-
validate(rules: unknown): unknown;
|
|
2742
|
-
sanitize(value: unknown, options?: unknown): unknown;
|
|
2743
|
-
isValidEmail(email: string): boolean;
|
|
2744
|
-
isValidUrl(url: string): boolean;
|
|
2745
|
-
sanitizeValue(value: unknown, rule: unknown): unknown;
|
|
2746
|
-
fingerprint(): string;
|
|
2747
|
-
userAgent(): {
|
|
2748
|
-
raw: string;
|
|
2749
|
-
browser: string;
|
|
2750
|
-
os: string;
|
|
2751
|
-
device: string;
|
|
2752
|
-
isMobile: boolean;
|
|
2753
|
-
isBot: boolean;
|
|
2754
|
-
};
|
|
2755
|
-
timing(): {
|
|
2756
|
-
start: number;
|
|
2757
|
-
duration: number;
|
|
2758
|
-
timestamp: string;
|
|
2759
|
-
};
|
|
2760
|
-
rateLimit(): {
|
|
2761
|
-
limit: number;
|
|
2762
|
-
remaining: number;
|
|
2763
|
-
reset: number;
|
|
2764
|
-
retryAfter: number;
|
|
2765
|
-
};
|
|
2766
|
-
parseBrowser(ua: string): string;
|
|
2767
|
-
parseOS(ua: string): string;
|
|
2768
|
-
parseDevice(ua: string): string;
|
|
2769
|
-
isBot(ua: string): boolean;
|
|
2770
|
-
isMobile(ua: string): boolean;
|
|
2771
|
-
}
|
|
2772
|
-
/**
|
|
2773
|
-
* Request Enhancer class for NextRush v2
|
|
2774
|
-
*
|
|
2775
|
-
* @example
|
|
2776
|
-
* ```typescript
|
|
2777
|
-
* import { RequestEnhancer } from '@/core/enhancers/request-enhancer';
|
|
2778
|
-
*
|
|
2779
|
-
* const enhancedReq = RequestEnhancer.enhance(req);
|
|
2780
|
-
* console.log(enhancedReq.ip()); // Client IP
|
|
2781
|
-
* console.log(enhancedReq.userAgent()); // User agent info
|
|
2782
|
-
* ```
|
|
2783
|
-
*/
|
|
2784
|
-
declare class RequestEnhancer {
|
|
2785
|
-
/**
|
|
2786
|
-
* Enhance a Node.js IncomingMessage with NextRush v2 features
|
|
2787
|
-
*
|
|
2788
|
-
* @param req - The original HTTP request
|
|
2789
|
-
* @returns Enhanced request with additional properties and methods
|
|
2790
|
-
*/
|
|
2791
|
-
static enhance(req: IncomingMessage): EnhancedRequest;
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
/**
|
|
2795
|
-
* Response Enhancer for NextRush v2
|
|
2796
|
-
*
|
|
2797
|
-
* @packageDocumentation
|
|
2798
|
-
*/
|
|
2799
|
-
|
|
2800
|
-
/**
|
|
2801
|
-
* File options interface
|
|
2802
|
-
*/
|
|
2803
|
-
interface FileOptions {
|
|
2804
|
-
etag?: boolean;
|
|
2805
|
-
root?: string;
|
|
2806
|
-
}
|
|
2807
|
-
/**
|
|
2808
|
-
* Enhanced response interface with Express-like methods
|
|
2809
|
-
*/
|
|
2810
|
-
interface EnhancedResponse extends ServerResponse {
|
|
2811
|
-
locals: Record<string, unknown>;
|
|
2812
|
-
status(code: number): EnhancedResponse;
|
|
2813
|
-
json(data: unknown): void;
|
|
2814
|
-
send(data: string | Buffer | object): void;
|
|
2815
|
-
html(data: string): void;
|
|
2816
|
-
text(data: string): void;
|
|
2817
|
-
xml(data: string): void;
|
|
2818
|
-
csv(data: unknown[], filename?: string): void;
|
|
2819
|
-
stream(stream: NodeJS.ReadableStream, contentType?: string): void;
|
|
2820
|
-
sendFile(filePath: string, options?: FileOptions): void;
|
|
2821
|
-
file(filePath: string, options?: FileOptions): EnhancedResponse;
|
|
2822
|
-
download(filePath: string, filename?: string, options?: FileOptions): void;
|
|
2823
|
-
getSmartContentType(filePath: string): string;
|
|
2824
|
-
generateETag(stats: unknown): string;
|
|
2825
|
-
redirect(url: string, status?: number): void;
|
|
2826
|
-
redirectPermanent(url: string): void;
|
|
2827
|
-
redirectTemporary(url: string): void;
|
|
2828
|
-
set(field: string | Record<string, string>, value?: string): EnhancedResponse;
|
|
2829
|
-
header(field: string, value: string): EnhancedResponse;
|
|
2830
|
-
removeHeader(field: string): EnhancedResponse;
|
|
2831
|
-
remove(field: string): EnhancedResponse;
|
|
2832
|
-
get(field: string): string | undefined;
|
|
2833
|
-
type(type: string): EnhancedResponse;
|
|
2834
|
-
length(length: number): EnhancedResponse;
|
|
2835
|
-
etag(etag: string): EnhancedResponse;
|
|
2836
|
-
lastModified(date: Date): EnhancedResponse;
|
|
2837
|
-
cookie(name: string, value: string, options?: CookieOptions): EnhancedResponse;
|
|
2838
|
-
clearCookie(name: string, options?: CookieOptions): EnhancedResponse;
|
|
2839
|
-
render(template: string, data?: unknown): void;
|
|
2840
|
-
getNestedValue(obj: unknown, path: string): unknown;
|
|
2841
|
-
isTruthy(value: unknown): boolean;
|
|
2842
|
-
cache(seconds: number): EnhancedResponse;
|
|
2843
|
-
noCache(): EnhancedResponse;
|
|
2844
|
-
cors(origin?: string): EnhancedResponse;
|
|
2845
|
-
security(): EnhancedResponse;
|
|
2846
|
-
compress(): EnhancedResponse;
|
|
2847
|
-
success(data: unknown, message?: string): void;
|
|
2848
|
-
error(message: string, code?: number, details?: unknown): void;
|
|
2849
|
-
paginate(data: unknown[], page: number, limit: number, total: number): void;
|
|
2850
|
-
getContentTypeFromExtension(ext: string): string;
|
|
2851
|
-
convertToCSV(data: unknown[]): string;
|
|
2852
|
-
time(label?: string): EnhancedResponse;
|
|
2853
|
-
}
|
|
2854
|
-
/**
|
|
2855
|
-
* Response Enhancer class for NextRush v2
|
|
2856
|
-
*
|
|
2857
|
-
* @example
|
|
2858
|
-
* ```typescript
|
|
2859
|
-
* import { ResponseEnhancer } from '@/core/enhancers/response-enhancer';
|
|
2860
|
-
*
|
|
2861
|
-
* const enhancedRes = ResponseEnhancer.enhance(res);
|
|
2862
|
-
* enhancedRes.json({ message: 'Hello World' });
|
|
2863
|
-
* ```
|
|
2864
|
-
*/
|
|
2865
|
-
declare class ResponseEnhancer {
|
|
2866
|
-
/**
|
|
2867
|
-
* Enhance a Node.js ServerResponse with NextRush v2 features
|
|
2868
|
-
*
|
|
2869
|
-
* @param res - The original HTTP response
|
|
2870
|
-
* @returns Enhanced response with additional methods
|
|
2871
|
-
*/
|
|
2872
|
-
static enhance(res: ServerResponse): EnhancedResponse;
|
|
2873
|
-
}
|
|
2874
|
-
|
|
2875
|
-
/**
|
|
2876
|
-
* Optimized Radix Tree Router for NextRush v2
|
|
2877
|
-
*
|
|
2878
|
-
* High-performance router with O(k) lookup performance
|
|
2879
|
-
* where k is path length, not route count.
|
|
2880
|
-
*
|
|
2881
|
-
* Performance optimizations:
|
|
2882
|
-
* - Zero-copy path splitting
|
|
2883
|
-
* - LRU cache for frequent paths
|
|
2884
|
-
* - Iterative traversal (no recursion)
|
|
2885
|
-
* - Pre-allocated parameter objects
|
|
2886
|
-
* - Optimized parameter matching
|
|
2887
|
-
*
|
|
2888
|
-
* @packageDocumentation
|
|
2889
|
-
*/
|
|
2890
|
-
|
|
2891
|
-
/**
|
|
2892
|
-
* Route match result with pre-allocated parameter object
|
|
2893
|
-
*/
|
|
2894
|
-
interface OptimizedRouteMatch {
|
|
2895
|
-
handler: RouteHandler;
|
|
2896
|
-
middleware: Middleware[];
|
|
2897
|
-
params: Record<string, string>;
|
|
2898
|
-
path: string;
|
|
2899
|
-
compiled?: (ctx: any) => Promise<void>;
|
|
2900
|
-
}
|
|
2901
|
-
/**
|
|
2902
|
-
* Optimized Router class with performance improvements
|
|
2903
|
-
*/
|
|
2904
|
-
declare class OptimizedRouter implements Router {
|
|
2905
|
-
private root;
|
|
2906
|
-
private middleware;
|
|
2907
|
-
private prefix;
|
|
2908
|
-
private cache;
|
|
2909
|
-
private paramPool;
|
|
2910
|
-
private maxPoolSize;
|
|
2911
|
-
private poolHits;
|
|
2912
|
-
private poolMisses;
|
|
2913
|
-
private readonly staticRoutes;
|
|
2914
|
-
constructor(prefix?: string, cacheSize?: number);
|
|
2915
|
-
/**
|
|
2916
|
-
* Optimized parameter object management
|
|
2917
|
-
*/
|
|
2918
|
-
private getParamObject;
|
|
2919
|
-
/**
|
|
2920
|
-
* Get pool statistics for monitoring
|
|
2921
|
-
*/
|
|
2922
|
-
private getPoolStats;
|
|
2923
|
-
/**
|
|
2924
|
-
* Register a GET route
|
|
2925
|
-
*/
|
|
2926
|
-
get(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2927
|
-
/**
|
|
2928
|
-
* Register a POST route
|
|
2929
|
-
*/
|
|
2930
|
-
post(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2931
|
-
/**
|
|
2932
|
-
* Register a PUT route
|
|
2933
|
-
*/
|
|
2934
|
-
put(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2935
|
-
/**
|
|
2936
|
-
* Register a DELETE route
|
|
2937
|
-
*/
|
|
2938
|
-
delete(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2939
|
-
/**
|
|
2940
|
-
* Register a PATCH route
|
|
2941
|
-
*/
|
|
2942
|
-
patch(path: string, handler: RouteHandler | RouteConfig): OptimizedRouter;
|
|
2943
|
-
/**
|
|
2944
|
-
* Use middleware or create sub-router
|
|
2945
|
-
*/
|
|
2946
|
-
use(middlewareOrPrefix: string | Middleware, router?: Router): OptimizedRouter;
|
|
2947
|
-
/**
|
|
2948
|
-
* Get all registered routes for sub-router integration
|
|
2949
|
-
*/
|
|
2950
|
-
getRoutes(): Map<string, RouteData>;
|
|
2951
|
-
/**
|
|
2952
|
-
* Get router middleware
|
|
2953
|
-
*/
|
|
2954
|
-
getMiddleware(): Middleware[];
|
|
2955
|
-
/**
|
|
2956
|
-
* 🔥 Inject compiled handler for a route (used by compiler)
|
|
2957
|
-
* This allows the pre-compilation system to inject optimized handlers
|
|
2958
|
-
*/
|
|
2959
|
-
setCompiledHandler(method: string, pattern: string, compiledExecute: (ctx: any) => Promise<void>): void;
|
|
2960
|
-
/**
|
|
2961
|
-
* Get comprehensive cache and performance statistics
|
|
2962
|
-
*/
|
|
2963
|
-
getCacheStats(): {
|
|
2964
|
-
cache: {
|
|
2965
|
-
size: number;
|
|
2966
|
-
hitRate: number;
|
|
2967
|
-
hits: number;
|
|
2968
|
-
misses: number;
|
|
2969
|
-
};
|
|
2970
|
-
pool: {
|
|
2971
|
-
poolSize: number;
|
|
2972
|
-
maxSize: number;
|
|
2973
|
-
hits: number;
|
|
2974
|
-
misses: number;
|
|
2975
|
-
hitRate: number;
|
|
2976
|
-
};
|
|
2977
|
-
performance: {
|
|
2978
|
-
totalRoutes: number;
|
|
2979
|
-
pathCacheSize: number;
|
|
2980
|
-
};
|
|
2981
|
-
};
|
|
2982
|
-
/**
|
|
2983
|
-
* Get total number of registered routes
|
|
2984
|
-
*/
|
|
2985
|
-
private getTotalRoutes;
|
|
2986
|
-
/**
|
|
2987
|
-
* Clear the route cache
|
|
2988
|
-
*/
|
|
2989
|
-
clearCache(): void;
|
|
2990
|
-
/**
|
|
2991
|
-
* Ultra-fast route finder with aggressive optimizations
|
|
2992
|
-
*/
|
|
2993
|
-
find(method: string, path: string): OptimizedRouteMatch | null;
|
|
2994
|
-
/**
|
|
2995
|
-
* Hyper-optimized internal finder with minimal allocations
|
|
2996
|
-
*/
|
|
2997
|
-
private findInternalOptimized;
|
|
2998
|
-
/**
|
|
2999
|
-
* Optimized route registration with O(k) insertion
|
|
3000
|
-
*/
|
|
3001
|
-
private registerRoute;
|
|
3002
|
-
/**
|
|
3003
|
-
* Iteratively collect all routes from the tree (no recursion)
|
|
3004
|
-
*/
|
|
3005
|
-
private collectRoutesIterative;
|
|
3006
|
-
}
|
|
3007
|
-
/**
|
|
3008
|
-
* Create a new optimized router instance
|
|
3009
|
-
*
|
|
3010
|
-
* @param prefix - Optional route prefix
|
|
3011
|
-
* @param cacheSize - Optional cache size (default: 1000)
|
|
3012
|
-
* @returns OptimizedRouter instance
|
|
3013
|
-
*
|
|
3014
|
-
* @example
|
|
3015
|
-
* ```typescript
|
|
3016
|
-
* import { createOptimizedRouter } from 'nextrush-v2';
|
|
3017
|
-
*
|
|
3018
|
-
* const userRouter = createOptimizedRouter('/users', 2000);
|
|
3019
|
-
*
|
|
3020
|
-
* userRouter.get('/profile', async (ctx) => {
|
|
3021
|
-
* ctx.res.json({ user: 'profile' });
|
|
3022
|
-
* });
|
|
3023
|
-
*
|
|
3024
|
-
* app.use(userRouter);
|
|
3025
|
-
* ```
|
|
3026
|
-
*/
|
|
3027
|
-
declare function createOptimizedRouter(prefix?: string, cacheSize?: number): OptimizedRouter;
|
|
3028
|
-
|
|
3029
|
-
/**
|
|
3030
|
-
* NextRush v2 - Main Entry Point
|
|
3031
|
-
*
|
|
3032
|
-
* @packageDocumentation
|
|
3033
|
-
*/
|
|
3034
|
-
|
|
3035
|
-
declare const VERSION = "2.0.0-alpha.1";
|
|
3036
|
-
declare const NODE_VERSION = ">=18.0.0";
|
|
3037
86
|
|
|
3038
|
-
declare const
|
|
3039
|
-
readonly createApp: typeof createApp;
|
|
3040
|
-
readonly VERSION: "2.0.0-alpha.1";
|
|
3041
|
-
readonly NODE_VERSION: ">=18.0.0";
|
|
3042
|
-
};
|
|
87
|
+
declare const VERSION = "3.0.0";
|
|
3043
88
|
|
|
3044
|
-
export {
|
|
89
|
+
export { VERSION };
|