@teambit/semantics.entities.semantic-schema 0.0.0-e4ef0e951da794f03096a5cc407420f4cde8b878

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 (233) hide show
  1. package/api-schema.ts +167 -0
  2. package/dist/api-schema.d.ts +36 -0
  3. package/dist/api-schema.js +171 -0
  4. package/dist/api-schema.js.map +1 -0
  5. package/dist/export.d.ts +38 -0
  6. package/dist/export.js +37 -0
  7. package/dist/export.js.map +1 -0
  8. package/dist/index.d.ts +11 -0
  9. package/dist/index.js +137 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/schema-node-constructor.d.ts +7 -0
  12. package/dist/schema-node-constructor.js +3 -0
  13. package/dist/schema-node-constructor.js.map +1 -0
  14. package/dist/schema-node.d.ts +51 -0
  15. package/dist/schema-node.js +67 -0
  16. package/dist/schema-node.js.map +1 -0
  17. package/dist/schema-registry.d.ts +17 -0
  18. package/dist/schema-registry.js +63 -0
  19. package/dist/schema-registry.js.map +1 -0
  20. package/dist/schemas/array-literal-expression.d.ts +15 -0
  21. package/dist/schemas/array-literal-expression.js +48 -0
  22. package/dist/schemas/array-literal-expression.js.map +1 -0
  23. package/dist/schemas/class.d.ts +59 -0
  24. package/dist/schemas/class.js +126 -0
  25. package/dist/schemas/class.js.map +1 -0
  26. package/dist/schemas/conditional-type.d.ts +25 -0
  27. package/dist/schemas/conditional-type.js +67 -0
  28. package/dist/schemas/conditional-type.js.map +1 -0
  29. package/dist/schemas/constructor.d.ts +9 -0
  30. package/dist/schemas/constructor.js +51 -0
  31. package/dist/schemas/constructor.js.map +1 -0
  32. package/dist/schemas/decorator.d.ts +35 -0
  33. package/dist/schemas/decorator.js +70 -0
  34. package/dist/schemas/decorator.js.map +1 -0
  35. package/dist/schemas/docs/doc.d.ts +30 -0
  36. package/dist/schemas/docs/doc.js +74 -0
  37. package/dist/schemas/docs/doc.js.map +1 -0
  38. package/dist/schemas/docs/index.d.ts +4 -0
  39. package/dist/schemas/docs/index.js +59 -0
  40. package/dist/schemas/docs/index.js.map +1 -0
  41. package/dist/schemas/docs/property-like-tag.d.ts +26 -0
  42. package/dist/schemas/docs/property-like-tag.js +59 -0
  43. package/dist/schemas/docs/property-like-tag.js.map +1 -0
  44. package/dist/schemas/docs/return-tag.d.ts +25 -0
  45. package/dist/schemas/docs/return-tag.js +55 -0
  46. package/dist/schemas/docs/return-tag.js.map +1 -0
  47. package/dist/schemas/docs/tag.d.ts +45 -0
  48. package/dist/schemas/docs/tag.js +75 -0
  49. package/dist/schemas/docs/tag.js.map +1 -0
  50. package/dist/schemas/enum-member.d.ts +36 -0
  51. package/dist/schemas/enum-member.js +66 -0
  52. package/dist/schemas/enum-member.js.map +1 -0
  53. package/dist/schemas/enum.d.ts +37 -0
  54. package/dist/schemas/enum.js +87 -0
  55. package/dist/schemas/enum.js.map +1 -0
  56. package/dist/schemas/export.d.ts +41 -0
  57. package/dist/schemas/export.js +92 -0
  58. package/dist/schemas/export.js.map +1 -0
  59. package/dist/schemas/expression-with-arguments.d.ts +19 -0
  60. package/dist/schemas/expression-with-arguments.js +59 -0
  61. package/dist/schemas/expression-with-arguments.js.map +1 -0
  62. package/dist/schemas/function-like.d.ts +66 -0
  63. package/dist/schemas/function-like.js +147 -0
  64. package/dist/schemas/function-like.js.map +1 -0
  65. package/dist/schemas/get-accessor.d.ts +22 -0
  66. package/dist/schemas/get-accessor.js +73 -0
  67. package/dist/schemas/get-accessor.js.map +1 -0
  68. package/dist/schemas/ignored.d.ts +17 -0
  69. package/dist/schemas/ignored.js +54 -0
  70. package/dist/schemas/ignored.js.map +1 -0
  71. package/dist/schemas/index-signature.d.ts +23 -0
  72. package/dist/schemas/index-signature.js +65 -0
  73. package/dist/schemas/index-signature.js.map +1 -0
  74. package/dist/schemas/index.d.ts +49 -0
  75. package/dist/schemas/index.js +623 -0
  76. package/dist/schemas/index.js.map +1 -0
  77. package/dist/schemas/indexed-access-type.d.ts +17 -0
  78. package/dist/schemas/indexed-access-type.js +55 -0
  79. package/dist/schemas/indexed-access-type.js.map +1 -0
  80. package/dist/schemas/inference-type.d.ts +22 -0
  81. package/dist/schemas/inference-type.js +65 -0
  82. package/dist/schemas/inference-type.js.map +1 -0
  83. package/dist/schemas/interface.d.ts +49 -0
  84. package/dist/schemas/interface.js +108 -0
  85. package/dist/schemas/interface.js.map +1 -0
  86. package/dist/schemas/keyword-type.d.ts +15 -0
  87. package/dist/schemas/keyword-type.js +43 -0
  88. package/dist/schemas/keyword-type.js.map +1 -0
  89. package/dist/schemas/literal-type.d.ts +15 -0
  90. package/dist/schemas/literal-type.js +43 -0
  91. package/dist/schemas/literal-type.js.map +1 -0
  92. package/dist/schemas/literal-value.d.ts +12 -0
  93. package/dist/schemas/literal-value.js +41 -0
  94. package/dist/schemas/literal-value.js.map +1 -0
  95. package/dist/schemas/module.d.ts +22 -0
  96. package/dist/schemas/module.js +87 -0
  97. package/dist/schemas/module.js.map +1 -0
  98. package/dist/schemas/named-tuple.d.ts +19 -0
  99. package/dist/schemas/named-tuple.js +53 -0
  100. package/dist/schemas/named-tuple.js.map +1 -0
  101. package/dist/schemas/object-literal-expression.d.ts +18 -0
  102. package/dist/schemas/object-literal-expression.js +52 -0
  103. package/dist/schemas/object-literal-expression.js.map +1 -0
  104. package/dist/schemas/parameter.d.ts +27 -0
  105. package/dist/schemas/parameter.js +95 -0
  106. package/dist/schemas/parameter.js.map +1 -0
  107. package/dist/schemas/parenthesized-type.d.ts +21 -0
  108. package/dist/schemas/parenthesized-type.js +54 -0
  109. package/dist/schemas/parenthesized-type.js.map +1 -0
  110. package/dist/schemas/property-assignment.d.ts +37 -0
  111. package/dist/schemas/property-assignment.js +67 -0
  112. package/dist/schemas/property-assignment.js.map +1 -0
  113. package/dist/schemas/set-accessor.d.ts +28 -0
  114. package/dist/schemas/set-accessor.js +65 -0
  115. package/dist/schemas/set-accessor.js.map +1 -0
  116. package/dist/schemas/template-literal-type-span.d.ts +19 -0
  117. package/dist/schemas/template-literal-type-span.js +53 -0
  118. package/dist/schemas/template-literal-type-span.js.map +1 -0
  119. package/dist/schemas/template-literal-type.d.ts +22 -0
  120. package/dist/schemas/template-literal-type.js +52 -0
  121. package/dist/schemas/template-literal-type.js.map +1 -0
  122. package/dist/schemas/this-type.d.ts +12 -0
  123. package/dist/schemas/this-type.js +37 -0
  124. package/dist/schemas/this-type.js.map +1 -0
  125. package/dist/schemas/tuple-type.d.ts +16 -0
  126. package/dist/schemas/tuple-type.js +47 -0
  127. package/dist/schemas/tuple-type.js.map +1 -0
  128. package/dist/schemas/type-array.d.ts +17 -0
  129. package/dist/schemas/type-array.js +50 -0
  130. package/dist/schemas/type-array.js.map +1 -0
  131. package/dist/schemas/type-intersection.d.ts +17 -0
  132. package/dist/schemas/type-intersection.js +50 -0
  133. package/dist/schemas/type-intersection.js.map +1 -0
  134. package/dist/schemas/type-literal.d.ts +18 -0
  135. package/dist/schemas/type-literal.js +64 -0
  136. package/dist/schemas/type-literal.js.map +1 -0
  137. package/dist/schemas/type-operator.d.ts +19 -0
  138. package/dist/schemas/type-operator.js +53 -0
  139. package/dist/schemas/type-operator.js.map +1 -0
  140. package/dist/schemas/type-predicate.d.ts +33 -0
  141. package/dist/schemas/type-predicate.js +75 -0
  142. package/dist/schemas/type-predicate.js.map +1 -0
  143. package/dist/schemas/type-query.d.ts +23 -0
  144. package/dist/schemas/type-query.js +59 -0
  145. package/dist/schemas/type-query.js.map +1 -0
  146. package/dist/schemas/type-ref.d.ts +80 -0
  147. package/dist/schemas/type-ref.js +159 -0
  148. package/dist/schemas/type-ref.js.map +1 -0
  149. package/dist/schemas/type-union.d.ts +17 -0
  150. package/dist/schemas/type-union.js +56 -0
  151. package/dist/schemas/type-union.js.map +1 -0
  152. package/dist/schemas/type.d.ts +23 -0
  153. package/dist/schemas/type.js +80 -0
  154. package/dist/schemas/type.js.map +1 -0
  155. package/dist/schemas/unimplemented-schema.d.ts +14 -0
  156. package/dist/schemas/unimplemented-schema.js +43 -0
  157. package/dist/schemas/unimplemented-schema.js.map +1 -0
  158. package/dist/schemas/unknown-schema.d.ts +18 -0
  159. package/dist/schemas/unknown-schema.js +47 -0
  160. package/dist/schemas/unknown-schema.js.map +1 -0
  161. package/dist/schemas/unresolved-schema.d.ts +14 -0
  162. package/dist/schemas/unresolved-schema.js +41 -0
  163. package/dist/schemas/unresolved-schema.js.map +1 -0
  164. package/dist/schemas/variable-like.d.ts +47 -0
  165. package/dist/schemas/variable-like.js +95 -0
  166. package/dist/schemas/variable-like.js.map +1 -0
  167. package/dist/semantic-schema.docs.md +6 -0
  168. package/dist/type.d.ts +1 -0
  169. package/dist/type.js +3 -0
  170. package/dist/type.js.map +1 -0
  171. package/dist/unknown-schema-factory.d.ts +4 -0
  172. package/dist/unknown-schema-factory.js +19 -0
  173. package/dist/unknown-schema-factory.js.map +1 -0
  174. package/export.ts +31 -0
  175. package/index.ts +13 -0
  176. package/package.json +46 -0
  177. package/schema-node-constructor.ts +8 -0
  178. package/schema-node.ts +96 -0
  179. package/schema-registry.ts +53 -0
  180. package/schemas/array-literal-expression.ts +33 -0
  181. package/schemas/class.ts +135 -0
  182. package/schemas/conditional-type.ts +63 -0
  183. package/schemas/constructor.ts +28 -0
  184. package/schemas/decorator.ts +54 -0
  185. package/schemas/docs/doc.ts +69 -0
  186. package/schemas/docs/index.ts +4 -0
  187. package/schemas/docs/property-like-tag.ts +47 -0
  188. package/schemas/docs/return-tag.ts +44 -0
  189. package/schemas/docs/tag.ts +66 -0
  190. package/schemas/enum-member.ts +57 -0
  191. package/schemas/enum.ts +73 -0
  192. package/schemas/export.ts +91 -0
  193. package/schemas/expression-with-arguments.ts +51 -0
  194. package/schemas/function-like.ts +154 -0
  195. package/schemas/get-accessor.ts +57 -0
  196. package/schemas/ignored.ts +43 -0
  197. package/schemas/index-signature.ts +49 -0
  198. package/schemas/index.ts +49 -0
  199. package/schemas/indexed-access-type.ts +47 -0
  200. package/schemas/inference-type.ts +60 -0
  201. package/schemas/interface.ts +94 -0
  202. package/schemas/keyword-type.ts +34 -0
  203. package/schemas/literal-type.ts +34 -0
  204. package/schemas/literal-value.ts +32 -0
  205. package/schemas/module.ts +87 -0
  206. package/schemas/named-tuple.ts +39 -0
  207. package/schemas/object-literal-expression.ts +42 -0
  208. package/schemas/parameter.ts +104 -0
  209. package/schemas/parenthesized-type.ts +42 -0
  210. package/schemas/property-assignment.ts +50 -0
  211. package/schemas/set-accessor.ts +47 -0
  212. package/schemas/template-literal-type-span.ts +42 -0
  213. package/schemas/template-literal-type.ts +40 -0
  214. package/schemas/this-type.ts +27 -0
  215. package/schemas/tuple-type.ts +35 -0
  216. package/schemas/type-array.ts +39 -0
  217. package/schemas/type-intersection.ts +39 -0
  218. package/schemas/type-literal.ts +60 -0
  219. package/schemas/type-operator.ts +41 -0
  220. package/schemas/type-predicate.ts +64 -0
  221. package/schemas/type-query.ts +49 -0
  222. package/schemas/type-ref.ts +143 -0
  223. package/schemas/type-union.ts +41 -0
  224. package/schemas/type.ts +61 -0
  225. package/schemas/unimplemented-schema.ts +35 -0
  226. package/schemas/unknown-schema.ts +38 -0
  227. package/schemas/unresolved-schema.ts +32 -0
  228. package/schemas/variable-like.ts +76 -0
  229. package/semantic-schema.docs.md +6 -0
  230. package/type.ts +1 -0
  231. package/types/asset.d.ts +41 -0
  232. package/types/style.d.ts +42 -0
  233. package/unknown-schema-factory.ts +10 -0
