shokupan 0.10.5 → 0.12.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.
Files changed (73) hide show
  1. package/README.md +46 -1815
  2. package/dist/{analyzer-BqIe1p0R.js → analyzer-BkNQHWj4.js} +3 -8
  3. package/dist/{analyzer-BqIe1p0R.js.map → analyzer-BkNQHWj4.js.map} +1 -1
  4. package/dist/{analyzer-CKLGLFtx.cjs → analyzer-DM-OlRq8.cjs} +2 -7
  5. package/dist/{analyzer-CKLGLFtx.cjs.map → analyzer-DM-OlRq8.cjs.map} +1 -1
  6. package/dist/{analyzer.impl-D9Yi1Hax.cjs → analyzer.impl-CVJ8zfGQ.cjs} +596 -42
  7. package/dist/analyzer.impl-CVJ8zfGQ.cjs.map +1 -0
  8. package/dist/{analyzer.impl-CV6W1Eq7.js → analyzer.impl-CsA1bS_s.js} +596 -42
  9. package/dist/analyzer.impl-CsA1bS_s.js.map +1 -0
  10. package/dist/cli.cjs +206 -18
  11. package/dist/cli.cjs.map +1 -1
  12. package/dist/cli.js +206 -18
  13. package/dist/cli.js.map +1 -1
  14. package/dist/context.d.ts +46 -9
  15. package/dist/index.cjs +3239 -1173
  16. package/dist/index.cjs.map +1 -1
  17. package/dist/index.js +3236 -1171
  18. package/dist/index.js.map +1 -1
  19. package/dist/plugins/application/api-explorer/static/explorer-client.mjs +375 -29
  20. package/dist/plugins/application/api-explorer/static/style.css +327 -8
  21. package/dist/plugins/application/api-explorer/static/theme.css +11 -2
  22. package/dist/plugins/application/asyncapi/generator.d.ts +4 -0
  23. package/dist/plugins/application/asyncapi/static/asyncapi-client.mjs +154 -22
  24. package/dist/plugins/application/asyncapi/static/style.css +24 -8
  25. package/dist/plugins/application/auth.d.ts +5 -0
  26. package/dist/plugins/application/dashboard/fetch-interceptor.d.ts +119 -0
  27. package/dist/plugins/application/dashboard/metrics-collector.d.ts +38 -2
  28. package/dist/plugins/application/dashboard/plugin.d.ts +53 -1
  29. package/dist/plugins/application/dashboard/static/charts.js +127 -62
  30. package/dist/plugins/application/dashboard/static/client.js +160 -0
  31. package/dist/plugins/application/dashboard/static/graph.mjs +167 -56
  32. package/dist/plugins/application/dashboard/static/reactflow.css +20 -10
  33. package/dist/plugins/application/dashboard/static/registry.js +112 -8
  34. package/dist/plugins/application/dashboard/static/requests.js +1167 -71
  35. package/dist/plugins/application/dashboard/static/styles.css +186 -14
  36. package/dist/plugins/application/dashboard/static/tabs.js +44 -9
  37. package/dist/plugins/application/dashboard/static/tabulator.css +23 -3
  38. package/dist/plugins/application/dashboard/static/theme.css +11 -2
  39. package/dist/plugins/application/mcp-server/plugin.d.ts +39 -0
  40. package/dist/plugins/application/openapi/analyzer.impl.d.ts +65 -1
  41. package/dist/plugins/application/openapi/openapi.d.ts +3 -0
  42. package/dist/plugins/application/shared/ast-utils.d.ts +7 -0
  43. package/dist/plugins/middleware/compression.d.ts +12 -2
  44. package/dist/plugins/middleware/rate-limit.d.ts +5 -0
  45. package/dist/router.d.ts +59 -19
  46. package/dist/server.d.ts +22 -0
  47. package/dist/shokupan.d.ts +31 -3
  48. package/dist/util/adapter/bun.d.ts +8 -0
  49. package/dist/util/adapter/filesystem.d.ts +20 -0
  50. package/dist/util/adapter/index.d.ts +4 -0
  51. package/dist/util/adapter/interface.d.ts +12 -0
  52. package/dist/util/adapter/node.d.ts +8 -0
  53. package/dist/util/adapter/wintercg.d.ts +5 -0
  54. package/dist/util/body-parser.d.ts +30 -0
  55. package/dist/util/controller-scanner.d.ts +4 -0
  56. package/dist/util/cpu-monitor.d.ts +2 -0
  57. package/dist/util/decorators.d.ts +20 -3
  58. package/dist/util/di.d.ts +3 -8
  59. package/dist/util/metadata.d.ts +18 -0
  60. package/dist/util/middleware-tracker.d.ts +10 -0
  61. package/dist/util/request.d.ts +1 -0
  62. package/dist/util/symbol.d.ts +1 -0
  63. package/dist/util/types.d.ts +167 -1
  64. package/package.json +7 -5
  65. package/dist/analyzer.impl-CV6W1Eq7.js.map +0 -1
  66. package/dist/analyzer.impl-D9Yi1Hax.cjs.map +0 -1
  67. package/dist/http-server-BEMPIs33.cjs +0 -85
  68. package/dist/http-server-BEMPIs33.cjs.map +0 -1
  69. package/dist/http-server-CCeagTyU.js +0 -68
  70. package/dist/http-server-CCeagTyU.js.map +0 -1
  71. package/dist/plugins/application/dashboard/static/failures.js +0 -85
  72. package/dist/plugins/application/dashboard/static/poll.js +0 -146
  73. package/dist/plugins/application/http-server.d.ts +0 -13
