@regle/core 1.17.1 → 1.17.3

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @regle/core v1.17.1
2
+ * @regle/core v1.17.3
3
3
  * (c) 2026 Victor Garcia
4
4
  * @license MIT
5
5
  */
@@ -15,403 +15,6 @@ type RegleStaticImpl<T> = Raw<T & {
15
15
  type IsRegleStatic<T> = T extends RegleStaticImpl<T> ? true : false;
16
16
  type UnwrapStatic<T> = IsUnknown<T> extends true ? any : NonNullable<T> extends RegleStaticImpl<infer U> ? Raw<U> : UnwrapStaticSimple<T>;
17
17
  type UnwrapStaticSimple<T> = NonNullable<T> extends Array<infer U> ? Array<UnwrapStatic<U>> : isRecordLiteral<NonNullable<T>> extends true ? { [K in keyof T]: UnwrapStatic<T[K]> } : T;
18
- type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
19
- type Maybe<T = any> = T | null | undefined;
20
- type MaybeInput<T = any> = T | null | undefined;
21
- type MaybeOutput<T = any> = T | undefined;
22
- type MaybeReadonly<T> = T | Readonly<T>;
23
- type NonUndefined<T> = Exclude<T, undefined>;
24
- type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
25
- type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
26
- type Unwrap<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
27
- type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends Ref ? UnwrapRef<T> : T extends ((...args: any[]) => infer U) ? U : T;
28
- type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
29
- type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
30
- type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
31
- type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
32
- type ExcludeByType<T, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] extends U$1 ? never : T[K] };
33
- type PrimitiveTypes = string | number | boolean | bigint | Date | File;
34
- type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
35
- type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
36
- /**
37
- * Extract the element type from an array.
38
- *
39
- * @example
40
- * ```ts
41
- * type Element = ArrayElement<[1, 2, 3]>; // number
42
- * ```
43
- */
44
- type ArrayElement<T> = T extends Array<infer U> ? U : never;
45
- /**
46
- * Declares a tuple that must have at least one element
47
- */
48
- type NonEmptyTuple<T> = [T, ...T[]] | T[];
49
- interface inferRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>> {
50
- <TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<DefaultValidatorsTree> & TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<DefaultValidatorsTree> & TCustomRules>>(state: MaybeRef<TState$1> | DeepReactiveState<TState$1> | undefined, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? TDecl : TState$1 extends Record<string, any> ? TRules$1 : {}): NonNullable<TState$1> extends PrimitiveTypes ? TDecl : TRules$1;
51
- }
52
- /**
53
- * Type helper to provide autocomplete and type-checking for your form rules.
54
- * It returns the rules without any processing - useful with computed rules.
55
- *
56
- * @param state - The state reference
57
- * @param rules - Your rule tree
58
- * @returns The rules object (passthrough)
59
- *
60
- * @example
61
- * ```ts
62
- * import { inferRules, useRegle } from '@regle/core';
63
- * import { required, minLength } from '@regle/rules';
64
- *
65
- * const state = ref({ name: '' });
66
- *
67
- * // inferRules preserves TypeScript autocompletion
68
- * const rules = computed(() => {
69
- * return inferRules(state, {
70
- * name: { required, minLength: minLength(2) }
71
- * })
72
- * });
73
- *
74
- * const { r$ } = useRegle(state, rules);
75
- * ```
76
- *
77
- * @see {@link https://reglejs.dev/core-concepts/#dynamic-rules-object Documentation}
78
- */
79
- declare const inferRules: inferRulesFn<Partial<ExtendedRulesDeclarations>>;
80
- interface GlobalConfigOptions<TCustomRules extends Partial<ExtendedRulesDeclarations> = CustomRulesDeclarationTree, TShortcuts extends RegleShortcutDefinition<any> = never> {
81
- /**
82
- * Declare custom rules to be used globally or override the default rules messages.
83
- *
84
- * Ex:
85
- * ```ts
86
- * import { defineRegleConfig } from '@regle/core';
87
- * import { required, withMessage } from '@regle/rules';
88
- *
89
- * export const { useRegle, inferRules, useRules } = defineRegleConfig({
90
- * rules: () => ({
91
- * required: withMessage(required, 'This field cannot be empty'),
92
- * }),
93
- * });
94
- * ```
95
- * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
96
- */
97
- rules?: () => TCustomRules;
98
- /**
99
- * Define modifiers to be used globally.
100
- *
101
- * Ex:
102
- * ```ts
103
- * import { defineRegleConfig } from '@regle/core';
104
- *
105
- * export const { useRegle, inferRules, useRules } = defineRegleConfig({
106
- * modifiers: {
107
- * lazy: true,
108
- * rewardEarly: true
109
- * }
110
- * });
111
- * ```
112
- * @see {@link https://reglejs.dev/advanced-usage/global-config#declare-modifiers Documentation}
113
- */
114
- modifiers?: RegleBehaviourOptions;
115
- /**
116
- * Define reusable validation shortcuts to be used globally.
117
- *
118
- * Ex:
119
- * ```ts
120
- * import { defineRegleConfig } from '@regle/core';
121
- *
122
- * export const { useRegle, inferRules, useRules } = defineRegleConfig({
123
- * shortcuts: {
124
- * fields: {
125
- * $isRequired: (field) => field.$rules.required?.$active ?? false,
126
- * },
127
- * },
128
- * });
129
- * ```
130
- * @see {@link https://reglejs.dev/advanced-usage/extend-properties#extend-properties Documentation}
131
- */
132
- shortcuts?: TShortcuts;
133
- /** Override default behaviors of Regle processors. */
134
- overrides?: GlobalConfigOverrides<unknown>;
135
- }
136
- /**
137
- * Define a global Regle configuration to customize the validation behavior across your application.
138
- *
139
- * Features:
140
- * - Customize built-in rules messages
141
- * - Add your custom rules with full type inference
142
- * - Define global modifiers (lazy, rewardEarly, etc.)
143
- * - Define shortcuts for common validation patterns
144
- *
145
- * @param options - Configuration options
146
- * @returns Object containing typed `useRegle`, `inferRules`, and `useRules` functions
147
- *
148
- * @example
149
- * ```ts
150
- * import { defineRegleConfig } from '@regle/core';
151
- * import { required, withMessage } from '@regle/rules';
152
- *
153
- * export const { useRegle, inferRules, useRules } = defineRegleConfig({
154
- * rules: () => ({
155
- * // Override default required message
156
- * required: withMessage(required, 'This field cannot be empty'),
157
- * // Add custom rule
158
- * myCustomRule: createRule({
159
- * validator: (value) => value === 'valid',
160
- * message: 'Invalid value'
161
- * })
162
- * }),
163
- * modifiers: {
164
- * lazy: true,
165
- * rewardEarly: true
166
- * }
167
- * });
168
- * ```
169
- *
170
- * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
171
- */
172
- declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<ExtendedRulesDeclarations>>({
173
- rules,
174
- modifiers,
175
- shortcuts,
176
- overrides
177
- }: GlobalConfigOptions<TCustomRules, TShortcuts>): {
178
- useRegle: useRegleFn<TCustomRules, TShortcuts>;
179
- inferRules: inferRulesFn<TCustomRules>;
180
- useRules: useRulesFn<TCustomRules, TShortcuts>;
181
- };
182
- /**
183
- * Extend an already created custom `useRegle` configuration with additional rules, modifiers, or shortcuts.
184
- *
185
- * @param regle - The existing useRegle function to extend
186
- * @param options - Additional configuration to merge
187
- * @param options.rules - Additional custom rules
188
- * @param options.modifiers - Additional modifiers to merge
189
- * @param options.shortcuts - Additional shortcuts to merge
190
- * @returns Object containing the extended `useRegle` and `inferRules` functions
191
- *
192
- * @example
193
- * ```ts
194
- * import { extendRegleConfig } from '@regle/core';
195
- * import { baseUseRegle } from './base-config';
196
- *
197
- * export const { useRegle, inferRules } = extendRegleConfig(baseUseRegle, {
198
- * rules: () => ({
199
- * additionalRule: myNewRule
200
- * }),
201
- * modifiers: {
202
- * rewardEarly: true
203
- * }
204
- * });
205
- * ```
206
- *
207
- * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
208
- */
209
- declare function extendRegleConfig<TRootCustomRules extends Partial<ExtendedRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<ExtendedRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
210
- rules,
211
- modifiers,
212
- shortcuts,
213
- overrides
214
- }: GlobalConfigOptions<TCustomRules, TShortcuts>): {
215
- useRegle: useRegleFn<Merge<TRootCustomRules, TCustomRules>, TRootShortcuts & TShortcuts>;
216
- inferRules: inferRulesFn<Merge<TRootCustomRules, TCustomRules>>;
217
- };
218
- type useRegleFnOptions<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<ExtendedRulesDeclarations>>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState$1 extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups> & TAdditionalOptions;
219
- interface useRegleFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
220
- <TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends DeepExact<TRules$1, ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<MaybeRef<TState$1> | DeepReactiveState<TState$1>>, rulesFactory: TState$1 extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : TState$1 extends Record<string, any> ? MaybeRefOrComputedRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<TState$1, TRules$1, TAdditionalOptions, TValidationGroups>])]): NonNullable<TState$1> extends PrimitiveTypes ? RegleSingleField<NonNullable<TState$1>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
221
- __config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
222
- }
223
- /**
224
- * `useRegle` serves as the foundation for validation logic.
225
- * It transforms your data and validation rules into a powerful, reactive validation system.
226
- *
227
- * @param state - Your form data (plain object, ref, reactive object, or structure with nested refs)
228
- * @param rules - Validation rules that should align with the structure of your state
229
- * @param modifiers - Optional configuration to customize regle behavior
230
- * @returns An object containing `r$` - the reactive validation state
231
- *
232
- * @example
233
- * ```ts
234
- * import { useRegle } from '@regle/core';
235
- * import { required, email, minLength } from '@regle/rules';
236
- *
237
- * const { r$ } = useRegle(
238
- * { name: '', email: '' },
239
- * {
240
- * name: { required, minLength: minLength(2) },
241
- * email: { required, email }
242
- * }
243
- * );
244
- *
245
- * // Access validation state
246
- * r$.$valid // Whether all validations pass
247
- * r$.$value // The current form values
248
- * r$.name.$errors // Errors for the name field
249
- *
250
- * // Trigger validation
251
- * const result = await r$.$validate();
252
- * ```
253
- *
254
- * @see {@link https://reglejs.dev/core-concepts/ Documentation}
255
- */
256
- declare const useRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
257
- /**
258
- * @internal
259
- * This is the internal function that creates the root storage for the Regle instance.
260
- * This allows shared logic between all `useRegle` like composables
261
- */
262
- declare function useRootStorage({
263
- initialState,
264
- originalState,
265
- options,
266
- scopeRules,
267
- state,
268
- customRules,
269
- shortcuts,
270
- schemaErrors,
271
- schemaMode,
272
- onValidate,
273
- overrides
274
- }: {
275
- scopeRules: Ref<$InternalReglePartialRuleTree>;
276
- state: Ref<Record<string, any> | PrimitiveTypes>;
277
- options: ResolvedRegleBehaviourOptions;
278
- initialState: Ref<Record<string, any> | PrimitiveTypes>;
279
- originalState: Record<string, any> | PrimitiveTypes;
280
- customRules?: () => CustomRulesDeclarationTree;
281
- shortcuts: RegleShortcutDefinition | undefined;
282
- schemaErrors?: Ref<any | undefined>;
283
- schemaMode?: boolean;
284
- onValidate?: () => Promise<$InternalRegleResult>;
285
- overrides: GlobalConfigOverrides | undefined;
286
- }): {
287
- regle: $InternalRegleStatusType | undefined;
288
- };
289
- /**
290
- * Converts a nested `$errors` object to a flat array of error strings.
291
- * Useful for displaying a complete list of form errors or counting total errors.
292
- *
293
- * With the `includePath` option, returns errors in Standard Schema Issue format
294
- * including the path to each error field.
295
- *
296
- * @param errors - The `$errors` object from a Regle instance (e.g., `r$.$errors`)
297
- * @param options - Configuration options
298
- * @param options.includePath - If true, returns Standard Schema Issues with paths
299
- * @returns Array of error strings, or Standard Schema Issues if `includePath` is true
300
- *
301
- * @example
302
- * ```ts
303
- * import { flatErrors, useRegle } from '@regle/core';
304
- * import { required, email, minLength } from '@regle/rules';
305
- *
306
- * const { r$ } = useRegle(
307
- * { name: '', email: 'invalid' },
308
- * { name: { required, minLength: minLength(3) }, email: { email } }
309
- * );
310
- *
311
- * await r$.$validate();
312
- *
313
- * // Get flat array of error messages
314
- * const errors = flatErrors(r$.$errors);
315
- * // ['This field is required', 'Value must be a valid email address']
316
- *
317
- * // Get errors with paths (Standard Schema format)
318
- * const issues = flatErrors(r$.$errors, { includePath: true });
319
- * // [{ message: 'This field is required', path: ['name'] }, ...]
320
- * ```
321
- *
322
- * @see {@link https://reglejs.dev/core-concepts/displaying-errors#display-flat-errors Documentation}
323
- */
324
- declare function flatErrors(errors: $InternalRegleErrors, options: {
325
- includePath: true;
326
- }): StandardSchemaV1.Issue[];
327
- declare function flatErrors(errors: $InternalRegleErrors, options?: {
328
- includePath?: false;
329
- }): string[];
330
- type useRulesFnOptions<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 = InferInput<TRules$1>> = Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups>;
331
- interface useRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
332
- <TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<ExtendedRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 extends Record<string, any> = InferInput<TRules$1>>(rulesFactory: TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, options?: useRulesFnOptions<TRules$1, TValidationGroups, TState$1>): NonNullable<TState$1> extends PrimitiveTypes ? Raw<RegleFieldStatus<NonNullable<TState$1>, TDecl, TShortcuts>> & StandardSchemaV1<TState$1> : Raw<RegleRoot<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts>> & StandardSchemaV1<TState$1>;
333
- __config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
334
- }
335
- /**
336
- * `useRules` is a variant of `useRegle` that doesn't require you to provide initial state.
337
- * It creates an empty state based on your rules structure and implements the Standard Schema spec.
338
- *
339
- * This is useful when you want to define validation rules first and infer the state type from them.
340
- *
341
- * @param rules - Your validation rules object
342
- * @param modifiers - Optional configuration to customize regle behavior
343
- * @returns The reactive validation state (implements StandardSchemaV1)
344
- *
345
- * @example
346
- * ```ts
347
- * import { useRules, type InferInput } from '@regle/core';
348
- * import { required, string, email } from '@regle/rules';
349
- *
350
- * const r$ = useRules({
351
- * name: { required, string },
352
- * email: { required, email }
353
- * });
354
- *
355
- * // State is automatically created and typed
356
- * r$.$value.name // string | null
357
- * r$.$value.email // string | null
358
- *
359
- * // Can be used with Standard Schema compatible libraries
360
- * const result = await r$['~standard'].validate({ name: '', email: '' });
361
- * ```
362
- *
363
- * @see {@link https://reglejs.dev/common-usage/standard-schema#userules Documentation}
364
- */
365
- declare const useRules: useRulesFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>>;
366
- /**
367
- * Marks a value as static and treats the constructor as a regular raw Field.
368
- * @param value - The value to mark as static.
369
- * @returns The marked value.
370
- * @example
371
- * ```ts
372
- * const StaticDecimal = markStatic(Decimal);
373
- * const StaticBigWrapper = markStatic(BigWrapper);
374
- * ```
375
- */
376
- declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
377
- /**
378
- * Infer type of the `r$` of any function returning a regle instance
379
- */
380
- type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
381
- /**
382
- * Infer custom rules declared in a global configuration
383
- */
384
- type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
385
- /**
386
- * Infer custom shortcuts declared in a global configuration
387
- */
388
- type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
389
- /**
390
- * Extract a set rules and setting them as required
391
- */
392
- type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
393
- /**
394
- * Extract a set of custom rules from a global configuration and setting them as required
395
-
396
- */
397
- type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules$1 extends keyof InferRegleRules<T>> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
398
- /**
399
- * Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
400
- */
401
- type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState$1 extends unknown = any, TRules$1 extends keyof InferRegleRules<T> = never> = RegleFieldStatus<TState$1, [TRules$1] extends [never] ? Partial<InferRegleRules<T>> : RegleEnforceCustomRequiredRules<T, TRules$1>, InferRegleShortcuts<T>>;
402
- /**
403
- /**
404
- * DeepExact<T, S> is a TypeScript utility type that recursively checks whether the structure of type S
405
- * exactly matches the structure of type T, including all nested properties.
406
- *
407
- * Used in `useRegle` and `inferRules` to enforce that the rules object matches the expected shape exactly.
408
- */
409
- type DeepExact<TInfer, TTree> = NonNullable<TTree> extends MaybeRef<RegleRuleDecl> ? TTree : NonNullable<TTree> extends MaybeRef<RegleCollectionRuleDecl> ? TTree : [keyof TInfer] extends [keyof ExtractFromGetter<TTree>] ? ExactObject<TInfer, TTree> : { [K in keyof TInfer as K extends keyof TTree ? never : K]: TypeError<`Unknown property: <${Coerce<K>}>`> };
410
- type ExactObject<TInfer, TTree> = { [K in keyof TTree]: NonNullable<TTree[K]> extends Record<string, any> ? ExtendOnlyRealRecord<TTree[K]> extends true ? NonNullable<TTree[K]> extends MaybeRef<RegleRuleDecl> ? TTree[K] : K extends keyof TInfer ? DeepExact<TInfer[K], NonNullable<TTree[K]>> : TTree[K] : TTree[K] : TTree[K] };
411
- type TypeError<Msg> = {
412
- [' TypeError']: Msg;
413
- };
414
- type Coerce<T> = `${T & string}`;
415
18
  interface GlobalConfigOverrides<TValue$1 extends unknown = unknown> {
416
19
  /**
417
20
  * Override the default $edited handler.
@@ -421,12 +24,12 @@ interface GlobalConfigOverrides<TValue$1 extends unknown = unknown> {
421
24
  type isEditedHandlerFn<TValue$1 extends unknown = unknown> = (currentValue: MaybeInput<TValue$1>, initialValue: MaybeInput<TValue$1>, defaultHandlerFn: (currentValue: unknown, initialValue: unknown) => boolean) => boolean;
422
25
  interface RegleBehaviourOptions {
423
26
  /**
424
- * Only display error when calling `r$.$validate()`
27
+ * Does not run rules until the field is dirty.
425
28
  * @default false
426
29
  */
427
30
  lazy?: boolean | undefined;
428
31
  /**
429
- * Automatically set the dirty set without the need of `$value` or `$touch`.
32
+ * Automatically set the dirty state to true when value is changed without the need of calling `$touch`.
430
33
  * @default true
431
34
  *
432
35
  */
@@ -453,6 +56,11 @@ interface RegleBehaviourOptions {
453
56
  * @default true
454
57
  */
455
58
  clearExternalErrorsOnChange?: boolean | undefined;
59
+ /**
60
+ * Set the dirty state to true when the form is initialized.
61
+ * @default false
62
+ */
63
+ immediateDirty?: boolean | undefined;
456
64
  }
457
65
  interface LocalRegleBehaviourOptions<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}> {
458
66
  /**
@@ -539,220 +147,607 @@ type RegleShortcutDefinition<TCustomRules extends Record<string, any> = {}> = {
539
147
  };
540
148
  type AddDollarToOptions<T extends Record<string, any>> = { [K in keyof T as `$${string & K}`]: T[K] };
541
149
  /**
542
- * The main Regle type that represents a complete validation instance.
543
- *
544
- * @template TState - The shape of the state object being validated
545
- * @template TRules - The validation rules tree for the state
546
- * @template TValidationGroups - Groups of validation rules that can be run together
547
- * @template TShortcuts - Custom shortcut definitions for common validation patterns
548
- * @template TAdditionalReturnProperties - Additional properties to extend the return type
150
+ * The main Regle type that represents a complete validation instance.
151
+ *
152
+ * @template TState - The shape of the state object being validated
153
+ * @template TRules - The validation rules tree for the state
154
+ * @template TValidationGroups - Groups of validation rules that can be run together
155
+ * @template TShortcuts - Custom shortcut definitions for common validation patterns
156
+ * @template TAdditionalReturnProperties - Additional properties to extend the return type
157
+ *
158
+ */
159
+ type Regle<TState$1 extends Record<string, any> = EmptyObject, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> = EmptyObject, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
160
+ /**
161
+ * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
162
+ *
163
+ * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
164
+ */
165
+ r$: Raw<RegleRoot<TState$1, TRules$1, TValidationGroups, TShortcuts>>;
166
+ } & TAdditionalReturnProperties;
167
+ /**
168
+ * The type for a single field validation instance.
169
+ *
170
+ * @template TState - The type of the state value being validated
171
+ * @template TRules - The validation rules for the field
172
+ * @template TShortcuts - Custom shortcut definitions for common validation patterns
173
+ * @template TAdditionalReturnProperties - Additional properties to extend the return type
174
+ */
175
+ type RegleSingleField<TState$1 extends Maybe<PrimitiveTypes> = any, TRules$1 extends RegleRuleDecl<NonNullable<TState$1>> = EmptyObject, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
176
+ /**
177
+ * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
178
+ *
179
+ * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
180
+ */
181
+ r$: Raw<RegleFieldStatus<TState$1, TRules$1, TShortcuts>>;
182
+ } & TAdditionalReturnProperties;
183
+ type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
184
+ type InferDeepReactiveState<TState$1> = NonNullable<TState$1> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState$1> extends Date | File ? MaybeRef<TState$1> : NonNullable<TState$1> extends Record<string, any> ? DeepReactiveState<TState$1> : MaybeRef<TState$1>;
185
+ type ResetOptions<TState$1 extends unknown> = RequireOneOrNone<{
186
+ /**
187
+ * Reset validation status and reset form state to its initial state.
188
+ *
189
+ * Initial state is different than the original state as the initial state can be mutated when using `$reset`.
190
+ *
191
+ * This serve as the base comparison state for `$edited` property.
192
+ *
193
+ * ⚠️ This doesn't work if the state is a `reactive` object.
194
+ */
195
+ toInitialState?: boolean;
196
+ /**
197
+ * Reset validation status and reset form state to its original state.
198
+ *
199
+ * Original state is the unmutated state that was passed to the form when it was initialized.
200
+ */
201
+ toOriginalState?: boolean;
202
+ /**
203
+ * Reset validation status and reset form state to the given state
204
+ * Also set the new state as the initial state.
205
+ */
206
+ toState?: TState$1 | (() => TState$1);
207
+ /**
208
+ * Clears the $externalErrors state back to an empty object.
209
+ *
210
+ * @default false
211
+ */
212
+ clearExternalErrors?: boolean;
213
+ /**
214
+ * Keep the validation state of the form ($dirty, $invalid, $pending etc..)
215
+ * Only useful if you only want to reset the form state.
216
+ *
217
+ * @default false
218
+ */
219
+ keepValidationState?: boolean;
220
+ }, 'toInitialState' | 'toState'>;
221
+ type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
222
+ '~~global': Record<string, SuperCompatibleRegleRoot>;
223
+ };
224
+ type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
225
+ type PartialFormState<TState$1 extends Record<string, any>> = [unknown] extends [TState$1] ? {} : Prettify<{ [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? never : TState$1[K] extends Array<any> ? never : K]?: MaybeOutput<TState$1[K]> } & { [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? K : TState$1[K] extends Array<any> ? K : never]: NonNullable<TState$1[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState$1[K]> }>;
226
+ type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
227
+ /** The result of the validation */
228
+ valid: false;
229
+ /** Output data, filter the result by checking the `valid` property */
230
+ data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Date | File ? MaybeOutput<Raw<Data>> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data> : unknown;
231
+ /**
232
+ * Collection of all the error messages, collected for all children properties and nested forms.
233
+ *
234
+ * Only contains errors from properties where $dirty equals true.
235
+ * */
236
+ issues: DataTypeRegleIssues<Data, TRules$1>;
237
+ /**
238
+ * Collection of all the issues, collected for all children properties and nested forms.
239
+ *
240
+ * Only contains issues from properties where $dirty equals true.
241
+ */
242
+ errors: DataTypeRegleErrors<Data>;
243
+ } | {
244
+ valid: true;
245
+ data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules$1>[] : NonNullable<Data> extends Date | File ? SafeFieldProperty<Raw<NonNullable<Data>>, TRules$1> : NonNullable<Data> extends Record<string, any> ? DeepSafeFormState<NonNullable<Data>, TRules$1> : SafeFieldProperty<Data, TRules$1> : unknown;
246
+ issues: EmptyObject;
247
+ errors: EmptyObject;
248
+ };
249
+ type DataTypeRegleIssues<TData extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any> = never> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? RegleFieldIssue<TRules$1>[] : RegleCollectionErrors<TData, true> : isRecordLiteral<TData> extends true ? RegleIssuesTree<TData> : RegleFieldIssue<TRules$1>[] : RegleFieldIssue | RegleCollectionErrors<TData, true> | RegleIssuesTree<TData>;
250
+ type DataTypeRegleErrors<TData extends Record<string, any> | any[] | unknown> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? string[] : RegleCollectionErrors<TData> : isRecordLiteral<TData> extends true ? RegleErrorTree<TData> : string[] : string[] | RegleErrorTree<TData> | RegleCollectionErrors<TData>;
251
+ type RegleCollectionResult<Data extends any[], TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
252
+ valid: false;
253
+ issues: RegleCollectionErrors<Data, true>;
254
+ errors: RegleCollectionErrors<Data>;
255
+ } | {
256
+ valid: true;
257
+ issues: EmptyObject;
258
+ errors: EmptyObject;
259
+ });
260
+ type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
261
+ valid: false;
262
+ issues: RegleFieldIssue<TRules$1>[];
263
+ errors: string[];
264
+ } | {
265
+ valid: true;
266
+ issues: [];
267
+ errors: [];
268
+ });
269
+ type $InternalRegleResult = {
270
+ valid: boolean;
271
+ data: any;
272
+ errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
273
+ issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
274
+ };
275
+ type DeepSafeFormState<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? {} : TRules$1 extends undefined ? TState$1 : TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? K : never]?: SafeProperty<TState$1[K], TRules$1[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState$1[K], TRules$1[K]> } & { [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState$1[K], TRules$1[K]> ? unknown : NonNullable<SafeProperty<TState$1[K], TRules$1[K]>> }> : TState$1;
276
+ type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRefOrComputedRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
277
+ type ObjectHaveAtLeastOneRequiredField<TState$1 extends Record<string, any>, TRule extends ReglePartialRuleTree<TState$1, any>> = TState$1 extends Maybe<TState$1> ? { [K in keyof NonNullable<TState$1>]-?: IsPropertyOutputRequired<NonNullable<TState$1>[K], TRule[K]> }[keyof TState$1] extends false ? false : true : true;
278
+ type ArrayHaveAtLeastOneRequiredField<TState$1 extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState$1>> = TState$1 extends Maybe<TState$1> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends MaybeRef<RegleRuleDecl> ? Omit<UnwrapRef<TRule>, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState$1>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
279
+ type SafeProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState$1 ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState$1 extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState$1 : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? DeepSafeFormState<NonNullable<TState$1> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState$1>> : {}, TRule> : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends true ? TState$1 : MaybeOutput<TState$1> : TState$1 : TState$1;
280
+ type IsPropertyOutputRequired<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? unknown : NonNullable<TState$1> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState$1>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState$1> extends Record<string, any> ? NonNullable<TState$1> : {}, TRule> extends false ? false : true : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends false ? false : true : false : false;
281
+ type SafeFieldProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState$1> : MaybeOutput<TState$1>;
282
+ /** Types to be augmented by @regle/schemas */
283
+ interface NarrowVariantExtracts {}
284
+ interface NarrowVariantFieldExtracts<T extends unknown> {}
285
+ type NarrowVariant<TRoot extends {
286
+ [x: string]: unknown;
287
+ $fields: {
288
+ [x: string]: unknown;
289
+ };
290
+ $value: unknown;
291
+ }, TKey$1 extends keyof TRoot, TValue$1 extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey$1], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
292
+ $value: infer V;
293
+ } ? V : unknown)> = Extract<TRoot, { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue$1>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue$1>[keyof NarrowVariantFieldExtracts<TValue$1>]) }> & {
294
+ $fields: Extract<TRoot['$fields'], { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue$1>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue$1>[keyof NarrowVariantFieldExtracts<TValue$1>]) }> & { [K in TKey$1]: TRoot[K] & {
295
+ $value: TValue$1;
296
+ } };
297
+ } & {
298
+ $value: Omit<TRoot['$value'], TKey$1> & { [K in TKey$1]: TValue$1 };
299
+ } & { [K in TKey$1]: TRoot[K] & {
300
+ $value: TValue$1;
301
+ } };
302
+ type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState$1>> extends true ? Omit<RegleStatus<TState$1, TRules$1, TShortcuts>, '$fields'> & {
303
+ $fields: ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>];
304
+ } & (HasNamedKeys<TState$1> extends true ? ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>] : {}) : RegleStatus<TState$1, TRules$1, TShortcuts>;
305
+ type ProcessChildrenFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState$1>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } : {} };
306
+ type FindCorrespondingVariant<TState$1 extends Record<string, any>, TRules$1 extends any[]> = TRules$1 extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState$1> ? [F] : FindCorrespondingVariant<TState$1, R> : [];
307
+ type PossibleLiteralTypes<T extends Record<string, any>, TKey$1 extends keyof T> = unknown extends T[TKey$1] ? {
308
+ [x: string]: { [K in TKey$1]-?: Omit<RegleRuleDecl<any, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
309
+ literal?: RegleRuleDefinition<any, [literal: any], false, boolean, any, string | number>;
310
+ } };
311
+ } : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
312
+ literal?: RegleRuleDefinition<MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number>;
313
+ } } };
314
+ type RequiredForm<T extends Record<string, any>, TKey$1 extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey$1> & PossibleLiteralTypes<T, TKey$1>[keyof PossibleLiteralTypes<T, TKey$1>];
315
+ type VariantTuple<T extends Record<string, any>, TKey$1 extends keyof T> = [RequiredForm<T, TKey$1>, ...RequiredForm<T, TKey$1>[]];
316
+ /**
317
+ * Combine all members of a union type, merging types for each key, and keeping loose types
318
+ */
319
+ type JoinDiscriminatedUnions<TUnion extends unknown> = HasNamedKeys<TUnion> extends true ? isRecordLiteral<TUnion> extends true ? HasCommonKey<UnionToTuple<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : DumbJoinDiscriminatedUnions<TUnion> : TUnion : TUnion;
320
+ /**
321
+ * Combine all members of a union type on one level and not nested.
322
+ */
323
+ type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
324
+ type DumbJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<TUnion>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
325
+ type RemoveCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
326
+ type HasCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? K$1 extends keyof F ? true : HasCommonKey<R, K$1> : false;
327
+ /**
328
+ * Transforms a union and apply undefined values to non-present keys to support intersection
329
+ */
330
+ type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
331
+ /**
332
+ * Combine all union values to be able to get even the normally "never" values, act as an intersection type
333
+ */
334
+ type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
335
+ /**
336
+ * Get all possible keys from a union, even the ones present only on one union
337
+ */
338
+ type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
339
+ /**
340
+ * Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
341
+ */
342
+ type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
343
+ type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K] };
344
+ /**
345
+ * Merge every boolean property into a single boolean.
346
+ */
347
+ type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
348
+ /**
349
+ * Ensure that if at least one prop is required, the "prop" object will be required too
350
+ */
351
+ type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
352
+ type EnumType<T extends Record<string, unknown>> = T[keyof T];
353
+ type EnumLike = {
354
+ [k: string]: string | number;
355
+ [nu: number]: string;
356
+ };
357
+ type MaybeRefOrComputedRef<T extends any> = MaybeRef<T> | ComputedRef<T>;
358
+ type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
359
+ type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
360
+ type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
361
+ type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
362
+ /**
363
+ * Convert a nested object to a deeply nested partial object.
364
+ */
365
+ type DeepPartial<T> = T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Date | File | RegleStaticImpl<unknown> ? T : T extends Record<string, any> ? { [K in keyof T]?: DeepPartial<T[K]> | undefined } : T | undefined;
366
+ type Prettify<T> = T extends infer R ? { [K in keyof R]: R[K] } & {} : never;
367
+ type Maybe<T = any> = T | null | undefined;
368
+ type MaybeInput<T = any> = T | null | undefined;
369
+ type MaybeOutput<T = any> = T | undefined;
370
+ type MaybeReadonly<T> = T | Readonly<T>;
371
+ type NonUndefined<T> = Exclude<T, undefined>;
372
+ type PromiseReturn<T> = T extends Promise<infer U> ? U : T;
373
+ type MaybeGetter<T, V$1 = any, TAdd extends Record<string, any> = {}> = T | ((value: Ref<V$1>, index: number) => T & TAdd);
374
+ type MaybeComputedOrGetter<T> = MaybeRefOrComputedRef<T> | ((...args: any[]) => T);
375
+ type Unwrap<T extends MaybeRef<unknown>> = T extends Ref ? UnwrapRef<T> : UnwrapNestedRefs<T>;
376
+ type UnwrapSimple<T extends MaybeRef<Record<string, any>>> = T extends MaybeComputedOrGetter<infer U> ? U : T extends Ref<infer U> ? U : T extends ((...args: any[]) => infer U) ? U : T;
377
+ type ExtractFromGetter<T extends MaybeGetter<any, any, any>> = T extends ((value: Ref<any>, index: number) => infer U extends Record<string, any>) ? U : T;
378
+ type ExtendOnlyRealRecord<T extends unknown> = NonNullable<T> extends File | Date | RegleStatic<{}> | RegleStaticImpl<{}> ? false : NonNullable<T> extends Record<string, any> ? true : false;
379
+ type OmitByType<T extends Record<string, any>, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] };
380
+ type DeepMaybeRef<T extends Record<string, any>> = { [K in keyof T]: MaybeRef<T[K]> };
381
+ type ExcludeByType<T, U$1> = { [K in keyof T as T[K] extends U$1 ? never : K]: T[K] extends U$1 ? never : T[K] };
382
+ type PrimitiveTypes = string | number | boolean | bigint | Date | File;
383
+ type isRecordLiteral<T extends unknown> = NonNullable<T> extends Date | File | RegleStatic<unknown> | RegleStaticImpl<unknown> ? false : NonNullable<T> extends Record<string, any> ? true : false;
384
+ type NoInferLegacy<A$1 extends any> = [A$1][A$1 extends any ? 0 : never];
385
+ /**
386
+ * Extract the element type from an array.
549
387
  *
388
+ * @example
389
+ * ```ts
390
+ * type Element = ArrayElement<[1, 2, 3]>; // number
391
+ * ```
550
392
  */
