@ddd-ts/shape 0.0.0-test-concurrency.5 → 0.0.0-ts-6-compat.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_.d.ts +7 -7
  3. package/dist/_.d.ts.map +1 -1
  4. package/dist/_.js +34 -51
  5. package/dist/_.mjs +36 -0
  6. package/dist/addons/microsecond-timestamp.d.ts +24 -0
  7. package/dist/addons/microsecond-timestamp.d.ts.map +1 -0
  8. package/dist/addons/microsecond-timestamp.js +62 -0
  9. package/dist/addons/microsecond-timestamp.mjs +61 -0
  10. package/dist/choice.d.ts +13 -26
  11. package/dist/choice.d.ts.map +1 -1
  12. package/dist/choice.js +43 -47
  13. package/dist/choice.mjs +44 -0
  14. package/dist/class.d.ts +8 -7
  15. package/dist/class.d.ts.map +1 -1
  16. package/dist/class.js +29 -30
  17. package/dist/class.mjs +30 -0
  18. package/dist/deserialization-error.d.ts +32 -0
  19. package/dist/deserialization-error.d.ts.map +1 -0
  20. package/dist/deserialization-error.js +45 -0
  21. package/dist/deserialization-error.mjs +44 -0
  22. package/dist/dict.d.ts +25 -13
  23. package/dist/dict.d.ts.map +1 -1
  24. package/dist/dict.js +46 -44
  25. package/dist/dict.mjs +47 -0
  26. package/dist/discriminated-union.d.ts +16 -17
  27. package/dist/discriminated-union.d.ts.map +1 -1
  28. package/dist/discriminated-union.js +61 -92
  29. package/dist/discriminated-union.mjs +66 -0
  30. package/dist/either.d.ts +56 -12
  31. package/dist/either.d.ts.map +1 -1
  32. package/dist/either.js +50 -61
  33. package/dist/either.mjs +51 -0
  34. package/dist/index.d.ts +2 -0
  35. package/dist/index.d.ts.map +1 -1
  36. package/dist/index.js +34 -29
  37. package/dist/index.mjs +16 -0
  38. package/dist/literal.d.ts +5 -7
  39. package/dist/literal.d.ts.map +1 -1
  40. package/dist/literal.js +26 -26
  41. package/dist/literal.mjs +27 -0
  42. package/dist/mapping.d.ts +16 -12
  43. package/dist/mapping.d.ts.map +1 -1
  44. package/dist/mapping.js +37 -49
  45. package/dist/mapping.mjs +38 -0
  46. package/dist/multiple.d.ts +10 -100
  47. package/dist/multiple.d.ts.map +1 -1
  48. package/dist/multiple.js +126 -105
  49. package/dist/multiple.mjs +127 -0
  50. package/dist/nothing.d.ts +2 -2
  51. package/dist/nothing.d.ts.map +1 -1
  52. package/dist/nothing.js +18 -18
  53. package/dist/nothing.mjs +19 -0
  54. package/dist/optional.d.ts +12 -14
  55. package/dist/optional.d.ts.map +1 -1
  56. package/dist/optional.js +33 -40
  57. package/dist/optional.mjs +34 -0
  58. package/dist/primitive.d.ts +5 -7
  59. package/dist/primitive.d.ts.map +1 -1
  60. package/dist/primitive.js +29 -29
  61. package/dist/primitive.mjs +30 -0
  62. package/package.json +24 -9
  63. package/dist/_.js.map +0 -1
  64. package/dist/choice.js.map +0 -1
  65. package/dist/choice.spec.d.ts +0 -2
  66. package/dist/choice.spec.d.ts.map +0 -1
  67. package/dist/choice.spec.js +0 -147
  68. package/dist/choice.spec.js.map +0 -1
  69. package/dist/class.js.map +0 -1
  70. package/dist/class.spec.d.ts +0 -2
  71. package/dist/class.spec.d.ts.map +0 -1
  72. package/dist/class.spec.js +0 -39
  73. package/dist/class.spec.js.map +0 -1
  74. package/dist/dict.js.map +0 -1
  75. package/dist/dict.spec.d.ts +0 -2
  76. package/dist/dict.spec.d.ts.map +0 -1
  77. package/dist/dict.spec.js +0 -180
  78. package/dist/dict.spec.js.map +0 -1
  79. package/dist/discriminated-union.js.map +0 -1
  80. package/dist/discriminated-union.spec.d.ts +0 -2
  81. package/dist/discriminated-union.spec.d.ts.map +0 -1
  82. package/dist/discriminated-union.spec.js +0 -262
  83. package/dist/discriminated-union.spec.js.map +0 -1
  84. package/dist/either.js.map +0 -1
  85. package/dist/either.spec.d.ts +0 -2
  86. package/dist/either.spec.d.ts.map +0 -1
  87. package/dist/either.spec.js +0 -211
  88. package/dist/either.spec.js.map +0 -1
  89. package/dist/index.js.map +0 -1
  90. package/dist/literal.js.map +0 -1
  91. package/dist/literal.spec.d.ts +0 -2
  92. package/dist/literal.spec.d.ts.map +0 -1
  93. package/dist/literal.spec.js +0 -162
  94. package/dist/literal.spec.js.map +0 -1
  95. package/dist/mapping.js.map +0 -1
  96. package/dist/mapping.spec.d.ts +0 -2
  97. package/dist/mapping.spec.d.ts.map +0 -1
  98. package/dist/mapping.spec.js +0 -207
  99. package/dist/mapping.spec.js.map +0 -1
  100. package/dist/multiple.js.map +0 -1
  101. package/dist/multiple.spec.d.ts +0 -2
  102. package/dist/multiple.spec.d.ts.map +0 -1
  103. package/dist/multiple.spec.js +0 -207
  104. package/dist/multiple.spec.js.map +0 -1
  105. package/dist/nothing.js.map +0 -1
  106. package/dist/nothing.spec.d.ts +0 -2
  107. package/dist/nothing.spec.d.ts.map +0 -1
  108. package/dist/nothing.spec.js +0 -172
  109. package/dist/nothing.spec.js.map +0 -1
  110. package/dist/optional.js.map +0 -1
  111. package/dist/optional.spec.d.ts +0 -2
  112. package/dist/optional.spec.d.ts.map +0 -1
  113. package/dist/optional.spec.js +0 -172
  114. package/dist/optional.spec.js.map +0 -1
  115. package/dist/primitive.js.map +0 -1
  116. package/dist/primitive.spec.d.ts +0 -2
  117. package/dist/primitive.spec.d.ts.map +0 -1
  118. package/dist/primitive.spec.js +0 -162
  119. package/dist/primitive.spec.js.map +0 -1
  120. package/dist/test.d.ts +0 -36
  121. package/dist/test.d.ts.map +0 -1
  122. package/dist/test.js +0 -45
  123. package/dist/test.js.map +0 -1
