@teambit/semantics.entities.semantic-schema 0.0.8 → 0.0.11

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 (122) hide show
  1. package/api-schema.ts +17 -22
  2. package/dist/api-schema.d.ts +6 -19
  3. package/dist/api-schema.js +21 -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 +3 -2
  9. package/dist/index.js +12 -3
  10. package/dist/index.js.map +1 -1
  11. package/dist/schema-node.d.ts +14 -7
  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 +4 -10
  18. package/dist/schemas/class.js +16 -9
  19. package/dist/schemas/class.js.map +1 -1
  20. package/dist/schemas/constructor.d.ts +6 -9
  21. package/dist/schemas/constructor.js +19 -11
  22. package/dist/schemas/constructor.js.map +1 -1
  23. package/dist/schemas/function-like.d.ts +14 -0
  24. package/dist/schemas/function-like.js +45 -0
  25. package/dist/schemas/function-like.js.map +1 -0
  26. package/dist/schemas/get-accessor.d.ts +7 -18
  27. package/dist/schemas/get-accessor.js +17 -11
  28. package/dist/schemas/get-accessor.js.map +1 -1
  29. package/dist/schemas/index-signature.d.ts +7 -17
  30. package/dist/schemas/index-signature.js +22 -12
  31. package/dist/schemas/index-signature.js.map +1 -1
  32. package/dist/schemas/index.d.ts +9 -2
  33. package/dist/schemas/index.js +19 -5
  34. package/dist/schemas/index.js.map +1 -1
  35. package/dist/schemas/inference-type.d.ts +10 -0
  36. package/dist/schemas/inference-type.js +19 -0
  37. package/dist/schemas/inference-type.js.map +1 -0
  38. package/dist/schemas/interface.d.ts +6 -12
  39. package/dist/schemas/interface.js +16 -9
  40. package/dist/schemas/interface.js.map +1 -1
  41. package/dist/schemas/keyword-type.d.ts +10 -0
  42. package/dist/schemas/keyword-type.js +19 -0
  43. package/dist/schemas/keyword-type.js.map +1 -0
  44. package/dist/schemas/literal-type.d.ts +14 -0
  45. package/dist/schemas/literal-type.js +25 -0
  46. package/dist/schemas/literal-type.js.map +1 -0
  47. package/dist/schemas/module.d.ts +5 -8
  48. package/dist/schemas/module.js +16 -6
  49. package/dist/schemas/module.js.map +1 -1
  50. package/dist/schemas/parameter.d.ts +10 -0
  51. package/dist/schemas/parameter.js +30 -0
  52. package/dist/schemas/parameter.js.map +1 -0
  53. package/dist/schemas/set-accessor.d.ts +8 -13
  54. package/dist/schemas/set-accessor.js +18 -12
  55. package/dist/schemas/set-accessor.js.map +1 -1
  56. package/dist/schemas/tuple-type.d.ts +7 -0
  57. package/dist/schemas/tuple-type.js +27 -0
  58. package/dist/schemas/tuple-type.js.map +1 -0
  59. package/dist/schemas/type-array.d.ts +7 -0
  60. package/dist/schemas/type-array.js +27 -0
  61. package/dist/schemas/type-array.js.map +1 -0
  62. package/dist/schemas/type-intersection.d.ts +5 -10
  63. package/dist/schemas/type-intersection.js +16 -8
  64. package/dist/schemas/type-intersection.js.map +1 -1
  65. package/dist/schemas/type-literal.d.ts +5 -10
  66. package/dist/schemas/type-literal.js +16 -8
  67. package/dist/schemas/type-literal.js.map +1 -1
  68. package/dist/schemas/type-operator.d.ts +8 -0
  69. package/dist/schemas/type-operator.js +28 -0
  70. package/dist/schemas/type-operator.js.map +1 -0
  71. package/dist/schemas/type-query.d.ts +12 -0
  72. package/dist/schemas/type-query.js +34 -0
  73. package/dist/schemas/type-query.js.map +1 -0
  74. package/dist/schemas/type-ref.d.ts +9 -13
  75. package/dist/schemas/type-ref.js +11 -15
  76. package/dist/schemas/type-ref.js.map +1 -1
  77. package/dist/schemas/type-union.d.ts +5 -10
  78. package/dist/schemas/type-union.js +16 -8
  79. package/dist/schemas/type-union.js.map +1 -1
  80. package/dist/schemas/type.d.ts +7 -14
  81. package/dist/schemas/type.js +17 -11
  82. package/dist/schemas/type.js.map +1 -1
  83. package/dist/schemas/variable.d.ts +6 -18
  84. package/dist/schemas/variable.js +16 -13
  85. package/dist/schemas/variable.js.map +1 -1
  86. package/{schemas/export.ts → export.ts} +5 -8
  87. package/index.ts +12 -5
  88. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.11.tgz +0 -0
  89. package/package.json +7 -4
  90. package/{preview-1652239597845.js → preview-1652930732694.js} +1 -1
  91. package/schema-node.ts +15 -5
  92. package/schema-obj-to-class.ts +36 -0
  93. package/schemas/class.ts +9 -10
  94. package/schemas/constructor.ts +13 -13
  95. package/schemas/function-like.ts +40 -0
  96. package/schemas/get-accessor.ts +10 -13
  97. package/schemas/index-signature.ts +16 -13
  98. package/schemas/index.ts +9 -2
  99. package/schemas/inference-type.ts +14 -0
  100. package/schemas/interface.ts +10 -9
  101. package/schemas/keyword-type.ts +14 -0
  102. package/schemas/literal-type.ts +21 -0
  103. package/schemas/module.ts +9 -7
  104. package/schemas/parameter.ts +22 -0
  105. package/schemas/set-accessor.ts +12 -14
  106. package/schemas/tuple-type.ts +16 -0
  107. package/schemas/type-array.ts +16 -0
  108. package/schemas/type-intersection.ts +10 -8
  109. package/schemas/type-literal.ts +10 -8
  110. package/schemas/type-operator.ts +16 -0
  111. package/schemas/type-query.ts +22 -0
  112. package/schemas/type-ref.ts +19 -22
  113. package/schemas/type-union.ts +9 -8
  114. package/schemas/type.ts +10 -10
  115. package/schemas/variable.ts +9 -15
  116. package/tsconfig.json +1 -0
  117. package/dist/schemas/export.js.map +0 -1
  118. package/dist/schemas/function.d.ts +0 -31
  119. package/dist/schemas/function.js +0 -37
  120. package/dist/schemas/function.js.map +0 -1
  121. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.8.tgz +0 -0
  122. package/schemas/function.ts +0 -44
