/** * @regle/schemas v1.30.1 * (c) 2026 Victor Garcia * @license MIT */ import { ArrayElement, CreateScopedUseRegleOptions, CustomCollectionProperties, CustomFieldProperties, CustomNestedProperties, DeepMaybeRef, DeepPartial, DeepReactiveState, GlobalConfigOverrides, HasNamedKeys, HaveAnyRequiredProps, JoinDiscriminatedUnions, LocalRegleBehaviourOptions, Maybe, MaybeOutput, MergedScopedRegles, NoInferLegacy, PrimitiveTypes, RegleBehaviourOptions, RegleCollectionErrors, RegleCommonStatus, RegleErrorTree, RegleExternalCollectionErrors, RegleExternalSchemaErrorTree, RegleExternalSchemaIssueTree, RegleFieldIssue, RegleIssuesTree, RegleRuleStatus, RegleShortcutDefinition, RegleStaticImpl, TupleToPlainObj, UseScopedRegleOptions, useCollectScopeFn } from "@regle/core"; import { MaybeRef, MaybeRefOrGetter, Raw, UnwrapNestedRefs } from "vue"; import { StandardSchemaV1 } from "@standard-schema/spec"; import { EmptyObject, IsAny, IsUnion, IsUnknown, UnionToTuple } from "type-fest"; type MaybeSchemaVariantStatus | undefined = Record, TOutput extends Record | undefined = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TRoot extends boolean = false> = IsUnion> extends true ? Omit, '$fields'> & { $fields: ProcessChildrenFields[keyof ProcessChildrenFields]; } & (HasNamedKeys extends true ? ProcessChildrenFields[keyof ProcessChildrenFields] : {}) : RegleSchemaStatus; type ProcessChildrenFields | undefined, TOutput = TInput, TShortcuts extends RegleShortcutDefinition = {}> = { [TIndex in keyof TupleToPlainObj>]: TIndex extends `${infer TIndexInt extends number}` ? { [TKey in keyof UnionToTuple[TIndexInt] as NonNullable[TIndexInt]>[TKey] extends UnionToTuple[TIndexInt][TKey] ? TKey : never]-?: InferRegleSchemaStatusType[TIndexInt]>[TKey], NonNullable[TIndexInt]>[TKey], TShortcuts>; } & { [TKey in keyof UnionToTuple[TIndexInt] as NonNullable[TIndexInt]>[TKey] extends UnionToTuple[TIndexInt][TKey] ? never : TKey]?: InferRegleSchemaStatusType[TIndexInt]>[TKey], NonNullable[TIndexInt]>[TKey], TShortcuts>; } : {}; }; type RegleSchema, TOutput extends Record = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record = {}> = { /** * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information. * * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties} */ r$: Raw>; } & TAdditionalReturnProperties; type RegleSingleFieldSchema, TOutput = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, TAdditionalReturnProperties extends Record = {}> = { /** * r$ is a reactive object containing the values, errors, dirty state and all the necessary validations properties you'll need to display information. * * To see the list of properties: {@link https://reglejs.dev/core-concepts/validation-properties} */ r$: Raw & { /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */ $validate: (forceValues?: TInput extends EmptyObject ? any : HasNamedKeys extends true ? TInput : any) => Promise>>; }>; } & TAdditionalReturnProperties; type RegleSchemaResult = { valid: false; data: DeepPartial; issues: RegleIssuesTree; errors: RegleErrorTree; } | { valid: true; data: TSchema; issues: EmptyObject; errors: EmptyObject; }; type ProcessNestedFields | undefined, TOutput extends Record | undefined = TInput, TShortcuts extends RegleShortcutDefinition = {}> = HasNamedKeys extends true ? { readonly [TKey in keyof JoinDiscriminatedUnions]: TKey extends keyof JoinDiscriminatedUnions ? InferRegleSchemaStatusType[TKey]>, TKey extends keyof JoinDiscriminatedUnions ? NonNullable[TKey]> : undefined, TShortcuts> : never; } & { readonly [TKey in keyof JoinDiscriminatedUnions as TKey extends keyof JoinDiscriminatedUnions ? JoinDiscriminatedUnions[TKey] extends NonNullable[TKey]> ? TKey : never : never]-?: TKey extends keyof JoinDiscriminatedUnions ? InferRegleSchemaStatusType[TKey]>, TKey extends keyof JoinDiscriminatedUnions ? NonNullable[TKey]> : undefined, TShortcuts> : never; } : { [x: string]: RegleSchemaCommonStatus; }; /** * @public */ type RegleSchemaStatus | undefined = Record, TOutput extends Record | undefined = TInput, TSchema extends StandardSchemaV1 = StandardSchemaV1, TShortcuts extends RegleShortcutDefinition = {}, IsRoot extends boolean = false> = Omit, (IsRoot extends false ? '$pending' : '') | '$issues' | '$errors'> & { /** Represents all the children of your object. You can access any nested child at any depth to get the relevant data you need for your form. */ readonly $fields: ProcessNestedFields, JoinDiscriminatedUnions, TShortcuts>; /** Collection of all issues, collected for all children properties and nested forms. * * Only contains errors from properties where $dirty equals true. */ readonly $issues: RegleIssuesTree; /** Collection of all the error messages, collected for all children properties and nested forms. * * Only contains errors from properties where $dirty equals true. */ readonly $errors: RegleErrorTree; readonly $output: TOutput; /** Collection of all the error messages, collected for all children properties. */ readonly $silentErrors: RegleErrorTree; /** Sets the external errors for the field. */ $setExternalErrors(errors: RegleExternalSchemaErrorTree): void; /** Sets the external issues for the field. */ $setExternalIssues(issues: RegleExternalSchemaIssueTree): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */ $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial; } & (HasNamedKeys extends true ? ProcessNestedFields, JoinDiscriminatedUnions, TShortcuts> : {}) & (IsRoot extends true ? { /** Sets all properties as dirty, triggering all rules. It returns a promise that will either resolve to false or a type safe copy of your form state. Values that had the required rule will be transformed into a non-nullable value (type only). */ $validate: (forceValues?: TInput extends EmptyObject ? (HasNamedKeys extends true ? TInput : any) : TInput) => Promise>>; } : {}) & CustomNestedProperties & ([TShortcuts['nested']] extends [never] ? {} : { [K in keyof TShortcuts['nested']]: ReturnType[K]>; }); /** * @public */ type InferRegleSchemaStatusType = IsAny extends true ? RegleSchemaFieldStatus : IsUnknown extends true ? RegleCommonStatus : NonNullable extends Array ? RegleSchemaCollectionStatus, NonNullable, TShortcuts> : NonNullable extends Date | File ? RegleSchemaFieldStatus : unknown extends TInput ? RegleSchemaFieldStatus : NonNullable extends Record ? NonNullable> extends RegleStaticImpl ? RegleSchemaFieldStatus, Raw, TShortcuts> : MaybeSchemaVariantStatus extends Record ? NonNullable : {}, NonNullable extends Record ? NonNullable : {}, StandardSchemaV1, TShortcuts> : RegleSchemaFieldStatus; /** * @public */ type RegleSchemaFieldStatus = Omit, '$pending' | '$value' | '$silentValue' | '$initialValue' | '$originalValue' | '$issues' | '$errors'> & { /** A reference to the original validated model. It can be used to bind your form with v-model.*/ $value: MaybeOutput>; /** $value variant that will not "touch" the field and update the value silently, running only the rules, so you can easily swap values without impacting user interaction. */ $silentValue: MaybeOutput>; /** * This value reflect the current initial value of the field. * The initial value is different than the original value as the initial value can be mutated when using `$reset`. */ readonly $initialValue: MaybeOutput>; /** * This value reflect the original value of the field at original call. This can't be mutated */ readonly $originalValue: MaybeOutput>; /** Collection of all the error messages, collected for all children properties and nested forms. * * Only contains errors from properties where $dirty equals true. */ readonly $errors: string[]; /** Collection of all the error messages, collected for all children properties and nested forms. */ readonly $silentErrors: string[]; /** * Collect all metadata of validators, Only contains errors from properties where $dirty equals true. */ readonly $issues: (RegleFieldIssue & StandardSchemaV1.Issue)[]; /** * Collect all metadata of validators, including the error message. */ readonly $silentIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[]; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */ readonly $externalErrors: string[]; /** Stores external issues of the current field */ readonly $externalIssues: (RegleFieldIssue & StandardSchemaV1.Issue)[]; /** Represents the inactive status. Is true when this state have empty rules */ readonly $inactive: boolean; /** This is reactive tree containing all the declared rules of your field. To know more about the rule properties check the rules properties section */ readonly $rules: { [`~validator`]: RegleRuleStatus extends true ? any : TInput, []>; }; readonly $output: TOutput; /** Sets the external errors for the field. */ $setExternalErrors(errors: string[]): void; /** Sets the external issues for the field. */ $setExternalIssues(issues: (RegleFieldIssue & StandardSchemaV1.Issue)[]): void; /** Will return a copy of your state with only the fields that are dirty. By default it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */ $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial; } & CustomFieldProperties & ([TShortcuts['fields']] extends [never] ? {} : { [K in keyof TShortcuts['fields']]: ReturnType[K]>; }); type RegleSchemaCommonStatus = Omit, '$pending'>; /** * @public */ type RegleSchemaCollectionStatus = Omit, '$issues' | '$errors' | '$silentErrors'> & { /** Collection of status for every item in your collection. Each item will be a field you can access or iterate to display your elements. */ readonly $each: Array, ArrayElement, TShortcuts>>; /** Represents the status of the collection itself. You can have validation rules on the array like minLength, this field represents the isolated status of the collection. */ readonly $self: RegleSchemaFieldStatus; /** * Collection of all the issues, collected for all children properties and nested forms. * * Only contains issues from properties where $dirty equals true. */ readonly $issues: RegleCollectionErrors; /** Collection of all the error messages, collected for all children properties and nested forms. * * Only contains errors from properties where $dirty equals true. */ readonly $errors: RegleCollectionErrors; /** Collection of all the error messages, collected for all children properties and nested forms. */ readonly $silentErrors: RegleCollectionErrors; readonly $output: TOutput; /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */ /** Sets the external errors for the field. */ $setExternalErrors(errors: RegleExternalCollectionErrors): void; /** Sets the external issues for the field. */ $setExternalIssues(errors: RegleExternalCollectionErrors): void; /** Will return a copy of your state with only the fields that are dirty. By default, it will filter out nullish values or objects, but you can override it with the first parameter $extractDirtyFields(false). */ $extractDirtyFields: (filterNullishValues?: boolean) => DeepPartial; } & CustomCollectionProperties & ([TShortcuts['collections']] extends [never] ? {} : { [K in keyof TShortcuts['collections']]: ReturnType[K]>; }); type RegleSchemaBehaviourOptions = { /** * Settings for applying transforms and default to the current state */ syncState?: { /** * Applies every transform on every update to the state */ onUpdate?: boolean; /** * Applies every transform only when calling `$validate` */ onValidate?: boolean; }; }; type useRegleSchemaFnOptions, TAdditionalOptions extends Record> = Omit> & LocalRegleBehaviourOptions, 'validationGroups' | 'lazy'> & RegleSchemaBehaviourOptions & TAdditionalOptions; interface useRegleSchemaFn = never, TAdditionalReturnProperties extends Record = {}, TAdditionalOptions extends Record = {}> { | undefined, TOutput extends StandardSchemaV1.InferOutput = StandardSchemaV1.InferOutput>(...params: [state: MaybeRef>> | DeepReactiveState>>, rulesFactory: MaybeRef, ...(HaveAnyRequiredProps>, TAdditionalOptions>> extends true ? [options: useRegleSchemaFnOptions>, TAdditionalOptions>] : [options?: useRegleSchemaFnOptions>, TAdditionalOptions>])]): NonNullable extends PrimitiveTypes ? RegleSingleFieldSchema, NonNullable, TSchema, TShortcuts, TAdditionalReturnProperties> : RegleSchema>, UnwrapNestedRefs>, TSchema, TShortcuts, TAdditionalReturnProperties>; } /** * `useRegleSchema` enables validation using Standard Schema compatible libraries * like Zod, Valibot, or ArkType. * * @param state - Your form data (plain object, ref, reactive object, or structure with nested refs) * @param schema - A Standard Schema compliant schema (Zod, Valibot, ArkType, etc.) * @param modifiers - Optional configuration to customize regle behavior * @returns An object containing `r$` - the reactive validation state * * @example * ```ts * import { useRegleSchema } from '@regle/schemas'; * import * as v from 'valibot'; * * // With Valibot * const { r$ } = useRegleSchema( * { name: '', email: '' }, * v.object({ * name: v.pipe(v.string(), v.minLength(3)), * email: v.pipe(v.string(), v.email()) * }) * ); * * // With Zod * import { z } from 'zod'; * * const { r$ } = useRegleSchema( * { name: '' }, * z.object({ * name: z.string().min(3) * }) * ); * * // Access validation state * r$.$valid // Whether all validations pass * r$.$value // The current form values * r$.name.$errors // Errors for the name field * ``` * * @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation} */ export declare const useRegleSchema: useRegleSchemaFn, {}, {}>; /** * Force a schema validation to re-run when specified dependencies change. * Useful when your schema depends on reactive values that aren't automatically tracked. * * @param schema - The Standard Schema to wrap * @param _depsArray - Array of reactive dependencies (their values will trigger re-validation) * @returns The same schema (passthrough) * * @example * ```ts * import { withDeps, useRegleSchema } from '@regle/schemas'; * import * as v from 'valibot'; * * const compareValue = ref(''); * * const schema = computed(() => v.object({ * name: withDeps( * v.pipe( * v.string(), * v.check((value) => value === compareValue.value) * ), * [compareValue.value] // Re-validate when this changes * ) * })); * * const { r$ } = useRegleSchema({ name: '' }, schema); * ``` * * @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation} */ export declare function withDeps(schema: TSchema, _depsArray: [...TParams]): TSchema; interface inferSchemaFn { | undefined>(state: MaybeRef> | DeepReactiveState>, rulesFactory: MaybeRef): NoInferLegacy; } /** * Type helper to provide autocomplete and type-checking for your schema. * Returns the schema without any processing - useful with computed schemas. * * @param state - The state reference * @param schema - Your Standard Schema (Zod, Valibot, ArkType, etc.) * @returns The schema (passthrough) * * @example * ```ts * import { inferSchema, useRegleSchema } from '@regle/schemas'; * import { z } from 'zod'; * * const state = ref({ name: '' }); * * // inferSchema preserves TypeScript autocompletion * const schema = computed(() => { * return inferSchema(state, z.object({ * name: z.string().min(2) * })); * }); * * const { r$ } = useRegleSchema(state, schema); * ``` * * @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation} */ export declare const inferSchema: inferSchemaFn; /** * Define a global configuration for `useRegleSchema`. * * Features: * - Define global modifiers (lazy, rewardEarly, etc.) * - Define shortcuts for common validation patterns * * @param options - Configuration options * @param options.modifiers - Global behavior modifiers * @param options.shortcuts - Reusable validation shortcuts * @returns Object containing typed `useRegleSchema` and `inferSchema` functions * * @example * ```ts * import { defineRegleSchemaConfig } from '@regle/schemas'; * * export const { useRegleSchema, inferSchema } = defineRegleSchemaConfig({ * modifiers: { * lazy: true, * rewardEarly: true * } * }); * ``` * * @see {@link https://reglejs.dev/integrations/schemas-libraries Documentation} */ export declare function defineRegleSchemaConfig({ modifiers, shortcuts, overrides }: { modifiers?: RegleBehaviourOptions; shortcuts?: TShortcuts; overrides?: GlobalConfigOverrides; }): { useRegleSchema: useRegleSchemaFn; inferSchema: inferSchemaFn; }; type CreateScopedUseRegleSchemaOptions, TAsRecord extends boolean> = Omit, 'customUseRegle'> & { /** * Inject a global configuration to the exported composables to keep your translations and typings */ customUseRegle?: TCustomRegle; }; /** * Create a scoped validation system for schema-based validation. * Similar to `createScopedUseRegle` but for use with Standard Schema libraries. * * @param options - Configuration options * @param options.customUseRegle - Custom useRegleSchema instance with your global config * @param options.customStore - External ref to store collected instances * @param options.asRecord - If true, collect instances in a Record (requires `id` param) * @returns Object containing `useScopedRegle` and `useCollectScope` functions * * @example * ```ts * import { createScopedUseRegleSchema, defineRegleSchemaConfig } from '@regle/schemas'; * * const { useRegleSchema } = defineRegleSchemaConfig({...}); * * export const { useScopedRegle, useCollectScope } = createScopedUseRegleSchema({ * customUseRegle: useRegleSchema * }); * ``` * * @see {@link https://reglejs.dev/advanced-usage/scoped-validation Documentation} */ export declare const createScopedUseRegleSchema: = TCustomRegle extends useRegleSchemaFn ? useRegleSchemaFn void; register: () => void; }, UseScopedRegleOptions> : useRegleSchemaFn void; register: () => void; }, UseScopedRegleOptions>>(options?: CreateScopedUseRegleSchemaOptions) => { useScopedRegle: TReturnedRegle; useCollectScope: useCollectScopeFn; }; declare const useCollectSchemaScope: [] = Record[]>(namespace?: MaybeRefOrGetter) => { r$: MergedScopedRegles; }; declare const useScopedRegleSchema: useRegleSchemaFn, {}, {}>; declare module '@regle/core' { interface NarrowVariantExtracts { 'regle-schemas-status': RegleSchemaStatus; 'regle-schemas-collection-status': RegleSchemaCollectionStatus; } interface NarrowVariantFieldExtracts { 'regle-schemas-field-status': RegleSchemaFieldStatus; } } export { type InferRegleSchemaStatusType, type MaybeSchemaVariantStatus, type RegleSchema, type RegleSchemaBehaviourOptions, type RegleSchemaCollectionStatus, type RegleSchemaCommonStatus, type RegleSchemaFieldStatus, type RegleSchemaResult, type RegleSchemaStatus, type RegleSingleFieldSchema, useCollectSchemaScope, useScopedRegleSchema };