pema 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/private/ArrayType.d.ts +1 -0
- package/lib/private/ArrayType.js +23 -27
- package/lib/private/BuiltinType.d.ts +0 -1
- package/lib/private/BuiltinType.js +2 -5
- package/lib/private/ConstructorType.d.ts +4 -1
- package/lib/private/ConstructorType.js +6 -2
- package/lib/private/DataType.d.ts +5 -0
- package/lib/private/DefaultType.js +3 -6
- package/lib/private/EnumType.d.ts +21 -0
- package/lib/private/EnumType.js +30 -0
- package/lib/private/FunctionType.d.ts +15 -0
- package/lib/private/FunctionType.js +20 -0
- package/lib/private/IsType.d.ts +19 -0
- package/lib/private/IsType.js +29 -0
- package/lib/private/Issue.d.ts +2 -0
- package/lib/private/IssueType.d.ts +3 -0
- package/lib/private/IssueType.js +2 -0
- package/lib/private/JSONType.d.ts +27 -0
- package/lib/private/JSONType.js +41 -0
- package/lib/private/LiteralType.d.ts +4 -0
- package/lib/private/LiteralType.js +10 -2
- package/lib/private/NormalizeSchema.d.ts +1 -1
- package/lib/private/NullType.js +2 -2
- package/lib/private/NumberType.d.ts +1 -1
- package/lib/private/NumberType.js +1 -1
- package/lib/private/ObjectType.d.ts +13 -4
- package/lib/private/ObjectType.js +18 -5
- package/lib/private/OmitType.js +4 -3
- package/lib/private/ParseError.d.ts +5 -1
- package/lib/private/ParseError.js +23 -13
- package/lib/private/Parsed.d.ts +1 -0
- package/lib/private/Parsed.js +3 -0
- package/lib/private/PartialType.js +5 -4
- package/lib/private/PrimitiveType.d.ts +0 -1
- package/lib/private/PrimitiveType.js +6 -14
- package/lib/private/RecordType.js +8 -27
- package/lib/private/Serialized.d.ts +18 -1
- package/lib/private/Storable.d.ts +2 -2
- package/lib/private/StoreType.js +2 -2
- package/lib/private/StringType.d.ts +0 -1
- package/lib/private/StringType.js +5 -11
- package/lib/private/TupleType.js +10 -8
- package/lib/private/UUIDType.d.ts +17 -0
- package/lib/private/UUIDType.js +33 -0
- package/lib/private/UUIDV4Type.d.ts +13 -0
- package/lib/private/UUIDV4Type.js +23 -0
- package/lib/private/UUIDV7Type.d.ts +13 -0
- package/lib/private/UUIDV7Type.js +23 -0
- package/lib/private/UnionType.js +5 -5
- package/lib/private/coerce/bigint.d.ts +1 -1
- package/lib/private/coerce/bigint.js +1 -1
- package/lib/private/coerce/float.d.ts +2 -0
- package/lib/private/coerce/float.js +8 -0
- package/lib/private/coerce/int.d.ts +1 -1
- package/lib/private/coerce/int.js +6 -3
- package/lib/private/enum.d.ts +3 -0
- package/lib/private/enum.js +5 -0
- package/lib/private/errors.d.ts +21 -0
- package/lib/private/errors.js +53 -0
- package/lib/private/function.d.ts +7 -0
- package/lib/private/function.js +6 -0
- package/lib/private/index.d.ts +79 -32
- package/lib/private/index.js +14 -0
- package/lib/private/is.d.ts +4 -0
- package/lib/private/is.js +3 -0
- package/lib/private/json/JSONIssue.d.ts +2 -0
- package/lib/private/json.d.ts +5 -0
- package/lib/private/json.js +5 -0
- package/lib/private/object.d.ts +1 -1
- package/lib/private/object.js +2 -2
- package/lib/private/schema-errors.d.ts +16 -0
- package/lib/private/schema-errors.js +17 -0
- package/lib/private/spec/bigint.d.ts +1 -1
- package/lib/private/spec/bigint.js +30 -41
- package/lib/private/spec/biguint.d.ts +1 -1
- package/lib/private/spec/biguint.js +29 -45
- package/lib/private/spec/int.d.ts +1 -1
- package/lib/private/spec/int.js +27 -38
- package/lib/private/spec/uint.d.ts +1 -1
- package/lib/private/spec/uint.js +31 -43
- package/lib/private/test.d.ts +34 -0
- package/lib/private/test.js +107 -0
- package/lib/private/uuid.d.ts +4 -0
- package/lib/private/uuid.js +3 -0
- package/lib/private/validator/ends-with.d.ts +1 -2
- package/lib/private/validator/ends-with.js +8 -10
- package/lib/private/validator/f32.js +3 -8
- package/lib/private/validator/integer.d.ts +1 -2
- package/lib/private/validator/integer.js +6 -10
- package/lib/private/validator/isotime.js +8 -10
- package/lib/private/validator/length.js +11 -19
- package/lib/private/validator/max.js +14 -15
- package/lib/private/validator/min.js +14 -15
- package/lib/private/validator/port.d.ts +1 -2
- package/lib/private/validator/port.js +6 -9
- package/lib/private/validator/range.js +5 -11
- package/lib/private/validator/regex.d.ts +1 -1
- package/lib/private/validator/regex.js +5 -9
- package/lib/private/validator/starts-with.d.ts +1 -2
- package/lib/private/validator/starts-with.js +8 -10
- package/lib/private/validator/unique-by.d.ts +1 -1
- package/lib/private/validator/unique-by.js +8 -14
- package/lib/private/validator/unique-with.d.ts +1 -1
- package/lib/private/validator/unique-with.js +3 -7
- package/lib/private/validator/unique.js +2 -6
- package/lib/private/validator/values.js +2 -6
- package/lib/public/StoreType.d.ts +1 -1
- package/lib/public/index.d.ts +1 -28
- package/lib/public/index.js +0 -16
- package/package.json +10 -9
- package/lib/private/SchemaError.d.ts +0 -4
- package/lib/private/SchemaError.js +0 -8
- package/lib/private/error/fail.d.ts +0 -3
- package/lib/private/error/fail.js +0 -5
- package/lib/private/error/schemafail.d.ts +0 -3
- package/lib/private/error/schemafail.js +0 -5
- package/lib/private/error.d.ts +0 -4
- package/lib/private/error.js +0 -11
- package/lib/private/expect.d.ts +0 -22
- package/lib/private/expect.js +0 -32
- package/lib/private/expected.d.ts +0 -3
- package/lib/private/expected.js +0 -11
- package/lib/private/fail.d.ts +0 -4
- package/lib/private/fail.js +0 -6
- package/lib/private/test/messages-of.d.ts +0 -3
- package/lib/private/test/messages-of.js +0 -4
- package/lib/private/test/paths-of.d.ts +0 -3
- package/lib/private/test/paths-of.js +0 -4
- package/lib/private/test/throws-issues.d.ts +0 -4
- package/lib/private/test/throws-issues.js +0 -13
- package/lib/private/validator/uuid.d.ts +0 -3
- package/lib/private/validator/uuid.js +0 -4
package/lib/private/spec/int.js
CHANGED
|
@@ -1,70 +1,59 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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(
|
|
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(
|
|
13
|
-
assert(
|
|
14
|
-
assert(
|
|
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(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
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
|
-
|
|
24
|
-
assert(
|
|
25
|
-
assert(
|
|
26
|
-
assert(
|
|
27
|
-
assert(
|
|
28
|
-
assert(
|
|
29
|
-
assert(
|
|
30
|
-
assert(
|
|
31
|
-
assert(
|
|
32
|
-
assert(
|
|
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
|
-
[
|
|
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(
|
|
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 =
|
|
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(
|
|
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 =
|
|
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(
|
|
49
|
+
assert(r).too_small([-11]);
|
|
61
50
|
});
|
|
62
51
|
test.case("validator - max", assert => {
|
|
63
|
-
const r =
|
|
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(
|
|
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>(
|
|
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
|
package/lib/private/spec/uint.js
CHANGED
|
@@ -1,73 +1,61 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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(
|
|
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(
|
|
13
|
-
assert(
|
|
7
|
+
assert(t).type();
|
|
8
|
+
assert(t.parse(1)).equals(1).type();
|
|
14
9
|
});
|
|
15
10
|
test.case("range", assert => {
|
|
16
|
-
assert(
|
|
17
|
-
assert(
|
|
18
|
-
assert(
|
|
19
|
-
assert(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
assert(
|
|
25
|
-
assert(
|
|
26
|
-
assert(
|
|
27
|
-
assert(
|
|
28
|
-
assert(
|
|
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
|
-
[
|
|
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(
|
|
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
|
-
[
|
|
33
|
+
[t.default(-1), t.default(() => -1)].forEach(d => {
|
|
45
34
|
assert(d).type();
|
|
46
|
-
assert(
|
|
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 =
|
|
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(
|
|
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 =
|
|
61
|
-
assert(r.parse(
|
|
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(
|
|
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 =
|
|
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(
|
|
70
|
-
assert(
|
|
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
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default (suffix)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
export default function f32(x) {
|
|
3
|
-
if (x !== new Float32Array([x])[0])
|
|
4
|
-
throw
|
|
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
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
import is from "@rcompat/is";
|
|
3
|
-
export default (x)
|
|
4
|
-
if (!is.int(x))
|
|
5
|
-
throw
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
path: "",
|
|
9
|
-
}]);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
3
|
+
export default function integer(x) {
|
|
4
|
+
if (!is.int(x))
|
|
5
|
+
throw E.invalid_type(x, `${x} is not an integer`);
|
|
6
|
+
}
|
|
7
|
+
;
|
|
12
8
|
//# sourceMappingURL=integer.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
import regex from "#validator/regex";
|
|
3
3
|
const ISOTIME = /^T?(?<hour>\d{2}):?(?<minute>\d{2}):?(?<second>\d{2})$/u;
|
|
4
4
|
const RANGE = {
|
|
@@ -6,25 +6,23 @@ const RANGE = {
|
|
|
6
6
|
minute: { max: 59, min: 0 },
|
|
7
7
|
second: { max: 60, min: 0 },
|
|
8
8
|
};
|
|
9
|
+
function validator(s) {
|
|
10
|
+
return `"${s}" is not a valid ISO time`;
|
|
11
|
+
}
|
|
9
12
|
export default function isotime(x) {
|
|
10
13
|
// check format
|
|
11
|
-
regex(ISOTIME,
|
|
14
|
+
regex(ISOTIME, validator)(x);
|
|
12
15
|
// check range
|
|
13
16
|
const match = ISOTIME.exec(x);
|
|
14
17
|
const g = match.groups;
|
|
15
18
|
const h = Number(g.hour);
|
|
16
19
|
const m = Number(g.minute);
|
|
17
20
|
const s = Number(g.second);
|
|
18
|
-
const
|
|
21
|
+
const in_range = h >= RANGE.hour.min && h <= RANGE.hour.max &&
|
|
19
22
|
m >= RANGE.minute.min && m <= RANGE.minute.max &&
|
|
20
23
|
s >= RANGE.second.min && s <= RANGE.second.max;
|
|
21
|
-
if (!
|
|
22
|
-
throw
|
|
23
|
-
input: x,
|
|
24
|
-
message: `"${x}" is not a valid ISO time`,
|
|
25
|
-
path: "",
|
|
26
|
-
}]);
|
|
27
|
-
}
|
|
24
|
+
if (!in_range)
|
|
25
|
+
throw E.out_of_range(x, validator(x));
|
|
28
26
|
}
|
|
29
27
|
;
|
|
30
28
|
//# sourceMappingURL=isotime.js.map
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import ParseError from "#ParseError";
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
4
3
|
import is from "@rcompat/is";
|
|
5
4
|
export default function length(from, to) {
|
|
6
|
-
if (!is.finite(from) || !is.finite(to))
|
|
7
|
-
throw
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (from > to) {
|
|
13
|
-
throw schemafail("length: {0} must be lower than {1}", from, to);
|
|
14
|
-
}
|
|
5
|
+
if (!is.finite(from) || !is.finite(to))
|
|
6
|
+
throw S.length_not_finite(from, to);
|
|
7
|
+
if (from < 0 || to < 0)
|
|
8
|
+
throw S.length_not_positive(from, to);
|
|
9
|
+
if (from > to)
|
|
10
|
+
throw S.length_from_exceeds_to(from, to);
|
|
15
11
|
return (x) => {
|
|
16
|
-
if (
|
|
17
|
-
throw
|
|
12
|
+
if (!is.string(x) && !is.array(x)) {
|
|
13
|
+
throw E.invalid_type(x, "string or array");
|
|
18
14
|
}
|
|
19
15
|
if (x.length < from || x.length > to) {
|
|
20
|
-
throw
|
|
21
|
-
input: x,
|
|
22
|
-
message: "length out of range",
|
|
23
|
-
path: "",
|
|
24
|
-
}]);
|
|
16
|
+
throw E.out_of_range(x, "length out of range");
|
|
25
17
|
}
|
|
26
18
|
};
|
|
27
19
|
}
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
3
3
|
import is from "@rcompat/is";
|
|
4
4
|
export default function max(limit) {
|
|
5
5
|
// validate limit once
|
|
6
|
-
if (
|
|
7
|
-
if (!is.finite(limit))
|
|
8
|
-
throw
|
|
9
|
-
}
|
|
6
|
+
if (is.number(limit)) {
|
|
7
|
+
if (!is.finite(limit))
|
|
8
|
+
throw S.max_limit_not_finite(limit);
|
|
10
9
|
return (x) => {
|
|
11
|
-
if (
|
|
10
|
+
if (is.number(x)) {
|
|
12
11
|
if (x > limit)
|
|
13
|
-
throw
|
|
12
|
+
throw E.too_large(x, `${x} is greater than ${limit}`);
|
|
14
13
|
}
|
|
15
|
-
else if (
|
|
14
|
+
else if (is.string(x) || is.array(x)) {
|
|
16
15
|
if (x.length > limit) {
|
|
17
|
-
const unit =
|
|
18
|
-
throw
|
|
16
|
+
const unit = is.string(x) ? "characters" : "items";
|
|
17
|
+
throw E.too_large(x, `max ${limit} ${unit}`);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
else {
|
|
22
|
-
throw
|
|
21
|
+
throw E.invalid_type(x, "number");
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
25
|
// bigint
|
|
27
26
|
return (x) => {
|
|
28
|
-
if (
|
|
27
|
+
if (is.bigint(x)) {
|
|
29
28
|
if (x > limit)
|
|
30
|
-
throw
|
|
29
|
+
throw E.too_large(x, `${x} is greater than ${limit}`);
|
|
31
30
|
}
|
|
32
31
|
else {
|
|
33
|
-
throw
|
|
32
|
+
throw E.invalid_type(x, "bigint");
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
}
|
|
@@ -1,36 +1,35 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
3
3
|
import is from "@rcompat/is";
|
|
4
4
|
export default function min(limit) {
|
|
5
5
|
// validate limit once
|
|
6
|
-
if (
|
|
7
|
-
if (!is.finite(limit))
|
|
8
|
-
throw
|
|
9
|
-
}
|
|
6
|
+
if (is.number(limit)) {
|
|
7
|
+
if (!is.finite(limit))
|
|
8
|
+
throw S.min_limit_not_finite(limit);
|
|
10
9
|
return (x) => {
|
|
11
|
-
if (
|
|
10
|
+
if (is.number(x)) {
|
|
12
11
|
if (x < limit)
|
|
13
|
-
throw
|
|
12
|
+
throw E.too_small(x, `${x} is lower than ${limit}`);
|
|
14
13
|
}
|
|
15
|
-
else if (
|
|
14
|
+
else if (is.string(x) || is.array(x)) {
|
|
16
15
|
if (x.length < limit) {
|
|
17
|
-
const unit =
|
|
18
|
-
throw
|
|
16
|
+
const unit = is.string(x) ? "characters" : "items";
|
|
17
|
+
throw E.too_small(x, `min ${limit} ${unit}`);
|
|
19
18
|
}
|
|
20
19
|
}
|
|
21
20
|
else {
|
|
22
|
-
throw
|
|
21
|
+
throw E.invalid_type(x, "number");
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
25
|
// bigint
|
|
27
26
|
return (x) => {
|
|
28
|
-
if (
|
|
27
|
+
if (is.bigint(x)) {
|
|
29
28
|
if (x < limit)
|
|
30
|
-
throw
|
|
29
|
+
throw E.too_small(x, `${x} is lower than ${limit}`);
|
|
31
30
|
}
|
|
32
31
|
else {
|
|
33
|
-
throw
|
|
32
|
+
throw E.invalid_type(x, "bigint");
|
|
34
33
|
}
|
|
35
34
|
};
|
|
36
35
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
// 1000
|
|
3
3
|
const min = 2 ** 10;
|
|
4
4
|
// 65535
|
|
5
5
|
const max = 2 ** 16 - 1;
|
|
6
|
-
export default (
|
|
7
|
-
if (
|
|
8
|
-
throw
|
|
9
|
-
input: port,
|
|
10
|
-
message: `${port} out of port range (${min} - ${max})`,
|
|
11
|
-
path: "",
|
|
12
|
-
}]);
|
|
6
|
+
export default function port(given) {
|
|
7
|
+
if (given < min || given > max) {
|
|
8
|
+
throw E.out_of_range(given, `${given} out of port range (${min} - ${max})`);
|
|
13
9
|
}
|
|
14
|
-
}
|
|
10
|
+
}
|
|
11
|
+
;
|
|
15
12
|
//# sourceMappingURL=port.js.map
|