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/dist/trie/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/trie/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,cAAM,SAAS;IACd,oDAAoD;IACpD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,oBAAoB;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd,wBAAwB;IACxB,KAAK,CAAC,EAAE,IAAI,CAAC;IAEb;;;;OAIG;gBACS,IAAI,EAAE,MAAM;CAGxB;AAED,yBAAiB,IAAI,CAAC;IACrB,0CAA0C;IAC1C,KAAY,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC5C;AAED,qBAAa,IAAI;;IAChB,yCAAyC;IACzC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAErB,uEAAuE;IACvE,GAAG,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAExB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,SAAS,CAAC;IAElB,oBAAoB;IACpB,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd,6BAA6B;IAC7B,IAAI,CAAC,EAAE,KAAK,CAAC;IAKb;;;;;OAKG;gBACS,OAAO,SAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE;IAY5C;;;OAGG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAWrB;;;;;;;;OAQG;IACH,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;IAevC;;;;;;OAMG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM;IAOrB;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM;
|
|
1
|
+
{"version":3,"file":"index.d.ts","source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AA;KAAE,GAAG,IAAI;CA2EpE"}
|
package/dist/trie/index.js
CHANGED
|
@@ -36,7 +36,7 @@ export class Trie {
|
|
|
36
36
|
constructor(segment = "/", children) {
|
|
37
37
|
this.seg = segment;
|
|
38
38
|
if (children?.length) {
|
|
39
|
-
this.map
|
|
39
|
+
this.map = new Map();
|
|
40
40
|
for (const child of children) {
|
|
41
41
|
this.map.set(child.seg.charCodeAt(0), child);
|
|
42
42
|
}
|
|
@@ -88,7 +88,13 @@ export class Trie {
|
|
|
88
88
|
* @returns the existing child with the same name, or creates a new
|
|
89
89
|
*/
|
|
90
90
|
set(name) {
|
|
91
|
-
|
|
91
|
+
if (this.param) {
|
|
92
|
+
if (this.param.name !== name) {
|
|
93
|
+
throw new TypeError(`Conflicting param names "${this.param.name}" and "${name}"`);
|
|
94
|
+
}
|
|
95
|
+
return this.param;
|
|
96
|
+
}
|
|
97
|
+
return (this.param = new ParamNode(name));
|
|
92
98
|
}
|
|
93
99
|
/**
|
|
94
100
|
* @param route route return when pattern is matched
|
package/dist/util/index.d.ts
CHANGED
|
@@ -1,10 +1,73 @@
|
|
|
1
1
|
/** General utility types */
|
|
2
2
|
export declare 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
|
+
type Bivariant<Fn extends (...args: any[]) => any> = {
|
|
12
|
+
bivariant(...args: Parameters<Fn>): ReturnType<Fn>;
|
|
13
|
+
}["bivariant"];
|
|
14
|
+
/**
|
|
15
|
+
* Recursive array type that allows a value or nested arrays of that value.
|
|
16
|
+
*
|
|
17
|
+
* @template T Item type
|
|
18
|
+
*/
|
|
3
19
|
type DeepArray<T> = T | DeepArray<T>[];
|
|
20
|
+
/**
|
|
21
|
+
* Flattens an inferred object type for improved readability in tooling.
|
|
22
|
+
*
|
|
23
|
+
* @template T Object type to normalize
|
|
24
|
+
*/
|
|
25
|
+
type Prettify<T> = {
|
|
26
|
+
[K in keyof T]: T[K];
|
|
27
|
+
} & {};
|
|
28
|
+
}
|
|
29
|
+
/** Media type utils */
|
|
30
|
+
export declare class Mime {
|
|
31
|
+
#private;
|
|
32
|
+
/** Mime type constants */
|
|
33
|
+
static type: {
|
|
34
|
+
readonly html: "text/html";
|
|
35
|
+
readonly text: "text/plain";
|
|
36
|
+
readonly json: "application/json";
|
|
37
|
+
readonly stream: "application/octet-stream";
|
|
38
|
+
readonly mp: "multipart/form-data";
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* @param mime Media type
|
|
42
|
+
* @returns `true` if the mime is markup
|
|
43
|
+
*/
|
|
44
|
+
static markup(mime: string): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* @param mime Media type
|
|
47
|
+
* @returns `true` if the mime is multipart
|
|
48
|
+
*/
|
|
49
|
+
static multipart(mime: string | null): boolean | undefined;
|
|
4
50
|
}
|
|
5
51
|
/** Header parsing utils */
|
|
6
52
|
export declare class Header {
|
|
7
|
-
|
|
53
|
+
/** Header name constants */
|
|
54
|
+
static readonly name: {
|
|
55
|
+
readonly type: "content-type";
|
|
56
|
+
readonly disp: "content-disposition";
|
|
57
|
+
readonly etag: "etag";
|
|
58
|
+
readonly cache: "cache-control";
|
|
59
|
+
readonly none: "if-none-match";
|
|
60
|
+
readonly cookie: "cookie";
|
|
61
|
+
readonly set: "set-cookie";
|
|
62
|
+
readonly loc: "location";
|
|
63
|
+
readonly origin: "origin";
|
|
64
|
+
readonly fetch: "sec-fetch-site";
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* @param mime
|
|
68
|
+
* @returns mime; charset=utf-8
|
|
69
|
+
*/
|
|
70
|
+
static utf8<M extends string>(mime: M): `${M}; charset=utf-8`;
|
|
8
71
|
/**
|
|
9
72
|
* @param header header value to parse
|
|
10
73
|
* @returns Base/first param
|
|
@@ -16,21 +79,87 @@ export declare class Header {
|
|
|
16
79
|
*/
|
|
17
80
|
static params(header: string | null): Record<string, string>;
|
|
18
81
|
}
|
|
19
|
-
/**
|
|
20
|
-
export declare class
|
|
82
|
+
/** Checksum util */
|
|
83
|
+
export declare class Checksum {
|
|
21
84
|
/**
|
|
22
|
-
* Fast
|
|
85
|
+
* Fast checksum algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
23
86
|
*
|
|
24
|
-
* @param s String to
|
|
25
|
-
* @returns
|
|
87
|
+
* @param s String to check
|
|
88
|
+
* @returns Checksum
|
|
26
89
|
*/
|
|
27
90
|
static djb2(s: string): string;
|
|
28
91
|
}
|
|
29
92
|
/** Shared encoding to use across features */
|
|
30
93
|
export declare class Codec {
|
|
31
94
|
#private;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Encodes a string into UTF-8 bytes.
|
|
97
|
+
*
|
|
98
|
+
* @param s String to encode
|
|
99
|
+
* @returns UTF-8 bytes
|
|
100
|
+
*/
|
|
101
|
+
static encode(s: string): Uint8Array<ArrayBuffer>;
|
|
102
|
+
/**
|
|
103
|
+
* Decodes UTF-8 bytes into a string.
|
|
104
|
+
*
|
|
105
|
+
* Note: do not use this for incremental/stream decoding.
|
|
106
|
+
*
|
|
107
|
+
* @param bytes UTF-8 bytes
|
|
108
|
+
* @returns Decoded string
|
|
109
|
+
*/
|
|
110
|
+
static decode(bytes?: Uint8Array): string;
|
|
111
|
+
static readonly Base64: {
|
|
112
|
+
new (): {};
|
|
113
|
+
/**
|
|
114
|
+
* Encodes bytes into a Base64 string.
|
|
115
|
+
*
|
|
116
|
+
* @param bytes Bytes to encode
|
|
117
|
+
* @returns Base64 string
|
|
118
|
+
*/
|
|
119
|
+
encode(bytes: Uint8Array): string;
|
|
120
|
+
/**
|
|
121
|
+
* Decodes a Base64 string into bytes.
|
|
122
|
+
*
|
|
123
|
+
* @param s Base64 string
|
|
124
|
+
* @returns Decoded bytes
|
|
125
|
+
*/
|
|
126
|
+
decode(s: string): Uint8Array<ArrayBuffer>;
|
|
127
|
+
};
|
|
128
|
+
static readonly Base64Url: {
|
|
129
|
+
new (): {};
|
|
130
|
+
/**
|
|
131
|
+
* Encodes bytes into a Base64Url string.
|
|
132
|
+
*
|
|
133
|
+
* @param bytes Bytes to encode
|
|
134
|
+
* @returns Base64Url string
|
|
135
|
+
*/
|
|
136
|
+
encode(bytes: Uint8Array): string;
|
|
137
|
+
/**
|
|
138
|
+
* Decodes a Base64Url string into bytes.
|
|
139
|
+
*
|
|
140
|
+
* @param s Base64Url string
|
|
141
|
+
* @returns Decoded bytes
|
|
142
|
+
*/
|
|
143
|
+
decode(s: string): Uint8Array<ArrayBuffer>;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** HTTP methods */
|
|
147
|
+
export declare class Method {
|
|
148
|
+
static readonly get = "GET";
|
|
149
|
+
static readonly post = "POST";
|
|
150
|
+
static readonly head = "HEAD";
|
|
151
|
+
}
|
|
152
|
+
/** Byte size constants */
|
|
153
|
+
export declare class Size {
|
|
154
|
+
static readonly kb = 1024;
|
|
155
|
+
static readonly mb: number;
|
|
156
|
+
}
|
|
157
|
+
/** Times in milliseconds */
|
|
158
|
+
export declare class Time {
|
|
159
|
+
static readonly second = 1000;
|
|
160
|
+
static readonly minute: number;
|
|
161
|
+
static readonly hour: number;
|
|
162
|
+
static readonly day: number;
|
|
163
|
+
static readonly week: number;
|
|
35
164
|
}
|
|
36
165
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/util/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yBAAiB,IAAI,CAAC;IACrB,KAAY,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,C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
|
|
6
|
+
text: Mime.#text("plain"),
|
|
7
|
+
json: Mime.#application("json"),
|
|
8
|
+
stream: Mime.#application("octet-stream"),
|
|
9
|
+
mp: "multipart/form-data",
|
|
10
|
+
};
|
|
11
|
+
static #text(type) {
|
|
12
|
+
return `text/${type}`;
|
|
13
|
+
}
|
|
14
|
+
static #application(type) {
|
|
15
|
+
return `application/${type}`;
|
|
16
|
+
}
|
|
17
|
+
static #markup = new Set([
|
|
18
|
+
Mime.type.html,
|
|
19
|
+
Mime.#text("xml"),
|
|
20
|
+
Mime.#application("xml"),
|
|
21
|
+
]);
|
|
22
|
+
/**
|
|
23
|
+
* @param mime Media type
|
|
24
|
+
* @returns `true` if the mime is markup
|
|
25
|
+
*/
|
|
26
|
+
static markup(mime) {
|
|
27
|
+
return (Mime.#markup.has(mime) ||
|
|
28
|
+
// covers other xml types like svg
|
|
29
|
+
mime.includes("+xml"));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @param mime Media type
|
|
33
|
+
* @returns `true` if the mime is multipart
|
|
34
|
+
*/
|
|
35
|
+
static multipart(mime) {
|
|
36
|
+
return mime?.startsWith("multipart/");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
1
39
|
/** Header parsing utils */
|
|
2
40
|
export class Header {
|
|
3
|
-
|
|
41
|
+
/** Header name constants */
|
|
42
|
+
static name = {
|
|
43
|
+
type: "content-type",
|
|
44
|
+
disp: "content-disposition",
|
|
45
|
+
etag: "etag",
|
|
46
|
+
cache: "cache-control",
|
|
47
|
+
none: "if-none-match",
|
|
48
|
+
cookie: "cookie",
|
|
49
|
+
set: "set-cookie",
|
|
50
|
+
loc: "location",
|
|
51
|
+
origin: "origin",
|
|
52
|
+
fetch: "sec-fetch-site",
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* @param mime
|
|
56
|
+
* @returns mime; charset=utf-8
|
|
57
|
+
*/
|
|
58
|
+
static utf8(mime) {
|
|
59
|
+
return `${mime}; charset=utf-8`;
|
|
60
|
+
}
|
|
4
61
|
/**
|
|
5
62
|
* @param header header value to parse
|
|
6
63
|
* @returns Base/first param
|
|
7
64
|
*/
|
|
8
65
|
static shift(header) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
return [header, null];
|
|
66
|
+
const semi = header?.indexOf(";") ?? -1;
|
|
67
|
+
return semi === -1
|
|
68
|
+
? [header, null]
|
|
69
|
+
: [header.slice(0, semi), header.slice(semi)];
|
|
16
70
|
}
|
|
17
71
|
/**
|
|
18
72
|
* @param header header value to parse
|
|
@@ -61,27 +115,106 @@ export class Header {
|
|
|
61
115
|
return parsed;
|
|
62
116
|
}
|
|
63
117
|
}
|
|
64
|
-
/**
|
|
65
|
-
export class
|
|
118
|
+
/** Checksum util */
|
|
119
|
+
export class Checksum {
|
|
66
120
|
/**
|
|
67
|
-
* Fast
|
|
121
|
+
* Fast checksum algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
68
122
|
*
|
|
69
|
-
* @param s String to
|
|
70
|
-
* @returns
|
|
123
|
+
* @param s String to check
|
|
124
|
+
* @returns Checksum
|
|
71
125
|
*/
|
|
72
126
|
static djb2(s) {
|
|
73
|
-
let
|
|
127
|
+
let c = 5381;
|
|
74
128
|
let i = s.length;
|
|
75
129
|
while (i)
|
|
76
|
-
|
|
77
|
-
return (
|
|
130
|
+
c = (c * 33) ^ s.charCodeAt(--i);
|
|
131
|
+
return (c >>> 0).toString(36);
|
|
78
132
|
}
|
|
79
133
|
}
|
|
80
134
|
/** Shared encoding to use across features */
|
|
81
135
|
export class Codec {
|
|
82
136
|
static #encoder = new TextEncoder();
|
|
83
137
|
static #decoder = new TextDecoder("utf-8", { fatal: true });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Encodes a string into UTF-8 bytes.
|
|
140
|
+
*
|
|
141
|
+
* @param s String to encode
|
|
142
|
+
* @returns UTF-8 bytes
|
|
143
|
+
*/
|
|
144
|
+
static encode(s) {
|
|
145
|
+
return Codec.#encoder.encode(s);
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Decodes UTF-8 bytes into a string.
|
|
149
|
+
*
|
|
150
|
+
* Note: do not use this for incremental/stream decoding.
|
|
151
|
+
*
|
|
152
|
+
* @param bytes UTF-8 bytes
|
|
153
|
+
* @returns Decoded string
|
|
154
|
+
*/
|
|
155
|
+
static decode(bytes) {
|
|
156
|
+
return Codec.#decoder.decode(bytes);
|
|
157
|
+
}
|
|
158
|
+
static Base64 = class Base64 {
|
|
159
|
+
/**
|
|
160
|
+
* Encodes bytes into a Base64 string.
|
|
161
|
+
*
|
|
162
|
+
* @param bytes Bytes to encode
|
|
163
|
+
* @returns Base64 string
|
|
164
|
+
*/
|
|
165
|
+
static encode(bytes) {
|
|
166
|
+
return btoa(String.fromCharCode(...bytes));
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Decodes a Base64 string into bytes.
|
|
170
|
+
*
|
|
171
|
+
* @param s Base64 string
|
|
172
|
+
* @returns Decoded bytes
|
|
173
|
+
*/
|
|
174
|
+
static decode(s) {
|
|
175
|
+
return Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
static Base64Url = class Base64Url {
|
|
179
|
+
/**
|
|
180
|
+
* Encodes bytes into a Base64Url string.
|
|
181
|
+
*
|
|
182
|
+
* @param bytes Bytes to encode
|
|
183
|
+
* @returns Base64Url string
|
|
184
|
+
*/
|
|
185
|
+
static encode(bytes) {
|
|
186
|
+
return btoa(String.fromCharCode(...bytes))
|
|
187
|
+
.replace(/[+/]/g, (c) => (c === "+" ? "-" : "_"))
|
|
188
|
+
.replace(/=+$/, "");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Decodes a Base64Url string into bytes.
|
|
192
|
+
*
|
|
193
|
+
* @param s Base64Url string
|
|
194
|
+
* @returns Decoded bytes
|
|
195
|
+
*/
|
|
196
|
+
static decode(s) {
|
|
197
|
+
const b64 = s.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
|
|
198
|
+
return Codec.Base64.decode(b64 + "=".repeat((4 - (b64.length % 4)) % 4));
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/** HTTP methods */
|
|
203
|
+
export class Method {
|
|
204
|
+
static get = "GET";
|
|
205
|
+
static post = "POST";
|
|
206
|
+
static head = "HEAD";
|
|
207
|
+
}
|
|
208
|
+
/** Byte size constants */
|
|
209
|
+
export class Size {
|
|
210
|
+
static kb = 1024;
|
|
211
|
+
static mb = 1024 * Size.kb;
|
|
212
|
+
}
|
|
213
|
+
/** Times in milliseconds */
|
|
214
|
+
export class Time {
|
|
215
|
+
static second = 1000;
|
|
216
|
+
static minute = 60 * Time.second;
|
|
217
|
+
static hour = 60 * Time.minute;
|
|
218
|
+
static day = 24 * Time.hour;
|
|
219
|
+
static week = 7 * Time.day;
|
|
87
220
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ovr",
|
|
3
3
|
"description": "The Streaming Framework",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.2.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -41,5 +41,8 @@
|
|
|
41
41
|
"check": "tsc --noEmit",
|
|
42
42
|
"dev": "tsc --watch",
|
|
43
43
|
"build": "tsc && cp ../../LICENSE.md dist"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@standard-schema/spec": "^1.1.0"
|
|
44
47
|
}
|
|
45
48
|
}
|
package/src/app/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Middleware } from "../middleware/index.js";
|
|
|
3
3
|
import type { Multipart } from "../multipart/index.js";
|
|
4
4
|
import { Route } from "../route/index.js";
|
|
5
5
|
import { Trie } from "../trie/index.js";
|
|
6
|
-
import type
|
|
6
|
+
import { Header, Method, type Util } from "../util/index.js";
|
|
7
7
|
|
|
8
8
|
export namespace App {
|
|
9
9
|
export namespace Options {
|
|
@@ -64,12 +64,13 @@ export class App {
|
|
|
64
64
|
* @param options configuration options
|
|
65
65
|
*/
|
|
66
66
|
constructor(options?: App.Options) {
|
|
67
|
-
this.#options =
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
this.#options = {
|
|
68
|
+
csrf: true,
|
|
69
|
+
trailingSlash: "never" as const,
|
|
70
|
+
...options,
|
|
71
|
+
};
|
|
71
72
|
|
|
72
|
-
if (this.#options.csrf
|
|
73
|
+
if (this.#options.csrf) this.#global.push(App.#csrf);
|
|
73
74
|
|
|
74
75
|
if (this.#options.trailingSlash !== "ignore") {
|
|
75
76
|
this.#global.push(App.#createTrailingSlash(this.#options.trailingSlash));
|
|
@@ -88,7 +89,7 @@ export class App {
|
|
|
88
89
|
for (const route of routes) {
|
|
89
90
|
if (route instanceof Route) {
|
|
90
91
|
this.#trie.add(route);
|
|
91
|
-
} else if (route
|
|
92
|
+
} else if (Array.isArray(route)) {
|
|
92
93
|
this.use(...route);
|
|
93
94
|
} else if (typeof route === "function") {
|
|
94
95
|
this.#global.push(route);
|
|
@@ -121,7 +122,8 @@ export class App {
|
|
|
121
122
|
// match
|
|
122
123
|
this.#trie.find(
|
|
123
124
|
// use GET for HEAD requests to find the correct route
|
|
124
|
-
(c.req.method ===
|
|
125
|
+
(c.req.method === Method.head ? Method.get : c.req.method) +
|
|
126
|
+
c.url.pathname,
|
|
125
127
|
),
|
|
126
128
|
),
|
|
127
129
|
this.#global.concat(c.route?.middleware ?? []),
|
|
@@ -131,10 +133,10 @@ export class App {
|
|
|
131
133
|
/** Basic CSRF middleware */
|
|
132
134
|
static #csrf(c: Middleware.Context, next: Middleware.Next) {
|
|
133
135
|
if (
|
|
134
|
-
c.req.method ===
|
|
135
|
-
c.req.method ===
|
|
136
|
-
c.req.headers.get(
|
|
137
|
-
c.req.headers.get(
|
|
136
|
+
c.req.method === Method.get ||
|
|
137
|
+
c.req.method === Method.head ||
|
|
138
|
+
c.req.headers.get(Header.name.fetch) === "same-origin" ||
|
|
139
|
+
c.req.headers.get(Header.name.origin) === c.url.origin
|
|
138
140
|
) {
|
|
139
141
|
return next();
|
|
140
142
|
}
|
|
@@ -149,12 +151,12 @@ export class App {
|
|
|
149
151
|
|
|
150
152
|
if (c.res.status && c.res.status !== 404) return;
|
|
151
153
|
|
|
152
|
-
const
|
|
154
|
+
const slash = c.url.pathname.endsWith("/");
|
|
153
155
|
|
|
154
|
-
if (mode === "always" &&
|
|
156
|
+
if (mode === "always" && !slash) {
|
|
155
157
|
c.url.pathname += "/";
|
|
156
158
|
c.redirect(c.url, 308);
|
|
157
|
-
} else if (mode === "never" && c.url.pathname !== "/" &&
|
|
159
|
+
} else if (mode === "never" && c.url.pathname !== "/" && slash) {
|
|
158
160
|
c.url.pathname = c.url.pathname.slice(0, -1);
|
|
159
161
|
c.redirect(c.url, 308);
|
|
160
162
|
}
|