pema 0.4.0 → 0.6.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 (264) hide show
  1. package/lib/private/ArrayType.d.ts +2 -1
  2. package/lib/private/ArrayType.js +29 -41
  3. package/lib/private/BigIntType.d.ts +2 -2
  4. package/lib/private/BigUintType.d.ts +2 -2
  5. package/lib/private/BlobType.d.ts +2 -2
  6. package/lib/private/BlobType.js +2 -2
  7. package/lib/private/BooleanType.d.ts +2 -2
  8. package/lib/private/BooleanType.js +4 -4
  9. package/lib/private/BuiltinType.d.ts +1 -2
  10. package/lib/private/BuiltinType.js +3 -8
  11. package/lib/private/ConstructorType.d.ts +5 -2
  12. package/lib/private/ConstructorType.js +7 -5
  13. package/lib/private/DataType.d.ts +5 -1
  14. package/lib/private/DateType.d.ts +2 -2
  15. package/lib/private/DateType.js +2 -2
  16. package/lib/private/DefaultType.js +3 -6
  17. package/lib/private/EnumType.d.ts +21 -0
  18. package/lib/private/EnumType.js +30 -0
  19. package/lib/private/FileType.d.ts +2 -2
  20. package/lib/private/FileType.js +2 -2
  21. package/lib/private/FunctionType.d.ts +15 -0
  22. package/lib/private/FunctionType.js +20 -0
  23. package/lib/private/GenericType.d.ts +1 -1
  24. package/lib/private/InferInputSchema.d.ts +7 -17
  25. package/lib/private/InferStore.d.ts +1 -1
  26. package/lib/private/IntType.d.ts +2 -2
  27. package/lib/private/IsType.d.ts +19 -0
  28. package/lib/private/IsType.js +29 -0
  29. package/lib/private/Issue.d.ts +3 -1
  30. package/lib/private/IssueType.d.ts +3 -0
  31. package/lib/private/IssueType.js +2 -0
  32. package/lib/private/JSONType.d.ts +26 -0
  33. package/lib/private/JSONType.js +41 -0
  34. package/lib/private/LiteralType.d.ts +5 -2
  35. package/lib/private/LiteralType.js +11 -5
  36. package/lib/private/NormalizeSchema.d.ts +4 -6
  37. package/lib/private/NullType.js +3 -5
  38. package/lib/private/NumberType.d.ts +1 -1
  39. package/lib/private/NumberType.js +1 -1
  40. package/lib/private/NumericType.d.ts +2 -2
  41. package/lib/private/ObjectType.d.ts +13 -4
  42. package/lib/private/ObjectType.js +24 -11
  43. package/lib/private/OmitType.d.ts +1 -1
  44. package/lib/private/OmitType.js +7 -6
  45. package/lib/private/ParseError.d.ts +6 -2
  46. package/lib/private/ParseError.js +25 -15
  47. package/lib/private/ParseOptions.d.ts +1 -1
  48. package/lib/private/Parsed.d.ts +2 -1
  49. package/lib/private/Parsed.js +3 -0
  50. package/lib/private/PartialType.js +8 -10
  51. package/lib/private/Partialable.d.ts +1 -1
  52. package/lib/private/PrimitiveType.d.ts +0 -1
  53. package/lib/private/PrimitiveType.js +23 -22
  54. package/lib/private/PureType.d.ts +1 -1
  55. package/lib/private/RecordType.js +14 -39
  56. package/lib/private/Schema.d.ts +1 -1
  57. package/lib/private/Serialized.d.ts +18 -4
  58. package/lib/private/{Storeable.d.ts → Storable.d.ts} +3 -3
  59. package/lib/private/{Storeable.js → Storable.js} +2 -2
  60. package/lib/private/StoreSchema.d.ts +3 -6
  61. package/lib/private/StoreType.d.ts +5 -1
  62. package/lib/private/StoreType.js +22 -2
  63. package/lib/private/StringType.d.ts +2 -3
  64. package/lib/private/StringType.js +7 -13
  65. package/lib/private/TupleType.d.ts +2 -2
  66. package/lib/private/TupleType.js +19 -14
  67. package/lib/private/Type.d.ts +1 -1
  68. package/lib/private/URLType.d.ts +2 -2
  69. package/lib/private/URLType.js +2 -2
  70. package/lib/private/UUIDType.d.ts +17 -0
  71. package/lib/private/UUIDType.js +33 -0
  72. package/lib/private/UUIDV4Type.d.ts +13 -0
  73. package/lib/private/UUIDV4Type.js +23 -0
  74. package/lib/private/UUIDV7Type.d.ts +13 -0
  75. package/lib/private/UUIDV7Type.js +23 -0
  76. package/lib/private/UintType.d.ts +2 -2
  77. package/lib/private/UnionType.d.ts +3 -3
  78. package/lib/private/UnionType.js +11 -13
  79. package/lib/private/VirtualType.js +2 -3
  80. package/lib/private/coerce/bigint.d.ts +1 -1
  81. package/lib/private/coerce/bigint.js +4 -6
  82. package/lib/private/coerce/float.d.ts +2 -0
  83. package/lib/private/coerce/float.js +8 -0
  84. package/lib/private/coerce/int.d.ts +1 -1
  85. package/lib/private/coerce/int.js +7 -5
  86. package/lib/private/constructor.d.ts +1 -1
  87. package/lib/private/dict.d.ts +11 -0
  88. package/lib/private/dict.js +6 -0
  89. package/lib/private/enum.d.ts +3 -0
  90. package/lib/private/enum.js +5 -0
  91. package/lib/private/errors.d.ts +21 -0
  92. package/lib/private/errors.js +53 -0
  93. package/lib/private/function.d.ts +7 -0
  94. package/lib/private/function.js +6 -0
  95. package/lib/private/index.d.ts +79 -30
  96. package/lib/private/index.js +20 -2
  97. package/lib/private/is.d.ts +4 -0
  98. package/lib/private/is.js +3 -0
  99. package/lib/private/json/JSONIssue.d.ts +2 -0
  100. package/lib/private/json/JSONPayload.d.ts +1 -1
  101. package/lib/private/json.d.ts +5 -0
  102. package/lib/private/json.js +5 -0
  103. package/lib/private/normalize.js +2 -3
  104. package/lib/private/object.d.ts +3 -4
  105. package/lib/private/object.js +2 -2
  106. package/lib/private/omit.d.ts +1 -1
  107. package/lib/private/path/join.d.ts +1 -1
  108. package/lib/private/path/next.d.ts +1 -1
  109. package/lib/private/path/rebase.d.ts +1 -1
  110. package/lib/private/schema-errors.d.ts +16 -0
  111. package/lib/private/schema-errors.js +17 -0
  112. package/lib/private/spec/bigint.d.ts +1 -1
  113. package/lib/private/spec/bigint.js +30 -41
  114. package/lib/private/spec/biguint.d.ts +1 -1
  115. package/lib/private/spec/biguint.js +29 -45
  116. package/lib/private/spec/int.d.ts +1 -1
  117. package/lib/private/spec/int.js +27 -38
  118. package/lib/private/spec/uint.d.ts +1 -1
  119. package/lib/private/spec/uint.js +31 -43
  120. package/lib/private/test.d.ts +34 -0
  121. package/lib/private/test.js +107 -0
  122. package/lib/private/uuid.d.ts +4 -0
  123. package/lib/private/uuid.js +3 -0
  124. package/lib/private/validator/ends-with.d.ts +1 -2
  125. package/lib/private/validator/ends-with.js +8 -10
  126. package/lib/private/validator/f32.js +3 -8
  127. package/lib/private/validator/integer.d.ts +1 -2
  128. package/lib/private/validator/integer.js +7 -11
  129. package/lib/private/validator/isotime.js +8 -10
  130. package/lib/private/validator/length.js +12 -20
  131. package/lib/private/validator/max.js +15 -16
  132. package/lib/private/validator/min.js +15 -16
  133. package/lib/private/validator/port.d.ts +1 -2
  134. package/lib/private/validator/port.js +6 -9
  135. package/lib/private/validator/range.js +7 -13
  136. package/lib/private/validator/regex.d.ts +1 -1
  137. package/lib/private/validator/regex.js +5 -9
  138. package/lib/private/validator/starts-with.d.ts +1 -2
  139. package/lib/private/validator/starts-with.js +8 -10
  140. package/lib/private/validator/unique-by.d.ts +1 -1
  141. package/lib/private/validator/unique-by.js +8 -14
  142. package/lib/private/validator/unique-with.d.ts +1 -1
  143. package/lib/private/validator/unique-with.js +3 -7
  144. package/lib/private/validator/unique.js +2 -6
  145. package/lib/private/validator/values.d.ts +1 -1
  146. package/lib/private/validator/values.js +5 -8
  147. package/lib/public/StoreType.d.ts +1 -1
  148. package/lib/public/index.d.ts +1 -9
  149. package/lib/public/index.js +0 -9
  150. package/package.json +18 -15
  151. package/lib/private/DecrementDepth.d.ts +0 -3
  152. package/lib/private/DecrementDepth.js +0 -2
  153. package/lib/private/InferSchema.d.ts +0 -20
  154. package/lib/private/InferSchema.js +0 -2
  155. package/lib/private/PrimaryType.d.ts +0 -14
  156. package/lib/private/PrimaryType.js +0 -26
  157. package/lib/private/SchemaError.d.ts +0 -4
  158. package/lib/private/SchemaError.js +0 -8
  159. package/lib/private/error/fail.d.ts +0 -3
  160. package/lib/private/error/fail.js +0 -5
  161. package/lib/private/error/schemafail.d.ts +0 -3
  162. package/lib/private/error/schemafail.js +0 -5
  163. package/lib/private/error.d.ts +0 -4
  164. package/lib/private/error.js +0 -11
  165. package/lib/private/expect.d.ts +0 -22
  166. package/lib/private/expect.js +0 -32
  167. package/lib/private/expected.d.ts +0 -3
  168. package/lib/private/expected.js +0 -11
  169. package/lib/private/primary.d.ts +0 -4
  170. package/lib/private/primary.js +0 -3
  171. package/lib/private/test/messages-of.d.ts +0 -3
  172. package/lib/private/test/messages-of.js +0 -4
  173. package/lib/private/test/paths-of.d.ts +0 -3
  174. package/lib/private/test/paths-of.js +0 -4
  175. package/lib/private/test/throws-issues.d.ts +0 -4
  176. package/lib/private/test/throws-issues.js +0 -13
  177. package/lib/private/validator/uuid.d.ts +0 -3
  178. package/lib/private/validator/uuid.js +0 -4
  179. package/lib/public/DataType.d.ts +0 -2
  180. package/lib/public/DataType.js +0 -2
  181. package/lib/public/Id.d.ts +0 -2
  182. package/lib/public/Id.js +0 -2
  183. package/lib/public/InferStore.d.ts +0 -2
  184. package/lib/public/InferStore.js +0 -2
  185. package/lib/public/InferStoreOut.d.ts +0 -2
  186. package/lib/public/InferStoreOut.js +0 -2
  187. package/lib/public/Issue.d.ts +0 -2
  188. package/lib/public/Issue.js +0 -2
  189. package/lib/public/JSONPayload.d.ts +0 -2
  190. package/lib/public/JSONPayload.js +0 -2
  191. package/lib/public/OmitType.d.ts +0 -2
  192. package/lib/public/OmitType.js +0 -2
  193. package/lib/public/Schema.d.ts +0 -2
  194. package/lib/public/Schema.js +0 -2
  195. package/lib/public/Serialized.d.ts +0 -2
  196. package/lib/public/Serialized.js +0 -2
  197. package/lib/public/StoreId.d.ts +0 -2
  198. package/lib/public/StoreId.js +0 -2
  199. package/lib/public/StoreSchema.d.ts +0 -2
  200. package/lib/public/StoreSchema.js +0 -2
  201. package/lib/public/array.d.ts +0 -3
  202. package/lib/public/array.js +0 -3
  203. package/lib/public/bigint.d.ts +0 -2
  204. package/lib/public/bigint.js +0 -2
  205. package/lib/public/biguint.d.ts +0 -2
  206. package/lib/public/biguint.js +0 -2
  207. package/lib/public/blob.d.ts +0 -2
  208. package/lib/public/blob.js +0 -2
  209. package/lib/public/boolean.d.ts +0 -3
  210. package/lib/public/boolean.js +0 -3
  211. package/lib/public/constructor.d.ts +0 -3
  212. package/lib/public/constructor.js +0 -3
  213. package/lib/public/date.d.ts +0 -2
  214. package/lib/public/date.js +0 -2
  215. package/lib/public/f32.d.ts +0 -2
  216. package/lib/public/f32.js +0 -2
  217. package/lib/public/f64.d.ts +0 -2
  218. package/lib/public/f64.js +0 -2
  219. package/lib/public/file.d.ts +0 -2
  220. package/lib/public/file.js +0 -2
  221. package/lib/public/i128.d.ts +0 -2
  222. package/lib/public/i128.js +0 -2
  223. package/lib/public/i16.d.ts +0 -2
  224. package/lib/public/i16.js +0 -2
  225. package/lib/public/i32.d.ts +0 -2
  226. package/lib/public/i32.js +0 -2
  227. package/lib/public/i64.d.ts +0 -2
  228. package/lib/public/i64.js +0 -2
  229. package/lib/public/i8.d.ts +0 -2
  230. package/lib/public/i8.js +0 -2
  231. package/lib/public/int.d.ts +0 -2
  232. package/lib/public/int.js +0 -2
  233. package/lib/public/number.d.ts +0 -3
  234. package/lib/public/number.js +0 -3
  235. package/lib/public/object.d.ts +0 -2
  236. package/lib/public/object.js +0 -2
  237. package/lib/public/optional.d.ts +0 -2
  238. package/lib/public/optional.js +0 -2
  239. package/lib/public/primary.d.ts +0 -2
  240. package/lib/public/primary.js +0 -2
  241. package/lib/public/pure.d.ts +0 -2
  242. package/lib/public/pure.js +0 -2
  243. package/lib/public/record.d.ts +0 -3
  244. package/lib/public/record.js +0 -3
  245. package/lib/public/string.d.ts +0 -3
  246. package/lib/public/string.js +0 -3
  247. package/lib/public/symbol.d.ts +0 -2
  248. package/lib/public/symbol.js +0 -2
  249. package/lib/public/u128.d.ts +0 -2
  250. package/lib/public/u128.js +0 -2
  251. package/lib/public/u16.d.ts +0 -2
  252. package/lib/public/u16.js +0 -2
  253. package/lib/public/u32.d.ts +0 -2
  254. package/lib/public/u32.js +0 -2
  255. package/lib/public/u64.d.ts +0 -2
  256. package/lib/public/u64.js +0 -2
  257. package/lib/public/u8.d.ts +0 -2
  258. package/lib/public/u8.js +0 -2
  259. package/lib/public/uint.d.ts +0 -3
  260. package/lib/public/uint.js +0 -3
  261. package/lib/public/union.d.ts +0 -3
  262. package/lib/public/union.js +0 -3
  263. package/lib/public/unknown.d.ts +0 -3
  264. package/lib/public/unknown.js +0 -2
