@angular/forms 21.1.0-next.0 → 21.1.0-next.2

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/types/forms.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v21.1.0-next.0
2
+ * @license Angular v21.1.0-next.2
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @license Angular v21.1.0-next.0
2
+ * @license Angular v21.1.0-next.2
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
@@ -23,7 +23,7 @@ type CompatFormOptions = Omit<FormOptions, 'adapter'>;
23
23
  * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
24
24
  *
25
25
  * @example
26
- * ```
26
+ * ```ts
27
27
  * const lastName = new FormControl('lastName');
28
28
  *
29
29
  * const nameModel = signal({
@@ -36,6 +36,7 @@ type CompatFormOptions = Omit<FormOptions, 'adapter'>;
36
36
  * });
37
37
  *
38
38
  * nameForm.last().value(); // lastName, not FormControl
39
+ * ```
39
40
  *
40
41
  * @param model A writable signal that contains the model data for the form. The resulting field
41
42
  * structure will match the shape of the model and any changes to the form data will be written to
@@ -52,7 +53,7 @@ declare function compatForm<TModel>(model: WritableSignal<TModel>): FieldTree<TM
52
53
  * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
53
54
  *
54
55
  * @example
55
- * ```
56
+ * ```ts
56
57
  * const lastName = new FormControl('lastName');
57
58
  *
58
59
  * const nameModel = signal({
@@ -85,7 +86,7 @@ declare function compatForm<TModel>(model: WritableSignal<TModel>, schemaOrOptio
85
86
  * compatibility with Reactive forms by accepting Reactive controls as a part of the data.
86
87
  *
87
88
  * @example
88
- * ```
89
+ * ```ts
89
90
  * const lastName = new FormControl('lastName');
90
91
  *
91
92
  * const nameModel = signal({
@@ -1,152 +1,16 @@
1
1
  /**
2
- * @license Angular v21.1.0-next.0
2
+ * @license Angular v21.1.0-next.2
3
3
  * (c) 2010-2025 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
6
6
 
7
- import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
8
- import { Signal, ResourceRef, InputSignal, ModelSignal, OutputRef } from '@angular/core';
9
- import { PathKind, FieldContext, TreeValidationResult, SchemaPath, SchemaPathRules, WithOptionalField, ValidationError, DisabledReason, Debouncer, LogicFn, FieldValidator, TreeValidator, AggregateMetadataKey, MetadataKey, OneOrMany, SchemaPathTree } from './_structure-chunk.js';
10
- export { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, CustomValidationError, EmailValidationError, FIELD, Field, FieldState, FieldTree, FormOptions, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, ReadonlyArrayLike, RequiredValidationError, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SignalFormsConfig, StandardSchemaValidationError, Subfields, SubmittedStatus, ValidationResult, ValidationSuccess, Validator, WithField, WithoutField, andMetadataKey, apply, applyEach, applyWhen, applyWhenValue, createMetadataKey, customError, emailError, form, listMetadataKey, maxError, maxLengthError, maxMetadataKey, minError, minLengthError, minMetadataKey, orMetadataKey, patternError, provideSignalFormsConfig, reducedMetadataKey, requiredError, schema, standardSchemaError, submit } from './_structure-chunk.js';
7
+ import { InputSignal, InputSignalWithTransform, ModelSignal, OutputRef, Signal, ResourceRef } from '@angular/core';
8
+ import { WithOptionalField, ValidationError, DisabledReason, PathKind, SchemaPath, SchemaPathRules, LogicFn, OneOrMany, SchemaPathTree, FieldValidator, FieldContext, TreeValidationResult, TreeValidator, Debouncer } from './_structure-chunk.js';
9
+ export { AsyncValidationResult, ChildFieldContext, CompatFieldState, CompatSchemaPath, CustomValidationError, EmailValidationError, FIELD, Field, FieldState, FieldTree, FormOptions, ItemFieldContext, ItemType, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MaxLengthValidationError, MaxValidationError, MaybeFieldTree, MaybeSchemaPathTree, MetadataKey, MetadataReducer, MetadataSetterType, MinLengthValidationError, MinValidationError, NgValidationError, PATTERN, PatternValidationError, REQUIRED, ReadonlyArrayLike, RequiredValidationError, RootFieldContext, Schema, SchemaFn, SchemaOrSchemaFn, SignalFormsConfig, StandardSchemaValidationError, Subfields, SubmittedStatus, ValidationResult, ValidationSuccess, Validator, WithField, WithoutField, apply, applyEach, applyWhen, applyWhenValue, createManagedMetadataKey, createMetadataKey, customError, emailError, form, maxError, maxLengthError, metadata, minError, minLengthError, patternError, provideSignalFormsConfig, requiredError, schema, standardSchemaError, submit } from './_structure-chunk.js';
11
10
  import { StandardSchemaV1 } from '@standard-schema/spec';
11
+ import { HttpResourceRequest, HttpResourceOptions } from '@angular/common/http';
12
12
  import '@angular/forms';
13
13
 
14
- /**
15
- * A function that takes the result of an async operation and the current field context, and maps it
16
- * to a list of validation errors.
17
- *
18
- * @param result The result of the async operation.
19
- * @param ctx The context for the field the validator is attached to.
20
- * @return A validation error, or list of validation errors to report based on the result of the async operation.
21
- * The returned errors can optionally specify a field that the error should be targeted to.
22
- * A targeted error will show up as an error on its target field rather than the field being validated.
23
- * If a field is not given, the error is assumed to apply to the field being validated.
24
- * @template TValue The type of value stored in the field being validated.
25
- * @template TResult The type of result returned by the async operation
26
- * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
27
- *
28
- * @experimental 21.0.0
29
- */
30
- type MapToErrorsFn<TValue, TResult, TPathKind extends PathKind = PathKind.Root> = (result: TResult, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
31
- /**
32
- * Options that indicate how to create a resource for async validation for a field,
33
- * and map its result to validation errors.
34
- *
35
- * @template TValue The type of value stored in the field being validated.
36
- * @template TParams The type of parameters to the resource.
37
- * @template TResult The type of result returned by the resource
38
- * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
39
- *
40
- * @category validation
41
- * @experimental 21.0.0
42
- */
43
- interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root> {
44
- /**
45
- * A function that receives the field context and returns the params for the resource.
46
- *
47
- * @param ctx The field context for the field being validated.
48
- * @returns The params for the resource.
49
- */
50
- readonly params: (ctx: FieldContext<TValue, TPathKind>) => TParams;
51
- /**
52
- * A function that receives the resource params and returns a resource of the given params.
53
- * The given params should be used as is to create the resource.
54
- * The forms system will report the params as `undefined` when this validation doesn't need to be run.
55
- *
56
- * @param params The params to use for constructing the resource
57
- * @returns A reference to the constructed resource.
58
- */
59
- readonly factory: (params: Signal<TParams | undefined>) => ResourceRef<TResult | undefined>;
60
- /**
61
- * A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
62
- * Receives the error and the field context, returns a list of validation errors.
63
- */
64
- readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
65
- /**
66
- * A function that takes the resource result, and the current field context and maps it to a list
67
- * of validation errors.
68
- *
69
- * @param result The resource result.
70
- * @param ctx The context for the field the validator is attached to.
71
- * @return A validation error, or list of validation errors to report based on the resource result.
72
- * The returned errors can optionally specify a field that the error should be targeted to.
73
- * A targeted error will show up as an error on its target field rather than the field being validated.
74
- * If a field is not given, the error is assumed to apply to the field being validated.
75
- */
76
- readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
77
- }
78
- /**
79
- * Options that indicate how to create an httpResource for async validation for a field,
80
- * and map its result to validation errors.
81
- *
82
- * @template TValue The type of value stored in the field being validated.
83
- * @template TResult The type of result returned by the httpResource
84
- * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
85
- *
86
- * @category validation
87
- * @experimental 21.0.0
88
- */
89
- interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = PathKind.Root> {
90
- /**
91
- * A function that receives the field context and returns the url or request for the httpResource.
92
- * If given a URL, the underlying httpResource will perform an HTTP GET on it.
93
- *
94
- * @param ctx The field context for the field being validated.
95
- * @returns The URL or request for creating the httpResource.
96
- */
97
- readonly request: ((ctx: FieldContext<TValue, TPathKind>) => string | undefined) | ((ctx: FieldContext<TValue, TPathKind>) => HttpResourceRequest | undefined);
98
- /**
99
- * A function that takes the httpResource result, and the current field context and maps it to a
100
- * list of validation errors.
101
- *
102
- * @param result The httpResource result.
103
- * @param ctx The context for the field the validator is attached to.
104
- * @return A validation error, or list of validation errors to report based on the httpResource result.
105
- * The returned errors can optionally specify a field that the error should be targeted to.
106
- * A targeted error will show up as an error on its target field rather than the field being validated.
107
- * If a field is not given, the error is assumed to apply to the field being validated.
108
- */
109
- readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
110
- /**
111
- * A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
112
- * Receives the error and the field context, returns a list of validation errors.
113
- */
114
- readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
115
- /**
116
- * The options to use when creating the httpResource.
117
- */
118
- readonly options?: HttpResourceOptions<TResult, unknown>;
119
- }
120
- /**
121
- * Adds async validation to the field corresponding to the given path based on a resource.
122
- * Async validation for a field only runs once all synchronous validation is passing.
123
- *
124
- * @param path A path indicating the field to bind the async validation logic to.
125
- * @param opts The async validation options.
126
- * @template TValue The type of value stored in the field being validated.
127
- * @template TParams The type of parameters to the resource.
128
- * @template TResult The type of result returned by the resource
129
- * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
130
- *
131
- * @category validation
132
- * @experimental 21.0.0
133
- */
134
- declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: AsyncValidatorOptions<TValue, TParams, TResult, TPathKind>): void;
135
- /**
136
- * Adds async validation to the field corresponding to the given path based on an httpResource.
137
- * Async validation for a field only runs once all synchronous validation is passing.
138
- *
139
- * @param path A path indicating the field to bind the async validation logic to.
140
- * @param opts The http validation options.
141
- * @template TValue The type of value stored in the field being validated.
142
- * @template TResult The type of result returned by the httpResource
143
- * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
144
- *
145
- * @category validation
146
- * @experimental 21.0.0
147
- */
148
- declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: HttpValidatorOptions<TValue, TResult, TPathKind>): void;
149
-
150
14
  /**
151
15
  * The base set of properties shared by all form control contracts.
152
16
  *
@@ -158,82 +22,82 @@ interface FormUiControl {
158
22
  * An input to receive the errors for the field. If implemented, the `Field` directive will
159
23
  * automatically bind errors from the bound field to this input.
160
24
  */
161
- readonly errors?: InputSignal<readonly WithOptionalField<ValidationError>[]>;
25
+ readonly errors?: InputSignal<readonly WithOptionalField<ValidationError>[]> | InputSignalWithTransform<readonly WithOptionalField<ValidationError>[], unknown>;
162
26
  /**
163
27
  * An input to receive the disabled status for the field. If implemented, the `Field` directive
164
28
  * will automatically bind the disabled status from the bound field to this input.
165
29
  */
166
- readonly disabled?: InputSignal<boolean>;
30
+ readonly disabled?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
167
31
  /**
168
32
  * An input to receive the reasons for the disablement of the field. If implemented, the `Field`
169
33
  * directive will automatically bind the disabled reason from the bound field to this input.
170
34
  */
171
- readonly disabledReasons?: InputSignal<readonly WithOptionalField<DisabledReason>[]>;
35
+ readonly disabledReasons?: InputSignal<readonly WithOptionalField<DisabledReason>[]> | InputSignalWithTransform<readonly WithOptionalField<DisabledReason>[], unknown>;
172
36
  /**
173
37
  * An input to receive the readonly status for the field. If implemented, the `Field` directive
174
38
  * will automatically bind the readonly status from the bound field to this input.
175
39
  */
176
- readonly readonly?: InputSignal<boolean>;
40
+ readonly readonly?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
177
41
  /**
178
42
  * An input to receive the hidden status for the field. If implemented, the `Field` directive
179
43
  * will automatically bind the hidden status from the bound field to this input.
180
44
  */
181
- readonly hidden?: InputSignal<boolean>;
45
+ readonly hidden?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
182
46
  /**
183
47
  * An input to receive the invalid status for the field. If implemented, the `Field` directive
184
48
  * will automatically bind the invalid status from the bound field to this input.
185
49
  */
186
- readonly invalid?: InputSignal<boolean>;
50
+ readonly invalid?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
187
51
  /**
188
52
  * An input to receive the pending status for the field. If implemented, the `Field` directive
189
53
  * will automatically bind the pending status from the bound field to this input.
190
54
  */
191
- readonly pending?: InputSignal<boolean>;
55
+ readonly pending?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
192
56
  /**
193
57
  * An input to receive the touched status for the field. If implemented, the `Field` directive
194
58
  * will automatically bind the touched status from the bound field to this input.
195
59
  */
196
- readonly touched?: ModelSignal<boolean> | InputSignal<boolean> | OutputRef<boolean>;
60
+ readonly touched?: ModelSignal<boolean> | InputSignal<boolean> | InputSignalWithTransform<boolean, unknown> | OutputRef<boolean>;
197
61
  /**
198
62
  * An input to receive the dirty status for the field. If implemented, the `Field` directive
199
63
  * will automatically bind the dirty status from the bound field to this input.
200
64
  */
201
- readonly dirty?: InputSignal<boolean>;
65
+ readonly dirty?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
202
66
  /**
203
67
  * An input to receive the name for the field. If implemented, the `Field` directive will
204
68
  * automatically bind the name from the bound field to this input.
205
69
  */
206
- readonly name?: InputSignal<string>;
70
+ readonly name?: InputSignal<string> | InputSignalWithTransform<string, unknown>;
207
71
  /**
208
72
  * An input to receive the required status for the field. If implemented, the `Field` directive
209
73
  * will automatically bind the required status from the bound field to this input.
210
74
  */
211
- readonly required?: InputSignal<boolean>;
75
+ readonly required?: InputSignal<boolean> | InputSignalWithTransform<boolean, unknown>;
212
76
  /**
213
77
  * An input to receive the min value for the field. If implemented, the `Field` directive will
214
78
  * automatically bind the min value from the bound field to this input.
215
79
  */
216
- readonly min?: InputSignal<number | undefined>;
80
+ readonly min?: InputSignal<number | undefined> | InputSignalWithTransform<number | undefined, unknown>;
217
81
  /**
218
82
  * An input to receive the min length for the field. If implemented, the `Field` directive will
219
83
  * automatically bind the min length from the bound field to this input.
220
84
  */
221
- readonly minLength?: InputSignal<number | undefined>;
85
+ readonly minLength?: InputSignal<number | undefined> | InputSignalWithTransform<number | undefined, unknown>;
222
86
  /**
223
87
  * An input to receive the max value for the field. If implemented, the `Field` directive will
224
88
  * automatically bind the max value from the bound field to this input.
225
89
  */
226
- readonly max?: InputSignal<number | undefined>;
90
+ readonly max?: InputSignal<number | undefined> | InputSignalWithTransform<number | undefined, unknown>;
227
91
  /**
228
92
  * An input to receive the max length for the field. If implemented, the `Field` directive will
229
93
  * automatically bind the max length from the bound field to this input.
230
94
  */
231
- readonly maxLength?: InputSignal<number | undefined>;
95
+ readonly maxLength?: InputSignal<number | undefined> | InputSignalWithTransform<number | undefined, unknown>;
232
96
  /**
233
97
  * An input to receive the value patterns for the field. If implemented, the `Field` directive
234
98
  * will automatically bind the value patterns from the bound field to this input.
235
99
  */
236
- readonly pattern?: InputSignal<readonly RegExp[]>;
100
+ readonly pattern?: InputSignal<readonly RegExp[]> | InputSignalWithTransform<readonly RegExp[], unknown>;
237
101
  }
238
102
  /**
239
103
  * A contract for a form control that edits a `FieldTree` of type `TValue`. Any component that
@@ -286,20 +150,6 @@ interface FormCheckboxControl extends FormUiControl {
286
150
  readonly value?: undefined;
287
151
  }
288
152
 
289
- /**
290
- * Configures the frequency at which a form field is updated by UI events.
291
- *
292
- * When this rule is applied, updates from the UI to the form model will be delayed until either
293
- * the field is touched, or the most recently debounced update resolves.
294
- *
295
- * @param path The target path to debounce.
296
- * @param durationOrDebouncer Either a debounce duration in milliseconds, or a custom
297
- * {@link Debouncer} function.
298
- *
299
- * @experimental 21.0.0
300
- */
301
- declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
302
-
303
153
  /**
304
154
  * Adds logic to a field to conditionally disable it. A disabled field does not contribute to the
305
155
  * validation, touched/dirty, or other state of its parent field.
@@ -314,19 +164,7 @@ declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(pa
314
164
  * @experimental 21.0.0
315
165
  */
316
166
  declare function disabled<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: string | NoInfer<LogicFn<TValue, boolean | string, TPathKind>>): void;
317
- /**
318
- * Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to
319
- * the validation, touched/dirty, or other state of its parent field.
320
- *
321
- * @param path The target path to make readonly.
322
- * @param logic A reactive function that returns `true` when the field is readonly.
323
- * @template TValue The type of value stored in the field the logic is bound to.
324
- * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
325
- *
326
- * @category logic
327
- * @experimental 21.0.0
328
- */
329
- declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
167
+
330
168
  /**
331
169
  * Adds logic to a field to conditionally hide it. A hidden field does not contribute to the
332
170
  * validation, touched/dirty, or other state of its parent field.
@@ -348,70 +186,20 @@ declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(pa
348
186
  * @experimental 21.0.0
349
187
  */
350
188
  declare function hidden<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
189
+
351
190
  /**
352
- * Adds logic to a field to determine if the field has validation errors.
353
- *
354
- * @param path The target path to add the validation logic to.
355
- * @param logic A `Validator` that returns the current validation errors.
356
- * @template TValue The type of value stored in the field the logic is bound to.
357
- * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
358
- *
359
- * @category logic
360
- * @experimental 21.0.0
361
- */
362
- declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>): void;
363
- /**
364
- * Adds logic to a field to determine if the field or any of its child fields has validation errors.
365
- *
366
- * @param path The target path to add the validation logic to.
367
- * @param logic A `TreeValidator` that returns the current validation errors.
368
- * Errors returned by the validator may specify a target field to indicate an error on a child field.
369
- * @template TValue The type of value stored in the field the logic is bound to.
370
- * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
371
- *
372
- * @category logic
373
- * @experimental 21.0.0
374
- */
375
- declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
376
- /**
377
- * Adds a value to an {@link AggregateMetadataKey} of a field.
191
+ * Adds logic to a field to conditionally make it readonly. A readonly field does not contribute to
192
+ * the validation, touched/dirty, or other state of its parent field.
378
193
  *
379
- * @param path The target path to set the aggregate metadata on.
380
- * @param key The aggregate metadata key
381
- * @param logic A function that receives the `FieldContext` and returns a value to add to the aggregate metadata.
194
+ * @param path The target path to make readonly.
195
+ * @param logic A reactive function that returns `true` when the field is readonly.
382
196
  * @template TValue The type of value stored in the field the logic is bound to.
383
- * @template TMetadataItem The type of value the metadata aggregates over.
384
197
  * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
385
198
  *
386
199
  * @category logic
387
200
  * @experimental 21.0.0
388
201
  */
389
- declare function aggregateMetadata<TValue, TMetadataItem, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: AggregateMetadataKey<any, TMetadataItem>, logic: NoInfer<LogicFn<TValue, TMetadataItem, TPathKind>>): void;
390
- /**
391
- * Creates a new {@link MetadataKey} and defines the value of the new metadata key for the given field.
392
- *
393
- * @param path The path to define the metadata for.
394
- * @param factory A factory function that creates the value for the metadata.
395
- * This function is **not** reactive. It is run once when the field is created.
396
- * @returns The newly created metadata key
397
- *
398
- * @category logic
399
- * @experimental 21.0.0
400
- */
401
- declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
402
- /**
403
- * Defines the value of a {@link MetadataKey} for a given field.
404
- *
405
- * @param path The path to define the metadata for.
406
- * @param key The metadata key to define.
407
- * @param factory A factory function that creates the value for the metadata.
408
- * This function is **not** reactive. It is run once when the field is created.
409
- * @returns The given metadata key
410
- *
411
- * @category logic
412
- * @experimental 21.0.0
413
- */
414
- declare function metadata<TValue, TData, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, key: MetadataKey<TData>, factory: (ctx: FieldContext<TValue, TPathKind>) => TData): MetadataKey<TData>;
202
+ declare function readonly<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic?: NoInfer<LogicFn<TValue, boolean, TPathKind>>): void;
415
203
 
416
204
  /** Represents a value that has a length or size, such as an array or string, or set. */
417
205
  type ValueWithLengthOrSize = {
@@ -594,5 +382,183 @@ type IgnoreUnknownProperties<T> = T extends Record<PropertyKey, unknown> ? {
594
382
  */
595
383
  declare function validateStandardSchema<TSchema, TModel extends IgnoreUnknownProperties<TSchema>>(path: SchemaPath<TModel> & SchemaPathTree<TModel>, schema: StandardSchemaV1<TSchema>): void;
596
384
 
597
- export { AggregateMetadataKey, Debouncer, DisabledReason, FieldContext, FieldValidator, LogicFn, MetadataKey, OneOrMany, PathKind, SchemaPath, SchemaPathRules, SchemaPathTree, TreeValidationResult, TreeValidator, ValidationError, WithOptionalField, aggregateMetadata, debounce, disabled, email, hidden, max, maxLength, metadata, min, minLength, pattern, readonly, required, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
385
+ /**
386
+ * Adds logic to a field to determine if the field has validation errors.
387
+ *
388
+ * @param path The target path to add the validation logic to.
389
+ * @param logic A `Validator` that returns the current validation errors.
390
+ * @template TValue The type of value stored in the field the logic is bound to.
391
+ * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
392
+ *
393
+ * @category logic
394
+ * @experimental 21.0.0
395
+ */
396
+ declare function validate<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<FieldValidator<TValue, TPathKind>>): void;
397
+
398
+ /**
399
+ * A function that takes the result of an async operation and the current field context, and maps it
400
+ * to a list of validation errors.
401
+ *
402
+ * @param result The result of the async operation.
403
+ * @param ctx The context for the field the validator is attached to.
404
+ * @return A validation error, or list of validation errors to report based on the result of the async operation.
405
+ * The returned errors can optionally specify a field that the error should be targeted to.
406
+ * A targeted error will show up as an error on its target field rather than the field being validated.
407
+ * If a field is not given, the error is assumed to apply to the field being validated.
408
+ * @template TValue The type of value stored in the field being validated.
409
+ * @template TResult The type of result returned by the async operation
410
+ * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
411
+ *
412
+ * @experimental 21.0.0
413
+ */
414
+ type MapToErrorsFn<TValue, TResult, TPathKind extends PathKind = PathKind.Root> = (result: TResult, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
415
+ /**
416
+ * Options that indicate how to create a resource for async validation for a field,
417
+ * and map its result to validation errors.
418
+ *
419
+ * @template TValue The type of value stored in the field being validated.
420
+ * @template TParams The type of parameters to the resource.
421
+ * @template TResult The type of result returned by the resource
422
+ * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
423
+ *
424
+ * @category validation
425
+ * @experimental 21.0.0
426
+ */
427
+ interface AsyncValidatorOptions<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root> {
428
+ /**
429
+ * A function that receives the field context and returns the params for the resource.
430
+ *
431
+ * @param ctx The field context for the field being validated.
432
+ * @returns The params for the resource.
433
+ */
434
+ readonly params: (ctx: FieldContext<TValue, TPathKind>) => TParams;
435
+ /**
436
+ * A function that receives the resource params and returns a resource of the given params.
437
+ * The given params should be used as is to create the resource.
438
+ * The forms system will report the params as `undefined` when this validation doesn't need to be run.
439
+ *
440
+ * @param params The params to use for constructing the resource
441
+ * @returns A reference to the constructed resource.
442
+ */
443
+ readonly factory: (params: Signal<TParams | undefined>) => ResourceRef<TResult | undefined>;
444
+ /**
445
+ * A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
446
+ * Receives the error and the field context, returns a list of validation errors.
447
+ */
448
+ readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
449
+ /**
450
+ * A function that takes the resource result, and the current field context and maps it to a list
451
+ * of validation errors.
452
+ *
453
+ * @param result The resource result.
454
+ * @param ctx The context for the field the validator is attached to.
455
+ * @return A validation error, or list of validation errors to report based on the resource result.
456
+ * The returned errors can optionally specify a field that the error should be targeted to.
457
+ * A targeted error will show up as an error on its target field rather than the field being validated.
458
+ * If a field is not given, the error is assumed to apply to the field being validated.
459
+ */
460
+ readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
461
+ }
462
+ /**
463
+ * Adds async validation to the field corresponding to the given path based on a resource.
464
+ * Async validation for a field only runs once all synchronous validation is passing.
465
+ *
466
+ * @param path A path indicating the field to bind the async validation logic to.
467
+ * @param opts The async validation options.
468
+ * @template TValue The type of value stored in the field being validated.
469
+ * @template TParams The type of parameters to the resource.
470
+ * @template TResult The type of result returned by the resource
471
+ * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
472
+ *
473
+ * @category validation
474
+ * @experimental 21.0.0
475
+ */
476
+ declare function validateAsync<TValue, TParams, TResult, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: AsyncValidatorOptions<TValue, TParams, TResult, TPathKind>): void;
477
+
478
+ /**
479
+ * Options that indicate how to create an httpResource for async validation for a field,
480
+ * and map its result to validation errors.
481
+ *
482
+ * @template TValue The type of value stored in the field being validated.
483
+ * @template TResult The type of result returned by the httpResource
484
+ * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
485
+ *
486
+ * @category validation
487
+ * @experimental 21.0.0
488
+ */
489
+ interface HttpValidatorOptions<TValue, TResult, TPathKind extends PathKind = PathKind.Root> {
490
+ /**
491
+ * A function that receives the field context and returns the url or request for the httpResource.
492
+ * If given a URL, the underlying httpResource will perform an HTTP GET on it.
493
+ *
494
+ * @param ctx The field context for the field being validated.
495
+ * @returns The URL or request for creating the httpResource.
496
+ */
497
+ readonly request: ((ctx: FieldContext<TValue, TPathKind>) => string | undefined) | ((ctx: FieldContext<TValue, TPathKind>) => HttpResourceRequest | undefined);
498
+ /**
499
+ * A function that takes the httpResource result, and the current field context and maps it to a
500
+ * list of validation errors.
501
+ *
502
+ * @param result The httpResource result.
503
+ * @param ctx The context for the field the validator is attached to.
504
+ * @return A validation error, or list of validation errors to report based on the httpResource result.
505
+ * The returned errors can optionally specify a field that the error should be targeted to.
506
+ * A targeted error will show up as an error on its target field rather than the field being validated.
507
+ * If a field is not given, the error is assumed to apply to the field being validated.
508
+ */
509
+ readonly onSuccess: MapToErrorsFn<TValue, TResult, TPathKind>;
510
+ /**
511
+ * A function to handle errors thrown by httpResource (HTTP errors, network errors, etc.).
512
+ * Receives the error and the field context, returns a list of validation errors.
513
+ */
514
+ readonly onError: (error: unknown, ctx: FieldContext<TValue, TPathKind>) => TreeValidationResult;
515
+ /**
516
+ * The options to use when creating the httpResource.
517
+ */
518
+ readonly options?: HttpResourceOptions<TResult, unknown>;
519
+ }
520
+ /**
521
+ * Adds async validation to the field corresponding to the given path based on an httpResource.
522
+ * Async validation for a field only runs once all synchronous validation is passing.
523
+ *
524
+ * @param path A path indicating the field to bind the async validation logic to.
525
+ * @param opts The http validation options.
526
+ * @template TValue The type of value stored in the field being validated.
527
+ * @template TResult The type of result returned by the httpResource
528
+ * @template TPathKind The kind of path being validated (a root path, child path, or item of an array)
529
+ *
530
+ * @category validation
531
+ * @experimental 21.0.0
532
+ */
533
+ declare function validateHttp<TValue, TResult = unknown, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, opts: HttpValidatorOptions<TValue, TResult, TPathKind>): void;
534
+
535
+ /**
536
+ * Adds logic to a field to determine if the field or any of its child fields has validation errors.
537
+ *
538
+ * @param path The target path to add the validation logic to.
539
+ * @param logic A `TreeValidator` that returns the current validation errors.
540
+ * Errors returned by the validator may specify a target field to indicate an error on a child field.
541
+ * @template TValue The type of value stored in the field the logic is bound to.
542
+ * @template TPathKind The kind of path the logic is bound to (a root path, child path, or item of an array)
543
+ *
544
+ * @category logic
545
+ * @experimental 21.0.0
546
+ */
547
+ declare function validateTree<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, logic: NoInfer<TreeValidator<TValue, TPathKind>>): void;
548
+
549
+ /**
550
+ * Configures the frequency at which a form field is updated by UI events.
551
+ *
552
+ * When this rule is applied, updates from the UI to the form model will be delayed until either
553
+ * the field is touched, or the most recently debounced update resolves.
554
+ *
555
+ * @param path The target path to debounce.
556
+ * @param durationOrDebouncer Either a debounce duration in milliseconds, or a custom
557
+ * {@link Debouncer} function.
558
+ *
559
+ * @experimental 21.0.0
560
+ */
561
+ declare function debounce<TValue, TPathKind extends PathKind = PathKind.Root>(path: SchemaPath<TValue, SchemaPathRules.Supported, TPathKind>, durationOrDebouncer: number | Debouncer<TValue, TPathKind>): void;
562
+
563
+ export { Debouncer, DisabledReason, FieldContext, FieldValidator, LogicFn, OneOrMany, PathKind, SchemaPath, SchemaPathRules, SchemaPathTree, TreeValidationResult, TreeValidator, ValidationError, WithOptionalField, debounce, disabled, email, hidden, max, maxLength, min, minLength, pattern, readonly, required, validate, validateAsync, validateHttp, validateStandardSchema, validateTree };
598
564
  export type { AsyncValidatorOptions, FormCheckboxControl, FormUiControl, FormValueControl, HttpValidatorOptions, IgnoreUnknownProperties, MapToErrorsFn, RemoveStringIndexUnknownKey };