@reformer/core 1.1.0-beta.3 → 1.1.0-beta.5

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,156 @@
1
+ import { V as d } from "./registry-helpers-BfCZcMkO.js";
2
+ function g() {
3
+ return l("");
4
+ }
5
+ function l(t) {
6
+ return new Proxy({}, {
7
+ get(e, i) {
8
+ if (typeof i == "symbol")
9
+ return;
10
+ if (i === "__path")
11
+ return t || i;
12
+ if (i === "__key") {
13
+ const a = t.split(".");
14
+ return a[a.length - 1] || i;
15
+ }
16
+ if (i === "then" || i === "catch" || i === "finally" || i === "constructor" || i === "toString" || i === "valueOf" || i === "toJSON")
17
+ return;
18
+ const n = t ? `${t}.${i}` : i, o = {
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ __key: i,
21
+ __path: n,
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ __formType: void 0,
24
+ __fieldType: void 0
25
+ };
26
+ return new Proxy(o, {
27
+ get(a, r) {
28
+ if (typeof r != "symbol") {
29
+ if (r === "__path") return n;
30
+ if (r === "__key") return i;
31
+ if (r !== "__formType" && r !== "__fieldType" && !(r === "then" || r === "catch" || r === "finally" || r === "constructor" || r === "toString" || r === "valueOf" || r === "toJSON"))
32
+ return l(`${n}.${r}`);
33
+ }
34
+ }
35
+ });
36
+ }
37
+ });
38
+ }
39
+ function m(t) {
40
+ if (typeof t == "string")
41
+ return t;
42
+ if (t && typeof t == "object") {
43
+ const e = t.__path;
44
+ if (typeof e == "string")
45
+ return e;
46
+ }
47
+ throw new Error("Invalid field path node: " + JSON.stringify(t));
48
+ }
49
+ function F(t) {
50
+ const e = m(t);
51
+ return l(e);
52
+ }
53
+ function V(t) {
54
+ if (t && typeof t == "object" && "__key" in t)
55
+ return t.__key;
56
+ if (typeof t == "string") {
57
+ const e = t.split(".");
58
+ return e[e.length - 1];
59
+ }
60
+ throw new Error("Invalid field path node");
61
+ }
62
+ function s(t) {
63
+ return t == null ? !1 : typeof t == "object" && "value" in t && "setValue" in t && "getValue" in t && "validate" in t;
64
+ }
65
+ function c(t) {
66
+ return t == null ? !1 : s(t) && "validators" in t && "asyncValidators" in t && // FieldNode имеет markAsTouched метод
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ typeof t.markAsTouched == "function" && // У FieldNode нет fields или items
69
+ !("fields" in t) && !("items" in t);
70
+ }
71
+ function u(t) {
72
+ return t == null ? !1 : s(t) && "applyValidationSchema" in t && "applyBehaviorSchema" in t && "getFieldByPath" in t && // GroupNode НЕ имеет items/push/removeAt (это ArrayNode)
73
+ !("items" in t) && !("push" in t) && !("removeAt" in t);
74
+ }
75
+ function y(t) {
76
+ return t == null ? !1 : s(t) && "items" in t && "length" in t && "push" in t && "removeAt" in t && "at" in t && // eslint-disable-next-line @typescript-eslint/no-explicit-any
77
+ typeof t.push == "function" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
+ typeof t.removeAt == "function";
79
+ }
80
+ function N(t) {
81
+ return c(t) ? "FieldNode" : u(t) ? "GroupNode" : y(t) ? "ArrayNode" : s(t) ? "FormNode" : "Unknown";
82
+ }
83
+ function f(t) {
84
+ return c(t) ? [t] : u(t) ? Array.from(t.getAllFields()).flatMap(f) : y(t) ? t.map((e) => f(e)).flat() : [];
85
+ }
86
+ async function w(t, e) {
87
+ const i = new d();
88
+ i.beginRegistration();
89
+ let n = [], o = !1;
90
+ try {
91
+ const a = g();
92
+ e(a), n = i.getCurrentContext()?.getValidators() || [], i.cancelRegistration(), o = !0, t.clearErrors();
93
+ const h = f(t);
94
+ return await Promise.all(h.map((_) => _.validate())), n.length > 0 && await t.applyContextualValidators(n), t.valid.value;
95
+ } catch (a) {
96
+ throw o || i.cancelRegistration(), a;
97
+ }
98
+ }
99
+ class A {
100
+ _form;
101
+ control;
102
+ /**
103
+ * Форма с типизированным Proxy-доступом к полям
104
+ */
105
+ form;
106
+ constructor(e, i, n) {
107
+ this._form = e, this.control = n, this.form = e._proxyInstance || e.getProxy();
108
+ }
109
+ /**
110
+ * Получить текущее значение поля (внутренний метод для validation-applicator)
111
+ * @internal
112
+ */
113
+ value() {
114
+ return this.control.value.value;
115
+ }
116
+ /**
117
+ * Безопасно установить значение поля по строковому пути
118
+ * Автоматически использует emitEvent: false для предотвращения циклов
119
+ */
120
+ setFieldValue(e, i) {
121
+ const n = this._form.getFieldByPath(e);
122
+ n && s(n) && n.setValue(i, { emitEvent: !1 });
123
+ }
124
+ }
125
+ class T {
126
+ _form;
127
+ /**
128
+ * Форма с типизированным Proxy-доступом к полям
129
+ */
130
+ form;
131
+ constructor(e) {
132
+ this._form = e, this.form = e._proxyInstance || e.getProxy();
133
+ }
134
+ /**
135
+ * Безопасно установить значение поля по строковому пути
136
+ * Автоматически использует emitEvent: false для предотвращения циклов
137
+ */
138
+ setFieldValue(e, i) {
139
+ const n = this._form.getFieldByPath(e);
140
+ n && s(n) && n.setValue(i, { emitEvent: !1 });
141
+ }
142
+ }
143
+ export {
144
+ T,
145
+ A as V,
146
+ s as a,
147
+ u as b,
148
+ g as c,
149
+ y as d,
150
+ m as e,
151
+ V as f,
152
+ N as g,
153
+ c as i,
154
+ F as t,
155
+ w as v
156
+ };
@@ -1,44 +1,45 @@
1
- import { h as g, t as o, j as f, a as x, G as y, A } from "./node-factory-D7DOnSSN.js";
2
- import { T as G, V as U, k as B } from "./node-factory-D7DOnSSN.js";
3
- import { g as u, V as w } from "./create-field-path-CdPF3lIK.js";
4
- function m(r, e, a) {
1
+ import { e as c, t as l, c as i } from "./validation-context-cWXmh_Ho.js";
2
+ import { T as H, V as P, f as W, v as M } from "./validation-context-cWXmh_Ho.js";
3
+ import { g as u } from "./registry-helpers-BfCZcMkO.js";
4
+ import { V as j } from "./registry-helpers-BfCZcMkO.js";
5
+ function n(r, e, a) {
5
6
  if (!r) return;
6
- const t = g(r);
7
- u().registerSync(t, e, a);
7
+ const m = c(r);
8
+ u().registerSync(m, e, a);
8
9
  }
9
- function D(r, e, a) {
10
- const t = g(r);
11
- u().registerAsync(t, e, a);
10
+ function A(r, e, a) {
11
+ const m = c(r);
12
+ u().registerAsync(m, e, a);
12
13
  }
13
- function b(r, e) {
14
+ function _(r, e) {
14
15
  u().registerTree(r, e);
15
16
  }
16
- function R(r, e) {
17
+ function $(r, e) {
17
18
  if (!Array.isArray(r) && !Array.isArray(e) && r && !("__key" in r) && !("__path" in r)) {
18
19
  e(r);
19
20
  return;
20
21
  }
21
22
  const a = (Array.isArray(r) ? r : [r]).filter(
22
23
  Boolean
23
- ), t = Array.isArray(e) ? e : [e];
24
- for (const n of a) {
25
- const s = o(n);
26
- for (const c of t)
27
- c(s);
24
+ ), m = Array.isArray(e) ? e : [e];
25
+ for (const s of a) {
26
+ const t = l(s);
27
+ for (const g of m)
28
+ g(t);
28
29
  }
29
30
  }
30
- function p(r, e, a) {
31
- const t = g(r);
32
- u().enterCondition(t, e);
31
+ function o(r, e, a) {
32
+ const m = c(r);
33
+ u().enterCondition(m, e);
33
34
  try {
34
- const n = f();
35
- a(n);
35
+ const s = i();
36
+ a(s);
36
37
  } finally {
37
38
  u().exitCondition();
38
39
  }
39
40
  }
40
- function N(r, e) {
41
- r && m(r, (a) => a == null || a === "" ? {
41
+ function w(r, e) {
42
+ r && n(r, (a) => a == null || a === "" ? {
42
43
  code: "required",
43
44
  message: e?.message || "Поле обязательно для заполнения",
44
45
  params: e?.params
@@ -48,55 +49,55 @@ function N(r, e) {
48
49
  params: e?.params
49
50
  } : null);
50
51
  }
51
- function L(r, e, a) {
52
- r && m(r, (t) => t == null ? null : t < e ? {
52
+ function D(r, e, a) {
53
+ r && n(r, (m) => m == null ? null : m < e ? {
53
54
  code: "min",
54
55
  message: a?.message || `Минимальное значение: ${e}`,
55
- params: { min: e, actual: t, ...a?.params }
56
+ params: { min: e, actual: m, ...a?.params }
56
57
  } : null);
57
58
  }
58
- function C(r, e, a) {
59
- r && m(r, (t) => t == null ? null : t > e ? {
59
+ function h(r, e, a) {
60
+ r && n(r, (m) => m == null ? null : m > e ? {
60
61
  code: "max",
61
62
  message: a?.message || `Максимальное значение: ${e}`,
62
- params: { max: e, actual: t, ...a?.params }
63
+ params: { max: e, actual: m, ...a?.params }
63
64
  } : null);
64
65
  }
65
- function _(r, e, a) {
66
- r && m(r, (t) => t && t.length < e ? {
66
+ function d(r, e, a) {
67
+ r && n(r, (m) => m && m.length < e ? {
67
68
  code: "minLength",
68
69
  message: a?.message || `Минимальная длина: ${e} символов`,
69
- params: { minLength: e, actualLength: t.length, ...a?.params }
70
+ params: { minLength: e, actualLength: m.length, ...a?.params }
70
71
  } : null);
71
72
  }
72
- function T(r, e, a) {
73
- r && m(r, (t) => t && t.length > e ? {
73
+ function b(r, e, a) {
74
+ r && n(r, (m) => m && m.length > e ? {
74
75
  code: "maxLength",
75
76
  message: a?.message || `Максимальная длина: ${e} символов`,
76
- params: { maxLength: e, actualLength: t.length, ...a?.params }
77
+ params: { maxLength: e, actualLength: m.length, ...a?.params }
77
78
  } : null);
78
79
  }
79
- function V(r, e) {
80
+ function L(r, e) {
80
81
  if (!r) return;
81
82
  const a = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
82
- m(r, (t) => t ? a.test(t) ? null : {
83
+ n(r, (m) => m ? a.test(m) ? null : {
83
84
  code: "email",
84
85
  message: e?.message || "Неверный формат email",
85
86
  params: e?.params
86
87
  } : null);
87
88
  }
88
- function q(r, e, a) {
89
- r && m(r, (t) => t ? e.test(t) ? null : {
89
+ function R(r, e, a) {
90
+ r && n(r, (m) => m ? e.test(m) ? null : {
90
91
  code: "pattern",
91
92
  message: a?.message || "Значение не соответствует требуемому формату",
92
93
  params: { pattern: e.source, ...a?.params }
93
94
  } : null);
94
95
  }
95
- function z(r, e) {
96
+ function T(r, e) {
96
97
  if (!r) return;
97
- const a = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i, t = /^https?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i;
98
- m(r, (n) => n ? (e?.requireProtocol ? t : a).test(n) ? e?.allowedProtocols && e.allowedProtocols.length > 0 && !e.allowedProtocols.some(
99
- (l) => n.toLowerCase().startsWith(`${l}://`)
98
+ const a = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i, m = /^https?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i;
99
+ n(r, (s) => s ? (e?.requireProtocol ? m : a).test(s) ? e?.allowedProtocols && e.allowedProtocols.length > 0 && !e.allowedProtocols.some(
100
+ (f) => s.toLowerCase().startsWith(`${f}://`)
100
101
  ) ? {
101
102
  code: "url_protocol",
102
103
  message: e?.message || `URL должен использовать один из протоколов: ${e.allowedProtocols.join(", ")}`,
@@ -107,9 +108,9 @@ function z(r, e) {
107
108
  params: e?.params
108
109
  } : null);
109
110
  }
110
- function I(r, e) {
111
+ function C(r, e) {
111
112
  if (!r) return;
112
- const a = e?.format || "any", t = {
113
+ const a = e?.format || "any", m = {
113
114
  // Международный формат: +1234567890 или +1 234 567 8900
114
115
  international: /^\+?[1-9]\d{1,14}$/,
115
116
  // Российский формат: +7 (XXX) XXX-XX-XX, 8 (XXX) XXX-XX-XX, и вариации
@@ -119,11 +120,11 @@ function I(r, e) {
119
120
  // Любой формат: минимум 10 цифр с возможными разделителями
120
121
  any: /^[\+]?[(]?[0-9]{1,4}[)]?[-\s\.]?[(]?[0-9]{1,4}[)]?[-\s\.]?[0-9]{1,9}$/
121
122
  };
122
- m(r, (n) => {
123
- if (!n)
123
+ n(r, (s) => {
124
+ if (!s)
124
125
  return null;
125
- if (!t[a].test(n)) {
126
- const c = {
126
+ if (!m[a].test(s)) {
127
+ const g = {
127
128
  international: "Введите телефон в международном формате (например, +1234567890)",
128
129
  ru: "Введите российский номер телефона (например, +7 900 123-45-67)",
129
130
  us: "Введите американский номер телефона (например, (123) 456-7890)",
@@ -131,15 +132,15 @@ function I(r, e) {
131
132
  };
132
133
  return {
133
134
  code: "phone",
134
- message: e?.message || c[a],
135
+ message: e?.message || g[a],
135
136
  params: { format: a, ...e?.params }
136
137
  };
137
138
  }
138
139
  return null;
139
140
  });
140
141
  }
141
- function P(r, e) {
142
- r && m(r, (a) => a == null ? null : typeof a != "number" || isNaN(a) ? {
142
+ function N(r, e) {
143
+ r && n(r, (a) => a == null ? null : typeof a != "number" || isNaN(a) ? {
143
144
  code: "number",
144
145
  message: e?.message || "Значение должно быть числом",
145
146
  params: e?.params
@@ -169,130 +170,114 @@ function P(r, e) {
169
170
  params: e?.params
170
171
  } : null);
171
172
  }
172
- function H(r, e) {
173
- r && m(r, (a) => {
173
+ function q(r, e) {
174
+ r && n(r, (a) => {
174
175
  if (!a)
175
176
  return null;
176
- let t;
177
+ let m;
177
178
  if (a instanceof Date)
178
- t = a;
179
+ m = a;
179
180
  else if (typeof a == "string")
180
- t = new Date(a);
181
+ m = new Date(a);
181
182
  else
182
183
  return {
183
184
  code: "date_invalid",
184
185
  message: e?.message || "Неверный формат даты",
185
186
  params: e?.params
186
187
  };
187
- if (isNaN(t.getTime()))
188
+ if (isNaN(m.getTime()))
188
189
  return {
189
190
  code: "date_invalid",
190
191
  message: e?.message || "Неверный формат даты",
191
192
  params: e?.params
192
193
  };
193
- const n = /* @__PURE__ */ new Date();
194
- if (n.setHours(0, 0, 0, 0), e?.minDate) {
195
- const s = new Date(e.minDate);
196
- if (s.setHours(0, 0, 0, 0), t < s)
194
+ const s = /* @__PURE__ */ new Date();
195
+ if (s.setHours(0, 0, 0, 0), e?.minDate) {
196
+ const t = new Date(e.minDate);
197
+ if (t.setHours(0, 0, 0, 0), m < t)
197
198
  return {
198
199
  code: "date_min",
199
- message: e?.message || `Дата должна быть не ранее ${s.toLocaleDateString()}`,
200
+ message: e?.message || `Дата должна быть не ранее ${t.toLocaleDateString()}`,
200
201
  params: { minDate: e.minDate, ...e?.params }
201
202
  };
202
203
  }
203
204
  if (e?.maxDate) {
204
- const s = new Date(e.maxDate);
205
- if (s.setHours(0, 0, 0, 0), t > s)
205
+ const t = new Date(e.maxDate);
206
+ if (t.setHours(0, 0, 0, 0), m > t)
206
207
  return {
207
208
  code: "date_max",
208
- message: e?.message || `Дата должна быть не позднее ${s.toLocaleDateString()}`,
209
+ message: e?.message || `Дата должна быть не позднее ${t.toLocaleDateString()}`,
209
210
  params: { maxDate: e.maxDate, ...e?.params }
210
211
  };
211
212
  }
212
- if (e?.noFuture && t > n)
213
+ if (e?.noFuture && m > s)
213
214
  return {
214
215
  code: "date_future",
215
216
  message: e?.message || "Дата не может быть в будущем",
216
217
  params: e?.params
217
218
  };
218
- if (e?.noPast && t < n)
219
+ if (e?.noPast && m < s)
219
220
  return {
220
221
  code: "date_past",
221
222
  message: e?.message || "Дата не может быть в прошлом",
222
223
  params: e?.params
223
224
  };
224
225
  if (e?.minAge !== void 0 || e?.maxAge !== void 0) {
225
- const s = Math.floor(
226
- (n.getTime() - t.getTime()) / 315576e5
226
+ const t = Math.floor(
227
+ (s.getTime() - m.getTime()) / 315576e5
227
228
  );
228
- if (e?.minAge !== void 0 && s < e.minAge)
229
+ if (e?.minAge !== void 0 && t < e.minAge)
229
230
  return {
230
231
  code: "date_min_age",
231
232
  message: e?.message || `Минимальный возраст: ${e.minAge} лет`,
232
- params: { minAge: e.minAge, currentAge: s, ...e?.params }
233
+ params: { minAge: e.minAge, currentAge: t, ...e?.params }
233
234
  };
234
- if (e?.maxAge !== void 0 && s > e.maxAge)
235
+ if (e?.maxAge !== void 0 && t > e.maxAge)
235
236
  return {
236
237
  code: "date_max_age",
237
238
  message: e?.message || `Максимальный возраст: ${e.maxAge} лет`,
238
- params: { maxAge: e.maxAge, currentAge: s, ...e?.params }
239
+ params: { maxAge: e.maxAge, currentAge: t, ...e?.params }
239
240
  };
240
241
  }
241
242
  return null;
242
243
  });
243
244
  }
244
- function M(r, e) {
245
- r && _(r, 1, {
245
+ function z(r, e) {
246
+ r && d(r, 1, {
246
247
  message: e?.message || "Массив не должен быть пустым",
247
248
  params: { minLength: 1, ...e?.params }
248
249
  });
249
250
  }
250
- function W(r, e) {
251
+ function I(r, e) {
251
252
  if (!r) return;
252
- const a = g(r);
253
+ const a = c(r);
253
254
  u().registerArrayItemValidation(a, e);
254
255
  }
255
- function i(r) {
256
- return r instanceof x ? [r] : r instanceof y ? Array.from(r.getAllFields()).flatMap(i) : r instanceof A ? r.map((e) => i(e)).flat() : [];
257
- }
258
- async function j(r, e) {
259
- const a = new w();
260
- a.beginRegistration();
261
- let t = [], n = !1;
262
- try {
263
- const s = f();
264
- e(s), t = a.getCurrentContext()?.getValidators() || [], a.cancelRegistration(), n = !0, r.clearErrors();
265
- const l = i(r);
266
- return await Promise.all(l.map((d) => d.validate())), t.length > 0 && await r.applyContextualValidators(t), r.valid.value;
267
- } catch (s) {
268
- throw n || a.cancelRegistration(), s;
269
- }
270
- }
271
256
  export {
272
- G as TreeValidationContextImpl,
273
- U as ValidationContextImpl,
274
- w as ValidationRegistry,
275
- R as apply,
276
- p as applyWhen,
277
- f as createFieldPath,
278
- H as date,
279
- V as email,
280
- B as extractKey,
281
- g as extractPath,
282
- C as max,
283
- T as maxLength,
284
- L as min,
285
- _ as minLength,
286
- M as notEmpty,
287
- P as number,
288
- q as pattern,
289
- I as phone,
290
- N as required,
291
- o as toFieldPath,
292
- z as url,
293
- m as validate,
294
- D as validateAsync,
295
- j as validateForm,
296
- W as validateItems,
297
- b as validateTree
257
+ H as TreeValidationContextImpl,
258
+ P as ValidationContextImpl,
259
+ j as ValidationRegistry,
260
+ $ as apply,
261
+ o as applyWhen,
262
+ i as createFieldPath,
263
+ q as date,
264
+ L as email,
265
+ W as extractKey,
266
+ c as extractPath,
267
+ h as max,
268
+ b as maxLength,
269
+ D as min,
270
+ d as minLength,
271
+ z as notEmpty,
272
+ N as number,
273
+ R as pattern,
274
+ C as phone,
275
+ w as required,
276
+ l as toFieldPath,
277
+ T as url,
278
+ n as validate,
279
+ A as validateAsync,
280
+ M as validateForm,
281
+ I as validateItems,
282
+ _ as validateTree
298
283
  };