@ddd-ts/shape 0.0.0-compute-timeout-on-process.2 → 0.0.0-compute-timeout-on-process.4
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/dist/_.d.ts +38 -0
- package/dist/_.d.ts.map +1 -0
- package/dist/_.js +37 -0
- package/dist/_.js.map +1 -0
- package/dist/addons/microsecond-timestamp.d.ts +27 -0
- package/dist/addons/microsecond-timestamp.d.ts.map +1 -0
- package/dist/addons/microsecond-timestamp.js +62 -0
- package/dist/addons/microsecond-timestamp.js.map +1 -0
- package/dist/choice.d.ts +28 -0
- package/dist/choice.d.ts.map +1 -0
- package/dist/choice.js +45 -0
- package/dist/choice.js.map +1 -0
- package/dist/class.d.ts +27 -0
- package/dist/class.d.ts.map +1 -0
- package/dist/class.js +31 -0
- package/dist/class.js.map +1 -0
- package/dist/dict.d.ts +38 -0
- package/dist/dict.d.ts.map +1 -0
- package/dist/dict.js +42 -0
- package/dist/dict.js.map +1 -0
- package/dist/discriminated-union.d.ts +63 -0
- package/dist/discriminated-union.d.ts.map +1 -0
- package/dist/discriminated-union.js +65 -0
- package/dist/discriminated-union.js.map +1 -0
- package/dist/either.d.ts +79 -0
- package/dist/either.d.ts.map +1 -0
- package/dist/either.js +52 -0
- package/dist/either.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +15 -0
- package/dist/literal.d.ts +19 -0
- package/dist/literal.d.ts.map +1 -0
- package/dist/literal.js +28 -0
- package/dist/literal.js.map +1 -0
- package/dist/mapping.d.ts +34 -0
- package/dist/mapping.d.ts.map +1 -0
- package/dist/mapping.js +46 -0
- package/dist/mapping.js.map +1 -0
- package/dist/multiple.d.ts +23 -0
- package/dist/multiple.d.ts.map +1 -0
- package/dist/multiple.js +120 -0
- package/dist/multiple.js.map +1 -0
- package/dist/nothing.d.ts +18 -0
- package/dist/nothing.d.ts.map +1 -0
- package/dist/nothing.js +20 -0
- package/dist/nothing.js.map +1 -0
- package/dist/optional.d.ts +29 -0
- package/dist/optional.d.ts.map +1 -0
- package/dist/optional.js +35 -0
- package/dist/optional.js.map +1 -0
- package/dist/primitive.d.ts +21 -0
- package/dist/primitive.d.ts.map +1 -0
- package/dist/primitive.js +31 -0
- package/dist/primitive.js.map +1 -0
- package/package.json +7 -4
package/dist/either.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ClassShorthand } from "./class.js";
|
|
2
|
+
import { AbstractConstructor, Constructor, DefinitionOf, Empty, Expand } from "./_.js";
|
|
3
|
+
|
|
4
|
+
//#region src/either.d.ts
|
|
5
|
+
type Config = {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
};
|
|
8
|
+
type ExhaustiveMatcher<C extends Config> = { [key in keyof C]: (value: InstanceType<C[key]>) => any };
|
|
9
|
+
type UnsafeFallthroughMatcher<C extends Config> = { [key in keyof C]?: (value: InstanceType<C[key]>) => any } & {
|
|
10
|
+
_: (value: InstanceType<C[keyof C]>) => any;
|
|
11
|
+
};
|
|
12
|
+
type PartialMatcher<C extends Config> = { [key in keyof C]?: (value: InstanceType<C[key]>) => any };
|
|
13
|
+
type Matcher<C extends Config> = ExhaustiveMatcher<C> | UnsafeFallthroughMatcher<C> | PartialMatcher<C>;
|
|
14
|
+
type EitherConfiguration = {
|
|
15
|
+
[key: string]: ClassShorthand;
|
|
16
|
+
};
|
|
17
|
+
type Internal<S extends EitherConfiguration, B extends AbstractConstructor<{}>> = {
|
|
18
|
+
Definition: DefinitionOf<S[keyof S]>;
|
|
19
|
+
Serialized: (B extends {
|
|
20
|
+
$name: infer U;
|
|
21
|
+
} ? {
|
|
22
|
+
$name: U;
|
|
23
|
+
} : {}) & {
|
|
24
|
+
_key: keyof S;
|
|
25
|
+
} & ReturnType<DefinitionOf<S[keyof S]>["$serialize"]>;
|
|
26
|
+
Deserializing: (B extends {
|
|
27
|
+
$name: infer U;
|
|
28
|
+
} ? {
|
|
29
|
+
$name: U;
|
|
30
|
+
} : {}) & {
|
|
31
|
+
_key: keyof S;
|
|
32
|
+
} & Parameters<DefinitionOf<S[keyof S]>["$deserialize"]>[0];
|
|
33
|
+
Inline: DefinitionOf<S[keyof S]>["$inline"];
|
|
34
|
+
};
|
|
35
|
+
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"]) => {
|
|
36
|
+
value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
|
|
37
|
+
serialize(): Expand<{ [K in keyof S]: {
|
|
38
|
+
_key: K;
|
|
39
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S]>;
|
|
40
|
+
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);
|
|
41
|
+
}) & {
|
|
42
|
+
serialized: { [K in keyof S]: {
|
|
43
|
+
_key: K;
|
|
44
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S];
|
|
45
|
+
of: S;
|
|
46
|
+
$shape: "either";
|
|
47
|
+
deserialize<T extends /*elided*/any>(this: T, value: Expand<{ [K in keyof S]: {
|
|
48
|
+
_key: K;
|
|
49
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S]>): InstanceType<T>;
|
|
50
|
+
$deserialize<T extends /*elided*/any>(this: T, value: { [K in keyof S]: {
|
|
51
|
+
_key: K;
|
|
52
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S]): DefinitionOf<S[keyof S]>["$inline"];
|
|
53
|
+
$serialize<T extends /*elided*/any>(this: T, value: DefinitionOf<S[keyof S]>["$inline"]): { [K in keyof S]: {
|
|
54
|
+
_key: K;
|
|
55
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S];
|
|
56
|
+
$inline: DefinitionOf<S[keyof S]>["$inline"];
|
|
57
|
+
}, "prototype"> & (abstract new (value: Expand<DefinitionOf<S[keyof S]>["$inline"]>) => InstanceType<B> & {
|
|
58
|
+
value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
|
|
59
|
+
serialize(): Expand<{ [K in keyof S]: {
|
|
60
|
+
_key: K;
|
|
61
|
+
} & ReturnType<DefinitionOf<S[K]>["$serialize"]> }[keyof S]>;
|
|
62
|
+
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);
|
|
63
|
+
});
|
|
64
|
+
type Either<S extends EitherConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<S, B>["Inline"]) => {
|
|
65
|
+
value: Internal<S, B>["Inline"];
|
|
66
|
+
serialize(): Internal<S, B>["Serialized"];
|
|
67
|
+
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);
|
|
68
|
+
}) & {
|
|
69
|
+
serialized: Internal<S, B>["Serialized"];
|
|
70
|
+
of: S;
|
|
71
|
+
$shape: "either";
|
|
72
|
+
deserialize<T extends Constructor>(this: T, value: Internal<S, B>["Serialized"]): InstanceType<T>;
|
|
73
|
+
$deserialize<T>(this: T, value: Internal<S, B>["Serialized"]): Internal<S, B>["Inline"];
|
|
74
|
+
$serialize<T>(this: T, value: Internal<S, B>["Inline"]): Internal<S, B>["Serialized"];
|
|
75
|
+
$inline: Internal<S, B>["Inline"];
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { Either, EitherConfiguration };
|
|
79
|
+
//# sourceMappingURL=either.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"either.d.ts","names":[],"sources":["../src/either.ts"],"mappings":";;;;KAWK,MAAA;EAAA,CAAY,GAAA;AAAA;AAAA,KAEZ,iBAAA,WAA4B,MAAA,oBACjB,CAAA,IAAK,KAAA,EAAO,YAAA,CAAa,CAAA,CAAE,GAAA;AAAA,KAGtC,wBAAA,WAAmC,MAAA,oBACxB,CAAA,KAAM,KAAA,EAAO,YAAA,CAAa,CAAA,CAAE,GAAA;EAE1C,CAAA,GAAI,KAAA,EAAO,YAAA,CAAa,CAAA,OAAQ,CAAA;AAAA;AAAA,KAG7B,cAAA,WAAyB,MAAA,oBACd,CAAA,KAAM,KAAA,EAAO,YAAA,CAAa,CAAA,CAAE,GAAA;AAAA,KAGvC,OAAA,WAAkB,MAAA,IACnB,iBAAA,CAAkB,CAAA,IAClB,wBAAA,CAAyB,CAAA,IACzB,cAAA,CAAe,CAAA;AAAA,KAEP,mBAAA;EAAA,CACT,GAAA,WAAc,cAAA;AAAA;AAAA,KAGZ,QAAA,WACO,mBAAA,YACA,mBAAA;EAEV,UAAA,EAAY,YAAA,CAAa,CAAA,OAAQ,CAAA;EACjC,UAAA,GAAa,CAAA;IAAY,KAAA;EAAA;IAAqB,KAAA,EAAO,CAAA;EAAA;IACnD,IAAA,QAAY,CAAA;EAAA,IACV,UAAA,CAAW,YAAA,CA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UAAA,CAAW,CAAA;AAAA;EAEvD,UAAA,EAAY,QAAA,CAAS,CAAA,EAAG,CAAA;EACxB,EAAA,EAAI,CAAA;EACJ,MAAA;EACA,WAAA,WAAsB,WAAA,EACpB,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,QAAA,CAAS,CAAA,EAAG,CAAA,kBAClB,YAAA,CAAa,CAAA;EAChB,YAAA,IACE,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,QAAA,CAAS,CAAA,EAAG,CAAA,kBAClB,QAAA,CAAS,CAAA,EAAG,CAAA;EACf,UAAA,IACE,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,QAAA,CAAS,CAAA,EAAG,CAAA,cAClB,QAAA,CAAS,CAAA,EAAG,CAAA;EACf,OAAA,EAAS,QAAA,CAAS,CAAA,EAAG,CAAA;AAAA"}
|
package/dist/either.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.js";
|
|
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 };
|
|
52
|
+
//# sourceMappingURL=either.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"either.js","names":[],"sources":["../src/either.ts"],"sourcesContent":["import {\n Constructor,\n Expand,\n DefinitionOf,\n Shape,\n AbstractConstructor,\n Empty,\n} from \"./_\";\nimport { ClassShorthand } from \"./class\";\nimport { PrimitiveShorthand } from \"./primitive\";\n\ntype Config = { [key: string]: any };\n\ntype ExhaustiveMatcher<C extends Config> = {\n [key in keyof C]: (value: InstanceType<C[key]>) => any;\n};\n\ntype UnsafeFallthroughMatcher<C extends Config> = {\n [key in keyof C]?: (value: InstanceType<C[key]>) => any;\n} & {\n _: (value: InstanceType<C[keyof C]>) => any;\n};\n\ntype PartialMatcher<C extends Config> = {\n [key in keyof C]?: (value: InstanceType<C[key]>) => any;\n};\n\ntype Matcher<C extends Config> =\n | ExhaustiveMatcher<C>\n | UnsafeFallthroughMatcher<C>\n | PartialMatcher<C>;\n\nexport type EitherConfiguration = {\n [key: string]: ClassShorthand;\n};\n\ntype Internal<\n S extends EitherConfiguration,\n B extends AbstractConstructor<{}>,\n> = {\n Definition: DefinitionOf<S[keyof S]>;\n Serialized: (B extends { $name: infer U } ? { $name: U } : {}) & {\n _key: keyof S;\n } & ReturnType<DefinitionOf<S[keyof S]>[\"$serialize\"]>;\n Deserializing: (B extends { $name: infer U } ? { $name: U } : {}) & {\n _key: keyof S;\n } & Parameters<DefinitionOf<S[keyof S]>[\"$deserialize\"]>[0];\n Inline: DefinitionOf<S[keyof S]>[\"$inline\"];\n};\n\nexport const Either = <\n const S extends EitherConfiguration,\n const B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n) => {\n type Serialized = {\n [K in keyof S]: { _key: K } & ReturnType<DefinitionOf<S[K]>[\"$serialize\"]>;\n }[keyof S];\n\n type Inline = DefinitionOf<S[keyof S]>[\"$inline\"];\n\n const definitions = Object.fromEntries(\n Object.entries(of).map(([key, value]) => {\n return [key, Shape(value)] as const;\n }),\n );\n\n abstract class $Either extends (base as any as Constructor<{}>) {\n constructor(public value: Inline) {\n super();\n }\n\n static serialized: Serialized;\n\n static of = of;\n\n static $shape = \"either\" as const;\n\n serialize(): Expand<Serialized> {\n return ($Either as any).$serialize(this.value) as any;\n }\n\n match<\n M extends Matcher<S>,\n F extends M extends ExhaustiveMatcher<S>\n ? []\n : M extends UnsafeFallthroughMatcher<S>\n ? []\n : M extends PartialMatcher<S>\n ? [\n fallback: (\n value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>,\n ) => any,\n ]\n : [],\n >(\n ...[matcher, fallback]: [matcher: M, ...F]\n ):\n | (M[keyof M] extends (...args: any[]) => any\n ? ReturnType<M[keyof M]>\n : never)\n | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never) {\n const key: any = Object.entries(of).find(\n ([_, v]) => v === ((this.value as any).constructor as any),\n )?.[0] as any;\n\n const handler = matcher[key];\n if (handler) {\n return handler(this.value as any);\n }\n if (fallback) {\n return fallback(this.value as any);\n }\n if (matcher._) {\n return matcher._(this.value as any);\n }\n throw new Error(\"Non-exhaustive match\");\n }\n\n static deserialize<T extends typeof $Either>(\n this: T,\n value: Expand<Serialized>,\n ): InstanceType<T> {\n return new (this as any)(this.$deserialize(value as any)) as any;\n }\n\n static $deserialize<T extends typeof $Either>(\n this: T,\n value: Serialized,\n ): Inline {\n const { _key: key, ...serialized } = value as any;\n const definition = definitions[key];\n if (!definition) {\n throw new Error(\"Cannot deserialize Either\");\n }\n return (definition as any).$deserialize(serialized);\n }\n\n static $serialize<T extends typeof $Either>(\n this: T,\n value: Inline,\n ): Serialized {\n const key = Object.entries(of).find(\n ([_, v]) => v === ((value as any).constructor as any),\n )?.[0];\n if (!key) {\n throw new Error(\"Cannot serialize Either, no matching key\");\n }\n\n const definition = definitions[key];\n if (!definition) {\n throw new Error(\"Cannot serialize Either\");\n }\n return { ...(definition as any).$serialize(value), _key: key } as any;\n }\n\n static $inline: Inline;\n }\n\n type EitherConstructor = abstract new (\n value: Expand<Inline>,\n ) => InstanceType<B> & $Either;\n type Either = Omit<B, \"prototype\"> &\n Omit<typeof $Either, \"prototype\"> &\n EitherConstructor;\n\n return $Either as Either;\n};\n\nexport type Either<\n S extends EitherConfiguration,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"prototype\"> &\n (abstract new (\n value: Internal<S, B>[\"Inline\"],\n ) => {\n value: Internal<S, B>[\"Inline\"];\n serialize(): Internal<S, B>[\"Serialized\"];\n match<\n M extends Matcher<S>,\n F extends M extends ExhaustiveMatcher<S>\n ? []\n : M extends UnsafeFallthroughMatcher<S>\n ? []\n : M extends PartialMatcher<S>\n ? [\n fallback: (\n value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>,\n ) => any,\n ]\n : [],\n >(\n matcher: M,\n ...fallback_n: F\n ):\n | (M[keyof M] extends (...args: any[]) => any\n ? ReturnType<M[keyof M]>\n : never)\n | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);\n }) & {\n serialized: Internal<S, B>[\"Serialized\"];\n of: S;\n $shape: \"either\";\n deserialize<T extends Constructor>(\n this: T,\n value: Internal<S, B>[\"Serialized\"],\n ): InstanceType<T>;\n $deserialize<T>(\n this: T,\n value: Internal<S, B>[\"Serialized\"],\n ): Internal<S, B>[\"Inline\"];\n $serialize<T>(\n this: T,\n value: Internal<S, B>[\"Inline\"],\n ): Internal<S, B>[\"Serialized\"];\n $inline: Internal<S, B>[\"Inline\"];\n };\n"],"mappings":";;;AAkDA,MAAa,UAIX,IACA,OAAU,UACP;CAOH,MAAM,cAAc,OAAO,YACzB,OAAO,QAAQ,GAAG,CAAC,KAAK,CAAC,KAAK,WAAW;AACvC,SAAO,CAAC,KAAK,MAAM,MAAM,CAAC;GAC1B,CACH;CAED,MAAe,gBAAiB,KAAgC;EAC9D,YAAY,AAAO,OAAe;AAChC,UAAO;GADU;;EAInB,OAAO;EAEP,OAAO,KAAK;EAEZ,OAAO,SAAS;EAEhB,YAAgC;AAC9B,UAAQ,QAAgB,WAAW,KAAK,MAAM;;EAGhD,MAcE,GAAG,CAAC,SAAS,WAKuD;GAKpE,MAAM,UAAU,QAJC,OAAO,QAAQ,GAAG,CAAC,MACjC,CAAC,GAAG,OAAO,MAAQ,KAAK,MAAc,YACxC,GAAG;AAGJ,OAAI,QACF,QAAO,QAAQ,KAAK,MAAa;AAEnC,OAAI,SACF,QAAO,SAAS,KAAK,MAAa;AAEpC,OAAI,QAAQ,EACV,QAAO,QAAQ,EAAE,KAAK,MAAa;AAErC,SAAM,IAAI,MAAM,uBAAuB;;EAGzC,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,KAAa,KAAK,aAAa,MAAa,CAAC;;EAG3D,OAAO,aAEL,OACQ;GACR,MAAM,EAAE,MAAM,KAAK,GAAG,eAAe;GACrC,MAAM,aAAa,YAAY;AAC/B,OAAI,CAAC,WACH,OAAM,IAAI,MAAM,4BAA4B;AAE9C,UAAQ,WAAmB,aAAa,WAAW;;EAGrD,OAAO,WAEL,OACY;GACZ,MAAM,MAAM,OAAO,QAAQ,GAAG,CAAC,MAC5B,CAAC,GAAG,OAAO,MAAQ,MAAc,YACnC,GAAG;AACJ,OAAI,CAAC,IACH,OAAM,IAAI,MAAM,2CAA2C;GAG7D,MAAM,aAAa,YAAY;AAC/B,OAAI,CAAC,WACH,OAAM,IAAI,MAAM,0BAA0B;AAE5C,UAAO;IAAE,GAAI,WAAmB,WAAW,MAAM;IAAE,MAAM;IAAK;;EAGhE,OAAO;;AAUT,QAAO"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Class, ClassShorthand, IClass } from "./class.js";
|
|
2
|
+
import { Dict, DictShorthand, IDict } from "./dict.js";
|
|
3
|
+
import { IPrimitive, Primitive, PrimitiveFromConstructor, PrimitiveShorthand } from "./primitive.js";
|
|
4
|
+
import { IMultiple, Multiple, MultipleConfiguration, MultipleShorthand } from "./multiple.js";
|
|
5
|
+
import { Nothing, NothingShorthand } from "./nothing.js";
|
|
6
|
+
import { ILiteral, Literal, LiteralShorthand } from "./literal.js";
|
|
7
|
+
import { AbstractConstructor, Concrete, Constructor, Definition, DefinitionOf, Empty, Expand, MakeAbstract, MergeClasses, Shape, Shorthand, forward } from "./_.js";
|
|
8
|
+
import { Choice, ChoiceMatcher, ChoiceMatcherResult, IChoice } from "./choice.js";
|
|
9
|
+
import { Either, EitherConfiguration } from "./either.js";
|
|
10
|
+
import { BestKey, DiscriminatedUnion, DiscriminatedUnionConfiguration, IDiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.js";
|
|
11
|
+
import { Mapping, MappingConfiguration } from "./mapping.js";
|
|
12
|
+
import { IOptional, Optional, OptionalConfiguration } from "./optional.js";
|
|
13
|
+
import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.js";
|
|
14
|
+
export { AbstractConstructor, BestKey, Choice, ChoiceMatcher, ChoiceMatcherResult, Class, ClassShorthand, Concrete, Constructor, Definition, DefinitionOf, Dict, DictShorthand, DiscriminatedUnion, DiscriminatedUnionConfiguration, Either, EitherConfiguration, Empty, Expand, IChoice, IClass, IDict, IDiscriminatedUnion, ILiteral, IMultiple, IOptional, IPrimitive, Literal, LiteralShorthand, MakeAbstract, Mapping, MappingConfiguration, MergeClasses, MicrosecondTimestamp, Multiple, MultipleConfiguration, MultipleShorthand, Nothing, NothingShorthand, Optional, OptionalConfiguration, Primitive, PrimitiveFromConstructor, PrimitiveShorthand, Shape, Shorthand, findBestKey, forward, prepareShapeMap };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Class } from "./class.js";
|
|
2
|
+
import { Dict } from "./dict.js";
|
|
3
|
+
import { Primitive } from "./primitive.js";
|
|
4
|
+
import { Multiple } from "./multiple.js";
|
|
5
|
+
import { Nothing } from "./nothing.js";
|
|
6
|
+
import { Literal } from "./literal.js";
|
|
7
|
+
import { Empty, Shape, forward } from "./_.js";
|
|
8
|
+
import { Choice } from "./choice.js";
|
|
9
|
+
import { Either } from "./either.js";
|
|
10
|
+
import { DiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.js";
|
|
11
|
+
import { Mapping } from "./mapping.js";
|
|
12
|
+
import { Optional } from "./optional.js";
|
|
13
|
+
import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.js";
|
|
14
|
+
|
|
15
|
+
export { Choice, Class, Dict, DiscriminatedUnion, Either, Empty, Literal, Mapping, MicrosecondTimestamp, Multiple, Nothing, Optional, Primitive, Shape, findBestKey, forward, prepareShapeMap };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AbstractConstructor, Constructor, Empty, Expand } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/literal.d.ts
|
|
4
|
+
type LiteralShorthand = string | number;
|
|
5
|
+
declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => ILiteral<S, B>;
|
|
6
|
+
type ILiteral<S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & {
|
|
7
|
+
value: S;
|
|
8
|
+
$shape: "literal";
|
|
9
|
+
deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;
|
|
10
|
+
$serialize(value: S): S;
|
|
11
|
+
$deserialize(value: S): S;
|
|
12
|
+
$inline: S;
|
|
13
|
+
} & (abstract new (value: Expand<S>) => InstanceType<B> & {
|
|
14
|
+
readonly value: S;
|
|
15
|
+
serialize(): S;
|
|
16
|
+
});
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ILiteral, Literal, LiteralShorthand };
|
|
19
|
+
//# sourceMappingURL=literal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.d.ts","names":[],"sources":["../src/literal.ts"],"mappings":";;;KAEY,gBAAA;AAAA,cAEC,OAAA,mBACK,gBAAA,YACN,mBAAA,cAAuB,KAAA,EAAA,EAAA,EAE7B,CAAA,EAAC,IAAA,GACC,CAAA,KACL,QAAA,CAAS,CAAA,EAAG,CAAA;AAAA,KAgCH,QAAA,WACA,gBAAA,YACA,mBAAA,cAAiC,KAAA,IACzC,IAAA,CAAK,CAAA;EACP,KAAA,EAAO,CAAA;EACP,MAAA;EACA,WAAA,WAAsB,WAAA,EAAa,IAAA,EAAM,CAAA,EAAG,KAAA,EAAO,CAAA,GAAI,YAAA,CAAa,CAAA;EACpE,UAAA,CAAW,KAAA,EAAO,CAAA,GAAI,CAAA;EACtB,YAAA,CAAa,KAAA,EAAO,CAAA,GAAI,CAAA;EACxB,OAAA,EAAS,CAAA;AAAA,mBAEP,KAAA,EAAO,MAAA,CAAO,CAAA,MACX,YAAA,CAAa,CAAA;EAAA,SACP,KAAA,EAAO,CAAA;EAChB,SAAA,IAAa,CAAA;AAAA"}
|
package/dist/literal.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Empty } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/literal.ts
|
|
4
|
+
const Literal = (of, base = Empty) => {
|
|
5
|
+
class $Literal extends base {
|
|
6
|
+
value = of;
|
|
7
|
+
static value = of;
|
|
8
|
+
static $shape = "literal";
|
|
9
|
+
serialize() {
|
|
10
|
+
return of;
|
|
11
|
+
}
|
|
12
|
+
static deserialize(value) {
|
|
13
|
+
return new this();
|
|
14
|
+
}
|
|
15
|
+
static $serialize(value) {
|
|
16
|
+
return of;
|
|
17
|
+
}
|
|
18
|
+
static $deserialize(value) {
|
|
19
|
+
return of;
|
|
20
|
+
}
|
|
21
|
+
static $inline;
|
|
22
|
+
}
|
|
23
|
+
return $Literal;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
export { Literal };
|
|
28
|
+
//# sourceMappingURL=literal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"literal.js","names":[],"sources":["../src/literal.ts"],"sourcesContent":["import { AbstractConstructor, Constructor, Empty, Expand } from \"./_\";\n\nexport type LiteralShorthand = string | number;\n\nexport const Literal = <\n const S extends LiteralShorthand,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n): ILiteral<S, B> => {\n type Inline = S;\n\n abstract class $Literal extends (base as any as Constructor<{}>) {\n public readonly value = of;\n static value = of;\n static $shape = \"literal\" as const;\n serialize(): S {\n return of;\n }\n\n static deserialize<T extends typeof $Literal>(\n this: T,\n value: Inline,\n ): InstanceType<T> {\n return new (this as any)() as InstanceType<T>;\n }\n\n static $serialize(value: Inline): Inline {\n return of;\n }\n\n static $deserialize(value: Inline): Inline {\n return of;\n }\n\n static $inline: Inline;\n }\n\n return $Literal as any;\n};\n\nexport type ILiteral<\n S extends LiteralShorthand,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"prototype\"> & {\n value: S;\n $shape: \"literal\";\n deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;\n $serialize(value: S): S;\n $deserialize(value: S): S;\n $inline: S;\n} & (abstract new (\n value: Expand<S>,\n ) => InstanceType<B> & {\n readonly value: S;\n serialize(): S;\n });\n"],"mappings":";;;AAIA,MAAa,WAIX,IACA,OAAU,UACS;CAGnB,MAAe,iBAAkB,KAAgC;EAC/D,AAAgB,QAAQ;EACxB,OAAO,QAAQ;EACf,OAAO,SAAS;EAChB,YAAe;AACb,UAAO;;EAGT,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,MAAc;;EAG5B,OAAO,WAAW,OAAuB;AACvC,UAAO;;EAGT,OAAO,aAAa,OAAuB;AACzC,UAAO;;EAGT,OAAO;;AAGT,QAAO"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AbstractConstructor, Constructor, Definition, DefinitionOf, Empty, Expand, Shorthand } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/mapping.d.ts
|
|
4
|
+
type MappingLiteralKey = [[StringConstructor, string], [NumberConstructor, number]];
|
|
5
|
+
type MappingKeyConstructor = MappingLiteralKey[number][0];
|
|
6
|
+
type MappingKeyRuntimeFromConstructor<S extends MappingKeyConstructor> = S extends StringConstructor ? string : number;
|
|
7
|
+
type MappingConfiguration = [MappingKeyConstructor, Definition | Shorthand] | [Definition | Shorthand];
|
|
8
|
+
type MappingOf<C extends MappingConfiguration> = C extends [infer K extends MappingKeyConstructor, infer V extends Definition | Shorthand] ? {
|
|
9
|
+
key: K;
|
|
10
|
+
value: DefinitionOf<V>;
|
|
11
|
+
} : C extends [infer V extends Definition | Shorthand] ? {
|
|
12
|
+
key: StringConstructor;
|
|
13
|
+
value: DefinitionOf<V>;
|
|
14
|
+
} : never;
|
|
15
|
+
type Internal<C extends MappingConfiguration, B extends AbstractConstructor<{}>> = {
|
|
16
|
+
Definition: MappingOf<C>["value"];
|
|
17
|
+
Serialized: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>;
|
|
18
|
+
Deserializing: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, Parameters<MappingOf<C>["value"]["$deserialize"]>[0]>;
|
|
19
|
+
Inline: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
|
|
20
|
+
};
|
|
21
|
+
declare const Mapping: <C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty>(config: C, base?: B) => Mapping<C, B>;
|
|
22
|
+
type Mapping<C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<C, B>["Inline"]) => InstanceType<B> & {
|
|
23
|
+
value: Internal<C, B>["Inline"];
|
|
24
|
+
serialize(): Expand<Internal<C, B>["Serialized"]>;
|
|
25
|
+
}) & {
|
|
26
|
+
$shape: "mapping";
|
|
27
|
+
deserialize<T extends Constructor>(this: T, value: Expand<Internal<C, B>["Serialized"]>): InstanceType<T>;
|
|
28
|
+
$deserialize<T>(this: T, value: Internal<C, B>["Deserializing"]): Internal<C, B>["Inline"];
|
|
29
|
+
$serialize<T>(this: T, value: Internal<C, B>["Inline"]): Internal<C, B>["Serialized"];
|
|
30
|
+
$inline: Internal<C, B>["Inline"];
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Mapping, MappingConfiguration };
|
|
34
|
+
//# sourceMappingURL=mapping.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.d.ts","names":[],"sources":["../src/mapping.ts"],"mappings":";;;KAYK,iBAAA,KACF,iBAAA,YACA,iBAAA;AAAA,KAEE,qBAAA,GAAwB,iBAAA;AAAA,KACxB,gCAAA,WAA2C,qBAAA,IAC9C,CAAA,SAAU,iBAAA;AAAA,KAEA,oBAAA,IACP,qBAAA,EAAuB,UAAA,GAAa,SAAA,KACpC,UAAA,GAAa,SAAA;AAAA,KAEb,SAAA,WAAoB,oBAAA,IAAwB,CAAA,0BAC/B,qBAAA,kBACA,UAAA,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;EACf,UAAA,IACE,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,QAAA,CAAS,CAAA,EAAG,CAAA,cAClB,QAAA,CAAS,CAAA,EAAG,CAAA;EACf,OAAA,EAAS,QAAA,CAAS,CAAA,EAAG,CAAA;AAAA"}
|
package/dist/mapping.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Primitive } from "./primitive.js";
|
|
2
|
+
import { Empty, Shape } from "./_.js";
|
|
3
|
+
|
|
4
|
+
//#region src/mapping.ts
|
|
5
|
+
const Mapping = (config, base = Empty) => {
|
|
6
|
+
let [_key, _value] = config;
|
|
7
|
+
if (config.length === 1) {
|
|
8
|
+
_key = Primitive(String);
|
|
9
|
+
_value = config[0];
|
|
10
|
+
}
|
|
11
|
+
const { $key, $value } = {
|
|
12
|
+
$key: _key,
|
|
13
|
+
$value: _value
|
|
14
|
+
};
|
|
15
|
+
class $Mapping extends base {
|
|
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
|
+
|
|
44
|
+
//#endregion
|
|
45
|
+
export { Mapping };
|
|
46
|
+
//# sourceMappingURL=mapping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mapping.js","names":[],"sources":["../src/mapping.ts"],"sourcesContent":["import {\n Definition,\n Expand,\n Shorthand,\n DefinitionOf,\n Shape,\n AbstractConstructor,\n Empty,\n Constructor,\n} from \"./_\";\nimport { Primitive } from \"./primitive\";\n\ntype MappingLiteralKey = [\n [StringConstructor, string],\n [NumberConstructor, number],\n];\ntype MappingKeyConstructor = MappingLiteralKey[number][0];\ntype MappingKeyRuntimeFromConstructor<S extends MappingKeyConstructor> =\n S extends StringConstructor ? string : number;\n\nexport type MappingConfiguration =\n | [MappingKeyConstructor, Definition | Shorthand]\n | [Definition | Shorthand];\n\ntype MappingOf<C extends MappingConfiguration> = C extends [\n infer K extends MappingKeyConstructor,\n infer V extends Definition | Shorthand,\n]\n ? { key: K; value: DefinitionOf<V> }\n : C extends [infer V extends Definition | Shorthand]\n ? { key: StringConstructor; value: DefinitionOf<V> }\n : never;\n\ntype Internal<\n C extends MappingConfiguration,\n B extends AbstractConstructor<{}>,\n> = {\n Definition: MappingOf<C>[\"value\"];\n Serialized: Record<\n MappingKeyRuntimeFromConstructor<MappingOf<C>[\"key\"]>,\n ReturnType<MappingOf<C>[\"value\"][\"$serialize\"]>\n >;\n Deserializing: Record<\n MappingKeyRuntimeFromConstructor<MappingOf<C>[\"key\"]>,\n Parameters<MappingOf<C>[\"value\"][\"$deserialize\"]>[0]\n >;\n Inline: Record<\n MappingKeyRuntimeFromConstructor<MappingOf<C>[\"key\"]>,\n MappingOf<C>[\"value\"][\"$inline\"]\n >;\n};\n\nexport const Mapping = <\n C extends MappingConfiguration,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n config: C,\n base: B = Empty as any,\n): Mapping<C, B> => {\n let [_key, _value] = config;\n if (config.length === 1) {\n _key = Primitive(String);\n _value = config[0];\n }\n\n const { $key, $value } = { $key: _key, $value: _value };\n\n type Definition = MappingOf<C>[\"value\"];\n type K = MappingOf<C>[\"key\"];\n type Key = MappingKeyRuntimeFromConstructor<K>;\n type Serialized = Record<Key, ReturnType<Definition[\"$serialize\"]>>;\n type Inline = Record<Key, Definition[\"$inline\"]>;\n\n type A = {\n Inline: Inline;\n Serialized: Serialized;\n Definition: Definition;\n Deserializing: Serialized;\n };\n\n abstract class $Mapping extends (base as any as Constructor<{}>) {\n constructor(public value: Inline) {\n super();\n }\n\n static $shape = \"mapping\" as const;\n\n serialize(): Expand<Serialized> {\n return $Mapping.$serialize(this.value) as any;\n }\n\n static deserialize<T extends typeof $Mapping>(\n this: T,\n value: Expand<Serialized>,\n ): InstanceType<T> {\n return new (this as any)(($Mapping as any).$deserialize(value)) as any;\n }\n\n static $deserialize<T extends typeof $Mapping>(\n this: T,\n value: Serialized,\n ): Inline {\n const split = Object.entries(value);\n const transform = split.map(([key, child]) => {\n const longhand = Shape(_value) as any;\n const deserialized = longhand.$deserialize(child as any);\n return [key, deserialized] as const;\n });\n return Object.fromEntries(transform) as any;\n }\n\n static $serialize<T extends typeof $Mapping>(\n this: T,\n value: Inline,\n ): Serialized {\n const split = Object.entries(value);\n const transform = split.map(([key, child]) => {\n const longhand = Shape($value) as any;\n const serialized = longhand.$serialize(child as any);\n return [key, serialized];\n });\n const merge = Object.fromEntries(transform);\n return merge;\n }\n\n static $inline: Inline;\n }\n\n type MappingConstructor = abstract new (\n value: Expand<Inline>,\n ) => InstanceType<B> & $Mapping;\n\n type Mapping = Omit<B, \"prototype\"> &\n Omit<typeof $Mapping, \"prototype\"> &\n MappingConstructor;\n\n return $Mapping as any;\n};\n\nexport type Mapping<\n C extends MappingConfiguration,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"prototype\"> &\n (abstract new (\n value: Internal<C, B>[\"Inline\"],\n ) => InstanceType<B> & {\n value: Internal<C, B>[\"Inline\"];\n serialize(): Expand<Internal<C, B>[\"Serialized\"]>;\n }) & {\n $shape: \"mapping\";\n deserialize<T extends Constructor>(\n this: T,\n value: Expand<Internal<C, B>[\"Serialized\"]>,\n ): InstanceType<T>;\n $deserialize<T>(\n this: T,\n value: Internal<C, B>[\"Deserializing\"],\n ): Internal<C, B>[\"Inline\"];\n $serialize<T>(\n this: T,\n value: Internal<C, B>[\"Inline\"],\n ): Internal<C, B>[\"Serialized\"];\n $inline: Internal<C, B>[\"Inline\"];\n };\n"],"mappings":";;;;AAoDA,MAAa,WAIX,QACA,OAAU,UACQ;CAClB,IAAI,CAAC,MAAM,UAAU;AACrB,KAAI,OAAO,WAAW,GAAG;AACvB,SAAO,UAAU,OAAO;AACxB,WAAS,OAAO;;CAGlB,MAAM,EAAE,MAAM,WAAW;EAAE,MAAM;EAAM,QAAQ;EAAQ;CAevD,MAAe,iBAAkB,KAAgC;EAC/D,YAAY,AAAO,OAAe;AAChC,UAAO;GADU;;EAInB,OAAO,SAAS;EAEhB,YAAgC;AAC9B,UAAO,SAAS,WAAW,KAAK,MAAM;;EAGxC,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,KAAc,SAAiB,aAAa,MAAM,CAAC;;EAGjE,OAAO,aAEL,OACQ;GAER,MAAM,YADQ,OAAO,QAAQ,MAAM,CACX,KAAK,CAAC,KAAK,WAAW;AAG5C,WAAO,CAAC,KAFS,MAAM,OAAO,CACA,aAAa,MAAa,CAC9B;KAC1B;AACF,UAAO,OAAO,YAAY,UAAU;;EAGtC,OAAO,WAEL,OACY;GAEZ,MAAM,YADQ,OAAO,QAAQ,MAAM,CACX,KAAK,CAAC,KAAK,WAAW;AAG5C,WAAO,CAAC,KAFS,MAAM,OAAO,CACF,WAAW,MAAa,CAC5B;KACxB;AAEF,UADc,OAAO,YAAY,UAAU;;EAI7C,OAAO;;AAWT,QAAO"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AbstractConstructor, Constructor, Definition, DefinitionOf, Empty, Expand, Shorthand } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/multiple.d.ts
|
|
4
|
+
type MultipleConfiguration = Definition | Shorthand;
|
|
5
|
+
type MultipleShorthand = [any] | readonly [any];
|
|
6
|
+
type Internal<S extends MultipleConfiguration> = {
|
|
7
|
+
Serialized: ReturnType<DefinitionOf<S>["$serialize"]>[];
|
|
8
|
+
Inline: DefinitionOf<S>["$inline"][];
|
|
9
|
+
};
|
|
10
|
+
declare const Multiple: <const S extends MultipleConfiguration, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IMultiple<S, B>;
|
|
11
|
+
type IMultiple<S extends MultipleConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<S>["Inline"]) => InstanceType<B> & Pick<Internal<S>["Inline"], "at" | "length" | "concat" | "copyWithin" | "entries" | "every" | "fill" | "filter" | "find" | "findIndex" | "flat" | "flatMap" | "forEach" | "includes" | "indexOf" | "join" | "keys" | "lastIndexOf" | "map" | "pop" | "push" | "reduce" | "reduceRight" | "reverse" | "shift" | "slice" | "some" | "sort" | "splice" | "unshift" | "values" | typeof Symbol.iterator> & {
|
|
12
|
+
value: Internal<S>["Inline"];
|
|
13
|
+
serialize(): Expand<Internal<S>["Serialized"]>;
|
|
14
|
+
}) & {
|
|
15
|
+
$shape: "multiple";
|
|
16
|
+
deserialize<T extends Constructor>(this: T, value: Expand<Internal<S>["Serialized"]>): InstanceType<T>;
|
|
17
|
+
$deserialize<T extends Constructor>(this: T, value: Internal<S>["Serialized"]): InstanceType<T>;
|
|
18
|
+
$serialize(value: Internal<S>["Inline"]): Internal<S>["Serialized"];
|
|
19
|
+
$inline: Internal<S>["Inline"];
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
|
22
|
+
export { IMultiple, Multiple, MultipleConfiguration, MultipleShorthand };
|
|
23
|
+
//# sourceMappingURL=multiple.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple.d.ts","names":[],"sources":["../src/multiple.ts"],"mappings":";;;KAWY,qBAAA,GAAwB,UAAA,GAAa,SAAA;AAAA,KACrC,iBAAA;AAAA,KAEP,QAAA,WAAmB,qBAAA;EACtB,UAAA,EAAY,UAAA,CAAW,YAAA,CAAa,CAAA;EACpC,MAAA,EAAQ,YAAA,CAAa,CAAA;AAAA;AAAA,cAGV,QAAA,mBACK,qBAAA,YACN,mBAAA,cAAuB,KAAA,EAAA,EAAA,EAE7B,CAAA,EAAC,IAAA,GACC,CAAA,KACL,SAAA,CAAU,CAAA,EAAG,CAAA;AAAA,KAqJJ,SAAA,WACA,qBAAA,YACA,mBAAA,cAAiC,KAAA,IACzC,IAAA,CAAK,CAAA,gCAEL,KAAA,EAAO,QAAA,CAAS,CAAA,gBACb,YAAA,CAAa,CAAA,IAChB,IAAA,CACE,QAAA,CAAS,CAAA,qWAgCA,MAAA,CAAO,QAAA;EAEhB,KAAA,EAAO,QAAA,CAAS,CAAA;EAChB,SAAA,IAAa,MAAA,CAAO,QAAA,CAAS,CAAA;AAAA;EAE/B,MAAA;EACA,WAAA,WAAsB,WAAA,EACpB,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,MAAA,CAAO,QAAA,CAAS,CAAA,mBACtB,YAAA,CAAa,CAAA;EAChB,YAAA,WAAuB,WAAA,EACrB,IAAA,EAAM,CAAA,EACN,KAAA,EAAO,QAAA,CAAS,CAAA,kBACf,YAAA,CAAa,CAAA;EAChB,UAAA,CAAW,KAAA,EAAO,QAAA,CAAS,CAAA,cAAe,QAAA,CAAS,CAAA;EACnD,OAAA,EAAS,QAAA,CAAS,CAAA;AAAA"}
|
package/dist/multiple.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Empty, Shape } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/multiple.ts
|
|
4
|
+
const Multiple = (of, base = Empty) => {
|
|
5
|
+
const longhand = Shape(of);
|
|
6
|
+
class $Multiple extends base {
|
|
7
|
+
constructor(value) {
|
|
8
|
+
super();
|
|
9
|
+
this.value = value;
|
|
10
|
+
}
|
|
11
|
+
static $shape = "multiple";
|
|
12
|
+
serialize() {
|
|
13
|
+
return $Multiple.$serialize(this.value);
|
|
14
|
+
}
|
|
15
|
+
static deserialize(value) {
|
|
16
|
+
return new this($Multiple.$deserialize(value));
|
|
17
|
+
}
|
|
18
|
+
static $deserialize(value) {
|
|
19
|
+
return value.map(longhand.$deserialize);
|
|
20
|
+
}
|
|
21
|
+
static $serialize(value) {
|
|
22
|
+
return value.map(longhand.$serialize);
|
|
23
|
+
}
|
|
24
|
+
[Symbol.iterator]() {
|
|
25
|
+
return this.value[Symbol.iterator]();
|
|
26
|
+
}
|
|
27
|
+
get map() {
|
|
28
|
+
return this.value.map.bind(this.value);
|
|
29
|
+
}
|
|
30
|
+
get reduce() {
|
|
31
|
+
return this.value.reduce.bind(this.value);
|
|
32
|
+
}
|
|
33
|
+
get filter() {
|
|
34
|
+
return this.value.filter.bind(this.value);
|
|
35
|
+
}
|
|
36
|
+
get forEach() {
|
|
37
|
+
return this.value.forEach.bind(this.value);
|
|
38
|
+
}
|
|
39
|
+
get some() {
|
|
40
|
+
return this.value.some.bind(this.value);
|
|
41
|
+
}
|
|
42
|
+
get every() {
|
|
43
|
+
return this.value.every.bind(this.value);
|
|
44
|
+
}
|
|
45
|
+
get find() {
|
|
46
|
+
return this.value.find.bind(this.value);
|
|
47
|
+
}
|
|
48
|
+
get findIndex() {
|
|
49
|
+
return this.value.findIndex.bind(this.value);
|
|
50
|
+
}
|
|
51
|
+
get indexOf() {
|
|
52
|
+
return this.value.indexOf.bind(this.value);
|
|
53
|
+
}
|
|
54
|
+
get lastIndexOf() {
|
|
55
|
+
return this.value.lastIndexOf.bind(this.value);
|
|
56
|
+
}
|
|
57
|
+
get includes() {
|
|
58
|
+
return this.value.includes.bind(this.value);
|
|
59
|
+
}
|
|
60
|
+
get keys() {
|
|
61
|
+
return this.value.keys.bind(this.value);
|
|
62
|
+
}
|
|
63
|
+
get values() {
|
|
64
|
+
return this.value.values.bind(this.value);
|
|
65
|
+
}
|
|
66
|
+
get entries() {
|
|
67
|
+
return this.value.entries.bind(this.value);
|
|
68
|
+
}
|
|
69
|
+
get at() {
|
|
70
|
+
return this.value.at.bind(this.value);
|
|
71
|
+
}
|
|
72
|
+
get concat() {
|
|
73
|
+
return this.value.concat.bind(this.value);
|
|
74
|
+
}
|
|
75
|
+
get flat() {
|
|
76
|
+
return this.value.flat.bind(this.value);
|
|
77
|
+
}
|
|
78
|
+
get splice() {
|
|
79
|
+
return this.value.splice.bind(this.value);
|
|
80
|
+
}
|
|
81
|
+
get flatMap() {
|
|
82
|
+
return this.value.flatMap.bind(this.value);
|
|
83
|
+
}
|
|
84
|
+
get push() {
|
|
85
|
+
return this.value.push.bind(this.value);
|
|
86
|
+
}
|
|
87
|
+
get pop() {
|
|
88
|
+
return this.value.pop.bind(this.value);
|
|
89
|
+
}
|
|
90
|
+
get sort() {
|
|
91
|
+
return this.value.sort.bind(this.value);
|
|
92
|
+
}
|
|
93
|
+
get slice() {
|
|
94
|
+
return this.value.slice.bind(this.value);
|
|
95
|
+
}
|
|
96
|
+
get length() {
|
|
97
|
+
return this.value.length;
|
|
98
|
+
}
|
|
99
|
+
get fill() {
|
|
100
|
+
return this.value.fill.bind(this.value);
|
|
101
|
+
}
|
|
102
|
+
get copyWithin() {
|
|
103
|
+
return this.value.copyWithin.bind(this.value);
|
|
104
|
+
}
|
|
105
|
+
get reverse() {
|
|
106
|
+
return this.value.reverse.bind(this.value);
|
|
107
|
+
}
|
|
108
|
+
get shift() {
|
|
109
|
+
return this.value.shift.bind(this.value);
|
|
110
|
+
}
|
|
111
|
+
get unshift() {
|
|
112
|
+
return this.value.unshift.bind(this.value);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return $Multiple;
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
//#endregion
|
|
119
|
+
export { Multiple };
|
|
120
|
+
//# sourceMappingURL=multiple.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiple.js","names":[],"sources":["../src/multiple.ts"],"sourcesContent":["import {\n Definition,\n Expand,\n Shorthand,\n DefinitionOf,\n Shape,\n AbstractConstructor,\n Empty,\n Constructor,\n} from \"./_\";\n\nexport type MultipleConfiguration = Definition | Shorthand;\nexport type MultipleShorthand = [any] | readonly [any];\n\ntype Internal<S extends MultipleConfiguration> = {\n Serialized: ReturnType<DefinitionOf<S>[\"$serialize\"]>[];\n Inline: DefinitionOf<S>[\"$inline\"][];\n};\n\nexport const Multiple = <\n const S extends MultipleConfiguration,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n): IMultiple<S, B> => {\n const longhand = Shape(of);\n\n abstract class $Multiple extends (base as any as Constructor<{}>) {\n constructor(public value: any[]) {\n super();\n }\n static $shape = \"multiple\" as const;\n\n serialize() {\n return $Multiple.$serialize(this.value);\n }\n\n static deserialize(value: any) {\n return new (this as any)(($Multiple as any).$deserialize(value));\n }\n\n static $deserialize(value: any) {\n return (value as any).map(longhand.$deserialize);\n }\n\n static $serialize(value: any) {\n return (value as any).map(longhand.$serialize as any);\n }\n\n [Symbol.iterator]() {\n return this.value[Symbol.iterator]();\n }\n\n get map() {\n return this.value.map.bind(this.value);\n }\n\n get reduce() {\n return this.value.reduce.bind(this.value);\n }\n\n get filter() {\n return this.value.filter.bind(this.value);\n }\n\n get forEach() {\n return this.value.forEach.bind(this.value);\n }\n\n get some() {\n return this.value.some.bind(this.value);\n }\n\n get every() {\n return this.value.every.bind(this.value);\n }\n\n get find() {\n return this.value.find.bind(this.value);\n }\n\n get findIndex() {\n return this.value.findIndex.bind(this.value);\n }\n\n get indexOf() {\n return this.value.indexOf.bind(this.value);\n }\n\n get lastIndexOf() {\n return this.value.lastIndexOf.bind(this.value);\n }\n\n get includes() {\n return this.value.includes.bind(this.value);\n }\n\n get keys() {\n return this.value.keys.bind(this.value);\n }\n\n get values() {\n return this.value.values.bind(this.value);\n }\n\n get entries() {\n return this.value.entries.bind(this.value);\n }\n\n get at() {\n return this.value.at.bind(this.value);\n }\n\n get concat() {\n return this.value.concat.bind(this.value);\n }\n\n get flat() {\n return this.value.flat.bind(this.value);\n }\n\n get splice() {\n return this.value.splice.bind(this.value);\n }\n\n get flatMap() {\n return this.value.flatMap.bind(this.value);\n }\n\n get push() {\n return this.value.push.bind(this.value);\n }\n\n get pop() {\n return this.value.pop.bind(this.value);\n }\n\n get sort() {\n return this.value.sort.bind(this.value);\n }\n\n get slice() {\n return this.value.slice.bind(this.value);\n }\n\n get length() {\n return this.value.length;\n }\n\n get fill() {\n return this.value.fill.bind(this.value);\n }\n\n get copyWithin() {\n return this.value.copyWithin.bind(this.value);\n }\n\n get reverse() {\n return this.value.reverse.bind(this.value);\n }\n\n get shift() {\n return this.value.shift.bind(this.value);\n }\n\n get unshift() {\n return this.value.unshift.bind(this.value);\n }\n }\n\n return $Multiple as any;\n};\n\nexport type IMultiple<\n S extends MultipleConfiguration,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"prototype\"> &\n (abstract new (\n value: Internal<S>[\"Inline\"],\n ) => InstanceType<B> &\n Pick<\n Internal<S>[\"Inline\"],\n | \"at\"\n | \"length\"\n | \"concat\"\n | \"copyWithin\"\n | \"entries\"\n | \"every\"\n | \"fill\"\n | \"filter\"\n | \"find\"\n | \"findIndex\"\n | \"flat\"\n | \"flatMap\"\n | \"forEach\"\n | \"includes\"\n | \"indexOf\"\n | \"join\"\n | \"keys\"\n | \"lastIndexOf\"\n | \"map\"\n | \"pop\"\n | \"push\"\n | \"reduce\"\n | \"reduceRight\"\n | \"reverse\"\n | \"shift\"\n | \"slice\"\n | \"some\"\n | \"sort\"\n | \"splice\"\n | \"unshift\"\n | \"values\"\n | typeof Symbol.iterator\n > & {\n value: Internal<S>[\"Inline\"];\n serialize(): Expand<Internal<S>[\"Serialized\"]>;\n }) & {\n $shape: \"multiple\";\n deserialize<T extends Constructor>(\n this: T,\n value: Expand<Internal<S>[\"Serialized\"]>,\n ): InstanceType<T>;\n $deserialize<T extends Constructor>(\n this: T,\n value: Internal<S>[\"Serialized\"],\n ): InstanceType<T>;\n $serialize(value: Internal<S>[\"Inline\"]): Internal<S>[\"Serialized\"];\n $inline: Internal<S>[\"Inline\"];\n };\n"],"mappings":";;;AAmBA,MAAa,YAIX,IACA,OAAU,UACU;CACpB,MAAM,WAAW,MAAM,GAAG;CAE1B,MAAe,kBAAmB,KAAgC;EAChE,YAAY,AAAO,OAAc;AAC/B,UAAO;GADU;;EAGnB,OAAO,SAAS;EAEhB,YAAY;AACV,UAAO,UAAU,WAAW,KAAK,MAAM;;EAGzC,OAAO,YAAY,OAAY;AAC7B,UAAO,IAAK,KAAc,UAAkB,aAAa,MAAM,CAAC;;EAGlE,OAAO,aAAa,OAAY;AAC9B,UAAQ,MAAc,IAAI,SAAS,aAAa;;EAGlD,OAAO,WAAW,OAAY;AAC5B,UAAQ,MAAc,IAAI,SAAS,WAAkB;;EAGvD,CAAC,OAAO,YAAY;AAClB,UAAO,KAAK,MAAM,OAAO,WAAW;;EAGtC,IAAI,MAAM;AACR,UAAO,KAAK,MAAM,IAAI,KAAK,KAAK,MAAM;;EAGxC,IAAI,SAAS;AACX,UAAO,KAAK,MAAM,OAAO,KAAK,KAAK,MAAM;;EAG3C,IAAI,SAAS;AACX,UAAO,KAAK,MAAM,OAAO,KAAK,KAAK,MAAM;;EAG3C,IAAI,UAAU;AACZ,UAAO,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM;;EAG5C,IAAI,OAAO;AACT,UAAO,KAAK,MAAM,KAAK,KAAK,KAAK,MAAM;;EAGzC,IAAI,QAAQ;AACV,UAAO,KAAK,MAAM,MAAM,KAAK,KAAK,MAAM;;EAG1C,IAAI,OAAO;AACT,UAAO,KAAK,MAAM,KAAK,KAAK,KAAK,MAAM;;EAGzC,IAAI,YAAY;AACd,UAAO,KAAK,MAAM,UAAU,KAAK,KAAK,MAAM;;EAG9C,IAAI,UAAU;AACZ,UAAO,KAAK,MA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5C,IAAI,QAAQ;AACV,UAAO,KAAK,MAAM,MAAM,KAAK,KAAK,MAAM;;EAG1C,IAAI,UAAU;AACZ,UAAO,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM;;;AAI9C,QAAO"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { AbstractConstructor, Constructor, Empty } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/nothing.d.ts
|
|
4
|
+
type NothingShorthand = undefined;
|
|
5
|
+
declare const Nothing: <B extends AbstractConstructor<{}> = typeof Empty>(config: void, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (...args: any[]) => {
|
|
6
|
+
serialize(): void;
|
|
7
|
+
}) & {
|
|
8
|
+
$shape: "nothing";
|
|
9
|
+
deserialize<T extends Constructor>(this: T, value: void): InstanceType<T>;
|
|
10
|
+
$deserialize(): void;
|
|
11
|
+
$serialize(): void;
|
|
12
|
+
$inline: void;
|
|
13
|
+
}, ""> & (abstract new (value: void) => InstanceType<B> & {
|
|
14
|
+
serialize(): void;
|
|
15
|
+
});
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Nothing, NothingShorthand };
|
|
18
|
+
//# sourceMappingURL=nothing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nothing.d.ts","names":[],"sources":["../src/nothing.ts"],"mappings":";;;KAEY,gBAAA;AAAA,cAEC,OAAA,aAAqB,mBAAA,cAAuB,KAAA,EAAA,MAAA,QAC3C,IAAA,GACN,CAAA,KAAC,IAAA,CAAA,CAAA,iBAAA,IAAA,mBAAA,IAAA;;;;wBAMwB,WAAA,EAAW,IAAA,EAChC,CAAA,EAAC,KAAA,SAEN,YAAA,CAAa,CAAA;;;;wCAUb,YAAA,CAAa,CAAA"}
|
package/dist/nothing.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Empty } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/nothing.ts
|
|
4
|
+
const Nothing = (config, base = Empty) => {
|
|
5
|
+
class $Nothing extends base {
|
|
6
|
+
static $shape = "nothing";
|
|
7
|
+
serialize() {}
|
|
8
|
+
static deserialize(value) {
|
|
9
|
+
return new this();
|
|
10
|
+
}
|
|
11
|
+
static $deserialize() {}
|
|
12
|
+
static $serialize() {}
|
|
13
|
+
static $inline;
|
|
14
|
+
}
|
|
15
|
+
return $Nothing;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
//#endregion
|
|
19
|
+
export { Nothing };
|
|
20
|
+
//# sourceMappingURL=nothing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nothing.js","names":[],"sources":["../src/nothing.ts"],"sourcesContent":["import { AbstractConstructor, Constructor, Definition, Empty } from \"./_\";\n\nexport type NothingShorthand = undefined;\n\nexport const Nothing = <B extends AbstractConstructor<{}> = typeof Empty>(\n config: void,\n base: B = Empty as any,\n) => {\n abstract class $Nothing extends (base as any as Constructor<{}>) {\n static $shape = \"nothing\" as const;\n\n serialize() {}\n static deserialize<T extends Constructor>(\n this: T,\n value: void,\n ): InstanceType<T> {\n return new (this as any)();\n }\n static $deserialize() {}\n static $serialize() {}\n static $inline: void;\n }\n\n type NothingConstructor = abstract new (\n value: void,\n ) => InstanceType<B> & $Nothing;\n\n type Nothing = Omit<B, \"prototype\"> &\n Omit<typeof $Nothing, \"\"> &\n NothingConstructor;\n\n return $Nothing as Nothing;\n};\n"],"mappings":";;;AAIA,MAAa,WACX,QACA,OAAU,UACP;CACH,MAAe,iBAAkB,KAAgC;EAC/D,OAAO,SAAS;EAEhB,YAAY;EACZ,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,MAAc;;EAE5B,OAAO,eAAe;EACtB,OAAO,aAAa;EACpB,OAAO;;AAWT,QAAO"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AbstractConstructor, Constructor, Definition, DefinitionOf, Empty, Expand, Shorthand } from "./_.js";
|
|
2
|
+
|
|
3
|
+
//#region src/optional.d.ts
|
|
4
|
+
type OptionalConfiguration = Definition | Shorthand;
|
|
5
|
+
type Matcher<V> = {
|
|
6
|
+
some: (value: V) => any;
|
|
7
|
+
none: () => any;
|
|
8
|
+
};
|
|
9
|
+
type Internal<S extends Definition | Shorthand> = {
|
|
10
|
+
Serialized: ReturnType<DefinitionOf<S>["$serialize"]> | undefined;
|
|
11
|
+
Deserializing: Parameters<DefinitionOf<S>["$deserialize"]>[0] | undefined;
|
|
12
|
+
Inline: Expand<DefinitionOf<S>["$inline"]> | undefined;
|
|
13
|
+
Required: Expand<DefinitionOf<S>["$inline"]>;
|
|
14
|
+
};
|
|
15
|
+
declare const Optional: <S extends Definition | Shorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IOptional<S, B>;
|
|
16
|
+
type IOptional<S extends Definition | Shorthand, B extends AbstractConstructor<{}> = typeof Object> = Omit<B, "prototype"> & {
|
|
17
|
+
$shape: "optional";
|
|
18
|
+
deserialize<T extends Constructor>(this: T, value: Internal<S>["Deserializing"]): InstanceType<T>;
|
|
19
|
+
$deserialize(value: Internal<S>["Deserializing"]): Definition["$inline"];
|
|
20
|
+
$serialize<T>(this: T, value: Internal<S>["Inline"]): Internal<S>["Serialized"];
|
|
21
|
+
$inline: Internal<S>["Inline"];
|
|
22
|
+
} & (abstract new (value: Internal<S>["Inline"]) => InstanceType<B> & {
|
|
23
|
+
value: Internal<S>["Inline"];
|
|
24
|
+
serialize(): Expand<Internal<S>["Serialized"]>;
|
|
25
|
+
match<M extends Matcher<Expand<Internal<S>["Required"]>>>(config: M): ReturnType<M["some"]> | ReturnType<M["none"]>;
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { IOptional, Optional, OptionalConfiguration };
|
|
29
|
+
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.d.ts","names":[],"sources":["../src/optional.ts"],"mappings":";;;KAWY,qBAAA,GAAwB,UAAA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