ts-fortress 2.6.2 → 2.8.0

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 (117) hide show
  1. package/dist/branded/brand.d.mts +3 -2
  2. package/dist/branded/brand.d.mts.map +1 -1
  3. package/dist/branded/brand.mjs +8 -7
  4. package/dist/branded/brand.mjs.map +1 -1
  5. package/dist/branded/number/finite-number.d.mts.map +1 -1
  6. package/dist/branded/number/finite-number.mjs +1 -0
  7. package/dist/branded/number/finite-number.mjs.map +1 -1
  8. package/dist/branded/number/int.d.mts.map +1 -1
  9. package/dist/branded/number/int.mjs +1 -0
  10. package/dist/branded/number/int.mjs.map +1 -1
  11. package/dist/branded/number/int16.d.mts.map +1 -1
  12. package/dist/branded/number/int16.mjs +1 -0
  13. package/dist/branded/number/int16.mjs.map +1 -1
  14. package/dist/branded/number/int32.d.mts.map +1 -1
  15. package/dist/branded/number/int32.mjs +1 -0
  16. package/dist/branded/number/int32.mjs.map +1 -1
  17. package/dist/branded/number/non-negative-finite-number.d.mts.map +1 -1
  18. package/dist/branded/number/non-negative-finite-number.mjs +1 -0
  19. package/dist/branded/number/non-negative-finite-number.mjs.map +1 -1
  20. package/dist/branded/number/non-zero-finite-number.d.mts.map +1 -1
  21. package/dist/branded/number/non-zero-finite-number.mjs +1 -0
  22. package/dist/branded/number/non-zero-finite-number.mjs.map +1 -1
  23. package/dist/branded/number/non-zero-int.d.mts.map +1 -1
  24. package/dist/branded/number/non-zero-int.mjs +1 -0
  25. package/dist/branded/number/non-zero-int.mjs.map +1 -1
  26. package/dist/branded/number/non-zero-safe-int.d.mts.map +1 -1
  27. package/dist/branded/number/non-zero-safe-int.mjs +1 -0
  28. package/dist/branded/number/non-zero-safe-int.mjs.map +1 -1
  29. package/dist/branded/number/positive-finite-number.d.mts.map +1 -1
  30. package/dist/branded/number/positive-finite-number.mjs +1 -0
  31. package/dist/branded/number/positive-finite-number.mjs.map +1 -1
  32. package/dist/branded/number/positive-int.d.mts.map +1 -1
  33. package/dist/branded/number/positive-int.mjs +1 -0
  34. package/dist/branded/number/positive-int.mjs.map +1 -1
  35. package/dist/branded/number/positive-safe-int.d.mts.map +1 -1
  36. package/dist/branded/number/positive-safe-int.mjs +1 -0
  37. package/dist/branded/number/positive-safe-int.mjs.map +1 -1
  38. package/dist/branded/number/safe-int.d.mts.map +1 -1
  39. package/dist/branded/number/safe-int.mjs +1 -0
  40. package/dist/branded/number/safe-int.mjs.map +1 -1
  41. package/dist/branded/number/safe-uint.d.mts.map +1 -1
  42. package/dist/branded/number/safe-uint.mjs +1 -0
  43. package/dist/branded/number/safe-uint.mjs.map +1 -1
  44. package/dist/branded/number/uint.d.mts.map +1 -1
  45. package/dist/branded/number/uint.mjs +1 -0
  46. package/dist/branded/number/uint.mjs.map +1 -1
  47. package/dist/branded/number/uint16.d.mts.map +1 -1
  48. package/dist/branded/number/uint16.mjs +1 -0
  49. package/dist/branded/number/uint16.mjs.map +1 -1
  50. package/dist/branded/number/uint32.d.mts.map +1 -1
  51. package/dist/branded/number/uint32.mjs +1 -0
  52. package/dist/branded/number/uint32.mjs.map +1 -1
  53. package/dist/utils/create-cast-fn.d.mts.map +1 -1
  54. package/dist/utils/create-cast-fn.mjs +1 -2
  55. package/dist/utils/create-cast-fn.mjs.map +1 -1
  56. package/dist/utils/validation-error.d.mts +2 -2
  57. package/dist/utils/validation-error.d.mts.map +1 -1
  58. package/dist/utils/validation-error.mjs +10 -3
  59. package/dist/utils/validation-error.mjs.map +1 -1
  60. package/package.json +2 -2
  61. package/src/array/array-of-length.test.mts +2 -2
  62. package/src/array/array.test.mts +2 -4
  63. package/src/array/non-empty-array.test.mts +2 -2
  64. package/src/array/tuple.test.mts +2 -2
  65. package/src/branded/brand.mts +16 -20
  66. package/src/branded/number/finite-number.mts +1 -0
  67. package/src/branded/number/finite-number.test.mts +5 -6
  68. package/src/branded/number/int.mts +1 -0
  69. package/src/branded/number/int.test.mts +6 -7
  70. package/src/branded/number/int16.mts +1 -0
  71. package/src/branded/number/int16.test.mts +4 -6
  72. package/src/branded/number/int32.mts +1 -0
  73. package/src/branded/number/int32.test.mts +4 -6
  74. package/src/branded/number/non-negative-finite-number.mts +1 -0
  75. package/src/branded/number/non-negative-finite-number.test.mts +4 -6
  76. package/src/branded/number/non-zero-finite-number.mts +1 -0
  77. package/src/branded/number/non-zero-finite-number.test.mts +4 -5
  78. package/src/branded/number/non-zero-int.mts +1 -0
  79. package/src/branded/number/non-zero-int.test.mts +4 -5
  80. package/src/branded/number/non-zero-safe-int.mts +1 -0
  81. package/src/branded/number/non-zero-safe-int.test.mts +4 -5
  82. package/src/branded/number/positive-finite-number.mts +1 -0
  83. package/src/branded/number/positive-finite-number.test.mts +4 -6
  84. package/src/branded/number/positive-int.mts +1 -0
  85. package/src/branded/number/positive-int.test.mts +6 -8
  86. package/src/branded/number/positive-safe-int.mts +1 -0
  87. package/src/branded/number/positive-safe-int.test.mts +4 -6
  88. package/src/branded/number/safe-int.mts +1 -0
  89. package/src/branded/number/safe-int.test.mts +4 -5
  90. package/src/branded/number/safe-uint.mts +1 -0
  91. package/src/branded/number/safe-uint.test.mts +4 -6
  92. package/src/branded/number/uint.mts +1 -0
  93. package/src/branded/number/uint.test.mts +6 -8
  94. package/src/branded/number/uint16.mts +1 -0
  95. package/src/branded/number/uint16.test.mts +4 -6
  96. package/src/branded/number/uint32.mts +1 -0
  97. package/src/branded/number/uint32.test.mts +4 -6
  98. package/src/branded/simple-branded-number.test.mts +4 -4
  99. package/src/branded/simple-branded-string.test.mts +6 -6
  100. package/src/compose/intersection.test.mts +2 -2
  101. package/src/enum/enum.test.mts +0 -2
  102. package/src/enum/uint-range.test.mts +0 -2
  103. package/src/primitives/bigint.test.mts +3 -3
  104. package/src/primitives/boolean.test.mts +4 -4
  105. package/src/primitives/null.test.mts +3 -3
  106. package/src/primitives/number.test.mts +5 -3
  107. package/src/primitives/string.test.mts +6 -4
  108. package/src/primitives/symbol.test.mts +1 -1
  109. package/src/primitives/undefined.test.mts +3 -3
  110. package/src/record/key-value-record.test.mts +2 -2
  111. package/src/record/omit.test.mts +1 -1
  112. package/src/record/partial.test.mts +5 -5
  113. package/src/record/pick.test.mts +1 -1
  114. package/src/record/record.test.mts +4 -4
  115. package/src/utils/create-cast-fn.mts +2 -8
  116. package/src/utils/validation-error.mts +18 -3
  117. package/src/utils/validation-error.test.mts +3 -3
