ovr 6.2.4 → 7.0.0-next.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.
Files changed (136) hide show
  1. package/README.md +3 -1
  2. package/dist/app/index.d.ts +51 -7
  3. package/dist/app/index.d.ts.map +1 -1
  4. package/dist/app/index.js +163 -28
  5. package/dist/auth/auth-data.d.ts +26 -0
  6. package/dist/auth/auth-data.d.ts.map +1 -0
  7. package/dist/auth/auth-data.js +42 -0
  8. package/dist/auth/cbor.d.ts +50 -0
  9. package/dist/auth/cbor.d.ts.map +1 -0
  10. package/dist/auth/cbor.js +200 -0
  11. package/dist/auth/client-source.d.ts +3 -0
  12. package/dist/auth/client-source.d.ts.map +1 -0
  13. package/dist/auth/client-source.js +3 -0
  14. package/dist/auth/client.d.ts +3 -0
  15. package/dist/auth/client.d.ts.map +1 -0
  16. package/dist/auth/client.js +186 -0
  17. package/dist/auth/configure.d.ts +28 -0
  18. package/dist/auth/configure.d.ts.map +1 -0
  19. package/dist/auth/configure.js +228 -0
  20. package/dist/auth/der.d.ts +6 -0
  21. package/dist/auth/der.d.ts.map +1 -0
  22. package/dist/auth/der.js +36 -0
  23. package/dist/auth/index.d.ts +242 -0
  24. package/dist/auth/index.d.ts.map +1 -0
  25. package/dist/auth/index.js +152 -0
  26. package/dist/auth/issue.d.ts +36 -0
  27. package/dist/auth/issue.d.ts.map +1 -0
  28. package/dist/auth/issue.js +47 -0
  29. package/dist/auth/metadata.d.ts +22 -0
  30. package/dist/auth/metadata.d.ts.map +1 -0
  31. package/dist/auth/metadata.js +134 -0
  32. package/dist/auth/oauth.d.ts +29 -0
  33. package/dist/auth/oauth.d.ts.map +1 -0
  34. package/dist/auth/oauth.js +724 -0
  35. package/dist/auth/passkey.d.ts +101 -0
  36. package/dist/auth/passkey.d.ts.map +1 -0
  37. package/dist/auth/passkey.js +393 -0
  38. package/dist/auth/state.d.ts +49 -0
  39. package/dist/auth/state.d.ts.map +1 -0
  40. package/dist/auth/state.js +184 -0
  41. package/dist/auth/storage.d.ts +193 -0
  42. package/dist/auth/storage.d.ts.map +1 -0
  43. package/dist/auth/storage.js +410 -0
  44. package/dist/auth/token.d.ts +12 -0
  45. package/dist/auth/token.d.ts.map +1 -0
  46. package/dist/auth/token.js +39 -0
  47. package/dist/context/index.d.ts +86 -16
  48. package/dist/context/index.d.ts.map +1 -1
  49. package/dist/context/index.js +166 -42
  50. package/dist/cookie/index.d.ts +3 -0
  51. package/dist/cookie/index.d.ts.map +1 -1
  52. package/dist/cookie/index.js +1 -0
  53. package/dist/database/index.d.ts +262 -0
  54. package/dist/database/index.d.ts.map +1 -0
  55. package/dist/database/index.js +807 -0
  56. package/dist/form/index.d.ts +699 -0
  57. package/dist/form/index.d.ts.map +1 -0
  58. package/dist/form/index.js +901 -0
  59. package/dist/index.d.ts +10 -3
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +9 -3
  62. package/dist/jsx/elements.d.ts +28 -2
  63. package/dist/jsx/elements.d.ts.map +1 -1
  64. package/dist/jsx/index.d.ts +20 -4
  65. package/dist/jsx/index.d.ts.map +1 -1
  66. package/dist/jsx/index.js +6 -65
  67. package/dist/limiter/index.d.ts +65 -0
  68. package/dist/limiter/index.d.ts.map +1 -0
  69. package/dist/limiter/index.js +157 -0
  70. package/dist/markdown/index.d.ts +61 -0
  71. package/dist/markdown/index.d.ts.map +1 -0
  72. package/dist/markdown/index.js +1160 -0
  73. package/dist/markup/index.d.ts +188 -0
  74. package/dist/markup/index.d.ts.map +1 -0
  75. package/dist/markup/index.js +718 -0
  76. package/dist/mcp/index.d.ts +73 -0
  77. package/dist/mcp/index.d.ts.map +1 -0
  78. package/dist/mcp/index.js +988 -0
  79. package/dist/middleware/index.d.ts +3 -4
  80. package/dist/middleware/index.d.ts.map +1 -1
  81. package/dist/multipart/index.d.ts +53 -7
  82. package/dist/multipart/index.d.ts.map +1 -1
  83. package/dist/multipart/index.js +332 -124
  84. package/dist/route/index.d.ts +226 -80
  85. package/dist/route/index.d.ts.map +1 -1
  86. package/dist/route/index.js +239 -99
  87. package/dist/schema/index.d.ts +307 -734
  88. package/dist/schema/index.d.ts.map +1 -1
  89. package/dist/schema/index.js +783 -1050
  90. package/dist/table/index.d.ts +132 -0
  91. package/dist/table/index.d.ts.map +1 -0
  92. package/dist/table/index.js +188 -0
  93. package/dist/trie/index.js +4 -4
  94. package/dist/util/index.d.ts +37 -5
  95. package/dist/util/index.d.ts.map +1 -1
  96. package/dist/util/index.js +156 -41
  97. package/package.json +11 -4
  98. package/src/app/index.ts +230 -42
  99. package/src/auth/auth-data.ts +56 -0
  100. package/src/auth/cbor.ts +231 -0
  101. package/src/auth/client-source.ts +3 -0
  102. package/src/auth/client.ts +205 -0
  103. package/src/auth/configure.ts +279 -0
  104. package/src/auth/der.ts +35 -0
  105. package/src/auth/index.ts +387 -0
  106. package/src/auth/issue.ts +52 -0
  107. package/src/auth/metadata.ts +149 -0
  108. package/src/auth/oauth.ts +882 -0
  109. package/src/auth/passkey.ts +556 -0
  110. package/src/auth/state.ts +213 -0
  111. package/src/auth/storage.ts +572 -0
  112. package/src/auth/token.ts +67 -0
  113. package/src/context/index.ts +240 -65
  114. package/src/cookie/index.ts +3 -0
  115. package/src/database/index.ts +1193 -0
  116. package/src/form/index.ts +1720 -0
  117. package/src/index.ts +10 -3
  118. package/src/jsx/elements.ts +45 -25
  119. package/src/jsx/index.ts +24 -69
  120. package/src/limiter/index.ts +221 -0
  121. package/src/markdown/index.ts +1322 -0
  122. package/src/markup/index.ts +853 -0
  123. package/src/mcp/conformance.2025-11-25.yml +39 -0
  124. package/src/mcp/conformance.2026-07-28.yml +56 -0
  125. package/src/mcp/index.ts +1262 -0
  126. package/src/middleware/index.ts +5 -6
  127. package/src/multipart/index.ts +410 -158
  128. package/src/route/index.ts +559 -278
  129. package/src/schema/index.ts +1542 -2256
  130. package/src/table/index.ts +387 -0
  131. package/src/trie/index.ts +4 -4
  132. package/src/util/index.ts +163 -49
  133. package/dist/render/index.d.ts +0 -79
  134. package/dist/render/index.d.ts.map +0 -1
  135. package/dist/render/index.js +0 -257
  136. package/src/render/index.ts +0 -314
