@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,135 @@
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 ClassSchema extends SchemaNode {
8
+ readonly members: SchemaNode[];
9
+ readonly doc?: DocSchema;
10
+
11
+ constructor(
12
+ readonly name: string,
13
+ members: SchemaNode[],
14
+ readonly location: SchemaLocation,
15
+ readonly signature: string,
16
+ doc?: DocSchema,
17
+ readonly typeParams?: string[],
18
+ readonly extendsNodes?: ExpressionWithTypeArgumentsSchema[],
19
+ readonly implementNodes?: ExpressionWithTypeArgumentsSchema[],
20
+ readonly decorators?: SchemaNode[]
21
+ ) {
22
+ super();
23
+ this.members = members;
24
+ this.doc = doc;
25
+ }
26
+
27
+ getNodes() {
28
+ return this.members;
29
+ }
30
+
31
+ toString(options?: { color?: boolean }): string {
32
+ const boldUnderline = options?.color ? chalk.bold.underline : (str: string) => str;
33
+ const membersStr = this.members.map((m) => `* ${m.toString(options)}`).join('\n');
34
+ const decoratorsStr = this.decorators?.map((decorator) => decorator.toString(options)).join('\n');
35
+ return `${this.decorators ? `${decoratorsStr}\n` : ''}${boldUnderline(this.name)}\n${membersStr}`;
36
+ }
37
+
38
+ toFullSignature(options?: { showDocs?: boolean }): string {
39
+ let result = '';
40
+
41
+ if (options?.showDocs && this.doc) {
42
+ result += `${this.doc.toFullSignature()}\n`;
43
+ }
44
+
45
+ const decoratorsStr = this.decorators?.map((decorator) => decorator.toFullSignature(options)).join('\n');
46
+ if (decoratorsStr) {
47
+ result += `${decoratorsStr}\n`;
48
+ }
49
+
50
+ let classDeclaration = `class ${this.name}`;
51
+
52
+ if (this.typeParams && this.typeParams.length > 0) {
53
+ classDeclaration += `<${this.typeParams.join(', ')}>`;
54
+ }
55
+
56
+ if (this.extendsNodes && this.extendsNodes.length > 0) {
57
+ const extendsStr = this.extendsNodes.map((node) => node.toFullSignature(options)).join(', ');
58
+ classDeclaration += ` extends ${extendsStr}`;
59
+ }
60
+
61
+ if (this.implementNodes && this.implementNodes.length > 0) {
62
+ const implementsStr = this.implementNodes.map((node) => node.toFullSignature(options)).join(', ');
63
+ classDeclaration += ` implements ${implementsStr}`;
64
+ }
65
+
66
+ result += `${classDeclaration} {\n`;
67
+
68
+ const membersStr = this.members
69
+ .map((member) => {
70
+ const memberStr = member.toFullSignature(options);
71
+ return memberStr
72
+ .split('\n')
73
+ .map((line) => ` ${line}`)
74
+ .join('\n');
75
+ })
76
+ .join('\n');
77
+
78
+ result += `${membersStr}\n`;
79
+
80
+ result += `}`;
81
+
82
+ return result;
83
+ }
84
+
85
+ toObject() {
86
+ return {
87
+ ...super.toObject(),
88
+ name: this.name,
89
+ members: this.members.map((member) => member.toObject()),
90
+ doc: this.doc?.toObject(),
91
+ signature: this.signature,
92
+ typeParams: this.typeParams,
93
+ extendsNodes: this.extendsNodes?.map((node) => node.toObject()),
94
+ implementNodes: this.implementNodes?.map((node) => node.toObject()),
95
+ decorators: this.decorators?.map((decorator) => decorator.toObject()),
96
+ };
97
+ }
98
+
99
+ static fromObject(obj: Record<string, any>): ClassSchema {
100
+ const name = obj.name;
101
+ const members = obj.members.map((member: any) => SchemaRegistry.fromObject(member));
102
+ const location = obj.location;
103
+ const signature = obj.signature;
104
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
105
+ const typeParams = obj.typeParams;
106
+ const extendsNodes = obj.extendsNodes?.map((node: any) => ExpressionWithTypeArgumentsSchema.fromObject(node));
107
+ const implementNodes = obj.implementNodes?.map((node: any) => ExpressionWithTypeArgumentsSchema.fromObject(node));
108
+ const decorators = obj.decorators?.map((decorator: any) => SchemaRegistry.fromObject(decorator));
109
+ return new ClassSchema(
110
+ name,
111
+ members,
112
+ location,
113
+ signature,
114
+ doc,
115
+ typeParams,
116
+ extendsNodes,
117
+ implementNodes,
118
+ decorators
119
+ );
120
+ }
121
+
122
+ static fromSchema(node: ClassSchema, memberTransformer: (_node: SchemaNode) => SchemaNode = (_node) => _node) {
123
+ return new ClassSchema(
124
+ node.name,
125
+ node.members.map(memberTransformer),
126
+ node.location,
127
+ node.signature,
128
+ node.doc,
129
+ node.typeParams,
130
+ node.extendsNodes,
131
+ node.implementNodes,
132
+ node.decorators
133
+ );
134
+ }
135
+ }
@@ -0,0 +1,63 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+
4
+ /**
5
+ * e.g. `T extends U ? Y : N`
6
+ *
7
+ */
8
+ export class ConditionalTypeSchema extends SchemaNode {
9
+ readonly checkType: SchemaNode;
10
+ readonly extendsType: SchemaNode;
11
+ readonly trueType: SchemaNode;
12
+ readonly falseType: SchemaNode;
13
+
14
+ constructor(
15
+ readonly location: SchemaLocation,
16
+ checkType: SchemaNode,
17
+ extendsType: SchemaNode,
18
+ trueType: SchemaNode,
19
+ falseType: SchemaNode
20
+ ) {
21
+ super();
22
+ this.checkType = checkType;
23
+ this.extendsType = extendsType;
24
+ this.trueType = trueType;
25
+ this.falseType = falseType;
26
+ }
27
+
28
+ getNodes() {
29
+ return [this.checkType, this.extendsType, this.trueType, this.falseType];
30
+ }
31
+
32
+ toString() {
33
+ return `${this.checkType.toString()} extends ${this.extendsType.toString()} ? ${this.trueType.toString()} : ${this.falseType.toString()}`;
34
+ }
35
+
36
+ toFullSignature(options?: { showDocs?: boolean }): string {
37
+ const checkTypeStr = this.checkType.toFullSignature(options);
38
+ const extendsTypeStr = this.extendsType.toFullSignature(options);
39
+ const trueTypeStr = this.trueType.toFullSignature(options);
40
+ const falseTypeStr = this.falseType.toFullSignature(options);
41
+
42
+ return `${checkTypeStr} extends ${extendsTypeStr} ? ${trueTypeStr} : ${falseTypeStr}`;
43
+ }
44
+
45
+ toObject() {
46
+ return {
47
+ ...super.toObject(),
48
+ checkType: this.checkType.toObject(),
49
+ extendsType: this.extendsType.toObject(),
50
+ trueType: this.trueType.toObject(),
51
+ falseType: this.falseType.toObject(),
52
+ };
53
+ }
54
+
55
+ static fromObject(obj: Record<string, any>): ConditionalTypeSchema {
56
+ const location = obj.location;
57
+ const checkType = SchemaRegistry.fromObject(obj.checkType);
58
+ const extendsType = SchemaRegistry.fromObject(obj.extendsType);
59
+ const trueType = SchemaRegistry.fromObject(obj.trueType);
60
+ const falseType = SchemaRegistry.fromObject(obj.falseType);
61
+ return new ConditionalTypeSchema(location, checkType, extendsType, trueType, falseType);
62
+ }
63
+ }
@@ -0,0 +1,28 @@
1
+ import { SchemaLocation } from '../schema-node';
2
+ import { ParameterSchema } from './parameter';
3
+ import { FunctionLikeSchema, Modifier } from './function-like';
4
+ import { DocSchema } from './docs';
5
+ import { ThisTypeSchema } from './this-type';
6
+
7
+ export class ConstructorSchema extends FunctionLikeSchema {
8
+ constructor(
9
+ location: SchemaLocation,
10
+ params: ParameterSchema[],
11
+ returnType: ThisTypeSchema,
12
+ signature: string,
13
+ modifiers: Modifier[] = [],
14
+ doc?: DocSchema
15
+ ) {
16
+ super(location, 'constructor', params, returnType, signature, modifiers, doc, undefined);
17
+ }
18
+
19
+ static fromObject(obj: Record<string, any>): ConstructorSchema {
20
+ const location = obj.location;
21
+ const params = obj.params.map((param: any) => ParameterSchema.fromObject(param));
22
+ const returns = ThisTypeSchema.fromObject(obj.returnType);
23
+ const signature = obj.signature;
24
+ const modifiers = obj.modifiers;
25
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
26
+ return new ConstructorSchema(location, params, returns, signature, modifiers, doc);
27
+ }
28
+ }
@@ -0,0 +1,54 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { SchemaRegistry } from '../schema-registry';
3
+ import { DocSchema } from './docs';
4
+
5
+ export class DecoratorSchema extends SchemaNode {
6
+ constructor(
7
+ readonly location: SchemaLocation,
8
+ readonly name: string,
9
+ readonly doc?: DocSchema,
10
+ readonly args?: SchemaNode[]
11
+ ) {
12
+ super();
13
+ }
14
+
15
+ getNodes() {
16
+ return this.args || [];
17
+ }
18
+
19
+ toString() {
20
+ const argsStr = this.args?.map((arg) => arg.toString()).join(', ');
21
+ return `@${this.name}${argsStr ? `(${argsStr})` : ''}`;
22
+ }
23
+
24
+ toFullSignature(options?: { showDocs?: boolean }): string {
25
+ let result = '';
26
+
27
+ if (options?.showDocs && this.doc) {
28
+ result += `${this.doc.toFullSignature()}\n`;
29
+ }
30
+
31
+ const argsStr = this.args?.map((arg) => arg.toFullSignature(options)).join(', ');
32
+
33
+ result += `@${this.name}${argsStr ? `(${argsStr})` : ''}`;
34
+
35
+ return result;
36
+ }
37
+
38
+ toObject() {
39
+ return {
40
+ ...super.toObject(),
41
+ name: this.name,
42
+ doc: this.doc?.toObject(),
43
+ args: this.args?.map((arg) => arg.toObject()),
44
+ };
45
+ }
46
+
47
+ static fromObject(obj: Record<string, any>): DecoratorSchema {
48
+ const location = obj.location;
49
+ const name = obj.name;
50
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
51
+ const args = obj.args ? obj.args.map((arg) => SchemaRegistry.fromObject(arg)) : undefined;
52
+ return new DecoratorSchema(location, name, doc, args);
53
+ }
54
+ }
@@ -0,0 +1,69 @@
1
+ import { SchemaLocation, SchemaNode } from '../../schema-node';
2
+ import { SchemaRegistry } from '../../schema-registry';
3
+ import { TagName, TagSchema } from './tag';
4
+
5
+ export class DocSchema extends SchemaNode {
6
+ readonly tags?: TagSchema[];
7
+
8
+ constructor(
9
+ readonly location: SchemaLocation,
10
+ readonly raw: string,
11
+ readonly comment?: string,
12
+ tags?: TagSchema[]
13
+ ) {
14
+ super();
15
+ this.tags = tags;
16
+ }
17
+
18
+ toString() {
19
+ const comment = this.comment ? `${this.comment}\n` : '';
20
+ const tags = this.tags ? this.tags.map((tag) => tag.toString()).join('\n') : '';
21
+ return `${comment}${tags}`;
22
+ }
23
+
24
+ toFullSignature(): string {
25
+ const lines: string[] = [];
26
+
27
+ if (this.comment) {
28
+ lines.push(...this.comment.split('\n').map((line) => ` * ${line.trim()}`));
29
+ }
30
+
31
+ if (this.tags && this.tags.length > 0) {
32
+ for (const tag of this.tags) {
33
+ lines.push(` * ${tag.toString().trim()}`);
34
+ }
35
+ }
36
+
37
+ if (lines.length === 0) {
38
+ return '';
39
+ }
40
+
41
+ return `/**\n${lines.join('\n')}\n */`;
42
+ }
43
+
44
+ hasTag(tagName: TagName) {
45
+ return Boolean(this.findTag(tagName));
46
+ }
47
+
48
+ findTag(tagName: TagName) {
49
+ return this.tags?.find((tag) => tag.tagName === tagName);
50
+ }
51
+
52
+ toObject() {
53
+ return {
54
+ __schema: this.__schema,
55
+ name: this.name,
56
+ location: this.location,
57
+ signature: this.signature,
58
+ raw: this.raw,
59
+ comment: this.comment,
60
+ tags: this.tags ? this.tags.map((tag) => tag.toObject()) : undefined,
61
+ };
62
+ }
63
+
64
+ static fromObject(obj: Record<string, any>): DocSchema {
65
+ const location = obj.location;
66
+ const tags = obj.tags ? obj.tags.map((tag: any) => SchemaRegistry.fromObject(tag)) : undefined;
67
+ return new DocSchema(location, obj.raw, obj.comment, tags);
68
+ }
69
+ }
@@ -0,0 +1,4 @@
1
+ export { DocSchema } from './doc';
2
+ export { TagSchema } from './tag';
3
+ export { ReturnTagSchema } from './return-tag';
4
+ export { PropertyLikeTagSchema } from './property-like-tag';
@@ -0,0 +1,47 @@
1
+ import { SchemaLocation, SchemaNode } from '../../schema-node';
2
+ import { SchemaRegistry } from '../../schema-registry';
3
+ import { TagName, TagSchema } from './tag';
4
+
5
+ /**
6
+ * e.g. `@param myParam {string} some comment`
7
+ */
8
+ export class PropertyLikeTagSchema extends TagSchema {
9
+ readonly type?: SchemaNode;
10
+ constructor(
11
+ readonly location: SchemaLocation,
12
+ readonly name: string,
13
+ readonly comment?: string,
14
+ type?: SchemaNode
15
+ ) {
16
+ super(location, TagName.parameter, comment);
17
+ this.type = type;
18
+ }
19
+
20
+ toString() {
21
+ const comment = this.comment ? ` ${this.comment}` : '';
22
+ const type = this.type ? ` {${this.type.toString()}} ` : '';
23
+ return `@${this.tagName} ${this.name}${type} ${comment}`;
24
+ }
25
+
26
+ toFullSignature(options?: { showDocs?: boolean }): string {
27
+ const typeStr = this.type ? ` {${this.type.toFullSignature(options)}} ` : '';
28
+ const comment = this.comment ? ` ${this.comment}` : '';
29
+ return `@${this.tagName} ${this.name}${typeStr}${comment}`;
30
+ }
31
+
32
+ toObject() {
33
+ return {
34
+ ...super.toObject(),
35
+ name: this.name,
36
+ type: this.type?.toObject(),
37
+ };
38
+ }
39
+
40
+ static fromObject(obj: Record<string, any>): PropertyLikeTagSchema {
41
+ const location = obj.location;
42
+ const name = obj.name;
43
+ const comment = obj.comment;
44
+ const type = obj.type ? SchemaRegistry.fromObject(obj.type) : undefined;
45
+ return new PropertyLikeTagSchema(location, name, comment, type);
46
+ }
47
+ }
@@ -0,0 +1,44 @@
1
+ import { SchemaLocation, SchemaNode } from '../../schema-node';
2
+ import { SchemaRegistry } from '../../schema-registry';
3
+ import { TagName, TagSchema } from './tag';
4
+
5
+ /**
6
+ * e.g. `@return {string} some comment`
7
+ */
8
+ export class ReturnTagSchema extends TagSchema {
9
+ readonly type?: SchemaNode;
10
+
11
+ constructor(
12
+ readonly location: SchemaLocation,
13
+ readonly comment?: string,
14
+ type?: SchemaNode
15
+ ) {
16
+ super(location, TagName.return, comment);
17
+ this.type = type;
18
+ }
19
+
20
+ toString() {
21
+ const comment = this.comment ? ` ${this.comment}` : '';
22
+ return `@${this.tagName}${comment}`;
23
+ }
24
+
25
+ toFullSignature(options?: { showDocs?: boolean }): string {
26
+ const typeStr = this.type ? ` {${this.type.toFullSignature(options)}}` : '';
27
+ const comment = this.comment ? ` ${this.comment}` : '';
28
+ return `@${this.tagName}${typeStr}${comment}`;
29
+ }
30
+
31
+ toObject() {
32
+ return {
33
+ ...super.toObject(),
34
+ type: this.type?.toObject(),
35
+ };
36
+ }
37
+
38
+ static fromObject(obj: Record<string, any>): ReturnTagSchema {
39
+ const location = obj.location;
40
+ const comment = obj.comment;
41
+ const type = obj.type ? SchemaRegistry.fromObject(obj.type) : undefined;
42
+ return new ReturnTagSchema(location, comment, type);
43
+ }
44
+ }
@@ -0,0 +1,66 @@
1
+ import { SchemaLocation, SchemaNode } from '../../schema-node';
2
+
3
+ /**
4
+ * e.g. `@deprecated please use something else`
5
+ */
6
+ export class TagSchema extends SchemaNode {
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly tagName: TagName | string,
10
+ readonly comment?: string
11
+ ) {
12
+ super();
13
+ }
14
+
15
+ toString() {
16
+ const comment = this.comment ? ` ${this.comment}` : '';
17
+ return `@${this.tagName}${comment}`;
18
+ }
19
+
20
+ toFullSignature(): string {
21
+ return this.toString();
22
+ }
23
+
24
+ static fromObject(obj: Record<string, any>): TagSchema {
25
+ const location = obj.location;
26
+ const tagName = obj.tagName;
27
+ const comment = obj.comment;
28
+ return new TagSchema(location, tagName, comment);
29
+ }
30
+
31
+ toObject() {
32
+ return {
33
+ __schema: this.__schema,
34
+ location: this.location,
35
+ name: this.name,
36
+ signature: this.signature,
37
+ tagName: this.tagName,
38
+ comment: this.comment,
39
+ };
40
+ }
41
+ }
42
+
43
+ export enum TagName {
44
+ augments = 'augments',
45
+ author = 'author',
46
+ class = 'class',
47
+ callback = 'callback',
48
+ public = 'public',
49
+ private = 'private',
50
+ protected = 'protected',
51
+ readonly = 'readonly',
52
+ override = 'override',
53
+ see = 'see',
54
+ enum = 'enum',
55
+ parameter = 'parameter',
56
+ this = 'this',
57
+ type = 'type',
58
+ template = 'template',
59
+ typedef = 'typedef',
60
+ property = 'property',
61
+ implements = 'implements',
62
+ return = 'return',
63
+ deprecated = 'deprecated',
64
+ exports = 'exports',
65
+ link = 'link',
66
+ }
@@ -0,0 +1,57 @@
1
+ import { SchemaLocation, SchemaNode } from '../schema-node';
2
+ import { DocSchema } from './docs';
3
+
4
+ export class EnumMemberSchema extends SchemaNode {
5
+ readonly doc?: DocSchema;
6
+
7
+ constructor(
8
+ readonly location: SchemaLocation,
9
+ readonly name: string,
10
+ readonly signature: string,
11
+ readonly value?: string,
12
+ doc?: DocSchema
13
+ ) {
14
+ super();
15
+ this.doc = doc;
16
+ }
17
+
18
+ toString() {
19
+ if (!this.value) return this.name;
20
+ return `${this.name}=${this.value}`;
21
+ }
22
+
23
+ toFullSignature(options?: { showDocs?: boolean }): string {
24
+ let result = '';
25
+
26
+ if (options?.showDocs && this.doc) {
27
+ result += `${this.doc.toFullSignature()}\n`;
28
+ }
29
+
30
+ if (this.value !== undefined) {
31
+ result += `${this.name} = ${this.value}`;
32
+ } else {
33
+ result += `${this.name}`;
34
+ }
35
+
36
+ return result;
37
+ }
38
+
39
+ toObject() {
40
+ return {
41
+ ...super.toObject(),
42
+ name: this.name,
43
+ signature: this.signature,
44
+ value: this.value,
45
+ doc: this.doc?.toObject(),
46
+ };
47
+ }
48
+
49
+ static fromObject(obj: Record<string, any>): EnumMemberSchema {
50
+ const location = obj.location;
51
+ const name = obj.name;
52
+ const signature = obj.signature;
53
+ const value = obj.value;
54
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
55
+ return new EnumMemberSchema(location, name, signature, value, doc);
56
+ }
57
+ }
@@ -0,0 +1,73 @@
1
+ import chalk from 'chalk';
2
+ import { SchemaLocation, SchemaNode } from '../schema-node';
3
+ import { DocSchema } from './docs';
4
+ import { SchemaRegistry } from '..';
5
+
6
+ export class EnumSchema extends SchemaNode {
7
+ readonly doc?: DocSchema;
8
+ readonly members: SchemaNode[];
9
+
10
+ constructor(
11
+ readonly location: SchemaLocation,
12
+ readonly name: string,
13
+ members: SchemaNode[],
14
+ readonly signature: string,
15
+ doc?: DocSchema
16
+ ) {
17
+ super();
18
+ this.doc = doc;
19
+ this.members = members;
20
+ }
21
+
22
+ getNodes() {
23
+ return this.members;
24
+ }
25
+
26
+ toString(options) {
27
+ const boldUnderline = options?.color ? chalk.bold.underline : (str: string) => str;
28
+ const membersStr = this.members.map((m) => `* ${m.toString(options)}`).join('\n');
29
+ return `${boldUnderline(this.name)}\n${membersStr}`;
30
+ }
31
+
32
+ toFullSignature(options?: { showDocs?: boolean }): string {
33
+ let result = '';
34
+
35
+ if (options?.showDocs && this.doc) {
36
+ result += `${this.doc.toFullSignature()}\n`;
37
+ }
38
+
39
+ result += `enum ${this.name} {\n`;
40
+
41
+ const membersStr = this.members
42
+ .map((member) => {
43
+ const memberStr = member.toFullSignature(options);
44
+ return ` ${memberStr}`;
45
+ })
46
+ .join(',\n');
47
+
48
+ result += `${membersStr}\n`;
49
+
50
+ result += `}`;
51
+
52
+ return result;
53
+ }
54
+
55
+ toObject() {
56
+ return {
57
+ ...super.toObject(),
58
+ name: this.name,
59
+ members: this.members.map((member) => member.toObject()),
60
+ doc: this.doc?.toObject(),
61
+ signature: this.signature,
62
+ };
63
+ }
64
+
65
+ static fromObject(obj: Record<string, any>): EnumSchema {
66
+ const location = obj.location;
67
+ const name = obj.name;
68
+ const members = obj.members.map((member: any) => SchemaRegistry.fromObject(member));
69
+ const signature = obj.signature;
70
+ const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
71
+ return new EnumSchema(location, name, members, signature, doc);
72
+ }
73
+ }