pema 0.3.0 → 0.4.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/OmitType.d.ts +20 -0
- package/lib/private/OmitType.js +43 -0
- package/lib/private/Serialized.d.ts +3 -0
- package/lib/private/StoreType.d.ts +4 -16
- package/lib/private/StoreType.js +4 -35
- package/lib/private/index.d.ts +2 -0
- package/lib/private/index.js +4 -0
- package/lib/private/omit.d.ts +6 -0
- package/lib/private/omit.js +5 -0
- package/lib/public/OmitType.d.ts +2 -0
- package/lib/public/OmitType.js +2 -0
- package/lib/public/index.d.ts +3 -0
- package/lib/public/index.js +3 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import type Infer from "#Infer";
|
|
3
|
+
import type ObjectType from "#ObjectType";
|
|
4
|
+
import type Parsed from "#Parsed";
|
|
5
|
+
import type ParseOptions from "#ParseOptions";
|
|
6
|
+
import type Serialized from "#Serialized";
|
|
7
|
+
import type Dict from "@rcompat/type/Dict";
|
|
8
|
+
export default class OmitType<P extends Dict<Parsed<unknown>>, K extends keyof P> extends GenericType<Omit<P, K>, Omit<{
|
|
9
|
+
[Key in keyof P]: Infer<P[Key]>;
|
|
10
|
+
}, K>, "OmitType"> {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(type: ObjectType<P>, keys: K[]);
|
|
13
|
+
get name(): "omit";
|
|
14
|
+
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
15
|
+
toJSON(): {
|
|
16
|
+
type: "omit";
|
|
17
|
+
properties: Dict<Serialized>;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=OmitType.d.ts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import GenericType from "#GenericType";
|
|
2
|
+
import ParsedKey from "#ParsedKey";
|
|
3
|
+
import join from "#path/join";
|
|
4
|
+
export default class OmitType extends GenericType {
|
|
5
|
+
#properties;
|
|
6
|
+
constructor(type, keys) {
|
|
7
|
+
super();
|
|
8
|
+
const props = { ...type.properties };
|
|
9
|
+
for (const key of keys) {
|
|
10
|
+
delete props[key];
|
|
11
|
+
}
|
|
12
|
+
this.#properties = props;
|
|
13
|
+
}
|
|
14
|
+
get name() {
|
|
15
|
+
return "omit";
|
|
16
|
+
}
|
|
17
|
+
parse(x, options = {}) {
|
|
18
|
+
if (typeof x !== "object" || x === null) {
|
|
19
|
+
throw new Error("Expected object");
|
|
20
|
+
}
|
|
21
|
+
const result = {};
|
|
22
|
+
const props = this.#properties;
|
|
23
|
+
for (const k in props) {
|
|
24
|
+
const field = props[k];
|
|
25
|
+
const r = field.parse(x[k], {
|
|
26
|
+
...options, [ParsedKey]: join(options[ParsedKey] ?? "", String(k)),
|
|
27
|
+
});
|
|
28
|
+
if (r !== undefined) {
|
|
29
|
+
result[k] = r;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
toJSON() {
|
|
35
|
+
const properties = {};
|
|
36
|
+
const props = this.#properties;
|
|
37
|
+
for (const [k, v] of Object.entries(props)) {
|
|
38
|
+
properties[k] = v.toJSON();
|
|
39
|
+
}
|
|
40
|
+
return { type: "omit", properties };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=OmitType.js.map
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type Infer from "#Infer";
|
|
3
|
-
import type InferStore from "#InferStore";
|
|
4
|
-
import type ParseOptions from "#ParseOptions";
|
|
1
|
+
import ObjectType from "#ObjectType";
|
|
5
2
|
import PartialType from "#PartialType";
|
|
6
|
-
import type Serialized from "#Serialized";
|
|
7
3
|
import type StoreSchema from "#StoreSchema";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
#private;
|
|
11
|
-
constructor(spec: T);
|
|
4
|
+
export default class StoreType<S extends StoreSchema> extends ObjectType<S> {
|
|
5
|
+
constructor(spec: S);
|
|
12
6
|
get name(): string;
|
|
13
|
-
|
|
14
|
-
partial(): PartialType<T>;
|
|
15
|
-
parse(x: unknown, options?: ParseOptions): Infer<this>;
|
|
16
|
-
toJSON(): {
|
|
17
|
-
type: "object";
|
|
18
|
-
properties: Dict<Serialized>;
|
|
19
|
-
};
|
|
7
|
+
partial(): PartialType<any>;
|
|
20
8
|
}
|
|
21
9
|
//# sourceMappingURL=StoreType.d.ts.map
|
package/lib/private/StoreType.js
CHANGED
|
@@ -1,45 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
import ParsedKey from "#ParsedKey";
|
|
1
|
+
import ObjectType from "#ObjectType";
|
|
3
2
|
import PartialType from "#PartialType";
|
|
4
|
-
|
|
5
|
-
export default class StoreType extends GenericType {
|
|
6
|
-
#properties;
|
|
3
|
+
export default class StoreType extends ObjectType {
|
|
7
4
|
constructor(spec) {
|
|
8
|
-
super();
|
|
9
|
-
this.#properties = spec;
|
|
5
|
+
super(spec);
|
|
10
6
|
}
|
|
11
7
|
get name() {
|
|
12
8
|
return "store";
|
|
13
9
|
}
|
|
14
|
-
get schema() {
|
|
15
|
-
return this.#properties;
|
|
16
|
-
}
|
|
17
10
|
partial() {
|
|
18
|
-
return new PartialType(this
|
|
19
|
-
}
|
|
20
|
-
parse(x, options = {}) {
|
|
21
|
-
const spec = this.#properties;
|
|
22
|
-
if (typeof x !== "object" || x === null) {
|
|
23
|
-
throw new Error("Expected object");
|
|
24
|
-
}
|
|
25
|
-
const result = {};
|
|
26
|
-
for (const k in spec) {
|
|
27
|
-
const r = spec[k].parse(x[k], {
|
|
28
|
-
...options, [ParsedKey]: join(options[ParsedKey] ?? "", String(k)),
|
|
29
|
-
});
|
|
30
|
-
// exclude undefined (optionals)
|
|
31
|
-
if (r !== undefined) {
|
|
32
|
-
result[k] = r;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return x;
|
|
36
|
-
}
|
|
37
|
-
toJSON() {
|
|
38
|
-
const properties = {};
|
|
39
|
-
for (const [k, v] of Object.entries(this.#properties)) {
|
|
40
|
-
properties[k] = v.toJSON();
|
|
41
|
-
}
|
|
42
|
-
return { type: "object", properties };
|
|
11
|
+
return new PartialType(this.properties);
|
|
43
12
|
}
|
|
44
13
|
}
|
|
45
14
|
//# sourceMappingURL=StoreType.js.map
|
package/lib/private/index.d.ts
CHANGED
|
@@ -22,6 +22,8 @@ declare namespace schema {
|
|
|
22
22
|
var i8: import("./IntType.js").default<"i8">;
|
|
23
23
|
var int: import("./IntType.js").default<"i32">;
|
|
24
24
|
var number: import("./NumberType.js").default<"f64">;
|
|
25
|
+
var omit: typeof import("#omit").default;
|
|
26
|
+
var record: <const Key extends import("./RecordTypeKey.js").default, const Value extends import("./Parsed.js").default<unknown>>(k: Key, v: Value) => import("./RecordType.js").default<Key, Value>;
|
|
25
27
|
var primary: import("./PrimaryType.js").default;
|
|
26
28
|
var string: import("./StringType.js").default;
|
|
27
29
|
var symbol: import("./SymbolType.js").default;
|
package/lib/private/index.js
CHANGED
|
@@ -16,7 +16,9 @@ import i8 from "#i8";
|
|
|
16
16
|
import int from "#int";
|
|
17
17
|
import normalize from "#normalize";
|
|
18
18
|
import number from "#number";
|
|
19
|
+
import omit from "#omit";
|
|
19
20
|
import primary from "#primary";
|
|
21
|
+
import record from "#record";
|
|
20
22
|
import string from "#string";
|
|
21
23
|
import symbol from "#symbol";
|
|
22
24
|
import u128 from "#u128";
|
|
@@ -50,6 +52,8 @@ schema.i64 = i64;
|
|
|
50
52
|
schema.i8 = i8;
|
|
51
53
|
schema.int = int;
|
|
52
54
|
schema.number = number;
|
|
55
|
+
schema.omit = omit;
|
|
56
|
+
schema.record = record;
|
|
53
57
|
schema.primary = primary;
|
|
54
58
|
schema.string = string;
|
|
55
59
|
schema.symbol = symbol;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type ObjectType from "#ObjectType";
|
|
2
|
+
import OmitType from "#OmitType";
|
|
3
|
+
import type Parsed from "#Parsed";
|
|
4
|
+
import type Dict from "@rcompat/type/Dict";
|
|
5
|
+
export default function omit<P extends Dict<Parsed<unknown>>, K extends keyof P>(type: ObjectType<P>, ...keys: K[]): OmitType<P, K>;
|
|
6
|
+
//# sourceMappingURL=omit.d.ts.map
|
package/lib/public/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { default as ConstructorType } from "#ConstructorType";
|
|
1
2
|
export { default as DefaultType } from "#DefaultType";
|
|
2
3
|
export { default } from "#index";
|
|
3
4
|
export { default as LiteralType } from "#LiteralType";
|
|
@@ -5,4 +6,6 @@ export { default as ObjectType } from "#ObjectType";
|
|
|
5
6
|
export { default as OptionalType } from "#OptionalType";
|
|
6
7
|
export { default as PureType } from "#PureType";
|
|
7
8
|
export { default as TupleType } from "#TupleType";
|
|
9
|
+
export { default as UndefinedType } from "#UndefinedType";
|
|
10
|
+
export { default as ArrayType } from "#ArrayType";
|
|
8
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/public/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { default as ConstructorType } from "#ConstructorType";
|
|
1
2
|
export { default as DefaultType } from "#DefaultType";
|
|
2
3
|
export { default } from "#index";
|
|
3
4
|
export { default as LiteralType } from "#LiteralType";
|
|
@@ -5,4 +6,6 @@ export { default as ObjectType } from "#ObjectType";
|
|
|
5
6
|
export { default as OptionalType } from "#OptionalType";
|
|
6
7
|
export { default as PureType } from "#PureType";
|
|
7
8
|
export { default as TupleType } from "#TupleType";
|
|
9
|
+
export { default as UndefinedType } from "#UndefinedType";
|
|
10
|
+
export { default as ArrayType } from "#ArrayType";
|
|
8
11
|
//# sourceMappingURL=index.js.map
|