@@ -1,6 +1,41 @@
1
- import { type JSX } from "../jsx/index.js";
2
- import { Multipart } from "../multipart/index.js";
3
- import type { StandardSchemaV1 } from "@standard-schema/spec";
1
+ import type { Field } from "../form/index.js";
2
+ import type { StandardJSONSchemaV1, StandardSchemaV1 } from "@standard-schema/spec";
3
+ /**
4
+ * Keywords a schema adds to its JSON Schema as an object's property, which
5
+ * fields use for their label and an unchecked box's default.
6
+ */
7
+ export declare const annotate: unique symbol;
8
+ /**
9
+ * Preprocessors that only normalize input, so a stored value parses unchanged.
10
+ * Tables allow these and reject other preprocessors.
11
+ */
12
+ export declare const normalizers: WeakSet<(value: any) => unknown>;
13
+ /**
14
+ * Set a property, defining `__proto__` as data since assigning it would
15
+ * change the object's prototype.
16
+ *
17
+ * @param data Object to set it on
18
+ * @param name Property name
19
+ * @param value Property value
20
+ */
21
+ export declare const own: (data: Record<string, unknown>, name: string, value: unknown) => void;
22
+ /**
23
+ * Add issues to a list, one at a time, since spreading a very long list
24
+ * into `push` overflows the stack.
25
+ *
26
+ * @template I Issue
27
+ * @param issues List to add to
28
+ * @param more Issues to add
29
+ */
30
+ export declare const append: <I>(issues: I[], more: readonly I[]) => void;
31
+ /**
32
+ * Convert to a number without rounding. Integers beyond 2^53 were or would
33
+ * be rounded, so they are left as text, which fails a number's validation.
34
+ *
35
+ * @param value Value to convert, such as form text or a driver's `numeric`
36
+ * @returns The number, or the text of an integer too large to be one
37
+ */
38
+ export declare const exact: (value: unknown) => string | number;
4
39
  export declare namespace Schema {
5
40
  /**
6
41
  * `Schema.parse` function type
@@ -23,7 +58,7 @@ export declare namespace Schema {
23
58
  issues?: never;
24
59
  }
25
60
  /** Invalid result type. */
26
- interface Invalid extends InstanceType<typeof Schema.AggregateIssue> {
61
+ interface Invalid extends Schema.AggregateIssue {
27
62
  data?: never;
28
63
  }
29
64
  /**
@@ -34,15 +69,6 @@ export declare namespace Schema {
34
69
  * @template V Extra valid result metadata
35
70
  */
36
71
  type Result<O, M extends object = {}, V extends object = {}> = (Valid<O> & V) | (Invalid & M);
37
- /**
38
- * Type of constructor input (path is required).
39
- *
40
- * @template O Parse output
41
- * @param value Unknown value to parse
42
- * @param path Issue path (internal)
43
- * @returns Parse result containing data or issues
44
- */
45
- type Constructor<O> = (value: unknown, path: Issue.Path) => Result<O>;
46
72
  }
47
73
  /**
48
74
  * Infer Output type of a schema or shape.
@@ -50,8 +76,119 @@ export declare namespace Schema {
50
76
  * @template S Schema or shape type to infer from
51
77
  */
52
78
  type Infer<S> = S extends Schema<infer Output> ? Output : S extends Object.Shape ? Object.Infer<S> : S extends any[] ? Infer<S[number]>[] : never;
53
- /** Schema.Issue type */
54
- type Issue = InstanceType<typeof Schema.Issue>;
79
+ namespace JsonSchema {
80
+ /** Supported JSON Schema dialects. */
81
+ type Target = "draft-2020-12" | "draft-07";
82
+ /** `toJsonSchema` options. */
83
+ interface Options {
84
+ /**
85
+ * JSON Schema dialect.
86
+ *
87
+ * @default "draft-2020-12"
88
+ */
89
+ readonly target?: Target;
90
+ /**
91
+ * Describe the accepted input or the parsed output.
92
+ *
93
+ * @default "output"
94
+ */
95
+ readonly io?: "input" | "output";
96
+ /**
97
+ * `"throw"` for values JSON Schema cannot describe (bigint, instances,
98
+ * transforms), or `"any"` to describe them as `{}`.
99
+ *
100
+ * @default "throw"
101
+ */
102
+ readonly unrepresentable?: "throw" | "any";
103
+ }
104
+ /** Resolved options used while describing a schema (internal). */
105
+ type Context = Required<Options>;
106
+ /** Description of one schema; `optional` keys are omitted from `required` (internal). */
107
+ interface Node {
108
+ readonly schema: Record<string, unknown>;
109
+ readonly optional?: boolean | undefined;
110
+ }
111
+ }
112
+ /**
113
+ * Inspectable definition of a schema.
114
+ *
115
+ * Parsing, JSON Schema, and database tables are all derived from it.
116
+ */
117
+ type Def = ({
118
+ readonly type: "unknown";
119
+ } | {
120
+ readonly type: "string" | "boolean" | "number" | "bigint" | "date";
121
+ readonly message?: string | undefined;
122
+ } | {
123
+ readonly type: "literal";
124
+ readonly value: unknown;
125
+ readonly message?: string | undefined;
126
+ } | {
127
+ readonly type: "enum";
128
+ readonly values: readonly unknown[];
129
+ readonly message?: string | undefined;
130
+ } | {
131
+ readonly type: "instance";
132
+ readonly class: new (...args: any[]) => unknown;
133
+ readonly message?: string | undefined;
134
+ } | {
135
+ readonly type: "array";
136
+ readonly item: Schema<unknown>;
137
+ readonly message?: string | undefined;
138
+ } | {
139
+ readonly type: "object";
140
+ readonly shape: Object.Shape;
141
+ readonly mode: Object.Mode;
142
+ } | {
143
+ readonly type: "union";
144
+ readonly options: readonly Schema<unknown>[];
145
+ } | {
146
+ readonly type: "optional" | "nullable" | "nullish";
147
+ readonly inner: Schema<unknown>;
148
+ } | {
149
+ readonly type: "default";
150
+ readonly inner: Schema<unknown>;
151
+ readonly value: unknown;
152
+ } | {
153
+ readonly type: "preprocess" | "transform";
154
+ readonly inner: Schema<unknown>;
155
+ readonly fn: (value: any) => unknown;
156
+ } | {
157
+ readonly type: "pipe";
158
+ readonly inner: Schema<unknown>;
159
+ readonly next: Schema<unknown>;
160
+ } | {
161
+ readonly type: "json";
162
+ readonly inner: Schema<unknown>;
163
+ readonly schema: Schema<unknown>;
164
+ readonly message?: string | undefined;
165
+ } | {
166
+ readonly type: "check";
167
+ readonly inner: Schema<unknown>;
168
+ readonly check: Check;
169
+ }) & {
170
+ /** What the value is, see `describe()` */
171
+ readonly description?: string;
172
+ };
173
+ /** Validation applied to the output of another schema. */
174
+ type Check = {
175
+ readonly name: "min" | "max";
176
+ readonly value: number | bigint;
177
+ readonly message: string;
178
+ } | {
179
+ readonly name: "int" | "email" | "url" | "uuid";
180
+ readonly message: string;
181
+ } | {
182
+ readonly name: "refine";
183
+ readonly fn: (value: any) => boolean;
184
+ readonly message: string;
185
+ };
186
+ /** Validation issue produced during parsing */
187
+ interface Issue extends IssueClass {
188
+ }
189
+ /** AggregateIssue containing at least one `Schema.Issue` */
190
+ interface AggregateIssue extends AggregateIssueClass {
191
+ }
55
192
  namespace Issue {
56
193
  /** Issue path representation. */
57
194
  type Path = (string | number)[];
@@ -62,6 +199,7 @@ export declare namespace Schema {
62
199
  * Object schema with extend capability.
63
200
  *
64
201
  * @template S Object shape type
202
+ * @template M How unknown keys are handled, `strip` by default
65
203
  */
66
204
  type Object<S extends Object.Shape, M extends Object.Mode = "strip"> = ObjectSchema<S, M>;
67
205
  namespace Object {
@@ -103,7 +241,7 @@ export declare namespace Schema {
103
241
  }
104
242
  }
105
243
  /** Shared shape types for `Shape` related runtime methods. */
106
- declare namespace ShapeUtil {
244
+ export declare namespace ShapeUtil {
107
245
  /**
108
246
  * Shape key name string.
109
247
  *
@@ -119,7 +257,7 @@ declare namespace ShapeUtil {
119
257
  type Extend<A extends Record<string, unknown>, B extends Record<string, unknown>> = globalThis.Omit<A, keyof B> & B;
120
258
  }
121
259
  /** Shared runtime shape operations used by object and form schema methods. */
122
- declare class ShapeUtil {
260
+ export declare class ShapeUtil {
123
261
  /**
124
262
  * Merge two record-like shapes where `extra` keys override `shape`.
125
263
  *
@@ -151,72 +289,67 @@ declare class ShapeUtil {
151
289
  */
152
290
  static omit<S extends Record<string, unknown>, N extends ShapeUtil.Name<S>>(shape: S, names: readonly [N, ...N[]]): Omit<S, N>;
153
291
  }
292
+ /** Validation issue produced during parsing. */
293
+ declare class Issue extends Error {
294
+ /** Expected type/value. */
295
+ readonly expected: string;
296
+ /** Path to the invalid value. */
297
+ readonly path: Schema.Issue.Path;
298
+ /**
299
+ * @param expected Expected value
300
+ * @param path Path to the invalid value
301
+ * @param message Issue message
302
+ */
303
+ constructor(expected: unknown, path: Schema.Issue.Path, message?: string);
304
+ /**
305
+ * @returns `Schema.Issue(path): message`
306
+ */
307
+ toString(): string;
308
+ toJSON(): this & {
309
+ message: string;
310
+ };
311
+ }
312
+ /** The classes `Schema`'s issue types are named for */
313
+ type IssueClass = Issue;
314
+ type AggregateIssueClass = AggregateIssue;
315
+ /** AggregateIssue containing at least one Schema.Issue */
316
+ declare class AggregateIssue extends AggregateError {
317
+ /** Non-empty tuple of issues */
318
+ readonly issues: Schema.Issue.List;
319
+ /** User submitted / sanitized values */
320
+ readonly values: Field.Value.Map | undefined;
321
+ /**
322
+ * Create a new AggregateIssue.
323
+ *
324
+ * Coerces issues into a non-empty tuple.
325
+ *
326
+ * @param issues Issues
327
+ * @param values Received values
328
+ */
329
+ constructor([first, ...rest]: Schema.Issue[], values?: Field.Value.Map);
330
+ toString(): string;
331
+ toJSON(): this & {
332
+ message: string;
333
+ };
334
+ }
154
335
  /**
155
336
  * Minimal schema validator geared around parsing form data like
156
337
  * multipart `FormData` and `URLSearchParams`.
157
338
  *
158
- * Implements Standard Schema v1 via the `~standard` property (sync validate).
339
+ * Implements Standard Schema v1 and Standard JSON Schema v1 via the
340
+ * `~standard` property (sync validate).
159
341
  *
160
342
  * @template Output Output type after parsing
161
343
  */
162
- export declare class Schema<Output> implements StandardSchemaV1<unknown, Output> {
344
+ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>, StandardJSONSchemaV1<unknown, Output> {
163
345
  #private;
164
346
  /** Validation issue produced during parsing. */
165
- static readonly Issue: {
166
- new (expected: unknown, path: Schema.Issue.Path, message?: string): {
167
- /** Expected type/value. */
168
- readonly expected: string;
169
- /** Path to the invalid value. */
170
- readonly path: Schema.Issue.Path;
171
- /**
172
- * @returns `Schema.Issue(path): message`
173
- */
174
- toString(): string;
175
- toJSON(): /*elided*/ any & {
176
- message: string;
177
- };
178
- name: string;
179
- message: string;
180
- stack?: string;
181
- cause?: unknown;
182
- };
183
- isError(error: unknown): error is Error;
184
- };
347
+ static readonly Issue: new (...args: ConstructorParameters<typeof Issue>) => Schema.Issue;
185
348
  /** AggregateIssue containing at least one Schema.Issue */
186
- static readonly AggregateIssue: {
187
- new ([first, ...rest]: {
188
- /** Expected type/value. */
189
- readonly expected: string;
190
- /** Path to the invalid value. */
191
- readonly path: Schema.Issue.Path;
192
- /**
193
- * @returns `Schema.Issue(path): message`
194
- */
195
- toString(): string;
196
- toJSON(): /*elided*/ any & {
197
- message: string;
198
- };
199
- name: string;
200
- message: string;
201
- stack?: string;
202
- cause?: unknown;
203
- }[], values?: Form.Value.Map): {
204
- /** Non-empty tuple of issues */
205
- readonly issues: Schema.Issue.List;
206
- /** User submitted / sanitized values */
207
- readonly values: Form.Value.Map | undefined;
208
- toString(): string;
209
- toJSON(): /*elided*/ any & {
210
- message: string;
211
- };
212
- name: string;
213
- message: string;
214
- stack?: string;
215
- errors: any[];
216
- cause?: unknown;
217
- };
218
- };
219
- readonly "~standard": StandardSchemaV1.Props<unknown, Output>;
349
+ static readonly AggregateIssue: new (...args: ConstructorParameters<typeof AggregateIssue>) => Schema.AggregateIssue;
350
+ readonly "~standard": StandardSchemaV1.Props<unknown, Output> & StandardJSONSchemaV1.Props<unknown, Output>;
351
+ /** Inspectable definition this schema was built from. */
352
+ readonly def: Schema.Def;
220
353
  /**
221
354
  * Parse and validate an unknown value.
222
355
  *
@@ -230,24 +363,58 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
230
363
  *
231
364
  * Use static methods on `Schema` to make a new schema.
232
365
  *
233
- * @param parse Parse function that validates and transforms input
366
+ * @param def Schema definition
234
367
  */
235
- constructor(parse: Schema.Parse.Constructor<Output>);
368
+ protected constructor(def: Schema.Def);
236
369
  /**
237
- * @internal Required for Field to override and return a `Field` instance
370
+ * Required for Field to override and return a `Field` instance
238
371
  * from the chained methods instead of a `Schema`
239
372
  * @template O Output type of the new schema
240
- * @param parse Parse function that validates and transforms input
373
+ * @param def Definition of the new schema
241
374
  * @returns New schema instance based on the current instance
242
375
  */
243
- derive<O>(parse: Schema.Parse.Constructor<O>): Schema<O>;
376
+ protected derive<O>(def: Schema.Def): Schema<O>;
377
+ /**
378
+ * Say what the value is. Agents read it as the `description` in its JSON
379
+ * Schema, such as of a tool's argument, and a field shows it to people
380
+ * under its control.
381
+ *
382
+ * ```ts
383
+ * Schema.string().uuid().describe("The bookmark's ID");
384
+ * Field.url().describe("An http or https address");
385
+ * ```
386
+ *
387
+ * @param text Description
388
+ * @returns Schema with the description
389
+ */
390
+ describe(text: string): this;
391
+ /**
392
+ * @returns The description given with `describe()`, here or on the
393
+ * schema this one wraps, such as before `optional()`
394
+ */
395
+ get description(): string | undefined;
396
+ /**
397
+ * @internal Overridden by Field to describe itself as an object's property
398
+ * @param _io Side of the description
399
+ * @returns Keywords added to the property's JSON Schema
400
+ */
401
+ [annotate](_io: "input" | "output"): Record<string, unknown> | void;
402
+ /**
403
+ * Convert the schema into a JSON Schema document.
404
+ *
405
+ * Refinements without a JSON Schema equivalent are omitted.
406
+ *
407
+ * @param options Target dialect, input/output side, and unrepresentable handling
408
+ * @returns JSON Schema object
409
+ */
410
+ toJsonSchema(options?: Schema.JsonSchema.Options): Record<string, unknown>;
244
411
  /**
245
412
  * @template T Field tag name
246
413
  * @template U Field input type attribute
247
414
  * @template V Field option values
248
415
  * @returns Optional field
249
416
  */
250
- optional<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | undefined, T, U, V>;
417
+ optional<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | undefined, T, U, V>;
251
418
  /**
252
419
  * @returns Optional schema
253
420
  */
@@ -258,7 +425,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
258
425
  * @template V Field option values
259
426
  * @returns Nullable field
260
427
  */
261
- nullable<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | null, T, U, V>;
428
+ nullable<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | null, T, U, V>;
262
429
  /**
263
430
  * @returns Nullable schema
264
431
  */
@@ -269,7 +436,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
269
436
  * @template V Field option values
270
437
  * @returns Nullish field
271
438
  */
272
- nullish<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | null | undefined, T, U, V>;
439
+ nullish<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>): Field.Instance<Output | null | undefined, T, U, V>;
273
440
  /**
274
441
  * @returns Nullish schema
275
442
  */
@@ -281,7 +448,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
281
448
  * @param value Default value to use when input is undefined
282
449
  * @returns Field with default
283
450
  */
284
- default<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>, value: Output): Field.Instance<Output, T, U, V>;
451
+ default<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>, value: Output): Field.Instance<Output, T, U, V>;
285
452
  /**
286
453
  * @param value Default value to use when input is undefined
287
454
  * @returns Schema with default
@@ -294,7 +461,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
294
461
  * @param fn Preprocess function to run before parsing
295
462
  * @returns Schema that preprocesses input before parsing
296
463
  */
297
- preprocess<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>, fn: (value: unknown) => unknown): Field.Instance<Output, T, U, V>;
464
+ preprocess<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>, fn: (value: unknown) => unknown): Field.Instance<Output, T, U, V>;
298
465
  /**
299
466
  * @param fn Preprocess function to run before parsing
300
467
  * @returns Schema that preprocesses input before parsing
@@ -308,7 +475,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
308
475
  * @param fn Transform function to apply to parsed output
309
476
  * @returns Transformed field
310
477
  */
311
- transform<O, T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>, fn: (value: Output) => O): Field.Instance<O, T, U, V>;
478
+ transform<O, T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>, fn: (value: Output) => O): Field.Instance<O, T, U, V>;
312
479
  /**
313
480
  * @template O Output type after transformation
314
481
  * @param fn Transform function to apply to parsed output
@@ -323,7 +490,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
323
490
  * @param next Schema to validate the result with
324
491
  * @returns Piped field
325
492
  */
326
- pipe<O, T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>, next: Schema<O>): Field.Instance<O, T, U, V>;
493
+ pipe<O, T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>, next: Schema<O>): Field.Instance<O, T, U, V>;
327
494
  /**
328
495
  * @template O Output type after pipe
329
496
  * @param next Schema to validate the result with
@@ -341,7 +508,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
341
508
  * @param message Issue message when invalid
342
509
  * @returns Parsed JSON field
343
510
  */