@@ -1,99 +1,68 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DiscriminatedUnion = void 0;
4
- exports.findBestKey = findBestKey;
5
- exports.prepareShapeMap = prepareShapeMap;
6
- const _1 = require("./_");
1
+ const require__ = require('./_.js');
2
+
3
+ //#region src/discriminated-union.ts
7
4
  function findBestKey(config) {
8
- const hash = {};
9
- for (const c of config) {
10
- const shape = "$of" in c ? c.$of : c;
11
- for (const key in shape) {
12
- const k = key;
13
- if (hash[key]) {
14
- hash[key].add(shape[k]);
15
- }
16
- else {
17
- hash[key] = new Set([shape[k]]);
18
- }
19
- }
20
- }
21
- const key = Object.entries(hash)
22
- .map(([key, value]) => [key, value.size])
23
- .filter(([_, value]) => value === config.length)
24
- .sort((a, b) => b[1] - a[1])?.[0]?.[0];
25
- if (!key) {
26
- throw new Error("Could not find key for DiscriminatedUnion");
27
- }
28
- return key;
5
+ const hash = {};
6
+ for (const c of config) {
7
+ const shape = "$of" in c ? c.$of : c;
8
+ for (const key in shape) {
9
+ const k = key;
10
+ if (hash[key]) hash[key].add(shape[k]);
11
+ else hash[key] = new Set([shape[k]]);
12
+ }
13
+ }
14
+ const key = Object.entries(hash).map(([key, value]) => [key, value.size]).filter(([_, value]) => value === config.length).sort((a, b) => b[1] - a[1])?.[0]?.[0];
15
+ if (!key) throw new Error("Could not find key for DiscriminatedUnion");
16
+ return key;
29
17
  }
