1 | import { VueNode } from '../_util/type';
|
2 | export declare type InternalNamePath = (string | number)[];
|
3 | export declare type NamePath = string | number | InternalNamePath;
|
4 | export declare type StoreValue = any;
|
5 | export interface Store {
|
6 | [name: string]: StoreValue;
|
7 | }
|
8 | export interface Meta {
|
9 | touched: boolean;
|
10 | validating: boolean;
|
11 | errors: string[];
|
12 | name: InternalNamePath;
|
13 | }
|
14 | export interface InternalFieldData extends Meta {
|
15 | value: StoreValue;
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 | export interface FieldData extends Partial<Omit<InternalFieldData, 'name'>> {
|
21 | name: NamePath;
|
22 | }
|
23 | export declare type RuleType = 'string' | 'number' | 'boolean' | 'method' | 'regexp' | 'integer' | 'float' | 'object' | 'enum' | 'date' | 'url' | 'hex' | 'email';
|
24 | declare type Validator = (rule: RuleObject, value: StoreValue, callback: (error?: string) => void) => Promise<void> | void;
|
25 | export interface ValidatorRule {
|
26 | message?: string | VueNode;
|
27 | validator: Validator;
|
28 | }
|
29 | interface BaseRule {
|
30 | enum?: StoreValue[];
|
31 | len?: number;
|
32 | max?: number;
|
33 | message?: string | VueNode;
|
34 | min?: number;
|
35 | pattern?: RegExp;
|
36 | required?: boolean;
|
37 | transform?: (value: StoreValue) => StoreValue;
|
38 | type?: RuleType;
|
39 | whitespace?: boolean;
|
40 |
|
41 | validateTrigger?: string | string[];
|
42 | }
|
43 | declare type AggregationRule = BaseRule & Partial<ValidatorRule>;
|
44 | interface ArrayRule extends Omit<AggregationRule, 'type'> {
|
45 | type: 'array';
|
46 | defaultField?: RuleObject;
|
47 | }
|
48 | export declare type RuleObject = AggregationRule | ArrayRule;
|
49 | export declare type Rule = RuleObject;
|
50 | export interface ValidateErrorEntity<Values = any> {
|
51 | values: Values;
|
52 | errorFields: {
|
53 | name: InternalNamePath;
|
54 | errors: string[];
|
55 | }[];
|
56 | outOfDate: boolean;
|
57 | }
|
58 | export interface FieldError {
|
59 | name: InternalNamePath;
|
60 | errors: string[];
|
61 | }
|
62 | export interface ValidateOptions {
|
63 | triggerName?: string;
|
64 | validateMessages?: ValidateMessages;
|
65 | }
|
66 | export declare type InternalValidateFields = (nameList?: NamePath[], options?: ValidateOptions) => Promise<Store>;
|
67 | export declare type ValidateFields = (nameList?: NamePath[]) => Promise<Store>;
|
68 | interface ValueUpdateInfo {
|
69 | type: 'valueUpdate';
|
70 | source: 'internal' | 'external';
|
71 | }
|
72 | interface ValidateFinishInfo {
|
73 | type: 'validateFinish';
|
74 | }
|
75 | interface ResetInfo {
|
76 | type: 'reset';
|
77 | }
|
78 | interface SetFieldInfo {
|
79 | type: 'setField';
|
80 | data: FieldData;
|
81 | }
|
82 | interface DependenciesUpdateInfo {
|
83 | type: 'dependenciesUpdate';
|
84 | |
85 |
|
86 |
|
87 |
|
88 |
|
89 | relatedFields: InternalNamePath[];
|
90 | }
|
91 | export declare type NotifyInfo = ValueUpdateInfo | ValidateFinishInfo | ResetInfo | SetFieldInfo | DependenciesUpdateInfo;
|
92 | export declare type ValuedNotifyInfo = NotifyInfo & {
|
93 | store: Store;
|
94 | };
|
95 | export interface Callbacks<Values = any> {
|
96 | onValuesChange?: (changedValues: any, values: Values) => void;
|
97 | onFieldsChange?: (changedFields: FieldData[], allFields: FieldData[]) => void;
|
98 | onFinish?: (values: Values) => void;
|
99 | onFinishFailed?: (errorInfo: ValidateErrorEntity<Values>) => void;
|
100 | }
|
101 | export declare type EventArgs = any[];
|
102 | declare type ValidateMessage = string | (() => string);
|
103 | export interface ValidateMessages {
|
104 | default?: ValidateMessage;
|
105 | required?: ValidateMessage;
|
106 | enum?: ValidateMessage;
|
107 | whitespace?: ValidateMessage;
|
108 | date?: {
|
109 | format?: ValidateMessage;
|
110 | parse?: ValidateMessage;
|
111 | invalid?: ValidateMessage;
|
112 | };
|
113 | types?: {
|
114 | string?: ValidateMessage;
|
115 | method?: ValidateMessage;
|
116 | array?: ValidateMessage;
|
117 | object?: ValidateMessage;
|
118 | number?: ValidateMessage;
|
119 | date?: ValidateMessage;
|
120 | boolean?: ValidateMessage;
|
121 | integer?: ValidateMessage;
|
122 | float?: ValidateMessage;
|
123 | regexp?: ValidateMessage;
|
124 | email?: ValidateMessage;
|
125 | url?: ValidateMessage;
|
126 | hex?: ValidateMessage;
|
127 | };
|
128 | string?: {
|
129 | len?: ValidateMessage;
|
130 | min?: ValidateMessage;
|
131 | max?: ValidateMessage;
|
132 | range?: ValidateMessage;
|
133 | };
|
134 | number?: {
|
135 | len?: ValidateMessage;
|
136 | min?: ValidateMessage;
|
137 | max?: ValidateMessage;
|
138 | range?: ValidateMessage;
|
139 | };
|
140 | array?: {
|
141 | len?: ValidateMessage;
|
142 | min?: ValidateMessage;
|
143 | max?: ValidateMessage;
|
144 | range?: ValidateMessage;
|
145 | };
|
146 | pattern?: {
|
147 | mismatch?: ValidateMessage;
|
148 | };
|
149 | }
|
150 | export {};
|
151 |
|
\ | No newline at end of file |