551
- type Regle<TState$1 extends Record<string, any> = EmptyObject, TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> = EmptyObject, TValidationGroups extends Record<string, RegleValidationGroupEntry[]> = {}, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
552
- /**
553
- * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
554
- *
555
- * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
556
- */
557
- r$: Raw<RegleRoot<TState$1, TRules$1, TValidationGroups, TShortcuts>>;
558
- } & TAdditionalReturnProperties;
393
+ type ArrayElement<T> = T extends Array<infer U> ? U : never;
559
394
  /**
560
- * The type for a single field validation instance.
395
+ * Declares a tuple that must have at least one element
396
+ */
397
+ type NonEmptyTuple<T> = [T, ...T[]] | T[];
398
+ interface inferRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>> {
399
+ <TState$1 extends MaybeRef<Record<string, any> | MaybeInput<PrimitiveTypes>>, TRules$1 extends ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<DefaultValidatorsTree> & TCustomRules>, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<DefaultValidatorsTree> & TCustomRules>>(state: Maybe<TState$1> | DeepReactiveState<TState$1>, rulesFactory: Unwrap<TState$1> extends MaybeInput<PrimitiveTypes> ? TDecl : Unwrap<TState$1> extends Record<string, any> ? TRules$1 : {}): NonNullable<Unwrap<TState$1>> extends PrimitiveTypes ? TDecl : TRules$1;
400
+ }
401
+ /**
402
+ * Type helper to provide autocomplete and type-checking for your form rules.
403
+ * It returns the rules without any processing - useful with computed rules.
561
404
  *
562
- * @template TState - The type of the state value being validated
563
- * @template TRules - The validation rules for the field
564
- * @template TShortcuts - Custom shortcut definitions for common validation patterns
565
- * @template TAdditionalReturnProperties - Additional properties to extend the return type
405
+ * @param state - The state reference
406
+ * @param rules - Your rule tree
407
+ * @returns The rules object (passthrough)
408
+ *
409
+ * @example
410
+ * ```ts
411
+ * import { inferRules, useRegle } from '@regle/core';
412
+ * import { required, minLength } from '@regle/rules';
413
+ *
414
+ * const state = ref({ name: '' });
415
+ *
416
+ * // inferRules preserves TypeScript autocompletion
417
+ * const rules = computed(() => {
418
+ * return inferRules(state, {
419
+ * name: { required, minLength: minLength(2) }
420
+ * })
421
+ * });
422
+ *
423
+ * const { r$ } = useRegle(state, rules);
424
+ * ```
425
+ *
426
+ * @see {@link https://reglejs.dev/core-concepts/#dynamic-rules-object Documentation}
566
427
  */
