@logixjs/form 0.0.1
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.
- package/dist/Error-VvknI9Wj.d.cts +37 -0
- package/dist/Error-VvknI9Wj.d.ts +37 -0
- package/dist/Error.cjs +46 -0
- package/dist/Error.cjs.map +1 -0
- package/dist/Error.d.cts +1 -0
- package/dist/Error.d.ts +1 -0
- package/dist/Error.js +14 -0
- package/dist/Error.js.map +1 -0
- package/dist/Form.cjs +2455 -0
- package/dist/Form.cjs.map +1 -0
- package/dist/Form.d.cts +64 -0
- package/dist/Form.d.ts +64 -0
- package/dist/Form.js +25 -0
- package/dist/Form.js.map +1 -0
- package/dist/FormView-CAg9LVrf.d.cts +17 -0
- package/dist/FormView-CAg9LVrf.d.ts +17 -0
- package/dist/FormView.cjs +61 -0
- package/dist/FormView.cjs.map +1 -0
- package/dist/FormView.d.cts +1 -0
- package/dist/FormView.d.ts +1 -0
- package/dist/FormView.js +8 -0
- package/dist/FormView.js.map +1 -0
- package/dist/Path-DOjMkAS6.d.cts +42 -0
- package/dist/Path-DOjMkAS6.d.ts +42 -0
- package/dist/Path.cjs +132 -0
- package/dist/Path.cjs.map +1 -0
- package/dist/Path.d.cts +1 -0
- package/dist/Path.d.ts +1 -0
- package/dist/Path.js +22 -0
- package/dist/Path.js.map +1 -0
- package/dist/Rule-BOAiSVz9.d.cts +202 -0
- package/dist/Rule-BOAiSVz9.d.ts +202 -0
- package/dist/Rule.cjs +307 -0
- package/dist/Rule.cjs.map +1 -0
- package/dist/Rule.d.cts +2 -0
- package/dist/Rule.d.ts +2 -0
- package/dist/Rule.js +34 -0
- package/dist/Rule.js.map +1 -0
- package/dist/SchemaErrorMapping-Cu5gl7-Z.d.ts +50 -0
- package/dist/SchemaErrorMapping-DOrgLzii.d.cts +50 -0
- package/dist/SchemaErrorMapping.cjs +305 -0
- package/dist/SchemaErrorMapping.cjs.map +1 -0
- package/dist/SchemaErrorMapping.d.cts +2 -0
- package/dist/SchemaErrorMapping.d.ts +2 -0
- package/dist/SchemaErrorMapping.js +17 -0
- package/dist/SchemaErrorMapping.js.map +1 -0
- package/dist/SchemaPathMapping-BCoUW-_q.d.ts +16 -0
- package/dist/SchemaPathMapping-BUq2zm8W.d.cts +20 -0
- package/dist/SchemaPathMapping-BUq2zm8W.d.ts +20 -0
- package/dist/SchemaPathMapping-DJnExqM3.d.cts +16 -0
- package/dist/SchemaPathMapping.cjs +179 -0
- package/dist/SchemaPathMapping.cjs.map +1 -0
- package/dist/SchemaPathMapping.d.cts +2 -0
- package/dist/SchemaPathMapping.d.ts +2 -0
- package/dist/SchemaPathMapping.js +12 -0
- package/dist/SchemaPathMapping.js.map +1 -0
- package/dist/Trait-Bu794ROY.d.cts +49 -0
- package/dist/Trait-Bu794ROY.d.ts +49 -0
- package/dist/Trait.cjs +48 -0
- package/dist/Trait.cjs.map +1 -0
- package/dist/Trait.d.cts +2 -0
- package/dist/Trait.d.ts +2 -0
- package/dist/Trait.js +12 -0
- package/dist/Trait.js.map +1 -0
- package/dist/chunk-5DRI5UGD.js +105 -0
- package/dist/chunk-5DRI5UGD.js.map +1 -0
- package/dist/chunk-AD2ZA7KA.js +23 -0
- package/dist/chunk-AD2ZA7KA.js.map +1 -0
- package/dist/chunk-EOXJRCM6.js +146 -0
- package/dist/chunk-EOXJRCM6.js.map +1 -0
- package/dist/chunk-JZ5FZKPJ.js +71 -0
- package/dist/chunk-JZ5FZKPJ.js.map +1 -0
- package/dist/chunk-LNJJPZAG.js +46 -0
- package/dist/chunk-LNJJPZAG.js.map +1 -0
- package/dist/chunk-NAR5SIFP.js +22 -0
- package/dist/chunk-NAR5SIFP.js.map +1 -0
- package/dist/chunk-OJVEZKU7.js +117 -0
- package/dist/chunk-OJVEZKU7.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +10 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-S5JTU2CM.js +31 -0
- package/dist/chunk-S5JTU2CM.js.map +1 -0
- package/dist/chunk-YHDEJ47V.js +1885 -0
- package/dist/chunk-YHDEJ47V.js.map +1 -0
- package/dist/chunk-YVHXLY63.js +315 -0
- package/dist/chunk-YVHXLY63.js.map +1 -0
- package/dist/impl-BfSlyM58.d.ts +225 -0
- package/dist/impl-Ccdm5eDF.d.cts +225 -0
- package/dist/index.cjs +2689 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +332 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +43 -0
- package/dist/react/index.d.ts +43 -0
- package/dist/react/index.js +201 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +62 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as Logix from '@logixjs/core';
|
|
2
|
+
|
|
3
|
+
declare const ERROR_VALUE_MAX_BYTES = 256;
|
|
4
|
+
declare const assertErrorValueBudget: (value: unknown, label: string) => unknown;
|
|
5
|
+
type RequiredDecl = boolean | string | Readonly<{
|
|
6
|
+
readonly message?: string;
|
|
7
|
+
readonly trim?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
declare const required: (decl: RequiredDecl) => ((value: unknown) => unknown | undefined);
|
|
10
|
+
type MinLengthDecl = number | Readonly<{
|
|
11
|
+
readonly min: number;
|
|
12
|
+
readonly message?: string;
|
|
13
|
+
}>;
|
|
14
|
+
declare const minLength: (decl: MinLengthDecl) => ((value: unknown) => unknown | undefined);
|
|
15
|
+
type MaxLengthDecl = number | Readonly<{
|
|
16
|
+
readonly max: number;
|
|
17
|
+
readonly message?: string;
|
|
18
|
+
}>;
|
|
19
|
+
declare const maxLength: (decl: MaxLengthDecl) => ((value: unknown) => unknown | undefined);
|
|
20
|
+
type MinDecl = number | Readonly<{
|
|
21
|
+
readonly min: number;
|
|
22
|
+
readonly message?: string;
|
|
23
|
+
}>;
|
|
24
|
+
declare const min: (decl: MinDecl) => ((value: unknown) => unknown | undefined);
|
|
25
|
+
type MaxDecl = number | Readonly<{
|
|
26
|
+
readonly max: number;
|
|
27
|
+
readonly message?: string;
|
|
28
|
+
}>;
|
|
29
|
+
declare const max: (decl: MaxDecl) => ((value: unknown) => unknown | undefined);
|
|
30
|
+
type PatternDecl = RegExp | Readonly<{
|
|
31
|
+
readonly re: RegExp;
|
|
32
|
+
readonly message?: string;
|
|
33
|
+
}>;
|
|
34
|
+
declare const pattern: (decl: PatternDecl) => ((value: unknown) => unknown | undefined);
|
|
35
|
+
|
|
36
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp | Function;
|
|
37
|
+
type NonNull<T> = Exclude<T, null | undefined>;
|
|
38
|
+
type IsPlainObject<T> = [NonNull<T>] extends [Primitive] ? false : [NonNull<T>] extends [readonly any[]] ? false : [NonNull<T>] extends [Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>] ? false : [NonNull<T>] extends [object] ? true : false;
|
|
39
|
+
type Join<K, P> = K extends string ? (P extends string ? `${K}.${P}` : never) : never;
|
|
40
|
+
type PrevDepth<D extends number> = D extends 5 ? 4 : D extends 4 ? 3 : D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
|
|
41
|
+
type IndexSegment = `${number}`;
|
|
42
|
+
type FieldPathInner<T, Depth extends number> = Depth extends 0 ? never : [NonNull<T>] extends [Primitive] ? never : [NonNull<T>] extends [readonly (infer Item)[]] ? IndexSegment | (FieldPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${IndexSegment}.${P}` : never : never) : [NonNull<T>] extends [object] ? {
|
|
43
|
+
[K in keyof NonNull<T> & string]: K | ([NonNull<T>[K]] extends [readonly (infer Item)[]] ? `${K}.${IndexSegment}` | (FieldPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${K}.${IndexSegment}.${P}` : never : never) : IsPlainObject<NonNull<T>[K]> extends true ? Join<K, FieldPathInner<NonNull<T>[K], PrevDepth<Depth>>> : never);
|
|
44
|
+
}[keyof NonNull<T> & string] : never;
|
|
45
|
+
/**
|
|
46
|
+
* FieldPath<TValues>:
|
|
47
|
+
* - A typed version of valuePath strings (aligned with the "ValuePath" mental model from 010).
|
|
48
|
+
* Array indices are represented as `${number}`; examples:
|
|
49
|
+
* - "profile.name"
|
|
50
|
+
* - "items.${number}.warehouseId"
|
|
51
|
+
* - Uses a max recursion depth of 5 to avoid TS Server performance issues.
|
|
52
|
+
*/
|
|
53
|
+
type FieldPath<TValues extends object> = FieldPathInner<TValues, 5>;
|
|
54
|
+
type AtIndex<T> = NonNull<T> extends readonly (infer Item)[] ? Item : never;
|
|
55
|
+
type FieldValueInner<TValues, P> = P extends `${infer Head}.${infer Rest}` ? Head extends IndexSegment ? FieldValueInner<AtIndex<TValues>, Rest> : Head extends keyof NonNull<TValues> ? FieldValueInner<NonNull<TValues>[Head], Rest> : never : P extends IndexSegment ? AtIndex<TValues> : P extends keyof NonNull<TValues> ? NonNull<TValues>[P] : never;
|
|
56
|
+
/**
|
|
57
|
+
* FieldValue<TValues, P>:
|
|
58
|
+
* - Given a values type and a FieldPath, infers the value type at that path.
|
|
59
|
+
*/
|
|
60
|
+
type FieldValue<TValues extends object, P extends FieldPath<TValues>> = FieldValueInner<TValues, P>;
|
|
61
|
+
type UnwrapArray<T> = [NonNull<T>] extends [readonly (infer Item)[]] ? Item : NonNull<T>;
|
|
62
|
+
type CanonicalPathInner<T, Depth extends number> = Depth extends 0 ? never : [NonNull<T>] extends [Primitive] ? never : [NonNull<T>] extends [readonly (infer Item)[]] ? CanonicalPathInner<Item, PrevDepth<Depth>> : [NonNull<T>] extends [object] ? {
|
|
63
|
+
[K in keyof NonNull<T> & string]: K | ([NonNull<T>[K]] extends [readonly (infer Item)[]] ? CanonicalPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${K}.${P}` : never : never : IsPlainObject<NonNull<T>[K]> extends true ? Join<K, CanonicalPathInner<NonNull<T>[K], PrevDepth<Depth>>> : never);
|
|
64
|
+
}[keyof NonNull<T> & string] : never;
|
|
65
|
+
/**
|
|
66
|
+
* CanonicalPath<TValues>:
|
|
67
|
+
* - The "canonical value path" aligned with Form.rules / Form.Rule.field/list:
|
|
68
|
+
* - No numeric segments (`${number}`) and no bracket/[] syntax.
|
|
69
|
+
* - For arrays: uses implicit pattern semantics to "pierce through array items"
|
|
70
|
+
* (e.g. `items.title`, `items.allocations.amount`).
|
|
71
|
+
* - Uses a max recursion depth of 5 to avoid TS Server performance issues.
|
|
72
|
+
*/
|
|
73
|
+
type CanonicalPath<TValues extends object> = CanonicalPathInner<TValues, 5>;
|
|
74
|
+
type CanonicalValueInner<TValues, P> = P extends `${infer Head}.${infer Rest}` ? Head extends keyof UnwrapArray<TValues> & string ? CanonicalValueInner<[
|
|
75
|
+
NonNull<UnwrapArray<TValues>[Head]>
|
|
76
|
+
] extends [readonly (infer Item)[]] ? Item : UnwrapArray<TValues>[Head], Rest> : never : P extends keyof UnwrapArray<TValues> & string ? UnwrapArray<TValues>[P] : never;
|
|
77
|
+
/**
|
|
78
|
+
* CanonicalValue<TValues, P>:
|
|
79
|
+
* - Given a values type and a CanonicalPath, infers the value type at that path.
|
|
80
|
+
*/
|
|
81
|
+
type CanonicalValue<TValues extends object, P extends CanonicalPath<TValues>> = CanonicalValueInner<TValues, P>;
|
|
82
|
+
/**
|
|
83
|
+
* CanonicalListPath<TValues>:
|
|
84
|
+
* - The subset of CanonicalPath whose endpoints are arrays; used as listPath hints for Form.Rule.list.
|
|
85
|
+
*/
|
|
86
|
+
type CanonicalListPath<TValues extends object> = {
|
|
87
|
+
[P in CanonicalPath<TValues>]: CanonicalValue<TValues, P> extends readonly any[] ? P : never;
|
|
88
|
+
}[CanonicalPath<TValues>];
|
|
89
|
+
type CanonicalListItem<TValues extends object, P extends CanonicalListPath<TValues>> = CanonicalValue<TValues, P> extends readonly (infer Item)[] ? Item : never;
|
|
90
|
+
|
|
91
|
+
type AutoValidateOn = 'onChange' | 'onBlur';
|
|
92
|
+
type RuleValidateOn = ReadonlyArray<AutoValidateOn>;
|
|
93
|
+
type RuleFn<Input, Ctx = unknown> = (input: Input, ctx: Ctx) => unknown | undefined;
|
|
94
|
+
type RuleDeps<Input> = Input extends object ? CanonicalPath<Input> extends never ? string : CanonicalPath<Input> : string;
|
|
95
|
+
type Rule<Input, Ctx = unknown> = Logix.StateTrait.CheckRule<Input, Ctx> & {
|
|
96
|
+
/**
|
|
97
|
+
* validateOn:
|
|
98
|
+
* - Only affects the auto-validation phase (onChange/onBlur); submit/manual always runs.
|
|
99
|
+
* - If an empty array, auto-validation is disabled (only submit/manual runs).
|
|
100
|
+
*/
|
|
101
|
+
readonly validateOn?: RuleValidateOn;
|
|
102
|
+
};
|
|
103
|
+
type RuleSet<Input, Ctx = unknown> = Readonly<Record<string, Rule<Input, Ctx>>>;
|
|
104
|
+
type RuleEntry<Input, Ctx = unknown> = RuleFn<Input, Ctx> | (Omit<Rule<Input, Ctx>, 'deps'> & {
|
|
105
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
106
|
+
});
|
|
107
|
+
type RuleGroup<Input, Ctx = unknown> = Readonly<{
|
|
108
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
109
|
+
readonly validateOn?: RuleValidateOn;
|
|
110
|
+
readonly validate: Readonly<Record<string, RuleEntry<Input, Ctx>>>;
|
|
111
|
+
}>;
|
|
112
|
+
type RuleConfig<Input, Ctx = unknown> = Readonly<{
|
|
113
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
114
|
+
readonly validateOn?: RuleValidateOn;
|
|
115
|
+
readonly required?: RequiredDecl;
|
|
116
|
+
readonly minLength?: MinLengthDecl;
|
|
117
|
+
readonly maxLength?: MaxLengthDecl;
|
|
118
|
+
readonly min?: MinDecl;
|
|
119
|
+
readonly max?: MaxDecl;
|
|
120
|
+
readonly pattern?: PatternDecl;
|
|
121
|
+
readonly validate?: RuleFn<Input, Ctx> | Readonly<Record<string, RuleEntry<Input, Ctx>>>;
|
|
122
|
+
}>;
|
|
123
|
+
type RuleInput<Input, Ctx = unknown> = RuleFn<Input, Ctx> | RuleGroup<Input, Ctx> | RuleConfig<Input, Ctx>;
|
|
124
|
+
/**
|
|
125
|
+
* make:
|
|
126
|
+
* - The result must be directly attachable to `StateTrait.node({ check })`.
|
|
127
|
+
* - Does not introduce an extra wrapper (e.g. `{ rules: ... }`).
|
|
128
|
+
*/
|
|
129
|
+
declare const make: <Input, Ctx = unknown>(input: RuleInput<Input, Ctx>) => RuleSet<Input, Ctx>;
|
|
130
|
+
declare const merge: <Input, Ctx = unknown>(...rules: ReadonlyArray<RuleSet<Input, Ctx>>) => RuleSet<Input, Ctx>;
|
|
131
|
+
type ErrorTarget = '$value' | '$self';
|
|
132
|
+
type ListIdentityPolicy = Readonly<{
|
|
133
|
+
readonly mode: 'trackBy';
|
|
134
|
+
readonly trackBy: string;
|
|
135
|
+
}> | Readonly<{
|
|
136
|
+
readonly mode: 'store';
|
|
137
|
+
}> | Readonly<{
|
|
138
|
+
readonly mode: 'index';
|
|
139
|
+
}>;
|
|
140
|
+
type FieldDecl<Input, Ctx = unknown> = Readonly<{
|
|
141
|
+
readonly kind: 'field';
|
|
142
|
+
readonly valuePath: string;
|
|
143
|
+
readonly rule: RuleInput<Input, Ctx>;
|
|
144
|
+
readonly errorTarget?: ErrorTarget;
|
|
145
|
+
}>;
|
|
146
|
+
type RootDecl<Input, Ctx = unknown> = Readonly<{
|
|
147
|
+
readonly kind: 'root';
|
|
148
|
+
readonly rule: RuleInput<Input, Ctx>;
|
|
149
|
+
}>;
|
|
150
|
+
type ListDecl<Item, Ctx = unknown> = Readonly<{
|
|
151
|
+
readonly kind: 'list';
|
|
152
|
+
readonly listPath: string;
|
|
153
|
+
readonly identity: ListIdentityPolicy;
|
|
154
|
+
readonly item?: RuleInput<Item, Ctx>;
|
|
155
|
+
readonly list?: RuleInput<ReadonlyArray<Item>, Ctx>;
|
|
156
|
+
}>;
|
|
157
|
+
type RulesDecl<TValues extends object = any> = FieldDecl<any> | RootDecl<TValues> | ListDecl<any>;
|
|
158
|
+
declare const field: <Input, Ctx = unknown>(valuePath: string, rule: RuleInput<Input, Ctx>, options?: {
|
|
159
|
+
readonly errorTarget?: ErrorTarget;
|
|
160
|
+
}) => FieldDecl<Input, Ctx>;
|
|
161
|
+
declare const root: <Input, Ctx = unknown>(rule: RuleInput<Input, Ctx>) => RootDecl<Input, Ctx>;
|
|
162
|
+
declare const list: <Item, Ctx = unknown>(listPath: string, spec: {
|
|
163
|
+
readonly identity: ListIdentityPolicy;
|
|
164
|
+
readonly item?: RuleInput<Item, Ctx>;
|
|
165
|
+
readonly list?: RuleInput<ReadonlyArray<Item>, Ctx>;
|
|
166
|
+
}) => ListDecl<Item, Ctx>;
|
|
167
|
+
declare const fields: <Input, Ctx = unknown>(...decls: ReadonlyArray<FieldDecl<Input, Ctx> | ReadonlyArray<FieldDecl<Input, Ctx>>>) => Readonly<Record<string, RuleInput<Input, Ctx>>>;
|
|
168
|
+
|
|
169
|
+
type Rule$1_AutoValidateOn = AutoValidateOn;
|
|
170
|
+
declare const Rule$1_ERROR_VALUE_MAX_BYTES: typeof ERROR_VALUE_MAX_BYTES;
|
|
171
|
+
type Rule$1_ErrorTarget = ErrorTarget;
|
|
172
|
+
type Rule$1_FieldDecl<Input, Ctx = unknown> = FieldDecl<Input, Ctx>;
|
|
173
|
+
type Rule$1_ListDecl<Item, Ctx = unknown> = ListDecl<Item, Ctx>;
|
|
174
|
+
type Rule$1_ListIdentityPolicy = ListIdentityPolicy;
|
|
175
|
+
type Rule$1_RootDecl<Input, Ctx = unknown> = RootDecl<Input, Ctx>;
|
|
176
|
+
type Rule$1_Rule<Input, Ctx = unknown> = Rule<Input, Ctx>;
|
|
177
|
+
type Rule$1_RuleConfig<Input, Ctx = unknown> = RuleConfig<Input, Ctx>;
|
|
178
|
+
type Rule$1_RuleEntry<Input, Ctx = unknown> = RuleEntry<Input, Ctx>;
|
|
179
|
+
type Rule$1_RuleFn<Input, Ctx = unknown> = RuleFn<Input, Ctx>;
|
|
180
|
+
type Rule$1_RuleGroup<Input, Ctx = unknown> = RuleGroup<Input, Ctx>;
|
|
181
|
+
type Rule$1_RuleInput<Input, Ctx = unknown> = RuleInput<Input, Ctx>;
|
|
182
|
+
type Rule$1_RuleSet<Input, Ctx = unknown> = RuleSet<Input, Ctx>;
|
|
183
|
+
type Rule$1_RuleValidateOn = RuleValidateOn;
|
|
184
|
+
type Rule$1_RulesDecl<TValues extends object = any> = RulesDecl<TValues>;
|
|
185
|
+
declare const Rule$1_assertErrorValueBudget: typeof assertErrorValueBudget;
|
|
186
|
+
declare const Rule$1_field: typeof field;
|
|
187
|
+
declare const Rule$1_fields: typeof fields;
|
|
188
|
+
declare const Rule$1_list: typeof list;
|
|
189
|
+
declare const Rule$1_make: typeof make;
|
|
190
|
+
declare const Rule$1_max: typeof max;
|
|
191
|
+
declare const Rule$1_maxLength: typeof maxLength;
|
|
192
|
+
declare const Rule$1_merge: typeof merge;
|
|
193
|
+
declare const Rule$1_min: typeof min;
|
|
194
|
+
declare const Rule$1_minLength: typeof minLength;
|
|
195
|
+
declare const Rule$1_pattern: typeof pattern;
|
|
196
|
+
declare const Rule$1_required: typeof required;
|
|
197
|
+
declare const Rule$1_root: typeof root;
|
|
198
|
+
declare namespace Rule$1 {
|
|
199
|
+
export { type Rule$1_AutoValidateOn as AutoValidateOn, Rule$1_ERROR_VALUE_MAX_BYTES as ERROR_VALUE_MAX_BYTES, type Rule$1_ErrorTarget as ErrorTarget, type Rule$1_FieldDecl as FieldDecl, type Rule$1_ListDecl as ListDecl, type Rule$1_ListIdentityPolicy as ListIdentityPolicy, type Rule$1_RootDecl as RootDecl, type Rule$1_Rule as Rule, type Rule$1_RuleConfig as RuleConfig, type Rule$1_RuleEntry as RuleEntry, type Rule$1_RuleFn as RuleFn, type Rule$1_RuleGroup as RuleGroup, type Rule$1_RuleInput as RuleInput, type Rule$1_RuleSet as RuleSet, type Rule$1_RuleValidateOn as RuleValidateOn, type Rule$1_RulesDecl as RulesDecl, Rule$1_assertErrorValueBudget as assertErrorValueBudget, Rule$1_field as field, Rule$1_fields as fields, Rule$1_list as list, Rule$1_make as make, Rule$1_max as max, Rule$1_maxLength as maxLength, Rule$1_merge as merge, Rule$1_min as min, Rule$1_minLength as minLength, Rule$1_pattern as pattern, Rule$1_required as required, Rule$1_root as root };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { type AutoValidateOn as A, maxLength as B, type CanonicalPath as C, min as D, type ErrorTarget as E, type FieldPath as F, max as G, pattern as H, type ListIdentityPolicy as L, Rule$1 as R, type FieldValue as a, type CanonicalValue as b, type CanonicalListPath as c, type CanonicalListItem as d, type RulesDecl as e, type RuleInput as f, type RootDecl as g, type ListDecl as h, type FieldDecl as i, type RuleEntry as j, type RuleValidateOn as k, type RuleFn as l, type Rule as m, type RuleSet as n, type RuleGroup as o, type RuleConfig as p, make as q, merge as r, field as s, root as t, list as u, fields as v, ERROR_VALUE_MAX_BYTES as w, assertErrorValueBudget as x, required as y, minLength as z };
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import * as Logix from '@logixjs/core';
|
|
2
|
+
|
|
3
|
+
declare const ERROR_VALUE_MAX_BYTES = 256;
|
|
4
|
+
declare const assertErrorValueBudget: (value: unknown, label: string) => unknown;
|
|
5
|
+
type RequiredDecl = boolean | string | Readonly<{
|
|
6
|
+
readonly message?: string;
|
|
7
|
+
readonly trim?: boolean;
|
|
8
|
+
}>;
|
|
9
|
+
declare const required: (decl: RequiredDecl) => ((value: unknown) => unknown | undefined);
|
|
10
|
+
type MinLengthDecl = number | Readonly<{
|
|
11
|
+
readonly min: number;
|
|
12
|
+
readonly message?: string;
|
|
13
|
+
}>;
|
|
14
|
+
declare const minLength: (decl: MinLengthDecl) => ((value: unknown) => unknown | undefined);
|
|
15
|
+
type MaxLengthDecl = number | Readonly<{
|
|
16
|
+
readonly max: number;
|
|
17
|
+
readonly message?: string;
|
|
18
|
+
}>;
|
|
19
|
+
declare const maxLength: (decl: MaxLengthDecl) => ((value: unknown) => unknown | undefined);
|
|
20
|
+
type MinDecl = number | Readonly<{
|
|
21
|
+
readonly min: number;
|
|
22
|
+
readonly message?: string;
|
|
23
|
+
}>;
|
|
24
|
+
declare const min: (decl: MinDecl) => ((value: unknown) => unknown | undefined);
|
|
25
|
+
type MaxDecl = number | Readonly<{
|
|
26
|
+
readonly max: number;
|
|
27
|
+
readonly message?: string;
|
|
28
|
+
}>;
|
|
29
|
+
declare const max: (decl: MaxDecl) => ((value: unknown) => unknown | undefined);
|
|
30
|
+
type PatternDecl = RegExp | Readonly<{
|
|
31
|
+
readonly re: RegExp;
|
|
32
|
+
readonly message?: string;
|
|
33
|
+
}>;
|
|
34
|
+
declare const pattern: (decl: PatternDecl) => ((value: unknown) => unknown | undefined);
|
|
35
|
+
|
|
36
|
+
type Primitive = string | number | boolean | bigint | symbol | null | undefined | Date | RegExp | Function;
|
|
37
|
+
type NonNull<T> = Exclude<T, null | undefined>;
|
|
38
|
+
type IsPlainObject<T> = [NonNull<T>] extends [Primitive] ? false : [NonNull<T>] extends [readonly any[]] ? false : [NonNull<T>] extends [Map<any, any> | Set<any> | WeakMap<any, any> | WeakSet<any>] ? false : [NonNull<T>] extends [object] ? true : false;
|
|
39
|
+
type Join<K, P> = K extends string ? (P extends string ? `${K}.${P}` : never) : never;
|
|
40
|
+
type PrevDepth<D extends number> = D extends 5 ? 4 : D extends 4 ? 3 : D extends 3 ? 2 : D extends 2 ? 1 : D extends 1 ? 0 : 0;
|
|
41
|
+
type IndexSegment = `${number}`;
|
|
42
|
+
type FieldPathInner<T, Depth extends number> = Depth extends 0 ? never : [NonNull<T>] extends [Primitive] ? never : [NonNull<T>] extends [readonly (infer Item)[]] ? IndexSegment | (FieldPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${IndexSegment}.${P}` : never : never) : [NonNull<T>] extends [object] ? {
|
|
43
|
+
[K in keyof NonNull<T> & string]: K | ([NonNull<T>[K]] extends [readonly (infer Item)[]] ? `${K}.${IndexSegment}` | (FieldPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${K}.${IndexSegment}.${P}` : never : never) : IsPlainObject<NonNull<T>[K]> extends true ? Join<K, FieldPathInner<NonNull<T>[K], PrevDepth<Depth>>> : never);
|
|
44
|
+
}[keyof NonNull<T> & string] : never;
|
|
45
|
+
/**
|
|
46
|
+
* FieldPath<TValues>:
|
|
47
|
+
* - A typed version of valuePath strings (aligned with the "ValuePath" mental model from 010).
|
|
48
|
+
* Array indices are represented as `${number}`; examples:
|
|
49
|
+
* - "profile.name"
|
|
50
|
+
* - "items.${number}.warehouseId"
|
|
51
|
+
* - Uses a max recursion depth of 5 to avoid TS Server performance issues.
|
|
52
|
+
*/
|
|
53
|
+
type FieldPath<TValues extends object> = FieldPathInner<TValues, 5>;
|
|
54
|
+
type AtIndex<T> = NonNull<T> extends readonly (infer Item)[] ? Item : never;
|
|
55
|
+
type FieldValueInner<TValues, P> = P extends `${infer Head}.${infer Rest}` ? Head extends IndexSegment ? FieldValueInner<AtIndex<TValues>, Rest> : Head extends keyof NonNull<TValues> ? FieldValueInner<NonNull<TValues>[Head], Rest> : never : P extends IndexSegment ? AtIndex<TValues> : P extends keyof NonNull<TValues> ? NonNull<TValues>[P] : never;
|
|
56
|
+
/**
|
|
57
|
+
* FieldValue<TValues, P>:
|
|
58
|
+
* - Given a values type and a FieldPath, infers the value type at that path.
|
|
59
|
+
*/
|
|
60
|
+
type FieldValue<TValues extends object, P extends FieldPath<TValues>> = FieldValueInner<TValues, P>;
|
|
61
|
+
type UnwrapArray<T> = [NonNull<T>] extends [readonly (infer Item)[]] ? Item : NonNull<T>;
|
|
62
|
+
type CanonicalPathInner<T, Depth extends number> = Depth extends 0 ? never : [NonNull<T>] extends [Primitive] ? never : [NonNull<T>] extends [readonly (infer Item)[]] ? CanonicalPathInner<Item, PrevDepth<Depth>> : [NonNull<T>] extends [object] ? {
|
|
63
|
+
[K in keyof NonNull<T> & string]: K | ([NonNull<T>[K]] extends [readonly (infer Item)[]] ? CanonicalPathInner<Item, PrevDepth<Depth>> extends infer P ? P extends string ? `${K}.${P}` : never : never : IsPlainObject<NonNull<T>[K]> extends true ? Join<K, CanonicalPathInner<NonNull<T>[K], PrevDepth<Depth>>> : never);
|
|
64
|
+
}[keyof NonNull<T> & string] : never;
|
|
65
|
+
/**
|
|
66
|
+
* CanonicalPath<TValues>:
|
|
67
|
+
* - The "canonical value path" aligned with Form.rules / Form.Rule.field/list:
|
|
68
|
+
* - No numeric segments (`${number}`) and no bracket/[] syntax.
|
|
69
|
+
* - For arrays: uses implicit pattern semantics to "pierce through array items"
|
|
70
|
+
* (e.g. `items.title`, `items.allocations.amount`).
|
|
71
|
+
* - Uses a max recursion depth of 5 to avoid TS Server performance issues.
|
|
72
|
+
*/
|
|
73
|
+
type CanonicalPath<TValues extends object> = CanonicalPathInner<TValues, 5>;
|
|
74
|
+
type CanonicalValueInner<TValues, P> = P extends `${infer Head}.${infer Rest}` ? Head extends keyof UnwrapArray<TValues> & string ? CanonicalValueInner<[
|
|
75
|
+
NonNull<UnwrapArray<TValues>[Head]>
|
|
76
|
+
] extends [readonly (infer Item)[]] ? Item : UnwrapArray<TValues>[Head], Rest> : never : P extends keyof UnwrapArray<TValues> & string ? UnwrapArray<TValues>[P] : never;
|
|
77
|
+
/**
|
|
78
|
+
* CanonicalValue<TValues, P>:
|
|
79
|
+
* - Given a values type and a CanonicalPath, infers the value type at that path.
|
|
80
|
+
*/
|
|
81
|
+
type CanonicalValue<TValues extends object, P extends CanonicalPath<TValues>> = CanonicalValueInner<TValues, P>;
|
|
82
|
+
/**
|
|
83
|
+
* CanonicalListPath<TValues>:
|
|
84
|
+
* - The subset of CanonicalPath whose endpoints are arrays; used as listPath hints for Form.Rule.list.
|
|
85
|
+
*/
|
|
86
|
+
type CanonicalListPath<TValues extends object> = {
|
|
87
|
+
[P in CanonicalPath<TValues>]: CanonicalValue<TValues, P> extends readonly any[] ? P : never;
|
|
88
|
+
}[CanonicalPath<TValues>];
|
|
89
|
+
type CanonicalListItem<TValues extends object, P extends CanonicalListPath<TValues>> = CanonicalValue<TValues, P> extends readonly (infer Item)[] ? Item : never;
|
|
90
|
+
|
|
91
|
+
type AutoValidateOn = 'onChange' | 'onBlur';
|
|
92
|
+
type RuleValidateOn = ReadonlyArray<AutoValidateOn>;
|
|
93
|
+
type RuleFn<Input, Ctx = unknown> = (input: Input, ctx: Ctx) => unknown | undefined;
|
|
94
|
+
type RuleDeps<Input> = Input extends object ? CanonicalPath<Input> extends never ? string : CanonicalPath<Input> : string;
|
|
95
|
+
type Rule<Input, Ctx = unknown> = Logix.StateTrait.CheckRule<Input, Ctx> & {
|
|
96
|
+
/**
|
|
97
|
+
* validateOn:
|
|
98
|
+
* - Only affects the auto-validation phase (onChange/onBlur); submit/manual always runs.
|
|
99
|
+
* - If an empty array, auto-validation is disabled (only submit/manual runs).
|
|
100
|
+
*/
|
|
101
|
+
readonly validateOn?: RuleValidateOn;
|
|
102
|
+
};
|
|
103
|
+
type RuleSet<Input, Ctx = unknown> = Readonly<Record<string, Rule<Input, Ctx>>>;
|
|
104
|
+
type RuleEntry<Input, Ctx = unknown> = RuleFn<Input, Ctx> | (Omit<Rule<Input, Ctx>, 'deps'> & {
|
|
105
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
106
|
+
});
|
|
107
|
+
type RuleGroup<Input, Ctx = unknown> = Readonly<{
|
|
108
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
109
|
+
readonly validateOn?: RuleValidateOn;
|
|
110
|
+
readonly validate: Readonly<Record<string, RuleEntry<Input, Ctx>>>;
|
|
111
|
+
}>;
|
|
112
|
+
type RuleConfig<Input, Ctx = unknown> = Readonly<{
|
|
113
|
+
readonly deps?: ReadonlyArray<RuleDeps<Input>>;
|
|
114
|
+
readonly validateOn?: RuleValidateOn;
|
|
115
|
+
readonly required?: RequiredDecl;
|
|
116
|
+
readonly minLength?: MinLengthDecl;
|
|
117
|
+
readonly maxLength?: MaxLengthDecl;
|
|
118
|
+
readonly min?: MinDecl;
|
|
119
|
+
readonly max?: MaxDecl;
|
|
120
|
+
readonly pattern?: PatternDecl;
|
|
121
|
+
readonly validate?: RuleFn<Input, Ctx> | Readonly<Record<string, RuleEntry<Input, Ctx>>>;
|
|
122
|
+
}>;
|
|
123
|
+
type RuleInput<Input, Ctx = unknown> = RuleFn<Input, Ctx> | RuleGroup<Input, Ctx> | RuleConfig<Input, Ctx>;
|
|
124
|
+
/**
|
|
125
|
+
* make:
|
|
126
|
+
* - The result must be directly attachable to `StateTrait.node({ check })`.
|
|
127
|
+
* - Does not introduce an extra wrapper (e.g. `{ rules: ... }`).
|
|
128
|
+
*/
|
|
129
|
+
declare const make: <Input, Ctx = unknown>(input: RuleInput<Input, Ctx>) => RuleSet<Input, Ctx>;
|
|
130
|
+
declare const merge: <Input, Ctx = unknown>(...rules: ReadonlyArray<RuleSet<Input, Ctx>>) => RuleSet<Input, Ctx>;
|
|
131
|
+
type ErrorTarget = '$value' | '$self';
|
|
132
|
+
type ListIdentityPolicy = Readonly<{
|
|
133
|
+
readonly mode: 'trackBy';
|
|
134
|
+
readonly trackBy: string;
|
|
135
|
+
}> | Readonly<{
|
|
136
|
+
readonly mode: 'store';
|
|
137
|
+
}> | Readonly<{
|
|
138
|
+
readonly mode: 'index';
|
|
139
|
+
}>;
|
|
140
|
+
type FieldDecl<Input, Ctx = unknown> = Readonly<{
|
|
141
|
+
readonly kind: 'field';
|
|
142
|
+
readonly valuePath: string;
|
|
143
|
+
readonly rule: RuleInput<Input, Ctx>;
|
|
144
|
+
readonly errorTarget?: ErrorTarget;
|
|
145
|
+
}>;
|
|
146
|
+
type RootDecl<Input, Ctx = unknown> = Readonly<{
|
|
147
|
+
readonly kind: 'root';
|
|
148
|
+
readonly rule: RuleInput<Input, Ctx>;
|
|
149
|
+
}>;
|
|
150
|
+
type ListDecl<Item, Ctx = unknown> = Readonly<{
|
|
151
|
+
readonly kind: 'list';
|
|
152
|
+
readonly listPath: string;
|
|
153
|
+
readonly identity: ListIdentityPolicy;
|
|
154
|
+
readonly item?: RuleInput<Item, Ctx>;
|
|
155
|
+
readonly list?: RuleInput<ReadonlyArray<Item>, Ctx>;
|
|
156
|
+
}>;
|
|
157
|
+
type RulesDecl<TValues extends object = any> = FieldDecl<any> | RootDecl<TValues> | ListDecl<any>;
|
|
158
|
+
declare const field: <Input, Ctx = unknown>(valuePath: string, rule: RuleInput<Input, Ctx>, options?: {
|
|
159
|
+
readonly errorTarget?: ErrorTarget;
|
|
160
|
+
}) => FieldDecl<Input, Ctx>;
|
|
161
|
+
declare const root: <Input, Ctx = unknown>(rule: RuleInput<Input, Ctx>) => RootDecl<Input, Ctx>;
|
|
162
|
+
declare const list: <Item, Ctx = unknown>(listPath: string, spec: {
|
|
163
|
+
readonly identity: ListIdentityPolicy;
|
|
164
|
+
readonly item?: RuleInput<Item, Ctx>;
|
|
165
|
+
readonly list?: RuleInput<ReadonlyArray<Item>, Ctx>;
|
|
166
|
+
}) => ListDecl<Item, Ctx>;
|
|
167
|
+
declare const fields: <Input, Ctx = unknown>(...decls: ReadonlyArray<FieldDecl<Input, Ctx> | ReadonlyArray<FieldDecl<Input, Ctx>>>) => Readonly<Record<string, RuleInput<Input, Ctx>>>;
|
|
168
|
+
|
|
169
|
+
type Rule$1_AutoValidateOn = AutoValidateOn;
|
|
170
|
+
declare const Rule$1_ERROR_VALUE_MAX_BYTES: typeof ERROR_VALUE_MAX_BYTES;
|
|
171
|
+
type Rule$1_ErrorTarget = ErrorTarget;
|
|
172
|
+
type Rule$1_FieldDecl<Input, Ctx = unknown> = FieldDecl<Input, Ctx>;
|
|
173
|
+
type Rule$1_ListDecl<Item, Ctx = unknown> = ListDecl<Item, Ctx>;
|
|
174
|
+
type Rule$1_ListIdentityPolicy = ListIdentityPolicy;
|
|
175
|
+
type Rule$1_RootDecl<Input, Ctx = unknown> = RootDecl<Input, Ctx>;
|
|
176
|
+
type Rule$1_Rule<Input, Ctx = unknown> = Rule<Input, Ctx>;
|
|
177
|
+
type Rule$1_RuleConfig<Input, Ctx = unknown> = RuleConfig<Input, Ctx>;
|
|
178
|
+
type Rule$1_RuleEntry<Input, Ctx = unknown> = RuleEntry<Input, Ctx>;
|
|
179
|
+
type Rule$1_RuleFn<Input, Ctx = unknown> = RuleFn<Input, Ctx>;
|
|
180
|
+
type Rule$1_RuleGroup<Input, Ctx = unknown> = RuleGroup<Input, Ctx>;
|
|
181
|
+
type Rule$1_RuleInput<Input, Ctx = unknown> = RuleInput<Input, Ctx>;
|
|
182
|
+
type Rule$1_RuleSet<Input, Ctx = unknown> = RuleSet<Input, Ctx>;
|
|
183
|
+
type Rule$1_RuleValidateOn = RuleValidateOn;
|
|
184
|
+
type Rule$1_RulesDecl<TValues extends object = any> = RulesDecl<TValues>;
|
|
185
|
+
declare const Rule$1_assertErrorValueBudget: typeof assertErrorValueBudget;
|
|
186
|
+
declare const Rule$1_field: typeof field;
|
|
187
|
+
declare const Rule$1_fields: typeof fields;
|
|
188
|
+
declare const Rule$1_list: typeof list;
|
|
189
|
+
declare const Rule$1_make: typeof make;
|
|
190
|
+
declare const Rule$1_max: typeof max;
|
|
191
|
+
declare const Rule$1_maxLength: typeof maxLength;
|
|
192
|
+
declare const Rule$1_merge: typeof merge;
|
|
193
|
+
declare const Rule$1_min: typeof min;
|
|
194
|
+
declare const Rule$1_minLength: typeof minLength;
|
|
195
|
+
declare const Rule$1_pattern: typeof pattern;
|
|
196
|
+
declare const Rule$1_required: typeof required;
|
|
197
|
+
declare const Rule$1_root: typeof root;
|
|
198
|
+
declare namespace Rule$1 {
|
|
199
|
+
export { type Rule$1_AutoValidateOn as AutoValidateOn, Rule$1_ERROR_VALUE_MAX_BYTES as ERROR_VALUE_MAX_BYTES, type Rule$1_ErrorTarget as ErrorTarget, type Rule$1_FieldDecl as FieldDecl, type Rule$1_ListDecl as ListDecl, type Rule$1_ListIdentityPolicy as ListIdentityPolicy, type Rule$1_RootDecl as RootDecl, type Rule$1_Rule as Rule, type Rule$1_RuleConfig as RuleConfig, type Rule$1_RuleEntry as RuleEntry, type Rule$1_RuleFn as RuleFn, type Rule$1_RuleGroup as RuleGroup, type Rule$1_RuleInput as RuleInput, type Rule$1_RuleSet as RuleSet, type Rule$1_RuleValidateOn as RuleValidateOn, type Rule$1_RulesDecl as RulesDecl, Rule$1_assertErrorValueBudget as assertErrorValueBudget, Rule$1_field as field, Rule$1_fields as fields, Rule$1_list as list, Rule$1_make as make, Rule$1_max as max, Rule$1_maxLength as maxLength, Rule$1_merge as merge, Rule$1_min as min, Rule$1_minLength as minLength, Rule$1_pattern as pattern, Rule$1_required as required, Rule$1_root as root };
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export { type AutoValidateOn as A, maxLength as B, type CanonicalPath as C, min as D, type ErrorTarget as E, type FieldPath as F, max as G, pattern as H, type ListIdentityPolicy as L, Rule$1 as R, type FieldValue as a, type CanonicalValue as b, type CanonicalListPath as c, type CanonicalListItem as d, type RulesDecl as e, type RuleInput as f, type RootDecl as g, type ListDecl as h, type FieldDecl as i, type RuleEntry as j, type RuleValidateOn as k, type RuleFn as l, type Rule as m, type RuleSet as n, type RuleGroup as o, type RuleConfig as p, make as q, merge as r, field as s, root as t, list as u, fields as v, ERROR_VALUE_MAX_BYTES as w, assertErrorValueBudget as x, required as y, minLength as z };
|