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/LICENSE.md
CHANGED
|
@@ -24,3 +24,5 @@ Portions of this software have been adapted from the following projects, which a
|
|
|
24
24
|
- Cookie handling - https://github.com/jshttp/cookie
|
|
25
25
|
Copyright (c) 2012-2014 Roman Shtylman <shtylman@gmail.com>
|
|
26
26
|
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
|
27
|
+
- Schema API - https://github.com/colinhacks/zod
|
|
28
|
+
Copyright (c) 2025 Colin McDonnell
|
package/dist/app/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/app/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAkB,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7D,yBAAiB,GAAG,CAAC;IACpB,UAAiB,OAAO,CAAC;QACxB,gCAAgC;QAChC,KAAY,aAAa,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAC;KAC1D;IAED,4BAA4B;IAC5B,KAAY,OAAO,GAAG;QACrB;;;;;;;;;;;;WAYG;QACH,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;QAExB;;;;;;;;WAQG;QACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC;QAE/C;;;WAGG;QACH,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC;KAClC,CAAC;CACF;AAED,6BAA6B;AAC7B,qBAAa,GAAG;;IAUf;;;;OAIG;gBACS,OAAO,CAAC,EAAE,GAAG,CAAC,OAAO;IAcjC;;;OAGG;IACH,GAAG,CACF,GAAG,MAAM,EAAE,IAAI,CAAC,SAAS,CACxB,KAAK,GAAG,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,GAAG,UAAU,CAAC,CACvD,EAAE;IAiBJ;;;;;;;;OAQG;IACH,QAAQ,CAAC,KAAK,GACb,UAAU,WAAW,GAAG,GAAG,EAC3B,UAAU,WAAW,uBAgBpB;CAkCF"}
|
package/dist/app/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Context } from "../context/index.js";
|
|
2
2
|
import { Route } from "../route/index.js";
|
|
3
3
|
import { Trie } from "../trie/index.js";
|
|
4
|
-
import { Method } from "../util/index.js";
|
|
4
|
+
import { Header, Method } from "../util/index.js";
|
|
5
5
|
/** Web server application */
|
|
6
6
|
export class App {
|
|
7
7
|
/** Route trie */
|
|
@@ -16,8 +16,12 @@ export class App {
|
|
|
16
16
|
* @param options configuration options
|
|
17
17
|
*/
|
|
18
18
|
constructor(options) {
|
|
19
|
-
this.#options =
|
|
20
|
-
|
|
19
|
+
this.#options = {
|
|
20
|
+
csrf: true,
|
|
21
|
+
trailingSlash: "never",
|
|
22
|
+
...options,
|
|
23
|
+
};
|
|
24
|
+
if (this.#options.csrf)
|
|
21
25
|
this.#global.push(App.#csrf);
|
|
22
26
|
if (this.#options.trailingSlash !== "ignore") {
|
|
23
27
|
this.#global.push(App.#createTrailingSlash(this.#options.trailingSlash));
|
|
@@ -32,7 +36,7 @@ export class App {
|
|
|
32
36
|
if (route instanceof Route) {
|
|
33
37
|
this.#trie.add(route);
|
|
34
38
|
}
|
|
35
|
-
else if (route
|
|
39
|
+
else if (Array.isArray(route)) {
|
|
36
40
|
this.use(...route);
|
|
37
41
|
}
|
|
38
42
|
else if (typeof route === "function") {
|
|
@@ -66,8 +70,8 @@ export class App {
|
|
|
66
70
|
static #csrf(c, next) {
|
|
67
71
|
if (c.req.method === Method.get ||
|
|
68
72
|
c.req.method === Method.head ||
|
|
69
|
-
c.req.headers.get(
|
|
70
|
-
c.req.headers.get(
|
|
73
|
+
c.req.headers.get(Header.name.fetch) === "same-origin" ||
|
|
74
|
+
c.req.headers.get(Header.name.origin) === c.url.origin) {
|
|
71
75
|
return next();
|
|
72
76
|
}
|
|
73
77
|
c.text("Forbidden", 403);
|
|
@@ -78,12 +82,12 @@ export class App {
|
|
|
78
82
|
await next();
|
|
79
83
|
if (c.res.status && c.res.status !== 404)
|
|
80
84
|
return;
|
|
81
|
-
const
|
|
82
|
-
if (mode === "always" &&
|
|
85
|
+
const slash = c.url.pathname.endsWith("/");
|
|
86
|
+
if (mode === "always" && !slash) {
|
|
83
87
|
c.url.pathname += "/";
|
|
84
88
|
c.redirect(c.url, 308);
|
|
85
89
|
}
|
|
86
|
-
else if (mode === "never" && c.url.pathname !== "/" &&
|
|
90
|
+
else if (mode === "never" && c.url.pathname !== "/" && slash) {
|
|
87
91
|
c.url.pathname = c.url.pathname.slice(0, -1);
|
|
88
92
|
c.redirect(c.url, 308);
|
|
89
93
|
}
|
package/dist/context/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { App } from "../app/index.js";
|
|
2
2
|
import { Cookie } from "../cookie/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import type { Middleware } from "../middleware/index.js";
|
|
4
4
|
import { Multipart } from "../multipart/index.js";
|
|
5
5
|
import { Route } from "../route/index.js";
|
|
6
|
-
import {
|
|
6
|
+
import { Form as FormSchema } from "../schema/index.js";
|
|
7
|
+
import type { Trie } from "../trie/index.js";
|
|
8
|
+
import { type Util } from "../util/index.js";
|
|
7
9
|
/** Properties to build the final `Response` with once middleware has run. */
|
|
8
10
|
declare class PreparedResponse {
|
|
9
11
|
/**
|
|
@@ -26,14 +28,27 @@ declare class PreparedResponse {
|
|
|
26
28
|
headers: Headers;
|
|
27
29
|
}
|
|
28
30
|
export declare namespace Context {
|
|
29
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Context.data return type.
|
|
33
|
+
*
|
|
34
|
+
* Routes without a schema return `null`.
|
|
35
|
+
*
|
|
36
|
+
* @template S Form shape
|
|
37
|
+
*/
|
|
38
|
+
type Result<S extends FormSchema.Shape> = [FormSchema.Shape] extends [
|
|
39
|
+
S
|
|
40
|
+
] ? null : Util.Prettify<FormSchema.Parse.Result<S, {
|
|
41
|
+
/** URL with invalid field values encoded into a search parameter. */
|
|
42
|
+
readonly url: URL;
|
|
43
|
+
}>>;
|
|
30
44
|
}
|
|
31
45
|
/**
|
|
32
46
|
* Request context.
|
|
33
47
|
*
|
|
34
48
|
* @template Params Parameters created from a route match
|
|
49
|
+
* @template Shape Parsed form data shape
|
|
35
50
|
*/
|
|
36
|
-
export declare class Context<Params extends Trie.Params = Trie.Params> {
|
|
51
|
+
export declare class Context<Params extends Trie.Params = Trie.Params, Shape extends FormSchema.Shape = FormSchema.Shape> {
|
|
37
52
|
#private;
|
|
38
53
|
/**
|
|
39
54
|
* Incoming `Request` to the server.
|
|
@@ -94,22 +109,24 @@ export declare class Context<Params extends Trie.Params = Trie.Params> {
|
|
|
94
109
|
* - [307 Temporary Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/307)
|
|
95
110
|
* - [308 Permanent Redirect](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/308)
|
|
96
111
|
*/
|
|
97
|
-
redirect(location: string | URL, status?: 301 | 302 | 303 | 307 | 308): void;
|
|
112
|
+
redirect(location: string | URL | Route, status?: 301 | 302 | 303 | 307 | 308): void;
|
|
98
113
|
/**
|
|
99
|
-
* Generates an etag from a
|
|
114
|
+
* Generates an etag from a checksum of the string provided.
|
|
100
115
|
* If the etag matches, sets the response to not modified.
|
|
101
116
|
*
|
|
102
117
|
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)
|
|
103
118
|
*
|
|
104
|
-
* @param string string to
|
|
119
|
+
* @param string string to check
|
|
105
120
|
* @returns `true` if the etag matches, `false` otherwise
|
|
106
121
|
*/
|
|
107
122
|
etag(string: string): boolean;
|
|
108
123
|
/**
|
|
109
|
-
* Parse multipart
|
|
124
|
+
* Parse a multipart request.
|
|
110
125
|
*
|
|
111
|
-
*
|
|
126
|
+
* _Prefer_ `Context.data()` _when possible to parse
|
|
127
|
+
* with a type-safe schema._
|
|
112
128
|
*
|
|
129
|
+
* @yields Multipart request `Part`(s)
|
|
113
130
|
* @example
|
|
114
131
|
*
|
|
115
132
|
* ```ts
|
|
@@ -125,6 +142,13 @@ export declare class Context<Params extends Trie.Params = Trie.Params> {
|
|
|
125
142
|
* ```
|
|
126
143
|
*/
|
|
127
144
|
form(options?: Multipart.Options): Multipart;
|
|
145
|
+
/**
|
|
146
|
+
* Parse route form data from search params or multipart requests.
|
|
147
|
+
*
|
|
148
|
+
* @param options Multipart options for POST requests
|
|
149
|
+
* @returns Parsed form data with possible invalid redirect URL state
|
|
150
|
+
*/
|
|
151
|
+
data(options?: Multipart.Options): Promise<Context.Result<Shape>>;
|
|
128
152
|
/**
|
|
129
153
|
* Composes a stack of `middleware` into a `Response`.
|
|
130
154
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/context/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE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AAoC;IACpC,QAAQ,CAAC,MAAM,SAAoB;IAQnC;;;;OAIG;gBACS,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,OAAO;IAM9C;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM;IAM3C;;;;;OAKG;IACH,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,SAAS,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,MAAM,CAAC,EAAE,MAAM;IAM3D;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM;IAM3C;;;;;;;;;;;OAWG;IACH,QAAQ,CACP,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,KAAK,EAC9B,MAAM,GAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAS;IAU1C;;;;;;;;OAQG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM;IAenB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO;IAIhC;;;;;OAKG;IACG,IAAI,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAuFvE;;;;;;OAMG;WACU,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE;CAkBzD"}
|
package/dist/context/index.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { Cookie } from "../cookie/index.js";
|
|
2
|
-
import {} from "../middleware/index.js";
|
|
3
2
|
import { Multipart } from "../multipart/index.js";
|
|
4
3
|
import { Render } from "../render/index.js";
|
|
5
4
|
import { Route } from "../route/index.js";
|
|
6
|
-
import {} from "../
|
|
7
|
-
import {
|
|
5
|
+
import { Form as FormSchema } from "../schema/index.js";
|
|
6
|
+
import { Checksum, Header, Method, Mime } from "../util/index.js";
|
|
8
7
|
/** Properties to build the final `Response` with once middleware has run. */
|
|
9
8
|
class PreparedResponse {
|
|
10
9
|
/**
|
|
@@ -30,6 +29,7 @@ class PreparedResponse {
|
|
|
30
29
|
* Request context.
|
|
31
30
|
*
|
|
32
31
|
* @template Params Parameters created from a route match
|
|
32
|
+
* @template Shape Parsed form data shape
|
|
33
33
|
*/
|
|
34
34
|
export class Context {
|
|
35
35
|
/**
|
|
@@ -54,6 +54,8 @@ export class Context {
|
|
|
54
54
|
cookie = new Cookie(this);
|
|
55
55
|
/** Forwarded app options */
|
|
56
56
|
#options;
|
|
57
|
+
/** Cached result from `data()` to avoid re-reading request bodies. */
|
|
58
|
+
#parsed;
|
|
57
59
|
/**
|
|
58
60
|
* Creates a new `Context` with the current `Request`.
|
|
59
61
|
*
|
|
@@ -73,7 +75,7 @@ export class Context {
|
|
|
73
75
|
html(body, status) {
|
|
74
76
|
this.res.body = body;
|
|
75
77
|
this.res.status = status;
|
|
76
|
-
this.res.headers.set(Header.type, Header.utf8(Mime.html));
|
|
78
|
+
this.res.headers.set(Header.name.type, Header.utf8(Mime.type.html));
|
|
77
79
|
}
|
|
78
80
|
/**
|
|
79
81
|
* Creates a JSON response.
|
|
@@ -84,7 +86,7 @@ export class Context {
|
|
|
84
86
|
json(data, status) {
|
|
85
87
|
this.res.body = JSON.stringify(data);
|
|
86
88
|
this.res.status = status;
|
|
87
|
-
this.res.headers.set(Header.type, Mime.json);
|
|
89
|
+
this.res.headers.set(Header.name.type, Mime.type.json);
|
|
88
90
|
}
|
|
89
91
|
/**
|
|
90
92
|
* Creates a plain text response.
|
|
@@ -95,7 +97,7 @@ export class Context {
|
|
|
95
97
|
text(body, status) {
|
|
96
98
|
this.res.body = body;
|
|
97
99
|
this.res.status = status;
|
|
98
|
-
this.res.headers.set(Header.type, Header.utf8(Mime.text));
|
|
100
|
+
this.res.headers.set(Header.name.type, Header.utf8(Mime.type.text));
|
|
99
101
|
}
|
|
100
102
|
/**
|
|
101
103
|
* Creates a redirect response.
|
|
@@ -112,21 +114,21 @@ export class Context {
|
|
|
112
114
|
redirect(location, status = 302) {
|
|
113
115
|
this.res.body = null;
|
|
114
116
|
this.res.status = status;
|
|
115
|
-
this.res.headers.set(
|
|
117
|
+
this.res.headers.set(Header.name.loc, location instanceof Route ? location.pathname() : String(location));
|
|
116
118
|
}
|
|
117
119
|
/**
|
|
118
|
-
* Generates an etag from a
|
|
120
|
+
* Generates an etag from a checksum of the string provided.
|
|
119
121
|
* If the etag matches, sets the response to not modified.
|
|
120
122
|
*
|
|
121
123
|
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag)
|
|
122
124
|
*
|
|
123
|
-
* @param string string to
|
|
125
|
+
* @param string string to check
|
|
124
126
|
* @returns `true` if the etag matches, `false` otherwise
|
|
125
127
|
*/
|
|
126
128
|
etag(string) {
|
|
127
|
-
const etag = `"${
|
|
128
|
-
this.res.headers.set(Header.etag, etag);
|
|
129
|
-
if (this.req.headers.get(Header.
|
|
129
|
+
const etag = `"${Checksum.djb2(string)}"`;
|
|
130
|
+
this.res.headers.set(Header.name.etag, etag);
|
|
131
|
+
if (this.req.headers.get(Header.name.none) === etag) {
|
|
130
132
|
this.res.body = null;
|
|
131
133
|
this.res.status = 304;
|
|
132
134
|
return true;
|
|
@@ -134,10 +136,12 @@ export class Context {
|
|
|
134
136
|
return false;
|
|
135
137
|
}
|
|
136
138
|
/**
|
|
137
|
-
* Parse multipart
|
|
139
|
+
* Parse a multipart request.
|
|
138
140
|
*
|
|
139
|
-
*
|
|
141
|
+
* _Prefer_ `Context.data()` _when possible to parse
|
|
142
|
+
* with a type-safe schema._
|
|
140
143
|
*
|
|
144
|
+
* @yields Multipart request `Part`(s)
|
|
141
145
|
* @example
|
|
142
146
|
*
|
|
143
147
|
* ```ts
|
|
@@ -153,7 +157,47 @@ export class Context {
|
|
|
153
157
|
* ```
|
|
154
158
|
*/
|
|
155
159
|
form(options) {
|
|
156
|
-
return new Multipart(this.req,
|
|
160
|
+
return new Multipart(this.req, { ...this.#options.form, ...options });
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Parse route form data from search params or multipart requests.
|
|
164
|
+
*
|
|
165
|
+
* @param options Multipart options for POST requests
|
|
166
|
+
* @returns Parsed form data with possible invalid redirect URL state
|
|
167
|
+
*/
|
|
168
|
+
async data(options) {
|
|
169
|
+
return (this.#parsed ??= (async () => {
|
|
170
|
+
const post = this.req.method === Method.post;
|
|
171
|
+
const form = this.route;
|
|
172
|
+
if (!form?.parse)
|
|
173
|
+
return null;
|
|
174
|
+
const result = await form.parse(post
|
|
175
|
+
? this.form({ parts: form.parts, ...options })
|
|
176
|
+
: this.url.searchParams);
|
|
177
|
+
if (result.issues) {
|
|
178
|
+
// create encoded URL state with invalid fields
|
|
179
|
+
let url = new URL(this.url);
|
|
180
|
+
if (post) {
|
|
181
|
+
const returnParam = url.searchParams.get(FormSchema.params[0]);
|
|
182
|
+
if (returnParam) {
|
|
183
|
+
try {
|
|
184
|
+
const returnUrl = new URL(returnParam, url);
|
|
185
|
+
if (returnUrl.origin === url.origin)
|
|
186
|
+
url = returnUrl;
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
// invalid redirect target
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
for (const param of FormSchema.params)
|
|
194
|
+
url.searchParams.delete(param);
|
|
195
|
+
if (result.search)
|
|
196
|
+
url.searchParams.set(...result.search);
|
|
197
|
+
return Object.assign(result, { url });
|
|
198
|
+
}
|
|
199
|
+
return result;
|
|
200
|
+
})());
|
|
157
201
|
}
|
|
158
202
|
/**
|
|
159
203
|
* Dispatches the stack of `middleware` provided.
|
|
@@ -180,14 +224,14 @@ export class Context {
|
|
|
180
224
|
}
|
|
181
225
|
else if (r !== undefined) {
|
|
182
226
|
// something to stream
|
|
183
|
-
const [mime] = Header.shift(this.res.headers.get(Header.type));
|
|
227
|
+
const [mime] = Header.shift(this.res.headers.get(Header.name.type));
|
|
184
228
|
this.res.body = Render.stream(r, {
|
|
185
229
|
// other defined types are safe
|
|
186
230
|
safe: Boolean(mime && !Mime.markup(mime)),
|
|
187
231
|
});
|
|
188
232
|
if (!mime) {
|
|
189
233
|
// default to HTML
|
|
190
|
-
this.res.headers.set(Header.type, Header.utf8(Mime.html));
|
|
234
|
+
this.res.headers.set(Header.name.type, Header.utf8(Mime.type.html));
|
|
191
235
|
}
|
|
192
236
|
// do not overwrite/remove status - that way user can set it before returning
|
|
193
237
|
}
|
package/dist/cookie/index.d.ts
CHANGED
|
@@ -73,7 +73,7 @@ export declare namespace Cookie {
|
|
|
73
73
|
};
|
|
74
74
|
type InsecureOptions = BaseOptions & {
|
|
75
75
|
/** Limits the scope of the cookie to a secure context (HTTPS). */
|
|
76
|
-
readonly secure?:
|
|
76
|
+
readonly secure?: boolean;
|
|
77
77
|
/**
|
|
78
78
|
* Controls whether the cookie is sent with cross-site requests.
|
|
79
79
|
* **Note:** `"none"` is not allowed unless `secure` is true.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cookie/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAGnD,yBAAiB,MAAM,CAAC;IACvB,KAAK,WAAW,GAAG;QAClB;;;WAGG;QACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAEzB;;;WAGG;QACH,QAAQ,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC;QAExB;;;WAGG;QACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;QAE5B;;;WAGG;QACH,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAEzB;;;;;WAKG;QACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAEvB,2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
|
@@ -20,7 +20,7 @@ export class Cookie {
|
|
|
20
20
|
* @returns Value of the cookie, or `undefined` if not found
|
|
21
21
|
*/
|
|
22
22
|
get(name) {
|
|
23
|
-
return (this.#parsed ??= Header.params(this.#c.req.headers.get(Header.cookie)))[name];
|
|
23
|
+
return (this.#parsed ??= Header.params(this.#c.req.headers.get(Header.name.cookie)))[name];
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
26
|
* Sets a cookie on the response using the `Set-Cookie` header.
|
|
@@ -51,6 +51,6 @@ export class Cookie {
|
|
|
51
51
|
cookie.push(`Max-Age=${options.maxAge}`);
|
|
52
52
|
if (options.expires)
|
|
53
53
|
cookie.push(`Expires=${options.expires.toUTCString()}`);
|
|
54
|
-
this.#c.res.headers.append(Header.
|
|
54
|
+
this.#c.res.headers.append(Header.name.set, cookie.join("; "));
|
|
55
55
|
}
|
|
56
56
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export { App } from "./app/index.js";
|
|
2
|
-
export { Route } from "./route/index.js";
|
|
3
|
-
export { Multipart } from "./multipart/index.js";
|
|
4
2
|
export { JSX } from "./jsx/index.js";
|
|
5
|
-
export { Render } from "./render/index.js";
|
|
6
3
|
export type { Middleware } from "./middleware/index.js";
|
|
4
|
+
export { Multipart } from "./multipart/index.js";
|
|
5
|
+
export { Render } from "./render/index.js";
|
|
6
|
+
export { Route } from "./route/index.js";
|
|
7
|
+
export { Field, Form, Schema } from "./schema/index.js";
|
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,YAAY,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { App } from "./app/index.js";
|
|
2
|
-
export { Route } from "./route/index.js";
|
|
3
|
-
export { Multipart } from "./multipart/index.js";
|
|
4
2
|
export { JSX } from "./jsx/index.js";
|
|
3
|
+
export { Multipart } from "./multipart/index.js";
|
|
5
4
|
export { Render } from "./render/index.js";
|
|
5
|
+
export { Route } from "./route/index.js";
|
|
6
|
+
export { Field, Form, Schema } from "./schema/index.js";
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import type { Context } from "../context/index.js";
|
|
1
|
+
import type { Context as ContextType } from "../context/index.js";
|
|
2
|
+
import type { Cookie as CookieType } from "../cookie/index.js";
|
|
3
|
+
import type { Form } from "../schema/index.js";
|
|
2
4
|
import type { Trie } from "../trie/index.js";
|
|
3
5
|
export declare namespace Middleware {
|
|
6
|
+
namespace Context {
|
|
7
|
+
namespace Cookie {
|
|
8
|
+
type Options = CookieType.Options;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
4
11
|
/**
|
|
5
12
|
* Middleware context.
|
|
6
13
|
*
|
|
7
14
|
* @template Params Parameters created from a route match
|
|
15
|
+
* @template Shape Parsed form data shape
|
|
8
16
|
*/
|
|
9
|
-
type Context<Params extends Trie.Params = Trie.Params> =
|
|
17
|
+
type Context<Params extends Trie.Params = Trie.Params, Shape extends Form.Shape = Form.Shape> = ContextType<Params, Shape>;
|
|
10
18
|
/** Dispatches the next middleware in the stack */
|
|
11
19
|
type Next = () => Promise<void>;
|
|
12
20
|
}
|
|
@@ -14,9 +22,10 @@ export declare namespace Middleware {
|
|
|
14
22
|
* App middleware.
|
|
15
23
|
*
|
|
16
24
|
* @template Params Parameters created from a route match
|
|
25
|
+
* @template Shape Parsed form data shape
|
|
17
26
|
* @param context Request context
|
|
18
27
|
* @param next Dispatches the next middleware in the stack
|
|
19
28
|
* @returns `Response` or element(s) to stream as HTML
|
|
20
29
|
*/
|
|
21
|
-
export type Middleware<Params extends Trie.Params = Trie.Params> = (context:
|
|
30
|
+
export type Middleware<Params extends Trie.Params = Trie.Params, Shape extends Form.Shape = Form.Shape> = (context: ContextType<Params, Shape>, next: Middleware.Next) => any;
|
|
22
31
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/middleware/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,yBAAiB,UAAU,CAAC;IAC3B,UAAiB,OAAO,CAAC;QACxB,UAAiB,MAAM,CAAC;YACvB,KAAY,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;SACzC;KACD;IAED;;;;;OAKG;IACH,KAAY,OAAO,CAClB,MAAM,SAAS,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EACxC,KAAK,SAAS,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAClC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAE/B,kDAAkD;IAClD,KAAY,IAAI,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACvC;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CACrB,MAAM,SAAS,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,EACxC,KAAK,SAAS,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAClC,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,KAAK,GAAG,CAAC"}
|
|
@@ -32,6 +32,11 @@ declare class Part extends Request {
|
|
|
32
32
|
* @param rawHeaders Raw buffer of HTTP headers for the part
|
|
33
33
|
*/
|
|
34
34
|
constructor(req: Request, body: ReadableStream, rawHeaders: Uint8Array);
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @returns Buffered FormDataEntryValue
|
|
38
|
+
*/
|
|
39
|
+
value(): Promise<FormDataEntryValue>;
|
|
35
40
|
}
|
|
36
41
|
export declare namespace Multipart {
|
|
37
42
|
/** Multipart options */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/multipart/index.ts"],"names":[],"mappings":"AAgCA,qBAAqB;AACrB,cAAM,IAAK,SAAQ,OAAO;IACzB;;;;;;;;OAQG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAGjC;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAG7B,gBAAgB;IAChB,SAAiB,IAAI,EAAE,cAAc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4C;IACrC,CAAC,MAAM,CAAC,aAAa,CAAC;IA8C7B;;;;;;;OAOG;IACG,IAAI;CASV"}
|
package/dist/multipart/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Codec, Header, Mime } from "../util/index.js";
|
|
1
|
+
import { Codec, Header, Mime, Size } from "../util/index.js";
|
|
2
2
|
/** Sequence of bytes to find within the stream */
|
|
3
3
|
class Needle extends Uint8Array {
|
|
4
4
|
/** Index of the last character in the needle */
|
|
@@ -74,20 +74,29 @@ class Part extends Request {
|
|
|
74
74
|
// @ts-expect-error - streaming https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#duplex
|
|
75
75
|
duplex: "half",
|
|
76
76
|
});
|
|
77
|
-
[this.type] = Header.shift(this.headers.get(Header.type));
|
|
78
|
-
({ name: this.name = null, filename: this.filename = null } = Header.params(this.headers.get(Header.
|
|
77
|
+
[this.type] = Header.shift(this.headers.get(Header.name.type));
|
|
78
|
+
({ name: this.name = null, filename: this.filename = null } = Header.params(this.headers.get(Header.name.disp)));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @returns Buffered FormDataEntryValue
|
|
83
|
+
*/
|
|
84
|
+
async value() {
|
|
85
|
+
if (this.filename || this.type === Mime.type.stream) {
|
|
86
|
+
const blob = await this.blob();
|
|
87
|
+
return new File([blob], this.filename ?? "blob", { type: blob.type });
|
|
88
|
+
}
|
|
89
|
+
return this.text();
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
/** Multipart request */
|
|
82
93
|
export class Multipart extends Request {
|
|
83
|
-
static #kb = 1024;
|
|
84
|
-
static #mb = 1024 ** 2;
|
|
85
94
|
/** New line needle to share across requests and parts */
|
|
86
95
|
static #newLine = new Needle("\r\n\r\n");
|
|
87
96
|
/** Parser options */
|
|
88
97
|
#options = {
|
|
89
|
-
memory: 4 *
|
|
90
|
-
payload: 16 *
|
|
98
|
+
memory: 4 * Size.mb,
|
|
99
|
+
payload: 16 * Size.mb,
|
|
91
100
|
parts: Infinity,
|
|
92
101
|
};
|
|
93
102
|
/** Request body reader */
|
|
@@ -123,7 +132,7 @@ export class Multipart extends Request {
|
|
|
123
132
|
*/
|
|
124
133
|
constructor(req, options) {
|
|
125
134
|
super(req);
|
|
126
|
-
const [mime, params] = Header.shift(this.headers.get(Header.type));
|
|
135
|
+
const [mime, params] = Header.shift(this.headers.get(Header.name.type));
|
|
127
136
|
if (!Mime.multipart(mime))
|
|
128
137
|
throw new TypeError("Unsupported Media Type");
|
|
129
138
|
const { boundary } = Header.params(params);
|
|
@@ -138,7 +147,7 @@ export class Multipart extends Request {
|
|
|
138
147
|
this.#memory = new Uint8Array(new ArrayBuffer(
|
|
139
148
|
// slightly larger than common chunk size/high water mark 64kb for leftover boundary
|
|
140
149
|
// prevents having to resize memory for most requests
|
|
141
|
-
65 *
|
|
150
|
+
65 * Size.kb,
|
|
142
151
|
// cap max chunk size + leftover
|
|
143
152
|
{ maxByteLength: this.#options.memory }));
|
|
144
153
|
}
|
|
@@ -321,19 +330,8 @@ export class Multipart extends Request {
|
|
|
321
330
|
async data() {
|
|
322
331
|
const data = new FormData();
|
|
323
332
|
for await (const part of this) {
|
|
324
|
-
if (part.name)
|
|
325
|
-
|
|
326
|
-
if (part.filename || part.type === Mime.stream) {
|
|
327
|
-
const blob = await part.blob();
|
|
328
|
-
value = new File([blob], part.filename ?? "blob", {
|
|
329
|
-
type: blob.type,
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
value = await part.text();
|
|
334
|
-
}
|
|
335
|
-
data.append(part.name, value);
|
|
336
|
-
}
|
|
333
|
+
if (part.name)
|
|
334
|
+
data.append(part.name, await part.value());
|
|
337
335
|
}
|
|
338
336
|
return data;
|
|
339
337
|
}
|
package/dist/render/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/render/index.ts"],"names":[],"mappings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;;;;;OAKG;gBACS,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO;IAK1D,iDAAiD;IAC1C,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC;IAqFrE;;;;;;;OAOG;IACH,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO;IA0C5D;;;;;;;;;;OAUG;IACG,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,OAAO;IAI3D;;;;;OAKG;IACH,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO;IAIzB;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CA4D1C"}
|
package/dist/render/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Codec } from "../util/index.js";
|
|
1
|
+
import { Codec, Size } from "../util/index.js";
|
|
2
2
|
/** Chunk containing the HTML from a rendered element */
|
|
3
3
|
class Chunk {
|
|
4
4
|
/** Safe value to render */
|
|
@@ -58,9 +58,10 @@ export class Render {
|
|
|
58
58
|
if (element instanceof Promise)
|
|
59
59
|
element = await element;
|
|
60
60
|
// resolve based on type
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
if (element == null || typeof element === "boolean" || element === "") {
|
|
62
|
+
// should not render
|
|
63
63
|
return;
|
|
64
|
+
}
|
|
64
65
|
if (element instanceof Chunk) {
|
|
65
66
|
// already escaped or safe
|
|
66
67
|
yield element;
|
|
@@ -162,7 +163,7 @@ export class Render {
|
|
|
162
163
|
// https://blog.cloudflare.com/unpacking-cloudflare-workers-cpu-performance-benchmarks/#inefficient-streams-adapters
|
|
163
164
|
// in Node, the default is 16kb, so this stacks another 2kb in front
|
|
164
165
|
// https://nodejs.org/api/http.html#outgoingmessagewritablehighwatermark
|
|
165
|
-
highWaterMark:
|
|
166
|
+
highWaterMark: 2 * Size.kb,
|
|
166
167
|
});
|
|
167
168
|
}
|
|
168
169
|
/**
|
|
@@ -171,6 +172,7 @@ export class Render {
|
|
|
171
172
|
* ### WARNING
|
|
172
173
|
*
|
|
173
174
|
* This negates streaming benefits and buffers the result into a string.
|
|
175
|
+
*
|
|
174
176
|
* @param element Element to render
|
|
175
177
|
* @param options Render options
|
|
176
178
|
* @returns Concatenated HTML
|