ovr 6.2.2 → 6.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.
@@ -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
- | (Valid<O> & V)
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?: Form.Value.Map;
298
+ readonly values: Form.Value.Map | undefined;
300
299
 
301
300
  /**
302
301
  * Create a new AggregateIssue.
@@ -390,8 +389,8 @@ export class Schema<Output> implements StandardSchemaV1<unknown, Output> {
390
389
  */
391
390
  optional(this: Schema<Output>): Schema<Output | undefined>;
392
391
  optional(this: Schema<Output>) {
393
- return this.derive((v, path) => {
394
- if (v === undefined) return { data: v as Output | undefined };
392
+ return this.derive<Output | undefined>((v, path) => {
393
+ if (v === undefined) return { data: undefined };
395
394
 
396
395
  return this.parse(v, path);
397
396
  });
@@ -415,8 +414,8 @@ export class Schema<Output> implements StandardSchemaV1<unknown, Output> {
415
414
  */
416
415
  nullable(this: Schema<Output>): Schema<Output | null>;
417
416
  nullable(this: Schema<Output>) {
418
- return this.derive((v, path) => {
419
- if (v === null) return { data: v as Output | null };
417
+ return this.derive<Output | null>((v, path) => {
418
+ if (v === null) return { data: null };
420
419
 
421
420
  return this.parse(v, path);
422
421
  });
@@ -440,8 +439,8 @@ export class Schema<Output> implements StandardSchemaV1<unknown, Output> {
440
439
  */
441
440
  nullish(this: Schema<Output>): Schema<Output | null | undefined>;
442
441
  nullish(this: Schema<Output>) {
443
- return this.derive((v, path) => {
444
- if (v == null) return { data: v as Output | null | undefined };
442
+ return this.derive<Output | null | undefined>((v, path) => {
443
+ if (v == null) return { data: v };
445
444
 
446
445
  return this.parse(v, path);
447
446
  });
@@ -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
- ...(result.data as Form.State<Shape>),
1583
- values:
1584
- (values || current) &&
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?: Stream;
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?: Map<number, Trie>;
33
+ map: Map<number, Trie> | undefined;
34
34
 
35
35
  /** Parametric child node */
36
- param?: ParamNode;
36
+ param: ParamNode | undefined;
37
37
 
38
38
  /** Matched route */
39
- route?: Route;
39
+ route: Route | undefined;
40
40
 
41
41
  /** Matched wildcard route */
42
- wild?: Route;
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(pathname: string): { route: Route; params: Trie.Params } | null {
254
- const segmentLength = this.seg.length;
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 < segmentLength ||
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 === this.seg) {
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(segmentLength));
280
+ const staticChild = this.map.get(pathname.charCodeAt(end));
277
281
 
278
282
  if (staticChild) {
279
- const result = staticChild.find(pathname.slice(segmentLength));
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("/", segmentLength);
290
+ const slashIndex = pathname.indexOf("/", end);
287
291
 
288
292
  // if there is not a slash immediately following this.segment
289
- if (slashIndex !== segmentLength) {
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(segmentLength) },
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.slice(slashIndex));
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;
package/src/util/index.ts CHANGED
@@ -119,7 +119,7 @@ export class Header {
119
119
  if (header) {
120
120
  const headerLength = header.length;
121
121
 
122
- for (let cursor = 0; cursor < headerLength; ) {
122
+ for (let cursor = 0; cursor < headerLength;) {
123
123
  const equal = header.indexOf("=", cursor);
124
124
  if (equal === -1) break; // done
125
125