567
- type RegleSingleField<TState$1 extends Maybe<PrimitiveTypes> = any, TRules$1 extends RegleRuleDecl<NonNullable<TState$1>> = EmptyObject, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record<string, any> = {}> = {
568
- /**
569
- * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information.
570
- *
571
- * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties}
572
- */
573
- r$: Raw<RegleFieldStatus<TState$1, TRules$1, TShortcuts>>;
574
- } & TAdditionalReturnProperties;
575
- type DeepReactiveState<T extends Record<string, any> | unknown | undefined> = ExtendOnlyRealRecord<T> extends true ? { [K in keyof T]: InferDeepReactiveState<T[K]> } : never;
576
- type InferDeepReactiveState<TState$1> = NonNullable<TState$1> extends Array<infer U extends Record<string, any>> ? DeepReactiveState<U[]> : NonNullable<TState$1> extends Date | File ? MaybeRef<TState$1> : NonNullable<TState$1> extends Record<string, any> ? DeepReactiveState<TState$1> : MaybeRef<TState$1>;
577
- type ResetOptions<TState$1 extends unknown> = RequireOneOrNone<{
428
+ declare const inferRules: inferRulesFn<Partial<ExtendedRulesDeclarations>>;
429
+ interface GlobalConfigOptions<TCustomRules extends Partial<ExtendedRulesDeclarations> = CustomRulesDeclarationTree, TShortcuts extends RegleShortcutDefinition<any> = never> {
578
430
  /**
579
- * Reset validation status and reset form state to its initial state.
580
- *
581
- * Initial state is different than the original state as the initial state can be mutated when using `$reset`.
582
- *
583
- * This serve as the base comparison state for `$edited` property.
431
+ * Declare custom rules to be used globally or override the default rules messages.
584
432
  *
585
- * ⚠️ This doesn't work if the state is a `reactive` object.
586
- */
587
- toInitialState?: boolean;
588
- /**
589
- * Reset validation status and reset form state to its original state.
433
+ * Ex:
434
+ * ```ts
435
+ * import { defineRegleConfig } from '@regle/core';
436
+ * import { required, withMessage } from '@regle/rules';
590
437
  *
591
- * Original state is the unmutated state that was passed to the form when it was initialized.
592
- */
593
- toOriginalState?: boolean;
594
- /**
595
- * Reset validation status and reset form state to the given state
596
- * Also set the new state as the initial state.
438
+ * export const { useRegle, inferRules, useRules } = defineRegleConfig({
439
+ * rules: () => ({
440
+ * required: withMessage(required, 'This field cannot be empty'),
441
+ * }),
442
+ * });
443
+ * ```
444
+ * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
597
445
  */
598
- toState?: TState$1 | (() => TState$1);
446
+ rules?: () => TCustomRules;
599
447
  /**
600
- * Clears the $externalErrors state back to an empty object.
448
+ * Define modifiers to be used globally.
601
449
  *
602
- * @default false
603
- */
604
- clearExternalErrors?: boolean;
605
- /**
606
- * Keep the validation state of the form ($dirty, $invalid, $pending etc..)
607
- * Only useful if you only want to reset the form state.
450
+ * Ex:
451
+ * ```ts
452
+ * import { defineRegleConfig } from '@regle/core';
608
453
  *
609
- * @default false
454
+ * export const { useRegle, inferRules, useRules } = defineRegleConfig({
455
+ * modifiers: {
456
+ * lazy: true,
457
+ * rewardEarly: true
458
+ * }
459
+ * });
460
+ * ```
461
+ * @see {@link https://reglejs.dev/advanced-usage/global-config#declare-modifiers Documentation}
610
462
  */
611
- keepValidationState?: boolean;
612
- }, 'toInitialState' | 'toState'>;
613
- type ScopedInstancesRecord = Record<string, Record<string, SuperCompatibleRegleRoot>> & {
614
- '~~global': Record<string, SuperCompatibleRegleRoot>;
615
- };
616
- type ScopedInstancesRecordLike = Partial<ScopedInstancesRecord>;
617
- type PartialFormState<TState$1 extends Record<string, any>> = [unknown] extends [TState$1] ? {} : Prettify<{ [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? never : TState$1[K] extends Array<any> ? never : K]?: MaybeOutput<TState$1[K]> } & { [K in keyof TState$1 as ExtendOnlyRealRecord<TState$1[K]> extends true ? K : TState$1[K] extends Array<any> ? K : never]: NonNullable<TState$1[K]> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : PartialFormState<TState$1[K]> }>;
618
- type RegleResult<Data extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = {
619
- /** The result of the validation */
620
- valid: false;
621
- /** Output data, filter the result by checking the `valid` property */
622
- data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Date | File ? MaybeOutput<Raw<Data>> : NonNullable<Data> extends Array<infer U extends Record<string, any>> ? PartialFormState<U>[] : NonNullable<Data> extends Record<string, any> ? PartialFormState<NonNullable<Data>> : MaybeOutput<Data> : unknown;
463
+ modifiers?: RegleBehaviourOptions;
623
464
  /**
624
- * Collection of all the error messages, collected for all children properties and nested forms.
465
+ * Define reusable validation shortcuts to be used globally.
625
466
  *
626
- * Only contains errors from properties where $dirty equals true.
627
- * */
628
- issues: DataTypeRegleIssues<Data, TRules$1>;
629
- /**
630
- * Collection of all the issues, collected for all children properties and nested forms.
467
+ * Ex:
468
+ * ```ts
469
+ * import { defineRegleConfig } from '@regle/core';
631
470
  *
632
- * Only contains issues from properties where $dirty equals true.
471
+ * export const { useRegle, inferRules, useRules } = defineRegleConfig({
472
+ * shortcuts: {
473
+ * fields: {
474
+ * $isRequired: (field) => field.$rules.required?.$active ?? false,
475
+ * },
476
+ * },
477
+ * });
478
+ * ```
479
+ * @see {@link https://reglejs.dev/advanced-usage/extend-properties#extend-properties Documentation}
633
480
  */
634
- errors: DataTypeRegleErrors<Data>;
635
- } | {
636
- valid: true;
637
- data: IsUnknown<Data> extends true ? unknown : IsAny<Data> extends true ? unknown : HasNamedKeys<Data> extends true ? NonNullable<Data> extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, TRules$1>[] : NonNullable<Data> extends Date | File ? SafeFieldProperty<Raw<NonNullable<Data>>, TRules$1> : NonNullable<Data> extends Record<string, any> ? DeepSafeFormState<NonNullable<Data>, TRules$1> : SafeFieldProperty<Data, TRules$1> : unknown;
638
- issues: EmptyObject;
639
- errors: EmptyObject;
481
+ shortcuts?: TShortcuts;
482
+ /** Override default behaviors of Regle processors. */
483
+ overrides?: GlobalConfigOverrides<unknown>;
484
+ }
485
+ /**
486
+ * Define a global Regle configuration to customize the validation behavior across your application.
487
+ *
488
+ * Features:
489
+ * - Customize built-in rules messages
490
+ * - Add your custom rules with full type inference
491
+ * - Define global modifiers (lazy, rewardEarly, etc.)
492
+ * - Define shortcuts for common validation patterns
493
+ *
494
+ * @param options - Configuration options
495
+ * @returns Object containing typed `useRegle`, `inferRules`, and `useRules` functions
496
+ *
497
+ * @example
498
+ * ```ts
499
+ * import { defineRegleConfig } from '@regle/core';
500
+ * import { required, withMessage } from '@regle/rules';
501
+ *
502
+ * export const { useRegle, inferRules, useRules } = defineRegleConfig({
503
+ * rules: () => ({
504
+ * // Override default required message
505
+ * required: withMessage(required, 'This field cannot be empty'),
506
+ * // Add custom rule
507
+ * myCustomRule: createRule({
508
+ * validator: (value) => value === 'valid',
509
+ * message: 'Invalid value'
510
+ * })
511
+ * }),
512
+ * modifiers: {
513
+ * lazy: true,
514
+ * rewardEarly: true
515
+ * }
516
+ * });
517
+ * ```
518
+ *
519
+ * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
520
+ */
521
+ declare function defineRegleConfig<TShortcuts extends RegleShortcutDefinition<TCustomRules>, TCustomRules extends Partial<ExtendedRulesDeclarations>>({
522
+ rules,
523
+ modifiers,
524
+ shortcuts,
525
+ overrides
526
+ }: GlobalConfigOptions<TCustomRules, TShortcuts>): {
527
+ useRegle: useRegleFn<TCustomRules, TShortcuts>;
528
+ inferRules: inferRulesFn<TCustomRules>;
529
+ useRules: useRulesFn<TCustomRules, TShortcuts>;
640
530
  };
641
- type DataTypeRegleIssues<TData extends Record<string, any> | any[] | unknown, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any> = never> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? RegleFieldIssue<TRules$1>[] : RegleCollectionErrors<TData, true> : isRecordLiteral<TData> extends true ? RegleIssuesTree<TData> : RegleFieldIssue<TRules$1>[] : RegleFieldIssue | RegleCollectionErrors<TData, true> | RegleIssuesTree<TData>;
642
- type DataTypeRegleErrors<TData extends Record<string, any> | any[] | unknown> = HasNamedKeys<TData> extends true ? NonNullable<TData> extends Array<infer U> ? isRecordLiteral<U> extends true ? string[] : RegleCollectionErrors<TData> : isRecordLiteral<TData> extends true ? RegleErrorTree<TData> : string[] : string[] | RegleErrorTree<TData> | RegleCollectionErrors<TData>;
643
- type RegleCollectionResult<Data extends any[], TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
644
- valid: false;
645
- issues: RegleCollectionErrors<Data, true>;
646
- errors: RegleCollectionErrors<Data>;
647
- } | {
648
- valid: true;
649
- issues: EmptyObject;
650
- errors: EmptyObject;
651
- });
652
- type RegleFieldResult<Data extends any, TRules$1 extends ReglePartialRuleTree<any> | RegleFormPropertyType<any>> = RegleResult<Data, TRules$1> & ({
653
- valid: false;
654
- issues: RegleFieldIssue<TRules$1>[];
655
- errors: string[];
656
- } | {
657
- valid: true;
658
- issues: [];
659
- errors: [];
660
- });
661
- type $InternalRegleResult = {
662
- valid: boolean;
663
- data: any;
664
- errors: $InternalRegleErrorTree | $InternalRegleCollectionErrors | string[];
665
- issues: $InternalRegleIssuesTree | $InternalRegleCollectionIssues | RegleFieldIssue[];
531
+ /**
532
+ * Extend an already created custom `useRegle` configuration with additional rules, modifiers, or shortcuts.
533
+ *
534
+ * @param regle - The existing useRegle function to extend
535
+ * @param options - Additional configuration to merge
536
+ * @param options.rules - Additional custom rules
537
+ * @param options.modifiers - Additional modifiers to merge
538
+ * @param options.shortcuts - Additional shortcuts to merge
539
+ * @returns Object containing the extended `useRegle` and `inferRules` functions
540
+ *
541
+ * @example
542
+ * ```ts
543
+ * import { extendRegleConfig } from '@regle/core';
544
+ * import { baseUseRegle } from './base-config';
545
+ *
546
+ * export const { useRegle, inferRules } = extendRegleConfig(baseUseRegle, {
547
+ * rules: () => ({
548
+ * additionalRule: myNewRule
549
+ * }),
550
+ * modifiers: {
551
+ * rewardEarly: true
552
+ * }
553
+ * });
554
+ * ```
555
+ *
556
+ * @see {@link https://reglejs.dev/advanced-usage/global-config Documentation}
557
+ */
558
+ declare function extendRegleConfig<TRootCustomRules extends Partial<ExtendedRulesDeclarations>, TRootShortcuts extends RegleShortcutDefinition<{}>, TShortcuts extends RegleShortcutDefinition<Merge<TRootCustomRules, TCustomRules>>, TCustomRules extends Partial<ExtendedRulesDeclarations>>(regle: useRegleFn<TRootCustomRules, TRootShortcuts>, {
559
+ rules,
560
+ modifiers,
561
+ shortcuts,
562
+ overrides
563
+ }: GlobalConfigOptions<TCustomRules, TShortcuts>): {
564
+ useRegle: useRegleFn<Merge<TRootCustomRules, TCustomRules>, TRootShortcuts & TShortcuts>;
565
+ inferRules: inferRulesFn<Merge<TRootCustomRules, TCustomRules>>;
666
566
  };
667
- type DeepSafeFormState<TState$1 extends Record<string, any>, TRules$1 extends ReglePartialRuleTree<Record<string, any>, CustomRulesDeclarationTree> | RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? {} : TRules$1 extends undefined ? TState$1 : TRules$1 extends ReglePartialRuleTree<TState$1, CustomRulesDeclarationTree> ? Prettify<{ [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? K : never]?: SafeProperty<TState$1[K], TRules$1[K]> extends MaybeInput<infer M> ? MaybeOutput<M> : SafeProperty<TState$1[K], TRules$1[K]> } & { [K in keyof TState$1 as IsPropertyOutputRequired<TState$1[K], TRules$1[K]> extends false ? never : K]-?: unknown extends SafeProperty<TState$1[K], TRules$1[K]> ? unknown : NonNullable<SafeProperty<TState$1[K], TRules$1[K]>> }> : TState$1;
668
- type FieldHaveRequiredRule<TRule extends RegleFormPropertyType<any, any> | undefined = never> = TRule extends MaybeRefOrComputedRef<RegleRuleDecl<any, any>> ? [unknown] extends UnwrapRef<TRule>['required'] ? NonNullable<UnwrapRef<TRule>['literal']> extends RegleRuleDefinition<any, any[], any, any, any, any> ? true : false : NonNullable<UnwrapRef<TRule>['required']> extends UnwrapRef<TRule>['required'] ? UnwrapRef<TRule>['required'] extends RegleRuleDefinition<any, infer Params, any, any, any, any> ? Params extends never[] ? true : false : false : false : false;
669
- type ObjectHaveAtLeastOneRequiredField<TState$1 extends Record<string, any>, TRule extends ReglePartialRuleTree<TState$1, any>> = TState$1 extends Maybe<TState$1> ? { [K in keyof NonNullable<TState$1>]-?: IsPropertyOutputRequired<NonNullable<TState$1>[K], TRule[K]> }[keyof TState$1] extends false ? false : true : true;
670
- type ArrayHaveAtLeastOneRequiredField<TState$1 extends Maybe<any[]>, TRule extends RegleCollectionRuleDecl<TState$1>> = TState$1 extends Maybe<TState$1> ? FieldHaveRequiredRule<Omit<TRule, '$each'> extends MaybeRef<RegleRuleDecl> ? Omit<UnwrapRef<TRule>, '$each'> : {}> | ObjectHaveAtLeastOneRequiredField<ArrayElement<NonNullable<TState$1>>, ExtractFromGetter<TRule['$each']> extends undefined ? {} : NonNullable<ExtractFromGetter<TRule['$each']>>> extends false ? false : true : true;
671
- type SafeProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = unknown extends TState$1 ? unknown : TRule extends RegleCollectionRuleDecl<any, any> ? TState$1 extends Array<infer U extends Record<string, any>> ? DeepSafeFormState<U, ExtractFromGetter<TRule['$each']>>[] : TState$1 : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? DeepSafeFormState<NonNullable<TState$1> extends Record<string, any> ? JoinDiscriminatedUnions<NonNullable<TState$1>> : {}, TRule> : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends true ? TState$1 : MaybeOutput<TState$1> : TState$1 : TState$1;
672
- type IsPropertyOutputRequired<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined> = [unknown] extends [TState$1] ? unknown : NonNullable<TState$1> extends Array<any> ? TRule extends RegleCollectionRuleDecl<any, any> ? ArrayHaveAtLeastOneRequiredField<NonNullable<TState$1>, TRule> extends false ? false : true : false : TRule extends ReglePartialRuleTree<any, any> ? ExtendOnlyRealRecord<TState$1> extends true ? ObjectHaveAtLeastOneRequiredField<NonNullable<TState$1> extends Record<string, any> ? NonNullable<TState$1> : {}, TRule> extends false ? false : true : TRule extends MaybeRef<RegleRuleDecl<any, any>> ? FieldHaveRequiredRule<UnwrapRef<TRule>> extends false ? false : true : false : false;
673
- type SafeFieldProperty<TState$1, TRule extends RegleFormPropertyType<any, any> | undefined = never> = FieldHaveRequiredRule<TRule> extends true ? NonNullable<TState$1> : MaybeOutput<TState$1>;
674
- /** Types to be augmented by @regle/schemas */
675
- interface NarrowVariantExtracts {}
676
- interface NarrowVariantFieldExtracts<T extends unknown> {}
677
- type NarrowVariant<TRoot extends {
678
- [x: string]: unknown;
679
- $fields: {
680
- [x: string]: unknown;
681
- };
682
- $value: unknown;
683
- }, TKey$1 extends keyof TRoot, TValue$1 extends (LazyJoinDiscriminatedUnions<Exclude<TRoot[TKey$1], RegleCollectionStatus<any, any, any> | RegleStatus<any, any, any> | NarrowVariantExtracts[keyof NarrowVariantExtracts]>> extends {
684
- $value: infer V;
685
- } ? V : unknown)> = Extract<TRoot, { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue$1>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue$1>[keyof NarrowVariantFieldExtracts<TValue$1>]) }> & {
686
- $fields: Extract<TRoot['$fields'], { [K in TKey$1]: RegleFieldStatus<TValue$1, any, any> | RegleFieldStatus<MaybeInput<TValue$1>, any, any> | (IsEmptyObject<NarrowVariantFieldExtracts<TValue$1>> extends true ? EmptyObject : NarrowVariantFieldExtracts<TValue$1>[keyof NarrowVariantFieldExtracts<TValue$1>]) }> & { [K in TKey$1]: TRoot[K] & {
687
- $value: TValue$1;
688
- } };
689
- } & {
690
- $value: Omit<TRoot['$value'], TKey$1> & { [K in TKey$1]: TValue$1 };
691
- } & { [K in TKey$1]: TRoot[K] & {
692
- $value: TValue$1;
693
- } };
694
- type MaybeVariantStatus<TState$1 extends Record<string, any> | undefined = Record<string, any>, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>> = Record<string, any>, TShortcuts extends RegleShortcutDefinition = {}> = IsUnion<NonNullable<TState$1>> extends true ? Omit<RegleStatus<TState$1, TRules$1, TShortcuts>, '$fields'> & {
695
- $fields: ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>];
696
- } & (HasNamedKeys<TState$1> extends true ? ProcessChildrenFields<TState$1, TRules$1, TShortcuts>[keyof ProcessChildrenFields<TState$1, TRules$1, TShortcuts>] : {}) : RegleStatus<TState$1, TRules$1, TShortcuts>;
697
- type ProcessChildrenFields<TState$1 extends Record<string, any> | undefined, TRules$1 extends ReglePartialRuleTree<NonNullable<TState$1>>, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj<UnionToTuple<TState$1>>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? TKey : never : never : TKey]-?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } & { [TKey in keyof UnionToTuple<TState$1>[TIndexInt] as IsEmptyObject<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject> extends true ? TKey extends keyof TState$1 ? TState$1[TKey] extends NonNullable<TState$1[TKey]> ? never : TKey : TKey : never]?: InferRegleStatusType<FindCorrespondingVariant<UnionToTuple<TState$1>[TIndexInt] extends Record<string, any> ? UnionToTuple<TState$1>[TIndexInt] : never, UnionToTuple<TRules$1>> extends [infer U] ? TKey extends keyof U ? U[TKey] : EmptyObject : EmptyObject, NonNullable<UnionToTuple<TState$1>[TIndexInt]>, TKey, TShortcuts> } : {} };
698
- type FindCorrespondingVariant<TState$1 extends Record<string, any>, TRules$1 extends any[]> = TRules$1 extends [infer F, ...infer R] ? F extends ReglePartialRuleTree<TState$1> ? [F] : FindCorrespondingVariant<TState$1, R> : [];
699
- type PossibleLiteralTypes<T extends Record<string, any>, TKey$1 extends keyof T> = unknown extends T[TKey$1] ? {
700
- [x: string]: { [K in TKey$1]-?: Omit<RegleRuleDecl<any, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
701
- literal?: RegleRuleDefinition<any, [literal: any], false, boolean, any, string | number>;
702
- } };
703
- } : { [TVal in NonNullable<T[TKey$1]>]: { [K in TKey$1]-?: Omit<RegleRuleDecl<TVal, Partial<ExtendedRulesDeclarations>>, 'literal'> & {
704
- literal?: RegleRuleDefinition<MaybeInput<TVal>, [literal: TVal], false, boolean, MaybeInput<TVal>, string | number>;
705
- } } };
706
- type RequiredForm<T extends Record<string, any>, TKey$1 extends keyof T> = Omit<ReglePartialRuleTree<T>, TKey$1> & PossibleLiteralTypes<T, TKey$1>[keyof PossibleLiteralTypes<T, TKey$1>];
707
- type VariantTuple<T extends Record<string, any>, TKey$1 extends keyof T> = [RequiredForm<T, TKey$1>, ...RequiredForm<T, TKey$1>[]];
567
+ type useRegleFnOptions<TState$1 extends Record<string, any> | MaybeInput<PrimitiveTypes>, TRules$1 extends ReglePartialRuleTree<Unwrap<TState$1 extends Record<string, any> ? TState$1 : {}>, Partial<ExtendedRulesDeclarations>>, TAdditionalOptions extends Record<string, any>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>> = TState$1 extends MaybeInput<PrimitiveTypes> ? Partial<DeepMaybeRef<RegleBehaviourOptions>> & TAdditionalOptions : Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups> & TAdditionalOptions;
568
+ interface useRegleFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never, TAdditionalReturnProperties extends Record<string, any> = {}, TAdditionalOptions extends Record<string, any> = {}> {
569
+ <TState$1 extends MaybeRef<Record<string, any> | MaybeInput<PrimitiveTypes>>, TRules$1 extends ReglePartialRuleTree<Unwrap<TState$1>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TDecl extends RegleRuleDecl<NonNullable<Unwrap<TState$1>>, Partial<ExtendedRulesDeclarations> & Partial<TCustomRules>>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>>(...params: [state: Maybe<TState$1> | DeepReactiveState<TState$1>, rulesFactory: Unwrap<TState$1> extends MaybeInput<PrimitiveTypes> ? MaybeRefOrGetter<TDecl> : Unwrap<TState$1> extends Record<string, any> ? MaybeComputedOrGetter<TRules$1> : {}, ...(HaveAnyRequiredProps<useRegleFnOptions<Unwrap<TState$1>, TRules$1, TAdditionalOptions, TValidationGroups>> extends true ? [options: useRegleFnOptions<Unwrap<TState$1>, TRules$1, TAdditionalOptions, TValidationGroups>] : [options?: useRegleFnOptions<Unwrap<TState$1>, TRules$1, TAdditionalOptions, TValidationGroups>])]): NonNullable<Unwrap<TState$1>> extends PrimitiveTypes ? RegleSingleField<NonNullable<Unwrap<TState$1>>, TDecl, TShortcuts, TAdditionalReturnProperties> : Regle<Unwrap<TState$1> extends Record<string, any> ? Unwrap<TState$1> : {}, UnwrapSimple<TRules$1> extends Record<string, any> ? UnwrapSimple<TRules$1> : {}, TValidationGroups, TShortcuts, TAdditionalReturnProperties>;
570
+ __config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
571
+ }
708
572
  /**
709
- * Combine all members of a union type, merging types for each key, and keeping loose types
573
+ * `useRegle` serves as the foundation for validation logic.
574
+ * It transforms your data and validation rules into a powerful, reactive validation system.
575
+ *
576
+ * @param state - Your form data (plain object, ref, reactive object, or structure with nested refs)
577
+ * @param rules - Validation rules that should align with the structure of your state
578
+ * @param modifiers - Optional configuration to customize regle behavior
579
+ * @returns An object containing `r$` - the reactive validation state
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * import { useRegle } from '@regle/core';
584
+ * import { required, email, minLength } from '@regle/rules';
585
+ *
586
+ * const { r$ } = useRegle(
587
+ * { name: '', email: '' },
588
+ * {
589
+ * name: { required, minLength: minLength(2) },
590
+ * email: { required, email }
591
+ * }
592
+ * );
593
+ *
594
+ * // Access validation state
595
+ * r$.$valid // Whether all validations pass
596
+ * r$.$value // The current form values
597
+ * r$.name.$errors // Errors for the name field
598
+ *
599
+ * // Trigger validation
600
+ * const result = await r$.$validate();
601
+ * ```
602
+ *
603
+ * @see {@link https://reglejs.dev/core-concepts/ Documentation}
710
604
  */
