@nice2dev/ui-core 1.0.25 → 1.0.27

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.
@@ -0,0 +1,46 @@
1
+ import type { NiceFilterGroup } from './datasource';
2
+ /** A validation operator. `*Field` variants compare against another record field. */
3
+ export type NiceFieldValidationOp = 'required' | 'minLength' | 'maxLength' | 'min' | 'max' | 'pattern' | 'email' | 'url' | 'equals' | 'notEquals' | 'greaterThan' | 'lessThan' | 'matchesField' | 'greaterThanField' | 'lessThanField' | 'custom';
4
+ /** A single validation rule targeting one field of a record. */
5
+ export interface NiceFieldValidationRule {
6
+ /** Stable id (for keyed rendering / diagnostics). */
7
+ id: string;
8
+ /** Field this rule validates. */
9
+ field: string;
10
+ /** What to check. */
11
+ op: NiceFieldValidationOp;
12
+ /** Literal comparison value (minLength/min/pattern/equals/…). */
13
+ value?: string | number;
14
+ /** Other field to compare against (matchesField/greaterThanField/lessThanField). */
15
+ compareField?: string;
16
+ /** Error message shown when the rule fails (a sensible default is generated). */
17
+ message?: string;
18
+ /** Severity — `'error'` blocks, `'warning'` is advisory. Default `'error'`. */
19
+ severity?: 'error' | 'warning';
20
+ /** Apply this rule only when the record matches this filter group (reuses the filter model). */
21
+ when?: NiceFilterGroup;
22
+ /** For `op: 'custom'` — predicate returning `true` when the value is VALID. */
23
+ validate?: (value: unknown, record: Record<string, unknown>) => boolean;
24
+ }
25
+ /** A validation problem produced by {@link evaluateValidation}. */
26
+ export interface NiceFieldValidationIssue {
27
+ field: string;
28
+ message: string;
29
+ severity: 'error' | 'warning';
30
+ ruleId?: string;
31
+ }
32
+ /** Default human-readable message for a rule that failed. */
33
+ export declare function defaultValidationMessage(rule: NiceFieldValidationRule): string;
34
+ /**
35
+ * Evaluate a single rule against a record. Returns `true` when the value PASSES.
36
+ * Non-`required` rules pass on empty values (let `required` own emptiness).
37
+ */
38
+ export declare function evaluateValidationRule(rule: NiceFieldValidationRule, record: Record<string, unknown>): boolean;
39
+ /**
40
+ * Evaluate all rules against a record, honoring each rule's `when` clause.
41
+ * Returns one issue per failing rule (empty array ⇒ valid).
42
+ */
43
+ export declare function evaluateValidation(rules: NiceFieldValidationRule[] | undefined, record: Record<string, unknown>): NiceFieldValidationIssue[];
44
+ /** Convenience: does the record satisfy every `error`-severity rule? */
45
+ export declare function isRecordValid(rules: NiceFieldValidationRule[] | undefined, record: Record<string, unknown>): boolean;
46
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/core/validation.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,qFAAqF;AACrF,MAAM,MAAM,qBAAqB,GAC7B,UAAU,GACV,WAAW,GACX,WAAW,GACX,KAAK,GACL,KAAK,GACL,SAAS,GACT,OAAO,GACP,KAAK,GACL,QAAQ,GACR,WAAW,GACX,aAAa,GACb,UAAU,GACV,cAAc,GACd,kBAAkB,GAClB,eAAe,GACf,QAAQ,CAAC;AAEb,gEAAgE;AAChE,MAAM,WAAW,uBAAuB;IACtC,qDAAqD;IACrD,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,EAAE,EAAE,qBAAqB,CAAC;IAC1B,iEAAiE;IACjE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,oFAAoF;IACpF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iFAAiF;IACjF,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC/B,gGAAgG;IAChG,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EA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