30
18
  function prepareShapeMap(config, key) {
31
- return config.reduce((acc, c) => {
32
- const shape = (0, _1.Shape)(c);
33
- // Here, we are handling the two cases of the configuration:
34
- // - the first one is when the configuration is a Definition directly.
35
- // we can access the discriminator directly from the shape $of property
36
- // - the second one is when the configuration is a DictShorthand or a plain Class.
37
- // we first have to turn it into a Definition before accessing the discriminator
38
- // Dict $of property references the configuration provided, which allows us to capture the discriminator
39
- // Class $of property references the constructor of the class, which allows us to capture the discriminator
40
- // which is mandatorily defined on the static side of the class
41
- const discriminator = key in c
42
- ? c[key]
43
- : "$of" in c
44
- ? c.$of[key]
45
- : shape.$of[key];
46
- acc[discriminator] = shape;
47
- return acc;
48
- }, {});
19
+ return config.reduce((acc, c) => {
20
+ const shape = require__.Shape(c);
21
+ const discriminator = key in c ? c[key] : "$of" in c ? c.$of[key] : shape.$of[key];
22
+ acc[discriminator] = shape;
23
+ return acc;
24
+ }, {});
49
25
  }
50
26
  const DiscriminatedUnion = (of, ...args) => {
51
- const base = args[0] || _1.Empty;
52
- const key = findBestKey(of);
53
- const map = prepareShapeMap(of, key);
54
- class $DiscriminatedUnion extends base {
55
- value;
56
- constructor(value) {
57
- super();
58
- this.value = value;
59
- }
60
- static serialized;
61
- static $of = of;
62
- static $shape = "discriminated-union";
63
- serialize() {
64
- return $DiscriminatedUnion.$serialize(this.value);
65
- }
66
- match(...[matcher, fallback]) {
67
- const element = this.value;
68
- const discriminant = element[key];
69
- const handler = matcher[discriminant];
70
- if (handler) {
71
- return handler(element);
72
- }
73
- if (fallback) {
74
- return fallback(element);
75
- }
76
- if (matcher._) {
77
- return matcher._(element);
78
- }
79
- throw new Error("Non-exhaustive match");
80
- }
81
- static deserialize(value) {
82
- return new this(this.$deserialize(value));
83
- }
84
- static $deserialize(value) {
85
- const definition = map[value[key]];
86
- if (!definition) {
87
- throw new Error("Cannot deserialize DiscriminatedUnion");
88
- }
89
- return definition.$deserialize(value);
90
- }
91
- static $serialize(value) {
92
- return map[value[key]].$serialize(value);
93
- }
94
- static $inline;
95
- }
96
- return $DiscriminatedUnion;
27
+ const base = args[0] || require__.Empty;
28
+ const key = findBestKey(of);
29
+ const map = prepareShapeMap(of, key);
30
+ class $DiscriminatedUnion extends base {
31
+ constructor(value) {
32
+ super();
33
+ this.value = value;
34
+ }
35
+ static $of = of;
36
+ static $shape = "discriminated-union";
37
+ serialize() {
38
+ return $DiscriminatedUnion.$serialize(this.value);
39
+ }
40
+ match(matcher, fallback) {
41
+ const element = this.value;
42
+ const handler = matcher[element[key]];
43
+ if (handler) return handler(element);
44
+ if (fallback) return fallback(element);
45
+ if (matcher._) return matcher._(element);
46
+ throw new Error("Non-exhaustive match");
47
+ }
48
+ static deserialize(value) {
49
+ return new this(this.$deserialize(value));
50
+ }
51
+ static $deserialize(value) {
52
+ const definition = map[value[key]];
53
+ if (!definition) throw new Error("Cannot deserialize DiscriminatedUnion");
54
+ return definition.$deserialize(value);
55
+ }
56
+ static $serialize(value) {
57
+ const definition = map[value[key]];
58
+ if (!definition) throw new Error("Cannot serialize DiscriminatedUnion");
59
+ return definition.$serialize(value);
60
+ }
61
+ }
62
+ return $DiscriminatedUnion;
97
63
  };