711
- type JoinDiscriminatedUnions<TUnion extends unknown> = HasNamedKeys<TUnion> extends true ? isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>[number]>> & Pick<NormalizeUnion<NonNullable<TUnion>>, keyof NormalizeUnion<NonNullable<TUnion>>>> : TUnion : TUnion;
605
+ declare const useRegle: useRegleFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>, {}, {}>;
712
606
  /**
713
- * Combine all members of a union type on one level and not nested.
607
+ * @internal
608
+ * This is the internal function that creates the root storage for the Regle instance.
609
+ * This allows shared logic between all `useRegle` like composables
714
610
  */
715
- type LazyJoinDiscriminatedUnions<TUnion extends unknown> = isRecordLiteral<TUnion> extends true ? Prettify<Partial<UnionToIntersection<RemoveCommonKey<UnionToTuple<TUnion>, keyof NonNullable<TUnion>>[number]>> & Pick<NonNullable<TUnion>, keyof NonNullable<TUnion>>> : TUnion;
716
- type RemoveCommonKey<T extends readonly any[], K$1 extends PropertyKey> = T extends [infer F, ...infer R] ? [Prettify<Omit<F, K$1>>, ...RemoveCommonKey<R, K$1>] : [];
611
+ declare function useRootStorage({
612
+ initialState,
613
+ originalState,
614
+ options,
615
+ scopeRules,
616
+ state,
617
+ customRules,
618
+ shortcuts,
619
+ schemaErrors,
620
+ schemaMode,
621
+ onValidate,
622
+ overrides
623
+ }: {
624
+ scopeRules: Ref<$InternalReglePartialRuleTree>;
625
+ state: Ref<Record<string, any> | PrimitiveTypes>;
626
+ options: ResolvedRegleBehaviourOptions;
627
+ initialState: Ref<Record<string, any> | PrimitiveTypes>;
628
+ originalState: Record<string, any> | PrimitiveTypes;
629
+ customRules?: () => CustomRulesDeclarationTree;
630
+ shortcuts: RegleShortcutDefinition | undefined;
631
+ schemaErrors?: Ref<any | undefined>;
632
+ schemaMode?: boolean;
633
+ onValidate?: () => Promise<$InternalRegleResult>;
634
+ overrides: GlobalConfigOverrides | undefined;
635
+ }): {
636
+ regle: $InternalRegleStatusType | undefined;
637
+ };
717
638
  /**
718
- * Transforms a union and apply undefined values to non-present keys to support intersection
639
+ * Converts a nested `$errors` object to a flat array of error strings.
640
+ * Useful for displaying a complete list of form errors or counting total errors.
641
+ *
642
+ * With the `includePath` option, returns errors in Standard Schema Issue format
643
+ * including the path to each error field.
644
+ *
645
+ * @param errors - The `$errors` object from a Regle instance (e.g., `r$.$errors`)
646
+ * @param options - Configuration options
647
+ * @param options.includePath - If true, returns Standard Schema Issues with paths
648
+ * @returns Array of error strings, or Standard Schema Issues if `includePath` is true
649
+ *
650
+ * @example
651
+ * ```ts
652
+ * import { flatErrors, useRegle } from '@regle/core';
653
+ * import { required, email, minLength } from '@regle/rules';
654
+ *
655
+ * const { r$ } = useRegle(
656
+ * { name: '', email: 'invalid' },
657
+ * { name: { required, minLength: minLength(3) }, email: { email } }
658
+ * );
659
+ *
660
+ * await r$.$validate();
661
+ *
662
+ * // Get flat array of error messages
663
+ * const errors = flatErrors(r$.$errors);
664
+ * // ['This field is required', 'Value must be a valid email address']
665
+ *
666
+ * // Get errors with paths (Standard Schema format)
667
+ * const issues = flatErrors(r$.$errors, { includePath: true });
668
+ * // [{ message: 'This field is required', path: ['name'] }, ...]
669
+ * ```
670
+ *
671
+ * @see {@link https://reglejs.dev/core-concepts/displaying-errors#display-flat-errors Documentation}
719
672
  */
