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.
- package/lib/private/ArrayType.d.ts +2 -1
- package/lib/private/ArrayType.js +29 -41
- package/lib/private/BigIntType.d.ts +2 -2
- package/lib/private/BigUintType.d.ts +2 -2
- package/lib/private/BlobType.d.ts +2 -2
- package/lib/private/BlobType.js +2 -2
- package/lib/private/BooleanType.d.ts +2 -2
- package/lib/private/BooleanType.js +4 -4
- package/lib/private/BuiltinType.d.ts +1 -2
- package/lib/private/BuiltinType.js +3 -8
- package/lib/private/ConstructorType.d.ts +5 -2
- package/lib/private/ConstructorType.js +7 -5
- package/lib/private/DataType.d.ts +5 -1
- package/lib/private/DateType.d.ts +2 -2
- package/lib/private/DateType.js +2 -2
- 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/FileType.d.ts +2 -2
- package/lib/private/FileType.js +2 -2
- package/lib/private/FunctionType.d.ts +15 -0
- package/lib/private/FunctionType.js +20 -0
- package/lib/private/GenericType.d.ts +1 -1
- package/lib/private/InferInputSchema.d.ts +7 -17
- package/lib/private/InferStore.d.ts +1 -1
- package/lib/private/IntType.d.ts +2 -2
- package/lib/private/IsType.d.ts +19 -0
- package/lib/private/IsType.js +29 -0
- package/lib/private/Issue.d.ts +3 -1
- package/lib/private/IssueType.d.ts +3 -0
- package/lib/private/IssueType.js +2 -0
- package/lib/private/JSONType.d.ts +26 -0
- package/lib/private/JSONType.js +41 -0
- package/lib/private/LiteralType.d.ts +5 -2
- package/lib/private/LiteralType.js +11 -5
- package/lib/private/NormalizeSchema.d.ts +4 -6
- package/lib/private/NullType.js +3 -5
- package/lib/private/NumberType.d.ts +1 -1
- package/lib/private/NumberType.js +1 -1
- package/lib/private/NumericType.d.ts +2 -2
- package/lib/private/ObjectType.d.ts +13 -4
- package/lib/private/ObjectType.js +24 -11
- package/lib/private/OmitType.d.ts +1 -1
- package/lib/private/OmitType.js +7 -6
- package/lib/private/ParseError.d.ts +6 -2
- package/lib/private/ParseError.js +25 -15
- package/lib/private/ParseOptions.d.ts +1 -1
- package/lib/private/Parsed.d.ts +2 -1
- package/lib/private/Parsed.js +3 -0
- package/lib/private/PartialType.js +8 -10
- package/lib/private/Partialable.d.ts +1 -1
- package/lib/private/PrimitiveType.d.ts +0 -1
- package/lib/private/PrimitiveType.js +23 -22
- package/lib/private/PureType.d.ts +1 -1
- package/lib/private/RecordType.js +14 -39
- package/lib/private/Schema.d.ts +1 -1
- package/lib/private/Serialized.d.ts +18 -4
- package/lib/private/{Storeable.d.ts → Storable.d.ts} +3 -3
- package/lib/private/{Storeable.js → Storable.js} +2 -2
- package/lib/private/StoreSchema.d.ts +3 -6
- package/lib/private/StoreType.d.ts +5 -1
- package/lib/private/StoreType.js +22 -2
- package/lib/private/StringType.d.ts +2 -3
- package/lib/private/StringType.js +7 -13
- package/lib/private/TupleType.d.ts +2 -2
- package/lib/private/TupleType.js +19 -14
- package/lib/private/Type.d.ts +1 -1
- package/lib/private/URLType.d.ts +2 -2
- package/lib/private/URLType.js +2 -2
- 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/UintType.d.ts +2 -2
- package/lib/private/UnionType.d.ts +3 -3
- package/lib/private/UnionType.js +11 -13
- package/lib/private/VirtualType.js +2 -3
- package/lib/private/coerce/bigint.d.ts +1 -1
- package/lib/private/coerce/bigint.js +4 -6
- 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 +7 -5
- package/lib/private/constructor.d.ts +1 -1
- package/lib/private/dict.d.ts +11 -0
- package/lib/private/dict.js +6 -0
- 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 -30
- package/lib/private/index.js +20 -2
- 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/JSONPayload.d.ts +1 -1
- package/lib/private/json.d.ts +5 -0
- package/lib/private/json.js +5 -0
- package/lib/private/normalize.js +2 -3
- package/lib/private/object.d.ts +3 -4
- package/lib/private/object.js +2 -2
- package/lib/private/omit.d.ts +1 -1
- package/lib/private/path/join.d.ts +1 -1
- package/lib/private/path/next.d.ts +1 -1
- package/lib/private/path/rebase.d.ts +1 -1
- 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 +7 -11
- package/lib/private/validator/isotime.js +8 -10
- package/lib/private/validator/length.js +12 -20
- package/lib/private/validator/max.js +15 -16
- package/lib/private/validator/min.js +15 -16
- package/lib/private/validator/port.d.ts +1 -2
- package/lib/private/validator/port.js +6 -9
- package/lib/private/validator/range.js +7 -13
- 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.d.ts +1 -1
- package/lib/private/validator/values.js +5 -8
- package/lib/public/StoreType.d.ts +1 -1
- package/lib/public/index.d.ts +1 -9
- package/lib/public/index.js +0 -9
- package/package.json +18 -15
- package/lib/private/DecrementDepth.d.ts +0 -3
- package/lib/private/DecrementDepth.js +0 -2
- package/lib/private/InferSchema.d.ts +0 -20
- package/lib/private/InferSchema.js +0 -2
- package/lib/private/PrimaryType.d.ts +0 -14
- package/lib/private/PrimaryType.js +0 -26
- 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/primary.d.ts +0 -4
- package/lib/private/primary.js +0 -3
- 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/public/DataType.d.ts +0 -2
- package/lib/public/DataType.js +0 -2
- package/lib/public/Id.d.ts +0 -2
- package/lib/public/Id.js +0 -2
- package/lib/public/InferStore.d.ts +0 -2
- package/lib/public/InferStore.js +0 -2
- package/lib/public/InferStoreOut.d.ts +0 -2
- package/lib/public/InferStoreOut.js +0 -2
- package/lib/public/Issue.d.ts +0 -2
- package/lib/public/Issue.js +0 -2
- package/lib/public/JSONPayload.d.ts +0 -2
- package/lib/public/JSONPayload.js +0 -2
- package/lib/public/OmitType.d.ts +0 -2
- package/lib/public/OmitType.js +0 -2
- package/lib/public/Schema.d.ts +0 -2
- package/lib/public/Schema.js +0 -2
- package/lib/public/Serialized.d.ts +0 -2
- package/lib/public/Serialized.js +0 -2
- package/lib/public/StoreId.d.ts +0 -2
- package/lib/public/StoreId.js +0 -2
- package/lib/public/StoreSchema.d.ts +0 -2
- package/lib/public/StoreSchema.js +0 -2
- package/lib/public/array.d.ts +0 -3
- package/lib/public/array.js +0 -3
- package/lib/public/bigint.d.ts +0 -2
- package/lib/public/bigint.js +0 -2
- package/lib/public/biguint.d.ts +0 -2
- package/lib/public/biguint.js +0 -2
- package/lib/public/blob.d.ts +0 -2
- package/lib/public/blob.js +0 -2
- package/lib/public/boolean.d.ts +0 -3
- package/lib/public/boolean.js +0 -3
- package/lib/public/constructor.d.ts +0 -3
- package/lib/public/constructor.js +0 -3
- package/lib/public/date.d.ts +0 -2
- package/lib/public/date.js +0 -2
- package/lib/public/f32.d.ts +0 -2
- package/lib/public/f32.js +0 -2
- package/lib/public/f64.d.ts +0 -2
- package/lib/public/f64.js +0 -2
- package/lib/public/file.d.ts +0 -2
- package/lib/public/file.js +0 -2
- package/lib/public/i128.d.ts +0 -2
- package/lib/public/i128.js +0 -2
- package/lib/public/i16.d.ts +0 -2
- package/lib/public/i16.js +0 -2
- package/lib/public/i32.d.ts +0 -2
- package/lib/public/i32.js +0 -2
- package/lib/public/i64.d.ts +0 -2
- package/lib/public/i64.js +0 -2
- package/lib/public/i8.d.ts +0 -2
- package/lib/public/i8.js +0 -2
- package/lib/public/int.d.ts +0 -2
- package/lib/public/int.js +0 -2
- package/lib/public/number.d.ts +0 -3
- package/lib/public/number.js +0 -3
- package/lib/public/object.d.ts +0 -2
- package/lib/public/object.js +0 -2
- package/lib/public/optional.d.ts +0 -2
- package/lib/public/optional.js +0 -2
- package/lib/public/primary.d.ts +0 -2
- package/lib/public/primary.js +0 -2
- package/lib/public/pure.d.ts +0 -2
- package/lib/public/pure.js +0 -2
- package/lib/public/record.d.ts +0 -3
- package/lib/public/record.js +0 -3
- package/lib/public/string.d.ts +0 -3
- package/lib/public/string.js +0 -3
- package/lib/public/symbol.d.ts +0 -2
- package/lib/public/symbol.js +0 -2
- package/lib/public/u128.d.ts +0 -2
- package/lib/public/u128.js +0 -2
- package/lib/public/u16.d.ts +0 -2
- package/lib/public/u16.js +0 -2
- package/lib/public/u32.d.ts +0 -2
- package/lib/public/u32.js +0 -2
- package/lib/public/u64.d.ts +0 -2
- package/lib/public/u64.js +0 -2
- package/lib/public/u8.d.ts +0 -2
- package/lib/public/u8.js +0 -2
- package/lib/public/uint.d.ts +0 -3
- package/lib/public/uint.js +0 -3
- package/lib/public/union.d.ts +0 -3
- package/lib/public/union.js +0 -3
- package/lib/public/unknown.d.ts +0 -3
- package/lib/public/unknown.js +0 -2
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
export default (x)
|
|
4
|
-
if (!
|
|
5
|
-
throw
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
path: "",
|
|
9
|
-
}]);
|
|
10
|
-
}
|
|
11
|
-
};
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import is from "@rcompat/is";
|
|
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
|
|
4
|
-
import isFinite from "@rcompat/is/finite";
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
3
|
+
import is from "@rcompat/is";
|
|
5
4
|
export default function length(from, to) {
|
|
6
|
-
if (!
|
|
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
|
|
3
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
3
|
+
import is from "@rcompat/is";
|
|
4
4
|
export default function max(limit) {
|
|
5
5
|
// validate limit once
|
|
6
|
-
if (
|
|
7
|
-
if (!
|
|
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
|
|
3
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import S from "#schema-errors";
|
|
3
|
+
import is from "@rcompat/is";
|
|
4
4
|
export default function min(limit) {
|
|
5
5
|
// validate limit once
|
|
6
|
-
if (
|
|
7
|
-
if (!
|
|
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
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
const fail = (input, msg) => new ParseError([{ input, message: msg, path: "" }]);
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import is from "@rcompat/is";
|
|
4
3
|
export default function range(from, to) {
|
|
5
|
-
if (!
|
|
4
|
+
if (!is.finite(from) || !is.finite(to)) {
|
|
6
5
|
throw new TypeError("range(): from and to must be finite numbers");
|
|
7
6
|
}
|
|
8
7
|
return (x) => {
|
|
9
|
-
if (
|
|
10
|
-
throw
|
|
11
|
-
}
|
|
12
|
-
if (x < from || x > to) {
|
|
13
|
-
throw new ParseError([{
|
|
14
|
-
input: x,
|
|
15
|
-
message: `${x} is out of range`,
|
|
16
|
-
path: "",
|
|
17
|
-
}]);
|
|
8
|
+
if (!is.number(x) && !is.bigint(x)) {
|
|
9
|
+
throw E.invalid_type(x, "number or bigint");
|
|
18
10
|
}
|
|
11
|
+
if (x < from || x > to)
|
|
12
|
+
throw E.out_of_range(x, `${x} is out of range`);
|
|
19
13
|
};
|
|
20
14
|
}
|
|
21
15
|
;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type Validator from "#Validator";
|
|
2
2
|
type ErrorFunction = (x: string) => string;
|
|
3
|
-
export default function
|
|
3
|
+
export default function regex(format: RegExp, error?: ErrorFunction): Validator<string>;
|
|
4
4
|
export {};
|
|
5
5
|
//# sourceMappingURL=regex.d.ts.map
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default function
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
export default function regex(format, error) {
|
|
3
3
|
return (x) => {
|
|
4
|
-
if (!
|
|
5
|
-
const message = (error ?? ((y) => `"${y}" is not a valid ${String(
|
|
6
|
-
throw
|
|
7
|
-
input: x,
|
|
8
|
-
message,
|
|
9
|
-
path: "", // root; the calling type should rebase if needed
|
|
10
|
-
}]);
|
|
4
|
+
if (!format.test(x)) {
|
|
5
|
+
const message = (error ?? ((y) => `"${y}" is not a valid ${String(format)}`))(x);
|
|
6
|
+
throw E.invalid_format(x, message);
|
|
11
7
|
}
|
|
12
8
|
};
|
|
13
9
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
export default (prefix)
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
};
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
export default function starts_with(prefix) {
|
|
3
|
+
return (x) => {
|
|
4
|
+
if (!x.startsWith(prefix)) {
|
|
5
|
+
throw E.invalid_format(x, `"${x}" does not start with "${prefix}"`);
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
}
|
|
11
9
|
//# sourceMappingURL=starts-with.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function unique_by<T, K>(select: (value: T) => K): (array: T[]) => void;
|
|
2
2
|
//# sourceMappingURL=unique-by.d.ts.map
|
|
@@ -1,22 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
import join from "#path/join";
|
|
3
|
-
function
|
|
4
|
-
return `duplicate key "${String(k)}" at index ${i} (first ${first})`;
|
|
5
|
-
}
|
|
6
|
-
export default function uniqueBy(selector) {
|
|
3
|
+
export default function unique_by(select) {
|
|
7
4
|
return (array) => {
|
|
8
5
|
const seen = new Map();
|
|
9
6
|
for (let i = 0; i < array.length; i++) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
message: message(k, i, first),
|
|
16
|
-
path: join("", i),
|
|
17
|
-
}]);
|
|
7
|
+
const value = array[i];
|
|
8
|
+
const key = select(value);
|
|
9
|
+
if (seen.has(key)) {
|
|
10
|
+
const first = seen.get(key);
|
|
11
|
+
throw E.duplicate(array, `duplicate value at index ${i} (first seen at ${first})`, join("", i));
|
|
18
12
|
}
|
|
19
|
-
seen.set(
|
|
13
|
+
seen.set(key, i);
|
|
20
14
|
}
|
|
21
15
|
};
|
|
22
16
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export default function
|
|
1
|
+
export default function unique<T>(equals: (a: T, b: T) => boolean): (array: Array<T>) => void;
|
|
2
2
|
//# sourceMappingURL=unique-with.d.ts.map
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
import join from "#path/join";
|
|
3
|
-
export default function
|
|
3
|
+
export default function unique(equals) {
|
|
4
4
|
return (array) => {
|
|
5
5
|
for (let i = 0; i < array.length; i++) {
|
|
6
6
|
for (let j = 0; j < i; j++) {
|
|
7
7
|
if (equals(array[i], array[j])) {
|
|
8
|
-
throw
|
|
9
|
-
input: array,
|
|
10
|
-
message: `items at ${j} and ${i} considered equal`,
|
|
11
|
-
path: join("", i),
|
|
12
|
-
}]);
|
|
8
|
+
throw E.duplicate(array, `items at ${j} and ${i} considered equal`, join("", i));
|
|
13
9
|
}
|
|
14
10
|
}
|
|
15
11
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
import join from "#path/join";
|
|
3
3
|
export default function unique(array) {
|
|
4
4
|
const seen = new Map();
|
|
@@ -7,11 +7,7 @@ export default function unique(array) {
|
|
|
7
7
|
if (seen.has(v)) {
|
|
8
8
|
const first = seen.get(v);
|
|
9
9
|
// key = current duplicate index
|
|
10
|
-
throw
|
|
11
|
-
input: array,
|
|
12
|
-
message: `duplicate value at index ${i} (first seen at ${first})`,
|
|
13
|
-
path: join("", i),
|
|
14
|
-
}]);
|
|
10
|
+
throw E.duplicate(array, `duplicate value at index ${i} (first seen at ${first})`, join("", i));
|
|
15
11
|
}
|
|
16
12
|
seen.set(v, i);
|
|
17
13
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import E from "#errors";
|
|
2
2
|
export default function values(input) {
|
|
3
|
-
const
|
|
3
|
+
const input_values = Object.values(input);
|
|
4
|
+
const allowed = input_values.map(v => String(v)).join(", ");
|
|
4
5
|
return (x) => {
|
|
5
|
-
if (!
|
|
6
|
-
throw
|
|
7
|
-
input: x,
|
|
8
|
-
message: `"${x}" not in given list of values (${allowed})`,
|
|
9
|
-
path: "",
|
|
10
|
-
}]);
|
|
6
|
+
if (!input_values.includes(x)) {
|
|
7
|
+
throw E.not_in_set(x, `"${x}" not in given list of values (${allowed})`);
|
|
11
8
|
}
|
|
12
9
|
};
|
|
13
10
|
}
|
package/lib/public/index.d.ts
CHANGED
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { default as DefaultType } from "#DefaultType";
|
|
1
|
+
export type * from "#index";
|
|
3
2
|
export { default } from "#index";
|
|
4
|
-
export { default as LiteralType } from "#LiteralType";
|
|
5
|
-
export { default as ObjectType } from "#ObjectType";
|
|
6
|
-
export { default as OptionalType } from "#OptionalType";
|
|
7
|
-
export { default as PureType } from "#PureType";
|
|
8
|
-
export { default as TupleType } from "#TupleType";
|
|
9
|
-
export { default as UndefinedType } from "#UndefinedType";
|
|
10
|
-
export { default as ArrayType } from "#ArrayType";
|
|
11
3
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/public/index.js
CHANGED
|
@@ -1,11 +1,2 @@
|
|
|
1
|
-
export { default as ConstructorType } from "#ConstructorType";
|
|
2
|
-
export { default as DefaultType } from "#DefaultType";
|
|
3
1
|
export { default } from "#index";
|
|
4
|
-
export { default as LiteralType } from "#LiteralType";
|
|
5
|
-
export { default as ObjectType } from "#ObjectType";
|
|
6
|
-
export { default as OptionalType } from "#OptionalType";
|
|
7
|
-
export { default as PureType } from "#PureType";
|
|
8
|
-
export { default as TupleType } from "#TupleType";
|
|
9
|
-
export { default as UndefinedType } from "#UndefinedType";
|
|
10
|
-
export { default as ArrayType } from "#ArrayType";
|
|
11
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Primate schema validation",
|
|
5
5
|
"homepage": "https://primate.run/docs/validation",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
7
|
+
"type": "module",
|
|
7
8
|
"license": "MIT",
|
|
8
|
-
"files": [
|
|
9
|
-
"/lib/**/*.js",
|
|
10
|
-
"/lib/**/*.d.ts",
|
|
11
|
-
"!/**/*.spec.*"
|
|
12
|
-
],
|
|
13
9
|
"repository": {
|
|
14
10
|
"type": "git",
|
|
15
11
|
"url": "https://github.com/primate-run/primate",
|
|
16
12
|
"directory": "packages/pema"
|
|
17
13
|
},
|
|
14
|
+
"files": [
|
|
15
|
+
"/lib/**/*.js",
|
|
16
|
+
"/lib/**/*.d.ts",
|
|
17
|
+
"!/**/*.spec.*"
|
|
18
|
+
],
|
|
18
19
|
"dependencies": {
|
|
19
|
-
"@rcompat/assert": "^0.
|
|
20
|
-
"@rcompat/cli": "^0.
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"@rcompat/
|
|
20
|
+
"@rcompat/assert": "^0.8.1",
|
|
21
|
+
"@rcompat/cli": "^0.18.1",
|
|
22
|
+
"@rcompat/error": "^0.3.1",
|
|
23
|
+
"@rcompat/is": "^0.6.1"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@rcompat/type": "^0.11.1"
|
|
23
27
|
},
|
|
24
|
-
"type": "module",
|
|
25
28
|
"imports": {
|
|
26
29
|
"#*": {
|
|
27
|
-
"
|
|
30
|
+
"@primate/source": "./src/private/*.ts",
|
|
28
31
|
"default": "./lib/private/*.js"
|
|
29
32
|
}
|
|
30
33
|
},
|
|
31
34
|
"exports": {
|
|
32
35
|
".": {
|
|
33
|
-
"
|
|
36
|
+
"@primate/source": "./src/public/index.ts",
|
|
34
37
|
"default": "./lib/public/index.js"
|
|
35
38
|
},
|
|
36
39
|
"./*": {
|
|
37
|
-
"
|
|
40
|
+
"@primate/source": "./src/public/*.ts",
|
|
38
41
|
"default": "./lib/public/*.js"
|
|
39
42
|
}
|
|
40
43
|
},
|
|
@@ -43,6 +46,6 @@
|
|
|
43
46
|
"clean": "rm -rf ./lib",
|
|
44
47
|
"lint": "eslint .",
|
|
45
48
|
"lint:fix": "eslint . --fix",
|
|
46
|
-
"test": "
|
|
49
|
+
"test": "npx proby"
|
|
47
50
|
}
|
|
48
51
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type ArrayType from "#ArrayType";
|
|
2
|
-
import type DecrementDepth from "#DecrementDepth";
|
|
3
|
-
import type Infer from "#Infer";
|
|
4
|
-
import type NullType from "#NullType";
|
|
5
|
-
import type Parsed from "#Parsed";
|
|
6
|
-
import type Schema from "#Schema";
|
|
7
|
-
import type TupleType from "#TupleType";
|
|
8
|
-
import type UndefinedType from "#UndefinedType";
|
|
9
|
-
import type UndefinedToOptional from "@rcompat/type/UndefinedToOptional";
|
|
10
|
-
type InferSchema<S, Depth extends number = 3> = [
|
|
11
|
-
Depth
|
|
12
|
-
] extends [never] ? never : S extends Parsed<unknown> ? Infer<S> : S extends null ? Infer<NullType> : S extends undefined ? Infer<UndefinedType> : S extends [infer Only] ? Only extends Parsed<unknown> ? Infer<ArrayType<Only>> : never : S extends Schema[] ? InferSchema<TupleType<{
|
|
13
|
-
[K in keyof S]: S[K] extends Parsed<unknown> ? InferSchema<S[K], DecrementDepth[Depth]> : never;
|
|
14
|
-
}>> : S extends {
|
|
15
|
-
[key: string]: Schema;
|
|
16
|
-
} ? UndefinedToOptional<{
|
|
17
|
-
[K in keyof S]: InferSchema<S[K], DecrementDepth[Depth]>;
|
|
18
|
-
}> : never;
|
|
19
|
-
export type { InferSchema as default };
|
|
20
|
-
//# sourceMappingURL=InferSchema.d.ts.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type Infer from "#Infer";
|
|
2
|
-
import type ParseOptions from "#ParseOptions";
|
|
3
|
-
import PrimitiveType from "#PrimitiveType";
|
|
4
|
-
import Storeable from "#Storeable";
|
|
5
|
-
export default class PrimaryType extends PrimitiveType<string | undefined, "PrimaryType"> implements Storeable<"primary"> {
|
|
6
|
-
get name(): "primary";
|
|
7
|
-
get datatype(): "primary";
|
|
8
|
-
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
9
|
-
toJSON(): {
|
|
10
|
-
type: "primary";
|
|
11
|
-
datatype: "primary";
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=PrimaryType.d.ts.map
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import error from "#error";
|
|
2
|
-
import ParseError from "#ParseError";
|
|
3
|
-
import PrimitiveType from "#PrimitiveType";
|
|
4
|
-
import Storeable from "#Storeable";
|
|
5
|
-
export default class PrimaryType extends PrimitiveType {
|
|
6
|
-
get name() {
|
|
7
|
-
return "primary";
|
|
8
|
-
}
|
|
9
|
-
get datatype() {
|
|
10
|
-
return "primary";
|
|
11
|
-
}
|
|
12
|
-
parse(x, options = {}) {
|
|
13
|
-
// the primary type is an optional ype
|
|
14
|
-
if (x === undefined) {
|
|
15
|
-
return x;
|
|
16
|
-
}
|
|
17
|
-
if (typeof x !== "string") {
|
|
18
|
-
throw new ParseError(error(this.name, x, options));
|
|
19
|
-
}
|
|
20
|
-
return x;
|
|
21
|
-
}
|
|
22
|
-
toJSON() {
|
|
23
|
-
return Storeable.serialize(this);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
//# sourceMappingURL=PrimaryType.js.map
|