@teambit/semantics.entities.semantic-schema 0.0.7 → 0.0.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 (118) hide show
  1. package/api-schema.ts +64 -0
  2. package/dist/api-schema.d.ts +24 -0
  3. package/dist/api-schema.js +44 -0
  4. package/dist/api-schema.js.map +1 -0
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +23 -4
  7. package/dist/index.js.map +1 -1
  8. package/dist/schema-node.d.ts +11 -5
  9. package/dist/schemas/class.d.ts +15 -0
  10. package/dist/schemas/class.js +26 -0
  11. package/dist/schemas/class.js.map +1 -1
  12. package/dist/schemas/constructor.d.ts +19 -0
  13. package/dist/schemas/constructor.js +24 -0
  14. package/dist/schemas/constructor.js.map +1 -0
  15. package/dist/schemas/export.d.ts +7 -3
  16. package/dist/schemas/export.js +8 -2
  17. package/dist/schemas/export.js.map +1 -1
  18. package/dist/schemas/function-like.d.ts +26 -0
  19. package/dist/schemas/function-like.js +41 -0
  20. package/dist/schemas/function-like.js.map +1 -0
  21. package/dist/schemas/get-accessor.d.ts +17 -0
  22. package/dist/schemas/get-accessor.js +30 -0
  23. package/dist/schemas/get-accessor.js.map +1 -0
  24. package/dist/schemas/index-signature.d.ts +19 -0
  25. package/dist/schemas/index-signature.js +26 -0
  26. package/dist/schemas/index-signature.js.map +1 -0
  27. package/dist/schemas/index.d.ts +20 -1
  28. package/dist/schemas/index.js +41 -3
  29. package/dist/schemas/index.js.map +1 -1
  30. package/dist/schemas/inference-type.d.ts +13 -0
  31. package/dist/schemas/inference-type.js +22 -0
  32. package/dist/schemas/inference-type.js.map +1 -0
  33. package/dist/schemas/interface.d.ts +14 -0
  34. package/dist/schemas/interface.js +26 -0
  35. package/dist/schemas/interface.js.map +1 -0
  36. package/dist/schemas/keyword-type.d.ts +13 -0
  37. package/dist/schemas/keyword-type.js +22 -0
  38. package/dist/schemas/keyword-type.js.map +1 -0
  39. package/dist/schemas/literal-type.d.ts +13 -0
  40. package/dist/schemas/literal-type.js +22 -0
  41. package/dist/schemas/literal-type.js.map +1 -0
  42. package/dist/schemas/module.d.ts +14 -10
  43. package/dist/schemas/module.js +33 -5
  44. package/dist/schemas/module.js.map +1 -1
  45. package/dist/schemas/parameter.d.ts +18 -0
  46. package/dist/schemas/parameter.js +25 -0
  47. package/dist/schemas/parameter.js.map +1 -0
  48. package/dist/schemas/set-accessor.d.ts +16 -0
  49. package/dist/schemas/set-accessor.js +30 -0
  50. package/dist/schemas/set-accessor.js.map +1 -0
  51. package/dist/schemas/tuple-type.d.ts +12 -0
  52. package/dist/schemas/tuple-type.js +19 -0
  53. package/dist/schemas/tuple-type.js.map +1 -0
  54. package/dist/schemas/type-array.d.ts +12 -0
  55. package/dist/schemas/type-array.js +19 -0
  56. package/dist/schemas/type-array.js.map +1 -0
  57. package/dist/schemas/type-intersection.d.ts +12 -0
  58. package/dist/schemas/type-intersection.js +19 -0
  59. package/dist/schemas/type-intersection.js.map +1 -0
  60. package/dist/schemas/type-literal.d.ts +15 -0
  61. package/dist/schemas/type-literal.js +22 -0
  62. package/dist/schemas/type-literal.js.map +1 -0
  63. package/dist/schemas/type-operator.d.ts +14 -0
  64. package/dist/schemas/type-operator.js +21 -0
  65. package/dist/schemas/type-operator.js.map +1 -0
  66. package/dist/schemas/type-query.d.ts +16 -0
  67. package/dist/schemas/type-query.js +27 -0
  68. package/dist/schemas/type-query.js.map +1 -0
  69. package/dist/schemas/type-ref.d.ts +12 -3
  70. package/dist/schemas/type-ref.js +29 -3
  71. package/dist/schemas/type-ref.js.map +1 -1
  72. package/dist/schemas/type-union.d.ts +12 -0
  73. package/dist/schemas/type-union.js +19 -0
  74. package/dist/schemas/type-union.js.map +1 -0
  75. package/dist/schemas/type.d.ts +16 -0
  76. package/dist/schemas/type.js +26 -0
  77. package/dist/schemas/type.js.map +1 -1
  78. package/dist/schemas/variable.d.ts +17 -0
  79. package/dist/schemas/variable.js +30 -0
  80. package/dist/schemas/variable.js.map +1 -0
  81. package/index.ts +29 -3
  82. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.10.tgz +0 -0
  83. package/package.json +3 -2
  84. package/{preview-1650468178717.js → preview-1652757984397.js} +1 -1
  85. package/schema-node.ts +7 -5
  86. package/schemas/class.ts +19 -0
  87. package/schemas/constructor.ts +19 -0
  88. package/schemas/export.ts +9 -2
  89. package/schemas/function-like.ts +43 -0
  90. package/schemas/get-accessor.ts +22 -0
  91. package/schemas/index-signature.ts +21 -0
  92. package/schemas/index.ts +20 -1
  93. package/schemas/inference-type.ts +19 -0
  94. package/schemas/interface.ts +17 -0
  95. package/schemas/keyword-type.ts +19 -0
  96. package/schemas/literal-type.ts +19 -0
  97. package/schemas/module.ts +36 -7
  98. package/schemas/parameter.ts +23 -0
  99. package/schemas/set-accessor.ts +23 -0
  100. package/schemas/tuple-type.ts +14 -0
  101. package/schemas/type-array.ts +14 -0
  102. package/schemas/type-intersection.ts +14 -0
  103. package/schemas/type-literal.ts +17 -0
  104. package/schemas/type-operator.ts +15 -0
  105. package/schemas/type-query.ts +23 -0
  106. package/schemas/type-ref.ts +29 -6
  107. package/schemas/type-union.ts +14 -0
  108. package/schemas/type.ts +17 -0
  109. package/schemas/variable.ts +22 -0
  110. package/dist/schemas/function.d.ts +0 -16
  111. package/dist/schemas/function.js +0 -16
  112. package/dist/schemas/function.js.map +0 -1
  113. package/dist/semantic-schema.d.ts +0 -12
  114. package/dist/semantic-schema.js +0 -17
  115. package/dist/semantic-schema.js.map +0 -1
  116. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.7.tgz +0 -0
  117. package/schemas/function.ts +0 -23
  118. package/semantic-schema.ts +0 -20
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TypeArraySchema implements SchemaNode {
4
+ constructor(private type: SchemaNode) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ type: this.type.toObject(),
9
+ };
10
+ }
11
+ toString() {
12
+ return `${this.type.toString()}[]`;
13
+ }
14
+ }
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TypeIntersectionSchema 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
+ };
10
+ }
11
+ toString() {
12
+ return `${this.types.map((type) => type.toString()).join(' & ')}`;
13
+ }
14
+ }
@@ -0,0 +1,17 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. `{ a: string; b: number }`
5
+ */
6
+ export class TypeLiteralSchema implements SchemaNode {
7
+ constructor(private members: SchemaNode[]) {}
8
+ toObject() {
9
+ return {
10
+ constructorName: this.constructor.name,
11
+ types: this.members.map((type) => type.toObject()),
12
+ };
13
+ }
14
+ toString() {
15
+ return `{ ${this.members.map((type) => type.toString()).join('; ')} }`;
16
+ }
17
+ }
@@ -0,0 +1,15 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TypeOperatorSchema implements SchemaNode {
4
+ constructor(private operatorName: string, private type: SchemaNode) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ operatorName: this.operatorName,
9
+ type: this.type.toObject(),
10
+ };
11
+ }
12
+ toString() {
13
+ return `${this.operatorName} ${this.type.toString()}`;
14
+ }
15
+ }
@@ -0,0 +1,23 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. `typeof Foo`
5
+ */
6
+ export class TypeQuerySchema implements SchemaNode {
7
+ constructor(private type: SchemaNode, private signature: string) {}
8
+ getSignature() {
9
+ return this.signature;
10
+ }
11
+
12
+ toObject() {
13
+ return {
14
+ constructorName: this.constructor.name,
15
+ type: this.type,
16
+ signature: this.signature,
17
+ };
18
+ }
19
+
20
+ toString() {
21
+ return `typeof ${this.type.toString()}`;
22
+ }
23
+ }
@@ -1,11 +1,11 @@
1
1
  import { ComponentID } from '@teambit/component';