720
- type NormalizeUnion<TUnion> = RetrieveUnionUnknownValues<NonNullable<UnionToTuple<TUnion>>, RetrieveUnionUnknownKeysOf<NonNullable<UnionToTuple<TUnion>>>[number]>[number];
673
+ declare function flatErrors(errors: $InternalRegleErrors, options: {
674
+ includePath: true;
675
+ }): StandardSchemaV1.Issue[];
676
+ declare function flatErrors(errors: $InternalRegleErrors, options?: {
677
+ includePath?: false;
678
+ }): string[];
679
+ type useRulesFnOptions<TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 = InferInput<TRules$1>> = Partial<DeepMaybeRef<RegleBehaviourOptions>> & LocalRegleBehaviourOptions<JoinDiscriminatedUnions<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}>, TState$1 extends Record<string, any> ? (TRules$1 extends Record<string, any> ? TRules$1 : {}) : {}, TValidationGroups>;
680
+ interface useRulesFn<TCustomRules extends Partial<ExtendedRulesDeclarations>, TShortcuts extends RegleShortcutDefinition<any> = never> {
681
+ <TRules$1 extends RegleUnknownRulesTree | RegleRuleDecl, TDecl extends RegleRuleDecl<NonNullable<TState$1>, Partial<ExtendedRulesDeclarations> & TCustomRules>, TValidationGroups extends Record<string, RegleValidationGroupEntry[]>, TState$1 extends Record<string, any> = InferInput<TRules$1>>(rulesFactory: TState$1 extends Record<string, any> ? MaybeRef<TRules$1> | ((...args: any[]) => TRules$1) : {}, options?: useRulesFnOptions<TRules$1, TValidationGroups, TState$1>): NonNullable<TState$1> extends PrimitiveTypes ? Raw<RegleFieldStatus<NonNullable<TState$1>, TDecl, TShortcuts>> & StandardSchemaV1<TState$1> : Raw<RegleRoot<TState$1 extends Record<string, any> ? Unwrap<TState$1> : {}, TRules$1 extends Record<string, any> ? TRules$1 : {}, TValidationGroups, TShortcuts>> & StandardSchemaV1<TState$1>;
682
+ __config?: GlobalConfigOptions<TCustomRules, TShortcuts>;
683
+ }
721
684
  /**
722
- * Combine all union values to be able to get even the normally "never" values, act as an intersection type
685
+ * `useRules` is a variant of `useRegle` that doesn't require you to provide initial state.
686
+ * It creates an empty state based on your rules structure and implements the Standard Schema spec.
687
+ *
688
+ * This is useful when you want to define validation rules first and infer the state type from them.
689
+ *
690
+ * @param rules - Your validation rules object
691
+ * @param modifiers - Optional configuration to customize regle behavior
692
+ * @returns The reactive validation state (implements StandardSchemaV1)
693
+ *
694
+ * @example
695
+ * ```ts
696
+ * import { useRules, type InferInput } from '@regle/core';
697
+ * import { required, string, email } from '@regle/rules';
698
+ *
699
+ * const r$ = useRules({
700
+ * name: { required, string },
701
+ * email: { required, email }
702
+ * });
703
+ *
704
+ * // State is automatically created and typed
705
+ * r$.$value.name // string | null
706
+ * r$.$value.email // string | null
707
+ *
708
+ * // Can be used with Standard Schema compatible libraries
709
+ * const result = await r$['~standard'].validate({ name: '', email: '' });
710
+ * ```
711
+ *
712
+ * @see {@link https://reglejs.dev/common-usage/standard-schema#userules Documentation}
723
713
  */
