@astral/validations 4.24.3 → 4.24.4
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/array/array.d.ts +1 -1
- package/boolean/boolean.d.ts +1 -1
- package/containsPunctuationMarks/containsPunctuationMarks.js +1 -1
- package/core/compose/compose.d.ts +1 -1
- package/core/composeAsync/composeAsync.d.ts +1 -1
- package/core/context/createContext/createContext.d.ts +1 -1
- package/core/errors/ArrayError/ArrayError.d.ts +1 -1
- package/core/errors/ErrorMap/ErrorMap.d.ts +1 -1
- package/core/errors/ErrorMap/index.d.ts +1 -1
- package/core/errors/ErrorMap/index.js +1 -1
- package/core/errors/SimpleError/SimpleError.d.ts +5 -5
- package/core/errors/SimpleError/createSimpleError/createSimpleError.d.ts +1 -1
- package/core/errors/SimpleError/index.d.ts +1 -1
- package/core/errors/SimpleError/index.js +1 -1
- package/core/errors/index.d.ts +3 -3
- package/core/errors/index.js +3 -3
- package/core/errors/types.d.ts +1 -1
- package/core/guard/createGuard/createGuard.d.ts +10 -10
- package/core/guard/createGuard/createGuard.js +1 -1
- package/core/index.d.ts +4 -4
- package/core/index.js +4 -4
- package/core/logger/logger.js +1 -0
- package/core/rule/callAsyncRule/callAsyncRule.d.ts +2 -2
- package/core/rule/callRule/callRule.d.ts +2 -2
- package/core/rule/createRule/createRule.d.ts +5 -5
- package/core/rule/index.d.ts +3 -3
- package/core/rule/index.js +3 -3
- package/core/rule/required/index.d.ts +1 -1
- package/core/rule/required/index.js +1 -1
- package/core/rule/required/required.js +3 -1
- package/core/types.d.ts +1 -1
- package/core/utils/index.d.ts +1 -1
- package/core/utils/index.js +1 -1
- package/core/utils/isHasConsecutiveChars/isHasConsecutiveChars.js +1 -1
- package/core/utils/isStringOfZeros/isStringOfZeros.js +1 -1
- package/date/date.d.ts +1 -1
- package/deepPartial/deepPartial.d.ts +2 -2
- package/email/email.js +3 -1
- package/emailOrPhone/constants.js +1 -1
- package/emailOrPhone/emailOrPhone.js +4 -5
- package/index.d.ts +48 -48
- package/index.js +48 -48
- package/innFL/index.d.ts +1 -1
- package/innFL/index.js +1 -1
- package/innIP/index.d.ts +1 -1
- package/innIP/index.js +1 -1
- package/innTwelveSymbols/index.d.ts +1 -1
- package/innTwelveSymbols/index.js +1 -1
- package/innUL/index.d.ts +1 -1
- package/innUL/index.js +1 -1
- package/length/index.d.ts +1 -1
- package/length/index.js +1 -1
- package/max/index.d.ts +1 -1
- package/max/index.js +1 -1
- package/max/max.d.ts +6 -6
- package/max/max.js +1 -0
- package/min/index.d.ts +1 -1
- package/min/index.js +1 -1
- package/min/min.d.ts +6 -6
- package/min/min.js +1 -0
- package/minYearsOld/index.d.ts +1 -1
- package/minYearsOld/index.js +1 -1
- package/minYearsOld/minYearsOld.d.ts +1 -1
- package/mobilePhone/index.d.ts +1 -1
- package/mobilePhone/index.js +1 -1
- package/node/array/array.d.ts +1 -1
- package/node/boolean/boolean.d.ts +1 -1
- package/node/containsPunctuationMarks/containsPunctuationMarks.js +1 -1
- package/node/core/compose/compose.d.ts +1 -1
- package/node/core/composeAsync/composeAsync.d.ts +1 -1
- package/node/core/context/createContext/createContext.d.ts +1 -1
- package/node/core/errors/ArrayError/ArrayError.d.ts +1 -1
- package/node/core/errors/ErrorMap/ErrorMap.d.ts +1 -1
- package/node/core/errors/ErrorMap/index.d.ts +1 -1
- package/node/core/errors/ErrorMap/index.js +1 -1
- package/node/core/errors/SimpleError/SimpleError.d.ts +5 -5
- package/node/core/errors/SimpleError/createSimpleError/createSimpleError.d.ts +1 -1
- package/node/core/errors/SimpleError/index.d.ts +1 -1
- package/node/core/errors/SimpleError/index.js +1 -1
- package/node/core/errors/index.d.ts +3 -3
- package/node/core/errors/index.js +3 -3
- package/node/core/errors/types.d.ts +1 -1
- package/node/core/guard/createGuard/createGuard.d.ts +10 -10
- package/node/core/guard/createGuard/createGuard.js +1 -1
- package/node/core/index.d.ts +4 -4
- package/node/core/index.js +4 -4
- package/node/core/logger/logger.js +1 -0
- package/node/core/rule/callAsyncRule/callAsyncRule.d.ts +2 -2
- package/node/core/rule/callRule/callRule.d.ts +2 -2
- package/node/core/rule/createRule/createRule.d.ts +5 -5
- package/node/core/rule/index.d.ts +3 -3
- package/node/core/rule/index.js +3 -3
- package/node/core/rule/required/index.d.ts +1 -1
- package/node/core/rule/required/index.js +1 -1
- package/node/core/rule/required/required.js +3 -1
- package/node/core/types.d.ts +1 -1
- package/node/core/utils/index.d.ts +1 -1
- package/node/core/utils/index.js +1 -1
- package/node/core/utils/isHasConsecutiveChars/isHasConsecutiveChars.js +1 -1
- package/node/core/utils/isStringOfZeros/isStringOfZeros.js +1 -1
- package/node/date/date.d.ts +1 -1
- package/node/deepPartial/deepPartial.d.ts +2 -2
- package/node/email/email.js +3 -1
- package/node/emailOrPhone/emailOrPhone.js +4 -5
- package/node/index.d.ts +48 -48
- package/node/index.js +136 -136
- package/node/innFL/index.d.ts +1 -1
- package/node/innFL/index.js +1 -1
- package/node/innIP/index.d.ts +1 -1
- package/node/innIP/index.js +1 -1
- package/node/innTwelveSymbols/index.d.ts +1 -1
- package/node/innTwelveSymbols/index.js +1 -1
- package/node/innUL/index.d.ts +1 -1
- package/node/innUL/index.js +1 -1
- package/node/length/index.d.ts +1 -1
- package/node/length/index.js +1 -1
- package/node/max/index.d.ts +1 -1
- package/node/max/index.js +1 -1
- package/node/max/max.d.ts +6 -6
- package/node/max/max.js +1 -0
- package/node/min/index.d.ts +1 -1
- package/node/min/index.js +1 -1
- package/node/min/min.d.ts +6 -6
- package/node/min/min.js +1 -0
- package/node/minYearsOld/index.d.ts +1 -1
- package/node/minYearsOld/index.js +1 -1
- package/node/minYearsOld/minYearsOld.d.ts +1 -1
- package/node/mobilePhone/index.d.ts +1 -1
- package/node/mobilePhone/index.js +1 -1
- package/node/number/index.d.ts +1 -1
- package/node/number/index.js +1 -1
- package/node/number/number.d.ts +1 -1
- package/node/object/index.d.ts +1 -1
- package/node/object/index.js +1 -1
- package/node/object/object.d.ts +6 -6
- package/node/object/object.js +6 -4
- package/node/object/objectAsync/objectAsync.d.ts +9 -9
- package/node/object/objectAsync/objectAsync.js +7 -5
- package/node/ogrnIP/index.d.ts +1 -1
- package/node/ogrnIP/index.js +1 -1
- package/node/ogrnUL/index.d.ts +1 -1
- package/node/ogrnUL/index.js +1 -1
- package/node/or/or.js +1 -1
- package/node/partial/partial.d.ts +1 -1
- package/node/passportNumber/passportNumber.js +1 -1
- package/node/pattern/index.d.ts +1 -1
- package/node/pattern/index.js +1 -1
- package/node/rangeDate/rangeDate.d.ts +1 -1
- package/node/rangeDate/rangeDate.js +9 -3
- package/node/rangeDateMinMax/rangeDateMinMax.js +3 -1
- package/node/snils/index.d.ts +1 -1
- package/node/snils/index.js +1 -1
- package/node/snils/snils.js +3 -1
- package/node/string/index.d.ts +1 -1
- package/node/string/index.js +1 -1
- package/node/string/string.d.ts +1 -1
- package/node/string/stringAsync/stringAsync.d.ts +1 -1
- package/node/string/stringAsync/stringAsync.js +1 -1
- package/node/toPlainError/toPlainError.js +1 -4
- package/node/toPlainError/utils/index.d.ts +1 -1
- package/node/toPlainError/utils/index.js +1 -1
- package/node/uploadedFile/index.d.ts +1 -1
- package/node/uploadedFile/index.js +1 -1
- package/node/uploadedFile/uploadedFile.d.ts +1 -1
- package/node/uploadedFileList/index.d.ts +1 -1
- package/node/uploadedFileList/index.js +1 -1
- package/node/uploadedFileList/uploadedFileList.d.ts +1 -1
- package/node/uploadedFileList/uploadedFileList.js +1 -1
- package/number/index.d.ts +1 -1
- package/number/index.js +1 -1
- package/number/number.d.ts +1 -1
- package/object/index.d.ts +1 -1
- package/object/index.js +1 -1
- package/object/object.d.ts +6 -6
- package/object/object.js +6 -4
- package/object/objectAsync/objectAsync.d.ts +9 -9
- package/object/objectAsync/objectAsync.js +7 -5
- package/ogrnIP/index.d.ts +1 -1
- package/ogrnIP/index.js +1 -1
- package/ogrnUL/index.d.ts +1 -1
- package/ogrnUL/index.js +1 -1
- package/or/or.js +1 -1
- package/package.json +1 -1
- package/partial/partial.d.ts +1 -1
- package/passportNumber/passportNumber.js +1 -1
- package/pattern/index.d.ts +1 -1
- package/pattern/index.js +1 -1
- package/rangeDate/rangeDate.d.ts +1 -1
- package/rangeDate/rangeDate.js +9 -3
- package/rangeDateMinMax/rangeDateMinMax.js +3 -1
- package/snils/index.d.ts +1 -1
- package/snils/index.js +1 -1
- package/snils/snils.js +3 -1
- package/string/index.d.ts +1 -1
- package/string/index.js +1 -1
- package/string/string.d.ts +1 -1
- package/string/stringAsync/stringAsync.d.ts +1 -1
- package/string/stringAsync/stringAsync.js +1 -1
- package/toPlainError/toPlainError.js +1 -4
- package/toPlainError/utils/index.d.ts +1 -1
- package/toPlainError/utils/index.js +1 -1
- package/uploadedFile/index.d.ts +1 -1
- package/uploadedFile/index.js +1 -1
- package/uploadedFile/uploadedFile.d.ts +1 -1
- package/uploadedFileList/index.d.ts +1 -1
- package/uploadedFileList/index.js +1 -1
- package/uploadedFileList/uploadedFileList.d.ts +1 -1
- package/uploadedFileList/uploadedFileList.js +1 -1
package/array/array.d.ts
CHANGED
@@ -12,4 +12,4 @@ import { type ValidationRule, type ValidationTypes } from '../core';
|
|
12
12
|
* validateArray(value);
|
13
13
|
* ```
|
14
14
|
*/
|
15
|
-
export declare const array: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<
|
15
|
+
export declare const array: <TItem extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(...rules: ValidationRule<TItem[], TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, {}>;
|
package/boolean/boolean.d.ts
CHANGED
@@ -10,4 +10,4 @@ import { type ValidationRule } from '../core';
|
|
10
10
|
* validate(true);
|
11
11
|
* ```
|
12
12
|
*/
|
13
|
-
export declare const boolean: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<boolean, TLastSchemaValues>[]) => import("../core").
|
13
|
+
export declare const boolean: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<boolean, TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, {}>;
|
@@ -9,7 +9,7 @@ import { CONTAINS_PUNCTUATION_MARKS_ERROR_CODE } from './constants';
|
|
9
9
|
* ```
|
10
10
|
*/
|
11
11
|
export const containsPunctuationMarks = (params) => createRule((value, ctx) => {
|
12
|
-
const containsPunctuationMarksRegex = /(?=.*[!$%&’”'"()
|
12
|
+
const containsPunctuationMarksRegex = /(?=.*[!$%&’”'"()+,-./:;<=>?@[\]^_{|}])/;
|
13
13
|
if (!containsPunctuationMarksRegex.test(value)) {
|
14
14
|
return ctx.createError({
|
15
15
|
code: CONTAINS_PUNCTUATION_MARKS_ERROR_CODE,
|
@@ -3,4 +3,4 @@ import { type IndependentValidationRule, type ValidationRule } from '../rule';
|
|
3
3
|
* Объединяет переданные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
|
4
4
|
* @example compose(min(), max());
|
5
5
|
*/
|
6
|
-
export declare const compose: <
|
6
|
+
export declare const compose: <TValidationType, TLastSchemaValues extends Record<string, unknown>>(...rules: Array<IndependentValidationRule<TValidationType, TLastSchemaValues> | ValidationRule<TValidationType, TLastSchemaValues>>) => IndependentValidationRule<TValidationType, Record<string, unknown>>;
|
@@ -3,4 +3,4 @@ import { type AsyncIndependentValidationRule, type AsyncValidationRule, type Ind
|
|
3
3
|
* Объединяет переданные асинхронные правила в цепочку правил, останавливает выполнение цепочки, если появилась ошибка. Выполняет правила слева направо
|
4
4
|
* @example composeAsync(stringAsync(), max());
|
5
5
|
*/
|
6
|
-
export declare const composeAsync: <
|
6
|
+
export declare const composeAsync: <TValidationType, TLastSchemaValues extends Record<string, unknown>>(...rules: Array<IndependentValidationRule<TValidationType, TLastSchemaValues> | AsyncIndependentValidationRule<TValidationType, TLastSchemaValues> | ValidationRule<TValidationType, TLastSchemaValues> | AsyncValidationRule<TValidationType, TLastSchemaValues>>) => AsyncIndependentValidationRule<TValidationType, Record<string, unknown>>;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { type DeepPartial } from 'utility-types';
|
2
|
-
import { type ValidationContext } from '../types';
|
3
2
|
import { type ValidationTypes } from '../../types';
|
3
|
+
import { type ValidationContext } from '../types';
|
4
4
|
type Params<TLastSchemaValues extends Record<string, unknown>> = {
|
5
5
|
/**
|
6
6
|
* Value последнего валидируемого объекта
|
@@ -8,7 +8,7 @@ export type ValidationArrayErrorCause = {
|
|
8
8
|
* Массив ошибок элементов валидируемого массива.
|
9
9
|
* Индекс errorArray соответвует индексу валидируемого элемента массива
|
10
10
|
*/
|
11
|
-
errorArray:
|
11
|
+
errorArray: ValidationResult[];
|
12
12
|
};
|
13
13
|
/**
|
14
14
|
* Array ошибок для массива
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { type ValidationErrorData, ValidationSimpleError } from '../SimpleError';
|
2
1
|
import { type ValidationResult } from '../../types';
|
2
|
+
import { type ValidationErrorData, ValidationSimpleError } from '../SimpleError';
|
3
3
|
/**
|
4
4
|
* Map, которое содержит результат валидации свойств
|
5
5
|
*/
|
@@ -2,15 +2,15 @@ import { type ErrorCode } from '../types';
|
|
2
2
|
/**
|
3
3
|
* Причина ошибки валидации
|
4
4
|
*/
|
5
|
-
export type ValidationErrorData<
|
6
|
-
cause:
|
5
|
+
export type ValidationErrorData<TAddCause extends Record<string, unknown>> = {
|
6
|
+
cause: TAddCause & {
|
7
7
|
code: ErrorCode;
|
8
8
|
};
|
9
9
|
};
|
10
10
|
/**
|
11
11
|
* Простая ошибка правил валидации. Не имеет вложенных ошибок
|
12
12
|
*/
|
13
|
-
export declare class ValidationSimpleError<
|
14
|
-
cause: ValidationErrorData<
|
15
|
-
constructor(message: string, data: ValidationErrorData<
|
13
|
+
export declare class ValidationSimpleError<TAddCause extends Record<string, unknown> = {}> extends Error {
|
14
|
+
cause: ValidationErrorData<TAddCause>['cause'];
|
15
|
+
constructor(message: string, data: ValidationErrorData<TAddCause>);
|
16
16
|
}
|
package/core/errors/index.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from './SimpleError';
|
2
1
|
export * from './ArrayError';
|
2
|
+
export * from './constants';
|
3
|
+
export * from './createErrorCode';
|
3
4
|
export * from './ErrorMap';
|
5
|
+
export * from './SimpleError';
|
4
6
|
export * from './types';
|
5
|
-
export * from './createErrorCode';
|
6
|
-
export * from './constants';
|
package/core/errors/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
export * from './SimpleError';
|
2
1
|
export * from './ArrayError';
|
2
|
+
export * from './constants';
|
3
|
+
export * from './createErrorCode';
|
3
4
|
export * from './ErrorMap';
|
5
|
+
export * from './SimpleError';
|
4
6
|
export * from './types';
|
5
|
-
export * from './createErrorCode';
|
6
|
-
export * from './constants';
|
package/core/errors/types.d.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
import { type ValidationArrayError } from './ArrayError';
|
1
2
|
import { type ValidationErrorMap } from './ErrorMap';
|
2
3
|
import { type ValidationSimpleError } from './SimpleError';
|
3
|
-
import { type ValidationArrayError } from './ArrayError';
|
4
4
|
/**
|
5
5
|
* Уникальный код ошибки валидации
|
6
6
|
*/
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type ValidationResult } from '../../types';
|
2
1
|
import { type ValidationContext } from '../../context';
|
3
|
-
|
2
|
+
import { type ValidationResult } from '../../types';
|
3
|
+
export type GuardDefOptions<TAddDefOptions extends Record<string, unknown>> = Partial<TAddDefOptions> & {
|
4
4
|
/**
|
5
5
|
* Переопределяет дефолтное сообщения ошибки для required
|
6
6
|
* @example string.define({ requiredMessage: 'ИНН не может быть пустым' })(inn())
|
@@ -21,35 +21,35 @@ export type GuardValue = unknown;
|
|
21
21
|
/**
|
22
22
|
* Интерфейс функции guard, которая в прототипе содержит метод define
|
23
23
|
*/
|
24
|
-
export interface
|
24
|
+
export interface IGuard<TLastSchemaValues extends Record<string, unknown> = {}, TAddDefOptions extends Record<string, unknown> = {}> {
|
25
25
|
(value: GuardValue, ctx?: ValidationContext<TLastSchemaValues>): ValidationResult;
|
26
26
|
/**
|
27
27
|
* Функция для создания нового guard с переопределенными дефолтными параметрами. Возвращает новый guard
|
28
28
|
* @param options - параметры, позволяющие переопределить дефолтные настройки guard
|
29
29
|
* @example string(inn()).define({ requiredMessage: 'ИНН не может быть пустым' })
|
30
30
|
*/
|
31
|
-
define<TDefineLastSchemaValues extends Record<string, unknown> = {}>(options: GuardDefOptions<
|
31
|
+
define<TDefineLastSchemaValues extends Record<string, unknown> = {}>(options: GuardDefOptions<TAddDefOptions>): IGuard<TDefineLastSchemaValues, TAddDefOptions>;
|
32
32
|
}
|
33
33
|
/**
|
34
34
|
* Интерфейс асинхронной функции guard, которая в прототипе содержит метод define
|
35
35
|
*/
|
36
|
-
export interface
|
36
|
+
export interface IAsyncGuard<TLastSchemaValues extends Record<string, unknown> = {}, TAddDefOptions extends Record<string, unknown> = {}> {
|
37
37
|
(value: GuardValue, ctx?: ValidationContext<TLastSchemaValues>): Promise<ValidationResult>;
|
38
38
|
/**
|
39
39
|
* Функция для создания нового guard с переопределенными дефолтными параметрами. Возвращает новый guard
|
40
40
|
* @param options - параметры, позволяющие переопределить дефолтные настройки guard
|
41
41
|
* @example string.define({ requiredMessage: 'ИНН не может быть пустым' })(inn())
|
42
42
|
*/
|
43
|
-
define(options: GuardDefOptions<
|
43
|
+
define(options: GuardDefOptions<TAddDefOptions>): IAsyncGuard<TLastSchemaValues, TAddDefOptions>;
|
44
44
|
}
|
45
45
|
/**
|
46
46
|
* Функция, которая позволяет определять частную логику для guard
|
47
47
|
*/
|
48
|
-
type GuardExecutor<TLastSchemaValues extends Record<string, unknown>,
|
48
|
+
type GuardExecutor<TLastSchemaValues extends Record<string, unknown>, TAddDefOptions extends Record<string, unknown>> = (value: unknown, ctx: ValidationContext<TLastSchemaValues>, defOptions: GuardDefOptions<TAddDefOptions>) => ValidationResult;
|
49
49
|
/**
|
50
50
|
* Функция, которая позволяет определять частную логику для guard
|
51
51
|
*/
|
52
|
-
type AsyncGuardExecutor<TLastSchemaValues extends Record<string, unknown>,
|
52
|
+
type AsyncGuardExecutor<TLastSchemaValues extends Record<string, unknown>, TAddDefOptions extends Record<string, unknown>> = (value: unknown, ctx: ValidationContext<TLastSchemaValues>, defOptions: GuardDefOptions<TAddDefOptions>) => Promise<ValidationResult>;
|
53
53
|
/**
|
54
54
|
* Создает guard. Guard - функция, проверяющая тип значения
|
55
55
|
* По-дефолту проверяет value на required. Для выключения required необходимо использовать optional().
|
@@ -66,6 +66,6 @@ type AsyncGuardExecutor<TLastSchemaValues extends Record<string, unknown>, AddDe
|
|
66
66
|
* });
|
67
67
|
* ```
|
68
68
|
*/
|
69
|
-
export declare function createGuard<TLastSchemaValues extends Record<string, unknown>,
|
70
|
-
export declare function createGuard<TLastSchemaValues extends Record<string, unknown>,
|
69
|
+
export declare function createGuard<TLastSchemaValues extends Record<string, unknown>, TAddDefOptions extends Record<string, unknown> = {}>(executor: GuardExecutor<TLastSchemaValues, TAddDefOptions>): IGuard<TLastSchemaValues, TAddDefOptions>;
|
70
|
+
export declare function createGuard<TLastSchemaValues extends Record<string, unknown>, TAddDefOptions extends Record<string, unknown> = {}>(executor: AsyncGuardExecutor<TLastSchemaValues, TAddDefOptions>): IAsyncGuard<TLastSchemaValues, TAddDefOptions>;
|
71
71
|
export {};
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import { required } from '../../rule';
|
2
1
|
import { createContext } from '../../context';
|
2
|
+
import { required } from '../../rule';
|
3
3
|
export function createGuard(executor) {
|
4
4
|
// выделено в отдельную именованную функцию для того, чтобы ее можно было рекурсивно вызывать в define
|
5
5
|
const createInnerGuard = (defOptions = {}) => {
|
package/core/index.d.ts
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './
|
1
|
+
export * from './compose';
|
2
|
+
export * from './composeAsync';
|
3
3
|
export * from './context';
|
4
4
|
export * from './errors';
|
5
|
+
export * from './errors';
|
5
6
|
export * from './guard';
|
6
7
|
export * from './rule';
|
7
|
-
export * from './
|
8
|
-
export * from './composeAsync';
|
8
|
+
export * from './types';
|
9
9
|
export * from './utils';
|
package/core/index.js
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
export * from './
|
2
|
-
export * from './
|
1
|
+
export * from './compose';
|
2
|
+
export * from './composeAsync';
|
3
3
|
export * from './context';
|
4
4
|
export * from './errors';
|
5
|
+
export * from './errors';
|
5
6
|
export * from './guard';
|
6
7
|
export * from './rule';
|
7
|
-
export * from './
|
8
|
-
export * from './composeAsync';
|
8
|
+
export * from './types';
|
9
9
|
export * from './utils';
|
package/core/logger/logger.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type AsyncValidationRule, type ValidationRule } from '../types';
|
2
|
-
import { type ValidationResult } from '../../types';
|
3
1
|
import { type ValidationContext } from '../../context';
|
2
|
+
import { type ValidationResult } from '../../types';
|
3
|
+
import { type AsyncValidationRule, type ValidationRule } from '../types';
|
4
4
|
/**
|
5
5
|
* Позволяет рекурсивно вызывать асинхронные правила. Rule может возвращать другой rule
|
6
6
|
* Если один из rule выбросит exception, то функция его обработает и вернет дефолтную ошибку
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { type ValidationRule } from '../types';
|
2
|
-
import { type ValidationResult } from '../../types';
|
3
1
|
import { type ValidationContext } from '../../context';
|
2
|
+
import { type ValidationResult } from '../../types';
|
3
|
+
import { type ValidationRule } from '../types';
|
4
4
|
/**
|
5
5
|
* Позволяет рекурсивно вызывать правила. Rule может возвращать другой rule
|
6
6
|
*/
|
@@ -1,19 +1,19 @@
|
|
1
|
-
import { type ValidationResult, type ValidationTypes } from '../../types';
|
2
1
|
import { type ValidationContext } from '../../context';
|
2
|
+
import { type ValidationResult, type ValidationTypes } from '../../types';
|
3
3
|
import { type IndependentValidationRule } from '../types';
|
4
4
|
/**
|
5
5
|
* Единые параметры для всех правил
|
6
6
|
*/
|
7
|
-
export type CommonRuleParams<
|
7
|
+
export type CommonRuleParams<TValidationType extends ValidationTypes> = {
|
8
8
|
/**
|
9
9
|
* Функция, позволяющая для каждого правила указать исключение
|
10
10
|
*/
|
11
|
-
exclude?: (value:
|
11
|
+
exclude?: (value: TValidationType, ctx: ValidationContext) => boolean;
|
12
12
|
};
|
13
13
|
/**
|
14
14
|
* Функция, которая позволяет определять частную логику для guard
|
15
15
|
*/
|
16
|
-
type RuleExecutor<
|
16
|
+
type RuleExecutor<TValidationType extends ValidationTypes, TLastSchemaValues extends Record<string, unknown>> = (value: TValidationType, ctx: ValidationContext<TLastSchemaValues>) => ValidationResult;
|
17
17
|
/**
|
18
18
|
* Создает правила валидации, которые можно использовать внутри guard или по отдельности
|
19
19
|
* @param executor - функция, которая позволяет определять частную логику для guard
|
@@ -30,5 +30,5 @@ type RuleExecutor<ValidationType extends ValidationTypes, TLastSchemaValues exte
|
|
30
30
|
* }, params);
|
31
31
|
* ```
|
32
32
|
*/
|
33
|
-
export declare const createRule: <
|
33
|
+
export declare const createRule: <TValidationType extends ValidationTypes, TLastSchemaValues extends Record<string, unknown> = {}>(executor: RuleExecutor<TValidationType, TLastSchemaValues>, commonParams?: CommonRuleParams<TValidationType>) => (value: Parameters<IndependentValidationRule<TValidationType, TLastSchemaValues>>[0], prevCtx?: Parameters<IndependentValidationRule<TValidationType, TLastSchemaValues>>[1]) => ReturnType<IndependentValidationRule<TValidationType, TLastSchemaValues>>;
|
34
34
|
export {};
|
package/core/rule/index.d.ts
CHANGED
package/core/rule/index.js
CHANGED
@@ -4,7 +4,9 @@ import { REQUIRED_ERROR_INFO } from './constants';
|
|
4
4
|
* Проверяет value на пустоту. Если значение пустое, то возвращает ошибку.
|
5
5
|
* Правило универсально для всех типов данных
|
6
6
|
*/
|
7
|
-
export const required = ({ message, } = {}) =>
|
7
|
+
export const required = ({ message, } = {}) =>
|
8
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
9
|
+
createRule((value, ctx) => {
|
8
10
|
const createRequiredError = () => ctx.createError(Object.assign(Object.assign({}, REQUIRED_ERROR_INFO), { message: message || REQUIRED_ERROR_INFO.message }));
|
9
11
|
if (value === null) {
|
10
12
|
return createRequiredError();
|
package/core/types.d.ts
CHANGED
@@ -6,4 +6,4 @@ export type ValidationResult = ValidationError | undefined;
|
|
6
6
|
/**
|
7
7
|
* Доступные для валидации типы value
|
8
8
|
*/
|
9
|
-
export type ValidationTypes = unknown | object | string | number | Date |
|
9
|
+
export type ValidationTypes = unknown | object | string | number | Date | unknown[];
|
package/core/utils/index.d.ts
CHANGED
package/core/utils/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
/**
|
2
2
|
* Проверяет, что текст не может содержать последовательно два спецсимвола/пробела
|
3
3
|
*/
|
4
|
-
export const isHasConsecutiveChars = (value) => /([`~!@#$%^&*()\-_=+[{\]}
|
4
|
+
export const isHasConsecutiveChars = (value) => /([`~!@#$%^&*()\-_=+[{\]}|;:'",<.>/?\s])([`~!@#$%^&*()\-_=+[{\]}|;:'",<.>/?\s])/.test(value);
|
package/date/date.d.ts
CHANGED
@@ -15,5 +15,5 @@ type AdditionalDefOptions = {
|
|
15
15
|
* validate(new Date('22.22.2022'));
|
16
16
|
* ```
|
17
17
|
*/
|
18
|
-
export declare const date: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<Date, TLastSchemaValues>[]) => import("../core").
|
18
|
+
export declare const date: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<Date, TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, AdditionalDefOptions>;
|
19
19
|
export {};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { type
|
1
|
+
import { type IGuard } from '../core';
|
2
2
|
/**
|
3
3
|
* Делает partial все object в схеме, независимо от уровня вложенности правил
|
4
4
|
* @param guard - любой guard
|
@@ -18,4 +18,4 @@ import { type Guard } from '../core';
|
|
18
18
|
* const result = validate({ info: { info: {} } });
|
19
19
|
* ```
|
20
20
|
*/
|
21
|
-
export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard:
|
21
|
+
export declare const deepPartial: <TLastSchemaValues extends Record<string, unknown>>(guard: IGuard<TLastSchemaValues>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TLastSchemaValues> | undefined) => ReturnType<import("../core").IndependentValidationRule<unknown, TLastSchemaValues>>;
|
package/email/email.js
CHANGED
@@ -10,7 +10,9 @@ import { ALLOWED_HOSTNAME_START_SYMBOL_REGEXP, ALLOWED_USERNAME_START_SYMBOL_REG
|
|
10
10
|
* validate('example@mail.ru');
|
11
11
|
* ```
|
12
12
|
*/
|
13
|
-
export const email = (params) =>
|
13
|
+
export const email = (params) =>
|
14
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
15
|
+
createRule((value, ctx) => {
|
14
16
|
const invalidEmailError = ctx.createError(Object.assign(Object.assign({}, INVALID_EMAIL_ERROR_INFO), { message: (params === null || params === void 0 ? void 0 : params.message) || INVALID_EMAIL_ERROR_INFO.message }));
|
15
17
|
const emailRegexp = (params === null || params === void 0 ? void 0 : params.allowCyrillic)
|
16
18
|
? EMAIL_CYRILLIC_PUNYCODE_REGEXP
|
@@ -14,11 +14,10 @@ import { EMAIL_OR_PHONE_ERROR_INFO, EMAIL_OR_PHONE_REQUIRED_ERROR_INFO, } from '
|
|
14
14
|
* ```
|
15
15
|
*/
|
16
16
|
// Отдельная функциональная обертка необходима для работы с guard optional
|
17
|
-
export const emailOrPhone = () => (value, ctx) =>
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
!Boolean(value.value);
|
17
|
+
export const emailOrPhone = () => (value, ctx) =>
|
18
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
19
|
+
createGuard((_, innerCtx) => {
|
20
|
+
const requiredValue = value && typeof value === 'object' && 'value' in value && !value.value;
|
22
21
|
const checkValidObject = !value ||
|
23
22
|
typeof value !== 'object' ||
|
24
23
|
!('value' in value) ||
|
package/index.d.ts
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
export {
|
2
|
-
export {
|
3
|
-
export { string, STRING_TYPE_ERROR_INFO, stringAsync } from './string';
|
4
|
-
export { textField, INVALID_TEXT_FIELD_ERROR_INFO, LENGTH_TEXT_FIELD_ERROR_INFO, } from './textField';
|
5
|
-
export { date, INVALID_DATE_ERROR_INFO, DATE_TYPE_ERROR_INFO } from './date';
|
6
|
-
export { number, NAN_NUMBER_ERROR_INFO, NUMBER_TYPE_ERROR_INFO, INFINITY_NUMBER_ERROR_INFO, } from './number';
|
7
|
-
export { boolean, BOOLEAN_TYPE_ERROR_INFO } from './boolean';
|
8
|
-
export { array, ARRAY_TYPE_ERROR_INFO } from './array';
|
1
|
+
export { any } from './any';
|
2
|
+
export { ARRAY_TYPE_ERROR_INFO, array } from './array';
|
9
3
|
export { arrayItem } from './arrayItem';
|
4
|
+
export { BOOLEAN_TYPE_ERROR_INFO, boolean } from './boolean';
|
5
|
+
export { CONTAINS_DIFFERENT_CASES_ERROR_CODE, containsDifferentCases, } from './containsDifferentCases';
|
6
|
+
export { CONTAINS_NUMBERS_ERROR_CODE, containsNumbers, } from './containsNumbers';
|
7
|
+
export { CONTAINS_PUNCTUATION_MARKS_ERROR_CODE, containsPunctuationMarks, } from './containsPunctuationMarks';
|
8
|
+
export { createRule, REQUIRED_ERROR_INFO, type ValidationRule } from './core';
|
9
|
+
export { DATE_TYPE_ERROR_INFO, date, INVALID_DATE_ERROR_INFO } from './date';
|
10
10
|
export { deepPartial } from './deepPartial';
|
11
|
-
export {
|
12
|
-
export {
|
13
|
-
export {
|
14
|
-
export { max, STRING_MAX_ERROR_CODE, ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, NUMBER_MAX_ERROR_CODE, } from './max';
|
15
|
-
export { integer, INTEGER_ERROR_INFO } from './integer';
|
16
|
-
export { positiveNumber, POSITIVE_NUMBER_ERROR_INFO } from './positiveNumber';
|
17
|
-
export { or } from './or';
|
18
|
-
export { pattern, PATTERN_ERROR_CODE } from './pattern';
|
19
|
-
export { onlyNumber, ONLY_NUMBER_ERROR_CODE } from './onlyNumber';
|
20
|
-
export { containsNumbers, CONTAINS_NUMBERS_ERROR_CODE, } from './containsNumbers';
|
21
|
-
export { containsPunctuationMarks, CONTAINS_PUNCTUATION_MARKS_ERROR_CODE, } from './containsPunctuationMarks';
|
22
|
-
export { containsDifferentCases, CONTAINS_DIFFERENT_CASES_ERROR_CODE, } from './containsDifferentCases';
|
23
|
-
export { toPlainError } from './toPlainError';
|
24
|
-
export { email, LENGTH_EMAIL_ERROR_INFO, INVALID_EMAIL_ERROR_INFO, } from './email';
|
25
|
-
export { emailOrPhone, EMAIL_OR_PHONE_ERROR_INFO } from './emailOrPhone';
|
11
|
+
export { email, INVALID_EMAIL_ERROR_INFO, LENGTH_EMAIL_ERROR_INFO, } from './email';
|
12
|
+
export { EMAIL_OR_PHONE_ERROR_INFO, emailOrPhone } from './emailOrPhone';
|
13
|
+
export { enabled } from './enabled';
|
26
14
|
export { guid, INVALID_GUID_ERROR_INFO } from './guid';
|
15
|
+
export { INN_FL_ERROR_INFO, innFL } from './innFL';
|
16
|
+
export { INN_IP_ERROR_INFO, innIP } from './innIP';
|
17
|
+
export { INN_12_SYMBOLS_ERROR_INFO, innTwelveSymbols, } from './innTwelveSymbols';
|
18
|
+
export { INN_UL_ERROR_INFO, innUL } from './innUL';
|
19
|
+
export { INTEGER_ERROR_INFO, integer } from './integer';
|
20
|
+
export { INVALID_KPP_ERROR_INFO, KPP_DOUBLE_ZERO_START_ERROR_INFO, KPP_ZEROS_ONLY_ERROR_INFO, kpp, } from './kpp';
|
27
21
|
export { length, STRING_LENGTH_ERROR_CODE } from './length';
|
28
|
-
export {
|
29
|
-
export {
|
30
|
-
export {
|
31
|
-
export {
|
32
|
-
export {
|
33
|
-
export {
|
34
|
-
export {
|
35
|
-
export {
|
36
|
-
export {
|
37
|
-
export {
|
38
|
-
export {
|
39
|
-
export {
|
40
|
-
export {
|
41
|
-
export {
|
42
|
-
export {
|
43
|
-
export {
|
44
|
-
export {
|
45
|
-
export {
|
22
|
+
export { ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, max, NUMBER_MAX_ERROR_CODE, STRING_MAX_ERROR_CODE, } from './max';
|
23
|
+
export { ARRAY_MIN_ERROR_CODE, DATE_MIN_ERROR_CODE, min, NUMBER_MIN_ERROR_CODE, STRING_MIN_ERROR_CODE, } from './min';
|
24
|
+
export { BIRTH_DATE_MAX_ERROR_CODE, BIRTH_DATE_MIN_ERROR_CODE, minYearsOld, } from './minYearsOld';
|
25
|
+
export { MOBILE_PHONE_ERROR_INFO, mobilePhone } from './mobilePhone';
|
26
|
+
export { INFINITY_NUMBER_ERROR_INFO, NAN_NUMBER_ERROR_INFO, NUMBER_TYPE_ERROR_INFO, number, } from './number';
|
27
|
+
export { OBJECT_TYPE_ERROR_INFO, type ObjectAsyncGuard, type ObjectGuard, object, objectAsync, type Schema, type SchemaValue, } from './object';
|
28
|
+
export { OGRN_IP_ERROR_INFO, ogrnIP } from './ogrnIP';
|
29
|
+
export { OGRN_UL_ERROR_INFO, ogrnUL } from './ogrnUL';
|
30
|
+
export { ONLY_NUMBER_ERROR_CODE, onlyNumber } from './onlyNumber';
|
31
|
+
export { optional, optionalAsync } from './optional';
|
32
|
+
export { or } from './or';
|
33
|
+
export { partial } from './partial';
|
34
|
+
export { PASSPORT_CODE_ERROR_INFO, PASSPORT_CODE_LENGTH_ERROR_INFO, PASSPORT_CODE_ONLY_DIGITS_ERROR_INFO, passportCode, } from './passportCode';
|
35
|
+
export { PASSPORT_NUMBER_ERROR_INFO, PASSPORT_NUMBER_LENGTH_ERROR_INFO, PASSPORT_NUMBER_ONLY_DIGITS_ERROR_INFO, passportNumber, } from './passportNumber';
|
36
|
+
export { PASSPORT_SERIES_ERROR_INFO, PASSPORT_SERIES_ERROR_LENGTH_INFO, PASSPORT_SERIES_ONLY_DIGITS_ERROR_INFO, passportSeries, } from './passportSeries';
|
37
|
+
export { PATTERN_ERROR_CODE, pattern } from './pattern';
|
38
|
+
export { PERSON_NAME_ERROR_INFO, personName } from './personName';
|
39
|
+
export { PERSON_PATRONYMIC_ERROR_INFO, personPatronymic, } from './personPatronymic';
|
40
|
+
export { PERSON_SURNAME_ERROR_INFO, personSurname } from './personSurname';
|
41
|
+
export { POSITIVE_NUMBER_ERROR_INFO, positiveNumber } from './positiveNumber';
|
42
|
+
export { RANGE_DATE_END_EARLIER_START_ERROR_INFO, RANGE_DATE_END_INVALID_ERROR_INFO, RANGE_DATE_END_REQUIRED_ERROR_INFO, RANGE_DATE_REQUIRED_ERROR_INFO, RANGE_DATE_START_INVALID_ERROR_INFO, RANGE_DATE_START_REQUIRED_ERROR_INFO, rangeDate, } from './rangeDate';
|
43
|
+
export { RANGE_DATE_INTERVAL_ERROR_INFO, rangeDateInterval, } from './rangeDateInterval';
|
44
|
+
export { RANGE_DATE_MAX_ERROR_INFO, RANGE_DATE_MIN_ERROR_INFO, rangeDateMinMax, } from './rangeDateMinMax';
|
45
|
+
export { RANGE_DATE_NOT_EQUAL_ERROR_INFO, rangeDateNotEqual, } from './rangeDateNotEqual';
|
46
|
+
export { SNILS_ERROR_INFO, snils } from './snils';
|
47
|
+
export { STRING_TYPE_ERROR_INFO, string, stringAsync } from './string';
|
48
|
+
export { INVALID_TEXT_FIELD_ERROR_INFO, LENGTH_TEXT_FIELD_ERROR_INFO, textField, } from './textField';
|
49
|
+
export { toPlainError } from './toPlainError';
|
46
50
|
export { toPrettyError } from './toPrettyError';
|
47
51
|
export { transform } from './transform';
|
48
|
-
export {
|
49
|
-
export {
|
50
|
-
export {
|
51
|
-
export { rangeDateMinMax, RANGE_DATE_MAX_ERROR_INFO, RANGE_DATE_MIN_ERROR_INFO, } from './rangeDateMinMax';
|
52
|
-
export { rangeDateNotEqual, RANGE_DATE_NOT_EQUAL_ERROR_INFO, } from './rangeDateNotEqual';
|
53
|
-
export { uploadedFile, FILE_UPLOAD_ERROR_INFO, FILE_LOADING_ERROR_INFO, FILE_REQUIRED_ERROR_INFO, FILE_RESTRICTION_ERROR_INFO, } from './uploadedFile';
|
54
|
-
export { uploadedFileList, FILE_LIST_NOT_ARRAY_ERROR_INFO, } from './uploadedFileList';
|
52
|
+
export { FILE_LOADING_ERROR_INFO, FILE_REQUIRED_ERROR_INFO, FILE_RESTRICTION_ERROR_INFO, FILE_UPLOAD_ERROR_INFO, uploadedFile, } from './uploadedFile';
|
53
|
+
export { FILE_LIST_NOT_ARRAY_ERROR_INFO, uploadedFileList, } from './uploadedFileList';
|
54
|
+
export { when } from './when';
|