pema 0.6.0 → 0.7.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.
- package/lib/private/ArrayType.d.ts +1 -1
- package/lib/private/ArrayType.js +11 -4
- package/lib/private/BuiltinType.d.ts +1 -1
- package/lib/private/BuiltinType.js +6 -2
- package/lib/private/ConstructorType.d.ts +1 -1
- package/lib/private/ConstructorType.js +3 -1
- package/lib/private/DefaultType.d.ts +1 -1
- package/lib/private/DefaultType.js +6 -5
- package/lib/private/EnumType.d.ts +1 -1
- package/lib/private/EnumType.js +5 -2
- package/lib/private/FunctionType.d.ts +1 -1
- package/lib/private/FunctionType.js +6 -3
- package/lib/private/IntType.d.ts +1 -1
- package/lib/private/IntType.js +2 -2
- package/lib/private/IsType.d.ts +1 -1
- package/lib/private/IsType.js +3 -1
- package/lib/private/JSONType.d.ts +3 -2
- package/lib/private/JSONType.js +3 -1
- package/lib/private/LiteralType.d.ts +1 -2
- package/lib/private/LiteralType.js +3 -4
- package/lib/private/Loose.d.ts +4 -0
- package/lib/private/Loose.js +3 -0
- package/lib/private/NormalizeSchema.d.ts +3 -3
- package/lib/private/NullType.d.ts +1 -1
- package/lib/private/NullType.js +5 -2
- package/lib/private/NumericType.d.ts +2 -1
- package/lib/private/ObjectType.d.ts +1 -1
- package/lib/private/ObjectType.js +18 -5
- package/lib/private/OmitType.d.ts +1 -1
- package/lib/private/OmitType.js +3 -1
- package/lib/private/OptionalType.d.ts +1 -1
- package/lib/private/OptionalType.js +6 -5
- package/lib/private/ParseError.d.ts +1 -1
- package/lib/private/ParseError.js +9 -8
- package/lib/private/ParseOptions.d.ts +2 -1
- package/lib/private/Parsed.d.ts +4 -3
- package/lib/private/Parsed.js +2 -3
- package/lib/private/PartialType.d.ts +1 -1
- package/lib/private/PartialType.js +3 -1
- package/lib/private/PrimitiveType.d.ts +1 -1
- package/lib/private/PrimitiveType.js +7 -4
- package/lib/private/PureType.d.ts +1 -1
- package/lib/private/PureType.js +2 -2
- package/lib/private/RecordType.d.ts +1 -1
- package/lib/private/RecordType.js +3 -1
- package/lib/private/Storable.d.ts +1 -0
- package/lib/private/Storable.js +4 -0
- package/lib/private/StoreType.d.ts +1 -1
- package/lib/private/StoreType.js +4 -2
- package/lib/private/TupleType.d.ts +1 -1
- package/lib/private/TupleType.js +11 -4
- package/lib/private/UUIDType.d.ts +1 -1
- package/lib/private/UUIDType.js +3 -1
- package/lib/private/UUIDV4Type.d.ts +1 -1
- package/lib/private/UUIDV4Type.js +3 -1
- package/lib/private/UUIDV7Type.d.ts +1 -1
- package/lib/private/UUIDV7Type.js +3 -1
- package/lib/private/UintType.d.ts +1 -1
- package/lib/private/UintType.js +2 -2
- package/lib/private/UnionType.d.ts +1 -1
- package/lib/private/UnionType.js +6 -4
- package/lib/private/VirtualType.js +2 -2
- package/lib/private/array.d.ts +6 -4
- package/lib/private/array.js +15 -2
- package/lib/private/blob.d.ts +6 -2
- package/lib/private/blob.js +8 -1
- package/lib/private/boolean.d.ts +6 -5
- package/lib/private/boolean.js +8 -4
- package/lib/private/coerce/date.js +3 -5
- package/lib/private/coerce/int.js +1 -1
- package/lib/private/constructor.d.ts +6 -5
- package/lib/private/constructor.js +16 -1
- package/lib/private/date.d.ts +6 -2
- package/lib/private/date.js +8 -1
- package/lib/private/dict.d.ts +12 -2
- package/lib/private/dict.js +10 -2
- package/lib/private/enum.d.ts +9 -1
- package/lib/private/enum.js +14 -1
- package/lib/private/errors.js +5 -6
- package/lib/private/f32.d.ts +6 -2
- package/lib/private/f32.js +8 -1
- package/lib/private/f64.d.ts +6 -2
- package/lib/private/f64.js +8 -1
- package/lib/private/file.d.ts +6 -2
- package/lib/private/file.js +8 -1
- package/lib/private/function.d.ts +6 -5
- package/lib/private/function.js +8 -1
- package/lib/private/i128.d.ts +6 -2
- package/lib/private/i128.js +8 -1
- package/lib/private/i16.d.ts +6 -2
- package/lib/private/i16.js +8 -1
- package/lib/private/i32.d.ts +6 -2
- package/lib/private/i32.js +8 -1
- package/lib/private/i64.d.ts +6 -2
- package/lib/private/i64.js +8 -1
- package/lib/private/i8.d.ts +6 -2
- package/lib/private/i8.js +8 -1
- package/lib/private/index.d.ts +33 -15
- package/lib/private/index.js +148 -41
- package/lib/private/is-parsed.d.ts +3 -0
- package/lib/private/is-parsed.js +7 -0
- package/lib/private/is.d.ts +6 -2
- package/lib/private/is.js +14 -1
- package/lib/private/json.d.ts +12 -2
- package/lib/private/json.js +14 -1
- package/lib/private/literal.d.ts +10 -2
- package/lib/private/literal.js +16 -1
- package/lib/private/normalize.js +4 -11
- package/lib/private/null.d.ts +6 -2
- package/lib/private/null.js +8 -1
- package/lib/private/object.d.ts +11 -4
- package/lib/private/object.js +22 -1
- package/lib/private/omit.d.ts +9 -1
- package/lib/private/omit.js +14 -1
- package/lib/private/partial.d.ts +9 -2
- package/lib/private/partial.js +16 -2
- package/lib/private/path/next.d.ts +1 -7
- package/lib/private/pure.d.ts +9 -1
- package/lib/private/pure.js +14 -1
- package/lib/private/record.d.ts +6 -5
- package/lib/private/record.js +14 -1
- package/lib/private/resolve.d.ts +2 -0
- package/lib/private/resolve.js +7 -0
- package/lib/private/spec/bigint.d.ts +4 -1
- package/lib/private/spec/bigint.js +27 -26
- package/lib/private/spec/biguint.d.ts +4 -1
- package/lib/private/spec/biguint.js +23 -22
- package/lib/private/spec/int.d.ts +4 -1
- package/lib/private/spec/int.js +24 -23
- package/lib/private/spec/uint.d.ts +4 -1
- package/lib/private/spec/uint.js +22 -21
- package/lib/private/string.d.ts +6 -5
- package/lib/private/string.js +8 -4
- package/lib/private/symbol.d.ts +6 -2
- package/lib/private/symbol.js +8 -1
- package/lib/private/test.d.ts +4 -21
- package/lib/private/test.js +0 -44
- package/lib/private/tuple.d.ts +9 -2
- package/lib/private/tuple.js +16 -1
- package/lib/private/u128.d.ts +6 -2
- package/lib/private/u128.js +8 -1
- package/lib/private/u16.d.ts +6 -2
- package/lib/private/u16.js +8 -1
- package/lib/private/u32.d.ts +6 -5
- package/lib/private/u32.js +8 -1
- package/lib/private/u64.d.ts +6 -2
- package/lib/private/u64.js +8 -1
- package/lib/private/u8.d.ts +6 -2
- package/lib/private/u8.js +8 -1
- package/lib/private/undefined.d.ts +6 -2
- package/lib/private/undefined.js +8 -1
- package/lib/private/union.d.ts +12 -3
- package/lib/private/union.js +14 -1
- package/lib/private/unknown.d.ts +6 -5
- package/lib/private/unknown.js +8 -1
- package/lib/private/url.d.ts +6 -2
- package/lib/private/url.js +8 -1
- package/lib/private/uuid.d.ts +6 -2
- package/lib/private/uuid.js +8 -1
- package/package.json +7 -6
- package/lib/private/is-parsed-type.d.ts +0 -3
- package/lib/private/is-parsed-type.js +0 -6
|
@@ -1,35 +1,36 @@
|
|
|
1
1
|
import test from "#test";
|
|
2
2
|
export default (t, min, max) => {
|
|
3
|
+
const { strict, loose } = t;
|
|
3
4
|
test.case("fail", assert => {
|
|
4
|
-
assert(
|
|
5
|
+
assert(strict).invalid_type(["1", 1.1, -1.1, 0, 1]);
|
|
5
6
|
});
|
|
6
7
|
test.case("pass", assert => {
|
|
7
|
-
assert(
|
|
8
|
-
assert(
|
|
9
|
-
assert(
|
|
8
|
+
assert(strict).type();
|
|
9
|
+
assert(strict.parse(0n)).equals(0n).type();
|
|
10
|
+
assert(strict.parse(1n)).equals(1n).type();
|
|
10
11
|
});
|
|
11
12
|
test.case("range", assert => {
|
|
12
|
-
assert(
|
|
13
|
-
assert(
|
|
14
|
-
assert(
|
|
15
|
-
});
|
|
16
|
-
test.case("
|
|
17
|
-
assert(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
20
|
-
assert(
|
|
21
|
-
assert(
|
|
22
|
-
assert(
|
|
23
|
-
assert(
|
|
24
|
-
assert(
|
|
25
|
-
assert(
|
|
26
|
-
assert(
|
|
27
|
-
assert(
|
|
28
|
-
assert(
|
|
29
|
-
assert(
|
|
13
|
+
assert(strict.parse(min)).equals(min).type();
|
|
14
|
+
assert(strict.parse(max)).equals(max).type();
|
|
15
|
+
assert(strict).out_of_range([min - 1n, max + 1n]);
|
|
16
|
+
});
|
|
17
|
+
test.case("loose", assert => {
|
|
18
|
+
assert(loose.parse(0n)).equals(0n).type();
|
|
19
|
+
assert(loose.parse(1n)).equals(1n).type();
|
|
20
|
+
assert(loose.parse(0)).equals(0n).type();
|
|
21
|
+
assert(loose.parse(1)).equals(1n).type();
|
|
22
|
+
assert(loose.parse("1")).equals(1n).type();
|
|
23
|
+
assert(loose.parse("1.0")).equals(1n).type();
|
|
24
|
+
assert(loose.parse("1.")).equals(1n).type();
|
|
25
|
+
assert(loose).invalid_type(["0.1", ".1"]);
|
|
26
|
+
assert(loose.parse(-1)).equals(-1n).type();
|
|
27
|
+
assert(loose.parse("-1")).equals(-1n).type();
|
|
28
|
+
assert(loose.parse("-1.0")).equals(-1n).type();
|
|
29
|
+
assert(loose.parse("-1.")).equals(-1n).type();
|
|
30
|
+
assert(loose).invalid_type(["-0.1", "-.1"]);
|
|
30
31
|
});
|
|
31
32
|
test.case("default", assert => {
|
|
32
|
-
[
|
|
33
|
+
[strict.default(1n), strict.default(() => 1n)].forEach(d => {
|
|
33
34
|
assert(d).type();
|
|
34
35
|
assert(d.parse(undefined)).equals(1n).type();
|
|
35
36
|
assert(d.parse(1n)).equals(1n).type();
|
|
@@ -38,21 +39,21 @@ export default (t, min, max) => {
|
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
test.case("validator - range", assert => {
|
|
41
|
-
const r =
|
|
42
|
+
const r = strict.range(-10n, 10n);
|
|
42
43
|
assert(r.parse(-10n)).equals(-10n).type();
|
|
43
44
|
assert(r.parse(0n)).equals(0n).type();
|
|
44
45
|
assert(r.parse(10n)).equals(10n).type();
|
|
45
46
|
assert(r).out_of_range([-11n, 11n]);
|
|
46
47
|
});
|
|
47
48
|
test.case("validator - min", assert => {
|
|
48
|
-
const r =
|
|
49
|
+
const r = strict.min(-10n);
|
|
49
50
|
assert(r.parse(-10n)).equals(-10n).type();
|
|
50
51
|
assert(r.parse(0n)).equals(0n).type();
|
|
51
52
|
assert(r.parse(10n)).equals(10n).type();
|
|
52
53
|
assert(r).too_small([-11n]);
|
|
53
54
|
});
|
|
54
55
|
test.case("validator - max", assert => {
|
|
55
|
-
const r =
|
|
56
|
+
const r = strict.max(10n);
|
|
56
57
|
assert(r.parse(-10n)).equals(-10n).type();
|
|
57
58
|
assert(r.parse(0n)).equals(0n).type();
|
|
58
59
|
assert(r.parse(10n)).equals(10n).type();
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type BigUintDataType from "#BigUintDataType";
|
|
2
2
|
import type BigUintType from "#BigUintType";
|
|
3
|
-
declare const _default: <T extends BigUintDataType>(t:
|
|
3
|
+
declare const _default: <T extends BigUintDataType>(t: {
|
|
4
|
+
loose: BigUintType<T>;
|
|
5
|
+
strict: BigUintType<T>;
|
|
6
|
+
}, min: bigint, max: bigint) => void;
|
|
4
7
|
export default _default;
|
|
5
8
|
//# sourceMappingURL=biguint.d.ts.map
|
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
import test from "#test";
|
|
2
2
|
export default (t, min, max) => {
|
|
3
|
+
const { strict, loose } = t;
|
|
3
4
|
test.case("fail", assert => {
|
|
4
|
-
assert(
|
|
5
|
+
assert(strict).invalid_type(["1", 0, 1, 1.1, -1.1]);
|
|
5
6
|
});
|
|
6
7
|
test.case("pass", assert => {
|
|
7
|
-
assert(
|
|
8
|
-
assert(
|
|
9
|
-
assert(
|
|
8
|
+
assert(strict).type();
|
|
9
|
+
assert(strict.parse(0n)).equals(0n).type();
|
|
10
|
+
assert(strict.parse(1n)).equals(1n).type();
|
|
10
11
|
});
|
|
11
12
|
test.case("range", assert => {
|
|
12
|
-
assert(
|
|
13
|
-
assert(
|
|
14
|
-
assert(
|
|
15
|
-
});
|
|
16
|
-
test.case("
|
|
17
|
-
assert(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
20
|
-
assert(
|
|
21
|
-
assert(
|
|
22
|
-
assert(
|
|
23
|
-
assert(
|
|
24
|
-
assert(
|
|
25
|
-
assert(
|
|
13
|
+
assert(strict.parse(min)).equals(min).type();
|
|
14
|
+
assert(strict.parse(max)).equals(max).type();
|
|
15
|
+
assert(strict).out_of_range([-1n, min - 1n, max + 1n]);
|
|
16
|
+
});
|
|
17
|
+
test.case("loose", assert => {
|
|
18
|
+
assert(loose.parse(0n)).equals(0n).type();
|
|
19
|
+
assert(loose.parse(1n)).equals(1n).type();
|
|
20
|
+
assert(loose.parse(0)).equals(0n).type();
|
|
21
|
+
assert(loose.parse(1)).equals(1n).type();
|
|
22
|
+
assert(loose.parse("1")).equals(1n).type();
|
|
23
|
+
assert(loose.parse("1.0")).equals(1n).type();
|
|
24
|
+
assert(loose.parse("1.")).equals(1n).type();
|
|
25
|
+
assert(loose).invalid_type(["0.1", .1, "-0.1", "-.1"]);
|
|
26
|
+
assert(loose).out_of_range([-1, "-1", "-1.0", "-1."]);
|
|
26
27
|
});
|
|
27
28
|
test.case("default", assert => {
|
|
28
|
-
[
|
|
29
|
+
[strict.default(1n), strict.default(() => 1n)].forEach(d => {
|
|
29
30
|
assert(d).type();
|
|
30
31
|
assert(d.parse(undefined)).equals(1n).type();
|
|
31
32
|
assert(d.parse(1n)).equals(1n).type();
|
|
@@ -34,20 +35,20 @@ export default (t, min, max) => {
|
|
|
34
35
|
});
|
|
35
36
|
});
|
|
36
37
|
test.case("validator - range", assert => {
|
|
37
|
-
const r =
|
|
38
|
+
const r = strict.range(0n, 10n);
|
|
38
39
|
assert(r.parse(0n)).equals(0n).type();
|
|
39
40
|
assert(r.parse(10n)).equals(10n).type();
|
|
40
41
|
assert(r).out_of_range([-1n, -11n, 11n]);
|
|
41
42
|
});
|
|
42
43
|
test.case("validator - min", assert => {
|
|
43
|
-
const r =
|
|
44
|
+
const r = strict.min(10n);
|
|
44
45
|
assert(r.parse(20n)).equals(20n).type();
|
|
45
46
|
assert(r.parse(10n)).equals(10n).type();
|
|
46
47
|
assert(r).out_of_range([-1n]);
|
|
47
48
|
assert(r).too_small([0n]);
|
|
48
49
|
});
|
|
49
50
|
test.case("validator - max", assert => {
|
|
50
|
-
const r =
|
|
51
|
+
const r = strict.max(10n);
|
|
51
52
|
assert(r.parse(0n)).equals(0n).type();
|
|
52
53
|
assert(r.parse(10n)).equals(10n).type();
|
|
53
54
|
assert(r).out_of_range([-1n]);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type IntDataType from "#IntDataType";
|
|
2
2
|
import type IntType from "#IntType";
|
|
3
|
-
declare const _default: <T extends IntDataType>(t:
|
|
3
|
+
declare const _default: <T extends IntDataType>(t: {
|
|
4
|
+
loose: IntType<T>;
|
|
5
|
+
strict: IntType<T>;
|
|
6
|
+
}, min: number, max: number) => void;
|
|
4
7
|
export default _default;
|
|
5
8
|
//# sourceMappingURL=int.d.ts.map
|
package/lib/private/spec/int.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
1
|
import test from "#test";
|
|
2
2
|
export default (t, min, max) => {
|
|
3
|
+
const { strict, loose } = t;
|
|
3
4
|
test.case("fail", assert => {
|
|
4
|
-
assert(
|
|
5
|
+
assert(strict).invalid_type(["1", 0n, 1n, 1.1, -1.1]);
|
|
5
6
|
});
|
|
6
7
|
test.case("pass", assert => {
|
|
7
|
-
assert(
|
|
8
|
-
assert(
|
|
9
|
-
assert(
|
|
8
|
+
assert(strict).type();
|
|
9
|
+
assert(strict.parse(0)).equals(0).type();
|
|
10
|
+
assert(strict.parse(1)).equals(1).type();
|
|
10
11
|
});
|
|
11
12
|
test.case("range", assert => {
|
|
12
|
-
assert(
|
|
13
|
-
assert(
|
|
14
|
-
assert(
|
|
15
|
-
});
|
|
16
|
-
test.case("
|
|
17
|
-
assert(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
20
|
-
assert(
|
|
21
|
-
assert(
|
|
22
|
-
assert(
|
|
23
|
-
assert(
|
|
24
|
-
assert(
|
|
25
|
-
assert(
|
|
26
|
-
assert(
|
|
13
|
+
assert(strict.parse(min)).equals(min).type();
|
|
14
|
+
assert(strict.parse(max)).equals(max).type();
|
|
15
|
+
assert(strict).out_of_range([min - 1, max + 1]);
|
|
16
|
+
});
|
|
17
|
+
test.case("loose", assert => {
|
|
18
|
+
assert(loose.parse(0)).equals(0).type();
|
|
19
|
+
assert(loose.parse(1)).equals(1).type();
|
|
20
|
+
assert(loose.parse("1")).equals(1).type();
|
|
21
|
+
assert(loose.parse("1.0")).equals(1).type();
|
|
22
|
+
assert(loose.parse("1.")).equals(1).type();
|
|
23
|
+
assert(strict).invalid_type(["0.1", ".1"]);
|
|
24
|
+
assert(loose.parse("-1")).equals(-1).type();
|
|
25
|
+
assert(loose.parse("-1.0")).equals(-1).type();
|
|
26
|
+
assert(loose.parse("-1.")).equals(-1).type();
|
|
27
|
+
assert(strict).invalid_type(["-0.1", "-.1"]);
|
|
27
28
|
});
|
|
28
29
|
test.case("default", assert => {
|
|
29
|
-
[
|
|
30
|
+
[strict.default(1), strict.default(() => 1)].forEach(d => {
|
|
30
31
|
assert(d).type();
|
|
31
32
|
assert(d.parse(undefined)).equals(1).type();
|
|
32
33
|
assert(d.parse(1)).equals(1).type();
|
|
@@ -35,21 +36,21 @@ export default (t, min, max) => {
|
|
|
35
36
|
});
|
|
36
37
|
});
|
|
37
38
|
test.case("validator - range", assert => {
|
|
38
|
-
const r =
|
|
39
|
+
const r = strict.range(-10, 10);
|
|
39
40
|
assert(r.parse(-10)).equals(-10).type();
|
|
40
41
|
assert(r.parse(0)).equals(0).type();
|
|
41
42
|
assert(r.parse(10)).equals(10).type();
|
|
42
43
|
assert(r).out_of_range([-11, 11]);
|
|
43
44
|
});
|
|
44
45
|
test.case("validator - min", assert => {
|
|
45
|
-
const r =
|
|
46
|
+
const r = strict.min(-10);
|
|
46
47
|
assert(r.parse(-10)).equals(-10).type();
|
|
47
48
|
assert(r.parse(0)).equals(0).type();
|
|
48
49
|
assert(r.parse(10)).equals(10).type();
|
|
49
50
|
assert(r).too_small([-11]);
|
|
50
51
|
});
|
|
51
52
|
test.case("validator - max", assert => {
|
|
52
|
-
const r =
|
|
53
|
+
const r = strict.max(10);
|
|
53
54
|
assert(r.parse(-10)).equals(-10).type();
|
|
54
55
|
assert(r.parse(0)).equals(0).type();
|
|
55
56
|
assert(r.parse(10)).equals(10).type();
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type UintDataType from "#UintDataType";
|
|
2
2
|
import type UintType from "#UintType";
|
|
3
|
-
declare const _default: <T extends UintDataType>(t:
|
|
3
|
+
declare const _default: <T extends UintDataType>(t: {
|
|
4
|
+
loose: UintType<T>;
|
|
5
|
+
strict: UintType<T>;
|
|
6
|
+
}, min: number, max: number) => void;
|
|
4
7
|
export default _default;
|
|
5
8
|
//# sourceMappingURL=uint.d.ts.map
|
package/lib/private/spec/uint.js
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
import test from "#test";
|
|
2
2
|
export default (t, min, max) => {
|
|
3
|
+
const { strict, loose } = t;
|
|
3
4
|
test.case("fail", assert => {
|
|
4
|
-
assert(
|
|
5
|
+
assert(strict).invalid_type(["1", 1n, 1.1, -1.1]);
|
|
5
6
|
});
|
|
6
7
|
test.case("pass", assert => {
|
|
7
|
-
assert(
|
|
8
|
-
assert(
|
|
8
|
+
assert(strict).type();
|
|
9
|
+
assert(strict.parse(1)).equals(1).type();
|
|
9
10
|
});
|
|
10
11
|
test.case("range", assert => {
|
|
11
|
-
assert(
|
|
12
|
-
assert(
|
|
13
|
-
assert(
|
|
14
|
-
assert(
|
|
15
|
-
});
|
|
16
|
-
test.case("
|
|
17
|
-
assert(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
20
|
-
assert(
|
|
21
|
-
assert(
|
|
22
|
-
assert(
|
|
23
|
-
assert(
|
|
12
|
+
assert(strict.parse(0)).equals(0).type();
|
|
13
|
+
assert(strict.parse(min)).equals(min).type();
|
|
14
|
+
assert(strict.parse(max)).equals(max).type();
|
|
15
|
+
assert(strict).out_of_range([-1, min - 1, max + 1]);
|
|
16
|
+
});
|
|
17
|
+
test.case("loose", assert => {
|
|
18
|
+
assert(loose.parse(0)).equals(0).type();
|
|
19
|
+
assert(loose.parse(1)).equals(1).type();
|
|
20
|
+
assert(loose.parse("1")).equals(1).type();
|
|
21
|
+
assert(loose.parse("1.0")).equals(1).type();
|
|
22
|
+
assert(loose.parse("1.")).equals(1).type();
|
|
23
|
+
assert(loose).invalid_type(["0.1", ".1"]);
|
|
24
|
+
assert(loose).out_of_range(["-1", "-1.0", "-1."]);
|
|
24
25
|
});
|
|
25
26
|
test.case("default", assert => {
|
|
26
|
-
[
|
|
27
|
+
[strict.default(1), strict.default(() => 1)].forEach(d => {
|
|
27
28
|
assert(d).type();
|
|
28
29
|
assert(d.parse(undefined)).equals(1).type();
|
|
29
30
|
assert(d.parse(1)).equals(1).type();
|
|
30
31
|
assert(d.parse(0)).equals(0).type();
|
|
31
32
|
assert(d).invalid_type(["1.2", "-1.2"]);
|
|
32
33
|
});
|
|
33
|
-
[
|
|
34
|
+
[strict.default(-1), strict.default(() => -1)].forEach(d => {
|
|
34
35
|
assert(d).type();
|
|
35
36
|
assert(d).out_of_range([undefined]);
|
|
36
37
|
assert(d.parse(1)).equals(1).type();
|
|
@@ -38,20 +39,20 @@ export default (t, min, max) => {
|
|
|
38
39
|
});
|
|
39
40
|
});
|
|
40
41
|
test.case("validator - range", assert => {
|
|
41
|
-
const r =
|
|
42
|
+
const r = strict.range(0, 10);
|
|
42
43
|
assert(r.parse(0)).equals(0).type();
|
|
43
44
|
assert(r.parse(10)).equals(10).type();
|
|
44
45
|
assert(r).out_of_range([-1, -11, 11]);
|
|
45
46
|
});
|
|
46
47
|
test.case("validator - min", assert => {
|
|
47
|
-
const r =
|
|
48
|
+
const r = strict.min(10);
|
|
48
49
|
assert(r.parse(20)).equals(20).type();
|
|
49
50
|
assert(r.parse(10)).equals(10).type();
|
|
50
51
|
assert(r).out_of_range([-1]);
|
|
51
52
|
assert(r).too_small([0]);
|
|
52
53
|
});
|
|
53
54
|
test.case("validator - max", assert => {
|
|
54
|
-
const r =
|
|
55
|
+
const r = strict.max(10);
|
|
55
56
|
assert(r.parse(0)).equals(0).type();
|
|
56
57
|
assert(r.parse(10)).equals(10).type();
|
|
57
58
|
assert(r).out_of_range([-1]);
|
package/lib/private/string.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import StringType from "#StringType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare const string: {
|
|
3
|
+
vanilla: StringType;
|
|
4
|
+
loose: StringType;
|
|
5
|
+
strict: StringType;
|
|
6
|
+
};
|
|
7
|
+
export default string;
|
|
7
8
|
//# sourceMappingURL=string.d.ts.map
|
package/lib/private/string.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import StringType from "#StringType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
const vanilla = new StringType();
|
|
4
|
+
const loose = new StringType();
|
|
5
|
+
loose[Loose] = true;
|
|
6
|
+
const strict = new StringType();
|
|
7
|
+
strict[Loose] = false;
|
|
8
|
+
const string = { vanilla, loose, strict };
|
|
9
|
+
export default string;
|
|
6
10
|
//# sourceMappingURL=string.js.map
|
package/lib/private/symbol.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import SymbolType from "#SymbolType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const symbol: {
|
|
3
|
+
vanilla: SymbolType;
|
|
4
|
+
loose: SymbolType;
|
|
5
|
+
strict: SymbolType;
|
|
6
|
+
};
|
|
7
|
+
export default symbol;
|
|
4
8
|
//# sourceMappingURL=symbol.d.ts.map
|
package/lib/private/symbol.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import SymbolType from "#SymbolType";
|
|
2
|
-
|
|
3
|
+
const vanilla = new SymbolType();
|
|
4
|
+
const loose = new SymbolType();
|
|
5
|
+
loose[Loose] = true;
|
|
6
|
+
const strict = new SymbolType();
|
|
7
|
+
strict[Loose] = false;
|
|
8
|
+
const symbol = { vanilla, loose, strict };
|
|
9
|
+
export default symbol;
|
|
3
10
|
//# sourceMappingURL=symbol.js.map
|
package/lib/private/test.d.ts
CHANGED
|
@@ -6,29 +6,12 @@ type IssueMatcher = {
|
|
|
6
6
|
path?: string;
|
|
7
7
|
message?: string;
|
|
8
8
|
};
|
|
9
|
+
type Shortcuts = {
|
|
10
|
+
[K in IssueType]: (inputs: unknown[], path?: JSONPointer) => void;
|
|
11
|
+
};
|
|
9
12
|
declare const _default: import("@rcompat/test/index").ExtendedTest<{
|
|
10
13
|
parse_issue: (type: IssueType, inputs: Input[]) => void;
|
|
11
|
-
coerce_issue: (type: IssueType, inputs: Input[]) => void;
|
|
12
14
|
parse_issues(input: unknown, matchers: IssueMatcher[]): void;
|
|
13
|
-
|
|
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
|
-
}>;
|
|
15
|
+
} & Shortcuts>;
|
|
33
16
|
export default _default;
|
|
34
17
|
//# sourceMappingURL=test.d.ts.map
|
package/lib/private/test.js
CHANGED
|
@@ -29,32 +29,11 @@ export default test.extend((assert, subject) => {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
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
32
|
const shortcuts = Object.fromEntries(issue_types.flatMap(type => [
|
|
52
33
|
[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
34
|
]));
|
|
55
35
|
return {
|
|
56
36
|
parse_issue,
|
|
57
|
-
coerce_issue,
|
|
58
37
|
parse_issues(input, matchers) {
|
|
59
38
|
try {
|
|
60
39
|
subject.parse(input);
|
|
@@ -78,29 +57,6 @@ export default test.extend((assert, subject) => {
|
|
|
78
57
|
}
|
|
79
58
|
}
|
|
80
59
|
},
|
|
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
60
|
...shortcuts,
|
|
105
61
|
};
|
|
106
62
|
});
|
package/lib/private/tuple.d.ts
CHANGED
|
@@ -4,6 +4,13 @@ import TupleType from "#TupleType";
|
|
|
4
4
|
type NormalizeSchemaArray<T extends Schema[]> = {
|
|
5
5
|
[K in keyof T]: NormalizeSchema<T[K]>;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
declare function vanilla<const T extends Schema[]>(...items: T): TupleType<NormalizeSchemaArray<T>>;
|
|
8
|
+
declare function loose<const T extends Schema[]>(...items: T): TupleType<NormalizeSchemaArray<T>>;
|
|
9
|
+
declare function strict<const T extends Schema[]>(...items: T): TupleType<NormalizeSchemaArray<T>>;
|
|
10
|
+
declare const tuple: {
|
|
11
|
+
vanilla: typeof vanilla;
|
|
12
|
+
loose: typeof loose;
|
|
13
|
+
strict: typeof strict;
|
|
14
|
+
};
|
|
15
|
+
export default tuple;
|
|
9
16
|
//# sourceMappingURL=tuple.d.ts.map
|
package/lib/private/tuple.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import TupleType from "#TupleType";
|
|
2
3
|
import normalize from "#normalize";
|
|
3
|
-
|
|
4
|
+
function vanilla(...items) {
|
|
4
5
|
// normalize each item so the class only sees Parsed
|
|
5
6
|
const parsed = items.map(normalize);
|
|
6
7
|
return new TupleType(parsed);
|
|
7
8
|
}
|
|
9
|
+
function loose(...items) {
|
|
10
|
+
const parsed = items.map(normalize);
|
|
11
|
+
const i = new TupleType(parsed);
|
|
12
|
+
i[Loose] = true;
|
|
13
|
+
return i;
|
|
14
|
+
}
|
|
15
|
+
function strict(...items) {
|
|
16
|
+
const parsed = items.map(normalize);
|
|
17
|
+
const i = new TupleType(parsed);
|
|
18
|
+
i[Loose] = false;
|
|
19
|
+
return i;
|
|
20
|
+
}
|
|
21
|
+
const tuple = { vanilla, loose, strict };
|
|
22
|
+
export default tuple;
|
|
8
23
|
//# sourceMappingURL=tuple.js.map
|
package/lib/private/u128.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import BigUintType from "#BigUintType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const u128: {
|
|
3
|
+
vanilla: BigUintType<"u128">;
|
|
4
|
+
loose: BigUintType<"u128">;
|
|
5
|
+
strict: BigUintType<"u128">;
|
|
6
|
+
};
|
|
7
|
+
export default u128;
|
|
4
8
|
//# sourceMappingURL=u128.d.ts.map
|
package/lib/private/u128.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import BigUintType from "#BigUintType";
|
|
2
|
+
import Loose from "#Loose";
|
|
2
3
|
import range from "#validator/range";
|
|
3
4
|
const from = 0n;
|
|
4
5
|
const to = 2n ** 128n - 1n;
|
|
5
|
-
|
|
6
|
+
const vanilla = new BigUintType("u128", [range(from, to)]);
|
|
7
|
+
const loose = new BigUintType("u128", [range(from, to)]);
|
|
8
|
+
loose[Loose] = true;
|
|
9
|
+
const strict = new BigUintType("u128", [range(from, to)]);
|
|
10
|
+
strict[Loose] = false;
|
|
11
|
+
const u128 = { vanilla, loose, strict };
|
|
12
|
+
export default u128;
|
|
6
13
|
//# sourceMappingURL=u128.js.map
|
package/lib/private/u16.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import UintType from "#UintType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const u16: {
|
|
3
|
+
vanilla: UintType<"u16">;
|
|
4
|
+
loose: UintType<"u16">;
|
|
5
|
+
strict: UintType<"u16">;
|
|
6
|
+
};
|
|
7
|
+
export default u16;
|
|
4
8
|
//# sourceMappingURL=u16.d.ts.map
|
package/lib/private/u16.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import UintType from "#UintType";
|
|
2
3
|
import range from "#validator/range";
|
|
3
4
|
const from = 0;
|
|
4
5
|
const to = 2 ** 16 - 1;
|
|
5
|
-
|
|
6
|
+
const vanilla = new UintType("u16", [range(from, to)]);
|
|
7
|
+
const loose = new UintType("u16", [range(from, to)]);
|
|
8
|
+
loose[Loose] = true;
|
|
9
|
+
const strict = new UintType("u16", [range(from, to)]);
|
|
10
|
+
strict[Loose] = false;
|
|
11
|
+
const u16 = { vanilla, loose, strict };
|
|
12
|
+
export default u16;
|
|
6
13
|
//# sourceMappingURL=u16.js.map
|
package/lib/private/u32.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import UintType from "#UintType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare const u32: {
|
|
3
|
+
vanilla: UintType<"u32">;
|
|
4
|
+
loose: UintType<"u32">;
|
|
5
|
+
strict: UintType<"u32">;
|
|
6
|
+
};
|
|
7
|
+
export default u32;
|
|
7
8
|
//# sourceMappingURL=u32.d.ts.map
|
package/lib/private/u32.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import UintType from "#UintType";
|
|
2
3
|
import range from "#validator/range";
|
|
3
4
|
const from = 0;
|
|
@@ -5,5 +6,11 @@ const to = 2 ** 32 - 1;
|
|
|
5
6
|
/**
|
|
6
7
|
* Value is an unsigned integer.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
+
const vanilla = new UintType("u32", [range(from, to)]);
|
|
10
|
+
const loose = new UintType("u32", [range(from, to)]);
|
|
11
|
+
loose[Loose] = true;
|
|
12
|
+
const strict = new UintType("u32", [range(from, to)]);
|
|
13
|
+
strict[Loose] = false;
|
|
14
|
+
const u32 = { vanilla, loose, strict };
|
|
15
|
+
export default u32;
|
|
9
16
|
//# sourceMappingURL=u32.js.map
|
package/lib/private/u64.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import BigUintType from "#BigUintType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const u64: {
|
|
3
|
+
vanilla: BigUintType<"u64">;
|
|
4
|
+
loose: BigUintType<"u64">;
|
|
5
|
+
strict: BigUintType<"u64">;
|
|
6
|
+
};
|
|
7
|
+
export default u64;
|
|
4
8
|
//# sourceMappingURL=u64.d.ts.map
|