@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,34 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. 'string', 'boolean', etc.
5
+ */
6
+ export class KeywordTypeSchema extends SchemaNode {
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly name: string
10
+ ) {
11
+ super();
12
+ }
13
+
14
+ toString() {
15
+ return this.name;
16
+ }
17
+
18
+ toFullSignature(): string {
19
+ return this.toString();
20
+ }
21
+
22
+ toObject() {
23
+ return {
24
+ ...super.toObject(),
25
+ name: this.name,
26
+ };
27
+ }
28
+
29
+ static fromObject(obj: Record<string, any>): KeywordTypeSchema {
30
+ const location = obj.location;
31
+ const name = obj.name;
32
+ return new KeywordTypeSchema(location, name);
33
+ }
34
+ }
@@ -0,0 +1,34 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. const a: 'a';
5
+ */
6
+ export class LiteralTypeSchema extends SchemaNode {
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly name: string
10
+ ) {
11
+ super();
12
+ }
13
+
14
+ toObject() {
15
+ return {
16
+ ...super.toObject(),
17
+ name: this.name,
18
+ };
19
+ }
20
+
21
+ toString() {
22
+ return this.name;
23
+ }
24
+
25
+ toFullSignature(): string {
26
+ return this.toString();
27
+ }
28
+
29
+ static fromObject(obj: Record<string, any>): LiteralTypeSchema {
30
+ const location = obj.location;
31
+ const name = obj.name;
32
+ return new LiteralTypeSchema(location, name);
33
+ }
34
+ }
@@ -0,0 +1,32 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+
3
+ export class LiteralValueSchema extends SchemaNode {
4
+ constructor(
5
+ readonly location: SchemaLocation,
6
+ readonly value: string
7
+ ) {
8
+ super();
9
+ this.value = this.value.replace(/^['"]|['"]$/g, '');
10
+ }
11
+
12
+ toString() {
13
+ return this.value;
14
+ }
15
+
16
+ toFullSignature(): string {
17
+ return this.toString();
18
+ }
19
+
20
+ toObject() {
21
+ return {
22
+ ...super.toObject(),
23
+ value: this.value,
24
+ };
25
+ }
26
+
27
+ static fromObject(obj: Record<string, any>): LiteralValueSchema {
28
+ const location = obj.location;
29
+ const value = obj.value;
30
+ return new LiteralValueSchema(location, value);
31
+ }
32
+ }
@@ -0,0 +1,87 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { SchemaRegistry } from '../schema-registry';
4
+ import { ExportSchema } from './export';
5
+
6
+ export class ModuleSchema extends SchemaNode {
7
+ // exports could either be re exports (export declarations) or nodes with export modifier
8
+ exports: SchemaNode[];
9
+ internals: SchemaNode[];
10
+ namespace?: string;
11
+
12
+ constructor(
13
+ readonly location: SchemaLocation,
14
+ exports: SchemaNode[],
15
+ internals: SchemaNode[]
16
+ ) {
17
+ super();
18
+ this.exports = exports;
19
+ this.internals = internals;
20
+ }
21
+
22
+ getNodes() {
23
+ return [...this.exports, ...this.internals];
24
+ }
25
+
26
+ flatExportsRecursively() {
27
+ this.exports = this.exports.reduce(
28
+ (acc, exp) => {
29
+ if (exp instanceof ModuleSchema) {
30
+ exp.flatExportsRecursively();
31
+ if (exp.namespace) return [...acc, exp];
32
+ return [...acc, ...exp.exports];
33
+ }
34
+ return [...acc, exp];
35
+ },
36
+ [] as (ExportSchema | SchemaNode)[]
37
+ );
38
+ }
39
+
40
+ toString(options?: { color?: boolean }) {
41
+ if (!this.namespace)
42
+ throw new Error(
43
+ 'toString() should not be called on a module without namespace, make sure this.flatExportsRecursively() is called'
44
+ );
45
+ const boldUnderline = options?.color ? chalk.bold.underline : (str: string) => str;
46
+
47
+ const exportsStr = this.exports.map((m) => `* ${m.toString(options)}`).join('\n');
48
+ return `${boldUnderline(this.namespace)}\n${exportsStr}`;
49
+ }
50
+
51
+ toFullSignature(options?: { showDocs?: boolean }): string {
52
+ if (!this.namespace)
53
+ throw new Error(
54
+ 'toFullSignature() should not be called on a module without namespace; make sure this.flatExportsRecursively() is called'
55
+ );
56
+
57
+ const exportsSignatures = this.exports.map((m) => m.toFullSignature(options)).join('\n');
58
+
59
+ let signature = `${this.namespace}\n${exportsSignatures}`;
60
+
61
+ if (options?.showDocs && this.doc) {
62
+ const docString = this.doc.toFullSignature();
63
+ signature = `${docString}\n${signature}`;
64
+ }
65
+
66
+ return signature;
67
+ }
68
+
69
+ toObject() {
70
+ return {
71
+ ...super.toObject(),
72
+ exports: this.exports.map((member) => member.toObject()),
73
+ internals: this.internals.map((member) => member.toObject()),
74
+ namespace: this.namespace,
75
+ };
76
+ }
77
+
78
+ static fromObject(obj: Record<string, any>): ModuleSchema {
79
+ const location = obj.location;
80
+ const exportNodes = (obj.exports || []).map((member: any) => SchemaRegistry.fromObject(member));
81
+ const internals = (obj.internals || []).map((member: any) => SchemaRegistry.fromObject(member));
82
+ const namespace = obj.namespace;
83
+ const module = new ModuleSchema(location, exportNodes, internals);
84
+ module.namespace = namespace;
85
+ return module;
86
+ }
87
+ }
@@ -0,0 +1,39 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class NamedTupleSchema extends SchemaNode {
5
+ constructor(
6
+ readonly location: SchemaLocation,
7
+ readonly type: SchemaNode,
8
+ readonly name?: string
9
+ ) {
10
+ super();
11
+ }
12
+
13
+ getNodes() {
14
+ return [this.type];
15
+ }
16
+
17
+ toString(options?: { color?: boolean }): string {
18
+ return `${this.name}: ${this.type.toString(options)}`;
19
+ }
20
+
21
+ toFullSignature(options?: { showDocs?: boolean }): string {
22
+ return `${this.name}: ${this.type.toFullSignature(options)}`;
23
+ }
24
+
25
+ toObject() {
26
+ return {
27
+ ...super.toObject(),
28
+ name: this.name,
29
+ type: this.type.toObject(),
30
+ };
31
+ }
32
+
33
+ static fromObject(obj: Record<string, any>): NamedTupleSchema {
34
+ const location = obj.location;
35
+ const type = SchemaRegistry.fromObject(obj.type);
36
+ const name = obj.name;
37
+ return new NamedTupleSchema(location, type, name);
38
+ }
39
+ }
@@ -0,0 +1,42 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class ObjectLiteralExpressionSchema extends SchemaNode {
5
+ constructor(
6
+ readonly members: SchemaNode[],
7
+ readonly location: SchemaLocation
8
+ ) {
9
+ super();
10
+ }
11
+
12
+ getNodes() {
13
+ return this.members;
14
+ }
15
+
16
+ toString(options?: { color?: boolean }): string {
17
+ return `{\n${this.members.map((member) => `\t${member.toString(options)}`).join('\n')}\n}`;
18
+ }
19
+
20
+ toFullSignature(options?: { showDocs?: boolean }): string {
21
+ const membersStr = this.members.map((member) => member.toFullSignature(options)).join(',\n');
22
+
23
+ return `{\n${membersStr
24
+ .split('\n')
25
+ .map((line) => ` ${line}`)
26
+ .join('\n')}\n}`;
27
+ }
28
+
29
+ toObject() {
30
+ return {
31
+ ...super.toObject(),
32
+ members: this.members.map((element) => element.toObject()),
33
+ location: this.location,
34
+ };
35
+ }
36
+
37
+ static fromObject(obj: Record<string, any>): ObjectLiteralExpressionSchema {
38
+ const members = obj.members.map((member) => SchemaRegistry.fromObject(member));
39
+ const location = obj.location;
40
+ return new ObjectLiteralExpressionSchema(members, location);
41
+ }
42
+ }
@@ -0,0 +1,104 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class ParameterSchema<T extends SchemaNode = SchemaNode> extends SchemaNode {
5
+ readonly type: T;
6
+ readonly objectBindingNodes?: SchemaNode[];
7
+
8
+ getNodes(): SchemaNode[] {
9
+ return [this.type, ...(this.objectBindingNodes || [])];
10
+ }
11
+
12
+ constructor(
13
+ readonly location: SchemaLocation,
14
+ readonly name: string,
15
+ type: T,
16
+ readonly isOptional: boolean,
17
+ readonly defaultValue?: any,
18
+ readonly description?: string,
19
+ objectBindingNodes?: SchemaNode[],
20
+ readonly isSpread: boolean = false
21
+ ) {
22
+ super();
23
+ this.type = type;
24
+ this.objectBindingNodes = objectBindingNodes;
25
+ }
26
+
27
+ toString() {
28
+ return `${this.name}${this.isOptional ? '?' : ''}: ${this.type.toString()}`;
29
+ }
30
+
31
+ toFullSignature(options?: { showDocs?: boolean }): string {
32
+ let paramStr = '';
33
+
34
+ if (options?.showDocs && this.description) {
35
+ paramStr += `/** ${this.description} */\n`;
36
+ }
37
+
38
+ if (this.isSpread) {
39
+ paramStr += '...';
40
+ }
41
+
42
+ let paramName = '';
43
+
44
+ if (this.objectBindingNodes && this.objectBindingNodes.length > 0) {
45
+ const bindingsStr = this.objectBindingNodes.map((node) => node.toFullSignature(options)).join(', ');
46
+ paramName += `{ ${bindingsStr} }`;
47
+ } else {
48
+ paramName += this.name;
49
+ }
50
+
51
+ if (this.isOptional) {
52
+ paramName += '?';
53
+ }
54
+
55
+ paramStr += `${paramName}`;
56
+
57
+ if (this.type && typeof this.type.toString === 'function') {
58
+ const typeName = this.type.toString();
59
+ if (typeName) {
60
+ paramStr += `: ${typeName}`;
61
+ }
62
+ }
63
+
64
+ if (this.defaultValue !== undefined) {
65
+ paramStr += ` = ${this.defaultValue}`;
66
+ }
67
+
68
+ return paramStr;
69
+ }
70
+
71
+ toObject() {
72
+ return {
73
+ ...super.toObject(),
74
+ name: this.name,
75
+ type: this.type.toObject(),
76
+ isOptional: this.isOptional,
77
+ defaultValue: this.defaultValue,
78
+ description: this.description,
79
+ objectBindingNodes: this.objectBindingNodes?.map((node) => node.toObject()),
80
+ isSpread: this.isSpread,
81
+ };
82
+ }
83
+
84
+ static fromObject<T extends SchemaNode = SchemaNode>(obj: Record<string, any>): ParameterSchema<T> {
85
+ const location = obj.location;
86
+ const name = obj.name;
87
+ const type = SchemaRegistry.fromObject(obj.type);
88
+ const isOptional = obj.isOptional;
89
+ const defaultValue = obj.defaultValue;
90
+ const description = obj.description;
91
+ const isSpread = obj.isSpread;
92
+ const objectBindingNodes = obj.objectBindingNodes?.map((node: any) => SchemaRegistry.fromObject(node));
93
+ return new ParameterSchema(
94
+ location,
95
+ name,
96
+ type,
97
+ isOptional,
98
+ defaultValue,
99
+ description,
100
+ objectBindingNodes,
101
+ isSpread
102
+ );
103
+ }
104
+ }
@@ -0,0 +1,42 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ /**
5
+ * type inside parentheses
6
+ * e.g. (T1 | T2)
7
+ */
8
+ export class ParenthesizedTypeSchema extends SchemaNode {
9
+ readonly type: SchemaNode;
10
+ constructor(
11
+ readonly location: SchemaLocation,
12
+ type: SchemaNode
13
+ ) {
14
+ super();
15
+ this.type = type;
16
+ }
17
+
18
+ getNodes() {
19
+ return [this.type];
20
+ }
21
+
22
+ toString(options?: { color?: boolean }): string {
23
+ return `(${this.type.toString(options)})`;
24
+ }
25
+
26
+ toFullSignature(options?: { showDocs?: boolean }): string {
27
+ return `(${this.type.toFullSignature(options)})`;
28
+ }
29
+
30
+ toObject() {
31
+ return {
32
+ ...super.toObject(),
33
+ type: this.type.toObject(),
34
+ };
35
+ }
36
+
37
+ static fromObject(obj: Record<string, any>): ParenthesizedTypeSchema {
38
+ const location = obj.location;
39
+ const type = SchemaRegistry.fromObject(obj.type);
40
+ return new ParenthesizedTypeSchema(location, type);
41
+ }
42
+ }
@@ -0,0 +1,50 @@
1
+ import { SchemaNode, SchemaLocation } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+ import { DocSchema } from './docs';
4
+
5
+ export class PropertyAssignmentSchema extends SchemaNode {
6
+ constructor(
7
+ readonly name: string,
8
+ readonly value: SchemaNode,
9
+ readonly location: SchemaLocation,
10
+ readonly doc?: DocSchema
11
+ ) {
12
+ super();
13
+ }
14
+
15
+ toString(options?: { color?: boolean }): string {
16
+ return `${this.name}: ${this.value.toString(options)}`;
17
+ }
18
+
19
+ toFullSignature(options?: { showDocs?: boolean }): string {
20
+ let result = '';
21
+
22
+ if (options?.showDocs && this.doc) {
23
+ result += `${this.doc.toFullSignature()}\n`;
24
+ }
25
+
26
+ const valueStr = this.value.toFullSignature(options);
27
+
28
+ result += `${this.name}: ${valueStr}`;
29
+
30
+ return result;
31
+ }
32
+
33
+ toObject() {
34
+ return {
35
+ ...super.toObject(),
36
+ name: this.name,
37
+ value: this.value.toObject(),
38
+ doc: this.doc?.toObject(),
39
+ location: this.location,
40
+ };
41
+ }
42
+
43
+ static fromObject(obj: Record<string, any>): PropertyAssignmentSchema {
44
+ const name = obj.name;
45
+ const value = SchemaRegistry.fromObject(obj.value);
46
+ const location = obj.location;
47
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
48
+ return new PropertyAssignmentSchema(name, value, location, doc);
49
+ }
50
+ }
@@ -0,0 +1,47 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { ParameterSchema } from './parameter';
4
+
5
+ export class SetAccessorSchema extends SchemaNode {
6
+ readonly param: ParameterSchema;
7
+
8
+ constructor(
9
+ readonly location: SchemaLocation,
10
+ readonly name: string,
11
+ param: ParameterSchema,
12
+ readonly signature: string
13
+ ) {
14
+ super();
15
+ this.param = param;
16
+ }
17
+
18
+ getSignature() {
19
+ return this.signature;
20
+ }
21
+
22
+ toString() {
23
+ return `set ${chalk.bold(this.name)}(${this.param.toString()})`;
24
+ }
25
+
26
+ toFullSignature(options?: { showDocs?: boolean }): string {
27
+ const paramStr = this.param.toFullSignature(options);
28
+ return `set ${this.name}(${paramStr})`;
29
+ }
30
+
31
+ toObject() {
32
+ return {
33
+ ...super.toObject(),
34
+ name: this.name,
35
+ param: this.param.toObject(),
36
+ signature: this.signature,
37
+ };
38
+ }
39
+
40
+ static fromObject(obj: Record<string, any>): SetAccessorSchema {
41
+ const location = obj.location;
42
+ const name = obj.name;
43
+ const param = ParameterSchema.fromObject(obj.param);
44
+ const signature = obj.signature;
45
+ return new SetAccessorSchema(location, name, param, signature);
46
+ }
47
+ }
@@ -0,0 +1,42 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class TemplateLiteralTypeSpanSchema extends SchemaNode {
5
+ type: SchemaNode;
6
+
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly literal: string,
10
+ type: SchemaNode
11
+ ) {
12
+ super();
13
+ this.type = type;
14
+ }
15
+
16
+ getNodes() {
17
+ return [this.type];
18
+ }
19
+
20
+ toString(options?: { color?: boolean }) {
21
+ return `${this.type.toString(options)} ${this.literal}`;
22
+ }
23
+
24
+ toFullSignature(options?: { showDocs?: boolean }): string {
25
+ return `${this.type.toFullSignature(options)} ${this.literal}`;
26
+ }
27
+
28
+ toObject() {
29
+ return {
30
+ ...super.toObject(),
31
+ literal: this.literal,
32
+ type: this.type.toObject(),
33
+ };
34
+ }
35
+
36
+ static fromObject(obj: Record<string, any>): TemplateLiteralTypeSpanSchema {
37
+ const location = obj.location;
38
+ const literal = obj.literal;
39
+ const type = SchemaRegistry.fromObject(obj.type);
40
+ return new TemplateLiteralTypeSpanSchema(location, literal, type);
41
+ }
42
+ }
@@ -0,0 +1,40 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { TemplateLiteralTypeSpanSchema } from './template-literal-type-span';
3
+
4
+ export class TemplateLiteralTypeSchema extends SchemaNode {
5
+ readonly templateSpans: TemplateLiteralTypeSpanSchema[];
6
+
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly head: string,
10
+ templateSpans: TemplateLiteralTypeSpanSchema[]
11
+ ) {
12
+ super();
13
+ this.templateSpans = templateSpans;
14
+ }
15
+
16
+ toString(options?: { color?: boolean }) {
17
+ const spans = this.templateSpans.map((span) => span.toString(options)).join('');
18
+ return `${this.head}${spans}`;
19
+ }
20
+
21
+ toFullSignature(options?: { showDocs?: boolean }): string {
22
+ const spans = this.templateSpans.map((span) => span.toFullSignature(options)).join('');
23
+ return `\`${this.head}${spans}\``;
24
+ }
25
+
26
+ toObject() {
27
+ return {
28
+ ...super.toObject(),
29
+ head: this.head,
30
+ templateSpans: this.templateSpans.map((span) => span.toObject()),
31
+ };
32
+ }
33
+
34
+ static fromObject(obj: Record<string, any>): TemplateLiteralTypeSchema {
35
+ const location = obj.location;
36
+ const head = obj.head;
37
+ const templateSpans = obj.templateSpans.map((span: any) => TemplateLiteralTypeSpanSchema.fromObject(span));
38
+ return new TemplateLiteralTypeSchema(location, head, templateSpans);
39
+ }
40
+ }
@@ -0,0 +1,27 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+
3
+ /**
4
+ * e.g. `class A { createA(): this {} }`
5
+ */
6
+ export class ThisTypeSchema extends SchemaNode {
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly name: string
10
+ ) {
11
+ super();
12
+ }
13
+
14
+ toString() {
15
+ return this.name;
16
+ }
17
+
18
+ toFullSignature() {
19
+ return this.toString();
20
+ }
21
+
22
+ static fromObject(obj: Record<string, any>): ThisTypeSchema {
23
+ const location = obj.location;
24
+ const name = obj.name;
25
+ return new ThisTypeSchema(location, name);
26
+ }
27
+ }
@@ -0,0 +1,35 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ export class TupleTypeSchema extends SchemaNode {
5
+ readonly elements: SchemaNode[];
6
+
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ elements: SchemaNode[]
10
+ ) {
11
+ super();
12
+ this.elements = elements;
13
+ }
14
+
15
+ toString(options?: { color?: boolean }) {
16
+ return `[${this.elements.map((elem) => elem.toString(options)).join(', ')}]`;
17
+ }
18
+
19
+ toFullSignature(options?: { showDocs?: boolean }): string {
20
+ return `[${this.elements.map((elem) => elem.toFullSignature(options)).join(', ')}]`;
21
+ }
22
+
23
+ toObject() {
24
+ return {
25
+ ...super.toObject(),
26
+ elements: this.elements.map((elem) => elem.toObject()),
27
+ };
28
+ }
29
+
30
+ static fromObject(obj: Record<string, any>): TupleTypeSchema {
31
+ const location = obj.location;
32
+ const elements = obj.elements.map((elem: any) => SchemaRegistry.fromObject(elem));
33
+ return new TupleTypeSchema(location, elements);
34
+ }
35
+ }