@ddd-ts/shape 0.0.0-compute-timeout-on-process.8 → 0.0.0-compute-timeout-on-process.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/dist/_.d.ts +35 -34
- package/dist/_.d.ts.map +1 -1
- package/dist/_.mjs +1 -2
- package/dist/addons/microsecond-timestamp.d.ts +22 -25
- package/dist/addons/microsecond-timestamp.d.ts.map +1 -1
- package/dist/addons/microsecond-timestamp.mjs +1 -2
- package/dist/choice.d.ts +28 -26
- package/dist/choice.d.ts.map +1 -1
- package/dist/choice.mjs +1 -2
- package/dist/choice.spec.d.ts +2 -0
- package/dist/choice.spec.d.ts.map +1 -0
- package/dist/class.d.ts +16 -20
- package/dist/class.d.ts.map +1 -1
- package/dist/class.mjs +1 -2
- package/dist/class.spec.d.ts +2 -0
- package/dist/class.spec.d.ts.map +1 -0
- package/dist/dict.d.ts +35 -30
- package/dist/dict.d.ts.map +1 -1
- package/dist/dict.mjs +1 -2
- package/dist/dict.spec.d.ts +2 -0
- package/dist/dict.spec.d.ts.map +1 -0
- package/dist/discriminated-union.d.ts +48 -37
- package/dist/discriminated-union.d.ts.map +1 -1
- package/dist/discriminated-union.mjs +1 -2
- package/dist/discriminated-union.spec.d.ts +2 -0
- package/dist/discriminated-union.spec.d.ts.map +1 -0
- package/dist/either.d.ts +71 -66
- package/dist/either.d.ts.map +1 -1
- package/dist/either.mjs +1 -2
- package/dist/either.spec.d.ts +2 -0
- package/dist/either.spec.d.ts.map +1 -0
- package/dist/index.d.ts +14 -14
- package/dist/index.d.ts.map +1 -0
- package/dist/literal.d.ts +12 -16
- package/dist/literal.d.ts.map +1 -1
- package/dist/literal.mjs +1 -2
- package/dist/literal.spec.d.ts +2 -0
- package/dist/literal.spec.d.ts.map +1 -0
- package/dist/mapping.d.ts +34 -25
- package/dist/mapping.d.ts.map +1 -1
- package/dist/mapping.mjs +1 -2
- package/dist/mapping.spec.d.ts +2 -0
- package/dist/mapping.spec.d.ts.map +1 -0
- package/dist/multiple.d.ts +15 -18
- package/dist/multiple.d.ts.map +1 -1
- package/dist/multiple.mjs +1 -2
- package/dist/multiple.spec.d.ts +2 -0
- package/dist/multiple.spec.d.ts.map +1 -0
- package/dist/nothing.d.ts +10 -14
- package/dist/nothing.d.ts.map +1 -1
- package/dist/nothing.mjs +1 -2
- package/dist/nothing.spec.d.ts +2 -0
- package/dist/nothing.spec.d.ts.map +1 -0
- package/dist/optional.d.ts +19 -22
- package/dist/optional.d.ts.map +1 -1
- package/dist/optional.mjs +1 -2
- package/dist/optional.spec.d.ts +2 -0
- package/dist/optional.spec.d.ts.map +1 -0
- package/dist/primitive.d.ts +34 -17
- package/dist/primitive.d.ts.map +1 -1
- package/dist/primitive.mjs +1 -2
- package/dist/primitive.spec.d.ts +2 -0
- package/dist/primitive.spec.d.ts.map +1 -0
- package/dist/test.d.ts +36 -0
- package/dist/test.d.ts.map +1 -0
- package/package.json +7 -7
- package/dist/_.mjs.map +0 -1
- package/dist/addons/microsecond-timestamp.mjs.map +0 -1
- package/dist/choice.mjs.map +0 -1
- package/dist/class.mjs.map +0 -1
- package/dist/dict.mjs.map +0 -1
- package/dist/discriminated-union.mjs.map +0 -1
- package/dist/either.mjs.map +0 -1
- package/dist/literal.mjs.map +0 -1
- package/dist/mapping.mjs.map +0 -1
- package/dist/multiple.mjs.map +0 -1
- package/dist/nothing.mjs.map +0 -1
- package/dist/optional.mjs.map +0 -1
- package/dist/primitive.mjs.map +0 -1
package/dist/nothing.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { AbstractConstructor, Constructor, Empty } from "./_
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare const Nothing: <B extends AbstractConstructor<{}> = typeof Empty>(config: void, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (...args: any[]) => {
|
|
6
|
-
serialize(): void;
|
|
1
|
+
import { type AbstractConstructor, type Constructor, Empty } from "./_";
|
|
2
|
+
export type NothingShorthand = undefined;
|
|
3
|
+
export declare const Nothing: <B extends AbstractConstructor<{}> = typeof Empty>(config: void, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (...args: any[]) => {
|
|
4
|
+
serialize(): void;
|
|
7
5
|
}) & {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
$shape: "nothing";
|
|
7
|
+
deserialize<T extends Constructor>(this: T, value: void): InstanceType<T>;
|
|
8
|
+
$deserialize(): void;
|
|
9
|
+
$serialize(): void;
|
|
10
|
+
$inline: void;
|
|
13
11
|
}, ""> & (abstract new (value: void) => InstanceType<B> & {
|
|
14
|
-
|
|
12
|
+
serialize(): void;
|
|
15
13
|
});
|
|
16
|
-
//#endregion
|
|
17
|
-
export { Nothing, NothingShorthand };
|
|
18
14
|
//# sourceMappingURL=nothing.d.ts.map
|
package/dist/nothing.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nothing.d.ts","
|
|
1
|
+
{"version":3,"file":"nothing.d.ts","sourceRoot":"","sources":["../src/nothing.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAmB,KAAK,EAAE,MAAM,KAAK,CAAC;AAEzF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAEzC,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,yBAC/C,IAAI,SACN,CAAC;;;YAGW,SAAS;gBAGN,CAAC,SAAS,WAAW,QAChC,CAAC,SACA,IAAI,GACV,YAAY,CAAC,CAAC,CAAC;;;aAKF,IAAI;+BAIb,IAAI,KACR,YAAY,CAAC,CAAC,CAAC;;CAAW,CAOhC,CAAC"}
|
package/dist/nothing.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nothing.spec.d.ts","sourceRoot":"","sources":["../src/nothing.spec.ts"],"names":[],"mappings":""}
|
package/dist/optional.d.ts
CHANGED
|
@@ -1,29 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
//#region src/optional.d.ts
|
|
4
|
-
type OptionalConfiguration = Definition | Shorthand;
|
|
1
|
+
import { type Definition, type Expand, type Shorthand, type DefinitionOf, type Constructor, type AbstractConstructor, Empty } from "./_";
|
|
2
|
+
export type OptionalConfiguration = Definition | Shorthand;
|
|
5
3
|
type Matcher<V> = {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
some: (value: V) => any;
|
|
5
|
+
none: () => any;
|
|
8
6
|
};
|
|
9
7
|
type Internal<S extends Definition | Shorthand> = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
Serialized: ReturnType<DefinitionOf<S>["$serialize"]> | undefined;
|
|
9
|
+
Deserializing: Parameters<DefinitionOf<S>["$deserialize"]>[0] | undefined;
|
|
10
|
+
Inline: Expand<DefinitionOf<S>["$inline"]> | undefined;
|
|
11
|
+
Required: Expand<DefinitionOf<S>["$inline"]>;
|
|
14
12
|
};
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
export declare const Optional: <S extends Definition | Shorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IOptional<S, B>;
|
|
14
|
+
export type IOptional<S extends Definition | Shorthand, B extends AbstractConstructor<{}> = typeof Object> = Omit<B, "prototype"> & {
|
|
15
|
+
$shape: "optional";
|
|
16
|
+
deserialize<T extends Constructor>(this: T, value: Internal<S>["Deserializing"]): InstanceType<T>;
|
|
17
|
+
$deserialize(value: Internal<S>["Deserializing"]): Definition["$inline"];
|
|
18
|
+
$serialize<T>(this: T, value: Internal<S>["Inline"]): Internal<S>["Serialized"];
|
|
19
|
+
$inline: Internal<S>["Inline"];
|
|
22
20
|
} & (abstract new (value: Internal<S>["Inline"]) => InstanceType<B> & {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
value: Internal<S>["Inline"];
|
|
22
|
+
serialize(): Expand<Internal<S>["Serialized"]>;
|
|
23
|
+
match<M extends Matcher<Expand<Internal<S>["Required"]>>>(config: M): ReturnType<M["some"]> | ReturnType<M["none"]>;
|
|
26
24
|
});
|
|
27
|
-
|
|
28
|
-
export { IOptional, Optional, OptionalConfiguration };
|
|
25
|
+
export {};
|
|
29
26
|
//# sourceMappingURL=optional.d.ts.map
|
package/dist/optional.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"optional.d.ts","
|
|
1
|
+
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,UAAU,EACf,KAAK,MAAM,EACX,KAAK,SAAS,EACd,KAAK,YAAY,EAEjB,KAAK,WAAW,EAChB,KAAK,mBAAmB,EACxB,KAAK,EACN,MAAM,KAAK,CAAC;AAEb,MAAM,MAAM,qBAAqB,GAAG,UAAU,GAAG,SAAS,CAAC;AAE3D,KAAK,OAAO,CAAC,CAAC,IAAI;IAAE,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,CAAA;CAAE,CAAC;AAE/D,KAAK,QAAQ,CAAC,CAAC,SAAS,UAAU,GAAG,SAAS,IAAI;IAChD,UAAU,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,GAAG,SAAS,CAAC;IAClE,aAAa,EAAE,UAAU,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,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,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC7B,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;IAC/C,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,EACtD,MAAM,EAAE,CAAC,GACR,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CAClD,CAAC,CAAC"}
|
package/dist/optional.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.spec.d.ts","sourceRoot":"","sources":["../src/optional.spec.ts"],"names":[],"mappings":""}
|
package/dist/primitive.d.ts
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
import { AbstractConstructor, Constructor, Empty, Expand } from "./_
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type AbstractConstructor, type Constructor, Empty, type Expand } from "./_";
|
|
2
|
+
type PrimitiveMap = [
|
|
3
|
+
[
|
|
4
|
+
StringConstructor,
|
|
5
|
+
string
|
|
6
|
+
],
|
|
7
|
+
[
|
|
8
|
+
NumberConstructor,
|
|
9
|
+
number
|
|
10
|
+
],
|
|
11
|
+
[
|
|
12
|
+
DateConstructor,
|
|
13
|
+
Date
|
|
14
|
+
],
|
|
15
|
+
[
|
|
16
|
+
BooleanConstructor,
|
|
17
|
+
boolean
|
|
18
|
+
]
|
|
19
|
+
];
|
|
5
20
|
type PrimitiveConstructor = PrimitiveMap[number][0];
|
|
6
|
-
type PrimitiveFromConstructor<S> = Extract<PrimitiveMap[number], [
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
21
|
+
export type PrimitiveFromConstructor<S> = Extract<PrimitiveMap[number], [
|
|
22
|
+
S,
|
|
23
|
+
any
|
|
24
|
+
]>[1];
|
|
25
|
+
export type PrimitiveShorthand = PrimitiveConstructor;
|
|
26
|
+
export type IPrimitive<S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, ""> & (abstract new (value: Expand<PrimitiveFromConstructor<S>>) => InstanceType<B> & {
|
|
27
|
+
readonly value: Expand<PrimitiveFromConstructor<S>>;
|
|
28
|
+
serialize(): PrimitiveFromConstructor<S>;
|
|
11
29
|
}) & {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
30
|
+
$shape: "primitive";
|
|
31
|
+
deserialize<T extends Constructor<any>>(this: T, value: PrimitiveFromConstructor<S>): InstanceType<T>;
|
|
32
|
+
$serialize(value: PrimitiveFromConstructor<S>): PrimitiveFromConstructor<S>;
|
|
33
|
+
$deserialize(value: PrimitiveFromConstructor<S>): PrimitiveFromConstructor<S>;
|
|
34
|
+
$inline: Expand<PrimitiveFromConstructor<S>>;
|
|
17
35
|
};
|
|
18
|
-
declare const Primitive: <S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IPrimitive<S, B>;
|
|
19
|
-
|
|
20
|
-
export { IPrimitive, Primitive, PrimitiveFromConstructor, PrimitiveShorthand };
|
|
36
|
+
export declare const Primitive: <S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IPrimitive<S, B>;
|
|
37
|
+
export {};
|
|
21
38
|
//# sourceMappingURL=primitive.d.ts.map
|
package/dist/primitive.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"primitive.d.ts","
|
|
1
|
+
{"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAiB,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,KAA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,GACjC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEJ,eAAO,MAAM,SAAS,GACpB,CAAC,SAAS,oBAAoB,EAC9B,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,qBAE7B,CAAC,SACC,CAAC,KACN,UAAU,CAAC,CAAC,EAAE,CAAC,CA4CjB,CAAC"}
|
package/dist/primitive.mjs
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"primitive.spec.d.ts","sourceRoot":"","sources":["../src/primitive.spec.ts"],"names":[],"mappings":""}
|
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type Constructor } from "./_";
|
|
2
|
+
type IfEquals<T, U, Y = unknown, N = never> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? Y : N;
|
|
3
|
+
export type Equals<X, Y> = IfEquals<X, Y, true, false>;
|
|
4
|
+
export declare function ex<Received>(received: Received): {
|
|
5
|
+
toBe<Expected>(expected: Expected): Equals<Received, Expected> extends true ? {
|
|
6
|
+
ok: true;
|
|
7
|
+
} : {
|
|
8
|
+
expected: Expected;
|
|
9
|
+
received: Received;
|
|
10
|
+
};
|
|
11
|
+
toStrictEqual<Expected>(expected: Expected): Equals<Received, Expected> extends true ? {
|
|
12
|
+
ok: true;
|
|
13
|
+
} : {
|
|
14
|
+
expected: Expected;
|
|
15
|
+
received: Received;
|
|
16
|
+
};
|
|
17
|
+
toBeInstanceOf<Expected extends Constructor>(expected: Expected): Equals<Received, InstanceType<Expected>> extends true ? {
|
|
18
|
+
ok: true;
|
|
19
|
+
} : {
|
|
20
|
+
expected: InstanceType<Expected>;
|
|
21
|
+
received: Received;
|
|
22
|
+
};
|
|
23
|
+
toHaveFirstParam<Expected>(): Received extends (first: infer P, ...rest: any[]) => any ? Equals<P, Expected> extends true ? {
|
|
24
|
+
ok: true;
|
|
25
|
+
} : {
|
|
26
|
+
expected: Expected;
|
|
27
|
+
received: P;
|
|
28
|
+
} : Received extends Constructor<any, [infer P, ...any[]]> ? Equals<P, Expected> extends true ? {
|
|
29
|
+
ok: true;
|
|
30
|
+
} : {
|
|
31
|
+
expected: Expected;
|
|
32
|
+
received: P;
|
|
33
|
+
} : "not a function or constructor";
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test.d.ts","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAEvC,KAAK,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,OAAO,EAAE,CAAC,GAAG,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAC/D,CAAC,GACD,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GACvC,CAAC,GACD,CAAC,CAAC;AAEN,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAgJvD,wBAAgB,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ;SAEtC,QAAQ,YACD,QAAQ,GACjB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,IAAI,GACtC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE;kBAQhC,QAAQ,YACV,QAAQ,GACjB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,SAAS,IAAI,GACtC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE;mBAQ/B,QAAQ,SAAS,WAAW,YAC/B,QAAQ,GACjB,MAAM,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC,SAAS,IAAI,GACpD;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;QAAC,QAAQ,EAAE,QAAQ,CAAA;KAAE;qBAQ3C,QAAQ,KAAK,QAAQ,SAAS,CAC7C,KAAK,EAAE,MAAM,CAAC,EACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,GAAG,GACJ,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,IAAI,GAChC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,CAAC,CAAA;KAAE,GACnC,QAAQ,SAAS,WAAW,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,CAAC,GACtD,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,SAAS,IAAI,GAChC;QAAE,EAAE,EAAE,IAAI,CAAA;KAAE,GACZ;QAAE,QAAQ,EAAE,QAAQ,CAAC;QAAC,QAAQ,EAAE,CAAC,CAAA;KAAE,GACnC,+BAA+B;EAItC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddd-ts/shape",
|
|
3
|
-
"version": "0.0.0-compute-timeout-on-process.
|
|
3
|
+
"version": "0.0.0-compute-timeout-on-process.10",
|
|
4
4
|
"types": "dist/index.d.ts",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -10,22 +10,22 @@
|
|
|
10
10
|
"dist"
|
|
11
11
|
],
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@ddd-ts/traits": "0.0.0-compute-timeout-on-process.
|
|
13
|
+
"@ddd-ts/traits": "0.0.0-compute-timeout-on-process.10"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@ddd-ts/tools": "0.0.0-compute-timeout-on-process.
|
|
17
|
-
"@ddd-ts/types": "0.0.0-compute-timeout-on-process.
|
|
16
|
+
"@ddd-ts/tools": "0.0.0-compute-timeout-on-process.10",
|
|
17
|
+
"@ddd-ts/types": "0.0.0-compute-timeout-on-process.10",
|
|
18
18
|
"@types/jest": "^29.5.1"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
".": {
|
|
22
|
-
"default": "./dist/index.js",
|
|
23
22
|
"import": "./dist/index.mjs",
|
|
24
|
-
"require": "./dist/index.js"
|
|
25
|
-
"types": "./dist/index.d.ts"
|
|
23
|
+
"require": "./dist/index.js"
|
|
26
24
|
},
|
|
27
25
|
"./package.json": "./package.json"
|
|
28
26
|
},
|
|
27
|
+
"main": "./dist/index.js",
|
|
28
|
+
"module": "./dist/index.mjs",
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsdown --config node_modules/@ddd-ts/tools/tsdown.config.js",
|
|
31
31
|
"test": "jest --config node_modules/@ddd-ts/tools/jest.config.js"
|
package/dist/_.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_.mjs","names":[],"sources":["../src/_.ts"],"sourcesContent":["import { Class, IClass, ClassShorthand } from \"./class\";\nimport { Dict, IDict, DictShorthand } from \"./dict\";\nimport { Primitive, PrimitiveShorthand } from \"./primitive\";\nimport { Multiple, IMultiple, MultipleShorthand } from \"./multiple\";\nimport { Nothing, NothingShorthand } from \"./nothing\";\nimport { Literal, ILiteral, LiteralShorthand } from \"./literal\";\n\nexport abstract class Empty {}\n\nexport interface Constructor<T = any, P extends any[] = any[]> {\n new (...args: P): T;\n}\nexport type AbstractConstructor<\n T = any,\n P extends any[] = any[],\n> = abstract new (...args: P) => T;\n\nexport interface Definition {\n $shape: string;\n $inline: any;\n $serialize(value: any): any;\n $deserialize(value: any): any;\n}\n\nexport type MakeAbstract<T> = T extends new (\n ...params: infer P\n) => infer R\n ? Omit<T, \"\"> & (abstract new (...params: P) => R)\n : never;\n\nexport type Concrete<T extends AbstractConstructor<any>> =\n T extends abstract new (\n ...params: infer P\n ) => infer R\n ? Omit<T, \"\"> & {\n new (...params: P): R;\n }\n : never;\n\nexport type Shorthand =\n | Definition\n | DictShorthand\n | PrimitiveShorthand\n | MultipleShorthand\n | NothingShorthand\n | ClassShorthand\n | LiteralShorthand;\n\nexport type DefinitionOf<\n T extends Shorthand | Definition,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = T extends LiteralShorthand\n ? ILiteral<T, B>\n : T extends undefined\n ? ReturnType<typeof Nothing<B>>\n : T extends PrimitiveShorthand\n ? ReturnType<typeof Primitive<T, B>>\n : T extends MultipleShorthand\n ? IMultiple<T[0], B>\n : T extends ClassShorthand\n ? IClass<T, B>\n : T extends Definition\n ? T\n : T extends DictShorthand\n ? IDict<T, B>\n : never;\n\nexport function Shape<\n const S extends Definition | Shorthand,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(shorthand: S, base: B = Empty as any): DefinitionOf<S, B> {\n if (typeof shorthand === \"string\" || typeof shorthand === \"number\") {\n return Literal(shorthand, base) as any;\n }\n\n if (\n shorthand &&\n \"$shape\" in shorthand &&\n \"name\" in shorthand &&\n typeof shorthand.name === \"string\"\n ) {\n if ((shorthand as any).name.startsWith(\"$\")) {\n return shorthand as any;\n }\n return Class(shorthand as any, base) as any;\n }\n if (shorthand === undefined) {\n return Nothing(undefined, base) as any;\n }\n if ([String, Number, Date, Boolean].includes(shorthand as any)) {\n return Primitive(shorthand as any, base) as any;\n }\n if (shorthand && \"prototype\" in shorthand) {\n return Class(shorthand as any, base) as any;\n }\n\n if (Array.isArray(shorthand)) {\n return (Multiple as any)(shorthand[0] as any, base);\n }\n\n if (typeof shorthand === \"object\") {\n return Dict(shorthand as any, base) as any;\n }\n\n throw new Error(\n `Could not determine longhand from shorthand ${JSON.stringify(shorthand)}`,\n );\n}\n\nexport type Expand<T> = T extends { serialize(): any }\n ? T\n : T extends Date\n ? T\n : T extends Record<string, any>\n ? { [key in keyof T]: Expand<T[key]> }\n : T;\n\nexport function forward<\n T extends AbstractConstructor<{ value: any }>,\n const Forward extends T extends AbstractConstructor<{ value: infer U }>\n ? (keyof U)[]\n : never,\n>(\n base: T,\n forward: Forward,\n): MakeAbstract<\n T &\n (new (\n ...args: ConstructorParameters<T>\n ) => InstanceType<T> & {\n [K in Forward[number]]: InstanceType<T>[\"value\"][K];\n })\n> {\n for (const key of forward) {\n Object.defineProperty(base.prototype, key, {\n get() {\n return (this.value as any)[key].bind(this.value);\n },\n });\n }\n return base as any;\n}\n\nexport type MergeClasses<\n B extends AbstractConstructor,\n Current extends AbstractConstructor,\n> = abstract new (\n ...args: ConstructorParameters<Current>\n) => InstanceType<B> & InstanceType<Current>;\n"],"mappings":";;;;;;;;AAOA,IAAsB,QAAtB,MAA4B;AA4D5B,SAAgB,MAGd,WAAc,OAAU,OAAkC;AAC1D,KAAI,OAAO,cAAc,YAAY,OAAO,cAAc,SACxD,QAAO,QAAQ,WAAW,KAAK;AAGjC,KACE,aACA,YAAY,aACZ,UAAU,aACV,OAAO,UAAU,SAAS,UAC1B;AACA,MAAK,UAAkB,KAAK,WAAW,IAAI,CACzC,QAAO;AAET,SAAO,MAAM,WAAkB,KAAK;;AAEtC,KAAI,cAAc,OAChB,QAAO,QAAQ,QAAW,KAAK;AAEjC,KAAI;EAAC;EAAQ;EAAQ;EAAM;EAAQ,CAAC,SAAS,UAAiB,CAC5D,QAAO,UAAU,WAAkB,KAAK;AAE1C,KAAI,aAAa,eAAe,UAC9B,QAAO,MAAM,WAAkB,KAAK;AAGtC,KAAI,MAAM,QAAQ,UAAU,CAC1B,QAAQ,SAAiB,UAAU,IAAW,KAAK;AAGrD,KAAI,OAAO,cAAc,SACvB,QAAO,KAAK,WAAkB,KAAK;AAGrC,OAAM,IAAI,MACR,+CAA+C,KAAK,UAAU,UAAU,GACzE;;AAWH,SAAgB,QAMd,MACA,SAQA;AACA,MAAK,MAAM,OAAO,QAChB,QAAO,eAAe,KAAK,WAAW,KAAK,EACzC,MAAM;AACJ,SAAQ,KAAK,MAAc,KAAK,KAAK,KAAK,MAAM;IAEnD,CAAC;AAEJ,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"microsecond-timestamp.mjs","names":[],"sources":["../../src/addons/microsecond-timestamp.ts"],"sourcesContent":["export class MicrosecondTimestamp {\n static MILLISECOND = new MicrosecondTimestamp(BigInt(1_000));\n static SECOND = this.MILLISECOND.mult(1000);\n static MINUTE = this.SECOND.mult(60);\n static HOUR = this.MINUTE.mult(60);\n static DAY = this.HOUR.mult(24);\n static WEEK = this.DAY.mult(7);\n static MONTH = this.DAY.mult(30);\n\n constructor(readonly micros: bigint) {}\n\n isAfter(other: MicrosecondTimestamp): boolean {\n return this.micros > other.micros;\n }\n\n equals(other: MicrosecondTimestamp): boolean {\n return this.micros === other.micros;\n }\n\n isBefore(other: MicrosecondTimestamp): boolean {\n return this.micros < other.micros;\n }\n\n add(micros: bigint | MicrosecondTimestamp): MicrosecondTimestamp {\n const value =\n micros instanceof MicrosecondTimestamp ? micros.micros : micros;\n return new MicrosecondTimestamp(this.micros + value);\n }\n\n sub(micros: bigint | MicrosecondTimestamp): MicrosecondTimestamp {\n const value =\n micros instanceof MicrosecondTimestamp ? micros.micros : micros;\n return new MicrosecondTimestamp(this.micros - value);\n }\n\n mult(factor: number): MicrosecondTimestamp {\n return new MicrosecondTimestamp(this.micros * BigInt(factor));\n }\n\n static now(): MicrosecondTimestamp {\n return new MicrosecondTimestamp(BigInt(Date.now()) * BigInt(1000));\n }\n\n static fromNanoseconds(nanoseconds: bigint): MicrosecondTimestamp {\n return new MicrosecondTimestamp(nanoseconds / BigInt(1000));\n }\n\n static fromMicroseconds(microseconds: bigint): MicrosecondTimestamp {\n return new MicrosecondTimestamp(microseconds);\n }\n\n static deserialize(\n serialized: Date | MicrosecondTimestamp | bigint,\n ): MicrosecondTimestamp {\n if (serialized instanceof MicrosecondTimestamp) {\n return serialized;\n }\n if (typeof serialized === \"bigint\") {\n return new MicrosecondTimestamp(serialized);\n }\n\n if (\n \"microseconds\" in serialized &&\n typeof serialized.microseconds === \"bigint\"\n ) {\n return new MicrosecondTimestamp(serialized.microseconds);\n }\n\n const micros = BigInt(serialized.getTime()) * BigInt(1000);\n return new MicrosecondTimestamp(micros);\n }\n\n serialize() {\n const date = new Date(Number(this.micros / BigInt(1000)));\n (date as any).microseconds = this.micros;\n return date;\n }\n\n static sort(left: MicrosecondTimestamp, right: MicrosecondTimestamp): number {\n if (left.isAfter(right)) {\n return 1;\n }\n if (left.isBefore(right)) {\n return -1;\n }\n return 0;\n }\n}\n"],"mappings":";AAAA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAO,cAAc,IAAI,qBAAqB,OAAO,IAAM,CAAC;CAC5D,OAAO,SAAS,KAAK,YAAY,KAAK,IAAK;CAC3C,OAAO,SAAS,KAAK,OAAO,KAAK,GAAG;CACpC,OAAO,OAAO,KAAK,OAAO,KAAK,GAAG;CAClC,OAAO,MAAM,KAAK,KAAK,KAAK,GAAG;CAC/B,OAAO,OAAO,KAAK,IAAI,KAAK,EAAE;CAC9B,OAAO,QAAQ,KAAK,IAAI,KAAK,GAAG;CAEhC,YAAY,AAAS,QAAgB;EAAhB;;CAErB,QAAQ,OAAsC;AAC5C,SAAO,KAAK,SAAS,MAAM;;CAG7B,OAAO,OAAsC;AAC3C,SAAO,KAAK,WAAW,MAAM;;CAG/B,SAAS,OAAsC;AAC7C,SAAO,KAAK,SAAS,MAAM;;CAG7B,IAAI,QAA6D;EAC/D,MAAM,QACJ,kBAAkB,uBAAuB,OAAO,SAAS;AAC3D,SAAO,IAAI,qBAAqB,KAAK,SAAS,MAAM;;CAGtD,IAAI,QAA6D;EAC/D,MAAM,QACJ,kBAAkB,uBAAuB,OAAO,SAAS;AAC3D,SAAO,IAAI,qBAAqB,KAAK,SAAS,MAAM;;CAGtD,KAAK,QAAsC;AACzC,SAAO,IAAI,qBAAqB,KAAK,SAAS,OAAO,OAAO,CAAC;;CAG/D,OAAO,MAA4B;AACjC,SAAO,IAAI,qBAAqB,OAAO,KAAK,KAAK,CAAC,GAAG,OAAO,IAAK,CAAC;;CAGpE,OAAO,gBAAgB,aAA2C;AAChE,SAAO,IAAI,qBAAqB,cAAc,OAAO,IAAK,CAAC;;CAG7D,OAAO,iBAAiB,cAA4C;AAClE,SAAO,IAAI,qBAAqB,aAAa;;CAG/C,OAAO,YACL,YACsB;AACtB,MAAI,sBAAsB,qBACxB,QAAO;AAET,MAAI,OAAO,eAAe,SACxB,QAAO,IAAI,qBAAqB,WAAW;AAG7C,MACE,kBAAkB,cAClB,OAAO,WAAW,iBAAiB,SAEnC,QAAO,IAAI,qBAAqB,WAAW,aAAa;AAI1D,SAAO,IAAI,qBADI,OAAO,WAAW,SAAS,CAAC,GAAG,OAAO,IAAK,CACnB;;CAGzC,YAAY;EACV,MAAM,OAAO,IAAI,KAAK,OAAO,KAAK,SAAS,OAAO,IAAK,CAAC,CAAC;AACzD,EAAC,KAAa,eAAe,KAAK;AAClC,SAAO;;CAGT,OAAO,KAAK,MAA4B,OAAqC;AAC3E,MAAI,KAAK,QAAQ,MAAM,CACrB,QAAO;AAET,MAAI,KAAK,SAAS,MAAM,CACtB,QAAO;AAET,SAAO"}
|
package/dist/choice.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"choice.mjs","names":[],"sources":["../src/choice.ts"],"sourcesContent":["import { AbstractConstructor, Empty, Expand, Constructor } from \"./_\";\n\nexport type ChoiceMatcher<S extends string[]> =\n | {\n [key in S[number]]: () => any;\n }\n | ({\n _: () => any;\n } & {\n [key in S[number]]?: () => any;\n });\n\nexport type ChoiceMatcherResult<M extends ChoiceMatcher<any>> =\n M[keyof M] extends () => infer R ? R : never;\n\nexport const Choice = <\n const S extends string[],\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n config: S,\n base: B = Empty as any,\n): IChoice<S, B> => {\n type Inline = S[number];\n\n abstract class $Choice extends (base as any as Constructor<{}>) {\n static $shape = \"choice\" as const;\n\n static $of = config;\n static values = config;\n\n constructor(public value: Expand<Inline>) {\n super();\n }\n\n is<T extends Inline>(\n value: T,\n ): this is Omit<this, \"value\" | \"serialize\"> & {\n value: T;\n serialize(): T;\n } {\n return this.value === value;\n }\n\n match<M extends ChoiceMatcher<S>>(matcher: M): ChoiceMatcherResult<M> {\n const handler = matcher[this.value];\n if (handler) return handler();\n return (matcher as { _: () => any })._();\n }\n\n serialize(): Inline {\n return this.value;\n }\n\n static deserialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): InstanceType<T> {\n return new (this as any)(value as any) as InstanceType<T>;\n }\n static $deserialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): Inline {\n return value;\n }\n static $serialize<T extends typeof $Choice>(\n this: T,\n value: Inline,\n ): Inline {\n return value;\n }\n\n static $inline: Inline;\n\n static {\n for (const choice of config) {\n (this as any)[choice] = function <T extends Constructor>(this: T) {\n return new this(choice as any);\n };\n }\n }\n }\n\n return $Choice as any;\n};\n\nexport type IChoice<\n S extends string[],\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"\"> & {\n $shape: \"choice\";\n $of: S;\n values: S;\n deserialize<T extends Constructor>(\n this: T,\n value: S[number],\n ): InstanceType<T>;\n $deserialize<T>(this: T, value: S[number]): S[number];\n $serialize<T>(this: T, value: S[number]): S[number];\n $inline: S[number];\n} & (abstract new (\n value: S[number],\n ) => InstanceType<B> & {\n value: S[number];\n is<TH, T extends S[number]>(\n this: TH,\n value: T,\n ): this is Omit<TH, \"serialize\" | \"value\"> & {\n value: T;\n serialize(): T;\n };\n match<M extends ChoiceMatcher<S>>(matcher: M): ChoiceMatcherResult<M>;\n serialize(): S[number];\n }) & {\n [K in S[number]]: <T extends Constructor>(this: T) => InstanceType<T>;\n };\n//# sourceMappingURL=choice.d.ts.map\n"],"mappings":";;;AAeA,MAAa,UAIX,QACA,OAAU,UACQ;CAGlB,MAAe,gBAAiB,KAAgC;EAC9D,OAAO,SAAS;EAEhB,OAAO,MAAM;EACb,OAAO,SAAS;EAEhB,YAAY,AAAO,OAAuB;AACxC,UAAO;GADU;;EAInB,GACE,OAIA;AACA,UAAO,KAAK,UAAU;;EAGxB,MAAkC,SAAoC;GACpE,MAAM,UAAU,QAAQ,KAAK;AAC7B,OAAI,QAAS,QAAO,SAAS;AAC7B,UAAQ,QAA6B,GAAG;;EAG1C,YAAoB;AAClB,UAAO,KAAK;;EAGd,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,KAAa,MAAa;;EAExC,OAAO,aAEL,OACQ;AACR,UAAO;;EAET,OAAO,WAEL,OACQ;AACR,UAAO;;EAGT,OAAO;EAEP;AACE,QAAK,MAAM,UAAU,OACnB,CAAC,KAAa,UAAU,WAA0C;AAChE,WAAO,IAAI,KAAK,OAAc;;;;AAMtC,QAAO"}
|
package/dist/class.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"class.mjs","names":[],"sources":["../src/class.ts"],"sourcesContent":["import { AbstractConstructor, Empty, Constructor, Expand } from \"./_\";\n\nexport type ClassShorthand = Constructor<{ serialize(): any }> & {\n deserialize(value: any): any;\n};\n\nexport const Class = <\n S extends Constructor<{ serialize(): any }> & {\n deserialize(value: any): any;\n },\n B extends AbstractConstructor<any> = typeof Empty,\n>(\n of: S,\n base = Empty,\n): IClass<S, B> => {\n type Serialized = ReturnType<InstanceType<S>[\"serialize\"]>;\n type Inline = InstanceType<S>;\n\n abstract class $Class extends base {\n static $shape = \"class\" as const;\n static $of = of;\n\n constructor(public value: InstanceType<B>) {\n super();\n }\n\n static deserialize<T extends Constructor<any>>(\n this: T,\n value: Expand<Parameters<S[\"deserialize\"]>[0]>,\n ): InstanceType<T> {\n return new this(of.deserialize(value)) as InstanceType<T>;\n }\n\n serialize<T extends $Class>(this: T): Expand<Serialized> {\n return this.value.serialize();\n }\n\n static $deserialize(value: Parameters<S[\"deserialize\"]>[0]): Inline {\n return of.deserialize(value);\n }\n\n static $serialize<T extends typeof $Class>(\n this: T,\n value: Inline,\n ): Serialized {\n return value.serialize();\n }\n\n static $inline: Inline;\n }\n\n return $Class as any;\n};\n\nexport type IClass<\n S extends ClassShorthand,\n B extends AbstractConstructor<any> = typeof Empty,\n> = (abstract new (\n value: InstanceType<B>,\n) => {\n value: InstanceType<B>;\n serialize<T>(this: T): Expand<ReturnType<InstanceType<S>[\"serialize\"]>>;\n}) & {\n $shape: \"class\";\n $of: S;\n deserialize<T extends Constructor<any>>(\n this: T,\n value: Expand<Parameters<S[\"deserialize\"]>[0]>,\n ): InstanceType<T>;\n $deserialize(value: Parameters<S[\"deserialize\"]>[0]): InstanceType<S>;\n $serialize<T>(\n this: T,\n value: InstanceType<S>,\n ): ReturnType<InstanceType<S>[\"serialize\"]>;\n $inline: InstanceType<S>;\n};\n"],"mappings":";;;AAMA,MAAa,SAMX,IACA,OAAO,UACU;CAIjB,MAAe,eAAe,KAAK;EACjC,OAAO,SAAS;EAChB,OAAO,MAAM;EAEb,YAAY,AAAO,OAAwB;AACzC,UAAO;GADU;;EAInB,OAAO,YAEL,OACiB;AACjB,UAAO,IAAI,KAAK,GAAG,YAAY,MAAM,CAAC;;EAGxC,YAAyD;AACvD,UAAO,KAAK,MAAM,WAAW;;EAG/B,OAAO,aAAa,OAAgD;AAClE,UAAO,GAAG,YAAY,MAAM;;EAG9B,OAAO,WAEL,OACY;AACZ,UAAO,MAAM,WAAW;;EAG1B,OAAO;;AAGT,QAAO"}
|
package/dist/dict.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dict.mjs","names":[],"sources":["../src/dict.ts"],"sourcesContent":["import {\n DefinitionOf,\n Shorthand,\n Shape,\n Expand,\n AbstractConstructor,\n Constructor,\n Empty,\n} from \"./_\";\n\nexport type DictShorthand = { [key: string]: Shorthand };\n\ntype Internal<S extends DictShorthand, B extends AbstractConstructor<{}>> = {\n Definition: { -readonly [K in keyof S]: DefinitionOf<S[K]> };\n Serialized: (B extends { $name: infer U } ? { $name: U } : {}) & {\n -readonly [K in keyof S]: ReturnType<DefinitionOf<S[K]>[\"$serialize\"]>;\n };\n Deserializing: (B extends { $name: infer U } ? { $name: U } : {}) & {\n -readonly [K in keyof S]: Parameters<DefinitionOf<S[K]>[\"$deserialize\"]>[0];\n };\n Inline: {\n -readonly [K in keyof S]: DefinitionOf<S[K]>[\"$inline\"];\n };\n};\n\nexport const Dict = <\n const S extends { [key: string]: any },\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n): IDict<S, B> => {\n abstract class $Dict extends (base as any as AbstractConstructor<{}>) {\n static $shape = \"dict\" as const;\n static $of = of;\n\n constructor(...args: any[]) {\n super();\n Object.assign(this, args[0]);\n }\n\n serialize() {\n return $Dict.$serialize(this as any) as any;\n }\n\n static deserialize<T extends Constructor>(\n this: T,\n value: any,\n ): InstanceType<T> {\n const runtime = (this as any).$deserialize(value as any);\n return new this(runtime as any) as any;\n }\n\n static $deserialize<T extends typeof $Dict>(this: T, value: any): any {\n const split = Object.entries(of);\n const transform = split.map(([key, child]) => {\n const longhand = Shape(child) as any;\n const deserialized = longhand.$deserialize((value as any)[key]);\n return [key, deserialized];\n });\n const merge = Object.fromEntries(transform);\n return merge;\n }\n\n static $serialize<T extends typeof $Dict>(\n this: T,\n value: InstanceType<T>,\n ): any {\n const split = Object.entries(of);\n const transform = split.map(([key, child]) => {\n const longhand = Shape(child as any) as any;\n const serialized = longhand.$serialize((value as any)[key]);\n return [key, serialized];\n });\n const merge = Object.fromEntries(transform);\n\n if (\"$name\" in base) {\n return { ...merge, $name: base.$name } as any;\n }\n\n return merge as any;\n }\n }\n\n return $Dict as any;\n};\n\nexport type IDict<\n S extends {\n [key: string]: any;\n },\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"\"> & {\n $shape: \"dict\";\n $of: S;\n deserialize<T extends Constructor>(\n this: T,\n value: Expand<Internal<S, B>[\"Serialized\"]>,\n ): InstanceType<T>;\n $deserialize<T>(\n this: T,\n value: Internal<S, B>[\"Deserializing\"],\n ): Internal<S, B>[\"Inline\"];\n $serialize<T extends Constructor>(\n this: T,\n value: InstanceType<T>,\n ): Internal<S, B>[\"Serialized\"];\n $inline: Internal<S, B>[\"Inline\"];\n} & (abstract new (\n value: Expand<Internal<S, B>[\"Inline\"]>,\n ) => InstanceType<B> & {\n serialize(): Expand<Internal<S, B>[\"Serialized\"]>;\n } & Internal<S, B>[\"Inline\"]);\n"],"mappings":";;;AAyBA,MAAa,QAIX,IACA,OAAU,UACM;CAChB,MAAe,cAAe,KAAwC;EACpE,OAAO,SAAS;EAChB,OAAO,MAAM;EAEb,YAAY,GAAG,MAAa;AAC1B,UAAO;AACP,UAAO,OAAO,MAAM,KAAK,GAAG;;EAG9B,YAAY;AACV,UAAO,MAAM,WAAW,KAAY;;EAGtC,OAAO,YAEL,OACiB;GACjB,MAAM,UAAW,KAAa,aAAa,MAAa;AACxD,UAAO,IAAI,KAAK,QAAe;;EAGjC,OAAO,aAA8C,OAAiB;GAEpE,MAAM,YADQ,OAAO,QAAQ,GAAG,CACR,KAAK,CAAC,KAAK,WAAW;AAG5C,WAAO,CAAC,KAFS,MAAM,MAAM,CACC,aAAc,MAAc,KAAK,CACrC;KAC1B;AAEF,UADc,OAAO,YAAY,UAAU;;EAI7C,OAAO,WAEL,OACK;GAEL,MAAM,YADQ,OAAO,QAAQ,GAAG,CACR,KAAK,CAAC,KAAK,WAAW;AAG5C,WAAO,CAAC,KAFS,MAAM,MAAa,CACR,WAAY,MAAc,KAAK,CACnC;KACxB;GACF,MAAM,QAAQ,OAAO,YAAY,UAAU;AAE3C,OAAI,WAAW,KACb,QAAO;IAAE,GAAG;IAAO,OAAO,KAAK;IAAO;AAGxC,UAAO;;;AAIX,QAAO"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"discriminated-union.mjs","names":[],"sources":["../src/discriminated-union.ts"],"sourcesContent":["import {\n Constructor,\n Expand,\n DefinitionOf,\n AbstractConstructor,\n Empty,\n type Shorthand,\n Shape,\n type Definition,\n} from \"./_\";\nimport { ClassShorthand } from \"./class\";\nimport { type DictShorthand } from \"./dict\";\n\ntype UnionToIntersection<U> = (\n U extends unknown\n ? (k: U) => void\n : never\n) extends (k: infer I) => void\n ? I\n : never;\ntype PopUnion<U> = UnionToOvlds<U> extends (a: infer A) => void ? A : never;\n\ntype UnionToArray<T, A extends unknown[] = []> = IsUnion<T> extends true\n ? UnionToArray<Exclude<T, PopUnion<T>>, [PopUnion<T>, ...A]>\n : [T, ...A];\ntype IsUnion<T> = [T] extends [UnionToIntersection<T>] ? false : true;\n\ntype CountUnion<T> = UnionToArray<T> extends infer U extends any[]\n ? U[\"length\"]\n : never;\n\ntype UnshiftUnion<U> = UnionToArray<U> extends [infer F, ...any[]] ? F : never;\n\ntype UnionToOvlds<U> = UnionToIntersection<\n U extends any ? (f: U) => void : never\n>;\n\ntype IsStringLiteral<T> = T extends string\n ? string extends T\n ? false\n : true\n : false;\n\ntype FindBestKeyForMatching<FromUnion> = UnshiftUnion<\n keyof FromUnion extends infer K\n ? K extends keyof FromUnion\n ? CountUnion<Pick<FromUnion, K>[K]> extends CountUnion<FromUnion>\n ? [IsStringLiteral<FromUnion[K]>] extends [true]\n ? K\n : never\n : never\n : never\n : never\n>;\n\ntype MatcherConfig = { [key: string]: any };\n\ntype ExhaustiveMatcher<C> = C extends MatcherConfig\n ? {\n [key in keyof C]: (value: Expand<DefinitionOf<C[key]>[\"$inline\"]>) => any;\n }\n : never;\n\ntype UnsafeFallthroughMatcher<C> = C extends MatcherConfig\n ? {\n [key in keyof C]?: (\n value: Expand<DefinitionOf<C[key]>[\"$inline\"]>,\n ) => any;\n } & {\n _: (value: Expand<DefinitionOf<C[keyof C]>[\"$inline\"]>) => any;\n }\n : never;\n\ntype PartialMatcher<C> = C extends MatcherConfig\n ? {\n [key in keyof C]?: (\n value: Expand<DefinitionOf<C[key]>[\"$inline\"]>,\n ) => any;\n }\n : never;\n\ntype Matcher<C> = C extends MatcherConfig\n ? ExhaustiveMatcher<C> | UnsafeFallthroughMatcher<C> | PartialMatcher<C>\n : never;\n\ntype Config = DictShorthandInput | ClassInput | ClassDictInput | DictInput;\n\ntype ClassInput = ClassShorthand;\n\ntype ClassDictInput = ClassShorthand & { $of: {} };\n\ntype DictInput = { $of: {} };\n\ntype DictShorthandInput = DictShorthand;\n\ntype Access<T, K> = K extends keyof T ? T[K] : never;\n\ntype Entries<T extends readonly any[], K> = UnionToIntersection<\n {\n [i in keyof T]: Access<GetShape<T[i]>, K> extends infer U extends string\n ? IsStringLiteral<U> extends true\n ? {\n [key in U]: T[i] extends DictShorthandInput\n ? DefinitionOf<T[i]>\n : T[i];\n }\n : never\n : never;\n }[number]\n>;\n\ntype GetShape<S extends Config> = S extends DictInput\n ? S[\"$of\"]\n : S extends ClassInput\n ? Access<S, \"prototype\">\n : S;\n\nexport type BestKey<S extends readonly Config[]> = {\n [key in keyof S]: GetShape<S[key]>;\n}[number] extends infer U\n ? FindBestKeyForMatching<U>\n : never;\n\nexport type DiscriminatedUnionConfiguration = readonly Config[];\n\nexport function findBestKey(config: DiscriminatedUnionConfiguration) {\n const hash: Record<string, Set<string>> = {};\n\n for (const c of config) {\n const shape = \"$of\" in c ? c.$of : c;\n for (const key in shape) {\n const k = key as keyof typeof shape;\n if (hash[key]) {\n hash[key].add(shape[k]);\n } else {\n hash[key] = new Set([shape[k]]);\n }\n }\n }\n\n const key = Object.entries(hash)\n .map(([key, value]) => [key, value.size] as const)\n .filter(([_, value]) => value === config.length)\n .sort((a, b) => b[1] - a[1])?.[0]?.[0];\n\n if (!key) {\n throw new Error(\"Could not find key for DiscriminatedUnion\");\n }\n\n return key;\n}\n\nexport function prepareShapeMap(\n config: DiscriminatedUnionConfiguration,\n key: string,\n) {\n return config.reduce<{ [key: string]: Definition }>((acc, c) => {\n const shape = Shape(c);\n\n // Here, we are handling the two cases of the configuration:\n // - the first one is when the configuration is a Definition directly.\n // we can access the discriminator directly from the shape $of property\n // - the second one is when the configuration is a DictShorthand or a plain Class.\n // we first have to turn it into a Definition before accessing the discriminator\n // Dict $of property references the configuration provided, which allows us to capture the discriminator\n // Class $of property references the constructor of the class, which allows us to capture the discriminator\n // which is mandatorily defined on the static side of the class\n const discriminator =\n key in c\n ? (c as any)[key]\n : \"$of\" in c\n ? (c as any).$of[key]\n : (shape as any).$of[key];\n\n acc[discriminator] = shape;\n return acc;\n }, {});\n}\n\ntype Internal<\n S extends DiscriminatedUnionConfiguration,\n K extends BestKey<S>,\n> = {\n Map: Entries<S, K>;\n Serialized: ReturnType<DefinitionOf<S[number]>[\"$serialize\"]>;\n Inline: DefinitionOf<S[number]>[\"$inline\"];\n};\n\nexport const DiscriminatedUnion = <\n S extends DiscriminatedUnionConfiguration,\n K extends BestKey<S>,\n const B extends AbstractConstructor = typeof Empty,\n>(\n of: S,\n ...args: [base?: B]\n): IDiscriminatedUnion<S, K, B> => {\n const base = args[0] || (Empty as any);\n\n const key = findBestKey(of);\n const map = prepareShapeMap(of, key);\n\n abstract class $DiscriminatedUnion extends (base as any as Constructor<{}>) {\n constructor(public value: any) {\n super();\n }\n\n static $of = of;\n static $shape = \"discriminated-union\" as const;\n\n serialize() {\n return $DiscriminatedUnion.$serialize(this.value);\n }\n\n match(matcher: any, fallback: any) {\n const element: any = this.value;\n const discriminant = element[key];\n\n const handler = matcher[discriminant];\n if (handler) {\n return handler(element);\n }\n if (fallback) {\n return fallback(element);\n }\n if (matcher._) {\n return matcher._(element);\n }\n throw new Error(\"Non-exhaustive match\");\n }\n\n static deserialize(value: any) {\n return new (this as any)(this.$deserialize(value as any)) as any;\n }\n\n static $deserialize(value: any) {\n const definition = map[value[key]];\n if (!definition) {\n throw new Error(\"Cannot deserialize DiscriminatedUnion\");\n }\n return (definition as any).$deserialize(value);\n }\n\n static $serialize(value: any): any {\n return map[(value as any)[key]].$serialize(value);\n }\n }\n\n return $DiscriminatedUnion as any;\n};\n\nexport type IDiscriminatedUnion<\n S extends DiscriminatedUnionConfiguration,\n K extends BestKey<S>,\n B extends AbstractConstructor = typeof Empty,\n> = Omit<B, \"prototype\"> & {\n $shape: \"discriminated-union\";\n $of: S;\n serialized: Internal<S, K>[\"Serialized\"];\n deserialize<T>(\n this: T,\n value: Expand<Internal<S, K>[\"Serialized\"]>,\n ): T extends AbstractConstructor ? InstanceType<T> : any;\n $deserialize<T>(\n this: T,\n value: Internal<S, K>[\"Serialized\"],\n ): Internal<S, K>[\"Inline\"];\n $serialize<T extends AbstractConstructor>(\n this: T,\n value: InstanceType<T>,\n ): Internal<S, K>[\"Serialized\"];\n $inline: Internal<S, K>[\"Inline\"];\n} & (abstract new (\n value: Internal<S, K>[\"Inline\"],\n ) => InstanceType<B> & {\n value: Internal<S, K>[\"Inline\"];\n serialize(): Internal<S, K>[\"Serialized\"];\n match<\n M extends Matcher<Internal<S, K>[\"Map\"]>,\n F extends M extends ExhaustiveMatcher<Internal<S, K>[\"Map\"]>\n ? []\n : M extends UnsafeFallthroughMatcher<Internal<S, K>[\"Map\"]>\n ? []\n : M extends PartialMatcher<Internal<S, K>[\"Map\"]>\n ? [\n fallback: (\n value: Omit<Internal<S, K>[\"Map\"], keyof M>[keyof Omit<\n Internal<S, K>[\"Map\"],\n keyof M\n >] extends infer U extends Shorthand\n ? Expand<DefinitionOf<U>[\"$inline\"]>\n : never,\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"],"m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SACF,QAAO,SAAS,QAAQ;AAE1B,OAAI,QAAQ,EACV,QAAO,QAAQ,EAAE,QAAQ;AAE3B,SAAM,IAAI,MAAM,uBAAuB;;EAGzC,OAAO,YAAY,OAAY;AAC7B,UAAO,IAAK,KAAa,KAAK,aAAa,MAAa,CAAC;;EAG3D,OAAO,aAAa,OAAY;GAC9B,MAAM,aAAa,IAAI,MAAM;AAC7B,OAAI,CAAC,WACH,OAAM,IAAI,MAAM,wCAAwC;AAE1D,UAAQ,WAAmB,aAAa,MAAM;;EAGhD,OAAO,WAAW,OAAiB;AACjC,UAAO,IAAK,MAAc,MAAM,WAAW,MAAM;;;AAIrD,QAAO"}
|
package/dist/either.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"either.mjs","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>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;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/literal.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"literal.mjs","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"}
|
package/dist/mapping.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mapping.mjs","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"}
|
package/dist/multiple.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multiple.mjs","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>(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MAAM,MAAM,KAAK,KAAK,MAAM;;EAG1C,IAAI,UAAU;AACZ,UAAO,KAAK,MAAM,QAAQ,KAAK,KAAK,MAAM;;;AAI9C,QAAO"}
|
package/dist/nothing.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nothing.mjs","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"}
|
package/dist/optional.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"optional.mjs","names":[],"sources":["../src/optional.ts"],"sourcesContent":["import {\n type Definition,\n type Expand,\n type Shorthand,\n type DefinitionOf,\n Shape,\n type Constructor,\n type AbstractConstructor,\n Empty,\n} from \"./_\";\n\nexport type OptionalConfiguration = Definition | Shorthand;\n\ntype Matcher<V> = { some: (value: V) => any; none: () => any };\n\ntype Internal<S extends Definition | Shorthand> = {\n Serialized: ReturnType<DefinitionOf<S>[\"$serialize\"]> | undefined;\n Deserializing: Parameters<DefinitionOf<S>[\"$deserialize\"]>[0] | undefined;\n Inline: Expand<DefinitionOf<S>[\"$inline\"]> | undefined;\n Required: Expand<DefinitionOf<S>[\"$inline\"]>;\n};\n\nexport const Optional = <\n S extends Definition | Shorthand,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n): IOptional<S, B> => {\n abstract class $Optional extends (base as any as Constructor<{}>) {\n constructor(public value: any) {\n super();\n }\n\n static $shape = \"optional\" as const;\n\n serialize() {\n return $Optional.$serialize((this as any).value) as any;\n }\n\n match(config: any) {\n if ((this as any).value === undefined) {\n return config.none();\n }\n return config.some((this as any).value);\n }\n\n static deserialize<T extends Constructor>(\n this: T,\n value: any,\n ): InstanceType<T> {\n return new (this as any)((this as any).$deserialize(value)) as any;\n }\n\n static $deserialize(value: any): any {\n if (value === undefined) {\n return undefined;\n }\n return (Shape(of) as any).$deserialize(value);\n }\n\n static $serialize<T extends typeof $Optional>(this: T, value: any): any {\n return value === undefined\n ? undefined\n : (Shape(of) as any).$serialize(value);\n }\n\n static $inline: any;\n }\n\n return $Optional as any;\n};\n\nexport type IOptional<\n S extends Definition | Shorthand,\n B extends AbstractConstructor<{}> = typeof Object,\n> = Omit<B, \"prototype\"> & {\n $shape: \"optional\";\n deserialize<T extends Constructor>(\n this: T,\n value: Internal<S>[\"Deserializing\"],\n ): InstanceType<T>;\n $deserialize(value: Internal<S>[\"Deserializing\"]): Definition[\"$inline\"];\n $serialize<T>(\n this: T,\n value: Internal<S>[\"Inline\"],\n ): Internal<S>[\"Serialized\"];\n $inline: Internal<S>[\"Inline\"];\n} & (abstract new (\n value: Internal<S>[\"Inline\"],\n ) => InstanceType<B> & {\n value: Internal<S>[\"Inline\"];\n serialize(): Expand<Internal<S>[\"Serialized\"]>;\n match<M extends Matcher<Expand<Internal<S>[\"Required\"]>>>(\n config: M,\n ): ReturnType<M[\"some\"]> | ReturnType<M[\"none\"]>;\n });\n"],"mappings":";;;AAsBA,MAAa,YAIX,IACA,OAAU,UACU;CACpB,MAAe,kBAAmB,KAAgC;EAChE,YAAY,AAAO,OAAY;AAC7B,UAAO;GADU;;EAInB,OAAO,SAAS;EAEhB,YAAY;AACV,UAAO,UAAU,WAAY,KAAa,MAAM;;EAGlD,MAAM,QAAa;AACjB,OAAK,KAAa,UAAU,OAC1B,QAAO,OAAO,MAAM;AAEtB,UAAO,OAAO,KAAM,KAAa,MAAM;;EAGzC,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,KAAc,KAAa,aAAa,MAAM,CAAC;;EAG7D,OAAO,aAAa,OAAiB;AACnC,OAAI,UAAU,OACZ;AAEF,UAAQ,MAAM,GAAG,CAAS,aAAa,MAAM;;EAG/C,OAAO,WAAgD,OAAiB;AACtE,UAAO,UAAU,SACb,SACC,MAAM,GAAG,CAAS,WAAW,MAAM;;EAG1C,OAAO;;AAGT,QAAO"}
|
package/dist/primitive.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"primitive.mjs","names":[],"sources":["../src/primitive.ts"],"sourcesContent":["import { AbstractConstructor, Concrete, Constructor, Empty, Expand } from \"./_\";\n\ntype PrimitiveMap = [\n [StringConstructor, string],\n [NumberConstructor, number],\n [DateConstructor, Date],\n [BooleanConstructor, boolean],\n];\n\ntype PrimitiveConstructor = PrimitiveMap[number][0];\nexport type PrimitiveFromConstructor<S> = Extract<\n PrimitiveMap[number],\n [S, any]\n>[1];\n\nexport type PrimitiveShorthand = PrimitiveConstructor;\n\nexport type IPrimitive<\n S extends PrimitiveConstructor,\n B extends AbstractConstructor<{}> = typeof Empty,\n> = Omit<B, \"\"> &\n (abstract new (\n value: Expand<PrimitiveFromConstructor<S>>,\n ) => InstanceType<B> & {\n readonly value: Expand<PrimitiveFromConstructor<S>>;\n serialize(): PrimitiveFromConstructor<S>;\n }) & {\n $shape: \"primitive\";\n deserialize<T extends Constructor<any>>(\n this: T,\n value: PrimitiveFromConstructor<S>,\n ): InstanceType<T>;\n $serialize(value: PrimitiveFromConstructor<S>): PrimitiveFromConstructor<S>;\n $deserialize(\n value: PrimitiveFromConstructor<S>,\n ): PrimitiveFromConstructor<S>;\n $inline: Expand<PrimitiveFromConstructor<S>>;\n };\n\nexport const Primitive = <\n S extends PrimitiveConstructor,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n): IPrimitive<S, B> => {\n type Inline = PrimitiveFromConstructor<S>;\n\n abstract class $Primitive extends (base as any as Constructor<{}>) {\n constructor(public readonly value: Expand<Inline>) {\n super();\n }\n\n static $shape = \"primitive\" as const;\n\n serialize(): Inline {\n return this.value;\n }\n\n static deserialize<T extends typeof $Primitive>(\n this: T,\n value: Inline,\n ): InstanceType<T> {\n return new (this as any)(this.$deserialize(value)) as InstanceType<T>;\n }\n\n static $serialize(value: Inline): Inline {\n return value;\n }\n\n static $deserialize(value: Inline): Inline {\n if (of === Date && typeof value === \"string\") {\n return new Date(value);\n }\n return value;\n }\n\n static $inline: Expand<Inline>;\n }\n\n type PrimitiveConstructor = abstract new (\n value: Expand<Inline>,\n ) => InstanceType<B> & $Primitive;\n\n type Primitive = Omit<B, \"prototype\"> &\n Omit<typeof $Primitive, \"prototype\"> &\n PrimitiveConstructor;\n\n return $Primitive as any;\n};\n"],"mappings":";;;AAuCA,MAAa,aAIX,IACA,OAAU,UACW;CAGrB,MAAe,mBAAoB,KAAgC;EACjE,YAAY,AAAgB,OAAuB;AACjD,UAAO;GADmB;;EAI5B,OAAO,SAAS;EAEhB,YAAoB;AAClB,UAAO,KAAK;;EAGd,OAAO,YAEL,OACiB;AACjB,UAAO,IAAK,KAAa,KAAK,aAAa,MAAM,CAAC;;EAGpD,OAAO,WAAW,OAAuB;AACvC,UAAO;;EAGT,OAAO,aAAa,OAAuB;AACzC,OAAI,OAAO,QAAQ,OAAO,UAAU,SAClC,QAAO,IAAI,KAAK,MAAM;AAExB,UAAO;;EAGT,OAAO;;AAWT,QAAO"}
|