@@ -0,0 +1,16 @@
1
+ import { Transform } from 'class-transformer';
2
+ import { Location, SchemaNode } from '../schema-node';
3
+ import { schemaObjToInstance } from '../schema-obj-to-class';
4
+
5
+ export class TypeOperatorSchema extends SchemaNode {
6
+ @Transform(schemaObjToInstance)
7
+ type: SchemaNode;
8
+ constructor(readonly location: Location, readonly operatorName: string, type: SchemaNode) {
9
+ super();
10
+ this.type = type;
11
+ }
12
+
13
+ toString() {
14
+ return `${this.operatorName} ${this.type.toString()}`;
15
+ }
16
+ }
@@ -0,0 +1,22 @@
1
+ import { Transform } from 'class-transformer';
2
+ import { Location, SchemaNode } from '../schema-node';
3
+ import { schemaObjToInstance } from '../schema-obj-to-class';
4
+
5
+ /**
6
+ * e.g. `typeof Foo`
7
+ */
8
+ export class TypeQuerySchema extends SchemaNode {
9
+ @Transform(schemaObjToInstance)
10
+ readonly type: SchemaNode;
11
+ constructor(readonly location: Location, type: SchemaNode, readonly signature: string) {
12
+ super();
13
+ this.type = type;
14
+ }
15
+ getSignature() {
16
+ return this.signature;
17
+ }
18
+
19
+ toString() {
20
+ return `typeof ${this.type.toString()}`;
21
+ }
22
+ }
@@ -1,16 +1,16 @@
1
1
  import { ComponentID } from '@teambit/component';
