@teambit/semantics.entities.semantic-schema 0.0.10 → 0.0.13

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 (134) hide show
  1. package/api-schema.ts +18 -22
  2. package/dist/api-schema.d.ts +6 -19
  3. package/dist/api-schema.js +22 -12
  4. package/dist/api-schema.js.map +1 -1
  5. package/dist/{schemas/export.d.ts → export.d.ts} +5 -10
  6. package/dist/{schemas/export.js → export.js} +4 -5
  7. package/dist/export.js.map +1 -0
  8. package/dist/index.d.ts +2 -1
  9. package/dist/index.js +7 -2
  10. package/dist/index.js.map +1 -1
  11. package/dist/schema-node.d.ts +9 -8
  12. package/dist/schema-node.js +16 -0
  13. package/dist/schema-node.js.map +1 -1
  14. package/dist/schema-obj-to-class.d.ts +10 -0
  15. package/dist/schema-obj-to-class.js +56 -0
  16. package/dist/schema-obj-to-class.js.map +1 -0
  17. package/dist/schemas/class.d.ts +2 -9
  18. package/dist/schemas/class.js +15 -9
  19. package/dist/schemas/class.js.map +1 -1
  20. package/dist/schemas/constructor.d.ts +4 -15
  21. package/dist/schemas/constructor.js +16 -8
  22. package/dist/schemas/constructor.js.map +1 -1
  23. package/dist/schemas/enum.d.ts +8 -0
  24. package/dist/schemas/enum.js +21 -0
  25. package/dist/schemas/enum.js.map +1 -1
  26. package/dist/schemas/function-like.d.ts +10 -18
  27. package/dist/schemas/function-like.js +30 -20
  28. package/dist/schemas/function-like.js.map +1 -1
  29. package/dist/schemas/get-accessor.d.ts +7 -14
  30. package/dist/schemas/get-accessor.js +17 -11
  31. package/dist/schemas/get-accessor.js.map +1 -1
  32. package/dist/schemas/index-signature.d.ts +6 -12
  33. package/dist/schemas/index-signature.js +19 -9
  34. package/dist/schemas/index-signature.js.map +1 -1
  35. package/dist/schemas/index.d.ts +4 -1
  36. package/dist/schemas/index.js +9 -3
  37. package/dist/schemas/index.js.map +1 -1
  38. package/dist/schemas/indexed-access-type.d.ts +8 -0
  39. package/dist/schemas/indexed-access-type.js +31 -0
  40. package/dist/schemas/indexed-access-type.js.map +1 -0
  41. package/dist/schemas/inference-type.d.ts +6 -8
  42. package/dist/schemas/inference-type.js +9 -8
  43. package/dist/schemas/inference-type.js.map +1 -1
  44. package/dist/schemas/interface.d.ts +6 -12
  45. package/dist/schemas/interface.js +16 -9
  46. package/dist/schemas/interface.js.map +1 -1
  47. package/dist/schemas/keyword-type.d.ts +4 -7
  48. package/dist/schemas/keyword-type.js +5 -8
  49. package/dist/schemas/keyword-type.js.map +1 -1
  50. package/dist/schemas/literal-type.d.ts +5 -4
  51. package/dist/schemas/literal-type.js +5 -2
  52. package/dist/schemas/literal-type.js.map +1 -1
  53. package/dist/schemas/module.d.ts +5 -8
  54. package/dist/schemas/module.js +16 -6
  55. package/dist/schemas/module.js.map +1 -1
  56. package/dist/schemas/parameter.d.ts +5 -13
  57. package/dist/schemas/parameter.js +17 -12
  58. package/dist/schemas/parameter.js.map +1 -1
  59. package/dist/schemas/parenthesized-type.d.ts +11 -0
  60. package/dist/schemas/parenthesized-type.js +31 -0
  61. package/dist/schemas/parenthesized-type.js.map +1 -0
  62. package/dist/schemas/set-accessor.d.ts +7 -12
  63. package/dist/schemas/set-accessor.js +17 -11
  64. package/dist/schemas/set-accessor.js.map +1 -1
  65. package/dist/schemas/tuple-type.d.ts +5 -10
  66. package/dist/schemas/tuple-type.js +16 -8
  67. package/dist/schemas/tuple-type.js.map +1 -1
  68. package/dist/schemas/type-array.d.ts +5 -10
  69. package/dist/schemas/type-array.js +16 -8
  70. package/dist/schemas/type-array.js.map +1 -1
  71. package/dist/schemas/type-intersection.d.ts +5 -10
  72. package/dist/schemas/type-intersection.js +16 -8
  73. package/dist/schemas/type-intersection.js.map +1 -1
  74. package/dist/schemas/type-literal.d.ts +5 -10
  75. package/dist/schemas/type-literal.js +16 -8
  76. package/dist/schemas/type-literal.js.map +1 -1
  77. package/dist/schemas/type-operator.d.ts +6 -12
  78. package/dist/schemas/type-operator.js +16 -9
  79. package/dist/schemas/type-operator.js.map +1 -1
  80. package/dist/schemas/type-predicate.d.ts +22 -0
  81. package/dist/schemas/type-predicate.js +44 -0
  82. package/dist/schemas/type-predicate.js.map +1 -0
  83. package/dist/schemas/type-query.d.ts +6 -10
  84. package/dist/schemas/type-query.js +17 -10
  85. package/dist/schemas/type-query.js.map +1 -1
  86. package/dist/schemas/type-ref.d.ts +15 -10
  87. package/dist/schemas/type-ref.js +34 -16
  88. package/dist/schemas/type-ref.js.map +1 -1
  89. package/dist/schemas/type-union.d.ts +5 -10
  90. package/dist/schemas/type-union.js +16 -8
  91. package/dist/schemas/type-union.js.map +1 -1
  92. package/dist/schemas/type.d.ts +7 -14
  93. package/dist/schemas/type.js +17 -11
  94. package/dist/schemas/type.js.map +1 -1
  95. package/dist/schemas/variable.d.ts +9 -14
  96. package/dist/schemas/variable.js +19 -13
  97. package/dist/schemas/variable.js.map +1 -1
  98. package/{schemas/export.ts → export.ts} +5 -8
  99. package/index.ts +5 -2
  100. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.13.tgz +0 -0
  101. package/package.json +6 -3
  102. package/{preview-1652757984397.js → preview-1653449228788.js} +1 -1
  103. package/schema-node.ts +13 -6
  104. package/schema-obj-to-class.ts +36 -0
  105. package/schemas/class.ts +8 -9
  106. package/schemas/constructor.ts +10 -10
  107. package/schemas/enum.ts +13 -0
  108. package/schemas/function-like.ts +36 -23
  109. package/schemas/get-accessor.ts +10 -12
  110. package/schemas/index-signature.ts +13 -9
  111. package/schemas/index.ts +4 -1
  112. package/schemas/indexed-access-type.ts +18 -0
  113. package/schemas/inference-type.ts +7 -9
  114. package/schemas/interface.ts +10 -9
  115. package/schemas/keyword-type.ts +4 -9
  116. package/schemas/literal-type.ts +5 -3
  117. package/schemas/module.ts +9 -7
  118. package/schemas/parameter.ts +12 -13
  119. package/schemas/parenthesized-type.ts +20 -0
  120. package/schemas/set-accessor.ts +10 -12
  121. package/schemas/tuple-type.ts +10 -8
  122. package/schemas/type-array.ts +10 -8
  123. package/schemas/type-intersection.ts +10 -8
  124. package/schemas/type-literal.ts +10 -8
  125. package/schemas/type-operator.ts +10 -9
  126. package/schemas/type-predicate.ts +36 -0
  127. package/schemas/type-query.ts +10 -11
  128. package/schemas/type-ref.ts +39 -20
  129. package/schemas/type-union.ts +9 -8
  130. package/schemas/type.ts +10 -10
  131. package/schemas/variable.ts +12 -14
  132. package/tsconfig.json +1 -0
  133. package/dist/schemas/export.js.map +0 -1
  134. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.10.tgz +0 -0