package/dist/router.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { ShokupanContext } from './context';
2
2
  import { Shokupan } from './shokupan';
3
- import { SurrealDatastore } from './util/datastore';
4
3
  import { $appRoot, $childControllers, $childRouters, $isApplication, $isMounted, $isRouter, $mountPath, $parent, $routes } from './util/symbol';
5
4
  import { GuardAPISpec, HeadersInit, JSXRenderer, Method, MethodAPISpec, Middleware, OpenAPIOptions, ProcessResult, RequestOptions, RouteMetadata, RouteParams, ShokupanController, ShokupanHandler, ShokupanHooks, ShokupanRoute, ShokupanRouteConfig, StaticServeOptions } from './util/types';
6
5
  export declare const RouterRegistry: Map<string, ShokupanRouter<any>>;
@@ -74,7 +73,27 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
74
73
  private [$parent];
75
74
  [$childRouters]: ShokupanRouter<T>[];
76
75
  [$childControllers]: ShokupanController[];
77
- get db(): SurrealDatastore | undefined;
76
+ private _hasOnResponseEndHook;
77
+ private _hasOnRequestStartHook;
78
+ private _hasOnRequestEndHook;
79
+ private _hasOnResponseStartHook;
80
+ private _hasOnErrorHook;
81
+ private _hasOnRequestTimeoutHook;
82
+ private _hasOnReadTimeoutHook;
83
+ private _hasOnWriteTimeoutHook;
84
+ private _hasBeforeValidateHook;
85
+ private _hasAfterValidateHook;
86
+ get hasOnResponseEndHook(): boolean;
87
+ get hasOnRequestStartHook(): boolean;
88
+ get hasOnRequestEndHook(): boolean;
89
+ get hasOnResponseStartHook(): boolean;
90
+ get hasOnErrorHook(): boolean;
91
+ get hasOnRequestTimeoutHook(): boolean;
92
+ get hasOnReadTimeoutHook(): boolean;
93
+ get hasOnWriteTimeoutHook(): boolean;
94
+ get hasBeforeValidateHook(): boolean;
95
+ get hasAfterValidateHook(): boolean;
96
+ requestTimeout?: number;
78
97
  private hookCache;
79
98
  private hooksInitialized;
80
99
  middleware: Middleware[];
@@ -85,10 +104,13 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
85
104
  development: boolean;
86
105
  enableAsyncLocalStorage: boolean;
87
106
  enableOpenApiGen: boolean;
107
+ blockOnOpenApiGen: boolean;
88
108
  enableAsyncApiGen: boolean;
109
+ blockOnAsyncApiGen: boolean;
89
110
  reusePort: boolean;
90
111
  controllersOnly: boolean;
91
112
  enableTracing?: boolean;
113
+ queryParserMode?: "extended" | "simple" | "strict";
92
114
  jsonParser?: "native" | "parse-json" | "secure-json-parse";
93
115
  autoBackpressureFeedback?: boolean;
