@teambit/semantics.entities.semantic-schema 0.0.51 → 0.0.54

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 (202) hide show
  1. package/api-schema.ts +32 -9
  2. package/class-transformers/comp-id-transformer.ts +21 -21
  3. package/class-transformers/index.ts +2 -2
  4. package/class-transformers/schema-obj-to-class.ts +51 -45
  5. package/dist/api-schema.d.ts +19 -3
  6. package/dist/api-schema.js +16 -19
  7. package/dist/api-schema.js.map +1 -1
  8. package/dist/class-transformers/comp-id-transformer.d.ts +0 -6
  9. package/dist/class-transformers/comp-id-transformer.js +21 -19
  10. package/dist/class-transformers/comp-id-transformer.js.map +1 -1
  11. package/dist/class-transformers/index.d.ts +0 -2
  12. package/dist/class-transformers/index.js +2 -8
  13. package/dist/class-transformers/index.js.map +1 -1
  14. package/dist/class-transformers/schema-obj-to-class.d.ts +0 -10
  15. package/dist/class-transformers/schema-obj-to-class.js +49 -66
  16. package/dist/class-transformers/schema-obj-to-class.js.map +1 -1
  17. package/dist/index.d.ts +8 -2
  18. package/dist/index.js +20 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/{preview-1676777489824.js → preview-1694692074267.js} +1 -1
  21. package/dist/schema-node-constructor.d.ts +7 -0
  22. package/dist/schema-node-constructor.js +3 -0
  23. package/dist/schema-node-constructor.js.map +1 -0
  24. package/dist/schema-node.d.ts +20 -4
  25. package/dist/schema-node.js +36 -2
  26. package/dist/schema-node.js.map +1 -1
  27. package/dist/schema-registry.d.ts +9 -0
  28. package/dist/schema-registry.js +31 -0
  29. package/dist/schema-registry.js.map +1 -0
  30. package/dist/schemas/class.d.ts +39 -3
  31. package/dist/schemas/class.js +22 -14
  32. package/dist/schemas/class.js.map +1 -1
  33. package/dist/schemas/conditional-type.d.ts +11 -3
  34. package/dist/schemas/conditional-type.js +15 -20
  35. package/dist/schemas/conditional-type.js.map +1 -1
  36. package/dist/schemas/constructor.d.ts +3 -2
  37. package/dist/schemas/constructor.js +14 -2
  38. package/dist/schemas/constructor.js.map +1 -1
  39. package/dist/schemas/docs/doc.d.ts +20 -3
  40. package/dist/schemas/docs/doc.js +17 -11
  41. package/dist/schemas/docs/doc.js.map +1 -1
  42. package/dist/schemas/docs/property-like-tag.d.ts +13 -3
  43. package/dist/schemas/docs/property-like-tag.js +12 -11
  44. package/dist/schemas/docs/property-like-tag.js.map +1 -1
  45. package/dist/schemas/docs/return-tag.d.ts +13 -3
  46. package/dist/schemas/docs/return-tag.js +11 -11
  47. package/dist/schemas/docs/return-tag.js.map +1 -1
  48. package/dist/schemas/docs/tag.d.ts +14 -4
  49. package/dist/schemas/docs/tag.js +17 -0
  50. package/dist/schemas/docs/tag.js.map +1 -1
  51. package/dist/schemas/enum-member.d.ts +25 -3
  52. package/dist/schemas/enum-member.js +13 -11
  53. package/dist/schemas/enum-member.js.map +1 -1
  54. package/dist/schemas/enum.d.ts +26 -3
  55. package/dist/schemas/enum.js +17 -14
  56. package/dist/schemas/enum.js.map +1 -1
  57. package/dist/schemas/expression-with-arguments.d.ts +10 -3
  58. package/dist/schemas/expression-with-arguments.js +11 -14
  59. package/dist/schemas/expression-with-arguments.js.map +1 -1
  60. package/dist/schemas/function-like.d.ts +40 -4
  61. package/dist/schemas/function-like.js +28 -18
  62. package/dist/schemas/function-like.js.map +1 -1
  63. package/dist/schemas/get-accessor.d.ts +10 -3
  64. package/dist/schemas/get-accessor.js +14 -11
  65. package/dist/schemas/get-accessor.js.map +1 -1
  66. package/dist/schemas/index-signature.d.ts +17 -3
  67. package/dist/schemas/index-signature.js +11 -14
  68. package/dist/schemas/index-signature.js.map +1 -1
  69. package/dist/schemas/index.d.ts +1 -1
  70. package/dist/schemas/index.js.map +1 -1
  71. package/dist/schemas/indexed-access-type.d.ts +9 -3
  72. package/dist/schemas/indexed-access-type.js +13 -14
  73. package/dist/schemas/indexed-access-type.js.map +1 -1
  74. package/dist/schemas/inference-type.d.ts +9 -3
  75. package/dist/schemas/inference-type.js +12 -1
  76. package/dist/schemas/inference-type.js.map +1 -1
  77. package/dist/schemas/interface.d.ts +33 -3
  78. package/dist/schemas/interface.js +21 -14
  79. package/dist/schemas/interface.js.map +1 -1
  80. package/dist/schemas/keyword-type.d.ts +7 -3
  81. package/dist/schemas/keyword-type.js +8 -0
  82. package/dist/schemas/keyword-type.js.map +1 -1
  83. package/dist/schemas/literal-type.d.ts +4 -4
  84. package/dist/schemas/literal-type.js +6 -4
  85. package/dist/schemas/literal-type.js.map +1 -1
  86. package/dist/schemas/module.d.ts +9 -7
  87. package/dist/schemas/module.js +15 -20
  88. package/dist/schemas/module.js.map +1 -1
  89. package/dist/schemas/named-tuple.d.ts +9 -3
  90. package/dist/schemas/named-tuple.js +13 -0
  91. package/dist/schemas/named-tuple.js.map +1 -1
  92. package/dist/schemas/parameter.d.ts +16 -5
  93. package/dist/schemas/parameter.js +20 -16
  94. package/dist/schemas/parameter.js.map +1 -1
  95. package/dist/schemas/parenthesized-type.d.ts +8 -3
  96. package/dist/schemas/parenthesized-type.js +12 -11
  97. package/dist/schemas/parenthesized-type.js.map +1 -1
  98. package/dist/schemas/set-accessor.d.ts +17 -3
  99. package/dist/schemas/set-accessor.js +11 -11
  100. package/dist/schemas/set-accessor.js.map +1 -1
  101. package/dist/schemas/template-literal-type-span.d.ts +9 -3
  102. package/dist/schemas/template-literal-type-span.js +13 -11
  103. package/dist/schemas/template-literal-type-span.js.map +1 -1
  104. package/dist/schemas/template-literal-type.d.ts +11 -3
  105. package/dist/schemas/template-literal-type.js +10 -11
  106. package/dist/schemas/template-literal-type.js.map +1 -1
  107. package/dist/schemas/this-type.d.ts +4 -3
  108. package/dist/schemas/this-type.js +4 -0
  109. package/dist/schemas/this-type.js.map +1 -1
  110. package/dist/schemas/tuple-type.d.ts +7 -3
  111. package/dist/schemas/tuple-type.js +9 -11
  112. package/dist/schemas/tuple-type.js.map +1 -1
  113. package/dist/schemas/type-array.d.ts +8 -3
  114. package/dist/schemas/type-array.js +12 -11
  115. package/dist/schemas/type-array.js.map +1 -1
  116. package/dist/schemas/type-intersection.d.ts +8 -3
  117. package/dist/schemas/type-intersection.js +12 -11
  118. package/dist/schemas/type-intersection.js.map +1 -1
  119. package/dist/schemas/type-literal.d.ts +8 -3
  120. package/dist/schemas/type-literal.js +12 -11
  121. package/dist/schemas/type-literal.js.map +1 -1
  122. package/dist/schemas/type-operator.d.ts +9 -3
  123. package/dist/schemas/type-operator.js +13 -11
  124. package/dist/schemas/type-operator.js.map +1 -1
  125. package/dist/schemas/type-predicate.d.ts +9 -3
  126. package/dist/schemas/type-predicate.js +12 -11
  127. package/dist/schemas/type-predicate.js.map +1 -1
  128. package/dist/schemas/type-query.d.ts +9 -3
  129. package/dist/schemas/type-query.js +13 -11
  130. package/dist/schemas/type-query.js.map +1 -1
  131. package/dist/schemas/type-ref.d.ts +28 -4
  132. package/dist/schemas/type-ref.js +43 -16
  133. package/dist/schemas/type-ref.js.map +1 -1
  134. package/dist/schemas/type-union.d.ts +8 -3
  135. package/dist/schemas/type-union.js +12 -11
  136. package/dist/schemas/type-union.js.map +1 -1
  137. package/dist/schemas/type.d.ts +10 -3
  138. package/dist/schemas/type.js +16 -14
  139. package/dist/schemas/type.js.map +1 -1
  140. package/dist/schemas/unimplemented-schema.d.ts +7 -3
  141. package/dist/schemas/unimplemented-schema.js +9 -0
  142. package/dist/schemas/unimplemented-schema.js.map +1 -1
  143. package/dist/schemas/unknown-schema.d.ts +7 -3
  144. package/dist/schemas/unknown-schema.js +9 -0
  145. package/dist/schemas/unknown-schema.js.map +1 -1
  146. package/dist/schemas/unresolved-schema.d.ts +5 -3
  147. package/dist/schemas/unresolved-schema.js +8 -0
  148. package/dist/schemas/unresolved-schema.js.map +1 -1
  149. package/dist/schemas/variable-like.d.ts +29 -3
  150. package/dist/schemas/variable-like.js +21 -15
  151. package/dist/schemas/variable-like.js.map +1 -1
  152. package/dist/unknown-schema-factory.d.ts +4 -0
  153. package/dist/unknown-schema-factory.js +13 -0
  154. package/dist/unknown-schema-factory.js.map +1 -0
  155. package/index.ts +10 -2
  156. package/package.json +3 -4
  157. package/schema-node-constructor.ts +8 -0
  158. package/schema-node.ts +62 -6
  159. package/schema-registry.ts +33 -0
  160. package/schemas/class.ts +32 -7
  161. package/schemas/conditional-type.ts +27 -11
  162. package/schemas/constructor.ts +14 -4
  163. package/schemas/docs/doc.ts +22 -5
  164. package/schemas/docs/property-like-tag.ts +19 -5
  165. package/schemas/docs/return-tag.ts +18 -5
  166. package/schemas/docs/tag.ts +21 -2
  167. package/schemas/enum-member.ts +21 -5
  168. package/schemas/enum.ts +26 -6
  169. package/schemas/expression-with-arguments.ts +26 -7
  170. package/schemas/function-like.ts +51 -10
  171. package/schemas/get-accessor.ts +24 -5
  172. package/schemas/index-signature.ts +19 -6
  173. package/schemas/index.ts +1 -1
  174. package/schemas/indexed-access-type.ts +24 -6
  175. package/schemas/inference-type.ts +23 -2
  176. package/schemas/interface.ts +30 -7
  177. package/schemas/keyword-type.ts +15 -2
  178. package/schemas/literal-type.ts +9 -3
  179. package/schemas/module.ts +24 -14
  180. package/schemas/named-tuple.ts +22 -2
  181. package/schemas/parameter.ts +43 -11
  182. package/schemas/parenthesized-type.ts +20 -5
  183. package/schemas/set-accessor.ts +26 -5
  184. package/schemas/template-literal-type-span.ts +23 -5
  185. package/schemas/template-literal-type.ts +22 -5
  186. package/schemas/this-type.ts +7 -2
  187. package/schemas/tuple-type.ts +17 -5
  188. package/schemas/type-array.ts +21 -5
  189. package/schemas/type-intersection.ts +21 -5
  190. package/schemas/type-literal.ts +21 -5
  191. package/schemas/type-operator.ts +22 -5
  192. package/schemas/type-predicate.ts +20 -5
  193. package/schemas/type-query.ts +24 -5
  194. package/schemas/type-ref.ts +51 -10
  195. package/schemas/type-union.ts +17 -5
  196. package/schemas/type.ts +25 -7
  197. package/schemas/unimplemented-schema.ts +16 -2
  198. package/schemas/unknown-schema.ts +16 -2
  199. package/schemas/unresolved-schema.ts +12 -2
  200. package/schemas/variable-like.ts +33 -8
  201. package/unknown-schema-factory.ts +10 -0
  202. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.51.tgz +0 -0
