ovr 6.2.3 → 6.2.4
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/app/index.d.ts.map +1 -1
- package/dist/app/index.js +3 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/cookie/index.d.ts +1 -1
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +2 -2
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +3 -3
- package/dist/multipart/index.d.ts +1 -1
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +39 -24
- package/dist/route/index.d.ts +4 -4
- package/dist/route/index.d.ts.map +1 -1
- package/dist/schema/index.d.ts +24 -8
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -2
- package/dist/trie/index.d.ts +6 -5
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +14 -16
- package/dist/util/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app/index.ts +6 -1
- package/src/context/index.ts +3 -2
- package/src/cookie/index.ts +2 -2
- package/src/jsx/elements.ts +3 -17
- package/src/jsx/index.ts +3 -5
- package/src/multipart/index.ts +1 -1
- package/src/render/index.ts +49 -31
- package/src/route/index.ts +5 -4
- package/src/schema/index.ts +11 -17
- package/src/trie/index.ts +22 -24
- package/src/util/index.ts +1 -1
package/src/trie/index.ts
CHANGED
|
@@ -30,16 +30,16 @@ export class Trie {
|
|
|
30
30
|
readonly seg: string;
|
|
31
31
|
|
|
32
32
|
/** Static child node map, key is the first character in the segment */
|
|
33
|
-
map
|
|
33
|
+
map: Map<number, Trie> | undefined;
|
|
34
34
|
|
|
35
35
|
/** Parametric child node */
|
|
36
|
-
param
|
|
36
|
+
param: ParamNode | undefined;
|
|
37
37
|
|
|
38
38
|
/** Matched route */
|
|
39
|
-
route
|
|
39
|
+
route: Route | undefined;
|
|
40
40
|
|
|
41
41
|
/** Matched wildcard route */
|
|
42
|
-
wild
|
|
42
|
+
wild: Route | undefined;
|
|
43
43
|
|
|
44
44
|
static readonly #paramMatch = /:.+?(?=\/|$)/g;
|
|
45
45
|
static readonly #paramSplit = /:.+?(?=\/|$)/;
|
|
@@ -180,7 +180,7 @@ export class Trie {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
// check if the staticSegment matches the current node
|
|
183
|
-
for (let charIndex = 0; ;
|
|
183
|
+
for (let charIndex = 0; ;) {
|
|
184
184
|
if (charIndex === staticSegment.length) {
|
|
185
185
|
// finished iterating through the staticSegment
|
|
186
186
|
if (charIndex < current.seg.length) {
|
|
@@ -248,21 +248,25 @@ export class Trie {
|
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
250
|
* @param pathname Path to find
|
|
251
|
+
* @param start Start of the current segment within the pathname
|
|
251
252
|
* @returns `Route` and the matched `params` if found, otherwise `null`
|
|
252
253
|
*/
|
|
253
|
-
find(
|
|
254
|
-
|
|
254
|
+
find(
|
|
255
|
+
pathname: string,
|
|
256
|
+
start = 0,
|
|
257
|
+
): { route: Route; params: Trie.Params } | null {
|
|
258
|
+
const end = start + this.seg.length;
|
|
255
259
|
|
|
256
260
|
if (
|
|
257
261
|
// too short
|
|
258
|
-
pathname.length <
|
|
262
|
+
pathname.length < end ||
|
|
259
263
|
// segment does not match current node segment
|
|
260
|
-
!pathname.startsWith(this.seg)
|
|
264
|
+
!pathname.startsWith(this.seg, start)
|
|
261
265
|
) {
|
|
262
266
|
return null;
|
|
263
267
|
}
|
|
264
268
|
|
|
265
|
-
if (pathname ===
|
|
269
|
+
if (pathname.length === end) {
|
|
266
270
|
// reached the end of the path
|
|
267
271
|
if (this.route) return { route: this.route, params: {} };
|
|
268
272
|
|
|
@@ -273,20 +277,20 @@ export class Trie {
|
|
|
273
277
|
|
|
274
278
|
if (this.map) {
|
|
275
279
|
// check for a static leaf that starts with the first character
|
|
276
|
-
const staticChild = this.map.get(pathname.charCodeAt(
|
|
280
|
+
const staticChild = this.map.get(pathname.charCodeAt(end));
|
|
277
281
|
|
|
278
282
|
if (staticChild) {
|
|
279
|
-
const result = staticChild.find(pathname
|
|
283
|
+
const result = staticChild.find(pathname, end);
|
|
280
284
|
if (result) return result;
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
// check for param leaf
|
|
285
289
|
if (this.param) {
|
|
286
|
-
const slashIndex = pathname.indexOf("/",
|
|
290
|
+
const slashIndex = pathname.indexOf("/", end);
|
|
287
291
|
|
|
288
292
|
// if there is not a slash immediately following this.segment
|
|
289
|
-
if (slashIndex !==
|
|
293
|
+
if (slashIndex !== end) {
|
|
290
294
|
// there is a valid parameter
|
|
291
295
|
if (
|
|
292
296
|
// param is the end of the pathname
|
|
@@ -295,19 +299,16 @@ export class Trie {
|
|
|
295
299
|
) {
|
|
296
300
|
return {
|
|
297
301
|
route: this.param.route,
|
|
298
|
-
params: { [this.param.name]: pathname.slice(
|
|
302
|
+
params: { [this.param.name]: pathname.slice(end) },
|
|
299
303
|
};
|
|
300
304
|
} else if (this.param.child) {
|
|
301
305
|
// there's a static node after the param
|
|
302
306
|
// this is how there can be multiple params, "/" in between
|
|
303
|
-
const result = this.param.child.find(pathname
|
|
307
|
+
const result = this.param.child.find(pathname, slashIndex);
|
|
304
308
|
|
|
305
309
|
if (result) {
|
|
306
310
|
// add original params to the result
|
|
307
|
-
result.params[this.param.name] = pathname.slice(
|
|
308
|
-
segmentLength,
|
|
309
|
-
slashIndex,
|
|
310
|
-
);
|
|
311
|
+
result.params[this.param.name] = pathname.slice(end, slashIndex);
|
|
311
312
|
|
|
312
313
|
return result;
|
|
313
314
|
}
|
|
@@ -317,10 +318,7 @@ export class Trie {
|
|
|
317
318
|
|
|
318
319
|
// check for wildcard leaf
|
|
319
320
|
if (this.wild) {
|
|
320
|
-
return {
|
|
321
|
-
route: this.wild,
|
|
322
|
-
params: { "*": pathname.slice(segmentLength) },
|
|
323
|
-
};
|
|
321
|
+
return { route: this.wild, params: { "*": pathname.slice(end) } };
|
|
324
322
|
}
|
|
325
323
|
|
|
326
324
|
return null;
|
package/src/util/index.ts
CHANGED
|
@@ -119,7 +119,7 @@ export class Header {
|
|
|
119
119
|
if (header) {
|
|
120
120
|
const headerLength = header.length;
|
|
121
121
|
|
|
122
|
-
for (let cursor = 0; cursor < headerLength;
|
|
122
|
+
for (let cursor = 0; cursor < headerLength;) {
|
|
123
123
|
const equal = header.indexOf("=", cursor);
|
|
124
124
|
if (equal === -1) break; // done
|
|
125
125
|
|