344
- json<O, T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<string, T, U, V>, schema: Schema<O>, message?: string): Field.Instance<O, T, U, V>;
511
+ json<O, T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, schema: Schema<O>, message?: string): Field.Instance<O, T, U, V>;
345
512
  /**
346
513
  * Parse a JSON string and validate the parsed value with the provided schema.
347
514
  *
@@ -361,7 +528,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
361
528
  * @param message Issue message when invalid
362
529
  * @returns Email field
363
530
  */
364
- email<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<string, T, U, V>, message?: string): Field.Instance<string, T, U, V>;
531
+ email<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, message?: string): Field.Instance<string, T, U, V>;
365
532
  /**
366
533
  * Validate an input is a valid email string using
367
534
  * [Reasonable Email Regex by Colin McDonnell](https://colinhacks.com/essays/reasonable-email-regex).
@@ -370,6 +537,23 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
370
537
  * @returns Email schema
371
538
  */
372
539
  email(this: Schema<string>, message?: string): Schema<string>;
540
+ /**
541
+ * Validate an input is a UUID string of any version.
542
+ *
543
+ * @template T Field tag name
544
+ * @template U Field input type attribute
545
+ * @template V Field option values
546
+ * @param message Issue message when invalid
547
+ * @returns UUID field
548
+ */
549
+ uuid<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, message?: string): Field.Instance<string, T, U, V>;
550
+ /**
551
+ * Validate an input is a UUID string of any version.
552
+ *
553
+ * @param message Issue message when invalid
554
+ * @returns UUID schema
555
+ */
556
+ uuid(this: Schema<string>, message?: string): Schema<string>;
373
557
  /**
374
558
  * Validate an input is a valid URL string.
375
559
  *
@@ -379,7 +563,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
379
563
  * @param message Issue message when invalid
380
564
  * @returns URL field
381
565
  */
