@ddd-ts/shape 0.0.0-test-concurrency.5 → 0.0.0-ts-6-compat.2
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 +7 -7
- package/dist/_.d.ts.map +1 -1
- package/dist/_.js +34 -51
- package/dist/_.mjs +36 -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 +62 -0
- package/dist/addons/microsecond-timestamp.mjs +61 -0
- package/dist/choice.d.ts +13 -26
- package/dist/choice.d.ts.map +1 -1
- package/dist/choice.js +43 -47
- package/dist/choice.mjs +44 -0
- package/dist/class.d.ts +8 -7
- package/dist/class.d.ts.map +1 -1
- package/dist/class.js +29 -30
- package/dist/class.mjs +30 -0
- package/dist/deserialization-error.d.ts +32 -0
- package/dist/deserialization-error.d.ts.map +1 -0
- package/dist/deserialization-error.js +45 -0
- package/dist/deserialization-error.mjs +44 -0
- package/dist/dict.d.ts +25 -13
- package/dist/dict.d.ts.map +1 -1
- package/dist/dict.js +46 -44
- package/dist/dict.mjs +47 -0
- package/dist/discriminated-union.d.ts +16 -17
- package/dist/discriminated-union.d.ts.map +1 -1
- package/dist/discriminated-union.js +61 -92
- package/dist/discriminated-union.mjs +66 -0
- package/dist/either.d.ts +56 -12
- package/dist/either.d.ts.map +1 -1
- package/dist/either.js +50 -61
- package/dist/either.mjs +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +34 -29
- package/dist/index.mjs +16 -0
- package/dist/literal.d.ts +5 -7
- package/dist/literal.d.ts.map +1 -1
- package/dist/literal.js +26 -26
- package/dist/literal.mjs +27 -0
- package/dist/mapping.d.ts +16 -12
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.js +37 -49
- package/dist/mapping.mjs +38 -0
- package/dist/multiple.d.ts +10 -100
- package/dist/multiple.d.ts.map +1 -1
- package/dist/multiple.js +126 -105
- package/dist/multiple.mjs +127 -0
- package/dist/nothing.d.ts +2 -2
- package/dist/nothing.d.ts.map +1 -1
- package/dist/nothing.js +18 -18
- package/dist/nothing.mjs +19 -0
- package/dist/optional.d.ts +12 -14
- package/dist/optional.d.ts.map +1 -1
- package/dist/optional.js +33 -40
- package/dist/optional.mjs +34 -0
- package/dist/primitive.d.ts +5 -7
- package/dist/primitive.d.ts.map +1 -1
- package/dist/primitive.js +29 -29
- package/dist/primitive.mjs +30 -0
- package/package.json +24 -9
- package/dist/_.js.map +0 -1
- package/dist/choice.js.map +0 -1
- package/dist/choice.spec.d.ts +0 -2
- package/dist/choice.spec.d.ts.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.d.ts +0 -2
- package/dist/class.spec.d.ts.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.d.ts +0 -2
- package/dist/dict.spec.d.ts.map +0 -1
- package/dist/dict.spec.js +0 -180
- package/dist/dict.spec.js.map +0 -1
- package/dist/discriminated-union.js.map +0 -1
- package/dist/discriminated-union.spec.d.ts +0 -2
- package/dist/discriminated-union.spec.d.ts.map +0 -1
- package/dist/discriminated-union.spec.js +0 -262
- package/dist/discriminated-union.spec.js.map +0 -1
- package/dist/either.js.map +0 -1
- package/dist/either.spec.d.ts +0 -2
- package/dist/either.spec.d.ts.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.d.ts +0 -2
- package/dist/literal.spec.d.ts.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.d.ts +0 -2
- package/dist/mapping.spec.d.ts.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.d.ts +0 -2
- package/dist/multiple.spec.d.ts.map +0 -1
- package/dist/multiple.spec.js +0 -207
- package/dist/multiple.spec.js.map +0 -1
- package/dist/nothing.js.map +0 -1
- package/dist/nothing.spec.d.ts +0 -2
- package/dist/nothing.spec.d.ts.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.d.ts +0 -2
- package/dist/optional.spec.d.ts.map +0 -1
- package/dist/optional.spec.js +0 -172
- package/dist/optional.spec.js.map +0 -1
- package/dist/primitive.js.map +0 -1
- package/dist/primitive.spec.d.ts +0 -2
- package/dist/primitive.spec.d.ts.map +0 -1
- package/dist/primitive.spec.js +0 -162
- package/dist/primitive.spec.js.map +0 -1
- package/dist/test.d.ts +0 -36
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js +0 -45
- package/dist/test.js.map +0 -1
|
@@ -1,99 +1,68 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
exports.findBestKey = findBestKey;
|
|
5
|
-
exports.prepareShapeMap = prepareShapeMap;
|
|
6
|
-
const _1 = require("./_");
|
|
1
|
+
const require__ = require('./_.js');
|
|
2
|
+
|
|
3
|
+
//#region src/discriminated-union.ts
|
|
7
4
|
function findBestKey(config) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const key = Object.entries(hash)
|
|
22
|
-
.map(([key, value]) => [key, value.size])
|
|
23
|
-
.filter(([_, value]) => value === config.length)
|
|
24
|
-
.sort((a, b) => b[1] - a[1])?.[0]?.[0];
|
|
25
|
-
if (!key) {
|
|
26
|
-
throw new Error("Could not find key for DiscriminatedUnion");
|
|
27
|
-
}
|
|
28
|
-
return key;
|
|
5
|
+
const hash = {};
|
|
6
|
+
for (const c of config) {
|
|
7
|
+
const shape = "$of" in c ? c.$of : c;
|
|
8
|
+
for (const key in shape) {
|
|
9
|
+
const k = key;
|
|
10
|
+
if (hash[key]) hash[key].add(shape[k]);
|
|
11
|
+
else hash[key] = new Set([shape[k]]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const key = Object.entries(hash).map(([key, value]) => [key, value.size]).filter(([_, value]) => value === config.length).sort((a, b) => b[1] - a[1])?.[0]?.[0];
|
|
15
|
+
if (!key) throw new Error("Could not find key for DiscriminatedUnion");
|
|
16
|
+
return key;
|
|
29
17
|
}
|
|
30
18
|
function prepareShapeMap(config, key) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
// we first have to turn it into a Definition before accessing the discriminator
|
|
38
|
-
// Dict $of property references the configuration provided, which allows us to capture the discriminator
|
|
39
|
-
// Class $of property references the constructor of the class, which allows us to capture the discriminator
|
|
40
|
-
// which is mandatorily defined on the static side of the class
|
|
41
|
-
const discriminator = key in c
|
|
42
|
-
? c[key]
|
|
43
|
-
: "$of" in c
|
|
44
|
-
? c.$of[key]
|
|
45
|
-
: shape.$of[key];
|
|
46
|
-
acc[discriminator] = shape;
|
|
47
|
-
return acc;
|
|
48
|
-
}, {});
|
|
19
|
+
return config.reduce((acc, c) => {
|
|
20
|
+
const shape = require__.Shape(c);
|
|
21
|
+
const discriminator = key in c ? c[key] : "$of" in c ? c.$of[key] : shape.$of[key];
|
|
22
|
+
acc[discriminator] = shape;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
49
25
|
}
|
|
50
26
|
const DiscriminatedUnion = (of, ...args) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
throw new Error("Cannot deserialize DiscriminatedUnion");
|
|
88
|
-
}
|
|
89
|
-
return definition.$deserialize(value);
|
|
90
|
-
}
|
|
91
|
-
static $serialize(value) {
|
|
92
|
-
return map[value[key]].$serialize(value);
|
|
93
|
-
}
|
|
94
|
-
static $inline;
|
|
95
|
-
}
|
|
96
|
-
return $DiscriminatedUnion;
|
|
27
|
+
const base = args[0] || require__.Empty;
|
|
28
|
+
const key = findBestKey(of);
|
|
29
|
+
const map = prepareShapeMap(of, key);
|
|
30
|
+
class $DiscriminatedUnion extends base {
|
|
31
|
+
constructor(value) {
|
|
32
|
+
super();
|
|
33
|
+
this.value = value;
|
|
34
|
+
}
|
|
35
|
+
static $of = of;
|
|
36
|
+
static $shape = "discriminated-union";
|
|
37
|
+
serialize() {
|
|
38
|
+
return $DiscriminatedUnion.$serialize(this.value);
|
|
39
|
+
}
|
|
40
|
+
match(matcher, fallback) {
|
|
41
|
+
const element = this.value;
|
|
42
|
+
const handler = matcher[element[key]];
|
|
43
|
+
if (handler) return handler(element);
|
|
44
|
+
if (fallback) return fallback(element);
|
|
45
|
+
if (matcher._) return matcher._(element);
|
|
46
|
+
throw new Error("Non-exhaustive match");
|
|
47
|
+
}
|
|
48
|
+
static deserialize(value) {
|
|
49
|
+
return new this(this.$deserialize(value));
|
|
50
|
+
}
|
|
51
|
+
static $deserialize(value) {
|
|
52
|
+
const definition = map[value[key]];
|
|
53
|
+
if (!definition) throw new Error("Cannot deserialize DiscriminatedUnion");
|
|
54
|
+
return definition.$deserialize(value);
|
|
55
|
+
}
|
|
56
|
+
static $serialize(value) {
|
|
57
|
+
const definition = map[value[key]];
|
|
58
|
+
if (!definition) throw new Error("Cannot serialize DiscriminatedUnion");
|
|
59
|
+
return definition.$serialize(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return $DiscriminatedUnion;
|
|
97
63
|
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
98
66
|
exports.DiscriminatedUnion = DiscriminatedUnion;
|
|
99
|
-
|
|
67
|
+
exports.findBestKey = findBestKey;
|
|
68
|
+
exports.prepareShapeMap = prepareShapeMap;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/discriminated-union.ts
|
|
4
|
+
function findBestKey(config) {
|
|
5
|
+
const hash = {};
|
|
6
|
+
for (const c of config) {
|
|
7
|
+
const shape = "$of" in c ? c.$of : c;
|
|
8
|
+
for (const key in shape) {
|
|
9
|
+
const k = key;
|
|
10
|
+
if (hash[key]) hash[key].add(shape[k]);
|
|
11
|
+
else hash[key] = new Set([shape[k]]);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const key = Object.entries(hash).map(([key, value]) => [key, value.size]).filter(([_, value]) => value === config.length).sort((a, b) => b[1] - a[1])?.[0]?.[0];
|
|
15
|
+
if (!key) throw new Error("Could not find key for DiscriminatedUnion");
|
|
16
|
+
return key;
|
|
17
|
+
}
|
|
18
|
+
function prepareShapeMap(config, key) {
|
|
19
|
+
return config.reduce((acc, c) => {
|
|
20
|
+
const shape = Shape(c);
|
|
21
|
+
const discriminator = key in c ? c[key] : "$of" in c ? c.$of[key] : shape.$of[key];
|
|
22
|
+
acc[discriminator] = shape;
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
}
|
|
26
|
+
const DiscriminatedUnion = (of, ...args) => {
|
|
27
|
+
const base = args[0] || Empty;
|
|
28
|
+
const key = findBestKey(of);
|
|
29
|
+
const map = prepareShapeMap(of, key);
|
|
30
|
+
class $DiscriminatedUnion extends base {
|
|
31
|
+
constructor(value) {
|
|
32
|
+
super();
|
|
33
|
+
this.value = value;
|
|
34
|
+
}
|
|
35
|
+
static $of = of;
|
|
36
|
+
static $shape = "discriminated-union";
|
|
37
|
+
serialize() {
|
|
38
|
+
return $DiscriminatedUnion.$serialize(this.value);
|
|
39
|
+
}
|
|
40
|
+
match(matcher, fallback) {
|
|
41
|
+
const element = this.value;
|
|
42
|
+
const handler = matcher[element[key]];
|
|
43
|
+
if (handler) return handler(element);
|
|
44
|
+
if (fallback) return fallback(element);
|
|
45
|
+
if (matcher._) return matcher._(element);
|
|
46
|
+
throw new Error("Non-exhaustive match");
|
|
47
|
+
}
|
|
48
|
+
static deserialize(value) {
|
|
49
|
+
return new this(this.$deserialize(value));
|
|
50
|
+
}
|
|
51
|
+
static $deserialize(value) {
|
|
52
|
+
const definition = map[value[key]];
|
|
53
|
+
if (!definition) throw new Error("Cannot deserialize DiscriminatedUnion");
|
|
54
|
+
return definition.$deserialize(value);
|
|
55
|
+
}
|
|
56
|
+
static $serialize(value) {
|
|
57
|
+
const definition = map[value[key]];
|
|
58
|
+
if (!definition) throw new Error("Cannot serialize DiscriminatedUnion");
|
|
59
|
+
return definition.$serialize(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return $DiscriminatedUnion;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { DiscriminatedUnion, findBestKey, prepareShapeMap };
|
package/dist/either.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Expand, DefinitionOf, AbstractConstructor, Empty } from "./_";
|
|
2
|
-
import { ClassShorthand } from "./class";
|
|
3
|
-
import { PrimitiveShorthand } from "./primitive";
|
|
1
|
+
import { type Constructor, type Expand, type DefinitionOf, type AbstractConstructor, Empty } from "./_";
|
|
2
|
+
import type { ClassShorthand } from "./class";
|
|
4
3
|
type Config = {
|
|
5
4
|
[key: string]: any;
|
|
6
5
|
};
|
|
@@ -17,24 +16,69 @@ type PartialMatcher<C extends Config> = {
|
|
|
17
16
|
};
|
|
18
17
|
type Matcher<C extends Config> = ExhaustiveMatcher<C> | UnsafeFallthroughMatcher<C> | PartialMatcher<C>;
|
|
19
18
|
export type EitherConfiguration = {
|
|
20
|
-
[key: string]:
|
|
19
|
+
[key: string]: ClassShorthand;
|
|
20
|
+
};
|
|
21
|
+
type Internal<S extends EitherConfiguration, B extends AbstractConstructor<{}>> = {
|
|
22
|
+
Definition: DefinitionOf<S[keyof S]>;
|
|
23
|
+
Serialized: (B extends {
|
|
24
|
+
$name: infer U;
|
|
25
|
+
} ? {
|
|
26
|
+
$name: U;
|
|
27
|
+
} : {}) & {
|
|
28
|
+
_key: keyof S;
|
|
29
|
+
} & ReturnType<DefinitionOf<S[keyof S]>["$serialize"]>;
|
|
30
|
+
Deserializing: (B extends {
|
|
31
|
+
$name: infer U;
|
|
32
|
+
} ? {
|
|
33
|
+
$name: U;
|
|
34
|
+
} : {}) & {
|
|
35
|
+
_key: keyof S;
|
|
36
|
+
} & Parameters<DefinitionOf<S[keyof S]>["$deserialize"]>[0];
|
|
37
|
+
Inline: DefinitionOf<S[keyof S]>["$inline"];
|
|
21
38
|
};
|
|
22
39
|
export declare const Either: <const S extends EitherConfiguration, const B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: DefinitionOf<S[keyof S]>["$inline"]) => {
|
|
23
40
|
value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
|
|
24
|
-
serialize(): Expand<{ [K in keyof S]:
|
|
25
|
-
|
|
41
|
+
serialize(): Expand<{ [K in keyof S]: {
|
|
42
|
+
_key: K;
|
|
43
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>;
|
|
44
|
+
match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
|
|
26
45
|
}) & {
|
|
27
|
-
serialized: { [K in keyof S]:
|
|
46
|
+
serialized: { [K in keyof S]: {
|
|
47
|
+
_key: K;
|
|
48
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S];
|
|
28
49
|
of: S;
|
|
29
50
|
$shape: "either";
|
|
30
|
-
deserialize<T extends any>(this: T, value: Expand<{ [K in keyof S]:
|
|
31
|
-
|
|
32
|
-
|
|
51
|
+
deserialize<T extends /*elided*/ any>(this: T, value: Expand<{ [K in keyof S]: {
|
|
52
|
+
_key: K;
|
|
53
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>): InstanceType<T>;
|
|
54
|
+
$deserialize<T extends /*elided*/ any>(this: T, value: { [K in keyof S]: {
|
|
55
|
+
_key: K;
|
|
56
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]): DefinitionOf<S[keyof S]>["$inline"];
|
|
57
|
+
$serialize<T extends /*elided*/ any>(this: T, value: DefinitionOf<S[keyof S]>["$inline"]): { [K in keyof S]: {
|
|
58
|
+
_key: K;
|
|
59
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S];
|
|
33
60
|
$inline: DefinitionOf<S[keyof S]>["$inline"];
|
|
34
61
|
}, "prototype"> & (abstract new (value: Expand<DefinitionOf<S[keyof S]>["$inline"]>) => InstanceType<B> & {
|
|
35
62
|
value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
|
|
36
|
-
serialize(): Expand<{ [K in keyof S]:
|
|
37
|
-
|
|
63
|
+
serialize(): Expand<{ [K in keyof S]: {
|
|
64
|
+
_key: K;
|
|
65
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>;
|
|
66
|
+
match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
|
|
38
67
|
});
|
|
68
|
+
export type Either<S extends EitherConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<S, B>["Inline"]) => {
|
|
69
|
+
value: Internal<S, B>["Inline"];
|
|
70
|
+
serialize(): Internal<S, B>["Serialized"];
|
|
71
|
+
match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [
|
|
72
|
+
fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any
|
|
73
|
+
] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
|
|
74
|
+
}) & {
|
|
75
|
+
serialized: Internal<S, B>["Serialized"];
|
|
76
|
+
of: S;
|
|
77
|
+
$shape: "either";
|
|
78
|
+
deserialize<T extends Constructor>(this: T, value: Internal<S, B>["Serialized"]): InstanceType<T>;
|
|
79
|
+
$deserialize<T>(this: T, value: Internal<S, B>["Serialized"]): Internal<S, B>["Inline"];
|
|
80
|
+
$serialize<T>(this: T, value: Internal<S, B>["Inline"]): Internal<S, B>["Serialized"];
|
|
81
|
+
$inline: Internal<S, B>["Inline"];
|
|
82
|
+
};
|
|
39
83
|
export {};
|
|
40
84
|
//# sourceMappingURL=either.d.ts.map
|
package/dist/either.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,MAAM,EACX,KAAK,YAAY,EAEjB,KAAK,mBAAmB,EACxB,KAAK,EACN,MAAM,KAAK,CAAC;AACb,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,KAAK,MAAM,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,CAAC;AAErC,KAAK,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI;KACxC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG;CACvD,CAAC;AAEF,KAAK,wBAAwB,CAAC,CAAC,SAAS,MAAM,IAAI;KAC/C,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG;CACxD,GAAG;IACF,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC;CAC7C,CAAC;AAEF,KAAK,cAAc,CAAC,CAAC,SAAS,MAAM,IAAI;KACrC,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG;CACxD,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,SAAS,MAAM,IACzB,iBAA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YAAY,CAAC,GAClC,YAAY,CAAC,CAAC,CAAC,CAAC;IACnB,YAAY,CAAC,CAAC,EACZ,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,GAClC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5B,UAAU,CAAC,CAAC,EACV,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,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/either.js
CHANGED
|
@@ -1,62 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
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
|
-
if (!key) {
|
|
49
|
-
throw new Error("Cannot serialize Either, no matching key");
|
|
50
|
-
}
|
|
51
|
-
const definition = definitions[key];
|
|
52
|
-
if (!definition) {
|
|
53
|
-
throw new Error("Cannot serialize Either");
|
|
54
|
-
}
|
|
55
|
-
return [key, definition.$serialize(value)];
|
|
56
|
-
}
|
|
57
|
-
static $inline;
|
|
58
|
-
}
|
|
59
|
-
return $Either;
|
|
1
|
+
const require__ = require('./_.js');
|
|
2
|
+
|
|
3
|
+
//#region src/either.ts
|
|
4
|
+
const Either = (of, base = require__.Empty) => {
|
|
5
|
+
const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
|
|
6
|
+
return [key, require__.Shape(value)];
|
|
7
|
+
}));
|
|
8
|
+
class $Either extends base {
|
|
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;
|
|
60
48
|
};
|
|
61
|
-
|
|
62
|
-
//#
|
|
49
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
exports.Either = Either;
|
package/dist/either.mjs
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/either.ts
|
|
4
|
+
const Either = (of, base = Empty) => {
|
|
5
|
+
const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
|
|
6
|
+
return [key, Shape(value)];
|
|
7
|
+
}));
|
|
8
|
+
class $Either extends base {
|
|
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
|
+
|
|
50
|
+
//#endregion
|
|
51
|
+
export { Either };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./_";
|
|
2
|
+
export * from "./deserialization-error";
|
|
2
3
|
export * from "./choice";
|
|
3
4
|
export * from "./class";
|
|
4
5
|
export * from "./dict";
|
|
@@ -10,4 +11,5 @@ export * from "./mapping";
|
|
|
10
11
|
export * from "./multiple";
|
|
11
12
|
export * from "./nothing";
|
|
12
13
|
export * from "./optional";
|
|
14
|
+
export * from "./addons/microsecond-timestamp";
|
|
13
15
|
//# 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,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"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,yBAAyB,CAAC;AACxC,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,29 +1,34 @@
|
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_class = require('./class.js');
|
|
3
|
+
const require_deserialization_error = require('./deserialization-error.js');
|
|
4
|
+
const require_dict = require('./dict.js');
|
|
5
|
+
const require_primitive = require('./primitive.js');
|
|
6
|
+
const require_multiple = require('./multiple.js');
|
|
7
|
+
const require_nothing = require('./nothing.js');
|
|
8
|
+
const require_literal = require('./literal.js');
|
|
9
|
+
const require__ = require('./_.js');
|
|
10
|
+
const require_choice = require('./choice.js');
|
|
11
|
+
const require_either = require('./either.js');
|
|
12
|
+
const require_discriminated_union = require('./discriminated-union.js');
|
|
13
|
+
const require_mapping = require('./mapping.js');
|
|
14
|
+
const require_optional = require('./optional.js');
|
|
15
|
+
const require_microsecond_timestamp = require('./addons/microsecond-timestamp.js');
|
|
16
|
+
|
|
17
|
+
exports.Choice = require_choice.Choice;
|
|
18
|
+
exports.Class = require_class.Class;
|
|
19
|
+
exports.DeserializationError = require_deserialization_error.DeserializationError;
|
|
20
|
+
exports.Dict = require_dict.Dict;
|
|
21
|
+
exports.DiscriminatedUnion = require_discriminated_union.DiscriminatedUnion;
|
|
22
|
+
exports.Either = require_either.Either;
|
|
23
|
+
exports.Empty = require__.Empty;
|
|
24
|
+
exports.Literal = require_literal.Literal;
|
|
25
|
+
exports.Mapping = require_mapping.Mapping;
|
|
26
|
+
exports.MicrosecondTimestamp = require_microsecond_timestamp.MicrosecondTimestamp;
|
|
27
|
+
exports.Multiple = require_multiple.Multiple;
|
|
28
|
+
exports.Nothing = require_nothing.Nothing;
|
|
29
|
+
exports.Optional = require_optional.Optional;
|
|
30
|
+
exports.Primitive = require_primitive.Primitive;
|
|
31
|
+
exports.Shape = require__.Shape;
|
|
32
|
+
exports.findBestKey = require_discriminated_union.findBestKey;
|
|
33
|
+
exports.forward = require__.forward;
|
|
34
|
+
exports.prepareShapeMap = require_discriminated_union.prepareShapeMap;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Class } from "./class.mjs";
|
|
2
|
+
import { DeserializationError } from "./deserialization-error.mjs";
|
|
3
|
+
import { Dict } from "./dict.mjs";
|
|
4
|
+
import { Primitive } from "./primitive.mjs";
|
|
5
|
+
import { Multiple } from "./multiple.mjs";
|
|
6
|
+
import { Nothing } from "./nothing.mjs";
|
|
7
|
+
import { Literal } from "./literal.mjs";
|
|
8
|
+
import { Empty, Shape, forward } from "./_.mjs";
|
|
9
|
+
import { Choice } from "./choice.mjs";
|
|
10
|
+
import { Either } from "./either.mjs";
|
|
11
|
+
import { DiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.mjs";
|
|
12
|
+
import { Mapping } from "./mapping.mjs";
|
|
13
|
+
import { Optional } from "./optional.mjs";
|
|
14
|
+
import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.mjs";
|
|
15
|
+
|
|
16
|
+
export { Choice, Class, DeserializationError, Dict, DiscriminatedUnion, Either, Empty, Literal, Mapping, MicrosecondTimestamp, Multiple, Nothing, Optional, Primitive, Shape, findBestKey, forward, prepareShapeMap };
|
package/dist/literal.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { AbstractConstructor, Empty, Expand } from "./_";
|
|
1
|
+
import { type AbstractConstructor, type Constructor, Empty, type Expand } from "./_";
|
|
2
2
|
export type LiteralShorthand = string | number;
|
|
3
|
-
export declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) =>
|
|
4
|
-
|
|
5
|
-
serialize(): S;
|
|
6
|
-
}) & {
|
|
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"> & {
|
|
7
5
|
value: S;
|
|
8
6
|
$shape: "literal";
|
|
9
|
-
deserialize<T extends
|
|
7
|
+
deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;
|
|
10
8
|
$serialize(value: S): S;
|
|
11
9
|
$deserialize(value: S): S;
|
|
12
10
|
$inline: S;
|
|
13
|
-
}
|
|
11
|
+
} & (abstract new (value: Expand<S>) => InstanceType<B> & {
|
|
14
12
|
readonly value: S;
|
|
15
13
|
serialize(): S;
|
|
16
14
|
});
|
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.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,CAAC;AAErF,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC;AAE/C,eAAO,MAAM,OAAO,GAClB,KAAK,CAAC,CAAC,SAAS,gBAAgB,EAChC,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,GAAG,OAAO,KAAK,MAE5C,CAAC,SACC,CAAC,KACN,QAAQ,CAAC,CAAC,EAAE,CAAC,CA8Bf,CAAC;AAEF,MAAM,MAAM,QAAQ,CAClB,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,GAAG,OAAO,KAAK,IAC9C,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG;IACzB,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACvE,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACxB,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC;CACZ,GAAG,CAAC,QAAQ,MACT,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KACb,YAAY,CAAC,CAAC,CAAC,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,SAAS,IAAI,CAAC,CAAC;CAChB,CAAC,CAAC"}
|