@scbt-ecom/ui 0.73.0 → 0.74.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.
- package/dist/index-CrR6G9lz.js +446 -0
- package/dist/index-CrR6G9lz.js.map +1 -0
- package/dist/shared/validation/base/base.constants.d.ts +1 -0
- package/dist/shared/validation/base/base.validators.d.ts +2 -0
- package/dist/shared/validation/base/regex.validators.d.ts +21 -0
- package/dist/shared/validation/index.d.ts +1 -0
- package/dist/validation.js +1 -1
- package/dist/widget.js +1 -1
- package/package.json +1 -1
- package/dist/index-lfBvBrWg.js +0 -436
- package/dist/index-lfBvBrWg.js.map +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type RegexValidatorsOptions<Required extends boolean> = {
|
|
3
|
+
/**
|
|
4
|
+
* указывает что поле обязательное
|
|
5
|
+
* @default true
|
|
6
|
+
*/
|
|
7
|
+
required?: Required;
|
|
8
|
+
/**
|
|
9
|
+
* значение по умолчанию
|
|
10
|
+
* @default undefined
|
|
11
|
+
*/
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
message?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const getRegexRequired: (regex: RegExp, props?: Omit<RegexValidatorsOptions<true>, "required">) => z.ZodDefault<z.ZodString>;
|
|
16
|
+
type RegexRequiredSchema = ReturnType<typeof getRegexRequired>;
|
|
17
|
+
declare const getRegexOptional: (regex: RegExp, props?: Omit<RegexValidatorsOptions<false>, "required">) => z.ZodEffects<z.ZodOptional<z.ZodDefault<z.ZodString>>, string | undefined, string | undefined>;
|
|
18
|
+
type RegexOptionalSchema = ReturnType<typeof getRegexOptional>;
|
|
19
|
+
export declare function getRegexSchema(regex: RegExp, props?: RegexValidatorsOptions<true>): RegexRequiredSchema;
|
|
20
|
+
export declare function getRegexSchema(regex: RegExp, props?: RegexValidatorsOptions<false>): RegexOptionalSchema;
|
|
21
|
+
export {};
|
|
@@ -14,6 +14,7 @@ export declare const zodValidators: {
|
|
|
14
14
|
getDateSchema: typeof import('./base/date.validators').getDateSchema;
|
|
15
15
|
getUnionSchema: typeof import('./base/union.validators').getUnionSchema;
|
|
16
16
|
getUrlSchema: typeof import('./base/url.validators').getUrlSchema;
|
|
17
|
+
getRegexSchema: typeof import('./base/regex.validators').getRegexSchema;
|
|
17
18
|
getBooleanSchema: typeof import('./base/boolean.validators').getBooleanSchema;
|
|
18
19
|
};
|
|
19
20
|
dadata: {
|
package/dist/validation.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Z as D, b as p, a as l, z as Z } from "./index-
|
|
1
|
+
import { Z as D, b as p, a as l, z as Z } from "./index-CrR6G9lz.js";
|
|
2
2
|
import { z as o, p as m, i as c } from "./utils-k3uzuyeN.js";
|
|
3
3
|
const I = /^[\u0400-\u04FF\u00CB\u00EB -]+$/, i = /^(?:[^-]+(?:-[^-]+){0,4}|[^-]+)$/, r = /^[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4}(?:\s+[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4})?$/i, t = {
|
|
4
4
|
REQUIRED: "Поле обязательно к заполнению",
|
package/dist/widget.js
CHANGED
|
@@ -21,7 +21,7 @@ import { scrollToElement as De, createPhoneNumber as yt, getUuid as Dt, capitali
|
|
|
21
21
|
import { i as re } from "./isClient-C9aZtt2Q.js";
|
|
22
22
|
import { u as Y, b as ne, a as ze, g as oe, F as Qe } from "./useDebounce-B__kmLt7.js";
|
|
23
23
|
import { o as Ve, z as Ae } from "./utils-k3uzuyeN.js";
|
|
24
|
-
import { z as ie, Z as ae } from "./index-
|
|
24
|
+
import { z as ie, Z as ae } from "./index-CrR6G9lz.js";
|
|
25
25
|
import { a as qe, u as Ue } from "./useFieldsProgress-BtrWDMY2.js";
|
|
26
26
|
import { createPortal as de } from "react-dom";
|
|
27
27
|
var B, Ut, We = (Ut = class extends Zt {
|
package/package.json
CHANGED
package/dist/index-lfBvBrWg.js
DELETED
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import { z as s, f as m, D as I, p as T, i as A, s as L } from "./utils-k3uzuyeN.js";
|
|
2
|
-
import { T as c } from "./typeGuards-CSiImkUY.js";
|
|
3
|
-
const D = (e) => {
|
|
4
|
-
const { defaultValue: t } = e || {};
|
|
5
|
-
return s.boolean().default(t ?? !1);
|
|
6
|
-
}, R = (e) => D(e).optional();
|
|
7
|
-
function y(e) {
|
|
8
|
-
const { required: t = !0, ...a } = e || {};
|
|
9
|
-
return t ? D(a) : R(a);
|
|
10
|
-
}
|
|
11
|
-
const l = {
|
|
12
|
-
NON_EMPTY: () => "Поле не может быть пустым",
|
|
13
|
-
MIN_LENGTH: (e) => `Поле должно содержать минимум символов: ${e}`,
|
|
14
|
-
MAX_LENGTH: (e) => `Поле должно содержать максимум символов: ${e}`,
|
|
15
|
-
FIX_LENGTH: (e) => `Поле должно быть фиксированной длины символов: ${e}`,
|
|
16
|
-
MIN_VALUE: (e) => `Значение не может быть меньше чем ${e}`,
|
|
17
|
-
MAX_VALUE: (e) => `Значение не может быть больше чем ${e}`,
|
|
18
|
-
PHONE_NON_EMPTY: () => "Номер телефона должен состоять из 11 цифр",
|
|
19
|
-
PHONE_INVALID_OPERATOR: () => "Код города/оператора должен начинаться с цифры 3, 4, 5, 6 или 9",
|
|
20
|
-
EMAIL_INVALID: () => "Email введен некорректно. Пример: example@domain.ru",
|
|
21
|
-
EMAIL_NON_EMPTY: () => "Введите адрес электронной почты",
|
|
22
|
-
SELECT_NON_EMPTY: () => "Выберите один из вариантов",
|
|
23
|
-
SELECT_MULTIPLE_MIN_LENGTH: (e) => `Выберите не менее ${e} вариантов`,
|
|
24
|
-
SELECT_MULTIPLE_MAX_LENGTH: (e) => `Выберите не более ${e} вариантов`,
|
|
25
|
-
SELECT_FIX_LENGTH: (e) => `Поле должно быть фиксированного количества вариантов: ${e}`,
|
|
26
|
-
DATE_INVALID_FORMAT: () => "Дата указана некорректно",
|
|
27
|
-
DATE_NON_EMPTY: () => "Укажите дату",
|
|
28
|
-
VALUE_OUT_OF_RANGE: (e) => `Выберите один из вариантов ${e.join(", ")}`,
|
|
29
|
-
DATE_MIN: (e) => {
|
|
30
|
-
const t = c.isString(e) ? new Date(e) : e;
|
|
31
|
-
return `Выбранная дата должна быть не раньше ${m(t)}`;
|
|
32
|
-
},
|
|
33
|
-
DATE_MAX: (e) => {
|
|
34
|
-
const t = c.isString(e) ? new Date(e) : e;
|
|
35
|
-
return `Выбранная дата должна быть не позже ${m(t)}`;
|
|
36
|
-
},
|
|
37
|
-
INVALID_URL: () => "Ссылка введена некорректно. Пример: https://example.com, example.com"
|
|
38
|
-
}, P = (e) => {
|
|
39
|
-
const { iso: t = !0, pattern: a = I, min: n, max: i, defaultValue: o, message: r } = e || {};
|
|
40
|
-
return s.string().min(8, (r == null ? void 0 : r.min) || l.DATE_NON_EMPTY()).superRefine((u, d) => {
|
|
41
|
-
const f = a.replace(/\W/g, "").length;
|
|
42
|
-
if (u.replace(/[._-]/g, "").length < f && d.addIssue({
|
|
43
|
-
code: s.ZodIssueCode.too_small,
|
|
44
|
-
minimum: f,
|
|
45
|
-
type: "date",
|
|
46
|
-
inclusive: !0,
|
|
47
|
-
message: (r == null ? void 0 : r.min) || l.DATE_NON_EMPTY()
|
|
48
|
-
}), t) {
|
|
49
|
-
let g = null;
|
|
50
|
-
try {
|
|
51
|
-
g = new Date(u);
|
|
52
|
-
} catch {
|
|
53
|
-
d.addIssue({
|
|
54
|
-
code: s.ZodIssueCode.invalid_date,
|
|
55
|
-
message: (r == null ? void 0 : r.invalidDate) || l.DATE_INVALID_FORMAT()
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
n && g.getTime() < (c.isString(n) ? new Date(n).getTime() : n.getTime()) && d.addIssue({
|
|
59
|
-
code: s.ZodIssueCode.invalid_date,
|
|
60
|
-
message: (r == null ? void 0 : r.min) || l.DATE_MIN(n)
|
|
61
|
-
}), i && g.getTime() > (c.isString(i) ? new Date(i).getTime() : i.getTime()) && d.addIssue({
|
|
62
|
-
code: s.ZodIssueCode.invalid_date,
|
|
63
|
-
message: (r == null ? void 0 : r.max) || l.DATE_MAX(i)
|
|
64
|
-
});
|
|
65
|
-
} else {
|
|
66
|
-
const g = T(u, a, /* @__PURE__ */ new Date());
|
|
67
|
-
A(g) || d.addIssue({
|
|
68
|
-
code: s.ZodIssueCode.invalid_date,
|
|
69
|
-
message: (r == null ? void 0 : r.invalidDate) || l.DATE_INVALID_FORMAT()
|
|
70
|
-
}), n && g.getTime() < (c.isString(n) ? new Date(n).getTime() : n.getTime()) && d.addIssue({
|
|
71
|
-
code: s.ZodIssueCode.invalid_date,
|
|
72
|
-
message: (r == null ? void 0 : r.min) || l.DATE_MIN(n)
|
|
73
|
-
}), i && g.getTime() > (c.isString(i) ? new Date(i).getTime() : i.getTime()) && d.addIssue({
|
|
74
|
-
code: s.ZodIssueCode.invalid_date,
|
|
75
|
-
message: (r == null ? void 0 : r.max) || l.DATE_MAX(i)
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}).default(o ?? "");
|
|
79
|
-
}, V = (e) => {
|
|
80
|
-
const { iso: t = !0, pattern: a = I, min: n, max: i, message: o } = e || {};
|
|
81
|
-
return s.string().transform((r) => r || void 0).superRefine((r, u) => {
|
|
82
|
-
if (c.isString(r) && r.length) {
|
|
83
|
-
const d = a.replace(/\W/g, "").length;
|
|
84
|
-
if (r.replace(/[._-]/g, "").length < d && u.addIssue({
|
|
85
|
-
code: s.ZodIssueCode.too_small,
|
|
86
|
-
minimum: d,
|
|
87
|
-
type: "date",
|
|
88
|
-
inclusive: !0,
|
|
89
|
-
message: (o == null ? void 0 : o.min) || l.DATE_NON_EMPTY()
|
|
90
|
-
}), t) {
|
|
91
|
-
let _ = null;
|
|
92
|
-
try {
|
|
93
|
-
_ = new Date(r);
|
|
94
|
-
} catch {
|
|
95
|
-
u.addIssue({
|
|
96
|
-
code: s.ZodIssueCode.invalid_date,
|
|
97
|
-
message: (o == null ? void 0 : o.invalidDate) || l.DATE_INVALID_FORMAT()
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
n && _.getTime() < (c.isString(n) ? new Date(n).getTime() : n.getTime()) && u.addIssue({
|
|
101
|
-
code: s.ZodIssueCode.invalid_date,
|
|
102
|
-
message: (o == null ? void 0 : o.min) || l.DATE_MIN(n)
|
|
103
|
-
}), i && _.getTime() > (c.isString(i) ? new Date(i).getTime() : i.getTime()) && u.addIssue({
|
|
104
|
-
code: s.ZodIssueCode.invalid_date,
|
|
105
|
-
message: (o == null ? void 0 : o.max) || l.DATE_MAX(i)
|
|
106
|
-
});
|
|
107
|
-
} else {
|
|
108
|
-
const _ = T(r, a, /* @__PURE__ */ new Date());
|
|
109
|
-
A(_) || u.addIssue({
|
|
110
|
-
code: s.ZodIssueCode.invalid_date,
|
|
111
|
-
message: (o == null ? void 0 : o.invalidDate) || l.DATE_INVALID_FORMAT()
|
|
112
|
-
}), n && _.getTime() < (c.isString(n) ? new Date(n).getTime() : n.getTime()) && u.addIssue({
|
|
113
|
-
code: s.ZodIssueCode.invalid_date,
|
|
114
|
-
message: (o == null ? void 0 : o.min) || l.DATE_MIN(n)
|
|
115
|
-
}), i && _.getTime() > (c.isString(i) ? new Date(i).getTime() : i.getTime()) && u.addIssue({
|
|
116
|
-
code: s.ZodIssueCode.invalid_date,
|
|
117
|
-
message: (o == null ? void 0 : o.max) || l.DATE_MAX(i)
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}).optional();
|
|
122
|
-
};
|
|
123
|
-
function h(e) {
|
|
124
|
-
const { required: t = !0 } = e || {};
|
|
125
|
-
return t ? P(e) : V(e);
|
|
126
|
-
}
|
|
127
|
-
const O = /^[\w-.]+@([\w-]+\.)+[\w-]{2,4}$/g, U = (e) => {
|
|
128
|
-
const { message: t, defaultValue: a, regexp: n = O } = e || {}, i = c.isString(n) ? new RegExp(n) : n;
|
|
129
|
-
return s.string().min(1, (t == null ? void 0 : t.min) || l.EMAIL_NON_EMPTY()).regex(i, (t == null ? void 0 : t.invalid) || l.EMAIL_INVALID()).default(a ?? "");
|
|
130
|
-
}, Y = (e) => {
|
|
131
|
-
const { message: t, regexp: a = O } = e || {}, n = c.isString(a) ? new RegExp(a) : a;
|
|
132
|
-
return s.string().refine(
|
|
133
|
-
(i) => c.isStringEmpty(i) ? !0 : n.test(i),
|
|
134
|
-
{
|
|
135
|
-
message: (t == null ? void 0 : t.invalid) || l.EMAIL_INVALID()
|
|
136
|
-
}
|
|
137
|
-
).optional().transform((i) => (i == null ? void 0 : i.length) === 0 ? void 0 : i);
|
|
138
|
-
};
|
|
139
|
-
function w(e) {
|
|
140
|
-
const { required: t = !0 } = e || {};
|
|
141
|
-
return t ? U(e) : Y(e);
|
|
142
|
-
}
|
|
143
|
-
const M = (e) => {
|
|
144
|
-
const { min: t, max: a, message: n, defaultValue: i } = e || {};
|
|
145
|
-
let o = s.coerce.number();
|
|
146
|
-
return t && (o = o.min(t, (n == null ? void 0 : n.min) || l.MIN_VALUE(t))), a && (o = o.max(a, (n == null ? void 0 : n.min) || l.MAX_VALUE(a))), o.default(i ?? 0);
|
|
147
|
-
}, H = (e) => M(e).optional().transform((t) => t || void 0);
|
|
148
|
-
function b(e) {
|
|
149
|
-
const { required: t = !0 } = e || {};
|
|
150
|
-
return t ? M(e) : H(e);
|
|
151
|
-
}
|
|
152
|
-
const p = (e) => {
|
|
153
|
-
const {
|
|
154
|
-
ignoreMask: t = !0,
|
|
155
|
-
maskSymbols: a = /[()+_ -]/g,
|
|
156
|
-
message: n,
|
|
157
|
-
defaultValue: i,
|
|
158
|
-
validOperatorCodes: o = ["3", "4", "5", "6", "7", "9"]
|
|
159
|
-
} = e || {}, r = c.isString(a) ? new RegExp(a) : a;
|
|
160
|
-
let u = s.string().superRefine((d, f) => {
|
|
161
|
-
const _ = d.replace(r, ""), g = _.charAt(1);
|
|
162
|
-
o.includes(g) || f.addIssue({
|
|
163
|
-
code: s.ZodIssueCode.invalid_string,
|
|
164
|
-
validation: "regex",
|
|
165
|
-
message: (n == null ? void 0 : n.invalidOperator) || l.PHONE_INVALID_OPERATOR()
|
|
166
|
-
}), _.length < 11 && f.addIssue({
|
|
167
|
-
code: s.ZodIssueCode.too_small,
|
|
168
|
-
minimum: 11,
|
|
169
|
-
inclusive: !0,
|
|
170
|
-
type: "string",
|
|
171
|
-
message: (n == null ? void 0 : n.min) || l.PHONE_NON_EMPTY()
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
return t && (u = u.transform((d) => d.replace(r, ""))), u.default(i ?? "");
|
|
175
|
-
}, x = (e) => {
|
|
176
|
-
const {
|
|
177
|
-
ignoreMask: t = !0,
|
|
178
|
-
maskSymbols: a = /[()+_ -]/g,
|
|
179
|
-
message: n,
|
|
180
|
-
validOperatorCodes: i = ["3", "4", "5", "6", "7", "9"]
|
|
181
|
-
} = e || {}, o = c.isString(a) ? new RegExp(a) : a;
|
|
182
|
-
let r = s.string().superRefine((u, d) => {
|
|
183
|
-
const f = u.replace(o, ""), _ = f.charAt(1);
|
|
184
|
-
i.includes(_) || d.addIssue({
|
|
185
|
-
code: s.ZodIssueCode.invalid_string,
|
|
186
|
-
validation: "regex",
|
|
187
|
-
message: (n == null ? void 0 : n.invalidOperator) || l.PHONE_INVALID_OPERATOR()
|
|
188
|
-
}), f.length < 11 && d.addIssue({
|
|
189
|
-
code: s.ZodIssueCode.too_small,
|
|
190
|
-
minimum: 11,
|
|
191
|
-
inclusive: !0,
|
|
192
|
-
type: "string",
|
|
193
|
-
message: (n == null ? void 0 : n.min) || l.PHONE_NON_EMPTY()
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
return t && (r = r.transform((u) => u.replace(o, ""))), r.transform((u) => u || void 0);
|
|
197
|
-
};
|
|
198
|
-
function v(e) {
|
|
199
|
-
const { required: t = !0 } = e || {};
|
|
200
|
-
return t ? p(e) : x(e);
|
|
201
|
-
}
|
|
202
|
-
const q = (e) => {
|
|
203
|
-
var i, o;
|
|
204
|
-
const { message: t, defaultValue: a } = e || {}, n = s.string().min(1, (t == null ? void 0 : t.single) || l.SELECT_NON_EMPTY()).nullable().refine((r) => !!r, (t == null ? void 0 : t.single) || l.SELECT_NON_EMPTY()).default(a ?? null);
|
|
205
|
-
if (e != null && e.multiple) {
|
|
206
|
-
let r = s.array(n).min((e == null ? void 0 : e.minLength) || 0, (t == null ? void 0 : t.multiple) || l.SELECT_MULTIPLE_MIN_LENGTH((e == null ? void 0 : e.minLength) || 0));
|
|
207
|
-
return e != null && e.length ? r.length(e.length, ((i = e.message) == null ? void 0 : i.length) || l.SELECT_FIX_LENGTH(e.length)).default([]) : (e != null && e.maxLength && (r = r.max(
|
|
208
|
-
e.maxLength,
|
|
209
|
-
((o = e.message) == null ? void 0 : o.maxLength) || l.SELECT_MULTIPLE_MAX_LENGTH(e.maxLength)
|
|
210
|
-
)), r.default([]));
|
|
211
|
-
}
|
|
212
|
-
return n;
|
|
213
|
-
};
|
|
214
|
-
function G(e) {
|
|
215
|
-
const t = s.string().nullable().optional();
|
|
216
|
-
return e != null && e.multiple ? s.array(t).optional() : t;
|
|
217
|
-
}
|
|
218
|
-
function X(e) {
|
|
219
|
-
const { required: t = !0 } = e || {};
|
|
220
|
-
return t ? q(e) : G(e);
|
|
221
|
-
}
|
|
222
|
-
const F = (e) => {
|
|
223
|
-
const { min: t, max: a, length: n, defaultValue: i, message: o } = e || {};
|
|
224
|
-
let r = s.string({ message: o == null ? void 0 : o.root });
|
|
225
|
-
return t && (r = r.min(t, { message: (o == null ? void 0 : o.min) || l.MIN_LENGTH(t) })), a && (r = r.max(a, { message: (o == null ? void 0 : o.max) || l.MAX_LENGTH(a) })), n && (r = r.length(n, { message: (o == null ? void 0 : o.length) || l.FIX_LENGTH(n) })), r.refine((u) => !!u.length, { message: (o == null ? void 0 : o.min) || l.NON_EMPTY() }).default(i ?? "");
|
|
226
|
-
}, $ = (e) => {
|
|
227
|
-
const { min: t, max: a, length: n, message: i } = e || {};
|
|
228
|
-
let o = s.string({ message: i == null ? void 0 : i.root });
|
|
229
|
-
return t && (o = o.min(t, { message: (i == null ? void 0 : i.min) || l.MIN_LENGTH(t) })), a && (o = o.max(a, { message: (i == null ? void 0 : i.max) || l.MAX_LENGTH(a) })), n && (o = o.length(n, { message: (i == null ? void 0 : i.length) || l.FIX_LENGTH(n) })), o.optional().transform((r) => r != null && r.length ? r : void 0);
|
|
230
|
-
};
|
|
231
|
-
function B(e) {
|
|
232
|
-
const { required: t = !0, ...a } = e || {};
|
|
233
|
-
return t ? F(a) : $(a);
|
|
234
|
-
}
|
|
235
|
-
const Z = (e, t) => {
|
|
236
|
-
const { message: a, ...n } = t || {}, [i, o, ...r] = e.map((d) => s.literal(d)), u = a ? typeof a == "function" ? a(e) : a : l.VALUE_OUT_OF_RANGE(e);
|
|
237
|
-
return s.union([i, o, ...r], {
|
|
238
|
-
message: u,
|
|
239
|
-
...n
|
|
240
|
-
}).nullable().refine(Boolean, l.NON_EMPTY()).default(null);
|
|
241
|
-
}, j = (e, t) => Z(e, t).optional();
|
|
242
|
-
function z(e, t) {
|
|
243
|
-
const { required: a, ...n } = t || {};
|
|
244
|
-
return a ? Z(e, n) : j(e, n);
|
|
245
|
-
}
|
|
246
|
-
const S = /^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([-.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/, k = (e) => {
|
|
247
|
-
const { message: t, defaultValue: a, regexp: n = S } = e || {}, i = c.isString(n) ? new RegExp(n) : n;
|
|
248
|
-
return L().min(1, (t == null ? void 0 : t.min) || l.NON_EMPTY()).regex(i, (t == null ? void 0 : t.invalid) || l.INVALID_URL()).default(a ?? "");
|
|
249
|
-
}, W = (e) => {
|
|
250
|
-
const { message: t, regexp: a = S } = e || {}, n = c.isString(a) ? new RegExp(a) : a;
|
|
251
|
-
return L().refine((i) => c.isStringEmpty(i) ? !0 : n.test(i), (t == null ? void 0 : t.invalid) || l.INVALID_URL()).optional().transform((i) => i != null && i.length ? i : void 0);
|
|
252
|
-
};
|
|
253
|
-
function K(e) {
|
|
254
|
-
const { required: t = !0 } = e || {};
|
|
255
|
-
return t ? k(e) : W(e);
|
|
256
|
-
}
|
|
257
|
-
const J = {
|
|
258
|
-
getStringSchema: B,
|
|
259
|
-
getEmailSchema: w,
|
|
260
|
-
getSelectSchema: X,
|
|
261
|
-
getNumberSchema: b,
|
|
262
|
-
getPhoneSchema: v,
|
|
263
|
-
getDateSchema: h,
|
|
264
|
-
getUnionSchema: z,
|
|
265
|
-
getUrlSchema: K,
|
|
266
|
-
getBooleanSchema: y
|
|
267
|
-
};
|
|
268
|
-
class re {
|
|
269
|
-
/**
|
|
270
|
-
* Функция для получения значения по умолчанию исходя из схемы
|
|
271
|
-
* @param zodSchema схема формы
|
|
272
|
-
* @param options настройки генерации значений по умолчанию
|
|
273
|
-
* @returns объект значений по умолчанию
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* const schema = z.object({
|
|
277
|
-
* name: zodValidators.base.getStringSchema(),
|
|
278
|
-
* role: zodValidators.base.getUnionSchema(['UNKNOWN', 'ADMIN', 'MODERATOR', 'USER'] as const),
|
|
279
|
-
* info: z.object({
|
|
280
|
-
* address: zodValidators.base.getStringSchema(),
|
|
281
|
-
* phone: zodValidators.base.getPhoneSchema({ ignoreMask: true }),
|
|
282
|
-
* age: zodValidators.base.getNumberSchema()
|
|
283
|
-
* })
|
|
284
|
-
* })
|
|
285
|
-
*
|
|
286
|
-
* const defaultValues = ZodUtils.getZodDefaults(schema)
|
|
287
|
-
*
|
|
288
|
-
* // default values will be inferred from schema
|
|
289
|
-
* // {
|
|
290
|
-
* // name: '',
|
|
291
|
-
* // role: 'UNKNOWN',
|
|
292
|
-
* // info: {
|
|
293
|
-
* // address: '',
|
|
294
|
-
* // phone: '',
|
|
295
|
-
* // age: 0
|
|
296
|
-
* // }
|
|
297
|
-
* // }
|
|
298
|
-
*/
|
|
299
|
-
static getZodDefaults(t, a) {
|
|
300
|
-
const { fillArrayWithValue: n } = a || {}, i = (d) => {
|
|
301
|
-
const f = d._def.schema;
|
|
302
|
-
return f instanceof s.ZodEffects || f._def.typeName === "ZodEffects" ? i(f) : f instanceof s.ZodObject || f._def.typeName === "ZodObject" ? this.getZodDefaults(f, a) : o(f);
|
|
303
|
-
}, o = (d) => {
|
|
304
|
-
if (d instanceof s.ZodEffects || d._def.typeName === "ZodEffects")
|
|
305
|
-
return i(d);
|
|
306
|
-
switch (!0) {
|
|
307
|
-
case (d._def.typeName === "ZodDefault" || d instanceof s.ZodDefault):
|
|
308
|
-
return d._def.defaultValue();
|
|
309
|
-
case (d._def.typeName === "ZodOptional" || d instanceof s.ZodOptional):
|
|
310
|
-
return;
|
|
311
|
-
case d._def.typeName === "ZodEffects":
|
|
312
|
-
return i(d);
|
|
313
|
-
case (d._def.typeName === "ZodNullable" || d instanceof s.ZodNullable):
|
|
314
|
-
return null;
|
|
315
|
-
case (d._def.typeName === "ZodArray" || d instanceof s.ZodArray):
|
|
316
|
-
return n ? [o(d.element)] : [];
|
|
317
|
-
case (d._def.typeName === "ZodObject" || d instanceof s.ZodObject):
|
|
318
|
-
return this.getZodDefaults(d, a);
|
|
319
|
-
case (d._def.typeName === "ZodUnion" || d instanceof s.ZodUnion):
|
|
320
|
-
return o(d._def.options[0]);
|
|
321
|
-
case (d._def.typeName === "ZodLiteral" || d instanceof s.ZodLiteral):
|
|
322
|
-
return d._def.value;
|
|
323
|
-
case (d._def.typeName === "ZodDiscriminatedUnion" || d instanceof s.ZodDiscriminatedUnion):
|
|
324
|
-
return o(d._def.options[0]);
|
|
325
|
-
case (d._def.typeName === "ZodEnum" || d instanceof s.ZodEnum):
|
|
326
|
-
return d._def.values[0];
|
|
327
|
-
case (d._def.typeName === "ZodString" || d instanceof s.ZodString):
|
|
328
|
-
return "";
|
|
329
|
-
case (d._def.typeName === "ZodNumber" || d instanceof s.ZodNumber):
|
|
330
|
-
return 0;
|
|
331
|
-
case (d._def.typeName === "ZodBoolean" || d instanceof s.ZodBoolean):
|
|
332
|
-
return !1;
|
|
333
|
-
case !("innerType" in d._def):
|
|
334
|
-
return;
|
|
335
|
-
default:
|
|
336
|
-
return o(d._def.innerType);
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
if (t instanceof s.ZodEffects || t._def.typeName === "ZodEffects")
|
|
340
|
-
return i(t);
|
|
341
|
-
const r = {};
|
|
342
|
-
return Object.entries(t.shape).map(([d, f]) => {
|
|
343
|
-
r[d] = o(f);
|
|
344
|
-
}), r;
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Функция для объединения zod схождений
|
|
348
|
-
* @param {ZodIntersection} zodSchema
|
|
349
|
-
* @returns объединенная схема двух схождений
|
|
350
|
-
*
|
|
351
|
-
* @example
|
|
352
|
-
* let schema = z.object({
|
|
353
|
-
* foo: z.string()
|
|
354
|
-
* })
|
|
355
|
-
* // this will return intersection and we need
|
|
356
|
-
* // to merge its left to right schema's
|
|
357
|
-
* .and(
|
|
358
|
-
* z.object({
|
|
359
|
-
* bar: z.string()
|
|
360
|
-
* })
|
|
361
|
-
* )
|
|
362
|
-
*
|
|
363
|
-
* schema = ZodUtils.zodMergeIntersection(schema)
|
|
364
|
-
*
|
|
365
|
-
* // schema will be
|
|
366
|
-
* z.object({
|
|
367
|
-
* foo: z.string(),
|
|
368
|
-
* bar: z.string()
|
|
369
|
-
* })
|
|
370
|
-
*/
|
|
371
|
-
static zodMergeIntersection(t) {
|
|
372
|
-
const { left: a, right: n } = t._def, i = a instanceof s.ZodDiscriminatedUnion || a._def.typeName === "ZodDiscriminatedUnion" ? a._def.options[0] : a, o = n instanceof s.ZodDiscriminatedUnion || n._def.typeName === "ZodDiscriminatedUnion" ? n._def.options[0] : n;
|
|
373
|
-
if ((i._def.typeName === "ZodObject" || i instanceof s.ZodObject) && (o._def.typeName === "ZodObject" || o instanceof s.ZodObject))
|
|
374
|
-
return i.merge(o);
|
|
375
|
-
throw new Error(`Cannot merge schema type ${o._def.typeName} to ${i._def.typeName}`);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const E = {
|
|
379
|
-
NON_EMPTY: () => "Поле обязательно для заполнения",
|
|
380
|
-
VALUE_NO_WHITESPACE: () => "Укажите фамилию, имя и отчество через пробел",
|
|
381
|
-
ONLY_CYRILLIC: () => "Данные должны быть написаны кириллицей",
|
|
382
|
-
NAME_OR_SURNAME_NON_EMPTY: () => "Укажите имя и фамилию",
|
|
383
|
-
INVALID_NAME: () => "Неверно введено имя",
|
|
384
|
-
INVALID_SURNAME: () => "Неверно введена фамилия",
|
|
385
|
-
INVALID_PATRONYMIC: () => "Неверно введено отчество"
|
|
386
|
-
}, N = {
|
|
387
|
-
ONLY_CYRILLIC: /[\u0400-\u04FF\u00CB\u00EB -]/g,
|
|
388
|
-
CHECK_HYPHEN: /^(?:[^-]+(?:-[^-]+){0,4}|[^-]+)$/,
|
|
389
|
-
PATRONYMIC: /^[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4}(?:\s+[a-zA-Zа-яА-ЯёЁ]+(?:\s*-\s*[a-zA-Zа-яА-ЯёЁ]+){0,4})?$/i
|
|
390
|
-
}, Q = (e) => {
|
|
391
|
-
const [t, a, ...n] = e.trim().replace(/\s+/g, " ").split(" "), i = n.join(" ");
|
|
392
|
-
return { surname: t, name: a, patronymic: i };
|
|
393
|
-
}, C = (e) => {
|
|
394
|
-
const { message: t } = e || {}, { nameOrSurnameEmpty: a, invalidSurname: n, invalidPatronymic: i, invalidName: o } = t || {};
|
|
395
|
-
return s.string().superRefine((r, u) => {
|
|
396
|
-
const { name: d, surname: f, patronymic: _ } = Q(r);
|
|
397
|
-
N.ONLY_CYRILLIC.test(r) || u.addIssue({
|
|
398
|
-
code: s.ZodIssueCode.invalid_string,
|
|
399
|
-
validation: "regex",
|
|
400
|
-
message: E.ONLY_CYRILLIC()
|
|
401
|
-
}), (!d || !f) && u.addIssue({
|
|
402
|
-
code: s.ZodIssueCode.invalid_string,
|
|
403
|
-
validation: "regex",
|
|
404
|
-
message: a || E.NAME_OR_SURNAME_NON_EMPTY()
|
|
405
|
-
}), N.CHECK_HYPHEN.test(d) || u.addIssue({
|
|
406
|
-
code: s.ZodIssueCode.invalid_string,
|
|
407
|
-
validation: "regex",
|
|
408
|
-
message: o || E.INVALID_NAME()
|
|
409
|
-
}), N.CHECK_HYPHEN.test(f) || u.addIssue({
|
|
410
|
-
code: s.ZodIssueCode.invalid_string,
|
|
411
|
-
validation: "regex",
|
|
412
|
-
message: n || E.INVALID_SURNAME()
|
|
413
|
-
}), _ && (N.PATRONYMIC.test(_) || u.addIssue({
|
|
414
|
-
code: s.ZodIssueCode.invalid_string,
|
|
415
|
-
validation: "regex",
|
|
416
|
-
message: i || E.INVALID_PATRONYMIC()
|
|
417
|
-
}));
|
|
418
|
-
}).transform((r) => r.trimEnd()).default("");
|
|
419
|
-
}, ee = (e) => C(e).optional().transform((t) => t != null && t.length ? t : void 0);
|
|
420
|
-
function te(e) {
|
|
421
|
-
const { required: t = !0, ...a } = e || {};
|
|
422
|
-
return t ? C(a) : ee(a);
|
|
423
|
-
}
|
|
424
|
-
const ne = {
|
|
425
|
-
getFioSchema: te
|
|
426
|
-
}, ae = {
|
|
427
|
-
base: J,
|
|
428
|
-
dadata: ne
|
|
429
|
-
};
|
|
430
|
-
export {
|
|
431
|
-
re as Z,
|
|
432
|
-
J as a,
|
|
433
|
-
l as b,
|
|
434
|
-
ae as z
|
|
435
|
-
};
|
|
436
|
-
//# sourceMappingURL=index-lfBvBrWg.js.map
|