@@ -1,10 +1,6 @@
1
1
  import { pipe, Result } from 'ts-data-forge';
2
2
  import { type Type } from '../type.mjs';
3
- import {
4
- createType,
5
- type ValidationError,
6
- type ValidationErrorWithMessage,
7
- } from '../utils/index.mjs';
3
+ import { createType, type ValidationError } from '../utils/index.mjs';
8
4
 
9
5
  type ArrayToUnion<A extends readonly unknown[]> = A extends readonly []
10
6
  ? never
@@ -17,31 +13,35 @@ export const brand = <
17
13
  >({
18
14
  codec,
19
15
  is,
16
+ defaultValue,
17
+ typeName,
20
18
  brandKeys,
21
19
  brandFalseKeys,
22
- defaultValue,
23
20
  }: Readonly<{
24
21
  codec: Type<A>;
25
22
  is: (
26
23
  a: A,
27
24
  ) => a is Brand<A, ArrayToUnion<BrandTrueKeys>, ArrayToUnion<BrandFalseKeys>>;
28
- brandKeys: BrandTrueKeys;
29
- brandFalseKeys?: BrandFalseKeys;
30
25
  defaultValue: Brand<
31
26
  A,
32
27
  ArrayToUnion<BrandTrueKeys>,
33
28
  ArrayToUnion<BrandFalseKeys>
34
29
  >;
30
+ typeName?: string;
31
+ brandKeys: BrandTrueKeys;
32
+ brandFalseKeys?: BrandFalseKeys;
35
33
  }>): Type<
