blaizejs 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,18 @@
1
- import * as _blaizejs_types from '@blaizejs/types';
2
- import { MiddlewareFunction, MiddlewareOptions, Middleware, Server, PluginHooks, PluginFactory, CreateDeleteRoute, CreateGetRoute, CreateHeadRoute, CreateOptionsRoute, CreatePatchRoute, CreatePostRoute, CreatePutRoute, ServerOptionsInput } from '@blaizejs/types';
3
- export { BuildRoutesRegistry } from '@blaizejs/types';
1
+ import http, { IncomingMessage, ServerResponse } from 'node:http';
2
+ import http2, { Http2ServerRequest, Http2ServerResponse } from 'node:http2';
3
+ import { AsyncLocalStorage } from 'node:async_hooks';
4
+ import { z } from 'zod';
5
+ import { EventEmitter } from 'node:events';
4
6
 
5
7
  /**
6
- * Create a middleware
8
+ * Compose multiple middleware functions into a single middleware function
7
9
  */
8
- declare function create$2(handlerOrOptions: MiddlewareFunction | MiddlewareOptions): Middleware;
10
+ declare function compose(middlewareStack: Middleware[]): MiddlewareFunction;
9
11
 
10
12
  /**
11
- * Compose multiple middleware functions into a single middleware function
13
+ * Create a middleware
12
14
  */
13
- declare function compose(middlewareStack: Middleware[]): MiddlewareFunction;
15
+ declare function create$2(handlerOrOptions: MiddlewareFunction | MiddlewareOptions): Middleware;
14
16
 
15
17
  /**
16
18
  * Create a plugin with the given name, version, and setup function
@@ -51,18 +53,681 @@ declare const createOptionsRoute: CreateOptionsRoute;
51
53
  */
52
54
  declare function create(options?: ServerOptionsInput): Server;
53
55
 
