import { CommonAlphaOptions, CommonComparisonOptions, FormRuleDeclaration, InlineRuleDeclaration, Maybe, MaybeInput, MaybeReadonly, RegleRuleDefinition, RegleRuleDefinitionWithMetadataProcessor, RegleRuleMetadataConsumer, RegleRuleMetadataDefinition, RegleRuleWithParamsDefinition, UnwrapRegleUniversalParams } from "@regle/core"; import { MaybeRef, MaybeRefOrGetter, Ref } from "vue"; //#region src/helpers/withMessage.d.ts /** * The withMessage wrapper lets you associate an error message with a rule. Pass your rule as the first argument and the error message as the second. * * ```ts * const { r$ } = useRegle({ name: '' }, { name: { customRule1: withMessage((value) => !!value, "Custom Error"), customRule2: withMessage(customRuleInlineWithMetaData, "Custom Error"), customRule3: withMessage( customRuleInlineWithMetaData, ({ $value, foo }) => `Custom Error: ${$value} ${foo}` ), } }) * ``` * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withmessage} */ declare function withMessage, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleWithParamsDefinition, newMessage: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleWithParamsDefinition; declare function withMessage, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleDefinition, newMessage: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleDefinition; declare function withMessage, TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: InlineRuleDeclaration, newMessage: RegleRuleDefinitionWithMetadataProcessor ? M : TReturn>, string | string[]>): RegleRuleDefinition ? M : TReturn>; declare function withMessage, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: (...args: any[]) => RegleRuleDefinition, newMessage: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleWithParamsDefinition; //#endregion //#region src/helpers/withTooltip.d.ts /** * The withTooltip wrapper allows you to display additional messages for your field that aren’t necessarily errors. Tooltips are aggregated and accessible via $fields.xxx.$tooltips . */ declare function withTooltip, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleWithParamsDefinition, newTooltip: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleWithParamsDefinition; declare function withTooltip, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleDefinition, newTooltip: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleDefinition; declare function withTooltip, TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: InlineRuleDeclaration, newTooltip: RegleRuleDefinitionWithMetadataProcessor ? M : TReturn>, string | string[]>): RegleRuleDefinition ? M : TReturn>; //#endregion //#region src/helpers/withAsync.d.ts /** * withAsync works like withParams, but is specifically designed for async rules that depend on external values. * * ```ts *import { withAsync } from '@regle/rules'; const base = ref('foo'); const { r$ } = useRegle({ name: '' }, { name: { customRule: withAsync(async (value, param) => { await someAsyncCall(param) }, [base]) } }) * ``` * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withasync} */ declare function withAsync | (() => unknown))[] = [], TReturn extends Promise = Promise, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn)>(rule: InlineRuleDeclaration, depsArray?: [...TParams]): RegleRuleDefinition, true, TMetadata>; declare function withAsync(rule: RegleRuleWithParamsDefinition, depsArray?: [...TParams]): RegleRuleWithParamsDefinition; //#endregion //#region src/helpers/withParams.d.ts /** * The withParams wrapper allows your rule to depend on external parameters, such as a reactive property in your component or store. * * By default, useRegle observes changes automatically when rules are defined using getter functions or computed properties. * * ```ts * import { withParams } from '@regle/rules'; const base = ref('foo'); const { r$ } = useRegle({ name: '' }, { name: { customRule: withParams((value, param) => value === param, [base]), // or customRule: withParams((value, param) => value === param, [() => base.value]), } }) * ``` * Docs: {@link https://reglejs.dev/core-concepts/rules/rule-wrappers#withparams} */ declare function withParams | (() => unknown))[] = [], TReturn extends RegleRuleMetadataDefinition = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: InlineRuleDeclaration | RegleRuleDefinition, depsArray: [...TParams]): RegleRuleDefinition, TAsync, TMetadata>; declare function withParams ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleWithParamsDefinition, depsArray: [...TParams]): RegleRuleWithParamsDefinition; //#endregion //#region src/helpers/applyIf.d.ts /** * The applyIf operator is similar to requiredIf, but it can be used with any rule. It simplifies conditional rule declarations. */ declare function applyIf = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(_condition: MaybeRefOrGetter>, rule: InlineRuleDeclaration | RegleRuleDefinition): RegleRuleDefinition; //#endregion //#region src/helpers/ruleHelpers/isFilled.d.ts /** * This is almost a must have for optional fields. It checks if any value you provided is defined (including arrays and objects). You can base your validator result on this. * * isFilled also acts as a type guard. * * @param value - the target value * @param [considerEmptyArrayInvalid=true] - will return true if set to `false`. (default: `true`) */ declare function isFilled(value: T, considerEmptyArrayInvalid?: boolean): value is NonNullable; //#endregion //#region src/helpers/ruleHelpers/isNumber.d.ts /** * This is a type guard that will check if the passed value is a real Number. This also returns false for NaN, so this is better than typeof value === "number". */ declare function isNumber(value: unknown): value is number; //#endregion //#region src/helpers/ruleHelpers/matchRegex.d.ts /** * This utility can take multiple regular expressions as arguments. It checks the input's validity and tests it against the provided regex patterns. */ declare function matchRegex(_value: string | number | null | undefined, ...expr: RegExp[]): boolean; //#endregion //#region src/helpers/ruleHelpers/getSize.d.ts /** * This helper will return the length of any data type you pass. It works with strings, arrays, objects and numbers. */ declare function getSize(value: MaybeRef | number>): number; //#endregion //#region src/helpers/ruleHelpers/toNumber.d.ts /** * This utility converts any string (or number) into a number using the Number constructor. * * @returns ⚠️ Warning, returned value can be NaN */ declare function toNumber(argument: T): number; //#endregion //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/observable-like.d.ts declare global { // eslint-disable-next-line @typescript-eslint/consistent-type-definitions -- It has to be an `interface` so that it can be merged. interface SymbolConstructor { readonly observable: symbol; } } /** @remarks The TC39 observable proposal defines a `closed` property, but some implementations (such as xstream) do not as of 10/08/2021. As well, some guidance on making an `Observable` to not include `closed` property. @see https://github.com/tc39/proposal-observable/blob/master/src/Observable.js#L129-L130 @see https://github.com/staltz/xstream/blob/6c22580c1d84d69773ee4b0905df44ad464955b3/src/index.ts#L79-L85 @see https://github.com/benlesh/symbol-observable#making-an-object-observable @category Observable */ //#endregion //#region ../../node_modules/.pnpm/type-fest@4.41.0/node_modules/type-fest/source/empty-object.d.ts declare const emptyObjectSymbol: unique symbol; /** Represents a strictly empty plain object, the `{}` value. When you annotate something as the type `{}`, it can be anything except `null` and `undefined`. This means that you cannot use `{}` to represent an empty plain object ([read more](https://stackoverflow.com/questions/47339869/typescript-empty-object-and-any-difference/52193484#52193484)). @example ``` import type {EmptyObject} from 'type-fest'; // The following illustrates the problem with `{}`. const foo1: {} = {}; // Pass const foo2: {} = []; // Pass const foo3: {} = 42; // Pass const foo4: {} = {a: 1}; // Pass // With `EmptyObject` only the first case is valid. const bar1: EmptyObject = {}; // Pass const bar2: EmptyObject = 42; // Fail const bar3: EmptyObject = []; // Fail const bar4: EmptyObject = {a: 1}; // Fail ``` Unfortunately, `Record`, `Record` and `Record` do not work. See {@link https://github.com/sindresorhus/type-fest/issues/395 #395}. @category Object */ type EmptyObject = { [emptyObjectSymbol]?: never; }; /** Returns a `boolean` for whether the type is strictly equal to an empty plain object, the `{}` value. @example ``` import type {IsEmptyObject} from 'type-fest'; type Pass = IsEmptyObject<{}>; //=> true type Fail = IsEmptyObject<[]>; //=> false type Fail = IsEmptyObject; //=> false ``` @see EmptyObject @category Object */ //#endregion //#region ../shared/utils/isEmpty.d.ts /** * This is the inverse of isFilled. It will check if the value is in any way empty (including arrays and objects) * * isEmpty also acts as a type guard. * * @param value - the target value * @param [considerEmptyArrayInvalid=true] - will return false if set to `false`. (default: `true`) */ declare function isEmpty(value: unknown, considerEmptyArrayInvalid?: boolean): value is null | undefined | [] | EmptyObject; //#endregion //#region ../shared/utils/isDate.d.ts /** * This is a useful helper that can check if the provided value is a Date, it is used internally for date rules. This can also check strings. */ declare function isDate(value: unknown): value is Date; //#endregion //#region ../shared/utils/toDate.d.ts /** * This utility will coerce any string, number or Date value into a Date using the Date constructor. */ declare function toDate(argument: Maybe): Date; //#endregion //#region src/types/utils/params.utils.d.ts type ExtractValueFromRules = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition ? [V, ...ExtractValueFromRules] : F extends InlineRuleDeclaration ? [V, ...ExtractValueFromRules] : [F, ...ExtractValueFromRules] : []; type ExtractAsyncStatesFromRules = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition ? [A, ...ExtractValueFromRules] : F extends InlineRuleDeclaration ? [ReturnType extends Promise ? true : false, ...ExtractValueFromRules] : [F, ...ExtractValueFromRules] : []; type ExtractAsync = T extends [infer F, ...infer R] ? F extends true ? true : F extends false ? ExtractAsync : false : false; type GuessAsyncFromRules = ExtractAsync>; type ExtractParamsFromRules = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition ? [P, ...ExtractParamsFromRules] : [F, ...ExtractParamsFromRules] : []; type MetadataBase = { $valid: boolean; [x: string]: any; }; type ExtractMetaDataFromRules = T extends [infer F, ...infer R] ? F extends RegleRuleDefinition ? [M, ...ExtractMetaDataFromRules] : F extends InlineRuleDeclaration> ? [M, ...ExtractMetaDataFromRules] : [...ExtractMetaDataFromRules] : []; type ExtractMetadata = T extends [infer F, ...infer R] ? F & ExtractMetadata : {}; type GuessMetadataFromRules>> = TMeta extends EmptyObject ? boolean : TMeta; type FilterTuple = T extends [infer F, ...infer R] ? [F] extends [[]] ? [...FilterTuple] : [F, ...FilterTuple] : []; type UnwrapTuples = FilterTuple extends [infer U extends any[]] ? U : FilterTuple; //#endregion //#region src/helpers/and.d.ts /** * The and operator combines multiple rules and validates successfully only if all provided rules are valid. */ declare function and, ...FormRuleDeclaration[]]>(...rules: [...TRules]): RegleRuleDefinition[number], UnwrapTuples>, GuessAsyncFromRules, GuessMetadataFromRules>; //#endregion //#region src/helpers/or.d.ts /** * The or operator validates successfully if at least one of the provided rules is valid. */ declare function or, ...FormRuleDeclaration[]]>(...rules: [...TRules]): RegleRuleDefinition[number], UnwrapTuples>, GuessAsyncFromRules, GuessMetadataFromRules>; //#endregion //#region src/helpers/not.d.ts /** * The not operator passes when the provided rule fails and fails when the rule passes. It can be combined with other rules. */ declare function not = RegleRuleMetadataDefinition, TMetadata extends RegleRuleMetadataDefinition = (TReturn extends Promise ? M : TReturn), TAsync extends boolean = (TReturn extends Promise ? true : false)>(rule: RegleRuleDefinition | InlineRuleDeclaration, message?: RegleRuleDefinitionWithMetadataProcessor, string | string[]>): RegleRuleDefinition; //#endregion //#region src/rules/alpha.d.ts /** * Allows only alphabetic characters. * * @param [options] - Alpha rules options * */ declare const alpha: RegleRuleWithParamsDefinition, string>; //#endregion //#region src/rules/alphaNum.d.ts /** * Allows only alphanumeric characters. * * @param [options] - Alpha rules options */ declare const alphaNum: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/between.d.ts /** * Checks if a number is in specified bounds. min and max are both inclusive. * * @param min - the minimum limit * @param max - the maximum limit */ declare const between: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/boolean.d.ts /** * Requires a value to be a native boolean type * * Mainly used for typing */ declare const boolean: RegleRuleDefinition, unknown>; //#endregion //#region src/rules/checked.d.ts /** * Requires a boolean value to be true. This is useful for checkbox inputs. */ declare const checked: RegleRuleDefinition>; //#endregion //#region src/rules/contains.d.ts /** * Checks if the string contains the specified substring. * * @param part - the part the value needs to contain */ declare const contains: RegleRuleWithParamsDefinition], false, boolean, MaybeInput>; //#endregion //#region src/rules/date.d.ts /** * Requires a value to be a native Date constructor * * Mainly used for typing */ declare const date: RegleRuleDefinition, unknown>; //#endregion //#region src/rules/dateAfter.d.ts /** * Checks if the date is after the given parameter. * * @param after - the date to compare to * @param options - comparison options */ declare const dateAfter: RegleRuleWithParamsDefinition, options?: CommonComparisonOptions], false, true | { $valid: false; error: 'date-not-after'; } | { $valid: false; error: 'value-or-parameter-not-a-date'; }, MaybeInput>; //#endregion //#region src/rules/dateBefore.d.ts /** * Checks if the date is before the given parameter. * * @param before - the date to compare to * @param options - comparison options */ declare const dateBefore: RegleRuleWithParamsDefinition, options?: CommonComparisonOptions], false, true | { $valid: false; error: 'date-not-before'; } | { $valid: false; error: 'value-or-parameter-not-a-date'; }, MaybeInput>; //#endregion //#region src/rules/dateBetween.d.ts /** * Checks if the date falls between the specified bounds. * * @param before - the minimum limit * @param after - the maximum limit * @param options - comparison options */ declare const dateBetween: RegleRuleWithParamsDefinition, after: MaybeInput, options?: CommonComparisonOptions], false, boolean, MaybeInput>; //#endregion //#region src/rules/decimal.d.ts /** * Allows positive and negative decimal numbers. */ declare const decimal: RegleRuleDefinition>; //#endregion //#region src/rules/email.d.ts /** * Validates email addresses. Always verify on the server to ensure the address is real and not already in use. */ declare const email: RegleRuleDefinition>; //#endregion //#region src/rules/endsWith.d.ts /** * Checks if the string ends with the specified substring. * * @param part - the value the field must end with */ declare const endsWith: RegleRuleWithParamsDefinition], false, boolean, MaybeInput>; //#endregion //#region src/rules/exactLength.d.ts /** * Requires the input value to have a strict specified length, inclusive. Works with arrays, objects and strings. * * @param count - the required length */ declare const exactLength: RegleRuleWithParamsDefinition, [count: number], false, boolean>; //#endregion //#region src/rules/exactValue.d.ts /** * Requires a field to have a strict numeric value. */ declare const exactValue: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/hexadecimal.d.ts /** * Allows only hexadecimal values. */ declare const hexadecimal: RegleRuleDefinition>; //#endregion //#region src/rules/integer.d.ts /** * Allows only integers (positive and negative). */ declare const integer: RegleRuleDefinition>; //#endregion //#region src/rules/ipv4Address.d.ts /** * Validates IPv4 addresses in dotted decimal notation 127.0.0.1. */ declare const ipv4Address: RegleRuleDefinition>; //#endregion //#region src/rules/literal.d.ts /** * Allow only one possible literal value */ declare function literal(literal: MaybeRefOrGetter): RegleRuleDefinition, string | number>; //#endregion //#region src/rules/macAddress.d.ts /** * Validates MAC addresses. Call as a function to specify a custom separator (e.g., ':' or an empty string for 00ff1122334455). * * @param separator - the custom separator */ declare const macAddress: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/maxLength.d.ts /** * Requires the input value to have a maximum specified length, inclusive. Works with arrays, objects and strings. * * @param max - the maximum length * @param options - comparison options */ declare const maxLength: RegleRuleWithParamsDefinition, [count: number, options?: CommonComparisonOptions], false, boolean>; //#endregion //#region src/rules/maxValue.d.ts /** * Requires a field to have a specified maximum numeric value. * * @param max - the maximum value * @param options - comparison options */ declare const maxValue: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/minLength.d.ts /** * Requires the input value to have a minimum specified length, inclusive. Works with arrays, objects and strings. * * @param min - the minimum value * @param options - comparison options */ declare const minLength: RegleRuleWithParamsDefinition, [count: number, options?: CommonComparisonOptions], false, boolean>; //#endregion //#region src/rules/minValue.d.ts /** * Requires a field to have a specified minimum numeric value. * * @param count - the minimum count * @param options - comparison options */ declare const minValue: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/nativeEnum.d.ts type EnumLike = { [k: string]: string | number; [nu: number]: string; }; /** * Validate against a native Typescript enum value. */ declare function nativeEnum(enumLike: T): RegleRuleDefinition, [enumLike: T], false, boolean, MaybeInput, string | number>; //#endregion //#region src/rules/number.d.ts /** * Requires a value to be a native number type * * Mainly used for typing */ declare const number: RegleRuleDefinition, unknown>; //#endregion //#region src/rules/numeric.d.ts /** * Allows only numeric values (including numeric strings). */ declare const numeric: RegleRuleDefinition>; //#endregion //#region src/rules/oneOf.d.ts interface OneOfFn { (options: MaybeReadonly>): RegleRuleDefinition, string | number>; /** Keep this definition without generics for inference */ (options: MaybeReadonly>): RegleRuleDefinition, string | number>; } /** * Allow only one of the values from a fixed Array of possible entries. */ declare const oneOf: OneOfFn; //#endregion //#region src/rules/regex.d.ts /** * Checks if the value matches one or more regular expressions. */ declare const regex: RegleRuleWithParamsDefinition>; //#endregion //#region src/rules/required.d.ts /** * Requires non-empty data. Checks for empty arrays and strings containing only whitespaces. */ declare const required: RegleRuleDefinition; //#endregion //#region src/rules/requiredIf.d.ts /** * Requires non-empty data, only if provided data property, ref, or a function resolves to true. * * @param condition - the condition to enable the required rule */ declare const requiredIf: RegleRuleWithParamsDefinition; //#endregion //#region src/rules/requiredUnless.d.ts /** * Requires non-empty data, only if provided data property, ref, or a function resolves to false. * * @param condition - the condition to disable the required rule */ declare const requiredUnless: RegleRuleWithParamsDefinition; //#endregion //#region src/rules/sameAs.d.ts interface SameAsFn { (target: MaybeRefOrGetter, otherName?: MaybeRefOrGetter): RegleRuleDefinition ? M : MaybeInput>; /** Keep this definition without generics for inference */ (target: MaybeRefOrGetter, otherName?: MaybeRefOrGetter): RegleRuleDefinition ? M : MaybeInput>; } /** * Checks if the value matches the specified property or ref. */ declare const sameAs: SameAsFn; //#endregion //#region src/rules/startsWith.d.ts /** * Checks if the string starts with the specified substring. * * @private part - the value the field must start with */ declare const startsWith: RegleRuleWithParamsDefinition], false, boolean, MaybeInput>; //#endregion //#region src/rules/string.d.ts /** * Requires a value to be a native string type * * Mainly used for typing */ declare const string: RegleRuleDefinition, unknown>; //#endregion //#region src/rules/type.d.ts /** * Define the input type of a rule. No runtime validation. * * Override any input type set by other rules. */ declare function type(): RegleRuleDefinition>; //#endregion //#region src/rules/url.d.ts /** * Validates URLs. */ declare const url: RegleRuleDefinition>; //#endregion export { EnumLike, alpha, alphaNum, and, applyIf, between, boolean, checked, contains, date, dateAfter, dateBefore, dateBetween, decimal, email, endsWith, exactLength, exactValue, getSize, hexadecimal, integer, ipv4Address, isDate, isEmpty, isFilled, isNumber, literal, macAddress, matchRegex, maxLength, maxValue, minLength, minValue, nativeEnum, not, number, numeric, oneOf, or, regex, required, requiredIf, requiredUnless, sameAs, startsWith, string, toDate, toNumber, type, url, withAsync, withMessage, withParams, withTooltip };