36
34
  Brand<A, ArrayToUnion<BrandTrueKeys>, ArrayToUnion<BrandFalseKeys>>
37
35
  > => {
38
36
  type T = Brand<A, ArrayToUnion<BrandTrueKeys>, ArrayToUnion<BrandFalseKeys>>;
39
37
 
40
38
  const brandKeysStr = [
41
- ...brandKeys,
42
- ...(brandFalseKeys?.map((s) => `not(${s})`) ?? []),
39
+ ...brandKeys.map((s) => `"${s}"`),
40
+ ...(brandFalseKeys?.map((s) => `not("${s}")`) ?? []),
43
41
  ].join(' & ');
44
42
 
43
+ const typeNameFilled = typeName ?? brandKeysStr;
44
+
45
45
  const validate: Type<T>['validate'] = (a) =>
46
46
  pipe(a)
47
47
  .map(codec.validate)
@@ -55,23 +55,19 @@ export const brand = <
55
55
  {
56
56
  path: [],
57
57
  actualValue: v.value,
58
- expectedType: brandKeysStr,
58
+ expectedType: typeNameFilled,
59
59
  typeName: brandKeysStr,
60
- message: `The value must satisfy the constraint corresponding to the brand keys: <${brandKeysStr}>`,
61
- } satisfies ValidationErrorWithMessage,
60
+ message:
61
+ typeName === undefined
62
+ ? `The value must satisfy the constraint corresponding to the brand keys: <${brandKeysStr}>`
63
+ : undefined,
64
+ } satisfies ValidationError,
62
65
  ]),
63
66
  ).value;
64
67
 
65
- const fill: Type<T>['fill'] = (a) =>
66
- Result.unwrapOkOr(
67
- validate(a) satisfies Result<T, unknown>,
68
- defaultValue satisfies T,
69
- ) satisfies T;
70
-
71
68
  return createType({
72
69
  typeName: brandKeysStr,
73
70
  defaultValue,
74
71
  validate,
75
- fill,
76
72
  });
77
73
  };
@@ -12,4 +12,5 @@ export const finiteNumber = (
12
12
  defaultValue,
13
13
  brandKeys: ['Finite'],
14
14
  brandFalseKeys: ['NaNValue'],
15
+ typeName: 'FiniteNumber',
15
16
  });
@@ -90,10 +90,9 @@ describe('finiteNumber', () => {
90
90
  {
91
91
  path: [],
92
92
  actualValue: Number.POSITIVE_INFINITY,
93
- expectedType: 'Finite & not(NaNValue)',
94
- typeName: 'Finite & not(NaNValue)',
95
- message:
96
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & not(NaNValue)>',
93
+ expectedType: 'FiniteNumber',
94
+ typeName: '"Finite" & not("NaNValue")',
95
+ message: undefined,
97
96
  },
98
97
  ]);