724
- type RetrieveUnionUnknownValues<T extends readonly any[], TKeys extends string> = T extends [infer F extends Record<string, any>, ...infer R] ? [{ [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? never : K]?: GetMaybeObjectValue<F, K> } & { [K in TKeys as GetMaybeObjectValue<F, K> extends NonUndefined<GetMaybeObjectValue<F, K>> ? K : never]: GetMaybeObjectValue<F, K> }, ...RetrieveUnionUnknownValues<R, TKeys>] : [];
714
+ declare const useRules: useRulesFn<Partial<ExtendedRulesDeclarations>, RegleShortcutDefinition<any>>;
725
715
  /**
726
- * Get all possible keys from a union, even the ones present only on one union
716
+ * Marks a value as static and treats the constructor as a regular raw Field.
717
+ * @param value - The value to mark as static.
718
+ * @returns The marked value.
719
+ * @example
720
+ * ```ts
721
+ * const StaticDecimal = markStatic(Decimal);
722
+ * const StaticBigWrapper = markStatic(BigWrapper);
723
+ * ```
727
724
  */
728
- type RetrieveUnionUnknownKeysOf<T extends readonly any[]> = T extends [infer F, ...infer R] ? [keyof F, ...RetrieveUnionUnknownKeysOf<R>] : [];
725
+ declare function markStatic<T extends object>(value: T): T extends RegleStaticImpl<unknown> ? T : RegleStatic<T>;
729
726
  /**
730
- * Get item value from object, otherwise fallback to undefined. Avoid TS to not be able to infer keys not present on all unions
727
+ * Infer type of the `r$` of any function returning a regle instance
731
728
  */