2
+ import chalk from 'chalk';
2
3
  import { SchemaNode } from '../schema-node';
3
4
 
4
5
  export type PlainTypeRefSchema = {
5
6
  name: string;
6
7
  componentId?: string;
7
8
  packageName?: string;
8
- node?: SchemaNode;
9
9
  };
10
10
 
11
11
  export class TypeRefSchema implements SchemaNode {
@@ -23,17 +23,40 @@ export class TypeRefSchema implements SchemaNode {
23
23
  /**
24
24
  * target package name. existing if type is defined in different package.
25
25
  */
26
- readonly packageName?: string,
27
-
28
- readonly node?: SchemaNode
26
+ readonly packageName?: string
29
27
  ) {}
30
28
 
29
+ toObject() {
30
+ return {
31
+ constructorName: this.constructor.name,
32
+ name: this.name,
33
+ componentId: this.componentId,
34
+ packageName: this.packageName,
35
+ };
36
+ }
37
+
38
+ toString() {
39
+ if (this.componentId) {
40
+ return `${this.componentId}/${this.name}`;
41
+ }
42
+ if (this.packageName) {
43
+ return `${chalk.dim(this.packageName)}/${this.name}`;
44
+ }
45
+ return this.name;
46
+ }
47
+
48
+ /**
49
+ * whether this type was already exported in this component
50
+ */
51
+ isFromThisComponent() {
52
+ return !this.componentId && !this.packageName;
53
+ }
54
+
31
55
  static from(plainSchema: PlainTypeRefSchema) {
32
56
  return new TypeRefSchema(
33
57
  plainSchema.name,
34
58
  plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
35
- plainSchema.packageName,
36
- plainSchema.node
59
+ plainSchema.packageName
37
60
  );
38
61
  }
39
62
  }
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
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
+ };
10
+ }
11
+ toString() {
12
+ return `${this.types.map((type) => type.toString()).join(' | ')}`;
13
+ }
14
+ }
package/schemas/type.ts CHANGED
@@ -0,0 +1,17 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+
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
+ };
13
+ }
14
+ toString() {
15
+ return `${chalk.bold(this.name)}: ${this.type.toString()}`;
16
+ }
17
+ }
@@ -0,0 +1,22 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+
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
+ };
17
+ }
18
+
19
+ toString() {
20
+ return `${chalk.bold(this.name)}: ${this.type.toString()}`;
21
+ }
22
+ }
@@ -1,16 +0,0 @@
1
- import { SchemaNode } from '../schema-node';
2
- import { TypeRefSchema } from './type-ref';
3
- export declare type Argument = {
4
- name: string;
5
- defaultValue?: any;
6
- description: any;
7
- type: string;
8
- };
9
- export declare class FunctionSchema implements SchemaNode {
10
- readonly name: string;
11
- readonly args: Argument[];
12
- readonly returnType: TypeRefSchema;
13
- constructor(name: string, args: Argument[], returnType: TypeRefSchema);
14
- serialize(): void;
15
- toJsonSchema(): void;
16
- }
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FunctionSchema = void 0;
4
- class FunctionSchema {
5
- constructor(name,
6
- // readonly doc: any,
7
- args, returnType) {
8
- this.name = name;
9
- this.args = args;
10
- this.returnType = returnType;
11
- }
12
- serialize() { }
13
- toJsonSchema() { }
14
- }
15
- exports.FunctionSchema = FunctionSchema;
16
- //# sourceMappingURL=function.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"function.js","sourceRoot":"","sources":["../../schemas/function.ts"],"names":[],"mappings":";;;AAUA,MAAa,cAAc;IACzB,YACW,IAAY;IACrB,qBAAqB;IACZ,IAAgB,EAEhB,UAAyB;QAJzB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,SAAI,GAAJ,IAAI,CAAY;QAEhB,eAAU,GAAV,UAAU,CAAe;IACjC,CAAC;IAEJ,SAAS,KAAI,CAAC;IAEd,YAAY,KAAI,CAAC;CAClB;AAZD,wCAYC"}
@@ -1,12 +0,0 @@
1
- import { Export } from './schemas';
2
- import { SchemaNode } from './schema-node';
3
- export declare type PlainSemanticSchema = {
4
- exports?: Export[];
5
- };
6
- export declare class SemanticSchema implements SchemaNode {
7
- readonly exports: Export[];
8
- constructor(exports?: Export[]);
9
- toString(): string;
10
- static fromSchema(): void;
11
- static from(plainSchema: PlainSemanticSchema): SemanticSchema;
12
- }
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SemanticSchema = void 0;
4
- class SemanticSchema {
5
- constructor(exports = []) {
6
- this.exports = exports;
7
- }
8
- toString() {
9
- return '';
10
- }
11
- static fromSchema() { }
12
- static from(plainSchema) {
13
- return new SemanticSchema(plainSchema.exports);
14
- }
15
- }
16
- exports.SemanticSchema = SemanticSchema;
17
- //# sourceMappingURL=semantic-schema.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"semantic-schema.js","sourceRoot":"","sources":["../semantic-schema.ts"],"names":[],"mappings":";;;AAOA,MAAa,cAAc;IACzB,YAAqB,UAAoB,EAAE;QAAtB,YAAO,GAAP,OAAO,CAAe;IAAG,CAAC;IAE/C,QAAQ;QACN,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,CAAC,UAAU,KAAI,CAAC;IAEtB,MAAM,CAAC,IAAI,CAAC,WAAgC;QAC1C,OAAO,IAAI,cAAc,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,CAAC;CACF;AAZD,wCAYC"}
@@ -1,23 +0,0 @@
1
- import { SchemaNode } from '../schema-node';
2
- import { TypeRefSchema } from './type-ref';
3
-
4
- export type Argument = {
5
- name: string;
6
- defaultValue?: any;
7
- description: any;
8
- type: string;
9
- };
10
-
11
- export class FunctionSchema implements SchemaNode {
12
- constructor(
13
- readonly name: string,
14
- // readonly doc: any,
15
- readonly args: Argument[],
16
-
17
- readonly returnType: TypeRefSchema
18
- ) {}
19
-
20
- serialize() {}
21
-
22
- toJsonSchema() {}
23
- }
@@ -1,20 +0,0 @@
1
- import { Export } from './schemas';
2
- import { SchemaNode } from './schema-node';
3
-
4
- export type PlainSemanticSchema = {
5
- exports?: Export[];
6
- };
7
-
8
- export class SemanticSchema implements SchemaNode {
9
- constructor(readonly exports: Export[] = []) {}
10
-
11
- toString() {
12
- return '';
13
- }
14
-
15
- static fromSchema() {}
16
-
17
- static from(plainSchema: PlainSemanticSchema) {
18
- return new SemanticSchema(plainSchema.exports);
19
- }
20
- }