99
98
  }
@@ -115,7 +114,7 @@ describe('finiteNumber', () => {
115
114
  ]);
116
115
 
117
116
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
118
- 'Expected number, got string',
117
+ 'Expected <number>, got <string> type value "not a number".',
119
118
  ]);
120
119
  }
121
120
  });
@@ -139,7 +138,7 @@ describe('finiteNumber', () => {
139
138
  targetType.assertIs;
140
139
  expect(() => {
141
140
  assertIs(x);
142
- }).toThrow('The value must satisfy the constraint');
141
+ }).toThrow('Expected <FiniteNumber>');
143
142
  });
144
143
  });
145
144
 
@@ -10,4 +10,5 @@ export const int = (defaultValue: Int = asInt(0)): Type<Int> =>
10
10
  defaultValue,
11
11
  brandKeys: ['Finite', 'Int'],
12
12
  brandFalseKeys: ['NaNValue'],
13
+ typeName: 'Int',
13
14
  });
@@ -69,15 +69,14 @@ describe('int', () => {
69
69
  {
70
70
  path: [],
71
71
  actualValue: 42.5,
72
- expectedType: 'Finite & Int & not(NaNValue)',
73
- typeName: 'Finite & Int & not(NaNValue)',
74
- message:
75
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & not(NaNValue)>',
72
+ expectedType: 'Int',
73
+ typeName: '"Finite" & "Int" & not("NaNValue")',
74
+ message: undefined,
76
75
  },
77
76
  ]);
78
77
 
79
78
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
80
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & not(NaNValue)>',
79
+ 'Expected <Int>, got <number> type value `42.5`.',
81
80
  ]);
82
81
  }
83
82
  });
@@ -98,7 +97,7 @@ describe('int', () => {
98
97
  ]);
99
98
 
100
99
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
101
- 'Expected number, got string',
100
+ 'Expected <number>, got <string> type value "not a number".',
102
101
  ]);
103
102
  }
104
103
  });
@@ -131,7 +130,7 @@ describe('int', () => {
131
130
  targetType.assertIs;
132
131
  expect(() => {
133
132
  assertIs(x);
134
- }).toThrow('The value must satisfy the constraint');
133
+ }).toThrow('Expected <Int>');
135
134
  });
136
135
  });
137
136
 
@@ -22,4 +22,5 @@ export const int16 = (defaultValue: Int16 = asInt16(0)): Type<Int16> =>
22
22
  '>= -2^15',
23
23
  ],
24
24
  brandFalseKeys: ['NaNValue'],
25
+ typeName: 'Int16',
25
26
  });
@@ -79,16 +79,14 @@ describe('int16', () => {
79
79
  {
80
80
  path: [],
81
81
  actualValue: 50000,
82
- expectedType:
83
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & < 2^15 & < 2^16 & > -2^16 & >= -2^15 & not(NaNValue)',
82
+ expectedType: 'Int16',
84
83
  typeName:
85
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & < 2^15 & < 2^16 & > -2^16 & >= -2^15 & not(NaNValue)',
86
- message:
87
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & < 2^15 & < 2^16 & > -2^16 & >= -2^15 & not(NaNValue)>',
84
+ '"Finite" & "Int" & "SafeInt" & "> -2^32" & ">= -2^31" & "< 2^32" & "< 2^31" & "< 2^15" & "< 2^16" & "> -2^16" & ">= -2^15" & not("NaNValue")',
85
+ message: undefined,
88
86
  },
89
87
  ]);
90
88
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
91
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & < 2^15 & < 2^16 & > -2^16 & >= -2^15 & not(NaNValue)>',
89
+ 'Expected <Int16>, got <number> type value `50000`.',
92
90
  ]);
93
91
  }
94
92
  });
@@ -18,4 +18,5 @@ export const int32 = (defaultValue: Int32 = asInt32(0)): Type<Int32> =>
18
18
  '< 2^31',
19
19
  ],
20
20
  brandFalseKeys: ['NaNValue'],
21
+ typeName: 'Int32',
21
22
  });