64
+
65
+ //#endregion
98
66
  exports.DiscriminatedUnion = DiscriminatedUnion;
99
- //# sourceMappingURL=discriminated-union.js.map
67
+ exports.findBestKey = findBestKey;
68
+ exports.prepareShapeMap = prepareShapeMap;
@@ -0,0 +1,66 @@
1
+ import { Empty, Shape } from "./_.mjs";
2
+
3
+ //#region src/discriminated-union.ts
4
+ function findBestKey(config) {
5
+ const hash = {};
6
+ for (const c of config) {
7
+ const shape = "$of" in c ? c.$of : c;
8
+ for (const key in shape) {
9
+ const k = key;
10
+ if (hash[key]) hash[key].add(shape[k]);
11
+ else hash[key] = new Set([shape[k]]);
12
+ }
13
+ }
14
+ const key = Object.entries(hash).map(([key, value]) => [key, value.size]).filter(([_, value]) => value === config.length).sort((a, b) => b[1] - a[1])?.[0]?.[0];
15
+ if (!key) throw new Error("Could not find key for DiscriminatedUnion");
16
+ return key;
17
+ }
18
+ function prepareShapeMap(config, key) {
19
+ return config.reduce((acc, c) => {
20
+ const shape = Shape(c);
21
+ const discriminator = key in c ? c[key] : "$of" in c ? c.$of[key] : shape.$of[key];
22
+ acc[discriminator] = shape;
23
+ return acc;
24
+ }, {});
25
+ }
26
+ const DiscriminatedUnion = (of, ...args) => {
27
+ const base = args[0] || Empty;
28
+ const key = findBestKey(of);
29
+ const map = prepareShapeMap(of, key);
30
+ class $DiscriminatedUnion extends base {
31
+ constructor(value) {
32
+ super();
33
+ this.value = value;
34
+ }
35
+ static $of = of;
36
+ static $shape = "discriminated-union";
37
+ serialize() {
38
+ return $DiscriminatedUnion.$serialize(this.value);
39
+ }
40
+ match(matcher, fallback) {
41
+ const element = this.value;
42
+ const handler = matcher[element[key]];
43
+ if (handler) return handler(element);
44
+ if (fallback) return fallback(element);
45
+ if (matcher._) return matcher._(element);
46
+ throw new Error("Non-exhaustive match");
47
+ }
48
+ static deserialize(value) {
49
+ return new this(this.$deserialize(value));
50
+ }
51
+ static $deserialize(value) {
52
+ const definition = map[value[key]];
53
+ if (!definition) throw new Error("Cannot deserialize DiscriminatedUnion");
54
+ return definition.$deserialize(value);
55
+ }
56
+ static $serialize(value) {
57
+ const definition = map[value[key]];
58
+ if (!definition) throw new Error("Cannot serialize DiscriminatedUnion");
59
+ return definition.$serialize(value);
60
+ }
61
+ }
62
+ return $DiscriminatedUnion;
63
+ };
64
+
65
+ //#endregion
66
+ export { DiscriminatedUnion, findBestKey, prepareShapeMap };
package/dist/either.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { Expand, DefinitionOf, AbstractConstructor, Empty } from "./_";
2
- import { ClassShorthand } from "./class";
3
- import { PrimitiveShorthand } from "./primitive";
1
+ import { type Constructor, type Expand, type DefinitionOf, type AbstractConstructor, Empty } from "./_";
2
+ import type { ClassShorthand } from "./class";
4
3
  type Config = {
5
4
  [key: string]: any;
6
5
  };
