pema 0.2.0 → 0.3.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 +4 -1
- package/lib/private/ArrayType.js +4 -0
- package/lib/private/index.d.ts +32 -1
- package/lib/private/index.js +58 -1
- package/package.json +1 -1
|
@@ -1,19 +1,22 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
1
2
|
import GenericType from "#GenericType";
|
|
2
3
|
import type Infer from "#Infer";
|
|
3
4
|
import OptionalType from "#OptionalType";
|
|
4
5
|
import type Parsed from "#Parsed";
|
|
5
6
|
import type ParseOptions from "#ParseOptions";
|
|
7
|
+
import type DefaultTrait from "#trait/Default";
|
|
6
8
|
import type OptionalTrait from "#trait/Optional";
|
|
7
9
|
import type Validator from "#Validator";
|
|
8
10
|
import type Primitive from "@rcompat/type/Primitive";
|
|
9
11
|
type Next<T> = {
|
|
10
12
|
validators?: Validator<T>[];
|
|
11
13
|
};
|
|
12
|
-
export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait {
|
|
14
|
+
export default class ArrayType<T extends Parsed<unknown>> extends GenericType<T, Infer<T>[], "ArrayType"> implements OptionalTrait, DefaultTrait<Infer<T>[]> {
|
|
13
15
|
#private;
|
|
14
16
|
constructor(item: T, validators?: Validator<Array<Infer<T>>>[]);
|
|
15
17
|
get name(): "array";
|
|
16
18
|
optional(): OptionalType<this>;
|
|
19
|
+
default(value: (() => Infer<T>[]) | Infer<T>[]): DefaultType<this, Infer<T>[]>;
|
|
17
20
|
derive(_next: Next<Array<Infer<T>>>): this;
|
|
18
21
|
/**
|
|
19
22
|
* Member values are unique — only for primitive subtypes.
|
package/lib/private/ArrayType.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import DefaultType from "#DefaultType";
|
|
1
2
|
import error from "#error";
|
|
2
3
|
import schemafail from "#error/schemafail";
|
|
3
4
|
import GenericType from "#GenericType";
|
|
@@ -30,6 +31,9 @@ export default class ArrayType extends GenericType {
|
|
|
30
31
|
optional() {
|
|
31
32
|
return new OptionalType(this);
|
|
32
33
|
}
|
|
34
|
+
default(value) {
|
|
35
|
+
return new DefaultType(this, value);
|
|
36
|
+
}
|
|
33
37
|
derive(_next) {
|
|
34
38
|
const Constructor = this.constructor;
|
|
35
39
|
return new Constructor(this.#item, [...this.#validators, ..._next.validators ?? []]);
|
package/lib/private/index.d.ts
CHANGED
|
@@ -3,5 +3,36 @@ import type Schema from "#Schema";
|
|
|
3
3
|
/**
|
|
4
4
|
* Create a schema.
|
|
5
5
|
*/
|
|
6
|
-
|
|
6
|
+
declare function schema<const S extends Schema>(s: S): NormalizeSchema<S>;
|
|
7
|
+
declare namespace schema {
|
|
8
|
+
var array: typeof import("#array").default;
|
|
9
|
+
var bigint: import("./BigIntType.js").default<"i64">;
|
|
10
|
+
var biguint: import("./BigUintType.js").default<"u64">;
|
|
11
|
+
var blob: import("./BlobType.js").default;
|
|
12
|
+
var boolean: import("./BooleanType.js").default;
|
|
13
|
+
var constructor: <const C extends import("@rcompat/type/AbstractNewable").default>(constructor: C) => import("./ConstructorType.js").default<C>;
|
|
14
|
+
var date: import("./DateType.js").default;
|
|
15
|
+
var f32: import("./NumberType.js").default<"f32">;
|
|
16
|
+
var f64: import("./NumberType.js").default<"f64">;
|
|
17
|
+
var file: import("./FileType.js").default;
|
|
18
|
+
var i128: import("./BigIntType.js").default<"i128">;
|
|
19
|
+
var i16: import("./IntType.js").default<"i16">;
|
|
20
|
+
var i32: import("./IntType.js").default<"i32">;
|
|
21
|
+
var i64: import("./BigIntType.js").default<"i64">;
|
|
22
|
+
var i8: import("./IntType.js").default<"i8">;
|
|
23
|
+
var int: import("./IntType.js").default<"i32">;
|
|
24
|
+
var number: import("./NumberType.js").default<"f64">;
|
|
25
|
+
var primary: import("./PrimaryType.js").default;
|
|
26
|
+
var string: import("./StringType.js").default;
|
|
27
|
+
var symbol: import("./SymbolType.js").default;
|
|
28
|
+
var u128: import("./BigUintType.js").default<"u128">;
|
|
29
|
+
var u16: import("./UintType.js").default<"u16">;
|
|
30
|
+
var u32: import("./UintType.js").default<"u32">;
|
|
31
|
+
var u64: import("./BigUintType.js").default<"u64">;
|
|
32
|
+
var u8: import("./UintType.js").default<"u8">;
|
|
33
|
+
var uint: import("./UintType.js").default<"u32">;
|
|
34
|
+
var union: typeof import("#union").default;
|
|
35
|
+
var unknown: import("./UnknownType.js").default;
|
|
36
|
+
}
|
|
37
|
+
export default schema;
|
|
7
38
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/private/index.js
CHANGED
|
@@ -1,8 +1,65 @@
|
|
|
1
|
+
import array from "#array";
|
|
2
|
+
import bigint from "#bigint";
|
|
3
|
+
import biguint from "#biguint";
|
|
4
|
+
import blob from "#blob";
|
|
5
|
+
import boolean from "#boolean";
|
|
6
|
+
import constructor from "#constructor";
|
|
7
|
+
import date from "#date";
|
|
8
|
+
import f32 from "#f32";
|
|
9
|
+
import f64 from "#f64";
|
|
10
|
+
import file from "#file";
|
|
11
|
+
import i128 from "#i128";
|
|
12
|
+
import i16 from "#i16";
|
|
13
|
+
import i32 from "#i32";
|
|
14
|
+
import i64 from "#i64";
|
|
15
|
+
import i8 from "#i8";
|
|
16
|
+
import int from "#int";
|
|
1
17
|
import normalize from "#normalize";
|
|
18
|
+
import number from "#number";
|
|
19
|
+
import primary from "#primary";
|
|
20
|
+
import string from "#string";
|
|
21
|
+
import symbol from "#symbol";
|
|
22
|
+
import u128 from "#u128";
|
|
23
|
+
import u16 from "#u16";
|
|
24
|
+
import u32 from "#u32";
|
|
25
|
+
import u64 from "#u64";
|
|
26
|
+
import u8 from "#u8";
|
|
27
|
+
import uint from "#uint";
|
|
28
|
+
import union from "#union";
|
|
29
|
+
import unknown from "#unknown";
|
|
2
30
|
/**
|
|
3
31
|
* Create a schema.
|
|
4
32
|
*/
|
|
5
|
-
|
|
33
|
+
function schema(s) {
|
|
6
34
|
return normalize(s);
|
|
7
35
|
}
|
|
36
|
+
schema.array = array;
|
|
37
|
+
schema.bigint = bigint;
|
|
38
|
+
schema.biguint = biguint;
|
|
39
|
+
schema.blob = blob;
|
|
40
|
+
schema.boolean = boolean;
|
|
41
|
+
schema.constructor = constructor;
|
|
42
|
+
schema.date = date;
|
|
43
|
+
schema.f32 = f32;
|
|
44
|
+
schema.f64 = f64;
|
|
45
|
+
schema.file = file;
|
|
46
|
+
schema.i128 = i128;
|
|
47
|
+
schema.i16 = i16;
|
|
48
|
+
schema.i32 = i32;
|
|
49
|
+
schema.i64 = i64;
|
|
50
|
+
schema.i8 = i8;
|
|
51
|
+
schema.int = int;
|
|
52
|
+
schema.number = number;
|
|
53
|
+
schema.primary = primary;
|
|
54
|
+
schema.string = string;
|
|
55
|
+
schema.symbol = symbol;
|
|
56
|
+
schema.u128 = u128;
|
|
57
|
+
schema.u16 = u16;
|
|
58
|
+
schema.u32 = u32;
|
|
59
|
+
schema.u64 = u64;
|
|
60
|
+
schema.u8 = u8;
|
|
61
|
+
schema.uint = uint;
|
|
62
|
+
schema.union = union;
|
|
63
|
+
schema.unknown = unknown;
|
|
64
|
+
export default schema;
|
|
8
65
|
//# sourceMappingURL=index.js.map
|