382
- url<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<string, T, U, V>, message?: string): Field.Instance<string, T, U, V>;
566
+ url<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, message?: string): Field.Instance<string, T, U, V>;
383
567
  /**
384
568
  * Validate an input is a valid URL string.
385
569
  *
@@ -396,7 +580,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
396
580
  * @param message Issue message when invalid
397
581
  * @returns Integer field
398
582
  */
399
- int<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<number, T, U, V>, message?: string): Field.Instance<number, T, U, V>;
583
+ int<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<number, T, U, V>, message?: string): Field.Instance<number, T, U, V>;
400
584
  /**
401
585
  * Validate an input is a safe integer.
402
586
  *
@@ -407,7 +591,8 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
407
591
  /**
408
592
  * Validate an input is greater than or equal to the minimum.
409
593
  *
410
- * For strings, this validates minimum length.
594
+ * For strings, this validates minimum length in Unicode characters,
595
+ * as JSON Schema and Postgres count them.
411
596
  *
412
597
  * @template T Field tag name
413
598
  * @template U Field input type attribute
@@ -416,7 +601,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
416
601
  * @param message Issue message when invalid
417
602
  * @returns Refined field
418
603
  */
419
- min<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<string, T, U, V>, value: number, message?: string): Field.Instance<string, T, U, V>;
604
+ min<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, value: number, message?: string): Field.Instance<string, T, U, V>;
420
605
  /**
421
606
  * Validate an input is greater than or equal to the minimum.
422
607
  *
@@ -427,7 +612,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
427
612
  * @param message Issue message when invalid
428
613
  * @returns Refined field
429
614
  */