@@ -17,24 +16,69 @@ type PartialMatcher<C extends Config> = {
17
16
  };
18
17
  type Matcher<C extends Config> = ExhaustiveMatcher<C> | UnsafeFallthroughMatcher<C> | PartialMatcher<C>;
19
18
  export type EitherConfiguration = {
20
- [key: string]: PrimitiveShorthand | ClassShorthand;
19
+ [key: string]: ClassShorthand;
20
+ };
21
+ type Internal<S extends EitherConfiguration, B extends AbstractConstructor<{}>> = {
22
+ Definition: DefinitionOf<S[keyof S]>;
23
+ Serialized: (B extends {
24
+ $name: infer U;
25
+ } ? {
26
+ $name: U;
27
+ } : {}) & {
28
+ _key: keyof S;
29
+ } & ReturnType<DefinitionOf<S[keyof S]>["$serialize"]>;
30
+ Deserializing: (B extends {
31
+ $name: infer U;
32
+ } ? {
33
+ $name: U;
34
+ } : {}) & {
35
+ _key: keyof S;
36
+ } & Parameters<DefinitionOf<S[keyof S]>["$deserialize"]>[0];
37
+ Inline: DefinitionOf<S[keyof S]>["$inline"];
21
38
  };
22
39
  export declare const Either: <const S extends EitherConfiguration, const B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: DefinitionOf<S[keyof S]>["$inline"]) => {
23
40
  value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
24
- serialize(): Expand<{ [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S]>;
25
- 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, ...__0_1: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
41
+ serialize(): Expand<{ [K in keyof S]: {
42
+ _key: K;
43
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>;
44
+ match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
26
45
  }) & {
27
- serialized: { [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S];
46
+ serialized: { [K in keyof S]: {
47
+ _key: K;
48
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S];
28
49
  of: S;
29
50
  $shape: "either";
30
- deserialize<T extends any>(this: T, value: Expand<{ [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S]>): InstanceType<T>;
31
- $deserialize<T_1 extends any>(this: T_1, value: { [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S]): DefinitionOf<S[keyof S]>["$inline"];
32
- $serialize<T_2 extends any>(this: T_2, value: DefinitionOf<S[keyof S]>["$inline"]): { [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S];
51
+ deserialize<T extends /*elided*/ any>(this: T, value: Expand<{ [K in keyof S]: {
52
+ _key: K;
53
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>): InstanceType<T>;
54
+ $deserialize<T extends /*elided*/ any>(this: T, value: { [K in keyof S]: {
55
+ _key: K;
56
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]): DefinitionOf<S[keyof S]>["$inline"];
57
+ $serialize<T extends /*elided*/ any>(this: T, value: DefinitionOf<S[keyof S]>["$inline"]): { [K in keyof S]: {
58
+ _key: K;
59
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S];
33
60
  $inline: DefinitionOf<S[keyof S]>["$inline"];
34
61
  }, "prototype"> & (abstract new (value: Expand<DefinitionOf<S[keyof S]>["$inline"]>) => InstanceType<B> & {
35
62
  value: DefinitionOf<S[keyof S], typeof Empty>["$inline"];
36
- serialize(): Expand<{ [K in keyof S]: [K, ReturnType<DefinitionOf<S[K]>["$serialize"]>]; }[keyof S]>;
37
- 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, ...__0_1: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
63
+ serialize(): Expand<{ [K in keyof S]: {
64
+ _key: K;
65
+ } & ReturnType<DefinitionOf<S[K]>["$serialize"]>; }[keyof S]>;
66
+ match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
38
67
  });
68
+ export type Either<S extends EitherConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<S, B>["Inline"]) => {
69
+ value: Internal<S, B>["Inline"];
70
+ serialize(): Internal<S, B>["Serialized"];
71
+ match<M extends Matcher<S>, F extends M extends ExhaustiveMatcher<S> ? [] : M extends UnsafeFallthroughMatcher<S> ? [] : M extends PartialMatcher<S> ? [
72
+ fallback: (value: InstanceType<Omit<S, keyof M>[keyof Omit<S, keyof M>]>) => any
73
+ ] : []>(matcher: M, ...fallback_n: F): (M[keyof M] extends (...args: any[]) => any ? ReturnType<M[keyof M]> : never) | (F[0] extends (...args: any[]) => any ? ReturnType<F[0]> : never);
74
+ }) & {
75
+ serialized: Internal<S, B>["Serialized"];
76
+ of: S;
77
+ $shape: "either";
78
+ deserialize<T extends Constructor>(this: T, value: Internal<S, B>["Serialized"]): InstanceType<T>;
79
+ $deserialize<T>(this: T, value: Internal<S, B>["Serialized"]): Internal<S, B>["Inline"];
80
+ $serialize<T>(this: T, value: Internal<S, B>["Inline"]): Internal<S, B>["Serialized"];
81
+ $inline: Internal<S, B>["Inline"];
82
+ };
39
83
  export {};
40
84
  //# sourceMappingURL=either.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"either.d.ts","sourceRoot":"","sources":["../src/either.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,YAAY,EAEZ,mBAAmB,EACnB,KAAK,EACN,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEjD,KAAK,M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AC9B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CACnC,CAAC"}
package/dist/either.js CHANGED
@@ -1,62 +1,51 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Either = void 0;
4
- const _1 = require("./_");
5
- const Either = (of, base = _1.Empty) => {
6
- const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
7
- return [key, (0, _1.Shape)(value)];
8
- }));
9
- class $Either extends base {
10
- value;
11
- constructor(value) {
12
- super();
13
- this.value = value;
14
- }
15
- static serialized;
16
- static of = of;
17
- static $shape = "either";
18
- serialize() {
19
- return $Either.$serialize(this.value);
20
- }
21
- match(...[matcher, fallback]) {
22
- const key = Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0];
23
- const handler = matcher[key];
24
- if (handler) {
25
- return handler(this.value);
26
- }
27
- if (fallback) {
28
- return fallback(this.value);
29
- }
30
- if (matcher._) {
31
- return matcher._(this.value);
32
- }
33
- throw new Error("Non-exhaustive match");
34
- }
35
- static deserialize(value) {
36
- return new this(this.$deserialize(value));
37
- }
38
- static $deserialize(value) {
39
- const [key, serialized] = value;
40
- const definition = definitions[key];
41
- if (!definition) {
42
- throw new Error("Cannot deserialize Either");
43
- }
44
- return definition.$deserialize(serialized);
45
- }
46
- static $serialize(value) {
47
- const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
48
- if (!key) {
49
- throw new Error("Cannot serialize Either, no matching key");
50
- }
51
- const definition = definitions[key];
52
- if (!definition) {
53
- throw new Error("Cannot serialize Either");
54
- }
55
- return [key, definition.$serialize(value)];
56
- }
57
- static $inline;
58
- }
59
- return $Either;
1
+ const require__ = require('./_.js');
2
+
3
+ //#region src/either.ts
4
+ const Either = (of, base = require__.Empty) => {
5
+ const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
6
+ return [key, require__.Shape(value)];
7
+ }));
8
+ class $Either extends base {
9
+ constructor(value) {
10
+ super();
11
+ this.value = value;
12
+ }
13
+ static serialized;
14
+ static of = of;
15
+ static $shape = "either";
16
+ serialize() {
17
+ return $Either.$serialize(this.value);
18
+ }
19
+ match(...[matcher, fallback]) {
20
+ const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
21
+ if (handler) return handler(this.value);
22
+ if (fallback) return fallback(this.value);
23
+ if (matcher._) return matcher._(this.value);
24
+ throw new Error("Non-exhaustive match");
25
+ }
26
+ static deserialize(value) {
27
+ return new this(this.$deserialize(value));
28
+ }
29
+ static $deserialize(value) {
30
+ const { _key: key, ...serialized } = value;
31
+ const definition = definitions[key];
32
+ if (!definition) throw new Error("Cannot deserialize Either");
33
+ return definition.$deserialize(serialized);
34
+ }
35
+ static $serialize(value) {
36
+ const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
37
+ if (!key) throw new Error("Cannot serialize Either, no matching key");
38
+ const definition = definitions[key];
39
+ if (!definition) throw new Error("Cannot serialize Either");
40
+ return {
41
+ ...definition.$serialize(value),
42
+ _key: key
43
+ };
44
+ }
45
+ static $inline;
46
+ }
47
+ return $Either;
60
48
  };
61
- exports.Either = Either;
62
- //# sourceMappingURL=either.js.map
49
+
50
+ //#endregion
51
+ exports.Either = Either;
@@ -0,0 +1,51 @@
1
+ import { Empty, Shape } from "./_.mjs";
2
+
3
+ //#region src/either.ts
4
+ const Either = (of, base = Empty) => {
5
+ const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
6
+ return [key, Shape(value)];
7
+ }));
8
+ class $Either extends base {
9
+ constructor(value) {
10
+ super();
11
+ this.value = value;
12
+ }
13
+ static serialized;
14
+ static of = of;
15
+ static $shape = "either";
16
+ serialize() {
17
+ return $Either.$serialize(this.value);
18
+ }
19
+ match(...[matcher, fallback]) {
20
+ const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
21
+ if (handler) return handler(this.value);
22
+ if (fallback) return fallback(this.value);
23
+ if (matcher._) return matcher._(this.value);
24
+ throw new Error("Non-exhaustive match");
25
+ }
26
+ static deserialize(value) {
27
+ return new this(this.$deserialize(value));
28
+ }
29
+ static $deserialize(value) {
30
+ const { _key: key, ...serialized } = value;
31
+ const definition = definitions[key];
32
+ if (!definition) throw new Error("Cannot deserialize Either");
33
+ return definition.$deserialize(serialized);
34
+ }
35
+ static $serialize(value) {
36
+ const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
37
+ if (!key) throw new Error("Cannot serialize Either, no matching key");
38
+ const definition = definitions[key];
39
+ if (!definition) throw new Error("Cannot serialize Either");
40
+ return {
41
+ ...definition.$serialize(value),
42
+ _key: key
43
+ };
44
+ }
45
+ static $inline;
46
+ }
47
+ return $Either;
48
+ };
49
+
50
+ //#endregion
51
+ export { Either };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./_";
2
+ export * from "./deserialization-error";
2
3
  export * from "./choice";
