ovr 6.1.0 → 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.map +1 -1
- package/dist/app/index.js +13 -9
- package/dist/context/index.d.ts +33 -9
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +61 -17
- 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/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 +20 -22
- 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 +94 -42
- 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 +113 -19
- package/dist/util/index.d.ts.map +1 -1
- package/dist/util/index.js +111 -35
- package/package.json +4 -1
- package/src/app/index.ts +13 -12
- package/src/context/index.ts +104 -25
- package/src/cookie/index.ts +3 -3
- package/src/index.ts +4 -3
- package/src/middleware/index.ts +19 -8
- package/src/multipart/index.ts +23 -24
- package/src/render/index.ts +7 -4
- package/src/route/index.ts +336 -95
- package/src/schema/index.ts +2794 -0
- package/src/trie/index.ts +12 -2
- package/src/util/index.ts +142 -36
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":"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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;IAchB;;;OAGG;IACH,GAAG,CAAC,KAAK,EAAE,KAAK;IA6GhB;;;OAGG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG;QAAE,KAAK,EAAE,KAAK,CAAC;QAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAA;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,15 +1,42 @@
|
|
|
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
|
+
} & {};
|
|
4
28
|
}
|
|
5
29
|
/** Media type utils */
|
|
6
30
|
export declare class Mime {
|
|
7
31
|
#private;
|
|
8
|
-
|
|
9
|
-
static
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
};
|
|
13
40
|
/**
|
|
14
41
|
* @param mime Media type
|
|
15
42
|
* @returns `true` if the mime is markup
|
|
@@ -23,12 +50,19 @@ export declare class Mime {
|
|
|
23
50
|
}
|
|
24
51
|
/** Header parsing utils */
|
|
25
52
|
export declare class Header {
|
|
26
|
-
|
|
27
|
-
static readonly
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
};
|
|
32
66
|
/**
|
|
33
67
|
* @param mime
|
|
34
68
|
* @returns mime; charset=utf-8
|
|
@@ -45,22 +79,69 @@ export declare class Header {
|
|
|
45
79
|
*/
|
|
46
80
|
static params(header: string | null): Record<string, string>;
|
|
47
81
|
}
|
|
48
|
-
/**
|
|
49
|
-
export declare class
|
|
82
|
+
/** Checksum util */
|
|
83
|
+
export declare class Checksum {
|
|
50
84
|
/**
|
|
51
|
-
* Fast
|
|
85
|
+
* Fast checksum algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
52
86
|
*
|
|
53
|
-
* @param s String to
|
|
54
|
-
* @returns
|
|
87
|
+
* @param s String to check
|
|
88
|
+
* @returns Checksum
|
|
55
89
|
*/
|
|
56
90
|
static djb2(s: string): string;
|
|
57
91
|
}
|
|
58
92
|
/** Shared encoding to use across features */
|
|
59
93
|
export declare class Codec {
|
|
60
94
|
#private;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
};
|
|
64
145
|
}
|
|
65
146
|
/** HTTP methods */
|
|
66
147
|
export declare class Method {
|
|
@@ -68,4 +149,17 @@ export declare class Method {
|
|
|
68
149
|
static readonly post = "POST";
|
|
69
150
|
static readonly head = "HEAD";
|
|
70
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;
|
|
164
|
+
}
|
|
71
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,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA,4BAA4B;AAC5B,yBAAiB,IAAI,CAAC;IACrB;;;;;;;OAOG;IACH,KAAY,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IAAI;QAC3D,SAAS,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC;KACnD,CAAC,WAAW,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B,UAAU;QAI/B;;;;;WAKG;kBACc,MAAM;MAGtB;IAEF,MAAM,CAAC,QAAQ,CAAC,SAAS;;QACxB;;;;;WAKG;sBACkB,UAAU;QAM/B;;;;;WAKG;kBACc,MAAM;MAKtB;CACF;AAED,mBAAmB;AACnB,qBAAa,MAAM;IAClB,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAC5B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAC9B,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;CAC9B;AAED,0BAA0B;AAC1B,qBAAa,IAAI;IAChB,MAAM,CAAC,QAAQ,CAAC,EAAE,QAAQ;IAC1B,MAAM,CAAC,QAAQ,CAAC,EAAE,SAAkB;CACpC;AAED,4BAA4B;AAC5B,qBAAa,IAAI;IAChB,MAAM,CAAC,QAAQ,CAAC,MAAM,QAAQ;IAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,SAAoB;IAC1C,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAoB;IACxC,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAkB;IACrC,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAgB;CACpC"}
|
package/dist/util/index.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
/** Media type utils */
|
|
2
2
|
export class Mime {
|
|
3
|
-
|
|
4
|
-
static
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/** Mime type constants */
|
|
4
|
+
static type = {
|
|
5
|
+
html: Mime.#text("html"),
|
|
6
|
+
text: Mime.#text("plain"),
|
|
7
|
+
json: Mime.#application("json"),
|
|
8
|
+
stream: Mime.#application("octet-stream"),
|
|
9
|
+
mp: "multipart/form-data",
|
|
10
|
+
};
|
|
9
11
|
static #text(type) {
|
|
10
12
|
return `text/${type}`;
|
|
11
13
|
}
|
|
12
14
|
static #application(type) {
|
|
13
15
|
return `application/${type}`;
|
|
14
16
|
}
|
|
15
|
-
static #multipart(type) {
|
|
16
|
-
return `${Mime.#multipartBase}${type}`;
|
|
17
|
-
}
|
|
18
17
|
static #markup = new Set([
|
|
19
|
-
Mime.html,
|
|
18
|
+
Mime.type.html,
|
|
20
19
|
Mime.#text("xml"),
|
|
21
20
|
Mime.#application("xml"),
|
|
22
21
|
]);
|
|
@@ -34,17 +33,24 @@ export class Mime {
|
|
|
34
33
|
* @returns `true` if the mime is multipart
|
|
35
34
|
*/
|
|
36
35
|
static multipart(mime) {
|
|
37
|
-
return mime?.startsWith(
|
|
36
|
+
return mime?.startsWith("multipart/");
|
|
38
37
|
}
|
|
39
38
|
}
|
|
40
39
|
/** Header parsing utils */
|
|
41
40
|
export class Header {
|
|
42
|
-
|
|
43
|
-
static
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
+
};
|
|
48
54
|
/**
|
|
49
55
|
* @param mime
|
|
50
56
|
* @returns mime; charset=utf-8
|
|
@@ -57,13 +63,10 @@ export class Header {
|
|
|
57
63
|
* @returns Base/first param
|
|
58
64
|
*/
|
|
59
65
|
static shift(header) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return [header, null];
|
|
66
|
+
const semi = header?.indexOf(";") ?? -1;
|
|
67
|
+
return semi === -1
|
|
68
|
+
? [header, null]
|
|
69
|
+
: [header.slice(0, semi), header.slice(semi)];
|
|
67
70
|
}
|
|
68
71
|
/**
|
|
69
72
|
* @param header header value to parse
|
|
@@ -112,29 +115,89 @@ export class Header {
|
|
|
112
115
|
return parsed;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
|
-
/**
|
|
116
|
-
export class
|
|
118
|
+
/** Checksum util */
|
|
119
|
+
export class Checksum {
|
|
117
120
|
/**
|
|
118
|
-
* Fast
|
|
121
|
+
* Fast checksum algorithm - [djb2](http://www.cse.yorku.ca/~oz/hash.html)
|
|
119
122
|
*
|
|
120
|
-
* @param s String to
|
|
121
|
-
* @returns
|
|
123
|
+
* @param s String to check
|
|
124
|
+
* @returns Checksum
|
|
122
125
|
*/
|
|
123
126
|
static djb2(s) {
|
|
124
|
-
let
|
|
127
|
+
let c = 5381;
|
|
125
128
|
let i = s.length;
|
|
126
129
|
while (i)
|
|
127
|
-
|
|
128
|
-
return (
|
|
130
|
+
c = (c * 33) ^ s.charCodeAt(--i);
|
|
131
|
+
return (c >>> 0).toString(36);
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
/** Shared encoding to use across features */
|
|
132
135
|
export class Codec {
|
|
133
136
|
static #encoder = new TextEncoder();
|
|
134
137
|
static #decoder = new TextDecoder("utf-8", { fatal: true });
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
+
};
|
|
138
201
|
}
|
|
139
202
|
/** HTTP methods */
|
|
140
203
|
export class Method {
|
|
@@ -142,3 +205,16 @@ export class Method {
|
|
|
142
205
|
static post = "POST";
|
|
143
206
|
static head = "HEAD";
|
|
144
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;
|
|
220
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ovr",
|
|
3
3
|
"description": "The Streaming Framework",
|
|
4
|
-
"version": "6.
|
|
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 { Method, type Util } from "../util/index.js";
|
|
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);
|
|
@@ -134,8 +135,8 @@ export class App {
|
|
|
134
135
|
if (
|
|
135
136
|
c.req.method === Method.get ||
|
|
136
137
|
c.req.method === Method.head ||
|
|
137
|
-
c.req.headers.get(
|
|
138
|
-
c.req.headers.get(
|
|
138
|
+
c.req.headers.get(Header.name.fetch) === "same-origin" ||
|
|
139
|
+
c.req.headers.get(Header.name.origin) === c.url.origin
|
|
139
140
|
) {
|
|
140
141
|
return next();
|
|
141
142
|
}
|
|
@@ -150,12 +151,12 @@ export class App {
|
|
|
150
151
|
|
|
151
152
|
if (c.res.status && c.res.status !== 404) return;
|
|
152
153
|
|
|
153
|
-
const
|
|
154
|
+
const slash = c.url.pathname.endsWith("/");
|
|
154
155
|
|
|
155
|
-
if (mode === "always" &&
|
|
156
|
+
if (mode === "always" && !slash) {
|
|
156
157
|
c.url.pathname += "/";
|
|
157
158
|
c.redirect(c.url, 308);
|
|
158
|
-
} else if (mode === "never" && c.url.pathname !== "/" &&
|
|
159
|
+
} else if (mode === "never" && c.url.pathname !== "/" && slash) {
|
|
159
160
|
c.url.pathname = c.url.pathname.slice(0, -1);
|
|
160
161
|
c.redirect(c.url, 308);
|
|
161
162
|
}
|