ovr 5.0.0 → 6.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/dist/LICENSE.md +26 -0
- package/dist/app/index.d.ts +49 -83
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +40 -92
- package/dist/context/index.d.ts +138 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +218 -0
- package/dist/cookie/index.d.ts +121 -0
- package/dist/cookie/index.d.ts.map +1 -0
- package/dist/cookie/index.js +56 -0
- package/dist/index.d.ts +6 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -6
- package/dist/jsx/{intrinsic-elements.d.ts → elements.d.ts} +14 -7
- package/dist/jsx/elements.d.ts.map +1 -0
- package/dist/jsx/index.d.ts +37 -52
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +71 -200
- package/dist/middleware/index.d.ts +22 -0
- package/dist/middleware/index.d.ts.map +1 -0
- package/dist/multipart/index.d.ts +122 -0
- package/dist/multipart/index.d.ts.map +1 -0
- package/dist/multipart/index.js +341 -0
- package/dist/render/index.d.ts +78 -0
- package/dist/render/index.d.ts.map +1 -0
- package/dist/render/index.js +248 -0
- package/dist/route/index.d.ts +147 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +126 -0
- package/dist/trie/index.d.ts +30 -30
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +67 -82
- package/dist/util/index.d.ts +38 -0
- package/dist/util/index.d.ts.map +1 -0
- package/dist/util/index.js +88 -0
- package/package.json +3 -3
- package/src/app/index.ts +99 -224
- package/src/context/index.ts +262 -0
- package/src/cookie/index.ts +189 -0
- package/src/index.ts +6 -7
- package/src/jsx/{intrinsic-elements.ts → elements.ts} +14 -7
- package/src/jsx/index.ts +81 -223
- package/src/middleware/index.ts +29 -0
- package/src/multipart/index.ts +486 -0
- package/src/render/index.ts +300 -0
- package/src/route/index.ts +332 -0
- package/src/trie/index.ts +87 -111
- package/src/util/index.ts +112 -0
- package/dist/app/context.d.ts +0 -149
- package/dist/app/context.d.ts.map +0 -1
- package/dist/app/context.js +0 -246
- package/dist/app/helper/get.d.ts +0 -30
- package/dist/app/helper/get.d.ts.map +0 -1
- package/dist/app/helper/get.js +0 -33
- package/dist/app/helper/index.d.ts +0 -51
- package/dist/app/helper/index.d.ts.map +0 -1
- package/dist/app/helper/index.js +0 -82
- package/dist/app/helper/post.d.ts +0 -35
- package/dist/app/helper/post.d.ts.map +0 -1
- package/dist/app/helper/post.js +0 -15
- package/dist/app/memo/index.d.ts +0 -12
- package/dist/app/memo/index.d.ts.map +0 -1
- package/dist/app/memo/index.js +0 -34
- package/dist/jsx/chunk/index.d.ts +0 -38
- package/dist/jsx/chunk/index.d.ts.map +0 -1
- package/dist/jsx/chunk/index.js +0 -69
- package/dist/jsx/intrinsic-elements.d.ts.map +0 -1
- package/dist/jsx/merge-async-generators.d.ts +0 -14
- package/dist/jsx/merge-async-generators.d.ts.map +0 -1
- package/dist/jsx/merge-async-generators.js +0 -42
- package/dist/types/index.d.ts +0 -17
- package/dist/types/index.d.ts.map +0 -1
- package/dist/util/hash.d.ts +0 -11
- package/dist/util/hash.d.ts.map +0 -1
- package/dist/util/hash.js +0 -16
- package/src/app/context.ts +0 -303
- package/src/app/helper/get.ts +0 -46
- package/src/app/helper/index.ts +0 -156
- package/src/app/helper/post.ts +0 -54
- package/src/app/memo/index.ts +0 -40
- package/src/jsx/chunk/index.ts +0 -79
- package/src/jsx/merge-async-generators.ts +0 -47
- package/src/types/index.ts +0 -42
- package/src/util/hash.ts +0 -17
- /package/dist/jsx/{intrinsic-elements.js → elements.js} +0 -0
- /package/dist/{types → middleware}/index.js +0 -0
package/src/trie/index.ts
CHANGED
|
@@ -1,74 +1,63 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Route } from "../route/index.js";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
/** Route pattern */
|
|
5
|
-
pattern: string;
|
|
6
|
-
|
|
7
|
-
/** Store returned when route is found */
|
|
8
|
-
store: Store;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param pattern route pattern
|
|
12
|
-
* @param store value to store in the patterns final node
|
|
13
|
-
*/
|
|
14
|
-
constructor(pattern: string, store: Store) {
|
|
15
|
-
if (pattern[0] !== "/") {
|
|
16
|
-
throw new Error(
|
|
17
|
-
`Invalid route: ${pattern} - route pattern must begin with "/"`,
|
|
18
|
-
);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
this.pattern = pattern;
|
|
22
|
-
this.store = store;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class ParamNode<Store> {
|
|
3
|
+
class ParamNode {
|
|
27
4
|
/** Name of the parameter (without the colon ":") */
|
|
28
|
-
name: string;
|
|
5
|
+
readonly name: string;
|
|
29
6
|
|
|
30
7
|
/** Matched route */
|
|
31
|
-
route
|
|
8
|
+
route?: Route;
|
|
32
9
|
|
|
33
10
|
/** Static child node */
|
|
34
|
-
|
|
11
|
+
child?: Trie;
|
|
35
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Create a new parameter node.
|
|
15
|
+
*
|
|
16
|
+
* @param name Name of the parameter.
|
|
17
|
+
*/
|
|
36
18
|
constructor(name: string) {
|
|
37
19
|
this.name = name;
|
|
38
20
|
}
|
|
39
21
|
}
|
|
40
22
|
|
|
41
|
-
export
|
|
23
|
+
export namespace Trie {
|
|
24
|
+
/** Params created from the route match */
|
|
25
|
+
export type Params = Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export class Trie {
|
|
42
29
|
/** Unique segment of the pattern trie */
|
|
43
|
-
|
|
30
|
+
readonly seg: string;
|
|
44
31
|
|
|
45
32
|
/** Static child node map, key is the first character in the segment */
|
|
46
|
-
|
|
33
|
+
map?: Map<number, Trie>;
|
|
47
34
|
|
|
48
35
|
/** Parametric child node */
|
|
49
|
-
|
|
36
|
+
param?: ParamNode;
|
|
50
37
|
|
|
51
38
|
/** Matched route */
|
|
52
|
-
route
|
|
39
|
+
route?: Route;
|
|
53
40
|
|
|
54
41
|
/** Matched wildcard route */
|
|
55
|
-
|
|
42
|
+
wild?: Route;
|
|
56
43
|
|
|
57
|
-
static #paramMatch = /:.+?(?=\/|$)/g;
|
|
58
|
-
static #paramSplit = /:.+?(?=\/|$)/;
|
|
44
|
+
static readonly #paramMatch = /:.+?(?=\/|$)/g;
|
|
45
|
+
static readonly #paramSplit = /:.+?(?=\/|$)/;
|
|
59
46
|
|
|
60
47
|
/**
|
|
48
|
+
* Create a new trie.
|
|
49
|
+
*
|
|
61
50
|
* @param segment pattern segment
|
|
62
|
-
* @param
|
|
51
|
+
* @param children static children nodes to add to staticMap
|
|
63
52
|
*/
|
|
64
|
-
constructor(segment = "/",
|
|
65
|
-
this.
|
|
53
|
+
constructor(segment = "/", children?: Trie[]) {
|
|
54
|
+
this.seg = segment;
|
|
66
55
|
|
|
67
|
-
if (
|
|
68
|
-
this.
|
|
56
|
+
if (children?.length) {
|
|
57
|
+
this.map ??= new Map();
|
|
69
58
|
|
|
70
|
-
for (const child of
|
|
71
|
-
this.
|
|
59
|
+
for (const child of children) {
|
|
60
|
+
this.map.set(child.seg.charCodeAt(0), child);
|
|
72
61
|
}
|
|
73
62
|
}
|
|
74
63
|
}
|
|
@@ -80,10 +69,10 @@ export class Trie<Store> {
|
|
|
80
69
|
clone(segment: string) {
|
|
81
70
|
const clone = new Trie(segment);
|
|
82
71
|
|
|
83
|
-
clone.
|
|
84
|
-
clone.
|
|
72
|
+
clone.map = this.map;
|
|
73
|
+
clone.param = this.param;
|
|
85
74
|
clone.route = this.route;
|
|
86
|
-
clone.
|
|
75
|
+
clone.wild = this.wild;
|
|
87
76
|
|
|
88
77
|
return clone;
|
|
89
78
|
}
|
|
@@ -98,13 +87,15 @@ export class Trie<Store> {
|
|
|
98
87
|
* @returns the new child produced from the new segment
|
|
99
88
|
*/
|
|
100
89
|
fork(charIndex: number, segment: string) {
|
|
101
|
-
const
|
|
102
|
-
const newChild = new Trie<Store>(segment.slice(charIndex)); // "movies/"
|
|
90
|
+
const newChild = new Trie(segment.slice(charIndex)); // "movies/"
|
|
103
91
|
|
|
104
92
|
Object.assign(
|
|
105
93
|
this,
|
|
106
94
|
// "api/" with the above as children
|
|
107
|
-
new Trie(this.
|
|
95
|
+
new Trie(this.seg.slice(0, charIndex), [
|
|
96
|
+
this.clone(this.seg.slice(charIndex)), // "posts/"
|
|
97
|
+
newChild,
|
|
98
|
+
]),
|
|
108
99
|
);
|
|
109
100
|
|
|
110
101
|
return newChild;
|
|
@@ -118,33 +109,27 @@ export class Trie<Store> {
|
|
|
118
109
|
* @param segment
|
|
119
110
|
*/
|
|
120
111
|
split(segment: string) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
112
|
+
Object.assign(
|
|
113
|
+
this,
|
|
114
|
+
new Trie(segment, [this.clone(this.seg.slice(segment.length))]),
|
|
115
|
+
);
|
|
124
116
|
}
|
|
125
117
|
|
|
126
118
|
/**
|
|
127
119
|
* @param name name of the param
|
|
128
120
|
* @returns the existing child with the same name, or creates a new
|
|
129
121
|
*/
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
throw new Error(
|
|
133
|
-
`Cannot create parameter "${name}" because a different parameter ` +
|
|
134
|
-
`("${this.paramChild.name}") already exists in this location.\n\n${this}`,
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return (this.paramChild ??= new ParamNode<Store>(name));
|
|
122
|
+
set(name: string) {
|
|
123
|
+
return (this.param ??= new ParamNode(name));
|
|
139
124
|
}
|
|
140
125
|
|
|
141
126
|
/**
|
|
142
127
|
* @param route route return when pattern is matched
|
|
143
128
|
* @returns this - the Node
|
|
144
129
|
*/
|
|
145
|
-
add(route: Route
|
|
146
|
-
let current: Trie
|
|
147
|
-
let pattern = route.pattern; // created to not modify the original
|
|
130
|
+
add(route: Route) {
|
|
131
|
+
let current: Trie = this;
|
|
132
|
+
let pattern = route.method + route.pattern; // created to not modify the original
|
|
148
133
|
|
|
149
134
|
const endsWithWildcard = pattern.endsWith("*");
|
|
150
135
|
if (endsWithWildcard) pattern = pattern.slice(0, -1);
|
|
@@ -169,26 +154,26 @@ export class Trie<Store> {
|
|
|
169
154
|
// there is only a second static segment (could just be "/")
|
|
170
155
|
// if there is a param to split them, so there must be a param here
|
|
171
156
|
|
|
172
|
-
const paramChild = current.
|
|
157
|
+
const paramChild = current.set(
|
|
173
158
|
// param without the ":" (only increment when this is reached)
|
|
174
159
|
paramSegments[paramIndex++]!.slice(1),
|
|
175
160
|
);
|
|
176
161
|
|
|
177
|
-
if (!paramChild.
|
|
162
|
+
if (!paramChild.child) {
|
|
178
163
|
// new - create node with the next static segment
|
|
179
|
-
current = paramChild.
|
|
164
|
+
current = paramChild.child = new Trie(staticSegment);
|
|
180
165
|
continue; // next segment - no need to check since it's new
|
|
181
166
|
}
|
|
182
167
|
|
|
183
168
|
// there's already a static child - need to check if it's a match
|
|
184
|
-
current = paramChild.
|
|
169
|
+
current = paramChild.child;
|
|
185
170
|
}
|
|
186
171
|
|
|
187
172
|
// check if the staticSegment matches the current node
|
|
188
173
|
for (let charIndex = 0; ; ) {
|
|
189
174
|
if (charIndex === staticSegment.length) {
|
|
190
175
|
// finished iterating through the staticSegment
|
|
191
|
-
if (charIndex < current.
|
|
176
|
+
if (charIndex < current.seg.length) {
|
|
192
177
|
// too short
|
|
193
178
|
current.split(staticSegment);
|
|
194
179
|
}
|
|
@@ -196,15 +181,15 @@ export class Trie<Store> {
|
|
|
196
181
|
break; // next segment
|
|
197
182
|
}
|
|
198
183
|
|
|
199
|
-
if (charIndex === current.
|
|
184
|
+
if (charIndex === current.seg.length) {
|
|
200
185
|
// passed the end of the current node
|
|
201
|
-
if (!current.
|
|
186
|
+
if (!current.map) {
|
|
202
187
|
// new pattern, create new leaf
|
|
203
|
-
current.
|
|
188
|
+
current.map = new Map();
|
|
204
189
|
} else {
|
|
205
190
|
// there's already static children,
|
|
206
191
|
// check to see if there's a leaf that starts with the char
|
|
207
|
-
const staticChild = current.
|
|
192
|
+
const staticChild = current.map.get(
|
|
208
193
|
staticSegment.charCodeAt(charIndex),
|
|
209
194
|
);
|
|
210
195
|
|
|
@@ -218,17 +203,14 @@ export class Trie<Store> {
|
|
|
218
203
|
}
|
|
219
204
|
|
|
220
205
|
// otherwise, add new staticChild
|
|
221
|
-
const staticChild = new Trie
|
|
222
|
-
current.
|
|
223
|
-
staticSegment.charCodeAt(charIndex),
|
|
224
|
-
staticChild,
|
|
225
|
-
);
|
|
206
|
+
const staticChild = new Trie(staticSegment.slice(charIndex));
|
|
207
|
+
current.map.set(staticSegment.charCodeAt(charIndex), staticChild);
|
|
226
208
|
current = staticChild;
|
|
227
209
|
|
|
228
210
|
break; // next segment
|
|
229
211
|
}
|
|
230
212
|
|
|
231
|
-
if (staticSegment[charIndex] !== current.
|
|
213
|
+
if (staticSegment[charIndex] !== current.seg[charIndex]) {
|
|
232
214
|
// different than the node - fork
|
|
233
215
|
current = current.fork(charIndex, staticSegment);
|
|
234
216
|
|
|
@@ -242,14 +224,13 @@ export class Trie<Store> {
|
|
|
242
224
|
|
|
243
225
|
if (paramIndex < paramSegments.length) {
|
|
244
226
|
// final segment is a param
|
|
245
|
-
current.
|
|
246
|
-
route;
|
|
227
|
+
current.set(paramSegments[paramIndex]!.slice(1)).route = route;
|
|
247
228
|
} else if (endsWithWildcard) {
|
|
248
229
|
// final segment is a wildcard
|
|
249
|
-
current.
|
|
230
|
+
current.wild = route;
|
|
250
231
|
} else {
|
|
251
232
|
// final segment is static
|
|
252
|
-
current.route
|
|
233
|
+
current.route = route;
|
|
253
234
|
}
|
|
254
235
|
|
|
255
236
|
return this;
|
|
@@ -259,67 +240,62 @@ export class Trie<Store> {
|
|
|
259
240
|
* @param pathname Path to find
|
|
260
241
|
* @returns `Route` and the matched `params` if found, otherwise `null`
|
|
261
242
|
*/
|
|
262
|
-
find(pathname: string): { route: Route
|
|
243
|
+
find(pathname: string): { route: Route; params: Trie.Params } | null {
|
|
244
|
+
const segmentLength = this.seg.length;
|
|
245
|
+
|
|
263
246
|
if (
|
|
264
247
|
// too short
|
|
265
|
-
pathname.length <
|
|
248
|
+
pathname.length < segmentLength ||
|
|
266
249
|
// segment does not match current node segment
|
|
267
|
-
!pathname.startsWith(this.
|
|
250
|
+
!pathname.startsWith(this.seg)
|
|
268
251
|
) {
|
|
269
252
|
return null;
|
|
270
253
|
}
|
|
271
254
|
|
|
272
|
-
if (pathname === this.
|
|
255
|
+
if (pathname === this.seg) {
|
|
273
256
|
// reached the end of the path
|
|
274
257
|
if (this.route) return { route: this.route, params: {} };
|
|
275
258
|
|
|
276
|
-
if (this.
|
|
277
|
-
return { route: this.wildcardRoute, params: { "*": "" } };
|
|
259
|
+
if (this.wild) return { route: this.wild, params: { "*": "" } };
|
|
278
260
|
|
|
279
261
|
return null;
|
|
280
262
|
}
|
|
281
263
|
|
|
282
|
-
if (this.
|
|
264
|
+
if (this.map) {
|
|
283
265
|
// check for a static leaf that starts with the first character
|
|
284
|
-
const staticChild = this.
|
|
285
|
-
pathname.charCodeAt(this.segment.length),
|
|
286
|
-
);
|
|
266
|
+
const staticChild = this.map.get(pathname.charCodeAt(segmentLength));
|
|
287
267
|
|
|
288
268
|
if (staticChild) {
|
|
289
|
-
const result = staticChild.find(pathname.slice(
|
|
269
|
+
const result = staticChild.find(pathname.slice(segmentLength));
|
|
290
270
|
if (result) return result;
|
|
291
271
|
}
|
|
292
272
|
}
|
|
293
273
|
|
|
294
274
|
// check for param leaf
|
|
295
|
-
if (this.
|
|
296
|
-
const slashIndex = pathname.indexOf("/",
|
|
275
|
+
if (this.param) {
|
|
276
|
+
const slashIndex = pathname.indexOf("/", segmentLength);
|
|
297
277
|
|
|
298
278
|
// if there is not a slash immediately following this.segment
|
|
299
|
-
if (slashIndex !==
|
|
279
|
+
if (slashIndex !== segmentLength) {
|
|
300
280
|
// there is a valid parameter
|
|
301
281
|
if (
|
|
302
282
|
// param is the end of the pathname
|
|
303
283
|
slashIndex === -1 &&
|
|
304
|
-
this.
|
|
284
|
+
this.param.route
|
|
305
285
|
) {
|
|
306
286
|
return {
|
|
307
|
-
route: this.
|
|
308
|
-
params: {
|
|
309
|
-
[this.paramChild.name]: pathname.slice(this.segment.length),
|
|
310
|
-
},
|
|
287
|
+
route: this.param.route,
|
|
288
|
+
params: { [this.param.name]: pathname.slice(segmentLength) },
|
|
311
289
|
};
|
|
312
|
-
} else if (this.
|
|
290
|
+
} else if (this.param.child) {
|
|
313
291
|
// there's a static node after the param
|
|
314
292
|
// this is how there can be multiple params, "/" in between
|
|
315
|
-
const result = this.
|
|
316
|
-
pathname.slice(slashIndex),
|
|
317
|
-
);
|
|
293
|
+
const result = this.param.child.find(pathname.slice(slashIndex));
|
|
318
294
|
|
|
319
295
|
if (result) {
|
|
320
296
|
// add original params to the result
|
|
321
|
-
result.params[this.
|
|
322
|
-
|
|
297
|
+
result.params[this.param.name] = pathname.slice(
|
|
298
|
+
segmentLength,
|
|
323
299
|
slashIndex,
|
|
324
300
|
);
|
|
325
301
|
|
|
@@ -330,10 +306,10 @@ export class Trie<Store> {
|
|
|
330
306
|
}
|
|
331
307
|
|
|
332
308
|
// check for wildcard leaf
|
|
333
|
-
if (this.
|
|
309
|
+
if (this.wild) {
|
|
334
310
|
return {
|
|
335
|
-
route: this.
|
|
336
|
-
params: { "*": pathname.slice(
|
|
311
|
+
route: this.wild,
|
|
312
|
+
params: { "*": pathname.slice(segmentLength) },
|
|
337
313
|
};
|
|
338
314
|
}
|
|
339
315
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** General utility types */
|
|
2
|
+
export namespace Util {
|
|
3
|
+
export type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
export type MaybeFunction<T> = T | (() => T);
|
|
5
|
+
export type DeepArray<T> = T | DeepArray<T>[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/** Header parsing utils */
|
|
9
|
+
export class Header {
|
|
10
|
+
// shared content type header to minify better
|
|
11
|
+
static readonly contentType = "content-type";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param header header value to parse
|
|
15
|
+
* @returns Base/first param
|
|
16
|
+
*/
|
|
17
|
+
static shift(header: string | null): [string | null, string | null] {
|
|
18
|
+
if (header) {
|
|
19
|
+
const semi = header.indexOf(";");
|
|
20
|
+
if (semi !== -1) {
|
|
21
|
+
return [header.slice(0, semi), header.slice(semi)];
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return [header, null];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param header header value to parse
|
|
30
|
+
* @returns Map containing each key=value pair
|
|
31
|
+
*/
|
|
32
|
+
static params(header: string | null) {
|
|
33
|
+
const parsed: Record<string, string> = {};
|
|
34
|
+
|
|
35
|
+
if (header) {
|
|
36
|
+
const headerLength = header.length;
|
|
37
|
+
|
|
38
|
+
for (let cursor = 0; cursor < headerLength; ) {
|
|
39
|
+
const equal = header.indexOf("=", cursor);
|
|
40
|
+
if (equal === -1) break; // done
|
|
41
|
+
|
|
42
|
+
let semi = header.indexOf(";", cursor);
|
|
43
|
+
if (semi === -1) semi = headerLength;
|
|
44
|
+
|
|
45
|
+
if (equal > semi) {
|
|
46
|
+
// equal is in the next pair, current is malformed
|
|
47
|
+
// move the cursor to the start of the next and ignore
|
|
48
|
+
cursor = header.lastIndexOf(";", equal - 1) + 1;
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const key = header.slice(cursor, equal).trim();
|
|
53
|
+
|
|
54
|
+
if (!(key in parsed)) {
|
|
55
|
+
// first value should take precedence
|
|
56
|
+
|
|
57
|
+
let value = header.slice(equal + 1, semi).trim();
|
|
58
|
+
|
|
59
|
+
if (value[0] === '"' && value[value.length - 1] === '"') {
|
|
60
|
+
// remove quotes
|
|
61
|
+
value = value.slice(1, -1);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (value.includes("%")) {
|
|
65
|
+
// most values don't need to be decoded
|
|
66
|
+
try {
|
|
67
|
+
// cookies must be a simple string
|
|
68
|
+
value = decodeURIComponent(value);
|
|
69
|
+
} catch {
|
|
70
|
+
// ignore
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
parsed[key] = value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
cursor = semi + 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return parsed;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Hash util */
|
|
86
|
+
export class Hash {
|
|
87
|
+
/**
|
|
88
|
+
* Fast hashing algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
89
|
+
*
|
|
90
|
+
* @param s String to hash
|
|
91
|
+
* @returns Hashed string
|
|
92
|
+
*/
|
|
93
|
+
static djb2(s: string) {
|
|
94
|
+
let hash = 5381;
|
|
95
|
+
let i = s.length;
|
|
96
|
+
|
|
97
|
+
while (i) hash = (hash * 33) ^ s.charCodeAt(--i);
|
|
98
|
+
|
|
99
|
+
return (hash >>> 0).toString(36);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Shared encoding to use across features */
|
|
104
|
+
export class Codec {
|
|
105
|
+
static #encoder = new TextEncoder();
|
|
106
|
+
static #decoder = new TextDecoder("utf-8", { fatal: true });
|
|
107
|
+
|
|
108
|
+
static encode = (s: string) => Codec.#encoder.encode(s);
|
|
109
|
+
|
|
110
|
+
/** DO NOT USE FOR STREAMS */
|
|
111
|
+
static decode = (input?: Uint8Array) => Codec.#decoder.decode(input);
|
|
112
|
+
}
|
package/dist/app/context.d.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import { type JSX } from "../jsx/index.js";
|
|
2
|
-
import { type Params, Route } from "../trie/index.js";
|
|
3
|
-
import { type Middleware } from "./index.js";
|
|
4
|
-
import { Memo } from "./memo/index.js";
|
|
5
|
-
type Layout = (props: {
|
|
6
|
-
children: JSX.Element;
|
|
7
|
-
}) => JSX.Element;
|
|
8
|
-
export declare class Context<P extends Params = Params> {
|
|
9
|
-
#private;
|
|
10
|
-
/**
|
|
11
|
-
* Incoming `Request` to the server.
|
|
12
|
-
*
|
|
13
|
-
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Request)
|
|
14
|
-
*/
|
|
15
|
-
req: Request;
|
|
16
|
-
/**
|
|
17
|
-
* Parsed `URL` created from `req.url`.
|
|
18
|
-
*
|
|
19
|
-
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL)
|
|
20
|
-
*/
|
|
21
|
-
url: URL;
|
|
22
|
-
/**
|
|
23
|
-
* Route pattern parameters
|
|
24
|
-
*
|
|
25
|
-
* Given the route pattern `/posts/:slug` is added, a request made to
|
|
26
|
-
* `/posts/my-post` creates a `params` object `{ slug: "my-post" }`.
|
|
27
|
-
*
|
|
28
|
-
* @example { slug: "my-post" }
|
|
29
|
-
*/
|
|
30
|
-
params: P;
|
|
31
|
-
/** Matched `Route` instance. */
|
|
32
|
-
route: Route<Middleware<P>[]> | null;
|
|
33
|
-
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#body) */
|
|
34
|
-
body: BodyInit | null;
|
|
35
|
-
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status) */
|
|
36
|
-
status?: number;
|
|
37
|
-
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */
|
|
38
|
-
headers: Headers;
|
|
39
|
-
/** `layouts` for the `Page` to be passed into before being injected into the `<body>` */
|
|
40
|
-
layouts: Layout[];
|
|
41
|
-
/** `JSX.Element`(s) to add to the head */
|
|
42
|
-
head: JSX.Element[];
|
|
43
|
-
/**
|
|
44
|
-
* Middleware to run when no `body` or `status` has been set on the `context`.
|
|
45
|
-
* Set to a new function to override the default.
|
|
46
|
-
*
|
|
47
|
-
* @default
|
|
48
|
-
*
|
|
49
|
-
* ```ts
|
|
50
|
-
* (c) => {
|
|
51
|
-
* c.text("Not found", 404);
|
|
52
|
-
* c.headers.set("cache-control", "no-cache");
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
notFound: Middleware<P>;
|
|
57
|
-
/**
|
|
58
|
-
* Base HTML to inject the `head` and `page` elements into.
|
|
59
|
-
*
|
|
60
|
-
* If left empty, components will be returned as partials.
|
|
61
|
-
*
|
|
62
|
-
* @default ""
|
|
63
|
-
*/
|
|
64
|
-
base: string;
|
|
65
|
-
/** `Memo` unique to the current `Request` context */
|
|
66
|
-
memo: Memo;
|
|
67
|
-
/**
|
|
68
|
-
* Creates a new `Context` with the current `Request`.
|
|
69
|
-
*
|
|
70
|
-
* @param req Request
|
|
71
|
-
*/
|
|
72
|
-
constructor(req: Request);
|
|
73
|
-
/**
|
|
74
|
-
* Mirrors `new Response()` constructor, set values with one function.
|
|
75
|
-
*
|
|
76
|
-
* @param body Response BodyInit
|
|
77
|
-
* @param init ResponseInit
|
|
78
|
-
*/
|
|
79
|
-
res(body: BodyInit | null, init?: {
|
|
80
|
-
/**
|
|
81
|
-
* [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
82
|
-
*
|
|
83
|
-
* @default 200
|
|
84
|
-
*/
|
|
85
|
-
status?: number;
|
|
86
|
-
/** [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Headers) */
|
|
87
|
-
headers?: HeadersInit;
|
|
88
|
-
}): void;
|
|
89
|
-
/**
|
|
90
|
-
* Creates an HTML response.
|
|
91
|
-
*
|
|
92
|
-
* @param body HTML body
|
|
93
|
-
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
94
|
-
*/
|
|
95
|
-
html(body: BodyInit | null, status?: number): void;
|
|
96
|
-
/**
|
|
97
|
-
* Creates a JSON response.
|
|
98
|
-
*
|
|
99
|
-
* @param data passed into JSON.stringify to create the body
|
|
100
|
-
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
101
|
-
*/
|
|
102
|
-
json(data: any, status?: number): void;
|
|
103
|
-
/**
|
|
104
|
-
* Creates a plain text response.
|
|
105
|
-
*
|
|
106
|
-
* @param body response body
|
|
107
|
-
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
108
|
-
*/
|
|
109
|
-
text(body: BodyInit, status?: number): void;
|
|
110
|
-
/**
|
|
111
|
-
* Creates a redirect response.
|
|
112
|
-
*
|
|
113
|
-
* @param location redirect `Location` header
|
|
114
|
-
* @param status HTTP status code
|
|
115
|
-
*
|
|
116
|
-
* - [301 Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/301)
|
|
117
|
-
* - [302 Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) (default)
|
|
118
|
-
* - [303 See Other](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/303)
|
|
119
|
-
* - [307 Temporary Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307)
|
|
120
|
-
* - [308 Permanent Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308)
|
|
121
|
-
*/
|
|
122
|
-
redirect(location: string | URL, status?: 301 | 302 | 303 | 307 | 308): void;
|
|
123
|
-
/**
|
|
124
|
-
* Creates an HTML response based on the `head` elements, `Layout`(s), and `Page` provided.
|
|
125
|
-
*
|
|
126
|
-
* @param Page `JSX.Element` to inject into the `<body>`
|
|
127
|
-
* @param status [HTTP response status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)
|
|
128
|
-
*/
|
|
129
|
-
page(Page: JSX.Element, status?: number): void;
|
|
130
|
-
/**
|
|
131
|
-
* Generates an etag from a hash of the string provided.
|
|
132
|
-
* If the etag matches, sets the response to not modified.
|
|
133
|
-
*
|
|
134
|
-
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)
|
|
135
|
-
*
|
|
136
|
-
* @param s string to hash
|
|
137
|
-
* @returns `true` if the etag matches, `false` otherwise
|
|
138
|
-
*/
|
|
139
|
-
etag(s: string): boolean;
|
|
140
|
-
/**
|
|
141
|
-
* Composes a stack of `middleware` into a `Response`.
|
|
142
|
-
*
|
|
143
|
-
* @param middleware stack to compose
|
|
144
|
-
* @returns constructed `Response`
|
|
145
|
-
*/
|
|
146
|
-
build(middleware: Middleware<P>[]): Promise<Response>;
|
|
147
|
-
}
|
|
148
|
-
export {};
|
|
149
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/app/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAY,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,KAAK,GAAG,CAAC,OAAO,CAAC;AAUhE,qBAAa,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;;IAC7C;;;;OAIG;IACH,GAAG,EAAE,OAAO,CAAC;IAEb;;;;OAIG;IACH,GAAG,EAAE,GAAG,CAAC;IAET;;;;;;;OAOG;IACH,MAAM,EAAE,CAAC,CAAW;IAEpB,gCAAgC;IAChC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAQ;IAE5C,+FAA+F;IAC/F,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAQ;IAE7B,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,OAAO,UAAiB;IAExB,yFAAyF;IACzF,OAAO,EAAE,MAAM,EAAE,CAAM;IAEvB,0CAA0C;IAC1C,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,CAAM;IAEzB;;;;;;;;;;;;OAYG;IACH,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,CAGrB;IAEF;;;;;;OAMG;IACH,IAAI,SAAM;IAEV,qDAAqD;IACrD,IAAI,OAAc;IAMlB;;;;OAIG;gBACS,GAAG,EAAE,OAAO;IAKxB;;;;;OAKG;IACH,GAAG,CACF,IAAI,EAAE,QAAQ,GAAG,IAAI,EACrB,IAAI,CAAC,EAAE;QACN;;;;WAIG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAEhB,gFAAgF;QAChF,OAAO,CAAC,EAAE,WAAW,CAAC;KACtB;IAYF;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM;IAO3C;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,MAAM;IAO/B;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAOpC;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,EAAE,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS;IAI1E;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM;IAwCvC;;;;;;;;OAQG;IACH,IAAI,CAAC,CAAC,EAAE,MAAM;IA6Cd;;;;;OAKG;IACG,KAAK,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE;CAOvC"}
|