94
116
  autoBackpressureLevel?: number;
@@ -108,10 +130,13 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
108
130
  fatal: (msg: string, props: Record<string, any>) => void;
109
131
  };
110
132
  readTimeout: number;
133
+ maxBodySize?: number;
111
134
  requestTimeout: number;
112
135
  writeTimeout: number;
113
136
  renderer: JSXRenderer;
114
137
  serverFactory: import('.').ServerFactory;
138
+ adapter?: "bun" | "node" | "wintercg" | import('./util/adapter').ServerAdapter;
139
+ fileSystem?: import('./util/adapter/filesystem').FileSystemAdapter;
115
140
  hooks: ShokupanHooks<Record<string, any>> | ShokupanHooks<Record<string, any>>[];
116
141
  validateStatusCodes: boolean;
117
142
  surreal?: {
@@ -148,6 +173,7 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
148
173
  spec_url: string;
149
174
  }>;
150
175
  };
176
+ securityHeaders?: boolean | any;
151
177
  }>;
152
178
  get root(): Shokupan<any>;
153
179
  [$routes]: ShokupanRoute[];
@@ -160,7 +186,7 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
160
186
  * Middleware will run for all routes matched by this router.
161
187
  */
162
188
  use(middleware: Middleware): this;
163
- getComponentRegistry(): {
189
+ get registry(): {
164
190
  metadata: RouteMetadata;
165
191
  middleware: {
166
192
  name: string;
@@ -195,6 +221,13 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
195
221
  routes: any[];
196
222
  };
197
223
  }[];
224
+ events: {
225
+ type: 'event';
226
+ name: string;
227
+ handlerName: string;
228
+ metadata: RouteMetadata;
229
+ _fn: ShokupanHandler<T>;
230
+ }[];
198
231
  };
199
232
  constructor(config?: ShokupanRouteConfig);
200
233
  private isRouterInstance;
@@ -202,10 +235,18 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
202
235
  * Registers an event handler for WebSocket.
203
236
  */
204
237
  event(name: string, handler: ShokupanHandler<T>): this;
238
+ /**
239
+ * Registers a lifecycle hook dynamically.
240
+ */
241
+ hook(name: keyof ShokupanHooks, handler: Function): this;
205
242
  /**
206
243
  * Finds an event handler(s) by name.
207
244
  */
208
245
  findEvent(name: string): ShokupanHandler<T>[] | null;
246
+ /**
247
+ * Registers a controller instance to the router.
248
+ */
249
+ bindController(controller: any): void;
209
250
  /**
210
251
  * Returns all registered event handlers.
211
252
  */
@@ -248,7 +289,6 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
248
289
  testRequest(options: RequestOptions): Promise<ProcessResult>;
249
290
  private wrapWithHooks;
250
291
  private mountRouter;
251
- private scanControllerRoutes;
252
292
  /**
253
293
  * Find a route matching the given method and path.
254
294
  * @param method HTTP method
@@ -260,7 +300,6 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
260
300
  params: Record<string, string>;
261
301
  } | null;
262
302
  private parsePath;
263
- requestTimeout?: number;
264
303
  /**
265
304
  * Adds a route to the router.
266
305
  *
@@ -297,7 +336,7 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
297
336
  * @param path - URL path
298
337
  * @param handlers - Route handler functions
299
338
  */
300
- get<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
339
+ get<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
301
340
  /**
302
341
  * Adds a GET route to the router.
303
342
  *
@@ -305,14 +344,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
305
344
  * @param spec - OpenAPI specification for the route
306
345
  * @param handlers - Route handler functions
307
346
  */
308
- get<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
347
+ get<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
309
348
  /**
310
349
  * Adds a POST route to the router.
311
350
  *
312
351
  * @param path - URL path
313
352
  * @param handlers - Route handler functions
314
353
  */
315
- post<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
354
+ post<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
316
355
  /**
317
356
  * Adds a POST route to the router.
318
357
  *
@@ -320,14 +359,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
320
359
  * @param spec - OpenAPI specification for the route
321
360
  * @param handlers - Route handler functions
322
361
  */
323
- post<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
362
+ post<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
324
363
  /**
325
364
  * Adds a PUT route to the router.
326
365
  *
327
366
  * @param path - URL path
328
367
  * @param handlers - Route handler functions
329
368
  */
