pema 0.7.0 → 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 +5 -2
- package/lib/private/ArrayType.js +4 -2
- 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/DateType.d.ts +4 -1
- package/lib/private/DateType.js +6 -0
- package/lib/private/IntType.d.ts +1 -1
- package/lib/private/LiteralType.d.ts +5 -2
- package/lib/private/LiteralType.js +7 -4
- package/lib/private/Mode.d.ts +3 -0
- package/lib/private/Mode.js +2 -0
- package/lib/private/NumberType.d.ts +1 -1
- package/lib/private/NumericType.d.ts +5 -2
- package/lib/private/NumericType.js +5 -2
- package/lib/private/ObjectType.d.ts +7 -4
- package/lib/private/ObjectType.js +6 -8
- package/lib/private/OmitType.d.ts +5 -2
- package/lib/private/OmitType.js +4 -1
- package/lib/private/PartialType.d.ts +5 -2
- package/lib/private/PartialType.js +4 -1
- package/lib/private/RecordType.d.ts +7 -4
- package/lib/private/RecordType.js +4 -1
- package/lib/private/Serialized.d.ts +13 -13
- package/lib/private/StoreType.d.ts +1 -1
- package/lib/private/TupleType.d.ts +5 -2
- package/lib/private/TupleType.js +3 -1
- package/lib/private/URLType.d.ts +6 -1
- package/lib/private/URLType.js +21 -0
- package/lib/private/UintType.d.ts +1 -1
- package/lib/private/UnionType.d.ts +5 -2
- package/lib/private/UnionType.js +4 -1
- package/lib/private/array.d.ts +2 -2
- package/lib/private/array.js +2 -7
- package/lib/private/blob.js +0 -3
- package/lib/private/boolean.d.ts +5 -5
- package/lib/private/boolean.js +5 -8
- package/lib/private/constructor.js +2 -7
- package/lib/private/date.d.ts +3 -3
- package/lib/private/date.js +2 -5
- package/lib/private/dict.d.ts +4 -4
- package/lib/private/enum.d.ts +3 -3
- package/lib/private/enum.js +3 -9
- package/lib/private/f32.d.ts +3 -3
- package/lib/private/f32.js +3 -6
- package/lib/private/f64.d.ts +3 -3
- package/lib/private/f64.js +2 -5
- package/lib/private/file.js +0 -3
- package/lib/private/function.js +0 -3
- package/lib/private/i128.d.ts +3 -3
- package/lib/private/i128.js +3 -6
- package/lib/private/i16.d.ts +3 -3
- package/lib/private/i16.js +3 -6
- package/lib/private/i32.d.ts +3 -3
- package/lib/private/i32.js +3 -6
- package/lib/private/i64.d.ts +3 -3
- package/lib/private/i64.js +3 -6
- package/lib/private/i8.d.ts +3 -3
- package/lib/private/i8.js +3 -6
- package/lib/private/index.d.ts +241 -43
- package/lib/private/is.js +2 -7
- package/lib/private/json.js +2 -7
- package/lib/private/literal.d.ts +5 -5
- package/lib/private/literal.js +3 -9
- package/lib/private/null.js +0 -3
- package/lib/private/object.d.ts +2 -2
- package/lib/private/object.js +2 -7
- package/lib/private/omit.d.ts +2 -2
- package/lib/private/omit.js +2 -7
- package/lib/private/partial.d.ts +2 -2
- package/lib/private/partial.js +2 -7
- package/lib/private/pure.js +2 -7
- package/lib/private/record.d.ts +3 -3
- package/lib/private/record.js +2 -7
- package/lib/private/spec/bigint.d.ts +3 -2
- package/lib/private/spec/bigint.js +1 -0
- package/lib/private/spec/biguint.d.ts +3 -2
- package/lib/private/spec/biguint.js +7 -0
- package/lib/private/spec/int.d.ts +3 -2
- package/lib/private/spec/int.js +2 -1
- package/lib/private/spec/uint.d.ts +3 -2
- package/lib/private/spec/uint.js +1 -0
- package/lib/private/string.js +0 -3
- package/lib/private/symbol.js +0 -3
- package/lib/private/tuple.d.ts +2 -2
- package/lib/private/tuple.js +2 -7
- package/lib/private/u128.d.ts +3 -3
- package/lib/private/u128.js +3 -6
- package/lib/private/u16.d.ts +3 -3
- package/lib/private/u16.js +3 -6
- package/lib/private/u32.d.ts +3 -3
- package/lib/private/u32.js +3 -9
- package/lib/private/u64.d.ts +3 -3
- package/lib/private/u64.js +3 -6
- package/lib/private/u8.d.ts +3 -3
- package/lib/private/u8.js +3 -6
- package/lib/private/undefined.d.ts +2 -2
- package/lib/private/undefined.js +1 -5
- package/lib/private/union.d.ts +4 -4
- package/lib/private/union.js +2 -7
- package/lib/private/unknown.d.ts +2 -2
- package/lib/private/unknown.js +1 -5
- package/lib/private/url.d.ts +3 -3
- package/lib/private/url.js +2 -5
- package/lib/private/uuid.js +0 -3
- package/package.json +2 -2
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
3
|
import type Infer from "#Infer";
|
|
4
|
+
import Loose from "#Loose";
|
|
5
|
+
import type Mode from "#Mode";
|
|
4
6
|
import OptionalType from "#OptionalType";
|
|
5
7
|
import type Parsed from "#Parsed";
|
|
6
8
|
import type ParseOptions from "#ParseOptions";
|
|
@@ -11,9 +13,10 @@ import type { Primitive } from "@rcompat/type";
|
|
|
11
13
|
type Next<T> = {
|
|
12
14
|
validators?: Validator<T>[];
|
|
13
15
|
};
|
|
14
|
-
export default class ArrayType<T extends Parsed<unknown
|
|
16
|
+
export default class ArrayType<T extends Parsed<unknown>, M extends Mode = undefined> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait, DefaultTrait<Infer<T>[]> {
|
|
15
17
|
#private;
|
|
16
|
-
|
|
18
|
+
[Loose]: M;
|
|
19
|
+
constructor(item: T, mode?: M, validators?: Validator<Array<Infer<T>>>[]);
|
|
17
20
|
get name(): "array";
|
|
18
21
|
optional(): OptionalType<this>;
|
|
19
22
|
default(value: (() => Infer<T>[]) | Infer<T>[]): DefaultType<this, Infer<T>[]>;
|
package/lib/private/ArrayType.js
CHANGED
|
@@ -24,9 +24,11 @@ function isPrimitive(x) {
|
|
|
24
24
|
export default class ArrayType extends GenericType {
|
|
25
25
|
#item;
|
|
26
26
|
#validators;
|
|
27
|
-
|
|
27
|
+
[Loose];
|
|
28
|
+
constructor(item, mode, validators = []) {
|
|
28
29
|
super();
|
|
29
30
|
this.#item = item;
|
|
31
|
+
this[Loose] = mode;
|
|
30
32
|
this.#validators = validators;
|
|
31
33
|
}
|
|
32
34
|
get name() {
|
|
@@ -40,7 +42,7 @@ export default class ArrayType extends GenericType {
|
|
|
40
42
|
}
|
|
41
43
|
derive(_next) {
|
|
42
44
|
const Constructor = this.constructor;
|
|
43
|
-
return new Constructor(this.#item, [...this.#validators, ..._next.validators ?? []]);
|
|
45
|
+
return new Constructor(this.#item, this[Loose], [...this.#validators, ..._next.validators ?? []]);
|
|
44
46
|
}
|
|
45
47
|
/**
|
|
46
48
|
* Member values are unique — only for primitive subtypes.
|
|
@@ -3,7 +3,7 @@ import coerce from "#coerce/bigint";
|
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
5
|
import type Storable from "#Storable";
|
|
6
|
-
export default class BigIntType<T extends BigIntDataType = "i64"> extends NumericType<T, bigint, "BigIntType"> implements Storable<T> {
|
|
6
|
+
export default class BigIntType<T extends BigIntDataType = "i64", L extends boolean | undefined = undefined> extends NumericType<T, bigint, "BigIntType", L> implements Storable<T> {
|
|
7
7
|
[CoerceKey]: typeof coerce;
|
|
8
8
|
get name(): string;
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@ import coerce from "#coerce/bigint";
|
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
5
|
import type Storable from "#Storable";
|
|
6
|
-
export default class BigUintType<T extends BigUintDataType = "u64"> extends NumericType<T, bigint, "BigUintType"> implements Storable<T> {
|
|
6
|
+
export default class BigUintType<T extends BigUintDataType = "u64", L extends boolean | undefined = undefined> extends NumericType<T, bigint, "BigUintType", L> implements Storable<T> {
|
|
7
7
|
[CoerceKey]: typeof coerce;
|
|
8
8
|
get name(): string;
|
|
9
9
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import CoerceKey from "#CoerceKey";
|
|
2
|
+
import Loose from "#Loose";
|
|
3
|
+
import type Mode from "#Mode";
|
|
2
4
|
import PrimitiveType from "#PrimitiveType";
|
|
3
5
|
import Storable from "#Storable";
|
|
4
|
-
export default class BooleanType extends PrimitiveType<boolean, "BooleanType"> implements Storable<"boolean"> {
|
|
6
|
+
export default class BooleanType<M extends Mode = undefined> extends PrimitiveType<boolean, "BooleanType"> implements Storable<"boolean"> {
|
|
7
|
+
[Loose]: M;
|
|
8
|
+
constructor(mode?: M);
|
|
5
9
|
get name(): "boolean";
|
|
6
10
|
get datatype(): "boolean";
|
|
7
11
|
[CoerceKey](x: unknown): unknown;
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import CoerceKey from "#CoerceKey";
|
|
2
|
+
import Loose from "#Loose";
|
|
2
3
|
import PrimitiveType from "#PrimitiveType";
|
|
3
4
|
import Storable from "#Storable";
|
|
4
5
|
import is from "@rcompat/is";
|
|
5
6
|
export default class BooleanType extends PrimitiveType {
|
|
7
|
+
[Loose];
|
|
8
|
+
constructor(mode) {
|
|
9
|
+
super();
|
|
10
|
+
this[Loose] = mode;
|
|
11
|
+
}
|
|
6
12
|
get name() {
|
|
7
13
|
return "boolean";
|
|
8
14
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
2
|
import coerce from "#coerce/date";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import Loose from "#Loose";
|
|
4
5
|
import Storable from "#Storable";
|
|
5
|
-
export default class DateType extends BuiltinType<Date, "DateType"> implements Storable<"datetime"> {
|
|
6
|
+
export default class DateType<M extends boolean | undefined = undefined> extends BuiltinType<Date, "DateType"> implements Storable<"datetime"> {
|
|
6
7
|
[CoerceKey]: typeof coerce;
|
|
8
|
+
[Loose]: M;
|
|
9
|
+
constructor(mode?: M);
|
|
7
10
|
get Type(): DateConstructor;
|
|
8
11
|
get name(): "date";
|
|
9
12
|
get datatype(): "datetime";
|
package/lib/private/DateType.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import BuiltinType from "#BuiltinType";
|
|
2
2
|
import coerce from "#coerce/date";
|
|
3
3
|
import CoerceKey from "#CoerceKey";
|
|
4
|
+
import Loose from "#Loose";
|
|
4
5
|
import Storable from "#Storable";
|
|
5
6
|
export default class DateType extends BuiltinType {
|
|
6
7
|
[CoerceKey] = coerce;
|
|
8
|
+
[Loose];
|
|
9
|
+
constructor(mode) {
|
|
10
|
+
super();
|
|
11
|
+
this[Loose] = mode;
|
|
12
|
+
}
|
|
7
13
|
get Type() {
|
|
8
14
|
return Date;
|
|
9
15
|
}
|
package/lib/private/IntType.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type IntDataType from "#IntDataType";
|
|
|
4
4
|
import NumericType from "#NumericType";
|
|
5
5
|
import type ParseOptions from "#ParseOptions";
|
|
6
6
|
import type Storable from "#Storable";
|
|
7
|
-
export default class IntType<T extends IntDataType> extends NumericType<T, number, "IntType"> implements Storable<T> {
|
|
7
|
+
export default class IntType<T extends IntDataType, L extends boolean | undefined = undefined> extends NumericType<T, number, "IntType", L> implements Storable<T> {
|
|
8
8
|
[CoerceKey]: typeof coerce;
|
|
9
9
|
get name(): string;
|
|
10
10
|
parse(u: unknown, options?: ParseOptions<number>): import("./Infer.js").default<this>;
|
|
@@ -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 Loose from "#Loose";
|
|
4
5
|
import OptionalType from "#OptionalType";
|
|
5
6
|
import type ParseOptions from "#ParseOptions";
|
|
7
|
+
import type Mode from "#Mode";
|
|
6
8
|
type Literal = string | boolean | number;
|
|
7
|
-
export default class LiteralType<T extends Literal> extends GenericType<T, T, "LiteralType"> {
|
|
9
|
+
export default class LiteralType<T extends Literal, M extends Mode = undefined> extends GenericType<T, T, "LiteralType"> {
|
|
8
10
|
#private;
|
|
9
|
-
|
|
11
|
+
[Loose]: M;
|
|
10
12
|
static get Literal(): Literal;
|
|
13
|
+
constructor(literal: T, mode?: M);
|
|
11
14
|
get name(): string;
|
|
12
15
|
optional(): OptionalType<this>;
|
|
13
16
|
default(value: (() => T) | T): DefaultType<this, T>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
|
+
import Loose from "#Loose";
|
|
3
4
|
import OptionalType from "#OptionalType";
|
|
4
5
|
import E from "#errors";
|
|
5
6
|
import resolve from "#resolve";
|
|
6
7
|
export default class LiteralType extends GenericType {
|
|
7
8
|
#literal;
|
|
8
|
-
|
|
9
|
-
super();
|
|
10
|
-
this.#literal = literal;
|
|
11
|
-
}
|
|
9
|
+
[Loose];
|
|
12
10
|
static get Literal() {
|
|
13
11
|
return undefined;
|
|
14
12
|
}
|
|
13
|
+
constructor(literal, mode) {
|
|
14
|
+
super();
|
|
15
|
+
this.#literal = literal;
|
|
16
|
+
this[Loose] = mode;
|
|
17
|
+
}
|
|
15
18
|
get name() {
|
|
16
19
|
return JSON.stringify(this.#literal);
|
|
17
20
|
}
|
|
@@ -2,7 +2,7 @@ import CoerceKey from "#CoerceKey";
|
|
|
2
2
|
import type FloatDataType from "#FloatDataType";
|
|
3
3
|
import NumericType from "#NumericType";
|
|
4
4
|
import coerce from "#coerce/float";
|
|
5
|
-
export default class NumberType<T extends FloatDataType = "f64"> extends NumericType<T, number, "NumberType"> {
|
|
5
|
+
export default class NumberType<T extends FloatDataType = "f64", L extends boolean | undefined = undefined> extends NumericType<T, number, "NumberType", L> {
|
|
6
6
|
[CoerceKey]: typeof coerce;
|
|
7
7
|
get name(): "number";
|
|
8
8
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type DataKey from "#DataKey";
|
|
2
|
+
import Loose from "#Loose";
|
|
3
|
+
import type Mode from "#Mode";
|
|
2
4
|
import type ParseOptions from "#ParseOptions";
|
|
3
5
|
import PrimitiveType from "#PrimitiveType";
|
|
4
6
|
import type Storable from "#Storable";
|
|
@@ -8,9 +10,10 @@ type Next<T> = {
|
|
|
8
10
|
options?: ParseOptions;
|
|
9
11
|
validators?: Validator<T>[];
|
|
10
12
|
};
|
|
11
|
-
export default abstract class NumericType<Key extends DataKey, T extends bigint | number, Name extends string> extends PrimitiveType<T, Name> implements Storable<Key> {
|
|
13
|
+
export default abstract class NumericType<Key extends DataKey, T extends bigint | number, Name extends string, M extends Mode = undefined> extends PrimitiveType<T, Name> implements Storable<Key> {
|
|
12
14
|
#private;
|
|
13
|
-
|
|
15
|
+
[Loose]: M;
|
|
16
|
+
constructor(datatype: Key, mode?: M, validators?: Validator<T>[], options?: ParseOptions);
|
|
14
17
|
derive(next: Next<T>): this;
|
|
15
18
|
values(anyof: Dict<T>): this;
|
|
16
19
|
range(from: T, to: T): this;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import Loose from "#Loose";
|
|
1
2
|
import PrimitiveType from "#PrimitiveType";
|
|
2
3
|
import max from "#validator/max";
|
|
3
4
|
import min from "#validator/min";
|
|
@@ -5,13 +6,15 @@ import range from "#validator/range";
|
|
|
5
6
|
import values from "#validator/values";
|
|
6
7
|
export default class NumericType extends PrimitiveType {
|
|
7
8
|
#datatype;
|
|
8
|
-
|
|
9
|
+
[Loose];
|
|
10
|
+
constructor(datatype, mode = undefined, validators = [], options = {}) {
|
|
9
11
|
super(validators, options);
|
|
10
12
|
this.#datatype = datatype;
|
|
13
|
+
this[Loose] = mode;
|
|
11
14
|
}
|
|
12
15
|
derive(next) {
|
|
13
16
|
const Constructor = this.constructor;
|
|
14
|
-
return new Constructor(this.#datatype, [...this.validators, ...next.validators ?? []], { ...this.options, ...next.options ?? {} });
|
|
17
|
+
return new Constructor(this.#datatype, this[Loose], [...this.validators, ...next.validators ?? []], { ...this.options, ...next.options ?? {} });
|
|
15
18
|
}
|
|
16
19
|
values(anyof) {
|
|
17
20
|
return this.derive({ validators: [values(anyof)] });
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import GenericType from "#GenericType";
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
3
|
import type InferInputSchema from "#InferInputSchema";
|
|
4
|
+
import Loose from "#Loose";
|
|
5
|
+
import type Mode from "#Mode";
|
|
4
6
|
import OptionalType from "#OptionalType";
|
|
5
7
|
import type Parsed from "#Parsed";
|
|
6
8
|
import type ParseOptions from "#ParseOptions";
|
|
@@ -10,18 +12,19 @@ import type { Dict, Unpack } from "@rcompat/type";
|
|
|
10
12
|
type ObjectInfer<P extends Dict<Parsed<unknown>>> = {
|
|
11
13
|
[K in keyof P]: P[K]["infer"];
|
|
12
14
|
};
|
|
13
|
-
export default class ObjectType<P extends Dict<Parsed<unknown>>, I = ObjectInfer<P>> extends GenericType<P, I, "ObjectType"> implements OptionalTrait {
|
|
15
|
+
export default class ObjectType<P extends Dict<Parsed<unknown>> = Dict<Parsed<unknown>>, M extends Mode = undefined, I = ObjectInfer<P>> extends GenericType<P, I, "ObjectType"> implements OptionalTrait {
|
|
14
16
|
#private;
|
|
17
|
+
[Loose]: M;
|
|
15
18
|
readonly Complement: ObjectType<Record<Exclude<string, keyof P>, Parsed<unknown>>>;
|
|
16
|
-
constructor(properties: P, options?: ParseOptions);
|
|
19
|
+
constructor(properties: P, mode?: M, options?: ParseOptions);
|
|
17
20
|
get name(): string;
|
|
18
21
|
get properties(): P;
|
|
19
22
|
get input(): InferInputSchema<P>;
|
|
20
23
|
optional(): OptionalType<this>;
|
|
21
|
-
shape<T>(): ObjectType<P, T>;
|
|
24
|
+
shape<T>(): ObjectType<P, M, T>;
|
|
22
25
|
extend<E extends {
|
|
23
26
|
[K in keyof E]: K extends keyof P ? never : Parsed<unknown>;
|
|
24
|
-
}>(extra: E | ObjectType<E>): ObjectType<Unpack<P & E
|
|
27
|
+
}>(extra: E | ObjectType<E, M>): ObjectType<Unpack<P & E>, M>;
|
|
25
28
|
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
|
26
29
|
toJSON(): {
|
|
27
30
|
type: "object";
|
|
@@ -9,9 +9,11 @@ import is from "@rcompat/is";
|
|
|
9
9
|
export default class ObjectType extends GenericType {
|
|
10
10
|
#properties;
|
|
11
11
|
#options;
|
|
12
|
-
|
|
12
|
+
[Loose];
|
|
13
|
+
constructor(properties, mode, options = {}) {
|
|
13
14
|
super();
|
|
14
15
|
this.#properties = properties;
|
|
16
|
+
this[Loose] = mode;
|
|
15
17
|
this.#options = options;
|
|
16
18
|
}
|
|
17
19
|
get name() {
|
|
@@ -28,7 +30,7 @@ export default class ObjectType extends GenericType {
|
|
|
28
30
|
}
|
|
29
31
|
#derive(options) {
|
|
30
32
|
const Constructor = this.constructor;
|
|
31
|
-
const instance = new Constructor(this.#properties, {
|
|
33
|
+
const instance = new Constructor(this.#properties, this[Loose], {
|
|
32
34
|
...this.#options, ...options,
|
|
33
35
|
});
|
|
34
36
|
instance[Loose] = this[Loose];
|
|
@@ -38,9 +40,7 @@ export default class ObjectType extends GenericType {
|
|
|
38
40
|
return new OptionalType(this);
|
|
39
41
|
}
|
|
40
42
|
shape() {
|
|
41
|
-
|
|
42
|
-
i[Loose] = this[Loose];
|
|
43
|
-
return i;
|
|
43
|
+
return new ObjectType(this.#properties, this[Loose], this.#options);
|
|
44
44
|
}
|
|
45
45
|
extend(extra) {
|
|
46
46
|
const properties = extra instanceof ObjectType ? extra.properties : extra;
|
|
@@ -48,9 +48,7 @@ export default class ObjectType extends GenericType {
|
|
|
48
48
|
if (key in this.#properties)
|
|
49
49
|
throw SE.extend_key_collision(key);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
instance[Loose] = this[Loose];
|
|
53
|
-
return instance;
|
|
51
|
+
return new ObjectType({ ...this.#properties, ...properties }, this[Loose], this.#options);
|
|
54
52
|
}
|
|
55
53
|
parse(u, options = {}) {
|
|
56
54
|
const x = resolve(u);
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import GenericType from "#GenericType";
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
|
+
import Loose from "#Loose";
|
|
4
|
+
import type Mode from "#Mode";
|
|
3
5
|
import type ObjectType from "#ObjectType";
|
|
4
6
|
import type Parsed from "#Parsed";
|
|
5
7
|
import type ParseOptions from "#ParseOptions";
|
|
6
8
|
import type Serialized from "#Serialized";
|
|
7
9
|
import type { Dict } from "@rcompat/type";
|
|
8
|
-
export default class OmitType<P extends Dict<Parsed<unknown>>, K extends keyof P> extends GenericType<Omit<P, K>, Omit<{
|
|
10
|
+
export default class OmitType<P extends Dict<Parsed<unknown>>, K extends keyof P, M extends Mode = undefined> extends GenericType<Omit<P, K>, Omit<{
|
|
9
11
|
[Key in keyof P]: Infer<P[Key]>;
|
|
10
12
|
}, K>, "OmitType"> {
|
|
11
13
|
#private;
|
|
12
|
-
|
|
14
|
+
[Loose]: M;
|
|
15
|
+
constructor(type: ObjectType<P>, keys: K[], mode?: M);
|
|
13
16
|
get name(): "omit";
|
|
14
17
|
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
|
15
18
|
toJSON(): {
|
package/lib/private/OmitType.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import E from "#errors";
|
|
2
2
|
import GenericType from "#GenericType";
|
|
3
|
+
import Loose from "#Loose";
|
|
3
4
|
import ParsedKey from "#ParsedKey";
|
|
4
5
|
import join from "#path/join";
|
|
5
6
|
import resolve from "#resolve";
|
|
6
7
|
import is from "@rcompat/is";
|
|
7
8
|
export default class OmitType extends GenericType {
|
|
8
9
|
#properties;
|
|
9
|
-
|
|
10
|
+
[Loose];
|
|
11
|
+
constructor(type, keys, mode) {
|
|
10
12
|
super();
|
|
11
13
|
const props = { ...type.properties };
|
|
12
14
|
for (const key of keys) {
|
|
13
15
|
delete props[key];
|
|
14
16
|
}
|
|
15
17
|
this.#properties = props;
|
|
18
|
+
this[Loose] = mode;
|
|
16
19
|
}
|
|
17
20
|
get name() {
|
|
18
21
|
return "omit";
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
|
+
import Loose from "#Loose";
|
|
4
|
+
import type Mode from "#Mode";
|
|
3
5
|
import type ParseOptions from "#ParseOptions";
|
|
4
6
|
import type Partialable from "#Partialable";
|
|
5
7
|
import type DefaultTrait from "#trait/Default";
|
|
@@ -7,9 +9,10 @@ import VirtualType from "#VirtualType";
|
|
|
7
9
|
type InferPartial<D extends Partialable> = {
|
|
8
10
|
-readonly [K in keyof D]?: NonNullable<Infer<D[K]>>;
|
|
9
11
|
};
|
|
10
|
-
export default class PartialType<D extends Partialable> extends VirtualType<D, InferPartial<D>, "PartialType"> implements DefaultTrait<InferPartial<D>> {
|
|
12
|
+
export default class PartialType<D extends Partialable, M extends Mode = undefined> extends VirtualType<D, InferPartial<D>, "PartialType"> implements DefaultTrait<InferPartial<D>> {
|
|
11
13
|
#private;
|
|
12
|
-
|
|
14
|
+
[Loose]: M;
|
|
15
|
+
constructor(spec: D, mode?: M);
|
|
13
16
|
get name(): "partial";
|
|
14
17
|
get schema(): D;
|
|
15
18
|
default(value: (() => InferPartial<D>) | InferPartial<D>): DefaultType<this, InferPartial<D>>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import DefaultType from "#DefaultType";
|
|
2
2
|
import E from "#errors";
|
|
3
|
+
import Loose from "#Loose";
|
|
3
4
|
import ParsedKey from "#ParsedKey";
|
|
4
5
|
import ParseError from "#ParseError";
|
|
5
6
|
import join from "#path/join";
|
|
@@ -9,9 +10,11 @@ import VirtualType from "#VirtualType";
|
|
|
9
10
|
import is from "@rcompat/is";
|
|
10
11
|
export default class PartialType extends VirtualType {
|
|
11
12
|
#spec;
|
|
12
|
-
|
|
13
|
+
[Loose];
|
|
14
|
+
constructor(spec, mode) {
|
|
13
15
|
super();
|
|
14
16
|
this.#spec = spec;
|
|
17
|
+
this[Loose] = mode;
|
|
15
18
|
}
|
|
16
19
|
get name() {
|
|
17
20
|
return "partial";
|
|
@@ -5,9 +5,12 @@ import type Parsed from "#Parsed";
|
|
|
5
5
|
import type ParseOptions from "#ParseOptions";
|
|
6
6
|
import type RecordTypeKey from "#RecordTypeKey";
|
|
7
7
|
import type OptionalTrait from "#trait/Optional";
|
|
8
|
-
|
|
8
|
+
import type Mode from "#Mode";
|
|
9
|
+
import Loose from "#Loose";
|
|
10
|
+
export default class RecordType<Key extends RecordTypeKey, Value extends Parsed<unknown>, M extends Mode = undefined> extends GenericType<Value, Record<Infer<Key>, Infer<Value>>, "RecordType"> implements OptionalTrait {
|
|
9
11
|
#private;
|
|
10
|
-
|
|
12
|
+
[Loose]: M;
|
|
13
|
+
constructor(k: Key, v: Value, mode?: M);
|
|
11
14
|
optional(): OptionalType<this>;
|
|
12
15
|
get name(): "record";
|
|
13
16
|
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
|
@@ -16,11 +19,11 @@ export default class RecordType<Key extends RecordTypeKey, Value extends Parsed<
|
|
|
16
19
|
key: {
|
|
17
20
|
type: "string";
|
|
18
21
|
datatype: "string";
|
|
19
|
-
} | {
|
|
20
|
-
type: "symbol";
|
|
21
22
|
} | {
|
|
22
23
|
type: "number" | "bigint";
|
|
23
24
|
datatype: "f64";
|
|
25
|
+
} | {
|
|
26
|
+
type: "symbol";
|
|
24
27
|
};
|
|
25
28
|
value: import("./Serialized.js").default;
|
|
26
29
|
};
|
|
@@ -6,13 +6,16 @@ import join from "#path/join";
|
|
|
6
6
|
import next from "#path/next";
|
|
7
7
|
import resolve from "#resolve";
|
|
8
8
|
import is from "@rcompat/is";
|
|
9
|
+
import Loose from "#Loose";
|
|
9
10
|
export default class RecordType extends GenericType {
|
|
10
11
|
#key;
|
|
11
12
|
#value;
|
|
12
|
-
|
|
13
|
+
[Loose];
|
|
14
|
+
constructor(k, v, mode) {
|
|
13
15
|
super();
|
|
14
16
|
this.#key = k;
|
|
15
17
|
this.#value = v;
|
|
18
|
+
this[Loose] = mode;
|
|
16
19
|
}
|
|
17
20
|
optional() {
|
|
18
21
|
return new OptionalType(this);
|
|
@@ -2,31 +2,31 @@ import type { Dict, JSONValue } from "@rcompat/type";
|
|
|
2
2
|
type DT<D extends string = string> = {
|
|
3
3
|
datatype?: D;
|
|
4
4
|
};
|
|
5
|
-
type PrimitiveSerialized = {
|
|
5
|
+
type PrimitiveSerialized = ({
|
|
6
6
|
type: "string";
|
|
7
|
-
} & DT | {
|
|
7
|
+
} & DT) | ({
|
|
8
8
|
type: "boolean";
|
|
9
|
-
} & DT | {
|
|
9
|
+
} & DT) | ({
|
|
10
10
|
type: "symbol";
|
|
11
|
-
} & DT | {
|
|
11
|
+
} & DT) | ({
|
|
12
12
|
type: "null";
|
|
13
|
-
} & DT | {
|
|
13
|
+
} & DT) | ({
|
|
14
14
|
type: "undefined";
|
|
15
|
-
} & DT | {
|
|
15
|
+
} & DT) | ({
|
|
16
16
|
type: "date";
|
|
17
|
-
} & DT | {
|
|
17
|
+
} & DT) | ({
|
|
18
18
|
type: "blob";
|
|
19
|
-
} & DT | {
|
|
19
|
+
} & DT) | ({
|
|
20
20
|
type: "file";
|
|
21
|
-
} & DT | {
|
|
21
|
+
} & DT) | ({
|
|
22
22
|
type: "url";
|
|
23
|
-
} & DT | {
|
|
23
|
+
} & DT) | ({
|
|
24
24
|
type: "uuid";
|
|
25
|
-
} & DT | {
|
|
25
|
+
} & DT) | ({
|
|
26
26
|
type: "uuid_v4";
|
|
27
|
-
} & DT | {
|
|
27
|
+
} & DT) | ({
|
|
28
28
|
type: "uuid_v7";
|
|
29
|
-
} & DT | {
|
|
29
|
+
} & DT) | {
|
|
30
30
|
type: "function";
|
|
31
31
|
};
|
|
32
32
|
type NumberSerialized = {
|
|
@@ -8,6 +8,6 @@ export default class StoreType<S extends StoreSchema> extends ObjectType<S> {
|
|
|
8
8
|
constructor(properties: S, pk?: string | null);
|
|
9
9
|
get name(): string;
|
|
10
10
|
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
|
11
|
-
partial(): PartialType<any>;
|
|
11
|
+
partial(): PartialType<any, undefined>;
|
|
12
12
|
}
|
|
13
13
|
//# sourceMappingURL=StoreType.d.ts.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import GenericType from "#GenericType";
|
|
2
2
|
import type Infer from "#Infer";
|
|
3
|
+
import Loose from "#Loose";
|
|
4
|
+
import type Mode from "#Mode";
|
|
3
5
|
import type NormalizeSchema from "#NormalizeSchema";
|
|
4
6
|
import OptionalType from "#OptionalType";
|
|
5
7
|
import type Parsed from "#Parsed";
|
|
@@ -9,9 +11,10 @@ import type OptionalTrait from "#trait/Optional";
|
|
|
9
11
|
type InferTuple<T extends Schema[]> = {
|
|
10
12
|
[K in keyof T]: T[K] extends Schema ? NormalizeSchema<T[K]>["infer"] : "tuple-never";
|
|
11
13
|
};
|
|
12
|
-
export default class TupleType<T extends Parsed<unknown>[]> extends GenericType<T, InferTuple<T>, "TupleType"> implements OptionalTrait {
|
|
14
|
+
export default class TupleType<T extends Parsed<unknown>[], M extends Mode = undefined> extends GenericType<T, InferTuple<T>, "TupleType"> implements OptionalTrait {
|
|
13
15
|
#private;
|
|
14
|
-
|
|
16
|
+
[Loose]: M;
|
|
17
|
+
constructor(items: T, mode?: M);
|
|
15
18
|
get name(): "tuple";
|
|
16
19
|
optional(): OptionalType<this>;
|
|
17
20
|
parse(u: unknown, options?: ParseOptions): Infer<this>;
|
package/lib/private/TupleType.js
CHANGED
|
@@ -7,9 +7,11 @@ import resolve from "#resolve";
|
|
|
7
7
|
import is from "@rcompat/is";
|
|
8
8
|
export default class TupleType extends GenericType {
|
|
9
9
|
#items;
|
|
10
|
-
|
|
10
|
+
[Loose];
|
|
11
|
+
constructor(items, mode) {
|
|
11
12
|
super();
|
|
12
13
|
this.#items = items;
|
|
14
|
+
this[Loose] = mode;
|
|
13
15
|
}
|
|
14
16
|
get name() {
|
|
15
17
|
return "tuple";
|
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
|
}
|
|
@@ -4,7 +4,7 @@ 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
|
/**
|
|
@@ -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,12 +10,14 @@ 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>;
|