@astral/validations 3.0.0-beta.1 → 3.0.0-beta.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.
Files changed (44) hide show
  1. package/README.md +93 -47
  2. package/any/any.d.ts +1 -9
  3. package/array/array.d.ts +8 -1
  4. package/arrayItem/arrayItem.d.ts +1 -9
  5. package/boolean/boolean.d.ts +8 -1
  6. package/core/context/types.d.ts +7 -6
  7. package/core/guard/createGuard/createGuard.d.ts +9 -6
  8. package/core/rule/createRule/createRule.d.ts +1 -9
  9. package/core/rule/required/required.d.ts +1 -9
  10. package/date/date.d.ts +8 -1
  11. package/deepPartial/deepPartial.d.ts +1 -9
  12. package/email/email.d.ts +1 -9
  13. package/index.d.ts +3 -0
  14. package/index.js +3 -0
  15. package/innIP/innIP.d.ts +1 -9
  16. package/innUL/innUL.d.ts +1 -9
  17. package/integer/constants.d.ts +2 -0
  18. package/integer/constants.js +5 -0
  19. package/integer/index.d.ts +2 -0
  20. package/integer/index.js +2 -0
  21. package/integer/integer.d.ts +25 -0
  22. package/integer/integer.js +28 -0
  23. package/kpp/kpp.d.ts +1 -9
  24. package/mobilePhone/mobilePhone.d.ts +1 -9
  25. package/number/number.d.ts +8 -1
  26. package/object/object.d.ts +10 -7
  27. package/object/object.js +1 -3
  28. package/ogrnIP/ogrnIP.d.ts +1 -9
  29. package/ogrnUL/ogrnUL.d.ts +1 -9
  30. package/onlyNumber/onlyNumber.d.ts +1 -9
  31. package/optional/optional.d.ts +1 -1
  32. package/optional/optional.js +0 -9
  33. package/or/or.d.ts +1 -9
  34. package/package.json +3 -2
  35. package/partial/partial.d.ts +11 -5
  36. package/pattern/pattern.d.ts +1 -9
  37. package/snils/snils.d.ts +1 -9
  38. package/string/string.d.ts +8 -1
  39. package/toPrettyError/index.d.ts +1 -0
  40. package/toPrettyError/index.js +1 -0
  41. package/toPrettyError/toPrettyError.d.ts +39 -0
  42. package/toPrettyError/toPrettyError.js +38 -0
  43. package/transform/transform.d.ts +1 -9
  44. package/when/when.d.ts +1 -9
