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

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 (82) hide show
  1. package/api-schema.ts +56 -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 +2 -2
  6. package/dist/index.js +14 -3
  7. package/dist/index.js.map +1 -1
  8. package/dist/schema-node.d.ts +5 -5
  9. package/dist/schemas/class.d.ts +14 -0
  10. package/dist/schemas/class.js +25 -0
  11. package/dist/schemas/class.js.map +1 -1
  12. package/dist/schemas/constructor.d.ts +11 -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.d.ts +20 -5
  19. package/dist/schemas/function.js +23 -2
  20. package/dist/schemas/function.js.map +1 -1
  21. package/dist/schemas/get-accessor.d.ts +21 -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 +23 -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 +12 -1
  28. package/dist/schemas/index.js +23 -1
  29. package/dist/schemas/index.js.map +1 -1
  30. package/dist/schemas/interface.d.ts +14 -0
  31. package/dist/schemas/interface.js +26 -0
  32. package/dist/schemas/interface.js.map +1 -0
  33. package/dist/schemas/module.d.ts +14 -10
  34. package/dist/schemas/module.js +33 -5
  35. package/dist/schemas/module.js.map +1 -1
  36. package/dist/schemas/set-accessor.d.ts +16 -0
  37. package/dist/schemas/set-accessor.js +30 -0
  38. package/dist/schemas/set-accessor.js.map +1 -0
  39. package/dist/schemas/type-intersection.d.ts +12 -0
  40. package/dist/schemas/type-intersection.js +19 -0
  41. package/dist/schemas/type-intersection.js.map +1 -0
  42. package/dist/schemas/type-literal.d.ts +15 -0
  43. package/dist/schemas/type-literal.js +22 -0
  44. package/dist/schemas/type-literal.js.map +1 -0
  45. package/dist/schemas/type-ref.d.ts +7 -0
  46. package/dist/schemas/type-ref.js +21 -0
  47. package/dist/schemas/type-ref.js.map +1 -1
  48. package/dist/schemas/type-union.d.ts +12 -0
  49. package/dist/schemas/type-union.js +19 -0
  50. package/dist/schemas/type-union.js.map +1 -0
  51. package/dist/schemas/type.d.ts +16 -0
  52. package/dist/schemas/type.js +26 -0
  53. package/dist/schemas/type.js.map +1 -1
  54. package/dist/schemas/variable.d.ts +21 -0
  55. package/dist/schemas/variable.js +30 -0
  56. package/dist/schemas/variable.js.map +1 -0
  57. package/index.ts +20 -2
  58. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.8.tgz +0 -0
  59. package/package.json +3 -2
  60. package/{preview-1650468178717.js → preview-1652239597845.js} +1 -1
  61. package/schema-node.ts +4 -5
  62. package/schemas/class.ts +19 -0
  63. package/schemas/constructor.ts +19 -0
  64. package/schemas/export.ts +9 -2
  65. package/schemas/function.ts +26 -5
  66. package/schemas/get-accessor.ts +23 -0
  67. package/schemas/index-signature.ts +22 -0
  68. package/schemas/index.ts +12 -1
  69. package/schemas/interface.ts +17 -0
  70. package/schemas/module.ts +36 -7
  71. package/schemas/set-accessor.ts +23 -0
  72. package/schemas/type-intersection.ts +14 -0
  73. package/schemas/type-literal.ts +17 -0
  74. package/schemas/type-ref.ts +20 -0
  75. package/schemas/type-union.ts +14 -0
  76. package/schemas/type.ts +17 -0
  77. package/schemas/variable.ts +23 -0
  78. package/dist/semantic-schema.d.ts +0 -12
  79. package/dist/semantic-schema.js +0 -17
  80. package/dist/semantic-schema.js.map +0 -1
  81. package/package-tar/teambit-semantics.entities.semantic-schema-0.0.7.tgz +0 -0
  82. package/semantic-schema.ts +0 -20
@@ -0,0 +1,23 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+ import { TypeRefSchema } from './type-ref';
4
+
5
+ export class GetAccessorSchema implements SchemaNode {
6
+ constructor(private name: string, private type: TypeRefSchema, private signature: string) {}
7
+ getSignature() {
8
+ return this.signature;
9
+ }
10
+
11
+ toObject() {
12
+ return {
13
+ constructorName: this.constructor.name,
14
+ name: this.name,
15
+ type: this.type.toObject(),
16
+ signature: this.signature,
17
+ };
18
+ }
19
+
20
+ toString() {
21
+ return `get ${chalk.bold(this.name)}(): ${this.type.toString()}`;
22
+ }
23
+ }
@@ -0,0 +1,22 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ import { Parameter } from './function';
3
+ import { TypeRefSchema } from './type-ref';
4
+
5
+ /**
6
+ * e.g. `{ [key: string]: boolean };`
7
+ * the "[key: string]" is the "parameter", and the "boolean" is the "type".
8
+ */
9
+ export class IndexSignatureSchema implements SchemaNode {
10
+ constructor(private parameters: Parameter[], private type: TypeRefSchema) {}
11
+ toObject() {
12
+ return {
13
+ constructorName: this.constructor.name,
14
+ parameters: this.parameters,
15
+ type: this.type.toObject(),
16
+ };
17
+ }
18
+ toString() {
19
+ const parameters = this.parameters.map((arg) => `${arg.name}: ${arg.type.toString()}`).join(', ');
20
+ return `[${parameters}]: ${this.type.toString()}`;
21
+ }
22
+ }
package/schemas/index.ts CHANGED
@@ -1,4 +1,15 @@
1
1
  export { Module } from './module';
