@stacksjs/bun-router 0.1.17 → 0.1.20
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 +17 -0
- package/dist/chunk-mpyfk9k4.js +357 -0
- package/dist/chunk-q4ktdehf.js +82 -0
- package/dist/chunk-sr7yt36v.js +102 -0
- package/dist/cli.js +8 -8
- package/dist/container/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -103
- package/dist/response/markers.d.ts +2 -0
- package/dist/response/response-factory.d.ts +0 -3
- package/dist/router/index.d.ts +1 -105
- package/dist/router/middleware-chain.d.ts +10 -0
- package/dist/router/router.d.ts +1 -1
- package/dist/router/runtime.d.ts +107 -0
- package/dist/runtime.d.ts +16 -0
- package/dist/runtime.js +2 -0
- package/package.json +11 -1
- package/dist/chunk-7s1kcj7w.js +0 -357
- package/dist/chunk-sccx6r6k.js +0 -82
|
@@ -70,9 +70,6 @@ export interface ResponseFactory {
|
|
|
70
70
|
serverError: (message?: string) => Response;
|
|
71
71
|
tooManyRequests: (message?: string, retryAfter?: number) => Response;
|
|
72
72
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Response factory with common response helpers
|
|
75
|
-
*/
|
|
76
73
|
export declare const response: ResponseFactory;
|
|
77
74
|
/**
|
|
78
75
|
* Fluent response builder
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,112 +1,8 @@
|
|
|
1
|
-
import type { ActionHandler, Route } from '../types';
|
|
2
1
|
import { Dependencies, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, SkipConditions } from '../middleware/pipeline';
|
|
3
2
|
import { FluentRouteBuilder, FluentRouter, RouteFactory, router, RouterUtils } from './fluent-routing';
|
|
4
|
-
import { Router } from './
|
|
5
|
-
import '../types';
|
|
3
|
+
import { Router } from './runtime';
|
|
6
4
|
export { Router };
|
|
7
5
|
export { applyRequestEnhancements } from './router';
|
|
8
|
-
declare module './router' {
|
|
9
|
-
interface Router {
|
|
10
|
-
stream: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, status?: number, headers?: Record<string, string>) => Response;
|
|
11
|
-
streamJson: <T>(data: Record<string, Iterable<T> | AsyncIterable<T>>, status?: number, headers?: Record<string, string>) => Response;
|
|
12
|
-
eventStream: <_T = any>(callback: () => Generator<{
|
|
13
|
-
data: any;
|
|
14
|
-
event?: string;
|
|
15
|
-
id?: string;
|
|
16
|
-
retry?: number;
|
|
17
|
-
}, void, unknown> | AsyncGenerator<{
|
|
18
|
-
data: any;
|
|
19
|
-
event?: string;
|
|
20
|
-
id?: string;
|
|
21
|
-
retry?: number;
|
|
22
|
-
}, void, unknown>, headers?: Record<string, string>) => Response;
|
|
23
|
-
streamDownload: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, filename: string, headers?: Record<string, string>) => Response;
|
|
24
|
-
streamFile: (filePath: string, request: any, options?: {
|
|
25
|
-
contentType?: string;
|
|
26
|
-
enableRanges?: boolean;
|
|
27
|
-
chunkSize?: number;
|
|
28
|
-
}) => Promise<Response>;
|
|
29
|
-
streamFileWithRanges: (filePath: string, req: any) => Promise<Response>;
|
|
30
|
-
streamResponse: (generator: () => AsyncGenerator<string | Uint8Array, void, unknown>, options?: {
|
|
31
|
-
headers?: Record<string, string>;
|
|
32
|
-
status?: number;
|
|
33
|
-
}) => Response;
|
|
34
|
-
transformStream: (transformer: (chunk: string | Uint8Array) => string | Uint8Array | Promise<string | Uint8Array>, options?: {
|
|
35
|
-
headers?: Record<string, string>;
|
|
36
|
-
status?: number;
|
|
37
|
-
}) => (req: Request) => Response;
|
|
38
|
-
model: <T>(key: string, modelClass: string | ((_value: string) => Promise<T | null>), callback?: (model: T | null) => Response | null) => Router;
|
|
39
|
-
implicitBinding: () => any;
|
|
40
|
-
missing: (callback: (req: any) => Response) => any;
|
|
41
|
-
scopedBindings: (bindings: Record<string, string>) => any;
|
|
42
|
-
clearModelCache: (modelName?: string) => Router;
|
|
43
|
-
getModelStats: () => {
|
|
44
|
-
totalEntries: number;
|
|
45
|
-
validEntries: number;
|
|
46
|
-
expiredEntries: number;
|
|
47
|
-
models: number;
|
|
48
|
-
};
|
|
49
|
-
readonly modelRegistry: {
|
|
50
|
-
has: (name: string) => boolean;
|
|
51
|
-
register: <_T>(name: string, config: any) => void;
|
|
52
|
-
resolve: <_T>(modelName: string, params: Record<string, string>, req?: any) => Promise<any>;
|
|
53
|
-
createErrorResponse: (modelName: string, result: any, params: Record<string, string>) => Response;
|
|
54
|
-
clearCache: (modelName: string, params?: Record<string, string>) => void;
|
|
55
|
-
clearAllCache: () => void;
|
|
56
|
-
getCacheStats: () => any;
|
|
57
|
-
};
|
|
58
|
-
matchRoute(path: string, method: string, domain?: string): {
|
|
59
|
-
route: Route;
|
|
60
|
-
params: Record<string, string>;
|
|
61
|
-
} | undefined;
|
|
62
|
-
getAllowedMethods(path: string, domain?: string): string[];
|
|
63
|
-
clearRouteCache: () => void;
|
|
64
|
-
getCacheStats: () => any;
|
|
65
|
-
getRouteStats: () => any;
|
|
66
|
-
warmRouteCache: (commonPaths: Array<{
|
|
67
|
-
path: string;
|
|
68
|
-
method: string;
|
|
69
|
-
}>) => void;
|
|
70
|
-
getRoutesByMethod: () => any;
|
|
71
|
-
getRouteConflicts: () => any;
|
|
72
|
-
rebuildRouteCompiler: () => void;
|
|
73
|
-
optimizeRoutes: (usageStats?: Record<string, number>) => void;
|
|
74
|
-
addRouteToCompiler: (route: Route) => void;
|
|
75
|
-
initializeRouteCompiler: () => void;
|
|
76
|
-
health: () => Router;
|
|
77
|
-
renderView: (view: string, data?: Record<string, any>, options?: {
|
|
78
|
-
layout?: string;
|
|
79
|
-
}) => Promise<string>;
|
|
80
|
-
view: (path: string, view: string, data?: Record<string, any>, options?: {
|
|
81
|
-
layout?: string;
|
|
82
|
-
status?: number;
|
|
83
|
-
headers?: Record<string, string>;
|
|
84
|
-
}) => Router;
|
|
85
|
-
withoutNativeDispatch: () => Router;
|
|
86
|
-
where: ((_param: string, _pattern: string | RegExp) => Router) & ((constraints: Record<string, string | RegExp>) => Router);
|
|
87
|
-
whereNumber: (param: string) => Router;
|
|
88
|
-
whereAlpha: (param: string) => Router;
|
|
89
|
-
whereAlphaNumeric: (param: string) => Router;
|
|
90
|
-
whereUuid: (param: string) => Router;
|
|
91
|
-
whereIn: (param: string, values: string[]) => Router;
|
|
92
|
-
domain: (domain: string, callback: () => void) => Router;
|
|
93
|
-
resource: (name: string, handlers: {
|
|
94
|
-
index?: ActionHandler;
|
|
95
|
-
show?: ActionHandler;
|
|
96
|
-
store?: ActionHandler;
|
|
97
|
-
update?: ActionHandler;
|
|
98
|
-
destroy?: ActionHandler;
|
|
99
|
-
create?: ActionHandler;
|
|
100
|
-
edit?: ActionHandler;
|
|
101
|
-
}) => Router;
|
|
102
|
-
head: (path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: any[]) => Router;
|
|
103
|
-
onError(handler: (error: Error) => Response | Promise<Response>): Router;
|
|
104
|
-
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
105
|
-
permanentRedirect(url: string): Response;
|
|
106
|
-
fallback(handler: ActionHandler): Router;
|
|
107
|
-
route(name: string, params?: Record<string, string>): string;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
6
|
export { Dependencies, FluentRouteBuilder, FluentRouter, globalMiddlewarePipeline, MiddlewareFactory, MiddlewarePipeline, RouteFactory, router, RouterUtils, SkipConditions };
|
|
111
7
|
export * from '../routing/route-caching';
|
|
112
8
|
export * from '../routing/route-throttling';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { EnhancedRequest, MiddlewareHandler } from '../types';
|
|
2
|
+
export type CompiledMiddlewareChain = (request: EnhancedRequest) => Response | null | Promise<Response | null>;
|
|
3
|
+
export type PublicMiddlewareChain = (request: EnhancedRequest) => Promise<Response | null>;
|
|
4
|
+
interface MiddlewareChainHost {
|
|
5
|
+
buildMiddlewareChain: (middlewares: MiddlewareHandler[]) => PublicMiddlewareChain;
|
|
6
|
+
}
|
|
7
|
+
export declare function compileMiddlewareChain(middlewares: MiddlewareHandler[]): CompiledMiddlewareChain;
|
|
8
|
+
export declare function buildMiddlewareChain(middlewares: MiddlewareHandler[]): PublicMiddlewareChain;
|
|
9
|
+
export declare function resolveMiddlewareChain(host: MiddlewareChainHost, middlewares: MiddlewareHandler[]): CompiledMiddlewareChain;
|
|
10
|
+
export {};
|
package/dist/router/router.d.ts
CHANGED
|
@@ -39,7 +39,7 @@ export declare class Router {
|
|
|
39
39
|
params: Record<string, string>;
|
|
40
40
|
}>;
|
|
41
41
|
staticRoutes: Map<string, Map<string, Route>>;
|
|
42
|
-
staticResponses: Map<string, Response
|
|
42
|
+
staticResponses: Map<string, Map<string, Response>>;
|
|
43
43
|
precompiledPatterns: Map<string, RegExp>;
|
|
44
44
|
domainPatternCache: Map<string, RegExp>;
|
|
45
45
|
routeCompiler: RouteCompiler | null;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ActionHandler, Route } from '../types';
|
|
2
|
+
import { Router } from './router';
|
|
3
|
+
import '../types';
|
|
4
|
+
export { Router };
|
|
5
|
+
export { applyRequestEnhancements } from './router';
|
|
6
|
+
declare module './router' {
|
|
7
|
+
interface Router {
|
|
8
|
+
stream: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, status?: number, headers?: Record<string, string>) => Response;
|
|
9
|
+
streamJson: <T>(data: Record<string, Iterable<T> | AsyncIterable<T>>, status?: number, headers?: Record<string, string>) => Response;
|
|
10
|
+
eventStream: <_T = any>(callback: () => Generator<{
|
|
11
|
+
data: any;
|
|
12
|
+
event?: string;
|
|
13
|
+
id?: string;
|
|
14
|
+
retry?: number;
|
|
15
|
+
}, void, unknown> | AsyncGenerator<{
|
|
16
|
+
data: any;
|
|
17
|
+
event?: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
retry?: number;
|
|
20
|
+
}, void, unknown>, headers?: Record<string, string>) => Response;
|
|
21
|
+
streamDownload: (callback: () => Generator<string | Uint8Array, void, unknown> | AsyncGenerator<string | Uint8Array, void, unknown>, filename: string, headers?: Record<string, string>) => Response;
|
|
22
|
+
streamFile: (filePath: string, request: any, options?: {
|
|
23
|
+
contentType?: string;
|
|
24
|
+
enableRanges?: boolean;
|
|
25
|
+
chunkSize?: number;
|
|
26
|
+
}) => Promise<Response>;
|
|
27
|
+
streamFileWithRanges: (filePath: string, req: any) => Promise<Response>;
|
|
28
|
+
streamResponse: (generator: () => AsyncGenerator<string | Uint8Array, void, unknown>, options?: {
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
status?: number;
|
|
31
|
+
}) => Response;
|
|
32
|
+
transformStream: (transformer: (chunk: string | Uint8Array) => string | Uint8Array | Promise<string | Uint8Array>, options?: {
|
|
33
|
+
headers?: Record<string, string>;
|
|
34
|
+
status?: number;
|
|
35
|
+
}) => (req: Request) => Response;
|
|
36
|
+
model: <T>(key: string, modelClass: string | ((_value: string) => Promise<T | null>), callback?: (model: T | null) => Response | null) => Router;
|
|
37
|
+
implicitBinding: () => any;
|
|
38
|
+
missing: (callback: (req: any) => Response) => any;
|
|
39
|
+
scopedBindings: (bindings: Record<string, string>) => any;
|
|
40
|
+
clearModelCache: (modelName?: string) => Router;
|
|
41
|
+
getModelStats: () => {
|
|
42
|
+
totalEntries: number;
|
|
43
|
+
validEntries: number;
|
|
44
|
+
expiredEntries: number;
|
|
45
|
+
models: number;
|
|
46
|
+
};
|
|
47
|
+
readonly modelRegistry: {
|
|
48
|
+
has: (name: string) => boolean;
|
|
49
|
+
register: <_T>(name: string, config: any) => void;
|
|
50
|
+
resolve: <_T>(modelName: string, params: Record<string, string>, req?: any) => Promise<any>;
|
|
51
|
+
createErrorResponse: (modelName: string, result: any, params: Record<string, string>) => Response;
|
|
52
|
+
clearCache: (modelName: string, params?: Record<string, string>) => void;
|
|
53
|
+
clearAllCache: () => void;
|
|
54
|
+
getCacheStats: () => any;
|
|
55
|
+
};
|
|
56
|
+
matchRoute(path: string, method: string, domain?: string): {
|
|
57
|
+
route: Route;
|
|
58
|
+
params: Record<string, string>;
|
|
59
|
+
} | undefined;
|
|
60
|
+
getAllowedMethods(path: string, domain?: string): string[];
|
|
61
|
+
clearRouteCache: () => void;
|
|
62
|
+
getCacheStats: () => any;
|
|
63
|
+
getRouteStats: () => any;
|
|
64
|
+
warmRouteCache: (commonPaths: Array<{
|
|
65
|
+
path: string;
|
|
66
|
+
method: string;
|
|
67
|
+
}>) => void;
|
|
68
|
+
getRoutesByMethod: () => any;
|
|
69
|
+
getRouteConflicts: () => any;
|
|
70
|
+
rebuildRouteCompiler: () => void;
|
|
71
|
+
optimizeRoutes: (usageStats?: Record<string, number>) => void;
|
|
72
|
+
addRouteToCompiler: (route: Route) => void;
|
|
73
|
+
initializeRouteCompiler: () => void;
|
|
74
|
+
health: () => Router;
|
|
75
|
+
renderView: (view: string, data?: Record<string, any>, options?: {
|
|
76
|
+
layout?: string;
|
|
77
|
+
}) => Promise<string>;
|
|
78
|
+
view: (path: string, view: string, data?: Record<string, any>, options?: {
|
|
79
|
+
layout?: string;
|
|
80
|
+
status?: number;
|
|
81
|
+
headers?: Record<string, string>;
|
|
82
|
+
}) => Router;
|
|
83
|
+
withoutNativeDispatch: () => Router;
|
|
84
|
+
where: ((_param: string, _pattern: string | RegExp) => Router) & ((constraints: Record<string, string | RegExp>) => Router);
|
|
85
|
+
whereNumber: (param: string) => Router;
|
|
86
|
+
whereAlpha: (param: string) => Router;
|
|
87
|
+
whereAlphaNumeric: (param: string) => Router;
|
|
88
|
+
whereUuid: (param: string) => Router;
|
|
89
|
+
whereIn: (param: string, values: string[]) => Router;
|
|
90
|
+
domain: (domain: string, callback: () => void) => Router;
|
|
91
|
+
resource: (name: string, handlers: {
|
|
92
|
+
index?: ActionHandler;
|
|
93
|
+
show?: ActionHandler;
|
|
94
|
+
store?: ActionHandler;
|
|
95
|
+
update?: ActionHandler;
|
|
96
|
+
destroy?: ActionHandler;
|
|
97
|
+
create?: ActionHandler;
|
|
98
|
+
edit?: ActionHandler;
|
|
99
|
+
}) => Router;
|
|
100
|
+
head: (path: string, handler: ActionHandler, type?: 'api' | 'web', name?: string, middleware?: any[]) => Router;
|
|
101
|
+
onError(handler: (error: Error) => Response | Promise<Response>): Router;
|
|
102
|
+
redirect(url: string, status?: 301 | 302 | 303 | 307 | 308): Response;
|
|
103
|
+
permanentRedirect(url: string): Response;
|
|
104
|
+
fallback(handler: ActionHandler): Router;
|
|
105
|
+
route(name: string, params?: Record<string, string>): string;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime-only router surface for frameworks and API servers.
|
|
3
|
+
*
|
|
4
|
+
* The root entry intentionally exposes every bun-router subsystem. Consumers
|
|
5
|
+
* that only need to register and serve routes can import this entry without
|
|
6
|
+
* loading auth, containers, sessions, or testing utilities.
|
|
7
|
+
*/
|
|
8
|
+
export { applyRequestEnhancements, Router } from './router/runtime';
|
|
9
|
+
export { enableRequestContext, getCurrentRequest, request, runWithRequest, runWithRequestArguments, setCurrentRequest, } from './request/context';
|
|
10
|
+
export { applyResponseCompression, DEFAULT_COMPRESSION, } from './response/compression';
|
|
11
|
+
export { response, ResponseBuilder, responseBuilder, } from './response/response-factory';
|
|
12
|
+
export { ENRICHED_NOT_FOUND_RESPONSE } from './response/markers';
|
|
13
|
+
export { createTypedRouter } from './typed/router';
|
|
14
|
+
export type { ActionHandler, ActionPath, EnhancedRequest, ExtractRouteParams, KnownRouteName, MiddlewareHandler, MiddlewareReference, PathForRouteName, RequestFor, Route, ServerOptions, } from './types';
|
|
15
|
+
export type { CompressionOptions } from './response/compression';
|
|
16
|
+
export type { TypedRouter } from './typed/router';
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{Re,B,j,T,Y,ve,Q,m,r,Z,Ke,ee,n,se,Ce}from"./chunk-sr7yt36v.js";export{Q as DEFAULT_COMPRESSION,ee as ENRICHED_NOT_FOUND_RESPONSE,Z as ResponseBuilder,n as Router,se as applyRequestEnhancements,m as applyResponseCompression,Ce as createTypedRouter,Re as enableRequestContext,Y as getCurrentRequest,ve as request,r as response,Ke as responseBuilder,B as runWithRequest,j as runWithRequestArguments,T as setCurrentRequest};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stacksjs/bun-router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.20",
|
|
5
5
|
"description": "A fast, type-safe router for Bun.",
|
|
6
6
|
"author": "Chris Breuer <chris@stacksjs.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,11 @@
|
|
|
28
28
|
"bun": "./dist/index.js",
|
|
29
29
|
"import": "./dist/index.js"
|
|
30
30
|
},
|
|
31
|
+
"./runtime": {
|
|
32
|
+
"types": "./dist/runtime.d.ts",
|
|
33
|
+
"bun": "./dist/runtime.js",
|
|
34
|
+
"import": "./dist/runtime.js"
|
|
35
|
+
},
|
|
31
36
|
"./container": {
|
|
32
37
|
"types": "./dist/container/index.d.ts",
|
|
33
38
|
"bun": "./dist/container/index.js",
|
|
@@ -45,6 +50,11 @@
|
|
|
45
50
|
"bun": "./dist/index.js",
|
|
46
51
|
"import": "./dist/index.js"
|
|
47
52
|
},
|
|
53
|
+
"./runtime": {
|
|
54
|
+
"types": "./dist/runtime.d.ts",
|
|
55
|
+
"bun": "./dist/runtime.js",
|
|
56
|
+
"import": "./dist/runtime.js"
|
|
57
|
+
},
|
|
48
58
|
"./container": {
|
|
49
59
|
"types": "./dist/container/index.d.ts",
|
|
50
60
|
"bun": "./dist/container/index.js",
|