package/README.md CHANGED
@@ -19,6 +19,7 @@
19
19
  - [number](#number)
20
20
  - [min](#min-number)
21
21
  - [max](#max-number)
22
+ - [integer](#integer)
22
23
  - [string](#string)
23
24
  - [min](#min-string)
24
25
  - [max](#max-string)
@@ -85,7 +86,8 @@ import {
85
86
  string,
86
87
  optional,
87
88
  min,
88
- number
89
+ number,
90
+ toPrettyError,
89
91
  } from '@astral/validations';
90
92
 
91
93
  type Permission = {
@@ -124,13 +126,15 @@ validate({
124
126
  },
125
127
  });
126
128
 
127
- // Error in info.permissions.0.description: Обязательно
128
- validate({
129
- name: 'Vasya',
130
- info: {
131
- permissions: [{ id: 1 }],
132
- },
133
- });
129
+ // { info: { permissions: [{ description: 'Обязательно' }] } }
130
+ toPrettyError(
131
+ validate({
132
+ name: 'Vasya',
133
+ info: {
134
+ permissions: [{ id: 1 }],
135
+ },
136
+ })
137
+ );
134
138
  ```
135
139
 
136
140
  Валидация отдельных value
@@ -233,6 +237,27 @@ validate(10)
233
237
 
234
238
  ---
235
239
 
240
+ ### integer
241
+
242
+ Проверяет является ли значение целым числом.
243
+
244
+ ```ts
245
+ import { number, integer } from '@astral/validations';
246
+
247
+ const validate = number(integer(5));
248
+
249
+ // undefined
250
+ validate(5)
251
+
252
+ // undefined
253
+ validate(7)
254
+
255
+ // { message: 'Только целые числа' }
256
+ validate(3.14)
257
+ ```
258
+
259
+ ---
260
+
236
261
  ## string
237
262
 
238
263
  - Возвращает ошибку если:
@@ -636,7 +661,8 @@ import {
636
661
  string,
637
662
  optional,
638
663
  min,
639
- number
664
+ number,
665
+ toPrettyError
640
666
  } from '@astral/validations';
641
667
 
642
668
  type User = {
@@ -670,13 +696,15 @@ validate({
670
696
  },
671
697
  });
672
698
 
673
- // Error in info.permissions.0.description: Обязательно
674
- validate({
675
- name: 'Vasya',
676
- info: {
677
- permissions: [{ id: 1 }],
678
- },
679
- });
699
+ // { info: { permissions: [{ description: 'Обязательно' }] } }
700
+ toPrettyError(
701
+ validate({
702
+ name: 'Vasya',
703
+ info: {
704
+ permissions: [{ id: 1 }],
705
+ },
706
+ })
707
+ );
680
708
  ```
681
709
 
682
710
  ### partial
@@ -684,7 +712,7 @@ validate({
684
712
  Позволяет сделать все поля объекта optional.
685
713
 
686
714
  ```ts
687
- import { partial, object, string } from '@astral/validations';
715
+ import { partial, object, string, toPrettyError } from '@astral/validations';
688
716
 
689
717
  type Values = {
690
718
  name: string;
@@ -696,8 +724,10 @@ const validateRequired = object<Values>({
696
724
  surname: string()
697
725
  })
698
726
 
699
- // { message: 'Ошибка в свойстве name: Обязательно' }
700
- validateRequired({});
727
+ // { name: 'Обязательно' }
728
+ toPrettyError(
729
+ validateRequired({})
730
+ );
701
731
 
702
732
  const validatePartial = partial(
703
733
  object<Values>({
@@ -778,7 +808,8 @@ validate({
778
808
  import {
779
809
  array,
780
810
  arrayItem,
781
- min
811
+ min,
812
+ toPrettyError
782
813
  } from '@astral/validations';
783
814
 
784
815
  type User = {
@@ -802,8 +833,10 @@ validate([{ name: 'Vasya' }]);
802
833
  // { message: 'Не меньше: 1' }
803
834
  validate([]);
804
835
 
805
- // { cause: { errorArray: [{ name: { message: 'Не является строкой' } }] } }
806
- validate([{ name: 22 }]);
836
+ // [{ name: 'Не является строкой' }]
837
+ toPrettyError(
838
+ validate([{ name: 22 }])
839
+ );
807
840
  ```
808
841
 
809
842
  ### arrayItem
@@ -811,7 +844,7 @@ validate([{ name: 22 }]);
811
844
  Применяет переданные правила валидации к каждому элементу массива.
812
845
 
813
846
  ```ts
814
- import { array, arrayItem, object, string, optional } from '@astral/validations';
847
+ import { array, arrayItem, object, string, optional, toPrettyError } from '@astral/validations';
815
848
 
816
849
  type User = {
817
850
  name: string;
@@ -831,16 +864,20 @@ const validate = array(
831
864
  validate([{ name: 'Vasya' }]);
832
865
 
833
866
  // { cause: { errorArray: [{ name: { message: 'Не является строкой' } }] } }
834
- validate([{ name: 22 }]);
867
+ toPrettyError(
868
+ validate([{ name: 22 }])
869
+ );
835
870
  ```
836
871
 
837
872
  ```ts
838
- import { array, arrayItem, string, min } from '@astral/validations';
873
+ import { array, arrayItem, string, min, toPrettyError } from '@astral/validations';
839
874
 
840
875
  const validate = array(arrayItem(string(min(3))));
841
876
 
842
- // { cause: { arrayError: [undefined, { message: 'Мин. символов: 3' }] } }
843
- validate(['vasya', 'ma']);
877
+ // [undefined, 'Мин. символов: 3']
878
+ toPrettyError(
879
+ validate(['vasya', 'ma'])
880
+ );
844
881
  ```
845
882
 
846
883
  ---
@@ -890,7 +927,7 @@ type Values = { name: string; isAgree: boolean };
890
927
 
891
928
  const validate = object<Values, Values>({
892
929
  name: when({
893
- is: (_, ctx) => ctx.global.values.isAgree,
930
+ is: (_, ctx) => Boolean(ctx.global.values.isAgree),
894
931
  then: string(),
895
932
  otherwise: any(),
896
933
  }),
@@ -898,10 +935,12 @@ const validate = object<Values, Values>({
898
935
  });
899
936
 
900
937
  // undefined
901
- const result1 = validate({ isAgree: false, name: '' });
938
+ validate({ isAgree: false, name: '' });
902
939
 
903
- // Required error для name
904
- const result2 = validate({ isAgree: true, name: '' });
940
+ // { name: 'Обязательно' }
941
+ toPrettyError(
942
+ validate({ isAgree: true, name: '' })
943
+ );
905
944
  ```
906
945
 
907
946
  ---
@@ -937,14 +976,14 @@ validateCustomString(20);
937
976
  ## Базовый пример
938
977
 
939
978
  ```ts
940
- import { string, object } from '@astral/validations';
979
+ import { string, object, toPrettyError } from '@astral/validations';
941
980
 
942
981
  type Values = {
943
982
  name: string;
944
983
  nickname: string;
945
984
  };
946
985
 
947
- const validate = object<Values>({
986
+ const validate = object<Values, Values>({
948
987
  name: string(),
949
988
  nickname: string((value, ctx) => {
950
989
  if (value.includes('_')) {
@@ -958,8 +997,10 @@ const validate = object<Values>({
958
997
  }),
959
998
  });
960
999
 
961
- // { cause: { errorMap: { nickname: { message: 'Символ "_" запрещен', code: 'nickname-symbol' } } } }
962
- validate({ name: 'Vasya', nickname: 'va_sya' });
1000
+ // { nickname: 'Символ "_" запрещен' }
1001
+ toPrettyError(
1002
+ validate({ name: 'Vasya', nickname: 'va_sya' })
1003
+ );
963
1004
  ```
964
1005
 
965
1006
  ## Связанные поля
@@ -967,7 +1008,7 @@ validate({ name: 'Vasya', nickname: 'va_sya' });
967
1008
  В ```ctx.global.values``` находится value, принятое самым верхнеуровневым guard'ом.
968
1009
 
969
1010
  ```ts
970
- import { object, string } from '@astral/validations';
1011
+ import { object, string, toPrettyError } from '@astral/validations';
971
1012
 
972
1013
  type Values = {
973
1014
  password: string;
@@ -976,7 +1017,7 @@ type Values = {
976
1017
 
977
1018
  const validate = object<Values, Values>({
978
1019
  password: string(min(9)),
979
- repeatPassword: string<Values>(min(9), (value, ctx) => {
1020
+ repeatPassword: string(min(9), (value, ctx) => {
980
1021
  if (value !== ctx.global.values.password) {
981
1022
  return ctx.createError({
982
1023
  message: 'Пароли не совпадают',
@@ -988,8 +1029,10 @@ const validate = object<Values, Values>({
988
1029
  }),
989
1030
  });
990
1031
 
991
- // Error.message "Пароли не совпадают" для repeatPassword
992
- validate({ password: 'qywerty123', repeatPassword: 'qywerty1234' });
1032
+ // { repeatPassword: 'Пароли не совпадают' }
1033
+ toPrettyError(
1034
+ validate({ password: 'qywerty123', repeatPassword: 'qywerty1234' })
1035
+ );
993
1036
  ```
994
1037
 
995
1038
  ## Переиспользуемое правило
@@ -1069,7 +1112,7 @@ type Values = { name: string; isAgree: boolean };
1069
1112
 
1070
1113
  const validate = object<Values, Values>({
1071
1114
  name: when({
1072
- is: (_, ctx) => ctx.global.values.isAgree,
1115
+ is: (_, ctx) => Boolean(ctx.global.values.isAgree),
1073
1116
  then: string(),
1074
1117
  otherwise: any(),
1075
1118
  }),
@@ -1077,10 +1120,12 @@ const validate = object<Values, Values>({
1077
1120
  });
1078
1121
 
1079
1122
  // undefined
1080
- const result1 = validate({ isAgree: false, name: '' });
1123
+ validate({ isAgree: false, name: '' });
1081
1124
 
1082
- // Required error для name
1083
- const result2 = validate({ isAgree: true, name: '' });
1125
+ // { name: 'Обязательно' }
1126
+ toPrettyError(
1127
+ validate({ isAgree: true, name: '' })
1128
+ );
1084
1129
  ```
1085
1130
 
1086
1131
  When для ветки объекта:
@@ -1094,19 +1139,20 @@ type Values = {
1094
1139
 
1095
1140
  const validate = object<Values, Values>({
1096
1141
  name: string(),
1097
- info: when<Values>({
1142
+ info: when({
1098
1143
  is: (_, ctx) => ctx.global.values.name === 'Vasya',
1099
1144
  then: object<ValuesInfo>({ surname: string() }),
1100
1145
  otherwise: any(),
1101
1146
  }),
1102
1147
  });
1103
1148
 
1104
- // Error.message "Обязательно" для info
1105
- validate({ name: 'Vasya' });
1149
+ // { info: 'Обязательно' }
1150
+ toPrettyError(
1151
+ validate({ name: 'Vasya' })
1152
+ );
1106
1153
 
1107
1154
  // undefined
1108
1155
  validate({ name: 'Kolya' });
1109
-
1110
1156
  ```
1111
1157
 
1112
1158
  ---
package/any/any.d.ts CHANGED
@@ -10,12 +10,4 @@
10
10
  * validate({});
11
11
  * ```
12
12
  */
13
- export declare const any: <TValues>() => (value: unknown, prevCtx?: Readonly<{
14
- global: Readonly<{
15
- values: TValues;
16
- overrides: Readonly<{
17
- objectIsPartial: boolean;
18
- }>;
19
- }>;
20
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
21
- }> | undefined) => import("../core").ValidationResult;
13
+ export declare const any: <TValues>() => (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
package/array/array.d.ts CHANGED
@@ -12,4 +12,11 @@ import { ValidationRule } from '../core';
12
12
  * validateArray(value);
13
13
  * ```
14
14
  */
15
- export declare const array: <TItem extends unknown, TValues = unknown>(...rules: ValidationRule<TItem[], TValues>[]) => import("../core").Guard<unknown[], TValues, {}>;
15
+ export declare const array: <TItem extends unknown, TValues = unknown>(...rules: ValidationRule<TItem[], TValues>[]) => {
16
+ (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined): import("../core").ValidationResult;
17
+ define(overridesDefOptions: Partial<{}> & {
18
+ requiredErrorMessage?: string | undefined;
19
+ typeErrorMessage?: string | undefined;
20
+ isOptional?: boolean | undefined;
21
+ }): any;
22
+ };
@@ -24,12 +24,4 @@ import { ValidationRule } from '../core';
24
24
  * validateArray(values);
25
25
  * ```
26
26
  */
27
- export declare const arrayItem: <TItem extends unknown, TValues = unknown>(...rules: ValidationRule<TItem, TValues>[]) => (value: TItem[], prevCtx?: Readonly<{
28
- global: Readonly<{
29
- values: TValues;
30
- overrides: Readonly<{
31
- objectIsPartial: boolean;
32
- }>;
33
- }>;
34
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
35
- }> | undefined) => import("../core").ValidationResult;
27
+ export declare const arrayItem: <TItem extends unknown, TValues = unknown>(...rules: ValidationRule<TItem, TValues>[]) => (value: TItem[], prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
@@ -10,4 +10,11 @@ import { ValidationRule } from '../core';
10
10
  * validate(true);
11
11
  * ```
12
12
  */
13
- export declare const boolean: <TValues>(...rules: ValidationRule<boolean, TValues>[]) => import("../core").Guard<boolean, TValues, {}>;
13
+ export declare const boolean: <TValues>(...rules: ValidationRule<boolean, TValues>[]) => {
14
+ (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined): import("../core").ValidationResult;
15
+ define(overridesDefOptions: Partial<{}> & {
16
+ requiredErrorMessage?: string | undefined;
17
+ typeErrorMessage?: string | undefined;
18
+ isOptional?: boolean | undefined;
19
+ }): any;
20
+ };
@@ -1,26 +1,27 @@
1
+ import { DeepPartial, DeepReadonly } from 'utility-types';
1
2
  import { createSimpleError } from '../errors';
2
3
  /**
3
4
  * @description Контекст, который доступен в каждом правиле
4
5
  */
5
- export type ValidationContext<TValues> = Readonly<{
6
+ export type ValidationContext<TValues> = DeepReadonly<{
6
7
  /**
7
8
  * @description Глобальные значения, идущие от самого верхнего правила к самому нижнему
8
9
  */
9
- global: Readonly<{
10
+ global: {
10
11
  /**
11
12
  * @description Значения, которые валидируется guard самого высоко порядка
12
13
  */
13
- values: TValues;
14
+ values: DeepPartial<TValues>;
14
15
  /**
15
16
  * @description Глобальные переопределения (сквозные для всех правил)
16
17
  */
17
- overrides: Readonly<{
18
+ overrides: {
18
19
  /**
19
20
  * @description Делает для всех объектов в схеме все свойства необязательными
20
21
  */
21
22
  objectIsPartial: boolean;
22
- }>;
23
- }>;
23
+ };
24
+ };
24
25
  /**
25
26
  * @description Фабрика ошибок. Возвращает новую ошибку валидации
26
27
  */
@@ -1,4 +1,4 @@
1
- import { ValidationResult, ValidationTypes } from '../../types';
1
+ import { ValidationResult } from '../../types';
2
2
  import { ValidationContext } from '../../context';
3
3
  type DefOptions<AddDefOptions extends Record<string, unknown>> = Partial<AddDefOptions> & {
4
4
  /**
@@ -17,18 +17,18 @@ type DefOptions<AddDefOptions extends Record<string, unknown>> = Partial<AddDefO
17
17
  */
18
18
  isOptional?: boolean;
19
19
  };
20
- type GuardValue<ValidationType> = ValidationType | undefined | null | unknown;
20
+ type GuardValue = unknown;
21
21
  /**
22
22
  * @description Интерфейс функции guard, которая в прототипе содержит метод define
23
23
  */
24
- export interface Guard<ValidationType extends ValidationTypes, TValues, AddDefOptions extends Record<string, unknown> = {}> {
25
- (value: GuardValue<ValidationType>, ctx?: ValidationContext<TValues>): ValidationResult;
24
+ export interface Guard<TValues = unknown, AddDefOptions extends Record<string, unknown> = {}> {
25
+ (value: GuardValue, ctx?: ValidationContext<TValues>): ValidationResult;
26
26
  /**
27
27
  * @description Функция для создания нового guard с переопределенными дефолтными параметрами. Возвращает новый guard
28
28
  * @param options - параметры, позволяющие переопределить дефолтные настройки guard
29
29
  * @example string.define({ requiredMessage: 'ИНН не может быть пустым' })(inn())
30
30
  */
31
- define(options: DefOptions<AddDefOptions>): Guard<ValidationType, TValues, AddDefOptions>;
31
+ define(options: DefOptions<AddDefOptions>): Guard<TValues, AddDefOptions>;
32
32
  }
33
33
  /**
34
34
  * @description Функция, которая позволяет определять частную логику для guard
@@ -50,5 +50,8 @@ type GuardExecutor<TValues, AddDefOptions extends Record<string, unknown>> = (va
50
50
  * });
51
51
  * ```
52
52
  */
53
- export declare const createGuard: <ValidationType extends unknown, TValues, AddDefOptions extends Record<string, unknown> = {}>(executeGuard: GuardExecutor<TValues, AddDefOptions>) => Guard<ValidationType, TValues, AddDefOptions>;
53
+ export declare const createGuard: <TValues, AddDefOptions extends Record<string, unknown> = {}>(executeGuard: GuardExecutor<TValues, AddDefOptions>) => {
54
+ (value: unknown, prevCtx?: ValidationContext<TValues> | undefined): ValidationResult;
55
+ define(overridesDefOptions: DefOptions<AddDefOptions>): any;
56
+ };
54
57
  export {};
@@ -30,13 +30,5 @@ type RuleExecutor<ValidationType extends ValidationTypes, TValues> = (value: Val
30
30
  * }, params);
31
31
  * ```
32
32
  */
33
- export declare const createRule: <ValidationType extends unknown, TValues = unknown>(executor: RuleExecutor<ValidationType, TValues>, commonParams?: CommonRuleParams<ValidationType> | undefined) => (value: ValidationType, prevCtx?: Readonly<{
34
- global: Readonly<{
35
- values: TValues;
36
- overrides: Readonly<{
37
- objectIsPartial: boolean;
38
- }>;
39
- }>;
40
- createError: ({ message, code }: import("../..").ErrorInfo) => import("../..").ValidationSimpleError<{}>;
41
- }> | undefined) => ValidationResult;
33
+ export declare const createRule: <ValidationType extends unknown, TValues = unknown>(executor: RuleExecutor<ValidationType, TValues>, commonParams?: CommonRuleParams<ValidationType> | undefined) => (value: ValidationType, prevCtx?: ValidationContext<TValues> | undefined) => ValidationResult;
42
34
  export {};
@@ -8,12 +8,4 @@ export declare const required: ({ message, }?: {
8
8
  * @default Обязательно
9
9
  */
10
10
  message?: string | undefined;
11
- }) => (value: unknown, prevCtx?: Readonly<{
12
- global: Readonly<{
13
- values: unknown;
14
- overrides: Readonly<{
15
- objectIsPartial: boolean;
16
- }>;
17
- }>;
18
- createError: ({ message, code }: import("../..").ErrorInfo) => import("../..").ValidationSimpleError<{}>;
19
- }> | undefined) => import("../..").ValidationResult;
11
+ }) => (value: unknown, prevCtx?: import("../..").ValidationContext<unknown> | undefined) => import("../..").ValidationResult;
package/date/date.d.ts CHANGED
@@ -15,5 +15,12 @@ type AdditionalDefOptions = {
15
15
  * validate(new Date('22.22.2022'));
16
16
  * ```
17
17
  */
18
- export declare const date: <TValues>(...rules: ValidationRule<Date, TValues>[]) => import("../core").Guard<Date, TValues, AdditionalDefOptions>;
18
+ export declare const date: <TValues>(...rules: ValidationRule<Date, TValues>[]) => {
19
+ (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined): import("../core").ValidationResult;
20
+ define(overridesDefOptions: Partial<AdditionalDefOptions> & {
21
+ requiredErrorMessage?: string | undefined;
22
+ typeErrorMessage?: string | undefined;
23
+ isOptional?: boolean | undefined;
24
+ }): any;
25
+ };
19
26
  export {};
@@ -18,12 +18,4 @@ import { Guard } from '../core';
18
18
  * const result = validate({ info: { info: {} } });
19
19
  * ```
20
20
  */
21
- export declare const deepPartial: <TValues>(guard: Guard<unknown, TValues, {}>) => (value: unknown, prevCtx?: Readonly<{
22
- global: Readonly<{
23
- values: TValues;
24
- overrides: Readonly<{
25
- objectIsPartial: boolean;
26
- }>;
27
- }>;
28
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
29
- }> | undefined) => import("../core").ValidationResult;
21
+ export declare const deepPartial: <TValues>(guard: Guard<TValues, {}>) => (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
package/email/email.d.ts CHANGED
@@ -16,13 +16,5 @@ type EmailParams = {
16
16
  * validate('example@mail.ru');
17
17
  * ```
18
18
  */
19
- export declare const email: <TValues>(params?: EmailParams) => (value: string, prevCtx?: Readonly<{
20
- global: Readonly<{
21
- values: TValues;
22
- overrides: Readonly<{
23
- objectIsPartial: boolean;
24
- }>;
25
- }>;
26
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
27
- }> | undefined) => import("../core").ValidationResult;
19
+ export declare const email: <TValues>(params?: EmailParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
28
20
  export {};
package/index.d.ts CHANGED
@@ -8,6 +8,8 @@ export { array, ARRAY_TYPE_ERROR_INFO } from './array';
8
8
  export { arrayItem } from './arrayItem';
9
9
  export { deepPartial } from './deepPartial';
10
10
  export { min, STRING_MIN_ERROR_CODE, ARRAY_MIN_ERROR_CODE, DATE_MIN_ERROR_CODE, NUMBER_MIN_ERROR_CODE, } from './min';
11
+ export { max, STRING_MAX_ERROR_CODE, ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, NUMBER_MAX_ERROR_CODE, } from './max';
12
+ export { integer, INTEGER_ERROR_INFO } from './integer';
11
13
  export { or } from './or';
12
14
  export { pattern, PATTERN_ERROR_CODE } from './pattern';
13
15
  export { onlyNumber, ONLY_NUMBER_ERROR_CODE } from './onlyNumber';
@@ -23,3 +25,4 @@ export { ogrnUL, OGRN_UL_ERROR_INFO } from './ogrnUL';
23
25
  export { ogrnIP, OGRN_IP_ERROR_INFO } from './ogrnIP';
24
26
  export { any } from './any';
25
27
  export { when } from './when';
28
+ export { toPrettyError } from './toPrettyError';
package/index.js CHANGED
@@ -8,6 +8,8 @@ export { array, ARRAY_TYPE_ERROR_INFO } from './array';
8
8
  export { arrayItem } from './arrayItem';
9
9
  export { deepPartial } from './deepPartial';
10
10
  export { min, STRING_MIN_ERROR_CODE, ARRAY_MIN_ERROR_CODE, DATE_MIN_ERROR_CODE, NUMBER_MIN_ERROR_CODE, } from './min';
11
+ export { max, STRING_MAX_ERROR_CODE, ARRAY_MAX_ERROR_CODE, DATE_MAX_ERROR_CODE, NUMBER_MAX_ERROR_CODE, } from './max';
12
+ export { integer, INTEGER_ERROR_INFO } from './integer';
11
13
  export { or } from './or';
12
14
  export { pattern, PATTERN_ERROR_CODE } from './pattern';
13
15
  export { onlyNumber, ONLY_NUMBER_ERROR_CODE } from './onlyNumber';
@@ -23,3 +25,4 @@ export { ogrnUL, OGRN_UL_ERROR_INFO } from './ogrnUL';
23
25
  export { ogrnIP, OGRN_IP_ERROR_INFO } from './ogrnIP';
24
26
  export { any } from './any';
25
27
  export { when } from './when';
28
+ export { toPrettyError } from './toPrettyError';
package/innIP/innIP.d.ts CHANGED
@@ -13,13 +13,5 @@ type InnIPParams = CommonRuleParams<string> & {
13
13
  * validate('384212952720');
14
14
  * ```
15
15
  */
16
- export declare const innIP: <TValues>(params?: InnIPParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const innIP: <TValues>(params?: InnIPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
package/innUL/innUL.d.ts CHANGED
@@ -13,13 +13,5 @@ type InnULParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const innUL: <TValues>(params?: InnULParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const innUL: <TValues>(params?: InnULParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
@@ -0,0 +1,2 @@
1
+ import { ErrorInfo } from '../core';
2
+ export declare const INTEGER_ERROR_INFO: ErrorInfo;
@@ -0,0 +1,5 @@
1
+ import { createErrorCode } from '../core';
2
+ export const INTEGER_ERROR_INFO = {
3
+ code: createErrorCode('integer'),
4
+ message: 'Только целые числа',
5
+ };
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './integer';
@@ -0,0 +1,2 @@
1
+ export * from './constants';
2
+ export * from './integer';
@@ -0,0 +1,25 @@
1
+ type IntegerParams = {
2
+ /**
3
+ * @description Замена стандартного сообщения ошибки.
4
+ */
5
+ message?: string;
6
+ };
7
+ /**
8
+ * @description
9
+ * Проверяет является ли значение целым числом.
10
+ * @example
11
+ * ```ts
12
+ * const validate = number(integer(5));
13
+ *
14
+ * // undefined
15
+ * validate(5)
16
+ *
17
+ * // undefined
18
+ * validate(7)
19
+ *
20
+ * // { message: 'Только целые числа' }
21
+ * validate(3.14)
22
+ * ```
23
+ */
24
+ export declare const integer: <TValues>(params?: IntegerParams) => (value: number, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
+ export {};
@@ -0,0 +1,28 @@
1
+ import { createRule } from '../core';
2
+ import { INTEGER_ERROR_INFO } from './constants';
3
+ /**
4
+ * @description
5
+ * Проверяет является ли значение целым числом.
6
+ * @example
7
+ * ```ts
8
+ * const validate = number(integer(5));
9
+ *
10
+ * // undefined
11
+ * validate(5)
12
+ *
13
+ * // undefined
14
+ * validate(7)
15
+ *
16
+ * // { message: 'Только целые числа' }
17
+ * validate(3.14)
18
+ * ```
19
+ */
20
+ export const integer = (params) => createRule((value, ctx) => {
21
+ if (!Number.isInteger(value)) {
22
+ return ctx.createError({
23
+ message: (params === null || params === void 0 ? void 0 : params.message) || INTEGER_ERROR_INFO.message,
24
+ code: INTEGER_ERROR_INFO.code,
25
+ });
26
+ }
27
+ return undefined;
28
+ });
package/kpp/kpp.d.ts CHANGED
@@ -13,13 +13,5 @@ type KPPParams = CommonRuleParams<string> & {
13
13
  * validate('770201001');
14
14
  * ```
15
15
  */
16
- export declare const kpp: <TValues>(params?: KPPParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const kpp: <TValues>(params?: KPPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
@@ -15,13 +15,5 @@ type MobilePhoneParams = CommonRuleParams<string> & {
15
15
  * validate('79999999999');
16
16
  * ```
17
17
  */
18
- export declare const mobilePhone: <TValues>(params?: MobilePhoneParams) => (value: string, prevCtx?: Readonly<{
19
- global: Readonly<{
20
- values: TValues;
21
- overrides: Readonly<{
22
- objectIsPartial: boolean;
23
- }>;
24
- }>;
25
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
26
- }> | undefined) => import("../core").ValidationResult;
18
+ export declare const mobilePhone: <TValues>(params?: MobilePhoneParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
27
19
  export {};
@@ -15,5 +15,12 @@ type AdditionalDefOptions = {
15
15
  * validate(24);
16
16
  * ```
17
17
  */
18
- export declare const number: <TValues>(...rules: ValidationRule<number, TValues>[]) => import("../core").Guard<number, TValues, AdditionalDefOptions>;
18
+ export declare const number: <TValues>(...rules: ValidationRule<number, TValues>[]) => {
19
+ (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined): import("../core").ValidationResult;
20
+ define(overridesDefOptions: Partial<AdditionalDefOptions> & {
21
+ requiredErrorMessage?: string | undefined;
22
+ typeErrorMessage?: string | undefined;
23
+ isOptional?: boolean | undefined;
24
+ }): any;
25
+ };
19
26
  export {};
@@ -4,8 +4,8 @@ import { Guard, ValidationContext, ValidationRule } from '../core';
4
4
  * Переопределение необходимо для того, чтобы ts показывал, что ctx required в кастомных правилах
5
5
  */
6
6
  interface ObjectPropGuard<TValues> {
7
- (value: Parameters<Guard<unknown, TValues>>[0], ctx: ValidationContext<TValues>): ReturnType<Guard<unknown, TValues>>;
8
- define: Guard<unknown, TValues>['define'];
7
+ (value: Parameters<Guard<TValues>>[0], ctx: ValidationContext<TValues>): ReturnType<Guard<TValues>>;
8
+ define: Guard<TValues>['define'];
9
9
  }
10
10
  type AdditionalDefOptions = {
11
11
  /**
@@ -13,10 +13,6 @@ type AdditionalDefOptions = {
13
13
  */
14
14
  isPartial?: boolean;
15
15
  };
16
- /**
17
- * @description Тип, который необходим для того, чтобы object невозможно было использовать без использования generic
18
- */
19
- type NeverSchema = Record<'__never', never>;
20
16
  /**
21
17
  * @description Возможные значения, принимаемые схемой
22
18
  */
@@ -48,5 +44,12 @@ export type Schema<TValue extends Record<string, unknown>, TValues = unknown> =
48
44
  * });
49
45
  * ```
50
46
  */
51
- export declare const object: <Value extends Record<string, unknown> = NeverSchema, TValues = unknown>(schema: Schema<Value, TValues>) => Guard<Value, TValues, AdditionalDefOptions>;
47
+ export declare const object: <Value extends Record<string, unknown>, TValues = unknown>(schema: Schema<Value, TValues>) => {
48
+ (value: unknown, prevCtx?: ValidationContext<TValues> | undefined): import("../core").ValidationResult;
49
+ define(overridesDefOptions: Partial<AdditionalDefOptions> & {
50
+ requiredErrorMessage?: string | undefined;
51
+ typeErrorMessage?: string | undefined;
52
+ isOptional?: boolean | undefined;
53
+ }): any;
54
+ };
52
55
  export {};
package/object/object.js CHANGED
@@ -35,9 +35,7 @@ export const object = (schema) => createGuard((value, ctx, { typeErrorMessage, i
35
35
  const isOptional = ctx.global.overrides.objectIsPartial || isPartial;
36
36
  return schemaEntries.reduce((errorMap, [key, rule]) => {
37
37
  const isGuard = 'define' in rule;
38
- const callRule = isGuard && isOptional
39
- ? optional(rule)
40
- : rule;
38
+ const callRule = isGuard && isOptional ? optional(rule) : rule;
41
39
  errorMap[key] = callRule(value[key], ctx);
42
40
  return errorMap;
43
41
  }, {});
@@ -13,13 +13,5 @@ type OgrnIPParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const ogrnIP: <TValues>(params?: OgrnIPParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const ogrnIP: <TValues>(params?: OgrnIPParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
@@ -13,13 +13,5 @@ type OgrnULParams = CommonRuleParams<string> & {
13
13
  * validate('7728168971');
14
14
  * ```
15
15
  */
16
- export declare const ogrnUL: <TValues>(params?: OgrnULParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const ogrnUL: <TValues>(params?: OgrnULParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
@@ -12,13 +12,5 @@ type OnlyNumberParams = {
12
12
  * validate('123');
13
13
  * ```
14
14
  */
15
- export declare const onlyNumber: <TValues>(params?: OnlyNumberParams) => (value: string, prevCtx?: Readonly<{
16
- global: Readonly<{
17
- values: TValues;
18
- overrides: Readonly<{
19
- objectIsPartial: boolean;
20
- }>;
21
- }>;
22
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
23
- }> | undefined) => import("../core").ValidationResult;
15
+ export declare const onlyNumber: <TValues>(params?: OnlyNumberParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
24
16
  export {};
@@ -4,4 +4,4 @@ import { Guard } from '../core';
4
4
  * @param guard - правило, проверяющее тип значения
5
5
  * @example object({ name: optional(string(min(22))) })
6
6
  */
7
- export declare const optional: <ValidationType extends unknown, TValues>(guard: Guard<ValidationType, TValues, {}>) => Guard<ValidationType, TValues, {}>;
7
+ export declare const optional: <TValues>(guard: Guard<TValues, {}>) => Guard<TValues, {}>;
@@ -1,15 +1,6 @@
1
- import { string } from '../string';
2
1
  /**
3
2
  * @description Выключает проверку на required в guard
4
3
  * @param guard - правило, проверяющее тип значения
5
4
  * @example object({ name: optional(string(min(22))) })
6
5
  */
7
6
  export const optional = (guard) => guard.define({ isOptional: true });
8
- const validateCustomString = string().define({
9
- typeErrorMessage: 'Только строка',
10
- requiredErrorMessage: 'Не может быть пустым',
11
- });
12
- // { message: 'Не может быть пустым' }
13
- validateCustomString(undefined);
14
- // { message: 'Только строка' }
15
- validateCustomString(20);
package/or/or.d.ts CHANGED
@@ -11,12 +11,4 @@ import { ValidationResult, ValidationRule } from '../core';
11
11
  * const result = validate('string');
12
12
  * ```
13
13
  */
14
- export declare const or: <TValues>(...rules: ValidationRule<unknown, TValues>[]) => (value: unknown, prevCtx?: Readonly<{
15
- global: Readonly<{
16
- values: TValues;
17
- overrides: Readonly<{
18
- objectIsPartial: boolean;
19
- }>;
20
- }>;
21
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
22
- }> | undefined) => ValidationResult;
14
+ export declare const or: <TValues>(...rules: ValidationRule<unknown, TValues>[]) => (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => ValidationResult;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@astral/validations",
3
- "version": "3.0.0-beta.1",
3
+ "version": "3.0.0-beta.4",
4
4
  "browser": "./index.js",
5
5
  "main": "./index.js",
6
6
  "dependencies": {
7
- "is-plain-obj": "^4.1.0"
7
+ "is-plain-obj": "^4.1.0",
8
+ "utility-types": "^3.10.0"
8
9
  },
9
10
  "author": "Astral.Soft",
10
11
  "license": "MIT",
@@ -1,10 +1,16 @@
1
+ import { object } from '../object';
1
2
  /**
2
3
  * @description Выключает проверку на required для всех полей объекта
3
4
  * @param objectGuard
4
5
  * @example partial(object({ name: string() }))
5
6
  */
6
- export declare const partial: (objectGuard: import("../core").Guard<Record<string, unknown>, unknown, {
7
- isPartial?: boolean | undefined;
8
- }>) => import("../core").Guard<Record<string, unknown>, unknown, {
9
- isPartial?: boolean | undefined;
10
- }>;
7
+ export declare const partial: (objectGuard: ReturnType<typeof object>) => {
8
+ (value: unknown, prevCtx?: import("../core").ValidationContext<unknown> | undefined): import("../core").ValidationResult;
9
+ define(overridesDefOptions: Partial<{
10
+ isPartial?: boolean | undefined;
11
+ }> & {
12
+ requiredErrorMessage?: string | undefined;
13
+ typeErrorMessage?: string | undefined;
14
+ isOptional?: boolean | undefined;
15
+ }): any;
16
+ };
@@ -14,13 +14,5 @@ type PatternParams = {
14
14
  * string(pattern(/[0-9]/))
15
15
  * ```
16
16
  */
17
- export declare const pattern: <TValues>(regex: RegExp, params?: PatternParams) => (value: string, prevCtx?: Readonly<{
18
- global: Readonly<{
19
- values: TValues;
20
- overrides: Readonly<{
21
- objectIsPartial: boolean;
22
- }>;
23
- }>;
24
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
25
- }> | undefined) => import("../core").ValidationResult;
17
+ export declare const pattern: <TValues>(regex: RegExp, params?: PatternParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
26
18
  export {};
package/snils/snils.d.ts CHANGED
@@ -13,13 +13,5 @@ type SnilsParams = CommonRuleParams<string> & {
13
13
  * validate('15657325992');
14
14
  * ```
15
15
  */
16
- export declare const snils: <TValues>(params?: SnilsParams) => (value: string, prevCtx?: Readonly<{
17
- global: Readonly<{
18
- values: TValues;
19
- overrides: Readonly<{
20
- objectIsPartial: boolean;
21
- }>;
22
- }>;
23
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
24
- }> | undefined) => import("../core").ValidationResult;
16
+ export declare const snils: <TValues>(params?: SnilsParams) => (value: string, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
25
17
  export {};
@@ -1,2 +1,9 @@
1
1
  import { ValidationRule } from '../core';
2
- export declare const string: <TValues>(...rules: ValidationRule<string, TValues>[]) => import("../core").Guard<string, TValues, {}>;
2
+ export declare const string: <TValues>(...rules: ValidationRule<string, TValues>[]) => {
3
+ (value: unknown, prevCtx?: import("../core").ValidationContext<TValues> | undefined): import("../core").ValidationResult;
4
+ define(overridesDefOptions: Partial<{}> & {
5
+ requiredErrorMessage?: string | undefined;
6
+ typeErrorMessage?: string | undefined;
7
+ isOptional?: boolean | undefined;
8
+ }): any;
9
+ };
@@ -0,0 +1 @@
1
+ export * from './toPrettyError';
@@ -0,0 +1 @@
1
+ export * from './toPrettyError';
@@ -0,0 +1,39 @@
1
+ import { ValidationResult } from '../core';
2
+ import { PlainValidationResult } from '../toPlainError';
3
+ /**
4
+ * @description Преобразует ошибку валидации в формат для вывода (например, в консоль)
5
+ * @param validationResult
6
+ * @example
7
+ * ```ts
8
+ *
9
+ * type ListItem = { description: string };
10
+ *
11
+ * type Values = {
12
+ * info: { name: string };
13
+ * list: ListItem[];
14
+ * };
15
+ *
16
+ * const validate = object<Values>({
17
+ * info: object<Values['info']>({ name: string() }),
18
+ * list: array(
19
+ * arrayItem(
20
+ * object<ListItem>({
21
+ * description: string(),
22
+ * }),
23
+ * ),
24
+ * ),
25
+ * });
26
+ *
27
+ * const error = validate({
28
+ * info: { name: 22 },
29
+ * list: [{}],
30
+ * });
31
+ *
32
+ * // {
33
+ * // info: { name: 'Не является строкой' },
34
+ * // list: [{ description: 'Обязательно' }],
35
+ * // }
36
+ * toPrettyError(error);
37
+ * ```
38
+ */
39
+ export declare const toPrettyError: (validationResult: ValidationResult) => PlainValidationResult<string>;
@@ -0,0 +1,38 @@
1
+ import { toPlainError } from '../toPlainError';
2
+ /**
3
+ * @description Преобразует ошибку валидации в формат для вывода (например, в консоль)
4
+ * @param validationResult
5
+ * @example
6
+ * ```ts
7
+ *
8
+ * type ListItem = { description: string };
9
+ *
10
+ * type Values = {
11
+ * info: { name: string };
12
+ * list: ListItem[];
13
+ * };
14
+ *
15
+ * const validate = object<Values>({
16
+ * info: object<Values['info']>({ name: string() }),
17
+ * list: array(
18
+ * arrayItem(
19
+ * object<ListItem>({
20
+ * description: string(),
21
+ * }),
22
+ * ),
23
+ * ),
24
+ * });
25
+ *
26
+ * const error = validate({
27
+ * info: { name: 22 },
28
+ * list: [{}],
29
+ * });
30
+ *
31
+ * // {
32
+ * // info: { name: 'Не является строкой' },
33
+ * // list: [{ description: 'Обязательно' }],
34
+ * // }
35
+ * toPrettyError(error);
36
+ * ```
37
+ */
38
+ export const toPrettyError = (validationResult) => toPlainError(validationResult, (err) => err.message);
@@ -14,13 +14,5 @@ type Transformer<TValue, TResult> = (value: TValue) => TResult;
14
14
  * );
15
15
  * ```
16
16
  */
17
- export declare const transform: <TValue extends unknown, TResult extends unknown, TValues>(transformer: Transformer<TValue, TResult>, ...rules: ValidationRule<TResult, TValues>[]) => (value: TValue, prevCtx?: Readonly<{
18
- global: Readonly<{
19
- values: TValues;
20
- overrides: Readonly<{
21
- objectIsPartial: boolean;
22
- }>;
23
- }>;
24
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
25
- }> | undefined) => import("../core").ValidationResult;
17
+ export declare const transform: <TValue extends unknown, TResult extends unknown, TValues>(transformer: Transformer<TValue, TResult>, ...rules: ValidationRule<TResult, TValues>[]) => (value: TValue, prevCtx?: import("../core").ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
26
18
  export {};
package/when/when.d.ts CHANGED
@@ -35,13 +35,5 @@ type Params<TValues> = {
35
35
  * const result2 = validate({ isAgree: true, name: '' });
36
36
  * ```
37
37
  */
38
- export declare const when: <TValues>({ is, then, otherwise }: Params<TValues>) => (value: unknown, prevCtx?: Readonly<{
39
- global: Readonly<{
40
- values: TValues;
41
- overrides: Readonly<{
42
- objectIsPartial: boolean;
43
- }>;
44
- }>;
45
- createError: ({ message, code }: import("../core").ErrorInfo) => import("../core").ValidationSimpleError<{}>;
46
- }> | undefined) => import("../core").ValidationResult;
38
+ export declare const when: <TValues>({ is, then, otherwise }: Params<TValues>) => (value: unknown, prevCtx?: ValidationContext<TValues> | undefined) => import("../core").ValidationResult;
47
39
  export {};