@ddd-ts/shape 0.0.0-elo.1 → 0.0.0-eventviz.10
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/LICENSE +21 -0
- package/dist/_.d.ts +10 -9
- package/dist/_.d.ts.map +1 -1
- package/dist/_.js +31 -46
- package/dist/_.mjs +34 -0
- package/dist/addons/microsecond-timestamp.d.ts +24 -0
- package/dist/addons/microsecond-timestamp.d.ts.map +1 -0
- package/dist/addons/microsecond-timestamp.js +61 -0
- package/dist/addons/microsecond-timestamp.mjs +61 -0
- package/dist/choice.d.ts +16 -28
- package/dist/choice.d.ts.map +1 -1
- package/dist/choice.js +41 -45
- package/dist/choice.mjs +43 -0
- package/dist/class.d.ts +10 -8
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +27 -28
- package/dist/class.mjs +29 -0
- package/dist/dict.d.ts +38 -13
- package/dist/dict.d.ts.map +1 -1
- package/dist/dict.js +37 -42
- package/dist/dict.mjs +39 -0
- package/dist/discriminated-union.d.ts +74 -0
- package/dist/discriminated-union.d.ts.map +1 -0
- package/dist/discriminated-union.js +65 -0
- package/dist/discriminated-union.mjs +63 -0
- package/dist/discriminated-union.spec.d.ts +2 -0
- package/dist/discriminated-union.spec.d.ts.map +1 -0
- package/dist/either.d.ts +57 -13
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +48 -61
- package/dist/either.mjs +50 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -27
- package/dist/index.mjs +14 -0
- package/dist/literal.d.ts +13 -38
- package/dist/literal.d.ts.map +1 -1
- package/dist/literal.js +23 -28
- package/dist/literal.mjs +25 -0
- package/dist/mapping.d.ts +17 -13
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +42 -48
- package/dist/mapping.mjs +44 -0
- package/dist/multiple.d.ts +17 -102
- package/dist/multiple.d.ts.map +1 -1
- package/dist/multiple.js +116 -104
- package/dist/multiple.mjs +118 -0
- package/dist/nothing.d.ts +3 -3
- package/dist/nothing.d.ts.map +1 -1
- package/dist/nothing.js +15 -17
- package/dist/nothing.mjs +17 -0
- package/dist/optional.d.ts +18 -15
- package/dist/optional.d.ts.map +1 -1
- package/dist/optional.js +31 -37
- package/dist/optional.mjs +33 -0
- package/dist/primitive.d.ts +38 -0
- package/dist/primitive.d.ts.map +1 -0
- package/dist/primitive.js +29 -0
- package/dist/primitive.mjs +29 -0
- package/dist/primitive.spec.d.ts +2 -0
- package/dist/primitive.spec.d.ts.map +1 -0
- package/dist/test.d.ts +11 -11
- package/dist/test.d.ts.map +1 -1
- package/package.json +23 -9
- package/dist/_.js.map +0 -1
- package/dist/choice.js.map +0 -1
- package/dist/choice.spec.js +0 -147
- package/dist/choice.spec.js.map +0 -1
- package/dist/class.js.map +0 -1
- package/dist/class.spec.js +0 -39
- package/dist/class.spec.js.map +0 -1
- package/dist/dict.js.map +0 -1
- package/dist/dict.spec.js +0 -180
- package/dist/dict.spec.js.map +0 -1
- package/dist/either.js.map +0 -1
- package/dist/either.spec.js +0 -211
- package/dist/either.spec.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/literal.js.map +0 -1
- package/dist/literal.spec.js +0 -162
- package/dist/literal.spec.js.map +0 -1
- package/dist/mapping.js.map +0 -1
- package/dist/mapping.spec.js +0 -207
- package/dist/mapping.spec.js.map +0 -1
- package/dist/multiple.js.map +0 -1
- package/dist/multiple.spec.js +0 -208
- package/dist/multiple.spec.js.map +0 -1
- package/dist/nothing.js.map +0 -1
- package/dist/nothing.spec.js +0 -172
- package/dist/nothing.spec.js.map +0 -1
- package/dist/optional.js.map +0 -1
- package/dist/optional.spec.js +0 -172
- package/dist/optional.spec.js.map +0 -1
- package/dist/test.js +0 -46
- package/dist/test.js.map +0 -1
package/dist/either.js
CHANGED
|
@@ -1,63 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
|
|
49
|
-
if (!key) {
|
|
50
|
-
throw new Error("Cannot serialize Either, no matching key");
|
|
51
|
-
}
|
|
52
|
-
const definition = definitions[key];
|
|
53
|
-
if (!definition) {
|
|
54
|
-
throw new Error("Cannot serialize Either");
|
|
55
|
-
}
|
|
56
|
-
return [key, definition.$serialize(value)];
|
|
57
|
-
}
|
|
58
|
-
static $inline;
|
|
59
|
-
}
|
|
60
|
-
return $Either;
|
|
1
|
+
const require__ = require("./_.js");
|
|
2
|
+
//#region src/either.ts
|
|
3
|
+
const Either = (of, base = require__.Empty) => {
|
|
4
|
+
const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
|
|
5
|
+
return [key, require__.Shape(value)];
|
|
6
|
+
}));
|
|
7
|
+
class $Either extends base {
|
|
8
|
+
value;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super();
|
|
11
|
+
this.value = value;
|
|
12
|
+
}
|
|
13
|
+
static serialized;
|
|
14
|
+
static of = of;
|
|
15
|
+
static $shape = "either";
|
|
16
|
+
serialize() {
|
|
17
|
+
return $Either.$serialize(this.value);
|
|
18
|
+
}
|
|
19
|
+
match(...[matcher, fallback]) {
|
|
20
|
+
const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
|
|
21
|
+
if (handler) return handler(this.value);
|
|
22
|
+
if (fallback) return fallback(this.value);
|
|
23
|
+
if (matcher._) return matcher._(this.value);
|
|
24
|
+
throw new Error("Non-exhaustive match");
|
|
25
|
+
}
|
|
26
|
+
static deserialize(value) {
|
|
27
|
+
return new this(this.$deserialize(value));
|
|
28
|
+
}
|
|
29
|
+
static $deserialize(value) {
|
|
30
|
+
const { _key: key, ...serialized } = value;
|
|
31
|
+
const definition = definitions[key];
|
|
32
|
+
if (!definition) throw new Error("Cannot deserialize Either");
|
|
33
|
+
return definition.$deserialize(serialized);
|
|
34
|
+
}
|
|
35
|
+
static $serialize(value) {
|
|
36
|
+
const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
|
|
37
|
+
if (!key) throw new Error("Cannot serialize Either, no matching key");
|
|
38
|
+
const definition = definitions[key];
|
|
39
|
+
if (!definition) throw new Error("Cannot serialize Either");
|
|
40
|
+
return {
|
|
41
|
+
...definition.$serialize(value),
|
|
42
|
+
_key: key
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static $inline;
|
|
46
|
+
}
|
|
47
|
+
return $Either;
|
|
61
48
|
};
|
|
49
|
+
//#endregion
|
|
62
50
|
exports.Either = Either;
|
|
63
|
-
//# sourceMappingURL=either.js.map
|
package/dist/either.mjs
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.mjs";
|
|
2
|
+
//#region src/either.ts
|
|
3
|
+
const Either = (of, base = Empty) => {
|
|
4
|
+
const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
|
|
5
|
+
return [key, Shape(value)];
|
|
6
|
+
}));
|
|
7
|
+
class $Either extends base {
|
|
8
|
+
value;
|
|
9
|
+
constructor(value) {
|
|
10
|
+
super();
|
|
11
|
+
this.value = value;
|
|
12
|
+
}
|
|
13
|
+
static serialized;
|
|
14
|
+
static of = of;
|
|
15
|
+
static $shape = "either";
|
|
16
|
+
serialize() {
|
|
17
|
+
return $Either.$serialize(this.value);
|
|
18
|
+
}
|
|
19
|
+
match(...[matcher, fallback]) {
|
|
20
|
+
const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
|
|
21
|
+
if (handler) return handler(this.value);
|
|
22
|
+
if (fallback) return fallback(this.value);
|
|
23
|
+
if (matcher._) return matcher._(this.value);
|
|
24
|
+
throw new Error("Non-exhaustive match");
|
|
25
|
+
}
|
|
26
|
+
static deserialize(value) {
|
|
27
|
+
return new this(this.$deserialize(value));
|
|
28
|
+
}
|
|
29
|
+
static $deserialize(value) {
|
|
30
|
+
const { _key: key, ...serialized } = value;
|
|
31
|
+
const definition = definitions[key];
|
|
32
|
+
if (!definition) throw new Error("Cannot deserialize Either");
|
|
33
|
+
return definition.$deserialize(serialized);
|
|
34
|
+
}
|
|
35
|
+
static $serialize(value) {
|
|
36
|
+
const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
|
|
37
|
+
if (!key) throw new Error("Cannot serialize Either, no matching key");
|
|
38
|
+
const definition = definitions[key];
|
|
39
|
+
if (!definition) throw new Error("Cannot serialize Either");
|
|
40
|
+
return {
|
|
41
|
+
...definition.$serialize(value),
|
|
42
|
+
_key: key
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
static $inline;
|
|
46
|
+
}
|
|
47
|
+
return $Either;
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
export { Either };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,12 @@ export * from "./choice";
|
|
|
3
3
|
export * from "./class";
|
|
4
4
|
export * from "./dict";
|
|
5
5
|
export * from "./either";
|
|
6
|
+
export * from "./primitive";
|
|
6
7
|
export * from "./literal";
|
|
8
|
+
export * from "./discriminated-union";
|
|
7
9
|
export * from "./mapping";
|
|
8
10
|
export * from "./multiple";
|
|
9
11
|
export * from "./nothing";
|
|
10
12
|
export * from "./optional";
|
|
13
|
+
export * from "./addons/microsecond-timestamp";
|
|
11
14
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gCAAgC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_class = require("./class.js");
|
|
3
|
+
const require_dict = require("./dict.js");
|
|
4
|
+
const require_primitive = require("./primitive.js");
|
|
5
|
+
const require_multiple = require("./multiple.js");
|
|
6
|
+
const require_nothing = require("./nothing.js");
|
|
7
|
+
const require_literal = require("./literal.js");
|
|
8
|
+
const require__ = require("./_.js");
|
|
9
|
+
const require_choice = require("./choice.js");
|
|
10
|
+
const require_either = require("./either.js");
|
|
11
|
+
const require_discriminated_union = require("./discriminated-union.js");
|
|
12
|
+
const require_mapping = require("./mapping.js");
|
|
13
|
+
const require_optional = require("./optional.js");
|
|
14
|
+
const require_microsecond_timestamp = require("./addons/microsecond-timestamp.js");
|
|
15
|
+
exports.Choice = require_choice.Choice;
|
|
16
|
+
exports.Class = require_class.Class;
|
|
17
|
+
exports.Dict = require_dict.Dict;
|
|
18
|
+
exports.DiscriminatedUnion = require_discriminated_union.DiscriminatedUnion;
|
|
19
|
+
exports.Either = require_either.Either;
|
|
20
|
+
exports.Empty = require__.Empty;
|
|
21
|
+
exports.Literal = require_literal.Literal;
|
|
22
|
+
exports.Mapping = require_mapping.Mapping;
|
|
23
|
+
exports.MicrosecondTimestamp = require_microsecond_timestamp.MicrosecondTimestamp;
|
|
24
|
+
exports.Multiple = require_multiple.Multiple;
|
|
25
|
+
exports.Nothing = require_nothing.Nothing;
|
|
26
|
+
exports.Optional = require_optional.Optional;
|
|
27
|
+
exports.Primitive = require_primitive.Primitive;
|
|
28
|
+
exports.Shape = require__.Shape;
|
|
29
|
+
exports.findBestKey = require_discriminated_union.findBestKey;
|
|
30
|
+
exports.forward = require__.forward;
|
|
31
|
+
exports.prepareShapeMap = require_discriminated_union.prepareShapeMap;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Class } from "./class.mjs";
|
|
2
|
+
import { Dict } from "./dict.mjs";
|
|
3
|
+
import { Primitive } from "./primitive.mjs";
|
|
4
|
+
import { Multiple } from "./multiple.mjs";
|
|
5
|
+
import { Nothing } from "./nothing.mjs";
|
|
6
|
+
import { Literal } from "./literal.mjs";
|
|
7
|
+
import { Empty, Shape, forward } from "./_.mjs";
|
|
8
|
+
import { Choice } from "./choice.mjs";
|
|
9
|
+
import { Either } from "./either.mjs";
|
|
10
|
+
import { DiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.mjs";
|
|
11
|
+
import { Mapping } from "./mapping.mjs";
|
|
12
|
+
import { Optional } from "./optional.mjs";
|
|
13
|
+
import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.mjs";
|
|
14
|
+
export { Choice, Class, Dict, DiscriminatedUnion, Either, Empty, Literal, Mapping, MicrosecondTimestamp, Multiple, Nothing, Optional, Primitive, Shape, findBestKey, forward, prepareShapeMap };
|
package/dist/literal.d.ts
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
|
-
import { AbstractConstructor, Empty, Expand } from "./_";
|
|
2
|
-
type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
],
|
|
15
|
-
[
|
|
16
|
-
BooleanConstructor,
|
|
17
|
-
boolean
|
|
18
|
-
]
|
|
19
|
-
];
|
|
20
|
-
type LiteralConstructor = LiteralMap[number][0];
|
|
21
|
-
export type LiteralFromConstructor<S> = Extract<LiteralMap[number], [
|
|
22
|
-
S,
|
|
23
|
-
any
|
|
24
|
-
]>[1];
|
|
25
|
-
export type LiteralShorthand = LiteralConstructor;
|
|
26
|
-
export declare const Literal: <S extends StringConstructor | NumberConstructor | DateConstructor | BooleanConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: Expand<LiteralFromConstructor<S>>) => {
|
|
27
|
-
readonly value: Expand<LiteralFromConstructor<S>>;
|
|
28
|
-
serialize(): LiteralFromConstructor<S>;
|
|
29
|
-
}) & {
|
|
30
|
-
$name: "literal";
|
|
31
|
-
deserialize<T extends any>(this: T, value: LiteralFromConstructor<S>): InstanceType<T>;
|
|
32
|
-
$serialize(value: LiteralFromConstructor<S>): LiteralFromConstructor<S>;
|
|
33
|
-
$deserialize(value: LiteralFromConstructor<S>): LiteralFromConstructor<S>;
|
|
34
|
-
$inline: Expand<LiteralFromConstructor<S>>;
|
|
35
|
-
}, "prototype"> & (abstract new (value: Expand<LiteralFromConstructor<S>>) => InstanceType<B> & {
|
|
36
|
-
readonly value: Expand<LiteralFromConstructor<S>>;
|
|
37
|
-
serialize(): LiteralFromConstructor<S>;
|
|
1
|
+
import { type AbstractConstructor, type Constructor, Empty, type Expand } from "./_";
|
|
2
|
+
export type LiteralShorthand = string | number;
|
|
3
|
+
export declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => ILiteral<S, B>;
|
|
4
|
+
export type ILiteral<S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & {
|
|
5
|
+
value: S;
|
|
6
|
+
$shape: "literal";
|
|
7
|
+
deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;
|
|
8
|
+
$serialize(value: S): S;
|
|
9
|
+
$deserialize(value: S): S;
|
|
10
|
+
$inline: S;
|
|
11
|
+
} & (abstract new (value: Expand<S>) => InstanceType<B> & {
|
|
12
|
+
readonly value: S;
|
|
13
|
+
serialize(): S;
|
|
38
14
|
});
|
|
39
|
-
export {};
|
|
40
15
|
//# sourceMappingURL=literal.d.ts.map
|
package/dist/literal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,
|
|
1
|
+
{"version":3,"file":"literal.d.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-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return value;
|
|
24
|
-
}
|
|
25
|
-
static $inline;
|
|
26
|
-
}
|
|
27
|
-
return $Literal;
|
|
1
|
+
const require__ = require("./_.js");
|
|
2
|
+
//#region src/literal.ts
|
|
3
|
+
const Literal = (of, base = require__.Empty) => {
|
|
4
|
+
class $Literal extends base {
|
|
5
|
+
value = of;
|
|
6
|
+
static value = of;
|
|
7
|
+
static $shape = "literal";
|
|
8
|
+
serialize() {
|
|
9
|
+
return of;
|
|
10
|
+
}
|
|
11
|
+
static deserialize(value) {
|
|
12
|
+
return new this();
|
|
13
|
+
}
|
|
14
|
+
static $serialize(value) {
|
|
15
|
+
return of;
|
|
16
|
+
}
|
|
17
|
+
static $deserialize(value) {
|
|
18
|
+
return of;
|
|
19
|
+
}
|
|
20
|
+
static $inline;
|
|
21
|
+
}
|
|
22
|
+
return $Literal;
|
|
28
23
|
};
|
|
24
|
+
//#endregion
|
|
29
25
|
exports.Literal = Literal;
|
|
30
|
-
//# sourceMappingURL=literal.js.map
|
package/dist/literal.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Empty } from "./_.mjs";
|
|
2
|
+
//#region src/literal.ts
|
|
3
|
+
const Literal = (of, base = Empty) => {
|
|
4
|
+
class $Literal extends base {
|
|
5
|
+
value = of;
|
|
6
|
+
static value = of;
|
|
7
|
+
static $shape = "literal";
|
|
8
|
+
serialize() {
|
|
9
|
+
return of;
|
|
10
|
+
}
|
|
11
|
+
static deserialize(value) {
|
|
12
|
+
return new this();
|
|
13
|
+
}
|
|
14
|
+
static $serialize(value) {
|
|
15
|
+
return of;
|
|
16
|
+
}
|
|
17
|
+
static $deserialize(value) {
|
|
18
|
+
return of;
|
|
19
|
+
}
|
|
20
|
+
static $inline;
|
|
21
|
+
}
|
|
22
|
+
return $Literal;
|
|
23
|
+
};
|
|
24
|
+
//#endregion
|
|
25
|
+
export { Literal };
|
package/dist/mapping.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Definition, Expand, Shorthand, DefinitionOf, AbstractConstructor, Empty } from "./_";
|
|
1
|
+
import { type Definition, type Expand, type Shorthand, type DefinitionOf, type AbstractConstructor, Empty, type Constructor } from "./_";
|
|
2
2
|
type MappingLiteralKey = [
|
|
3
3
|
[
|
|
4
4
|
StringConstructor,
|
|
@@ -22,18 +22,22 @@ type MappingOf<C extends MappingConfiguration> = C extends [
|
|
|
22
22
|
key: StringConstructor;
|
|
23
23
|
value: DefinitionOf<V>;
|
|
24
24
|
} : never;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
type Internal<C extends MappingConfiguration, B extends AbstractConstructor<{}>> = {
|
|
26
|
+
Definition: MappingOf<C>["value"];
|
|
27
|
+
Serialized: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>;
|
|
28
|
+
Deserializing: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, Parameters<MappingOf<C>["value"]["$deserialize"]>[0]>;
|
|
29
|
+
Inline: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
|
|
30
|
+
};
|
|
31
|
+
export declare const Mapping: <C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty>(config: C, base?: B) => Mapping<C, B>;
|
|
32
|
+
export type Mapping<C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<C, B>["Inline"]) => InstanceType<B> & {
|
|
33
|
+
value: Internal<C, B>["Inline"];
|
|
34
|
+
serialize(): Expand<Internal<C, B>["Serialized"]>;
|
|
28
35
|
}) & {
|
|
29
|
-
$
|
|
30
|
-
deserialize<T extends
|
|
31
|
-
$deserialize<
|
|
32
|
-
$serialize<
|
|
33
|
-
$inline:
|
|
34
|
-
}
|
|
35
|
-
value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
|
|
36
|
-
serialize(): Expand<Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>>;
|
|
37
|
-
});
|
|
36
|
+
$shape: "mapping";
|
|
37
|
+
deserialize<T extends Constructor>(this: T, value: Expand<Internal<C, B>["Serialized"]>): InstanceType<T>;
|
|
38
|
+
$deserialize<T>(this: T, value: Internal<C, B>["Deserializing"]): Internal<C, B>["Inline"];
|
|
39
|
+
$serialize<T>(this: T, value: Internal<C, B>["Inline"]): Internal<C, B>["Serialized"];
|
|
40
|
+
$inline: Internal<C, B>["Inline"];
|
|
41
|
+
};
|
|
38
42
|
export {};
|
|
39
43
|
//# sourceMappingURL=mapping.d.ts.map
|
package/dist/mapping.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,YAAY,EAEjB,KAAK,mBAAmB,EACxB,KAAK,EACL,KAAK,WAAW,EACjB,MAAM,KAAK,CAAC;AAGb,KAAK,iBAAiB,GAAG;IACvB;QAAC,iBAAiB;QAAE,MAAM;KAAC;IAC3B;QAAC,iBAAiB;QAAE,MAAM;KAAC;CAC5B,CAAC;AACF,KAAK,qBAAqB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,KAAK,gCAAgC,CAAC,CAAC,SAAS,qBAAqB,IACnE,CAAC,SAAS,iBA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CAAC,CAAC,QAAQ,CAAC,GAC9B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CACnC,CAAC"}
|
package/dist/mapping.js
CHANGED
|
@@ -1,50 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const merge = Object.fromEntries(transform);
|
|
43
|
-
return merge;
|
|
44
|
-
}
|
|
45
|
-
static $inline;
|
|
46
|
-
}
|
|
47
|
-
return $Mapping;
|
|
1
|
+
const require_primitive = require("./primitive.js");
|
|
2
|
+
const require__ = require("./_.js");
|
|
3
|
+
//#region src/mapping.ts
|
|
4
|
+
const Mapping = (config, base = require__.Empty) => {
|
|
5
|
+
let [_key, _value] = config;
|
|
6
|
+
if (config.length === 1) {
|
|
7
|
+
_key = require_primitive.Primitive(String);
|
|
8
|
+
_value = config[0];
|
|
9
|
+
}
|
|
10
|
+
const { $key, $value } = {
|
|
11
|
+
$key: _key,
|
|
12
|
+
$value: _value
|
|
13
|
+
};
|
|
14
|
+
class $Mapping extends base {
|
|
15
|
+
value;
|
|
16
|
+
constructor(value) {
|
|
17
|
+
super();
|
|
18
|
+
this.value = value;
|
|
19
|
+
}
|
|
20
|
+
static $shape = "mapping";
|
|
21
|
+
serialize() {
|
|
22
|
+
return $Mapping.$serialize(this.value);
|
|
23
|
+
}
|
|
24
|
+
static deserialize(value) {
|
|
25
|
+
return new this($Mapping.$deserialize(value));
|
|
26
|
+
}
|
|
27
|
+
static $deserialize(value) {
|
|
28
|
+
const transform = Object.entries(value).map(([key, child]) => {
|
|
29
|
+
return [key, require__.Shape(_value).$deserialize(child)];
|
|
30
|
+
});
|
|
31
|
+
return Object.fromEntries(transform);
|
|
32
|
+
}
|
|
33
|
+
static $serialize(value) {
|
|
34
|
+
const transform = Object.entries(value).map(([key, child]) => {
|
|
35
|
+
return [key, require__.Shape($value).$serialize(child)];
|
|
36
|
+
});
|
|
37
|
+
return Object.fromEntries(transform);
|
|
38
|
+
}
|
|
39
|
+
static $inline;
|
|
40
|
+
}
|
|
41
|
+
return $Mapping;
|
|
48
42
|
};
|
|
43
|
+
//#endregion
|
|
49
44
|
exports.Mapping = Mapping;
|
|
50
|
-
//# sourceMappingURL=mapping.js.map
|
package/dist/mapping.mjs
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Primitive } from "./primitive.mjs";
|
|
2
|
+
import { Empty, Shape } from "./_.mjs";
|
|
3
|
+
//#region src/mapping.ts
|
|
4
|
+
const Mapping = (config, base = Empty) => {
|
|
5
|
+
let [_key, _value] = config;
|
|
6
|
+
if (config.length === 1) {
|
|
7
|
+
_key = Primitive(String);
|
|
8
|
+
_value = config[0];
|
|
9
|
+
}
|
|
10
|
+
const { $key, $value } = {
|
|
11
|
+
$key: _key,
|
|
12
|
+
$value: _value
|
|
13
|
+
};
|
|
14
|
+
class $Mapping extends base {
|
|
15
|
+
value;
|
|
16
|
+
constructor(value) {
|
|
17
|
+
super();
|
|
18
|
+
this.value = value;
|
|
19
|
+
}
|
|
20
|
+
static $shape = "mapping";
|
|
21
|
+
serialize() {
|
|
22
|
+
return $Mapping.$serialize(this.value);
|
|
23
|
+
}
|
|
24
|
+
static deserialize(value) {
|
|
25
|
+
return new this($Mapping.$deserialize(value));
|
|
26
|
+
}
|
|
27
|
+
static $deserialize(value) {
|
|
28
|
+
const transform = Object.entries(value).map(([key, child]) => {
|
|
29
|
+
return [key, Shape(_value).$deserialize(child)];
|
|
30
|
+
});
|
|
31
|
+
return Object.fromEntries(transform);
|
|
32
|
+
}
|
|
33
|
+
static $serialize(value) {
|
|
34
|
+
const transform = Object.entries(value).map(([key, child]) => {
|
|
35
|
+
return [key, Shape($value).$serialize(child)];
|
|
36
|
+
});
|
|
37
|
+
return Object.fromEntries(transform);
|
|
38
|
+
}
|
|
39
|
+
static $inline;
|
|
40
|
+
}
|
|
41
|
+
return $Mapping;
|
|
42
|
+
};
|
|
43
|
+
//#endregion
|
|
44
|
+
export { Mapping };
|