/** * The declarative validation rules Photon Grid ships with. * * Every export here is a {@link ValidatorFactory}: it receives whatever the * column declared for the rule (`true`, a number, a `RegExp`, …) and returns a * {@link ValidatorFn} — or `null` when that configuration disables the rule, so * the compiled rule list for a column holds no no-ops to step over on every * commit. * * ### Why factories rather than plain validators * All of the per-column work — compiling a pattern, coercing a bound to a * comparable primitive, rendering the bound into display text — happens **once** * inside the factory, at compile time, and is closed over by the returned * function. A 100k-row grid therefore never recompiles a `RegExp` or re-formats * a `Date` while the user types. See {@link ValidationEngine.compile}, which * memoises the whole compiled set per `ColumnDef`. * * ### The blank-value contract * Every rule except {@link createRequiredRule} returns {@link VALID} for * `null`, `undefined` and `''`. `required` owns emptiness, exclusively. Without * that split an optional column carrying a `min` could never be left blank — * clearing the cell would trip the range rule — and the user would be told * "Price must be at least 10" about a field they are allowed to omit. * * ### Message wording * Messages are built from {@link ValidationContext.label} (the column header, * falling back to its field) so the text names the column the user is looking * at, and the wording deliberately matches the legacy `validateValue` in * `engines/editing/value-parser.ts` — a grid migrating to this engine must not * see its copy change. Each failure carries the rule name as its `code`, so an * application can style, group or translate failures without string-matching. * * @packageDocumentation */ import type { ValidatorFactory, ValidatorFn } from '../../types/validation.types'; /** * Value must be filled in. * * The one rule that judges emptiness, and therefore the one rule that must run * first — see the ordering note on {@link ValidationEngine.compile}. * * @param config - `true` to enable. Anything else disables the rule. */ export declare function createRequiredRule(config: unknown): ValidatorFn | null; /** * Value must look like an email address. * * Implied for free by `type: 'email'` — see `impliedValidationFor`. * * @param config - `true` to enable. */ export declare function createEmailRule(config: unknown): ValidatorFn | null; /** * Value must be an absolute URL. * * Implied for free by `type: 'url'`. * * @param config - `true` to enable. */ export declare function createUrlRule(config: unknown): ValidatorFn | null; /** * A pattern rule's configuration. * * The object form exists so `ColumnValidation.patternMessage` can be folded into * the rule at compile time instead of wrapping the validator in a * message-rewriting closure that would allocate on every failure. */ export interface PatternRuleConfig { /** The expression to match, as a `RegExp` or an uncompiled source string. */ readonly pattern: RegExp | string; /** Replaces the generic wording. */ readonly message?: string; } /** * Value's string form must match an expression. * * The expression is compiled **once**, here, never per keystroke. * * @param config - A `RegExp`, a source string, or a {@link PatternRuleConfig} * carrying a custom message. */ export declare function createPatternRule(config: unknown): ValidatorFn | null; /** * Value must be at least `config`. * * A value with no numeric (or temporal) reading passes: type-correctness is the * business of the `decimal`/`date` rules, which a typed column already implies, * and the legacy `validateValue` skipped its range check on `NaN` for exactly * this reason. Reporting "must be at least 10" about the text `"abc"` would be * the wrong sentence anyway. * * @param config - Inclusive lower bound, `number` or `Date`. */ export declare function createMinRule(config: unknown): ValidatorFn | null; /** * Value must be at most `config`. * * Mirrors {@link createMinRule}, including its deference to the type rules on * un-coercible values. * * @param config - Inclusive upper bound, `number` or `Date`. */ export declare function createMaxRule(config: unknown): ValidatorFn | null; /** * Value's string form must be at least `config` characters. * * @param config - Minimum length. A blank value is exempt — that is `required`'s * call to make. */ export declare function createMinLengthRule(config: unknown): ValidatorFn | null; /** * Value's string form must be at most `config` characters. * * @param config - Maximum length. */ export declare function createMaxLengthRule(config: unknown): ValidatorFn | null; /** * Value must be a whole number. * * Non-numeric input fails as `"must be a number"` rather than * `"must be a whole number"`: the first sentence is the one that describes what * the user actually did wrong. * * @param config - `true` to enable. */ export declare function createIntegerRule(config: unknown): ValidatorFn | null; /** * Value must be a number, optionally with a bounded number of decimal places. * * This is the rule the numeric column types imply, which is why it — and not * `min`/`max` — is what reports `"must be a number"` for a `type: 'number'` * column, matching the legacy `validateValue` wording exactly. * * @param config - `true` to assert numeric-ness only, or a number giving the * maximum decimal places. */ export declare function createDecimalRule(config: unknown): ValidatorFn | null; /** * Value must be greater than zero. * * @param config - `true` to enable. */ export declare function createPositiveRule(config: unknown): ValidatorFn | null; /** * Value must be less than zero. * * @param config - `true` to enable. */ export declare function createNegativeRule(config: unknown): ValidatorFn | null; /** * Value must resolve to a real date. * * Implied by the date-like column types. Accepts a `Date`, an epoch number, or * anything `Date.parse` understands — which is what the grid's own * `parseValue` produces for those types (an ISO string). * * @param config - `true` to enable. */ export declare function createDateRule(config: unknown): ValidatorFn | null; /** * Every rule Photon Grid ships with, keyed by the name a column declares it * under (`validation: { min: 10 }` resolves `'min'` here). * * A function rather than a module-scope constant, following the house registry * style: a consumer assembling a slim {@link ValidatorRegistry} of their own * never references the built-ins, and each call hands back a fresh record so one * registry's `clear()` cannot strip another's defaults. * * The order of the keys is documentation only — {@link ValidationEngine.compile} * owns the order rules actually execute in, because "required before min" is a * guarantee about the message the user reads and must not depend on object key * ordering. */ export declare function createDefaultValidatorFactories(): Record; //# sourceMappingURL=index.d.ts.map