ovr 6.2.3 → 6.2.5
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/index.d.ts.map +1 -1
- package/dist/app/index.js +3 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -0
- package/dist/cookie/index.d.ts +1 -1
- package/dist/cookie/index.d.ts.map +1 -1
- package/dist/jsx/elements.d.ts.map +1 -1
- package/dist/jsx/index.d.ts +2 -2
- package/dist/jsx/index.d.ts.map +1 -1
- package/dist/jsx/index.js +3 -3
- package/dist/multipart/index.d.ts +1 -1
- package/dist/multipart/index.d.ts.map +1 -1
- package/dist/multipart/index.js +103 -61
- package/dist/render/index.d.ts.map +1 -1
- package/dist/render/index.js +51 -28
- package/dist/route/index.d.ts +4 -4
- package/dist/route/index.d.ts.map +1 -1
- package/dist/schema/index.d.ts +24 -8
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +1 -2
- package/dist/trie/index.d.ts +6 -5
- package/dist/trie/index.d.ts.map +1 -1
- package/dist/trie/index.js +14 -16
- package/dist/util/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/app/index.ts +6 -1
- package/src/context/index.ts +3 -2
- package/src/cookie/index.ts +2 -2
- package/src/jsx/elements.ts +3 -17
- package/src/jsx/index.ts +3 -5
- package/src/multipart/index.ts +126 -86
- package/src/render/index.ts +57 -35
- package/src/route/index.ts +5 -4
- package/src/schema/index.ts +11 -17
- package/src/trie/index.ts +22 -24
- package/src/util/index.ts +1 -1
package/src/multipart/index.ts
CHANGED
|
@@ -165,7 +165,7 @@ export namespace Multipart {
|
|
|
165
165
|
* new Multipart(request, { parts });
|
|
166
166
|
* ```
|
|
167
167
|
*/
|
|
168
|
-
parts?: number;
|
|
168
|
+
parts?: number | undefined;
|
|
169
169
|
};
|
|
170
170
|
|
|
171
171
|
/** Type for a `Part` of the multipart body */
|
|
@@ -188,7 +188,10 @@ export class Multipart extends Request {
|
|
|
188
188
|
readonly #reader: ReadableStreamDefaultReader;
|
|
189
189
|
|
|
190
190
|
/** Current values being buffered in memory */
|
|
191
|
-
|
|
191
|
+
#memory = new Uint8Array(0);
|
|
192
|
+
|
|
193
|
+
/** Owned storage for headers and boundaries spanning input chunks. */
|
|
194
|
+
readonly #scratch: Uint8Array<ArrayBuffer>;
|
|
192
195
|
|
|
193
196
|
/** Opening boundary needle */
|
|
194
197
|
readonly #opening: Needle;
|
|
@@ -202,6 +205,9 @@ export class Multipart extends Request {
|
|
|
202
205
|
/** Start index of the found needle */
|
|
203
206
|
#start = 0;
|
|
204
207
|
|
|
208
|
+
/** Start of unread data within the buffer. */
|
|
209
|
+
#offset = 0;
|
|
210
|
+
|
|
205
211
|
/** End index of the found needle */
|
|
206
212
|
#end = 0;
|
|
207
213
|
|
|
@@ -240,7 +246,7 @@ export class Multipart extends Request {
|
|
|
240
246
|
this.#opening = new Needle(`--${boundary}\r\n`);
|
|
241
247
|
this.#boundary = new Needle(`\r\n--${boundary}`);
|
|
242
248
|
|
|
243
|
-
this.#
|
|
249
|
+
this.#scratch = new Uint8Array(
|
|
244
250
|
new ArrayBuffer(
|
|
245
251
|
// slightly larger than common chunk size/high water mark 64kb for leftover boundary
|
|
246
252
|
// prevents having to resize memory for most requests
|
|
@@ -251,64 +257,65 @@ export class Multipart extends Request {
|
|
|
251
257
|
);
|
|
252
258
|
}
|
|
253
259
|
|
|
254
|
-
/**
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
*/
|
|
261
|
-
async #read(append = true) {
|
|
262
|
-
const next = await this.#reader.read();
|
|
263
|
-
|
|
260
|
+
/** Account for a source read and append or temporarily borrow its bytes. */
|
|
261
|
+
#read(
|
|
262
|
+
next: ReadableStreamReadResult<Uint8Array<ArrayBuffer>>,
|
|
263
|
+
append = true,
|
|
264
|
+
borrow = false,
|
|
265
|
+
) {
|
|
264
266
|
if (next.done) return true;
|
|
265
|
-
|
|
266
267
|
const nextLength = next.value.length;
|
|
267
|
-
|
|
268
268
|
if ((this.#payloadSize += nextLength) > this.#options.payload) {
|
|
269
269
|
throw new RangeError("Payload Too Large");
|
|
270
270
|
}
|
|
271
|
-
|
|
272
271
|
if (append) {
|
|
273
|
-
const
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
if (required > size) {
|
|
278
|
-
this.#memory.buffer.resize(
|
|
279
|
-
Math.min(
|
|
280
|
-
this.#options.memory, // in case double is larger than the max
|
|
281
|
-
Math.max(required, size * 2),
|
|
282
|
-
),
|
|
283
|
-
);
|
|
272
|
+
const length = this.#valid - this.#offset;
|
|
273
|
+
const required = length + nextLength;
|
|
274
|
+
if (required > this.#scratch.buffer.maxByteLength) {
|
|
275
|
+
throw new RangeError("Multipart buffer limit exceeded");
|
|
284
276
|
}
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
277
|
+
if (length || !borrow) {
|
|
278
|
+
this.#retain();
|
|
279
|
+
if (required > this.#scratch.length) {
|
|
280
|
+
this.#scratch.buffer.resize(
|
|
281
|
+
Math.min(
|
|
282
|
+
this.#scratch.buffer.maxByteLength,
|
|
283
|
+
Math.max(required, this.#scratch.length * 2),
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
this.#scratch.set(next.value, length);
|
|
288
|
+
} else {
|
|
289
|
+
// The caller must consume or retain these bytes before yielding.
|
|
290
|
+
this.#memory = next.value;
|
|
291
|
+
}
|
|
292
|
+
this.#valid = required;
|
|
293
|
+
this.#start -= this.#offset;
|
|
294
|
+
this.#end -= this.#offset;
|
|
295
|
+
this.#offset = 0;
|
|
289
296
|
}
|
|
290
297
|
}
|
|
291
298
|
|
|
299
|
+
/** Preserve unread bytes before the source can reuse its input storage. */
|
|
300
|
+
#retain() {
|
|
301
|
+
const length = this.#valid - this.#offset;
|
|
302
|
+
if (length > this.#scratch.length) this.#scratch.buffer.resize(length);
|
|
303
|
+
this.#scratch.set(this.#memory.subarray(this.#offset, this.#valid));
|
|
304
|
+
this.#memory = this.#scratch;
|
|
305
|
+
this.#valid = length;
|
|
306
|
+
this.#start -= this.#offset;
|
|
307
|
+
this.#end -= this.#offset;
|
|
308
|
+
this.#offset = 0;
|
|
309
|
+
}
|
|
310
|
+
|
|
292
311
|
/**
|
|
293
312
|
* Cuts off the buffer < end index.
|
|
294
313
|
*
|
|
295
314
|
* @returns Shifted off buffer < start index
|
|
296
315
|
*/
|
|
297
316
|
#shift() {
|
|
298
|
-
const before = this.#memory.
|
|
299
|
-
|
|
300
|
-
// how much data is left after the found needle
|
|
301
|
-
const remainder = this.#valid - this.#end;
|
|
302
|
-
|
|
303
|
-
if (remainder) {
|
|
304
|
-
// copy remainder to the start of the buffer
|
|
305
|
-
// this doesn't move the chunks, just copies to the start
|
|
306
|
-
// old will be overwritten
|
|
307
|
-
this.#memory.copyWithin(0, this.#end, this.#valid);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
this.#valid = remainder;
|
|
311
|
-
this.#start = this.#end = 0;
|
|
317
|
+
const before = this.#memory.subarray(this.#offset, this.#start);
|
|
318
|
+
this.#offset = this.#start = this.#end;
|
|
312
319
|
|
|
313
320
|
return before;
|
|
314
321
|
}
|
|
@@ -346,8 +353,10 @@ export class Multipart extends Request {
|
|
|
346
353
|
|
|
347
354
|
// where to safely start the next search in the concatenated chunk result
|
|
348
355
|
// go back len - 1 in case it was partially at the end
|
|
349
|
-
this.#start = this.#end =
|
|
350
|
-
|
|
356
|
+
this.#start = this.#end = Math.max(
|
|
357
|
+
this.#offset,
|
|
358
|
+
haystackLength - (needle.length - 1),
|
|
359
|
+
);
|
|
351
360
|
}
|
|
352
361
|
|
|
353
362
|
/**
|
|
@@ -359,7 +368,10 @@ export class Multipart extends Request {
|
|
|
359
368
|
*/
|
|
360
369
|
async #findConcat(needle: Needle) {
|
|
361
370
|
let found: Uint8Array | undefined;
|
|
362
|
-
while (
|
|
371
|
+
while (
|
|
372
|
+
!(found = this.#find(needle)) &&
|
|
373
|
+
!this.#read(await this.#reader.read())
|
|
374
|
+
);
|
|
363
375
|
return found;
|
|
364
376
|
}
|
|
365
377
|
|
|
@@ -368,50 +380,78 @@ export class Multipart extends Request {
|
|
|
368
380
|
* @returns Stream that streams the content until the next find
|
|
369
381
|
*/
|
|
370
382
|
#findStream(needle: Needle) {
|
|
383
|
+
let pending: Uint8Array<ArrayBuffer> | undefined;
|
|
384
|
+
let ended = false;
|
|
371
385
|
return new ReadableStream({
|
|
372
386
|
type: "bytes",
|
|
373
387
|
pull: async (c) => {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
for (
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
388
|
+
if (!pending?.length) {
|
|
389
|
+
let found: Uint8Array<ArrayBuffer> | undefined;
|
|
390
|
+
for (
|
|
391
|
+
let done: boolean | undefined;
|
|
392
|
+
!(found = this.#find(needle)) && !done;
|
|
393
|
+
done = this.#read(await this.#reader.read(), true, true)
|
|
394
|
+
) {
|
|
395
|
+
// Retain only a suffix that could begin a boundary.
|
|
396
|
+
this.#start = this.#end = this.#valid;
|
|
397
|
+
const last = this.#valid - 1;
|
|
398
|
+
const indices =
|
|
399
|
+
this.#valid > this.#offset
|
|
400
|
+
? needle.loc[this.#memory[last]!]
|
|
401
|
+
: undefined;
|
|
402
|
+
if (indices) {
|
|
403
|
+
search: for (let i = indices.length - 1; i >= 0; i--) {
|
|
404
|
+
for (
|
|
405
|
+
let match = indices[i]!, cursor = last;
|
|
406
|
+
match >= 0 &&
|
|
407
|
+
cursor >= this.#offset &&
|
|
408
|
+
needle[match] === this.#memory[cursor];
|
|
409
|
+
match--, cursor--
|
|
410
|
+
) {
|
|
411
|
+
if (match === 0) {
|
|
412
|
+
this.#start = this.#end = cursor;
|
|
413
|
+
break search;
|
|
414
|
+
}
|
|
400
415
|
}
|
|
401
416
|
}
|
|
402
417
|
}
|
|
418
|
+
pending = this.#shift();
|
|
419
|
+
if (pending.length) break;
|
|
420
|
+
if (this.#memory !== this.#scratch) this.#retain();
|
|
403
421
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
c.enqueue(before);
|
|
408
|
-
return; // wait for next pull
|
|
422
|
+
if (!pending?.length) {
|
|
423
|
+
pending = found;
|
|
424
|
+
ended = true;
|
|
409
425
|
}
|
|
410
426
|
}
|
|
411
427
|
|
|
412
|
-
if (
|
|
413
|
-
|
|
414
|
-
|
|
428
|
+
if (pending?.length) {
|
|
429
|
+
const request = c.byobRequest;
|
|
430
|
+
const view = request?.view;
|
|
431
|
+
if (view) {
|
|
432
|
+
const length = Math.min(view.byteLength, pending.length);
|
|
433
|
+
new Uint8Array(view.buffer, view.byteOffset, length).set(
|
|
434
|
+
pending.subarray(0, length),
|
|
435
|
+
);
|
|
436
|
+
pending = pending.subarray(length);
|
|
437
|
+
request.respond(length);
|
|
438
|
+
} else {
|
|
439
|
+
// Byte-stream enqueue transfers this independent allocation.
|
|
440
|
+
c.enqueue(new Uint8Array(pending));
|
|
441
|
+
pending = undefined;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
if (this.#memory !== this.#scratch) {
|
|
445
|
+
// Source buffers may be reused on the next pull. Borrow only
|
|
446
|
+
// within this synchronous continuation, including small BYOB reads.
|
|
447
|
+
if (pending?.length) pending = new Uint8Array(pending);
|
|
448
|
+
this.#retain();
|
|
449
|
+
}
|
|
450
|
+
if (ended && !pending?.length) {
|
|
451
|
+
c.close();
|
|
452
|
+
// An empty part or final short BYOB read still needs a response.
|
|
453
|
+
c.byobRequest?.respond(0);
|
|
454
|
+
}
|
|
415
455
|
},
|
|
416
456
|
});
|
|
417
457
|
}
|
|
@@ -447,14 +487,14 @@ export class Multipart extends Request {
|
|
|
447
487
|
|
|
448
488
|
if (
|
|
449
489
|
// ensures invalid characters aren't used to determine if it's done
|
|
450
|
-
this.#valid > 1 &&
|
|
490
|
+
this.#valid - this.#offset > 1 &&
|
|
451
491
|
// check for --
|
|
452
492
|
// if not done it would be \r\nNEXT-HEADER
|
|
453
|
-
this.#memory[
|
|
454
|
-
this.#memory[1] === 45
|
|
493
|
+
this.#memory[this.#offset] === 45 &&
|
|
494
|
+
this.#memory[this.#offset + 1] === 45
|
|
455
495
|
) {
|
|
456
496
|
// done, drain any epilogue
|
|
457
|
-
while (!(await this.#read(false))
|
|
497
|
+
while (!this.#read(await this.#reader.read(), false));
|
|
458
498
|
break;
|
|
459
499
|
}
|
|
460
500
|
}
|
package/src/render/index.ts
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import type { JSX } from "../jsx/index.js";
|
|
2
2
|
import { Codec, Size } from "../util/index.js";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/** Completed generator read */
|
|
5
|
+
type Read = {
|
|
6
|
+
/** Index of the generator within the merged list */
|
|
7
|
+
i: number;
|
|
8
|
+
|
|
9
|
+
/** Result returned by the generator */
|
|
10
|
+
result: IteratorResult<Chunk, void>;
|
|
11
|
+
};
|
|
5
12
|
|
|
6
13
|
/** Chunk containing the HTML from a rendered element */
|
|
7
14
|
class Chunk {
|
|
@@ -59,7 +66,7 @@ export class Render {
|
|
|
59
66
|
readonly #element: JSX.Element;
|
|
60
67
|
|
|
61
68
|
/** Render options */
|
|
62
|
-
readonly #options
|
|
69
|
+
readonly #options: Render.Options | undefined;
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
72
|
* Creates an `AsyncIterable` that renders the `Element`.
|
|
@@ -98,8 +105,10 @@ export class Render {
|
|
|
98
105
|
if (typeof element === "object") {
|
|
99
106
|
if (Symbol.asyncIterator in element) {
|
|
100
107
|
// any async iterable - lazily resolve
|
|
101
|
-
for await (const children of element)
|
|
102
|
-
|
|
108
|
+
for await (const children of element) {
|
|
109
|
+
if (children instanceof Chunk) yield children;
|
|
110
|
+
else yield* new Render(children, this.#options);
|
|
111
|
+
}
|
|
103
112
|
return;
|
|
104
113
|
}
|
|
105
114
|
|
|
@@ -107,8 +116,10 @@ export class Render {
|
|
|
107
116
|
// sync iterable
|
|
108
117
|
if ("next" in element) {
|
|
109
118
|
// sync generator - lazily resolve, avoids loading all in memory
|
|
110
|
-
for (const children of element)
|
|
111
|
-
|
|
119
|
+
for (const children of element) {
|
|
120
|
+
if (children instanceof Chunk) yield children;
|
|
121
|
+
else yield* new Render(children, this.#options);
|
|
122
|
+
}
|
|
112
123
|
return;
|
|
113
124
|
}
|
|
114
125
|
|
|
@@ -248,49 +259,60 @@ export class Render {
|
|
|
248
259
|
);
|
|
249
260
|
}
|
|
250
261
|
|
|
251
|
-
/**
|
|
252
|
-
* @param gen
|
|
253
|
-
* @param i index of the generator within the list
|
|
254
|
-
* @returns promise containing the index and the next result of the iteration
|
|
255
|
-
*/
|
|
256
|
-
static async #next(
|
|
257
|
-
gen: AsyncGenerator<Chunk, void, unknown>,
|
|
258
|
-
i: number,
|
|
259
|
-
): Promise<Next> {
|
|
260
|
-
return { i, result: await gen.next() };
|
|
261
|
-
}
|
|
262
|
-
|
|
263
262
|
/**
|
|
264
263
|
* Merges `Render[]` into a single `AsyncGenerator`, resolving all in parallel.
|
|
265
264
|
* The return of each `Render` is yielded from the generator with `done: true`.
|
|
266
265
|
*
|
|
267
|
-
* Adapted from [stack overflow answers](https://stackoverflow.com/questions/50585456).
|
|
268
|
-
*
|
|
269
266
|
* @param renders Resolved in parallel.
|
|
270
|
-
* @yields
|
|
267
|
+
* @yields Iteration result and index of the resolved generator.
|
|
271
268
|
*/
|
|
272
269
|
static async *#merge(renders: Render[]) {
|
|
273
270
|
const generators = renders.map((render) => render[Symbol.asyncIterator]());
|
|
274
|
-
const
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
let
|
|
271
|
+
const ready: Read[] = [];
|
|
272
|
+
let cursor = 0;
|
|
273
|
+
let active = generators.length;
|
|
274
|
+
let notify: (() => void) | undefined;
|
|
275
|
+
let error: unknown;
|
|
276
|
+
let failed = false;
|
|
277
|
+
let value: Read;
|
|
278
|
+
|
|
279
|
+
// keep one read in flight per generator
|
|
280
|
+
const next = (i: number) => {
|
|
281
|
+
generators[i]!.next().then(
|
|
282
|
+
(result) => {
|
|
283
|
+
ready.push({ i, result });
|
|
284
|
+
notify?.();
|
|
285
|
+
notify = undefined;
|
|
286
|
+
},
|
|
287
|
+
(reason) => {
|
|
288
|
+
if (!failed) error = reason;
|
|
289
|
+
failed = true;
|
|
290
|
+
notify?.();
|
|
291
|
+
notify = undefined;
|
|
292
|
+
},
|
|
293
|
+
);
|
|
294
|
+
};
|
|
281
295
|
|
|
282
296
|
try {
|
|
283
|
-
|
|
284
|
-
yield (next = await Promise.race(promises.values()));
|
|
297
|
+
for (let i = 0; i < active; i++) next(i);
|
|
285
298
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
while (active) {
|
|
300
|
+
if (cursor === ready.length) {
|
|
301
|
+
ready.length = cursor = 0;
|
|
302
|
+
if (!failed) await new Promise<void>((resolve) => (notify = resolve));
|
|
290
303
|
}
|
|
304
|
+
|
|
305
|
+
if (failed) throw error;
|
|
306
|
+
|
|
307
|
+
yield (value = ready[cursor++]!);
|
|
308
|
+
|
|
309
|
+
if (value.result.done) active--;
|
|
310
|
+
else next(value.i);
|
|
291
311
|
}
|
|
292
312
|
} finally {
|
|
293
|
-
|
|
313
|
+
if (active) {
|
|
314
|
+
await Promise.allSettled(generators.map((gen) => gen.return()));
|
|
315
|
+
}
|
|
294
316
|
}
|
|
295
317
|
}
|
|
296
318
|
}
|
package/src/route/index.ts
CHANGED
|
@@ -153,18 +153,19 @@ export namespace Route {
|
|
|
153
153
|
// Iterable is more accurate than the built in string[][] + URLSearchParams
|
|
154
154
|
// https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/2070
|
|
155
155
|
| Iterable<[string, string]>
|
|
156
|
-
| Record<string, string
|
|
156
|
+
| Record<string, string>
|
|
157
|
+
| undefined;
|
|
157
158
|
|
|
158
159
|
/**
|
|
159
160
|
* Hash (fragment) of the URL. `"#"` prefix is added if not present.
|
|
160
161
|
*
|
|
161
162
|
* [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/URL/hash)
|
|
162
163
|
*/
|
|
163
|
-
readonly hash?: string;
|
|
164
|
+
readonly hash?: string | undefined;
|
|
164
165
|
} & (keyof Params extends never
|
|
165
166
|
? {
|
|
166
167
|
/** Route pattern does not contain parameters */
|
|
167
|
-
readonly params?:
|
|
168
|
+
readonly params?: undefined;
|
|
168
169
|
}
|
|
169
170
|
: {
|
|
170
171
|
/** Route pattern parameters */
|
|
@@ -196,7 +197,7 @@ export namespace Route {
|
|
|
196
197
|
*/
|
|
197
198
|
export type Form<Pattern extends string> = (
|
|
198
199
|
props: JSX.IntrinsicElements["form"] &
|
|
199
|
-
URLOptions<ExtractParams<Pattern>> & { state?: URL },
|
|
200
|
+
URLOptions<ExtractParams<Pattern>> & { state?: URL | undefined },
|
|
200
201
|
) => JSX.Element;
|
|
201
202
|
|
|
202
203
|
/**
|
package/src/schema/index.ts
CHANGED
|
@@ -42,8 +42,7 @@ export namespace Schema {
|
|
|
42
42
|
* @template V Extra valid result metadata
|
|
43
43
|
*/
|
|
44
44
|
export type Result<O, M extends object = {}, V extends object = {}> =
|
|
45
|
-
|
|
46
|
-
| (Invalid & M);
|
|
45
|
+
(Valid<O> & V) | (Invalid & M);
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Type of constructor input (path is required).
|
|
@@ -296,7 +295,7 @@ export class Schema<Output> implements StandardSchemaV1<unknown, Output> {
|
|
|
296
295
|
readonly issues: Schema.Issue.List;
|
|
297
296
|
|
|
298
297
|
/** User submitted / sanitized values */
|
|
299
|
-
readonly values
|
|
298
|
+
readonly values: Form.Value.Map | undefined;
|
|
300
299
|
|
|
301
300
|
/**
|
|
302
301
|
* Create a new AggregateIssue.
|
|
@@ -1369,7 +1368,7 @@ export namespace Form {
|
|
|
1369
1368
|
} & M,
|
|
1370
1369
|
{
|
|
1371
1370
|
/** Rest of the multipart parts to stream */
|
|
1372
|
-
readonly stream?: AsyncGenerator<Multipart.Part
|
|
1371
|
+
readonly stream?: AsyncGenerator<Multipart.Part> | undefined;
|
|
1373
1372
|
}
|
|
1374
1373
|
>;
|
|
1375
1374
|
|
|
@@ -1579,11 +1578,9 @@ export class Form<Shape extends Form.Shape = Form.Shape> {
|
|
|
1579
1578
|
const current = this.#sanitize(result.data.values);
|
|
1580
1579
|
|
|
1581
1580
|
return {
|
|
1582
|
-
...
|
|
1583
|
-
values:
|
|
1584
|
-
|
|
1585
|
-
({ ...values, ...current } as Form.Value.Map<Shape>),
|
|
1586
|
-
};
|
|
1581
|
+
...result.data,
|
|
1582
|
+
values: (values || current) && { ...values, ...current },
|
|
1583
|
+
} as unknown as Form.State<Shape>;
|
|
1587
1584
|
}
|
|
1588
1585
|
} catch {}
|
|
1589
1586
|
}
|
|
@@ -1833,7 +1830,7 @@ class FieldSchema<
|
|
|
1833
1830
|
readonly parts: number;
|
|
1834
1831
|
|
|
1835
1832
|
/** If the field should be streamed as a part */
|
|
1836
|
-
readonly streaming
|
|
1833
|
+
readonly streaming: Stream | undefined;
|
|
1837
1834
|
|
|
1838
1835
|
/** If the field should persist invalid-state values. */
|
|
1839
1836
|
readonly #persist: boolean;
|
|
@@ -1911,7 +1908,7 @@ class FieldSchema<
|
|
|
1911
1908
|
* @returns Field that persists submitted values across invalid redirects
|
|
1912
1909
|
*/
|
|
1913
1910
|
persist<
|
|
1914
|
-
U extends Tag extends "input" ? Exclude<Type, "password" | "file"> : Type,
|
|
1911
|
+
U extends (Tag extends "input" ? Exclude<Type, "password" | "file"> : Type),
|
|
1915
1912
|
>(
|
|
1916
1913
|
this: Field.Instance<Output, Tag, U, Values, Stream>,
|
|
1917
1914
|
): Field.Instance<Output, Tag, U, Values, Stream>;
|
|
@@ -2168,7 +2165,7 @@ export namespace Field {
|
|
|
2168
2165
|
readonly values?: V;
|
|
2169
2166
|
|
|
2170
2167
|
/** Field props */
|
|
2171
|
-
readonly props?: Props;
|
|
2168
|
+
readonly props?: Props | undefined;
|
|
2172
2169
|
}
|
|
2173
2170
|
|
|
2174
2171
|
/**
|
|
@@ -2178,10 +2175,7 @@ export namespace Field {
|
|
|
2178
2175
|
* and checkboxes read presence.
|
|
2179
2176
|
*/
|
|
2180
2177
|
export type Input =
|
|
2181
|
-
| FormDataEntryValue
|
|
2182
|
-
| FormDataEntryValue[]
|
|
2183
|
-
| boolean
|
|
2184
|
-
| undefined;
|
|
2178
|
+
FormDataEntryValue | FormDataEntryValue[] | boolean | undefined;
|
|
2185
2179
|
|
|
2186
2180
|
/**
|
|
2187
2181
|
* @param data FormData or URLSearchParams
|
|
@@ -2240,7 +2234,7 @@ export namespace Field {
|
|
|
2240
2234
|
readonly name: ShapeUtil.Name<S>;
|
|
2241
2235
|
|
|
2242
2236
|
/** Form state */
|
|
2243
|
-
readonly state?: I extends true ? URL : Form.State<S
|
|
2237
|
+
readonly state?: (I extends true ? URL : Form.State<S>) | undefined;
|
|
2244
2238
|
} & Field.Props;
|
|
2245
2239
|
|
|
2246
2240
|
/** Root element for the Field component */
|
package/src/trie/index.ts
CHANGED
|
@@ -30,16 +30,16 @@ export class Trie {
|
|
|
30
30
|
readonly seg: string;
|
|
31
31
|
|
|
32
32
|
/** Static child node map, key is the first character in the segment */
|
|
33
|
-
map
|
|
33
|
+
map: Map<number, Trie> | undefined;
|
|
34
34
|
|
|
35
35
|
/** Parametric child node */
|
|
36
|
-
param
|
|
36
|
+
param: ParamNode | undefined;
|
|
37
37
|
|
|
38
38
|
/** Matched route */
|
|
39
|
-
route
|
|
39
|
+
route: Route | undefined;
|
|
40
40
|
|
|
41
41
|
/** Matched wildcard route */
|
|
42
|
-
wild
|
|
42
|
+
wild: Route | undefined;
|
|
43
43
|
|
|
44
44
|
static readonly #paramMatch = /:.+?(?=\/|$)/g;
|
|
45
45
|
static readonly #paramSplit = /:.+?(?=\/|$)/;
|
|
@@ -180,7 +180,7 @@ export class Trie {
|
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
// check if the staticSegment matches the current node
|
|
183
|
-
for (let charIndex = 0; ;
|
|
183
|
+
for (let charIndex = 0; ;) {
|
|
184
184
|
if (charIndex === staticSegment.length) {
|
|
185
185
|
// finished iterating through the staticSegment
|
|
186
186
|
if (charIndex < current.seg.length) {
|
|
@@ -248,21 +248,25 @@ export class Trie {
|
|
|
248
248
|
|
|
249
249
|
/**
|
|
250
250
|
* @param pathname Path to find
|
|
251
|
+
* @param start Start of the current segment within the pathname
|
|
251
252
|
* @returns `Route` and the matched `params` if found, otherwise `null`
|
|
252
253
|
*/
|
|
253
|
-
find(
|
|
254
|
-
|
|
254
|
+
find(
|
|
255
|
+
pathname: string,
|
|
256
|
+
start = 0,
|
|
257
|
+
): { route: Route; params: Trie.Params } | null {
|
|
258
|
+
const end = start + this.seg.length;
|
|
255
259
|
|
|
256
260
|
if (
|
|
257
261
|
// too short
|
|
258
|
-
pathname.length <
|
|
262
|
+
pathname.length < end ||
|
|
259
263
|
// segment does not match current node segment
|
|
260
|
-
!pathname.startsWith(this.seg)
|
|
264
|
+
!pathname.startsWith(this.seg, start)
|
|
261
265
|
) {
|
|
262
266
|
return null;
|
|
263
267
|
}
|
|
264
268
|
|
|
265
|
-
if (pathname ===
|
|
269
|
+
if (pathname.length === end) {
|
|
266
270
|
// reached the end of the path
|
|
267
271
|
if (this.route) return { route: this.route, params: {} };
|
|
268
272
|
|
|
@@ -273,20 +277,20 @@ export class Trie {
|
|
|
273
277
|
|
|
274
278
|
if (this.map) {
|
|
275
279
|
// check for a static leaf that starts with the first character
|
|
276
|
-
const staticChild = this.map.get(pathname.charCodeAt(
|
|
280
|
+
const staticChild = this.map.get(pathname.charCodeAt(end));
|
|
277
281
|
|
|
278
282
|
if (staticChild) {
|
|
279
|
-
const result = staticChild.find(pathname
|
|
283
|
+
const result = staticChild.find(pathname, end);
|
|
280
284
|
if (result) return result;
|
|
281
285
|
}
|
|
282
286
|
}
|
|
283
287
|
|
|
284
288
|
// check for param leaf
|
|
285
289
|
if (this.param) {
|
|
286
|
-
const slashIndex = pathname.indexOf("/",
|
|
290
|
+
const slashIndex = pathname.indexOf("/", end);
|
|
287
291
|
|
|
288
292
|
// if there is not a slash immediately following this.segment
|
|
289
|
-
if (slashIndex !==
|
|
293
|
+
if (slashIndex !== end) {
|
|
290
294
|
// there is a valid parameter
|
|
291
295
|
if (
|
|
292
296
|
// param is the end of the pathname
|
|
@@ -295,19 +299,16 @@ export class Trie {
|
|
|
295
299
|
) {
|
|
296
300
|
return {
|
|
297
301
|
route: this.param.route,
|
|
298
|
-
params: { [this.param.name]: pathname.slice(
|
|
302
|
+
params: { [this.param.name]: pathname.slice(end) },
|
|
299
303
|
};
|
|
300
304
|
} else if (this.param.child) {
|
|
301
305
|
// there's a static node after the param
|
|
302
306
|
// this is how there can be multiple params, "/" in between
|
|
303
|
-
const result = this.param.child.find(pathname
|
|
307
|
+
const result = this.param.child.find(pathname, slashIndex);
|
|
304
308
|
|
|
305
309
|
if (result) {
|
|
306
310
|
// add original params to the result
|
|
307
|
-
result.params[this.param.name] = pathname.slice(
|
|
308
|
-
segmentLength,
|
|
309
|
-
slashIndex,
|
|
310
|
-
);
|
|
311
|
+
result.params[this.param.name] = pathname.slice(end, slashIndex);
|
|
311
312
|
|
|
312
313
|
return result;
|
|
313
314
|
}
|
|
@@ -317,10 +318,7 @@ export class Trie {
|
|
|
317
318
|
|
|
318
319
|
// check for wildcard leaf
|
|
319
320
|
if (this.wild) {
|
|
320
|
-
return {
|
|
321
|
-
route: this.wild,
|
|
322
|
-
params: { "*": pathname.slice(segmentLength) },
|
|
323
|
-
};
|
|
321
|
+
return { route: this.wild, params: { "*": pathname.slice(end) } };
|
|
324
322
|
}
|
|
325
323
|
|
|
326
324
|
return null;
|