@astral/validations 4.10.0 → 4.10.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/index.d.ts
CHANGED
@@ -7,6 +7,7 @@ export { boolean, BOOLEAN_TYPE_ERROR_INFO } from './boolean';
|
|
7
7
|
export { array, ARRAY_TYPE_ERROR_INFO } from './array';
|
8
8
|
export { arrayItem } from './arrayItem';
|
9
9
|
export { deepPartial } from './deepPartial';
|
10
|
+
export { partial } from './partial';
|
10
11
|
export { min, STRING_MIN_ERROR_CODE, ARRAY_MIN_ERROR_CODE, DATE_MIN_ERROR_CODE, NUMBER_MIN_ERROR_CODE, } from './min';
|
11
12
|
export { max, STRING_MAX_ERROR_CODE, ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, NUMBER_MAX_ERROR_CODE, } from './max';
|
12
13
|
export { integer, INTEGER_ERROR_INFO } from './integer';
|
package/index.js
CHANGED
@@ -7,6 +7,7 @@ export { boolean, BOOLEAN_TYPE_ERROR_INFO } from './boolean';
|
|
7
7
|
export { array, ARRAY_TYPE_ERROR_INFO } from './array';
|
8
8
|
export { arrayItem } from './arrayItem';
|
9
9
|
export { deepPartial } from './deepPartial';
|
10
|
+
export { partial } from './partial';
|
10
11
|
export { min, STRING_MIN_ERROR_CODE, ARRAY_MIN_ERROR_CODE, DATE_MIN_ERROR_CODE, NUMBER_MIN_ERROR_CODE, } from './min';
|
11
12
|
export { max, STRING_MAX_ERROR_CODE, ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, NUMBER_MAX_ERROR_CODE, } from './max';
|
12
13
|
export { integer, INTEGER_ERROR_INFO } from './integer';
|
package/object/object.js
CHANGED
@@ -37,8 +37,7 @@ export const object = (schema) => createGuard((value, ctx, { typeErrorMessage, i
|
|
37
37
|
const schemaEntries = Object.entries(schema);
|
38
38
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
39
39
|
return schemaEntries.reduce((errorMap, [key, rule]) => {
|
40
|
-
const
|
41
|
-
const callRule = isGuard && isOptional ? optional(rule) : rule;
|
40
|
+
const callRule = isOptional ? optional(rule) : rule;
|
42
41
|
errorMap[key] = callRecursiveRule(callRule, value[key], context);
|
43
42
|
return errorMap;
|
44
43
|
}, {});
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
};
|
10
10
|
import isPlainObject from 'is-plain-obj';
|
11
11
|
import { callAsyncRule as callAsyncRecursiveRule, createContext, createErrorMap, createGuard, } from '../../core';
|
12
|
-
import {
|
12
|
+
import { optionalAsync } from '../../optional';
|
13
13
|
import { isEmptyErrors } from '../isEmptyErrors';
|
14
14
|
import { OBJECT_TYPE_ERROR_INFO } from '../constants';
|
15
15
|
// TODO: необходимо реализовать переиспользование логики между object и objectAsync
|
@@ -55,8 +55,7 @@ export const objectAsync = (schema) => createGuard((value, ctx, { typeErrorMessa
|
|
55
55
|
const schemaEntries = Object.entries(schema);
|
56
56
|
const isOptional = context.global.overrides.objectIsPartial || isPartial;
|
57
57
|
const results = yield Promise.all(schemaEntries.map(([key, rule]) => {
|
58
|
-
const
|
59
|
-
const callRule = isGuard && isOptional ? optional(rule) : rule;
|
58
|
+
const callRule = isOptional ? optionalAsync(rule) : rule;
|
60
59
|
return callAsyncRecursiveRule(callRule, value[key], context);
|
61
60
|
}));
|
62
61
|
return results.reduce((errorMap, validationResult, index) => {
|
@@ -1,6 +1,6 @@
|
|
1
|
-
import { AsyncIndependentValidationRule, AsyncValidationRule } from '../../core';
|
1
|
+
import { AsyncIndependentValidationRule, AsyncValidationRule, ValidationRule } from '../../core';
|
2
2
|
/**
|
3
3
|
* @description Выключает проверку на required в guard. Предназначен для асинхронных правил.
|
4
4
|
* @example object({ name: optionalAsync(stringAsync(min(22))) })
|
5
5
|
*/
|
6
|
-
export declare const optionalAsync: <TLastSchemaValues extends Record<string, unknown>>(rule: AsyncValidationRule<unknown, TLastSchemaValues>) => AsyncIndependentValidationRule<unknown, TLastSchemaValues>;
|
6
|
+
export declare const optionalAsync: <TLastSchemaValues extends Record<string, unknown>>(rule: AsyncValidationRule<unknown, TLastSchemaValues> | ValidationRule<unknown, TLastSchemaValues>) => AsyncIndependentValidationRule<unknown, TLastSchemaValues>;
|