@glass-cannon/router 0.10.7 → 0.11.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/dist/index.d.ts +4 -49
- package/dist/index.js +4 -144
- package/dist/index.js.map +1 -1
- package/dist/middleware/contentType.d.ts +5 -6
- package/dist/middleware/contentType.js +11 -11
- package/dist/middleware/contentType.js.map +1 -1
- package/dist/middleware/index.d.ts +8 -9
- package/dist/middleware/index.js +12 -18
- package/dist/middleware/index.js.map +1 -1
- package/dist/node.d.ts +14 -0
- package/dist/node.js +2 -0
- package/dist/node.js.map +1 -0
- package/dist/nodeBuilder.d.ts +25 -0
- package/dist/nodeBuilder.js +65 -0
- package/dist/nodeBuilder.js.map +1 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugin.js +2 -0
- package/dist/plugin.js.map +1 -0
- package/dist/router.d.ts +14 -0
- package/dist/router.js +153 -0
- package/dist/router.js.map +1 -0
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,49 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
export type RouteContext<Context = unknown> = Request & {
|
|
6
|
-
params: Record<string, string>;
|
|
7
|
-
route: Route;
|
|
8
|
-
} & Context;
|
|
9
|
-
export interface Route {
|
|
10
|
-
method?: string;
|
|
11
|
-
path: string;
|
|
12
|
-
handler: RouteHandler;
|
|
13
|
-
}
|
|
14
|
-
export interface RouterGroup<Context = unknown> {
|
|
15
|
-
route<NewContext>(options: RouteOptions<Context, NewContext>): Route;
|
|
16
|
-
group<NewContext>(options: GroupOptions<NewContext>): RouterGroup<Context & NewContext>;
|
|
17
|
-
}
|
|
18
|
-
export interface RouterOptions<Context = unknown> {
|
|
19
|
-
fallback?: Handler;
|
|
20
|
-
middleware?: Middleware<Context>;
|
|
21
|
-
}
|
|
22
|
-
export interface RouteOptions<Context = unknown, NewContext = unknown> {
|
|
23
|
-
method?: StringWithSuggestions<'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS'>;
|
|
24
|
-
path: string;
|
|
25
|
-
middleware?: Middleware<NewContext>;
|
|
26
|
-
handler: RouteHandler<Context & NewContext>;
|
|
27
|
-
}
|
|
28
|
-
export interface GroupOptions<Context = unknown> {
|
|
29
|
-
prefix?: string;
|
|
30
|
-
middleware?: Middleware<Context>;
|
|
31
|
-
}
|
|
32
|
-
export declare class Router<Context = unknown> implements RouterGroup<Context> {
|
|
33
|
-
private readonly fallback;
|
|
34
|
-
private readonly middleware;
|
|
35
|
-
private routes;
|
|
36
|
-
constructor(options?: RouterOptions<Context>);
|
|
37
|
-
matchingRoute(method: string, path: string): Route | undefined;
|
|
38
|
-
handle: Handler;
|
|
39
|
-
route<NewContext>(route: RouteOptions<Context, NewContext>): Route;
|
|
40
|
-
group<NewContext>(options: GroupOptions<NewContext>): RouterGroup<Context & NewContext>;
|
|
41
|
-
private matchingRouteWithMetadata;
|
|
42
|
-
private matchingGeneralRouteWithMetadata;
|
|
43
|
-
private computeMetadata;
|
|
44
|
-
private computeScore;
|
|
45
|
-
private pathToRegex;
|
|
46
|
-
private pathToCapturingRegex;
|
|
47
|
-
private compileRegex;
|
|
48
|
-
}
|
|
49
|
-
export {};
|
|
1
|
+
export * from './router.js';
|
|
2
|
+
export * from './node.js';
|
|
3
|
+
export * from './nodeBuilder.js';
|
|
4
|
+
export * from './plugin.js';
|
package/dist/index.js
CHANGED
|
@@ -1,145 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
middleware;
|
|
6
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
7
|
-
routes = Object.create(null);
|
|
8
|
-
constructor(options) {
|
|
9
|
-
this.fallback = options?.fallback ?? (() => ({ status: 404 }));
|
|
10
|
-
this.middleware = options?.middleware ?? noop;
|
|
11
|
-
}
|
|
12
|
-
matchingRoute(method, path) {
|
|
13
|
-
return this.matchingRouteWithMetadata(method, path)?.route;
|
|
14
|
-
}
|
|
15
|
-
handle = async (request) => {
|
|
16
|
-
const path = request.url.pathname;
|
|
17
|
-
const routeWithMetadata = this.matchingRouteWithMetadata(request.method, path);
|
|
18
|
-
if (!routeWithMetadata)
|
|
19
|
-
return await this.fallback(request);
|
|
20
|
-
const { route, capturingRegex } = routeWithMetadata;
|
|
21
|
-
const params = { ...capturingRegex.exec(path).groups };
|
|
22
|
-
const context = { ...request, params, route };
|
|
23
|
-
return await route.handler(context);
|
|
24
|
-
};
|
|
25
|
-
route(route) {
|
|
26
|
-
const handler = route.middleware
|
|
27
|
-
? applyMiddleware(this.middleware, applyMiddleware(route.middleware, route.handler))
|
|
28
|
-
: applyMiddleware(this.middleware, route.handler);
|
|
29
|
-
const path = route.path.endsWith('/') ? route.path.slice(0, -1) : route.path;
|
|
30
|
-
const metadata = this.computeMetadata({ method: route.method, path, handler });
|
|
31
|
-
const method = route.method?.toUpperCase() ?? ALL_METHODS;
|
|
32
|
-
this.routes[method] ??= [[], undefined];
|
|
33
|
-
binaryInsert(this.routes[method][0], metadata, (route) => route.score);
|
|
34
|
-
this.routes[method][1] = undefined;
|
|
35
|
-
return metadata.route;
|
|
36
|
-
}
|
|
37
|
-
group(options) {
|
|
38
|
-
const prefix = options.prefix?.endsWith('/')
|
|
39
|
-
? options.prefix.slice(0, -1)
|
|
40
|
-
: (options.prefix ?? '');
|
|
41
|
-
return {
|
|
42
|
-
route: (route) => {
|
|
43
|
-
const path = `${prefix}${route.path}`;
|
|
44
|
-
const middlewares = [];
|
|
45
|
-
if (options.middleware)
|
|
46
|
-
middlewares.push(options.middleware);
|
|
47
|
-
if (route.middleware)
|
|
48
|
-
middlewares.push(route.middleware);
|
|
49
|
-
const middleware = pipe(...middlewares);
|
|
50
|
-
return this.route({ ...route, path, middleware });
|
|
51
|
-
},
|
|
52
|
-
group: (group) => {
|
|
53
|
-
const newPrefix = `${prefix}${group.prefix}`;
|
|
54
|
-
const middlewares = [];
|
|
55
|
-
if (options.middleware)
|
|
56
|
-
middlewares.push(options.middleware);
|
|
57
|
-
if (group.middleware)
|
|
58
|
-
middlewares.push(group.middleware);
|
|
59
|
-
const middleware = pipe(...middlewares);
|
|
60
|
-
return this.group({ prefix: newPrefix, middleware });
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
matchingRouteWithMetadata(method, path) {
|
|
65
|
-
const routes = this.routes[method];
|
|
66
|
-
if (!routes)
|
|
67
|
-
return this.matchingGeneralRouteWithMetadata(path);
|
|
68
|
-
routes[1] ??= this.compileRegex(method);
|
|
69
|
-
const match = routes[1].exec(path);
|
|
70
|
-
if (!match)
|
|
71
|
-
return this.matchingGeneralRouteWithMetadata(path);
|
|
72
|
-
const matchIndex = match.findLastIndex(Boolean) - 1;
|
|
73
|
-
return routes[0][matchIndex];
|
|
74
|
-
}
|
|
75
|
-
matchingGeneralRouteWithMetadata(path) {
|
|
76
|
-
const routes = this.routes[ALL_METHODS];
|
|
77
|
-
if (!routes)
|
|
78
|
-
return;
|
|
79
|
-
routes[1] ??= this.compileRegex(ALL_METHODS);
|
|
80
|
-
const match = routes[1].exec(path);
|
|
81
|
-
if (!match)
|
|
82
|
-
return;
|
|
83
|
-
const matchIndex = match.findLastIndex(Boolean) - 1;
|
|
84
|
-
return routes[0][matchIndex];
|
|
85
|
-
}
|
|
86
|
-
computeMetadata(route) {
|
|
87
|
-
const score = this.computeScore(route.path);
|
|
88
|
-
const regex = this.pathToRegex(route.path);
|
|
89
|
-
const capturingRegex = new RegExp(this.pathToCapturingRegex(route.path));
|
|
90
|
-
return { route, regex, score, capturingRegex };
|
|
91
|
-
}
|
|
92
|
-
computeScore(path) {
|
|
93
|
-
let score = 0;
|
|
94
|
-
for (const c of path) {
|
|
95
|
-
if (c === '/') {
|
|
96
|
-
score += 2;
|
|
97
|
-
}
|
|
98
|
-
else if (c === ':') {
|
|
99
|
-
score -= 1;
|
|
100
|
-
}
|
|
101
|
-
else if (c === '*') {
|
|
102
|
-
score -= 2;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
return score;
|
|
106
|
-
}
|
|
107
|
-
pathToRegex(path) {
|
|
108
|
-
return ('^(' +
|
|
109
|
-
path
|
|
110
|
-
.replace(/([.+?^=!:${}()[\]|/\\])/g, '\\$1')
|
|
111
|
-
.replace(/\\:([a-zA-Z0-9_]+)\*/g, '(?:.*)')
|
|
112
|
-
.replace(/\\\*/g, '(?:.*)')
|
|
113
|
-
.replace(/\\:([a-zA-Z0-9_]+)/g, '(?:[^/]+)') +
|
|
114
|
-
'/?)$');
|
|
115
|
-
}
|
|
116
|
-
pathToCapturingRegex(path) {
|
|
117
|
-
return ('^' +
|
|
118
|
-
path
|
|
119
|
-
.replace(/([.+?^=!:${}()[\]|/\\])/g, '\\$1')
|
|
120
|
-
.replace(/\\:([a-zA-Z0-9_]+)\*/g, '(?<$1>.*)')
|
|
121
|
-
.replace(/\\\*/g, '(?:.*)')
|
|
122
|
-
.replace(/\\:([a-zA-Z0-9_]+)/g, '(?<$1>[^/]+)') +
|
|
123
|
-
'/?$');
|
|
124
|
-
}
|
|
125
|
-
compileRegex(method) {
|
|
126
|
-
const regex = this.routes[method][0].map((route) => route.regex).join('|');
|
|
127
|
-
return new RegExp(regex);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
function binaryInsert(array, value, score) {
|
|
131
|
-
let low = 0;
|
|
132
|
-
let high = array.length;
|
|
133
|
-
while (low < high) {
|
|
134
|
-
const mid = Math.floor((low + high) / 2);
|
|
135
|
-
if (score(value) < score(array[mid])) {
|
|
136
|
-
low = mid + 1;
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
high = mid;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
array.splice(low, 0, value);
|
|
143
|
-
return low;
|
|
144
|
-
}
|
|
1
|
+
export * from './router.js';
|
|
2
|
+
export * from './node.js';
|
|
3
|
+
export * from './nodeBuilder.js';
|
|
4
|
+
export * from './plugin.js';
|
|
145
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,eAAe,CAAC;AAC9B,cAAc,UAAU,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { Middleware } from './index.js';
|
|
1
|
+
import { type MiddlewareWrapper } from './index.js';
|
|
3
2
|
import type { RouteContext } from '../index.js';
|
|
4
3
|
export interface ContentTypeOptions {
|
|
5
4
|
allowNoContent?: boolean;
|
|
@@ -7,13 +6,13 @@ export interface ContentTypeOptions {
|
|
|
7
6
|
}
|
|
8
7
|
export declare function contentType<T>({ contentType, deserializeRequest, allowNoContent, onInvalidContentType, }: {
|
|
9
8
|
contentType: string;
|
|
10
|
-
deserializeRequest: (
|
|
11
|
-
} & ContentTypeOptions):
|
|
9
|
+
deserializeRequest: (request?: Request) => Promise<T> | T;
|
|
10
|
+
} & ContentTypeOptions): MiddlewareWrapper<{
|
|
12
11
|
body: T;
|
|
13
12
|
}>;
|
|
14
|
-
export declare function textBody(options?: ContentTypeOptions):
|
|
13
|
+
export declare function textBody(options?: ContentTypeOptions): MiddlewareWrapper<{
|
|
15
14
|
body: string;
|
|
16
15
|
}>;
|
|
17
|
-
export declare function jsonBody(options?: ContentTypeOptions):
|
|
16
|
+
export declare function jsonBody(options?: ContentTypeOptions): MiddlewareWrapper<{
|
|
18
17
|
body: unknown;
|
|
19
18
|
}>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export function contentType({ contentType, deserializeRequest, allowNoContent = true, onInvalidContentType = () => ({ status: 415 }), }) {
|
|
3
|
-
return async (next, context) => {
|
|
4
|
-
const contentTypeHeader = context.headers.get('Content-Type');
|
|
5
|
-
if (!contentTypeHeader) {
|
|
1
|
+
import { middleware } from './index.js';
|
|
2
|
+
export function contentType({ contentType, deserializeRequest, allowNoContent = true, onInvalidContentType = () => new Response(null, { status: 415 }), }) {
|
|
3
|
+
return middleware(async (next, context) => {
|
|
4
|
+
const contentTypeHeader = context.request.headers.get('Content-Type');
|
|
5
|
+
if (!contentTypeHeader || !context.request.body) {
|
|
6
6
|
if (allowNoContent) {
|
|
7
7
|
const body = await deserializeRequest();
|
|
8
|
-
return await next({ body });
|
|
8
|
+
return await next({ ...context, body });
|
|
9
9
|
}
|
|
10
10
|
else {
|
|
11
11
|
return await onInvalidContentType(context);
|
|
@@ -15,25 +15,25 @@ export function contentType({ contentType, deserializeRequest, allowNoContent =
|
|
|
15
15
|
return await onInvalidContentType(context);
|
|
16
16
|
let body;
|
|
17
17
|
try {
|
|
18
|
-
body = await deserializeRequest(context.
|
|
18
|
+
body = await deserializeRequest(context.request);
|
|
19
19
|
}
|
|
20
20
|
catch {
|
|
21
21
|
return await onInvalidContentType(context);
|
|
22
22
|
}
|
|
23
|
-
return await next({ body });
|
|
24
|
-
};
|
|
23
|
+
return await next({ ...context, body });
|
|
24
|
+
});
|
|
25
25
|
}
|
|
26
26
|
export function textBody(options) {
|
|
27
27
|
return contentType({
|
|
28
28
|
contentType: 'text/plain',
|
|
29
|
-
deserializeRequest: (
|
|
29
|
+
deserializeRequest: (request) => (request ? request.text() : ''),
|
|
30
30
|
...options,
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
export function jsonBody(options) {
|
|
34
34
|
return contentType({
|
|
35
35
|
contentType: 'application/json',
|
|
36
|
-
deserializeRequest: (
|
|
36
|
+
deserializeRequest: (request) => request?.json(),
|
|
37
37
|
...options,
|
|
38
38
|
});
|
|
39
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentType.js","sourceRoot":"","sources":["../../src/middleware/contentType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"contentType.js","sourceRoot":"","sources":["../../src/middleware/contentType.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA0B,MAAM,GAAG,CAAC;AAQvD,MAAM,UAAU,WAAW,CAAI,EAC7B,WAAW,EACX,kBAAkB,EAClB,cAAc,GAAG,IAAI,EACrB,oBAAoB,GAAG,GAAG,EAAE,CAAC,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAI5C;IACpB,OAAO,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QACxC,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACtE,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YAChD,IAAI,cAAc,EAAE,CAAC;gBACnB,MAAM,IAAI,GAAG,MAAM,kBAAkB,EAAE,CAAC;gBACxC,OAAO,MAAM,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;YAC1C,CAAC;iBAAM,CAAC;gBACN,OAAO,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;YAC7C,CAAC;QACH,CAAC;QAED,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,WAAW,CAAC;YAAE,OAAO,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC3F,IAAI,IAAO,CAAC;QACZ,IAAI,CAAC;YACH,IAAI,GAAG,MAAM,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACnD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAC7C,CAAC;QACD,OAAO,MAAM,IAAI,CAAC,EAAE,GAAG,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,OAA4B;IACnD,OAAO,WAAW,CAAC;QACjB,WAAW,EAAE,YAAY;QACzB,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,OAA4B;IACnD,OAAO,WAAW,CAAC;QACjB,WAAW,EAAE,kBAAkB;QAC/B,kBAAkB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,IAAI,EAAE;QAChD,GAAG,OAAO;KACX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { Response } from '@glass-cannon/server';
|
|
2
1
|
import type { RouteContext, RouteHandler } from '../index.js';
|
|
3
2
|
export * from './contentType.js';
|
|
4
|
-
export type
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare
|
|
3
|
+
export type MergeRequires<Provides, Requires, NextRequires> = Provides & Requires extends NextRequires ? Requires : Requires & Omit<NextRequires, keyof Provides>;
|
|
4
|
+
export type Middleware<Provides = unknown, Requires = unknown> = (next: RouteHandler<Provides & NoInfer<Requires>>, context: RouteContext & Requires) => Promise<Response> | Response;
|
|
5
|
+
export interface MiddlewareWrapper<Provides = unknown, Requires = unknown> extends Middleware<Provides, Requires> {
|
|
6
|
+
pipe<NextProvides, NextRequires = unknown>(other: Middleware<NextProvides, NextRequires>): MiddlewareWrapper<Provides & NextProvides, MergeRequires<Provides, Requires, NextRequires>>;
|
|
7
|
+
}
|
|
8
|
+
export declare function apply<Provides = unknown, Requires = unknown, HandlerRequires = Provides & Requires>(fn: Middleware<Provides, Requires>, handler: RouteHandler<HandlerRequires>): RouteHandler<MergeRequires<Provides, Requires, HandlerRequires>>;
|
|
9
|
+
export declare function pipe<Provides = unknown, Requires = unknown, NextProvides = unknown, NextRequires = unknown>(first: Middleware<Provides, Requires>, second: Middleware<NextProvides, NextRequires>): MiddlewareWrapper<Provides & NextProvides, MergeRequires<Provides, Requires, NextRequires>>;
|
|
10
|
+
export declare function middleware<Provides = unknown, Requires = unknown>(fn: Middleware<Provides, Requires> | MiddlewareWrapper<Provides, Requires>): MiddlewareWrapper<Provides, Requires>;
|
package/dist/middleware/index.js
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
export * from './contentType.js';
|
|
2
|
-
export function
|
|
3
|
-
return
|
|
2
|
+
export function apply(fn, handler) {
|
|
3
|
+
return (context) => fn(handler, context);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
6
|
-
return (next, context) =>
|
|
7
|
-
return middleware1((newContext1) => {
|
|
8
|
-
return middleware2((newContext2) => next({ ...newContext1, ...newContext2 }), {
|
|
9
|
-
...context,
|
|
10
|
-
...newContext1,
|
|
11
|
-
});
|
|
12
|
-
}, context);
|
|
13
|
-
};
|
|
5
|
+
export function pipe(first, second) {
|
|
6
|
+
return middleware((next, context) => first((nextContext) => second(next, nextContext), context));
|
|
14
7
|
}
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
return
|
|
18
|
-
|
|
8
|
+
export function middleware(fn) {
|
|
9
|
+
if ('pipe' in fn)
|
|
10
|
+
return fn;
|
|
11
|
+
return Object.assign(fn, {
|
|
12
|
+
pipe(other) {
|
|
13
|
+
return pipe(fn, other);
|
|
14
|
+
},
|
|
15
|
+
});
|
|
19
16
|
}
|
|
20
|
-
export const noop = (next) => {
|
|
21
|
-
return next({});
|
|
22
|
-
};
|
|
23
17
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAEA,cAAc,eAAe,CAAC;AAmB9B,MAAM,UAAU,KAAK,CAKnB,EAAkC,EAClC,OAAsC;IAEtC,OAAO,CAAC,OAAO,EAAE,EAAE,CACjB,EAAE,CACA,OAAuD,EACvD,OAA6C,CAC9C,CAAC;AACN,CAAC;AAED,MAAM,UAAU,IAAI,CAMlB,KAAqC,EACrC,MAA8C;IAE9C,OAAO,UAAU,CAAC,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,CAClC,KAAK,CACH,CAAC,WAAW,EAAE,EAAE,CACd,MAAM,CACJ,IAA4D,EAC5D,WAAqD,CACtD,EACH,OAA6C,CAC9C,CACF,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,UAAU,CACxB,EAA0E;IAE1E,IAAI,MAAM,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAC5B,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE;QACvB,IAAI,CACF,KAA6C;YAE7C,OAAO,IAAI,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACzB,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Middleware } from './middleware/index.js';
|
|
2
|
+
export interface RouteContext {
|
|
3
|
+
url: URL;
|
|
4
|
+
method: string;
|
|
5
|
+
params: Record<string, string>;
|
|
6
|
+
request: Request;
|
|
7
|
+
}
|
|
8
|
+
export type RouteHandler<Requires = unknown> = (context: RouteContext & Requires) => Promise<Response> | Response;
|
|
9
|
+
export interface RouteNode<Requires = unknown> {
|
|
10
|
+
children: Record<string, RouteNode>;
|
|
11
|
+
methods: Record<string, RouteHandler<Requires>>;
|
|
12
|
+
middleware?: Middleware<unknown, Requires>;
|
|
13
|
+
}
|
|
14
|
+
export declare const ALL_METHODS = "*";
|
package/dist/node.js
ADDED
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAmBA,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type MergeRequires, type Middleware } from './middleware/index.js';
|
|
2
|
+
import { type RouteHandler, type RouteNode } from './node.js';
|
|
3
|
+
import type { Plugin } from './plugin.js';
|
|
4
|
+
export interface RouteOptions<HandlerRequires = unknown, Provides = unknown, MiddlewareRequires = unknown, ContextRequires = unknown> {
|
|
5
|
+
method?: string;
|
|
6
|
+
path: string;
|
|
7
|
+
middleware?: Middleware<Provides, MiddlewareRequires>;
|
|
8
|
+
handler: RouteHandler<NoInfer<Provides & MiddlewareRequires & ContextRequires> & HandlerRequires>;
|
|
9
|
+
}
|
|
10
|
+
export interface GroupOptions<Provides = unknown, MiddlewareRequires = unknown> {
|
|
11
|
+
prefix?: string;
|
|
12
|
+
middleware?: Middleware<Provides, MiddlewareRequires>;
|
|
13
|
+
}
|
|
14
|
+
export declare class NodeBuilder<Requires = unknown> {
|
|
15
|
+
private root;
|
|
16
|
+
route<HandlerRequires = unknown, Provides = unknown, MiddlewareRequires = unknown>({ method, path, middleware: routeMiddleware, handler, }: RouteOptions<HandlerRequires, Provides, MiddlewareRequires, Requires>): NodeBuilder<Requires & MergeRequires<Provides, MiddlewareRequires, HandlerRequires>>;
|
|
17
|
+
group<Provides = unknown, MiddlewareRequires = unknown, NodeRequires = unknown>({ prefix, middleware: groupMiddleware }: GroupOptions<Provides, MiddlewareRequires>, node: NodeBuilder<NodeRequires>): NodeBuilder<Requires & MergeRequires<Provides, MiddlewareRequires, NodeRequires>>;
|
|
18
|
+
use<NodeRequires = unknown>(node: NodeBuilder<NodeRequires>): NodeBuilder<Requires & NodeRequires>;
|
|
19
|
+
apply<NextRequires = Requires>(plugin: Plugin<Requires, NextRequires>): NodeBuilder<NextRequires>;
|
|
20
|
+
build(): RouteNode<Requires>;
|
|
21
|
+
private getOrCreateNode;
|
|
22
|
+
private merge;
|
|
23
|
+
}
|
|
24
|
+
export declare function route<HandlerRequires = unknown, Provides = unknown, MiddlewareRequires = unknown>(options: RouteOptions<HandlerRequires, Provides, MiddlewareRequires>): NodeBuilder<MergeRequires<Provides, MiddlewareRequires, HandlerRequires>>;
|
|
25
|
+
export declare function routes<Requires = unknown>(): NodeBuilder<Requires>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { apply, pipe } from './middleware/index.js';
|
|
2
|
+
import { ALL_METHODS } from './node.js';
|
|
3
|
+
export class NodeBuilder {
|
|
4
|
+
root = { children: {}, methods: {} };
|
|
5
|
+
route({ method, path, middleware: routeMiddleware, handler, }) {
|
|
6
|
+
method ??= ALL_METHODS;
|
|
7
|
+
const target = this.getOrCreateNode(path);
|
|
8
|
+
target.methods[method] = routeMiddleware
|
|
9
|
+
? apply(routeMiddleware, handler)
|
|
10
|
+
: handler;
|
|
11
|
+
return this;
|
|
12
|
+
}
|
|
13
|
+
group({ prefix, middleware: groupMiddleware }, node) {
|
|
14
|
+
const target = this.getOrCreateNode(prefix);
|
|
15
|
+
if (groupMiddleware) {
|
|
16
|
+
target.middleware = target.middleware
|
|
17
|
+
? pipe(target.middleware, groupMiddleware)
|
|
18
|
+
: groupMiddleware;
|
|
19
|
+
}
|
|
20
|
+
this.merge(target, node.build());
|
|
21
|
+
return this;
|
|
22
|
+
}
|
|
23
|
+
use(node) {
|
|
24
|
+
this.merge(this.root, node.build());
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
apply(plugin) {
|
|
28
|
+
this.root = plugin(this.root);
|
|
29
|
+
return this;
|
|
30
|
+
}
|
|
31
|
+
build() {
|
|
32
|
+
return this.root;
|
|
33
|
+
}
|
|
34
|
+
getOrCreateNode(path) {
|
|
35
|
+
const segments = path?.split('/').filter(Boolean) ?? [];
|
|
36
|
+
let current = this.root;
|
|
37
|
+
for (const segment of segments) {
|
|
38
|
+
current.children[segment] ??= { children: {}, methods: {} };
|
|
39
|
+
current = current.children[segment];
|
|
40
|
+
}
|
|
41
|
+
return current;
|
|
42
|
+
}
|
|
43
|
+
merge(target, source) {
|
|
44
|
+
if (source.middleware) {
|
|
45
|
+
target.middleware = target.middleware
|
|
46
|
+
? pipe(target.middleware, source.middleware)
|
|
47
|
+
: source.middleware;
|
|
48
|
+
}
|
|
49
|
+
for (const [method, handler] of Object.entries(source.methods)) {
|
|
50
|
+
target.methods[method] = handler;
|
|
51
|
+
}
|
|
52
|
+
for (const [segment, child] of Object.entries(source.children)) {
|
|
53
|
+
target.children[segment] ??= { children: {}, methods: {} };
|
|
54
|
+
this.merge(target.children[segment], child);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export function route(options) {
|
|
59
|
+
const builder = new NodeBuilder();
|
|
60
|
+
return builder.route(options);
|
|
61
|
+
}
|
|
62
|
+
export function routes() {
|
|
63
|
+
return new NodeBuilder();
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=nodeBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodeBuilder.js","sourceRoot":"","sources":["../src/nodeBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAuC,MAAM,cAAc,CAAC;AAChF,OAAO,EAAE,WAAW,EAAqC,MAAM,QAAQ,CAAC;AAoBxE,MAAM,OAAO,WAAW;IACd,IAAI,GAAc,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;IAExD,KAAK,CAA8E,EACjF,MAAM,EACN,IAAI,EACJ,UAAU,EAAE,eAAe,EAC3B,OAAO,GAC+D;QAGtE,MAAM,KAAK,WAAW,CAAC;QACvB,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,I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C"}
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":""}
|
package/dist/router.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Handler } from '@glass-cannon/server';
|
|
2
|
+
import { type RouteNode } from './node.js';
|
|
3
|
+
import type { NodeBuilder } from './nodeBuilder.js';
|
|
4
|
+
export interface RouterOptions {
|
|
5
|
+
fallback?: Handler;
|
|
6
|
+
}
|
|
7
|
+
export declare class Router {
|
|
8
|
+
private readonly routes;
|
|
9
|
+
private readonly fallback;
|
|
10
|
+
private constructor();
|
|
11
|
+
static from(node: RouteNode | NodeBuilder, options?: RouterOptions): Router;
|
|
12
|
+
handle: Handler;
|
|
13
|
+
private matchMethod;
|
|
14
|
+
}
|
package/dist/router.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { apply, pipe } from './middleware/index.js';
|
|
2
|
+
import { ALL_METHODS } from './node.js';
|
|
3
|
+
export class Router {
|
|
4
|
+
routes;
|
|
5
|
+
fallback;
|
|
6
|
+
constructor(routes, fallback) {
|
|
7
|
+
this.routes = routes;
|
|
8
|
+
this.fallback = fallback;
|
|
9
|
+
}
|
|
10
|
+
static from(node, options) {
|
|
11
|
+
const rootNode = 'build' in node ? node.build() : node;
|
|
12
|
+
const routes = compileRouteNode(rootNode);
|
|
13
|
+
const fallback = options?.fallback ?? (() => new Response(null, { status: 404 }));
|
|
14
|
+
return new Router(routes, fallback);
|
|
15
|
+
}
|
|
16
|
+
handle = async (request) => {
|
|
17
|
+
const url = new URL(request.url);
|
|
18
|
+
const rawPath = url.pathname;
|
|
19
|
+
const path = rawPath.length > 1 && rawPath.endsWith('/') ? rawPath.slice(0, -1) : rawPath;
|
|
20
|
+
const method = request.method.toUpperCase();
|
|
21
|
+
const match = this.matchMethod(method, path) ?? this.matchMethod(ALL_METHODS, path);
|
|
22
|
+
if (!match)
|
|
23
|
+
return await this.fallback(request);
|
|
24
|
+
return await match.handler({
|
|
25
|
+
url,
|
|
26
|
+
method,
|
|
27
|
+
params: match.params,
|
|
28
|
+
request,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
matchMethod(method, path) {
|
|
32
|
+
const methodRoutes = this.routes[method];
|
|
33
|
+
if (!methodRoutes)
|
|
34
|
+
return undefined;
|
|
35
|
+
const staticHandler = methodRoutes.static[path];
|
|
36
|
+
if (staticHandler) {
|
|
37
|
+
return { handler: staticHandler, params: {} };
|
|
38
|
+
}
|
|
39
|
+
const dynamic = methodRoutes.dynamic;
|
|
40
|
+
if (!dynamic)
|
|
41
|
+
return undefined;
|
|
42
|
+
const match = dynamic.regex.exec(path);
|
|
43
|
+
if (!match)
|
|
44
|
+
return undefined;
|
|
45
|
+
const matchIndex = match.findLastIndex(Boolean) - 1;
|
|
46
|
+
const route = dynamic.routes[matchIndex];
|
|
47
|
+
const params = { ...route.capturingRegex.exec(path)?.groups };
|
|
48
|
+
return { handler: route.handler, params };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function compileRouteNode(root) {
|
|
52
|
+
const staticByMethod = Object.create(null);
|
|
53
|
+
const dynamicByMethod = Object.create(null);
|
|
54
|
+
function visit(node, currentPath, inheritedMiddleware) {
|
|
55
|
+
const middleware = inheritedMiddleware
|
|
56
|
+
? node.middleware
|
|
57
|
+
? pipe(inheritedMiddleware, node.middleware)
|
|
58
|
+
: inheritedMiddleware
|
|
59
|
+
: node.middleware;
|
|
60
|
+
const isDynamic = currentPath.includes(':') || currentPath.includes('*');
|
|
61
|
+
for (const [rawMethod, rawHandler] of Object.entries(node.methods)) {
|
|
62
|
+
const method = rawMethod.toUpperCase();
|
|
63
|
+
const handler = middleware ? apply(middleware, rawHandler) : rawHandler;
|
|
64
|
+
if (isDynamic) {
|
|
65
|
+
dynamicByMethod[method] ??= [];
|
|
66
|
+
const metadata = computeMetadata(currentPath, handler);
|
|
67
|
+
binaryInsert(dynamicByMethod[method], metadata, (item) => item.score);
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
staticByMethod[method] ??= Object.create(null);
|
|
71
|
+
staticByMethod[method][currentPath || '/'] = handler;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const [segment, child] of Object.entries(node.children)) {
|
|
75
|
+
visit(child, `${currentPath}/${segment}`, middleware);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
visit(root, '');
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
80
|
+
const compiled = Object.create(null);
|
|
81
|
+
const methods = new Set([...Object.keys(staticByMethod), ...Object.keys(dynamicByMethod)]);
|
|
82
|
+
for (const method of methods) {
|
|
83
|
+
const dynamicRoutes = dynamicByMethod[method];
|
|
84
|
+
compiled[method] = {
|
|
85
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
86
|
+
static: staticByMethod[method] ?? Object.create(null),
|
|
87
|
+
...(dynamicRoutes && dynamicRoutes.length > 0
|
|
88
|
+
? {
|
|
89
|
+
dynamic: {
|
|
90
|
+
routes: dynamicRoutes,
|
|
91
|
+
regex: new RegExp(dynamicRoutes.map((r) => r.regex).join('|')),
|
|
92
|
+
},
|
|
93
|
+
}
|
|
94
|
+
: {}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return compiled;
|
|
98
|
+
}
|
|
99
|
+
function computeMetadata(path, handler) {
|
|
100
|
+
const score = computeScore(path);
|
|
101
|
+
const regex = pathToRegex(path);
|
|
102
|
+
const capturingRegex = new RegExp(pathToCapturingRegex(path));
|
|
103
|
+
return { handler, regex, score, capturingRegex };
|
|
104
|
+
}
|
|
105
|
+
function computeScore(path) {
|
|
106
|
+
let score = 0;
|
|
107
|
+
for (const c of path) {
|
|
108
|
+
if (c === '/') {
|
|
109
|
+
score += 2;
|
|
110
|
+
}
|
|
111
|
+
else if (c === ':') {
|
|
112
|
+
score -= 1;
|
|
113
|
+
}
|
|
114
|
+
else if (c === '*') {
|
|
115
|
+
score -= 2;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return score;
|
|
119
|
+
}
|
|
120
|
+
function pathToRegex(path) {
|
|
121
|
+
return ('^(' +
|
|
122
|
+
path
|
|
123
|
+
.replace(/([.+?^=!:${}()[\]|/\\])/g, '\\$1')
|
|
124
|
+
.replace(/\\:([a-zA-Z0-9_]+)\*/g, '(?:.*)')
|
|
125
|
+
.replace(/\\\*/g, '(?:.*)')
|
|
126
|
+
.replace(/\\:([a-zA-Z0-9_]+)/g, '(?:[^/]+)') +
|
|
127
|
+
'/?)$');
|
|
128
|
+
}
|
|
129
|
+
function pathToCapturingRegex(path) {
|
|
130
|
+
return ('^' +
|
|
131
|
+
path
|
|
132
|
+
.replace(/([.+?^=!:${}()[\]|/\\])/g, '\\$1')
|
|
133
|
+
.replace(/\\:([a-zA-Z0-9_]+)\*/g, '(?<$1>.*)')
|
|
134
|
+
.replace(/\\\*/g, '(?:.*)')
|
|
135
|
+
.replace(/\\:([a-zA-Z0-9_]+)/g, '(?<$1>[^/]+)') +
|
|
136
|
+
'/?$');
|
|
137
|
+
}
|
|
138
|
+
function binaryInsert(array, value, score) {
|
|
139
|
+
let low = 0;
|
|
140
|
+
let high = array.length;
|
|
141
|
+
while (low < high) {
|
|
142
|
+
const mid = Math.floor((low + high) / 2);
|
|
143
|
+
if (score(value) < score(array[mid])) {
|
|
144
|
+
low = mid + 1;
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
high = mid;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
array.splice(low, 0, value);
|
|
151
|
+
return low;
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAA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,KAA2B;IACxE,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,IAAI,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC;IAExB,OAAO,GAAG,GAAG,IAAI,EAAE,CAAC;QAClB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAEzC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAE,CAAC,EAAE,CAAC;YACtC,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC;QAChB,CAAC;aAAM,CAAC;YACN,IAAI,GAAG,GAAG,CAAC;QACb,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5B,OAAO,GAAG,CAAC;AACb,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glass-cannon/router",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
7
7
|
"import": "./dist/index.js",
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@glass-cannon/server": "0.
|
|
19
|
+
"@glass-cannon/server": "0.11.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/bun": "latest"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"typescript": "^5 || ^6"
|
|
25
|
+
"typescript": "^5 || ^6 || ^7"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
28
|
"build": "tsc && tsc-alias"
|