@scbt-ecom/ui 0.30.2 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{CustomLink-BerIdUpJ.js → CustomLink-DmltAHJD.js} +4 -4
- package/dist/{CustomLink-BerIdUpJ.js.map → CustomLink-DmltAHJD.js.map} +1 -1
- package/dist/mergeRefs-qDToYXtM.js +12 -0
- package/dist/mergeRefs-qDToYXtM.js.map +1 -0
- package/dist/shared/ui/formElements/controlled/index.d.ts +2 -2
- package/dist/shared/ui/formElements/uncontrolled/dayPicker/DayPicker.d.ts +1 -1
- package/dist/shared/ui/formElements/uncontrolled/index.d.ts +3 -3
- package/dist/shared/ui/formElements/uncontrolled/select/Select.d.ts +1 -1
- package/dist/shared/ui/formElements/uncontrolled/select/ui/SelectItem.d.ts +1 -1
- package/dist/shared/ui/formElements/uncontrolled/textarea/Textarea.d.ts +1 -1
- package/dist/shared/ui/notification/ui/CustomToast.d.ts +1 -1
- package/dist/shared/utils/typeGuards.d.ts +1 -1
- package/dist/shared/validation/base/base.constants.d.ts +17 -0
- package/dist/shared/validation/base/base.validators.d.ts +20 -0
- package/dist/shared/validation/base/date.validators.d.ts +47 -0
- package/dist/shared/validation/base/email.validators.d.ts +33 -0
- package/dist/shared/validation/base/index.d.ts +1 -0
- package/dist/shared/validation/base/number.validators.d.ts +36 -0
- package/dist/shared/validation/base/phone.validators.d.ts +47 -0
- package/dist/shared/validation/base/select.validators.d.ts +60 -0
- package/dist/shared/validation/base/string.validators.d.ts +44 -0
- package/dist/shared/validation/base/union.validators.d.ts +34 -0
- package/dist/shared/validation/index.d.ts +23 -0
- package/dist/{typeGuards-CaNkXs7N.js → typeGuards-B82KZ2oS.js} +3 -12
- package/dist/typeGuards-B82KZ2oS.js.map +1 -0
- package/dist/ui.js +408 -430
- package/dist/ui.js.map +1 -1
- package/dist/{parse-C_80L3wX.js → utils-b38KjjXe.js} +1060 -1030
- package/dist/utils-b38KjjXe.js.map +1 -0
- package/dist/utils.js +5 -4
- package/dist/utils.js.map +1 -1
- package/dist/validation.js +198 -39
- package/dist/validation.js.map +1 -1
- package/dist/widget.js +1 -1
- package/package.json +1 -1
- package/dist/parse-C_80L3wX.js.map +0 -1
- package/dist/typeGuards-CaNkXs7N.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const o = (...f) => {
|
|
2
|
+
const r = f.filter(Boolean);
|
|
3
|
+
return r.length <= 1 ? r[0] || null : function(t) {
|
|
4
|
+
r.forEach((e) => {
|
|
5
|
+
typeof e == "function" ? e(t) : e && (e.current = t);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
o as m
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=mergeRefs-qDToYXtM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mergeRefs-qDToYXtM.js","sources":["../lib/shared/utils/mergeRefs.ts"],"sourcesContent":["import type React from 'react'\n\nexport const mergeRefs = <T>(...inputRefs: (React.Ref<T> | undefined)[]): React.Ref<T> | React.RefCallback<T> => {\n const filteredInputRefs = inputRefs.filter(Boolean)\n\n if (filteredInputRefs.length <= 1) {\n const firstRef = filteredInputRefs[0]\n\n return firstRef || null\n }\n\n return function mergedRefs(ref) {\n filteredInputRefs.forEach((inputRef) => {\n if (typeof inputRef === 'function') {\n inputRef(ref)\n } else if (inputRef) {\n ;(inputRef as React.MutableRefObject<T | null>).current = ref\n }\n })\n }\n}\n"],"names":["mergeRefs","inputRefs","filteredInputRefs","ref","inputRef"],"mappings":"AAEa,MAAAA,IAAY,IAAOC,MAAiF;AACzG,QAAAC,IAAoBD,EAAU,OAAO,OAAO;AAE9C,SAAAC,EAAkB,UAAU,IACbA,EAAkB,CAAC,KAEjB,OAGd,SAAoBC,GAAK;AACZ,IAAAD,EAAA,QAAQ,CAACE,MAAa;AAClC,MAAA,OAAOA,KAAa,aACtBA,EAASD,CAAG,IACHC,MACPA,EAA8C,UAAUD;AAAA,IAC5D,CACD;AAAA,EACH;AACF;"}
|
|
@@ -26,7 +26,7 @@ export declare const Controlled: {
|
|
|
26
26
|
};
|
|
27
27
|
helperText?: string;
|
|
28
28
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
29
|
-
SelectControl: <TFieldValues extends import('react-hook-form').FieldValues = import('react-hook-form').FieldValues>({ control, classes, name, rules, shouldUnregister, disabled, defaultValue, returnValue, options, helperText, ...props }: import('react-hook-form').UseControllerProps<TFieldValues, import('react-hook-form').Path<TFieldValues>> & Omit<import('@headlessui/react').ComboboxProps<import('..').SelectItemOption, boolean, "li">, "
|
|
29
|
+
SelectControl: <TFieldValues extends import('react-hook-form').FieldValues = import('react-hook-form').FieldValues>({ control, classes, name, rules, shouldUnregister, disabled, defaultValue, returnValue, options, helperText, ...props }: import('react-hook-form').UseControllerProps<TFieldValues, import('react-hook-form').Path<TFieldValues>> & Omit<import('@headlessui/react').ComboboxProps<import('..').SelectItemOption, boolean, "li">, "className" | "onChange" | "multiple" | "by" | "virtual"> & {
|
|
30
30
|
label: string;
|
|
31
31
|
isMulti?: boolean | undefined;
|
|
32
32
|
invalid?: boolean;
|
|
@@ -94,7 +94,7 @@ export declare const Controlled: {
|
|
|
94
94
|
dadataBaseUrl: string;
|
|
95
95
|
formatter?: (item: import('./dadata/types').IDadataOrganizationOption) => import('..').SelectItemOption;
|
|
96
96
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
97
|
-
SliderControl: ({ control, name, defaultValue, disabled, rules, shouldUnregister, classes, ...props }: Omit<import('../uncontrolled/slider/SliderBase').SliderBaseProps, "
|
|
97
|
+
SliderControl: ({ control, name, defaultValue, disabled, rules, shouldUnregister, classes, ...props }: Omit<import('../uncontrolled/slider/SliderBase').SliderBaseProps, "onChange" | "value" | "classes"> & import('react-hook-form').UseControllerProps<import('react-hook-form').FieldValues, string> & {
|
|
98
98
|
control: import('react-hook-form').Control<import('react-hook-form').FieldValues>;
|
|
99
99
|
classes?: import('../uncontrolled/slider/SliderBase').SliderBaseClasses & {
|
|
100
100
|
container?: string;
|
|
@@ -32,7 +32,7 @@ export type DayPickerProps = Omit<MaskInputProps, 'value' | 'onChange' | 'mask'
|
|
|
32
32
|
*/
|
|
33
33
|
externalHandlers?: ExternalHandlers;
|
|
34
34
|
};
|
|
35
|
-
export declare const DayPickerBase: import('react').ForwardRefExoticComponent<Omit<MaskInputProps, "
|
|
35
|
+
export declare const DayPickerBase: import('react').ForwardRefExoticComponent<Omit<MaskInputProps, "onChange" | "mask" | "value" | "classes"> & {
|
|
36
36
|
/**
|
|
37
37
|
* Указывает, открыт ли календарь по умолчанию
|
|
38
38
|
*/
|
|
@@ -40,7 +40,7 @@ export declare const Uncontrolled: {
|
|
|
40
40
|
mask: "datetime" | "email" | "numeric" | "currency" | "decimal" | "integer" | "percentage" | "url" | "ip" | "mac" | "ssn" | "brl-currency" | "cpf" | "cnpj" | (string & {}) | (string[] & {}) | null;
|
|
41
41
|
externalMaskDefinitions?: Record<string, import('./maskInput/MaskInput').Definition>;
|
|
42
42
|
} & import('react').RefAttributes<HTMLInputElement>>;
|
|
43
|
-
SelectBase: import('react').ForwardRefExoticComponent<Omit<import('@headlessui/react').ComboboxProps<import('./select').SelectItemOption, boolean, "li">, "
|
|
43
|
+
SelectBase: import('react').ForwardRefExoticComponent<Omit<import('@headlessui/react').ComboboxProps<import('./select').SelectItemOption, boolean, "li">, "className" | "onChange" | "multiple" | "by" | "virtual"> & {
|
|
44
44
|
label: string;
|
|
45
45
|
isMulti?: boolean | undefined;
|
|
46
46
|
invalid?: boolean;
|
|
@@ -66,7 +66,7 @@ export declare const Uncontrolled: {
|
|
|
66
66
|
onFocus?: (event: React.FocusEvent<HTMLButtonElement>) => void;
|
|
67
67
|
};
|
|
68
68
|
} & import('react').RefAttributes<HTMLButtonElement>>;
|
|
69
|
-
DayPickerBase: import('react').ForwardRefExoticComponent<Omit<import('./maskInput').MaskInputProps, "
|
|
69
|
+
DayPickerBase: import('react').ForwardRefExoticComponent<Omit<import('./maskInput').MaskInputProps, "onChange" | "mask" | "value" | "classes"> & {
|
|
70
70
|
defaultOpen?: boolean;
|
|
71
71
|
value?: string;
|
|
72
72
|
onChange?: (value: string) => void;
|
|
@@ -107,7 +107,7 @@ export declare const Uncontrolled: {
|
|
|
107
107
|
onBlur?: (event: React.FocusEvent<HTMLButtonElement>) => void;
|
|
108
108
|
};
|
|
109
109
|
} & import('react').RefAttributes<HTMLDivElement>>;
|
|
110
|
-
TextareaBase: import('react').ForwardRefExoticComponent<Omit<import('react').TextareaHTMLAttributes<HTMLTextAreaElement>, "
|
|
110
|
+
TextareaBase: import('react').ForwardRefExoticComponent<Omit<import('react').TextareaHTMLAttributes<HTMLTextAreaElement>, "className" | "size"> & {
|
|
111
111
|
classes?: {
|
|
112
112
|
container?: string;
|
|
113
113
|
textarea?: string;
|
|
@@ -73,7 +73,7 @@ export type SelectBaseProps<Multi extends boolean> = Omit<ComboboxProps<SelectIt
|
|
|
73
73
|
*/
|
|
74
74
|
externalHandlers?: ExternalHandlers;
|
|
75
75
|
};
|
|
76
|
-
export declare const SelectBase: import('react').ForwardRefExoticComponent<Omit<ComboboxProps<SelectItemOption, boolean, "li">, "
|
|
76
|
+
export declare const SelectBase: import('react').ForwardRefExoticComponent<Omit<ComboboxProps<SelectItemOption, boolean, "li">, "className" | "onChange" | "multiple" | "by" | "virtual"> & {
|
|
77
77
|
/**
|
|
78
78
|
* Отображаемый лейбл
|
|
79
79
|
*/
|
|
@@ -14,7 +14,7 @@ export type SelectItemProps = Omit<ComboboxOptionProps, 'className' | 'value'> &
|
|
|
14
14
|
displayValue?: (option: SelectItemOption) => string;
|
|
15
15
|
motionProps?: React.ComponentPropsWithoutRef<typeof motion.li>;
|
|
16
16
|
};
|
|
17
|
-
export declare const SelectItem: import('react').ForwardRefExoticComponent<Omit<ComboboxOptionProps, "
|
|
17
|
+
export declare const SelectItem: import('react').ForwardRefExoticComponent<Omit<ComboboxOptionProps, "className" | "value"> & {
|
|
18
18
|
option: SelectItemOption;
|
|
19
19
|
isMulti?: boolean;
|
|
20
20
|
classes?: SelectItemClasses;
|
|
@@ -34,7 +34,7 @@ export type TextareaBaseProps = Omit<React.TextareaHTMLAttributes<HTMLTextAreaEl
|
|
|
34
34
|
*/
|
|
35
35
|
externalHandlers?: ExternalHandlers;
|
|
36
36
|
};
|
|
37
|
-
export declare const TextareaBase: import('react').ForwardRefExoticComponent<Omit<import('react').TextareaHTMLAttributes<HTMLTextAreaElement>, "
|
|
37
|
+
export declare const TextareaBase: import('react').ForwardRefExoticComponent<Omit<import('react').TextareaHTMLAttributes<HTMLTextAreaElement>, "className" | "size"> & {
|
|
38
38
|
/**
|
|
39
39
|
* Дополнительные стили внутренних компонентов
|
|
40
40
|
*/
|
|
@@ -2,7 +2,7 @@ import { Toast } from 'react-hot-toast';
|
|
|
2
2
|
import { VariantProps } from 'class-variance-authority';
|
|
3
3
|
import { NotificationProps } from '../Notification';
|
|
4
4
|
declare const toastContainerConfig: (props?: ({
|
|
5
|
-
intent?: "
|
|
5
|
+
intent?: "info" | "error" | null | undefined;
|
|
6
6
|
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
7
7
|
type TContainerConfig = VariantProps<typeof toastContainerConfig>;
|
|
8
8
|
export type ICustomToastProps = NotificationProps & TContainerConfig & Toast;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class TypeGuards {
|
|
2
2
|
static isString(value: unknown): value is string;
|
|
3
|
-
static isStringEmpty(value: unknown):
|
|
3
|
+
static isStringEmpty(value: unknown): value is string;
|
|
4
4
|
static isNull(value: unknown): value is null;
|
|
5
5
|
static isUndefined(value: unknown): value is undefined;
|
|
6
6
|
static isNil(value: unknown): value is boolean;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Primitive } from 'zod';
|
|
2
|
+
export declare const baseDefaultMessages: {
|
|
3
|
+
NON_EMPTY: () => string;
|
|
4
|
+
MIN_LENGTH: (min: number) => string;
|
|
5
|
+
MAX_LENGTH: (max: number) => string;
|
|
6
|
+
MIN_VALUE: (min: number) => string;
|
|
7
|
+
MAX_VALUE: (max: number) => string;
|
|
8
|
+
PHONE_NON_EMPTY: () => string;
|
|
9
|
+
PHONE_INVALID_OPERATOR: () => string;
|
|
10
|
+
EMAIL_INVALID: () => string;
|
|
11
|
+
EMAIL_NON_EMPTY: () => string;
|
|
12
|
+
SELECT_NON_EMPTY: () => string;
|
|
13
|
+
SELECT_MULTIPLE_NON_EMPTY: (length: number) => string;
|
|
14
|
+
DATE_INVALID_FORMAT: () => string;
|
|
15
|
+
DATE_NON_EMPTY: () => string;
|
|
16
|
+
VALUE_OUT_OF_RANGE: <T extends Primitive>(range: T[]) => string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
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>[]]>>;
|
|
20
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type DateValidationOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* парсить строку с учетом ISO формата
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
iso?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* шаблон для валидации строки (будет проигнорирован, если `iso = true`)
|
|
10
|
+
* @default 'dd.MM.yyyy'
|
|
11
|
+
*/
|
|
12
|
+
pattern?: string;
|
|
13
|
+
message?: {
|
|
14
|
+
min?: string;
|
|
15
|
+
invalidDate?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Схема валидации опционального поля номера телефона
|
|
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
|
+
*/
|
|
32
|
+
export declare const getDateRequired: (props?: DateValidationOptions) => z.ZodDefault<z.ZodEffects<z.ZodString, string, string>>;
|
|
33
|
+
/**
|
|
34
|
+
* Схема валидации опционального поля номера телефона
|
|
35
|
+
* @param {DateValidationOptions} props настройки схемы
|
|
36
|
+
* @typeParam `iso` - `boolean | undefined` `default: false` парсить строку с учетом ISO формата
|
|
37
|
+
* @typeParam `pattern` - `string | undefined` `default: 'dd.MM.yyyy'` шаблон для валидации строки (будет проигнорирован, если `iso = true`)
|
|
38
|
+
* @typeParam `message` - `{ [min | invalidOperator]: string }`
|
|
39
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* z.object({
|
|
43
|
+
* field: zodValidators.base.getDateOptional()
|
|
44
|
+
* })
|
|
45
|
+
* // will returns z.string()
|
|
46
|
+
*/
|
|
47
|
+
export declare const getDateOptional: (props?: DateValidationOptions) => z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string | undefined, string>, string | undefined, string>>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type EmailValidationOptions = {
|
|
3
|
+
message?: {
|
|
4
|
+
min?: string;
|
|
5
|
+
invalid?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Схема валидации обязательного поля типа email
|
|
10
|
+
* @param {EmailValidationOptions} props настройки схемы
|
|
11
|
+
* @typeParam `message` - `{ [min | invalid]: string }`
|
|
12
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* z.object({
|
|
16
|
+
* field: zodValidators.base.getEmailRequired({ message: { min: '' } })
|
|
17
|
+
* })
|
|
18
|
+
* // 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
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* z.object({
|
|
29
|
+
* field: zodValidators.base.getEmailOptional({ message: { min: '' } })
|
|
30
|
+
* })
|
|
31
|
+
* // will returns z.string().min(1).email().optional()
|
|
32
|
+
*/
|
|
33
|
+
export declare const getEmailOptional: (props?: EmailValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>, string | undefined, string | undefined>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './base.validators';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type NumberValidationOptions = {
|
|
3
|
+
min?: number;
|
|
4
|
+
max?: number;
|
|
5
|
+
message?: Record<keyof Omit<NumberValidationOptions, 'message'>, string>;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Схема валидации обязательного поля числового типа
|
|
9
|
+
* @param {NumberValidationOptions} props настройки схемы
|
|
10
|
+
* @typeParam `min` - `number | undefined` `default: 1`
|
|
11
|
+
* @typeParam `max` - `number | undefined` `default: undefined`
|
|
12
|
+
* @typeParam `message` - `{ [min | max]: string }`
|
|
13
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* z.object({
|
|
17
|
+
* field: zodValidators.base.getNumberRequired({ min: 10, max: 20 })
|
|
18
|
+
* })
|
|
19
|
+
* // 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
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* z.object({
|
|
32
|
+
* field: zodValidators.base.getNumberOptional({ min: 10, max: 20 })
|
|
33
|
+
* })
|
|
34
|
+
* // will returns z.coerce.number().min(10).max(20).optional()
|
|
35
|
+
*/
|
|
36
|
+
export declare const getNumberOptional: (props?: NumberValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodDefault<z.ZodNumber>>, number | undefined, number | undefined>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type PhoneValidationOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* исключает маску в возвращаемом значении
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
ignoreMask?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* игнорирует символы для проверки поля исключая данные символы
|
|
10
|
+
* @default /[()+_ -]/g
|
|
11
|
+
*/
|
|
12
|
+
maskSymbols?: RegExp;
|
|
13
|
+
message?: {
|
|
14
|
+
min?: string;
|
|
15
|
+
invalidOperator?: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Схема валидации обязательного поля номера телефона
|
|
20
|
+
* @param {PhoneValidationOptions} props настройки схемы
|
|
21
|
+
* @typeParam `ignoreMask` - `boolean | undefined` `default: false`
|
|
22
|
+
* @typeParam `maskSymbols` - `RegExp | undefined` `default: /[()+_ -]/g`
|
|
23
|
+
* @typeParam `message` - `{ [min | invalidOperator]: string }`
|
|
24
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* z.object({
|
|
28
|
+
* field: zodValidators.base.getPhoneRequired()
|
|
29
|
+
* })
|
|
30
|
+
* // 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
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* z.object({
|
|
43
|
+
* field: zodValidators.base.getPhoneOptional()
|
|
44
|
+
* })
|
|
45
|
+
* // will returns z.string()
|
|
46
|
+
*/
|
|
47
|
+
export declare const getPhoneOptional: (props?: PhoneValidationOptions) => z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string | undefined, string>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type SelectSingleValidationOptions<Multi extends boolean = false> = {
|
|
3
|
+
/**
|
|
4
|
+
* включает валидацию мульти селекта
|
|
5
|
+
* @default false
|
|
6
|
+
*/
|
|
7
|
+
multiple?: Multi;
|
|
8
|
+
message?: {
|
|
9
|
+
single?: string;
|
|
10
|
+
multiple?: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
type SelectMultipleValidationOptions<Multi extends boolean = true> = SelectSingleValidationOptions<Multi> & {
|
|
14
|
+
/**
|
|
15
|
+
* минимальное количество элементов
|
|
16
|
+
* @default 0
|
|
17
|
+
*/
|
|
18
|
+
minLength?: number;
|
|
19
|
+
};
|
|
20
|
+
type SelectValidationOptions<Multi extends boolean> = Multi extends true ? SelectMultipleValidationOptions<Multi> : SelectSingleValidationOptions<Multi>;
|
|
21
|
+
/**
|
|
22
|
+
* Схема валидации обязательного поля типа select
|
|
23
|
+
* @param {SelectValidationOptions} props настройки схемы
|
|
24
|
+
* @typeParam `multiple` - `boolean`
|
|
25
|
+
* @typeParam `minLength` - `number` `required if multiple = true`
|
|
26
|
+
* @typeParam `message` - `{ [single | multiple]: string }`
|
|
27
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* z.object({
|
|
31
|
+
* field: zodValidators.base.getSelectRequired({ multiple: false })
|
|
32
|
+
* })
|
|
33
|
+
* // will returns z.string().min(1).nullable().refine(Boolean)
|
|
34
|
+
*
|
|
35
|
+
* z.object({
|
|
36
|
+
* field: zodValidators.base.getSelectRequired({ multiple: true, minLength: 3 })
|
|
37
|
+
* })
|
|
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 схема валидации поля в соответствии с настройками
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* z.object({
|
|
50
|
+
* field: zodValidators.base.getSelectOptional({ multiple: false })
|
|
51
|
+
* })
|
|
52
|
+
* // will returns z.string().nullable()
|
|
53
|
+
*
|
|
54
|
+
* z.object({
|
|
55
|
+
* field: zodValidators.base.getSelectOptional({ multiple: true })
|
|
56
|
+
* })
|
|
57
|
+
* // will returns z.array(z.string().nullable())
|
|
58
|
+
*/
|
|
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">>;
|
|
60
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type StringValidationOptions = {
|
|
3
|
+
/**
|
|
4
|
+
* минимальное количество символов
|
|
5
|
+
* @default 1
|
|
6
|
+
*/
|
|
7
|
+
min?: number;
|
|
8
|
+
/**
|
|
9
|
+
* максимальное количество символов
|
|
10
|
+
* @default undefined
|
|
11
|
+
*/
|
|
12
|
+
max?: number;
|
|
13
|
+
message?: Record<keyof Omit<StringValidationOptions, 'message'>, string>;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Схема валидации обязательного поля строкового типа
|
|
17
|
+
* @param {StringValidationOptions} props настройки схемы
|
|
18
|
+
* @typeParam `min` - `number | undefined` `default: 1`
|
|
19
|
+
* @typeParam `max` - `number | undefined` `default: undefined`
|
|
20
|
+
* @typeParam `message` - `{ [min | max]: string }`
|
|
21
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* z.object({
|
|
25
|
+
* field: zodValidators.base.getStringRequired({ min: 10, max: 20 })
|
|
26
|
+
* })
|
|
27
|
+
* // 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
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* z.object({
|
|
40
|
+
* field: zodValidators.base.getStringOptional({ min: 10, max: 20 })
|
|
41
|
+
* })
|
|
42
|
+
* // will returns z.string().min(10).max(20).optional()
|
|
43
|
+
*/
|
|
44
|
+
export declare const getStringOptional: (props?: StringValidationOptions) => z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { default as z } from 'zod';
|
|
2
|
+
export type UnionValidationOptions<T extends z.Primitive> = {
|
|
3
|
+
message?: ((values: readonly T[]) => string) | string;
|
|
4
|
+
errorMap?: z.ZodErrorMap;
|
|
5
|
+
invalid_type_error?: string;
|
|
6
|
+
required_error?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Схема валидации обязательного поля из выборки
|
|
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
|
+
*/
|
|
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>[]]>;
|
|
22
|
+
/**
|
|
23
|
+
* Схема валидации обязательного поля из выборки
|
|
24
|
+
* @param {z.Primitive} values литералы
|
|
25
|
+
* @param {z.RawCreateParams & { message: (values: z.Primitive[]) => string }} props настройки схемы
|
|
26
|
+
* @returns схема валидации поля в соответствии с настройками
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* z.object({
|
|
30
|
+
* field: zodValidators.base.getUnionRequired(['A', 'B'] as const)
|
|
31
|
+
* }) ^ it need to infer literal type
|
|
32
|
+
* // will returns z.union([z.literal('A'), z.literal('B')]).optional()
|
|
33
|
+
*/
|
|
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>[]]>>;
|
|
@@ -1,3 +1,26 @@
|
|
|
1
1
|
export * from './regExp';
|
|
2
2
|
export * from './messages';
|
|
3
3
|
export * from './zodValidation';
|
|
4
|
+
export type * from './base';
|
|
5
|
+
export declare const zodValidators: {
|
|
6
|
+
base: {
|
|
7
|
+
getStringRequired: (props?: import('./base/string.validators').StringValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
|
|
8
|
+
getStringOptional: (props?: import('./base/string.validators').StringValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodString>, string | undefined, string | undefined>;
|
|
9
|
+
getEmailRequired: (props?: import('./base/email.validators').EmailValidationOptions) => import('zod').ZodDefault<import('zod').ZodString>;
|
|
10
|
+
getEmailOptional: (props?: import('./base/email.validators').EmailValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodEffects<import('zod').ZodString, string, string>>, string | undefined, string | undefined>;
|
|
11
|
+
getSelectRequired: <Multi extends boolean>(props?: Multi extends true ? import('./base/select.validators').SelectSingleValidationOptions<Multi> & {
|
|
12
|
+
minLength?: number;
|
|
13
|
+
} : import('./base/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">>;
|
|
14
|
+
getSelectOptional: <Multi extends boolean>(props?: Omit<Multi extends true ? import('./base/select.validators').SelectSingleValidationOptions<Multi> & {
|
|
15
|
+
minLength?: number;
|
|
16
|
+
} : import('./base/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">>;
|
|
17
|
+
getNumberRequired: (props?: import('./base/number.validators').NumberValidationOptions) => import('zod').ZodDefault<import('zod').ZodNumber>;
|
|
18
|
+
getNumberOptional: (props?: import('./base/number.validators').NumberValidationOptions) => import('zod').ZodEffects<import('zod').ZodOptional<import('zod').ZodDefault<import('zod').ZodNumber>>, number | undefined, number | undefined>;
|
|
19
|
+
getPhoneRequired: (props?: import('./base/phone.validators').PhoneValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
|
|
20
|
+
getPhoneOptional: (props?: import('./base/phone.validators').PhoneValidationOptions) => import('zod').ZodEffects<import('zod').ZodEffects<import('zod').ZodString, string, string>, string | undefined, string>;
|
|
21
|
+
getDateRequired: (props?: import('./base/date.validators').DateValidationOptions) => import('zod').ZodDefault<import('zod').ZodEffects<import('zod').ZodString, string, string>>;
|
|
22
|
+
getDateOptional: (props?: import('./base/date.validators').DateValidationOptions) => import('zod').ZodOptional<import('zod').ZodEffects<import('zod').ZodEffects<import('zod').ZodString, string | undefined, string>, string | undefined, string>>;
|
|
23
|
+
getUnionRequired: <T extends import('zod').Primitive>(values: [T, T, ...T[]], props?: import('./base/union.validators').UnionValidationOptions<T>) => import('zod').ZodUnion<[import('zod').ZodLiteral<T>, import('zod').ZodLiteral<T>, ...import('zod').ZodLiteral<T>[]]>;
|
|
24
|
+
getUnionOptional: <T extends import('zod').Primitive>(values: [T, T, ...T[]], props?: import('./base/union.validators').UnionValidationOptions<T>) => import('zod').ZodOptional<import('zod').ZodUnion<[import('zod').ZodLiteral<T>, import('zod').ZodLiteral<T>, ...import('zod').ZodLiteral<T>[]]>>;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const t = i.filter(Boolean);
|
|
3
|
-
return t.length <= 1 ? t[0] || null : function(s) {
|
|
4
|
-
t.forEach((r) => {
|
|
5
|
-
typeof r == "function" ? r(s) : r && (r.current = s);
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
};
|
|
9
|
-
class f {
|
|
1
|
+
class r {
|
|
10
2
|
static isString(t) {
|
|
11
3
|
return typeof t == "string";
|
|
12
4
|
}
|
|
@@ -30,7 +22,6 @@ class f {
|
|
|
30
22
|
}
|
|
31
23
|
}
|
|
32
24
|
export {
|
|
33
|
-
|
|
34
|
-
n as m
|
|
25
|
+
r as T
|
|
35
26
|
};
|
|
36
|
-
//# sourceMappingURL=typeGuards-
|
|
27
|
+
//# sourceMappingURL=typeGuards-B82KZ2oS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typeGuards-B82KZ2oS.js","sources":["../lib/shared/utils/typeGuards.ts"],"sourcesContent":["export class TypeGuards {\n static isString(value: unknown): value is string {\n return typeof value === 'string'\n }\n\n static isStringEmpty(value: unknown): value is string {\n return this.isString(value) && !value.length\n }\n\n static isNull(value: unknown): value is null {\n return value === null\n }\n\n static isUndefined(value: unknown): value is undefined {\n return value === undefined && typeof value === 'undefined'\n }\n\n static isNil(value: unknown): value is boolean {\n return this.isNull(value) || this.isUndefined(value)\n }\n\n static isArray(value: unknown): value is unknown[] {\n return Array.isArray(value)\n }\n\n static isArrayEmpty(value: unknown): boolean {\n return this.isArray(value) && !value.length\n }\n}\n"],"names":["TypeGuards","value"],"mappings":"AAAO,MAAMA,EAAW;AAAA,EACtB,OAAO,SAASC,GAAiC;AAC/C,WAAO,OAAOA,KAAU;AAAA,EAAA;AAAA,EAG1B,OAAO,cAAcA,GAAiC;AACpD,WAAO,KAAK,SAASA,CAAK,KAAK,CAACA,EAAM;AAAA,EAAA;AAAA,EAGxC,OAAO,OAAOA,GAA+B;AAC3C,WAAOA,MAAU;AAAA,EAAA;AAAA,EAGnB,OAAO,YAAYA,GAAoC;AAC9C,WAAAA,MAAU,UAAa,OAAOA,IAAU;AAAA,EAAA;AAAA,EAGjD,OAAO,MAAMA,GAAkC;AAC7C,WAAO,KAAK,OAAOA,CAAK,KAAK,KAAK,YAAYA,CAAK;AAAA,EAAA;AAAA,EAGrD,OAAO,QAAQA,GAAoC;AAC1C,WAAA,MAAM,QAAQA,CAAK;AAAA,EAAA;AAAA,EAG5B,OAAO,aAAaA,GAAyB;AAC3C,WAAO,KAAK,QAAQA,CAAK,KAAK,CAACA,EAAM;AAAA,EAAA;AAEzC;"}
|