@@ -1,6 +1,8 @@
1
+ import { Transform } from 'class-transformer';
1
2
  import { ComponentID } from '@teambit/component';
2
3
  import chalk from 'chalk';
3
- import { SchemaNode } from '../schema-node';
4
+ import { Location, SchemaNode } from '../schema-node';
5
+ import { schemaObjArrayToInstances } from '../schema-obj-to-class';
4
6
 
5
7
  export type PlainTypeRefSchema = {
6
8
  name: string;
@@ -8,8 +10,21 @@ export type PlainTypeRefSchema = {
8
10
  packageName?: string;
9
11
  };
10
12
 
11
- export class TypeRefSchema implements SchemaNode {
13
+ /**
14
+ * can be one of the following:
15
+ * 1. a reference to another "export" in the same component
16
+ * 2. a reference to another component.
17
+ * 3. a reference to a package.
18
+ */
19
+ export class TypeRefSchema extends SchemaNode {
20
+ @Transform(schemaObjArrayToInstances)
21
+ /**
22
+ * optional type arguments, e.g. type Foo = Bar<X, Y>. The X and Y are type arguments.
23
+ */
24
+ typeArgs?: SchemaNode[];
25
+
12
26
  constructor(
27
+ readonly location: Location,
13
28
  /**
14
29
  * name of the reference to type.
15
30
  */
@@ -24,23 +39,27 @@ export class TypeRefSchema implements SchemaNode {
24
39
  * target package name. existing if type is defined in different package.
25
40
  */
26
41
  readonly packageName?: string
27
- ) {}
28
-
29
- toObject() {
30
- return {
31
- constructorName: this.constructor.name,
32
- name: this.name,
33
- componentId: this.componentId,
34
- packageName: this.packageName,
35
- };
42
+ ) {
43
+ super();
36
44
  }
37
45
 
38
46
  toString() {
47
+ const name = this.nameToString();
48
+ if (!this.typeArgs) {
49
+ return name;
50
+ }
51
+ const args = this.typeArgs.map((arg) => arg.toString()).join(', ');
52
+ return `${name}<${args}>`;
53
+ }
54
+
55
+ private nameToString() {
39
56
  if (this.componentId) {
40
- return `${this.componentId}/${this.name}`;
57
+ const compStr = chalk.dim(`(component: ${this.componentId.toStringWithoutVersion()})`);
58
+ return `${compStr} ${this.name}`;
41
59
  }
42
60
  if (this.packageName) {
43
- return `${chalk.dim(this.packageName)}/${this.name}`;
61
+ const pkgStr = chalk.dim(`(package: ${this.packageName})`);
62
+ return `${pkgStr} ${this.name}`;
44
63
  }
45
64
  return this.name;
46
65
  }
@@ -52,11 +71,11 @@ export class TypeRefSchema implements SchemaNode {
52
71
  return !this.componentId && !this.packageName;
53
72
  }
54
73
 
55
- static from(plainSchema: PlainTypeRefSchema) {
56
- return new TypeRefSchema(
57
- plainSchema.name,
58
- plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
59
- plainSchema.packageName
60
- );
61
- }
74
+ // static from(plainSchema: PlainTypeRefSchema) {
75
+ // return new TypeRefSchema(
76
+ // plainSchema.name,
77
+ // plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
78
+ // plainSchema.packageName
79
+ // );
80
+ // }
62
81
  }
@@ -1,12 +1,13 @@
1
- import { SchemaNode } from '../schema-node';
1
+ import { Transform } from 'class-transformer';
2
+ import { Location, SchemaNode } from '../schema-node';
3
+ import { schemaObjArrayToInstances } from '../schema-obj-to-class';
2
4
 
3
- export class TypeUnionSchema implements SchemaNode {
4
- constructor(private types: SchemaNode[]) {}
5
- toObject() {
6
- return {
7
- constructorName: this.constructor.name,
8
- types: this.types.map((type) => type.toObject()),
9
- };
5
+ export class TypeUnionSchema extends SchemaNode {
6
+ @Transform(schemaObjArrayToInstances)
7
+ readonly types: SchemaNode[];
8
+ constructor(readonly location: Location, types: SchemaNode[]) {
9
+ super();
10
+ this.types = types;
10
11
  }
11
12
  toString() {
12
13
  return `${this.types.map((type) => type.toString()).join(' | ')}`;
package/schemas/type.ts CHANGED
@@ -1,16 +1,16 @@
1
+ import { Transform } from 'class-transformer';
1
2
  import chalk from 'chalk';
2
- import { SchemaNode } from '../schema-node';
3
+ import { Location, SchemaNode } from '../schema-node';
4
+ import { schemaObjToInstance } from '../schema-obj-to-class';
3
5
 
4
- export class TypeSchema implements SchemaNode {
5
- constructor(private name: string, private type: SchemaNode, private signature: string) {}
6
- toObject() {
7
- return {
8
- constructorName: this.constructor.name,
9
- name: this.name,
10
- type: this.type.toObject(),
11
- signature: this.signature,
12
- };
6
+ export class TypeSchema extends SchemaNode {
7
+ @Transform(schemaObjToInstance)
8
+ readonly type: SchemaNode;
9
+ constructor(readonly location: Location, readonly name: string, type: SchemaNode, readonly signature: string) {
10
+ super();
11
+ this.type = type;
13
12
  }
13
+
14
14
  toString() {
15
15
  return `${chalk.bold(this.name)}: ${this.type.toString()}`;
16
16
  }
@@ -1,19 +1,17 @@
1
+ import { Transform } from 'class-transformer';
1
2
  import chalk from 'chalk';
2
- import { SchemaNode } from '../schema-node';
3
+ import { Location, SchemaNode } from '../schema-node';
4
+ import { schemaObjToInstance } from '../schema-obj-to-class';
3
5
 
4
- export class VariableSchema implements SchemaNode {
5
- constructor(readonly name: string, private signature: string, private type: SchemaNode) {}
6
- getSignature() {
7
- return this.signature;
8
- }
9
-
10
- toObject() {
11
- return {
12
- constructorName: this.constructor.name,
13
- name: this.name,
14
- signature: this.signature,
15
- type: this.type.toObject(),
16
- };
6
+ /**
7
+ * can be also a property.
8
+ */
9
+ export class VariableSchema extends SchemaNode {
10
+ @Transform(schemaObjToInstance)
11
+ type: SchemaNode;
12
+ constructor(readonly location: Location, readonly name: string, readonly signature: string, type: SchemaNode) {
13
+ super();
14
+ this.type = type;
17
15
  }
18
16
 
19
17
  toString() {
package/tsconfig.json CHANGED
@@ -14,6 +14,7 @@
14
14
  "declaration": true,
15
15
  "sourceMap": true,
16
16
  "skipLibCheck": true,
17
+ "experimentalDecorators": true,
17
18
  "outDir": "dist",
18
19
  "moduleResolution": "node",
19
20
  "esModuleInterop": true,
@@ -1 +0,0 @@
1
- {"version":3,"file":"export.js","sourceRoot":"","sources":["../../schemas/export.ts"],"names":[],"mappings":";;;AAKA,MAAa,MAAM;IACjB;IACE;;OAEG;IACM,UAAkB;IAE3B;;OAEG;IACM,KAAoB;IAE7B;;;;;;OAMG;IACM,gBAAmC;QAdnC,eAAU,GAAV,UAAU,CAAQ;QAKlB,UAAK,GAAL,KAAK,CAAe;QASpB,qBAAgB,GAAhB,gBAAgB,CAAmB;IAC3C,CAAC;IAEJ,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;IACJ,CAAC;CACF;AA5BD,wBA4BC"}