2
2
  export { Export, StaticProperties } from './export';
3
- export { FunctionSchema } from './function';
3
+ export { FunctionSchema, Parameter } from './function';
4
4
  export { TypeRefSchema } from './type-ref';
5
+ export { VariableSchema } from './variable';
6
+ export { ClassSchema } from './class';
7
+ export { ConstructorSchema } from './constructor';
8
+ export { TypeSchema } from './type';
9
+ export { TypeIntersectionSchema } from './type-intersection';
10
+ export { TypeUnionSchema } from './type-union';
11
+ export { TypeLiteralSchema } from './type-literal';
12
+ export { IndexSignatureSchema } from './index-signature';
13
+ export { InterfaceSchema } from './interface';
14
+ export { GetAccessorSchema } from './get-accessor';
15
+ export { SetAccessorSchema } from './set-accessor';
@@ -0,0 +1,17 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+
4
+ export class InterfaceSchema implements SchemaNode {
5
+ constructor(private name: string, private members: SchemaNode[]) {}
6
+ toObject() {
7
+ return {
8
+ constructorName: this.constructor.name,
9
+ name: this.name,
10
+ types: this.members.map((type) => type.toObject()),
11
+ };
12
+ }
13
+ toString() {
14
+ const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
15
+ return `${chalk.bold.underline(this.name)}\n${membersStr}`;
16
+ }
17
+ }
package/schemas/module.ts CHANGED
@@ -1,11 +1,40 @@
1
- import { Export } from './export';
1
+ import chalk from 'chalk';
2
2
  import { SchemaNode } from '../schema-node';
3
+ import { Export } from '../schemas';
3
4
 
4
5
  export class Module implements SchemaNode {
5
- constructor(
6
- /**
7
- * all module exports.
8
- */
9
- readonly exports: Export[]
10
- ) {}
6
+ namespace?: string;
7
+ constructor(public exports: SchemaNode[]) {}
8
+
9
+ getExportSchemas(): Export[] {
10
+ return this.exports.filter((e) => e instanceof Export) as Export[];
11
+ }
12
+
13
+ toObject() {
14
+ return {
15
+ constructorName: this.constructor.name,
16
+ namespace: this.namespace,
17
+ exports: this.exports.map((exp) => exp.toObject()),
18
+ };
19
+ }
20
+
21
+ flatExportsRecursively() {
22
+ this.exports = this.exports.reduce((acc, exp) => {
23
+ if (exp instanceof Module) {
24
+ exp.flatExportsRecursively();
25
+ if (exp.namespace) return [...acc, exp];
26
+ return [...acc, ...exp.exports];
27
+ }
28
+ return [...acc, exp];
29
+ }, [] as SchemaNode[]);
30
+ }
31
+
32
+ toString() {
33
+ if (!this.namespace)
34
+ throw new Error(
35
+ 'toString() should not be called on a module without namespace, make sure this.flatExportsRecursively() is called'
36
+ );
37
+ const exportsStr = this.exports.map((m) => `* ${m.toString()}`).join('\n');
38
+ return `${chalk.bold.underline(this.namespace)}\n${exportsStr}`;
39
+ }
11
40
  }
@@ -0,0 +1,23 @@
1
+ import chalk from 'chalk';
2
+ import { Parameter } from '.';
3
+ import { SchemaNode } from '../schema-node';
4
+
5
+ export class SetAccessorSchema implements SchemaNode {
6
+ constructor(private name: string, private param: Parameter, private signature: string) {}
7
+ getSignature() {
8
+ return this.signature;
9
+ }
10
+
11
+ toObject() {
12
+ return {
13
+ constructorName: this.constructor.name,
14
+ name: this.name,
15
+ param: this.param,
16
+ signature: this.signature,
17
+ };
18
+ }
19
+
20
+ toString() {
21
+ return `set ${chalk.bold(this.name)}(${this.param.name}: ${this.param.type})`;
22
+ }
23
+ }
@@ -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
+ }
@@ -1,4 +1,5 @@
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 = {
@@ -28,6 +29,25 @@ export class TypeRefSchema implements SchemaNode {
28
29
  readonly node?: SchemaNode
29
30
  ) {}
30
31
 
32
+ toObject() {
33
+ return {
34
+ constructorName: this.constructor.name,
35
+ name: this.name,
36
+ componentId: this.componentId,
37
+ packageName: this.packageName,
38
+ };
39
+ }
40
+
41
+ toString() {
42
+ if (this.componentId) {
43
+ return `${this.componentId}/${this.name}`;
44
+ }
45
+ if (this.packageName) {
46
+ return `${chalk.dim(this.packageName)}/${this.name}`;
47
+ }
48
+ return this.name;
49
+ }
50
+
31
51
  static from(plainSchema: PlainTypeRefSchema) {
32
52
  return new TypeRefSchema(
33
53
  plainSchema.name,
@@ -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,23 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+ import { TypeRefSchema } from './type-ref';
4
+
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
+ };
18
+ }
19
+
20
+ toString() {
21
+ return `${chalk.bold(this.name)}: ${this.type.toString()}`;
22
+ }
23
+ }
@@ -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,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
- }