@ddd-ts/shape 0.0.0-elo.1 → 0.0.0-eventviz.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/LICENSE +21 -0
  2. package/dist/_.d.ts +10 -9
  3. package/dist/_.d.ts.map +1 -1
  4. package/dist/_.js +31 -46
  5. package/dist/_.mjs +34 -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 +61 -0
  9. package/dist/addons/microsecond-timestamp.mjs +61 -0
  10. package/dist/choice.d.ts +16 -28
  11. package/dist/choice.d.ts.map +1 -1
  12. package/dist/choice.js +41 -45
  13. package/dist/choice.mjs +43 -0
  14. package/dist/class.d.ts +10 -8
  15. package/dist/class.d.ts.map +1 -1
  16. package/dist/class.js +27 -28
  17. package/dist/class.mjs +29 -0
  18. package/dist/dict.d.ts +38 -13
  19. package/dist/dict.d.ts.map +1 -1
  20. package/dist/dict.js +37 -42
  21. package/dist/dict.mjs +39 -0
  22. package/dist/discriminated-union.d.ts +74 -0
  23. package/dist/discriminated-union.d.ts.map +1 -0
  24. package/dist/discriminated-union.js +65 -0
  25. package/dist/discriminated-union.mjs +63 -0
  26. package/dist/discriminated-union.spec.d.ts +2 -0
  27. package/dist/discriminated-union.spec.d.ts.map +1 -0
  28. package/dist/either.d.ts +57 -13
  29. package/dist/either.d.ts.map +1 -1
  30. package/dist/either.js +48 -61
  31. package/dist/either.mjs +50 -0
  32. package/dist/index.d.ts +3 -0
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +31 -27
  35. package/dist/index.mjs +14 -0
  36. package/dist/literal.d.ts +13 -38
  37. package/dist/literal.d.ts.map +1 -1
  38. package/dist/literal.js +23 -28
  39. package/dist/literal.mjs +25 -0
  40. package/dist/mapping.d.ts +17 -13
  41. package/dist/mapping.d.ts.map +1 -1
  42. package/dist/mapping.js +42 -48
  43. package/dist/mapping.mjs +44 -0
  44. package/dist/multiple.d.ts +17 -102
  45. package/dist/multiple.d.ts.map +1 -1
  46. package/dist/multiple.js +116 -104
  47. package/dist/multiple.mjs +118 -0
  48. package/dist/nothing.d.ts +3 -3
  49. package/dist/nothing.d.ts.map +1 -1
  50. package/dist/nothing.js +15 -17
  51. package/dist/nothing.mjs +17 -0
  52. package/dist/optional.d.ts +18 -15
  53. package/dist/optional.d.ts.map +1 -1
  54. package/dist/optional.js +31 -37
  55. package/dist/optional.mjs +33 -0
  56. package/dist/primitive.d.ts +38 -0
  57. package/dist/primitive.d.ts.map +1 -0
  58. package/dist/primitive.js +29 -0
  59. package/dist/primitive.mjs +29 -0
  60. package/dist/primitive.spec.d.ts +2 -0
  61. package/dist/primitive.spec.d.ts.map +1 -0
  62. package/dist/test.d.ts +11 -11
  63. package/dist/test.d.ts.map +1 -1
  64. package/package.json +23 -9
  65. package/dist/_.js.map +0 -1
  66. package/dist/choice.js.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.js +0 -39
  71. package/dist/class.spec.js.map +0 -1
  72. package/dist/dict.js.map +0 -1
  73. package/dist/dict.spec.js +0 -180
  74. package/dist/dict.spec.js.map +0 -1
  75. package/dist/either.js.map +0 -1
  76. package/dist/either.spec.js +0 -211
  77. package/dist/either.spec.js.map +0 -1
  78. package/dist/index.js.map +0 -1
  79. package/dist/literal.js.map +0 -1
  80. package/dist/literal.spec.js +0 -162
  81. package/dist/literal.spec.js.map +0 -1
  82. package/dist/mapping.js.map +0 -1
  83. package/dist/mapping.spec.js +0 -207
  84. package/dist/mapping.spec.js.map +0 -1
  85. package/dist/multiple.js.map +0 -1
  86. package/dist/multiple.spec.js +0 -208
  87. package/dist/multiple.spec.js.map +0 -1
  88. package/dist/nothing.js.map +0 -1
  89. package/dist/nothing.spec.js +0 -172
  90. package/dist/nothing.spec.js.map +0 -1
  91. package/dist/optional.js.map +0 -1
  92. package/dist/optional.spec.js +0 -172
  93. package/dist/optional.spec.js.map +0 -1
  94. package/dist/test.js +0 -46
  95. package/dist/test.js.map +0 -1