@@ -73,16 +73,14 @@ describe('int32', () => {
73
73
  {
74
74
  path: [],
75
75
  actualValue: 3000000000,
76
- expectedType:
77
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & not(NaNValue)',
76
+ expectedType: 'Int32',
78
77
  typeName:
79
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & not(NaNValue)',
80
- message:
81
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & not(NaNValue)>',
78
+ '"Finite" & "Int" & "SafeInt" & "> -2^32" & ">= -2^31" & "< 2^32" & "< 2^31" & not("NaNValue")',
79
+ message: undefined,
82
80
  },
83
81
  ]);
84
82
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
85
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & < 2^32 & < 2^31 & not(NaNValue)>',
83
+ 'Expected <Int32>, got <number> type value `3000000000`.',
86
84
  ]);
87
85
  }
88
86
  });
@@ -15,4 +15,5 @@ export const nonNegativeFiniteNumber = (
15
15
  defaultValue,
16
16
  brandKeys: ['>=0', '> -2^16', '> -2^32', '>= -2^15', '>= -2^31', 'Finite'],
17
17
  brandFalseKeys: ['NaNValue'],
18
+ typeName: 'NonNegativeFiniteNumber',
18
19
  });
@@ -90,16 +90,14 @@ describe('nonNegativeFiniteNumber', () => {
90
90
  {
91
91
  path: [],
92
92
  actualValue: -5.5,
93
- expectedType:
94
- '>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & not(NaNValue)',
93
+ expectedType: 'NonNegativeFiniteNumber',
95
94
  typeName:
96
- '>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & not(NaNValue)',
97
- message:
98
- 'The value must satisfy the constraint corresponding to the brand keys: <>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & not(NaNValue)>',
95
+ '">=0" & "> -2^16" & "> -2^32" & ">= -2^15" & ">= -2^31" & "Finite" & not("NaNValue")',
96
+ message: undefined,
99
97
  },
100
98
  ]);
101
99
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
102
- 'The value must satisfy the constraint corresponding to the brand keys: <>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & not(NaNValue)>',
100
+ 'Expected <NonNegativeFiniteNumber>, got <number> type value `-5.5`.',
103
101
  ]);
104
102
  }
105
103
  });
@@ -12,4 +12,5 @@ export const nonZeroFiniteNumber = (
12
12
  defaultValue,
13
13
  brandKeys: ['!=0', 'Finite'],
14
14
  brandFalseKeys: ['NaNValue'],
15
+ typeName: 'NonZeroFiniteNumber',
15
16
  });
@@ -86,14 +86,13 @@ describe('nonZeroFiniteNumber', () => {
86
86
  {
87
87
  path: [],
88
88
  actualValue: 0,
89
- expectedType: '!=0 & Finite & not(NaNValue)',
90
- typeName: '!=0 & Finite & not(NaNValue)',
91
- message:
92
- 'The value must satisfy the constraint corresponding to the brand keys: <!=0 & Finite & not(NaNValue)>',
89
+ expectedType: 'NonZeroFiniteNumber',
90
+ typeName: '"!=0" & "Finite" & not("NaNValue")',
91
+ message: undefined,
93
92
  },
94
93
  ]);
95
94
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
96
- 'The value must satisfy the constraint corresponding to the brand keys: <!=0 & Finite & not(NaNValue)>',
95
+ 'Expected <NonZeroFiniteNumber>, got <number> type value `0`.',
97
96
  ]);
98
97
  }
99
98
  });
@@ -12,4 +12,5 @@ export const nonZeroInt = (
12
12
  defaultValue,
13
13
  brandKeys: ['Finite', 'Int', '!=0'],
14
14
  brandFalseKeys: ['NaNValue'],
15
+ typeName: 'NonZeroInt',
15
16
  });
@@ -79,14 +79,13 @@ describe('nonZeroInt', () => {
79
79
  {
80
80
  path: [],
81
81
  actualValue: 0,
82
- expectedType: 'Finite & Int & !=0 & not(NaNValue)',
83
- typeName: 'Finite & Int & !=0 & not(NaNValue)',
84
- message:
85
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & !=0 & not(NaNValue)>',
82
+ expectedType: 'NonZeroInt',
83
+ typeName: '"Finite" & "Int" & "!=0" & not("NaNValue")',
84
+ message: undefined,
86
85
  },
87
86
  ]);
