@ddd-ts/shape 0.0.32 → 0.0.33

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 (46) hide show
  1. package/dist/_.d.ts +5 -5
  2. package/dist/_.d.ts.map +1 -1
  3. package/dist/_.js.map +1 -1
  4. package/dist/addons/microsecond-timestamp.d.ts +22 -0
  5. package/dist/addons/microsecond-timestamp.d.ts.map +1 -0
  6. package/dist/addons/microsecond-timestamp.js +73 -0
  7. package/dist/addons/microsecond-timestamp.js.map +1 -0
  8. package/dist/choice.d.ts +11 -24
  9. package/dist/choice.d.ts.map +1 -1
  10. package/dist/choice.js +1 -0
  11. package/dist/choice.js.map +1 -1
  12. package/dist/class.d.ts +6 -5
  13. package/dist/class.d.ts.map +1 -1
  14. package/dist/class.js.map +1 -1
  15. package/dist/dict.d.ts +18 -10
  16. package/dist/dict.d.ts.map +1 -1
  17. package/dist/dict.js +0 -1
  18. package/dist/dict.js.map +1 -1
  19. package/dist/discriminated-union.d.ts +14 -15
  20. package/dist/discriminated-union.d.ts.map +1 -1
  21. package/dist/discriminated-union.js +1 -3
  22. package/dist/discriminated-union.js.map +1 -1
  23. package/dist/either.d.ts +34 -1
  24. package/dist/either.d.ts.map +1 -1
  25. package/dist/either.js.map +1 -1
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +1 -0
  29. package/dist/index.js.map +1 -1
  30. package/dist/literal.d.ts +5 -7
  31. package/dist/literal.d.ts.map +1 -1
  32. package/dist/literal.js.map +1 -1
  33. package/dist/mapping.d.ts +16 -12
  34. package/dist/mapping.d.ts.map +1 -1
  35. package/dist/mapping.js.map +1 -1
  36. package/dist/multiple.d.ts +9 -99
  37. package/dist/multiple.d.ts.map +1 -1
  38. package/dist/multiple.js +15 -1
  39. package/dist/multiple.js.map +1 -1
  40. package/dist/optional.d.ts +11 -13
  41. package/dist/optional.d.ts.map +1 -1
  42. package/dist/optional.js.map +1 -1
  43. package/dist/primitive.d.ts +5 -7
  44. package/dist/primitive.d.ts.map +1 -1
  45. package/dist/primitive.js.map +1 -1
  46. package/package.json +4 -4
@@ -6,23 +6,21 @@ type Matcher<V> = {
6
6
  };
7
7
  type Internal<S extends Definition | Shorthand> = {
8
8
  Serialized: ReturnType<DefinitionOf<S>["$serialize"]> | undefined;
9
+ Deserializing: Parameters<DefinitionOf<S>["$deserialize"]>[0] | undefined;
9
10
  Inline: Expand<DefinitionOf<S>["$inline"]> | undefined;
10
11
  Required: Expand<DefinitionOf<S>["$inline"]>;
11
12
  };
