@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
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.TypeRefSchema = void 0;
4
7
  const component_1 = require("@teambit/component");
8
+ const chalk_1 = __importDefault(require("chalk"));
5
9
  class TypeRefSchema {
6
10
  constructor(
7
11
  /**
@@ -15,14 +19,36 @@ class TypeRefSchema {
15
19
  /**
16
20
  * target package name. existing if type is defined in different package.
17
21
  */
18
- packageName, node) {
22
+ packageName) {
19
23
  this.name = name;
20
24
  this.componentId = componentId;
21
25
  this.packageName = packageName;
22
- this.node = node;
26
+ }
27
+ toObject() {
28
+ return {
29
+ constructorName: this.constructor.name,
30
+ name: this.name,
31
+ componentId: this.componentId,
32
+ packageName: this.packageName,
33
+ };
34
+ }
35
+ toString() {
36
+ if (this.componentId) {
37
+ return `${this.componentId}/${this.name}`;
38
+ }
39
+ if (this.packageName) {
40
+ return `${chalk_1.default.dim(this.packageName)}/${this.name}`;
41
+ }
42
+ return this.name;
43
+ }
44
+ /**
45
+ * whether this type was already exported in this component
46
+ */
47
+ isFromThisComponent() {
48
+ return !this.componentId && !this.packageName;
23
49
  }
24
50
  static from(plainSchema) {
25
- return new TypeRefSchema(plainSchema.name, plainSchema.componentId ? component_1.ComponentID.fromString(plainSchema.componentId) : undefined, plainSchema.packageName, plainSchema.node);
51
+ return new TypeRefSchema(plainSchema.name, plainSchema.componentId ? component_1.ComponentID.fromString(plainSchema.componentId) : undefined, plainSchema.packageName);
26
52
  }
27
53
  }
28
54
  exports.TypeRefSchema = TypeRefSchema;