732
- type GetMaybeObjectValue<O extends Record<string, any>, K$1 extends string> = K$1 extends keyof O ? O[K$1] : undefined;
733
- type RemoveIndexSignature<T> = { [K in keyof T as string extends K ? never : number extends K ? never : symbol extends K ? never : K]: T[K] };
729
+ type InferRegleRoot<T extends (...args: any[]) => SuperCompatibleRegle> = T extends ((...args: any[]) => infer U) ? U extends SuperCompatibleRegle ? U['r$'] : never : never;
734
730
  /**
735
- * Merge every boolean property into a single boolean.
731
+ * Infer custom rules declared in a global configuration
736
732
  */
737
- type MergePropsIntoRequiredBooleans<TObject extends Record<string, any>> = { [K in keyof TObject]-?: TObject[K] extends NonNullable<TObject[K]> ? true : false }[keyof TObject];
733
+ type InferRegleRules<T extends useRegleFn<any, any>> = T extends useRegleFn<infer U, any> ? UnwrapRuleTree<Partial<DefaultValidators>> & UnwrapRuleTree<Partial<U>> : {};
738
734
  /**
739
- * Ensure that if at least one prop is required, the "prop" object will be required too
735
+ * Infer custom shortcuts declared in a global configuration
740
736
  */
741
- type HaveAnyRequiredProps<TObject extends Record<string, any>> = [TObject] extends [never] ? false : TObject extends Record<string, any> ? MergePropsIntoRequiredBooleans<TObject> extends false ? false : true : false;
742
- type EnumType<T extends Record<string, unknown>> = T[keyof T];
743
- type EnumLike = {
744
- [k: string]: string | number;
745
- [nu: number]: string;
746
- };
747
- type MaybeRefOrComputedRef<T extends any> = MaybeRef<T> | ComputedRef<T>;
748
- type UnwrapMaybeRef<T extends MaybeRef<any> | DeepReactiveState<any>> = T extends Ref<any> ? UnwrapRef<T> : UnwrapNestedRefs<T>;
749
- type TupleToPlainObj<T> = { [I in keyof T & `${number}`]: T[I] };
750
- type HasNamedKeys<T> = IsUnion<T> extends true ? ProcessHasNamedKeys<LazyJoinDiscriminatedUnions<T>> : ProcessHasNamedKeys<T>;
751
- type ProcessHasNamedKeys<T> = { [K in keyof NonNullable<T>]: K extends string ? (string extends K ? never : K) : never }[keyof NonNullable<T>] extends never ? false : true;
737
+ type InferRegleShortcuts<T extends useRegleFn<any, any>> = T extends useRegleFn<any, infer U> ? U : {};
752
738
  /**
753
- * Convert a nested object to a deeply nested partial object.
739
+ * Extract a set rules and setting them as required
754
740
  */