@@ -1,11 +1,31 @@
1
- import { Location, SchemaNode } from '../schema-node';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
2
3
 
3
4
  export class NamedTupleSchema extends SchemaNode {
4
- constructor(readonly location: Location, readonly type: SchemaNode, readonly name?: string) {
5
+ constructor(readonly location: SchemaLocation, readonly type: SchemaNode, readonly name?: string) {
5
6
  super();
6
7
  }
7
8
 
9
+ getNodes() {
10
+ return [this.type];
11
+ }
12
+
8
13
  toString() {
9
14
  return `${this.name}: ${this.type.toString()}`;
10
15
  }
16
+
17
+ toObject() {
18
+ return {
19
+ ...super.toObject(),
20
+ name: this.name,
21
+ type: this.type.toObject(),
22
+ };
23
+ }
24
+
25
+ static fromObject(obj: Record<string, any>): NamedTupleSchema {
26
+ const location = obj.location;
27
+ const type = SchemaRegistry.fromObject(obj.type);
28
+ const name = obj.name;
29
+ return new NamedTupleSchema(location, type, name);
30
+ }
11
31
  }
@@ -1,29 +1,61 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
4
- import { schemaObjArrayToInstances } from '../class-transformers/schema-obj-to-class';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
5
3
 
6
- export class ParameterSchema extends SchemaNode {
7
- @Transform(schemaObjToInstance)
8
- readonly type: SchemaNode;
9
- @Transform(schemaObjArrayToInstances)
4
+ export class ParameterSchema<T extends SchemaNode = SchemaNode> extends SchemaNode {
5
+ readonly type: T;
10
6
  readonly objectBindingNodes?: SchemaNode[];
11
7
 
12
8
  constructor(
13
- readonly location: Location,
9
+ readonly location: SchemaLocation,
14
10
  readonly name: string,
15
- type: SchemaNode,
11
+ type: T,
16
12
  readonly isOptional: boolean,
17
13
  readonly defaultValue?: any,
18
14
  readonly description?: string,
19
- objectBindingNodes?: SchemaNode[]
15
+ objectBindingNodes?: SchemaNode[],
16
+ readonly isSpread: boolean = false
20
17
  ) {
21
18
  super();
22
19
  this.type = type;
23
20
  this.objectBindingNodes = objectBindingNodes;
21
+ this.isSpread = isSpread;
24
22
  }
25
23
 
26
24
  toString() {
27
25
  return `${this.name}${this.isOptional ? '?' : ''}: ${this.type.toString()}`;
28
26
  }
27
+
28
+ toObject() {
29
+ return {
30
+ ...super.toObject(),
31
+ name: this.name,
32
+ type: this.type.toObject(),
33
+ isOptional: this.isOptional,
34
+ defaultValue: this.defaultValue,
35
+ description: this.description,
36
+ objectBindingNodes: this.objectBindingNodes?.map((node) => node.toObject()),
37
+ isSpread: this.isSpread,
38
+ };
39
+ }
40
+
41
+ static fromObject<T extends SchemaNode = SchemaNode>(obj: Record<string, any>): ParameterSchema<T> {
42
+ const location = obj.location;
43
+ const name = obj.name;
44
+ const type = SchemaRegistry.fromObject(obj.type);
45
+ const isOptional = obj.isOptional;
46
+ const defaultValue = obj.defaultValue;
47
+ const description = obj.description;
48
+ const isSpread = obj.isSpread;
49
+ const objectBindingNodes = obj.objectBindingNodes?.map((node: any) => SchemaRegistry.fromObject(node));
50
+ return new ParameterSchema(
51
+ location,
52
+ name,
53
+ type,
54
+ isOptional,
55
+ defaultValue,
56
+ description,
57
+ objectBindingNodes,
58
+ isSpread
59
+ );
60
+ }
29
61
  }
@@ -1,20 +1,35 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  /**
6
5
  * type inside parentheses
7
6
  * e.g. (T1 | T2)
8
7
  */
9
8
  export class ParenthesizedTypeSchema extends SchemaNode {
10
- @Transform(schemaObjToInstance)
11
9
  readonly type: SchemaNode;
12
- constructor(readonly location: Location, type: SchemaNode) {
10
+ constructor(readonly location: SchemaLocation, type: SchemaNode) {
13
11
  super();
14
12
  this.type = type;
15
13
  }
16
14
 
15
+ getNodes() {
16
+ return [this.type];
17
+ }
18
+
17
19
  toString() {
18
20
  return `(${this.type.toString()})`;
19
21
  }
22
+
23
+ toObject() {
24
+ return {
25
+ ...super.toObject(),
26
+ type: this.type.toObject(),
27
+ };
28
+ }
29
+
30
+ static fromObject(obj: Record<string, any>): ParenthesizedTypeSchema {
31
+ const location = obj.location;
32
+ const type = SchemaRegistry.fromObject(obj.type);
33
+ return new ParenthesizedTypeSchema(location, type);
34
+ }
20
35
  }
@@ -1,16 +1,20 @@
1
- import { Transform } from 'class-transformer';
2
1
  import chalk from 'chalk';
3
- import { Location, SchemaNode } from '../schema-node';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
4
3
  import { ParameterSchema } from './parameter';
5
- import { schemaObjToInstance } from '../class-transformers';
6
4
 
7
5
  export class SetAccessorSchema extends SchemaNode {
8
- @Transform(schemaObjToInstance)
9
6
  readonly param: ParameterSchema;
10
- constructor(readonly location: Location, readonly name: string, param: ParameterSchema, readonly signature: string) {
7
+
8
+ constructor(
9
+ readonly location: SchemaLocation,
10
+ readonly name: string,
11
+ param: ParameterSchema,
12
+ readonly signature: string
13
+ ) {
11
14
  super();
12
15
  this.param = param;
13
16
  }
17
+
14
18
  getSignature() {
15
19
  return this.signature;
16
20
  }
@@ -18,4 +22,21 @@ export class SetAccessorSchema extends SchemaNode {
18
22
  toString() {
19
23
  return `set ${chalk.bold(this.name)}(${this.param.toString()})`;
20
24
  }
25
+
26
+ toObject() {
27
+ return {
28
+ ...super.toObject(),
29
+ name: this.name,
30
+ param: this.param.toObject(),
31
+ signature: this.signature,
32
+ };
33
+ }
34
+
35
+ static fromObject(obj: Record<string, any>): SetAccessorSchema {
36
+ const location = obj.location;
37
+ const name = obj.name;
38
+ const param = ParameterSchema.fromObject(obj.param);
39
+ const signature = obj.signature;
40
+ return new SetAccessorSchema(location, name, param, signature);
41
+ }
21
42
  }
@@ -1,16 +1,34 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  export class TemplateLiteralTypeSpanSchema extends SchemaNode {
6
- @Transform(schemaObjToInstance)
7
5
  type: SchemaNode;
8
- constructor(readonly location: Location, readonly literal: string, type: SchemaNode) {
6
+
7
+ constructor(readonly location: SchemaLocation, readonly literal: string, type: SchemaNode) {
9
8
  super();
10
9
  this.type = type;
11
10
  }
12
11
 
12
+ getNodes() {
13
+ return [this.type];
14
+ }
15
+
13
16
  toString() {
14
17
  return `${this.type.toString()} ${this.literal}`;
15
18
  }
19
+
20
+ toObject() {
21
+ return {
22
+ ...super.toObject(),
23
+ literal: this.literal,
24
+ type: this.type.toObject(),
25
+ };
26
+ }
27
+
28
+ static fromObject(obj: Record<string, any>): TemplateLiteralTypeSpanSchema {
29
+ const location = obj.location;
30
+ const literal = obj.literal;
31
+ const type = SchemaRegistry.fromObject(obj.type);
32
+ return new TemplateLiteralTypeSpanSchema(location, literal, type);
33
+ }
16
34
  }
@@ -1,12 +1,14 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjArrayToInstances } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
4
2
  import { TemplateLiteralTypeSpanSchema } from './template-literal-type-span';
5
3
 
6
4
  export class TemplateLiteralTypeSchema extends SchemaNode {
7
- @Transform(schemaObjArrayToInstances)
8
5
  readonly templateSpans: TemplateLiteralTypeSpanSchema[];
9
- constructor(readonly location: Location, readonly head: string, templateSpans: TemplateLiteralTypeSpanSchema[]) {
6
+
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly head: string,
10
+ templateSpans: TemplateLiteralTypeSpanSchema[]
11
+ ) {
10
12
  super();
11
13
  this.templateSpans = templateSpans;
12
14
  }
@@ -15,4 +17,19 @@ export class TemplateLiteralTypeSchema extends SchemaNode {
15
17
  const spans = this.templateSpans.map((span) => span.toString()).join('');
16
18
  return `${this.head}${spans}`;
17
19
  }
20
+
21
+ toObject() {
22
+ return {
23
+ ...super.toObject(),
24
+ head: this.head,
25
+ templateSpans: this.templateSpans.map((span) => span.toObject()),
26
+ };
27
+ }
28
+
29
+ static fromObject(obj: Record<string, any>): TemplateLiteralTypeSchema {
30
+ const location = obj.location;
31
+ const head = obj.head;
32
+ const templateSpans = obj.templateSpans.map((span: any) => TemplateLiteralTypeSpanSchema.fromObject(span));
33
+ return new TemplateLiteralTypeSchema(location, head, templateSpans);
34
+ }
18
35
  }
@@ -1,14 +1,19 @@
1
- import { Location, SchemaNode } from '../schema-node';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
2
 
3
3
  /**
4
4
  * e.g. `class A { createA(): this {} }`
5
5
  */
6
6
  export class ThisTypeSchema extends SchemaNode {
7
- constructor(readonly location: Location) {
7
+ constructor(readonly location: SchemaLocation) {
8
8
  super();
9
9
  }
10
10
 
11
11
  toString() {
12
12
  return 'this';
13
13
  }
14
+
15
+ static fromObject(obj: Record<string, any>): ThisTypeSchema {
16
+ const location = obj.location;
17
+ return new ThisTypeSchema(location);
18
+ }
14
19
  }
@@ -1,11 +1,10 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjArrayToInstances } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  export class TupleTypeSchema extends SchemaNode {
6
- @Transform(schemaObjArrayToInstances)
7
5
  readonly elements: SchemaNode[];
8
- constructor(readonly location: Location, elements: SchemaNode[]) {
6
+
7
+ constructor(readonly location: SchemaLocation, elements: SchemaNode[]) {
9
8
  super();
10
9
  this.elements = elements;
11
10
  }
@@ -13,4 +12,17 @@ export class TupleTypeSchema extends SchemaNode {
13
12
  toString() {
14
13
  return `[${this.elements.map((elem) => elem.toString()).join(', ')}]`;
15
14
  }
15
+
16
+ toObject() {
17
+ return {
18
+ ...super.toObject(),
19
+ elements: this.elements.map((elem) => elem.toObject()),
20
+ };
21
+ }
22
+
23
+ static fromObject(obj: Record<string, any>): TupleTypeSchema {
24
+ const location = obj.location;
25
+ const elements = obj.elements.map((elem: any) => SchemaRegistry.fromObject(elem));
26
+ return new TupleTypeSchema(location, elements);
27
+ }
16
28
  }
@@ -1,16 +1,32 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  export class TypeArraySchema extends SchemaNode {
6
- @Transform(schemaObjToInstance)
7
5
  readonly type: SchemaNode;
8
- constructor(readonly location: Location, type: SchemaNode) {
6
+
7
+ constructor(readonly location: SchemaLocation, type: SchemaNode) {
9
8
  super();
10
9
  this.type = type;
11
10
  }
12
11
 
12
+ getNodes() {
13
+ return [this.type];
14
+ }
15
+
13
16
  toString() {
14
17
  return `${this.type.toString()}[]`;
15
18
  }
19
+
20
+ toObject() {
21
+ return {
22
+ ...super.toObject(),
23
+ type: this.type.toObject(),
24
+ };
25
+ }
26
+
27
+ static fromObject(obj: Record<string, any>): TypeArraySchema {
28
+ const location = obj.location;
29
+ const type = SchemaRegistry.fromObject(obj.type);
30
+ return new TypeArraySchema(location, type);
31
+ }
16
32
  }
@@ -1,16 +1,32 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjArrayToInstances } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  export class TypeIntersectionSchema extends SchemaNode {
6
- @Transform(schemaObjArrayToInstances)
7
5
  readonly types: SchemaNode[];
8
- constructor(readonly location: Location, types: SchemaNode[]) {
6
+
7
+ constructor(readonly location: SchemaLocation, types: SchemaNode[]) {
9
8
  super();
10
9
  this.types = types;
11
10
  }
12
11
 
12
+ getNodes() {
13
+ return this.types;
14
+ }
15
+
13
16
  toString() {
14
17
  return `${this.types.map((type) => type.toString()).join(' & ')}`;
15
18
  }
19
+
20
+ toObject() {
21
+ return {
22
+ ...super.toObject(),
23
+ types: this.types.map((type) => type.toObject()),
24
+ };
25
+ }
26
+
27
+ static fromObject(obj: Record<string, any>): TypeIntersectionSchema {
28
+ const location = obj.location;
29
+ const types = obj.types.map((type: any) => SchemaRegistry.fromObject(type));
30
+ return new TypeIntersectionSchema(location, types);
31
+ }
16
32
  }
@@ -1,19 +1,35 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjArrayToInstances } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  /**
6
5
  * e.g. `{ a: string; b: number }`
7
6
  */
8
7
  export class TypeLiteralSchema extends SchemaNode {
9
- @Transform(schemaObjArrayToInstances)
10
8
  readonly members: SchemaNode[];
11
- constructor(readonly location: Location, members: SchemaNode[]) {
9
+
10
+ constructor(readonly location: SchemaLocation, members: SchemaNode[]) {
12
11
  super();
13
12
  this.members = members;
14
13
  }
15
14
 
15
+ getNodes() {
16
+ return this.members;
17
+ }
18
+
16
19
  toString() {
17
20
  return `{ ${this.members.map((type) => type.toString()).join('; ')} }`;
18
21
  }
22
+
23
+ toObject() {
24
+ return {
25
+ ...super.toObject(),
26
+ members: this.members.map((type) => type.toObject()),
27
+ };
28
+ }
29
+
30
+ static fromObject(obj: Record<string, any>): TypeLiteralSchema {
31
+ const location = obj.location;
32
+ const members = obj.members.map((type: any) => SchemaRegistry.fromObject(type));
33
+ return new TypeLiteralSchema(location, members);
34
+ }
19
35
  }
@@ -1,16 +1,33 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  export class TypeOperatorSchema extends SchemaNode {
6
- @Transform(schemaObjToInstance)
7
5
  type: SchemaNode;
8
- constructor(readonly location: Location, readonly name: string, type: SchemaNode) {
6
+ constructor(readonly location: SchemaLocation, readonly name: string, type: SchemaNode) {
9
7
  super();
10
8
  this.type = type;
11
9
  }
12
10
 
11
+ getNodes() {
12
+ return [this.type];
13
+ }
14
+
13
15
  toString() {
14
16
  return `${this.name} ${this.type.toString()}`;
15
17
  }
18
+
19
+ toObject() {
20
+ return {
21
+ ...super.toObject(),
22
+ name: this.name,
23
+ type: this.type.toObject(),
24
+ };
25
+ }
26
+
27
+ static fromObject(obj: Record<string, any>): TypeOperatorSchema {
28
+ const location = obj.location;
29
+ const name = obj.name;
30
+ const type = SchemaRegistry.fromObject(obj.type);
31
+ return new TypeOperatorSchema(location, name, type);
32
+ }
16
33
  }
@@ -1,6 +1,5 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  /**
6
5
  * e.g. `function f(str: any): str is string {}`
@@ -16,10 +15,9 @@ import { schemaObjToInstance } from '../class-transformers';
16
15
  *
17
16
  */
18
17
  export class TypePredicateSchema extends SchemaNode {
19
- @Transform(schemaObjToInstance)
20
18
  readonly type?: SchemaNode;
21
19
  constructor(
22
- readonly location: Location,
20
+ readonly location: SchemaLocation,
23
21
  readonly name: string,
24
22
  type?: SchemaNode,
25
23
  readonly hasAssertsModifier = false
@@ -33,4 +31,21 @@ export class TypePredicateSchema extends SchemaNode {
33
31
  const typeStr = this.type ? ` is ${this.type.toString()}` : '';
34
32
  return assertsKeyword + this.name + typeStr;
35
33
  }
34
+
35
+ toObject() {
36
+ return {
37
+ ...super.toObject(),
38
+ name: this.name,
39
+ type: this.type?.toObject(),
40
+ hasAssertsModifier: this.hasAssertsModifier,
41
+ };
42
+ }
43
+
44
+ static fromObject(obj: Record<string, any>): TypePredicateSchema {
45
+ const location = obj.location;
46
+ const name = obj.name;
47
+ const type = obj.type ? SchemaRegistry.fromObject(obj.type) : undefined;
48
+ const hasAssertsModifier = obj.hasAssertsModifier;
49
+ return new TypePredicateSchema(location, name, type, hasAssertsModifier);
50
+ }
36
51
  }
@@ -1,17 +1,21 @@
1
- import { Transform } from 'class-transformer';
2
- import { Location, SchemaNode } from '../schema-node';
3
- import { schemaObjToInstance } from '../class-transformers';
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
4
3
 
5
4
  /**
6
5
  * e.g. `typeof Foo`
7
6
  */
8
7
  export class TypeQuerySchema extends SchemaNode {
9
- @Transform(schemaObjToInstance)
10
8
  readonly type: SchemaNode;
11
- constructor(readonly location: Location, type: SchemaNode, readonly signature: string) {
9
+
10
+ constructor(readonly location: SchemaLocation, type: SchemaNode, readonly signature: string) {
12
11
  super();
13
12
  this.type = type;
14
13
  }
14
+
15
+ getNodes() {
16
+ return [this.type];
17
+ }
18
+
15
19
  getSignature() {
16
20
  return this.signature;
17
21
  }
@@ -19,4 +23,19 @@ export class TypeQuerySchema extends SchemaNode {
19
23
  toString() {
20
24
  return `typeof ${this.type.toString()}`;
21
25
  }
26
+
27
+ toObject() {
28
+ return {
29
+ ...super.toObject(),
30
+ type: this.type.toObject(),
31
+ signature: this.signature,
32
+ };
33
+ }
34
+
35
+ static fromObject(obj: Record<string, any>): TypeQuerySchema {
36
+ const location = obj.location;
37
+ const type = SchemaRegistry.fromObject(obj.type);
38
+ const signature = obj.signature;
39
+ return new TypeQuerySchema(location, type, signature);
40
+ }
22
41
  }
@@ -1,9 +1,7 @@
1
- import { Transform } from 'class-transformer';
2
1
  import { ComponentID } from '@teambit/component';
3
2
  import chalk from 'chalk';
4
- import { Location, SchemaNode } from '../schema-node';
5
- import { schemaObjArrayToInstances } from '../class-transformers';
6
- import { componentIdTransformer } from '../class-transformers/comp-id-transformer';
3
+ import { SchemaLocation, SchemaNode } from '../schema-node';
4
+ import { SchemaRegistry } from '../schema-registry';
7
5
 
8
6
  export type PlainTypeRefSchema = {
9
7
  name: string;
@@ -19,38 +17,41 @@ export type PlainTypeRefSchema = {
19
17
  * 4. a reference to a package.
20
18
  */
21
19
  export class TypeRefSchema extends SchemaNode {
22
- @Transform(schemaObjArrayToInstances)
23
20
  /**
24
21
  * optional type arguments, e.g. type Foo = Bar<X, Y>. The X and Y are type arguments.
25
22
  */
26
23
  typeArgs?: SchemaNode[];
27
24
 
28
- @Transform(componentIdTransformer)
29
25
  readonly componentId?: ComponentID;
30
26
 
31
27
  constructor(
32
- readonly location: Location,
28
+ readonly location: SchemaLocation,
33
29
  /**
34
30
  * name of the reference to type.
35
31
  */
36
32
  readonly name: string,
37
-
38
33
  /**
39
34
  * target component id. existing if the type is defined in another component.
40
35
  */
41
36
  componentId?: ComponentID,
42
-
43
37
  /**
44
38
  * target package name. existing if type is defined in different package.
45
39
  */
46
40
  readonly packageName?: string,
47
-
41
+ /**
42
+ * if the reference is not exported from the component, it can be internal to the file.
43
+ */
48
44
  readonly internalFilePath?: string
49
45
  ) {
50
46
  super();
51
47
  this.componentId = componentId;
52
48
  }
53
49
 
50
+ withTypeArgs(typeArgs: SchemaNode[]) {
51
+ this.typeArgs = typeArgs;
52
+ return this;
53
+ }
54
+
54
55
  toString() {
55
56
  const name = this.nameToString();
56
57
  if (!this.typeArgs) {
@@ -78,4 +79,44 @@ export class TypeRefSchema extends SchemaNode {
78
79
  isFromThisComponent() {
79
80
  return !this.componentId && !this.packageName;
80
81
  }
82
+
83
+ /**
84
+ * whether this type is internal to the file.
85
+ */
86
+ isInternalReference() {
87
+ return !!this.internalFilePath && this.isFromThisComponent();
88
+ }
89
+
90
+ /**
91
+ * whether this type is exported from this component.
92
+ */
93
+ isExported() {
94
+ return this.isFromThisComponent() && !this.isInternalReference();
95
+ }
96
+
97
+ toObject() {
98
+ return {
99
+ ...super.toObject(),
100
+ name: this.name,
101
+ componentId: this.componentId ? this.componentId.toObject() : undefined,
102
+ packageName: this.packageName,
103
+ internalFilePath: this.internalFilePath,
104
+ typeArgs: this.typeArgs?.map((type) => type.toObject()),
105
+ };
106
+ }
107
+
108
+ static fromObject(obj: Record<string, any>): TypeRefSchema {
109
+ const location = obj.location;
110
+ const name = obj.name;
111
+ let componentId;
112
+ try {
113
+ componentId = obj.componentId ? ComponentID.fromObject(obj.componentId) : undefined;
114
+ } catch (e) {
115
+ componentId = undefined;
116
+ }
117
+ const packageName = obj.packageName;
118
+ const internalFilePath = obj.internalFilePath;
119
+ const typeArgs = obj.typeArgs?.map((type: any) => SchemaRegistry.fromObject(type));
120
+ return new TypeRefSchema(location, name, componentId, packageName, internalFilePath).withTypeArgs(typeArgs);
121
+ }
81
122
  }