@scbt-ecom/ui 0.31.5 → 0.33.0

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.
@@ -1,230 +1,393 @@
1
- import { z as o, V as l, p as m, i as _, D as E } from "./utils-b38KjjXe.js";
2
- import { T as f } from "./typeGuards-B82KZ2oS.js";
3
- const T = /^[\u0400-\u04FF\u00CB\u00EB -]+$/, I = /^(?:[^-]+(?:-[^-]+){0,4}|[^-]+)$/, L = /^[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4}(?:\s+[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4})?$/i, O = (n) => {
4
- const t = n.trim().replace(/\s+/g, " ").split(" "), [s, e, ...i] = t, d = i == null ? void 0 : i.join(" ");
1
+ import { z as o, V as l, p as I, i as E, D as A } from "./utils-b38KjjXe.js";
2
+ import { T as L } from "./typeGuards-B82KZ2oS.js";
3
+ const D = /^[\u0400-\u04FF\u00CB\u00EB -]+$/, N = /^(?:[^-]+(?:-[^-]+){0,4}|[^-]+)$/, Z = /^[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4}(?:\s+[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4})?$/i, h = (e) => {
4
+ const t = e.trim().replace(/\s+/g, " ").split(" "), [s, n, ...i] = t, a = i == null ? void 0 : i.join(" ");
5
5
  return {
6
6
  surname: s,
7
- name: e,
8
- patronymic: d
7
+ name: n,
8
+ patronymic: a
9
9
  };
10
- }, b = o.string({ invalid_type_error: "Обязательно к заполнению", required_error: "Обязательно к заполнению" }).superRefine((n, t) => {
11
- n === "" && t.addIssue({
10
+ }, ee = o.string({ invalid_type_error: "Обязательно к заполнению", required_error: "Обязательно к заполнению" }).superRefine((e, t) => {
11
+ e === "" && t.addIssue({
12
12
  code: o.ZodIssueCode.custom,
13
13
  message: "Введите имя и фамилию"
14
- }), T.test(n) || t.addIssue({
14
+ }), D.test(e) || t.addIssue({
15
15
  code: o.ZodIssueCode.custom,
16
16
  message: "Должна быть только кириллица"
17
17
  });
18
- const { surname: s, name: e, patronymic: i } = O(n);
19
- (!s || !e) && t.addIssue({
18
+ const { surname: s, name: n, patronymic: i } = h(e);
19
+ (!s || !n) && t.addIssue({
20
20
  code: o.ZodIssueCode.custom,
21
21
  message: "Введите имя и фамилию"
22
- }), I.test(e) || t.addIssue({
22
+ }), N.test(n) || t.addIssue({
23
23
  code: o.ZodIssueCode.custom,
24
24
  message: "Неверно введено имя"
25
- }), I.test(s) || t.addIssue({
25
+ }), N.test(s) || t.addIssue({
26
26
  code: o.ZodIssueCode.custom,
27
27
  message: "Неверно введена фамилия"
28
- }), i && (L.test(i) || t.addIssue({
28
+ }), i && (Z.test(i) || t.addIssue({
29
29
  code: o.ZodIssueCode.custom,
30
30
  message: "Неверно введено отчество"
31
31
  }));
32
- }), U = o.string().length(10, { message: l.INVALID_DATE }).superRefine((n, t) => {
33
- const [s, e, i] = (n == null ? void 0 : n.split(".")) ?? "", d = m(`${s}/${e}/${i}`, "dd/MM/yyyy", /* @__PURE__ */ new Date());
32
+ }), te = o.string().length(10, { message: l.INVALID_DATE }).superRefine((e, t) => {
33
+ const [s, n, i] = (e == null ? void 0 : e.split(".")) ?? "", a = I(`${s}/${n}/${i}`, "dd/MM/yyyy", /* @__PURE__ */ new Date());
34
34
  +i <= 1950 && t.addIssue({
35
35
  code: o.ZodIssueCode.custom,
36
36
  message: l.INVALID_DATE
37
- }), _(d) || t.addIssue({
37
+ }), E(a) || t.addIssue({
38
38
  code: o.ZodIssueCode.custom,
39
39
  message: l.INVALID_DATE
40
- }), (/* @__PURE__ */ new Date()).getTime() < new Date(d).getTime() && t.addIssue({
40
+ }), (/* @__PURE__ */ new Date()).getTime() < new Date(a).getTime() && t.addIssue({
41
41
  code: o.ZodIssueCode.custom,
42
42
  message: l.FUTURE_DATE_NOT_ALLOWED
43
43
  });
44
- }), G = o.string().superRefine((n, t) => {
45
- const s = n.charAt(0);
44
+ }), ne = o.string().superRefine((e, t) => {
45
+ const s = e.charAt(0);
46
46
  ["3", "4", "5", "6", "9"].includes(s) || t.addIssue({
47
47
  code: o.ZodIssueCode.custom,
48
48
  message: "Код города/оператора должен начинаться с цифры 3, 4, 5, 6 или 9"
49
- }), n.length !== 10 && t.addIssue({
49
+ }), e.length !== 10 && t.addIssue({
50
50
  code: o.ZodIssueCode.custom,
51
51
  message: "Введите номер телефона полностью"
52
52
  });
53
- }).transform((n) => `7${n}`), w = o.coerce.number().min(1e3, `${l.FIX_LENGTH} 4`).max(9999, `${l.FIX_LENGTH} 4`).nullable().superRefine((n, t) => {
54
- n === null && t.addIssue({
53
+ }).transform((e) => `7${e}`), ie = o.coerce.number().min(1e3, `${l.FIX_LENGTH} 4`).max(9999, `${l.FIX_LENGTH} 4`).nullable().superRefine((e, t) => {
54
+ e === null && t.addIssue({
55
55
  code: o.ZodIssueCode.invalid_type,
56
56
  expected: "number",
57
57
  received: "null",
58
58
  message: `${l.FIX_LENGTH} 4`
59
59
  });
60
- }).default(null), a = {
60
+ }).default(null), r = {
61
61
  NON_EMPTY: () => "Поле не может быть пустым",
62
- MIN_LENGTH: (n) => `Поле должно содержать минимум символов: ${n}`,
63
- MAX_LENGTH: (n) => `Поле должно содержать максимум символов: ${n}`,
64
- MIN_VALUE: (n) => `Значение не может быть меньше чем ${n}`,
65
- MAX_VALUE: (n) => `Значение не может быть больше чем ${n}`,
62
+ MIN_LENGTH: (e) => `Поле должно содержать минимум символов: ${e}`,
63
+ MAX_LENGTH: (e) => `Поле должно содержать максимум символов: ${e}`,
64
+ FIX_LENGTH: (e) => `Поле должно быть фиксированной длины символов: ${e}`,
65
+ MIN_VALUE: (e) => `Значение не может быть меньше чем ${e}`,
66
+ MAX_VALUE: (e) => `Значение не может быть больше чем ${e}`,
66
67
  PHONE_NON_EMPTY: () => "Номер телефона должен состоять из 11 цифр",
67
68
  PHONE_INVALID_OPERATOR: () => "Код города/оператора должен начинаться с цифры 3, 4, 5, 6 или 9",
68
69
  EMAIL_INVALID: () => "Email введен некорректно. Пример: example@domain.ru",
69
70
  EMAIL_NON_EMPTY: () => "Введите адрес электронной почты",
70
71
  SELECT_NON_EMPTY: () => "Выберите один из вариантов",
71
- SELECT_MULTIPLE_NON_EMPTY: (n) => `Выберите не менее ${n} вариантов`,
72
+ SELECT_MULTIPLE_MIN_LENGTH: (e) => `Выберите не менее ${e} вариантов`,
73
+ SELECT_MULTIPLE_MAX_LENGTH: (e) => `Выберите не более ${e} вариантов`,
74
+ SELECT_FIX_LENGTH: (e) => `Поле должно быть фиксированного количества вариантов: ${e}`,
72
75
  DATE_INVALID_FORMAT: () => "Дата указана некорректно",
73
76
  DATE_NON_EMPTY: () => "Укажите дату",
74
- VALUE_OUT_OF_RANGE: (n) => `Выберите один из вариантов ${n.join(", ")}`
75
- }, D = (n) => {
76
- const { iso: t = !1, pattern: s = E, message: e } = n || {};
77
- return o.string().min(8, (e == null ? void 0 : e.min) || a.DATE_NON_EMPTY()).superRefine((i, d) => {
78
- const r = s.replace(/\W/g, "").length;
79
- if (i.replace(/[._-]/g, "").length < r && d.addIssue({
77
+ VALUE_OUT_OF_RANGE: (e) => `Выберите один из вариантов ${e.join(", ")}`
78
+ }, P = (e) => {
79
+ const { iso: t = !1, pattern: s = A, message: n } = e || {};
80
+ return o.string().min(8, (n == null ? void 0 : n.min) || r.DATE_NON_EMPTY()).superRefine((i, a) => {
81
+ const u = s.replace(/\W/g, "").length;
82
+ if (i.replace(/[._-]/g, "").length < u && a.addIssue({
80
83
  code: o.ZodIssueCode.too_small,
81
- minimum: r,
84
+ minimum: u,
82
85
  type: "date",
83
86
  inclusive: !0,
84
- message: (e == null ? void 0 : e.min) || a.DATE_NON_EMPTY()
87
+ message: (n == null ? void 0 : n.min) || r.DATE_NON_EMPTY()
85
88
  }), t)
86
89
  try {
87
90
  new Date(i).toISOString();
88
91
  } catch {
89
- d.addIssue({
92
+ a.addIssue({
90
93
  code: o.ZodIssueCode.invalid_date,
91
- message: (e == null ? void 0 : e.invalidDate) || a.DATE_INVALID_FORMAT()
94
+ message: (n == null ? void 0 : n.invalidDate) || r.DATE_INVALID_FORMAT()
92
95
  });
93
96
  }
94
97
  else {
95
- const u = m(i, s, /* @__PURE__ */ new Date());
96
- _(u) || d.addIssue({
98
+ const c = I(i, s, /* @__PURE__ */ new Date());
99
+ E(c) || a.addIssue({
97
100
  code: o.ZodIssueCode.invalid_date,
98
- message: (e == null ? void 0 : e.invalidDate) || a.DATE_INVALID_FORMAT()
101
+ message: (n == null ? void 0 : n.invalidDate) || r.DATE_INVALID_FORMAT()
99
102
  });
100
103
  }
101
104
  }).default("");
102
- }, M = (n) => {
103
- const { iso: t = !1, pattern: s = E, message: e } = n || {};
104
- return o.string().transform((i) => i || void 0).superRefine((i, d) => {
105
- if (f.isString(i) && i.length) {
106
- const r = s.replace(/\W/g, "").length;
107
- if (i.replace(/[._-]/g, "").length < r && d.addIssue({
105
+ }, R = (e) => {
106
+ const { iso: t = !1, pattern: s = A, message: n } = e || {};
107
+ return o.string().transform((i) => i || void 0).superRefine((i, a) => {
108
+ if (L.isString(i) && i.length) {
109
+ const u = s.replace(/\W/g, "").length;
110
+ if (i.replace(/[._-]/g, "").length < u && a.addIssue({
108
111
  code: o.ZodIssueCode.too_small,
109
- minimum: r,
112
+ minimum: u,
110
113
  type: "date",
111
114
  inclusive: !0,
112
- message: (e == null ? void 0 : e.min) || a.DATE_NON_EMPTY()
115
+ message: (n == null ? void 0 : n.min) || r.DATE_NON_EMPTY()
113
116
  }), t)
114
117
  try {
115
118
  new Date(i).toISOString();
116
119
  } catch {
117
- d.addIssue({
120
+ a.addIssue({
118
121
  code: o.ZodIssueCode.invalid_date,
119
- message: (e == null ? void 0 : e.invalidDate) || a.DATE_INVALID_FORMAT()
122
+ message: (n == null ? void 0 : n.invalidDate) || r.DATE_INVALID_FORMAT()
120
123
  });
121
124
  }
122
125
  else {
123
- const u = m(i, s, /* @__PURE__ */ new Date());
124
- _(u) || d.addIssue({
126
+ const c = I(i, s, /* @__PURE__ */ new Date());
127
+ E(c) || a.addIssue({
125
128
  code: o.ZodIssueCode.invalid_date,
126
- message: (e == null ? void 0 : e.invalidDate) || a.DATE_INVALID_FORMAT()
129
+ message: (n == null ? void 0 : n.invalidDate) || r.DATE_INVALID_FORMAT()
127
130
  });
128
131
  }
129
132
  }
130
133
  }).optional();
131
- }, N = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/g, h = (n) => {
132
- const { message: t } = n || {};
133
- return o.string().min(1, (t == null ? void 0 : t.min) || a.EMAIL_NON_EMPTY()).regex(N, (t == null ? void 0 : t.invalid) || a.EMAIL_INVALID()).default("");
134
- }, C = (n) => {
135
- const { message: t } = n || {};
134
+ };
135
+ function S(e) {
136
+ const { required: t = !0 } = e || {};
137
+ return t ? P(e) : R(e);
138
+ }
139
+ const T = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/g, V = (e) => {
140
+ const { message: t, regexp: s = T } = e || {};
141
+ return o.string().min(1, (t == null ? void 0 : t.min) || r.EMAIL_NON_EMPTY()).regex(s, (t == null ? void 0 : t.invalid) || r.EMAIL_INVALID()).default("");
142
+ }, y = (e) => {
143
+ const { message: t, regexp: s = T } = e || {};
136
144
  return o.string().refine(
137
- (s) => f.isStringEmpty(s) ? !0 : N.test(s),
145
+ (n) => L.isStringEmpty(n) ? !0 : s.test(n),
138
146
  {
139
- message: (t == null ? void 0 : t.invalid) || a.EMAIL_INVALID()
147
+ message: (t == null ? void 0 : t.invalid) || r.EMAIL_INVALID()
140
148
  }
141
- ).optional().transform((s) => (s == null ? void 0 : s.length) === 0 ? void 0 : s);
142
- }, g = (n) => {
143
- const { min: t = 0, max: s, message: e } = n || {};
144
- let i = o.coerce.number().min(t, (e == null ? void 0 : e.min) || a.MIN_VALUE(t));
145
- return s && (i = i.max(s, (e == null ? void 0 : e.min) || a.MAX_VALUE(s))), i.default(0);
146
- }, R = (n) => g(n).optional().transform((t) => t || void 0), P = (n) => {
147
- const { ignoreMask: t = !0, maskSymbols: s = /[()+_ -]/g, message: e } = n || {};
148
- let i = o.string().superRefine((d, r) => {
149
- const c = d.replace(s, ""), u = c.charAt(1);
150
- ["3", "4", "5", "6", "7", "9"].includes(u) || r.addIssue({
149
+ ).optional().transform((n) => (n == null ? void 0 : n.length) === 0 ? void 0 : n);
150
+ };
151
+ function H(e) {
152
+ const { required: t = !0 } = e || {};
153
+ return t ? V(e) : y(e);
154
+ }
155
+ const O = (e) => {
156
+ const { min: t = 0, max: s, message: n } = e || {};
157
+ let i = o.coerce.number().min(t, (n == null ? void 0 : n.min) || r.MIN_VALUE(t));
158
+ return s && (i = i.max(s, (n == null ? void 0 : n.min) || r.MAX_VALUE(s))), i.default(0);
159
+ }, Y = (e) => O(e).optional().transform((t) => t || void 0);
160
+ function F(e) {
161
+ const { required: t = !0 } = e || {};
162
+ return t ? O(e) : Y(e);
163
+ }
164
+ const U = (e) => {
165
+ const { ignoreMask: t = !0, maskSymbols: s = /[()+_ -]/g, message: n } = e || {};
166
+ let i = o.string().superRefine((a, u) => {
167
+ const d = a.replace(s, ""), c = d.charAt(1);
168
+ ["3", "4", "5", "6", "7", "9"].includes(c) || u.addIssue({
151
169
  code: o.ZodIssueCode.invalid_string,
152
170
  validation: "regex",
153
- message: (e == null ? void 0 : e.invalidOperator) || a.PHONE_INVALID_OPERATOR()
154
- }), c.length < 11 && r.addIssue({
171
+ message: (n == null ? void 0 : n.invalidOperator) || r.PHONE_INVALID_OPERATOR()
172
+ }), d.length < 11 && u.addIssue({
155
173
  code: o.ZodIssueCode.too_small,
156
174
  minimum: 11,
157
175
  inclusive: !0,
158
176
  type: "string",
159
- message: (e == null ? void 0 : e.min) || a.PHONE_NON_EMPTY()
177
+ message: (n == null ? void 0 : n.min) || r.PHONE_NON_EMPTY()
160
178
  });
161
179
  });
162
- return t && (i = i.transform((d) => d.replace(s, ""))), i.default("");
163
- }, V = (n) => {
164
- const { ignoreMask: t = !0, maskSymbols: s = /[()+_ -]/g, message: e } = n || {};
165
- let i = o.string().superRefine((d, r) => {
166
- const c = d.replace(s, ""), u = c.charAt(1);
167
- ["3", "4", "5", "6", "7", "9"].includes(u) || r.addIssue({
180
+ return t && (i = i.transform((a) => a.replace(s, ""))), i.default("");
181
+ }, G = (e) => {
182
+ const { ignoreMask: t = !0, maskSymbols: s = /[()+_ -]/g, message: n } = e || {};
183
+ let i = o.string().superRefine((a, u) => {
184
+ const d = a.replace(s, ""), c = d.charAt(1);
185
+ ["3", "4", "5", "6", "7", "9"].includes(c) || u.addIssue({
168
186
  code: o.ZodIssueCode.invalid_string,
169
187
  validation: "regex",
170
- message: (e == null ? void 0 : e.invalidOperator) || a.PHONE_INVALID_OPERATOR()
171
- }), c.length < 11 && r.addIssue({
188
+ message: (n == null ? void 0 : n.invalidOperator) || r.PHONE_INVALID_OPERATOR()
189
+ }), d.length < 11 && u.addIssue({
172
190
  code: o.ZodIssueCode.too_small,
173
191
  minimum: 11,
174
192
  inclusive: !0,
175
193
  type: "string",
176
- message: (e == null ? void 0 : e.min) || a.PHONE_NON_EMPTY()
194
+ message: (n == null ? void 0 : n.min) || r.PHONE_NON_EMPTY()
177
195
  });
178
196
  });
179
- return t && (i = i.transform((d) => d.replace(s, ""))), i.transform((d) => d || void 0);
180
- }, S = (n) => {
181
- const { message: t } = n || {}, s = o.string().min(1, (t == null ? void 0 : t.single) || a.SELECT_NON_EMPTY()).nullable().refine((e) => !!e, (t == null ? void 0 : t.single) || a.SELECT_NON_EMPTY()).default(null);
182
- return n != null && n.multiple ? o.array(s).min((n == null ? void 0 : n.minLength) || 0, (t == null ? void 0 : t.multiple) || a.SELECT_MULTIPLE_NON_EMPTY((n == null ? void 0 : n.minLength) || 0)).default([]) : s;
183
- }, p = (n) => {
197
+ return t && (i = i.transform((a) => a.replace(s, ""))), i.transform((a) => a || void 0);
198
+ };
199
+ function $(e) {
200
+ const { required: t = !0 } = e || {};
201
+ return t ? U(e) : G(e);
202
+ }
203
+ const b = (e) => {
204
+ var n, i;
205
+ const { message: t } = e || {}, s = o.string().min(1, (t == null ? void 0 : t.single) || r.SELECT_NON_EMPTY()).nullable().refine((a) => !!a, (t == null ? void 0 : t.single) || r.SELECT_NON_EMPTY()).default(null);
206
+ if (e != null && e.multiple) {
207
+ let a = o.array(s).min((e == null ? void 0 : e.minLength) || 0, (t == null ? void 0 : t.multiple) || r.SELECT_MULTIPLE_MIN_LENGTH((e == null ? void 0 : e.minLength) || 0));
208
+ return e != null && e.length ? a.length(e.length, ((n = e.message) == null ? void 0 : n.length) || r.SELECT_FIX_LENGTH(e.length)).default([]) : (e != null && e.maxLength && (a = a.max(
209
+ e.maxLength,
210
+ ((i = e.message) == null ? void 0 : i.maxLength) || r.SELECT_MULTIPLE_MAX_LENGTH(e.maxLength)
211
+ )), a.default([]));
212
+ }
213
+ return s;
214
+ };
215
+ function q(e) {
184
216
  const t = o.string().nullable().optional();
185
- return n != null && n.multiple ? o.array(t).optional() : t;
186
- }, y = (n) => {
187
- const { min: t = 1, max: s, message: e } = n || {};
188
- let i = o.string().min(t, { message: (e == null ? void 0 : e.min) || a.MIN_LENGTH(t) });
189
- return s && (i = i.max(s, { message: (e == null ? void 0 : e.max) || a.MAX_LENGTH(s) })), i.refine((d) => !!d.length, { message: (e == null ? void 0 : e.min) || a.NON_EMPTY() }).default("");
190
- }, Z = (n) => {
191
- const { min: t, max: s, message: e } = n || {};
192
- let i = o.string();
193
- return t && (i = i.min(t, { message: (e == null ? void 0 : e.min) || a.MIN_LENGTH(t) })), s && (i = i.max(s, { message: (e == null ? void 0 : e.max) || a.MAX_LENGTH(s) })), i.optional().transform((d) => d != null && d.length ? d : void 0);
194
- }, A = (n, t) => {
195
- const { message: s, ...e } = t || {}, [i, d, ...r] = n.map((u) => o.literal(u)), c = s ? typeof s == "function" ? s(n) : s : a.VALUE_OUT_OF_RANGE(n);
196
- return o.union([i, d, ...r], {
197
- message: c,
198
- ...e
217
+ return e != null && e.multiple ? o.array(t).optional() : t;
218
+ }
219
+ function X(e) {
220
+ const { required: t = !0 } = e || {};
221
+ return t ? b(e) : q(e);
222
+ }
223
+ const x = (e) => {
224
+ const { min: t = 1, max: s, length: n, message: i } = e || {};
225
+ let a = o.string({ message: i == null ? void 0 : i.root }).min(t, { message: (i == null ? void 0 : i.min) || r.MIN_LENGTH(t) });
226
+ return s && (a = a.max(s, { message: (i == null ? void 0 : i.max) || r.MAX_LENGTH(s) })), n && (a = a.length(n, { message: (i == null ? void 0 : i.length) || r.FIX_LENGTH(n) })), a.refine((u) => !!u.length, { message: (i == null ? void 0 : i.min) || r.NON_EMPTY() }).default("");
227
+ }, w = (e) => {
228
+ const { min: t, max: s, length: n, message: i } = e || {};
229
+ let a = o.string({ message: i == null ? void 0 : i.root });
230
+ return t && (a = a.min(t, { message: (i == null ? void 0 : i.min) || r.MIN_LENGTH(t) })), s && (a = a.max(s, { message: (i == null ? void 0 : i.max) || r.MAX_LENGTH(s) })), n && (a = a.length(n, { message: (i == null ? void 0 : i.length) || r.FIX_LENGTH(n) })), a.optional().transform((u) => u != null && u.length ? u : void 0);
231
+ };
232
+ function z(e) {
233
+ const { required: t = !0, ...s } = e || {};
234
+ return t ? x(s) : w(s);
235
+ }
236
+ const M = (e, t) => {
237
+ const { message: s, ...n } = t || {}, [i, a, ...u] = e.map((c) => o.literal(c)), d = s ? typeof s == "function" ? s(e) : s : r.VALUE_OUT_OF_RANGE(e);
238
+ return o.union([i, a, ...u], {
239
+ message: d,
240
+ ...n
199
241
  });
200
- }, $ = (n, t) => A(n, t).optional(), F = {
201
- getStringRequired: y,
202
- getStringOptional: Z,
203
- getEmailRequired: h,
204
- getEmailOptional: C,
205
- getSelectRequired: S,
206
- getSelectOptional: p,
207
- getNumberRequired: g,
208
- getNumberOptional: R,
209
- getPhoneRequired: P,
210
- getPhoneOptional: V,
211
- getDateRequired: D,
212
- getDateOptional: M,
213
- getUnionRequired: A,
214
- getUnionOptional: $
215
- }, z = {
216
- base: F
242
+ }, B = (e, t) => M(e, t).optional();
243
+ function j(e, t) {
244
+ const { required: s, ...n } = t || {};
245
+ return s ? M(e, n) : B(e, n);
246
+ }
247
+ const k = {
248
+ getStringSchema: z,
249
+ getEmailSchema: H,
250
+ getSelectSchema: X,
251
+ getNumberSchema: F,
252
+ getPhoneSchema: $,
253
+ getDateSchema: S,
254
+ getUnionSchema: j
255
+ };
256
+ class se {
257
+ /**
258
+ * Функция для получения значения по умолчанию исходя из схемы
259
+ * @param zodSchema схема формы
260
+ * @param options настройки генерации значений по умолчанию
261
+ * @returns объект значений по умолчанию
262
+ *
263
+ * @example
264
+ * const schema = z.object({
265
+ * name: zodValidators.base.getStringSchema(),
266
+ * role: zodValidators.base.getUnionSchema(['UNKNOWN', 'ADMIN', 'MODERATOR', 'USER'] as const),
267
+ * info: z.object({
268
+ * address: zodValidators.base.getStringSchema(),
269
+ * phone: zodValidators.base.getPhoneSchema({ ignoreMask: true }),
270
+ * age: zodValidators.base.getNumberSchema()
271
+ * })
272
+ * })
273
+ *
274
+ * const defaultValues = ZodUtils.getZodDefaults(schema)
275
+ *
276
+ * // default values will be inferred from schema
277
+ * // {
278
+ * // name: '',
279
+ * // role: 'UNKNOWN',
280
+ * // info: {
281
+ * // address: '',
282
+ * // phone: '',
283
+ * // age: 0
284
+ * // }
285
+ * // }
286
+ */
287
+ static getZodDefaults(t, s) {
288
+ const { fillArrayWithValue: n } = s || {};
289
+ if (t instanceof o.ZodEffects)
290
+ return t.innerType() instanceof o.ZodEffects ? this.getZodDefaults(t.innerType(), s) : this.getZodDefaults(o.ZodObject.create(t.innerType().shape), s);
291
+ const i = (d) => {
292
+ switch (!0) {
293
+ case d instanceof o.ZodDefault:
294
+ return d._def.defaultValue();
295
+ case d instanceof o.ZodOptional:
296
+ return i(d.unwrap());
297
+ case d instanceof o.ZodNullable:
298
+ return null;
299
+ case d instanceof o.ZodArray:
300
+ return n ? [i(d.element)] : [];
301
+ case d instanceof o.ZodObject:
302
+ return this.getZodDefaults(d, s);
303
+ case d instanceof o.ZodUnion:
304
+ return i(d._def.options[0]);
305
+ case d instanceof o.ZodLiteral:
306
+ return d._def.value;
307
+ case d instanceof o.ZodEnum:
308
+ return d._def.values[0];
309
+ case d instanceof o.ZodString:
310
+ return "";
311
+ case d instanceof o.ZodNumber:
312
+ return 0;
313
+ case d instanceof o.ZodBoolean:
314
+ return !1;
315
+ case !("innerType" in d._def):
316
+ return;
317
+ default:
318
+ return i(d._def.innerType);
319
+ }
320
+ }, a = {};
321
+ return Object.entries(t.shape).map(([d, c]) => {
322
+ a[d] = i(c);
323
+ }), a;
324
+ }
325
+ }
326
+ const _ = {
327
+ NON_EMPTY: () => "Поле обязательно для заполнения",
328
+ VALUE_NO_WHITESPACE: () => "Укажите фамилию, имя и отчество через пробел",
329
+ ONLY_CYRILLIC: () => "Данные должны быть написаны кириллицей",
330
+ NAME_OR_SURNAME_NON_EMPTY: () => "Укажите имя и фамилию",
331
+ INVALID_NAME: () => "Неверно введено имя",
332
+ INVALID_SURNAME: () => "Неверно введена фамилия",
333
+ INVALID_PATRONYMIC: () => "Неверно введено отчество"
334
+ }, f = {
335
+ ONLY_CYRILLIC: /[\u0400-\u04FF\u00CB\u00EB -]/g,
336
+ CHECK_HYPHEN: /^(?:[^-]+(?:-[^-]+){0,4}|[^-]+)$/,
337
+ PATRONYMIC: /^[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4}(?:\s+[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4})?$/i
338
+ }, W = (e) => {
339
+ const [t, s, ...n] = e.trim().replace(/\s+/g, " ").split(" "), i = n.join(" ");
340
+ return { surname: t, name: s, patronymic: i };
341
+ }, C = (e) => {
342
+ const { message: t } = e || {}, { nameOrSurnameEmpty: s, invalidSurname: n, invalidPatronymic: i, invalidName: a } = t || {};
343
+ return o.string().superRefine((u, d) => {
344
+ const { name: c, surname: m, patronymic: g } = W(u);
345
+ f.ONLY_CYRILLIC.test(u) || d.addIssue({
346
+ code: o.ZodIssueCode.invalid_string,
347
+ validation: "regex",
348
+ message: _.ONLY_CYRILLIC()
349
+ }), (!c || !m) && d.addIssue({
350
+ code: o.ZodIssueCode.invalid_string,
351
+ validation: "regex",
352
+ message: s || _.NAME_OR_SURNAME_NON_EMPTY()
353
+ }), f.CHECK_HYPHEN.test(c) || d.addIssue({
354
+ code: o.ZodIssueCode.invalid_string,
355
+ validation: "regex",
356
+ message: a || _.INVALID_NAME()
357
+ }), f.CHECK_HYPHEN.test(m) || d.addIssue({
358
+ code: o.ZodIssueCode.invalid_string,
359
+ validation: "regex",
360
+ message: n || _.INVALID_SURNAME()
361
+ }), g && (f.PATRONYMIC.test(g) || d.addIssue({
362
+ code: o.ZodIssueCode.invalid_string,
363
+ validation: "regex",
364
+ message: i || _.INVALID_PATRONYMIC()
365
+ }));
366
+ }).transform((u) => u.trimEnd()).default("");
367
+ }, v = (e) => C(e).optional().transform((t) => t != null && t.length ? t : void 0);
368
+ function K(e) {
369
+ const { required: t = !0, ...s } = e || {};
370
+ return t ? C(s) : v(s);
371
+ }
372
+ const J = {
373
+ getFioSchema: K
374
+ }, oe = {
375
+ base: k,
376
+ dadata: J
217
377
  };
218
378
  export {
219
- I as RgxCheckForHyphen,
220
- L as RgxPatronymic,
221
- T as RgxUnicode,
379
+ N as RgxCheckForHyphen,
380
+ Z as RgxPatronymic,
381
+ D as RgxUnicode,
222
382
  l as VALIDATION_MESSAGES,
223
- O as formattedDadataFio,
224
- U as zodCalendarValidate,
225
- b as zodDadataFioSchema,
226
- w as zodOtpCodeSchema,
227
- G as zodPhoneSchema,
228
- z as zodValidators
383
+ se as ZodUtils,
384
+ r as baseDefaultMessages,
385
+ k as baseValidationSchemas,
386
+ h as formattedDadataFio,
387
+ te as zodCalendarValidate,
388
+ ee as zodDadataFioSchema,
389
+ ie as zodOtpCodeSchema,
390
+ ne as zodPhoneSchema,
391
+ oe as zodValidators
229
392
  };
230
393
  //# sourceMappingURL=validation.js.map