package/dist/either.js CHANGED
@@ -1,63 +1,50 @@
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 $name = "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
- ;
36
- static deserialize(value) {
37
- return new this(this.$deserialize(value));
38
- }
39
- static $deserialize(value) {
40
- const [key, serialized] = value;
41
- const definition = definitions[key];
42
- if (!definition) {
43
- throw new Error("Cannot deserialize Either");
44
- }
45
- return definition.$deserialize(serialized);
46
- }
47
- static $serialize(value) {
48
- const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
49
- if (!key) {
50
- throw new Error("Cannot serialize Either, no matching key");
51
- }
52
- const definition = definitions[key];
53
- if (!definition) {
54
- throw new Error("Cannot serialize Either");
55
- }
56
- return [key, definition.$serialize(value)];
57
- }
58
- static $inline;
59
- }
60
- return $Either;
1
+ const require__ = require("./_.js");
2
+ //#region src/either.ts
3
+ const Either = (of, base = require__.Empty) => {
4
+ const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
5
+ return [key, require__.Shape(value)];
6
+ }));
7
+ class $Either extends base {
8
+ value;
9
+ constructor(value) {
10
+ super();
11
+ this.value = value;
12
+ }
13
+ static serialized;
14
+ static of = of;
15
+ static $shape = "either";
16
+ serialize() {
17
+ return $Either.$serialize(this.value);
18
+ }
19
+ match(...[matcher, fallback]) {
20
+ const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
21
+ if (handler) return handler(this.value);
22
+ if (fallback) return fallback(this.value);
23
+ if (matcher._) return matcher._(this.value);
24
+ throw new Error("Non-exhaustive match");
25
+ }
26
+ static deserialize(value) {
27
+ return new this(this.$deserialize(value));
28
+ }
29
+ static $deserialize(value) {
30
+ const { _key: key, ...serialized } = value;
31
+ const definition = definitions[key];
32
+ if (!definition) throw new Error("Cannot deserialize Either");
33
+ return definition.$deserialize(serialized);
34
+ }
35
+ static $serialize(value) {
36
+ const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
37
+ if (!key) throw new Error("Cannot serialize Either, no matching key");
38
+ const definition = definitions[key];
39
+ if (!definition) throw new Error("Cannot serialize Either");
40
+ return {
41
+ ...definition.$serialize(value),
42
+ _key: key
43
+ };
44
+ }
45
+ static $inline;
46
+ }
47
+ return $Either;
61
48
  };
49
+ //#endregion
62
50
  exports.Either = Either;
63
- //# sourceMappingURL=either.js.map
@@ -0,0 +1,50 @@
1
+ import { Empty, Shape } from "./_.mjs";
2
+ //#region src/either.ts
3
+ const Either = (of, base = Empty) => {
4
+ const definitions = Object.fromEntries(Object.entries(of).map(([key, value]) => {
5
+ return [key, Shape(value)];
6
+ }));
7
+ class $Either extends base {
8
+ value;
9
+ constructor(value) {
10
+ super();
11
+ this.value = value;
12
+ }
13
+ static serialized;
14
+ static of = of;
15
+ static $shape = "either";
16
+ serialize() {
17
+ return $Either.$serialize(this.value);
18
+ }
19
+ match(...[matcher, fallback]) {
20
+ const handler = matcher[Object.entries(of).find(([_, v]) => v === this.value.constructor)?.[0]];
21
+ if (handler) return handler(this.value);
22
+ if (fallback) return fallback(this.value);
23
+ if (matcher._) return matcher._(this.value);
24
+ throw new Error("Non-exhaustive match");
25
+ }
26
+ static deserialize(value) {
27
+ return new this(this.$deserialize(value));
28
+ }
29
+ static $deserialize(value) {
30
+ const { _key: key, ...serialized } = value;
31
+ const definition = definitions[key];
32
+ if (!definition) throw new Error("Cannot deserialize Either");
33
+ return definition.$deserialize(serialized);
34
+ }
35
+ static $serialize(value) {
36
+ const key = Object.entries(of).find(([_, v]) => v === value.constructor)?.[0];
37
+ if (!key) throw new Error("Cannot serialize Either, no matching key");
38
+ const definition = definitions[key];
39
+ if (!definition) throw new Error("Cannot serialize Either");
40
+ return {
41
+ ...definition.$serialize(value),
42
+ _key: key
43
+ };
44
+ }
45
+ static $inline;
46
+ }
47
+ return $Either;
48
+ };
49
+ //#endregion
50
+ export { Either };
package/dist/index.d.ts CHANGED
@@ -3,9 +3,12 @@ export * from "./choice";
3
3
  export * from "./class";