330
- put<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
369
+ put<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
331
370
  /**
332
371
  * Adds a PUT route to the router.
333
372
  *
@@ -335,14 +374,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
335
374
  * @param spec - OpenAPI specification for the route
336
375
  * @param handlers - Route handler functions
337
376
  */
338
- put<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
377
+ put<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
339
378
  /**
340
379
  * Adds a DELETE route to the router.
341
380
  *
342
381
  * @param path - URL path
343
382
  * @param handlers - Route handler functions
344
383
  */
345
- delete<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
384
+ delete<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
346
385
  /**
347
386
  * Adds a DELETE route to the router.
348
387
  *
@@ -350,14 +389,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
350
389
  * @param spec - OpenAPI specification for the route
351
390
  * @param handlers - Route handler functions
352
391
  */
353
- delete<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
392
+ delete<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
354
393
  /**
355
394
  * Adds a PATCH route to the router.
356
395
  *
357
396
  * @param path - URL path
358
397
  * @param handlers - Route handler functions
359
398
  */
360
- patch<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
399
+ patch<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
361
400
  /**
362
401
  * Adds a PATCH route to the router.
363
402
  *
@@ -365,14 +404,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
365
404
  * @param spec - OpenAPI specification for the route
366
405
  * @param handlers - Route handler functions
367
406
  */
368
- patch<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
407
+ patch<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
369
408
  /**
370
409
  * Adds a OPTIONS route to the router.
371
410
  *
372
411
  * @param path - URL path
373
412
  * @param handlers - Route handler functions
374
413
  */
375
- options<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
414
+ options<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
376
415
  /**
377
416
  * Adds a OPTIONS route to the router.
378
417
  *
@@ -380,14 +419,14 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
380
419
  * @param spec - OpenAPI specification for the route
381
420
  * @param handlers - Route handler functions
382
421
  */
383
- options<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
422
+ options<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
384
423
  /**
385
424
  * Adds a HEAD route to the router.
386
425
  *
387
426
  * @param path - URL path
388
427
  * @param handlers - Route handler functions
389
428
  */
