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.
- package/README.md +46 -1815
- package/dist/{analyzer-BqIe1p0R.js → analyzer-BkNQHWj4.js} +3 -8
- package/dist/{analyzer-BqIe1p0R.js.map → analyzer-BkNQHWj4.js.map} +1 -1
- package/dist/{analyzer-CKLGLFtx.cjs → analyzer-DM-OlRq8.cjs} +2 -7
- package/dist/{analyzer-CKLGLFtx.cjs.map → analyzer-DM-OlRq8.cjs.map} +1 -1
- package/dist/{analyzer.impl-D9Yi1Hax.cjs → analyzer.impl-CVJ8zfGQ.cjs} +596 -42
- package/dist/analyzer.impl-CVJ8zfGQ.cjs.map +1 -0
- package/dist/{analyzer.impl-CV6W1Eq7.js → analyzer.impl-CsA1bS_s.js} +596 -42
- package/dist/analyzer.impl-CsA1bS_s.js.map +1 -0
- package/dist/cli.cjs +206 -18
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +206 -18
- package/dist/cli.js.map +1 -1
- package/dist/context.d.ts +46 -9
- package/dist/index.cjs +3239 -1173
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3236 -1171
- package/dist/index.js.map +1 -1
- package/dist/plugins/application/api-explorer/static/explorer-client.mjs +375 -29
- package/dist/plugins/application/api-explorer/static/style.css +327 -8
- package/dist/plugins/application/api-explorer/static/theme.css +11 -2
- package/dist/plugins/application/asyncapi/generator.d.ts +4 -0
- package/dist/plugins/application/asyncapi/static/asyncapi-client.mjs +154 -22
- package/dist/plugins/application/asyncapi/static/style.css +24 -8
- package/dist/plugins/application/auth.d.ts +5 -0
- package/dist/plugins/application/dashboard/fetch-interceptor.d.ts +119 -0
- package/dist/plugins/application/dashboard/metrics-collector.d.ts +38 -2
- package/dist/plugins/application/dashboard/plugin.d.ts +53 -1
- package/dist/plugins/application/dashboard/static/charts.js +127 -62
- package/dist/plugins/application/dashboard/static/client.js +160 -0
- package/dist/plugins/application/dashboard/static/graph.mjs +167 -56
- package/dist/plugins/application/dashboard/static/reactflow.css +20 -10
- package/dist/plugins/application/dashboard/static/registry.js +112 -8
- package/dist/plugins/application/dashboard/static/requests.js +1167 -71
- package/dist/plugins/application/dashboard/static/styles.css +186 -14
- package/dist/plugins/application/dashboard/static/tabs.js +44 -9
- package/dist/plugins/application/dashboard/static/tabulator.css +23 -3
- package/dist/plugins/application/dashboard/static/theme.css +11 -2
- package/dist/plugins/application/mcp-server/plugin.d.ts +39 -0
- package/dist/plugins/application/openapi/analyzer.impl.d.ts +65 -1
- package/dist/plugins/application/openapi/openapi.d.ts +3 -0
- package/dist/plugins/application/shared/ast-utils.d.ts +7 -0
- package/dist/plugins/middleware/compression.d.ts +12 -2
- package/dist/plugins/middleware/rate-limit.d.ts +5 -0
- package/dist/router.d.ts +59 -19
- package/dist/server.d.ts +22 -0
- package/dist/shokupan.d.ts +31 -3
- package/dist/util/adapter/bun.d.ts +8 -0
- package/dist/util/adapter/filesystem.d.ts +20 -0
- package/dist/util/adapter/index.d.ts +4 -0
- package/dist/util/adapter/interface.d.ts +12 -0
- package/dist/util/adapter/node.d.ts +8 -0
- package/dist/util/adapter/wintercg.d.ts +5 -0
- package/dist/util/body-parser.d.ts +30 -0
- package/dist/util/controller-scanner.d.ts +4 -0
- package/dist/util/cpu-monitor.d.ts +2 -0
- package/dist/util/decorators.d.ts +20 -3
- package/dist/util/di.d.ts +3 -8
- package/dist/util/metadata.d.ts +18 -0
- package/dist/util/middleware-tracker.d.ts +10 -0
- package/dist/util/request.d.ts +1 -0
- package/dist/util/symbol.d.ts +1 -0
- package/dist/util/types.d.ts +167 -1
- package/package.json +7 -5
- package/dist/analyzer.impl-CV6W1Eq7.js.map +0 -1
- package/dist/analyzer.impl-D9Yi1Hax.cjs.map +0 -1
- package/dist/http-server-BEMPIs33.cjs +0 -85
- package/dist/http-server-BEMPIs33.cjs.map +0 -1
- package/dist/http-server-CCeagTyU.js +0 -68
- package/dist/http-server-CCeagTyU.js.map +0 -1
- package/dist/plugins/application/dashboard/static/failures.js +0 -85
- package/dist/plugins/application/dashboard/static/poll.js +0 -146
- 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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/dist/server.d.ts
ADDED
|
@@ -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
|
+
}
|
package/dist/shokupan.d.ts
CHANGED
|
@@ -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
|
-
|
|
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,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,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
|
+
}
|
|
@@ -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
|
-
*
|
|
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
|
|
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,
|
|
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
|
+
}
|
package/dist/util/request.d.ts
CHANGED
package/dist/util/symbol.d.ts
CHANGED
|
@@ -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;
|