pema 0.6.1 → 0.8.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 +6 -3
- package/lib/private/ArrayType.js +15 -6
- package/lib/private/BigIntType.d.ts +1 -1
- package/lib/private/BigUintType.d.ts +1 -1
- package/lib/private/BooleanType.d.ts +5 -1
- package/lib/private/BooleanType.js +6 -0
- package/lib/private/BuiltinType.d.ts +1 -1
- package/lib/private/BuiltinType.js +6 -2
- package/lib/private/ConstructorType.d.ts +1 -1
- package/lib/private/ConstructorType.js +3 -1
- package/lib/private/DateType.d.ts +4 -1
- package/lib/private/DateType.js +6 -0
- package/lib/private/DefaultType.d.ts +1 -1
- package/lib/private/DefaultType.js +6 -5
- package/lib/private/EnumType.d.ts +1 -1
- package/lib/private/EnumType.js +5 -2
- package/lib/private/FunctionType.d.ts +1 -1
- package/lib/private/FunctionType.js +6 -3
- package/lib/private/IntType.d.ts +2 -2
- package/lib/private/IntType.js +2 -2
- package/lib/private/IsType.d.ts +1 -1
- package/lib/private/IsType.js +3 -1
- package/lib/private/JSONType.d.ts +1 -1
- package/lib/private/JSONType.js +3 -1
- package/lib/private/LiteralType.d.ts +6 -4
- package/lib/private/LiteralType.js +10 -8
- package/lib/private/Loose.d.ts +4 -0
- package/lib/private/Loose.js +3 -0
- package/lib/private/Mode.d.ts +3 -0
- package/lib/private/Mode.js +2 -0
- package/lib/private/NormalizeSchema.d.ts +3 -3
- package/lib/private/NullType.d.ts +1 -1
- package/lib/private/NullType.js +5 -2
- package/lib/private/NumberType.d.ts +1 -1
- package/lib/private/NumericType.d.ts +7 -3
- package/lib/private/NumericType.js +5 -2
- package/lib/private/ObjectType.d.ts +8 -5
- package/lib/private/ObjectType.js +17 -6
- package/lib/private/OmitType.d.ts +6 -3
- package/lib/private/OmitType.js +7 -2
- package/lib/private/OptionalType.d.ts +1 -1
- package/lib/private/OptionalType.js +6 -5
- package/lib/private/ParseError.d.ts +1 -1
- package/lib/private/ParseError.js +9 -8
- package/lib/private/ParseOptions.d.ts +2 -1
- package/lib/private/Parsed.d.ts +4 -3
- package/lib/private/Parsed.js +2 -3
- package/lib/private/PartialType.d.ts +6 -3
- package/lib/private/PartialType.js +7 -2
- package/lib/private/PrimitiveType.d.ts +1 -1
- package/lib/private/PrimitiveType.js +7 -4
- package/lib/private/PureType.d.ts +1 -1
- package/lib/private/PureType.js +2 -2
- package/lib/private/RecordType.d.ts +8 -5
- package/lib/private/RecordType.js +7 -2
- package/lib/private/Serialized.d.ts +13 -13
- package/lib/private/Storable.d.ts +1 -0
- package/lib/private/Storable.js +4 -0
- package/lib/private/StoreType.d.ts +2 -2
- package/lib/private/StoreType.js +4 -2
- package/lib/private/TupleType.d.ts +6 -3
- package/lib/private/TupleType.js +14 -5
- package/lib/private/URLType.d.ts +6 -1
- package/lib/private/URLType.js +21 -0
- package/lib/private/UUIDType.d.ts +1 -1
- package/lib/private/UUIDType.js +3 -1
- package/lib/private/UUIDV4Type.d.ts +1 -1
- package/lib/private/UUIDV4Type.js +3 -1
- package/lib/private/UUIDV7Type.d.ts +1 -1
- package/lib/private/UUIDV7Type.js +3 -1
- package/lib/private/UintType.d.ts +2 -2
- package/lib/private/UintType.js +2 -2
- package/lib/private/UnionType.d.ts +6 -3
- package/lib/private/UnionType.js +10 -5
- package/lib/private/VirtualType.js +2 -2
- package/lib/private/array.d.ts +6 -4
- package/lib/private/array.js +10 -2
- package/lib/private/blob.d.ts +6 -2
- package/lib/private/blob.js +5 -1
- package/lib/private/boolean.d.ts +5 -4
- package/lib/private/boolean.js +5 -4
- package/lib/private/coerce/date.js +3 -5
- package/lib/private/coerce/int.js +1 -1
- package/lib/private/constructor.d.ts +6 -5
- package/lib/private/constructor.js +11 -1
- package/lib/private/date.d.ts +6 -2
- package/lib/private/date.js +5 -1
- package/lib/private/dict.d.ts +12 -2
- package/lib/private/dict.js +10 -2
- package/lib/private/enum.d.ts +9 -1
- package/lib/private/enum.js +8 -1
- package/lib/private/errors.js +5 -6
- package/lib/private/f32.d.ts +6 -2
- package/lib/private/f32.js +5 -1
- package/lib/private/f64.d.ts +6 -2
- package/lib/private/f64.js +5 -1
- package/lib/private/file.d.ts +6 -2
- package/lib/private/file.js +5 -1
- package/lib/private/function.d.ts +6 -5
- package/lib/private/function.js +5 -1
- package/lib/private/i128.d.ts +6 -2
- package/lib/private/i128.js +5 -1
- package/lib/private/i16.d.ts +6 -2
- package/lib/private/i16.js +5 -1
- package/lib/private/i32.d.ts +6 -2
- package/lib/private/i32.js +5 -1
- package/lib/private/i64.d.ts +6 -2
- package/lib/private/i64.js +5 -1
- package/lib/private/i8.d.ts +6 -2
- package/lib/private/i8.js +5 -1
- package/lib/private/index.d.ts +257 -41
- package/lib/private/index.js +148 -41
- package/lib/private/is-parsed.d.ts +3 -0
- package/lib/private/is-parsed.js +7 -0
- package/lib/private/is.d.ts +6 -2
- package/lib/private/is.js +9 -1
- package/lib/private/json.d.ts +12 -2
- package/lib/private/json.js +9 -1
- package/lib/private/literal.d.ts +9 -1
- package/lib/private/literal.js +10 -1
- package/lib/private/normalize.js +4 -11
- package/lib/private/null.d.ts +6 -2
- package/lib/private/null.js +5 -1
- package/lib/private/object.d.ts +11 -4
- package/lib/private/object.js +17 -1
- package/lib/private/omit.d.ts +9 -1
- package/lib/private/omit.js +9 -1
- package/lib/private/partial.d.ts +9 -2
- package/lib/private/partial.js +11 -2
- package/lib/private/path/next.d.ts +1 -7
- package/lib/private/pure.d.ts +9 -1
- package/lib/private/pure.js +9 -1
- package/lib/private/record.d.ts +6 -5
- package/lib/private/record.js +9 -1
- package/lib/private/resolve.d.ts +2 -0
- package/lib/private/resolve.js +7 -0
- package/lib/private/spec/bigint.d.ts +5 -1
- package/lib/private/spec/bigint.js +28 -26
- package/lib/private/spec/biguint.d.ts +5 -1
- package/lib/private/spec/biguint.js +30 -22
- package/lib/private/spec/int.d.ts +5 -1
- package/lib/private/spec/int.js +25 -23
- package/lib/private/spec/uint.d.ts +5 -1
- package/lib/private/spec/uint.js +23 -21
- package/lib/private/string.d.ts +6 -5
- package/lib/private/string.js +5 -4
- package/lib/private/symbol.d.ts +6 -2
- package/lib/private/symbol.js +5 -1
- package/lib/private/test.d.ts +4 -21
- package/lib/private/test.js +0 -44
- package/lib/private/tuple.d.ts +9 -2
- package/lib/private/tuple.js +11 -1
- package/lib/private/u128.d.ts +6 -2
- package/lib/private/u128.js +5 -1
- package/lib/private/u16.d.ts +6 -2
- package/lib/private/u16.js +5 -1
- package/lib/private/u32.d.ts +6 -5
- package/lib/private/u32.js +5 -4
- package/lib/private/u64.d.ts +6 -2
- package/lib/private/u64.js +5 -1
- package/lib/private/u8.d.ts +6 -2
- package/lib/private/u8.js +5 -1
- package/lib/private/undefined.d.ts +5 -1
- package/lib/private/undefined.js +4 -1
- package/lib/private/union.d.ts +12 -3
- package/lib/private/union.js +9 -1
- package/lib/private/unknown.d.ts +5 -4
- package/lib/private/unknown.js +4 -1
- package/lib/private/url.d.ts +6 -2
- package/lib/private/url.js +5 -1
- package/lib/private/uuid.d.ts +6 -2
- package/lib/private/uuid.js +5 -1
- package/package.json +8 -7
- package/lib/private/is-parsed-type.d.ts +0 -3
- package/lib/private/is-parsed-type.js +0 -6
package/lib/private/TupleType.js
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import E from "#errors";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
|
+
import Loose from "#Loose";
|
|
3
4
|
import OptionalType from "#OptionalType";
|
|
4
5
|
import next from "#path/next";
|
|
6
|
+
import resolve from "#resolve";
|
|
7
|
+
import is from "@rcompat/is";
|
|
5
8
|
export default class TupleType extends GenericType {
|
|
6
9
|
#items;
|
|
7
|
-
|
|
10
|
+
[Loose];
|
|
11
|
+
constructor(items, mode) {
|
|
8
12
|
super();
|
|
9
13
|
this.#items = items;
|
|
14
|
+
this[Loose] = mode;
|
|
10
15
|
}
|
|
11
16
|
get name() {
|
|
12
17
|
return "tuple";
|
|
@@ -14,19 +19,23 @@ export default class TupleType extends GenericType {
|
|
|
14
19
|
optional() {
|
|
15
20
|
return new OptionalType(this);
|
|
16
21
|
}
|
|
17
|
-
parse(
|
|
18
|
-
|
|
22
|
+
parse(u, options = {}) {
|
|
23
|
+
const x = resolve(u);
|
|
24
|
+
if (!is.array(x))
|
|
19
25
|
throw E.invalid_type(x, "array", options);
|
|
26
|
+
const $options = this[Loose] !== undefined
|
|
27
|
+
? { ...options, [Loose]: this[Loose] }
|
|
28
|
+
: options;
|
|
20
29
|
const items = this.#items;
|
|
21
30
|
const n = items.length;
|
|
22
31
|
const out = new Array(n);
|
|
23
32
|
// validate each expected item
|
|
24
33
|
for (let i = 0; i < n; i++) {
|
|
25
|
-
out[i] = items[i].parse(x[i], next(i, options));
|
|
34
|
+
out[i] = items[i].parse(x[i], next(i, $options));
|
|
26
35
|
}
|
|
27
36
|
// reject extra items
|
|
28
37
|
if (x.length > n)
|
|
29
|
-
throw E.invalid_type(x[n], "undefined", next(n, options));
|
|
38
|
+
throw E.invalid_type(x[n], "undefined", next(n, $options));
|
|
30
39
|
return out;
|
|
31
40
|
}
|
|
32
41
|
toJSON() {
|
package/lib/private/URLType.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import Loose from "#Loose";
|
|
2
4
|
import Storable from "#Storable";
|
|
3
|
-
export default class URLType extends BuiltinType<URL, "URLType"> implements Storable<"url"> {
|
|
5
|
+
export default class URLType<M extends boolean | undefined = undefined> extends BuiltinType<URL, "URLType"> implements Storable<"url"> {
|
|
6
|
+
[Loose]: M;
|
|
7
|
+
constructor(mode?: M);
|
|
4
8
|
get Type(): {
|
|
5
9
|
new (url: string | URL, base?: string | URL): URL;
|
|
6
10
|
prototype: URL;
|
|
@@ -11,6 +15,7 @@ export default class URLType extends BuiltinType<URL, "URLType"> implements Stor
|
|
|
11
15
|
};
|
|
12
16
|
get name(): "url";
|
|
13
17
|
get datatype(): "url";
|
|
18
|
+
[CoerceKey](x: unknown): unknown;
|
|
14
19
|
toJSON(): {
|
|
15
20
|
type: "url";
|
|
16
21
|
datatype: "url";
|
package/lib/private/URLType.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
|
+
import CoerceKey from "#CoerceKey";
|
|
3
|
+
import Loose from "#Loose";
|
|
2
4
|
import Storable from "#Storable";
|
|
5
|
+
import is from "@rcompat/is";
|
|
3
6
|
export default class URLType extends BuiltinType {
|
|
7
|
+
[Loose];
|
|
8
|
+
constructor(mode) {
|
|
9
|
+
super();
|
|
10
|
+
this[Loose] = mode;
|
|
11
|
+
}
|
|
12
|
+
/*get [as.out](): L extends true ? "text" : never {
|
|
13
|
+
return (this[Loose] === true ? as.$("text") : as.$()) as never;
|
|
14
|
+
}*/
|
|
4
15
|
get Type() {
|
|
5
16
|
return URL;
|
|
6
17
|
}
|
|
@@ -10,6 +21,16 @@ export default class URLType extends BuiltinType {
|
|
|
10
21
|
get datatype() {
|
|
11
22
|
return "url";
|
|
12
23
|
}
|
|
24
|
+
[CoerceKey](x) {
|
|
25
|
+
if (!is.string(x))
|
|
26
|
+
return x;
|
|
27
|
+
try {
|
|
28
|
+
return new URL(x);
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return x;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
13
34
|
toJSON() {
|
|
14
35
|
return Storable.serialize(this);
|
|
15
36
|
}
|
|
@@ -6,7 +6,7 @@ import UUIDV7Type from "#UUIDV7Type";
|
|
|
6
6
|
export default class UUIDType extends PrimitiveType<string, "UUIDType"> implements Storable<"uuid"> {
|
|
7
7
|
get name(): "string";
|
|
8
8
|
get datatype(): "uuid";
|
|
9
|
-
parse(
|
|
9
|
+
parse(u: unknown): Infer<this>;
|
|
10
10
|
toJSON(): {
|
|
11
11
|
type: "string";
|
|
12
12
|
datatype: "uuid";
|
package/lib/private/UUIDType.js
CHANGED
|
@@ -3,6 +3,7 @@ import Storable from "#Storable";
|
|
|
3
3
|
import UUIDV4Type from "#UUIDV4Type";
|
|
4
4
|
import UUIDV7Type from "#UUIDV7Type";
|
|
5
5
|
import E from "#errors";
|
|
6
|
+
import resolve from "#resolve";
|
|
6
7
|
import is from "@rcompat/is";
|
|
7
8
|
const re = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
8
9
|
const v4 = new UUIDV4Type();
|
|
@@ -14,7 +15,8 @@ export default class UUIDType extends PrimitiveType {
|
|
|
14
15
|
get datatype() {
|
|
15
16
|
return "uuid";
|
|
16
17
|
}
|
|
17
|
-
parse(
|
|
18
|
+
parse(u) {
|
|
19
|
+
const x = resolve(u);
|
|
18
20
|
if (!is.string(x) || !re.test(x)) {
|
|
19
21
|
throw E.invalid_format(x, `"${x}" is not a valid UUID`);
|
|
20
22
|
}
|
|
@@ -4,7 +4,7 @@ import Storable from "#Storable";
|
|
|
4
4
|
export default class UUIDV4Type extends PrimitiveType<string, "UUIDV4Type"> implements Storable<"uuid_v4"> {
|
|
5
5
|
get name(): "string";
|
|
6
6
|
get datatype(): "uuid_v4";
|
|
7
|
-
parse(
|
|
7
|
+
parse(u: unknown): Infer<this>;
|
|
8
8
|
toJSON(): {
|
|
9
9
|
type: "string";
|
|
10
10
|
datatype: "uuid_v4";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
2
|
import Storable from "#Storable";
|
|
3
3
|
import E from "#errors";
|
|
4
|
+
import resolve from "#resolve";
|
|
4
5
|
import is from "@rcompat/is";
|
|
5
6
|
const re = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
|
|
6
7
|
export default class UUIDV4Type extends PrimitiveType {
|
|
@@ -10,7 +11,8 @@ export default class UUIDV4Type extends PrimitiveType {
|
|
|
10
11
|
get datatype() {
|
|
11
12
|
return "uuid_v4";
|
|
12
13
|
}
|
|
13
|
-
parse(
|
|
14
|
+
parse(u) {
|
|
15
|
+
const x = resolve(u);
|
|
14
16
|
if (!is.string(x) || !re.test(x)) {
|
|
15
17
|
throw E.invalid_format(x, `"${x}" is not a valid UUID v4`);
|
|
16
18
|
}
|
|
@@ -4,7 +4,7 @@ import Storable from "#Storable";
|
|
|
4
4
|
export default class UUIDV7Type extends PrimitiveType<string, "UUIDV7Type"> implements Storable<"uuid_v7"> {
|
|
5
5
|
get name(): "string";
|
|
6
6
|
get datatype(): "uuid_v7";
|
|
7
|
-
parse(
|
|
7
|
+
parse(u: unknown): Infer<this>;
|
|
8
8
|
toJSON(): {
|
|
9
9
|
type: "string";
|
|
10
10
|
datatype: "uuid_v7";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import PrimitiveType from "#PrimitiveType";
|
|
2
2
|
import Storable from "#Storable";
|
|
3
3
|
import E from "#errors";
|
|
4
|
+
import resolve from "#resolve";
|
|
4
5
|
import is from "@rcompat/is";
|
|
5
6
|
const re = /^[\da-f]{8}-[\da-f]{4}-7[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
|
|
6
7
|
export default class UUIDV7Type extends PrimitiveType {
|
|
@@ -10,7 +11,8 @@ export default class UUIDV7Type extends PrimitiveType {
|
|
|
10
11
|
get datatype() {
|
|
11
12
|
return "uuid_v7";
|
|
12
13
|
}
|
|
13
|
-
parse(
|
|
14
|
+
parse(u) {
|
|
15
|
+
const x = resolve(u);
|
|
14
16
|
if (!is.string(x) || !re.test(x)) {
|
|
15
17
|
throw E.invalid_format(x, `"${x}" is not a valid UUID v7`);
|
|
16
18
|
}
|
|
@@ -4,13 +4,13 @@ import NumericType from "#NumericType";
|
|
|
4
4
|
import type ParseOptions from "#ParseOptions";
|
|
5
5
|
import type Storable from "#Storable";
|
|
6
6
|
import type UintDataType from "#UintDataType";
|
|
7
|
-
export default class UintType<T extends UintDataType> extends NumericType<T, number, "UintType"> implements Storable<T> {
|
|
7
|
+
export default class UintType<T extends UintDataType, L extends boolean | undefined = undefined> extends NumericType<T, number, "UintType", L> implements Storable<T> {
|
|
8
8
|
[CoerceKey]: typeof coerce;
|
|
9
9
|
get name(): string;
|
|
10
10
|
/**
|
|
11
11
|
* Value is a non-privileged port number (1000 - 65535).
|
|
12
12
|
*/
|
|
13
13
|
port(): this;
|
|
14
|
-
parse(
|
|
14
|
+
parse(u: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=UintType.d.ts.map
|
package/lib/private/UintType.js
CHANGED
|
@@ -14,8 +14,8 @@ export default class UintType extends NumericType {
|
|
|
14
14
|
port() {
|
|
15
15
|
return this.derive({ validators: [port] });
|
|
16
16
|
}
|
|
17
|
-
parse(
|
|
18
|
-
return super.parse(
|
|
17
|
+
parse(u, options = {}) {
|
|
18
|
+
return super.parse(u, {
|
|
19
19
|
...options,
|
|
20
20
|
validators: [integer],
|
|
21
21
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
|
+
import type Mode from "#Mode";
|
|
2
3
|
import GenericType from "#GenericType";
|
|
3
4
|
import type Infer from "#Infer";
|
|
4
5
|
import type NormalizeSchema from "#NormalizeSchema";
|
|
@@ -9,17 +10,19 @@ import type Schema from "#Schema";
|
|
|
9
10
|
import type DefaultTrait from "#trait/Default";
|
|
10
11
|
import type OptionalTrait from "#trait/Optional";
|
|
11
12
|
import type { TupleToUnion } from "@rcompat/type";
|
|
13
|
+
import Loose from "#Loose";
|
|
12
14
|
type InferUnion<T extends Schema[]> = TupleToUnion<{
|
|
13
15
|
[K in keyof T]: T[K] extends Schema ? NormalizeSchema<T[K]>["infer"] : "union-never";
|
|
14
16
|
}>;
|
|
15
|
-
export default class UnionType<T extends Parsed<unknown>[]> extends GenericType<T, InferUnion<T>, "UnionType"> implements OptionalTrait, DefaultTrait<InferUnion<T>> {
|
|
17
|
+
export default class UnionType<T extends Parsed<unknown>[], M extends Mode = undefined> extends GenericType<T, InferUnion<T>, "UnionType"> implements OptionalTrait, DefaultTrait<InferUnion<T>> {
|
|
16
18
|
#private;
|
|
17
|
-
|
|
19
|
+
[Loose]: M;
|
|
20
|
+
constructor(of: T, mode?: M);
|
|
18
21
|
get name(): "union";
|
|
19
22
|
get schema(): T;
|
|
20
23
|
optional(): OptionalType<this>;
|
|
21
24
|
default(value: (() => InferUnion<T>) | InferUnion<T>): DefaultType<this, InferUnion<T>>;
|
|
22
|
-
parse(
|
|
25
|
+
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
|
23
26
|
toJSON(): {
|
|
24
27
|
type: "union";
|
|
25
28
|
of: import("./Serialized.js").default[];
|
package/lib/private/UnionType.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import E from "#errors";
|
|
3
3
|
import GenericType from "#GenericType";
|
|
4
|
-
import
|
|
4
|
+
import is_parsed from "#is-parsed";
|
|
5
5
|
import OptionalType from "#OptionalType";
|
|
6
6
|
import ParseError from "#ParseError";
|
|
7
|
+
import resolve from "#resolve";
|
|
7
8
|
import S from "#schema-errors";
|
|
8
9
|
import assert from "@rcompat/assert";
|
|
10
|
+
import Loose from "#Loose";
|
|
9
11
|
const print = (type) => {
|
|
10
|
-
const parsed =
|
|
12
|
+
const parsed = is_parsed(type);
|
|
11
13
|
if (parsed) {
|
|
12
14
|
return type.name;
|
|
13
15
|
}
|
|
@@ -25,13 +27,15 @@ const print = (type) => {
|
|
|
25
27
|
}
|
|
26
28
|
return type;
|
|
27
29
|
};
|
|
28
|
-
const union_error = (types) => `\`${types.map(t =>
|
|
30
|
+
const union_error = (types) => `\`${types.map(t => is_parsed(t) ? t.name : print(t)).join(" | ")}\``;
|
|
29
31
|
export default class UnionType extends GenericType {
|
|
30
32
|
#of;
|
|
31
|
-
|
|
33
|
+
[Loose];
|
|
34
|
+
constructor(of, mode) {
|
|
32
35
|
assert.true(of.length > 1, S.union_at_least_two_members());
|
|
33
36
|
super();
|
|
34
37
|
this.#of = of;
|
|
38
|
+
this[Loose] = mode;
|
|
35
39
|
}
|
|
36
40
|
get name() {
|
|
37
41
|
return "union";
|
|
@@ -45,7 +49,8 @@ export default class UnionType extends GenericType {
|
|
|
45
49
|
default(value) {
|
|
46
50
|
return new DefaultType(this, value);
|
|
47
51
|
}
|
|
48
|
-
parse(
|
|
52
|
+
parse(u, options = {}) {
|
|
53
|
+
const x = resolve(u);
|
|
49
54
|
for (const type of this.#of) {
|
|
50
55
|
try {
|
|
51
56
|
type.parse(x, options);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import GenericType from "#GenericType";
|
|
2
|
-
|
|
2
|
+
import Storable from "#Storable";
|
|
3
3
|
export default class VirtualType extends GenericType {
|
|
4
4
|
get datatype() {
|
|
5
|
-
if (
|
|
5
|
+
if (Storable.is(this.schema))
|
|
6
6
|
return this.schema.datatype;
|
|
7
7
|
throw new Error("cannot be used in a store");
|
|
8
8
|
}
|
package/lib/private/array.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import ArrayType from "#ArrayType";
|
|
2
2
|
import type NormalizeSchema from "#NormalizeSchema";
|
|
3
3
|
import type Schema from "#Schema";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
declare const array: {
|
|
5
|
+
strict: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, false>;
|
|
6
|
+
loose: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>, true>;
|
|
7
|
+
vanilla: <const S extends Schema>(of: S) => ArrayType<NormalizeSchema<S>>;
|
|
8
|
+
};
|
|
9
|
+
export default array;
|
|
8
10
|
//# sourceMappingURL=array.d.ts.map
|
package/lib/private/array.js
CHANGED
|
@@ -3,7 +3,15 @@ import normalize from "#normalize";
|
|
|
3
3
|
/**
|
|
4
4
|
* Value is an array of the given type.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
const vanilla = function array(of) {
|
|
7
7
|
return new ArrayType(normalize(of));
|
|
8
|
-
}
|
|
8
|
+
};
|
|
9
|
+
const loose = function array(of) {
|
|
10
|
+
return new ArrayType(normalize(of), true);
|
|
11
|
+
};
|
|
12
|
+
const strict = function array(of) {
|
|
13
|
+
return new ArrayType(normalize(of), false);
|
|
14
|
+
};
|
|
15
|
+
const array = { strict, loose, vanilla };
|
|
16
|
+
export default array;
|
|
9
17
|
//# sourceMappingURL=array.js.map
|
package/lib/private/blob.d.ts
CHANGED
package/lib/private/blob.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import BlobType from "#BlobType";
|
|
2
|
-
|
|
2
|
+
const vanilla = new BlobType();
|
|
3
|
+
const loose = new BlobType();
|
|
4
|
+
const strict = new BlobType();
|
|
5
|
+
const blob = { vanilla, loose, strict };
|
|
6
|
+
export default blob;
|
|
3
7
|
//# sourceMappingURL=blob.js.map
|
package/lib/private/boolean.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import BooleanType from "#BooleanType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
declare const _default: {
|
|
3
|
+
strict: BooleanType<false>;
|
|
4
|
+
loose: BooleanType<true>;
|
|
5
|
+
vanilla: BooleanType<undefined>;
|
|
6
|
+
};
|
|
6
7
|
export default _default;
|
|
7
8
|
//# sourceMappingURL=boolean.d.ts.map
|
package/lib/private/boolean.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import BooleanType from "#BooleanType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export default {
|
|
3
|
+
strict: new BooleanType(false),
|
|
4
|
+
loose: new BooleanType(true),
|
|
5
|
+
vanilla: new BooleanType(),
|
|
6
|
+
};
|
|
6
7
|
//# sourceMappingURL=boolean.js.map
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import is from "@rcompat/is";
|
|
1
2
|
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
2
3
|
// time with optional :ss and .ms, but TZ is REQUIRED (Z or ±HH:MM)
|
|
3
4
|
const ISO_DATETIME_TZ = /^\d{4}-\d{2}-\d{2}[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,3})?)?(?:Z|[+-]\d{2}:\d{2})$/;
|
|
@@ -44,13 +45,10 @@ export default function coerceDate(x) {
|
|
|
44
45
|
if (x instanceof Date)
|
|
45
46
|
return x;
|
|
46
47
|
// numbers are treated as epochs
|
|
47
|
-
if (
|
|
48
|
+
if (is.finite(x))
|
|
48
49
|
return fromNumber(x);
|
|
49
|
-
|
|
50
|
-
// strings
|
|
51
|
-
if (typeof x === "string") {
|
|
50
|
+
if (is.string(x))
|
|
52
51
|
return fromString(x);
|
|
53
|
-
}
|
|
54
52
|
return x;
|
|
55
53
|
}
|
|
56
54
|
//# sourceMappingURL=date.js.map
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import ConstructorType from "#ConstructorType";
|
|
2
2
|
import type { AbstractNewable } from "@rcompat/type";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
declare const constructor: {
|
|
4
|
+
vanilla: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
|
|
5
|
+
loose: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
|
|
6
|
+
strict: <const C extends AbstractNewable>(c: C) => ConstructorType<C>;
|
|
7
|
+
};
|
|
8
|
+
export default constructor;
|
|
8
9
|
//# sourceMappingURL=constructor.d.ts.map
|
|
@@ -2,5 +2,15 @@ import ConstructorType from "#ConstructorType";
|
|
|
2
2
|
/**
|
|
3
3
|
* Value is a constructed instance of the given class.
|
|
4
4
|
*/
|
|
5
|
-
|
|
5
|
+
const vanilla = function constructor(c) {
|
|
6
|
+
return new ConstructorType(c);
|
|
7
|
+
};
|
|
8
|
+
const loose = function constructor(c) {
|
|
9
|
+
return new ConstructorType(c);
|
|
10
|
+
};
|
|
11
|
+
const strict = function constructor(c) {
|
|
12
|
+
return new ConstructorType(c);
|
|
13
|
+
};
|
|
14
|
+
const constructor = { vanilla, loose, strict };
|
|
15
|
+
export default constructor;
|
|
6
16
|
//# sourceMappingURL=constructor.js.map
|
package/lib/private/date.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import DateType from "#DateType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const date: {
|
|
3
|
+
vanilla: DateType<undefined>;
|
|
4
|
+
loose: DateType<true>;
|
|
5
|
+
strict: DateType<false>;
|
|
6
|
+
};
|
|
7
|
+
export default date;
|
|
4
8
|
//# sourceMappingURL=date.d.ts.map
|
package/lib/private/date.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import DateType from "#DateType";
|
|
2
|
-
|
|
2
|
+
const vanilla = new DateType();
|
|
3
|
+
const loose = new DateType(true);
|
|
4
|
+
const strict = new DateType(false);
|
|
5
|
+
const date = { vanilla, loose, strict };
|
|
6
|
+
export default date;
|
|
3
7
|
//# sourceMappingURL=date.js.map
|
package/lib/private/dict.d.ts
CHANGED
|
@@ -6,6 +6,16 @@ import type StringType from "#StringType";
|
|
|
6
6
|
*
|
|
7
7
|
* @param of - The value type (defaults to p.string)
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
declare function vanilla(): RecordType<StringType, StringType>;
|
|
10
|
+
declare function vanilla<const Value extends Parsed<unknown>>(of: Value): RecordType<StringType, Value>;
|
|
11
|
+
declare function loose(): RecordType<StringType, StringType, true>;
|
|
12
|
+
declare function loose<const Value extends Parsed<unknown>>(of: Value): RecordType<StringType, Value, true>;
|
|
13
|
+
declare function strict(): RecordType<StringType, StringType, false>;
|
|
14
|
+
declare function strict<const Value extends Parsed<unknown>>(of: Value): RecordType<StringType, Value, false>;
|
|
15
|
+
declare const dict: {
|
|
16
|
+
vanilla: typeof vanilla;
|
|
17
|
+
loose: typeof loose;
|
|
18
|
+
strict: typeof strict;
|
|
19
|
+
};
|
|
20
|
+
export default dict;
|
|
11
21
|
//# sourceMappingURL=dict.d.ts.map
|
package/lib/private/dict.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import record from "#record";
|
|
2
2
|
import string from "#string";
|
|
3
|
-
|
|
4
|
-
return record(string, of);
|
|
3
|
+
function vanilla(of = string.strict) {
|
|
4
|
+
return record.vanilla(string.strict, of);
|
|
5
5
|
}
|
|
6
|
+
function loose(of = string.loose) {
|
|
7
|
+
return record.loose(string.loose, of);
|
|
8
|
+
}
|
|
9
|
+
function strict(of = string.loose) {
|
|
10
|
+
return record.strict(string.loose, of);
|
|
11
|
+
}
|
|
12
|
+
const dict = { vanilla, loose, strict };
|
|
13
|
+
export default dict;
|
|
6
14
|
//# sourceMappingURL=dict.js.map
|
package/lib/private/enum.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
import EnumType from "#EnumType";
|
|
2
|
-
|
|
2
|
+
declare function vanilla<T extends readonly string[]>(values: T): EnumType<T>;
|
|
3
|
+
declare function loose<T extends readonly string[]>(values: T): EnumType<T>;
|
|
4
|
+
declare function strict<T extends readonly string[]>(values: T): EnumType<T>;
|
|
5
|
+
declare const _default: {
|
|
6
|
+
loose: typeof loose;
|
|
7
|
+
strict: typeof strict;
|
|
8
|
+
vanilla: typeof vanilla;
|
|
9
|
+
};
|
|
10
|
+
export default _default;
|
|
3
11
|
//# sourceMappingURL=enum.d.ts.map
|
package/lib/private/enum.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import EnumType from "#EnumType";
|
|
2
|
-
|
|
2
|
+
function vanilla(values) {
|
|
3
3
|
return new EnumType(values);
|
|
4
4
|
}
|
|
5
|
+
function loose(values) {
|
|
6
|
+
return new EnumType(values);
|
|
7
|
+
}
|
|
8
|
+
function strict(values) {
|
|
9
|
+
return new EnumType(values);
|
|
10
|
+
}
|
|
11
|
+
export default { loose, strict, vanilla };
|
|
5
12
|
//# sourceMappingURL=enum.js.map
|
package/lib/private/errors.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import ParsedKey from "#ParsedKey";
|
|
2
2
|
import ParseError from "#ParseError";
|
|
3
|
+
import is from "@rcompat/is";
|
|
3
4
|
function print_got(x) {
|
|
4
|
-
if (x
|
|
5
|
+
if (is.undefined(x))
|
|
5
6
|
return "undefined";
|
|
6
|
-
if (x
|
|
7
|
+
if (is.null(x))
|
|
7
8
|
return "null";
|
|
8
|
-
return `\`${x
|
|
9
|
+
return `\`${x.toString()}\` (${typeof x})`;
|
|
9
10
|
}
|
|
10
11
|
function invalid_type(input, expected, options = "") {
|
|
11
|
-
const path =
|
|
12
|
-
? options
|
|
13
|
-
: options[ParsedKey] ?? "";
|
|
12
|
+
const path = is.string(options) ? options : options[ParsedKey] ?? "";
|
|
14
13
|
return new ParseError([{
|
|
15
14
|
type: "invalid_type",
|
|
16
15
|
input,
|
package/lib/private/f32.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import NumberType from "#NumberType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const f32$: {
|
|
3
|
+
vanilla: NumberType<"f32", undefined>;
|
|
4
|
+
loose: NumberType<"f32", true>;
|
|
5
|
+
strict: NumberType<"f32", false>;
|
|
6
|
+
};
|
|
7
|
+
export default f32$;
|
|
4
8
|
//# sourceMappingURL=f32.d.ts.map
|
package/lib/private/f32.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import NumberType from "#NumberType";
|
|
2
2
|
import f32 from "#validator/f32";
|
|
3
|
-
|
|
3
|
+
const vanilla = new NumberType("f32", undefined, [f32]);
|
|
4
|
+
const strict = new NumberType("f32", false, [f32]);
|
|
5
|
+
const loose = new NumberType("f32", true, [f32]);
|
|
6
|
+
const f32$ = { vanilla, loose, strict };
|
|
7
|
+
export default f32$;
|
|
4
8
|
//# sourceMappingURL=f32.js.map
|
package/lib/private/f64.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import NumberType from "#NumberType";
|
|
2
|
-
declare const
|
|
3
|
-
|
|
2
|
+
declare const f64: {
|
|
3
|
+
strict: NumberType<"f64", false>;
|
|
4
|
+
loose: NumberType<"f64", true>;
|
|
5
|
+
vanilla: NumberType<"f64", undefined>;
|
|
6
|
+
};
|
|
7
|
+
export default f64;
|
|
4
8
|
//# sourceMappingURL=f64.d.ts.map
|
package/lib/private/f64.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import NumberType from "#NumberType";
|
|
2
|
-
|
|
2
|
+
const vanilla = new NumberType("f64");
|
|
3
|
+
const loose = new NumberType("f64", true);
|
|
4
|
+
const strict = new NumberType("f64", false);
|
|
5
|
+
const f64 = { strict, loose, vanilla };
|
|
6
|
+
export default f64;
|
|
3
7
|
//# sourceMappingURL=f64.js.map
|
package/lib/private/file.d.ts
CHANGED
package/lib/private/file.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
import FileType from "#FileType";
|
|
2
|
-
|
|
2
|
+
const vanilla = new FileType();
|
|
3
|
+
const loose = new FileType();
|
|
4
|
+
const strict = new FileType();
|
|
5
|
+
const file = { vanilla, loose, strict };
|
|
6
|
+
export default file;
|
|
3
7
|
//# sourceMappingURL=file.js.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import FunctionType from "#FunctionType";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
declare const function$: {
|
|
3
|
+
vanilla: FunctionType;
|
|
4
|
+
loose: FunctionType;
|
|
5
|
+
strict: FunctionType;
|
|
6
|
+
};
|
|
7
|
+
export default function$;
|
|
7
8
|
//# sourceMappingURL=function.d.ts.map
|