ovr 4.2.2 → 4.2.4
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/app/context.d.ts.map +1 -1
- package/dist/app/context.js +26 -11
- package/dist/jsx/chunk/index.d.ts +4 -4
- package/dist/jsx/chunk/index.d.ts.map +1 -1
- package/dist/jsx/chunk/index.js +11 -13
- package/package.json +1 -1
- package/src/app/context.ts +40 -23
- package/src/jsx/chunk/index.ts +12 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/app/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAe,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,MAAM,YAAY,CAAC;AAGpB,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE;IAAE,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAA;CAAE,KAAK,GAAG,CAAC,OAAO,CAAC;AAShE,qBAAa,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;;IAC7C,gFAAgF;IAChF,GAAG,EAAE,OAAO,CAAC;IAEb,4EAA4E;IAC5E,GAAG,EAAE,GAAG,CAAC;IAET;;;;;;;OAOG;IACH,MAAM,EAAG,CAAC,CAAC;IAEX,oCAAoC;IACpC,KAAK,EAAG,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE/B,+FAA+F;IAC/F,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAQ;IAE7B,gFAAgF;IAChF,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gFAAgF;IAChF,OAAO,UAAiB;IAQxB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,CAAC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42
42
|
notFound;
|
|
43
|
+
/** `Memo` unique to the current `Request` context */
|
|
43
44
|
#memo = new Memo();
|
|
44
45
|
memo = this.#memo.use;
|
|
46
|
+
/** Final `Response` set in `build` */
|
|
47
|
+
#response;
|
|
48
|
+
/** Used across requests */
|
|
45
49
|
static #encoder = new TextEncoder();
|
|
46
50
|
constructor(req, url, trailingSlash, base, error, notFound) {
|
|
47
51
|
this.req = req;
|
|
@@ -122,6 +126,12 @@ export class Context {
|
|
|
122
126
|
* @param Element `JSX.Element` to add to the head
|
|
123
127
|
*/
|
|
124
128
|
head(...Element) {
|
|
129
|
+
if (this.#bodyUsed) {
|
|
130
|
+
throw new Error("Cannot call `head` after `Response.body` has been read. " +
|
|
131
|
+
"This can occur if `head` is called within a component since " +
|
|
132
|
+
"components are evaluated during the stream, often times after " +
|
|
133
|
+
"the <head> element has already been sent.");
|
|
134
|
+
}
|
|
125
135
|
this.#headElements.push(...Element);
|
|
126
136
|
}
|
|
127
137
|
/**
|
|
@@ -171,25 +181,22 @@ export class Context {
|
|
|
171
181
|
// HTML partial - just use the layouts + page
|
|
172
182
|
gen = toGenerator(Page);
|
|
173
183
|
}
|
|
174
|
-
const close = (c) => {
|
|
175
|
-
c?.close();
|
|
176
|
-
gen.return();
|
|
177
|
-
};
|
|
178
184
|
let result;
|
|
179
185
|
this.html(new ReadableStream({
|
|
180
186
|
pull: async (c) => {
|
|
181
|
-
if (this.req.signal.aborted)
|
|
182
|
-
return close(c);
|
|
183
187
|
result = await gen.next();
|
|
184
|
-
if (result.done)
|
|
185
|
-
|
|
188
|
+
if (result.done) {
|
|
189
|
+
c.close();
|
|
190
|
+
gen.return();
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
186
193
|
// need to encode for Node JS (ex: during prerendering)
|
|
187
194
|
c.enqueue(Context.#encoder.encode(result.value.value));
|
|
188
195
|
},
|
|
189
196
|
cancel() {
|
|
190
|
-
|
|
197
|
+
gen.return();
|
|
191
198
|
},
|
|
192
|
-
}
|
|
199
|
+
}), status);
|
|
193
200
|
}
|
|
194
201
|
/**
|
|
195
202
|
* Generates an etag from a hash of the string provided.
|
|
@@ -235,7 +242,15 @@ export class Context {
|
|
|
235
242
|
}
|
|
236
243
|
if (!this.body && !this.status)
|
|
237
244
|
this.notFound(this);
|
|
238
|
-
return new Response(this.body, this);
|
|
245
|
+
return (this.#response = new Response(this.body, this));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if the `Response` has been set and the body has been read.
|
|
249
|
+
*
|
|
250
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/bodyUsed)
|
|
251
|
+
*/
|
|
252
|
+
get #bodyUsed() {
|
|
253
|
+
return Boolean(this.#response?.bodyUsed);
|
|
239
254
|
}
|
|
240
255
|
/**
|
|
241
256
|
* Call within the scope of a handler to get the current context.
|
|
@@ -5,10 +5,10 @@ export declare class Chunk {
|
|
|
5
5
|
/**
|
|
6
6
|
* `Chunk` to send in an HTML stream.
|
|
7
7
|
*
|
|
8
|
-
* @param
|
|
8
|
+
* @param html string of HTML to escape
|
|
9
9
|
* @param safe Set to `true` if the HTML is safe and should not be escaped
|
|
10
10
|
*/
|
|
11
|
-
constructor(
|
|
11
|
+
constructor(html: unknown, safe?: boolean);
|
|
12
12
|
/**
|
|
13
13
|
* @returns `value`
|
|
14
14
|
*/
|
|
@@ -20,10 +20,10 @@ export declare class Chunk {
|
|
|
20
20
|
/**
|
|
21
21
|
* Escapes strings of HTML.
|
|
22
22
|
*
|
|
23
|
-
* @param
|
|
23
|
+
* @param html String to escape
|
|
24
24
|
* @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
|
|
25
25
|
* @returns Escaped string of HTML
|
|
26
26
|
*/
|
|
27
|
-
static escape(
|
|
27
|
+
static escape(html: string, attr?: boolean): string;
|
|
28
28
|
}
|
|
29
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsx/chunk/index.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;;IAIjB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;gBACS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/jsx/chunk/index.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;;IAIjB,2BAA2B;IAC3B,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;OAKG;gBACS,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,OAAO;IAKzC;;OAEG;IACH,QAAQ;IAIR;;OAEG;IACH,MAAM,CAAC,GAAG,MAAM,EAAE,KAAK,EAAE;IAIzB;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CA2B1C"}
|
package/dist/jsx/chunk/index.js
CHANGED
|
@@ -6,11 +6,11 @@ export class Chunk {
|
|
|
6
6
|
/**
|
|
7
7
|
* `Chunk` to send in an HTML stream.
|
|
8
8
|
*
|
|
9
|
-
* @param
|
|
9
|
+
* @param html string of HTML to escape
|
|
10
10
|
* @param safe Set to `true` if the HTML is safe and should not be escaped
|
|
11
11
|
*/
|
|
12
|
-
constructor(
|
|
13
|
-
const value = String(
|
|
12
|
+
constructor(html, safe) {
|
|
13
|
+
const value = String(html ?? "");
|
|
14
14
|
this.value = safe ? value : Chunk.escape(value);
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
@@ -28,11 +28,11 @@ export class Chunk {
|
|
|
28
28
|
/**
|
|
29
29
|
* Escapes strings of HTML.
|
|
30
30
|
*
|
|
31
|
-
* @param
|
|
31
|
+
* @param html String to escape
|
|
32
32
|
* @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
|
|
33
33
|
* @returns Escaped string of HTML
|
|
34
34
|
*/
|
|
35
|
-
static escape(
|
|
35
|
+
static escape(html, attr) {
|
|
36
36
|
// adapted from https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/escaping.js
|
|
37
37
|
const regex = attr ? Chunk.#attr : Chunk.#content;
|
|
38
38
|
// search starts at beginning of the string
|
|
@@ -40,21 +40,19 @@ export class Chunk {
|
|
|
40
40
|
// tracks the position of the last successful match in the input string
|
|
41
41
|
let start = 0;
|
|
42
42
|
let result = "";
|
|
43
|
-
// index of the match
|
|
44
|
-
let i;
|
|
45
|
-
let match;
|
|
46
43
|
// since `g` flag is used, regex maintains state with each loop,
|
|
47
44
|
// checking from the lastIndex onward each time
|
|
48
|
-
while (regex.test(
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
while (regex.test(html)) {
|
|
46
|
+
// index of the match
|
|
47
|
+
const i = regex.lastIndex - 1;
|
|
48
|
+
const match = html[i];
|
|
51
49
|
result +=
|
|
52
50
|
// everything that didn't match during this test
|
|
53
|
-
|
|
51
|
+
html.slice(start, i) +
|
|
54
52
|
// replacement
|
|
55
53
|
(match === "&" ? "&" : match === '"' ? """ : "<");
|
|
56
54
|
start = regex.lastIndex;
|
|
57
55
|
}
|
|
58
|
-
return result +
|
|
56
|
+
return result + html.slice(start);
|
|
59
57
|
}
|
|
60
58
|
}
|
package/package.json
CHANGED
package/src/app/context.ts
CHANGED
|
@@ -64,10 +64,15 @@ export class Context<P extends Params = Params> {
|
|
|
64
64
|
/** Passed from `app.notFound` */
|
|
65
65
|
notFound: NotFoundHandler<P>;
|
|
66
66
|
|
|
67
|
+
/** `Memo` unique to the current `Request` context */
|
|
67
68
|
#memo = new Memo();
|
|
68
69
|
|
|
69
70
|
memo = this.#memo.use;
|
|
70
71
|
|
|
72
|
+
/** Final `Response` set in `build` */
|
|
73
|
+
#response: Response | undefined;
|
|
74
|
+
|
|
75
|
+
/** Used across requests */
|
|
71
76
|
static #encoder = new TextEncoder();
|
|
72
77
|
|
|
73
78
|
constructor(
|
|
@@ -176,6 +181,15 @@ export class Context<P extends Params = Params> {
|
|
|
176
181
|
* @param Element `JSX.Element` to add to the head
|
|
177
182
|
*/
|
|
178
183
|
head(...Element: JSX.Element[]) {
|
|
184
|
+
if (this.#bodyUsed) {
|
|
185
|
+
throw new Error(
|
|
186
|
+
"Cannot call `head` after `Response.body` has been read. " +
|
|
187
|
+
"This can occur if `head` is called within a component since " +
|
|
188
|
+
"components are evaluated during the stream, often times after " +
|
|
189
|
+
"the <head> element has already been sent.",
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
|
|
179
193
|
this.#headElements.push(...Element);
|
|
180
194
|
}
|
|
181
195
|
|
|
@@ -234,33 +248,27 @@ export class Context<P extends Params = Params> {
|
|
|
234
248
|
gen = toGenerator(Page);
|
|
235
249
|
}
|
|
236
250
|
|
|
237
|
-
const close = (c?: ReadableStreamDefaultController) => {
|
|
238
|
-
c?.close();
|
|
239
|
-
gen.return();
|
|
240
|
-
};
|
|
241
|
-
|
|
242
251
|
let result: IteratorResult<Chunk>;
|
|
243
252
|
|
|
244
253
|
this.html(
|
|
245
|
-
new ReadableStream<Uint8Array>(
|
|
246
|
-
{
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
254
|
+
new ReadableStream<Uint8Array>({
|
|
255
|
+
pull: async (c) => {
|
|
256
|
+
result = await gen.next();
|
|
257
|
+
|
|
258
|
+
if (result.done) {
|
|
259
|
+
c.close();
|
|
260
|
+
gen.return();
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// need to encode for Node JS (ex: during prerendering)
|
|
265
|
+
c.enqueue(Context.#encoder.encode(result.value.value));
|
|
266
|
+
},
|
|
257
267
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
},
|
|
268
|
+
cancel() {
|
|
269
|
+
gen.return();
|
|
261
270
|
},
|
|
262
|
-
|
|
263
|
-
),
|
|
271
|
+
}),
|
|
264
272
|
status,
|
|
265
273
|
);
|
|
266
274
|
}
|
|
@@ -320,7 +328,16 @@ export class Context<P extends Params = Params> {
|
|
|
320
328
|
|
|
321
329
|
if (!this.body && !this.status) this.notFound(this);
|
|
322
330
|
|
|
323
|
-
return new Response(this.body, this);
|
|
331
|
+
return (this.#response = new Response(this.body, this));
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Check if the `Response` has been set and the body has been read.
|
|
336
|
+
*
|
|
337
|
+
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Response/bodyUsed)
|
|
338
|
+
*/
|
|
339
|
+
get #bodyUsed() {
|
|
340
|
+
return Boolean(this.#response?.bodyUsed);
|
|
324
341
|
}
|
|
325
342
|
|
|
326
343
|
/**
|
package/src/jsx/chunk/index.ts
CHANGED
|
@@ -8,11 +8,11 @@ export class Chunk {
|
|
|
8
8
|
/**
|
|
9
9
|
* `Chunk` to send in an HTML stream.
|
|
10
10
|
*
|
|
11
|
-
* @param
|
|
11
|
+
* @param html string of HTML to escape
|
|
12
12
|
* @param safe Set to `true` if the HTML is safe and should not be escaped
|
|
13
13
|
*/
|
|
14
|
-
constructor(
|
|
15
|
-
const value = String(
|
|
14
|
+
constructor(html: unknown, safe?: boolean) {
|
|
15
|
+
const value = String(html ?? "");
|
|
16
16
|
this.value = safe ? value : Chunk.escape(value);
|
|
17
17
|
}
|
|
18
18
|
|
|
@@ -33,11 +33,11 @@ export class Chunk {
|
|
|
33
33
|
/**
|
|
34
34
|
* Escapes strings of HTML.
|
|
35
35
|
*
|
|
36
|
-
* @param
|
|
36
|
+
* @param html String to escape
|
|
37
37
|
* @param attr Set to `true` if the value is an attribute, otherwise it's a string of HTML content
|
|
38
38
|
* @returns Escaped string of HTML
|
|
39
39
|
*/
|
|
40
|
-
static escape(
|
|
40
|
+
static escape(html: string, attr?: boolean) {
|
|
41
41
|
// adapted from https://github.com/sveltejs/svelte/blob/main/packages/svelte/src/escaping.js
|
|
42
42
|
const regex = attr ? Chunk.#attr : Chunk.#content;
|
|
43
43
|
|
|
@@ -46,23 +46,22 @@ export class Chunk {
|
|
|
46
46
|
// tracks the position of the last successful match in the input string
|
|
47
47
|
let start = 0;
|
|
48
48
|
let result = "";
|
|
49
|
-
// index of the match
|
|
50
|
-
let i: number;
|
|
51
|
-
let match: string | undefined;
|
|
52
49
|
|
|
53
50
|
// since `g` flag is used, regex maintains state with each loop,
|
|
54
51
|
// checking from the lastIndex onward each time
|
|
55
|
-
while (regex.test(
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
while (regex.test(html)) {
|
|
53
|
+
// index of the match
|
|
54
|
+
const i = regex.lastIndex - 1;
|
|
55
|
+
const match = html[i];
|
|
56
|
+
|
|
58
57
|
result +=
|
|
59
58
|
// everything that didn't match during this test
|
|
60
|
-
|
|
59
|
+
html.slice(start, i) +
|
|
61
60
|
// replacement
|
|
62
61
|
(match === "&" ? "&" : match === '"' ? """ : "<");
|
|
63
62
|
start = regex.lastIndex;
|
|
64
63
|
}
|
|
65
64
|
|
|
66
|
-
return result +
|
|
65
|
+
return result + html.slice(start);
|
|
67
66
|
}
|
|
68
67
|
}
|