@scbt-ecom/ui 0.31.5 → 0.32.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # React + TypeScript + Vite
1
+ # React + TypeScript + Vite haha
2
2
 
3
3
  This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
4
 
@@ -3,6 +3,7 @@ export declare const baseDefaultMessages: {
3
3
  NON_EMPTY: () => string;
4
4
  MIN_LENGTH: (min: number) => string;
5
5
  MAX_LENGTH: (max: number) => string;
6
+ FIX_LENGTH: (length: number) => string;
6
7
  MIN_VALUE: (min: number) => string;
7
8
  MAX_VALUE: (max: number) => string;
8
9
  PHONE_NON_EMPTY: () => string;
@@ -10,7 +11,9 @@ export declare const baseDefaultMessages: {
10
11
  EMAIL_INVALID: () => string;
11
12
  EMAIL_NON_EMPTY: () => string;
12
13
  SELECT_NON_EMPTY: () => string;
13
- SELECT_MULTIPLE_NON_EMPTY: (length: number) => string;
14
+ SELECT_MULTIPLE_MIN_LENGTH: (length: number) => string;
15
+ SELECT_MULTIPLE_MAX_LENGTH: (length: number) => string;
16
+ SELECT_FIX_LENGTH: (length: number) => string;
14
17
  DATE_INVALID_FORMAT: () => string;
15
18
  DATE_NON_EMPTY: () => string;
16
19
  VALUE_OUT_OF_RANGE: <T extends Primitive>(range: T[]) => string;
@@ -1,20 +1,16 @@
1
+ import { getDateSchema } from './date.validators';
2
+ import { getEmailSchema } from './email.validators';
3
+ import { getNumberSchema } from './number.validators';
4
+ import { getPhoneSchema } from './phone.validators';
5
+ import { getSelectSchema } from './select.validators';
6
+ import { getStringSchema } from './string.validators';
7
+ import { getUnionSchema } from './union.validators';
1
8
  export declare const baseValidationSchemas: {
2
- getStringRequired: (props?: import('./string.validators').StringValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
3
- getStringOptional: (props?: import('./string.validators').StringValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodString>, string | undefined, string | undefined>;
4
- getEmailRequired: (props?: import('./email.validators').EmailValidationOptions) => import('zod').ZodDefault<import('zod').ZodString>;
5
- getEmailOptional: (props?: import('./email.validators').EmailValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodEffects<import('zod').ZodString, string, string>>, string | undefined, string | undefined>;
6
- getSelectRequired: <Multi extends boolean>(props?: Multi extends true ? import('./select.validators').SelectSingleValidationOptions<Multi> & {
7
- minLength?: number;
8
- } : import('./select.validators').SelectSingleValidationOptions<Multi>) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodNullable<import('zod').ZodString>, string | null, string | null>> | import('zod').ZodDefault<import('zod').ZodArray<import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodNullable<import('zod').ZodString>, string | null, string | null>>, "many">>;
9
- getSelectOptional: <Multi extends boolean>(props?: Omit<Multi extends true ? import('./select.validators').SelectSingleValidationOptions<Multi> & {
10
- minLength?: number;
11
- } : import('./select.validators').SelectSingleValidationOptions<Multi>, "message">) => import('zod').ZodOptional<import('zod').ZodNullable<import('zod').ZodString>> | import('zod').ZodOptional<import('zod').ZodArray<import('zod').ZodOptional<import('zod').ZodNullable<import('zod').ZodString>>, "many">>;
12
- getNumberRequired: (props?: import('./number.validators').NumberValidationOptions) => import('zod').ZodDefault<import('zod').ZodNumber>;
13
- getNumberOptional: (props?: import('./number.validators').NumberValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodDefault<import('zod').ZodNumber>>, number | undefined, number | undefined>;
14
- getPhoneRequired: (props?: import('./phone.validators').PhoneValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
15
- getPhoneOptional: (props?: import('./phone.validators').PhoneValidationOptions) => import('zod').ZodEffects<import('zod').ZodEffects<import('zod').ZodString, string, string>, string | undefined, string>;
16
- getDateRequired: (props?: import('./date.validators').DateValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
17
- getDateOptional: (props?: import('./date.validators').DateValidationOptions) => import('zod').ZodOptional<import('zod').ZodEffects<import('zod').ZodEffects<import('zod').ZodString, string | undefined, string>, string | undefined, string>>;
18
- getUnionRequired: <T extends import('zod').Primitive>(values: [T, T, ...T[]], props?: import('./union.validators').UnionValidationOptions<T>) => import('zod').ZodUnion<[import('zod').ZodLiteral<T>, import('zod').ZodLiteral<T>, ...import('zod').ZodLiteral<T>[]]>;
19
- getUnionOptional: <T extends import('zod').Primitive>(values: [T, T, ...T[]], props?: import('./union.validators').UnionValidationOptions<T>) => import('zod').ZodOptional<import('zod').ZodUnion<[import('zod').ZodLiteral<T>, import('zod').ZodLiteral<T>, ...import('zod').ZodLiteral<T>[]]>>;
9
+ getStringSchema: typeof getStringSchema;
10
+ getEmailSchema: typeof getEmailSchema;
11
+ getSelectSchema: typeof getSelectSchema;
12
+ getNumberSchema: typeof getNumberSchema;
13
+ getPhoneSchema: typeof getPhoneSchema;
14
+ getDateSchema: typeof getDateSchema;
15
+ getUnionSchema: typeof getUnionSchema;
20
16
  };
@@ -1,7 +1,7 @@
1
1
  import { default as z } from 'zod';
2
- export type DateValidationOptions = {
2
+ export type DateValidationOptions<Required extends boolean> = {
3
3
  /**
4
- * парсить строку с учетом ISO формата
4
+ * валидация строки с учетом ISO формата
5
5
  * @default false
6
6
  */
7
7
  iso?: boolean;
@@ -10,6 +10,10 @@ export type DateValidationOptions = {
10
10
  * @default 'dd.MM.yyyy'
11
11
  */
12
12
  pattern?: string;
13
+ /**
14
+ * указывает что поле обязательное
15
+ */
16
+ required?: Required;
13
17
  message?: {
14
18
  min?: string;
15
19
  invalidDate?: string;
@@ -17,31 +21,35 @@ export type DateValidationOptions = {
17
21
  };
18
22
  /**
19
23
  * Схема валидации опционального поля номера телефона
20
- * @param {DateValidationOptions} props настройки схемы
21
- * @typeParam `iso` - `boolean | undefined` `default: false`
22
- * @typeParam `pattern` - `string | undefined` `default: 'dd.MM.yyyy'`
23
- * @typeParam `message` - `{ [min | invalidOperator]: string }`
24
- * @returns схема валидации поля в соответствии с настройками
25
- *
26
- * @example
27
- * z.object({
28
- * field: zodValidators.base.getDateRequired()
29
- * })
30
- * // will returns z.string()
31
24
  */
32
- export declare const getDateRequired: (props?: DateValidationOptions) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
25
+ declare const getDateRequired: (props?: Omit<DateValidationOptions<boolean>, "required">) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
26
+ type DateRequiredSchema = ReturnType<typeof getDateRequired>;
33
27
  /**
34
28
  * Схема валидации опционального поля номера телефона
29
+ */
30
+ declare const getDateOptional: (props?: Omit<DateValidationOptions<boolean>, "required">) => z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string | undefined, string>, string | undefined, string>>;
31
+ type DateOptionalSchema = ReturnType<typeof getDateOptional>;
32
+ /**
33
+ * Схема валидации поля даты
35
34
  * @param {DateValidationOptions} props настройки схемы
36
- * @typeParam `iso` - `boolean | undefined` `default: false` парсить строку с учетом ISO формата
37
- * @typeParam `pattern` - `string | undefined` `default: 'dd.MM.yyyy'` шаблон для валидации строки (будет проигнорирован, если `iso = true`)
35
+ * @typeParam `required` - `boolean`
36
+ * @typeParam `iso` - `boolean | undefined`
37
+ * @typeParam `pattern` - `string | undefined`
38
38
  * @typeParam `message` - `{ [min | invalidOperator]: string }`
39
39
  * @returns схема валидации поля в соответствии с настройками
40
40
  *
41
- * @example
41
+ * @example with required value
42
42
  * z.object({
43
- * field: zodValidators.base.getDateOptional()
43
+ * field: zodValidators.base.getDateSchema()
44
44
  * })
45
45
  * // will returns z.string()
46
+ *
47
+ * @example with required value
48
+ * z.object({
49
+ * field: zodValidators.base.getDateSchema({ required: false })
50
+ * })
51
+ * // will returns z.string().optional()
46
52
  */
47
- export declare const getDateOptional: (props?: DateValidationOptions) => z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string | undefined, string>, string | undefined, string>>;
53
+ export declare function getDateSchema(props?: DateValidationOptions<true>): DateRequiredSchema;
54
+ export declare function getDateSchema(props?: DateValidationOptions<false>): DateOptionalSchema;
55
+ export {};
@@ -1,5 +1,14 @@
1
1
  import { default as z } from 'zod';
2
- export type EmailValidationOptions = {
2
+ export type EmailValidationOptions<Required extends boolean> = {
3
+ /**
4
+ * указывает что поле обязательное
5
+ * @default true
6
+ */
7
+ required?: Required;
8
+ /**
9
+ * Регулярное выражение для проверки email на валидность
10
+ */
11
+ regexp?: RegExp;
3
12
  message?: {
4
13
  min?: string;
5
14
  invalid?: string;
@@ -7,27 +16,34 @@ export type EmailValidationOptions = {
7
16
  };
8
17
  /**
9
18
  * Схема валидации обязательного поля типа email
19
+ */
20
+ declare const getEmailRequired: (props?: Omit<EmailValidationOptions<true>, "required">) => z.ZodDefault<z.ZodString>;
21
+ type EmailRequiredSchema = ReturnType<typeof getEmailRequired>;
22
+ /**
23
+ * Схема валидации опционального поля типа email
24
+ */
25
+ declare const getEmailOptional: (props?: Omit<EmailValidationOptions<false>, "required">) => z.ZodEffects<z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>, string | undefined, string | undefined>;
26
+ type EmailOptionalSchema = ReturnType<typeof getEmailOptional>;
27
+ /**
28
+ * Схема валидации поля типа email
10
29
  * @param {EmailValidationOptions} props настройки схемы
30
+ * @typeParam `required` - `boolean`
31
+ * @typeParam `regexp` - `RegExp`
11
32
  * @typeParam `message` - `{ [min | invalid]: string }`
12
33
  * @returns схема валидации поля в соответствии с настройками
13
34
  *
14
- * @example
35
+ * @example with required value
15
36
  * z.object({
16
- * field: zodValidators.base.getEmailRequired({ message: { min: '' } })
37
+ * field: zodValidators.base.getEmailSchema()
17
38
  * })
18
39
  * // will returns z.string().min(1).email()
19
- */
20
- export declare const getEmailRequired: (props?: EmailValidationOptions) => z.ZodDefault<z.ZodString>;
21
- /**
22
- * Схема валидации опционального поля типа email
23
- * @param {EmailValidationOptions} props настройки схемы
24
- * @typeParam `message` - `{ [min | invalid]: string }`
25
- * @returns схема валидации поля в соответствии с настройками
26
40
  *
27
- * @example
41
+ * @example with optional value
28
42
  * z.object({
29
- * field: zodValidators.base.getEmailOptional({ message: { min: '' } })
43
+ * field: zodValidators.base.getEmailSchema({ required: false })
30
44
  * })
31
45
  * // will returns z.string().min(1).email().optional()
32
46
  */
33
- export declare const getEmailOptional: (props?: EmailValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>, string | undefined, string | undefined>;
47
+ export declare function getEmailSchema(props?: EmailValidationOptions<true>): EmailRequiredSchema;
48
+ export declare function getEmailSchema(props?: EmailValidationOptions<false>): EmailOptionalSchema;
49
+ export {};
@@ -1 +1,2 @@
1
1
  export * from './base.validators';
2
+ export { baseDefaultMessages } from './base.constants';
@@ -1,36 +1,53 @@
1
1
  import { default as z } from 'zod';
2
- export type NumberValidationOptions = {
2
+ export type NumberValidationOptions<Required extends boolean> = {
3
+ /**
4
+ * минимальное значение
5
+ * @default 0
6
+ */
3
7
  min?: number;
8
+ /**
9
+ * максимальное значение
10
+ * @default undefined
11
+ */
4
12
  max?: number;
5
- message?: Record<keyof Omit<NumberValidationOptions, 'message'>, string>;
13
+ /**
14
+ * указывает что поле обязательное
15
+ * @default true
16
+ */
17
+ required?: Required;
18
+ message?: Record<keyof Omit<NumberValidationOptions<Required>, 'message'>, string>;
6
19
  };
7
20
  /**
8
21
  * Схема валидации обязательного поля числового типа
22
+ */
23
+ declare const getNumberRequired: (props?: Omit<NumberValidationOptions<true>, "required">) => z.ZodDefault<z.ZodNumber>;
24
+ type NumberRequiredSchema = ReturnType<typeof getNumberRequired>;
25
+ /**
26
+ * Схема валидации опционального поля числового типа
27
+ */
28
+ declare const getNumberOptional: (props?: Omit<NumberValidationOptions<false>, "required">) => z.ZodEffects<z.ZodOptional<z.ZodDefault<z.ZodNumber>>, number | undefined, number | undefined>;
29
+ type NumberOptionalSchema = ReturnType<typeof getNumberOptional>;
30
+ /**
31
+ * Схема валидации опционального поля числового типа
9
32
  * @param {NumberValidationOptions} props настройки схемы
33
+ @typeParam `required` - `boolean`
10
34
  * @typeParam `min` - `number | undefined` `default: 1`
11
35
  * @typeParam `max` - `number | undefined` `default: undefined`
12
36
  * @typeParam `message` - `{ [min | max]: string }`
13
37
  * @returns схема валидации поля в соответствии с настройками
14
38
  *
15
- * @example
39
+ * @example with required min, max value
16
40
  * z.object({
17
- * field: zodValidators.base.getNumberRequired({ min: 10, max: 20 })
41
+ * field: zodValidators.base.getNumberSchema({ min: 10, max: 20 })
18
42
  * })
19
43
  * // will returns z.coerce.number().min(10).max(20)
20
- */
21
- export declare const getNumberRequired: (props?: NumberValidationOptions) => z.ZodDefault<z.ZodNumber>;
22
- /**
23
- * Схема валидации опционального поля числового типа
24
- * @param {NumberValidationOptions} props настройки схемы
25
- * @typeParam `min` - `number | undefined` `default: 1`
26
- * @typeParam `max` - `number | undefined` `default: undefined`
27
- * @typeParam `message` - `{ [min | max]: string }`
28
- * @returns схема валидации поля в соответствии с настройками
29
44
  *
30
- * @example
45
+ * @example with optional min, max value
31
46
  * z.object({
32
- * field: zodValidators.base.getNumberOptional({ min: 10, max: 20 })
47
+ * field: zodValidators.base.getNumberSchema({ min: 10, max: 20, required: false })
33
48
  * })
34
49
  * // will returns z.coerce.number().min(10).max(20).optional()
35
50
  */
36
- export declare const getNumberOptional: (props?: NumberValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodDefault<z.ZodNumber>>, number | undefined, number | undefined>;
51
+ export declare function getNumberSchema(props?: NumberValidationOptions<true>): NumberRequiredSchema;
52
+ export declare function getNumberSchema(props?: NumberValidationOptions<false>): NumberOptionalSchema;
53
+ export {};
@@ -1,8 +1,8 @@
1
1
  import { default as z } from 'zod';
2
- export type PhoneValidationOptions = {
2
+ export type PhoneValidationOptions<Required extends boolean> = {
3
3
  /**
4
4
  * исключает маску в возвращаемом значении
5
- * @default false
5
+ * @default true
6
6
  */
7
7
  ignoreMask?: boolean;
8
8
  /**
@@ -10,6 +10,10 @@ export type PhoneValidationOptions = {
10
10
  * @default /[()+_ -]/g
11
11
  */
12
12
  maskSymbols?: RegExp;
13
+ /**
14
+ * указывает что поле обязательное
15
+ */
16
+ required?: Required;
13
17
  message?: {
14
18
  min?: string;
15
19
  invalidOperator?: string;
@@ -17,31 +21,35 @@ export type PhoneValidationOptions = {
17
21
  };
18
22
  /**
19
23
  * Схема валидации обязательного поля номера телефона
24
+ */
25
+ declare const getPhoneRequired: (props?: Omit<PhoneValidationOptions<true>, "required">) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
26
+ type PhoneRequiredSchema = ReturnType<typeof getPhoneRequired>;
27
+ /**
28
+ * Схема валидации опционального поля номера телефона
29
+ */
30
+ declare const getPhoneOptional: (props?: Omit<PhoneValidationOptions<false>, "required">) => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string | undefined, string>;
31
+ type PhoneOptionalSchema = ReturnType<typeof getPhoneOptional>;
32
+ /**
33
+ * Схема валидации опционального поля номера телефона
20
34
  * @param {PhoneValidationOptions} props настройки схемы
21
- * @typeParam `ignoreMask` - `boolean | undefined` `default: false`
35
+ @typeParam `required` - `boolean`
36
+ * @typeParam `ignoreSeparators` - `boolean | undefined` `default: false`
22
37
  * @typeParam `maskSymbols` - `RegExp | undefined` `default: /[()+_ -]/g`
23
38
  * @typeParam `message` - `{ [min | invalidOperator]: string }`
24
39
  * @returns схема валидации поля в соответствии с настройками
25
40
  *
26
- * @example
41
+ * @example with required value
27
42
  * z.object({
28
- * field: zodValidators.base.getPhoneRequired()
43
+ * field: zodValidators.base.getPhoneSchema()
29
44
  * })
30
45
  * // will returns z.string()
31
- */
32
- export declare const getPhoneRequired: (props?: PhoneValidationOptions) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
33
- /**
34
- * Схема валидации опционального поля номера телефона
35
- * @param {PhoneValidationOptions} props настройки схемы
36
- * @typeParam `ignoreSeparators` - `boolean | undefined` `default: false` возвращает строку вырезая символы маски
37
- * @typeParam `maskSymbols` - `RegExp | undefined` `default: /[()+_ -]/g` игнорирует символы для проверки поля исключая данные символы
38
- * @typeParam `message` - `{ [min | invalidOperator]: string }`
39
- * @returns схема валидации поля в соответствии с настройками
40
46
  *
41
- * @example
47
+ * @example with optional value
42
48
  * z.object({
43
- * field: zodValidators.base.getPhoneOptional()
49
+ * field: zodValidators.base.getPhoneSchema({ required: false })
44
50
  * })
45
- * // will returns z.string()
51
+ * // will returns z.string().optional()
46
52
  */
47
- export declare const getPhoneOptional: (props?: PhoneValidationOptions) => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string | undefined, string>;
53
+ export declare function getPhoneSchema(props?: PhoneValidationOptions<true>): PhoneRequiredSchema;
54
+ export declare function getPhoneSchema(props?: PhoneValidationOptions<false>): PhoneOptionalSchema;
55
+ export {};
@@ -1,60 +1,85 @@
1
1
  import { default as z } from 'zod';
2
- export type SelectSingleValidationOptions<Multi extends boolean = false> = {
2
+ export type SelectSingleValidationOptions<Required extends boolean, Multi extends boolean = false> = {
3
3
  /**
4
4
  * включает валидацию мульти селекта
5
5
  * @default false
6
6
  */
7
7
  multiple?: Multi;
8
+ /**
9
+ * указывает что поле обязательное
10
+ * @default true
11
+ */
12
+ required?: Required;
8
13
  message?: {
9
14
  single?: string;
10
15
  multiple?: string;
11
16
  };
12
17
  };
13
- type SelectMultipleValidationOptions<Multi extends boolean = true> = SelectSingleValidationOptions<Multi> & {
18
+ type SelectMultipleValidationOptions<Required extends boolean, Multi extends boolean = true> = SelectSingleValidationOptions<Required, Multi> & {
14
19
  /**
15
20
  * минимальное количество элементов
16
21
  * @default 0
17
22
  */
18
23
  minLength?: number;
24
+ /**
25
+ * максимальное количество элементов
26
+ * @default undefined
27
+ */
28
+ maxLength?: number;
29
+ /**
30
+ * фиксированное количество элементов
31
+ * @default undefined
32
+ */
33
+ length?: number;
34
+ message?: SelectSingleValidationOptions<Required, Multi> & {
35
+ minLength?: string;
36
+ maxLength?: string;
37
+ length?: string;
38
+ };
19
39
  };
20
- type SelectValidationOptions<Multi extends boolean> = Multi extends true ? SelectMultipleValidationOptions<Multi> : SelectSingleValidationOptions<Multi>;
40
+ type SelectValidationOptions<Required extends boolean, Multi extends boolean> = Multi extends true ? SelectMultipleValidationOptions<Required, Multi> : SelectSingleValidationOptions<Required, Multi>;
21
41
  /**
22
42
  * Схема валидации обязательного поля типа select
43
+ */
44
+ declare const getSelectRequired: <Required extends boolean, Multi extends boolean>(props?: SelectValidationOptions<Required, Multi>) => z.ZodDefault<z.ZodEffects<z.ZodNullable<z.ZodString>, string | null, string | null>> | z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodEffects<z.ZodNullable<z.ZodString>, string | null, string | null>>, "many">>;
45
+ type SelectRequiredSchema = ReturnType<typeof getSelectRequired>;
46
+ /**
47
+ * Схема валидации опционального поля типа select
48
+ */
49
+ declare function getSelectOptional<Required extends boolean, Multi extends boolean>(props?: Omit<SelectValidationOptions<Required, Multi>, 'message'>): z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodArray<z.ZodOptional<z.ZodNullable<z.ZodString>>, "many">>;
50
+ type SelectOptionalSchema = ReturnType<typeof getSelectOptional>;
51
+ /**
52
+ * Схема валидации опционального поля типа select
23
53
  * @param {SelectValidationOptions} props настройки схемы
54
+ @typeParam `required` - `boolean`
24
55
  * @typeParam `multiple` - `boolean`
25
- * @typeParam `minLength` - `number` `required if multiple = true`
26
- * @typeParam `message` - `{ [single | multiple]: string }`
56
+ * @typeParam `minLength` - `number | undefined`
27
57
  * @returns схема валидации поля в соответствии с настройками
28
58
  *
29
- * @example
59
+ * @example with required single value
30
60
  * z.object({
31
- * field: zodValidators.base.getSelectRequired({ multiple: false })
61
+ * field: zodValidators.base.getSelectSchema({ multiple: false })
32
62
  * })
33
- * // will returns z.string().min(1).nullable().refine(Boolean)
63
+ * // will returns z.string().nullable()
34
64
  *
65
+ * @example with required multiple value
35
66
  * z.object({
36
- * field: zodValidators.base.getSelectRequired({ multiple: true, minLength: 3 })
67
+ * field: zodValidators.base.getSelectSchema({ multiple: true })
37
68
  * })
38
- * // will returns z.array(z.string().min(1).nullable().refine(Boolean))
39
- */
40
- export declare const getSelectRequired: <Multi extends boolean>(props?: SelectValidationOptions<Multi>) => z.ZodDefault<z.ZodEffects<z.ZodNullable<z.ZodString>, string | null, string | null>> | z.ZodDefault<z.ZodArray<z.ZodDefault<z.ZodEffects<z.ZodNullable<z.ZodString>, string | null, string | null>>, "many">>;
41
- /**
42
- * Схема валидации опционального поля типа select
43
- * @param {SelectValidationOptions} props настройки схемы
44
- * @typeParam `multiple` - `boolean`
45
- * @typeParam `minLength` - `number` `required if multiple = true`
46
- * @returns схема валидации поля в соответствии с настройками
69
+ * // will returns z.array(z.string().nullable())
47
70
  *
48
- * @example
71
+ * @example with optional single value
49
72
  * z.object({
50
- * field: zodValidators.base.getSelectOptional({ multiple: false })
73
+ * field: zodValidators.base.getSelectSchema({ required: false, multiple: false })
51
74
  * })
52
- * // will returns z.string().nullable()
75
+ * // will returns z.string().nullable().optional()
53
76
  *
77
+ * @example with optional multiple value
54
78
  * z.object({
55
- * field: zodValidators.base.getSelectOptional({ multiple: true })
79
+ * field: zodValidators.base.getSelectSchema({ required: false, multiple: true })
56
80
  * })
57
- * // will returns z.array(z.string().nullable())
81
+ * // will returns z.array(z.string().nullable().optional()).optional()
58
82
  */
59
- export declare const getSelectOptional: <Multi extends boolean>(props?: Omit<SelectValidationOptions<Multi>, "message">) => z.ZodOptional<z.ZodNullable<z.ZodString>> | z.ZodOptional<z.ZodArray<z.ZodOptional<z.ZodNullable<z.ZodString>>, "many">>;
83
+ export declare function getSelectSchema<Multi extends boolean>(props?: SelectValidationOptions<true, Multi>): SelectRequiredSchema;
84
+ export declare function getSelectSchema<Multi extends boolean>(props?: SelectValidationOptions<false, Multi>): SelectOptionalSchema;
60
85
  export {};
@@ -1,5 +1,5 @@
1
1
  import { default as z } from 'zod';
2
- export type StringValidationOptions = {
2
+ export type StringValidationOptions<Required extends boolean> = {
3
3
  /**
4
4
  * минимальное количество символов
5
5
  * @default 1
@@ -10,8 +10,27 @@ export type StringValidationOptions = {
10
10
  * @default undefined
11
11
  */
12
12
  max?: number;
13
- message?: Record<keyof Omit<StringValidationOptions, 'message'>, string>;
13
+ /**
14
+ * фиксированная длина символов
15
+ */
16
+ length?: number;
17
+ /**
18
+ * указывает что поле обязательное
19
+ * @default true
20
+ */
21
+ required?: Required;
22
+ message?: Record<keyof Omit<StringValidationOptions<Required>, 'message'> | 'root', string>;
14
23
  };
24
+ /**
25
+ * Схема валидации обязательного поля строкового типа
26
+ */
27
+ declare const getStringRequired: (props?: Omit<StringValidationOptions<true>, "required">) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
28
+ type StringRequiredSchema = ReturnType<typeof getStringRequired>;
29
+ /**
30
+ * Схема валидации обязательного поля строкового типа
31
+ */
32
+ declare const getStringOptional: (props?: Omit<StringValidationOptions<false>, "required">) => z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
33
+ type StringOptionalSchema = ReturnType<typeof getStringOptional>;
15
34
  /**
16
35
  * Схема валидации обязательного поля строкового типа
17
36
  * @param {StringValidationOptions} props настройки схемы
@@ -20,25 +39,30 @@ export type StringValidationOptions = {
20
39
  * @typeParam `message` - `{ [min | max]: string }`
21
40
  * @returns схема валидации поля в соответствии с настройками
22
41
  *
23
- * @example
42
+ * @example with required min value
43
+ * z.object({
44
+ * field: zodValidators.base.getStringSchema({ min: 10 })
45
+ * })
46
+ * // will returns z.string().min(10)
47
+ *
48
+ * @example with required min, max value
24
49
  * z.object({
25
- * field: zodValidators.base.getStringRequired({ min: 10, max: 20 })
50
+ * field: zodValidators.base.getStringSchema({ min: 10, max: 20 })
26
51
  * })
27
52
  * // will returns z.string().min(10).max(20)
28
- */
29
- export declare const getStringRequired: (props?: StringValidationOptions) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
30
- /**
31
- * Схема валидации обязательного поля строкового типа
32
- * @param {StringValidationOptions} props настройки схемы
33
- * @typeParam `min` - `number | undefined` `default: 1`
34
- * @typeParam `max` - `number | undefined` `default: undefined`
35
- * @typeParam `message` - `{ [min | max]: string }`
36
- * @returns схема валидации поля в соответствии с настройками
37
53
  *
38
- * @example
54
+ * @example with optional min value
55
+ * z.object({
56
+ * field: zodValidators.base.getStringSchema({ required: false, min: 10 })
57
+ * })
58
+ * // will returns z.string().min(10).optional()
59
+ *
60
+ * @example with optional min, max value
39
61
  * z.object({
40
- * field: zodValidators.base.getStringOptional({ min: 10, max: 20 })
62
+ * field: zodValidators.base.getStringSchema({ required: false, min: 10, max: 20 })
41
63
  * })
42
64
  * // will returns z.string().min(10).max(20).optional()
43
65
  */
44
- export declare const getStringOptional: (props?: StringValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
66
+ export declare function getStringSchema(props?: StringValidationOptions<true>): StringRequiredSchema;
67
+ export declare function getStringSchema(props?: StringValidationOptions<false>): StringOptionalSchema;
68
+ export {};
@@ -1,34 +1,56 @@
1
1
  import { default as z } from 'zod';
2
- export type UnionValidationOptions<T extends z.Primitive> = {
2
+ export type UnionValidationOptions<Required extends boolean, T extends z.Primitive> = {
3
+ /**
4
+ * сообщение об ошибке
5
+ */
3
6
  message?: ((values: readonly T[]) => string) | string;
4
7
  errorMap?: z.ZodErrorMap;
8
+ /**
9
+ * сообщение об ошибке при не правильном типе значение
10
+ */
5
11
  invalid_type_error?: string;
12
+ /**
13
+ * сообщение об ошибке при отсутствии значения
14
+ */
6
15
  required_error?: string;
16
+ /**
17
+ * описание схемы
18
+ */
7
19
  description?: string;
20
+ /**
21
+ * указывает что поле обязательное
22
+ * @default true
23
+ */
24
+ required?: Required;
8
25
  };
9
26
  /**
10
27
  * Схема валидации обязательного поля из выборки
11
- * @param {z.Primitive[]} values литералы
12
- * @param {z.RawCreateParams & { message: (values: z.Primitive[]) => string }} props настройки схемы
13
- * @returns схема валидации поля в соответствии с настройками
14
- *
15
- * @example
16
- * z.object({
17
- * field: zodValidators.base.getUnionRequired(['A', 'B'] as const)
18
- * }) ^ it need to infer literal type
19
- * // will returns z.union([z.literal('A'), z.literal('B')])
20
28
  */
21
- export declare const getUnionRequired: <T extends z.Primitive>(values: [T, T, ...T[]], props?: UnionValidationOptions<T>) => z.ZodUnion<[z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]>;
29
+ declare const getUnionRequired: <T extends z.Primitive>(values: [T, T, ...T[]], props?: Omit<UnionValidationOptions<true, T>, "required">) => z.ZodUnion<[z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]>;
30
+ type UnionRequiredSchema<T extends z.Primitive> = ReturnType<typeof getUnionRequired<T>>;
31
+ /**
32
+ * Схема валидации обязательного поля из выборки
33
+ */
34
+ declare const getUnionOptional: <T extends z.Primitive>(values: [T, T, ...T[]], props?: UnionValidationOptions<false, T>) => z.ZodOptional<z.ZodUnion<[z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]>>;
35
+ type UnionOptionalSchema<T extends z.Primitive> = ReturnType<typeof getUnionOptional<T>>;
22
36
  /**
23
37
  * Схема валидации обязательного поля из выборки
24
38
  * @param {z.Primitive} values литералы
25
39
  * @param {z.RawCreateParams & { message: (values: z.Primitive[]) => string }} props настройки схемы
26
40
  * @returns схема валидации поля в соответствии с настройками
27
41
  *
28
- * @example
42
+ * @example with required union value
43
+ * z.object({
44
+ * field: zodValidators.base.getUnionSchema(['A', 'B'] as const)
45
+ * }) ^ it need to infer literal type
46
+ * // will returns z.union([z.literal('A'), z.literal('B')])
47
+ *
48
+ * @example with optional union value
29
49
  * z.object({
30
- * field: zodValidators.base.getUnionRequired(['A', 'B'] as const)
50
+ * field: zodValidators.base.getUnionSchema(['A', 'B'] as const, { required: false })
31
51
  * }) ^ it need to infer literal type
32
52
  * // will returns z.union([z.literal('A'), z.literal('B')]).optional()
33
53
  */
34
- export declare const getUnionOptional: <T extends z.Primitive>(values: [T, T, ...T[]], props?: UnionValidationOptions<T>) => z.ZodOptional<z.ZodUnion<[z.ZodLiteral<T>, z.ZodLiteral<T>, ...z.ZodLiteral<T>[]]>>;
54
+ export declare function getUnionSchema<T extends z.Primitive>(values: [T, T, ...T[]], props?: UnionValidationOptions<true, T>): UnionRequiredSchema<T>;
55
+ export declare function getUnionSchema<T extends z.Primitive>(values: [T, T, ...T[]], props?: UnionValidationOptions<false, T>): UnionOptionalSchema<T>;
56
+ export {};
@@ -0,0 +1,14 @@
1
+ export declare const fioDefaultMessages: {
2
+ NON_EMPTY: () => string;
3
+ VALUE_NO_WHITESPACE: () => string;
4
+ ONLY_CYRILLIC: () => string;
5
+ NAME_OR_SURNAME_NON_EMPTY: () => string;
6
+ INVALID_NAME: () => string;
7
+ INVALID_SURNAME: () => string;
8
+ INVALID_PATRONYMIC: () => string;
9
+ };
10
+ export declare const fioRegex: {
11
+ ONLY_CYRILLIC: RegExp;
12
+ CHECK_HYPHEN: RegExp;
13
+ PATRONYMIC: RegExp;
14
+ };