@@ -1 +1 @@
1
- {"version":3,"file":"type-ref.js","sourceRoot":"","sources":["../../schemas/type-ref.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AAUjD,MAAa,aAAa;IACxB;IACE;;OAEG;IACM,IAAY;IAErB;;OAEG;IACM,WAAyB;IAElC;;OAEG;IACM,WAAoB,EAEpB,IAAiB;QAZjB,SAAI,GAAJ,IAAI,CAAQ;QAKZ,gBAAW,GAAX,WAAW,CAAc;QAKzB,gBAAW,GAAX,WAAW,CAAS;QAEpB,SAAI,GAAJ,IAAI,CAAa;IACzB,CAAC;IAEJ,MAAM,CAAC,IAAI,CAAC,WAA+B;QACzC,OAAO,IAAI,aAAa,CACtB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,uBAAW,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,EACrF,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,IAAI,CACjB,CAAC;IACJ,CAAC;CACF;AA5BD,sCA4BC"}
1
+ {"version":3,"file":"type-ref.js","sourceRoot":"","sources":["../../schemas/type-ref.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAiD;AACjD,kDAA0B;AAS1B,MAAa,aAAa;IACxB;IACE;;OAEG;IACM,IAAY;IAErB;;OAEG;IACM,WAAyB;IAElC;;OAEG;IACM,WAAoB;QAVpB,SAAI,GAAJ,IAAI,CAAQ;QAKZ,gBAAW,GAAX,WAAW,CAAc;QAKzB,gBAAW,GAAX,WAAW,CAAS;IAC5B,CAAC;IAEJ,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,GAAG,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SAC3C;QACD,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,OAAO,GAAG,eAAK,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;SACtD;QACD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,CAAC,IAAI,CAAC,WAAW,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;IAChD,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,WAA+B;QACzC,OAAO,IAAI,aAAa,CACtB,WAAW,CAAC,IAAI,EAChB,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,uBAAW,CAAC,UAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS,EACrF,WAAW,CAAC,WAAW,CACxB,CAAC;IACJ,CAAC;CACF;AAnDD,sCAmDC"}
@@ -0,0 +1,12 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ export declare class TypeUnionSchema implements SchemaNode {
3
+ private types;
4
+ constructor(types: SchemaNode[]);
5
+ toObject(): {
6
+ constructorName: string;
7
+ types: (Record<string, any> & {
8
+ constructorName: string;
9
+ })[];
10
+ };
11
+ toString(): string;
12
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TypeUnionSchema = void 0;
4
+ class TypeUnionSchema {
5
+ constructor(types) {
6
+ this.types = types;
7
+ }
8
+ toObject() {
9
+ return {
10
+ constructorName: this.constructor.name,
11
+ types: this.types.map((type) => type.toObject()),
12
+ };
13
+ }
14
+ toString() {
15
+ return `${this.types.map((type) => type.toString()).join(' | ')}`;
16
+ }
17
+ }
18
+ exports.TypeUnionSchema = TypeUnionSchema;
19
+ //# sourceMappingURL=type-union.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-union.js","sourceRoot":"","sources":["../../schemas/type-union.ts"],"names":[],"mappings":";;;AAEA,MAAa,eAAe;IAC1B,YAAoB,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;IAAG,CAAC;IAC3C,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC;IACD,QAAQ;QACN,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;IACpE,CAAC;CACF;AAXD,0CAWC"}
@@ -0,0 +1,16 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ export declare class TypeSchema implements SchemaNode {
3
+ private name;
4
+ private type;
5
+ private signature;
6
+ constructor(name: string, type: SchemaNode, signature: string);
7
+ toObject(): {
8
+ constructorName: string;
9
+ name: string;
10
+ type: Record<string, any> & {
11
+ constructorName: string;
12
+ };
13
+ signature: string;
14
+ };
15
+ toString(): string;
16
+ }
@@ -1 +1,27 @@
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.TypeSchema = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ class TypeSchema {
9
+ constructor(name, type, signature) {
10
+ this.name = name;
11
+ this.type = type;
12
+ this.signature = signature;
13
+ }
14
+ toObject() {
15
+ return {
16
+ constructorName: this.constructor.name,
17
+ name: this.name,
18
+ type: this.type.toObject(),
19
+ signature: this.signature,
20
+ };
21
+ }
22
+ toString() {
23
+ return `${chalk_1.default.bold(this.name)}: ${this.type.toString()}`;
24
+ }
25
+ }
26
+ exports.TypeSchema = TypeSchema;
1
27
  //# sourceMappingURL=type.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"type.js","sourceRoot":"","sources":["../../schemas/type.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../schemas/type.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,MAAa,UAAU;IACrB,YAAoB,IAAY,EAAU,IAAgB,EAAU,SAAiB;QAAjE,SAAI,GAAJ,IAAI,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAY;QAAU,cAAS,GAAT,SAAS,CAAQ;IAAG,CAAC;IACzF,QAAQ;QACN,OAAO;YACL,eAAe,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI;YACtC,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;SAC1B,CAAC;IACJ,CAAC;IACD,QAAQ;QACN,OAAO,GAAG,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,CAAC;CACF;AAbD,gCAaC"}
@@ -0,0 +1,17 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ export declare class VariableSchema implements SchemaNode {
3
+ readonly name: string;
4
+ private signature;
5
+ private type;
6
+ constructor(name: string, signature: string, type: SchemaNode);
7
+ getSignature(): string;
8
+ toObject(): {
9
+ constructorName: string;
10
+ name: string;
11
+ signature: string;
12
+ type: Record<string, any> & {
13
+ constructorName: string;
14
+ };
15
+ };
16
+ toString(): string;
17
+ }
@@ -0,0 +1,30 @@
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.VariableSchema = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ class VariableSchema {
9
+ constructor(name, signature, type) {
10
+ this.name = name;
11
+ this.signature = signature;
12
+ this.type = type;
13
+ }
14
+ getSignature() {
15
+ return this.signature;
16
+ }
17
+ toObject() {
18
+ return {
19
+ constructorName: this.constructor.name,
20
+ name: this.name,
21
+ signature: this.signature,
22
+ type: this.type.toObject(),
23
+ };
24
+ }
25
+ toString() {
26
+ return `${chalk_1.default.bold(this.name)}: ${this.type.toString()}`;
27
+ }
28
+ }
29
+ exports.VariableSchema = VariableSchema;
30
+ //# sourceMappingURL=variable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"variable.js","sourceRoot":"","sources":["../../schemas/variable.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAG1B,MAAa,cAAc;IACzB,YAAqB,IAAY,EAAU,SAAiB,EAAU,IAAgB;QAAjE,SAAI,GAAJ,IAAI,CAAQ;QAAU,cAAS,GAAT,SAAS,CAAQ;QAAU,SAAI,GAAJ,IAAI,CAAY;IAAG,CAAC;IAC1F,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,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE;SAC3B,CAAC;IACJ,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,CAAC;CACF;AAlBD,wCAkBC"}
package/index.ts CHANGED
@@ -1,4 +1,30 @@
1
- export { SemanticSchema } from './semantic-schema';
2
- export type { SchemaNode } from './schema-node';
3
- export { Export, Module, StaticProperties, FunctionSchema, TypeRefSchema } from './schemas';
1
+ export { APISchema } from './api-schema';
2
+ export type { SchemaNode, Location } from './schema-node';
3
+ export {
4
+ Export,
5
+ Module,
6
+ StaticProperties,
7
+ FunctionLikeSchema,
8
+ Modifier,
9
+ TypeRefSchema,
10
+ VariableSchema,
11
+ ClassSchema,
12
+ ConstructorSchema,
13
+ TypeSchema,
14
+ TypeIntersectionSchema,
15
+ TypeUnionSchema,
16
+ TypeLiteralSchema,
17
+ IndexSignatureSchema,
18
+ InterfaceSchema,
19
+ GetAccessorSchema,
20
+ SetAccessorSchema,
21
+ TypeQuerySchema,
22
+ InferenceTypeSchema,
23
+ LiteralTypeSchema,
24
+ KeywordTypeSchema,
25
+ TypeArraySchema,
26
+ TypeOperatorSchema,
27
+ TupleTypeSchema,
28
+ ParameterSchema,
29
+ } from './schemas';
4
30
  export type { JSONSchema, JSONSchemaObject } from './json-schema';
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@teambit/semantics.entities.semantic-schema",
3
- "version": "0.0.7",
3
+ "version": "0.0.10",
4
4
  "homepage": "https://bit.dev/teambit/semantics/entities/semantic-schema",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.semantics",
8
8
  "name": "entities/semantic-schema",
9
- "version": "0.0.7"
9
+ "version": "0.0.10"
10
10
  },
11
11
  "dependencies": {
12
+ "chalk": "2.4.2",
12
13
  "json-schema": "0.4.0"
13
14
  },
14
15
  "devDependencies": {
@@ -1 +1 @@
1
- export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.7/dist/semantic-schema.docs.md')]
1
+ export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.10/dist/semantic-schema.docs.md')]
package/schema-node.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  /**
2
- * an interface for implmenting a new schema node.
2
+ * an interface for implementing a new schema node.
3
3
  */
4
4
  export interface SchemaNode {
5
+ readonly location?: Location;
6
+ getSignature?(): string;
7
+
5
8
  toString(): string;
6
9
 
7
- /**
8
- * TODO: this should be made mandatory. this is the main serialization method.
9
- */
10
- toObject?(): string;
10
+ toObject(): Record<string, any> & { constructorName: string };
11
11
  }
12
+
13
+ export type Location = { file: string; line: number; character: number };
package/schemas/class.ts CHANGED
@@ -0,0 +1,19 @@
1
+ import chalk from 'chalk';
2
+ import { Location, SchemaNode } from '../schema-node';
3
+
4
+ export class ClassSchema implements SchemaNode {
5
+ constructor(readonly className: string, readonly members: SchemaNode[], readonly location: Location) {}
6
+
7
+ toObject() {
8
+ return {
9
+ constructorName: this.constructor.name,
10
+ name: this.className,
11
+ members: this.members.map((member) => member.toObject()),
12
+ };
13
+ }
14
+
15
+ toString() {
16
+ const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
17
+ return `${chalk.bold.underline(this.className)}\n${membersStr}`;
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
+
5
+ export class ConstructorSchema implements SchemaNode {
6
+ constructor(readonly params: ParameterSchema[]) {}
7
+
8
+ toString() {
9
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
10
+ return `${chalk.bold('constructor')}(${paramsStr})`;
11
+ }
12
+
13
+ toObject() {
14
+ return {
15
+ constructorName: this.constructor.name,
16
+ args: this.params.map((arg) => arg.toObject()),
17
+ };
18
+ }
19
+ }
package/schemas/export.ts CHANGED
@@ -3,7 +3,7 @@ import { SchemaNode } from '../schema-node';
3
3
  type Primitive = string | number | boolean | null | undefined;
4
4
  export type StaticProperties = Map<string, Primitive>;
5
5
 
6
- export class Export {
6
+ export class Export implements SchemaNode {
7
7
  constructor(
8
8
  /**
9
9
  * named export identifier of the module export.
@@ -13,7 +13,7 @@ export class Export {
13
13
  /**
14
14
  * API node.
15
15
  */
16
- readonly node?: SchemaNode,
16
+ readonly nodes?: SchemaNode[],
17
17
 
18
18
  /**
19
19
  * static properties attached to this export
@@ -24,4 +24,11 @@ export class Export {
24
24
  */
25
25
  readonly staticProperties?: StaticProperties
26
26
  ) {}
27
+
28
+ toObject() {
29
+ return {
30
+ constructorName: this.constructor.name,
31
+ identifier: this.identifier,
32
+ };
33
+ }
27
34
  }
@@ -0,0 +1,43 @@
1
+ import chalk from 'chalk';
2
+ import { Location, SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
+
5
+ export type Modifier = 'static' | 'public' | 'private' | 'protected' | 'readonly' | 'abstract' | 'async' | 'override';
6
+
7
+ export class FunctionLikeSchema implements SchemaNode {
8
+ constructor(
9
+ readonly name: string,
10
+ // readonly doc: any,
11
+ readonly params: ParameterSchema[],
12
+
13
+ readonly returnType: SchemaNode,
14
+ readonly signature: string,
15
+ readonly location: Location,
16
+ readonly modifiers: Modifier[] = []
17
+ ) {}
18
+
19
+ serialize() {}
20
+
21
+ toJsonSchema() {}
22
+
23
+ getSignature() {
24
+ return this.signature;
25
+ }
26
+
27
+ toObject() {
28
+ return {
29
+ constructorName: this.constructor.name,
30
+ name: this.name,
31
+ params: this.params,
32
+ returnType: this.returnType.toObject(),
33
+ signature: this.signature,
34
+ modifiers: this.modifiers,
35
+ };
36
+ }
37
+
38
+ toString() {
39
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
40
+ const modifiersStr = this.modifiers.length ? `${this.modifiers.join(' ')} ` : '';
41
+ return `${modifiersStr}${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
42
+ }
43
+ }
@@ -0,0 +1,22 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+
4
+ export class GetAccessorSchema implements SchemaNode {
5
+ constructor(private name: string, private type: SchemaNode, private signature: string) {}
6
+ getSignature() {
7
+ return this.signature;
8
+ }
9
+
10
+ toObject() {
11
+ return {
12
+ constructorName: this.constructor.name,
13
+ name: this.name,
14
+ type: this.type.toObject(),
15
+ signature: this.signature,
16
+ };
17
+ }
18
+
19
+ toString() {
20
+ return `get ${chalk.bold(this.name)}(): ${this.type.toString()}`;
21
+ }
22
+ }
@@ -0,0 +1,21 @@
1
+ import { SchemaNode } from '../schema-node';
2
+ import { ParameterSchema } from './parameter';
3
+
4
+ /**
5
+ * e.g. `{ [key: string]: boolean };`
6
+ * the "[key: string]" is the "parameter", and the "boolean" is the "type".
7
+ */
8
+ export class IndexSignatureSchema implements SchemaNode {
9
+ constructor(private params: ParameterSchema[], private type: SchemaNode) {}
10
+ toObject() {
11
+ return {
12
+ constructorName: this.constructor.name,
13
+ parameters: this.params,
14
+ type: this.type.toObject(),
15
+ };
16
+ }
17
+ toString() {
18
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
19
+ return `[${paramsStr}]: ${this.type.toString()}`;
20
+ }
21
+ }
package/schemas/index.ts CHANGED
@@ -1,4 +1,23 @@
1
1
  export { Module } from './module';
2
2
  export { Export, StaticProperties } from './export';
3
- export { FunctionSchema } from './function';
3
+ export { FunctionLikeSchema, Modifier } from './function-like';
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';
16
+ export { TypeQuerySchema } from './type-query';
17
+ export { InferenceTypeSchema } from './inference-type';
18
+ export { LiteralTypeSchema } from './literal-type';
19
+ export { KeywordTypeSchema } from './keyword-type';
20
+ export { TypeArraySchema } from './type-array';
21
+ export { TypeOperatorSchema } from './type-operator';
22
+ export { TupleTypeSchema } from './tuple-type';
23
+ export { ParameterSchema } from './parameter';
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * where there is no explicit type, the type is taken from the "quickinfo" of tsserver
5
+ */
6
+ export class InferenceTypeSchema implements SchemaNode {
7
+ constructor(private type: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ type: this.type,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.type;
18
+ }
19
+ }
@@ -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
+ }
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. 'string', 'boolean', etc.
5
+ */
6
+ export class KeywordTypeSchema implements SchemaNode {
7
+ constructor(private name: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ name: this.name,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.name;
18
+ }
19
+ }
@@ -0,0 +1,19 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. const a: 'a';
5
+ */
6
+ export class LiteralTypeSchema implements SchemaNode {
7
+ constructor(private name: string) {}
8
+
9
+ toObject() {
10
+ return {
11
+ constructorName: this.constructor.name,
12
+ name: this.name,
13
+ };
14
+ }
15
+
16
+ toString() {
17
+ return this.name;
18
+ }
19
+ }
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 { SchemaNode } from '../schema-node';
2
+
3
+ export class ParameterSchema implements SchemaNode {
4
+ constructor(
5
+ readonly name: string,
6
+ readonly type: SchemaNode,
7
+ readonly defaultValue?: any,
8
+ readonly description?: string
9
+ ) {}
10
+
11
+ toObject() {
12
+ return {
13
+ constructorName: this.constructor.name,
14
+ name: this.name,
15
+ type: this.type.toObject(),
16
+ defaultValue: this.defaultValue,
17
+ description: this.description,
18
+ };
19
+ }
20
+ toString() {
21
+ return `${this.name}: ${this.type.toString()}`;
22
+ }
23
+ }
@@ -0,0 +1,23 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
+
5
+ export class SetAccessorSchema implements SchemaNode {
6
+ constructor(private name: string, private param: ParameterSchema, 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.toString()})`;
22
+ }
23
+ }
@@ -0,0 +1,14 @@
1
+ import { SchemaNode } from '../schema-node';
2
+
3
+ export class TupleTypeSchema implements SchemaNode {
4
+ constructor(private elements: SchemaNode[]) {}
5
+ toObject() {
6
+ return {
7
+ constructorName: this.constructor.name,
8
+ elements: this.elements.map((elem) => elem.toObject()),
9
+ };
10
+ }
11
+ toString() {
12
+ return `[${this.elements.map((elem) => elem.toString()).join(', ')}]`;
13
+ }
14
+ }