@barqel/barq 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/app.d.ts +159 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/app.js +1370 -0
- package/dist/app.js.map +1 -0
- package/dist/context.d.ts +55 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +261 -0
- package/dist/context.js.map +1 -0
- package/dist/cookies.d.ts +5 -0
- package/dist/cookies.d.ts.map +1 -0
- package/dist/cookies.js +234 -0
- package/dist/cookies.js.map +1 -0
- package/dist/cors.d.ts +11 -0
- package/dist/cors.d.ts.map +1 -0
- package/dist/cors.js +82 -0
- package/dist/cors.js.map +1 -0
- package/dist/errors.d.ts +10 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +81 -0
- package/dist/errors.js.map +1 -0
- package/dist/http.d.ts +7 -0
- package/dist/http.d.ts.map +1 -0
- package/dist/http.js +127 -0
- package/dist/http.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/ip.d.ts +6 -0
- package/dist/internal/ip.d.ts.map +1 -0
- package/dist/internal/ip.js +151 -0
- package/dist/internal/ip.js.map +1 -0
- package/dist/internal/pathname.d.ts +9 -0
- package/dist/internal/pathname.d.ts.map +1 -0
- package/dist/internal/pathname.js +158 -0
- package/dist/internal/pathname.js.map +1 -0
- package/dist/internal/query.d.ts +5 -0
- package/dist/internal/query.d.ts.map +1 -0
- package/dist/internal/query.js +126 -0
- package/dist/internal/query.js.map +1 -0
- package/dist/internal/scan.d.ts +33 -0
- package/dist/internal/scan.d.ts.map +1 -0
- package/dist/internal/scan.js +1069 -0
- package/dist/internal/scan.js.map +1 -0
- package/dist/internal/shutdown.d.ts +7 -0
- package/dist/internal/shutdown.d.ts.map +1 -0
- package/dist/internal/shutdown.js +30 -0
- package/dist/internal/shutdown.js.map +1 -0
- package/dist/internal/trie.d.ts +43 -0
- package/dist/internal/trie.d.ts.map +1 -0
- package/dist/internal/trie.js +560 -0
- package/dist/internal/trie.js.map +1 -0
- package/dist/middleware.d.ts +13 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +269 -0
- package/dist/middleware.js.map +1 -0
- package/dist/types.d.ts +59 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/validation.d.ts +27 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +32 -0
- package/dist/validation.js.map +1 -0
- package/package.json +58 -4
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
import { HttpError } from "../errors";
|
|
2
|
+
export const MATCH_HANDLER = Symbol("barq.match.handler");
|
|
3
|
+
export const MATCH_NOT_ALLOWED = Symbol("barq.match.not-allowed");
|
|
4
|
+
const METHOD_BITS = {
|
|
5
|
+
GET: 1 << 0,
|
|
6
|
+
POST: 1 << 1,
|
|
7
|
+
PUT: 1 << 2,
|
|
8
|
+
DELETE: 1 << 3,
|
|
9
|
+
PATCH: 1 << 4,
|
|
10
|
+
HEAD: 1 << 5,
|
|
11
|
+
OPTIONS: 1 << 6,
|
|
12
|
+
};
|
|
13
|
+
const _ALL_METHODS_BITMASK = (1 << 7) - 1;
|
|
14
|
+
// Linear key checks beat substring creation only at very small fanout.
|
|
15
|
+
const STATIC_CHILD_SCAN_THRESHOLD = 4;
|
|
16
|
+
function methodBit(method) {
|
|
17
|
+
return METHOD_BITS[method] ?? 0;
|
|
18
|
+
}
|
|
19
|
+
function _hasMethod(bits, method) {
|
|
20
|
+
return (bits & methodBit(method)) !== 0;
|
|
21
|
+
}
|
|
22
|
+
function _methodsToString(bits) {
|
|
23
|
+
const methods = [];
|
|
24
|
+
if (bits & METHOD_BITS.GET)
|
|
25
|
+
methods.push("GET");
|
|
26
|
+
if (bits & METHOD_BITS.POST)
|
|
27
|
+
methods.push("POST");
|
|
28
|
+
if (bits & METHOD_BITS.PUT)
|
|
29
|
+
methods.push("PUT");
|
|
30
|
+
if (bits & METHOD_BITS.DELETE)
|
|
31
|
+
methods.push("DELETE");
|
|
32
|
+
if (bits & METHOD_BITS.PATCH)
|
|
33
|
+
methods.push("PATCH");
|
|
34
|
+
if (bits & METHOD_BITS.HEAD)
|
|
35
|
+
methods.push("HEAD");
|
|
36
|
+
if (bits & METHOD_BITS.OPTIONS)
|
|
37
|
+
methods.push("OPTIONS");
|
|
38
|
+
return methods.join(", ");
|
|
39
|
+
}
|
|
40
|
+
function createNode() {
|
|
41
|
+
return {
|
|
42
|
+
staticChildren: null,
|
|
43
|
+
staticChildKeys: [],
|
|
44
|
+
staticChildNodes: [],
|
|
45
|
+
paramChildren: null,
|
|
46
|
+
paramChild: null,
|
|
47
|
+
paramName: null,
|
|
48
|
+
wildcardChild: null,
|
|
49
|
+
wildcardName: null,
|
|
50
|
+
handlers: null,
|
|
51
|
+
allow: null,
|
|
52
|
+
notAllowed: null,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function cloneNode(node) {
|
|
56
|
+
const staticChildren = node.staticChildren
|
|
57
|
+
? new Map(Array.from(node.staticChildren, ([key, child]) => [
|
|
58
|
+
key,
|
|
59
|
+
cloneNode(child),
|
|
60
|
+
]))
|
|
61
|
+
: null;
|
|
62
|
+
const staticChildKeys = node.staticChildKeys.slice();
|
|
63
|
+
const staticChildNodes = staticChildren
|
|
64
|
+
? staticChildKeys.map((key) => staticChildren.get(key))
|
|
65
|
+
: [];
|
|
66
|
+
const paramChildren = node.paramChildren
|
|
67
|
+
? new Map(Array.from(node.paramChildren, ([name, child]) => [
|
|
68
|
+
name,
|
|
69
|
+
cloneNode(child),
|
|
70
|
+
]))
|
|
71
|
+
: null;
|
|
72
|
+
let handlers = null;
|
|
73
|
+
if (node.handlers !== null) {
|
|
74
|
+
handlers = Object.assign(Object.create(null), node.handlers);
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
staticChildren,
|
|
78
|
+
staticChildKeys,
|
|
79
|
+
staticChildNodes,
|
|
80
|
+
paramChildren,
|
|
81
|
+
paramChild: node.paramChild ? cloneNode(node.paramChild) : null,
|
|
82
|
+
paramName: node.paramName,
|
|
83
|
+
wildcardChild: node.wildcardChild ? cloneNode(node.wildcardChild) : null,
|
|
84
|
+
wildcardName: node.wildcardName,
|
|
85
|
+
handlers,
|
|
86
|
+
allow: node.allow,
|
|
87
|
+
notAllowed: node.notAllowed,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const MAX_OPTIONAL_PARAMS = 8;
|
|
91
|
+
export function parsePattern(pattern) {
|
|
92
|
+
if (pattern.length === 0 || pattern.charCodeAt(0) !== 47) {
|
|
93
|
+
throw new Error(`Invalid route pattern "${pattern}": must start with '/'`);
|
|
94
|
+
}
|
|
95
|
+
if (pattern.indexOf("#") !== -1) {
|
|
96
|
+
throw new Error(`Invalid route pattern "${pattern}": must not contain '#'`);
|
|
97
|
+
}
|
|
98
|
+
let p = pattern;
|
|
99
|
+
if (p.length > 1 && p.charCodeAt(p.length - 1) === 47) {
|
|
100
|
+
p = p.slice(0, -1);
|
|
101
|
+
}
|
|
102
|
+
const segments = [];
|
|
103
|
+
const names = new Set();
|
|
104
|
+
let i = 1;
|
|
105
|
+
while (i < p.length) {
|
|
106
|
+
const slash = p.indexOf("/", i);
|
|
107
|
+
const end = slash === -1 ? p.length : slash;
|
|
108
|
+
const seg = p.slice(i, end);
|
|
109
|
+
if (seg.length === 0) {
|
|
110
|
+
throw new Error(`Invalid route pattern "${pattern}": empty segment ('//')`);
|
|
111
|
+
}
|
|
112
|
+
const c0 = seg.charCodeAt(0);
|
|
113
|
+
if (seg.includes("?") &&
|
|
114
|
+
!(c0 === 58 && seg.endsWith("?") && seg.indexOf("?") === seg.length - 1)) {
|
|
115
|
+
throw new Error(`Invalid route pattern "${pattern}": malformed optional parameter`);
|
|
116
|
+
}
|
|
117
|
+
if (c0 === 58) {
|
|
118
|
+
const optional = seg.endsWith("?");
|
|
119
|
+
const name = optional ? seg.slice(1, -1) : seg.slice(1);
|
|
120
|
+
if (name.length === 0) {
|
|
121
|
+
throw new Error(`Invalid route pattern "${pattern}": empty parameter name in segment ":${name}"`);
|
|
122
|
+
}
|
|
123
|
+
if (names.has(name)) {
|
|
124
|
+
throw new Error(`Invalid route pattern "${pattern}": duplicate parameter name "${name}"`);
|
|
125
|
+
}
|
|
126
|
+
names.add(name);
|
|
127
|
+
if (name.includes("?")) {
|
|
128
|
+
throw new Error(`Invalid route pattern "${pattern}": malformed optional parameter`);
|
|
129
|
+
}
|
|
130
|
+
segments.push(optional
|
|
131
|
+
? { kind: "param", name, optional: true }
|
|
132
|
+
: { kind: "param", name });
|
|
133
|
+
}
|
|
134
|
+
else if (c0 === 42) {
|
|
135
|
+
if (end !== p.length) {
|
|
136
|
+
throw new Error(`Invalid route pattern "${pattern}": wildcard '*' must be the final segment`);
|
|
137
|
+
}
|
|
138
|
+
const name = seg.length > 1 ? seg.slice(1) : null;
|
|
139
|
+
if (name !== null) {
|
|
140
|
+
if (names.has(name)) {
|
|
141
|
+
throw new Error(`Invalid route pattern "${pattern}": duplicate parameter name "${name}"`);
|
|
142
|
+
}
|
|
143
|
+
names.add(name);
|
|
144
|
+
}
|
|
145
|
+
segments.push({ kind: "wildcard", name });
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
segments.push({ kind: "static", value: seg });
|
|
149
|
+
}
|
|
150
|
+
i = end + 1;
|
|
151
|
+
}
|
|
152
|
+
const optionalCount = segments.reduce((count, segment) => count + (segment.kind === "param" && segment.optional ? 1 : 0), 0);
|
|
153
|
+
if (optionalCount > MAX_OPTIONAL_PARAMS) {
|
|
154
|
+
throw new RangeError(`Route pattern exceeds the limit of ${MAX_OPTIONAL_PARAMS} optional parameters`);
|
|
155
|
+
}
|
|
156
|
+
return segments;
|
|
157
|
+
}
|
|
158
|
+
function _segmentEquals(path, start, end, key) {
|
|
159
|
+
const n = end - start;
|
|
160
|
+
if (key.length !== n)
|
|
161
|
+
return false;
|
|
162
|
+
for (let i = 0; i < n; i++) {
|
|
163
|
+
if (path.charCodeAt(start + i) !== key.charCodeAt(i))
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
return true;
|
|
167
|
+
}
|
|
168
|
+
function decodeParam(raw) {
|
|
169
|
+
if (raw.indexOf("%") === -1)
|
|
170
|
+
return raw;
|
|
171
|
+
try {
|
|
172
|
+
return decodeURIComponent(raw);
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
throw new HttpError(400, { error: "Bad Request" });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function matchNode(rootNode, pathname, startI, method, paramNames, paramValues, startDepth) {
|
|
179
|
+
let node = rootNode;
|
|
180
|
+
let i = startI;
|
|
181
|
+
const depth = startDepth;
|
|
182
|
+
while (true) {
|
|
183
|
+
const len = pathname.length;
|
|
184
|
+
if (i >= len) {
|
|
185
|
+
const handlers = node.handlers;
|
|
186
|
+
if (handlers === null)
|
|
187
|
+
return null;
|
|
188
|
+
let handler = handlers[method];
|
|
189
|
+
if (handler === undefined && method === "HEAD") {
|
|
190
|
+
handler = handlers.GET;
|
|
191
|
+
}
|
|
192
|
+
if (handler === undefined) {
|
|
193
|
+
return node.notAllowed;
|
|
194
|
+
}
|
|
195
|
+
if (depth === 0)
|
|
196
|
+
return handler;
|
|
197
|
+
const p = Object.create(null);
|
|
198
|
+
p[MATCH_HANDLER] = handler;
|
|
199
|
+
for (let k = 0; k < depth; k++) {
|
|
200
|
+
p[paramNames[k]] = paramValues[k];
|
|
201
|
+
}
|
|
202
|
+
return p;
|
|
203
|
+
}
|
|
204
|
+
const slash = pathname.indexOf("/", i);
|
|
205
|
+
const segEnd = slash === -1 ? len : slash;
|
|
206
|
+
if (segEnd === i) {
|
|
207
|
+
// A single trailing slash is accepted; empty interior segments are not.
|
|
208
|
+
if (slash === len - 1) {
|
|
209
|
+
return matchNode(node, pathname, len, method, paramNames, paramValues, depth);
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
const nextI = slash === -1 ? len : slash + 1;
|
|
214
|
+
let notAllowedCandidate = null;
|
|
215
|
+
const staticChildren = node.staticChildren;
|
|
216
|
+
if (staticChildren !== null) {
|
|
217
|
+
let child;
|
|
218
|
+
if (staticChildren.size <= STATIC_CHILD_SCAN_THRESHOLD) {
|
|
219
|
+
const keys = node.staticChildKeys;
|
|
220
|
+
const nodes = node.staticChildNodes;
|
|
221
|
+
for (let childIndex = 0; childIndex < keys.length; childIndex++) {
|
|
222
|
+
if (_segmentEquals(pathname, i, segEnd, keys[childIndex])) {
|
|
223
|
+
child = nodes[childIndex];
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
child = staticChildren.get(pathname.slice(i, segEnd));
|
|
230
|
+
}
|
|
231
|
+
if (child !== undefined) {
|
|
232
|
+
const hasParamChildren = node.paramChildren !== null && node.paramChildren.size > 0;
|
|
233
|
+
if (!hasParamChildren && node.wildcardChild === null) {
|
|
234
|
+
node = child;
|
|
235
|
+
i = nextI;
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const res = matchNode(child, pathname, nextI, method, paramNames, paramValues, depth);
|
|
239
|
+
if (res !== null) {
|
|
240
|
+
if (MATCH_NOT_ALLOWED in res) {
|
|
241
|
+
notAllowedCandidate = res;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return res;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const paramChildren = node.paramChildren ??
|
|
250
|
+
(node.paramChild !== null && node.paramName !== null
|
|
251
|
+
? new Map([[node.paramName, node.paramChild]])
|
|
252
|
+
: null);
|
|
253
|
+
if (paramChildren !== null && paramChildren.size > 0) {
|
|
254
|
+
for (const [paramName, child] of paramChildren) {
|
|
255
|
+
if (nextI >= len && child.handlers !== null) {
|
|
256
|
+
let leafH = child.handlers[method];
|
|
257
|
+
if (leafH === undefined && method === "HEAD")
|
|
258
|
+
leafH = child.handlers.GET;
|
|
259
|
+
if (leafH !== undefined) {
|
|
260
|
+
const paramVal = pathname.indexOf("%", i) !== -1
|
|
261
|
+
? decodeParam(pathname.slice(i, segEnd))
|
|
262
|
+
: pathname.slice(i, segEnd);
|
|
263
|
+
const p = {
|
|
264
|
+
[paramName]: paramVal,
|
|
265
|
+
[MATCH_HANDLER]: leafH,
|
|
266
|
+
};
|
|
267
|
+
if (depth === 0)
|
|
268
|
+
return p;
|
|
269
|
+
for (let k = 0; k < depth; k++) {
|
|
270
|
+
p[paramNames[k]] = paramValues[k];
|
|
271
|
+
}
|
|
272
|
+
return p;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
paramNames[depth] = paramName;
|
|
276
|
+
paramValues[depth] = decodeParam(pathname.slice(i, segEnd));
|
|
277
|
+
const res = matchNode(child, pathname, nextI, method, paramNames, paramValues, depth + 1);
|
|
278
|
+
if (res !== null) {
|
|
279
|
+
if (MATCH_NOT_ALLOWED in res) {
|
|
280
|
+
notAllowedCandidate ??= res;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
return res;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (node.wildcardChild !== null) {
|
|
289
|
+
let wildcardDepth = depth;
|
|
290
|
+
if (node.wildcardName !== null) {
|
|
291
|
+
let rest = pathname.slice(i);
|
|
292
|
+
if (rest.length > 1 && rest.charCodeAt(rest.length - 1) === 47) {
|
|
293
|
+
rest = rest.slice(0, -1);
|
|
294
|
+
}
|
|
295
|
+
paramNames[wildcardDepth] = node.wildcardName;
|
|
296
|
+
paramValues[wildcardDepth] = decodeParam(rest);
|
|
297
|
+
wildcardDepth++;
|
|
298
|
+
}
|
|
299
|
+
const handlers = node.wildcardChild.handlers;
|
|
300
|
+
if (handlers !== null) {
|
|
301
|
+
let handler = handlers[method];
|
|
302
|
+
if (handler === undefined && method === "HEAD") {
|
|
303
|
+
handler = handlers.GET;
|
|
304
|
+
}
|
|
305
|
+
if (handler === undefined) {
|
|
306
|
+
return node.wildcardChild.notAllowed;
|
|
307
|
+
}
|
|
308
|
+
if (wildcardDepth === 0)
|
|
309
|
+
return handler;
|
|
310
|
+
const p = Object.create(null);
|
|
311
|
+
for (let k = 0; k < wildcardDepth; k++) {
|
|
312
|
+
p[paramNames[k]] = paramValues[k];
|
|
313
|
+
}
|
|
314
|
+
p[MATCH_HANDLER] = handler;
|
|
315
|
+
return p;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return notAllowedCandidate;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
export class SegmentTrie {
|
|
322
|
+
root = createNode();
|
|
323
|
+
staticRoutes = new Map();
|
|
324
|
+
staticNotAllowed = new Map();
|
|
325
|
+
maxStaticLength = 0;
|
|
326
|
+
paramNameBuffer = [];
|
|
327
|
+
paramValueBuffer = [];
|
|
328
|
+
addBatch(routes) {
|
|
329
|
+
if (routes.length === 0)
|
|
330
|
+
return;
|
|
331
|
+
if (routes.length === 1) {
|
|
332
|
+
const route = routes[0];
|
|
333
|
+
this.add(route.method, route.pattern, route.handler);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
const staged = this.clone();
|
|
337
|
+
const parsedPatterns = new Map();
|
|
338
|
+
for (const route of routes) {
|
|
339
|
+
let segments = parsedPatterns.get(route.pattern);
|
|
340
|
+
if (segments === undefined) {
|
|
341
|
+
segments = parsePattern(route.pattern);
|
|
342
|
+
parsedPatterns.set(route.pattern, segments);
|
|
343
|
+
}
|
|
344
|
+
staged.addWithSegments(route.method, route.pattern, segments, route.handler);
|
|
345
|
+
}
|
|
346
|
+
this.root = staged.root;
|
|
347
|
+
this.staticRoutes = staged.staticRoutes;
|
|
348
|
+
this.staticNotAllowed = staged.staticNotAllowed;
|
|
349
|
+
this.maxStaticLength = staged.maxStaticLength;
|
|
350
|
+
}
|
|
351
|
+
clone() {
|
|
352
|
+
const copy = new SegmentTrie();
|
|
353
|
+
copy.root = cloneNode(this.root);
|
|
354
|
+
copy.staticRoutes = new Map(Array.from(this.staticRoutes, ([path, handlers]) => [
|
|
355
|
+
path,
|
|
356
|
+
Object.assign(Object.create(null), handlers),
|
|
357
|
+
]));
|
|
358
|
+
copy.staticNotAllowed = new Map(this.staticNotAllowed);
|
|
359
|
+
copy.maxStaticLength = this.maxStaticLength;
|
|
360
|
+
return copy;
|
|
361
|
+
}
|
|
362
|
+
add(method, pattern, handler) {
|
|
363
|
+
const segments = parsePattern(pattern);
|
|
364
|
+
let optionalCount = 0;
|
|
365
|
+
for (const segment of segments) {
|
|
366
|
+
if (segment.kind === "param" && segment.optional)
|
|
367
|
+
optionalCount++;
|
|
368
|
+
}
|
|
369
|
+
if (optionalCount === 0) {
|
|
370
|
+
this.addParsed(method, pattern, segments, handler, false);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const staged = this.clone();
|
|
374
|
+
staged.addWithSegments(method, pattern, segments, handler);
|
|
375
|
+
this.root = staged.root;
|
|
376
|
+
this.staticRoutes = staged.staticRoutes;
|
|
377
|
+
this.staticNotAllowed = staged.staticNotAllowed;
|
|
378
|
+
}
|
|
379
|
+
addWithSegments(method, pattern, segments, handler) {
|
|
380
|
+
let optionalCount = 0;
|
|
381
|
+
for (const segment of segments) {
|
|
382
|
+
if (segment.kind === "param" && segment.optional)
|
|
383
|
+
optionalCount++;
|
|
384
|
+
}
|
|
385
|
+
if (optionalCount === 0) {
|
|
386
|
+
this.addParsed(method, pattern, segments, handler, false);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
const selected = [];
|
|
390
|
+
const addVariants = (index) => {
|
|
391
|
+
if (index === segments.length) {
|
|
392
|
+
const variant = selected.length === 0
|
|
393
|
+
? "/"
|
|
394
|
+
: `/${selected.map((segment) => (segment.kind === "static" ? segment.value : segment.kind === "param" ? `:${segment.name}` : `*${segment.name ?? ""}`)).join("/")}`;
|
|
395
|
+
this.addParsed(method, variant, selected, handler, true);
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const segment = segments[index];
|
|
399
|
+
if (segment.kind === "param" && segment.optional) {
|
|
400
|
+
selected.push({ kind: "param", name: segment.name });
|
|
401
|
+
addVariants(index + 1);
|
|
402
|
+
selected.pop();
|
|
403
|
+
addVariants(index + 1);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
selected.push(segment);
|
|
407
|
+
addVariants(index + 1);
|
|
408
|
+
selected.pop();
|
|
409
|
+
};
|
|
410
|
+
addVariants(0);
|
|
411
|
+
}
|
|
412
|
+
addParsed(method, pattern, segments, handler, _allowConflictingParamNames) {
|
|
413
|
+
const bit = methodBit(method);
|
|
414
|
+
if (bit === 0) {
|
|
415
|
+
throw new Error(`Unsupported HTTP method "${method}" for route "${pattern}"`);
|
|
416
|
+
}
|
|
417
|
+
const isPureStatic = segments.every((s) => s.kind === "static");
|
|
418
|
+
let cleanPattern;
|
|
419
|
+
if (isPureStatic) {
|
|
420
|
+
cleanPattern =
|
|
421
|
+
pattern.length > 1 && pattern.charCodeAt(pattern.length - 1) === 47
|
|
422
|
+
? pattern.slice(0, -1)
|
|
423
|
+
: pattern;
|
|
424
|
+
if (cleanPattern.length > this.maxStaticLength) {
|
|
425
|
+
this.maxStaticLength = cleanPattern.length;
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
for (const seg of segments) {
|
|
429
|
+
if (seg.kind === "static") {
|
|
430
|
+
}
|
|
431
|
+
else if (seg.kind === "param") {
|
|
432
|
+
if (isPureStatic) {
|
|
433
|
+
throw new Error(`Internal error: param segment in pure static route`);
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
else {
|
|
437
|
+
if (isPureStatic) {
|
|
438
|
+
throw new Error(`Internal error: wildcard segment in pure static route`);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
let node = this.root;
|
|
443
|
+
for (const seg of segments) {
|
|
444
|
+
if (seg.kind === "static") {
|
|
445
|
+
if (node.staticChildren === null) {
|
|
446
|
+
node.staticChildren = new Map();
|
|
447
|
+
}
|
|
448
|
+
let child = node.staticChildren.get(seg.value);
|
|
449
|
+
if (child === undefined) {
|
|
450
|
+
child = createNode();
|
|
451
|
+
node.staticChildren.set(seg.value, child);
|
|
452
|
+
node.staticChildKeys.push(seg.value);
|
|
453
|
+
node.staticChildNodes.push(child);
|
|
454
|
+
}
|
|
455
|
+
node = child;
|
|
456
|
+
}
|
|
457
|
+
else if (seg.kind === "param") {
|
|
458
|
+
if (node.wildcardChild !== null) {
|
|
459
|
+
throw new Error(`Ambiguous routes: wildcard "${node.wildcardName ?? "*"}" and param ":${seg.name}" compete at the same position in "${pattern}"`);
|
|
460
|
+
}
|
|
461
|
+
if (node.paramChildren === null) {
|
|
462
|
+
node.paramChildren = new Map();
|
|
463
|
+
}
|
|
464
|
+
let child = node.paramChildren.get(seg.name);
|
|
465
|
+
if (child === undefined) {
|
|
466
|
+
child = createNode();
|
|
467
|
+
node.paramChildren.set(seg.name, child);
|
|
468
|
+
if (node.paramChild === null && node.paramChildren.size === 1) {
|
|
469
|
+
node.paramChild = child;
|
|
470
|
+
node.paramName = seg.name;
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
node.paramChild = null;
|
|
474
|
+
node.paramName = null;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
node = child;
|
|
478
|
+
}
|
|
479
|
+
else {
|
|
480
|
+
if (node.wildcardChild !== null) {
|
|
481
|
+
if (node.wildcardName !== seg.name) {
|
|
482
|
+
throw new Error(`Conflicting wildcards at the same position: "*${node.wildcardName ?? ""}" vs "*${seg.name ?? ""}" (route "${pattern}")`);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
if (node.paramChildren !== null && node.paramChildren.size > 0) {
|
|
487
|
+
const existingParam = node.paramChildren.keys().next().value;
|
|
488
|
+
if (existingParam !== undefined) {
|
|
489
|
+
throw new Error(`Ambiguous routes: param ":${existingParam}" and wildcard "*${seg.name ?? ""}" compete at the same position in "${pattern}"`);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
node.wildcardChild = createNode();
|
|
493
|
+
node.wildcardName = seg.name;
|
|
494
|
+
}
|
|
495
|
+
node = node.wildcardChild;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
if (node.handlers?.[method] !== undefined) {
|
|
499
|
+
throw new Error(`Duplicate route: ${method} ${pattern} is already registered`);
|
|
500
|
+
}
|
|
501
|
+
if (node.handlers === null)
|
|
502
|
+
node.handlers = Object.create(null);
|
|
503
|
+
node.handlers[method] = handler;
|
|
504
|
+
node.allow = SegmentTrie.computeAllow(node.handlers);
|
|
505
|
+
node.notAllowed = Object.freeze({
|
|
506
|
+
[MATCH_NOT_ALLOWED]: node.allow,
|
|
507
|
+
});
|
|
508
|
+
if (isPureStatic) {
|
|
509
|
+
let sHandlers = this.staticRoutes.get(cleanPattern);
|
|
510
|
+
if (sHandlers === undefined) {
|
|
511
|
+
sHandlers = Object.create(null);
|
|
512
|
+
this.staticRoutes.set(cleanPattern, sHandlers);
|
|
513
|
+
}
|
|
514
|
+
sHandlers[method] = handler;
|
|
515
|
+
const sAllow = SegmentTrie.computeAllow(sHandlers);
|
|
516
|
+
this.staticNotAllowed.set(cleanPattern, Object.freeze({ [MATCH_NOT_ALLOWED]: sAllow }));
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
static computeAllow(handlers) {
|
|
520
|
+
const methods = Object.keys(handlers);
|
|
521
|
+
if (methods.includes("GET") && !methods.includes("HEAD")) {
|
|
522
|
+
return [...methods, "HEAD"].join(", ");
|
|
523
|
+
}
|
|
524
|
+
return methods.join(", ");
|
|
525
|
+
}
|
|
526
|
+
match(method, pathname) {
|
|
527
|
+
const len = pathname.length;
|
|
528
|
+
const cleanPath = len > 1 && pathname.charCodeAt(len - 1) === 47
|
|
529
|
+
? pathname.slice(0, -1)
|
|
530
|
+
: pathname;
|
|
531
|
+
if (cleanPath.length <= this.maxStaticLength) {
|
|
532
|
+
const sHandlers = this.staticRoutes.get(cleanPath);
|
|
533
|
+
if (sHandlers !== undefined) {
|
|
534
|
+
let handler = sHandlers[method];
|
|
535
|
+
if (handler === undefined && method === "HEAD") {
|
|
536
|
+
handler = sHandlers.GET;
|
|
537
|
+
}
|
|
538
|
+
if (handler !== undefined) {
|
|
539
|
+
return handler;
|
|
540
|
+
}
|
|
541
|
+
const dynamicMatch = matchNode(this.root, pathname, 1, method, this.paramNameBuffer, this.paramValueBuffer, 0);
|
|
542
|
+
if (this.paramNameBuffer.length > 0) {
|
|
543
|
+
this.paramNameBuffer.length = 0;
|
|
544
|
+
this.paramValueBuffer.length = 0;
|
|
545
|
+
}
|
|
546
|
+
if (dynamicMatch !== null && !(MATCH_NOT_ALLOWED in dynamicMatch)) {
|
|
547
|
+
return dynamicMatch;
|
|
548
|
+
}
|
|
549
|
+
return this.staticNotAllowed.get(cleanPath);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const res = matchNode(this.root, pathname, 1, method, this.paramNameBuffer, this.paramValueBuffer, 0);
|
|
553
|
+
if (this.paramNameBuffer.length > 0) {
|
|
554
|
+
this.paramNameBuffer.length = 0;
|
|
555
|
+
this.paramValueBuffer.length = 0;
|
|
556
|
+
}
|
|
557
|
+
return res;
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
//# sourceMappingURL=trie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trie.js","sourceRoot":"","sources":["../../src/internal/trie.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAGtC,MAAM,CAAC,MAAM,aAAa,GAAkB,MAAM,CAAC,oBAAoB,CAAC,CAAC;AAE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type { Context } from "./context";
|
|
2
|
+
import type { ErrorResolver, Middleware } from "./types";
|
|
3
|
+
type PipelineHandler = (ctx: Context) => Response | Promise<Response>;
|
|
4
|
+
export type MiddlewareDispatcher = (ctx: Context, handler: PipelineHandler) => Response | Promise<Response>;
|
|
5
|
+
export declare function isThenable(value: unknown): value is PromiseLike<unknown>;
|
|
6
|
+
/** Compile a middleware chain once for reuse by native and fallback routes. */
|
|
7
|
+
export declare function composeMiddlewareDispatcher(mws: readonly Middleware[], errorResolver?: ErrorResolver): MiddlewareDispatcher;
|
|
8
|
+
/** Compile a route-specific chain around its handler. */
|
|
9
|
+
export declare function composeMiddlewares(mws: readonly Middleware[], handler: PipelineHandler, errorResolver?: ErrorResolver): PipelineHandler;
|
|
10
|
+
export declare function runPipeline(mws: readonly Middleware[], ctx: Context, handler: (ctx: Context) => Response | Promise<Response>, errorResolver?: ErrorResolver): Response | Promise<Response>;
|
|
11
|
+
export declare function unwindAfter(mws: readonly Middleware[], ctx: Context, res: Response, enteredCount: number, errorResolver?: ErrorResolver): Response | Promise<Response>;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=middleware.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../src/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEzD,KAAK,eAAe,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAEtE,MAAM,MAAM,oBAAoB,GAAG,CACjC,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE,eAAe,KACrB,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;AAElC,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,I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