56
+ /**
57
+ * Unified request type supporting both HTTP/1.1 and HTTP/2
58
+ */
59
+ type UnifiedRequest = IncomingMessage | Http2ServerRequest;
60
+ /**
61
+ * Unified response type supporting both HTTP/1.1 and HTTP/2
62
+ */
63
+ type UnifiedResponse = ServerResponse | Http2ServerResponse;
64
+ /**
65
+ * Request parameters extracted from URL path
66
+ */
67
+ interface RequestParams {
68
+ [key: string]: string;
69
+ }
70
+ /**
71
+ * Query parameters from URL
72
+ */
73
+ interface QueryParams {
74
+ [key: string]: string | string[] | undefined;
75
+ }
76
+ /**
77
+ * Options for streaming responses
78
+ */
79
+ interface StreamOptions {
80
+ contentType?: string;
81
+ status?: number;
82
+ headers?: Record<string, string>;
83
+ }
84
+ /**
85
+ * State container for storing request-scoped data
86
+ * Allows for proper typing with generics
87
+ */
88
+ interface State {
89
+ [key: string]: unknown;
90
+ }
91
+ interface ContextResponse<S extends State = State> {
92
+ raw: UnifiedResponse;
93
+ sent: boolean;
94
+ status: (code: number) => ContextResponse<S>;
95
+ header: (name: string, value: string) => ContextResponse<S>;
96
+ headers: (headers: Record<string, string>) => ContextResponse<S>;
97
+ type: (contentType: string) => ContextResponse<S>;
98
+ json: (body: unknown, status?: number) => void;
99
+ text: (body: string, status?: number) => void;
100
+ html: (body: string, status?: number) => void;
101
+ redirect: (url: string, status?: number) => void;
102
+ stream: (readable: NodeJS.ReadableStream, options?: StreamOptions) => void;
103
+ }
104
+ interface ContextRequest<TBody = unknown> {
105
+ raw: UnifiedRequest;
106
+ method: string;
107
+ path: string;
108
+ url: URL | null;
109
+ query: QueryParams;
110
+ params: RequestParams;
111
+ protocol: string;
112
+ isHttp2: boolean;
113
+ body?: TBody;
114
+ header: (name: string) => string | undefined;
115
+ headers: (names?: string[]) => Record<string, string | undefined>;
116
+ }
117
+ /**
118
+ * Context object representing a request/response cycle
119
+ */
120
+ interface Context<S extends State = State, TBody = unknown, TQuery = QueryParams> {
121
+ /**
122
+ * Request information
123
+ */
124
+ request: Omit<ContextRequest, 'body' | 'query'> & {
125
+ body: TBody;
126
+ query: TQuery;
127
+ };
128
+ /**
129
+ * Response handling
130
+ */
131
+ response: ContextResponse<S>;
132
+ /**
133
+ * Request-scoped state for storing data during the request lifecycle
134
+ */
135
+ state: S;
136
+ }
137
+ /**
138
+ * Options for creating a context
139
+ */
140
+ interface ContextOptions {
141
+ /**
142
+ * Whether to parse the request body
143
+ */
144
+ parseBody?: boolean;
145
+ /**
146
+ * Additional state to merge into the context
147
+ */
148
+ initialState?: State;
149
+ }
150
+ /**
151
+ * Function to get the current context from AsyncLocalStorage
152
+ */
153
+ type GetContextFn = <S extends State = State>() => Context<S> | undefined;
154
+ /**
155
+ * Factory function for creating a new context
156
+ */
157
+ type CreateContextFn = (req: UnifiedRequest, res: UnifiedResponse, options?: ContextOptions) => Promise<Context>;
158
+ /**
159
+ * Type representing unknown function
160
+ *
161
+ * This is a generic function type that can accept any number of arguments
162
+ * and return any type of value. It is used for type inference in various
163
+ * contexts where the specific function signature is not known or not
164
+ * important.
165
+ */
166
+ type UnknownFunction = (...args: unknown[]) => unknown;
167
+
168
+ /**
169
+ * Function to pass control to the next middleware
170
+ */
171
+ type NextFunction = () => Promise<void> | void;
172
+ /**
173
+ * Middleware function signature
174
+ */
175
+ type MiddlewareFunction = (ctx: Context, next: NextFunction) => Promise<void> | void;
176
+ /**
177
+ * Named middleware options
178
+ */
179
+ interface MiddlewareOptions {
180
+ /** Name of the middleware for debugging and logging */
181
+ name?: string;
182
+ /** The middleware handler function */
183
+ handler: MiddlewareFunction;
184
+ /** Skip function to conditionally bypass middleware */
185
+ skip?: ((ctx: Context) => boolean) | undefined;
186
+ /** Enable debugging for this middleware */
187
+ debug?: boolean;
188
+ }
189
+ /**
190
+ * Middleware type
191
+ */
192
+ interface Middleware {
193
+ name: string;
194
+ execute: MiddlewareFunction;
195
+ skip?: ((ctx: Context) => boolean) | undefined;
196
+ debug?: boolean | undefined;
197
+ }
198
+
199
+ /**
200
+ * Helper type to extract TypeScript type from Zod schema
201
+ */
202
+ type Infer<T> = T extends z.ZodType<infer R> ? R : unknown;
203
+ /**
204
+ * HTTP methods supported by the router
205
+ */
206
+ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
207
+ /**
208
+ * Schema for route validation with generic type parameters
209
+ */
210
+ interface RouteSchema<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>> {
211
+ /** Parameter schema for validation */
212
+ params?: P;
213
+ /** Query schema for validation */
214
+ query?: Q;
215
+ /** Body schema for validation */
216
+ body?: B;
217
+ /** Response schema for validation */
218
+ response?: R;
219
+ }
220
+ /**
221
+ * Route handler function with strongly typed params and response
222
+ */
223
+ type RouteHandler<TParams = Record<string, string>, TQuery = Record<string, string | string[] | undefined>, TBody = unknown, TResponse = unknown> = (ctx: Context<State, TBody, TQuery>, params: TParams) => Promise<TResponse> | TResponse;
224
+ /**
225
+ * Options for a route method with schema-based type inference
226
+ */
227
+ interface RouteMethodOptions<P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>> {
228
+ /** Schema for request/response validation */
229
+ schema?: RouteSchema<P, Q, B, R>;
230
+ /** Handler function for the route */
231
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, B extends z.ZodType ? Infer<B> : unknown, R extends z.ZodType ? Infer<R> : unknown>;
232
+ /** Middleware to apply to this route */
233
+ middleware?: Middleware[];
234
+ /** Route-specific options */
235
+ options?: Record<string, unknown>;
236
+ }
237
+ /**
238
+ * Route definition mapping HTTP methods to handlers
239
+ */
240
+ interface RouteDefinition {
241
+ GET?: RouteMethodOptions<any, any, never, any>;
242
+ POST?: RouteMethodOptions<any, any, any, any>;
243
+ PUT?: RouteMethodOptions<any, any, any, any>;
244
+ DELETE?: RouteMethodOptions<any, any, never, any>;
245
+ PATCH?: RouteMethodOptions<any, any, any, any>;
246
+ HEAD?: RouteMethodOptions<any, any, never, any>;
247
+ OPTIONS?: RouteMethodOptions<any, any, never, any>;
248
+ }
249
+ /**
250
+ * Route object with path
251
+ */
252
+ interface Route extends RouteDefinition {
253
+ /** Path of the route */
254
+ path: string;
255
+ }
256
+ /**
257
+ * Options for route creation
258
+ */
259
+ interface RouteOptions {
260
+ /** Base path for the route */
261
+ basePath?: string;
262
+ }
263
+ /**
264
+ * Result type for handling success and error responses
265
+ */
266
+ type Result<T, E = {
267
+ error: string;
268
+ message: string;
269
+ details?: unknown;
270
+ }> = {
271
+ success: true;
272
+ data: T;
273
+ status?: number;
274
+ } | {
275
+ success: false;
276
+ error: E;
277
+ status?: number;
278
+ };
279
+ /**
280
+ * Router options
281
+ */
282
+ interface RouterOptions {
283
+ /** Directory containing route files */
284
+ routesDir: string;
285
+ /** Base path for all routes */
286
+ basePath?: string;
287
+ /** Watch for file changes in development */
288
+ watchMode?: boolean;
289
+ }
290
+ /**
291
+ * Router interface
292
+ */
293
+ interface Router {
294
+ /** Handle an incoming request */
295
+ handleRequest: (ctx: Context) => Promise<void>;
296
+ /** Get all registered routes */
297
+ getRoutes: () => Route[];
298
+ /** Add a route programmatically */
299
+ addRoute: (route: Route) => void;
300
+ /** Add a route directory for plugins */
301
+ addRouteDirectory(directory: string, options?: {
302
+ prefix?: string;
303
+ }): Promise<void>;
304
+ /** Get route conflicts */
305
+ getRouteConflicts(): Array<{
306
+ path: string;
307
+ sources: string[];
308
+ }>;
309
+ }
310
+ /**
311
+ * Route match result
312
+ */
313
+ interface RouteMatch {
314
+ /** The matched route handler (null if method not allowed) */
315
+ route: RouteMethodOptions | null;
316
+ /** Extracted route parameters */
317
+ params: Record<string, string>;
318
+ /** Flag indicating if the path exists but method isn't allowed */
319
+ methodNotAllowed?: boolean;
320
+ /** List of allowed methods for this path (when method not allowed) */
321
+ allowedMethods?: HttpMethod[];
322
+ }
323
+ /**
324
+ * Route matcher interface
325
+ */
326
+ interface Matcher {
327
+ /** Add a route to the matcher */
328
+ add: (path: string, method: HttpMethod, route: RouteMethodOptions) => void;
329
+ /** Match a URL path to a route */
330
+ match: (path: string, method: HttpMethod) => RouteMatch | null;
331
+ /** Get all registered routes */
332
+ getRoutes: () => {
333
+ path: string;
334
+ method: HttpMethod;
335
+ }[];
336
+ /** Find routes matching a specific path */
337
+ findRoutes: (path: string) => {
338
+ path: string;
339
+ method: HttpMethod;
340
+ params: Record<string, string>;
341
+ }[];
342
+ }
343
+ interface ParsedRoute {
344
+ filePath: string;
345
+ routePath: string;
346
+ params: string[];
347
+ }
348
+ /**
349
+ * Node in the radix tree for efficient route matching
350
+ */
351
+ interface RouteNode {
352
+ segment: string;
353
+ paramName: string | null;
354
+ isWildcard: boolean;
355
+ children: RouteNode[];
356
+ handlers: Partial<Record<HttpMethod, RouteMethodOptions>>;
357
+ pattern: RegExp | null;
358
+ }
359
+ interface RouteEntry {
360
+ /** The route path pattern */
361
+ path: string;
362
+ /** The HTTP method */
363
+ method: HttpMethod;
364
+ /** The compiled regex pattern */
365
+ pattern: RegExp;
366
+ /** The parameter names in order */
367
+ paramNames: string[];
368
+ /** The route handler options */
369
+ routeOptions: RouteMethodOptions;
370
+ }
371
+ interface ErrorHandlerOptions {
372
+ /** Show detailed errors in response */
373
+ detailed?: boolean;
374
+ /** Log errors to console */
375
+ log?: boolean;
376
+ }
377
+ interface ProcessResponseOptions {
378
+ /** Status code to use if not specified */
379
+ defaultStatus?: number;
380
+ }
381
+ /**
382
+ * Standard error response structure
383
+ */
384
+ interface StandardErrorResponse {
385
+ error: string;
386
+ message: string;
387
+ }
388
+ /**
389
+ * GET route creator - no body schema needed
390
+ */
391
+ type CreateGetRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
392
+ schema?: {
393
+ params?: P;
394
+ query?: Q;
395
+ response?: R;
396
+ };
397
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, never, R extends z.ZodType ? Infer<R> : unknown>;
398
+ middleware?: Middleware[];
399
+ options?: Record<string, unknown>;
400
+ }) => {
401
+ GET: RouteMethodOptions<P, Q, never, R>;
402
+ path: string;
403
+ };
404
+ /**
405
+ * POST route creator - includes body schema
406
+ */
407
+ type CreatePostRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
408
+ schema?: {
409
+ params?: P;
410
+ query?: Q;
411
+ body?: B;
412
+ response?: R;
413
+ };
414
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, B extends z.ZodType ? Infer<B> : unknown, R extends z.ZodType ? Infer<R> : unknown>;
415
+ middleware?: Middleware[];
416
+ options?: Record<string, unknown>;
417
+ }) => {
418
+ POST: RouteMethodOptions<P, Q, B, R>;
419
+ path: string;
420
+ };
421
+ /**
422
+ * PUT route creator - includes body schema
423
+ */
424
+ type CreatePutRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
425
+ schema?: {
426
+ params?: P;
427
+ query?: Q;
428
+ body?: B;
429
+ response?: R;
430
+ };
431
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, B extends z.ZodType ? Infer<B> : unknown, R extends z.ZodType ? Infer<R> : unknown>;
432
+ middleware?: Middleware[];
433
+ options?: Record<string, unknown>;
434
+ }) => {
435
+ PUT: RouteMethodOptions<P, Q, B, R>;
436
+ path: string;
437
+ };
438
+ /**
439
+ * DELETE route creator - typically no body
440
+ */
441
+ type CreateDeleteRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
442
+ schema?: {
443
+ params?: P;
444
+ query?: Q;
445
+ response?: R;
446
+ };
447
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, never, R extends z.ZodType ? Infer<R> : unknown>;
448
+ middleware?: Middleware[];
449
+ options?: Record<string, unknown>;
450
+ }) => {
451
+ DELETE: RouteMethodOptions<P, Q, never, R>;
452
+ path: string;
453
+ };
454
+ /**
455
+ * PATCH route creator - includes body schema
456
+ */
457
+ type CreatePatchRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, B extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
458
+ schema?: {
459
+ params?: P;
460
+ query?: Q;
461
+ body?: B;
462
+ response?: R;
463
+ };
464
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, B extends z.ZodType ? Infer<B> : unknown, R extends z.ZodType ? Infer<R> : unknown>;
465
+ middleware?: Middleware[];
466
+ options?: Record<string, unknown>;
467
+ }) => {
468
+ PATCH: RouteMethodOptions<P, Q, B, R>;
469
+ path: string;
470
+ };
471
+ /**
472
+ * HEAD route creator - no body schema needed (same as GET)
473
+ */
474
+ type CreateHeadRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
475
+ schema?: {
476
+ params?: P;
477
+ query?: Q;
478
+ response?: R;
479
+ };
480
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, never, R extends z.ZodType ? Infer<R> : unknown>;
481
+ middleware?: Middleware[];
482
+ options?: Record<string, unknown>;
483
+ }) => {
484
+ HEAD: RouteMethodOptions<P, Q, never, R>;
485
+ path: string;
486
+ };
487
+ /**
488
+ * OPTIONS route creator - typically no body or response schema
489
+ */
490
+ type CreateOptionsRoute = <P extends z.ZodType = z.ZodType<any>, Q extends z.ZodType = z.ZodType<any>, R extends z.ZodType = z.ZodType<any>>(config: {
491
+ schema?: {
492
+ params?: P;
493
+ query?: Q;
494
+ response?: R;
495
+ };
496
+ handler: RouteHandler<P extends z.ZodType ? Infer<P> : Record<string, string>, Q extends z.ZodType ? Infer<Q> : QueryParams, never, R extends z.ZodType ? Infer<R> : unknown>;
497
+ middleware?: Middleware[];
498
+ options?: Record<string, unknown>;
499
+ }) => {
500
+ OPTIONS: RouteMethodOptions<P, Q, never, R>;
501
+ path: string;
502
+ };
503
+
504
+ type ExtractParams<T> = T extends RouteMethodOptions<infer P, any, any, any> ? P extends z.ZodType ? Infer<P> : Record<string, string> : never;
505
+ type ExtractQuery<T> = T extends RouteMethodOptions<any, infer Q, any, any> ? Q extends z.ZodType ? Infer<Q> : Record<string, string | string[] | undefined> : never;
506
+ type ExtractBody<T> = T extends RouteMethodOptions<any, any, infer B, any> ? B extends z.ZodType ? Infer<B> : unknown : never;
507
+ type ExtractResponse<T> = T extends RouteMethodOptions<any, any, any, infer R> ? R extends z.ZodType ? Infer<R> : unknown : never;
508
+ type ExtractMethod<T> = T extends {
509
+ GET: any;
510
+ } ? 'GET' : T extends {
511
+ POST: any;
512
+ } ? 'POST' : T extends {
513
+ PUT: any;
514
+ } ? 'PUT' : T extends {
515
+ DELETE: any;
516
+ } ? 'DELETE' : T extends {
517
+ PATCH: any;
518
+ } ? 'PATCH' : T extends {
519
+ HEAD: any;
520
+ } ? 'HEAD' : T extends {
521
+ OPTIONS: any;
522
+ } ? 'OPTIONS' : never;
523
+ type BuildRoutesRegistry<TRoutes extends Record<string, any>> = {
524
+ [Method in ExtractMethod<TRoutes[keyof TRoutes]> as `$${Lowercase<Method>}`]: {
525
+ [K in keyof TRoutes as ExtractMethod<TRoutes[K]> extends Method ? K : never]: TRoutes[K];
526
+ };
527
+ };
528
+ type GetRouteMethod<TRoute> = TRoute extends {
529
+ path: string;
530
+ } ? Omit<TRoute, 'path'>[keyof Omit<TRoute, 'path'>] : never;
531
+ type CreateClientMethod<TRoute> = GetRouteMethod<TRoute> extends RouteMethodOptions<any, any, any, any> ? (args?: {
532
+ params?: ExtractParams<GetRouteMethod<TRoute>>;
533
+ query?: ExtractQuery<GetRouteMethod<TRoute>>;
534
+ body?: ExtractBody<GetRouteMethod<TRoute>>;
535
+ }) => Promise<ExtractResponse<GetRouteMethod<TRoute>>> : never;
536
+ type CreateClient<TRoutes extends Record<string, Record<string, any>>> = {
537
+ [Method in keyof TRoutes]: {
538
+ [RouteName in keyof TRoutes[Method]]: CreateClientMethod<TRoutes[Method][RouteName]>;
539
+ };
540
+ };
541
+ interface ClientConfig {
542
+ baseUrl: string;
543
+ defaultHeaders?: Record<string, string>;
544
+ timeout?: number;
545
+ }
546
+ interface RequestArgs {
547
+ params?: Record<string, string>;
548
+ query?: Record<string, any>;
549
+ body?: unknown;
550
+ }
551
+ interface RequestOptions {
552
+ method: string;
553
+ url: string;
554
+ headers: Record<string, string>;
555
+ body?: string;
556
+ timeout: number;
557
+ }
558
+
559
+ /**
560
+ * BlaizeJS Plugin Module
561
+ *
562
+ * Provides the plugin system for extending framework functionality.
563
+ */
564
+
565
+ /**
566
+ * Plugin options
567
+ */
568
+ interface PluginOptions<_T = any> {
569
+ /** Plugin configuration */
570
+ [key: string]: any;
571
+ }
572
+ /**
573
+ * Plugin lifecycle hooks
574
+ */
575
+ interface PluginHooks {
576
+ /** Called when the plugin is registered */
577
+ register: (app: Server) => void | Promise<void>;
578
+ /** Called when the server is initialized */
579
+ initialize?: (app?: Server) => void | Promise<void>;
580
+ /** Called when the server is terminated */
581
+ terminate?: (app?: Server) => void | Promise<void>;
582
+ /** Called when the server starts */
583
+ onServerStart?: (server: any) => void | Promise<void>;
584
+ /** Called when the server stops */
585
+ onServerStop?: (server: any) => void | Promise<void>;
586
+ }
587
+ /**
588
+ * Plugin interface
589
+ */
590
+ interface Plugin extends PluginHooks {
591
+ /** Plugin name */
592
+ name: string;
593
+ /** Plugin version */
594
+ version: string;
595
+ }
596
+ /**
597
+ * Plugin factory function
598
+ */
599
+ type PluginFactory<T = any> = (options?: T) => Plugin;
600
+ interface PluginLifecycleManager {
601
+ initializePlugins(server: Server): Promise<void>;
602
+ terminatePlugins(server: Server): Promise<void>;
603
+ onServerStart(server: Server, httpServer: any): Promise<void>;
604
+ onServerStop(server: Server, httpServer: any): Promise<void>;
605
+ }
606
+ interface PluginLifecycleOptions {
607
+ /** Continue initialization even if a plugin fails */
608
+ continueOnError?: boolean;
609
+ /** Log plugin lifecycle events */
610
+ debug?: boolean;
611
+ /** Custom error handler for plugin failures */
612
+ onError?: (plugin: Plugin, phase: string, error: Error) => void;
613
+ }
614
+
615
+ /**
616
+ * BlaizeJS Server Module
617
+ *
618
+ * Provides the core HTTP/2 server implementation with HTTP/1.1 fallback.
619
+ */
620
+
621
+ interface Http2Options {
622
+ enabled?: boolean | undefined;
623
+ keyFile?: string | undefined;
624
+ certFile?: string | undefined;
625
+ }
626
+ interface StartOptions {
627
+ port?: number;
628
+ host?: string;
629
+ }
630
+ interface StopOptions {
631
+ timeout?: number;
632
+ plugins?: Plugin[];
633
+ onStopping?: () => Promise<void> | void;
634
+ onStopped?: () => Promise<void> | void;
635
+ }
636
+ /**
637
+ * Server options for configuring the BlaizeJS server
638
+ */
639
+ interface ServerOptionsInput {
640
+ /** Port to listen on (default: 3000) */
641
+ port?: number;
642
+ /** Host to bind to (default: localhost) */
643
+ host?: string;
644
+ /** Directory containing route files (default: ./routes) */
645
+ routesDir?: string;
646
+ /** HTTP/2 options */
647
+ http2?: {
648
+ /** Enable HTTP/2 (default: true) */
649
+ enabled?: boolean | undefined;
650
+ /** Path to key file for HTTPS/HTTP2 */
651
+ keyFile?: string | undefined;
652
+ /** Path to certificate file for HTTPS/HTTP2 */
653
+ certFile?: string | undefined;
654
+ };
655
+ /** Global middleware to apply to all routes */
656
+ middleware?: Middleware[];
657
+ /** Plugins to register */
658
+ plugins?: Plugin[];
659
+ }
660
+ /**
661
+ * Configuration for a BlaizeJS server
662
+ */
663
+ interface ServerOptions {
664
+ /** Port to listen on (default: 3000) */
665
+ port: number;
666
+ /** Host to bind to (default: localhost) */
667
+ host: string;
668
+ /** Directory containing route files (default: ./routes) */
669
+ routesDir: string;
670
+ /** HTTP/2 options */
671
+ http2?: {
672
+ /** Enable HTTP/2 (default: true) */
673
+ enabled?: boolean | undefined;
674
+ /** Path to key file for HTTPS/HTTP2 */
675
+ keyFile?: string | undefined;
676
+ /** Path to certificate file for HTTPS/HTTP2 */
677
+ certFile?: string | undefined;
678
+ };
679
+ /** Global middleware to apply to all routes */
680
+ middleware?: Middleware[];
681
+ /** Plugins to register */
682
+ plugins?: Plugin[];
683
+ }
684
+ /**
685
+ * BlaizeJS Server instance
686
+ */
687
+ interface Server {
688
+ /** The underlying HTTP or HTTP/2 server */
689
+ server: http.Server | http2.Http2Server | undefined;
690
+ /** The port the server is configured to listen on */
691
+ port: number;
692
+ /** The host the server is bound to */
693
+ host: string;
694
+ events: EventEmitter;
695
+ /** Direct access to registered plugins */
696
+ plugins: Plugin[];
697
+ /** Direct access to registered plugins */
698
+ middleware: Middleware[];
699
+ /** Internal property for signal hanlders */
700
+ _signalHandlers?: {
701
+ unregister: () => void;
702
+ };
703
+ /** Start the server and listen for connections */
704
+ listen: (port?: number, host?: string) => Promise<Server>;
705
+ /** Stop the server */
706
+ close: (stopOptions?: StopOptions) => Promise<void>;
707
+ /** Add global middleware */
708
+ use: (middleware: Middleware | Middleware[]) => Server;
709
+ /** Register a plugin */
710
+ register: (plugin: Plugin) => Promise<Server>;
711
+ /** Access to the routing system */
712
+ router: Router;
713
+ /** Context storage system */
714
+ context: AsyncLocalStorage<Context>;
715
+ pluginManager: PluginLifecycleManager;
716
+ }
717
+ type RequestHandler = (req: http.IncomingMessage | http2.Http2ServerRequest, res: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
718
+
54
719
  declare const VERSION = "0.1.0";
55
720
  declare const ServerAPI: {
56
721
  createServer: typeof create;
57
722
  };
58
723
  declare const RouterAPI: {
59
- createDeleteRoute: _blaizejs_types.CreateDeleteRoute;
60
- createGetRoute: _blaizejs_types.CreateGetRoute;
61
- createHeadRoute: _blaizejs_types.CreateHeadRoute;
62
- createOptionsRoute: _blaizejs_types.CreateOptionsRoute;
63
- createPatchRoute: _blaizejs_types.CreatePatchRoute;
64
- createPostRoute: _blaizejs_types.CreatePostRoute;
65
- createPutRoute: _blaizejs_types.CreatePutRoute;
724
+ createDeleteRoute: CreateDeleteRoute;
725
+ createGetRoute: CreateGetRoute;
726
+ createHeadRoute: CreateHeadRoute;
727
+ createOptionsRoute: CreateOptionsRoute;
728
+ createPatchRoute: CreatePatchRoute;
729
+ createPostRoute: CreatePostRoute;
730
+ createPutRoute: CreatePutRoute;
66
731
  };
67
732
  declare const MiddlewareAPI: {
68
733
  createMiddleware: typeof create$2;
@@ -79,13 +744,13 @@ declare const Blaize: {
79
744
  createServer: typeof create;
80
745
  };
81
746
  Router: {
82
- createDeleteRoute: _blaizejs_types.CreateDeleteRoute;
83
- createGetRoute: _blaizejs_types.CreateGetRoute;
84
- createHeadRoute: _blaizejs_types.CreateHeadRoute;
85
- createOptionsRoute: _blaizejs_types.CreateOptionsRoute;
86
- createPatchRoute: _blaizejs_types.CreatePatchRoute;
87
- createPostRoute: _blaizejs_types.CreatePostRoute;
88
- createPutRoute: _blaizejs_types.CreatePutRoute;
747
+ createDeleteRoute: CreateDeleteRoute;
748
+ createGetRoute: CreateGetRoute;
749
+ createHeadRoute: CreateHeadRoute;
750
+ createOptionsRoute: CreateOptionsRoute;
751
+ createPatchRoute: CreatePatchRoute;
752
+ createPostRoute: CreatePostRoute;
753
+ createPutRoute: CreatePutRoute;
89
754
  };
90
755
  Middleware: {
91
756
  createMiddleware: typeof create$2;
@@ -97,4 +762,4 @@ declare const Blaize: {
97
762
  VERSION: string;
98
763
  };
99
764
 
100
- export { Blaize, MiddlewareAPI, PluginsAPI, RouterAPI, ServerAPI, VERSION, compose, createDeleteRoute, createGetRoute, createHeadRoute, create$2 as createMiddleware, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPostRoute, createPutRoute, create as createServer, Blaize as default };
765
+ export { Blaize, type BuildRoutesRegistry, type ClientConfig, type Context, type ContextOptions, type ContextRequest, type ContextResponse, type CreateClient, type CreateContextFn, type CreateDeleteRoute, type CreateGetRoute, type CreateHeadRoute, type CreateOptionsRoute, type CreatePatchRoute, type CreatePostRoute, type CreatePutRoute, type ErrorHandlerOptions, type ExtractBody, type ExtractMethod, type ExtractParams, type ExtractQuery, type ExtractResponse, type GetContextFn, type Http2Options, type HttpMethod, type Infer, type Matcher, type Middleware, MiddlewareAPI, type MiddlewareFunction, type MiddlewareOptions, type NextFunction, type ParsedRoute, type Plugin, type PluginFactory, type PluginHooks, type PluginLifecycleManager, type PluginLifecycleOptions, type PluginOptions, PluginsAPI, type ProcessResponseOptions, type QueryParams, type RequestArgs, type RequestHandler, type RequestOptions, type RequestParams, type Result, type Route, type RouteDefinition, type RouteEntry, type RouteHandler, type RouteMatch, type RouteMethodOptions, type RouteNode, type RouteOptions, type RouteSchema, type Router, RouterAPI, type RouterOptions, type Server, ServerAPI, type ServerOptions, type ServerOptionsInput, type StandardErrorResponse, type StartOptions, type State, type StopOptions, type StreamOptions, type UnifiedRequest, type UnifiedResponse, type UnknownFunction, VERSION, compose, createDeleteRoute, createGetRoute, createHeadRoute, create$2 as createMiddleware, createOptionsRoute, createPatchRoute, create$1 as createPlugin, createPostRoute, createPutRoute, create as createServer, Blaize as default };