@4riders/reform 3.0.24

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +266 -0
  3. package/dist/index.d.ts +2715 -0
  4. package/dist/index.es.js +1715 -0
  5. package/dist/index.es.js.map +1 -0
  6. package/package.json +70 -0
  7. package/src/index.ts +90 -0
  8. package/src/reform/ArrayHelper.ts +164 -0
  9. package/src/reform/Form.tsx +81 -0
  10. package/src/reform/FormManager.ts +494 -0
  11. package/src/reform/Reform.ts +15 -0
  12. package/src/reform/components/BaseCheckboxField.tsx +72 -0
  13. package/src/reform/components/BaseDateField.tsx +84 -0
  14. package/src/reform/components/BaseRadioField.tsx +72 -0
  15. package/src/reform/components/BaseSelectField.tsx +103 -0
  16. package/src/reform/components/BaseTextAreaField.tsx +87 -0
  17. package/src/reform/components/BaseTextField.tsx +135 -0
  18. package/src/reform/components/InputHTMLProps.tsx +89 -0
  19. package/src/reform/observers/observer.ts +131 -0
  20. package/src/reform/observers/observerPath.ts +327 -0
  21. package/src/reform/observers/useObservers.ts +232 -0
  22. package/src/reform/useForm.ts +246 -0
  23. package/src/reform/useFormContext.tsx +37 -0
  24. package/src/reform/useFormField.ts +75 -0
  25. package/src/reform/useRender.ts +12 -0
  26. package/src/yop/MessageProvider.ts +204 -0
  27. package/src/yop/Metadata.ts +304 -0
  28. package/src/yop/ObjectsUtil.ts +811 -0
  29. package/src/yop/TypesUtil.ts +148 -0
  30. package/src/yop/ValidationContext.ts +207 -0
  31. package/src/yop/Yop.ts +430 -0
  32. package/src/yop/constraints/CommonConstraints.ts +124 -0
  33. package/src/yop/constraints/Constraint.ts +135 -0
  34. package/src/yop/constraints/MinMaxConstraints.ts +53 -0
  35. package/src/yop/constraints/OneOfConstraint.ts +40 -0
  36. package/src/yop/constraints/TestConstraint.ts +176 -0
  37. package/src/yop/decorators/array.ts +157 -0
  38. package/src/yop/decorators/boolean.ts +69 -0
  39. package/src/yop/decorators/date.ts +73 -0
  40. package/src/yop/decorators/email.ts +66 -0
  41. package/src/yop/decorators/file.ts +69 -0
  42. package/src/yop/decorators/id.ts +35 -0
  43. package/src/yop/decorators/ignored.ts +40 -0
  44. package/src/yop/decorators/instance.ts +110 -0
  45. package/src/yop/decorators/number.ts +73 -0
  46. package/src/yop/decorators/string.ts +90 -0
  47. package/src/yop/decorators/test.ts +41 -0
  48. package/src/yop/decorators/time.ts +112 -0