390
- head<Path extends string>(path: Path, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
429
+ head<Path extends string>(path: Path, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
391
430
  /**
392
431
  * Adds a HEAD route to the router.
393
432
  *
@@ -395,7 +434,7 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
395
434
  * @param spec - OpenAPI specification for the route
396
435
  * @param handlers - Route handler functions
397
436
  */
398
- head<Path extends string>(path: Path, spec: MethodAPISpec, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
437
+ head<Path extends string>(path: Path, spec: MethodAPISpec, handler: ShokupanHandler<T, RouteParams<Path>>, ...handlers: ShokupanHandler<T, RouteParams<Path>>[]): any;
399
438
  /**
400
439
  * Adds a guard to the router that applies to all routes added **after** this point.
401
440
  * Guards must return true or call `ctx.next()` to allow the request to continue.
@@ -427,6 +466,7 @@ export declare class ShokupanRouter<T extends Record<string, any> = Record<strin
427
466
  * Now includes runtime analysis of handler functions to infer request/response types.
428
467
  */
429
468
  generateApiSpec(options?: OpenAPIOptions): Promise<any>;
469
+ hasHooks(name: keyof ShokupanHooks): boolean;
430
470
  private ensureHooksInitialized;
431
471
  runHooks(name: keyof ShokupanHooks, ...args: any[]): void | Promise<void[]>;
432
472
  }
@@ -0,0 +1,22 @@
1
+ import { Shokupan } from './shokupan';
2
+ /**
3
+ * Shokupan Server
4
+ *
5
+ * Responsible for the lifecycle of the HTTP server (listen, stop)
6
+ * and managing the underlying adapter (Bun, Node, etc).
7
+ */
8
+ export declare class ShokupanServer {
9
+ private app;
10
+ private server?;
11
+ private adapter?;
12
+ constructor(app: Shokupan);
13
+ /**
14
+ * Starts the application server.
15
+ * @param port The port to listen on.
16
+ */
17
+ listen(port?: number): Promise<any>;
18
+ /**
19
+ * Stops the server.
20
+ */
21
+ stop(closeActiveConnections?: boolean): Promise<void>;
22
+ }
@@ -1,9 +1,9 @@
1
- import { $dispatch } from './util/symbol';
2
- import { Middleware, ProcessResult, RequestOptions, ShokupanConfig, ShokupanPlugin } from './util/types';
3
1
  import { Server } from 'bun';
4
2
  import { ShokupanRouter } from './router';
5
3
  import { SurrealDatastore } from './util/datastore';
6
4
  import { ShokupanRequest } from './util/request';
5
+ import { $dispatch } from './util/symbol';
6
+ import { Middleware, ProcessResult, RequestOptions, ShokupanConfig, ShokupanPlugin } from './util/types';
7
7
  /**
8
8
  * Shokupan Application
9
9
  *
@@ -72,11 +72,15 @@ export declare class Shokupan<T = any> extends ShokupanRouter<T> {
72
72
  readonly applicationConfig: ShokupanConfig;
73
73
  openApiSpec?: any;
74
74
  asyncApiSpec?: any;
75
+ private openApiSpecPromise?;
76
+ private asyncApiSpecPromise?;
75
77
  private composedMiddleware?;
76
78
  private cpuMonitor?;
77
- private server?;
79
+ server?: Server<any>;
80
+ private httpServer?;
78
81
  private datastore?;
79
82
  dbPromise?: Promise<any>;
83
+ private rootTrie?;
80
84
  get db(): SurrealDatastore | undefined;
81
85
  get logger(): {
82
86
  verbose: boolean;
@@ -88,6 +92,9 @@ export declare class Shokupan<T = any> extends ShokupanRouter<T> {
88
92
  };
89
93
  constructor(applicationConfig?: ShokupanConfig);
90
94
  private initDatastore;
95
+ /**
96
+ * Adds middleware to the application.
97
+ */
91
98
  /**
92
99
  * Adds middleware to the application.
93
100
  */
@@ -109,6 +116,17 @@ export declare class Shokupan<T = any> extends ShokupanRouter<T> {
109
116
  * This happens after generateOpenApi() but before the server starts listening (or at least before it finishes startup if async).
110
117
  */
111
118
  onSpecAvailable(callback: (spec: any) => void | Promise<void>): this;
119
+ /**
120
+ * Starts the application server.
121
+ *
122
+ * @param port - The port to listen on. If not specified, the port from the configuration is used. If that is not specified, port 3000 is used.
123
+ * @returns The server instance.
124
+ */
125
+ /**
126
+ * Prepare the application for listening.
127
+ * Use this if you want to initialize the app without starting the server immediately.
128
+ */
129
+ start(): Promise<void>;
112
130
  /**
113
131
  * Starts the application server.
114
132
  *
@@ -150,4 +168,14 @@ export declare class Shokupan<T = any> extends ShokupanRouter<T> {
150
168
  */
151
169
  fetch(req: Request, server?: Server<any>): Promise<Response>;
152
170
  private handleRequest;
171
+ /**
172
+ * Compiles all routes into a master Trie for O(1) router lookup.
173
+ * Use this if adding routes dynamically after start (not recommended but possible).
174
+ */
175
+ compile(): void;
176
+ private flattenRoutes;
177
+ find(method: string, path: string): {
178
+ handler: import('.').ShokupanHandler<T>;
179
+ params: Record<string, string>;
180
+ };
153
181
  }
@@ -0,0 +1,8 @@
1
+ import { Server } from 'bun';
2
+ import { Shokupan } from '../../shokupan';
3
+ import { ServerAdapter } from './interface';
4
+ export declare class BunAdapter implements ServerAdapter {
5
+ private server?;
6
+ listen(port: number, app: Shokupan): Promise<Server<any>>;
7
+ stop(): Promise<void>;
8
+ }
@@ -0,0 +1,20 @@
1
+ export interface FileSystemAdapter {
2
+ readFile(path: string): Promise<Uint8Array | string | ReadableStream>;
3
+ stat?(path: string): Promise<{
4
+ size: number;
5
+ mtime: Date;
6
+ }>;
7
+ }
8
+ /**
9
+ * Default file system adapter that uses Bun.file for Bun and Node.js fs.promises for Node.js.
10
+ */
11
+ export declare class DefaultFileSystemAdapter implements FileSystemAdapter {
12
+ readFile(path: string): Promise<Uint8Array | string | ReadableStream>;
13
+ stat(path: string): Promise<{
14
+ size: number;
15
+ mtime: Date;
16
+ }>;
17
+ }
18
+ export declare class NoOpFileSystemAdapter implements FileSystemAdapter {
19
+ readFile(path: string): Promise<Uint8Array | string | ReadableStream>;
20
+ }
@@ -0,0 +1,4 @@
1
+ export * from './bun';
2
+ export * from './interface';
3
+ export * from './node';
4
+ export * from './wintercg';
@@ -0,0 +1,12 @@
1
+ import { Server } from 'bun';
2
+ import { Shokupan } from '../../shokupan';
3
+ export interface ServerAdapter {
4
+ /**
5
+ * Start listening on the specified port.
6
+ */
7
+ listen(port: number, app: Shokupan): Promise<Server<any>>;
8
+ /**
9
+ * Stop the server.
10
+ */
11
+ stop?(): Promise<void>;
12
+ }
@@ -0,0 +1,8 @@
1
+ import { Server } from 'bun';
2
+ import { Shokupan } from '../../shokupan';
3
+ import { ServerAdapter } from './interface';
4
+ export declare class NodeAdapter implements ServerAdapter {
5
+ private server?;
6
+ listen(port: number, app: Shokupan): Promise<Server<any>>;
7
+ stop(): Promise<void>;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { Shokupan } from '../../shokupan';
2
+ import { ServerAdapter } from './interface';
3
+ export declare class WinterCGAdapter implements ServerAdapter {
4
+ listen(port: number, app: Shokupan): Promise<any>;
5
+ }
@@ -0,0 +1,30 @@
1
+ import { ShokupanRequest } from './request';
2
+ import { ShokupanConfig } from './types';
3
+ /**
4
+ * Utility class for parsing request bodies.
5
+ * Handles size limits, parsing, and caching logic detached from the Context.
6
+ */
7
+ export declare class BodyParser {
8
+ /**
9
+ * Parses the body of a request based on Content-Type header.
10
+ * @param req The ShokupanRequest object
11
+ * @param config Application configuration for limits and parser options
12
+ * @returns The parsed body or throws an error
13
+ */
14
+ static parse(req: ShokupanRequest<any>, config?: ShokupanConfig): Promise<{
15
+ type: string;
16
+ body: any;
17
+ }>;
18
+ /**
19
+ * Parsing helper for JSON
20
+ */
21
+ static parseJson(req: ShokupanRequest<any>, parserType: 'native' | 'parse-json' | 'secure-json-parse', maxBodySize: number): Promise<any>;
22
+ /**
23
+ * Parsing helper for FormData
24
+ */
25
+ static parseFormData(req: ShokupanRequest<any>, maxBodySize: number): Promise<FormData>;
26
+ /**
27
+ * Reads raw body as string with size enforcement
28
+ */
29
+ static readRawBody(req: ShokupanRequest<any>, maxBodySize: number): Promise<string>;
30
+ }
@@ -0,0 +1,4 @@
1
+ import { ShokupanRouter } from '../router';
2
+ export declare class ControllerScanner {
3
+ static scan<T extends Record<string, any>>(router: ShokupanRouter<T>, prefix: string, controller: any): void;
4
+ }
@@ -3,7 +3,9 @@ export declare class SystemCpuMonitor {
3
3
  private interval;
4
4
  private lastCpus;
5
5
  private currentUsage;
6
+ private osStub;
6
7
  constructor(intervalMs?: number);
8
+ private init;
7
9
  start(): void;
8
10
  stop(): void;
9
11
  getUsage(): number;
@@ -5,9 +5,26 @@ import { AsyncAPISpec, GuardAPISpec, MethodAPISpec, Middleware } from './types';
5
5
  */
6
6
  export declare function Controller(path?: string): (target: any) => void;
7
7
  /**
8
- * Decorator: Applies middleware to a class or method.
8
+ * Registers this class as a **Singleton** service.
9
+ * A single instance will be created and shared across the process.
9
10
  */
10
- export declare function Use(...middleware: Middleware[]): (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void;
11
+ export declare function Injectable(scope: 'singleton'): ClassDecorator;
12
+ /**
13
+ * Registers this class as an **Instanced** (Transient) service.
14
+ * A new instance will be created every time dependency is resolved.
15
+ */
16
+ export declare function Injectable(scope: 'instanced'): ClassDecorator;
17
+ /**
18
+ * Property/Parameter Decorator: Injects a service.
19
+ * Used on class properties or constructor parameters.
20
+ */
21
+ export declare function Inject(token: any): PropertyDecorator & ParameterDecorator;
22
+ /**
23
+ * Decorator: Applies middleware OR injects dependencies.
24
+ * - Class/Method: Middleware
25
+ * - Property/Parameter: Dependency Injection
26
+ */
27
+ export declare function Use(tokenOrMiddleware?: any | Middleware, ...moreMiddleware: Middleware[]): (target: any, propertyKey?: string, indexOrDescriptor?: PropertyDescriptor | number) => void;
11
28
  /**
12
29
  * Decorator: Binds a parameter to the request body.
13
30
  */
@@ -76,4 +93,4 @@ export declare function Event(eventName: string): (target: any, propertyKey: str
76
93
  /**
77
94
  * Decorator: Applies a rate limit to a class or method.
78
95
  */
79
- export declare function RateLimit(options: RateLimitOptions): (target: any, propertyKey?: string, descriptor?: PropertyDescriptor) => void;
96
+ export declare function RateLimit(options: RateLimitOptions): (target: any, propertyKey?: string, indexOrDescriptor?: PropertyDescriptor | number) => void;
package/dist/util/di.d.ts CHANGED
@@ -6,13 +6,8 @@ export declare class Container {
6
6
  static register<T>(target: new (...args: any[]) => T, instance: T): void;
7
7
  static get<T>(target: new (...args: any[]) => T): T | undefined;
8
8
  static has(target: any): boolean;
9
+ private static cache;
10
+ private static resolvingStack;
9
11
  static resolve<T>(target: new (...args: any[]) => T): T;
12
+ static teardown(): Promise<void>;
10
13
  }
11
- /**
12
- * Decorator to mark a class as injectable (Service).
13
- */
14
- export declare function Injectable(): (target: any) => void;
15
- /**
16
- * Property Decorator: Injects a service.
17
- */
18
- export declare function Inject(token: any): (target: any, key: string) => void;
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Lightweight Polyfill for Reflect Metadata API.
3
+ *
4
+ * Replaces the need for 'reflect-metadata' package to reduce bundle size
5
+ * while maintaining compatibility with TypeScript's emitDecoratorMetadata.
6
+ */
7
+ export declare function defineMetadata(key: string | symbol, value: any, target: any, propertyKey?: string | symbol): void;
8
+ export declare function getMetadata(key: string | symbol, target: any, propertyKey?: string | symbol): any;
9
+ declare global {
10
+ namespace Reflect {
11
+ function defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey?: string | symbol): void;
12
+ function getMetadata(metadataKey: any, target: Object, propertyKey?: string | symbol): any;
13
+ function metadata(metadataKey: any, metadataValue: any): {
14
+ (target: Function): void;
15
+ (target: Object, propertyKey: string | symbol): void;
16
+ };
17
+ }
18
+ }
@@ -0,0 +1,10 @@
1
+ import { Middleware, ShokupanHandler } from '../util/types';
2
+ export declare class MiddlewareTracker {
3
+ static wrap(handler: Middleware | ShokupanHandler<any>, context: {
4
+ file: string;
5
+ line: number;
6
+ name?: string;
7
+ isBuiltin?: boolean;
8
+ pluginName?: string;
9
+ }): any;
10
+ }
@@ -18,6 +18,7 @@ declare class ShokupanRequestBase {
18
18
  text(): Promise<string>;
19
19
  formData(): Promise<FormData>;
20
20
  constructor(props: ShokupanRequestProps);
21
+ clone(): ShokupanRequest<any>;
21
22
  }
22
23
  /**
23
24
  * This type is used to add properties to the request object.
@@ -29,6 +29,7 @@ export declare const $cachedProtocol: unique symbol;
29
29
  export declare const $cachedHost: unique symbol;
30
30
  export declare const $cachedOrigin: unique symbol;
31
31
  export declare const $cachedQuery: unique symbol;
32
+ export declare const $cachedCookies: unique symbol;
32
33
  export declare const $ws: unique symbol;
33
34
  export declare const $socket: unique symbol;
34
35
  export declare const $io: unique symbol;