88
87
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
89
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & !=0 & not(NaNValue)>',
88
+ 'Expected <NonZeroInt>, got <number> type value `0`.',
90
89
  ]);
91
90
  }
92
91
  });
@@ -12,4 +12,5 @@ export const nonZeroSafeInt = (
12
12
  defaultValue,
13
13
  brandKeys: ['Finite', 'Int', 'SafeInt', '!=0'],
14
14
  brandFalseKeys: ['NaNValue'],
15
+ typeName: 'NonZeroSafeInt',
15
16
  });
@@ -86,14 +86,13 @@ describe('nonZeroSafeInt', () => {
86
86
  {
87
87
  path: [],
88
88
  actualValue: 0,
89
- expectedType: 'Finite & Int & SafeInt & !=0 & not(NaNValue)',
90
- typeName: 'Finite & Int & SafeInt & !=0 & not(NaNValue)',
91
- message:
92
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & !=0 & not(NaNValue)>',
89
+ expectedType: 'NonZeroSafeInt',
90
+ typeName: '"Finite" & "Int" & "SafeInt" & "!=0" & not("NaNValue")',
91
+ message: undefined,
93
92
  },
94
93
  ]);
95
94
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
96
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & !=0 & not(NaNValue)>',
95
+ 'Expected <NonZeroSafeInt>, got <number> type value `0`.',
97
96
  ]);
98
97
  }
99
98
  });
@@ -20,4 +20,5 @@ export const positiveFiniteNumber = (
20
20
  '!=0',
21
21
  ],
22
22
  brandFalseKeys: ['NaNValue'],
23
+ typeName: 'PositiveFiniteNumber',
23
24
  });
@@ -86,16 +86,14 @@ describe('positiveFiniteNumber', () => {
86
86
  {
87
87
  path: [],
88
88
  actualValue: 0,
89
- expectedType:
90
- '>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & !=0 & not(NaNValue)',
89
+ expectedType: 'PositiveFiniteNumber',
91
90
  typeName:
92
- '>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & !=0 & not(NaNValue)',
93
- message:
94
- 'The value must satisfy the constraint corresponding to the brand keys: <>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & !=0 & not(NaNValue)>',
91
+ '">=0" & "> -2^16" & "> -2^32" & ">= -2^15" & ">= -2^31" & "Finite" & "!=0" & not("NaNValue")',
92
+ message: undefined,
95
93
  },
96
94
  ]);
97
95
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
98
- 'The value must satisfy the constraint corresponding to the brand keys: <>=0 & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & Finite & !=0 & not(NaNValue)>',
96
+ 'Expected <PositiveFiniteNumber>, got <number> type value `0`.',
99
97
  ]);
100
98
  }
101
99
  });
@@ -21,4 +21,5 @@ export const positiveInt = (
21
21
  '!=0',
22
22
  ],
23
23
  brandFalseKeys: ['NaNValue'],
24
+ typeName: 'PositiveInt',
24
25
  });
@@ -96,16 +96,14 @@ describe('positiveInt', () => {
96
96
  {
97
97
  path: [],
98
98
  actualValue: -5,
99
- expectedType:
100
- 'Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)',
99
+ expectedType: 'PositiveInt',
101
100
  typeName:
102
- 'Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)',
103
- message:
104
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)>',
101
+ '"Finite" & "Int" & "> -2^32" & ">= -2^31" & "> -2^16" & ">= -2^15" & ">=0" & "!=0" & not("NaNValue")',
102
+ message: undefined,
105
103
  },
106
104
  ]);
107
105
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
108
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)>',
106
+ 'Expected <PositiveInt>, got <number> type value `-5`.',
109
107
  ]);
110
108
  }
111
109
  });
@@ -125,7 +123,7 @@ describe('positiveInt', () => {
125
123
  },
126
124
  ]);
127
125
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
128
- 'Expected number, got string',
126
+ 'Expected <number>, got <string> type value "not a number".',
129
127
  ]);