@@ -1,73 +1,62 @@
1
- import expect from "#expect";
2
- import test from "@rcompat/test";
3
- export default (i, min, max) => {
1
+ import test from "#test";
2
+ export default (t, min, max) => {
4
3
  test.case("fail", assert => {
5
- assert(() => i.parse("1")).throws(expect("bi", "1"));
6
- assert(() => i.parse(1.1)).throws(expect("bi", 1.1));
7
- assert(() => i.parse(-1.1)).throws(expect("bi", -1.1));
8
- assert(() => i.parse(0)).throws(expect("bi", 0));
9
- assert(() => i.parse(1)).throws(expect("bi", 1));
4
+ assert(t).invalid_type(["1", 1.1, -1.1, 0, 1]);
10
5
  });
11
6
  test.case("pass", assert => {
12
- assert(i).type();
13
- assert(i.parse(0n)).equals(0n).type();
14
- assert(i.parse(1n)).equals(1n).type();
7
+ assert(t).type();
8
+ assert(t.parse(0n)).equals(0n).type();
9
+ assert(t.parse(1n)).equals(1n).type();
15
10
  });
16
11
  test.case("range", assert => {
17
- assert(i.parse(min)).equals(min).type();
18
- assert(i.parse(max)).equals(max).type();
19
- assert(() => i.parse(min - 1n)).throws(`${min - 1n} is out of range`);
20
- assert(() => i.parse(max + 1n)).throws(`${max + 1n} is out of range`);
12
+ assert(t.parse(min)).equals(min).type();
13
+ assert(t.parse(max)).equals(max).type();
14
+ assert(t).out_of_range([min - 1n, max + 1n]);
21
15
  });
22
16
  test.case("coerced", assert => {
23
- const coerced = i.coerce;
24
- assert(coerced.parse(0n)).equals(0n).type();
25
- assert(coerced.parse(1n)).equals(1n).type();
26
- assert(coerced.parse(0)).equals(0n).type();
27
- assert(coerced.parse(1)).equals(1n).type();
28
- assert(coerced.parse("1")).equals(1n).type();
29
- assert(coerced.parse("1.0")).equals(1n).type();
30
- assert(coerced.parse("1.")).equals(1n).type();
31
- assert(() => coerced.parse("0.1")).throws(expect("bi", "0.1"));
32
- assert(() => coerced.parse(".1")).throws(expect("bi", ".1"));
33
- assert(coerced.parse(-1)).equals(-1n).type();
34
- assert(coerced.parse("-1")).equals(-1n).type();
35
- assert(coerced.parse("-1.0")).equals(-1n).type();
36
- assert(coerced.parse("-1.")).equals(-1n).type();
37
- assert(() => coerced.parse("-0.1")).throws(expect("bi", "-0.1"));
38
- assert(() => coerced.parse("-.1")).throws(expect("bi", "-.1"));
17
+ assert(t.coerce(0n)).equals(0n).type();
18
+ assert(t.coerce(1n)).equals(1n).type();
19
+ assert(t.coerce(0)).equals(0n).type();
20
+ assert(t.coerce(1)).equals(1n).type();
21
+ assert(t.coerce("1")).equals(1n).type();
22
+ assert(t.coerce("1.0")).equals(1n).type();
23
+ assert(t.coerce("1.")).equals(1n).type();
24
+ assert(t).coerce_invalid_type(["0.1", ".1"]);
25
+ assert(t.coerce(-1)).equals(-1n).type();
26
+ assert(t.coerce("-1")).equals(-1n).type();
27
+ assert(t.coerce("-1.0")).equals(-1n).type();
28
+ assert(t.coerce("-1.")).equals(-1n).type();
29
+ assert(t).coerce_invalid_type(["-0.1", "-.1"]);
39
30
  });
40
31
  test.case("default", assert => {
41
- [i.default(1n), i.default(() => 1n)].forEach(d => {
32
+ [t.default(1n), t.default(() => 1n)].forEach(d => {
42
33
  assert(d).type();
43
34
  assert(d.parse(undefined)).equals(1n).type();
44
35
  assert(d.parse(1n)).equals(1n).type();
45
36
  assert(d.parse(0n)).equals(0n).type();
46
- assert(() => d.parse(1.2)).throws(expect("bi", 1.2));
47
- assert(() => d.parse(-1.2)).throws(expect("bi", -1.2));
37
+ assert(d).invalid_type([1.2, -1.2]);
48
38
  });
49
39
  });
50
40
  test.case("validator - range", assert => {
51
- const r = i.range(-10n, 10n);
41
+ const r = t.range(-10n, 10n);
52
42
  assert(r.parse(-10n)).equals(-10n).type();
53
43
  assert(r.parse(0n)).equals(0n).type();
54
44
  assert(r.parse(10n)).equals(10n).type();
55
- assert(() => r.parse(-11n)).throws("-11 is out of range");
56
- assert(() => r.parse(11n)).throws("11 is out of range");
45
+ assert(r).out_of_range([-11n, 11n]);
57
46
  });
58
47
  test.case("validator - min", assert => {
59
- const r = i.min(-10n);
48
+ const r = t.min(-10n);
60
49
  assert(r.parse(-10n)).equals(-10n).type();
61
50
  assert(r.parse(0n)).equals(0n).type();
62
51
  assert(r.parse(10n)).equals(10n).type();
63
- assert(() => r.parse(-11n)).throws("-11 is lower than min (-10)");
52
+ assert(r).too_small([-11n]);
64
53
  });
65
54
  test.case("validator - max", assert => {
66
- const r = i.max(10n);
55
+ const r = t.max(10n);
67
56
  assert(r.parse(-10n)).equals(-10n).type();
68
57
  assert(r.parse(0n)).equals(0n).type();
69
58
  assert(r.parse(10n)).equals(10n).type();
70
- assert(() => r.parse(11n)).throws("11 is greater than max (10)");
59
+ assert(r).too_large([11n]);
71
60
  });
72
61
  };
73
62
  //# sourceMappingURL=bigint.js.map
@@ -1,5 +1,5 @@
1
1
  import type BigUintDataType from "#BigUintDataType";
2
2
  import type BigUintType from "#BigUintType";
3
- declare const _default: <T extends BigUintDataType>(i: BigUintType<T>, min: bigint, max: bigint) => void;
3
+ declare const _default: <T extends BigUintDataType>(t: BigUintType<T>, min: bigint, max: bigint) => void;
4
4
  export default _default;
5
5
  //# sourceMappingURL=biguint.d.ts.map
@@ -1,73 +1,57 @@
1
- import expect from "#expect";
2
- import test from "@rcompat/test";
3
- export default (i, min, max) => {
1
+ import test from "#test";
2
+ export default (t, min, max) => {
4
3
  test.case("fail", assert => {
5
- assert(() => i.parse("1")).throws(expect("bi", "1"));
6
- assert(() => i.parse(1.1)).throws(expect("bi", 1.1));
7
- assert(() => i.parse(-1.1)).throws(expect("bi", -1.1));
8
- assert(() => i.parse(-1n)).throws("-1 is out of range");
9
- assert(() => i.parse(0)).throws(expect("bi", 0));
10
- assert(() => i.parse(1)).throws(expect("bi", 1));
4
+ assert(t).invalid_type(["1", 0, 1, 1.1, -1.1]);
11
5
  });
12
6
  test.case("pass", assert => {
13
- assert(i).type();
14
- assert(i.parse(0n)).equals(0n).type();
15
- assert(i.parse(1n)).equals(1n).type();
7
+ assert(t).type();
8
+ assert(t.parse(0n)).equals(0n).type();
9
+ assert(t.parse(1n)).equals(1n).type();
16
10
  });
17
11
  test.case("range", assert => {
18
- assert(i.parse(min)).equals(min).type();
19
- assert(i.parse(max)).equals(max).type();
20
- assert(() => i.parse(min - 1n)).throws(`${min - 1n} is out of range`);
21
- assert(() => i.parse(max + 1n)).throws(`${max + 1n} is out of range`);
12
+ assert(t.parse(min)).equals(min).type();
13
+ assert(t.parse(max)).equals(max).type();
14
+ assert(t).out_of_range([-1n, min - 1n, max + 1n]);
22
15
  });
23
16
  test.case("coerced", assert => {
24
- const coerced = i.coerce;
25
- assert(coerced.parse(0n)).equals(0n).type();
26
- assert(coerced.parse(1n)).equals(1n).type();
27
- assert(coerced.parse(0)).equals(0n).type();
28
- assert(coerced.parse(1)).equals(1n).type();
29
- assert(coerced.parse("1")).equals(1n).type();
30
- assert(coerced.parse("1.0")).equals(1n).type();
31
- assert(coerced.parse("1.")).equals(1n).type();
32
- assert(() => coerced.parse("0.1")).throws(expect("bi", "0.1"));
33
- assert(() => coerced.parse(".1")).throws(expect("bi", ".1"));
34
- assert(() => coerced.parse(-1)).throws("-1 is out of range");
35
- assert(() => coerced.parse("-1")).throws("-1 is out of range");
36
- assert(() => coerced.parse("-1.0")).throws("-1 is out of range");
37
- assert(() => coerced.parse("-1.")).throws("-1 is out of range");
38
- assert(() => coerced.parse("-0.1")).throws(expect("bi", "-0.1"));
39
- assert(() => coerced.parse("-.1")).throws(expect("bi", "-.1"));
17
+ assert(t.coerce(0n)).equals(0n).type();
18
+ assert(t.coerce(1n)).equals(1n).type();
19
+ assert(t.coerce(0)).equals(0n).type();
20
+ assert(t.coerce(1)).equals(1n).type();
21
+ assert(t.coerce("1")).equals(1n).type();
22
+ assert(t.coerce("1.0")).equals(1n).type();
23
+ assert(t.coerce("1.")).equals(1n).type();
24
+ assert(t).coerce_invalid_type(["0.1", .1, "-0.1", "-.1"]);
25
+ assert(t).coerce_out_of_range([-1, "-1", "-1.0", "-1."]);
40
26
  });
41
27
  test.case("default", assert => {
42
- [i.default(1n), i.default(() => 1n)].forEach(d => {
28
+ [t.default(1n), t.default(() => 1n)].forEach(d => {
43
29
  assert(d).type();
44
30
  assert(d.parse(undefined)).equals(1n).type();
45
31
  assert(d.parse(1n)).equals(1n).type();
46
32
  assert(d.parse(0n)).equals(0n).type();
47
- assert(() => d.parse(1.2)).throws(expect("bi", 1.2));
48
- assert(() => d.parse(-1.2)).throws(expect("bi", -1.2));
33
+ assert(d).invalid_type([1.2, -1.2]);
49
34
  });
50
35
  });
51
36
  test.case("validator - range", assert => {
52
- const r = i.range(0n, 10n);
37
+ const r = t.range(0n, 10n);
53
38
  assert(r.parse(0n)).equals(0n).type();
54
39
  assert(r.parse(10n)).equals(10n).type();
55
- assert(() => r.parse(-1n)).throws("-1 is out of range");
56
- assert(() => r.parse(-11n)).throws("-11 is out of range");
57
- assert(() => r.parse(11n)).throws("11 is out of range");
40
+ assert(r).out_of_range([-1n, -11n, 11n]);
58
41
  });
59
42
  test.case("validator - min", assert => {
60
- const r = i.min(0n);
61
- assert(r.parse(0n)).equals(0n).type();
43
+ const r = t.min(10n);
44
+ assert(r.parse(20n)).equals(20n).type();
62
45
  assert(r.parse(10n)).equals(10n).type();
63
- assert(() => r.parse(-1n)).throws("-1 is out of range");
46
+ assert(r).out_of_range([-1n]);
47
+ assert(r).too_small([0n]);
64
48
  });
65
49
  test.case("validator - max", assert => {
66
- const r = i.max(10n);
50
+ const r = t.max(10n);
67
51
  assert(r.parse(0n)).equals(0n).type();
68
52
  assert(r.parse(10n)).equals(10n).type();
69
- assert(() => r.parse(-1n)).throws("-1 is out of range");
70
- assert(() => r.parse(11n)).throws("11 is greater than max (10)");
53
+ assert(r).out_of_range([-1n]);
54
+ assert(r).too_large([11n]);
71
55
  });
72
56
  };
73
57
  //# sourceMappingURL=biguint.js.map
@@ -1,5 +1,5 @@
1
1
  import type IntDataType from "#IntDataType";
2
2
  import type IntType from "#IntType";
3
- declare const _default: <T extends IntDataType>(i: IntType<T>, min: number, max: number) => void;
3
+ declare const _default: <T extends IntDataType>(t: IntType<T>, min: number, max: number) => void;
4
4
  export default _default;
5
5
  //# sourceMappingURL=int.d.ts.map
@@ -1,70 +1,59 @@
1
- import expect from "#expect";
2
- import test from "@rcompat/test";
3
- export default (i, min, max) => {
1
+ import test from "#test";
2
+ export default (t, min, max) => {
4
3
  test.case("fail", assert => {
5
- assert(() => i.parse("1")).throws(expect("n", "1"));
6
- assert(() => i.parse(1.1)).throws("1.1 is not an integer");
7
- assert(() => i.parse(-1.1)).throws("-1.1 is not an integer");
8
- assert(() => i.parse(0n)).throws(expect("n", 0n));
9
- assert(() => i.parse(1n)).throws(expect("n", 1n));
4
+ assert(t).invalid_type(["1", 0n, 1n, 1.1, -1.1]);
10
5
  });
11
6
  test.case("pass", assert => {
12
- assert(i).type();
13
- assert(i.parse(0)).equals(0).type();
14
- assert(i.parse(1)).equals(1).type();
7
+ assert(t).type();
8
+ assert(t.parse(0)).equals(0).type();
9
+ assert(t.parse(1)).equals(1).type();
15
10
  });
16
11
  test.case("range", assert => {
17
- assert(i.parse(min)).equals(min).type();
18
- assert(i.parse(max)).equals(max).type();
19
- assert(() => i.parse(min - 1)).throws(`${min - 1} is out of range`);
20
- assert(() => i.parse(max + 1)).throws(`${max + 1} is out of range`);
12
+ assert(t.parse(min)).equals(min).type();
13
+ assert(t.parse(max)).equals(max).type();
14
+ assert(t).out_of_range([min - 1, max + 1]);
21
15
  });
22
16
  test.case("coerced", assert => {
23
- const coerced = i.coerce;
24
- assert(coerced.parse(0)).equals(0).type();
25
- assert(coerced.parse(1)).equals(1).type();
26
- assert(coerced.parse("1")).equals(1).type();
27
- assert(coerced.parse("1.0")).equals(1).type();
28
- assert(coerced.parse("1.")).equals(1).type();
29
- assert(() => coerced.parse("0.1")).throws("0.1 is not an integer");
30
- assert(() => coerced.parse(".1")).throws("0.1 is not an integer");
31
- assert(coerced.parse("-1")).equals(-1).type();
32
- assert(coerced.parse("-1.0")).equals(-1).type();
33
- assert(coerced.parse("-1.")).equals(-1).type();
34
- assert(() => coerced.parse("-0.1")).throws("-0.1 is not an integer");
35
- assert(() => coerced.parse("-.1")).throws("-0.1 is not an integer");
17
+ assert(t.coerce(0)).equals(0).type();
18
+ assert(t.coerce(1)).equals(1).type();
19
+ assert(t.coerce("1")).equals(1).type();
20
+ assert(t.coerce("1.0")).equals(1).type();
21
+ assert(t.coerce("1.")).equals(1).type();
22
+ assert(t).invalid_type(["0.1", ".1"]);
23
+ assert(t.coerce("-1")).equals(-1).type();
24
+ assert(t.coerce("-1.0")).equals(-1).type();
25
+ assert(t.coerce("-1.")).equals(-1).type();
26
+ assert(t).invalid_type(["-0.1", "-.1"]);
36
27
  });
37
28
  test.case("default", assert => {
38
- [i.default(1), i.default(() => 1)].forEach(d => {
29
+ [t.default(1), t.default(() => 1)].forEach(d => {
39
30
  assert(d).type();
40
31
  assert(d.parse(undefined)).equals(1).type();
41
32
  assert(d.parse(1)).equals(1).type();
42
33
  assert(d.parse(0)).equals(0).type();
43
- assert(() => d.parse(1.2)).throws("1.2 is not an integer");
44
- assert(() => d.parse(-1.2)).throws("-1.2 is not an integer");
34
+ assert(d).invalid_type(["1.2", "-1.2"]);
45
35
  });
46
36
  });
47
37
  test.case("validator - range", assert => {
48
- const r = i.range(-10, 10);
38
+ const r = t.range(-10, 10);
49
39
  assert(r.parse(-10)).equals(-10).type();
50
40
  assert(r.parse(0)).equals(0).type();
51
41
  assert(r.parse(10)).equals(10).type();
52
- assert(() => r.parse(-11)).throws("-11 is out of range");
53
- assert(() => r.parse(11)).throws("11 is out of range");
42
+ assert(r).out_of_range([-11, 11]);
54
43
  });
55
44
  test.case("validator - min", assert => {
56
- const r = i.min(-10);
45
+ const r = t.min(-10);
57
46
  assert(r.parse(-10)).equals(-10).type();
58
47
  assert(r.parse(0)).equals(0).type();
59
48
  assert(r.parse(10)).equals(10).type();
60
- assert(() => r.parse(-11)).throws("-11 is lower than min (-10)");
49
+ assert(r).too_small([-11]);
61
50
  });
62
51
  test.case("validator - max", assert => {
63
- const r = i.max(10);
52
+ const r = t.max(10);
64
53
  assert(r.parse(-10)).equals(-10).type();
65
54
  assert(r.parse(0)).equals(0).type();
66
55
  assert(r.parse(10)).equals(10).type();
67
- assert(() => r.parse(11)).throws("11 is greater than max (10)");
56
+ assert(r).too_large([11]);
68
57
  });
69
58
  };
70
59
  //# sourceMappingURL=int.js.map
@@ -1,5 +1,5 @@
1
1
  import type UintDataType from "#UintDataType";
2
2
  import type UintType from "#UintType";
3
- declare const _default: <T extends UintDataType>(i: UintType<T>, min: number, max: number) => void;
3
+ declare const _default: <T extends UintDataType>(t: UintType<T>, min: number, max: number) => void;
4
4
  export default _default;
5
5
  //# sourceMappingURL=uint.d.ts.map
@@ -1,73 +1,61 @@
1
- import expect from "#expect";
2
- import test from "@rcompat/test";
3
- export default (i, min, max) => {
1
+ import test from "#test";
2
+ export default (t, min, max) => {
4
3
  test.case("fail", assert => {
5
- assert(() => i.parse("1")).throws(expect("n", "1"));
6
- assert(() => i.parse(1.1)).throws("1.1 is not an integer");
7
- assert(() => i.parse(-1.1)).throws("-1.1 is not an integer");
8
- assert(() => i.parse(-1)).throws("-1 is out of range");
9
- assert(() => i.parse(1n)).throws(expect("n", 1n));
4
+ assert(t).invalid_type(["1", 1n, 1.1, -1.1]);
10
5
  });
11
6
  test.case("pass", assert => {
12
- assert(i).type();
13
- assert(i.parse(1)).equals(1).type();
7
+ assert(t).type();
8
+ assert(t.parse(1)).equals(1).type();
14
9
  });
15
10
  test.case("range", assert => {
16
- assert(i.parse(0)).equals(0).type();
17
- assert(i.parse(min)).equals(min).type();
18
- assert(i.parse(max)).equals(max).type();
19
- assert(() => i.parse(min - 1)).throws(`${min - 1} is out of range`);
20
- assert(() => i.parse(max + 1)).throws(`${max + 1} is out of range`);
21
- });
22
- test.case("coerced", assert => {
23
- const coerced = i.coerce;
24
- assert(coerced.parse(0)).equals(0).type();
25
- assert(coerced.parse(1)).equals(1).type();
26
- assert(coerced.parse("1")).equals(1).type();
27
- assert(coerced.parse("1.0")).equals(1).type();
28
- assert(coerced.parse("1.")).equals(1).type();
29
- assert(() => coerced.parse("0.1")).throws("0.1 is not an integer");
30
- assert(() => coerced.parse(".1")).throws("0.1 is not an integer");
31
- assert(() => coerced.parse("-1")).throws("-1 is out of range");
32
- assert(() => coerced.parse("-1.0")).throws("-1 is out of range");
33
- assert(() => coerced.parse("-1.")).throws("-1 is out of range");
11
+ assert(t.parse(0)).equals(0).type();
12
+ assert(t.parse(min)).equals(min).type();
13
+ assert(t.parse(max)).equals(max).type();
14
+ assert(t).out_of_range([-1, min - 1, max + 1]);
15
+ });
16
+ test.case("coerce", assert => {
17
+ assert(t.coerce(0)).equals(0).type();
18
+ assert(t.coerce(1)).equals(1).type();
19
+ assert(t.coerce("1")).equals(1).type();
20
+ assert(t.coerce("1.0")).equals(1).type();
21
+ assert(t.coerce("1.")).equals(1).type();
22
+ assert(t).coerce_invalid_type(["0.1", ".1"]);
23
+ assert(t).coerce_out_of_range(["-1", "-1.0", "-1."]);
34
24
  });
35
25
  test.case("default", assert => {
36
- [i.default(1), i.default(() => 1)].forEach(d => {
26
+ [t.default(1), t.default(() => 1)].forEach(d => {
37
27
  assert(d).type();
38
28
  assert(d.parse(undefined)).equals(1).type();
39
29
  assert(d.parse(1)).equals(1).type();
40
30
  assert(d.parse(0)).equals(0).type();
41
- assert(() => d.parse(1.2)).throws("1.2 is not an integer");
42
- assert(() => d.parse(-1.2)).throws("-1.2 is not an integer");
31
+ assert(d).invalid_type(["1.2", "-1.2"]);
43
32
  });
44
- [i.default(-1), i.default(() => -1)].forEach(d => {
33
+ [t.default(-1), t.default(() => -1)].forEach(d => {
45
34
  assert(d).type();
46
- assert(() => d.parse(undefined)).throws("-1 is out of range");
35
+ assert(d).out_of_range([undefined]);
47
36
  assert(d.parse(1)).equals(1).type();
48
37
  assert(d.parse(0)).equals(0).type();
49
38
  });
50
39
  });
51
40
  test.case("validator - range", assert => {
52
- const r = i.range(0, 10);
41
+ const r = t.range(0, 10);
53
42
  assert(r.parse(0)).equals(0).type();
54
43
  assert(r.parse(10)).equals(10).type();
55
- assert(() => r.parse(-1)).throws("-1 is out of range");
56
- assert(() => r.parse(-11)).throws("-11 is out of range");
57
- assert(() => r.parse(11)).throws("11 is out of range");
44
+ assert(r).out_of_range([-1, -11, 11]);
58
45
  });
59
46
  test.case("validator - min", assert => {
60
- const r = i.min(0);
61
- assert(r.parse(0)).equals(0).type();
47
+ const r = t.min(10);
48
+ assert(r.parse(20)).equals(20).type();
62
49
  assert(r.parse(10)).equals(10).type();
63
- assert(() => r.parse(-1)).throws("-1 is out of range");
50
+ assert(r).out_of_range([-1]);
51
+ assert(r).too_small([0]);
64
52
  });
65
53
  test.case("validator - max", assert => {
66
- const r = i.max(10);
54
+ const r = t.max(10);
67
55
  assert(r.parse(0)).equals(0).type();
68
56
  assert(r.parse(10)).equals(10).type();
69
- assert(() => r.parse(-1)).throws("-1 is out of range");
70
- assert(() => r.parse(11)).throws("11 is greater than max (10)");
57
+ assert(r).out_of_range([-1]);
58
+ assert(r).too_large([11]);
71
59
  });
72
60
  };
73
61
  //# sourceMappingURL=uint.js.map
@@ -0,0 +1,34 @@
1
+ import type IssueType from "#IssueType";
2
+ import type { JSONPointer } from "@rcompat/type";
3
+ type Input = [unknown, string?];
4
+ type IssueMatcher = {
5
+ type: IssueType;
6
+ path?: string;
7
+ message?: string;
8
+ };
9
+ declare const _default: import("@rcompat/test/index").ExtendedTest<{
10
+ parse_issue: (type: IssueType, inputs: Input[]) => void;
11
+ coerce_issue: (type: IssueType, inputs: Input[]) => void;
12
+ parse_issues(input: unknown, matchers: IssueMatcher[]): void;
13
+ coerce_issues(input: unknown, matchers: IssueMatcher[]): void;
14
+ } & {
15
+ invalid_type: (inputs: unknown[], path?: JSONPointer) => void;
16
+ invalid_format: (inputs: unknown[], path?: JSONPointer) => void;
17
+ too_small: (inputs: unknown[], path?: JSONPointer) => void;
18
+ too_large: (inputs: unknown[], path?: JSONPointer) => void;
19
+ out_of_range: (inputs: unknown[], path?: JSONPointer) => void;
20
+ not_in_set: (inputs: unknown[], path?: JSONPointer) => void;
21
+ duplicate: (inputs: unknown[], path?: JSONPointer) => void;
22
+ network_error: (inputs: unknown[], path?: JSONPointer) => void;
23
+ } & {
24
+ coerce_invalid_type: (inputs: unknown[], path?: JSONPointer) => void;
25
+ coerce_invalid_format: (inputs: unknown[], path?: JSONPointer) => void;
26
+ coerce_too_small: (inputs: unknown[], path?: JSONPointer) => void;
27
+ coerce_too_large: (inputs: unknown[], path?: JSONPointer) => void;
28
+ coerce_out_of_range: (inputs: unknown[], path?: JSONPointer) => void;
29
+ coerce_not_in_set: (inputs: unknown[], path?: JSONPointer) => void;
30
+ coerce_duplicate: (inputs: unknown[], path?: JSONPointer) => void;
31
+ coerce_network_error: (inputs: unknown[], path?: JSONPointer) => void;
32
+ }>;
33
+ export default _default;
34
+ //# sourceMappingURL=test.d.ts.map
@@ -0,0 +1,107 @@
1
+ import ParseError from "#ParseError";
2
+ import test from "@rcompat/test";
3
+ const issue_types = [
4
+ "invalid_type",
5
+ "invalid_format",
6
+ "too_small",
7
+ "too_large",
8
+ "out_of_range",
9
+ "not_in_set",
10
+ "duplicate",
11
+ ];
12
+ export default test.extend((assert, subject) => {
13
+ const parse_issue = (type, inputs) => {
14
+ for (const [input, path] of inputs) {
15
+ try {
16
+ subject.parse(input);
17
+ assert("[did not throw]").equals("[threw]");
18
+ }
19
+ catch (e) {
20
+ if (ParseError.is(e)) {
21
+ const issue = e.issues[0];
22
+ assert(issue.type).equals(type);
23
+ if (path !== undefined)
24
+ assert(issue.path).equals(path);
25
+ }
26
+ else {
27
+ throw e;
28
+ }
29
+ }
30
+ }
31
+ };
32
+ const coerce_issue = (type, inputs) => {
33
+ for (const [input, path] of inputs) {
34
+ try {
35
+ subject.coerce(input);
36
+ assert("[did not throw]").equals("[threw]");
37
+ }
38
+ catch (e) {
39
+ if (ParseError.is(e)) {
40
+ const issue = e.issues[0];
41
+ assert(issue.type).equals(type);
42
+ if (path !== undefined)
43
+ assert(issue.path).equals(path);
44
+ }
45
+ else {
46
+ throw e;
47
+ }
48
+ }
49
+ }
50
+ };
51
+ const shortcuts = Object.fromEntries(issue_types.flatMap(type => [
52
+ [type, (inputs, path = "") => parse_issue(type, inputs.map(input => [input, path]))],
53
+ [`coerce_${type}`, (inputs, path = "") => coerce_issue(type, inputs.map(input => [input, path]))],
54
+ ]));
55
+ return {
56
+ parse_issue,
57
+ coerce_issue,
58
+ parse_issues(input, matchers) {
59
+ try {
60
+ subject.parse(input);
61
+ assert("[did not throw]").equals("[threw]");
62
+ }
63
+ catch (e) {
64
+ if (ParseError.is(e)) {
65
+ assert(e.issues.length).equals(matchers.length);
66
+ for (let i = 0; i < matchers.length; i++) {
67
+ assert(e.issues[i].type).equals(matchers[i].type);
68
+ if (matchers[i].path !== undefined) {
69
+ assert(e.issues[i].path).equals(matchers[i].path);
70
+ }
71
+ if (matchers[i].message !== undefined) {
72
+ assert(e.issues[i].message).equals(matchers[i].message);
73
+ }
74
+ }
75
+ }
76
+ else {
77
+ throw e;
78
+ }
79
+ }
80
+ },
81
+ coerce_issues(input, matchers) {
82
+ try {
83
+ subject.coerce(input);
84
+ assert("[did not throw]").equals("[threw]");
85
+ }
86
+ catch (e) {
87
+ if (ParseError.is(e)) {
88
+ assert(e.issues.length).equals(matchers.length);
89
+ for (let i = 0; i < matchers.length; i++) {
90
+ assert(e.issues[i].type).equals(matchers[i].type);
91
+ if (matchers[i].path !== undefined) {
92
+ assert(e.issues[i].path).equals(matchers[i].path);
93
+ }
94
+ if (matchers[i].message !== undefined) {
95
+ assert(e.issues[i].message).equals(matchers[i].message);
96
+ }
97
+ }
98
+ }
99
+ else {
100
+ throw e;
101
+ }
102
+ }
103
+ },
104
+ ...shortcuts,
105
+ };
106
+ });
107
+ //# sourceMappingURL=test.js.map
@@ -0,0 +1,4 @@
1
+ import UUIDType from "#UUIDType";
2
+ declare const _default: UUIDType;
3
+ export default _default;
4
+ //# sourceMappingURL=uuid.d.ts.map
@@ -0,0 +1,3 @@
1
+ import UUIDType from "#UUIDType";
2
+ export default new UUIDType();
3
+ //# sourceMappingURL=uuid.js.map
@@ -1,4 +1,3 @@
1
1
  import type Validator from "#Validator";
2
- declare const _default: (suffix: string) => Validator<string>;
3
- export default _default;
2
+ export default function ends_with(suffix: string): Validator<string>;
4
3
  //# sourceMappingURL=ends-with.d.ts.map
@@ -1,11 +1,9 @@
1
- import ParseError from "#ParseError";
2
- export default (suffix) => (x) => {
3
- if (!x.endsWith(suffix)) {
4
- throw new ParseError([{
5
- input: x,
6
- message: `"${x}" does not end with "${suffix}"`,
7
- path: "",
8
- }]);
9
- }
10
- };
1
+ import E from "#errors";
2
+ export default function ends_with(suffix) {
3
+ return (x) => {
4
+ if (!x.endsWith(suffix)) {
5
+ throw E.invalid_format(x, `"${x}" does not end with "${suffix}"`);
6
+ }
7
+ };
8
+ }
11
9
  //# sourceMappingURL=ends-with.js.map
@@ -1,11 +1,6 @@
1
- import ParseError from "#ParseError";
1
+ import E from "#errors";
2
2
  export default function f32(x) {
3
- if (x !== new Float32Array([x])[0]) {
4
- throw new ParseError([{
5
- input: x,
6
- message: `${x} is not a 32-bit float`,
7
- path: "",
8
- }]);
9
- }
3
+ if (x !== new Float32Array([x])[0])
4
+ throw E.out_of_range(x, `${x} is not a 32-bit float`);
10
5
  }
11
6
  //# sourceMappingURL=f32.js.map