@@ -0,0 +1,91 @@
1
+ import { SchemaNode, SchemaLocation } from '../schema-node';
2
+ import { DocSchema } from './docs';
3
+ import { SchemaRegistry } from '../schema-registry';
4
+
5
+ export class ExportSchema extends SchemaNode {
6
+ alias?: string;
7
+ exportNode: SchemaNode;
8
+ readonly doc?: DocSchema;
9
+ readonly signature?: string;
10
+
11
+ constructor(
12
+ readonly location: SchemaLocation,
13
+ readonly name: string,
14
+ exportNode: SchemaNode,
15
+ alias?: string,
16
+ doc?: DocSchema
17
+ ) {
18
+ super();
19
+ this.exportNode = exportNode;
20
+ this.alias = alias;
21
+ this.doc = doc;
22
+ this.signature = exportNode.signature || this.toFullSignature();
23
+ }
24
+
25
+ toString(options?: { color?: boolean }): string {
26
+ let signature = '';
27
+
28
+ const alias = this.alias || this.name;
29
+ const originalName = this.exportNode.name || this.name;
30
+
31
+ if (alias !== originalName) {
32
+ signature += `export { ${originalName} as ${alias} };\n`;
33
+ } else {
34
+ signature += `export { ${originalName} };\n`;
35
+ }
36
+
37
+ const exportNodeSignature = this.exportNode.toString(options);
38
+
39
+ signature += `\n${exportNodeSignature}`;
40
+
41
+ return signature;
42
+ }
43
+
44
+ toFullSignature(options?: { showDocs?: boolean }): string {
45
+ let signature = '';
46
+
47
+ if (options?.showDocs && this.doc) {
48
+ const docString = this.doc.toFullSignature();
49
+ signature += `${docString}\n`;
50
+ }
51
+
52
+ const alias = this.alias || this.name;
53
+ const originalName = this.exportNode.name || this.name;
54
+
55
+ if (alias !== originalName) {
56
+ signature += `export { ${originalName} as ${alias} };\n`;
57
+ } else {
58
+ signature += `export { ${originalName} };\n`;
59
+ }
60
+
61
+ const exportNodeSignature = this.exportNode.toFullSignature(options);
62
+
63
+ signature += `\n${exportNodeSignature}`;
64
+
65
+ return signature;
66
+ }
67
+
68
+ toObject() {
69
+ return {
70
+ ...super.toObject(),
71
+ name: this.name,
72
+ doc: this.doc?.toObject(),
73
+ location: this.location,
74
+ exportNode: this.exportNode.toObject(),
75
+ alias: this.alias,
76
+ };
77
+ }
78
+
79
+ static fromObject(obj: Record<string, any>): ExportSchema {
80
+ const name = obj.name;
81
+ const location = obj.location;
82
+ const exportNode = SchemaRegistry.fromObject(obj.exportNode);
83
+ const alias = obj.alias;
84
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
85
+ return new ExportSchema(location, name, exportNode, alias, doc);
86
+ }
87
+
88
+ static isExportSchema(node: SchemaNode): node is ExportSchema {
89
+ return 'exportNode' in node;
90
+ }
91
+ }
@@ -0,0 +1,51 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class ExpressionWithTypeArgumentsSchema extends SchemaNode {
5
+ readonly typeArgs: SchemaNode[];
6
+ readonly expression: SchemaNode;
7
+
8
+ constructor(
9
+ typeArgs: SchemaNode[],
10
+ expression: SchemaNode,
11
+ readonly name: string,
12
+ readonly location: SchemaLocation
13
+ ) {
14
+ super();
15
+ this.typeArgs = typeArgs;
16
+ this.expression = expression;
17
+ }
18
+
19
+ toString() {
20
+ return this.name;
21
+ }
22
+
23
+ toFullSignature(options?: { showDocs?: boolean }): string {
24
+ let result = this.name;
25
+
26
+ if (this.typeArgs && this.typeArgs.length > 0) {
27
+ const typeArgsStr = this.typeArgs.map((arg) => arg.toFullSignature(options)).join(', ');
28
+ result += `<${typeArgsStr}>`;
29
+ }
30
+
31
+ return result;
32
+ }
33
+
34
+ toObject() {
35
+ return {
36
+ ...super.toObject(),
37
+ name: this.name,
38
+ location: this.location,
39
+ typeArgs: this.typeArgs.map((typeArg) => typeArg.toObject()),
40
+ expression: this.expression,
41
+ };
42
+ }
43
+
44
+ static fromObject(obj: Record<string, any>): ExpressionWithTypeArgumentsSchema {
45
+ const name = obj.name;
46
+ const location = obj.location;
47
+ const typeArgs = obj.typeArgs.map((typeArg: any) => SchemaRegistry.fromObject(typeArg));
48
+ const expression = SchemaRegistry.fromObject(obj.expression);
49
+ return new ExpressionWithTypeArgumentsSchema(typeArgs, expression, name, location);
50
+ }
51
+ }
@@ -0,0 +1,154 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
+ import { DocSchema } from './docs';
5
+ import { TagName } from './docs/tag';
6
+ import { SchemaRegistry } from '../schema-registry';
7
+
8
+ export type Modifier =
9
+ | 'static'
10
+ | 'public'
11
+ | 'private'
12
+ | 'protected'
13
+ | 'readonly'
14
+ | 'abstract'
15
+ | 'async'
16
+ | 'override'
17
+ | 'export';
18
+
19
+ /**
20
+ * function-like can be a function, method, arrow-function, variable-function, etc.
21
+ */
22
+ export class FunctionLikeSchema extends SchemaNode {
23
+ readonly returnType: SchemaNode;
24
+ readonly params: ParameterSchema[];
25
+ readonly doc?: DocSchema;
26
+ readonly signature?: string | undefined;
27
+ readonly displaySchemaName = 'Functions';
28
+
29
+ constructor(
30
+ readonly location: SchemaLocation,
31
+ readonly name: string,
32
+ params: ParameterSchema[],
33
+ returnType: SchemaNode,
34
+ signature: string,
35
+ readonly modifiers: Modifier[] = [],
36
+ doc?: DocSchema,
37
+ readonly typeParams?: string[],
38
+ readonly decorators?: SchemaNode[]
39
+ ) {
40
+ super();
41
+ this.params = params;
42
+ this.returnType = returnType;
43
+ this.doc = doc;
44
+ this.signature = signature || FunctionLikeSchema.createSignature(this.name, this.params, this.returnType);
45
+ }
46
+
47
+ getNodes() {
48
+ return [...this.params, this.returnType, ...(this.decorators || [])];
49
+ }
50
+
51
+ toString(options?: { color?: boolean }) {
52
+ const bold = options?.color ? chalk.bold : (text: string) => text;
53
+ const paramsStr = this.params.map((param) => param.toString()).join(', ');
54
+ const typeParamsStr = this.typeParams ? `<${this.typeParams.join(', ')}>` : '';
55
+ const decoratorsStr = this.decorators?.map((decorator) => decorator.toString(options)).join('\n');
56
+ return `${this.decorators ? `${decoratorsStr}\n` : ''}${this.modifiersToString()}${typeParamsStr}${bold(
57
+ this.name
58
+ )}(${paramsStr}): ${this.returnType.toString(options)}`;
59
+ }
60
+
61
+ toFullSignature(options?: { showDocs?: boolean }): string {
62
+ let result = '';
63
+ if (options?.showDocs && this.doc) {
64
+ result += `${this.doc.toFullSignature()}\n`;
65
+ }
66
+ const decoratorsStr = this.decorators?.map((decorator) => decorator.toString()).join('\n');
67
+ if (decoratorsStr) {
68
+ result += `${decoratorsStr}\n`;
69
+ }
70
+ const modifiersStr = this.modifiersToString();
71
+ const typeParamsStr = this.typeParams ? `<${this.typeParams.join(', ')}>` : '';
72
+ const paramsStr = this.params
73
+ .map((param) => {
74
+ let paramStr = '';
75
+ if (param.isSpread) {
76
+ paramStr += '...';
77
+ }
78
+ paramStr += param.name;
79
+ if (param.isOptional) {
80
+ paramStr += '?';
81
+ }
82
+ paramStr += `: ${param.type.toString()}`;
83
+ if (param.defaultValue !== undefined) {
84
+ paramStr += ` = ${param.defaultValue}`;
85
+ }
86
+ return paramStr;
87
+ })
88
+ .join(', ');
89
+ result += `${modifiersStr}${this.name}${typeParamsStr}(${paramsStr}): ${this.returnType.toString()}`;
90
+ return result;
91
+ }
92
+
93
+ isDeprecated(): boolean {
94
+ return Boolean(this.doc?.hasTag(TagName.deprecated));
95
+ }
96
+
97
+ isPrivate(): boolean {
98
+ return Boolean(this.modifiers.find((m) => m === 'private') || this.doc?.hasTag(TagName.private));
99
+ }
100
+
101
+ generateSignature(): string {
102
+ return FunctionLikeSchema.createSignature(this.name, this.params, this.returnType, this.decorators);
103
+ }
104
+
105
+ static createSignature(
106
+ name: string,
107
+ params: ParameterSchema[],
108
+ returnType: SchemaNode,
109
+ decorators?: SchemaNode[]
110
+ ): string {
111
+ const paramsStr = params
112
+ .map((param) => {
113
+ let type = param.type.toString();
114
+ if (param.isSpread) type = `...${type}`;
115
+ return `${param.name}${param.isOptional ? '?' : ''}: ${type}`;
116
+ })
117
+ .join(', ');
118
+ const decoratorsStr = decorators?.map((decorator) => decorator.toString()).join('\n');
119
+ return `${decorators ? `${decoratorsStr}\n` : ''}${name}(${paramsStr}): ${returnType.toString()}`;
120
+ }
121
+
122
+ toObject() {
123
+ return {
124
+ ...super.toObject(),
125
+ name: this.name,
126
+ params: this.params.map((param) => param.toObject()),
127
+ returnType: this.returnType.toObject(),
128
+ signature: this.signature,
129
+ modifiers: this.modifiers,
130
+ doc: this.doc?.toObject(),
131
+ typeParams: this.typeParams,
132
+ decorators: this.decorators?.map((decorator) => decorator.toObject()),
133
+ };
134
+ }
135
+
136
+ static fromObject(obj: Record<string, any>) {
137
+ return new FunctionLikeSchema(
138
+ obj.location,
139
+ obj.name,
140
+ obj.params.map((param: Record<string, any>) => ParameterSchema.fromObject(param)),
141
+ SchemaRegistry.fromObject(obj.returnType),
142
+ obj.signature,
143
+ obj.modifiers,
144
+ obj.doc ? DocSchema.fromObject(obj.doc) : undefined,
145
+ obj.typeParams,
146
+ obj.decorators?.map((decorator) => SchemaRegistry.fromObject(decorator))
147
+ );
148
+ }
149
+
150
+ private modifiersToString() {
151
+ const modifiersToPrint = this.modifiers.filter((modifier) => modifier !== 'export');
152
+ return modifiersToPrint.length ? `${modifiersToPrint.join(' ')} ` : '';
153
+ }
154
+ }
@@ -0,0 +1,57 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { SchemaRegistry } from '../schema-registry';
4
+
5
+ export class GetAccessorSchema extends SchemaNode {
6
+ readonly type: SchemaNode;
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly name: string,
10
+ type: SchemaNode,
11
+ readonly signature: string
12
+ ) {
13
+ super();
14
+ this.type = type;
15
+ }
16
+ getSignature() {
17
+ return this.signature;
18
+ }
19
+
20
+ getNodes() {
21
+ return [this.type];
22
+ }
23
+
24
+ toString(options?: { color?: boolean }): string {
25
+ const bold = options?.color ? chalk.bold : (x: string) => x;
26
+ return `get ${bold(this.name)}(): ${this.type.toString(options)}`;
27
+ }
28
+
29
+ toFullSignature(options?: { showDocs?: boolean }): string {
30
+ let result = '';
31
+
32
+ if (options?.showDocs && this.doc) {
33
+ result += `${this.doc.toFullSignature()}\n`;
34
+ }
35
+
36
+ result += `get ${this.name}(): ${this.type.toFullSignature(options)}`;
37
+
38
+ return result;
39
+ }
40
+
41
+ toObject() {
42
+ return {
43
+ ...super.toObject(),
44
+ name: this.name,
45
+ type: this.type.toObject(),
46
+ signature: this.signature,
47
+ };
48
+ }
49
+
50
+ static fromObject(obj: Record<string, any>): GetAccessorSchema {
51
+ const location = obj.location;
52
+ const name = obj.name;
53
+ const type = SchemaRegistry.fromObject(obj.type);
54
+ const signature = obj.signature;
55
+ return new GetAccessorSchema(location, name, type, signature);
56
+ }
57
+ }
@@ -0,0 +1,43 @@
1
+ import { DocSchema, SchemaRegistry } from '..';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+
4
+ export class IgnoredSchema extends SchemaNode {
5
+ public location: SchemaLocation;
6
+ public doc?: DocSchema;
7
+ public name?: string;
8
+
9
+ constructor(public readonly node: SchemaNode) {
10
+ super();
11
+ this.location = node.location;
12
+ this.doc = node.doc;
13
+ this.name = node.name;
14
+ }
15
+
16
+ getNodes() {
17
+ return [];
18
+ }
19
+
20
+ getAllNodesRecursively(): SchemaNode[] {
21
+ return [];
22
+ }
23
+
24
+ toString() {
25
+ return '';
26
+ }
27
+
28
+ toFullSignature(): string {
29
+ return '';
30
+ }
31
+
32
+ toObject() {
33
+ return {
34
+ ...super.toObject(),
35
+ node: this.node.toObject(),
36
+ };
37
+ }
38
+
39
+ static fromObject(obj: Record<string, any>): IgnoredSchema {
40
+ const node = SchemaRegistry.fromObject(obj.node);
41
+ return new IgnoredSchema(node);
42
+ }
43
+ }
@@ -0,0 +1,49 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+ import { ParameterSchema } from './parameter';
4
+
5
+ /**
6
+ * [key: number]: string
7
+ * keyType: number
8
+ * valueType: string
9
+ */
10
+ export class IndexSignatureSchema extends SchemaNode {
11
+ readonly keyType: SchemaNode;
12
+ readonly valueType: SchemaNode;
13
+ constructor(
14
+ readonly location: SchemaLocation,
15
+ keyType: ParameterSchema,
16
+ valueType: SchemaNode
17
+ ) {
18
+ super();
19
+ this.keyType = keyType;
20
+ this.valueType = valueType;
21
+ }
22
+
23
+ toString() {
24
+ return `[${this.keyType.toString()}]: ${this.valueType.toString()}`;
25
+ }
26
+
27
+ toFullSignature(options?: { showDocs?: boolean }): string {
28
+ const keyTypeStr = this.keyType.toFullSignature(options);
29
+ const valueTypeStr = this.valueType.toFullSignature(options);
30
+
31
+ return `[${keyTypeStr}]: ${valueTypeStr}`;
32
+ }
33
+
34
+ toObject() {
35
+ return {
36
+ ...super.toObject(),
37
+ location: this.location,
38
+ keyType: this.keyType.toObject(),
39
+ valueType: this.valueType.toObject(),
40
+ };
41
+ }
42
+
43
+ static fromObject(obj: Record<string, any>): IndexSignatureSchema {
44
+ const location = obj.location;
45
+ const keyType = ParameterSchema.fromObject(obj.keyType);
46
+ const valueType = SchemaRegistry.fromObject(obj.valueType);
47
+ return new IndexSignatureSchema(location, keyType, valueType);
48
+ }
49
+ }
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Ensure that any new Schema class ends with the word 'Schema'
3
+ * This will make sure that the Class Name is not minimized during prod bundling process
4
+ * and the schemaObjToClass can match and instantiate the Schema Class correctly
5
+ */
6
+ export { ModuleSchema } from './module';
7
+ export { FunctionLikeSchema } from './function-like';
8
+ export { TypeRefSchema } from './type-ref';
9
+ export { VariableLikeSchema } from './variable-like';
10
+ export { ClassSchema } from './class';
11
+ export { ConstructorSchema } from './constructor';
12
+ export { TypeSchema } from './type';
13
+ export { TypeIntersectionSchema } from './type-intersection';
14
+ export { TypeUnionSchema } from './type-union';
15
+ export { TypeLiteralSchema } from './type-literal';
16
+ export { IndexSignatureSchema } from './index-signature';
17
+ export { InterfaceSchema } from './interface';
18
+ export { GetAccessorSchema } from './get-accessor';
19
+ export { SetAccessorSchema } from './set-accessor';
20
+ export { TypeQuerySchema } from './type-query';
21
+ export { InferenceTypeSchema } from './inference-type';
22
+ export { LiteralTypeSchema } from './literal-type';
23
+ export { KeywordTypeSchema } from './keyword-type';
24
+ export { TypeArraySchema } from './type-array';
25
+ export { TypeOperatorSchema } from './type-operator';
26
+ export { TupleTypeSchema } from './tuple-type';
27
+ export { ParameterSchema } from './parameter';
28
+ export { EnumSchema } from './enum';
29
+ export { EnumMemberSchema } from './enum-member';
30
+ export { ParenthesizedTypeSchema } from './parenthesized-type';
31
+ export { TypePredicateSchema } from './type-predicate';
32
+ export { IndexedAccessSchema } from './indexed-access-type';
33
+ export { TemplateLiteralTypeSchema } from './template-literal-type';
34
+ export { TemplateLiteralTypeSpanSchema } from './template-literal-type-span';
35
+ export { ThisTypeSchema } from './this-type';
36
+ export { UnknownSchema } from './unknown-schema';
37
+ export { UnresolvedSchema } from './unresolved-schema';
38
+ export { ConditionalTypeSchema } from './conditional-type';
39
+ export { ExpressionWithTypeArgumentsSchema } from './expression-with-arguments';
40
+ export { NamedTupleSchema } from './named-tuple';
41
+ export { UnImplementedSchema } from './unimplemented-schema';
42
+ export { ObjectLiteralExpressionSchema } from './object-literal-expression';
43
+ export { ArrayLiteralExpressionSchema } from './array-literal-expression';
44
+ export { PropertyAssignmentSchema } from './property-assignment';
45
+ export { DecoratorSchema } from './decorator';
46
+ export { LiteralValueSchema } from './literal-value';
47
+ export { IgnoredSchema } from './ignored';
48
+ export { ExportSchema } from './export';
49
+ export * from './docs';
@@ -0,0 +1,47 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class IndexedAccessSchema extends SchemaNode {
5
+ readonly objectType: SchemaNode;
6
+ readonly indexType: SchemaNode;
7
+
8
+ constructor(
9
+ readonly location: SchemaLocation,
10
+ objectType: SchemaNode,
11
+ indexType: SchemaNode
12
+ ) {
13
+ super();
14
+ this.objectType = objectType;
15
+ this.indexType = indexType;
16
+ }
17
+
18
+ getNodes() {
19
+ return [this.objectType, this.indexType];
20
+ }
21
+
22
+ toString() {
23
+ return `${this.objectType.toString()}[${this.indexType.toString()}]`;
24
+ }
25
+
26
+ toFullSignature(options?: { showDocs?: boolean }): string {
27
+ const objectTypeStr = this.objectType.toFullSignature(options);
28
+ const indexTypeStr = this.indexType.toFullSignature(options);
29
+
30
+ return `${objectTypeStr}[${indexTypeStr}]`;
31
+ }
32
+
33
+ toObject() {
34
+ return {
35
+ ...super.toObject(),
36
+ objectType: this.objectType.toObject(),
37
+ indexType: this.indexType.toObject(),
38
+ };
39
+ }
40
+
41
+ static fromObject(obj: Record<string, any>): IndexedAccessSchema {
42
+ const location = obj.location;
43
+ const objectType = SchemaRegistry.fromObject(obj.objectType);
44
+ const indexType = SchemaRegistry.fromObject(obj.indexType);
45
+ return new IndexedAccessSchema(location, objectType, indexType);
46
+ }
47
+ }
@@ -0,0 +1,60 @@
1
+ import { SchemaLocation, 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 extends SchemaNode {
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly type: string,
10
+ readonly name?: string,
11
+ readonly defaultValue?: string,
12
+ readonly isSpread?: boolean,
13
+ readonly alias?: string
14
+ ) {
15
+ super();
16
+ }
17
+
18
+ toString() {
19
+ if (this.name && this.name !== this.type) {
20
+ return `${this.name}: ${this.type}`;
21
+ }
22
+ return this.type;
23
+ }
24
+
25
+ toFullSignature(): string {
26
+ let result = '';
27
+
28
+ if (this.name && this.name !== this.type) {
29
+ result += `${this.name}: `;
30
+ }
31
+
32
+ result += this.type;
33
+
34
+ if (this.defaultValue !== undefined) {
35
+ result += ` = ${this.defaultValue}`;
36
+ }
37
+
38
+ return result;
39
+ }
40
+
41
+ toObject() {
42
+ return {
43
+ ...super.toObject(),
44
+ type: this.type,
45
+ defaultValue: this.defaultValue,
46
+ isSpread: this.isSpread,
47
+ alias: this.alias,
48
+ };
49
+ }
50
+
51
+ static fromObject(obj: Record<string, any>): InferenceTypeSchema {
52
+ const location = obj.location;
53
+ const type = obj.type;
54
+ const name = obj.name;
55
+ const defaultValue = obj.defaultValue;
56
+ const isSpread = obj.isSpread;
57
+ const alias = obj.alias;
58
+ return new InferenceTypeSchema(location, type, name, defaultValue, isSpread, alias);
59
+ }
60
+ }
@@ -0,0 +1,94 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { DocSchema } from './docs';
4
+ import { ExpressionWithTypeArgumentsSchema } from './expression-with-arguments';
5
+ import { SchemaRegistry } from '../schema-registry';
6
+
7
+ export class InterfaceSchema extends SchemaNode {
8
+ readonly members: SchemaNode[];
9
+ readonly doc?: DocSchema;
10
+
11
+ constructor(
12
+ readonly location: SchemaLocation,
13
+ readonly name: string,
14
+ readonly signature: string,
15
+ readonly extendsNodes: ExpressionWithTypeArgumentsSchema[],
16
+ members: SchemaNode[],
17
+ doc?: DocSchema,
18
+ readonly typeParams?: string[]
19
+ ) {
20
+ super();
21
+ this.members = members;
22
+ this.doc = doc;
23
+ }
24
+
25
+ getNodes() {
26
+ return this.members;
27
+ }
28
+
29
+ toString(options?: { color?: boolean }): string {
30
+ const boldUnderline = options?.color ? chalk.bold.underline : (str: string) => str;
31
+ const membersStr = this.members.map((m) => `* ${m.toString(options)}`).join('\n');
32
+ return `${boldUnderline(this.name)}\n${membersStr}`;
33
+ }
34
+
35
+ toFullSignature(options?: { showDocs?: boolean }): string {
36
+ let result = '';
37
+
38
+ if (options?.showDocs && this.doc) {
39
+ result += `${this.doc.toFullSignature()}\n`;
40
+ }
41
+
42
+ let interfaceDeclaration = `interface ${this.name}`;
43
+
44
+ if (this.typeParams && this.typeParams.length > 0) {
45
+ interfaceDeclaration += `<${this.typeParams.join(', ')}>`;
46
+ }
47
+
48
+ if (this.extendsNodes && this.extendsNodes.length > 0) {
49
+ const extendsStr = this.extendsNodes.map((node) => node.toFullSignature(options)).join(', ');
50
+ interfaceDeclaration += ` extends ${extendsStr}`;
51
+ }
52
+
53
+ result += `${interfaceDeclaration} {\n`;
54
+
55
+ const membersStr = this.members
56
+ .map((member) => {
57
+ const memberStr = member.toFullSignature(options);
58
+ return memberStr
59
+ .split('\n')
60
+ .map((line) => ` ${line}`)
61
+ .join('\n');
62
+ })
63
+ .join('\n');
64
+
65
+ result += `${membersStr}\n`;
66
+
67
+ result += `}`;
68
+
69
+ return result;
70
+ }
71
+
72
+ toObject() {
73
+ return {
74
+ ...super.toObject(),
75
+ name: this.name,
76
+ members: this.members.map((member) => member.toObject()),
77
+ doc: this.doc?.toObject(),
78
+ signature: this.signature,
79
+ extendsNodes: this.extendsNodes?.map((node) => node.toObject()),
80
+ typeParams: this.typeParams,
81
+ };
82
+ }
83
+
84
+ static fromObject(obj: Record<string, any>): InterfaceSchema {
85
+ const location = obj.location;
86
+ const name = obj.name;
87
+ const signature = obj.signature;
88
+ const extendsNodes = obj.extendsNodes?.map((node: any) => ExpressionWithTypeArgumentsSchema.fromObject(node));
89
+ const members = obj.members.map((member: any) => SchemaRegistry.fromObject(member));
90
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
91
+ const typeParams = obj.typeParams;
92
+ return new InterfaceSchema(location, name, signature, extendsNodes, members, doc, typeParams);
93
+ }
94
+ }