130
128
  }
131
129
  });
@@ -149,7 +147,7 @@ describe('positiveInt', () => {
149
147
  targetType.assertIs;
150
148
  expect(() => {
151
149
  assertIs(x);
152
- }).toThrow('The value must satisfy the constraint');
150
+ }).toThrow('Expected <PositiveInt>');
153
151
  });
154
152
  });
155
153
 
@@ -22,4 +22,5 @@ export const positiveSafeInt = (
22
22
  '!=0',
23
23
  ],
24
24
  brandFalseKeys: ['NaNValue'],
25
+ typeName: 'PositiveSafeInt',
25
26
  });
@@ -90,16 +90,14 @@ describe('positiveSafeInt', () => {
90
90
  {
91
91
  path: [],
92
92
  actualValue: 0,
93
- expectedType:
94
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)',
93
+ expectedType: 'PositiveSafeInt',
95
94
  typeName:
96
- 'Finite & Int & SafeInt & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)',
97
- message:
98
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)>',
95
+ '"Finite" & "Int" & "SafeInt" & "> -2^32" & ">= -2^31" & "> -2^16" & ">= -2^15" & ">=0" & "!=0" & not("NaNValue")',
96
+ message: undefined,
99
97
  },
100
98
  ]);
101
99
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
102
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & !=0 & not(NaNValue)>',
100
+ 'Expected <PositiveSafeInt>, got <number> type value `0`.',
103
101
  ]);
104
102
  }
105
103
  });
@@ -10,4 +10,5 @@ export const safeInt = (defaultValue: SafeInt = asSafeInt(0)): Type<SafeInt> =>
10
10
  defaultValue,
11
11
  brandKeys: ['Finite', 'Int', 'SafeInt'],
12
12
  brandFalseKeys: ['NaNValue'],
13
+ typeName: 'SafeInt',
13
14
  });
@@ -78,15 +78,14 @@ describe('safeInt', () => {
78
78
  {
79
79
  path: [],
80
80
  actualValue: Number.MAX_SAFE_INTEGER + 1,
81
- expectedType: 'Finite & Int & SafeInt & not(NaNValue)',
82
- typeName: 'Finite & Int & SafeInt & not(NaNValue)',
83
- message:
84
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & not(NaNValue)>',
81
+ expectedType: 'SafeInt',
82
+ typeName: '"Finite" & "Int" & "SafeInt" & not("NaNValue")',
83
+ message: undefined,
85
84
  },
86
85
  ]);
87
86
 
88
87
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
89
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & not(NaNValue)>',
88
+ 'Expected <SafeInt>, got <number> type value `9007199254740992`.',
90
89
  ]);
91
90
  }
92
91
  });
@@ -21,4 +21,5 @@ export const safeUint = (
21
21
  '>=0',
22
22
  ],
23
23
  brandFalseKeys: ['NaNValue'],
24
+ typeName: 'SafeUint',
24
25
  });
@@ -85,16 +85,14 @@ describe('safeUint', () => {
85
85
  {
86
86
  path: [],
87
87
  actualValue: -5,
88
- expectedType:
89
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & not(NaNValue)',
88
+ expectedType: 'SafeUint',
90
89
  typeName:
91
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & not(NaNValue)',
92
- message:
93
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & not(NaNValue)>',
90
+ '"Finite" & "Int" & "SafeInt" & "> -2^16" & "> -2^32" & ">= -2^15" & ">= -2^31" & ">=0" & not("NaNValue")',
91
+ message: undefined,
94
92
  },
95
93
  ]);
96
94
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
97
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & not(NaNValue)>',
95
+ 'Expected <SafeUint>, got <number> type value `-5`.',
98
96
  ]);
99
97
  }
100
98
  });
@@ -18,4 +18,5 @@ export const uint = (defaultValue: Uint = asUint(0)): Type<Uint> =>
18
18
  '>=0',
19
19
  ],
20
20
  brandFalseKeys: ['NaNValue'],
21
+ typeName: 'Uint',
21
22
  });