3
4
  export * from "./class";
4
5
  export * from "./dict";
@@ -10,4 +11,5 @@ export * from "./mapping";
10
11
  export * from "./multiple";
11
12
  export * from "./nothing";
12
13
  export * from "./optional";
14
+ export * from "./addons/microsecond-timestamp";
13
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,yBAAyB,CAAC;AACxC,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gCAAgC,CAAC"}
package/dist/index.js CHANGED
@@ -1,29 +1,34 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./_"), exports);
18
- __exportStar(require("./choice"), exports);
19
- __exportStar(require("./class"), exports);
20
- __exportStar(require("./dict"), exports);
21
- __exportStar(require("./either"), exports);
22
- __exportStar(require("./primitive"), exports);
23
- __exportStar(require("./literal"), exports);
24
- __exportStar(require("./discriminated-union"), exports);
25
- __exportStar(require("./mapping"), exports);
26
- __exportStar(require("./multiple"), exports);
27
- __exportStar(require("./nothing"), exports);
28
- __exportStar(require("./optional"), exports);
29
- //# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_class = require('./class.js');
3
+ const require_deserialization_error = require('./deserialization-error.js');
4
+ const require_dict = require('./dict.js');
5
+ const require_primitive = require('./primitive.js');
6
+ const require_multiple = require('./multiple.js');
7
+ const require_nothing = require('./nothing.js');
8
+ const require_literal = require('./literal.js');
9
+ const require__ = require('./_.js');
10
+ const require_choice = require('./choice.js');
11
+ const require_either = require('./either.js');
12
+ const require_discriminated_union = require('./discriminated-union.js');
13
+ const require_mapping = require('./mapping.js');
14
+ const require_optional = require('./optional.js');
15
+ const require_microsecond_timestamp = require('./addons/microsecond-timestamp.js');
16
+
17
+ exports.Choice = require_choice.Choice;
18
+ exports.Class = require_class.Class;
19
+ exports.DeserializationError = require_deserialization_error.DeserializationError;
20
+ exports.Dict = require_dict.Dict;
21
+ exports.DiscriminatedUnion = require_discriminated_union.DiscriminatedUnion;
22
+ exports.Either = require_either.Either;
23
+ exports.Empty = require__.Empty;
24
+ exports.Literal = require_literal.Literal;
25
+ exports.Mapping = require_mapping.Mapping;
26
+ exports.MicrosecondTimestamp = require_microsecond_timestamp.MicrosecondTimestamp;
27
+ exports.Multiple = require_multiple.Multiple;
28
+ exports.Nothing = require_nothing.Nothing;
29
+ exports.Optional = require_optional.Optional;
30
+ exports.Primitive = require_primitive.Primitive;
31
+ exports.Shape = require__.Shape;
32
+ exports.findBestKey = require_discriminated_union.findBestKey;
33
+ exports.forward = require__.forward;
34
+ exports.prepareShapeMap = require_discriminated_union.prepareShapeMap;
package/dist/index.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import { Class } from "./class.mjs";
2
+ import { DeserializationError } from "./deserialization-error.mjs";
3
+ import { Dict } from "./dict.mjs";
4
+ import { Primitive } from "./primitive.mjs";
5
+ import { Multiple } from "./multiple.mjs";
6
+ import { Nothing } from "./nothing.mjs";
7
+ import { Literal } from "./literal.mjs";
8
+ import { Empty, Shape, forward } from "./_.mjs";
9
+ import { Choice } from "./choice.mjs";
10
+ import { Either } from "./either.mjs";
11
+ import { DiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.mjs";
12
+ import { Mapping } from "./mapping.mjs";
13
+ import { Optional } from "./optional.mjs";
14
+ import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.mjs";
15
+
16
+ export { Choice, Class, DeserializationError, Dict, DiscriminatedUnion, Either, Empty, Literal, Mapping, MicrosecondTimestamp, Multiple, Nothing, Optional, Primitive, Shape, findBestKey, forward, prepareShapeMap };
package/dist/literal.d.ts CHANGED
@@ -1,16 +1,14 @@
1
- import { AbstractConstructor, Empty, Expand } from "./_";
1
+ import { type AbstractConstructor, type Constructor, Empty, type Expand } from "./_";
2
2
  export type LiteralShorthand = string | number;
3
- export declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (...args: any[]) => {
4
- readonly value: S;
5
- serialize(): S;
6
- }) & {
3
+ export declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => ILiteral<S, B>;
4
+ export type ILiteral<S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & {
7
5
  value: S;
8
6
  $shape: "literal";
9
- deserialize<T extends any>(this: T, value: S): InstanceType<T>;
7
+ deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;
10
8
  $serialize(value: S): S;
11
9
  $deserialize(value: S): S;
12
10
  $inline: S;
13
- }, "prototype"> & (abstract new (value: Expand<S>) => InstanceType<B> & {
11
+ } & (abstract new (value: Expand<S>) => InstanceType<B> & {
14
12
  readonly value: S;
15
13
  serialize(): S;
16
14
  });
@@ -1 +1 @@
1
- {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAe,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAEtE,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MA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