@astral/validations 4.24.2 → 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/node/object/index.d.ts
CHANGED
package/node/object/index.js
CHANGED
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./object"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./object"), exports);
|
19
19
|
__exportStar(require("./objectAsync"), exports);
|
package/node/object/object.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { type
|
1
|
+
import { type IGuard, type ValidationContext, type ValidationRule } from '../core';
|
2
2
|
/**
|
3
3
|
* Специальный итерфейс Guard для object. В данном интерфейсе ctx required
|
4
4
|
* Переопределение необходимо для того, чтобы ts показывал, что ctx required в кастомных правилах
|
5
5
|
*/
|
6
|
-
interface
|
7
|
-
(value: Parameters<
|
8
|
-
define:
|
6
|
+
interface IObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
7
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IGuard<TLastSchemaValues>>;
|
8
|
+
define: IGuard<TLastSchemaValues>['define'];
|
9
9
|
}
|
10
10
|
type AdditionalDefOptions = {
|
11
11
|
/**
|
@@ -16,7 +16,7 @@ type AdditionalDefOptions = {
|
|
16
16
|
/**
|
17
17
|
* Возможные значения, принимаемые схемой
|
18
18
|
*/
|
19
|
-
export type SchemaValue<TValue extends Record<string, unknown>> =
|
19
|
+
export type SchemaValue<TValue extends Record<string, unknown>> = IObjectPropGuard<TValue> | ValidationRule<unknown, TValue>;
|
20
20
|
/**
|
21
21
|
* Схема правил валдиации для объекта
|
22
22
|
*/
|
@@ -44,6 +44,6 @@ export type Schema<TValue extends Record<string, unknown>> = Record<keyof TValue
|
|
44
44
|
* });
|
45
45
|
* ```
|
46
46
|
*/
|
47
|
-
export declare const object: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: Schema<TValue>) =>
|
47
|
+
export declare const object: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: Schema<TValue>) => IGuard<TLastSchemaValues, AdditionalDefOptions>;
|
48
48
|
export type ObjectGuard<TValue extends Record<string, unknown>> = ReturnType<typeof object<TValue>>;
|
49
49
|
export {};
|
package/node/object/object.js
CHANGED
@@ -4,8 +4,8 @@ exports.object = void 0;
|
|
4
4
|
const utils_1 = require("@astral/utils");
|
5
5
|
const core_1 = require("../core");
|
6
6
|
const optional_1 = require("../optional");
|
7
|
-
const isEmptyErrors_1 = require("./isEmptyErrors");
|
8
7
|
const constants_1 = require("./constants");
|
8
|
+
const isEmptyErrors_1 = require("./isEmptyErrors");
|
9
9
|
/**
|
10
10
|
* Guard для объекта
|
11
11
|
* @param schema - схема валидации объекта
|
@@ -39,10 +39,12 @@ const object = (schema) => (0, core_1.createGuard)((value, ctx, { typeErrorMessa
|
|
39
39
|
const generateErrorMap = () => {
|
40
40
|
const schemaEntries = Object.entries(schema);
|
41
41
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
42
|
-
return schemaEntries.reduce((
|
42
|
+
return schemaEntries.reduce((errorMapResult, [key, rule]) => {
|
43
43
|
const callRule = isOptional ? (0, optional_1.optional)(rule) : rule;
|
44
|
-
|
45
|
-
|
44
|
+
errorMapResult[key] = (0, core_1.callRule)(callRule,
|
45
|
+
// biome-ignore lint/nursery/noShadow: <>
|
46
|
+
value[key], context);
|
47
|
+
return errorMapResult;
|
46
48
|
}, {});
|
47
49
|
};
|
48
50
|
const errorMap = generateErrorMap();
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import { type
|
1
|
+
import { type AsyncValidationRule, type IAsyncGuard, type IGuard, type ValidationContext, type ValidationRule } from '../../core';
|
2
2
|
/**
|
3
3
|
* Специальный итерфейс Guard для object. В данном интерфейсе ctx required
|
4
4
|
* Переопределение необходимо для того, чтобы ts показывал, что ctx required в кастомных правилах
|
5
5
|
*/
|
6
|
-
interface
|
7
|
-
(value: Parameters<
|
8
|
-
define:
|
6
|
+
interface IObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
7
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IGuard<TLastSchemaValues>>;
|
8
|
+
define: IGuard<TLastSchemaValues>['define'];
|
9
9
|
}
|
10
|
-
interface
|
11
|
-
(value: Parameters<
|
12
|
-
define:
|
10
|
+
interface IAsyncObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
11
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IAsyncGuard<TLastSchemaValues>>;
|
12
|
+
define: IAsyncGuard<TLastSchemaValues>['define'];
|
13
13
|
}
|
14
14
|
type AdditionalDefOptions = {
|
15
15
|
/**
|
@@ -20,7 +20,7 @@ type AdditionalDefOptions = {
|
|
20
20
|
/**
|
21
21
|
* Возможные значения, принимаемые схемой
|
22
22
|
*/
|
23
|
-
export type AsyncSchemaValue<TValue extends Record<string, unknown>> =
|
23
|
+
export type AsyncSchemaValue<TValue extends Record<string, unknown>> = IObjectPropGuard<TValue> | IAsyncObjectPropGuard<TValue> | ValidationRule<unknown, TValue> | AsyncValidationRule<unknown, TValue>;
|
24
24
|
/**
|
25
25
|
* Схема правил валдиации для объекта
|
26
26
|
*/
|
@@ -56,6 +56,6 @@ export type AsyncSchema<TValue extends Record<string, unknown>> = Record<keyof T
|
|
56
56
|
* });
|
57
57
|
* ```
|
58
58
|
*/
|
59
|
-
export declare const objectAsync: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: AsyncSchema<TValue>) =>
|
59
|
+
export declare const objectAsync: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: AsyncSchema<TValue>) => IAsyncGuard<TLastSchemaValues, AdditionalDefOptions>;
|
60
60
|
export type ObjectAsyncGuard<TValue extends Record<string, unknown>> = ReturnType<typeof objectAsync<TValue>>;
|
61
61
|
export {};
|
@@ -13,8 +13,8 @@ exports.objectAsync = void 0;
|
|
13
13
|
const utils_1 = require("@astral/utils");
|
14
14
|
const core_1 = require("../../core");
|
15
15
|
const optional_1 = require("../../optional");
|
16
|
-
const isEmptyErrors_1 = require("../isEmptyErrors");
|
17
16
|
const constants_1 = require("../constants");
|
17
|
+
const isEmptyErrors_1 = require("../isEmptyErrors");
|
18
18
|
// TODO: необходимо реализовать переиспользование логики между object и objectAsync
|
19
19
|
/**
|
20
20
|
* Guard для объекта, который поддерживает асинхронную валидацию
|
@@ -59,12 +59,14 @@ const objectAsync = (schema) => (0, core_1.createGuard)((value_1, ctx_1, _a) =>
|
|
59
59
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
60
60
|
const results = yield Promise.all(schemaEntries.map(([key, rule]) => {
|
61
61
|
const callRule = isOptional ? (0, optional_1.optionalAsync)(rule) : rule;
|
62
|
-
return (0, core_1.callAsyncRule)(callRule,
|
62
|
+
return (0, core_1.callAsyncRule)(callRule,
|
63
|
+
// biome-ignore lint/nursery/noShadow: <>
|
64
|
+
value[key], context);
|
63
65
|
}));
|
64
|
-
return results.reduce((
|
66
|
+
return results.reduce((errorMapResult, validationResult, index) => {
|
65
67
|
const [key] = schemaEntries[index];
|
66
|
-
|
67
|
-
return
|
68
|
+
errorMapResult[key] = validationResult;
|
69
|
+
return errorMapResult;
|
68
70
|
}, {});
|
69
71
|
});
|
70
72
|
const errorMap = yield generateErrorMap();
|
package/node/ogrnIP/index.d.ts
CHANGED
package/node/ogrnIP/index.js
CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./ogrnIP"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./ogrnIP"), exports);
|
package/node/ogrnUL/index.d.ts
CHANGED
package/node/ogrnUL/index.js
CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./ogrnUL"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./ogrnUL"), exports);
|
package/node/or/or.js
CHANGED
@@ -4,6 +4,6 @@ import { type object } from '../object';
|
|
4
4
|
* @param objectGuard
|
5
5
|
* @example partial(object({ name: string() }))
|
6
6
|
*/
|
7
|
-
export declare const partial: (objectGuard: ReturnType<typeof object>) => import("../core").
|
7
|
+
export declare const partial: (objectGuard: ReturnType<typeof object>) => import("../core").IGuard<{}, {
|
8
8
|
isPartial?: boolean;
|
9
9
|
}>;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.passportNumber = void 0;
|
4
|
-
const onlyNumber_1 = require("../onlyNumber");
|
5
4
|
const core_1 = require("../core");
|
5
|
+
const onlyNumber_1 = require("../onlyNumber");
|
6
6
|
const constants_1 = require("./constants");
|
7
7
|
/**
|
8
8
|
* Проверяет валиден ли номер паспорта
|
package/node/pattern/index.d.ts
CHANGED
package/node/pattern/index.js
CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./pattern"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./pattern"), exports);
|
@@ -46,5 +46,5 @@ type RangeDateParams = {
|
|
46
46
|
* validate({ start: new Date(), end: new Date() });
|
47
47
|
* ```
|
48
48
|
*/
|
49
|
-
export declare const rangeDate: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<RangeDateValue, TLastSchemaValues>[]) => import("../core").
|
49
|
+
export declare const rangeDate: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<RangeDateValue, TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, RangeDateParams>;
|
50
50
|
export {};
|
@@ -13,12 +13,18 @@ const constants_1 = require("./constants");
|
|
13
13
|
* validate({ start: new Date(), end: new Date() });
|
14
14
|
* ```
|
15
15
|
*/
|
16
|
-
const rangeDate = (...rules) => (0, core_1.createGuard)(
|
16
|
+
const rangeDate = (...rules) => (0, core_1.createGuard)(
|
17
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
18
|
+
(externalValue, ctx, params) => {
|
17
19
|
const { required, messages } = Object.assign(Object.assign({}, (params || {})), { required: {
|
18
|
-
start:
|
20
|
+
start:
|
21
|
+
// biome-ignore lint/correctness/noUnsafeOptionalChaining: <>
|
22
|
+
(params === null || params === void 0 ? void 0 : params.required) && 'start' in (params === null || params === void 0 ? void 0 : params.required)
|
19
23
|
? params === null || params === void 0 ? void 0 : params.required.start
|
20
24
|
: true,
|
21
|
-
end:
|
25
|
+
end:
|
26
|
+
// biome-ignore lint/correctness/noUnsafeOptionalChaining: <>
|
27
|
+
(params === null || params === void 0 ? void 0 : params.required) && 'end' in (params === null || params === void 0 ? void 0 : params.required)
|
22
28
|
? params === null || params === void 0 ? void 0 : params.required.end
|
23
29
|
: true,
|
24
30
|
} });
|
@@ -16,7 +16,9 @@ const formatDateToView = (date) => {
|
|
16
16
|
* validate({ start: new Date(), end: new Date() });
|
17
17
|
* ```
|
18
18
|
*/
|
19
|
-
const rangeDateMinMax = (params) =>
|
19
|
+
const rangeDateMinMax = (params) =>
|
20
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
21
|
+
(0, core_1.createRule)((value, ctx) => {
|
20
22
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
|
21
23
|
if (!value.start && !value.end) {
|
22
24
|
return undefined;
|
package/node/snils/index.d.ts
CHANGED
package/node/snils/index.js
CHANGED
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./snils"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./snils"), exports);
|
package/node/snils/snils.js
CHANGED
@@ -21,7 +21,9 @@ const compareCheckSum = (calculatedCheckSum, checkSum) => {
|
|
21
21
|
* validate('15657325992');
|
22
22
|
* ```
|
23
23
|
*/
|
24
|
-
const snils = (params) => (0, core_1.createRule)(
|
24
|
+
const snils = (params) => (0, core_1.createRule)(
|
25
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <>
|
26
|
+
(value, ctx) => {
|
25
27
|
const createSnilsError = () => ctx.createError({
|
26
28
|
message: (params === null || params === void 0 ? void 0 : params.message) || constants_1.SNILS_ERROR_INFO.message,
|
27
29
|
code: constants_1.SNILS_ERROR_INFO.code,
|
package/node/string/index.d.ts
CHANGED
package/node/string/index.js
CHANGED
@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./constants"), exports);
|
17
18
|
__exportStar(require("./string"), exports);
|
18
19
|
__exportStar(require("./stringAsync"), exports);
|
19
|
-
__exportStar(require("./constants"), exports);
|
package/node/string/string.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { type ValidationRule } from '../core';
|
2
|
-
export declare const string: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<string, TLastSchemaValues>[]) => import("../core").
|
2
|
+
export declare const string: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<string, TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, {}>;
|
@@ -3,4 +3,4 @@ import { type AsyncValidationRule, type ValidationRule } from '../../core';
|
|
3
3
|
* Позволяет использовать для валидации асинхронные правила
|
4
4
|
* @example stringAsync(async () => undefined)
|
5
5
|
*/
|
6
|
-
export declare const stringAsync: <TLastSchemaValues extends Record<string, unknown>>(...rules: Array<ValidationRule<string, TLastSchemaValues> | AsyncValidationRule<string, TLastSchemaValues>>) => import("../../core").
|
6
|
+
export declare const stringAsync: <TLastSchemaValues extends Record<string, unknown>>(...rules: Array<ValidationRule<string, TLastSchemaValues> | AsyncValidationRule<string, TLastSchemaValues>>) => import("../../core").IAsyncGuard<TLastSchemaValues, {}>;
|
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.stringAsync = void 0;
|
13
13
|
const core_1 = require("../../core");
|
14
|
-
const utils_1 = require("../utils");
|
15
14
|
const constants_1 = require("../constants");
|
15
|
+
const utils_1 = require("../utils");
|
16
16
|
// TODO: необходимо реализовать переиспользование логики между string и stringAsync
|
17
17
|
/**
|
18
18
|
* Позволяет использовать для валидации асинхронные правила
|
@@ -3,12 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.toPlainError = void 0;
|
4
4
|
const core_1 = require("../core");
|
5
5
|
const utils_1 = require("./utils");
|
6
|
-
const toPlainArrayResult = (error, formatErrorInfo, path) => error.cause.errorArray.map((errorItem, index) =>
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
8
|
-
(0, exports.toPlainError)(errorItem, formatErrorInfo, (0, utils_1.generateArrayPath)(index, path)));
|
6
|
+
const toPlainArrayResult = (error, formatErrorInfo, path) => error.cause.errorArray.map((errorItem, index) => (0, exports.toPlainError)(errorItem, formatErrorInfo, (0, utils_1.generateArrayPath)(index, path)));
|
9
7
|
function toPlainErrorMap(error, formatErrorInfo, path) {
|
10
8
|
return Object.entries(error.cause.errorMap).reduce((plainErrorMap, [key, currentError]) => {
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
12
9
|
const plainError = (0, exports.toPlainError)(currentError, formatErrorInfo, (0, utils_1.generateObjectPath)(key, path));
|
13
10
|
if (plainError === undefined) {
|
14
11
|
return plainErrorMap;
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./generateObjectPath"), exports);
|
18
17
|
__exportStar(require("./generateArrayPath"), exports);
|
18
|
+
__exportStar(require("./generateObjectPath"), exports);
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./uploadedFile"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./uploadedFile"), exports);
|
@@ -27,4 +27,4 @@ import type { UploadFile } from './types';
|
|
27
27
|
* });
|
28
28
|
* ```
|
29
29
|
*/
|
30
|
-
export declare const uploadedFile: <TLastSchemeValues extends Record<string, unknown>>(...rules: ValidationRule<UploadFile, TLastSchemeValues>[]) => import("../core").
|
30
|
+
export declare const uploadedFile: <TLastSchemeValues extends Record<string, unknown>>(...rules: ValidationRule<UploadFile, TLastSchemeValues>[]) => import("../core").IGuard<TLastSchemeValues, {}>;
|
@@ -14,5 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
15
|
};
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
-
__exportStar(require("./uploadedFileList"), exports);
|
18
17
|
__exportStar(require("./constants"), exports);
|
18
|
+
__exportStar(require("./uploadedFileList"), exports);
|
@@ -21,4 +21,4 @@ import { type UploadFile } from '../uploadedFile/types';
|
|
21
21
|
* ]);
|
22
22
|
* ```
|
23
23
|
*/
|
24
|
-
export declare const uploadedFileList: <TLastSchemeValues extends Record<string, unknown>>(...rules: ValidationRule<UploadFile[], TLastSchemeValues>[]) => import("../core").
|
24
|
+
export declare const uploadedFileList: <TLastSchemeValues extends Record<string, unknown>>(...rules: ValidationRule<UploadFile[], TLastSchemeValues>[]) => import("../core").IGuard<TLastSchemeValues, {}>;
|
@@ -1,8 +1,8 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.uploadedFileList = void 0;
|
4
|
-
const core_1 = require("../core");
|
5
4
|
const array_1 = require("../array");
|
5
|
+
const core_1 = require("../core");
|
6
6
|
const uploadedFile_1 = require("../uploadedFile");
|
7
7
|
const constants_1 = require("./constants");
|
8
8
|
/**
|
package/number/index.d.ts
CHANGED
package/number/index.js
CHANGED
package/number/number.d.ts
CHANGED
@@ -15,5 +15,5 @@ type AdditionalDefOptions = {
|
|
15
15
|
* validate(24);
|
16
16
|
* ```
|
17
17
|
*/
|
18
|
-
export declare const number: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<number, TLastSchemaValues>[]) => import("../core").
|
18
|
+
export declare const number: <TLastSchemaValues extends Record<string, unknown>>(...rules: ValidationRule<number, TLastSchemaValues>[]) => import("../core").IGuard<TLastSchemaValues, AdditionalDefOptions>;
|
19
19
|
export {};
|
package/object/index.d.ts
CHANGED
package/object/index.js
CHANGED
package/object/object.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
import { type
|
1
|
+
import { type IGuard, type ValidationContext, type ValidationRule } from '../core';
|
2
2
|
/**
|
3
3
|
* Специальный итерфейс Guard для object. В данном интерфейсе ctx required
|
4
4
|
* Переопределение необходимо для того, чтобы ts показывал, что ctx required в кастомных правилах
|
5
5
|
*/
|
6
|
-
interface
|
7
|
-
(value: Parameters<
|
8
|
-
define:
|
6
|
+
interface IObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
7
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IGuard<TLastSchemaValues>>;
|
8
|
+
define: IGuard<TLastSchemaValues>['define'];
|
9
9
|
}
|
10
10
|
type AdditionalDefOptions = {
|
11
11
|
/**
|
@@ -16,7 +16,7 @@ type AdditionalDefOptions = {
|
|
16
16
|
/**
|
17
17
|
* Возможные значения, принимаемые схемой
|
18
18
|
*/
|
19
|
-
export type SchemaValue<TValue extends Record<string, unknown>> =
|
19
|
+
export type SchemaValue<TValue extends Record<string, unknown>> = IObjectPropGuard<TValue> | ValidationRule<unknown, TValue>;
|
20
20
|
/**
|
21
21
|
* Схема правил валдиации для объекта
|
22
22
|
*/
|
@@ -44,6 +44,6 @@ export type Schema<TValue extends Record<string, unknown>> = Record<keyof TValue
|
|
44
44
|
* });
|
45
45
|
* ```
|
46
46
|
*/
|
47
|
-
export declare const object: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: Schema<TValue>) =>
|
47
|
+
export declare const object: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: Schema<TValue>) => IGuard<TLastSchemaValues, AdditionalDefOptions>;
|
48
48
|
export type ObjectGuard<TValue extends Record<string, unknown>> = ReturnType<typeof object<TValue>>;
|
49
49
|
export {};
|
package/object/object.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { isPlainObject } from '@astral/utils';
|
2
2
|
import { callRule as callRecursiveRule, createContext, createErrorMap, createGuard, } from '../core';
|
3
3
|
import { optional } from '../optional';
|
4
|
-
import { isEmptyErrors } from './isEmptyErrors';
|
5
4
|
import { OBJECT_TYPE_ERROR_INFO } from './constants';
|
5
|
+
import { isEmptyErrors } from './isEmptyErrors';
|
6
6
|
/**
|
7
7
|
* Guard для объекта
|
8
8
|
* @param schema - схема валидации объекта
|
@@ -36,10 +36,12 @@ export const object = (schema) => createGuard((value, ctx, { typeErrorMessage, i
|
|
36
36
|
const generateErrorMap = () => {
|
37
37
|
const schemaEntries = Object.entries(schema);
|
38
38
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
39
|
-
return schemaEntries.reduce((
|
39
|
+
return schemaEntries.reduce((errorMapResult, [key, rule]) => {
|
40
40
|
const callRule = isOptional ? optional(rule) : rule;
|
41
|
-
|
42
|
-
|
41
|
+
errorMapResult[key] = callRecursiveRule(callRule,
|
42
|
+
// biome-ignore lint/nursery/noShadow: <>
|
43
|
+
value[key], context);
|
44
|
+
return errorMapResult;
|
43
45
|
}, {});
|
44
46
|
};
|
45
47
|
const errorMap = generateErrorMap();
|
@@ -1,15 +1,15 @@
|
|
1
|
-
import { type
|
1
|
+
import { type AsyncValidationRule, type IAsyncGuard, type IGuard, type ValidationContext, type ValidationRule } from '../../core';
|
2
2
|
/**
|
3
3
|
* Специальный итерфейс Guard для object. В данном интерфейсе ctx required
|
4
4
|
* Переопределение необходимо для того, чтобы ts показывал, что ctx required в кастомных правилах
|
5
5
|
*/
|
6
|
-
interface
|
7
|
-
(value: Parameters<
|
8
|
-
define:
|
6
|
+
interface IObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
7
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IGuard<TLastSchemaValues>>;
|
8
|
+
define: IGuard<TLastSchemaValues>['define'];
|
9
9
|
}
|
10
|
-
interface
|
11
|
-
(value: Parameters<
|
12
|
-
define:
|
10
|
+
interface IAsyncObjectPropGuard<TLastSchemaValues extends Record<string, unknown>> {
|
11
|
+
(value: Parameters<IGuard<TLastSchemaValues>>[0], ctx: ValidationContext<TLastSchemaValues>): ReturnType<IAsyncGuard<TLastSchemaValues>>;
|
12
|
+
define: IAsyncGuard<TLastSchemaValues>['define'];
|
13
13
|
}
|
14
14
|
type AdditionalDefOptions = {
|
15
15
|
/**
|
@@ -20,7 +20,7 @@ type AdditionalDefOptions = {
|
|
20
20
|
/**
|
21
21
|
* Возможные значения, принимаемые схемой
|
22
22
|
*/
|
23
|
-
export type AsyncSchemaValue<TValue extends Record<string, unknown>> =
|
23
|
+
export type AsyncSchemaValue<TValue extends Record<string, unknown>> = IObjectPropGuard<TValue> | IAsyncObjectPropGuard<TValue> | ValidationRule<unknown, TValue> | AsyncValidationRule<unknown, TValue>;
|
24
24
|
/**
|
25
25
|
* Схема правил валдиации для объекта
|
26
26
|
*/
|
@@ -56,6 +56,6 @@ export type AsyncSchema<TValue extends Record<string, unknown>> = Record<keyof T
|
|
56
56
|
* });
|
57
57
|
* ```
|
58
58
|
*/
|
59
|
-
export declare const objectAsync: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: AsyncSchema<TValue>) =>
|
59
|
+
export declare const objectAsync: <TValue extends Record<string, unknown>, TLastSchemaValues extends Record<string, unknown> = {}>(schema: AsyncSchema<TValue>) => IAsyncGuard<TLastSchemaValues, AdditionalDefOptions>;
|
60
60
|
export type ObjectAsyncGuard<TValue extends Record<string, unknown>> = ReturnType<typeof objectAsync<TValue>>;
|
61
61
|
export {};
|
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
import { isPlainObject } from '@astral/utils';
|
11
11
|
import { callAsyncRule as callAsyncRecursiveRule, createContext, createErrorMap, createGuard, } from '../../core';
|
12
12
|
import { optionalAsync } from '../../optional';
|
13
|
-
import { isEmptyErrors } from '../isEmptyErrors';
|
14
13
|
import { OBJECT_TYPE_ERROR_INFO } from '../constants';
|
14
|
+
import { isEmptyErrors } from '../isEmptyErrors';
|
15
15
|
// TODO: необходимо реализовать переиспользование логики между object и objectAsync
|
16
16
|
/**
|
17
17
|
* Guard для объекта, который поддерживает асинхронную валидацию
|
@@ -56,12 +56,14 @@ export const objectAsync = (schema) => createGuard((value_1, ctx_1, _a) => __awa
|
|
56
56
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
57
57
|
const results = yield Promise.all(schemaEntries.map(([key, rule]) => {
|
58
58
|
const callRule = isOptional ? optionalAsync(rule) : rule;
|
59
|
-
return callAsyncRecursiveRule(callRule,
|
59
|
+
return callAsyncRecursiveRule(callRule,
|
60
|
+
// biome-ignore lint/nursery/noShadow: <>
|
61
|
+
value[key], context);
|
60
62
|
}));
|
61
|
-
return results.reduce((
|
63
|
+
return results.reduce((errorMapResult, validationResult, index) => {
|
62
64
|
const [key] = schemaEntries[index];
|
63
|
-
|
64
|
-
return
|
65
|
+
errorMapResult[key] = validationResult;
|
66
|
+
return errorMapResult;
|
65
67
|
}, {});
|
66
68
|
});
|
67
69
|
const errorMap = yield generateErrorMap();
|
package/ogrnIP/index.d.ts
CHANGED
package/ogrnIP/index.js
CHANGED
package/ogrnUL/index.d.ts
CHANGED
package/ogrnUL/index.js
CHANGED
package/or/or.js
CHANGED