@@ -0,0 +1,2715 @@
1
+ import { default as default_2 } from 'react';
2
+ import { DOMAttributes } from 'react';
3
+ import { FormEvent } from 'react';
4
+ import { FormHTMLAttributes } from 'react';
5
+ import { InputHTMLAttributes } from 'react';
6
+ import { JSX as JSX_2 } from 'react';
7
+ import { JSX as JSX_3 } from 'react/jsx-runtime';
8
+ import { SelectHTMLAttributes } from 'react';
9
+ import { TextareaHTMLAttributes } from 'react';
10
+
11
+ /**
12
+ * Decorator for validating a field value as an array of a specified element type. The `of` property can be set to a custom
13
+ * class constructor, or a validation decorator such as {@link string}, {@link number}, etc. Using a validation decorator allows
14
+ * applying constraints to each array element.
15
+ *
16
+ * Example usage:
17
+ * ```tsx
18
+ * class Person {
19
+ *
20
+ * // the array itself must not be null, but its elements may be null
21
+ * @array({ of: Dog, required: true })
22
+ * dogs: Dog[] | null = null
23
+ *
24
+ * // the array must not be null, and all its elements must also be non-null
25
+ * @array({ of: instance({ of: Cat, required: true }), required: true })
26
+ * cats: Cat[] | null = null
27
+ *
28
+ * // a non-empty array of strings with at least 5 characters each
29
+ * @array({ of: string({ required: true, min: 5 }), required: true, min: 1 })
30
+ * names: string[] | null = null
31
+ * }
32
+ * const form = useForm(Person, ...)
33
+ *
34
+ * // the array decorator can also be used as a function to allow standalone validation:
35
+ * Yop.validate([], array({ of: Dog, min: 1 })) // error: "At least 1 element"
36
+ * ```
37
+ *
38
+ * @template Value - The type of the array value.
39
+ * @template Parent - The type of the parent object.
40
+ * @param constraints - The array constraints to apply.
41
+ * @param groups - Optional validation groups.
42
+ * @returns A field decorator function with validation.
43
+ * @category Property Decorators
44
+ */
45
+ export declare function array<Value extends ArrayValue, Parent>(constraints?: ArrayConstraints<Value, Parent>, groups?: Groups<ArrayConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
46
+
47
+ /**
48
+ * Interface for array field constraints, combining common, min/max, test, and element type constraints.
49
+ * @template Value - The type of the array value.
50
+ * @template Parent - The type of the parent object.
51
+ * @see {@link id}
52
+ * @see {@link CommonConstraints}
53
+ * @see {@link MinMaxConstraints}
54
+ * @see {@link TestConstraint}
55
+ * @category Property Decorators
56
+ */
57
+ export declare interface ArrayConstraints<Value extends ArrayValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, number, Parent>, TestConstraint<Value, Parent> {
58
+ /**
59
+ * A class constructor, a function returning a constructor, a validation decorator, or a class id (see {@link id}) to
60
+ * validate each array element against.
61
+ * @see {@link array}
62
+ */
63
+ of: (Constructor<ArrayElementType<Value>> | (() => Constructor<ArrayElementType<Value>>) | ((_: any, context: ClassFieldDecoratorContext<Value, ArrayElementType<Value>>) => void) | string);
64
+ }
65
+
66
+ /**
67
+ * Type for extracting the element type from an array type.
68
+ * @template ArrayType - The array type.
69
+ * @ignore
70
+ */
71
+ export declare type ArrayElementType<ArrayType> = ArrayType extends Array<infer ElementType> ? ElementType : never;
72
+
73
+ /**
74
+ * Utility class for manipulating array fields in a form model, with automatic touch, validation, and rendering. See {@link FormManager.array} for details.
75
+ * @template T - The type of array elements.
76
+ * @category Form Management
77
+ */
78
+ export declare class ArrayHelper<T = any> {
79
+ readonly form: InternalFormManager<any>;
80
+ readonly path: string | Path;
81
+ private array;
82
+ /**
83
+ * Creates an ArrayHelper for a given form and path.
84
+ * @param form - The form manager instance.
85
+ * @param path - The path to the array field in the form.
86
+ */
87
+ constructor(form: InternalFormManager<any>, path: string | Path);
88
+ /**
89
+ * Tells if the field at the given path was an array.
90
+ * @returns True if the field was an array, false otherwise.
91
+ */
92
+ isArray(): boolean;
93
+ /**
94
+ * Appends an element to the array.
95
+ * @param element - The element to append.
96
+ * @param commit - Whether to validate and render after the operation (default: true).
97
+ */
98
+ append(element: T, commit?: boolean): void;
99
+ /**
100
+ * Replaces the element at the given index.
101
+ * @param index - The index to replace.
102
+ * @param element - The new element.
103
+ * @param commit - Whether to validate and render after the operation (default: true).
104
+ */
105
+ replace(index: number, element: T, commit?: boolean): void;
106
+ /**
107
+ * Inserts an element at the given index.
108
+ * @param index - The index to insert at.
109
+ * @param element - The element to insert.
110
+ * @param commit - Whether to validate and render after the operation (default: true).
111
+ */
112
+ insert(index: number, element: T, commit?: boolean): void;
113
+ /**
114
+ * Removes the element at the given index.
115
+ * @param index - The index to remove.
116
+ * @param commit - Whether to validate and render after the operation (default: true).
117
+ */
118
+ remove(index: number, commit?: boolean): void;
119
+ /**
120
+ * Swaps two elements in the array.
121
+ * @param index1 - The first index.
122
+ * @param index2 - The second index.
123
+ * @param commit - Whether to validate and render after the operation (default: true).
124
+ */
125
+ swap(index1: number, index2: number, commit?: boolean): void;
126
+ /**
127
+ * Moves an element from one index to another.
128
+ * @param from - The source index.
129
+ * @param to - The destination index.
130
+ * @param commit - Whether to validate and render after the operation (default: true).
131
+ */
132
+ move(from: number, to: number, commit?: boolean): void;
133
+ /**
134
+ * Removes all elements from the array.
135
+ * @param commit - Whether to validate and render after the operation (default: true).
136
+ */
137
+ clear(commit?: boolean): void;
138
+ /**
139
+ * Validates and renders the form if value is true.
140
+ * @param value - Whether to commit (validate and render).
141
+ */
142
+ private commit;
143
+ }
144
+
145
+ /**
146
+ * Constant representing the kind of array validation decorator.
147
+ * @ignore
148
+ */
149
+ export declare const arrayKind = "array";
150
+
151
+ /**
152
+ * Type for an array value, which can be an array, null, or undefined.
153
+ * @ignore
154
+ */
155
+ export declare type ArrayValue = any[] | null | undefined;
156
+
157
+ /**
158
+ * Assigns properties from source to target, with options for skipping undefined, including, or excluding keys.
159
+ * @template T - The target type.
160
+ * @template U - The source type.
161
+ * @param target - The target object.
162
+ * @param source - The source object.
163
+ * @param options - Optional settings for assignment.
164
+ * @returns The merged object.
165
+ * @category Utilities
166
+ */
167
+ export declare function assign<T extends {}, U>(target: T, source: U, options?: {
168
+ skipUndefined?: boolean;
169
+ includes?: (keyof U)[];
170
+ excludes?: (keyof U)[];
171
+ }): T & U;
172
+
173
+ /**
174
+ * Interface for an asynchronous test constraint.
175
+ * @template Value - The type of the value being validated.
176
+ * @template Parent - The type of the parent object.
177
+ * @property promise - Function returning a promise for the constraint message.
178
+ * @property pendingMessage - Message to show while pending.
179
+ * @property unavailableMessage - Message to show if async service is unavailable.
180
+ * @property dependencies - Function to get dependencies for revalidation.
181
+ * @property revalidate - Function to determine if revalidation is needed.
182
+ * @category Shared Constraints
183
+ */
184
+ export declare interface AsyncTestConstraint<Value, Parent = unknown> {
185
+ promise: (context: ValidationContext<NonNullable<Value>, Parent>) => Promise<TestConstraintMessage>;
186
+ pendingMessage?: ConstraintMessage;
187
+ unavailableMessage?: ConstraintMessage;
188
+ dependencies?: (context: InternalValidationContext<Value, Parent>) => any[];
189
+ revalidate?: (context: InternalValidationContext<Value, Parent>, previous: any[], current: any[], status: ValidationStatus | undefined) => boolean;
190
+ }
191
+
192
+ /**
193
+ * Type for async validation status, including dependencies.
194
+ * @category Validation Management
195
+ */
196
+ export declare type AsyncValidationStatus = {
197
+ /**
198
+ * The current validation status, which can be "pending", "unavailable", or a regular validation status.
199
+ */
200
+ status?: ValidationStatus | undefined;
201
+ /**
202
+ * The dependencies for the asynchronous validation.
203
+ */
204
+ dependencies: any[];
205
+ };
206
+
207
+ /**
208
+ * A base checkbox field component that can be used to create custom checkbox input components connected to the form state.
209
+ * @category Base Inputs Components
210
+ */
211
+ export declare function BaseCheckboxField(props: BaseCheckboxFieldProps): JSX_3.Element;
212
+
213
+ /**
214
+ * @ignore
215
+ */
216
+ export declare type BaseCheckboxFieldHTMLAttributes = Omit<InputAttributes<'checkbox'>, 'accept' | 'alt' | 'autocomplete' | 'capture' | 'dirname' | 'height' | 'list' | 'max' | 'maxLength' | 'min' | 'minLength' | 'multiple' | 'placeholder' | 'readOnly' | 'size' | 'src' | 'step' | 'type' | 'width'>;
217
+
218
+ /**
219
+ * @category Base Inputs Components
220
+ */
221
+ export declare type BaseCheckboxFieldProps = BaseCheckboxFieldHTMLAttributes & Omit<ReformEvents<boolean>, 'onBlur'> & {
222
+ render: () => void;
223
+ };
224
+
225
+ /**
226
+ * A base date field component that can be used to create custom date input components connected to the form state.
227
+ * @category Base Inputs Components
228
+ */
229
+ export declare function BaseDateField(props: BaseDateFieldProps): JSX_3.Element;
230
+
231
+ /**
232
+ * @category Base Inputs Components
233
+ */
234
+ declare type BaseDateFieldProps = BaseTextFieldHTMLAttributes & ReformEvents<Date> & {
235
+ render: () => void;
236
+ };
237
+
238
+ /**
239
+ * A base radio field component that can be used to create custom radio input components connected to the form state.
240
+ * @category Base Inputs Components
241
+ */
242
+ export declare function BaseRadioField<V = any>(props: BaseRadioFieldProps<V>): JSX_3.Element;
243
+
244
+ /**
245
+ * @ignore
246
+ */
247
+ export declare type BaseRadioFieldHTMLAttributes = Omit<InputAttributes<'radio'>, 'accept' | 'alt' | 'autocomplete' | 'capture' | 'dirname' | 'height' | 'list' | 'max' | 'maxLength' | 'min' | 'minLength' | 'multiple' | 'placeholder' | 'readOnly' | 'size' | 'src' | 'step' | 'type' | 'width'>;
248
+
249
+ /**
250
+ * @category Base Inputs Components
251
+ */
252
+ export declare type BaseRadioFieldProps<V> = BaseRadioFieldHTMLAttributes & ReformEvents<V> & {
253
+ modelValue: V;
254
+ render: () => void;
255
+ };
256
+
257
+ /**
258
+ * A base select field component that can be used to create custom select input components connected to the form state.
259
+ *
260
+ * To use it with with a basic { value, label } pair, you can use the following props:
261
+ * ```tsx
262
+ * <BaseSelectField
263
+ * name="mySelectId"
264
+ * modelValues={[ null, "1", "2" ]}
265
+ * toOptionValue={ modelValue => modelValue ?? "" }
266
+ * toOptionContent={ modelValue => modelValue == null ? "Select..." : `Option ${modelValue}` }
267
+ * toModelValue={ optionValue => optionValue === "" ? null : optionValue }
268
+ * render={ myRenderFunction } />
269
+ * ```
270
+ * @category Base Inputs Components
271
+ */
272
+ export declare function BaseSelectField<Value = string>(props: BaseSelectFieldProps<Value | null>): JSX_3.Element;
273
+
274
+ /**
275
+ * @ignore
276
+ */
277
+ export declare type BaseSelectFieldHTMLAttributes = (Omit<SelectHTMLAttributes<HTMLSelectElement>, 'name' | 'value' | 'defaultValue' | 'defaultChecked' | 'suppressContentEditableWarning' | 'suppressHydrationWarning' | 'contentEditable' | 'contextMenu' | 'hidden' | 'is' | 'autoComplete' | 'form' | 'multiple' | keyof DOMAttributes<HTMLSelectElement>> & {
278
+ name: string;
279
+ });
280
+
281
+ /**
282
+ * @category Base Inputs Components
283
+ */
284
+ export declare type BaseSelectFieldProps<V> = BaseSelectFieldHTMLAttributes & ReformEvents<V> & {
285
+ modelValues: V[];
286
+ toOptionValue: (modelValue: V) => string;
287
+ toOptionContent: (modelValue: V) => string;
288
+ toModelValue: (optionValue: string) => V;
289
+ render: () => void;
290
+ };
291
+
292
+ /**
293
+ * A base text area component that can be used to create custom text area input components connected to the form state.
294
+ * @category Base Inputs Components
295
+ */
296
+ export declare function BaseTextAreaField(props: BaseTextAreaFieldProps): JSX_3.Element;
297
+
298
+ /**
299
+ * @ignore
300
+ */
301
+ export declare type BaseTextAreaFieldHTMLAttributes = (Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'name' | 'value' | 'defaultValue' | 'defaultChecked' | 'suppressContentEditableWarning' | 'suppressHydrationWarning' | 'contentEditable' | 'contextMenu' | 'hidden' | 'is' | 'autoComplete' | 'dirName' | 'form' | keyof DOMAttributes<HTMLTextAreaElement>> & {
302
+ name: string;
303
+ });
304
+
305
+ /**
306
+ * @category Base Inputs Components
307
+ */
308
+ export declare type BaseTextAreaFieldProps = BaseTextAreaFieldHTMLAttributes & ReformEvents<string> & {
309
+ render: () => void;
310
+ };
311
+
312
+ /**
313
+ * A base text field component that can be used to create custom text input components connected to the form state. It handles change and blur events,
314
+ * converts between the input value and the model value using the provided `toModelValue` and `toTextValue` functions, and calls the provided `render`
315
+ * function to update the form state when the value changes. It also supports an `acceptInputValue` function to validate the input value on each change
316
+ * and a `formatDisplayedValue` function to format the displayed value while editing.
317
+ * @category Base Inputs Components
318
+ */
319
+ export declare function BaseTextField<Value = string>(props: BaseTextFieldProps<Value>): JSX_3.Element;
320
+
321
+ /**
322
+ * @ignore
323
+ */
324
+ export declare type BaseTextFieldHTMLAttributes = Omit<InputAttributes<"text" | "search" | "number" | "date" | "email" | "password" | "tel" | "time">, 'accept' | 'alt' | 'capture' | 'height' | 'multiple' | 'src' | 'step' | 'width'>;
325
+
326
+ /**
327
+ * @category Base Inputs Components
328
+ */
329
+ export declare type BaseTextFieldProps<V> = BaseTextFieldHTMLAttributes & ReformEvents<V> & {
330
+ toModelValue?: (value: string) => V | null;
331
+ toTextValue?: (value: V | null) => string;
332
+ acceptInputValue?: (value: string) => boolean;
333
+ formatDisplayedValue?: (value: string) => string;
334
+ formatOnEdit?: boolean;
335
+ render: () => void;
336
+ };
337
+
338
+ /**
339
+ * Basic implementation of MessageProvider for localized validation messages.
340
+ * @category Localization
341
+ */
342
+ export declare class BasicMessageProvider implements MessageProvider {
343
+ readonly locale: string;
344
+ private readonly numberFormat;
345
+ private readonly dateFormat;
346
+ private readonly listFormat;
347
+ private readonly pluralRules;
348
+ /**
349
+ * Map of message codes to message functions.
350
+ */
351
+ readonly messages: Map<string, MessageFunction>;
352
+ /**
353
+ * Creates a new BasicMessageProvider for a given locale and message entries.
354
+ * @param locale - The locale identifier.
355
+ * @param entries - Optional array of [code, message function] pairs.
356
+ */
357
+ constructor(locale: string, entries?: (readonly [string, MessageFunction])[]);
358
+ /**
359
+ * @inheritdoc
360
+ */
361
+ getMessage(context: InternalValidationContext<unknown>, code: string, constraint: any, message: ConstraintMessage | undefined, level: Level): ConstraintMessage;
362
+ }
363
+
364
+ /**
365
+ * Decorator for applying validation rules to a boolean field.
366
+ *
367
+ * Example usage:
368
+ * ```tsx
369
+ * class Person {
370
+ * @boolean({ required: true, oneOf: [[true], "Must be an adult"] })
371
+ * adult: boolean | null = null
372
+ * }
373
+ * const form = useForm(Person, ...)
374
+ *
375
+ * // the boolean decorator can also be used as a function to allow standalone validation:
376
+ * Yop.validate(false, boolean({ oneOf: [true] })) // error: "Must be one of: true"
377
+ * ```
378
+ * @template Value - The type of the boolean value.
379
+ * @template Parent - The type of the parent object.
380
+ * @param constraints - The boolean constraints to apply.
381
+ * @param groups - Optional validation groups.
382
+ * @returns A field decorator function with validation.
383
+ * @category Property Decorators
384
+ */
385
+ export declare function boolean<Value extends BooleanValue, Parent>(constraints?: BooleanConstraints<Value, Parent>, groups?: Groups<BooleanConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
386
+
387
+ /**
388
+ * Interface for boolean field constraints, combining common, oneOf, and test constraints.
389
+ * @template Value - The type of the boolean value.
390
+ * @template Parent - The type of the parent object.
391
+ * @see {@link CommonConstraints}
392
+ * @see {@link OneOfConstraint}
393
+ * @see {@link TestConstraint}
394
+ * @category Property Decorators
395
+ */
396
+ export declare interface BooleanConstraints<Value extends BooleanValue, Parent> extends CommonConstraints<Value, Parent>, OneOfConstraint<Value, Parent>, TestConstraint<Value, Parent> {
397
+ }
398
+
399
+ /**
400
+ * Type for a boolean value, which can be true, false, null, or undefined.
401
+ * @ignore
402
+ */
403
+ export declare type BooleanValue = boolean | null | undefined;
404
+
405
+ /**
406
+ * Type for a class constructor of a given type.
407
+ * @template Type - The type of the class instance.
408
+ * @ignore
409
+ */
410
+ export declare type ClassConstructor<Type> = new (...args: any) => NonNullable<Type>;
411
+
412
+ /**
413
+ * Type for a class field decorator function.
414
+ * @template Value - The type of the field value.
415
+ * @template Parent - The type of the parent object.
416
+ * @ignore
417
+ */
418
+ export declare type ClassFieldDecorator<Value, Parent = unknown> = (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
419
+
420
+ /**
421
+ * Deep clones a value, handling arrays, objects, dates, maps, sets, and files.
422
+ * @template T - The value type.
423
+ * @param value - The value to clone.
424
+ * @param cloned - Optional map of already cloned values.
425
+ * @returns The cloned value.
426
+ * @category Utilities
427
+ */
428
+ export declare function clone<T>(value: T, cloned?: Map<any, any>): T;
429
+
430
+ /**
431
+ * Common validation constraints for a value, used in decorators and validation logic.
432
+ * @template Value - The type of the value being validated.
433
+ * @template Parent - The type of the parent object.
434
+ * @category Shared Constraints
435
+ */
436
+ export declare interface CommonConstraints<Value, Parent = unknown> {
437
+ /**
438
+ * If `true`, the validation of the decorated element is skipped.
439
+ */
440
+ ignored?: Constraint<Value | null | undefined, boolean, Parent>;
441
+ /**
442
+ * If `true`, the property must be present in the parent object (ie: `"prop" in obj` is true).
443
+ */
444
+ exists?: Constraint<Value | null | undefined, boolean, Parent>;
445
+ /**
446
+ * If `true`, the value must not be `undefined`.
447
+ */
448
+ defined?: Constraint<Value | null | undefined, boolean, Parent>;
449
+ /**
450
+ * If `true`, the value must not be `null`.
451
+ */
452
+ notnull?: Constraint<Value | null | undefined, boolean, Parent>;
453
+ /**
454
+ * If `true`, the value must not be `undefined` or `null`.
455
+ */
456
+ required?: Constraint<Value | null | undefined, boolean, Parent>;
457
+ }
458
+
459
+ /**
460
+ * A constraint can be defined as a direct value, a tuple with value, message and level, or a function returning
461
+ * either of those.
462
+ * @category Shared Constraints
463
+ */
464
+ export declare type Constraint<Value, ConstraintType, Parent = unknown> = ConstraintValue<ConstraintType> | ConstraintFunction<Value, ConstraintType, Parent>;
465
+
466
+ /**
467
+ * Type representing a constraint function that returns a constraint value.
468
+ * @template Value - The type of the value being validated.
469
+ * @template ConstraintType - The type of the constraint value.
470
+ * @template Parent - The type of the parent object.
471
+ * @category Shared Constraints
472
+ */
473
+ export declare type ConstraintFunction<Value, ConstraintType, Parent = unknown> = ((context: ValidationContext<Value, Parent>) => ConstraintValue<ConstraintType> | undefined);
474
+
475
+ /**
476
+ * Type representing a constraint message, which can be a direct string or JSX element.
477
+ * @category Shared Constraints
478
+ */
479
+ export declare type ConstraintMessage = string | JSX_2.Element;
480
+
481
+ /**
482
+ * Interface for settings used when resolving constraints at a specific path.
483
+ * @ignore
484
+ */
485
+ export declare interface ConstraintsAtSettings extends ValidationSettings {
486
+ unsafeMetadata?: boolean;
487
+ }
488
+
489
+ /**
490
+ * Type representing a constraint value, which can be a direct value or a tuple containing the value, an optional message, and an optional level.
491
+ * This allows for flexible constraint definitions that can include custom error messages and severity levels.
492
+ * @template ConstraintType - The type of the constraint value.
493
+ * @category Shared Constraints
494
+ */
495
+ export declare type ConstraintValue<ConstraintType> = ConstraintType | readonly [ConstraintType, ConstraintMessage, Level?];
496
+
497
+ /**
498
+ * Type for a constructor of a given type, including primitive constructors.
499
+ * @template Type - The type to construct.
500
+ * @ignore
501
+ */
502
+ export declare type Constructor<Type = unknown> = Type extends unknown ? ClassConstructor<Type> | StringConstructor | BooleanConstructor | NumberConstructor : [
503
+ Type
504
+ ] extends [string | null | undefined] ? StringConstructor : [
505
+ Type
506
+ ] extends [boolean | null | undefined] ? BooleanConstructor : [
507
+ Type
508
+ ] extends [number | null | undefined] ? NumberConstructor : ClassConstructor<Type>;
509
+
510
+ /**
511
+ * Extracts the parent type from a CommonConstraints type.
512
+ * @ignore
513
+ */
514
+ export declare type ContraintsParent<Contraints> = Contraints extends CommonConstraints<infer _Value, infer Parent> ? Parent : never;
515
+
516
+ /**
517
+ * Extracts the value type from a CommonConstraints type.
518
+ * @ignore
519
+ */
520
+ export declare type ContraintsValue<Contraints> = Contraints extends CommonConstraints<infer Value, infer _Parent> ? Value : never;
521
+
522
+ /**
523
+ * Decorator for applying validation rules to a Date field.
524
+ *
525
+ * Example usage:
526
+ * ```tsx
527
+ * class Person {
528
+ * @date({ required: true, min: new Date("1900-01-01") })
529
+ * dateOfBirth: Date | null = null
530
+ * }
531
+ * const form = useForm(Person, ...)
532
+ *
533
+ * // the date decorator can also be used as a function to allow standalone validation:
534
+ * Yop.validate(null, date({ required: true })) // error: "Required field"
535
+ * ```
536
+ * @template Value - The type of the date value.
537
+ * @template Parent - The type of the parent object.
538
+ * @param constraints - The date constraints to apply.
539
+ * @param groups - Optional validation groups.
540
+ * @returns A field decorator function with validation.
541
+ * @category Property Decorators
542
+ */
543
+ export declare function date<Value extends DateValue, Parent>(constraints?: DateConstraints<Value, Parent>, groups?: Groups<DateConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
544
+
545
+ /**
546
+ * Interface for date field constraints, combining common, min/max, oneOf, and test constraints.
547
+ * @template Value - The type of the date value.
548
+ * @template Parent - The type of the parent object.
549
+ * @see {@link CommonConstraints}
550
+ * @see {@link MinMaxConstraints}
551
+ * @see {@link OneOfConstraint}
552
+ * @see {@link TestConstraint}
553
+ * @category Property Decorators
554
+ */
555
+ export declare interface DateConstraints<Value extends DateValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, Date, Parent>, OneOfConstraint<Value, Parent>, TestConstraint<Value, Parent> {
556
+ }
557
+
558
+ /**
559
+ * Type for a date value, which can be a Date object, null, or undefined.
560
+ * @ignore
561
+ */
562
+ export declare type DateValue = Date | null | undefined;
563
+
564
+ /**
565
+ * Defines a lazily-evaluated property on an object.
566
+ * @template T - The object type.
567
+ * @param o - The object.
568
+ * @param name - The property name.
569
+ * @param get - The getter function.
570
+ * @ignore
571
+ */
572
+ export declare function defineLazyProperty<T>(o: T, name: PropertyKey, get: ((_this: T) => unknown)): void;
573
+
574
+ /**
575
+ * Type for a diff result between two values.
576
+ * @template A - The first value type.
577
+ * @template B - The second value type.
578
+ * @category Utilities
579
+ */
580
+ export declare type Diff<A = any, B = any> = {
581
+ /**
582
+ * The first value in the diff comparison.
583
+ */
584
+ a: A;
585
+ /**
586
+ * The second value in the diff comparison.
587
+ */
588
+ b: B;
589
+ /**
590
+ * The diff tree representing differences between the two values. The tree is a nested object where keys are path segments and values are
591
+ * either further nested objects or empty objects indicating a difference at that path. If a path is not present in the tree, it means
592
+ * the values are equal at that path. When `equal` is true, the tree is an empty object: `{}`.
593
+ */
594
+ tree: {
595
+ [key: string | number]: any;
596
+ };
597
+ /**
598
+ * Indicates whether the two values are equal.
599
+ */
600
+ equal: boolean;
601
+ };
602
+
603
+ /**
604
+ * Computes the diff between two values, returning a diff tree and equality flag.
605
+ * @template A - The first value type.
606
+ * @template B - The second value type.
607
+ * @param a - The first value.
608
+ * @param b - The second value.
609
+ * @returns The diff result.
610
+ * @category Utilities
611
+ */
612
+ export declare function diff<A = any, B = any>(a: A, b: B): Diff<A, B>;
613
+
614
+ /**
615
+ * Checks if two values differ at a given path, using a diff tree.
616
+ * @param diff - The diff result.
617
+ * @param path - The path to check.
618
+ * @returns True if values differ at the path, false otherwise.
619
+ * @category Utilities
620
+ */
621
+ export declare function differs(diff: Diff, path: Path): boolean;
622
+
623
+ /**
624
+ * Decorator for applying validation rules to an email field. Emails are validated against a standard email regex pattern (RFC 5322 compliant).
625
+ *
626
+ * Example usage:
627
+ * ```tsx
628
+ * class Person {
629
+ * @email({ required: true, formatError: "Invalid email address" })
630
+ * email: string | null = null
631
+ * }
632
+ * const form = useForm(Person, ...)
633
+ *
634
+ * // the email decorator can also be used as a function to allow standalone validation:
635
+ * Yop.validate(null, email({ required: true })) // error: "Required field"
636
+ * ```
637
+ * @template Value - The type of the string value.
638
+ * @template Parent - The type of the parent object.
639
+ * @param constraints - The email constraints to apply.
640
+ * @param groups - Optional validation groups.
641
+ * @returns A field decorator function with validation.
642
+ * @category Property Decorators
643
+ */
644
+ export declare function email<Value extends StringValue, Parent>(constraints?: EmailConstraints<Value, Parent>, groups?: Groups<EmailConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
645
+
646
+ /**
647
+ * Interface for email field constraints, extending string constraints but omitting 'match'.
648
+ * @template Value - The type of the string value.
649
+ * @template Parent - The type of the parent object.
650
+ * @property formatError - Custom error message for invalid email format.
651
+ * @see {@link StringConstraints}
652
+ * @category Property Decorators
653
+ */
654
+ export declare interface EmailConstraints<Value extends StringValue, Parent> extends Omit<StringConstraints<Value, Parent>, "match"> {
655
+ /**
656
+ * Custom error message for invalid email format. `formatError` can be a {@link Message} or a function that returns a {@link Message}.
657
+ * @see {@link emailRegex}
658
+ */
659
+ formatError?: Message<Value, Parent>;
660
+ }
661
+
662
+ /**
663
+ * Regular expression for validating email addresses (RFC 5322 compliant).
664
+ * @ignore
665
+ */
666
+ export declare const emailRegex: RegExp;
667
+
668
+ /**
669
+ * Checks deep equality between two values, optionally ignoring a path.
670
+ * @param a - The first value.
671
+ * @param b - The second value.
672
+ * @param ignoredPath - Optional path to ignore.
673
+ * @returns True if equal, false otherwise.
674
+ * @category Utilities
675
+ */
676
+ export declare function equal(a: any, b: any, ignoredPath?: string | Path): boolean;
677
+
678
+ /**
679
+ * Creates a class field decorator that assigns or modifies field constraints.
680
+ * @template Parent - The type of the parent object.
681
+ * @template Value - The type of the field value.
682
+ * @param properties - An object or function to assign/modify field constraints.
683
+ * @param reset - If true, resets the field constraints before applying properties.
684
+ * @returns A class field decorator function.
685
+ * @ignore
686
+ */
687
+ export declare function fieldDecorator<Parent, Value>(properties: object | ((field: InternalCommonConstraints) => void), reset?: boolean): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
688
+
689
+ /**
690
+ * Represents the state of a form field, including value, validation, and metadata.
691
+ * @template Value - The type of the field value.
692
+ * @template MinMax - The type for min/max constraints.
693
+ * @template Root - The type of the root form values.
694
+ * @category Form Management
695
+ */
696
+ export declare type FieldState<Value, MinMax, Root = any> = {
697
+ /** The current value of the field. */
698
+ value: Value | undefined;
699
+ /** Whether the field has been touched. */
700
+ touched: boolean;
701
+ /** The validation status of the field, if any. See {@link ValidationStatus} for details. */
702
+ status?: ValidationStatus;
703
+ /** The form manager instance. See {@link FormManager} for details. */
704
+ form: FormManager<Root>;
705
+ /** Function to trigger a re-render of the component that called {@link useFormField} to get this field state. */
706
+ render: () => void;
707
+ /** The resolved constraints for the field, if any. See {@link ResolvedConstraints} for details. */
708
+ constraints?: ResolvedConstraints<MinMax>;
709
+ };
710
+
711
+ /**
712
+ * Creates a field validation decorator with the specified kind, constraints, groups, and validator.
713
+ * @template Constraints - The type of the field constraints.
714
+ * @template Value - The type of the field value.
715
+ * @template Parent - The type of the parent object.
716
+ * @param kind - The kind of the field (e.g., 'string', 'number').
717
+ * @param constraints - The field constraints to apply.
718
+ * @param groups - Optional groups of constraints.
719
+ * @param validator - The validation function for the field.
720
+ * @param isMinMaxType - Optional function to check min/max type.
721
+ * @param traverse - Optional traverser function for the field.
722
+ * @returns A class field decorator function with validation.
723
+ * @ignore
724
+ */
725
+ export declare function fieldValidationDecorator<Constraints extends CommonConstraints<any, any>, Value = ContraintsValue<Constraints>, Parent = ContraintsParent<Constraints>>(kind: string, constraints: Constraints, groups: Groups<Constraints> | undefined, validator: Validator<Constraints>, isMinMaxType?: (value: any) => boolean, traverse?: Traverser<Constraints>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
726
+
727
+ /**
728
+ * Decorator for applying validation rules to a File field.
729
+ *
730
+ * Example usage:
731
+ * ```tsx
732
+ * class Person {
733
+ * @file({ required: true, min: [1024, "Picture size must be at least 1KB"] })
734
+ * profilePicture: File | null = null
735
+ * }
736
+ * const form = useForm(Person, ...)
737
+ *
738
+ * // the file decorator can also be used as a function to allow standalone validation:
739
+ * Yop.validate(null, file({ required: true })) // error: "Required field"
740
+ * ```
741
+ * @template Value - The type of the file value.
742
+ * @template Parent - The type of the parent object.
743
+ * @param constraints - The file constraints to apply.
744
+ * @param groups - Optional validation groups.
745
+ * @returns A field decorator function with validation.
746
+ * @category Property Decorators
747
+ */
748
+ export declare function file<Value extends FileValue, Parent>(constraints?: FileConstraints<Value, Parent>, groups?: Groups<FileConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
749
+
750
+ /**
751
+ * Interface for file field constraints, combining common, min/max, and test constraints.
752
+ * @template Value - The type of the file value.
753
+ * @template Parent - The type of the parent object.
754
+ * @see {@link CommonConstraints}
755
+ * @see {@link MinMaxConstraints}
756
+ * @see {@link TestConstraint}
757
+ * @category Property Decorators
758
+ */
759
+ export declare interface FileConstraints<Value extends FileValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, number, Parent>, TestConstraint<Value, Parent> {
760
+ }
761
+
762
+ /**
763
+ * Type for a file value, which can be a File object, null, or undefined.
764
+ * @ignore
765
+ */
766
+ export declare type FileValue = File | null | undefined;
767
+
768
+ /**
769
+ * React component for rendering an HTML form with context, error display, and automatic form disabling. All children of
770
+ * this component will have access to the form manager via context, and they will be enclosed in an HTML `fieldset` that is disabled according to the
771
+ * `disabled` prop. If there are any validation errors, and if the debug option `displayFormErrors` is enabled (see {@link Reform.displayFormErrors}),
772
+ * they will be displayed in a formatted block below the form.
773
+ *
774
+ * Example usage:
775
+ * ```tsx
776
+ * const form = useForm(MyFormModel, onSubmit)
777
+ * return (
778
+ * <Form form={form} autoComplete="off" noValidate disabled={form.submitting}>
779
+ * // form fields here, using form context
780
+ * <button type="submit">Submit</button>
781
+ * </Form>
782
+ * )
783
+ * ```
784
+ *
785
+ * @param props - The Form props.
786
+ * @returns The rendered Form component.
787
+ * @category Form Management
788
+ */
789
+ export declare function Form(props: FormProps): JSX_3.Element;
790
+
791
+ /**
792
+ * Configuration options for the useForm hook.
793
+ * @template T - The type of the form values.
794
+ * @category Form Management
795
+ */
796
+ export declare type FormConfig<T extends object | any[] | null | undefined> = {
797
+ /**
798
+ * Initial values for the form. Can be an object, a function returning an object, or a function returning a promise that
799
+ * resolves to an object. Initial values are cloned and stored internally the first time they are neither `null` nor `undefined`.
800
+ * If a function is provided, it will be called on the first render and whenever the config changes, allowing for dynamic
801
+ * initial values. If the function returns a promise, the form will be in a pending state until the promise resolves, at
802
+ * which point the initial values will be set and the form will re-render.
803
+ *
804
+ * @see {@link FormManager.initialValuesPending}
805
+ * @see {@link FormConfig.initialValuesConverter}
806
+ */
807
+ readonly initialValues?: T | (() => T) | (() => Promise<T>) | null;
808
+ /**
809
+ * Converter function for initial values. This function is called with the initial values whenever they become neither
810
+ * `null` nor `undefined`. It allows for transformation or normalization of the initial values before they are set in the form.
811
+ * @param values - The initial values.
812
+ * @returns The transformed initial values.
813
+ */
814
+ readonly initialValuesConverter?: (values: T) => T;
815
+ /**
816
+ * The validation schema for the form. This can be a schema object created with the `instance` or `array` decorator.
817
+ * It defines the rules for validating the form values.
818
+ *
819
+ * Example usage:
820
+ * ```tsx
821
+ * const form = useForm({
822
+ * initialValues: new Person(),
823
+ * validationSchema: instance({ of: Person, required: true }),
824
+ * })
825
+ * ```
826
+ */
827
+ readonly validationSchema?: ((_: unknown, context: ClassFieldDecoratorContext<unknown, T>) => void);
828
+ /**
829
+ * Path or paths to validate. This can be a single path string or an array of path strings. If specified, only the values
830
+ * at these paths will be validated. If not specified, the entire form values will be validated.
831
+ */
832
+ readonly validationPath?: string | string[];
833
+ /**
834
+ * Validation groups to use during validation. This can be a single group or an array of groups. If specified, the validation
835
+ * rules associated with these groups will be applied. If not specified, only the validation rules of the default group will
836
+ * be applied.
837
+ *
838
+ * For example:
839
+ * ```tsx
840
+ * // will apply validation rules of "group1":
841
+ * validationGroups: "group1"
842
+ * // will apply validation rules of "group1" and "group2":
843
+ * validationGroups: ["group1", "group2"]
844
+ * // will apply validation rules of the default group and "group2":
845
+ * validationGroups: [undefined, "group2"]
846
+ * ```
847
+ */
848
+ readonly validationGroups?: Group;
849
+ /**
850
+ * Function to determine if a path should be ignored during validation. This function is called with the path being
851
+ * validated and the form manager instance. If it returns `true`, the path will be ignored and no validation will be
852
+ * performed for it.
853
+ * @param path - The path being validated.
854
+ * @param form - The form manager instance.
855
+ * @returns `true` if the path should be ignored, `false` otherwise.
856
+ */
857
+ readonly ignore?: (path: Path, form: FormManager<T>) => boolean;
858
+ /**
859
+ * Function to determine if the form can be submitted. This function is called with the form manager instance when a submit
860
+ * is attempted. If it returns `true`, the form will be submitted and the `onSubmit` callback will be called. If it returns
861
+ * `false`, the submit will be aborted and the `onSubmit` callback will not be called.
862
+ * @param form - The form manager instance.
863
+ * @returns `true` if the form can be submitted, `false` otherwise.
864
+ */
865
+ readonly submitGuard?: (form: FormManager<T>) => boolean;
866
+ /**
867
+ * Callback for form submission. This function is called with the form manager instance when the form is submitted and the
868
+ * `submitGuard` (if provided) returns `true`. It is responsible for handling the form submission logic, such as sending
869
+ * the form values to a server or updating application state. The {@link FormManager.submitting} is automatically set to
870
+ * `true` while this function is called. It is the responsibility of the caller to set it back to `false` when the
871
+ * submission process is complete (see {@link FormManager.setSubmitting}).
872
+ *
873
+ * Example usage:
874
+ * ```tsx
875
+ * const form = useForm({
876
+ * initialValues: new Person(),
877
+ * validationSchema: instance({ of: Person, required: true }),
878
+ * onSubmit: (form) => {
879
+ * console.log("Form submitted with values:", form.values)
880
+ * try {
881
+ * // perform submission logic here
882
+ * }
883
+ * finally {
884
+ * form.setSubmitting(false)
885
+ * }
886
+ * }
887
+ * })
888
+ * ```
889
+ * @param form - The form manager instance.
890
+ * @returns void
891
+ */
892
+ readonly onSubmit?: (form: FormManager<T>) => void;
893
+ /**
894
+ * Whether to dispatch events for observer propagation. If `true`, when a value changes, an event will be dispatched that can
895
+ * be listened to by observers to react to value changes. Default is `true`.
896
+ */
897
+ readonly dispatchEvent?: boolean;
898
+ };
899
+
900
+ /**
901
+ * React context for providing a FormManager instance to descendant components.
902
+ * @ignore
903
+ */
904
+ export declare const FormContext: default_2.Context<FormManager<unknown> | null>;
905
+
906
+ /**
907
+ * Interface for a form manager, providing value management, validation, and event APIs.
908
+ * @category Form Management
909
+ */
910
+ export declare interface FormManager<T> extends ValidationForm {
911
+ /**
912
+ * Renders the form, causing any changes to be reflected in the UI.
913
+ */
914
+ render(): void;
915
+ /**
916
+ * Sets the submitting state of the form. Submitting state is automatically set to `true` when the form is submitted, and
917
+ * should be reset to `false` when submission is complete.
918
+ * @param submitting - Whether the form is submitting.
919
+ */
920
+ setSubmitting(submitting: boolean): void;
921
+ /**
922
+ * The initial values of the form, as provided in the form config. These values are not modified by the form manager, and
923
+ * represent the original state of the form.
924
+ */
925
+ readonly initialValues: T | null | undefined;
926
+ /**
927
+ * Used when initialValues is provided as a promise. Indicates whether the promise is still pending.
928
+ */
929
+ readonly initialValuesPending: boolean;
930
+ /**
931
+ * The current values of the form. These values are managed by the form manager and should be considered the source of truth
932
+ * for the form state.
933
+ */
934
+ readonly values: T;
935
+ /**
936
+ * Sets the value of a form field.
937
+ * @param path - The path to the field.
938
+ * @param value - The value to set.
939
+ * @param options - Options for setting the value. See {@link SetValueOptions}.
940
+ * @returns The result of the set operation, or undefined if the path was invalid. See {@link SetResult}.
941
+ */
942
+ setValue(path: string | Path, value: unknown, options?: SetValueOptions): SetResult;
943
+ /**
944
+ * Validates the entire form.
945
+ * @param touchedOnly - Whether to validate only touched fields.
946
+ * @param ignore - A function to determine if a path should be ignored during validation.
947
+ */
948
+ validate(touchedOnly?: boolean, ignore?: (path: Path) => boolean): Map<string, ValidationStatus>;
949
+ /**
950
+ * Validates a specific field located at a given path in the form.
951
+ * @param path - The path to the field.
952
+ * @param touchedOnly - Whether to validate only touched fields.
953
+ * @param skipAsync - Whether to skip asynchronous validation.
954
+ */
955
+ validateAt(path: string | Path, touchedOnly?: boolean, skipAsync?: boolean): {
956
+ changed: boolean;
957
+ statuses: Map<string, ValidationStatus>;
958
+ };
959
+ /**
960
+ * Updates the asynchronous validation status of a specific field.
961
+ * @param path - The path to the field.
962
+ */
963
+ updateAsyncStatus(path: string | Path): void;
964
+ /**
965
+ * Scrolls to the first field with a validation error, if any. This is typically called after form submission if there
966
+ * are validation errors, to bring the user's attention to the first error. The implementation will scroll to an HTML with
967
+ * an id set to the path of the field with the error, so form fields should have their id set accordingly for this to work.
968
+ */
969
+ scrollToFirstError(): void;
970
+ /**
971
+ * Retrieves the constraints for a specific field.
972
+ * @param path - The path to the field.
973
+ * @param unsafeMetadata - Whether to include unsafe field metadata. If `true`, the resolved constraints will be of type
974
+ * {@link UnsafeResolvedConstraints}, which enables modification of the field constraints stored in the class metadata.
975
+ * This can be useful for advanced use cases, but should be used with caution.
976
+ * @return The resolved constraints for the field, or undefined if there are no constraints. See {@link ResolvedConstraints}.
977
+ */
978
+ constraintsAt<MinMax = unknown>(path: string | Path, unsafeMetadata?: boolean): ResolvedConstraints<MinMax> | undefined;
979
+ /**
980
+ * Handler for form submission. This should be called in the onSubmit handler of the form element. It will prevent the default
981
+ * form submission behavior,
982
+ * @param e - The form submission event.
983
+ */
984
+ submit(e: FormEvent<HTMLFormElement>): void;
985
+ /**
986
+ * Retrieves an array helper for a specific field. The array helper provides methods for manipulating array fields, such
987
+ * as appending, inserting, and removing elements, with automatic touch, validation, and rendering.
988
+ * @param path - The path to the array field.
989
+ * @return An ArrayHelper instance for the specified path, or undefined if the field is not an array.
990
+ */
991
+ array<T = any>(path: string): ArrayHelper<T> | undefined;
992
+ /**
993
+ * Adds an event listener for reform events of type {@link ReformSetValueEvent}.
994
+ * @param listener - The event listener to add.
995
+ */
996
+ addReformEventListener(listener: EventListener): void;
997
+ /**
998
+ * Removes an event listener for reform events of type {@link ReformSetValueEvent}.
999
+ * @param listener - The event listener to remove.
1000
+ */
1001
+ removeReformEventListener(listener: EventListener): void;
1002
+ }
1003
+
1004
+ /**
1005
+ * Props for the Form component.
1006
+ * @property form - The form manager instance.
1007
+ * @property disabled - Whether the form is disabled.
1008
+ * @category Form Management
1009
+ */
1010
+ export declare interface FormProps extends Omit<FormHTMLAttributes<HTMLFormElement>, "onSubmit"> {
1011
+ /** The form manager instance. */
1012
+ form: FormManager<unknown>;
1013
+ /** Whether the form is disabled. */
1014
+ disabled?: boolean;
1015
+ }
1016
+
1017
+ /**
1018
+ * Retrieves a value from an object or array using a string or parsed path.
1019
+ * @param value - The root object or array.
1020
+ * @param path - The path string or array.
1021
+ * @param cache - Optional cache for parsed paths.
1022
+ * @returns The value at the path, or undefined if not found.
1023
+ * @category Utilities
1024
+ */
1025
+ export declare function get<T = any>(value: unknown, path: string | Path, cache?: Map<string, Path>): T | undefined;
1026
+
1027
+ /**
1028
+ * Retrieves the class constructor from validation metadata, handling array and instance kinds.
1029
+ * @template T - The type of the class instance.
1030
+ * @param metadata - The validation metadata object.
1031
+ * @returns The class constructor, if found.
1032
+ * @ignore
1033
+ */
1034
+ export declare function getClassConstructor<T>(metadata: any): ClassConstructor<T> | undefined;
1035
+
1036
+ /**
1037
+ * Retrieves the validation metadata for a given class constructor.
1038
+ * @template T - The type of the class instance.
1039
+ * @param model - The class constructor.
1040
+ * @returns The common constraints metadata, if any.
1041
+ * @ignore
1042
+ */
1043
+ export declare function getMetadata<T>(model: ClassConstructor<T>): CommonConstraints<any, T> | undefined;
1044
+
1045
+ /**
1046
+ * Retrieves the field constraints metadata for all fields of a class constructor.
1047
+ * @template T - The type of the class instance.
1048
+ * @param model - The class constructor.
1049
+ * @returns An object mapping field names to their constraints, if any.
1050
+ * @ignore
1051
+ */
1052
+ export declare function getMetadataFields<T>(model: ClassConstructor<T>): { [K in keyof T]: CommonConstraints<any, T>; } | undefined;
1053
+
1054
+ /**
1055
+ * Retrieves field metadata from a class field decorator.
1056
+ * @template Value - The type of the field value.
1057
+ * @template Parent - The type of the parent object.
1058
+ * @param decorator - The class field decorator function.
1059
+ * @returns The field constraints metadata for a placeholder field.
1060
+ * @ignore
1061
+ */
1062
+ export declare function getMetadataFromDecorator<Value, Parent>(decorator: ClassFieldDecorator<Value, Parent>): InternalCommonConstraints | undefined;
1063
+
1064
+ /**
1065
+ * Retrieves the kind of a validation decorator from a value.
1066
+ * @param value - The value to inspect.
1067
+ * @returns The decorator kind, if present.
1068
+ * @ignore
1069
+ */
1070
+ export declare function getValidationDecoratorKind(value: any): string | undefined;
1071
+
1072
+ /**
1073
+ * Type representing the validation group or groups being currently validated. `undefined` means the default group.
1074
+ * @category Validation Management
1075
+ */
1076
+ export declare type Group = string | ((string | undefined)[]);
1077
+
1078
+ /**
1079
+ * Type for a map of group names to constraints.
1080
+ * @template Constraints - The type of the constraints.
1081
+ * @ignore
1082
+ */
1083
+ export declare type Groups<Constraints> = {
1084
+ [group: string]: Constraints;
1085
+ };
1086
+
1087
+ /**
1088
+ * The HTMLInputTypeAttribute type is a union of string literals that represent the valid values for the "type" attribute of an HTML input element
1089
+ * It includes common input types such as "text", "password", "email", etc., as well as a catch-all for any other string value that may be used as a
1090
+ * custom input type. This allows for flexibility while still providing type safety for known input types.
1091
+ * @ignore
1092
+ */
1093
+ declare type HTMLInputTypeAttribute = 'button' | 'checkbox' | 'color' | 'date' | 'datetime-local' | 'email' | 'file' | 'hidden' | 'image' | 'month' | 'number' | 'password' | 'radio' | 'range' | 'reset' | 'search' | 'submit' | 'tel' | 'text' | 'time' | 'url' | 'week' | (string & {});
1094
+
1095
+ /**
1096
+ * Class decorator to register a class with a unique identifier in the Yop registry. It can be used when you need to reference
1097
+ * classes by an identifier to prevent circular references.
1098
+ *
1099
+ * Example usage:
1100
+ * ```tsx
1101
+ * @id("Person")
1102
+ * class Person {
1103
+ *
1104
+ * @instance({ of: "Person" }) // circular reference to itself using the class id
1105
+ * friend: Person | null = null
1106
+ *
1107
+ * @array({ of: "Person" }) // circular reference to itself using the class id
1108
+ * friends: Person[] | null = null
1109
+ * }
1110
+ * ```
1111
+ *
1112
+ * @template Type - The type of the class instance.
1113
+ * @template Class - The constructor type of the class.
1114
+ * @param id - The unique identifier for the class.
1115
+ * @returns A class decorator function that registers the class in the Yop registry.
1116
+ * @see {@link InstanceConstraints}
1117
+ * @see {@link ArrayConstraints}
1118
+ * @category Class Decorators
1119
+ */
1120
+ export declare function id<Type extends object, Class extends Constructor<Type>>(id: string): (target: Class, _: ClassDecoratorContext<Class>) => void;
1121
+
1122
+ /**
1123
+ * Field decorator to mark a field as ignored for validation.
1124
+ *
1125
+ * Example usage:
1126
+ * ```tsx
1127
+ * class Person {
1128
+ * @string({ required: true, match: /^[A-Za-z]+$/ })
1129
+ * name: string | null = null
1130
+ * }
1131
+ * class Anonymous extends Person {
1132
+ * @ignored() // ignore all validation constraints on `name`
1133
+ * override name: string | null = null
1134
+ * }
1135
+ * ```
1136
+ *
1137
+ * @template Parent - The type of the parent object.
1138
+ * @param ignored - The constraint or boolean indicating if the field should be ignored (default: true).
1139
+ * @param groups - Optional groups with their own ignored constraints.
1140
+ * @returns A field decorator function that marks a field as ignored for validation.
1141
+ * @category Property Decorators
1142
+ */
1143
+ export declare function ignored<Parent>(ignored?: Constraint<any, boolean, Parent>, groups?: Groups<Constraint<any, boolean, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, any>) => void;
1144
+
1145
+ /**
1146
+ * Initializes and returns the internal class constraints for a given decorator metadata object.
1147
+ * @param decoratorMetadata - The metadata object from a class decorator.
1148
+ * @returns The initialized internal class constraints.
1149
+ * @ignore
1150
+ */
1151
+ export declare function initClassConstraints(decoratorMetadata: DecoratorMetadata): InternalClassConstraints<any>;
1152
+
1153
+ /**
1154
+ * The InputAttributes type is a utility type that takes an InputType parameter, which extends the HTMLInputTypeAttribute type. It uses the Omit utility
1155
+ * type to exclude certain properties from the InputHTMLAttributes type, such as 'name', 'type', 'value', 'checked', and others that are not relevant
1156
+ * for the input component. It then adds back the 'name' property as a required string and the 'type' property as an optional InputType. This allows for
1157
+ * creating a more specific set of attributes for input components while still maintaining flexibility for different input types.
1158
+ * @ignore
1159
+ */
1160
+ export declare type InputAttributes<InputType extends HTMLInputTypeAttribute> = (Omit<InputHTMLAttributes<HTMLInputElement>, 'name' | 'type' | 'value' | 'checked' | 'defaultValue' | 'defaultChecked' | 'suppressContentEditableWarning' | 'suppressHydrationWarning' | 'contentEditable' | 'contextMenu' | 'hidden' | 'is' | 'alt' | 'form' | 'formaction' | 'formenctype' | 'formmethod' | 'formnovalidate' | 'formtarget' | 'pattern' | 'src' | keyof DOMAttributes<HTMLInputElement>> & {
1161
+ name: string;
1162
+ type?: InputType;
1163
+ });
1164
+
1165
+ /**
1166
+ * @ignore
1167
+ */
1168
+ export declare interface InputSelection {
1169
+ start: number | null;
1170
+ end: number | null;
1171
+ direction?: "forward" | "backward" | "none";
1172
+ }
1173
+
1174
+ /**
1175
+ * Decorator for validating a field value as an instance of a specified class. The `of` property must be set to a custom
1176
+ * class constructor, not a built-in object type like String or Date.
1177
+ *
1178
+ * Example usage:
1179
+ * ```tsx
1180
+ * class Person {
1181
+ * @instance({ of: Dog, required: true })
1182
+ * dog: Dog | null = null
1183
+ * }
1184
+ * const form = useForm(Person, ...)
1185
+ *
1186
+ * // the instance decorator can also be used as a function to allow standalone validation:
1187
+ * Yop.validate(new Person(), instance({ of: Person })) // error: dog is a "Required field"
1188
+ * ```
1189
+ * @template Value - The type of the instance value.
1190
+ * @template Parent - The type of the parent object.
1191
+ * @param constraints - The instance constraints.
1192
+ * @param groups - Optional validation groups.
1193
+ * @returns A field decorator that stores the instance constraints and validation function in the class metadata.
1194
+ * @category Property Decorators
1195
+ */
1196
+ export declare function instance<Value extends InstanceValue, Parent>(constraints?: InstanceConstraints<Value, Parent>, groups?: Groups<InstanceConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
1197
+
1198
+ /**
1199
+ * Constraints for validating an instance of a class. Inherits common and test constraints.
1200
+ * @template Value - The type of the instance value.
1201
+ * @template Parent - The type of the parent object.
1202
+ * @property of - A class constructor, a function returning a constructor, or a class id to validate the instance against.
1203
+ * @see {@link id}
1204
+ * @see {@link CommonConstraints}
1205
+ * @see {@link TestConstraint}
1206
+ * @category Property Decorators
1207
+ */
1208
+ export declare interface InstanceConstraints<Value extends InstanceValue, Parent> extends CommonConstraints<Value, Parent>, TestConstraint<Value, Parent> {
1209
+ /**
1210
+ * A class constructor, a function returning a constructor, or a class id (see {@link id}) to validate the instance against.
1211
+ */
1212
+ of: ClassConstructor<NoInfer<Value>> | (() => ClassConstructor<NoInfer<Value>>) | string;
1213
+ }
1214
+
1215
+ /**
1216
+ * The kind string used to identify instance constraints.
1217
+ * @ignore
1218
+ */
1219
+ export declare const instanceKind = "instance";
1220
+
1221
+ /**
1222
+ * Utility type to extract the instance type from a constructor.
1223
+ * @template Class - The constructor type.
1224
+ * @category Class Decorators
1225
+ */
1226
+ declare type InstanceType_2<Class> = Class extends Constructor<infer Type> ? Type : never;
1227
+ export { InstanceType_2 as InstanceType }
1228
+
1229
+ /**
1230
+ * Type for values that can be validated as instances (objects, null, or undefined).
1231
+ * @ignore
1232
+ */
1233
+ export declare type InstanceValue = object | null | undefined;
1234
+
1235
+ /**
1236
+ * Internal constraints for a class, including test and field constraints.
1237
+ * @template Class - The type of the class.
1238
+ * @ignore
1239
+ */
1240
+ export declare interface InternalClassConstraints<Class = any> extends InternalConstraints {
1241
+ /**
1242
+ * Optional test constraint function for the class.
1243
+ */
1244
+ test?: TestConstraintFunction<Class>;
1245
+ /**
1246
+ * Optional map of field names to their internal constraints.
1247
+ */
1248
+ fields?: {
1249
+ [name: string]: InternalCommonConstraints;
1250
+ };
1251
+ }
1252
+
1253
+ /**
1254
+ * Internal constraints that include both common and internal constraint logic.
1255
+ * @ignore
1256
+ */
1257
+ export declare interface InternalCommonConstraints extends CommonConstraints<any, any>, InternalConstraints {
1258
+ }
1259
+
1260
+ /**
1261
+ * Used internally.
1262
+ * @ignore
1263
+ */
1264
+ export declare interface InternalConstraints {
1265
+ /**
1266
+ * The kind of the decorated value (eg: `string`, `number`, etc.)
1267
+ */
1268
+ kind: string;
1269
+ /**
1270
+ * The method that validates the decorated value.
1271
+ */
1272
+ validate: Validator<this>;
1273
+ /**
1274
+ * The method that returns the constraints and value of a nested field.
1275
+ */
1276
+ traverse?: Traverser<this>;
1277
+ /**
1278
+ * Validation groups with specific constraints. If specified, the given constraints will only be validated if at least one
1279
+ * of the groups is active in the validation context.
1280
+ */
1281
+ groups?: Groups<this>;
1282
+ }
1283
+
1284
+ /**
1285
+ * Implementation of the FormManager interface, providing value management, validation, eventing, and array helpers.
1286
+ * @ignore
1287
+ */
1288
+ export declare class InternalFormManager<T extends object | null | undefined> implements FormManager<T> {
1289
+ readonly render: () => void;
1290
+ private _config;
1291
+ private yop;
1292
+ private pathCache;
1293
+ private _initialValues;
1294
+ private _initialValuesPending;
1295
+ private _values;
1296
+ private _statuses;
1297
+ private touched;
1298
+ private _submitting;
1299
+ private _submitted;
1300
+ private eventTarget;
1301
+ htmlForm?: HTMLFormElement;
1302
+ constructor(render: () => void);
1303
+ addReformEventListener(listener: EventListener): void;
1304
+ removeReformEventListener(listener: EventListener): void;
1305
+ get initialValuesPending(): boolean;
1306
+ get submitted(): boolean;
1307
+ get submitting(): boolean;
1308
+ get config(): FormConfig<T>;
1309
+ get store(): Map<string, any>;
1310
+ set initialValuesPending(pending: boolean);
1311
+ setSubmitting(submitting: boolean): void;
1312
+ commitInitialValues(): void;
1313
+ onRender(config: FormConfig<T>): void;
1314
+ get initialValues(): T | null | undefined;
1315
+ get values(): T;
1316
+ getValue<V = any>(path: string | Path): V | undefined;
1317
+ setValue(path: string | Path, value: unknown, options?: SetValueOptions): SetResult;
1318
+ isDirty(path?: string | Path, ignoredPath?: string | Path): boolean;
1319
+ isTouched(path?: string | Path): boolean;
1320
+ touch(path?: string | Path): void;
1321
+ untouch(path?: string | Path): void;
1322
+ getTouchedValue<T = any>(path: string | Path): T;
1323
+ setTouchedValue(path: string | Path, value: any): void;
1324
+ get statuses(): Map<string, ValidationStatus>;
1325
+ get errors(): ValidationStatus[];
1326
+ validate(touchedOnly?: boolean, ignore?: (path: Path, form: FormManager<T>) => boolean): Map<string, ValidationStatus>;
1327
+ validateAt(path: string | Path, touchedOnly?: boolean, skipAsync?: boolean): {
1328
+ changed: boolean;
1329
+ statuses: Map<string, ValidationStatus>;
1330
+ };
1331
+ constraintsAt<MinMax = unknown>(path: string | Path, unsafeMetadata?: boolean): ResolvedConstraints<MinMax> | undefined;
1332
+ updateAsyncStatus(path: string | Path): void;
1333
+ submit(e: FormEvent<HTMLFormElement>): void;
1334
+ scrollToFirstError(errors?: ValidationStatus[]): void;
1335
+ array<T = any>(path: string): ArrayHelper<T> | undefined;
1336
+ }
1337
+
1338
+ /**
1339
+ * Internal implementation of the ValidationContext interface, used for managing validation state and providing utility methods
1340
+ * for creating child contexts and statuses.
1341
+ * @ignore
1342
+ */
1343
+ export declare class InternalValidationContext<Value, Parent = unknown> implements ValidationContext<Value, Parent> {
1344
+ readonly yop: Yop;
1345
+ readonly kind: string;
1346
+ readonly value: Value;
1347
+ readonly path: Path;
1348
+ readonly parentContext: InternalValidationContext<Parent> | undefined;
1349
+ readonly rootContext: InternalValidationContext<unknown> | undefined;
1350
+ readonly settings: ValidationSettings | undefined;
1351
+ readonly store: Map<string, any>;
1352
+ readonly statuses: Map<string, ValidationStatus>;
1353
+ constructor(props: {
1354
+ yop: Yop;
1355
+ kind: string;
1356
+ value: Value;
1357
+ key?: string | number | undefined;
1358
+ parentContext?: InternalValidationContext<Parent> | undefined;
1359
+ rootContext?: InternalValidationContext<unknown> | undefined;
1360
+ userContext?: unknown | undefined;
1361
+ statuses?: Map<string, ValidationStatus>;
1362
+ settings?: ValidationSettings;
1363
+ });
1364
+ ignored(): boolean;
1365
+ get parent(): Parent;
1366
+ get groups(): Group | undefined;
1367
+ get form(): ValidationForm | undefined;
1368
+ getRoot<T>(): T | undefined;
1369
+ createChildContext(props: {
1370
+ kind: string;
1371
+ value: Value;
1372
+ key: string | number;
1373
+ }): InternalValidationContext<Value, Value>;
1374
+ createStatus(code: string, constraint: any, message?: ConstraintMessage, level?: Level): ValidationStatus;
1375
+ setStatus(code: string, constraint: any, message?: ConstraintMessage, level?: Level): ValidationStatus;
1376
+ }
1377
+
1378
+ /**
1379
+ * Checks if a value is a boolean.
1380
+ * @template T - The boolean type.
1381
+ * @param value - The value to check.
1382
+ * @returns True if value is boolean.
1383
+ * @ignore
1384
+ */
1385
+ export declare const isBoolean: <T extends boolean>(value: any) => value is T;
1386
+
1387
+ /**
1388
+ * Checks if a value is an array of booleans.
1389
+ * @template T - The boolean type.
1390
+ * @param value - The value to check.
1391
+ * @returns True if value is an array of booleans.
1392
+ * @ignore
1393
+ */
1394
+ export declare const isBooleanArray: <T extends boolean>(value: any) => value is Array<T>;
1395
+
1396
+ /**
1397
+ * Checks if a value is a valid Date object.
1398
+ * @template T - The Date type.
1399
+ * @param value - The value to check.
1400
+ * @returns True if value is a valid Date.
1401
+ * @ignore
1402
+ */
1403
+ export declare const isDate: <T extends Date>(value: any) => value is T;
1404
+
1405
+ /**
1406
+ * Checks if a value is an array of Date objects.
1407
+ * @template T - The Date type.
1408
+ * @param value - The value to check.
1409
+ * @returns True if value is an array of Dates.
1410
+ * @ignore
1411
+ */
1412
+ export declare const isDateArray: <T extends Date>(value: any) => value is Array<T>;
1413
+
1414
+ /**
1415
+ * Checks if a value is a File object.
1416
+ * @template T - The File type.
1417
+ * @param value - The value to check.
1418
+ * @returns True if value is a File.
1419
+ * @ignore
1420
+ */
1421
+ export declare const isFile: <T extends File>(value: any) => value is T;
1422
+
1423
+ /**
1424
+ * Checks if a value is a function.
1425
+ * @template T - The function type.
1426
+ * @param value - The value to check.
1427
+ * @returns True if value is a function.
1428
+ * @ignore
1429
+ */
1430
+ export declare const isFunction: <T extends Function>(value: any) => value is T;
1431
+
1432
+ /**
1433
+ * Checks if a value is a valid number (not NaN).
1434
+ * @template T - The number type.
1435
+ * @param value - The value to check.
1436
+ * @returns True if value is a valid number.
1437
+ * @ignore
1438
+ */
1439
+ export declare const isNumber: <T extends number>(value: any) => value is T;
1440
+
1441
+ /**
1442
+ * Checks if a value is an array of numbers.
1443
+ * @template T - The number type.
1444
+ * @param value - The value to check.
1445
+ * @returns True if value is an array of numbers.
1446
+ * @ignore
1447
+ */
1448
+ export declare const isNumberArray: <T extends number>(value: any) => value is Array<T>;
1449
+
1450
+ /**
1451
+ * Checks if a value is a non-null object (not an array).
1452
+ * @template T - The object type.
1453
+ * @param value - The value to check.
1454
+ * @returns True if value is an object.
1455
+ * @ignore
1456
+ */
1457
+ export declare const isObject: <T extends object>(value: any) => value is T;
1458
+
1459
+ /**
1460
+ * Checks if a value is a Promise.
1461
+ * @template T - The Promise type.
1462
+ * @param value - The value to check.
1463
+ * @returns True if value is a Promise.
1464
+ * @ignore
1465
+ */
1466
+ export declare const isPromise: <T>(value: any) => value is Promise<T>;
1467
+
1468
+ /**
1469
+ * Checks if a value is a RegExp object.
1470
+ * @param value - The value to check.
1471
+ * @returns True if value is a RegExp.
1472
+ * @ignore
1473
+ */
1474
+ export declare const isRegExp: (value: any) => value is RegExp;
1475
+
1476
+ /**
1477
+ * Checks if a value is a string.
1478
+ * @template T - The string type.
1479
+ * @param value - The value to check.
1480
+ * @returns True if value is a string.
1481
+ * @ignore
1482
+ */
1483
+ export declare const isString: <T extends string>(value: any) => value is T;
1484
+
1485
+ /**
1486
+ * Checks if a value is an array of strings.
1487
+ * @template T - The string type.
1488
+ * @param value - The value to check.
1489
+ * @returns True if value is an array of strings.
1490
+ * @ignore
1491
+ */
1492
+ export declare const isStringArray: <T extends string>(value: any) => value is Array<T>;
1493
+
1494
+ /**
1495
+ * Checks if a class constructor is a subclass of another.
1496
+ * @template T - The parent class type.
1497
+ * @param value - The class constructor to check.
1498
+ * @param parent - The parent class constructor.
1499
+ * @returns True if value is a subclass of parent.
1500
+ * @ignore
1501
+ */
1502
+ export declare const isSubclassOf: <T>(value: ClassConstructor<any>, parent: ClassConstructor<T>) => value is ClassConstructor<T>;
1503
+
1504
+ /**
1505
+ * Joins path segments into a string, using dot/bracket notation as needed.
1506
+ * @param segments - The path segments to join.
1507
+ * @returns The joined path string.
1508
+ * @category Utilities
1509
+ */
1510
+ export declare function joinPath(segments: Path): string;
1511
+
1512
+ /**
1513
+ * The types of validation status levels. "pending" and "unavailable" are only used for asynchronous validations.
1514
+ * "pending" indicates that the asynchronous validation is in progress, while "unavailable" indicates that the validation
1515
+ * couldn't be performed (e.g., due to an unreachable server).
1516
+ * @see {@link ValidationStatus}
1517
+ * @category Validation Management
1518
+ */
1519
+ export declare type Level = "info" | "warning" | "error" | "pending" | "unavailable";
1520
+
1521
+ /**
1522
+ * @ignore
1523
+ */
1524
+ export declare const localDateToString: (date: Date | null | undefined) => string | null;
1525
+
1526
+ /**
1527
+ * Merges default constraint properties into field metadata, applying to all groups if not already set.
1528
+ * @template Constraints - The type of the constraints.
1529
+ * @template Parent - The type of the parent object.
1530
+ * @template Value - The type of the field value.
1531
+ * @param decorator - The field decorator function.
1532
+ * @param defaultProps - The default constraint properties to merge.
1533
+ * @returns A new field decorator function with merged defaults.
1534
+ * @ignore
1535
+ */
1536
+ export declare function mergeDefaultMetadata<Constraints extends {}, Parent, Value>(decorator: (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void, defaultProps: Constraints): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
1537
+
1538
+ /**
1539
+ * Merges constraints from props and groups using a merger function.
1540
+ * @template Constraints - The type of the constraints.
1541
+ * @param props - The main constraints object.
1542
+ * @param groups - Optional groups of constraints.
1543
+ * @param merger - Function to merge each constraints object.
1544
+ * @ignore
1545
+ */
1546
+ export declare function mergeMetadata<Constraints>(props?: Constraints, groups?: Groups<Constraints>, merger?: (params: Constraints) => void): void;
1547
+
1548
+ /**
1549
+ * A validation message can be defined as a direct string/JSX element or a function returning a message.
1550
+ * @category Shared Constraints
1551
+ */
1552
+ export declare type Message<Value, Parent> = ConstraintMessage | ((context: ValidationContext<Value, Parent>) => ConstraintMessage);
1553
+
1554
+ /**
1555
+ * Function type for generating a message from message properties.
1556
+ * @see {@link MessageProps}
1557
+ * @category Localization
1558
+ */
1559
+ export declare type MessageFunction = (props: MessageProps) => string;
1560
+
1561
+ /**
1562
+ * Properties passed to a message function for formatting.
1563
+ * @category Localization
1564
+ */
1565
+ export declare type MessageProps = {
1566
+ context: ValidationContext<unknown>;
1567
+ code: string;
1568
+ constraint: {
1569
+ raw: any;
1570
+ formatted: string;
1571
+ plural?: Intl.LDMLPluralRule;
1572
+ };
1573
+ level: Level;
1574
+ };
1575
+
1576
+ /**
1577
+ * Interface for providing localized validation messages.
1578
+ * @category Localization
1579
+ */
1580
+ export declare interface MessageProvider {
1581
+ /**
1582
+ * The locale identifier (e.g., 'en-US', 'fr-FR').
1583
+ */
1584
+ readonly locale: string;
1585
+ /**
1586
+ * Returns a localized message for a given validation context and code.
1587
+ * @param context - The validation context.
1588
+ * @param code - The message code.
1589
+ * @param constraint - The constraint value.
1590
+ * @param message - An optional custom message.
1591
+ * @param level - The validation level (e.g., 'error', 'pending').
1592
+ * @returns The resolved message.
1593
+ */
1594
+ getMessage(context: InternalValidationContext<unknown>, code: string, constraint: any, message: ConstraintMessage | undefined, level: Level): ConstraintMessage;
1595
+ }
1596
+
1597
+ /**
1598
+ * English (US) message provider for validation messages.
1599
+ * @category Localization
1600
+ */
1601
+ export declare const messageProvider_en_US: BasicMessageProvider;
1602
+
1603
+ /**
1604
+ * French (FR) message provider for validation messages.
1605
+ * @category Localization
1606
+ */
1607
+ export declare const messageProvider_fr_FR: BasicMessageProvider;
1608
+
1609
+ /**
1610
+ * Interface for min and max constraints on a value.
1611
+ * @template Value - The type of the value being validated.
1612
+ * @template MinMax - The type for min/max values.
1613
+ * @template Parent - The type of the parent object.
1614
+ * @property min - Minimum constraint for the value, if any.
1615
+ * @property max - Maximum constraint for the value, if any.
1616
+ * @property isMinMaxType - Type guard for min/max values.
1617
+ * @category Shared Constraints
1618
+ */
1619
+ export declare interface MinMaxConstraints<Value, MinMax, Parent = unknown> {
1620
+ /**
1621
+ * Minimum constraint for the value. The value must be greater than or equal to this constraint.
1622
+ */
1623
+ min?: Constraint<NonNullable<Value>, MinMax | null | undefined, Parent>;
1624
+ /**
1625
+ * Maximum constraint for the value. The value must be less than or equal to this constraint.
1626
+ */
1627
+ max?: Constraint<NonNullable<Value>, MinMax | null | undefined, Parent>;
1628
+ /**
1629
+ * Optional type guard function to determine if a value is a valid min/max constraint. This can be used to ensure
1630
+ * that the constraint values are of the expected type.
1631
+ */
1632
+ isMinMaxType?: (value: any) => value is MinMax;
1633
+ }
1634
+
1635
+ /**
1636
+ * Type for a class constructor of a model.
1637
+ * @category Form Management
1638
+ */
1639
+ export declare type Model<T> = new (...args: any) => NonNullable<T>;
1640
+
1641
+ /**
1642
+ * Decorator for applying validation rules to a number field.
1643
+ *
1644
+ * Example usage:
1645
+ * ```tsx
1646
+ * class Person {
1647
+ * @number({ required: true, min: 0 })
1648
+ * age: number | null = null
1649
+ * }
1650
+ * const form = useForm(Person, ...)
1651
+ *
1652
+ * // the number decorator can also be used as a function to allow standalone validation:
1653
+ * Yop.validate(-1, number({ required: true, min: 0 })) // error: "Must be greater or equal to 0"
1654
+ * ```
1655
+ * @template Value - The type of the number value.
1656
+ * @template Parent - The type of the parent object.
1657
+ * @param constraints - The number constraints to apply.
1658
+ * @param groups - Optional validation groups.
1659
+ * @returns A field decorator function with validation.
1660
+ * @category Property Decorators
1661
+ */
1662
+ export declare function number<Value extends NumberValue, Parent>(constraints?: NumberConstraints<Value, Parent>, groups?: Groups<NumberConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
1663
+
1664
+ /**
1665
+ * Interface for number field constraints, combining common, min/max, oneOf, and test constraints.
1666
+ * @template Value - The type of the number value.
1667
+ * @template Parent - The type of the parent object.
1668
+ * @see {@link CommonConstraints}
1669
+ * @see {@link MinMaxConstraints}
1670
+ * @see {@link OneOfConstraint}
1671
+ * @see {@link TestConstraint}
1672
+ * @category Property Decorators
1673
+ */
1674
+ export declare interface NumberConstraints<Value extends NumberValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, number, Parent>, OneOfConstraint<Value, Parent>, TestConstraint<Value, Parent> {
1675
+ }
1676
+
1677
+ /**
1678
+ * Type for a number value, which can be a number, null, or undefined.
1679
+ * @ignore
1680
+ */
1681
+ export declare type NumberValue = number | null | undefined;
1682
+
1683
+ /**
1684
+ * Decorator to register or remove an observer callback for a field. Observer paths use a syntax similar to Unix file paths,
1685
+ * supporting wildcards and array indices, and are relative to the parent object of the field where the observer is attached.
1686
+ * Paths can also be absolute (starting with a slash `/`) to observe fields from the root, or use `..` to observe fields from
1687
+ * higher up in the object tree.
1688
+ *
1689
+ * Observers are only triggered if {@link FormConfig.dispatchEvent} isn't set to `false` and if the class holding `observers`
1690
+ * decorators is bound to the current form using {@link useObservers}.
1691
+ *
1692
+ * Examples:
1693
+ * - `name` observes the `name` field of the parent object.
1694
+ * - `user/name` observes the `name` field of the sibling `user` object.
1695
+ * - `items[*]/price` observes the `price` field of all items in the sibling `items` array.
1696
+ * - `orders[0]/status` observes the `status` field of the first order in the sibling `orders` array.
1697
+ * - `/name` observes the `name` field at the root level.
1698
+ * - `../name` observes the `name` field in the parent of the parent object.
1699
+ *
1700
+ * Example usage:
1701
+ * ```tsx
1702
+ * class MyFormModel {
1703
+ *
1704
+ * age: number | null = null
1705
+ *
1706
+ * @observer("age", (context) => context.setValue(
1707
+ * context.observedValue != null ? (context.observedValue as number) >= 18 : null,
1708
+ * { untouch: true }
1709
+ * ))
1710
+ * adult: boolean | null = null
1711
+ * }
1712
+ *
1713
+ * const form = useForm(MyFormModel, ...)
1714
+ *
1715
+ * ```
1716
+ *
1717
+ * @template Value - The type of the field value where the observer is attached.
1718
+ * @template Parent - The parent type containing the field.
1719
+ * @param path - The path to observe.
1720
+ * @param callback - The observer callback function, or undefined to remove it.
1721
+ * @returns A field decorator function.
1722
+ * @category Observers
1723
+ */
1724
+ export declare function observer<Value, Parent>(path: string, callback: ObserverCallback<Value> | undefined): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
1725
+
1726
+ /**
1727
+ * Observer callback function type.
1728
+ *
1729
+ * @template T - The type of the field value where the observer is attached.
1730
+ * @param context - The context for the observer callback. See {@link ObserverCallbackContext}.
1731
+ * @category Observers
1732
+ */
1733
+ export declare type ObserverCallback<T> = (context: ObserverCallbackContext<T>) => void;
1734
+
1735
+ /**
1736
+ * Context object passed to observer callbacks.
1737
+ *
1738
+ * @template T - The type of the field value where the observer is attached.
1739
+ * @category Observers
1740
+ */
1741
+ export declare type ObserverCallbackContext<T> = {
1742
+ /** The absolute path of the field value where the observer is attached */
1743
+ path: Path;
1744
+ /** The value being observed. */
1745
+ observedValue: unknown;
1746
+ /** The current value of the field where the observer is attached. */
1747
+ currentValue: T;
1748
+ /** Sets the value of the field where the observer is attached. */
1749
+ setValue: (value: T, options?: ObserverCallbackOptions) => void;
1750
+ /** The event object providing context. See {@link ReformSetValueEvent}. */
1751
+ event: ReformSetValueEvent<unknown>;
1752
+ };
1753
+
1754
+ /**
1755
+ * Options for observer callback behavior.
1756
+ * @category Observers
1757
+ */
1758
+ export declare type ObserverCallbackOptions = {
1759
+ /** If `true`, marks the field as untouched. */
1760
+ untouch?: boolean;
1761
+ /** If `true`, propagates the value change to other observers. Defaults to `false` to prevent potential infinite loops*/
1762
+ propagate?: boolean;
1763
+ };
1764
+
1765
+ /**
1766
+ * Metadata for an observer, including its path and callback.
1767
+ *
1768
+ * @template T - The type of the field value where the observer is attached.
1769
+ * @ignore
1770
+ */
1771
+ export declare type ObserverMetadata<T> = {
1772
+ /** The path of the field being observed. */
1773
+ path: string;
1774
+ /** The observer callback function. */
1775
+ callback: ObserverCallback<T>;
1776
+ };
1777
+
1778
+ /**
1779
+ * Map of observer metadata, keyed by observed path.
1780
+ * @ignore
1781
+ */
1782
+ export declare type Observers = Map<string, ObserverMetadata<any>>;
1783
+
1784
+ /**
1785
+ * Field metadata type that can hold observers in addition to common constraints.
1786
+ * @ignore
1787
+ */
1788
+ export declare type ObserversField = InternalCommonConstraints & {
1789
+ observers?: Observers;
1790
+ };
1791
+
1792
+ /**
1793
+ * Interface for a constraint that checks if a value is one of a set of allowed values.
1794
+ * @template Value - The type of the value being validated.
1795
+ * @template Parent - The type of the parent object.
1796
+ * @property oneOf - Constraint for allowed values, if any.
1797
+ * @category Shared Constraints
1798
+ */
1799
+ export declare interface OneOfConstraint<Value, Parent = unknown> {
1800
+ oneOf?: Constraint<NonNullable<Value>, NoInfer<NonNullable<Value>>[], Parent>;
1801
+ }
1802
+
1803
+ /**
1804
+ * Type for a parsed path, as an array of string or number segments. Numbers represent array indices, while strings represent object keys. This type
1805
+ * is used for efficient access to nested properties in objects or arrays.
1806
+ * @see {@link splitPath}
1807
+ * @category Utilities
1808
+ */
1809
+ export declare type Path = (string | number)[];
1810
+
1811
+ /**
1812
+ * Static configuration for form error display and logging.
1813
+ * @category Form Management
1814
+ */
1815
+ export declare class Reform {
1816
+ /**
1817
+ * Whether to display form errors in the UI (debug only).
1818
+ */
1819
+ static displayFormErrors: boolean;
1820
+ /**
1821
+ * Whether to log form errors to the console (debug only).
1822
+ */
1823
+ static logFormErrors: boolean;
1824
+ }
1825
+
1826
+ /**
1827
+ * Settings for constraintsAt validation, combining reform and Yop constraint settings.
1828
+ * @ignore
1829
+ */
1830
+ export declare interface ReformConstraintsAtSettings extends ReformValidationSettings, ConstraintsAtSettings {
1831
+ }
1832
+
1833
+ /**
1834
+ * The ReformEvents type is a generic type that takes two parameters: Value, which represents the type of the value being handled, and Root,
1835
+ * which extends object and represents the type of the form's root state. It defines two optional event handler properties: onChange and onBlur.
1836
+ * Both handlers receive the current value (which can be of type Value or null) and an instance of FormManager that manages the form's state.
1837
+ * This allows for handling changes and blur events in a way that is integrated with the form management system.
1838
+ * @category Base Inputs Components
1839
+ */
1840
+ export declare type ReformEvents<Value, Root extends object = any> = {
1841
+ onChange?: (value: Value | null, form: FormManager<Root>) => void;
1842
+ onBlur?: (value: Value | null, form: FormManager<Root>) => void;
1843
+ };
1844
+
1845
+ /**
1846
+ * Event fired when a value is set in the form, used for observer propagation.
1847
+ * @template T - The type of the value being set.
1848
+ * @category Form Management
1849
+ */
1850
+ export declare interface ReformSetValueEvent<T = any> extends CustomEvent<{
1851
+ readonly form: FormManager<unknown>;
1852
+ readonly path: string;
1853
+ readonly previousValue: T;
1854
+ readonly value: T;
1855
+ readonly options: SetValueOptionsObject;
1856
+ }> {
1857
+ }
1858
+
1859
+ /**
1860
+ * Validation settings for reform forms, extending base validation settings.
1861
+ * @property method - The validation method to use.
1862
+ * @ignore
1863
+ */
1864
+ export declare interface ReformValidationSettings extends ValidationSettings {
1865
+ method: "validate" | "validateAt" | "constraintsAt";
1866
+ }
1867
+
1868
+ /**
1869
+ * Type for resolved constraints, including required, min, and max.
1870
+ * @template MinMax - The type for min/max values.
1871
+ * @category Validation Management
1872
+ */
1873
+ export declare type ResolvedConstraints<MinMax = unknown> = {
1874
+ /**
1875
+ * Whether the field is required.
1876
+ */
1877
+ required: boolean;
1878
+ /**
1879
+ * The minimum value or length for the field, if applicable.
1880
+ */
1881
+ min?: MinMax;
1882
+ /**
1883
+ * The maximum value or length for the field, if applicable.
1884
+ */
1885
+ max?: MinMax;
1886
+ };
1887
+
1888
+ /**
1889
+ * Sets a value in an object or array at a given path, optionally cloning and using a condition.
1890
+ * @param value - The root object or array.
1891
+ * @param path - The path string or array.
1892
+ * @param newValue - The value to set.
1893
+ * @param cache - Optional cache for parsed paths.
1894
+ * @param options - Optional settings for cloning and condition.
1895
+ * @returns The set result, including root and previous value.
1896
+ * @category Utilities
1897
+ */
1898
+ export declare function set(value: unknown, path: string | Path, newValue: unknown, cache?: Map<string, Path>, options?: {
1899
+ clone?: boolean;
1900
+ condition?: (currentValue: unknown) => boolean;
1901
+ }): SetResult;
1902
+
1903
+ /**
1904
+ * Result type for set operation, including root and previous value.
1905
+ * @category Utilities
1906
+ */
1907
+ export declare type SetResult = undefined | {
1908
+ root: unknown;
1909
+ previousValue?: unknown;
1910
+ };
1911
+
1912
+ /**
1913
+ * Options for setValue: either a boolean (validate) or an options object.
1914
+ * @category Form Management
1915
+ */
1916
+ export declare type SetValueOptions = boolean | SetValueOptionsObject;
1917
+
1918
+ /**
1919
+ * Options object for setValue operations.
1920
+ * @property touch - Whether to mark the field as touched.
1921
+ * @property validate - Whether to validate after setting the value.
1922
+ * @property propagate - Whether to propagate the change to observers.
1923
+ * @category Form Management
1924
+ */
1925
+ export declare type SetValueOptionsObject = {
1926
+ /** Whether to mark the field as touched. */
1927
+ touch?: boolean;
1928
+ /** Whether to validate after setting the value. */
1929
+ validate?: boolean;
1930
+ /** Whether to propagate the change to observers. */
1931
+ propagate?: boolean;
1932
+ };
1933
+
1934
+ /**
1935
+ * Splits a string path into segments, handling dot/bracket/quote notation.
1936
+ * @param path - The path string to split.
1937
+ * @param cache - Optional cache for parsed paths.
1938
+ * @returns The parsed path as an array, or undefined if invalid.
1939
+ * @category Utilities
1940
+ */
1941
+ export declare function splitPath(path: string, cache?: Map<string, Path>): Path | undefined;
1942
+
1943
+ /**
1944
+ * Decorator for applying validation rules to a string field. A required string field can be an empty string, but neither `null` nor `undefined`.
1945
+ * To enforce non-empty strings, use the `min` constraint with a value of 1.
1946
+ *
1947
+ * Example usage:
1948
+ * ```tsx
1949
+ * class Person {
1950
+ * @string({ required: true, min: 1 })
1951
+ * name: string | null = null
1952
+ * }
1953
+ * const form = useForm(Person, ...)
1954
+ *
1955
+ * // the string decorator can also be used as a function to allow standalone validation:
1956
+ * Yop.validate("", string({ required: true, min: 1 })) // error: "Minimum 1 character"
1957
+ * ```
1958
+ * @template Value - The type of the string value.
1959
+ * @template Parent - The type of the parent object.
1960
+ * @param constraints - The string constraints to apply.
1961
+ * @param groups - Optional validation groups.
1962
+ * @returns A field decorator function with validation.
1963
+ * @category Property Decorators
1964
+ */
1965
+ export declare function string<Value extends StringValue, Parent>(constraints?: StringConstraints<Value, Parent>, groups?: Groups<StringConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
1966
+
1967
+ /**
1968
+ * Interface for string field constraints, combining common, min/max, oneOf, test, and match constraints.
1969
+ * @template Value - The type of the string value.
1970
+ * @template Parent - The type of the parent object.
1971
+ * @property match - Constraint for matching a regular expression.
1972
+ * @see {@link CommonConstraints}
1973
+ * @see {@link MinMaxConstraints}
1974
+ * @see {@link OneOfConstraint}
1975
+ * @see {@link TestConstraint}
1976
+ * @category Property Decorators
1977
+ */
1978
+ export declare interface StringConstraints<Value extends StringValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, number, Parent>, OneOfConstraint<Value, Parent>, TestConstraint<Value, Parent> {
1979
+ /**
1980
+ * Constraint for matching a regular expression. The constraint value can be a RegExp, a function that returns a RegExp.
1981
+ */
1982
+ match?: Constraint<NonNullable<Value>, RegExp, Parent>;
1983
+ }
1984
+
1985
+ /**
1986
+ * @ignore
1987
+ */
1988
+ export declare const stringToLocalDate: (value: unknown) => Date | null;
1989
+
1990
+ /**
1991
+ * Type for a string value, which can be a string, null, or undefined.
1992
+ * @ignore
1993
+ */
1994
+ export declare type StringValue = string | null | undefined;
1995
+
1996
+ /**
1997
+ * Class decorator to add a test constraint function to a class for validation. The test function will be called with the
1998
+ * class instance after all field validations have passed, allowing for complex custom validation logic that depends on
1999
+ * the entire object state.
2000
+ *
2001
+ * Example usage:
2002
+ * ```tsx
2003
+ * @test(credentials => credentials.password === credentials.confirmPassword ? true : "Passwords do not match")
2004
+ * class Credentials {
2005
+ * @string({ required: true, min: 8 })
2006
+ * username: string | null = null
2007
+ * @string({ required: true, min: 8, test: checkPasswordStrength })
2008
+ * password: string | null = null
2009
+ * @string({ required: true, min: 8 })
2010
+ * confirmPassword: string | null = null
2011
+ * }
2012
+ * const form = useForm(Credentials, ...)
2013
+ * ```
2014
+ * @template Class - The constructor type of the class.
2015
+ * @param test - The test constraint function to apply to the class instance.
2016
+ * @returns A class decorator function that sets the test constraint.
2017
+ * @see {@link TestConstraintFunction}
2018
+ * @category Class Decorators
2019
+ */
2020
+ export declare function test<Class extends Constructor>(test: TestConstraintFunction<InstanceType_2<Class>>): (_: Class, context: ClassDecoratorContext<Class>) => void;
2021
+
2022
+ /**
2023
+ * Interface for a test constraint, which can be sync, async, or both.
2024
+ * @template Value - The type of the value being validated.
2025
+ * @template Parent - The type of the parent object.
2026
+ * @property test - The test constraint function or async constraint.
2027
+ * @category Shared Constraints
2028
+ */
2029
+ export declare interface TestConstraint<Value, Parent = unknown> {
2030
+ test?: TestConstraintFunction<Value, Parent> | AsyncTestConstraint<Value, Parent> | readonly [TestConstraintFunction<Value, Parent>, AsyncTestConstraint<Value, Parent>];
2031
+ }
2032
+
2033
+ /**
2034
+ * Type for a test constraint function, which can return a test constraint message or be undefined.
2035
+ * @template Value - The type of the value being validated.
2036
+ * @template Parent - The type of the parent object.
2037
+ * @category Shared Constraints
2038
+ */
2039
+ export declare type TestConstraintFunction<Value, Parent = unknown> = ConstraintFunction<NonNullable<Value>, TestConstraintMessage, Parent>;
2040
+
2041
+ /**
2042
+ * Type for test constraint messages, which can be a simple message, a tuple of message and level, a boolean, or undefined.
2043
+ * @category Shared Constraints
2044
+ */
2045
+ export declare type TestConstraintMessage = ConstraintMessage | readonly [ConstraintMessage, Level] | boolean | undefined;
2046
+
2047
+ /**
2048
+ * Decorator for applying validation rules to a time field. A valid time value must be a string in the format HH:mm[:ss[.sss]] (24-hour clock).
2049
+ *
2050
+ * Example usage:
2051
+ * ```tsx
2052
+ * class Person {
2053
+ * @time({ required: true, formatError: "Invalid wake up time format", max: "18:00" })
2054
+ * wakeUpTime: string | null = null
2055
+ * }
2056
+ * const form = useForm(Person, ...)
2057
+ *
2058
+ * // the time decorator can also be used as a function to allow standalone validation:
2059
+ * Yop.validate("00:00", time({ min: "01:00" })) // error: "Must be after or equal to 01:00"
2060
+ * ```
2061
+ * @template Value - The type of the string value.
2062
+ * @template Parent - The type of the parent object.
2063
+ * @param constraints - The time constraints to apply.
2064
+ * @param groups - Optional validation groups.
2065
+ * @returns A field decorator function with validation.
2066
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats#time_strings
2067
+ * @category Property Decorators
2068
+ */
2069
+ export declare function time<Value extends StringValue, Parent>(constraints?: TimeConstraints<Value, Parent>, groups?: Groups<TimeConstraints<Value, Parent>>): (_: unknown, context: ClassFieldDecoratorContext<Parent, Value>) => void;
2070
+
2071
+ /**
2072
+ * Interface for time field constraints, combining common, min/max, oneOf, and test constraints.
2073
+ * @template Value - The type of the string value.
2074
+ * @template Parent - The type of the parent object.
2075
+ * @property formatError - Optional custom error message for invalid time format.
2076
+ * @see {@link CommonConstraints}
2077
+ * @see {@link MinMaxConstraints}
2078
+ * @see {@link OneOfConstraint}
2079
+ * @see {@link TestConstraint}
2080
+ * @category Property Decorators
2081
+ */
2082
+ export declare interface TimeConstraints<Value extends StringValue, Parent> extends CommonConstraints<Value, Parent>, MinMaxConstraints<Value, string, Parent>, OneOfConstraint<Value, Parent>, TestConstraint<Value, Parent> {
2083
+ /**
2084
+ * Optional custom error message for invalid time format. `formatError` can be a {@link Message} or a function that returns a {@link Message}.
2085
+ * @see {@link timeRegex}
2086
+ */
2087
+ formatError?: Message<Value, Parent>;
2088
+ }
2089
+
2090
+ /**
2091
+ * Regular expression for validating time strings in the format HH:mm[:ss[.sss]].
2092
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats#time_strings
2093
+ * @ignore
2094
+ */
2095
+ export declare const timeRegex: RegExp;
2096
+
2097
+ /**
2098
+ * Converts a time string (HH:mm[:ss[.sss]]) to milliseconds since midnight.
2099
+ * @param time - The time string to convert.
2100
+ * @returns The number of milliseconds since midnight, or undefined if invalid.
2101
+ * @ignore
2102
+ */
2103
+ export declare function timeToMillis(time: string): number | undefined;
2104
+
2105
+ /**
2106
+ * Traverses a class field to retrieve its constraints and value.
2107
+ * @param context - The validation context for the class.
2108
+ * @param constraints - The class constraints.
2109
+ * @param key - The field name or index to traverse.
2110
+ * @param traverseNullish - If true, traverses only if value is not nullish; otherwise, returns undefined for nullish values.
2111
+ * @returns A tuple of the field constraints (if any) and the value at the given key.
2112
+ * @ignore
2113
+ */
2114
+ export declare function traverseClass(context: InternalValidationContext<unknown>, constraints: InternalClassConstraints, key: string | number, traverseNullish?: boolean): readonly [InternalCommonConstraints | undefined, any];
2115
+
2116
+ /**
2117
+ * Type for a function that traverses nested constraints and values.
2118
+ * @ignore
2119
+ */
2120
+ export declare type Traverser<Constraints, Value = ContraintsValue<Constraints>, Parent = ContraintsParent<Constraints>> = ((context: InternalValidationContext<Value, Parent>, constraints: Constraints, propertyOrIndex: string | number, traverseNullish?: boolean) => readonly [InternalCommonConstraints | undefined, InternalValidationContext<unknown>]);
2121
+
2122
+ /**
2123
+ * @ignore
2124
+ */
2125
+ export declare const UndefinedParent: any;
2126
+
2127
+ /**
2128
+ * Type for resolved constraints with an editable field metadata. *Warning*: the `fieldMetadata` property is mutable and should be used with
2129
+ * caution, as modifying it can lead to unexpected behavior in validation logic. It is intended for advanced use cases where access to the
2130
+ * original constraints is necessary, but it should not be modified during normal validation operations.
2131
+ * @template MinMax - The type for min/max values.
2132
+ * @category Validation Management
2133
+ */
2134
+ export declare type UnsafeResolvedConstraints<MinMax = unknown> = ResolvedConstraints<MinMax> & {
2135
+ fieldMetadata?: CommonConstraints<any, any> | undefined;
2136
+ };
2137
+
2138
+ /**
2139
+ * Removes a value from an object or array at a given path.
2140
+ * @param value - The root object or array.
2141
+ * @param path - The path string or array.
2142
+ * @param cache - Optional cache for parsed paths.
2143
+ * @returns True if unset, false otherwise.
2144
+ * @category Utilities
2145
+ */
2146
+ export declare function unset(value: unknown, path: string | Path, cache?: Map<string, Path>): boolean | undefined;
2147
+
2148
+ /**
2149
+ * ## First overload signature
2150
+ *
2151
+ * React hook to create and manage a form with all configuration options available in {@link FormConfig}. This overload allows for the most flexible
2152
+ * usage of the `useForm` hook, with full control over initial values, validation schema, submission logic, and more.
2153
+ *
2154
+ * However, it doesn't register automatically observers listeners, and you need to use the {@link useObservers} hook manually to register observers on
2155
+ * the form manager instance, as shown in the example below.
2156
+ *
2157
+ * Example usage:
2158
+ * ```tsx
2159
+ * const form = useForm({
2160
+ * initialValues: new Person(),
2161
+ * validationSchema: instance({ of: Person, required: true }),
2162
+ * onSubmit: (form) => {
2163
+ * console.log("Form submitted with values:", form.values)
2164
+ * form.setSubmitting(false)
2165
+ * }
2166
+ * })
2167
+ * // Optional, if observers are used in the form:
2168
+ * useObservers(Person, form)
2169
+ * ```
2170
+ * @overload@overload
2171
+ * @template T - The type of the form values.
2172
+ * @param config - The form configuration object.
2173
+ * @param deps - Optional dependency list for memoization of the form manager.
2174
+ * @returns The form manager instance.
2175
+ * @category Form Management
2176
+ */
2177
+ export declare function useForm<T extends object | null | undefined>(config: FormConfig<T>, deps?: React.DependencyList): FormManager<T>;
2178
+
2179
+ /**
2180
+ * ## Second overload signature
2181
+ *
2182
+ * React hook to create and manage a form with validation, and automatic observer support. This overload allows for a simpler syntax. The initial values
2183
+ * will be created by instantiating the provided model class, and the validation schema will be automatically generated using the `instance` decorator with
2184
+ * the provided model class and `required: true`.
2185
+ *
2186
+ * There is no need to use {@link useObservers} here, observers will be automatically registered on the form manager instance
2187
+ * for the provided model class. The code example below is strictly equivalent to the one in the other overload signature,
2188
+ * but with a simpler syntax.
2189
+ *
2190
+ * Example usage:
2191
+ * ```tsx
2192
+ * const form = useForm(Person, (form) => {
2193
+ * console.log("Form submitted with values:", form.values)
2194
+ * form.setSubmitting(false)
2195
+ * })
2196
+ * ```
2197
+ *
2198
+ * @overload@overload
2199
+ * @template T - The type of the form values.
2200
+ * @param model - The model class constructor.
2201
+ * @param onSubmit - Callback for form submission.
2202
+ * @param deps - Optional dependency list for memoization of the form manager.
2203
+ * @returns The form manager instance.
2204
+ * @category Form Management
2205
+ */
2206
+ export declare function useForm<T extends object | null | undefined>(model: Model<T>, onSubmit: (form: FormManager<T>) => void, deps?: React.DependencyList): FormManager<T>;
2207
+
2208
+ /**
2209
+ * React hook to access the current {@link FormManager} from context. This hook should be used within a component that is a descendant of a {@link Form} component,
2210
+ * which provides the FormManager via context. The generic type parameter `T` can be used to specify the type of the form values managed by the FormManager,
2211
+ * allowing for type-safe access to form values.
2212
+ *
2213
+ * Example usage:
2214
+ * ```tsx
2215
+ * function MyFormComponent() {
2216
+ * const form = useFormContext<MyFormValues>()
2217
+ * // use form to access values, statuses, etc.
2218
+ * }
2219
+ *
2220
+ * const form = useForm(MyFormModel, onSubmit)
2221
+ * return (
2222
+ * <Form form={form} autoComplete="off" noValidate disabled={form.submitting}>
2223
+ * <MyFormComponent />
2224
+ * </Form>
2225
+ * )
2226
+ * ```
2227
+ *
2228
+ * @template T - The type of the form values managed by the FormManager.
2229
+ * @returns The {@link FormManager} instance from context.
2230
+ * @category Form Management
2231
+ */
2232
+ export declare function useFormContext<T = unknown>(): FormManager<T>;
2233
+
2234
+ /**
2235
+ * React hook to access and manage the state of a form field, including value, validation status, and constraints.
2236
+ * Handles async validation and triggers re-renders as needed.
2237
+ *
2238
+ * Example usage:
2239
+ * ```tsx
2240
+ * function MyTextField(props: { path: string }) {
2241
+ * const { constraints, status, value, form } = useFormField<string, number>(props.path)
2242
+ * // render input with value, display validation status, etc.
2243
+ * }
2244
+ * ```
2245
+ *
2246
+ * @template Value - The type of the field value.
2247
+ * @template MinMax - The type for min/max constraints.
2248
+ * @template Root - The type of the root form values.
2249
+ * @param name - The field name or path.
2250
+ * @param unsafeMetadata - Whether to use unsafe metadata for constraints.
2251
+ * @returns The current state of the field. See {@link FieldState} for details.
2252
+ * @category Form Management
2253
+ */
2254
+ export declare function useFormField<Value, MinMax, Root = any>(name: string, unsafeMetadata?: boolean): FieldState<Value, MinMax, Root>;
2255
+
2256
+ /**
2257
+ * React hook to register reform event listeners for {@link observer}s on a model. This hook scans the provided model class for any observer metadata
2258
+ * and registers a single event listener on the form manager instance that will trigger the appropriate observer callbacks when relevant fields
2259
+ * are updated.
2260
+ *
2261
+ * There is no need to use this hook if you are using the {@link useForm} hook with a model class, as observers will be automatically registered on
2262
+ * the form manager instance.
2263
+ *
2264
+ * Example usage:
2265
+ * ```tsx
2266
+ * const form = useForm({
2267
+ * initialValues: new MyFormModel(),
2268
+ * validationSchema: instance({ of: MyFormModel }),
2269
+ * onSubmit: (form) => { ... }
2270
+ * })
2271
+ * useObservers(MyFormModel, form)
2272
+ * ```
2273
+ *
2274
+ * @template T
2275
+ * @param model - The class constructor to scan for observers.
2276
+ * @param form - The form manager instance holding the values to observe.
2277
+ * @category Observers
2278
+ */
2279
+ export declare function useObservers<T extends object>(model: ClassConstructor<T> | null | undefined, form: FormManager<unknown>): void;
2280
+
2281
+ /**
2282
+ * React hook that returns a function to force a component re-render.
2283
+ * Useful for triggering updates in custom hooks or non-stateful logic.
2284
+ *
2285
+ * @returns A function that, when called, forces the component to re-render.
2286
+ * @category Form Management
2287
+ */
2288
+ export declare function useRender(): () => void;
2289
+
2290
+ /**
2291
+ * Validates a class object against its constraints, including all fields and test constraints.
2292
+ * @param context - The validation context for the class object.
2293
+ * @param constraints - The class constraints to validate.
2294
+ * @returns True if all constraints pass, false otherwise.
2295
+ * @ignore
2296
+ */
2297
+ export declare function validateClass(context: InternalValidationContext<{
2298
+ [x: string]: any;
2299
+ }>, constraints: InternalClassConstraints): boolean;
2300
+
2301
+ /**
2302
+ * Validates the common constraints (defined, notnull, required) for a value.
2303
+ * @template Value - The type of the value being validated.
2304
+ * @template Parent - The type of the parent object.
2305
+ * @param context - The validation context.
2306
+ * @param constraints - The constraints to validate.
2307
+ * @returns True if all constraints pass, false otherwise.
2308
+ * @ignore
2309
+ */
2310
+ export declare function validateCommonConstraints<Value, Parent>(context: InternalValidationContext<Value, Parent>, constraints: CommonConstraints<Value, Parent>): boolean;
2311
+
2312
+ /**
2313
+ * Validates a constraint for a given context and constraint definition.
2314
+ * Handles group-based constraints and default values/messages.
2315
+ *
2316
+ * @template Value - The type of the value being validated.
2317
+ * @template ConstraintType - The type of the constraint value.
2318
+ * @template Parent - The type of the parent object.
2319
+ * @template Constraints - The type of the constraints object.
2320
+ * @param context - The validation context.
2321
+ * @param constraints - The constraints object.
2322
+ * @param name - The name of the constraint to validate.
2323
+ * @param isConstraintType - Type guard for the constraint value.
2324
+ * @param validate - Function to validate the value against the constraint.
2325
+ * @param defaultConstraint - Optional default constraint value.
2326
+ * @param defaultMessage - Optional default error message.
2327
+ * @param setStatus - Whether to set the status on failure (default: true).
2328
+ * @returns True if the constraint passes, false otherwise.
2329
+ * @ignore
2330
+ */
2331
+ export declare function validateConstraint<Value, ConstraintType, Parent, Constraints = {
2332
+ [name: string]: Constraint<Value, ConstraintType, Parent>;
2333
+ }>(context: InternalValidationContext<Value, Parent>, constraints: Constraints, name: keyof Constraints, isConstraintType: (value: any) => value is ConstraintType, validate: (value: Value, constraintValue: NonNullable<ConstraintType>) => boolean, defaultConstraint?: ConstraintType, defaultMessage?: Message<Value, Parent>, setStatus?: boolean): boolean;
2334
+
2335
+ /**
2336
+ * Validates an email field against its constraints and the email regex.
2337
+ * @template Value - The type of the string value.
2338
+ * @template Parent - The type of the parent object.
2339
+ * @param context - The validation context.
2340
+ * @param constraints - The email constraints to validate.
2341
+ * @returns True if the value is a valid email, false otherwise.
2342
+ * @ignore
2343
+ */
2344
+ export declare function validateEmail<Value extends StringValue, Parent>(context: InternalValidationContext<Value, Parent>, constraints: EmailConstraints<Value, Parent>): boolean;
2345
+
2346
+ /**
2347
+ * Validates min and max constraints for a value.
2348
+ * @template Value - The type of the value being validated.
2349
+ * @template MinMax - The type for min/max values.
2350
+ * @template Parent - The type of the parent object.
2351
+ * @param context - The validation context.
2352
+ * @param constraints - The min/max constraints to validate.
2353
+ * @param isConstraintValue - Type guard for min/max values.
2354
+ * @param validateMin - Function to validate the min constraint.
2355
+ * @param validateMax - Function to validate the max constraint.
2356
+ * @returns True if both min and max constraints pass, false otherwise.
2357
+ * @ignore
2358
+ */
2359
+ export declare function validateMinMaxConstraints<Value, MinMax, Parent>(context: InternalValidationContext<Value, Parent>, constraints: MinMaxConstraints<Value, MinMax, Parent>, isConstraintValue: (value: any) => value is MinMax, validateMin: (value: NonNullable<Value>, min: NonNullable<MinMax>) => boolean, validateMax: (value: NonNullable<Value>, max: NonNullable<MinMax>) => boolean): boolean;
2360
+
2361
+ /**
2362
+ * Validates the oneOf constraint for a value.
2363
+ * @template Value - The type of the value being validated.
2364
+ * @template OneOfType - The type for the allowed values array.
2365
+ * @template Parent - The type of the parent object.
2366
+ * @param context - The validation context.
2367
+ * @param constraints - The oneOf constraint to validate.
2368
+ * @param isConstraintValue - Type guard for the allowed values array.
2369
+ * @param equals - Optional equality function for comparing values.
2370
+ * @returns True if the value is one of the allowed values, false otherwise.
2371
+ * @ignore
2372
+ */
2373
+ export declare function validateOneOfConstraint<Value, OneOfType extends NoInfer<NonNullable<Value>>[], Parent>(context: InternalValidationContext<Value, Parent>, constraints: OneOfConstraint<Value, Parent>, isConstraintValue: (value: any) => value is OneOfType, equals?: (value1: NonNullable<Value>, value2: NonNullable<Value>) => boolean): boolean;
2374
+
2375
+ /**
2376
+ * Validates a string field against its constraints.
2377
+ * @template Value - The type of the string value.
2378
+ * @template Parent - The type of the parent object.
2379
+ * @param context - The validation context.
2380
+ * @param constraints - The string constraints to validate.
2381
+ * @param defaultRegexp - Optional default regular expression for matching.
2382
+ * @param defaultMatchMessage - Optional default error message for match failures.
2383
+ * @param type - Optional type name for error reporting.
2384
+ * @returns True if all constraints pass, false otherwise.
2385
+ * @ignore
2386
+ */
2387
+ export declare function validateString<Value extends StringValue, Parent>(context: InternalValidationContext<Value, Parent>, constraints: StringConstraints<Value, Parent>, defaultRegexp?: RegExp, defaultMatchMessage?: Message<Value, Parent>, type?: string): boolean;
2388
+
2389
+ /**
2390
+ * Validates a test constraint for a value, handling sync and async cases.
2391
+ * @template Value - The type of the value being validated.
2392
+ * @template Parent - The type of the parent object.
2393
+ * @param context - The validation context.
2394
+ * @param testConstraint - The test constraint to validate.
2395
+ * @returns True if the constraint passes, false otherwise.
2396
+ * @ignore
2397
+ */
2398
+ export declare function validateTestConstraint<Value, Parent>(context: InternalValidationContext<Value, Parent>, testConstraint: TestConstraint<Value, Parent>): boolean;
2399
+
2400
+ /**
2401
+ * Validates a time field against its constraints.
2402
+ * @template Value - The type of the string value.
2403
+ * @template Parent - The type of the parent object.
2404
+ * @param context - The validation context.
2405
+ * @param constraints - The time constraints to validate.
2406
+ * @returns True if all constraints pass, false otherwise.
2407
+ * @ignore
2408
+ */
2409
+ export declare function validateTime<Value extends StringValue, Parent>(context: InternalValidationContext<Value, Parent>, constraints: TimeConstraints<Value, Parent>): boolean;
2410
+
2411
+ /**
2412
+ * Validates the type of a value using a provided type check function.
2413
+ * @param context - The validation context.
2414
+ * @param checkType - Function to check the value's type.
2415
+ * @param expectedType - The expected type as a string.
2416
+ * @returns True if the value matches the expected type, false otherwise.
2417
+ * @ignore
2418
+ */
2419
+ export declare function validateTypeConstraint(context: InternalValidationContext<any>, checkType: (value: any) => boolean, expectedType: string): boolean;
2420
+
2421
+ /**
2422
+ * Interface representing the context of a validation operation, providing access to the value being validated, its path,
2423
+ * parent context, root context, settings, form, and a store for sharing data across validations.
2424
+ *
2425
+ * @template Value - The type of the value being validated.
2426
+ * @template Parent - The type of the parent object containing the value.
2427
+ * @category Validation Management
2428
+ */
2429
+ export declare interface ValidationContext<Value, Parent = unknown> {
2430
+ readonly kind: string;
2431
+ readonly value: Value;
2432
+ readonly path: Path;
2433
+ readonly parent: Parent;
2434
+ readonly parentContext: ValidationContext<Parent> | undefined;
2435
+ getRoot<T>(): T | undefined;
2436
+ readonly rootContext: ValidationContext<unknown> | undefined;
2437
+ readonly settings: ValidationSettings | undefined;
2438
+ readonly form: ValidationForm | undefined;
2439
+ readonly store: Map<string, any>;
2440
+ }
2441
+
2442
+ /**
2443
+ * Base interface of a form manager, extended by {@link FormManager}, representing form state and operations.
2444
+ * @category Validation Management
2445
+ */
2446
+ export declare interface ValidationForm {
2447
+ /**
2448
+ * Whether the form has been submitted at least once, even if the submission was unsuccessful.
2449
+ */
2450
+ readonly submitted: boolean;
2451
+ /**
2452
+ * Whether the form is currently being submitted.
2453
+ */
2454
+ readonly submitting: boolean;
2455
+ /**
2456
+ * Map of validation statuses for each field.
2457
+ */
2458
+ readonly statuses: Map<string, ValidationStatus>;
2459
+ /**
2460
+ * List of all errors in the form: this includes all validation statuses with a severity level of "error".
2461
+ */
2462
+ readonly errors: ValidationStatus[];
2463
+ /**
2464
+ * A map that can be used to store arbitrary data related to the form.
2465
+ */
2466
+ readonly store: Map<string, any>;
2467
+ /**
2468
+ * The HTML form element associated with this validation form.
2469
+ */
2470
+ readonly htmlForm?: HTMLFormElement;
2471
+ /**
2472
+ * Retrieves the value of a field by its path.
2473
+ * @template T - The expected type of the field value.
2474
+ * @param path - The path to the field.
2475
+ * @returns The value of the field, or undefined if not found.
2476
+ */
2477
+ getValue<T = any>(path: string | Path): T | undefined;
2478
+ /**
2479
+ * Checks if a field has been touched.
2480
+ * @param path - The path to the field.
2481
+ * @returns True if the field has been touched, false otherwise.
2482
+ */
2483
+ isTouched(path?: string | Path): boolean;
2484
+ /**
2485
+ * Marks a field as touched.
2486
+ * @param path - The path to the field.
2487
+ */
2488
+ touch(path?: string | Path): void;
2489
+ /**
2490
+ * Marks a field as untouched.
2491
+ * @param path - The path to the field.
2492
+ */
2493
+ untouch(path?: string | Path): void;
2494
+ /**
2495
+ * Checks if a field is dirty (has been modified). If no path is provided, checks if any field in the entire form is dirty.
2496
+ * @param path - The path to the field.
2497
+ * @param ignoredPath - Optional path to ignore during the check.
2498
+ * @returns True if the field is dirty, false otherwise.
2499
+ */
2500
+ isDirty(path?: string | Path, ignoredPath?: string | Path): boolean;
2501
+ }
2502
+
2503
+ /**
2504
+ * Interface for validation settings, including path, groups, and options.
2505
+ * @category Validation Management
2506
+ */
2507
+ export declare interface ValidationSettings {
2508
+ /**
2509
+ * The path to the field or object being validated. This can be a string with dot notation (e.g., "address.street") or
2510
+ * an array of path segments (e.g., ["address", "street"]). If omitted, the validation will be performed on the root value.
2511
+ */
2512
+ path?: string | Path;
2513
+ /**
2514
+ * Validation groups to apply during validation. This can be a single group or an array of groups. If specified, only the
2515
+ * constraints associated with at least one of the active groups will be validated.
2516
+ */
2517
+ groups?: Group;
2518
+ /**
2519
+ * Function to determine if a path should be ignored during validation.
2520
+ */
2521
+ ignore?: (path: Path) => boolean;
2522
+ /**
2523
+ * Whether to skip asynchronous validation.
2524
+ */
2525
+ skipAsync?: boolean;
2526
+ /**
2527
+ * The validation form associated with this validation context. This form is set by the form manager when performing form-level validation
2528
+ * and can be used to access form state and operations during validation.
2529
+ */
2530
+ form?: ValidationForm;
2531
+ }
2532
+
2533
+ /**
2534
+ * Interface representing the status of a validation, including its level, path, value, kind, code, constraint, and message.
2535
+ * This is used to track the results of validation operations and provide feedback to the user.
2536
+ * @category Validation Management
2537
+ */
2538
+ export declare type ValidationStatus = {
2539
+ /**
2540
+ * The severity level of the validation status, or the status of asynchronous validation.
2541
+ * @see {@link Level}
2542
+ */
2543
+ level: Level;
2544
+ /**
2545
+ * The path to the validated value, represented as a string (e.g., "users[0].address.street").
2546
+ */
2547
+ path: string;
2548
+ /**
2549
+ * The value that was validated.
2550
+ */
2551
+ value: any;
2552
+ /**
2553
+ * The kind of validation (e.g., "string", "number", "array"), used for message resolution.
2554
+ */
2555
+ kind: string;
2556
+ /**
2557
+ * A code representing the specific validation type (e.g., "required", "min"), used for message resolution.
2558
+ */
2559
+ code: string;
2560
+ /**
2561
+ * The constraint value that caused the validation error (e.g., `true` for a "required" constraint, `1` for a "min" constraint).
2562
+ */
2563
+ constraint: any;
2564
+ /**
2565
+ * The resolved message for this validation status, which can be displayed to the user.
2566
+ */
2567
+ message: ConstraintMessage;
2568
+ };
2569
+
2570
+ /**
2571
+ * Symbol used to store validation metadata on class fields. This symbol is used as a key to attach validation constraints and related
2572
+ * information to class properties.
2573
+ * @ignore
2574
+ */
2575
+ export declare const validationSymbol: unique symbol;
2576
+
2577
+ /**
2578
+ * Type for a validation function for a set of constraints.
2579
+ * @ignore
2580
+ */
2581
+ export declare type Validator<Constraints, Value = ContraintsValue<Constraints>, Parent = ContraintsParent<Constraints>> = (context: InternalValidationContext<Value, Parent>, constraints: Constraints) => boolean;
2582
+
2583
+ /**
2584
+ * @ignore
2585
+ */
2586
+ export declare type ValuedContext<Value, Parent> = InternalValidationContext<NonNullable<Value>, Parent>;
2587
+
2588
+ /**
2589
+ * Main class for validation logic, constraint resolution, and message provider management.
2590
+ * @category Validation Management
2591
+ */
2592
+ export declare class Yop {
2593
+ private static defaultInstance?;
2594
+ private static classIds;
2595
+ private static messageProviders;
2596
+ private locale;
2597
+ private _store;
2598
+ private _asyncStatuses;
2599
+ /**
2600
+ * Gets the store map, which can be used to store arbitrary data related to validation operations. This allows sharing data across different
2601
+ * validation contexts and operations.
2602
+ */
2603
+ get store(): Map<string, any>;
2604
+ /**
2605
+ * Gets the map of asynchronous validation statuses, where each key is a path and the value is the corresponding asynchronous validation status.
2606
+ */
2607
+ get asyncStatuses(): Map<string, AsyncValidationStatus>;
2608
+ /**
2609
+ * Registers a class constructor with a given ID.
2610
+ * @param id The ID to associate with the class constructor.
2611
+ * @param constructor The class constructor to register.
2612
+ * @ignore
2613
+ */
2614
+ static registerClass(id: string, constructor: Constructor<unknown>): void;
2615
+ /**
2616
+ * Resolves a class constructor by its ID.
2617
+ * @param id The ID of the class or a function reference.
2618
+ * @param silent If true, suppresses error messages for unregistered classes.
2619
+ * @returns The resolved class constructor, or undefined if not found.
2620
+ * @ignore
2621
+ */
2622
+ static resolveClass<T>(id: unknown, silent?: boolean): Constructor<T> | undefined;
2623
+ private contextAt;
2624
+ /**
2625
+ * Retrieves the constraints for a given class field decorator and value, using the provided settings.
2626
+ * @param decorator The class field decorator defining the constraints.
2627
+ * @param value The value to be validated against the constraints.
2628
+ * @param settings Optional settings for constraint resolution, including path and unsafe metadata flag.
2629
+ * @returns The resolved constraints, or undefined if no constraints are found.
2630
+ */
2631
+ constraintsAt<MinMax = unknown>(decorator: ClassFieldDecorator<any>, value: any, settings?: ConstraintsAtSettings): ResolvedConstraints<MinMax> | undefined;
2632
+ /**
2633
+ * Static version of the constraintsAt method, which initializes the Yop instance and retrieves the constraints for a given class field decorator and value.
2634
+ * @param decorator The class field decorator defining the constraints.
2635
+ * @param value The value to be validated against the constraints.
2636
+ * @param settings Optional settings for constraint resolution, including path and unsafe metadata flag.
2637
+ * @returns The resolved constraints, or undefined if no constraints are found.
2638
+ */
2639
+ static constraintsAt<Value>(decorator: ClassFieldDecorator<Value>, value: any, settings?: ConstraintsAtSettings): ResolvedConstraints<unknown> | undefined;
2640
+ /**
2641
+ * Retrieves the asynchronous validation status for a given path. The path can be a string or an array of path segments.
2642
+ * @param path The path for which to retrieve the asynchronous validation status.
2643
+ * @returns The asynchronous validation status, or undefined if not found.
2644
+ */
2645
+ getAsyncStatus(path: string | Path): ValidationStatus | undefined;
2646
+ /**
2647
+ * Validates a value against the constraints defined by a class field decorator, using the provided validation settings. This method performs
2648
+ * the validation logic and returns the validation context, which includes the results of the validation operation. The context contains
2649
+ * information about the value, its path, any validation statuses.
2650
+ * @param value The value to be validated.
2651
+ * @param decorator The decorator defining the validation constraints.
2652
+ * @param settings The validation settings, including the path and other options.
2653
+ * @returns The validation context after performing the validation.
2654
+ * @ignore
2655
+ */
2656
+ rawValidate<Value>(value: any, decorator: ClassFieldDecorator<Value>, settings?: ValidationSettings): InternalValidationContext<any, unknown> | undefined;
2657
+ /**
2658
+ * Validates a value against the constraints defined by a class field decorator, using the provided validation settings. This method performs
2659
+ * the validation logic and returns the validation statuses array.
2660
+ * @param value The value to be validated.
2661
+ * @param decorator The decorator defining the validation constraints.
2662
+ * @param settings The validation settings, including the path and other options.
2663
+ * @returns An array of validation statuses after performing the validation.
2664
+ */
2665
+ validate<Value>(value: any, decorator: ClassFieldDecorator<Value>, settings?: ValidationSettings): ValidationStatus[];
2666
+ /**
2667
+ * Static version of the validate method, which initializes the Yop instance and performs validation on the provided value using the specified
2668
+ * decorator and settings.
2669
+ * @param value The value to be validated.
2670
+ * @param decorator The decorator defining the validation constraints.
2671
+ * @param settings The validation settings, including the path and other options.
2672
+ * @returns An array of validation statuses after performing the validation.
2673
+ * @see {@link Yop#validate}
2674
+ */
2675
+ static validate<Value>(value: any, decorator: ClassFieldDecorator<Value>, settings?: ValidationSettings): ValidationStatus[];
2676
+ /**
2677
+ * Registers a message provider for a specific locale. The message provider is used to retrieve localized validation messages
2678
+ * based on the current locale setting.
2679
+ * @param provider The message provider to register.
2680
+ */
2681
+ static registerMessageProvider(provider: MessageProvider): void;
2682
+ /**
2683
+ * Gets the current locale used for message resolution. This locale determines which message provider is used to retrieve validation messages.
2684
+ * @returns The current locale as a string.
2685
+ */
2686
+ getLocale(): string;
2687
+ /**
2688
+ * Static version of the getLocale method, which initializes the Yop instance and retrieves the current locale.
2689
+ * @returns The current locale as a string.
2690
+ * @see {@link Yop#getLocale}
2691
+ */
2692
+ static getLocale(): string;
2693
+ /**
2694
+ * Sets the current locale used for message resolution. This locale determines which message provider is used to retrieve validation messages.
2695
+ * @param locale The locale to set. This should be a valid BCP 47 language tag (e.g., "en-US", "fr-FR").
2696
+ */
2697
+ setLocale(locale: string): void;
2698
+ /**
2699
+ * Static version of the setLocale method, which initializes the Yop instance and sets the current locale.
2700
+ * @param locale The locale to set. This should be a valid BCP 47 language tag (e.g., "en-US", "fr-FR").
2701
+ * @see {@link Yop#setLocale}
2702
+ */
2703
+ static setLocale(locale: string): void;
2704
+ /**
2705
+ * Gets the message provider for the current locale. This message provider is used to retrieve localized validation messages based on the current locale setting.
2706
+ */
2707
+ get messageProvider(): MessageProvider;
2708
+ /**
2709
+ * Initializes the Yop instance if it hasn't been initialized yet and returns the default instance.
2710
+ * @returns The default Yop instance.
2711
+ */
2712
+ static init(): Yop;
2713
+ }
2714
+
2715
+ export { }