4
4
  export * from "./dict";
5
5
  export * from "./either";
6
+ export * from "./primitive";
6
7
  export * from "./literal";
8
+ export * from "./discriminated-union";
7
9
  export * from "./mapping";
8
10
  export * from "./multiple";
9
11
  export * from "./nothing";
10
12
  export * from "./optional";
13
+ export * from "./addons/microsecond-timestamp";
11
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,KAAK,CAAC;AACpB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,uBAAuB,CAAC;AACtC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,gCAAgC,CAAC"}
package/dist/index.js CHANGED
@@ -1,27 +1,31 @@
1
- "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("./literal"), exports);
23
- __exportStar(require("./mapping"), exports);
24
- __exportStar(require("./multiple"), exports);
25
- __exportStar(require("./nothing"), exports);
26
- __exportStar(require("./optional"), exports);
27
- //# sourceMappingURL=index.js.map
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_class = require("./class.js");
3
+ const require_dict = require("./dict.js");
4
+ const require_primitive = require("./primitive.js");
5
+ const require_multiple = require("./multiple.js");
6
+ const require_nothing = require("./nothing.js");
7
+ const require_literal = require("./literal.js");
8
+ const require__ = require("./_.js");
9
+ const require_choice = require("./choice.js");
10
+ const require_either = require("./either.js");
11
+ const require_discriminated_union = require("./discriminated-union.js");
12
+ const require_mapping = require("./mapping.js");
13
+ const require_optional = require("./optional.js");
14
+ const require_microsecond_timestamp = require("./addons/microsecond-timestamp.js");
15
+ exports.Choice = require_choice.Choice;
16
+ exports.Class = require_class.Class;
17
+ exports.Dict = require_dict.Dict;
18
+ exports.DiscriminatedUnion = require_discriminated_union.DiscriminatedUnion;
19
+ exports.Either = require_either.Either;
20
+ exports.Empty = require__.Empty;
21
+ exports.Literal = require_literal.Literal;
22
+ exports.Mapping = require_mapping.Mapping;
23
+ exports.MicrosecondTimestamp = require_microsecond_timestamp.MicrosecondTimestamp;
24
+ exports.Multiple = require_multiple.Multiple;
25
+ exports.Nothing = require_nothing.Nothing;
26
+ exports.Optional = require_optional.Optional;
27
+ exports.Primitive = require_primitive.Primitive;
28
+ exports.Shape = require__.Shape;
29
+ exports.findBestKey = require_discriminated_union.findBestKey;
30
+ exports.forward = require__.forward;
31
+ exports.prepareShapeMap = require_discriminated_union.prepareShapeMap;
package/dist/index.mjs ADDED
@@ -0,0 +1,14 @@
1
+ import { Class } from "./class.mjs";
2
+ import { Dict } from "./dict.mjs";
3
+ import { Primitive } from "./primitive.mjs";
4
+ import { Multiple } from "./multiple.mjs";
5
+ import { Nothing } from "./nothing.mjs";
6
+ import { Literal } from "./literal.mjs";
7
+ import { Empty, Shape, forward } from "./_.mjs";
8
+ import { Choice } from "./choice.mjs";
9
+ import { Either } from "./either.mjs";
10
+ import { DiscriminatedUnion, findBestKey, prepareShapeMap } from "./discriminated-union.mjs";
11
+ import { Mapping } from "./mapping.mjs";
12
+ import { Optional } from "./optional.mjs";
13
+ import { MicrosecondTimestamp } from "./addons/microsecond-timestamp.mjs";
14
+ export { Choice, Class, Dict, DiscriminatedUnion, Either, Empty, Literal, Mapping, MicrosecondTimestamp, Multiple, Nothing, Optional, Primitive, Shape, findBestKey, forward, prepareShapeMap };
package/dist/literal.d.ts CHANGED
@@ -1,40 +1,15 @@
1
- import { AbstractConstructor, Empty, Expand } from "./_";
2
- type LiteralMap = [
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
- ];
20
- type LiteralConstructor = LiteralMap[number][0];
21
- export type LiteralFromConstructor<S> = Extract<LiteralMap[number], [
22
- S,
23
- any
24
- ]>[1];
25
- export type LiteralShorthand = LiteralConstructor;
26
- export declare const Literal: <S extends StringConstructor | NumberConstructor | DateConstructor | BooleanConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: Expand<LiteralFromConstructor<S>>) => {
27
- readonly value: Expand<LiteralFromConstructor<S>>;
28
- serialize(): LiteralFromConstructor<S>;
29
- }) & {
30
- $name: "literal";
31
- deserialize<T extends any>(this: T, value: LiteralFromConstructor<S>): InstanceType<T>;
32
- $serialize(value: LiteralFromConstructor<S>): LiteralFromConstructor<S>;
33
- $deserialize(value: LiteralFromConstructor<S>): LiteralFromConstructor<S>;
34
- $inline: Expand<LiteralFromConstructor<S>>;
35
- }, "prototype"> & (abstract new (value: Expand<LiteralFromConstructor<S>>) => InstanceType<B> & {
36
- readonly value: Expand<LiteralFromConstructor<S>>;
37
- serialize(): LiteralFromConstructor<S>;
1
+ import { type AbstractConstructor, type Constructor, Empty, type Expand } from "./_";
2
+ export type LiteralShorthand = string | number;
3
+ export declare const Literal: <const S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => ILiteral<S, B>;
4
+ export type ILiteral<S extends LiteralShorthand, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & {
5
+ value: S;
6
+ $shape: "literal";
7
+ deserialize<T extends Constructor>(this: T, value: S): InstanceType<T>;
8
+ $serialize(value: S): S;
9
+ $deserialize(value: S): S;
10
+ $inline: S;
11
+ } & (abstract new (value: Expand<S>) => InstanceType<B> & {
12
+ readonly value: S;
13
+ serialize(): S;
38
14
  });
39
- export {};
40
15
  //# sourceMappingURL=literal.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAyB,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAEhF,KAAK,UAAU,GAAG;IAChB;QAAC,iBAAiB;QAAE,MAAM;KAAC;IAC3B;QAAC,iBAAiB;QAAE,MAAM;KAAC;IAC3B;QAAC,eAAe;QAAE,IAAI;KAAC;IACvB;QAAC,kBAAkB;QAAE,OAAO;KAAC;CAC9B,CAAC;AAEF,KAAK,kBAAkB,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI,OAAO,CAC7C,UAAU,CAAC,MAAM,CAAC,EAClB;IAAC,CAAC;IAAE,GAAG;CAAC,CACT,CAAC,CAAC,CAAC,CAAC;AAEL,MAAM,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAElD,eAAO,MAAM,OAAO,iJAId,CAAC,SACC,CAAC;;;;;qCAgBG,CAAC,qCAEN,aAAa,CAAC,CAAC;;;;;;;EAwBrB,CAAC"}
1
+ {"version":3,"file":"literal.d.ts","sourceRoot":"","sources":["../src/literal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,WAAW,EAAE,KAAK,EAAE,KAAK,MAAM,EAAE,MAAM,KAAK,CAAC;AAErF,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC;AAE/C,eAAO,MAAM,OAAO,SACZ,CAAC,SAAS,gBAAgB,EAChC,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,qBAE7B,CAAC,SACC,CAAC,KACN,QAAQ,CAAC,CAAC,EAAE,CAAC,CA8Bf,CAAC;AAEF,MAAM,MAAM,QAAQ,CAClB,CAAC,SAAS,gBAAgB,EAC1B,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,GAAG,OAAO,KAAK,IAC9C,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG;IACzB,KAAK,EAAE,CAAC,CAAC;IACT,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,CAAC,SAAS,WAAW,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC;IACvE,UAAU,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IACxB,YAAY,CAAC,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC;IAC1B,OAAO,EAAE,CAAC,CAAC;CACZ,GAAG,CAAC,QAAQ,MACT,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,KACb,YAAY,CAAC,CAAC,CAAC,GAAG;IACrB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;IAClB,SAAS,IAAI,CAAC,CAAC;CAChB,CAAC,CAAC"}
package/dist/literal.js CHANGED
@@ -1,30 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Literal = void 0;
4
- const _1 = require("./_");
5
- const Literal = (of, base = _1.Empty) => {
6
- class $Literal extends base {
7
- value;
8
- constructor(value) {
9
- super();
10
- this.value = value;
11
- }
12
- static $name = "literal";
13
- serialize() {
14
- return this.value;
15
- }
16
- static deserialize(value) {
17
- return new this(this.$deserialize(value));
18
- }
19
- static $serialize(value) {
20
- return value;
21
- }
22
- static $deserialize(value) {
23
- return value;
24
- }
25
- static $inline;
26
- }
27
- return $Literal;
1
+ const require__ = require("./_.js");
2
+ //#region src/literal.ts
3
+ const Literal = (of, base = require__.Empty) => {
4
+ class $Literal extends base {
5
+ value = of;
6
+ static value = of;
7
+ static $shape = "literal";
8
+ serialize() {
9
+ return of;
10
+ }
11
+ static deserialize(value) {
12
+ return new this();
13
+ }
14
+ static $serialize(value) {
15
+ return of;
16
+ }
17
+ static $deserialize(value) {
18
+ return of;
19
+ }
20
+ static $inline;
21
+ }
22
+ return $Literal;
28
23
  };
24
+ //#endregion
29
25
  exports.Literal = Literal;
30
- //# sourceMappingURL=literal.js.map
@@ -0,0 +1,25 @@
1
+ import { Empty } from "./_.mjs";
2
+ //#region src/literal.ts
3
+ const Literal = (of, base = Empty) => {
4
+ class $Literal extends base {
5
+ value = of;
6
+ static value = of;
7
+ static $shape = "literal";
8
+ serialize() {
9
+ return of;
10
+ }
11
+ static deserialize(value) {
12
+ return new this();
13
+ }
14
+ static $serialize(value) {
15
+ return of;
16
+ }
17
+ static $deserialize(value) {
18
+ return of;
19
+ }
20
+ static $inline;
21
+ }
22
+ return $Literal;
23
+ };
24
+ //#endregion
25
+ export { Literal };
package/dist/mapping.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Definition, Expand, Shorthand, DefinitionOf, AbstractConstructor, Empty } from "./_";
1
+ import { type Definition, type Expand, type Shorthand, type DefinitionOf, type AbstractConstructor, Empty, type Constructor } from "./_";
2
2
  type MappingLiteralKey = [
3
3
  [
4
4
  StringConstructor,
@@ -22,18 +22,22 @@ type MappingOf<C extends MappingConfiguration> = C extends [
22
22
  key: StringConstructor;
23
23
  value: DefinitionOf<V>;
24
24
  } : never;
25
- export declare const Mapping: <C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty>(config: C, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>) => {
26
- value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
27
- serialize(): Expand<Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>>;
25
+ type Internal<C extends MappingConfiguration, B extends AbstractConstructor<{}>> = {
26
+ Definition: MappingOf<C>["value"];
27
+ Serialized: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>;
28
+ Deserializing: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, Parameters<MappingOf<C>["value"]["$deserialize"]>[0]>;
29
+ Inline: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
30
+ };
31
+ export declare const Mapping: <C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty>(config: C, base?: B) => Mapping<C, B>;
32
+ export type Mapping<C extends MappingConfiguration, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, "prototype"> & (abstract new (value: Internal<C, B>["Inline"]) => InstanceType<B> & {
33
+ value: Internal<C, B>["Inline"];
34
+ serialize(): Expand<Internal<C, B>["Serialized"]>;
28
35
  }) & {
29
- $name: "mapping";
30
- deserialize<T extends any>(this: T, value: Expand<Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>>): InstanceType<T>;
31
- $deserialize<T_1 extends any>(this: T_1, value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>): Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
32
- $serialize<T_2 extends any>(this: T_2, value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>): Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>;
33
- $inline: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
34
- }, "prototype"> & (abstract new (value: Expand<Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>>) => InstanceType<B> & {
35
- value: Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, MappingOf<C>["value"]["$inline"]>;
36
- serialize(): Expand<Record<MappingKeyRuntimeFromConstructor<MappingOf<C>["key"]>, ReturnType<MappingOf<C>["value"]["$serialize"]>>>;
37
- });
36
+ $shape: "mapping";
37
+ deserialize<T extends Constructor>(this: T, value: Expand<Internal<C, B>["Serialized"]>): InstanceType<T>;
38
+ $deserialize<T>(this: T, value: Internal<C, B>["Deserializing"]): Internal<C, B>["Inline"];
39
+ $serialize<T>(this: T, value: Internal<C, B>["Inline"]): Internal<C, B>["Serialized"];
40
+ $inline: Internal<C, B>["Inline"];
41
+ };
38
42
  export {};
39
43
  //# sourceMappingURL=mapping.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mapping.d.ts","sourceRoot":"","sources":["../src/mapping.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,UAAU,EACV,MAAM,EACN,SAAS,EACT,YAAY,EAEZ,mBAAmB,EACnB,KAAK,EAEN,MAAM,KAAK,CAAC;AAGb,KAAK,iBAAiB,GAAG;IACvB;QAAC,iBAAiB;QAAE,MAAM;KAAC;IAC3B;QAAC,iBAAiB;QAAE,MAAM;KAAC;CAC5B,CAAC;AACF,KAAK,qBAAqB,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAC1D,KAAK,gCAAgC,CAAC,CAAC,SAAS,qBAAqB,IACnE,CAAC,SAAS,iBAAiB,GAAG,MAAM,GAAG,MAAM,CAAC;AAEhD,MAAM,MAAM,oBAAoB,GAC5B,CAAC,qBAAqB,EAAE,UAAU,GAAG,SAAS,CAAC,GAC/C,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;AAE7B,KAAK,SAAS,CAAC,CAAC,SAAS,oBAAoB,IAAI,CAAC,SAAS;IACzD,MAAM,CAAC,SAAS,qBAAqB;IACrC,MAAM,CAAC,SAAS,UAAU,GAAG,SAAS;C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AK,IAC9C,IAAI,CAAC,CAAC,EAAE,WAAW,CAAC,GACtB,CAAC,QAAQ,MACP,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAC5B,YAAY,CAAC,CAAC,CAAC,GAAG;IACrB,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAChC,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC;CACnD,CAAC,GAAG;IACH,MAAM,EAAE,SAAS,CAAC;IAClB,WAAW,CAAC,CAAC,SAAS,WAAW,EAC/B,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,GAC1C,YAAY,CAAC,CAAC,CAAC,CAAC;IACnB,YAAY,CAAC,CAAC,EACZ,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,GACrC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC5B,UAAU,CAAC,CAAC,EACV,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,GAC9B,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;IAChC,OAAO,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;CACnC,CAAC"}
package/dist/mapping.js CHANGED
@@ -1,50 +1,44 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Mapping = void 0;
4
- const _1 = require("./_");
5
- const literal_1 = require("./literal");
6
- const Mapping = (config, base = _1.Empty) => {
7
- let [_key, _value] = config;
8
- if (config.length === 1) {
9
- _key = (0, literal_1.Literal)(String);
10
- _value = config[0];
11
- }
12
- const { $key, $value } = { $key: _key, $value: _value };
13
- class $Mapping extends base {
14
- value;
15
- constructor(value) {
16
- super();
17
- this.value = value;
18
- }
19
- static $name = "mapping";
20
- serialize() {
21
- return $Mapping.$serialize(this.value);
22
- }
23
- static deserialize(value) {
24
- return new this($Mapping.$deserialize(value));
25
- }
26
- static $deserialize(value) {
27
- const split = Object.entries(value);
28
- const transform = split.map(([key, child]) => {
29
- const longhand = (0, _1.Shape)(_value);
30
- const deserialized = longhand.$deserialize(child);
31
- return [key, deserialized];
32
- });
33
- return Object.fromEntries(transform);
34
- }
35
- static $serialize(value) {
36
- const split = Object.entries(value);
37
- const transform = split.map(([key, child]) => {
38
- const longhand = (0, _1.Shape)($value);
39
- const serialized = longhand.$serialize(child);
40
- return [key, serialized];
41
- });
42
- const merge = Object.fromEntries(transform);
43
- return merge;
44
- }
45
- static $inline;
46
- }
47
- return $Mapping;
1
+ const require_primitive = require("./primitive.js");
2
+ const require__ = require("./_.js");
3
+ //#region src/mapping.ts
4
+ const Mapping = (config, base = require__.Empty) => {
5
+ let [_key, _value] = config;
6
+ if (config.length === 1) {
7
+ _key = require_primitive.Primitive(String);
8
+ _value = config[0];
9
+ }
10
+ const { $key, $value } = {
11
+ $key: _key,
12
+ $value: _value
13
+ };
14
+ class $Mapping extends base {
15
+ value;
16
+ constructor(value) {
17
+ super();
18
+ this.value = value;
19
+ }
20
+ static $shape = "mapping";
21
+ serialize() {
22
+ return $Mapping.$serialize(this.value);
23
+ }
24
+ static deserialize(value) {
25
+ return new this($Mapping.$deserialize(value));
26
+ }
27
+ static $deserialize(value) {
28
+ const transform = Object.entries(value).map(([key, child]) => {
29
+ return [key, require__.Shape(_value).$deserialize(child)];
30
+ });
31
+ return Object.fromEntries(transform);
32
+ }
33
+ static $serialize(value) {
34
+ const transform = Object.entries(value).map(([key, child]) => {
35
+ return [key, require__.Shape($value).$serialize(child)];
36
+ });
37
+ return Object.fromEntries(transform);
38
+ }
39
+ static $inline;
40
+ }
41
+ return $Mapping;
48
42
  };
43
+ //#endregion
49
44
  exports.Mapping = Mapping;
50
- //# sourceMappingURL=mapping.js.map
@@ -0,0 +1,44 @@
1
+ import { Primitive } from "./primitive.mjs";
2
+ import { Empty, Shape } from "./_.mjs";
3
+ //#region src/mapping.ts
4
+ const Mapping = (config, base = Empty) => {
5
+ let [_key, _value] = config;
6
+ if (config.length === 1) {
7
+ _key = Primitive(String);
8
+ _value = config[0];
9
+ }
10
+ const { $key, $value } = {
11
+ $key: _key,
12
+ $value: _value
13
+ };
14
+ class $Mapping extends base {
15
+ value;
16
+ constructor(value) {
17
+ super();
18
+ this.value = value;
19
+ }
20
+ static $shape = "mapping";
21
+ serialize() {
22
+ return $Mapping.$serialize(this.value);
23
+ }
24
+ static deserialize(value) {
25
+ return new this($Mapping.$deserialize(value));
26
+ }
27
+ static $deserialize(value) {
28
+ const transform = Object.entries(value).map(([key, child]) => {
29
+ return [key, Shape(_value).$deserialize(child)];
30
+ });
31
+ return Object.fromEntries(transform);
32
+ }
33
+ static $serialize(value) {
34
+ const transform = Object.entries(value).map(([key, child]) => {
35
+ return [key, Shape($value).$serialize(child)];
36
+ });
37
+ return Object.fromEntries(transform);
38
+ }
39
+ static $inline;
40
+ }
41
+ return $Mapping;
42
+ };
43
+ //#endregion
44
+ export { Mapping };