755
- type DeepPartial<T> = T extends Array<infer U> ? Array<DeepPartial<U>> : T extends Date | File | RegleStaticImpl<unknown> ? T : T extends Record<string, any> ? { [K in keyof T]?: DeepPartial<T[K]> | undefined } : T | undefined;
741
+ type RegleEnforceRequiredRules<TRules$1 extends keyof DefaultValidators> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: UnwrapRuleWithParams<DefaultValidators[K]> };
742
+ /**
743
+ * Extract a set of custom rules from a global configuration and setting them as required
744
+
745
+ */
746
+ type RegleEnforceCustomRequiredRules<T extends useRegleFn<any, any>, TRules$1 extends keyof InferRegleRules<T>> = Omit<Partial<DefaultValidatorsTree>, TRules$1> & { [K in TRules$1]-?: T extends useRegleFn<any, any> ? K extends keyof InferRegleRules<T> ? NonNullable<UnwrapRuleWithParams<InferRegleRules<T>[K]>> : never : K extends keyof T ? NonNullable<T[K]> : never };
747
+ /**
748
+ * Extract custom rules and custom shortcuts and apply them to a RegleFieldStatus type
749
+ */
750
+ type RegleCustomFieldStatus<T extends useRegleFn<any, any>, TState$1 extends unknown = any, TRules$1 extends keyof InferRegleRules<T> = never> = RegleFieldStatus<TState$1, [TRules$1] extends [never] ? Partial<InferRegleRules<T>> : RegleEnforceCustomRequiredRules<T, TRules$1>, InferRegleShortcuts<T>>;
756
751
  /**
757
752
  * Infer safe output type from a rules object and it's original state type
758
753
  *
@@ -1991,4 +1986,4 @@ declare function refineRules<TRules$1 extends RegleUnknownRulesTree, TRefinement
1991
1986
  * @see {@link https://reglejs.dev/introduction/devtools Documentation}
1992
1987
  */
1993
1988
  declare const RegleVuePlugin: Plugin;
1994
- export { type $InternalRegleStatus, type AllRulesDeclarations, type ArrayElement, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepPartial, type DeepReactiveState, type DefaultValidatorsTree, type ExtendedRulesDeclarations, type FormRuleDeclaration, type GlobalConfigOverrides, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferOutput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleSettings, type InferRegleShortcuts, type InferRegleStatusType, type InferRegleValidationResult, type InferSafeOutput, type InferValidOutput, type InlineRuleDeclaration, InternalRuleType, type IsRegleStatic, type JoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NarrowVariantExtracts, type NarrowVariantFieldExtracts, type NoInferLegacy, type NonEmptyTuple, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, type RegleLike, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleRuleWithParamsDefinitionInput, type RegleShortcutDefinition, type RegleSingleField, type RegleStatic, type RegleStaticImpl, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, RegleVuePlugin, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type TupleToPlainObj, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UnwrapStatic, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, type isEditedHandlerFn, markStatic, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useRules, type useRulesFn, useScopedRegle, variantToRef };
1989
+ export { type $InternalRegleStatus, type AllRulesDeclarations, type ArrayElement, type CommonAlphaOptions, type CommonComparisonOptions, type CreateScopedUseRegleOptions, type DeepMaybeRef, type DeepPartial, type DeepReactiveState, type DefaultValidatorsTree, type DumbJoinDiscriminatedUnions, type ExtendedRulesDeclarations, type FormRuleDeclaration, type GlobalConfigOverrides, type HasNamedKeys, type HaveAnyRequiredProps, type InferInput, type InferOutput, type InferRegleRoot, type InferRegleRule, type InferRegleRules, type InferRegleSettings, type InferRegleShortcuts, type InferRegleStatusType, type InferRegleValidationResult, type InferSafeOutput, type InferValidOutput, type InlineRuleDeclaration, InternalRuleType, type IsRegleStatic, type JoinDiscriminatedUnions, type LazyJoinDiscriminatedUnions, type LocalRegleBehaviourOptions, type Maybe, type MaybeInput, type MaybeOutput, type MaybeReadonly, type MaybeVariantStatus, type MergedRegles, type MergedScopedRegles, type NarrowVariant, type NarrowVariantExtracts, type NarrowVariantFieldExtracts, type NoInferLegacy, type NonEmptyTuple, type PrimitiveTypes, type Regle, type RegleBehaviourOptions, type RegleCollectionErrors, type RegleCollectionRuleDecl, type RegleCollectionRuleDefinition, type RegleCollectionStatus, type RegleCommonStatus, type RegleComputedRules, type RegleCustomFieldStatus, type RegleEnforceCustomRequiredRules, type RegleEnforceRequiredRules, type RegleErrorTree, type RegleExternalCollectionErrors, type RegleExternalErrorTree, type RegleExternalSchemaErrorTree, type RegleFieldIssue, type RegleFieldStatus, type RegleFormPropertyType, type RegleInternalRuleDefs, type RegleIssuesTree, type RegleLike, type ReglePartialRuleTree, type RegleResult, type RegleRoot, type RegleRuleCore, type RegleRuleDecl, type RegleRuleDefinition, type RegleRuleDefinitionProcessor, type RegleRuleDefinitionWithMetadataProcessor, type RegleRuleInit, type RegleRuleMetadataConsumer, type RegleRuleMetadataDefinition, type RegleRuleMetadataExtended, type RegleRuleRaw, type RegleRuleStatus, type RegleRuleTypeReturn, type RegleRuleWithParamsDefinition, type RegleRuleWithParamsDefinitionInput, type RegleShortcutDefinition, type RegleSingleField, type RegleStatic, type RegleStaticImpl, type RegleStatus, type RegleUniversalParams, type RegleUnknownRulesTree, type RegleValidationErrors, type RegleValidationGroupEntry, type RegleValidationGroupOutput, type RegleRuleTree as RegleValidationTree, RegleVuePlugin, type ResolvedRegleBehaviourOptions, type ScopedInstancesRecord, type ScopedInstancesRecordLike, type SuperCompatibleRegle, type SuperCompatibleRegleCollectionErrors, type SuperCompatibleRegleCollectionStatus, type SuperCompatibleRegleFieldStatus, type SuperCompatibleRegleResult, type SuperCompatibleRegleRoot, type SuperCompatibleRegleRuleStatus, type SuperCompatibleRegleStatus, type TupleToPlainObj, type Unwrap, type UnwrapRegleUniversalParams, type UnwrapRuleWithParams, type UnwrapStatic, type UseScopedRegleOptions, createRule, createScopedUseRegle, createVariant, defineRegleConfig, defineRules, extendRegleConfig, flatErrors, inferRules, type inferRulesFn, type isEditedHandlerFn, markStatic, mergeRegles, narrowVariant, refineRules, unwrapRuleParameters, useCollectScope, type useCollectScopeFn, useRegle, type useRegleFn, useRootStorage, useRules, type useRulesFn, useScopedRegle, variantToRef };