430
- min<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<number, T, U, V>, value: number, message?: string): Field.Instance<number, T, U, V>;
615
+ min<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<number, T, U, V>, value: number, message?: string): Field.Instance<number, T, U, V>;
431
616
  /**
432
617
  * Validate an input is greater than or equal to the minimum.
433
618
  *
@@ -438,11 +623,12 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
438
623
  * @param message Issue message when invalid
439
624
  * @returns Refined field
440
625
  */
441
- min<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<bigint, T, U, V>, value: bigint, message?: string): Field.Instance<bigint, T, U, V>;
626
+ min<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<bigint, T, U, V>, value: bigint, message?: string): Field.Instance<bigint, T, U, V>;
442
627
  /**
443
628
  * Validate an input is greater than or equal to the minimum.
444
629
  *
445
- * For strings, this validates minimum length.
630
+ * For strings, this validates minimum length in Unicode characters,
631
+ * as JSON Schema and Postgres count them.
446
632
  *
447
633
  * @param value Minimum value or length
448
634
  * @param message Issue message when invalid
@@ -468,7 +654,8 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
468
654
  /**
469
655
  * Validate an input is less than or equal to the maximum.
470
656
  *
471
- * For strings, this validates maximum length.
657
+ * For strings, this validates maximum length in Unicode characters,
658
+ * as JSON Schema and Postgres count them.
472
659
  *
473
660
  * @template T Field tag name
474
661
  * @template U Field input type attribute
@@ -477,7 +664,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
477
664
  * @param message Issue message when invalid
478
665
  * @returns Refined field
479
666
  */
480
- max<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<string, T, U, V>, value: number, message?: string): Field.Instance<string, T, U, V>;
667
+ max<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<string, T, U, V>, value: number, message?: string): Field.Instance<string, T, U, V>;
481
668
  /**
482
669
  * Validate an input is less than or equal to the maximum.
483
670
  *
@@ -488,7 +675,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
488
675
  * @param message Issue message when invalid
489
676
  * @returns Refined field
490
677
  */
491
- max<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<number, T, U, V>, value: number, message?: string): Field.Instance<number, T, U, V>;
678
+ max<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<number, T, U, V>, value: number, message?: string): Field.Instance<number, T, U, V>;
492
679
  /**
493
680
  * Validate an input is less than or equal to the maximum.
494
681
  *
@@ -499,11 +686,12 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
499
686
  * @param message Issue message when invalid
500
687
  * @returns Refined field
501
688
  */
502
- max<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<bigint, T, U, V>, value: bigint, message?: string): Field.Instance<bigint, T, U, V>;
689
+ max<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<bigint, T, U, V>, value: bigint, message?: string): Field.Instance<bigint, T, U, V>;
503
690
  /**
504
691
  * Validate an input is less than or equal to the maximum.
505
692
  *
506
- * For strings, this validates maximum length.
693
+ * For strings, this validates maximum length in Unicode characters,
694
+ * as JSON Schema and Postgres count them.
507
695
  *
508
696
  * @param value Maximum value or length
509
697
  * @param message Issue message when invalid
@@ -534,7 +722,7 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
534
722
  * @param message Issue message when invalid
535
723
  * @returns Refined field
536
724
  */
537
- refine<T extends Field.Tag, U extends Field.Type, V extends Field.Values | undefined>(this: Field.Instance<Output, T, U, V>, check: (value: Output) => boolean, message: string): Field.Instance<Output, T, U, V>;
725
+ refine<T extends Field.Tag, U extends Field.Type, V extends Field.Options | undefined>(this: Field.Instance<Output, T, U, V>, check: (value: Output) => boolean, message: string): Field.Instance<Output, T, U, V>;
538
726
  /**
539
727
  * @param check Validation function that returns `false` to fail
540
728
  * @param message Issue message when invalid
@@ -577,6 +765,15 @@ export declare class Schema<Output> implements StandardSchemaV1<unknown, Output>
577
765
  * @returns Big integer schema
578
766
  */
579
767
  static bigint(message?: string): Schema<bigint>;
768
+ /**
769
+ * Validate an input is a valid `Date`.
770
+ *
771
+ * Rejects invalid dates like `new Date("")`.
772
+ *
773
+ * @param message Issue message when invalid
774
+ * @returns Date schema
775
+ */
776
+ static date(message?: string): Schema<Date>;
580
777
  /**
581
778
  * @template L Literal type
582
779
  * @param literal Exact value to match
@@ -644,8 +841,10 @@ declare class ObjectSchema<Shape extends Schema.Object.Shape, Mode extends Schem
644
841
  *
645
842
  * @param shape Object shape
646
843
  * @param mode Object parsing mode
844
+ * @param description Description from `describe()`
647
845
  */
648
- constructor(shape: Shape, mode?: Mode);
846
+ constructor(shape: Shape, mode?: Mode, description?: string);
847
+ describe(text: string): this;
649
848
  /**
650
849
  * Merge `extra` into the current shape.
651
850
  *
@@ -654,6 +853,13 @@ declare class ObjectSchema<Shape extends Schema.Object.Shape, Mode extends Schem
654
853
  * @returns New object schema with the merged shape
655
854
  */
656
855
  extend<E extends Schema.Object.Shape>(extra: E): Schema.Object<ShapeUtil.Extend<Shape, E>, Mode>;
856
+ /**
857
+ * Merge the shape of `extra`, an object schema, into the current shape.
858
+ *
859
+ * @template E Extra shape type
860
+ * @param extra Object schema to merge
861
+ * @returns New object schema with the merged shape
862
+ */
657
863
  extend<E extends Schema.Object.Shape>(extra: Schema.Object<E>): Schema.Object<ShapeUtil.Extend<Shape, E>, Mode>;
658
864
  /**
659
865
  * Keep only selected field names.
@@ -684,638 +890,5 @@ declare class ObjectSchema<Shape extends Schema.Object.Shape, Mode extends Schem
684
890
  */
685
891
  loose(): Schema.Object<Shape, "loose">;
686
892
  }
