ovr 6.0.1 → 6.2.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 +2 -0
- package/dist/app/index.d.ts +1 -1
- package/dist/app/index.d.ts.map +1 -1
- package/dist/app/index.js +17 -11
- package/dist/context/index.d.ts +37 -13
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +70 -29
- package/dist/cookie/index.d.ts +1 -1
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/cookie/index.js +2 -2
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/jsx/elements.d.ts +194 -2
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +18 -8
- package/dist/middleware/index.d.ts +12 -3
- package/dist/middleware/index.d.ts.map +1 -1
- package/dist/multipart/index.d.ts +5 -0
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +22 -24
- package/dist/render/index.d.ts +1 -0
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +6 -4
- package/dist/route/index.d.ts +143 -42
- package/dist/route/index.d.ts.map +1 -1
- package/dist/route/index.js +95 -43
- package/dist/schema/index.d.ts +1286 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +1321 -0
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +8 -2
- package/dist/util/index.d.ts +138 -9
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +152 -19
- package/package.json +4 -1
- package/src/app/index.ts +17 -15
- package/src/context/index.ts +116 -40
- package/src/cookie/index.ts +5 -5
- package/src/index.ts +4 -3
- package/src/jsx/elements.ts +320 -64
- package/src/jsx/index.ts +16 -8
- package/src/middleware/index.ts +19 -8
- package/src/multipart/index.ts +25 -27
- package/src/render/index.ts +7 -4
- package/src/route/index.ts +338 -94
- package/src/schema/index.ts +2794 -0
- package/src/trie/index.ts +12 -2
- package/src/util/index.ts +193 -19
package/src/trie/index.ts
CHANGED
|
@@ -54,7 +54,7 @@ export class Trie {
|
|
|
54
54
|
this.seg = segment;
|
|
55
55
|
|
|
56
56
|
if (children?.length) {
|
|
57
|
-
this.map
|
|
57
|
+
this.map = new Map();
|
|
58
58
|
|
|
59
59
|
for (const child of children) {
|
|
60
60
|
this.map.set(child.seg.charCodeAt(0), child);
|
|
@@ -120,7 +120,17 @@ export class Trie {
|
|
|
120
120
|
* @returns the existing child with the same name, or creates a new
|
|
121
121
|
*/
|
|
122
122
|
set(name: string) {
|
|
123
|
-
|
|
123
|
+
if (this.param) {
|
|
124
|
+
if (this.param.name !== name) {
|
|
125
|
+
throw new TypeError(
|
|
126
|
+
`Conflicting param names "${this.param.name}" and "${name}"`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return this.param;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return (this.param = new ParamNode(name));
|
|
124
134
|
}
|
|
125
135
|
|
|
126
136
|
/**
|
package/src/util/index.ts
CHANGED
|
@@ -1,25 +1,112 @@
|
|
|
1
1
|
/** General utility types */
|
|
2
2
|
export namespace Util {
|
|
3
|
+
/**
|
|
4
|
+
* Function type wrapper that opts into bivariant parameter checking.
|
|
5
|
+
*
|
|
6
|
+
* Useful for public structural types that need to accept handlers from
|
|
7
|
+
* compatible but differently-parameterized generic instances.
|
|
8
|
+
*
|
|
9
|
+
* @template Fn Function type
|
|
10
|
+
*/
|
|
11
|
+
export type Bivariant<Fn extends (...args: any[]) => any> = {
|
|
12
|
+
bivariant(...args: Parameters<Fn>): ReturnType<Fn>;
|
|
13
|
+
}["bivariant"];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Recursive array type that allows a value or nested arrays of that value.
|
|
17
|
+
*
|
|
18
|
+
* @template T Item type
|
|
19
|
+
*/
|
|
3
20
|
export type DeepArray<T> = T | DeepArray<T>[];
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Flattens an inferred object type for improved readability in tooling.
|
|
24
|
+
*
|
|
25
|
+
* @template T Object type to normalize
|
|
26
|
+
*/
|
|
27
|
+
export type Prettify<T> = { [K in keyof T]: T[K] } & {};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Media type utils */
|
|
31
|
+
export class Mime {
|
|
32
|
+
/** Mime type constants */
|
|
33
|
+
static type = {
|
|
34
|
+
html: Mime.#text("html"),
|
|
35
|
+
text: Mime.#text("plain"),
|
|
36
|
+
json: Mime.#application("json"),
|
|
37
|
+
stream: Mime.#application("octet-stream"),
|
|
38
|
+
mp: "multipart/form-data",
|
|
39
|
+
} as const;
|
|
40
|
+
|
|
41
|
+
static #text<T extends string>(type: T) {
|
|
42
|
+
return `text/${type}` as const;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static #application<T extends string>(type: T) {
|
|
46
|
+
return `application/${type}` as const;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static readonly #markup = new Set<string>([
|
|
50
|
+
Mime.type.html,
|
|
51
|
+
Mime.#text("xml"),
|
|
52
|
+
Mime.#application("xml"),
|
|
53
|
+
]);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @param mime Media type
|
|
57
|
+
* @returns `true` if the mime is markup
|
|
58
|
+
*/
|
|
59
|
+
static markup(mime: string) {
|
|
60
|
+
return (
|
|
61
|
+
Mime.#markup.has(mime) ||
|
|
62
|
+
// covers other xml types like svg
|
|
63
|
+
mime.includes("+xml")
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param mime Media type
|
|
69
|
+
* @returns `true` if the mime is multipart
|
|
70
|
+
*/
|
|
71
|
+
static multipart(mime: string | null) {
|
|
72
|
+
return mime?.startsWith("multipart/");
|
|
73
|
+
}
|
|
4
74
|
}
|
|
5
75
|
|
|
6
76
|
/** Header parsing utils */
|
|
7
77
|
export class Header {
|
|
8
|
-
|
|
78
|
+
/** Header name constants */
|
|
79
|
+
static readonly name = {
|
|
80
|
+
type: "content-type",
|
|
81
|
+
disp: "content-disposition",
|
|
82
|
+
etag: "etag",
|
|
83
|
+
cache: "cache-control",
|
|
84
|
+
none: "if-none-match",
|
|
85
|
+
cookie: "cookie",
|
|
86
|
+
set: "set-cookie",
|
|
87
|
+
loc: "location",
|
|
88
|
+
origin: "origin",
|
|
89
|
+
fetch: "sec-fetch-site",
|
|
90
|
+
} as const;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @param mime
|
|
94
|
+
* @returns mime; charset=utf-8
|
|
95
|
+
*/
|
|
96
|
+
static utf8<M extends string>(mime: M) {
|
|
97
|
+
return `${mime}; charset=utf-8` as const;
|
|
98
|
+
}
|
|
9
99
|
|
|
10
100
|
/**
|
|
11
101
|
* @param header header value to parse
|
|
12
102
|
* @returns Base/first param
|
|
13
103
|
*/
|
|
14
104
|
static shift(header: string | null): [string | null, string | null] {
|
|
15
|
-
|
|
16
|
-
const semi = header.indexOf(";");
|
|
17
|
-
if (semi !== -1) {
|
|
18
|
-
return [header.slice(0, semi), header.slice(semi)];
|
|
19
|
-
}
|
|
20
|
-
}
|
|
105
|
+
const semi = header?.indexOf(";") ?? -1;
|
|
21
106
|
|
|
22
|
-
return
|
|
107
|
+
return semi === -1
|
|
108
|
+
? [header, null]
|
|
109
|
+
: [header!.slice(0, semi), header!.slice(semi)];
|
|
23
110
|
}
|
|
24
111
|
|
|
25
112
|
/**
|
|
@@ -79,21 +166,21 @@ export class Header {
|
|
|
79
166
|
}
|
|
80
167
|
}
|
|
81
168
|
|
|
82
|
-
/**
|
|
83
|
-
export class
|
|
169
|
+
/** Checksum util */
|
|
170
|
+
export class Checksum {
|
|
84
171
|
/**
|
|
85
|
-
* Fast
|
|
172
|
+
* Fast checksum algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
86
173
|
*
|
|
87
|
-
* @param s String to
|
|
88
|
-
* @returns
|
|
174
|
+
* @param s String to check
|
|
175
|
+
* @returns Checksum
|
|
89
176
|
*/
|
|
90
177
|
static djb2(s: string) {
|
|
91
|
-
let
|
|
178
|
+
let c = 5381;
|
|
92
179
|
let i = s.length;
|
|
93
180
|
|
|
94
|
-
while (i)
|
|
181
|
+
while (i) c = (c * 33) ^ s.charCodeAt(--i);
|
|
95
182
|
|
|
96
|
-
return (
|
|
183
|
+
return (c >>> 0).toString(36);
|
|
97
184
|
}
|
|
98
185
|
}
|
|
99
186
|
|
|
@@ -102,8 +189,95 @@ export class Codec {
|
|
|
102
189
|
static #encoder = new TextEncoder();
|
|
103
190
|
static #decoder = new TextDecoder("utf-8", { fatal: true });
|
|
104
191
|
|
|
105
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Encodes a string into UTF-8 bytes.
|
|
194
|
+
*
|
|
195
|
+
* @param s String to encode
|
|
196
|
+
* @returns UTF-8 bytes
|
|
197
|
+
*/
|
|
198
|
+
static encode(s: string) {
|
|
199
|
+
return Codec.#encoder.encode(s);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Decodes UTF-8 bytes into a string.
|
|
204
|
+
*
|
|
205
|
+
* Note: do not use this for incremental/stream decoding.
|
|
206
|
+
*
|
|
207
|
+
* @param bytes UTF-8 bytes
|
|
208
|
+
* @returns Decoded string
|
|
209
|
+
*/
|
|
210
|
+
static decode(bytes?: Uint8Array) {
|
|
211
|
+
return Codec.#decoder.decode(bytes);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
static readonly Base64 = class Base64 {
|
|
215
|
+
/**
|
|
216
|
+
* Encodes bytes into a Base64 string.
|
|
217
|
+
*
|
|
218
|
+
* @param bytes Bytes to encode
|
|
219
|
+
* @returns Base64 string
|
|
220
|
+
*/
|
|
221
|
+
static encode(bytes: Uint8Array) {
|
|
222
|
+
return btoa(String.fromCharCode(...bytes));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Decodes a Base64 string into bytes.
|
|
227
|
+
*
|
|
228
|
+
* @param s Base64 string
|
|
229
|
+
* @returns Decoded bytes
|
|
230
|
+
*/
|
|
231
|
+
static decode(s: string) {
|
|
232
|
+
return Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
233
|
+
}
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
static readonly Base64Url = class Base64Url {
|
|
237
|
+
/**
|
|
238
|
+
* Encodes bytes into a Base64Url string.
|
|
239
|
+
*
|
|
240
|
+
* @param bytes Bytes to encode
|
|
241
|
+
* @returns Base64Url string
|
|
242
|
+
*/
|
|
243
|
+
static encode(bytes: Uint8Array) {
|
|
244
|
+
return btoa(String.fromCharCode(...bytes))
|
|
245
|
+
.replace(/[+/]/g, (c) => (c === "+" ? "-" : "_"))
|
|
246
|
+
.replace(/=+$/, "");
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Decodes a Base64Url string into bytes.
|
|
251
|
+
*
|
|
252
|
+
* @param s Base64Url string
|
|
253
|
+
* @returns Decoded bytes
|
|
254
|
+
*/
|
|
255
|
+
static decode(s: string) {
|
|
256
|
+
const b64 = s.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
|
|
257
|
+
|
|
258
|
+
return Codec.Base64.decode(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/** HTTP methods */
|
|
264
|
+
export class Method {
|
|
265
|
+
static readonly get = "GET";
|
|
266
|
+
static readonly post = "POST";
|
|
267
|
+
static readonly head = "HEAD";
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/** Byte size constants */
|
|
271
|
+
export class Size {
|
|
272
|
+
static readonly kb = 1024;
|
|
273
|
+
static readonly mb = 1024 * Size.kb;
|
|
274
|
+
}
|
|
106
275
|
|
|
107
|
-
|
|
108
|
-
|
|
276
|
+
/** Times in milliseconds */
|
|
277
|
+
export class Time {
|
|
278
|
+
static readonly second = 1000;
|
|
279
|
+
static readonly minute = 60 * Time.second;
|
|
280
|
+
static readonly hour = 60 * Time.minute;
|
|
281
|
+
static readonly day = 24 * Time.hour;
|
|
282
|
+
static readonly week = 7 * Time.day;
|
|
109
283
|
}
|