2
2
  import chalk from 'chalk';
3
- import { SchemaNode } from '../schema-node';
3
+ import { Location, SchemaNode } from '../schema-node';
4
4
 
5
5
  export type PlainTypeRefSchema = {
6
6
  name: string;
7
7
  componentId?: string;
8
8
  packageName?: string;
9
- node?: SchemaNode;
10
9
  };
11
10
 
12
- export class TypeRefSchema implements SchemaNode {
11
+ export class TypeRefSchema extends SchemaNode {
13
12
  constructor(
13
+ readonly location: Location,
14
14
  /**
15
15
  * name of the reference to type.
16
16
  */
@@ -24,18 +24,9 @@ export class TypeRefSchema implements SchemaNode {
24
24
  /**
25
25
  * target package name. existing if type is defined in different package.
26
26
  */
27
- readonly packageName?: string,
28
-
29
- readonly node?: SchemaNode
30
- ) {}
31
-
32
- toObject() {
33
- return {
34
- constructorName: this.constructor.name,
35
- name: this.name,
36
- componentId: this.componentId,
37
- packageName: this.packageName,
38
- };
27
+ readonly packageName?: string
28
+ ) {
29
+ super();
39
30
  }
40
31
 
41
32
  toString() {
@@ -48,12 +39,18 @@ export class TypeRefSchema implements SchemaNode {
48
39
  return this.name;
49
40
  }
50
41
 
51
- static from(plainSchema: PlainTypeRefSchema) {
52
- return new TypeRefSchema(
53
- plainSchema.name,
54
- plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
55
- plainSchema.packageName,
56
- plainSchema.node
57
- );
42
+ /**
43
+ * whether this type was already exported in this component
44
+ */
45
+ isFromThisComponent() {
46
+ return !this.componentId && !this.packageName;
58
47
  }
48
+
49
+ // static from(plainSchema: PlainTypeRefSchema) {
50
+ // return new TypeRefSchema(
51
+ // plainSchema.name,
52
+ // plainSchema.componentId ? ComponentID.fromString(plainSchema.componentId) : undefined,
53
+ // plainSchema.packageName
54
+ // );
55
+ // }
59
56
  }
@@ -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,20 +1,14 @@
1
+ import { Transform } from 'class-transformer';
1
2
  import chalk from 'chalk';
2
- import { SchemaNode } from '../schema-node';
3
- import { TypeRefSchema } from './type-ref';
3
+ import { Location, SchemaNode } from '../schema-node';
4
+ import { schemaObjToInstance } from '../schema-obj-to-class';
4
5
 
5
- export class VariableSchema implements SchemaNode {
6
- constructor(readonly name: string, private signature: string, private type: TypeRefSchema) {}
7
- getSignature() {
8
- return this.signature;
9
- }
10
-
11
- toObject() {
12
- return {
13
- constructorName: this.constructor.name,
14
- name: this.name,
15
- signature: this.signature,
16
- type: this.type.toObject(),
17
- };
6
+ export class VariableSchema extends SchemaNode {
7
+ @Transform(schemaObjToInstance)
8
+ type: SchemaNode;
9
+ constructor(readonly location: Location, readonly name: string, readonly signature: string, type: SchemaNode) {
10
+ super();
11
+ this.type = type;
18
12
  }
19
13
 
20
14
  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"}
@@ -1,31 +0,0 @@
1
- import { SchemaNode } from '../schema-node';
2
- import { TypeRefSchema } from './type-ref';
3
- export declare type Parameter = {
4
- name: string;
5
- type: TypeRefSchema;
6
- defaultValue?: any;
7
- description?: string;
8
- };
9
- export declare class FunctionSchema implements SchemaNode {
10
- readonly name: string;
11
- readonly params: Parameter[];
12
- readonly returnType: TypeRefSchema;
13
- private signature;
14
- constructor(name: string, params: Parameter[], returnType: TypeRefSchema, signature: string);
15
- serialize(): void;
16
- toJsonSchema(): void;
17
- getSignature(): string;
18
- toObject(): {
19
- constructorName: string;
20
- name: string;
21
- params: Parameter[];
22
- returnType: {
23
- constructorName: string;
24
- name: string;
25
- componentId: import("@teambit/component").ComponentID;
26
- packageName: string;
27
- };
28
- signature: string;
29
- };
30
- toString(): string;
31
- }
@@ -1,37 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.FunctionSchema = void 0;
7
- const chalk_1 = __importDefault(require("chalk"));
8
- class FunctionSchema {
9
- constructor(name,
10
- // readonly doc: any,
11
- params, returnType, signature) {
12
- this.name = name;
13
- this.params = params;
14
- this.returnType = returnType;
15
- this.signature = signature;
16
- }
17
- serialize() { }
18
- toJsonSchema() { }
19
- getSignature() {
20
- return this.signature;
21
- }
22
- toObject() {
23
- return {
24
- constructorName: this.constructor.name,
25
- name: this.name,
26
- params: this.params,
27
- returnType: this.returnType.toObject(),
28
- signature: this.signature,
29
- };
30
- }
31
- toString() {
32
- const paramsStr = this.params.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
33
- return `${chalk_1.default.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
34
- }
35
- }
36
- exports.FunctionSchema = FunctionSchema;
37
- //# sourceMappingURL=function.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"function.js","sourceRoot":"","sources":["../../schemas/function.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAW1B,MAAa,cAAc;IACzB,YACW,IAAY;IACrB,qBAAqB;IACZ,MAAmB,EAEnB,UAAyB,EAC1B,SAAiB;QALhB,SAAI,GAAJ,IAAI,CAAQ;QAEZ,WAAM,GAAN,MAAM,CAAa;QAEnB,eAAU,GAAV,UAAU,CAAe;QAC1B,cAAS,GAAT,SAAS,CAAQ;IACxB,CAAC;IAEJ,SAAS,KAAI,CAAC;IAEd,YAAY,KAAI,CAAC;IAEjB,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtC,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7F,OAAO,GAAG,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,SAAS,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC;IACjF,CAAC;CACF;AAhCD,wCAgCC"}
@@ -1,44 +0,0 @@
1
- import chalk from 'chalk';
2
- import { SchemaNode } from '../schema-node';
3
- import { TypeRefSchema } from './type-ref';
4
-
5
- export type Parameter = {
6
- name: string;
7
- type: TypeRefSchema;
8
- defaultValue?: any;
9
- description?: string;
10
- };
11
-
12
- export class FunctionSchema implements SchemaNode {
13
- constructor(
14
- readonly name: string,
15
- // readonly doc: any,
16
- readonly params: Parameter[],
17
-
18
- readonly returnType: TypeRefSchema,
19
- private signature: string
20
- ) {}
21
-
22
- serialize() {}
23
-
24
- toJsonSchema() {}
25
-
26
- getSignature() {
27
- return this.signature;
28
- }
29
-
30
- toObject() {
31
- return {
32
- constructorName: this.constructor.name,
33
- name: this.name,
34
- params: this.params,
35
- returnType: this.returnType.toObject(),
36
- signature: this.signature,
37
- };
38
- }
39
-
40
- toString() {
41
- const paramsStr = this.params.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
42
- return `${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
43
- }
44
- }