687
- export declare namespace Form {
688
- /** Form field shape. */
689
- type Shape = Record<string, Field.Any>;
690
- /** Persisted form value */
691
- type Value = string | number | boolean | string[];
692
- namespace Value {
693
- /**
694
- * Value map by field name.
695
- *
696
- * @template S Shape type
697
- */
698
- type Map<S extends Shape = Shape> = Partial<Record<ShapeUtil.Name<S>, Value>>;
699
- }
700
- /**
701
- * Encoded form state.
702
- *
703
- * @template S Shape type to infer value keys from
704
- */
705
- interface State<S extends Shape = Shape> {
706
- /** Form id generated using the field names */
707
- readonly id: string;
708
- /** Non-empty list of validation issues */
709
- readonly issues?: Schema.Issue.List;
710
- /** Map of field names to possible values */
711
- readonly values?: Value.Map<S>;
712
- }
713
- namespace Parse {
714
- /**
715
- * Field names that are not marked to stream as multipart parts.
716
- *
717
- * @template S Form shape
718
- */
719
- type NonStreamNames<S extends Shape> = {
720
- [K in keyof S]-?: S[K] extends Field.Instance<any, any, any, any, infer P> ? P extends true ? never : K : never;
721
- }[keyof S];
722
- /**
723
- * Parsed data shape with streamed `stream()` fields removed.
724
- *
725
- * @template S Form shape
726
- */
727
- type NonStreamShape<S extends Shape> = Pick<S, NonStreamNames<S>>;
728
- /**
729
- * Parsed form data output.
730
- *
731
- * @template S Form shape
732
- */
733
- export type Data<S extends Shape> = Schema.Infer<NonStreamShape<S>>;
734
- /**
735
- * Form parse result.
736
- *
737
- * @template S Form shape
738
- * @template M Extra invalid result metadata
739
- */
740
- export type Result<S extends Shape, M extends object = {}> = Schema.Parse.Result<Data<S>, {
741
- /** Encoded URL search param field state */
742
- readonly search: Result.Search;
743
- /** Invalid parses do not expose remaining multipart parts */
744
- readonly stream?: never;
745
- } & M, {
746
- /** Rest of the multipart parts to stream */
747
- readonly stream?: AsyncGenerator<Multipart.Part> | undefined;
748
- }>;
749
- export namespace Result {
750
- /** Form search params iterable */
751
- type Search = [[(typeof Form.params)[1], string]] | undefined;
752
- }
753
- export {};
754
- }
755
- }
756
- /**
757
- * Form schema with JSX rendering capabilities.
758
- *
759
- * Parses `FormData` or `URLSearchParams` and generates form field
760
- * components.
761
- *
762
- * @template Shape Form field shape type
763
- */
764
- export declare class Form<Shape extends Form.Shape = Form.Shape> {
765
- #private;
766
- /** Query param keys ordered as `[return, form]`. */
767
- static readonly params: readonly ["_return", "_form"];
768
- /** Field definitions. */
769
- readonly shape: Shape;
770
- /** Field names in definition order. */
771
- readonly names: ShapeUtil.Name<Shape>[];
772
- /** Maximum expected multipart parts derived from field cardinality. */
773
- readonly parts: number;
774
- /**
775
- * Create a new form schema validator.
776
- *
777
- * @param shape Form fields
778
- */
779
- constructor(shape: Shape);
780
- /**
781
- * Merge `extra` into the current fields.
782
- *
783
- * @template E Extra field shape type
784
- * @param extra Extra fields or form schema to merge
785
- * @returns New form schema with merged fields
786
- */
787
- extend: {
788
- <E extends Form.Shape>(extra: E): Form<ShapeUtil.Extend<Shape, E>>;
789
- <E extends Form.Shape>(extra: Form<E>): Form<ShapeUtil.Extend<Shape, E>>;
790
- (extra: Form<any>): Form<ShapeUtil.Extend<Shape, Form.Shape>>;
791
- };
792
- /**
793
- * Keep only selected field names.
794
- *
795
- * @template N Selected field names
796
- * @param names Non-empty list of field names to keep
797
- * @returns New form schema with only selected fields
798
- */
799
- pick: <N extends ShapeUtil.Name<Shape>>(names: readonly [N, ...N[]]) => Form<Pick<Shape, N>>;
800
- /**
801
- * Remove selected field names.
802
- *
803
- * @template N Field names to remove
804
- * @param names Non-empty list of field names to remove
805
- * @returns New form schema without selected fields
806
- */
807
- omit: <N extends ShapeUtil.Name<Shape>>(names: readonly [N, ...N[]]) => Form<Omit<Shape, N>>;
808
- /**
809
- * Parse and validate form data.
810
- *
811
- * @param source FormData, URLSearchParams, or Multipart to parse
812
- * @param path Internal path reference
813
- * @returns Parsed result
814
- */
815
- parse: (source: FormData | URLSearchParams | Multipart, path?: Schema.Issue.Path) => Promise<Form.Parse.Result<Shape>>;
816
- /**
817
- * Render a single form field.
818
- *
819
- * @param props Component props
820
- * @example
821
- *
822
- * ```tsx
823
- * <User.Field name="username" />
824
- * ```
825
- */
826
- Field: (props: Field.Component.Props<Shape>) => JSX.Element;
827
- /**
828
- * Render all form fields.
829
- *
830
- * @param props Component props
831
- * @example
832
- *
833
- * ```tsx
834
- * <User.Fields />
835
- * ```
836
- */
837
- Fields: (props?: Partial<Field.Component.Props<Shape>>) => JSX.Element[];
838
- /**
839
- * Access bound sub-components for a field.
840
- *
841
- * @template N Type of the form field name
842
- * @param props Field component props
843
- * @example
844
- *
845
- * ```tsx
846
- * const Radio = User.component({ name: "radio" });
847
- *
848
- * <Radio.Label />
849
- * <Radio.Control />
850
- * ```
851
- */
852
- component: <N extends ShapeUtil.Name<Shape>>(props: {
853
- name: N;
854
- } & Field.Component.Props<Shape>) => Field.Component<Shape[N]>;
855
- /**
856
- * Create a Form from a shape or use another Form.
857
- *
858
- * @template S Form field shape type
859
- * @param shape Form fields
860
- */
861
- static from<S extends Form.Shape>(shape: S | Form<S>): Form<S>;
862
- }
863
- /**
864
- * Represents a form field with parsing logic and rendering metadata.
865
- *
866
- * @template Output Output type of the field
867
- * @template Tag Tag name
868
- * @template Type Input type
869
- * @template Values Persisted field value type
870
- * @template Stream If the field should be streamed as a part
871
- */
872
- declare class FieldSchema<Output = unknown, Tag extends Field.Tag = "input", Type extends Field.Type = Field.Type, Values extends Field.Values | undefined = undefined, Stream extends boolean | undefined = undefined> extends Schema<Output> {
873
- #private;
874
- /** Field type */
875
- readonly type: Type;
876
- /** Field tag */
877
- readonly tag: Tag;
878
- /** Field values */
879
- readonly values: Values;
880
- /** Maximum expected multipart part count for this field name. */
881
- readonly parts: number;
882
- /** If the field should be streamed as a part */
883
- readonly streaming: Stream | undefined;
884
- /**
885
- * Create a new field.
886
- *
887
- * @param options Field options
888
- * @param parse How to validate the input
889
- * @param read How to read the form data
890
- * @param parts Maximum expected multipart parts for this field
891
- * @param stream If this field should be streamed as a multipart part
892
- * @param persist If this field should persist invalid state values
893
- */
894
- constructor(options: Field.Options<Values, Tag>, parse: Schema<Output> | Schema.Parse.Constructor<Output>, read?: Field.Read, parts?: number, stream?: Stream, persist?: boolean);
895
- /**
896
- * @param field Field instance
897
- * @param data Form data source
898
- * @param name HTML name attribute
899
- * @returns Raw field input
900
- */
901
- static read(field: Field.Any, data: FormData | URLSearchParams, name: string): Field.Input;
902
- /**
903
- * Stream this field as a multipart request `Part`.
904
- *
905
- * @returns Part field
906
- */
907
- stream(): Field.Instance<Output, Tag, Type, Values, true>;
908
- /**
909
- * Persist this field in the encoded invalid form state.
910
- *
911
- * Use this for non-sensitive values that should refill after an invalid
912
- * redirect.
913
- *
914
- * @returns Field that persists submitted values across invalid redirects
915
- */
916
- persist<U extends (Tag extends "input" ? Exclude<Type, "password" | "file"> : Type)>(this: Field.Instance<Output, Tag, U, Values, Stream>): Field.Instance<Output, Tag, U, Values, Stream>;
917
- /**
918
- * Derive a new Field from the current instance type.
919
- *
920
- * @template O Output type of the new Field
921
- * @param parse Parse function that validates and transforms input
922
- * @returns New `Field` instance
923
- */
924
- derive<O>(parse: Schema.Parse.Constructor<O>): Field.Instance<O, Tag, Type, Values, Stream>;
925
- /**
926
- * @template S Form shape type
927
- * @param props Field control props
928
- * @returns Field component with sub-components
929
- */
930
- component<S extends Form.Shape>(props: Field.Component.Props<S, false>): Field.Component<this>;
931
- /**
932
- * @template S Form shape type
933
- * @param props Field control props including `name` of the field to render
934
- * @returns Component that renders the HTML field with default structure
935
- */
936
- render<S extends Form.Shape>(props: Field.Component.Props<S, false>): JSX.Element;
937
- /**
938
- * @param field Field definition
939
- * @returns `true` when the field persists invalid-state values
940
- */
941
- static persisted(field: Field.Any): boolean;
942
- }
943
- export declare namespace Field {
944
- /**
945
- * Base options to create a Field.
946
- *
947
- * @template V Type of the values for group inputs
948
- * @template T Tag name
949
- */
950
- interface Options<V extends Values | undefined = undefined, T extends Tag = Tag> {
951
- /**
952
- * Tag name.
953
- *
954
- * @default "input"
955
- */
956
- readonly tag?: T;
957
- /** Values are used for group inputs */
958
- readonly values?: V;
959
- /** Field props */
960
- readonly props?: Props | undefined;
961
- }
962
- /**
963
- * Raw field value before schema parsing.
964
- *
965
- * Single-value fields read one entry, multi-value fields read all entries,
966
- * and checkboxes read presence.
967
- */
968
- type Input = FormDataEntryValue | FormDataEntryValue[] | boolean | undefined;
969
- /**
970
- * @param data FormData or URLSearchParams
971
- * @param name HTML name attribute
972
- * @returns Resolved value read from the form data
973
- */
974
- type Read = (data: FormData | URLSearchParams, name: string) => Input;
975
- /** Form field tag name */
976
- type Tag = "input" | "textarea" | "select";
977
- /** `<input type=...>` */
978
- type Type = JSX.IntrinsicElements["input"]["type"];
979
- /** Value type for select and radio options */
980
- type Values = readonly [string, ...string[]];
981
- /** Field instance type */
982
- type Instance<Output = unknown, Tag extends Field.Tag = "input", Type extends Field.Type = Field.Type, Values extends Field.Values | undefined = undefined, Stream extends boolean | undefined = undefined> = FieldSchema<Output, Tag, Type, Values, Stream>;
983
- /** Any field - `<input type=...>` / `<select>` / `<textarea>` */
984
- type Any = Instance<any, Tag, Type, Values | undefined, boolean | undefined>;
985
- /**
986
- * Obtain the tag name of a field.
987
- *
988
- * @template F Field
989
- */
990
- type TagOf<F extends Any> = F extends Instance<any, infer T, Field.Type, Field.Values | undefined> ? T : Tag;
991
- namespace Component {
992
- /**
993
- * Component props available to users to pass into the
994
- * constructed `<Field />` component.
995
- *
996
- * @template S Form shape type
997
- * @template I `true` the state is a `URL`, `false` is just `State`
998
- */
999
- type Props<S extends Form.Shape, I extends boolean = true> = {
1000
- /** Field name attribute */
1001
- readonly name: ShapeUtil.Name<S>;
1002
- /** Form state */
1003
- readonly state?: (I extends true ? URL : Form.State<S>) | undefined;
1004
- } & Field.Props;
1005
- /** Root element for the Field component */
1006
- type Root = JSX.IntrinsicElements["div"];
1007
- namespace Root {
1008
- /** Root for input groups */
1009
- type Group = JSX.IntrinsicElements["fieldset"];
1010
- }
1011
- /** `<Field.Legend />` component props */
1012
- type Legend = JSX.IntrinsicElements["legend"];
1013
- /** `<Field.Issue />` component props */
1014
- type Issue = JSX.IntrinsicElements["p"];
1015
- /**
1016
- * `<Field.Control />` component props
1017
- *
1018
- * @template T Tag name
1019
- */
1020
- type Control<T extends Tag> = T extends "textarea" ? JSX.IntrinsicElements["textarea"] : T extends "select" ? JSX.IntrinsicElements["select"] : JSX.IntrinsicElements["input"];
1021
- namespace Control {
1022
- /**
1023
- * `<Field.Control />` component props for group input element.
1024
- *
1025
- * @template T Tag name
1026
- * @template V Option values
1027
- */
1028
- type Group<T extends Tag, V extends Values> = Control<T> & {
1029
- readonly value: V[number];
1030
- };
1031
- }
1032
- /** `<Field.Label />` component props */
1033
- type Label = JSX.IntrinsicElements["label"];
1034
- namespace Label {
1035
- /**
1036
- * `<Field.Label />` component props for group input element.
1037
- *
1038
- * @template V Option values
1039
- */
1040
- type Group<V extends Values> = Label & {
1041
- readonly value: V[number];
1042
- };
1043
- }
1044
- /**
1045
- * `<Field.Option />` select component props
1046
- *
1047
- * @template V Values
1048
- */
1049
- type Option<V extends Values> = JSX.IntrinsicElements["option"] & {
1050
- /** Option value */
1051
- readonly value: V[number];
1052
- };
1053
- namespace Option {
1054
- /**
1055
- * `<Field.Option />` input group component props
1056
- *
1057
- * Wrapper for both the `<Label />` and `<Input />` components.
1058
- *
1059
- * @template V Values
1060
- */
1061
- type Input<V extends Values> = JSX.IntrinsicElements["div"] & {
1062
- /** Option value */
1063
- readonly value: V[number];
1064
- };
1065
- }
1066
- }
1067
- /**
1068
- * Base Field component object that contains sub-components,
1069
- * use for fine grained rendering control.
1070
- *
1071
- * @template F Field
1072
- */
1073
- type Component<F extends Any> = Readonly<{
1074
- /**
1075
- * @param props Issue props
1076
- * @returns Issue container paragraph
1077
- */
1078
- Issue: (props?: Component.Issue) => JSX.Element;
1079
- } & (F extends Instance<any, "select", Field.Type, infer V> ? V extends Values ? {
1080
- /** Select option values */
1081
- values: V;
1082
- /**
1083
- * @param props Root props
1084
- * @returns Root container div
1085
- */
1086
- Root: (props?: Component.Root) => JSX.Element;
1087
- /**
1088
- * @param props Label props
1089
- * @returns Label element
1090
- */
1091
- Label: (props?: Component.Label) => JSX.Element;
1092
- /**
1093
- * @param props Control props
1094
- * @returns Control select element
1095
- */
1096
- Control: (props?: Component.Control<"select">) => JSX.Element;
1097
- /**
1098
- * @param props Option props
1099
- * @returns Select option element
1100
- */
1101
- Option: (props: Component.Option<V>) => JSX.Element;
1102
- } : never : F extends Instance<any, "input", Field.Type, infer V> ? V extends Values ? {
1103
- /** Input group values */
1104
- values: V;
1105
- /**
1106
- * @param props Root props
1107
- * @returns Root container fieldset
1108
- */
1109
- Root: (props?: Component.Root.Group) => JSX.Element;
1110
- /**
1111
- * @param props Legend element props
1112
- * @returns Legend element
1113
- */
1114
- Legend: (props?: Component.Legend) => JSX.Element;
1115
- /**
1116
- * @param props Label props including `value`
1117
- * @returns Label element
1118
- */
1119
- Label: (props: Component.Label.Group<V>) => JSX.Element;
1120
- /**
1121
- * @param props Control props
1122
- * @returns Control input element
1123
- */
1124
- Control: (props?: Component.Control.Group<"input", V>) => JSX.Element;
1125
- /**
1126
- * @param props Option props
1127
- * @returns Both label and input elements together
1128
- */
1129
- Option: (props: Component.Option.Input<V>) => JSX.Element;
1130
- } : {
1131
- /**
1132
- * @param props Root props
1133
- * @returns Root container div
1134
- */
1135
- Root: (props?: Component.Root) => JSX.Element;
1136
- /**
1137
- * @param props Label props
1138
- * @returns Label element
1139
- */
1140
- Label: (props?: Component.Label) => JSX.Element;
1141
- /**
1142
- * @param props Control props
1143
- * @returns Control input element
1144
- */
1145
- Control: (props?: Component.Control<"input">) => JSX.Element;
1146
- } : {
1147
- /**
1148
- * @param props Root props
1149
- * @returns Root container div
1150
- */
1151
- Root: (props?: Component.Root) => JSX.Element;
1152
- /**
1153
- * @param props Label props
1154
- * @returns Label element
1155
- */
1156
- Label: (props?: Component.Label) => JSX.Element;
1157
- /**
1158
- * @param props Control props
1159
- * @returns Control textarea element
1160
- */
1161
- Control: (props?: Component.Control<"textarea">) => JSX.Element;
1162
- })>;
1163
- /** Any field props */
1164
- type Props = Props.Input | Props.Select | Props.Textarea;
1165
- namespace Props {
1166
- /** Extra props in addition to HTML attributes */
1167
- interface Meta {
1168
- /** Field label */
1169
- readonly label?: string;
1170
- }
1171
- /** Props for `<input>` fields */
1172
- export type Input = Meta & JSX.IntrinsicElements["input"];
1173
- /** Props for `<select>` fields */
1174
- export type Select = Meta & JSX.IntrinsicElements["select"];
1175
- /** Props for `<textarea>` fields */
1176
- export type Textarea = Meta & JSX.IntrinsicElements["textarea"];
1177
- export {};
1178
- }
1179
- }
1180
- /** Field factory functions */
1181
- export declare class Field {
1182
- #private;
1183
- /**
1184
- * @param props Input props
1185
- * @returns Text input field
1186
- */
1187
- static text(props?: Field.Props.Input): Field.Instance<string, "input", "text">;
1188
- /**
1189
- * @param props Input props
1190
- * @returns Password input field
1191
- */
1192
- static password(props?: Field.Props.Input): Field.Instance<string, "input", "password">;
1193
- /**
1194
- * @param props Input props
1195
- * @returns Search input field
1196
- */
1197
- static search(props?: Field.Props.Input): Field.Instance<string, "input", "search">;
1198
- /**
1199
- * @param props Input props
1200
- * @returns Telephone input field
1201
- */
1202
- static tel(props?: Field.Props.Input): Field.Instance<string, "input", "tel">;
1203
- /**
1204
- * @param props Input props
1205
- * @returns Color input field
1206
- */
1207
- static color(props?: Field.Props.Input): Field.Instance<string, "input", "color">;
1208
- /**
1209
- * @param props Input props
1210
- * @returns Hidden input field
1211
- */
1212
- static hidden(props?: Field.Props.Input): Field.Instance<string, "input", "hidden">;
1213
- /**
1214
- * @param props Input props
1215
- * @returns Date input field
1216
- */
1217
- static date(props?: Field.Props.Input): Field.Instance<string, "input", "date">;
1218
- /**
1219
- * @param props Input props
1220
- * @returns Datetime input field
1221
- */
1222
- static datetime(props?: Field.Props.Input): Field.Instance<string, "input", "datetime-local">;
1223
- /**
1224
- * @param props Input props
1225
- * @returns Month input field
1226
- */
1227
- static month(props?: Field.Props.Input): Field.Instance<string, "input", "month">;
1228
- /**
1229
- * @param props Input props
1230
- * @returns Week input field
1231
- */
1232
- static week(props?: Field.Props.Input): Field.Instance<string, "input", "week">;
1233
- /**
1234
- * @param props Input props
1235
- * @returns Time input field
1236
- */
1237
- static time(props?: Field.Props.Input): Field.Instance<string, "input", "time">;
1238
- /**
1239
- * Validates email string.
1240
- *
1241
- * @param props Input props
1242
- * @param message Issue message when invalid
1243
- * @returns Email input field
1244
- */
1245
- static email(props?: Field.Props.Input, message?: string): Field.Instance<string, "input", "email">;
1246
- /**
1247
- * Validates parsable URL.
1248
- *
1249
- * @param props Input props
1250
- * @param message Issue message when invalid
1251
- * @returns URL input field
1252
- */
1253
- static url(props?: Field.Props.Input, message?: string): Field.Instance<string, "input", "url">;
1254
- /**
1255
- * Coerces to number.
1256
- *
1257
- * @param props Input props
1258
- * @returns Number input field
1259
- */
1260
- static number(props?: Field.Props.Input): Field.Instance<number, "input", "number">;
1261
- /**
1262
- * Coerces to number.
1263
- *
1264
- * @param props Input props
1265
- * @returns Range input field
1266
- */
1267
- static range(props?: Field.Props.Input): Field.Instance<number, "input", "range">;
1268
- /**
1269
- * - unchecked => key missing => `false`
1270
- * - checked => key present => `true`
1271
- *
1272
- * @param props Input props
1273
- * @returns Checkbox input field
1274
- */
1275
- static checkbox(props?: Field.Props.Input): Field.Instance<boolean, "input", "checkbox">;
1276
- /**
1277
- * @param props Input props
1278
- * @returns File input field
1279
- */
1280
- static file(props?: Field.Props.Input): Field.Instance<File, "input", "file">;
1281
- /**
1282
- * @param props Input props
1283
- * @returns Multiple file input field
1284
- */
1285
- static files(props?: Field.Props.Input): Field.Instance<File[], "input", "file">;
1286
- /**
1287
- * @template V Value type
1288
- * @param values Checkbox values
1289
- * @param props Input props
1290
- * @returns Checkbox group input field
1291
- */
1292
- static checkboxes<const V extends string>(values: readonly [V, ...V[]], props?: Field.Props.Input): Field.Instance<V[], "input", "checkbox", readonly [V, ...V[]]>;
1293
- /**
1294
- * @template V Value type
1295
- * @param values Radio button values
1296
- * @param props Input props
1297
- * @returns Radio group input field
1298
- */
1299
- static radio<const V extends string>(values: readonly [V, ...V[]], props?: Field.Props.Input): Field.Instance<V, "input", "radio", readonly [V, ...V[]]>;
1300
- /**
1301
- * @param props Textarea props
1302
- * @returns Textarea field
1303
- */
1304
- static textarea(props?: Field.Props.Textarea): Field.Instance<string, "textarea">;
1305
- /**
1306
- * @template V Value type
1307
- * @param values Select options
1308
- * @param props Select props
1309
- * @returns Select field
1310
- */
1311
- static select<const V extends string>(values: readonly [V, ...V[]], props?: Field.Props.Select): Field.Instance<V, "select", Field.Type, readonly [V, ...V[]]>;
1312
- /**
1313
- * @template V Value type
1314
- * @param values Select options
1315
- * @param props Select props
1316
- * @returns Multi-select field
1317
- */
1318
- static multiselect<const V extends string>(values: readonly [V, ...V[]], props?: Field.Props.Select): Field.Instance<V[], "select", Field.Type, readonly [V, ...V[]]>;
1319
- }
1320
893
  export {};
1321
894
  //# sourceMappingURL=index.d.ts.map