@@ -91,16 +91,14 @@ describe('uint', () => {
91
91
  {
92
92
  path: [],
93
93
  actualValue: -5,
94
- expectedType:
95
- 'Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & not(NaNValue)',
94
+ expectedType: 'Uint',
96
95
  typeName:
97
- 'Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & not(NaNValue)',
98
- message:
99
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & not(NaNValue)>',
96
+ '"Finite" & "Int" & "> -2^32" & ">= -2^31" & "> -2^16" & ">= -2^15" & ">=0" & not("NaNValue")',
97
+ message: undefined,
100
98
  },
101
99
  ]);
102
100
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
103
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & > -2^32 & >= -2^31 & > -2^16 & >= -2^15 & >=0 & not(NaNValue)>',
101
+ 'Expected <Uint>, got <number> type value `-5`.',
104
102
  ]);
105
103
  }
106
104
  });
@@ -120,7 +118,7 @@ describe('uint', () => {
120
118
  },
121
119
  ]);
122
120
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
123
- 'Expected number, got string',
121
+ 'Expected <number>, got <string> type value "not a number".',
124
122
  ]);
125
123
  }
126
124
  });
@@ -144,7 +142,7 @@ describe('uint', () => {
144
142
  targetType.assertIs;
145
143
  expect(() => {
146
144
  assertIs(x);
147
- }).toThrow('The value must satisfy the constraint');
145
+ }).toThrow('Expected <Uint>');
148
146
  });
149
147
  });
150
148
 
@@ -22,4 +22,5 @@ export const uint16 = (defaultValue: Uint16 = asUint16(0)): Type<Uint16> =>
22
22
  '< 2^31',
23
23
  ],
24
24
  brandFalseKeys: ['NaNValue'],
25
+ typeName: 'Uint16',
25
26
  });
@@ -85,16 +85,14 @@ describe('uint16', () => {
85
85
  {
86
86
  path: [],
87
87
  actualValue: -5,
88
- expectedType:
89
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & < 2^16 & < 2^31 & not(NaNValue)',
88
+ expectedType: 'Uint16',
90
89
  typeName:
91
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & < 2^16 & < 2^31 & not(NaNValue)',
92
- message:
93
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & < 2^16 & < 2^31 & not(NaNValue)>',
90
+ '"Finite" & "Int" & "SafeInt" & "> -2^16" & "> -2^32" & ">= -2^15" & ">= -2^31" & ">=0" & "< 2^32" & "< 2^16" & "< 2^31" & not("NaNValue")',
91
+ message: undefined,
94
92
  },
95
93
  ]);
96
94
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
97
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & < 2^16 & < 2^31 & not(NaNValue)>',
95
+ 'Expected <Uint16>, got <number> type value `-5`.',
98
96
  ]);
99
97
  }
100
98
  });
@@ -20,4 +20,5 @@ export const uint32 = (defaultValue: Uint32 = asUint32(0)): Type<Uint32> =>
20
20
  '< 2^32',
21
21
  ],
22
22
  brandFalseKeys: ['NaNValue'],
23
+ typeName: 'Uint32',
23
24
  });
@@ -85,16 +85,14 @@ describe('uint32', () => {
85
85
  {
86
86
  path: [],
87
87
  actualValue: -5,
88
- expectedType:
89
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & not(NaNValue)',
88
+ expectedType: 'Uint32',
90
89
  typeName:
91
- 'Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & not(NaNValue)',
92
- message:
93
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & not(NaNValue)>',
90
+ '"Finite" & "Int" & "SafeInt" & "> -2^16" & "> -2^32" & ">= -2^15" & ">= -2^31" & ">=0" & "< 2^32" & not("NaNValue")',
91
+ message: undefined,
94
92
  },
95
93
  ]);
96
94
  expect(validationErrorsToMessages(result.value)).toStrictEqual([
97
- 'The value must satisfy the constraint corresponding to the brand keys: <Finite & Int & SafeInt & > -2^16 & > -2^32 & >= -2^15 & >= -2^31 & >=0 & < 2^32 & not(NaNValue)>',
95
+ 'Expected <Uint32>, got <number> type value `-5`.',
98
96
  ]);
99
97
  }
100
98
  });