12
- export declare const Optional: <S extends Definition | Shorthand, B extends AbstractConstructor<{}> = typeof Empty, Cache extends Internal<S> = Internal<S>>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: Cache["Inline"]) => {
13
- value: Cache["Inline"];
14
- serialize(): Expand<Cache["Serialized"]>;
15
- match<M extends Matcher<Expand<Cache["Required"]>>>(config: M): ReturnType<M["some"]> | ReturnType<M["none"]>;
16
- }) & {
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"> & {
17
15
  $shape: "optional";
18
- deserialize<T extends Constructor>(this: T, value: Cache["Inline"]): InstanceType<T>;
19
- $deserialize(value: Cache["Serialized"]): Definition["$inline"];
20
- $serialize<T extends /*elided*/ any>(this: T, value: Cache["Inline"]): Cache["Serialized"];
21
- $inline: Cache["Inline"];
22
- }, ""> & (abstract new (value: Expand<Cache["Inline"]>) => InstanceType<B> & {
23
- value: Cache["Inline"];
24
- serialize(): Expand<Cache["Serialized"]>;
25
- match<M extends Matcher<Expand<Cache["Required"]>>>(config: M): ReturnType<M["some"]> | ReturnType<M["none"]>;
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"];
20
+ } & (abstract new (value: Internal<S>["Inline"]) => InstanceType<B> & {
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
25
  export {};
28
26
  //# sourceMappingURL=optional.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,YAAY,EAEZ,WAAW,EACX,mBAAmB,EACnB,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,MAAM,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,SAAS,CAAC;IACvD,QAAQ,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,QAAQ,GACnB,CAAC,SAAS,UAAU,GAAG,SAAS,EAChC,CAAC,SAAS,mBAAmB,CAAC,EAAE,CAAC,iBACjC,KAAK,SAAS,QAAQ,CAAC,CA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AED,KAAK,CACH,MAAS;YAET,IAAK,IAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;YACvB,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAE,IAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,CAAC,WAAW,CAEhB,KAAsB;YAEtB,OAAO,IAAK,IAAY,CAAE,IAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAQ,CAAC;QACrE,CAAC;QAED,MAAM,CAAC,YAAY,CAAC,KAA0B;YAC5C,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAQ,IAAA,QAAK,EAAC,EAAE,CAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,CAAC,UAAU,CAEf,KAAsB;YAEtB,OAAO,KAAK,KAAK,SAAS;gBACxB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAE,IAAA,QAAK,EAAC,EAAE,CAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,CAAC,OAAO,CAAkB;;IAWlC,OAAO,SAA4B,CAAC;AACtC,CAAC,CAAC;AA/DW,QAAA,QAAQ,YA+DnB","sourcesContent":["import {\n Definition,\n Expand,\n Shorthand,\n DefinitionOf,\n Shape,\n Constructor,\n 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 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 Cache extends Internal<S> = Internal<S>,\n>(\n of: S,\n base: B = Empty as any,\n) => {\n abstract class $Optional extends (base as any as Constructor<{}>) {\n constructor(public value: Cache[\"Inline\"]) {\n super();\n }\n\n static $shape = \"optional\" as const;\n\n serialize(): Expand<Cache[\"Serialized\"]> {\n return $Optional.$serialize((this as any).value) as any;\n }\n\n match<M extends Matcher<Expand<Cache[\"Required\"]>>>(\n config: M,\n ): ReturnType<M[\"some\"]> | ReturnType<M[\"none\"]> {\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: Cache[\"Inline\"],\n ): InstanceType<T> {\n return new (this as any)((this as any).$deserialize(value)) as any;\n }\n\n static $deserialize(value: Cache[\"Serialized\"]): Definition[\"$inline\"] {\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>(\n this: T,\n value: Cache[\"Inline\"],\n ): Cache[\"Serialized\"] {\n return value === undefined\n ? undefined\n : (Shape(of) as any).$serialize(value);\n }\n\n static $inline: Cache[\"Inline\"];\n }\n\n type OptionalConstructor = abstract new (\n value: Expand<Cache[\"Inline\"]>,\n ) => InstanceType<B> & $Optional;\n\n type Optional = Omit<B, \"prototype\"> &\n Omit<typeof $Optional, \"\"> &\n OptionalConstructor;\n\n return $Optional as any as Optional;\n};\n"]}
1
+ {"version":3,"file":"optional.js","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":";;;AAAA,0BASa;AAaN,MAAM,QAAQ,GAAG,CAItB,EAAK,EACL,OAAU,QAAY,EACL,EAAE;IACnB,MAAe,SAAU,SAAS,IAA+B;QAC5C;QAAnB,YAAmB,KAAU;YAC3B,KAAK,EAAE,CAAC;YADS,UAAK,GAAL,KAAK,CAAK;QAE7B,CAAC;QAED,MAAM,CAAC,MAAM,GAAG,UAAmB,CAAC;QAEpC,SAAS;YACP,OAAO,SAAS,CAAC,UAAU,CAAE,IAAY,CAAC,KAAK,CAAQ,CAAC;QAC1D,CAAC;QAED,KAAK,CAAC,MAAW;YACf,IAAK,IAAY,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;gBACtC,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC;YACvB,CAAC;YACD,OAAO,MAAM,CAAC,IAAI,CAAE,IAAY,CAAC,KAAK,CAAC,CAAC;QAC1C,CAAC;QAED,MAAM,CAAC,WAAW,CAEhB,KAAU;YAEV,OAAO,IAAK,IAAY,CAAE,IAAY,CAAC,YAAY,CAAC,KAAK,CAAC,CAAQ,CAAC;QACrE,CAAC;QAED,MAAM,CAAC,YAAY,CAAC,KAAU;YAC5B,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACxB,OAAO,SAAS,CAAC;YACnB,CAAC;YACD,OAAQ,IAAA,QAAK,EAAC,EAAE,CAAS,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;QAChD,CAAC;QAED,MAAM,CAAC,UAAU,CAAsC,KAAU;YAC/D,OAAO,KAAK,KAAK,SAAS;gBACxB,CAAC,CAAC,SAAS;gBACX,CAAC,CAAE,IAAA,QAAK,EAAC,EAAE,CAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,CAAC,OAAO,CAAM;;IAGtB,OAAO,SAAgB,CAAC;AAC1B,CAAC,CAAC;AAjDW,QAAA,QAAQ,YAiDnB","sourcesContent":["import {\n Definition,\n Expand,\n Shorthand,\n DefinitionOf,\n Shape,\n Constructor,\n 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"]}
@@ -1,4 +1,4 @@
1
- import { AbstractConstructor, Empty, Expand } from "./_";
1
+ import { AbstractConstructor, Constructor, Empty, Expand } from "./_";
2
2
  type PrimitiveMap = [
3
3
  [
4
4
  StringConstructor,
@@ -23,18 +23,16 @@ export type PrimitiveFromConstructor<S> = Extract<PrimitiveMap[number], [
23
23
  any
24
24
  ]>[1];
25
25
  export type PrimitiveShorthand = PrimitiveConstructor;
26
- export declare const Primitive: <S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => Omit<B, "prototype"> & Omit<(abstract new (value: Expand<PrimitiveFromConstructor<S>>) => {
26
+ export type IPrimitive<S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty> = Omit<B, ""> & (abstract new (value: Expand<PrimitiveFromConstructor<S>>) => InstanceType<B> & {
27
27
  readonly value: Expand<PrimitiveFromConstructor<S>>;
28
28
  serialize(): PrimitiveFromConstructor<S>;
29
29
  }) & {
30
30
  $shape: "primitive";
31
- deserialize<T extends /*elided*/ any>(this: T, value: PrimitiveFromConstructor<S>): InstanceType<T>;
31
+ deserialize<T extends Constructor<any>>(this: T, value: PrimitiveFromConstructor<S>): InstanceType<T>;
32
32
  $serialize(value: PrimitiveFromConstructor<S>): PrimitiveFromConstructor<S>;
33
33
  $deserialize(value: PrimitiveFromConstructor<S>): PrimitiveFromConstructor<S>;
34
34
  $inline: Expand<PrimitiveFromConstructor<S>>;
35
- }, "prototype"> & (abstract new (value: Expand<PrimitiveFromConstructor<S>>) => InstanceType<B> & {
36
- readonly value: Expand<PrimitiveFromConstructor<S>>;
37
- serialize(): PrimitiveFromConstructor<S>;
38
- });
35
+ };
36
+ export declare const Primitive: <S extends PrimitiveConstructor, B extends AbstractConstructor<{}> = typeof Empty>(of: S, base?: B) => IPrimitive<S, B>;
39
37
  export {};
40
38
  //# sourceMappingURL=primitive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"primitive.d.ts","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAyB,KAAK,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC;AAEhF,KAAK,YAAY,GAAG;IAClB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","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":";;;AAAA,0BAAgF;AAiBzE,MAAM,SAAS,GAAG,CAIvB,EAAK,EACL,OAAU,QAAY,EACtB,EAAE;IAGF,MAAe,UAAW,SAAS,IAA+B;QACpC;QAA5B,YAA4B,KAAqB;YAC/C,KAAK,EAAE,CAAC;YADkB,UAAK,GAAL,KAAK,CAAgB;QAEjD,CAAC;QAED,MAAM,CAAC,MAAM,GAAG,WAAoB,CAAC;QAErC,SAAS;YACP,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,MAAM,CAAC,WAAW,CAEhB,KAAa;YAEb,OAAO,IAAK,IAAY,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAoB,CAAC;QACxE,CAAC;QAED,MAAM,CAAC,UAAU,CAAC,KAAa;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,YAAY,CAAC,KAAa;YAC/B,IAAI,EAAE,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC7C,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,OAAO,CAAiB;;IAWjC,OAAO,UAAuB,CAAC;AACjC,CAAC,CAAC;AAlDW,QAAA,SAAS,aAkDpB","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 const Primitive = <\n S extends PrimitiveConstructor,\n B extends AbstractConstructor<{}> = typeof Empty,\n>(\n of: S,\n base: B = Empty as any,\n) => {\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 Primitive;\n};\n"]}
1
+ {"version":3,"file":"primitive.js","sourceRoot":"","sources":["../src/primitive.ts"],"names":[],"mappings":";;;AAAA,0BAAgF;AAuCzE,MAAM,SAAS,GAAG,CAIvB,EAAK,EACL,OAAU,QAAY,EACJ,EAAE;IAGpB,MAAe,UAAW,SAAS,IAA+B;QACpC;QAA5B,YAA4B,KAAqB;YAC/C,KAAK,EAAE,CAAC;YADkB,UAAK,GAAL,KAAK,CAAgB;QAEjD,CAAC;QAED,MAAM,CAAC,MAAM,GAAG,WAAoB,CAAC;QAErC,SAAS;YACP,OAAO,IAAI,CAAC,KAAK,CAAC;QACpB,CAAC;QAED,MAAM,CAAC,WAAW,CAEhB,KAAa;YAEb,OAAO,IAAK,IAAY,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,CAAoB,CAAC;QACxE,CAAC;QAED,MAAM,CAAC,UAAU,CAAC,KAAa;YAC7B,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,YAAY,CAAC,KAAa;YAC/B,IAAI,EAAE,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC7C,OAAO,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,CAAC;YACD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,CAAC,OAAO,CAAiB;;IAWjC,OAAO,UAAiB,CAAC;AAC3B,CAAC,CAAC;AAlDW,QAAA,SAAS,aAkDpB","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ddd-ts/shape",
3
- "version": "0.0.32",
3
+ "version": "0.0.33",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "MIT",
@@ -9,11 +9,11 @@
9
9
  "test": "jest --config node_modules/@ddd-ts/tools/jest.config.js"
10
10
  },
11
11
  "dependencies": {
12
- "@ddd-ts/traits": "0.0.32"
12
+ "@ddd-ts/traits": "0.0.33"
13
13
  },
14
14
  "devDependencies": {
15
- "@ddd-ts/tools": "0.0.32",
16
- "@ddd-ts/types": "0.0.32",
15
+ "@ddd-ts/tools": "0.0.33",
16
+ "@ddd-ts/types": "0.0.33",
17
17
  "@types/jest": "^29.5.1"
18
18
  }
19
19
  }