@reformer/core 9.1.0 → 10.0.0-beta.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/README.md +39 -28
- package/dist/behaviors-node-DUrqAqp1.js +18 -0
- package/dist/behaviors.js +1 -1
- package/dist/form/create-form.d.ts +13 -17
- package/dist/form/index.d.ts +4 -6
- package/dist/form/nodes/group-node.d.ts +2 -15
- package/dist/form/types/schema-node.d.ts +13 -9
- package/dist/form/types/validation-schema.d.ts +7 -29
- package/dist/form/validation/index.d.ts +7 -0
- package/dist/form/validation/validators/email.d.ts +1 -1
- package/dist/form/validation/validators/file-type.d.ts +31 -0
- package/dist/form/validation/validators/file-utils.d.ts +51 -0
- package/dist/form/validation/validators/future-date.d.ts +1 -1
- package/dist/form/validation/validators/index.d.ts +7 -0
- package/dist/form/validation/validators/is-date.d.ts +1 -1
- package/dist/form/validation/validators/max-file-size.d.ts +28 -0
- package/dist/form/validation/validators/max-files.d.ts +26 -0
- package/dist/form/validation/validators/max-total-file-size.d.ts +26 -0
- package/dist/form/validation/validators/min-file-size.d.ts +28 -0
- package/dist/form/validation/validators/min-files.d.ts +26 -0
- package/dist/form/validation/validators/past-date.d.ts +1 -1
- package/dist/form/validation/validators/pattern.d.ts +1 -1
- package/dist/form/validation/validators/phone.d.ts +1 -1
- package/dist/form/validation/validators/url.d.ts +1 -1
- package/dist/form/validation-schema.d.ts +93 -0
- package/dist/index.js +352 -454
- package/dist/signal-node-registry-tiwel-TV.js +11 -0
- package/dist/state/behaviors-value.d.ts +3 -3
- package/dist/validation.d.ts +2 -0
- package/dist/validation.js +115 -0
- package/dist/validators.js +196 -65
- package/llms.txt +1198 -582
- package/package.json +5 -1
- package/dist/behaviors-node-BMOI2JJF.js +0 -26
- package/dist/form/validate-model-core.d.ts +0 -72
- package/dist/form/validate-model.d.ts +0 -27
|
@@ -85,13 +85,13 @@ export declare function syncFields<T>(a: Signal<T>, b: Signal<T>, options?: {
|
|
|
85
85
|
transform?: (value: T) => T;
|
|
86
86
|
}): BehaviorCleanup;
|
|
87
87
|
/**
|
|
88
|
-
* Вызывает `revalidate()` при изменении зависимостей (не на инициализации).
|
|
89
|
-
*
|
|
88
|
+
* Вызывает `revalidate()` при изменении зависимостей (не на инициализации). Валидация on-demand
|
|
89
|
+
* (`validateModel` из `@reformer/core/validation`), поэтому ревалидация выражается явным колбэком.
|
|
90
90
|
*
|
|
91
91
|
* @group Model
|
|
92
92
|
* @example
|
|
93
93
|
* ```typescript
|
|
94
|
-
* revalidateWhen([model.$.maxAmount], () =>
|
|
94
|
+
* revalidateWhen([model.$.maxAmount], () => void validateModel(model, schema));
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
97
|
export declare function revalidateWhen(deps: ReadonlySignal<unknown>[], revalidate: () => void): BehaviorCleanup;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { g as d } from "./signal-node-registry-tiwel-TV.js";
|
|
2
|
+
let l = null;
|
|
3
|
+
function i(t) {
|
|
4
|
+
if (!l)
|
|
5
|
+
throw new Error(
|
|
6
|
+
`[@reformer/core/validation] "${t}" вызван вне схемы валидации — операторы валидации можно вызывать только внутри прогона validateModel(...) (напрямую или через apply/each).`
|
|
7
|
+
);
|
|
8
|
+
return l;
|
|
9
|
+
}
|
|
10
|
+
function f(t, n) {
|
|
11
|
+
let e = t.errors.get(n);
|
|
12
|
+
return e || t.errors.set(n, e = []), e;
|
|
13
|
+
}
|
|
14
|
+
const u = (t) => t.whenStack.every((n) => n());
|
|
15
|
+
function k(t, n) {
|
|
16
|
+
const e = i("validate"), r = f(e, t);
|
|
17
|
+
if (!u(e)) return;
|
|
18
|
+
const o = t.peek();
|
|
19
|
+
for (const a of n) {
|
|
20
|
+
const s = a(o, e.model, e.model);
|
|
21
|
+
s && r.push(s);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function y(t, n) {
|
|
25
|
+
const e = i("validateAsync"), r = f(e, t);
|
|
26
|
+
if (!u(e)) return;
|
|
27
|
+
const o = t.peek(), a = e.signal;
|
|
28
|
+
for (const s of n)
|
|
29
|
+
e.pending.push(
|
|
30
|
+
s(o, { signal: a }).then(
|
|
31
|
+
(c) => {
|
|
32
|
+
c && !a.aborted && r.push(c);
|
|
33
|
+
},
|
|
34
|
+
() => {
|
|
35
|
+
}
|
|
36
|
+
)
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function b(t, n) {
|
|
40
|
+
const e = i("validateWhen");
|
|
41
|
+
e.whenStack.push(t);
|
|
42
|
+
try {
|
|
43
|
+
n();
|
|
44
|
+
} finally {
|
|
45
|
+
e.whenStack.pop();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function m(t, n) {
|
|
49
|
+
const e = i("cross"), r = f(e, t);
|
|
50
|
+
if (!u(e)) return;
|
|
51
|
+
const o = n(e.model.get());
|
|
52
|
+
o && r.push(o);
|
|
53
|
+
}
|
|
54
|
+
function S(t, n) {
|
|
55
|
+
i("each");
|
|
56
|
+
const e = t.length;
|
|
57
|
+
for (let r = 0; r < e; r++) n(t.at(r));
|
|
58
|
+
}
|
|
59
|
+
function x(...t) {
|
|
60
|
+
const e = i("apply").model;
|
|
61
|
+
for (const r of t) r({ model: e });
|
|
62
|
+
}
|
|
63
|
+
function M(t) {
|
|
64
|
+
return t;
|
|
65
|
+
}
|
|
66
|
+
const p = /* @__PURE__ */ new WeakMap();
|
|
67
|
+
function h(t, n) {
|
|
68
|
+
let e = p.get(t);
|
|
69
|
+
e || p.set(t, e = /* @__PURE__ */ new WeakMap());
|
|
70
|
+
let r = e.get(n);
|
|
71
|
+
return r || e.set(n, r = { fields: /* @__PURE__ */ new Set(), ac: null }), r;
|
|
72
|
+
}
|
|
73
|
+
const g = (t) => {
|
|
74
|
+
for (const n of t.values()) for (const e of n) if (e.severity !== "warning") return !0;
|
|
75
|
+
return !1;
|
|
76
|
+
};
|
|
77
|
+
function v(t) {
|
|
78
|
+
return t.aborted ? Promise.resolve() : new Promise((n) => {
|
|
79
|
+
t.addEventListener("abort", () => n(), { once: !0 });
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
async function A(t, n) {
|
|
83
|
+
const e = h(t, n);
|
|
84
|
+
e.ac?.abort();
|
|
85
|
+
const r = new AbortController();
|
|
86
|
+
e.ac = r;
|
|
87
|
+
const o = {
|
|
88
|
+
model: t,
|
|
89
|
+
errors: /* @__PURE__ */ new Map(),
|
|
90
|
+
pending: [],
|
|
91
|
+
whenStack: [],
|
|
92
|
+
signal: r.signal
|
|
93
|
+
}, a = l;
|
|
94
|
+
l = o;
|
|
95
|
+
try {
|
|
96
|
+
n({ model: t });
|
|
97
|
+
} finally {
|
|
98
|
+
l = a;
|
|
99
|
+
}
|
|
100
|
+
if (o.pending.length && await Promise.race([Promise.all(o.pending), v(r.signal)]), r.signal.aborted) return !1;
|
|
101
|
+
const s = new Set(o.errors.keys());
|
|
102
|
+
for (const c of e.fields) s.has(c) || d(c)?.setErrors([]);
|
|
103
|
+
for (const c of s) d(c)?.setErrors(o.errors.get(c) ?? []);
|
|
104
|
+
return e.fields = s, !g(o.errors);
|
|
105
|
+
}
|
|
106
|
+
export {
|
|
107
|
+
x as apply,
|
|
108
|
+
m as cross,
|
|
109
|
+
M as defineValidationSchema,
|
|
110
|
+
S as each,
|
|
111
|
+
k as validate,
|
|
112
|
+
y as validateAsync,
|
|
113
|
+
A as validateModel,
|
|
114
|
+
b as validateWhen
|
|
115
|
+
};
|
package/dist/validators.js
CHANGED
|
@@ -1,69 +1,200 @@
|
|
|
1
|
-
import { required as
|
|
2
|
-
import { min as
|
|
3
|
-
import { max as
|
|
4
|
-
import { minLength as
|
|
5
|
-
import { maxLength as
|
|
6
|
-
import { email as
|
|
7
|
-
import { pattern as
|
|
8
|
-
import { url as
|
|
9
|
-
import { phone as
|
|
10
|
-
import { isNumber as
|
|
11
|
-
import { integer as
|
|
12
|
-
import { multipleOf as
|
|
13
|
-
import { nonNegative as
|
|
14
|
-
import { nonZero as
|
|
15
|
-
import { isDate as
|
|
16
|
-
import { minDate as
|
|
17
|
-
import { maxDate as
|
|
18
|
-
import { pastDate as
|
|
19
|
-
import { futureDate as
|
|
20
|
-
import { minAge as
|
|
21
|
-
import { maxAge as
|
|
22
|
-
|
|
1
|
+
import { required as u } from "./validators/required.js";
|
|
2
|
+
import { min as a } from "./validators/min.js";
|
|
3
|
+
import { max as p } from "./validators/max.js";
|
|
4
|
+
import { minLength as c } from "./validators/min-length.js";
|
|
5
|
+
import { maxLength as g } from "./validators/max-length.js";
|
|
6
|
+
import { email as d } from "./validators/email.js";
|
|
7
|
+
import { pattern as z } from "./validators/pattern.js";
|
|
8
|
+
import { url as h } from "./validators/url.js";
|
|
9
|
+
import { phone as y } from "./validators/phone.js";
|
|
10
|
+
import { isNumber as F } from "./validators/is-number.js";
|
|
11
|
+
import { integer as x } from "./validators/integer.js";
|
|
12
|
+
import { multipleOf as S } from "./validators/multiple-of.js";
|
|
13
|
+
import { nonNegative as b } from "./validators/non-negative.js";
|
|
14
|
+
import { nonZero as A } from "./validators/non-zero.js";
|
|
15
|
+
import { isDate as L } from "./validators/is-date.js";
|
|
16
|
+
import { minDate as T } from "./validators/min-date.js";
|
|
17
|
+
import { maxDate as C } from "./validators/max-date.js";
|
|
18
|
+
import { pastDate as D } from "./validators/past-date.js";
|
|
19
|
+
import { futureDate as N } from "./validators/future-date.js";
|
|
20
|
+
import { minAge as W } from "./validators/min-age.js";
|
|
21
|
+
import { maxAge as _ } from "./validators/max-age.js";
|
|
22
|
+
function m(r) {
|
|
23
|
+
if (typeof r != "object" || r === null) return !1;
|
|
24
|
+
const i = r;
|
|
25
|
+
return !(typeof i.name != "string" || i.size !== void 0 && typeof i.size != "number" || i.type !== void 0 && typeof i.type != "string");
|
|
26
|
+
}
|
|
27
|
+
function o(r) {
|
|
28
|
+
return Array.isArray(r) ? r.filter(m) : m(r) ? [r] : null;
|
|
29
|
+
}
|
|
30
|
+
function s(r, i) {
|
|
31
|
+
const e = i.split(",").map((l) => l.trim().toLowerCase()).filter(Boolean);
|
|
32
|
+
if (e.length === 0) return !0;
|
|
33
|
+
const n = r.name.toLowerCase(), t = (r.type ?? "").toLowerCase();
|
|
34
|
+
return e.some((l) => l.startsWith(".") ? n.endsWith(l) : l.endsWith("/*") ? t.startsWith(l.slice(0, -1)) : l.includes("/") ? t === l : !1);
|
|
35
|
+
}
|
|
36
|
+
function j(r, i) {
|
|
37
|
+
return (e) => {
|
|
38
|
+
if (e == null || e === "")
|
|
39
|
+
return null;
|
|
40
|
+
const n = o(e);
|
|
41
|
+
if (n === null || n.length === 0) return null;
|
|
42
|
+
for (const t of n)
|
|
43
|
+
if (typeof t.size == "number" && t.size > r)
|
|
44
|
+
return {
|
|
45
|
+
code: "maxFileSize",
|
|
46
|
+
message: i?.message ?? "invalid",
|
|
47
|
+
params: {
|
|
48
|
+
maxFileSize: r,
|
|
49
|
+
fileName: t.name,
|
|
50
|
+
actualSize: t.size,
|
|
51
|
+
...i?.params
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
return null;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function w(r, i) {
|
|
58
|
+
return (e) => {
|
|
59
|
+
if (e == null || e === "")
|
|
60
|
+
return null;
|
|
61
|
+
const n = o(e);
|
|
62
|
+
if (n === null || n.length === 0) return null;
|
|
63
|
+
for (const t of n)
|
|
64
|
+
if (typeof t.size == "number" && t.size < r)
|
|
65
|
+
return {
|
|
66
|
+
code: "minFileSize",
|
|
67
|
+
message: i?.message ?? "invalid",
|
|
68
|
+
params: {
|
|
69
|
+
minFileSize: r,
|
|
70
|
+
fileName: t.name,
|
|
71
|
+
actualSize: t.size,
|
|
72
|
+
...i?.params
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function O(r, i) {
|
|
79
|
+
return (e) => {
|
|
80
|
+
if (e == null || e === "")
|
|
81
|
+
return null;
|
|
82
|
+
const n = o(e);
|
|
83
|
+
if (n === null || n.length === 0) return null;
|
|
84
|
+
for (const t of n)
|
|
85
|
+
if (!s(t, r))
|
|
86
|
+
return {
|
|
87
|
+
code: "fileType",
|
|
88
|
+
message: i?.message ?? "invalid",
|
|
89
|
+
params: { accept: r, fileName: t.name, ...i?.params }
|
|
90
|
+
};
|
|
91
|
+
return null;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function k(r, i) {
|
|
95
|
+
return (e) => {
|
|
96
|
+
if (e == null || e === "")
|
|
97
|
+
return null;
|
|
98
|
+
const n = o(e);
|
|
99
|
+
return n === null || n.length === 0 ? null : n.length > r ? {
|
|
100
|
+
code: "maxFiles",
|
|
101
|
+
message: i?.message ?? "invalid",
|
|
102
|
+
params: { maxFiles: r, actualCount: n.length, ...i?.params }
|
|
103
|
+
} : null;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function q(r, i) {
|
|
107
|
+
return (e) => {
|
|
108
|
+
if (e == null || e === "")
|
|
109
|
+
return null;
|
|
110
|
+
const n = o(e);
|
|
111
|
+
return n === null || n.length === 0 ? null : n.length < r ? {
|
|
112
|
+
code: "minFiles",
|
|
113
|
+
message: i?.message ?? "invalid",
|
|
114
|
+
params: { minFiles: r, actualCount: n.length, ...i?.params }
|
|
115
|
+
} : null;
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
function B(r, i) {
|
|
119
|
+
return (e) => {
|
|
120
|
+
if (e == null || e === "")
|
|
121
|
+
return null;
|
|
122
|
+
const n = o(e);
|
|
123
|
+
if (n === null || n.length === 0) return null;
|
|
124
|
+
const t = n.reduce(
|
|
125
|
+
(l, f) => l + (typeof f.size == "number" ? f.size : 0),
|
|
126
|
+
0
|
|
127
|
+
);
|
|
128
|
+
return t > r ? {
|
|
129
|
+
code: "maxTotalFileSize",
|
|
130
|
+
message: i?.message ?? "invalid",
|
|
131
|
+
params: { maxTotalFileSize: r, actualTotal: t, ...i?.params }
|
|
132
|
+
} : null;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const te = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
23
136
|
__proto__: null,
|
|
24
|
-
email:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
137
|
+
email: d,
|
|
138
|
+
fileType: O,
|
|
139
|
+
futureDate: N,
|
|
140
|
+
integer: x,
|
|
141
|
+
isDate: L,
|
|
142
|
+
isFileLike: m,
|
|
143
|
+
isNumber: F,
|
|
144
|
+
matchesFileAccept: s,
|
|
145
|
+
max: p,
|
|
146
|
+
maxAge: _,
|
|
147
|
+
maxDate: C,
|
|
148
|
+
maxFileSize: j,
|
|
149
|
+
maxFiles: k,
|
|
150
|
+
maxLength: g,
|
|
151
|
+
maxTotalFileSize: B,
|
|
152
|
+
min: a,
|
|
153
|
+
minAge: W,
|
|
154
|
+
minDate: T,
|
|
155
|
+
minFileSize: w,
|
|
156
|
+
minFiles: q,
|
|
157
|
+
minLength: c,
|
|
158
|
+
multipleOf: S,
|
|
159
|
+
nonNegative: b,
|
|
160
|
+
nonZero: A,
|
|
161
|
+
pastDate: D,
|
|
162
|
+
pattern: z,
|
|
163
|
+
phone: y,
|
|
164
|
+
required: u,
|
|
165
|
+
toFileArray: o,
|
|
166
|
+
url: h
|
|
45
167
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
46
168
|
export {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
169
|
+
te as default,
|
|
170
|
+
d as email,
|
|
171
|
+
O as fileType,
|
|
172
|
+
N as futureDate,
|
|
173
|
+
x as integer,
|
|
174
|
+
L as isDate,
|
|
175
|
+
m as isFileLike,
|
|
176
|
+
F as isNumber,
|
|
177
|
+
s as matchesFileAccept,
|
|
178
|
+
p as max,
|
|
179
|
+
_ as maxAge,
|
|
180
|
+
C as maxDate,
|
|
181
|
+
j as maxFileSize,
|
|
182
|
+
k as maxFiles,
|
|
183
|
+
g as maxLength,
|
|
184
|
+
B as maxTotalFileSize,
|
|
185
|
+
a as min,
|
|
186
|
+
W as minAge,
|
|
187
|
+
T as minDate,
|
|
188
|
+
w as minFileSize,
|
|
189
|
+
q as minFiles,
|
|
190
|
+
c as minLength,
|
|
191
|
+
S as multipleOf,
|
|
192
|
+
b as nonNegative,
|
|
193
|
+
A as nonZero,
|
|
194
|
+
D as pastDate,
|
|
195
|
+
z as pattern,
|
|
196
|
+
y as phone,
|
|
197
|
+
u as required,
|
|
198
|
+
o as toFileArray,
|
|
199
|
+
h as url
|
|
69
200
|
};
|