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
|
@@ -7,7 +7,7 @@ import type ParseOptions from "#ParseOptions";
|
|
|
7
7
|
import type DefaultTrait from "#trait/Default";
|
|
8
8
|
import type OptionalTrait from "#trait/Optional";
|
|
9
9
|
import type Validator from "#Validator";
|
|
10
|
-
import type Primitive from "@rcompat/type
|
|
10
|
+
import type { Primitive } from "@rcompat/type";
|
|
11
11
|
type Next<T> = {
|
|
12
12
|
validators?: Validator<T>[];
|
|
13
13
|
};
|
|
@@ -25,6 +25,7 @@ export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T,
|
|
|
25
25
|
* @returns ArrayType<T>
|
|
26
26
|
*/
|
|
27
27
|
unique(this: Infer<T> extends Primitive ? ArrayType<T> : never): ArrayType<T>;
|
|
28
|
+
uniqueBy<K>(select: (value: Infer<T>) => K): this;
|
|
28
29
|
min(limit: number): this;
|
|
29
30
|
max(limit: number): this;
|
|
30
31
|
length(from: number, to: number): this;
|
package/lib/private/ArrayType.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
2
|
+
import EnumType from "#EnumType";
|
|
3
|
+
import E from "#errors";
|
|
4
4
|
import GenericType from "#GenericType";
|
|
5
5
|
import OptionalType from "#OptionalType";
|
|
6
6
|
import ParsedKey from "#ParsedKey";
|
|
@@ -9,14 +9,15 @@ import join from "#path/join";
|
|
|
9
9
|
import next from "#path/next";
|
|
10
10
|
import rebase from "#path/rebase";
|
|
11
11
|
import PrimitiveType from "#PrimitiveType";
|
|
12
|
+
import S from "#schema-errors";
|
|
12
13
|
import length from "#validator/length";
|
|
13
14
|
import max from "#validator/max";
|
|
14
15
|
import min from "#validator/min";
|
|
15
16
|
import unique from "#validator/unique";
|
|
17
|
+
import uniqueBy from "#validator/unique-by";
|
|
16
18
|
function isPrimitive(x) {
|
|
17
|
-
return x instanceof PrimitiveType;
|
|
19
|
+
return x instanceof PrimitiveType || x instanceof EnumType;
|
|
18
20
|
}
|
|
19
|
-
const is = (x, validator) => validator(x);
|
|
20
21
|
export default class ArrayType extends GenericType {
|
|
21
22
|
#item;
|
|
22
23
|
#validators;
|
|
@@ -46,64 +47,51 @@ export default class ArrayType extends GenericType {
|
|
|
46
47
|
*/
|
|
47
48
|
unique() {
|
|
48
49
|
if (!isPrimitive(this.#item)) {
|
|
49
|
-
throw
|
|
50
|
+
throw S.unique_subtype_not_primitive(this.#item.name);
|
|
50
51
|
}
|
|
51
52
|
return this.derive({ validators: [unique] });
|
|
52
53
|
}
|
|
54
|
+
uniqueBy(select) {
|
|
55
|
+
return this.derive({ validators: [uniqueBy(select)] });
|
|
56
|
+
}
|
|
53
57
|
min(limit) {
|
|
54
|
-
if (limit < 0)
|
|
55
|
-
throw
|
|
56
|
-
}
|
|
58
|
+
if (limit < 0)
|
|
59
|
+
throw S.min_negative(limit);
|
|
57
60
|
return this.derive({ validators: [min(limit)] });
|
|
58
61
|
}
|
|
59
62
|
max(limit) {
|
|
60
|
-
if (limit < 0)
|
|
61
|
-
throw
|
|
62
|
-
}
|
|
63
|
+
if (limit < 0)
|
|
64
|
+
throw S.max_negative(limit);
|
|
63
65
|
return this.derive({ validators: [max(limit)] });
|
|
64
66
|
}
|
|
65
67
|
length(from, to) {
|
|
66
68
|
return this.derive({ validators: [length(from, to)] });
|
|
67
69
|
}
|
|
68
70
|
parse(x, options = {}) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (i
|
|
77
|
-
throw
|
|
78
|
-
|
|
79
|
-
path: join(base, last),
|
|
80
|
-
}]);
|
|
81
|
-
}
|
|
82
|
-
const validator = this.#item;
|
|
83
|
-
validator.parse(v, next(i, options));
|
|
84
|
-
last++;
|
|
85
|
-
});
|
|
86
|
-
// sparse array with end slots
|
|
87
|
-
if (x.length > last) {
|
|
88
|
-
throw new ParseError([{
|
|
89
|
-
...error(this.#item.name, undefined, options)[0],
|
|
90
|
-
path: join(base, last),
|
|
91
|
-
}]);
|
|
71
|
+
const path = options[ParsedKey] ?? "";
|
|
72
|
+
if (!Array.isArray(x))
|
|
73
|
+
throw E.invalid_type(x, "array", path);
|
|
74
|
+
const item = this.#item;
|
|
75
|
+
const len = x.length;
|
|
76
|
+
const out = new Array(len);
|
|
77
|
+
for (let i = 0; i < len; i++) {
|
|
78
|
+
if (!(i in x))
|
|
79
|
+
throw E.invalid_type(undefined, item.name, join(path, i));
|
|
80
|
+
out[i] = item.parse(x[i], next(i, options));
|
|
92
81
|
}
|
|
93
|
-
|
|
82
|
+
const validators = this.#validators;
|
|
83
|
+
for (let i = 0; i < validators.length; i++) {
|
|
94
84
|
try {
|
|
95
|
-
|
|
85
|
+
validators[i](out);
|
|
96
86
|
}
|
|
97
87
|
catch (e) {
|
|
98
|
-
if (e
|
|
99
|
-
|
|
100
|
-
.map(i => ({ ...i, path: rebase(base, i.path) }));
|
|
101
|
-
throw new ParseError(rebased);
|
|
88
|
+
if (ParseError.is(e)) {
|
|
89
|
+
throw new ParseError(e.issues.map(issue => ({ ...issue, path: rebase(path, issue.path) })));
|
|
102
90
|
}
|
|
103
91
|
throw e;
|
|
104
92
|
}
|
|
105
93
|
}
|
|
106
|
-
return
|
|
94
|
+
return out;
|
|
107
95
|
}
|
|
108
96
|
toJSON() {
|
|
109
97
|
return { type: this.name, of: this.#item.toJSON() };
|
|
@@ -2,8 +2,8 @@ import type BigIntDataType from "#BigIntDataType";
|
|
|
2
2
|
import coerce from "#coerce/bigint";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
|
-
import type
|
|
6
|
-
export default class BigIntType<T extends BigIntDataType = "i64"> extends NumericType<T, bigint, "BigIntType"> implements
|
|
5
|
+
import type Storable from "#Storable";
|
|
6
|
+
export default class BigIntType<T extends BigIntDataType = "i64"> extends NumericType<T, bigint, "BigIntType"> implements Storable<T> {
|
|
7
7
|
[CoerceKey]: typeof coerce;
|
|
8
8
|
get name(): string;
|
|
9
9
|
}
|
|
@@ -2,8 +2,8 @@ import type BigUintDataType from "#BigUintDataType";
|
|
|
2
2
|
import coerce from "#coerce/bigint";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
|
-
import type
|
|
6
|
-
export default class BigUintType<T extends BigUintDataType = "u64"> extends NumericType<T, bigint, "BigUintType"> implements
|
|
5
|
+
import type Storable from "#Storable";
|
|
6
|
+
export default class BigUintType<T extends BigUintDataType = "u64"> extends NumericType<T, bigint, "BigUintType"> implements Storable<T> {
|
|
7
7
|
[CoerceKey]: typeof coerce;
|
|
8
8
|
get name(): string;
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
import
|
|
3
|
-
export default class BlobType extends BuiltinType<Blob, "BlobType"> implements
|
|
2
|
+
import Storable from "#Storable";
|
|
3
|
+
export default class BlobType extends BuiltinType<Blob, "BlobType"> implements Storable<"blob"> {
|
|
4
4
|
get Type(): {
|
|
5
5
|
new (blobParts?: BlobPart[], options?: BlobPropertyBag): Blob;
|
|
6
6
|
prototype: Blob;
|
package/lib/private/BlobType.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
import
|
|
2
|
+
import Storable from "#Storable";
|
|
3
3
|
export default class BlobType extends BuiltinType {
|
|
4
4
|
get Type() {
|
|
5
5
|
return Blob;
|
|
@@ -11,7 +11,7 @@ export default class BlobType extends BuiltinType {
|
|
|
11
11
|
return "blob";
|
|
12
12
|
}
|
|
13
13
|
toJSON() {
|
|
14
|
-
return
|
|
14
|
+
return Storable.serialize(this);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=BlobType.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import CoerceKey from "#CoerceKey";
|
|
2
2
|
import PrimitiveType from "#PrimitiveType";
|
|
3
|
-
import
|
|
4
|
-
export default class BooleanType extends PrimitiveType<boolean, "BooleanType"> implements
|
|
3
|
+
import Storable from "#Storable";
|
|
4
|
+
export default class BooleanType extends PrimitiveType<boolean, "BooleanType"> implements Storable<"boolean"> {
|
|
5
5
|
get name(): "boolean";
|
|
6
6
|
get datatype(): "boolean";
|
|
7
7
|
[CoerceKey](x: unknown): unknown;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import CoerceKey from "#CoerceKey";
|
|
2
2
|
import PrimitiveType from "#PrimitiveType";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
3
|
+
import Storable from "#Storable";
|
|
4
|
+
import is from "@rcompat/is";
|
|
5
5
|
export default class BooleanType extends PrimitiveType {
|
|
6
6
|
get name() {
|
|
7
7
|
return "boolean";
|
|
@@ -10,10 +10,10 @@ export default class BooleanType extends PrimitiveType {
|
|
|
10
10
|
return "boolean";
|
|
11
11
|
}
|
|
12
12
|
[CoerceKey](x) {
|
|
13
|
-
return boolish(x) ? x === "true" : x;
|
|
13
|
+
return is.boolish(x) ? x === "true" : x;
|
|
14
14
|
}
|
|
15
15
|
toJSON() {
|
|
16
|
-
return
|
|
16
|
+
return Storable.serialize(this);
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
//# sourceMappingURL=BooleanType.js.map
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type Infer from "#Infer";
|
|
2
2
|
import type ParseOptions from "#ParseOptions";
|
|
3
3
|
import Type from "#Type";
|
|
4
|
-
import type AbstractNewable from "@rcompat/type
|
|
4
|
+
import type { AbstractNewable } from "@rcompat/type";
|
|
5
5
|
export default abstract class BuiltinType<StaticType, Name extends string> extends Type<StaticType, Name> {
|
|
6
6
|
#private;
|
|
7
7
|
abstract get Type(): AbstractNewable;
|
|
8
8
|
constructor(options?: ParseOptions);
|
|
9
|
-
get coerce(): this;
|
|
10
9
|
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
11
10
|
}
|
|
12
11
|
//# sourceMappingURL=BuiltinType.d.ts.map
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import CoerceKey from "#CoerceKey";
|
|
2
|
-
import
|
|
3
|
-
import ParseError from "#ParseError";
|
|
2
|
+
import E from "#errors";
|
|
4
3
|
import Type from "#Type";
|
|
5
4
|
export default class BuiltinType extends Type {
|
|
6
5
|
#options;
|
|
@@ -12,15 +11,11 @@ export default class BuiltinType extends Type {
|
|
|
12
11
|
const Constructor = this.constructor;
|
|
13
12
|
return new Constructor({ ...this.#options, ...next });
|
|
14
13
|
}
|
|
15
|
-
get coerce() {
|
|
16
|
-
return this.#derive({ coerce: true });
|
|
17
|
-
}
|
|
18
14
|
parse(x, options = {}) {
|
|
19
15
|
const $options = { ...this.#options, ...options };
|
|
20
16
|
const $x = $options.coerce === true ? this[CoerceKey](x) : x;
|
|
21
|
-
if (!($x instanceof this.Type))
|
|
22
|
-
throw
|
|
23
|
-
}
|
|
17
|
+
if (!($x instanceof this.Type))
|
|
18
|
+
throw E.invalid_type($x, this.name, $options);
|
|
24
19
|
return $x;
|
|
25
20
|
}
|
|
26
21
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
3
|
import type Infer from "#Infer";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
4
5
|
import type ParseOptions from "#ParseOptions";
|
|
5
6
|
import type DefaultTrait from "#trait/Default";
|
|
6
|
-
import type
|
|
7
|
-
|
|
7
|
+
import type OptionalTrait from "#trait/Optional";
|
|
8
|
+
import type { AbstractNewable } from "@rcompat/type";
|
|
9
|
+
export default class ConstructorType<C extends AbstractNewable> extends GenericType<C, InstanceType<C>, "InstanceType"> implements OptionalTrait, DefaultTrait<InstanceType<C>> {
|
|
8
10
|
#private;
|
|
9
11
|
constructor(t: C);
|
|
10
12
|
get name(): string;
|
|
13
|
+
optional(): OptionalType<this>;
|
|
11
14
|
default(value: (() => InstanceType<C>) | InstanceType<C>): DefaultType<this, InstanceType<C>>;
|
|
12
15
|
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
13
16
|
toJSON(): {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
|
-
import
|
|
2
|
+
import E from "#errors";
|
|
3
3
|
import GenericType from "#GenericType";
|
|
4
|
-
import
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
5
|
export default class ConstructorType extends GenericType {
|
|
6
6
|
#type;
|
|
7
7
|
constructor(t) {
|
|
@@ -11,13 +11,15 @@ export default class ConstructorType extends GenericType {
|
|
|
11
11
|
get name() {
|
|
12
12
|
return "constructor";
|
|
13
13
|
}
|
|
14
|
+
optional() {
|
|
15
|
+
return new OptionalType(this);
|
|
16
|
+
}
|
|
14
17
|
default(value) {
|
|
15
18
|
return new DefaultType(this, value);
|
|
16
19
|
}
|
|
17
20
|
parse(x, options = {}) {
|
|
18
|
-
if (!(x instanceof this.#type))
|
|
19
|
-
throw
|
|
20
|
-
}
|
|
21
|
+
if (!(x instanceof this.#type))
|
|
22
|
+
throw E.invalid_type(x, this.name, options);
|
|
21
23
|
return x;
|
|
22
24
|
}
|
|
23
25
|
toJSON() {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JSONValue } from "@rcompat/type";
|
|
1
2
|
type DataType = {
|
|
2
3
|
blob: Blob;
|
|
3
4
|
boolean: boolean;
|
|
@@ -9,7 +10,7 @@ type DataType = {
|
|
|
9
10
|
i32: number;
|
|
10
11
|
i64: bigint;
|
|
11
12
|
i8: number;
|
|
12
|
-
|
|
13
|
+
json: JSONValue;
|
|
13
14
|
string: string;
|
|
14
15
|
time: string;
|
|
15
16
|
u128: bigint;
|
|
@@ -18,6 +19,9 @@ type DataType = {
|
|
|
18
19
|
u64: bigint;
|
|
19
20
|
u8: number;
|
|
20
21
|
url: URL;
|
|
22
|
+
uuid: string;
|
|
23
|
+
uuid_v4: string;
|
|
24
|
+
uuid_v7: string;
|
|
21
25
|
};
|
|
22
26
|
export type { DataType as default };
|
|
23
27
|
//# sourceMappingURL=DataType.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
2
|
import coerce from "#coerce/date";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
|
-
import
|
|
5
|
-
export default class DateType extends BuiltinType<Date, "DateType"> implements
|
|
4
|
+
import Storable from "#Storable";
|
|
5
|
+
export default class DateType extends BuiltinType<Date, "DateType"> implements Storable<"datetime"> {
|
|
6
6
|
[CoerceKey]: typeof coerce;
|
|
7
7
|
get Type(): DateConstructor;
|
|
8
8
|
get name(): "date";
|
package/lib/private/DateType.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
2
|
import coerce from "#coerce/date";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
|
-
import
|
|
4
|
+
import Storable from "#Storable";
|
|
5
5
|
export default class DateType extends BuiltinType {
|
|
6
6
|
[CoerceKey] = coerce;
|
|
7
7
|
get Type() {
|
|
@@ -14,7 +14,7 @@ export default class DateType extends BuiltinType {
|
|
|
14
14
|
return "datetime";
|
|
15
15
|
}
|
|
16
16
|
toJSON() {
|
|
17
|
-
return
|
|
17
|
+
return Storable.serialize(this);
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
//# sourceMappingURL=DateType.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import VirtualType from "#VirtualType";
|
|
2
|
-
|
|
3
|
-
return typeof x === "function";
|
|
4
|
-
}
|
|
5
|
-
;
|
|
2
|
+
import is from "@rcompat/is";
|
|
6
3
|
export default class DefaultType extends VirtualType {
|
|
7
4
|
#schema;
|
|
8
5
|
#default;
|
|
@@ -23,8 +20,8 @@ export default class DefaultType extends VirtualType {
|
|
|
23
20
|
parse(x, options = {}) {
|
|
24
21
|
let $x = x;
|
|
25
22
|
// default fallback
|
|
26
|
-
if ($x
|
|
27
|
-
$x =
|
|
23
|
+
if (is.undefined($x)) {
|
|
24
|
+
$x = is.function(this.#default) ? this.#default() : this.#default;
|
|
28
25
|
}
|
|
29
26
|
return this.#schema.parse($x, options);
|
|
30
27
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import GenericType from "#GenericType";
|
|
3
|
+
import type Infer from "#Infer";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
|
+
import type ParseOptions from "#ParseOptions";
|
|
6
|
+
import type OptionalTrait from "#trait/Optional";
|
|
7
|
+
type Literal = string;
|
|
8
|
+
export default class EnumType<T extends readonly Literal[]> extends GenericType<T, T[number], "EnumType"> implements OptionalTrait {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(values: T);
|
|
11
|
+
get name(): string;
|
|
12
|
+
optional(): OptionalType<this>;
|
|
13
|
+
default<D extends T[number]>(value: (() => D) | D): DefaultType<EnumType<T>, D>;
|
|
14
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
15
|
+
toJSON(): {
|
|
16
|
+
type: "enum";
|
|
17
|
+
values: T[number][];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {};
|
|
21
|
+
//# sourceMappingURL=EnumType.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import E from "#errors";
|
|
3
|
+
import GenericType from "#GenericType";
|
|
4
|
+
import OptionalType from "#OptionalType";
|
|
5
|
+
export default class EnumType extends GenericType {
|
|
6
|
+
#values;
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super();
|
|
9
|
+
this.#values = values;
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return this.#values.map(v => `"${v}"`).join(" | ");
|
|
13
|
+
}
|
|
14
|
+
optional() {
|
|
15
|
+
return new OptionalType(this);
|
|
16
|
+
}
|
|
17
|
+
default(value) {
|
|
18
|
+
return new DefaultType(this, value);
|
|
19
|
+
}
|
|
20
|
+
parse(x, options = {}) {
|
|
21
|
+
if (typeof x !== "string" || !this.#values.includes(x)) {
|
|
22
|
+
throw E.invalid_type(x, this.name, options);
|
|
23
|
+
}
|
|
24
|
+
return x;
|
|
25
|
+
}
|
|
26
|
+
toJSON() {
|
|
27
|
+
return { type: "enum", values: [...this.#values] };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=EnumType.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
import
|
|
3
|
-
export default class FileType extends BuiltinType<File, "FileType"> implements
|
|
2
|
+
import Storable from "#Storable";
|
|
3
|
+
export default class FileType extends BuiltinType<File, "FileType"> implements Storable<"blob"> {
|
|
4
4
|
get Type(): {
|
|
5
5
|
new (fileBits: BlobPart[], fileName: string, options?: FilePropertyBag): File;
|
|
6
6
|
prototype: File;
|
package/lib/private/FileType.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
-
import
|
|
2
|
+
import Storable from "#Storable";
|
|
3
3
|
export default class FileType extends BuiltinType {
|
|
4
4
|
get Type() {
|
|
5
5
|
return File;
|
|
@@ -11,7 +11,7 @@ export default class FileType extends BuiltinType {
|
|
|
11
11
|
return "blob";
|
|
12
12
|
}
|
|
13
13
|
toJSON() {
|
|
14
|
-
return
|
|
14
|
+
return Storable.serialize(this);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
//# sourceMappingURL=FileType.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import OptionalType from "#OptionalType";
|
|
4
|
+
import type ParseOptions from "#ParseOptions";
|
|
5
|
+
import type OptionalTrait from "#trait/Optional";
|
|
6
|
+
import type { UnknownFunction } from "@rcompat/type";
|
|
7
|
+
export default class FunctionType extends GenericType<UnknownFunction, UnknownFunction, "FunctionType"> implements OptionalTrait {
|
|
8
|
+
get name(): "function";
|
|
9
|
+
optional(): OptionalType<this>;
|
|
10
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
11
|
+
toJSON(): {
|
|
12
|
+
type: "function";
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=FunctionType.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import OptionalType from "#OptionalType";
|
|
3
|
+
import E from "#errors";
|
|
4
|
+
export default class FunctionType extends GenericType {
|
|
5
|
+
get name() {
|
|
6
|
+
return "function";
|
|
7
|
+
}
|
|
8
|
+
optional() {
|
|
9
|
+
return new OptionalType(this);
|
|
10
|
+
}
|
|
11
|
+
parse(x, options = {}) {
|
|
12
|
+
if (typeof x !== "function")
|
|
13
|
+
throw E.invalid_type(x, this.name, options);
|
|
14
|
+
return x;
|
|
15
|
+
}
|
|
16
|
+
toJSON() {
|
|
17
|
+
return { type: this.name };
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=FunctionType.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Parsed from "#Parsed";
|
|
2
|
-
import type PrintableGeneric from "@rcompat/type
|
|
2
|
+
import type { PrintableGeneric } from "@rcompat/type";
|
|
3
3
|
export default abstract class GenericType<Type, Inferred, Name extends string> extends Parsed<Inferred> implements PrintableGeneric<Type> {
|
|
4
4
|
get Name(): Name;
|
|
5
5
|
get Type(): Type;
|
|
@@ -1,26 +1,16 @@
|
|
|
1
|
-
import type ArrayType from "#ArrayType";
|
|
2
|
-
import type DecrementDepth from "#DecrementDepth";
|
|
3
1
|
import type DefaultType from "#DefaultType";
|
|
4
|
-
import type
|
|
5
|
-
import type NullType from "#NullType";
|
|
2
|
+
import type NormalizeSchema from "#NormalizeSchema";
|
|
6
3
|
import type ObjectType from "#ObjectType";
|
|
7
4
|
import type OptionalType from "#OptionalType";
|
|
8
5
|
import type Parsed from "#Parsed";
|
|
9
6
|
import type Schema from "#Schema";
|
|
10
|
-
import type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
type InferInputSchema<S, Depth extends number = 3> = [
|
|
15
|
-
Depth
|
|
16
|
-
] extends [never] ? never : S extends DefaultType<infer T, unknown> ? Infer<T> | undefined : S extends OptionalType<infer T> ? Infer<T> | undefined : S extends ObjectType<infer P> ? ImpliedOptional<UndefinedToOptional<{
|
|
17
|
-
[K in keyof P]: InferInputSchema<P[K], DecrementDepth[Depth]>;
|
|
18
|
-
}>> : 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[] ? InferInputSchema<TupleType<{
|
|
19
|
-
[K in keyof S]: S[K] extends Parsed<unknown> ? InferInputSchema<S[K], DecrementDepth[Depth]> : never;
|
|
20
|
-
}>> : S extends {
|
|
7
|
+
import type { ImpliedOptional, UndefinedToOptional } from "@rcompat/type";
|
|
8
|
+
type InferInputSchema<S> = S extends DefaultType<infer T, unknown> ? T["infer"] | undefined : S extends OptionalType<infer T> ? T["infer"] | undefined : S extends ObjectType<infer P> ? ImpliedOptional<UndefinedToOptional<{
|
|
9
|
+
[K in keyof P]: InferInputSchema<P[K]>;
|
|
10
|
+
}>> : S extends Parsed<unknown> ? S["infer"] : S extends {
|
|
21
11
|
[key: string]: Schema;
|
|
22
12
|
} ? ImpliedOptional<UndefinedToOptional<{
|
|
23
|
-
[K in keyof S]: InferInputSchema<S[K]
|
|
24
|
-
}>> :
|
|
13
|
+
[K in keyof S]: InferInputSchema<S[K]>;
|
|
14
|
+
}>> : NormalizeSchema<S>["infer"];
|
|
25
15
|
export type { InferInputSchema as default };
|
|
26
16
|
//# sourceMappingURL=InferInputSchema.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type Parsed from "#Parsed";
|
|
2
2
|
import type StoreSchema from "#StoreSchema";
|
|
3
|
-
import type UndefinedToOptional from "@rcompat/type
|
|
3
|
+
import type { UndefinedToOptional } from "@rcompat/type";
|
|
4
4
|
type StoreValue<T> = T extends Parsed<infer U> ? U : never;
|
|
5
5
|
type InferStore<T extends StoreSchema> = UndefinedToOptional<{
|
|
6
6
|
[K in keyof T]: StoreValue<T[K]>;
|
package/lib/private/IntType.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import CoerceKey from "#CoerceKey";
|
|
|
3
3
|
import type IntDataType from "#IntDataType";
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
5
|
import type ParseOptions from "#ParseOptions";
|
|
6
|
-
import type
|
|
7
|
-
export default class IntType<T extends IntDataType> extends NumericType<T, number, "IntType"> implements
|
|
6
|
+
import type Storable from "#Storable";
|
|
7
|
+
export default class IntType<T extends IntDataType> extends NumericType<T, number, "IntType"> implements Storable<T> {
|
|
8
8
|
[CoerceKey]: typeof coerce;
|
|
9
9
|
get name(): string;
|
|
10
10
|
parse(x: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import OptionalType from "#OptionalType";
|
|
4
|
+
import Parsed from "#Parsed";
|
|
5
|
+
import type ParseOptions from "#ParseOptions";
|
|
6
|
+
import type DefaultTrait from "#trait/Default";
|
|
7
|
+
import type OptionalTrait from "#trait/Optional";
|
|
8
|
+
export default class IsType<T> extends Parsed<T> implements OptionalTrait, DefaultTrait<T> {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(predicate: (x: unknown) => x is T);
|
|
11
|
+
get name(): "is";
|
|
12
|
+
optional(): OptionalType<this>;
|
|
13
|
+
default(value: (() => T) | T): DefaultType<this, T>;
|
|
14
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
15
|
+
toJSON(): {
|
|
16
|
+
type: "is";
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=IsType.d.ts.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
2
|
+
import E from "#errors";
|
|
3
|
+
import OptionalType from "#OptionalType";
|
|
4
|
+
import Parsed from "#Parsed";
|
|
5
|
+
export default class IsType extends Parsed {
|
|
6
|
+
#predicate;
|
|
7
|
+
constructor(predicate) {
|
|
8
|
+
super();
|
|
9
|
+
this.#predicate = predicate;
|
|
10
|
+
}
|
|
11
|
+
get name() {
|
|
12
|
+
return "is";
|
|
13
|
+
}
|
|
14
|
+
optional() {
|
|
15
|
+
return new OptionalType(this);
|
|
16
|
+
}
|
|
17
|
+
default(value) {
|
|
18
|
+
return new DefaultType(this, value);
|
|
19
|
+
}
|
|
20
|
+
parse(x, options = {}) {
|
|
21
|
+
if (!this.#predicate(x))
|
|
22
|
+
throw E.invalid_type(x, this.name, options);
|
|
23
|
+
return x;
|
|
24
|
+
}
|
|
25
|
+
toJSON() {
|
|
26
|
+
return { type: this.name };
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=IsType.js.map
|
package/lib/private/Issue.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import type IssueType from "#IssueType";
|
|
2
|
+
import type { JSONPointer } from "@rcompat/type";
|
|
2
3
|
export default interface Issue {
|
|
4
|
+
readonly type: IssueType;
|
|
3
5
|
readonly message: string;
|
|
4
6
|
readonly path: JSONPointer;
|
|
5
7
|
}
|