@teambit/semantics.entities.semantic-schema 0.0.51 → 0.0.54
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.
- package/api-schema.ts +32 -9
- package/class-transformers/comp-id-transformer.ts +21 -21
- package/class-transformers/index.ts +2 -2
- package/class-transformers/schema-obj-to-class.ts +51 -45
- package/dist/api-schema.d.ts +19 -3
- package/dist/api-schema.js +16 -19
- package/dist/api-schema.js.map +1 -1
- package/dist/class-transformers/comp-id-transformer.d.ts +0 -6
- package/dist/class-transformers/comp-id-transformer.js +21 -19
- package/dist/class-transformers/comp-id-transformer.js.map +1 -1
- package/dist/class-transformers/index.d.ts +0 -2
- package/dist/class-transformers/index.js +2 -8
- package/dist/class-transformers/index.js.map +1 -1
- package/dist/class-transformers/schema-obj-to-class.d.ts +0 -10
- package/dist/class-transformers/schema-obj-to-class.js +49 -66
- package/dist/class-transformers/schema-obj-to-class.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +20 -2
- package/dist/index.js.map +1 -1
- package/dist/{preview-1676777489824.js → preview-1694692074267.js} +1 -1
- package/dist/schema-node-constructor.d.ts +7 -0
- package/dist/schema-node-constructor.js +3 -0
- package/dist/schema-node-constructor.js.map +1 -0
- package/dist/schema-node.d.ts +20 -4
- package/dist/schema-node.js +36 -2
- package/dist/schema-node.js.map +1 -1
- package/dist/schema-registry.d.ts +9 -0
- package/dist/schema-registry.js +31 -0
- package/dist/schema-registry.js.map +1 -0
- package/dist/schemas/class.d.ts +39 -3
- package/dist/schemas/class.js +22 -14
- package/dist/schemas/class.js.map +1 -1
- package/dist/schemas/conditional-type.d.ts +11 -3
- package/dist/schemas/conditional-type.js +15 -20
- package/dist/schemas/conditional-type.js.map +1 -1
- package/dist/schemas/constructor.d.ts +3 -2
- package/dist/schemas/constructor.js +14 -2
- package/dist/schemas/constructor.js.map +1 -1
- package/dist/schemas/docs/doc.d.ts +20 -3
- package/dist/schemas/docs/doc.js +17 -11
- package/dist/schemas/docs/doc.js.map +1 -1
- package/dist/schemas/docs/property-like-tag.d.ts +13 -3
- package/dist/schemas/docs/property-like-tag.js +12 -11
- package/dist/schemas/docs/property-like-tag.js.map +1 -1
- package/dist/schemas/docs/return-tag.d.ts +13 -3
- package/dist/schemas/docs/return-tag.js +11 -11
- package/dist/schemas/docs/return-tag.js.map +1 -1
- package/dist/schemas/docs/tag.d.ts +14 -4
- package/dist/schemas/docs/tag.js +17 -0
- package/dist/schemas/docs/tag.js.map +1 -1
- package/dist/schemas/enum-member.d.ts +25 -3
- package/dist/schemas/enum-member.js +13 -11
- package/dist/schemas/enum-member.js.map +1 -1
- package/dist/schemas/enum.d.ts +26 -3
- package/dist/schemas/enum.js +17 -14
- package/dist/schemas/enum.js.map +1 -1
- package/dist/schemas/expression-with-arguments.d.ts +10 -3
- package/dist/schemas/expression-with-arguments.js +11 -14
- package/dist/schemas/expression-with-arguments.js.map +1 -1
- package/dist/schemas/function-like.d.ts +40 -4
- package/dist/schemas/function-like.js +28 -18
- package/dist/schemas/function-like.js.map +1 -1
- package/dist/schemas/get-accessor.d.ts +10 -3
- package/dist/schemas/get-accessor.js +14 -11
- package/dist/schemas/get-accessor.js.map +1 -1
- package/dist/schemas/index-signature.d.ts +17 -3
- package/dist/schemas/index-signature.js +11 -14
- package/dist/schemas/index-signature.js.map +1 -1
- package/dist/schemas/index.d.ts +1 -1
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/indexed-access-type.d.ts +9 -3
- package/dist/schemas/indexed-access-type.js +13 -14
- package/dist/schemas/indexed-access-type.js.map +1 -1
- package/dist/schemas/inference-type.d.ts +9 -3
- package/dist/schemas/inference-type.js +12 -1
- package/dist/schemas/inference-type.js.map +1 -1
- package/dist/schemas/interface.d.ts +33 -3
- package/dist/schemas/interface.js +21 -14
- package/dist/schemas/interface.js.map +1 -1
- package/dist/schemas/keyword-type.d.ts +7 -3
- package/dist/schemas/keyword-type.js +8 -0
- package/dist/schemas/keyword-type.js.map +1 -1
- package/dist/schemas/literal-type.d.ts +4 -4
- package/dist/schemas/literal-type.js +6 -4
- package/dist/schemas/literal-type.js.map +1 -1
- package/dist/schemas/module.d.ts +9 -7
- package/dist/schemas/module.js +15 -20
- package/dist/schemas/module.js.map +1 -1
- package/dist/schemas/named-tuple.d.ts +9 -3
- package/dist/schemas/named-tuple.js +13 -0
- package/dist/schemas/named-tuple.js.map +1 -1
- package/dist/schemas/parameter.d.ts +16 -5
- package/dist/schemas/parameter.js +20 -16
- package/dist/schemas/parameter.js.map +1 -1
- package/dist/schemas/parenthesized-type.d.ts +8 -3
- package/dist/schemas/parenthesized-type.js +12 -11
- package/dist/schemas/parenthesized-type.js.map +1 -1
- package/dist/schemas/set-accessor.d.ts +17 -3
- package/dist/schemas/set-accessor.js +11 -11
- package/dist/schemas/set-accessor.js.map +1 -1
- package/dist/schemas/template-literal-type-span.d.ts +9 -3
- package/dist/schemas/template-literal-type-span.js +13 -11
- package/dist/schemas/template-literal-type-span.js.map +1 -1
- package/dist/schemas/template-literal-type.d.ts +11 -3
- package/dist/schemas/template-literal-type.js +10 -11
- package/dist/schemas/template-literal-type.js.map +1 -1
- package/dist/schemas/this-type.d.ts +4 -3
- package/dist/schemas/this-type.js +4 -0
- package/dist/schemas/this-type.js.map +1 -1
- package/dist/schemas/tuple-type.d.ts +7 -3
- package/dist/schemas/tuple-type.js +9 -11
- package/dist/schemas/tuple-type.js.map +1 -1
- package/dist/schemas/type-array.d.ts +8 -3
- package/dist/schemas/type-array.js +12 -11
- package/dist/schemas/type-array.js.map +1 -1
- package/dist/schemas/type-intersection.d.ts +8 -3
- package/dist/schemas/type-intersection.js +12 -11
- package/dist/schemas/type-intersection.js.map +1 -1
- package/dist/schemas/type-literal.d.ts +8 -3
- package/dist/schemas/type-literal.js +12 -11
- package/dist/schemas/type-literal.js.map +1 -1
- package/dist/schemas/type-operator.d.ts +9 -3
- package/dist/schemas/type-operator.js +13 -11
- package/dist/schemas/type-operator.js.map +1 -1
- package/dist/schemas/type-predicate.d.ts +9 -3
- package/dist/schemas/type-predicate.js +12 -11
- package/dist/schemas/type-predicate.js.map +1 -1
- package/dist/schemas/type-query.d.ts +9 -3
- package/dist/schemas/type-query.js +13 -11
- package/dist/schemas/type-query.js.map +1 -1
- package/dist/schemas/type-ref.d.ts +28 -4
- package/dist/schemas/type-ref.js +43 -16
- package/dist/schemas/type-ref.js.map +1 -1
- package/dist/schemas/type-union.d.ts +8 -3
- package/dist/schemas/type-union.js +12 -11
- package/dist/schemas/type-union.js.map +1 -1
- package/dist/schemas/type.d.ts +10 -3
- package/dist/schemas/type.js +16 -14
- package/dist/schemas/type.js.map +1 -1
- package/dist/schemas/unimplemented-schema.d.ts +7 -3
- package/dist/schemas/unimplemented-schema.js +9 -0
- package/dist/schemas/unimplemented-schema.js.map +1 -1
- package/dist/schemas/unknown-schema.d.ts +7 -3
- package/dist/schemas/unknown-schema.js +9 -0
- package/dist/schemas/unknown-schema.js.map +1 -1
- package/dist/schemas/unresolved-schema.d.ts +5 -3
- package/dist/schemas/unresolved-schema.js +8 -0
- package/dist/schemas/unresolved-schema.js.map +1 -1
- package/dist/schemas/variable-like.d.ts +29 -3
- package/dist/schemas/variable-like.js +21 -15
- package/dist/schemas/variable-like.js.map +1 -1
- package/dist/unknown-schema-factory.d.ts +4 -0
- package/dist/unknown-schema-factory.js +13 -0
- package/dist/unknown-schema-factory.js.map +1 -0
- package/index.ts +10 -2
- package/package.json +3 -4
- package/schema-node-constructor.ts +8 -0
- package/schema-node.ts +62 -6
- package/schema-registry.ts +33 -0
- package/schemas/class.ts +32 -7
- package/schemas/conditional-type.ts +27 -11
- package/schemas/constructor.ts +14 -4
- package/schemas/docs/doc.ts +22 -5
- package/schemas/docs/property-like-tag.ts +19 -5
- package/schemas/docs/return-tag.ts +18 -5
- package/schemas/docs/tag.ts +21 -2
- package/schemas/enum-member.ts +21 -5
- package/schemas/enum.ts +26 -6
- package/schemas/expression-with-arguments.ts +26 -7
- package/schemas/function-like.ts +51 -10
- package/schemas/get-accessor.ts +24 -5
- package/schemas/index-signature.ts +19 -6
- package/schemas/index.ts +1 -1
- package/schemas/indexed-access-type.ts +24 -6
- package/schemas/inference-type.ts +23 -2
- package/schemas/interface.ts +30 -7
- package/schemas/keyword-type.ts +15 -2
- package/schemas/literal-type.ts +9 -3
- package/schemas/module.ts +24 -14
- package/schemas/named-tuple.ts +22 -2
- package/schemas/parameter.ts +43 -11
- package/schemas/parenthesized-type.ts +20 -5
- package/schemas/set-accessor.ts +26 -5
- package/schemas/template-literal-type-span.ts +23 -5
- package/schemas/template-literal-type.ts +22 -5
- package/schemas/this-type.ts +7 -2
- package/schemas/tuple-type.ts +17 -5
- package/schemas/type-array.ts +21 -5
- package/schemas/type-intersection.ts +21 -5
- package/schemas/type-literal.ts +21 -5
- package/schemas/type-operator.ts +22 -5
- package/schemas/type-predicate.ts +20 -5
- package/schemas/type-query.ts +24 -5
- package/schemas/type-ref.ts +51 -10
- package/schemas/type-union.ts +17 -5
- package/schemas/type.ts +25 -7
- package/schemas/unimplemented-schema.ts +16 -2
- package/schemas/unknown-schema.ts +16 -2
- package/schemas/unresolved-schema.ts +12 -2
- package/schemas/variable-like.ts +33 -8
- package/unknown-schema-factory.ts +10 -0
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.51.tgz +0 -0
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../../schema-node';
|
|
2
|
+
import { SchemaRegistry } from '../../schema-registry';
|
|
3
3
|
import { TagName, TagSchema } from './tag';
|
|
4
|
-
import { schemaObjToInstance } from '../../class-transformers';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* e.g. `@return {string} some comment`
|
|
8
7
|
*/
|
|
9
8
|
export class ReturnTagSchema extends TagSchema {
|
|
10
|
-
@Transform(schemaObjToInstance)
|
|
11
9
|
readonly type?: SchemaNode;
|
|
12
|
-
|
|
10
|
+
|
|
11
|
+
constructor(readonly location: SchemaLocation, readonly comment?: string, type?: SchemaNode) {
|
|
13
12
|
super(location, TagName.return, comment);
|
|
14
13
|
this.type = type;
|
|
15
14
|
}
|
|
@@ -18,4 +17,18 @@ export class ReturnTagSchema extends TagSchema {
|
|
|
18
17
|
const comment = this.comment ? ` ${this.comment}` : '';
|
|
19
18
|
return `@${this.tagName}${comment}`;
|
|
20
19
|
}
|
|
20
|
+
|
|
21
|
+
toObject() {
|
|
22
|
+
return {
|
|
23
|
+
...super.toObject(),
|
|
24
|
+
type: this.type?.toObject(),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static fromObject(obj: Record<string, any>): ReturnTagSchema {
|
|
29
|
+
const location = obj.location;
|
|
30
|
+
const comment = obj.comment;
|
|
31
|
+
const type = obj.type ? SchemaRegistry.fromObject(obj.type) : undefined;
|
|
32
|
+
return new ReturnTagSchema(location, comment, type);
|
|
33
|
+
}
|
|
21
34
|
}
|
package/schemas/docs/tag.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* e.g. `@deprecated please use something else`
|
|
5
5
|
*/
|
|
6
6
|
export class TagSchema extends SchemaNode {
|
|
7
|
-
constructor(readonly location:
|
|
7
|
+
constructor(readonly location: SchemaLocation, readonly tagName: TagName | string, readonly comment?: string) {
|
|
8
8
|
super();
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -12,6 +12,24 @@ export class TagSchema extends SchemaNode {
|
|
|
12
12
|
const comment = this.comment ? ` ${this.comment}` : '';
|
|
13
13
|
return `@${this.tagName}${comment}`;
|
|
14
14
|
}
|
|
15
|
+
|
|
16
|
+
static fromObject(obj: Record<string, any>): TagSchema {
|
|
17
|
+
const location = obj.location;
|
|
18
|
+
const tagName = obj.tagName;
|
|
19
|
+
const comment = obj.comment;
|
|
20
|
+
return new TagSchema(location, tagName, comment);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
__schema: this.__schema,
|
|
26
|
+
location: this.location,
|
|
27
|
+
name: this.name,
|
|
28
|
+
signature: this.signature,
|
|
29
|
+
tagName: this.tagName,
|
|
30
|
+
comment: this.comment,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
15
33
|
}
|
|
16
34
|
|
|
17
35
|
export enum TagName {
|
|
@@ -35,4 +53,5 @@ export enum TagName {
|
|
|
35
53
|
implements = 'implements',
|
|
36
54
|
return = 'return',
|
|
37
55
|
deprecated = 'deprecated',
|
|
56
|
+
exports = 'exports',
|
|
38
57
|
}
|
package/schemas/enum-member.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { schemaObjToInstance } from '../class-transformers';
|
|
3
|
-
import { Location, SchemaNode } from '../schema-node';
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
4
2
|
import { DocSchema } from './docs';
|
|
5
3
|
|
|
6
4
|
export class EnumMemberSchema extends SchemaNode {
|
|
7
|
-
@Transform(schemaObjToInstance)
|
|
8
5
|
readonly doc?: DocSchema;
|
|
9
6
|
|
|
10
7
|
constructor(
|
|
11
|
-
readonly location:
|
|
8
|
+
readonly location: SchemaLocation,
|
|
12
9
|
readonly name: string,
|
|
13
10
|
readonly signature: string,
|
|
14
11
|
readonly value?: string,
|
|
@@ -22,4 +19,23 @@ export class EnumMemberSchema extends SchemaNode {
|
|
|
22
19
|
if (!this.value) return this.name;
|
|
23
20
|
return `${this.name}=${this.value}`;
|
|
24
21
|
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
...super.toObject(),
|
|
26
|
+
name: this.name,
|
|
27
|
+
signature: this.signature,
|
|
28
|
+
value: this.value,
|
|
29
|
+
doc: this.doc?.toObject(),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static fromObject(obj: Record<string, any>): EnumMemberSchema {
|
|
34
|
+
const location = obj.location;
|
|
35
|
+
const name = obj.name;
|
|
36
|
+
const signature = obj.signature;
|
|
37
|
+
const value = obj.value;
|
|
38
|
+
const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
|
|
39
|
+
return new EnumMemberSchema(location, name, signature, value, doc);
|
|
40
|
+
}
|
|
25
41
|
}
|
package/schemas/enum.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
import { Transform } from 'class-transformer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
import { Location, SchemaNode } from '../schema-node';
|
|
2
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
5
3
|
import { DocSchema } from './docs';
|
|
4
|
+
import { SchemaRegistry } from '..';
|
|
6
5
|
|
|
7
6
|
export class EnumSchema extends SchemaNode {
|
|
8
|
-
@Transform(schemaObjToInstance)
|
|
9
7
|
readonly doc?: DocSchema;
|
|
10
|
-
@Transform(schemaObjArrayToInstances)
|
|
11
8
|
readonly members: SchemaNode[];
|
|
12
9
|
|
|
13
10
|
constructor(
|
|
14
|
-
readonly location:
|
|
11
|
+
readonly location: SchemaLocation,
|
|
15
12
|
readonly name: string,
|
|
16
13
|
members: SchemaNode[],
|
|
17
14
|
readonly signature: string,
|
|
@@ -22,8 +19,31 @@ export class EnumSchema extends SchemaNode {
|
|
|
22
19
|
this.members = members;
|
|
23
20
|
}
|
|
24
21
|
|
|
22
|
+
getNodes() {
|
|
23
|
+
return this.members;
|
|
24
|
+
}
|
|
25
|
+
|
|
25
26
|
toString() {
|
|
26
27
|
const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
|
|
27
28
|
return `${chalk.bold.underline(this.name)}\n${membersStr}`;
|
|
28
29
|
}
|
|
30
|
+
|
|
31
|
+
toObject() {
|
|
32
|
+
return {
|
|
33
|
+
...super.toObject(),
|
|
34
|
+
name: this.name,
|
|
35
|
+
members: this.members.map((member) => member.toObject()),
|
|
36
|
+
doc: this.doc?.toObject(),
|
|
37
|
+
signature: this.signature,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static fromObject(obj: Record<string, any>): EnumSchema {
|
|
42
|
+
const location = obj.location;
|
|
43
|
+
const name = obj.name;
|
|
44
|
+
const members = obj.members.map((member: any) => SchemaRegistry.fromObject(member));
|
|
45
|
+
const signature = obj.signature;
|
|
46
|
+
const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
|
|
47
|
+
return new EnumSchema(location, name, members, signature, doc);
|
|
48
|
+
}
|
|
29
49
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { schemaObjArrayToInstances, schemaObjToInstance } from '../class-transformers';
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
4
3
|
|
|
5
4
|
export class ExpressionWithTypeArgumentsSchema extends SchemaNode {
|
|
6
|
-
@Transform(schemaObjArrayToInstances)
|
|
7
5
|
readonly typeArgs: SchemaNode[];
|
|
8
|
-
|
|
9
|
-
@Transform(schemaObjToInstance)
|
|
10
6
|
readonly expression: SchemaNode;
|
|
11
7
|
|
|
12
|
-
constructor(
|
|
8
|
+
constructor(
|
|
9
|
+
typeArgs: SchemaNode[],
|
|
10
|
+
expression: SchemaNode,
|
|
11
|
+
readonly name: string,
|
|
12
|
+
readonly location: SchemaLocation
|
|
13
|
+
) {
|
|
13
14
|
super();
|
|
14
15
|
this.typeArgs = typeArgs;
|
|
15
16
|
this.expression = expression;
|
|
@@ -18,4 +19,22 @@ export class ExpressionWithTypeArgumentsSchema extends SchemaNode {
|
|
|
18
19
|
toString() {
|
|
19
20
|
return this.name;
|
|
20
21
|
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
...super.toObject(),
|
|
26
|
+
name: this.name,
|
|
27
|
+
location: this.location,
|
|
28
|
+
typeArgs: this.typeArgs.map((typeArg) => typeArg.toObject()),
|
|
29
|
+
expression: this.expression,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static fromObject(obj: Record<string, any>): ExpressionWithTypeArgumentsSchema {
|
|
34
|
+
const name = obj.name;
|
|
35
|
+
const location = obj.location;
|
|
36
|
+
const typeArgs = obj.typeArgs.map((typeArg: any) => SchemaRegistry.fromObject(typeArg));
|
|
37
|
+
const expression = SchemaRegistry.fromObject(obj.expression);
|
|
38
|
+
return new ExpressionWithTypeArgumentsSchema(typeArgs, expression, name, location);
|
|
39
|
+
}
|
|
21
40
|
}
|
package/schemas/function-like.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { Transform } from 'class-transformer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
import { schemaObjArrayToInstances, schemaObjToInstance } from '../class-transformers';
|
|
2
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
5
3
|
import { ParameterSchema } from './parameter';
|
|
6
4
|
import { DocSchema } from './docs';
|
|
7
5
|
import { TagName } from './docs/tag';
|
|
6
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
8
7
|
|
|
9
8
|
export type Modifier =
|
|
10
9
|
| 'static'
|
|
@@ -21,21 +20,17 @@ export type Modifier =
|
|
|
21
20
|
* function-like can be a function, method, arrow-function, variable-function, etc.
|
|
22
21
|
*/
|
|
23
22
|
export class FunctionLikeSchema extends SchemaNode {
|
|
24
|
-
@Transform(schemaObjToInstance)
|
|
25
23
|
readonly returnType: SchemaNode;
|
|
26
|
-
|
|
27
|
-
@Transform(schemaObjArrayToInstances)
|
|
28
24
|
readonly params: ParameterSchema[];
|
|
29
|
-
|
|
30
|
-
@Transform(schemaObjToInstance)
|
|
31
25
|
readonly doc?: DocSchema;
|
|
26
|
+
readonly signature?: string | undefined;
|
|
32
27
|
|
|
33
28
|
constructor(
|
|
34
|
-
readonly location:
|
|
29
|
+
readonly location: SchemaLocation,
|
|
35
30
|
readonly name: string,
|
|
36
31
|
params: ParameterSchema[],
|
|
37
32
|
returnType: SchemaNode,
|
|
38
|
-
|
|
33
|
+
signature: string,
|
|
39
34
|
readonly modifiers: Modifier[] = [],
|
|
40
35
|
doc?: DocSchema,
|
|
41
36
|
readonly typeParams?: string[] // generics e.g. <T>myFunction
|
|
@@ -44,6 +39,11 @@ export class FunctionLikeSchema extends SchemaNode {
|
|
|
44
39
|
this.params = params;
|
|
45
40
|
this.returnType = returnType;
|
|
46
41
|
this.doc = doc;
|
|
42
|
+
this.signature = signature || FunctionLikeSchema.createSignature(this.name, this.params, this.returnType);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
getNodes() {
|
|
46
|
+
return [...this.params, this.returnType];
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
toString() {
|
|
@@ -62,6 +62,47 @@ export class FunctionLikeSchema extends SchemaNode {
|
|
|
62
62
|
return Boolean(this.modifiers.find((m) => m === 'private') || this.doc?.hasTag(TagName.private));
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
generateSignature(): string {
|
|
66
|
+
return FunctionLikeSchema.createSignature(this.name, this.params, this.returnType);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
static createSignature(name: string, params: ParameterSchema[], returnType: SchemaNode): string {
|
|
70
|
+
const paramsStr = params
|
|
71
|
+
.map((param) => {
|
|
72
|
+
let type = param.type.toString();
|
|
73
|
+
if (param.isSpread) type = `...${type}`;
|
|
74
|
+
return `${param.name}${param.isOptional ? '?' : ''}: ${type}`;
|
|
75
|
+
})
|
|
76
|
+
.join(', ');
|
|
77
|
+
return `${name}(${paramsStr}): ${returnType.toString()}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
toObject() {
|
|
81
|
+
return {
|
|
82
|
+
...super.toObject(),
|
|
83
|
+
name: this.name,
|
|
84
|
+
params: this.params.map((param) => param.toObject()),
|
|
85
|
+
returnType: this.returnType.toObject(),
|
|
86
|
+
signature: this.signature,
|
|
87
|
+
modifiers: this.modifiers,
|
|
88
|
+
doc: this.doc?.toObject(),
|
|
89
|
+
typeParams: this.typeParams,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static fromObject(obj: Record<string, any>) {
|
|
94
|
+
return new FunctionLikeSchema(
|
|
95
|
+
obj.location,
|
|
96
|
+
obj.name,
|
|
97
|
+
obj.params.map((param: Record<string, any>) => ParameterSchema.fromObject(param)),
|
|
98
|
+
SchemaRegistry.fromObject(obj.returnType),
|
|
99
|
+
obj.signature,
|
|
100
|
+
obj.modifiers,
|
|
101
|
+
obj.doc ? DocSchema.fromObject(obj.doc) : undefined,
|
|
102
|
+
obj.typeParams
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
65
106
|
private modifiersToString() {
|
|
66
107
|
const modifiersToPrint = this.modifiers.filter((modifier) => modifier !== 'export');
|
|
67
108
|
return modifiersToPrint.length ? `${modifiersToPrint.join(' ')} ` : '';
|
package/schemas/get-accessor.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import { Transform } from 'class-transformer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
3
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
5
4
|
|
|
6
5
|
export class GetAccessorSchema extends SchemaNode {
|
|
7
|
-
@Transform(schemaObjToInstance)
|
|
8
6
|
readonly type: SchemaNode;
|
|
9
|
-
constructor(readonly location:
|
|
7
|
+
constructor(readonly location: SchemaLocation, readonly name: string, type: SchemaNode, readonly signature: string) {
|
|
10
8
|
super();
|
|
11
9
|
this.type = type;
|
|
12
10
|
}
|
|
@@ -14,7 +12,28 @@ export class GetAccessorSchema extends SchemaNode {
|
|
|
14
12
|
return this.signature;
|
|
15
13
|
}
|
|
16
14
|
|
|
15
|
+
getNodes() {
|
|
16
|
+
return [this.type];
|
|
17
|
+
}
|
|
18
|
+
|
|
17
19
|
toString() {
|
|
18
20
|
return `get ${chalk.bold(this.name)}(): ${this.type.toString()}`;
|
|
19
21
|
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
...super.toObject(),
|
|
26
|
+
name: this.name,
|
|
27
|
+
type: this.type.toObject(),
|
|
28
|
+
signature: this.signature,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromObject(obj: Record<string, any>): GetAccessorSchema {
|
|
33
|
+
const location = obj.location;
|
|
34
|
+
const name = obj.name;
|
|
35
|
+
const type = SchemaRegistry.fromObject(obj.type);
|
|
36
|
+
const signature = obj.signature;
|
|
37
|
+
return new GetAccessorSchema(location, name, type, signature);
|
|
38
|
+
}
|
|
20
39
|
}
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
3
3
|
import { ParameterSchema } from './parameter';
|
|
4
|
-
import { schemaObjArrayToInstances, schemaObjToInstance } from '../class-transformers';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* e.g. `{ [key: string]: boolean };`
|
|
8
7
|
* the "[key: string]" is the "parameter", and the "boolean" is the "type".
|
|
9
8
|
*/
|
|
10
9
|
export class IndexSignatureSchema extends SchemaNode {
|
|
11
|
-
@Transform(schemaObjArrayToInstances)
|
|
12
10
|
readonly params: ParameterSchema[];
|
|
13
|
-
@Transform(schemaObjToInstance)
|
|
14
11
|
readonly type: SchemaNode;
|
|
15
|
-
constructor(readonly location:
|
|
12
|
+
constructor(readonly location: SchemaLocation, params: ParameterSchema[], type: SchemaNode) {
|
|
16
13
|
super();
|
|
17
14
|
this.params = params;
|
|
18
15
|
this.type = type;
|
|
@@ -22,4 +19,20 @@ export class IndexSignatureSchema extends SchemaNode {
|
|
|
22
19
|
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
23
20
|
return `[${paramsStr}]: ${this.type.toString()}`;
|
|
24
21
|
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
...super.toObject(),
|
|
26
|
+
location: this.location,
|
|
27
|
+
params: this.params.map((param) => param.toObject()),
|
|
28
|
+
type: this.type.toObject(),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static fromObject(obj: Record<string, any>): IndexSignatureSchema {
|
|
33
|
+
const location = obj.location;
|
|
34
|
+
const params = obj.params.map((param: any) => ParameterSchema.fromObject(param));
|
|
35
|
+
const type = SchemaRegistry.fromObject(obj.type);
|
|
36
|
+
return new IndexSignatureSchema(location, params, type);
|
|
37
|
+
}
|
|
25
38
|
}
|
package/schemas/index.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* and the schemaObjToClass can match and instantiate the Schema Class correctly
|
|
5
5
|
*/
|
|
6
6
|
export { ModuleSchema } from './module';
|
|
7
|
-
export { FunctionLikeSchema
|
|
7
|
+
export { FunctionLikeSchema } from './function-like';
|
|
8
8
|
export { TypeRefSchema } from './type-ref';
|
|
9
9
|
export { VariableLikeSchema } from './variable-like';
|
|
10
10
|
export { ClassSchema } from './class';
|
|
@@ -1,18 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { schemaObjToInstance } from '../class-transformers';
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
4
3
|
|
|
5
4
|
export class IndexedAccessSchema extends SchemaNode {
|
|
6
|
-
@Transform(schemaObjToInstance)
|
|
7
5
|
readonly objectType: SchemaNode;
|
|
8
|
-
@Transform(schemaObjToInstance)
|
|
9
6
|
readonly indexType: SchemaNode;
|
|
10
|
-
|
|
7
|
+
|
|
8
|
+
constructor(readonly location: SchemaLocation, objectType: SchemaNode, indexType: SchemaNode) {
|
|
11
9
|
super();
|
|
12
10
|
this.objectType = objectType;
|
|
13
11
|
this.indexType = indexType;
|
|
14
12
|
}
|
|
13
|
+
|
|
14
|
+
getNodes() {
|
|
15
|
+
return [this.objectType, this.indexType];
|
|
16
|
+
}
|
|
17
|
+
|
|
15
18
|
toString() {
|
|
16
19
|
return `${this.objectType.toString()}[${this.indexType.toString()}]`;
|
|
17
20
|
}
|
|
21
|
+
|
|
22
|
+
toObject() {
|
|
23
|
+
return {
|
|
24
|
+
...super.toObject(),
|
|
25
|
+
objectType: this.objectType.toObject(),
|
|
26
|
+
indexType: this.indexType.toObject(),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static fromObject(obj: Record<string, any>): IndexedAccessSchema {
|
|
31
|
+
const location = obj.location;
|
|
32
|
+
const objectType = SchemaRegistry.fromObject(obj.objectType);
|
|
33
|
+
const indexType = SchemaRegistry.fromObject(obj.indexType);
|
|
34
|
+
return new IndexedAccessSchema(location, objectType, indexType);
|
|
35
|
+
}
|
|
18
36
|
}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* where there is no explicit type, the type is taken from the "quickinfo" of tsserver
|
|
5
5
|
*/
|
|
6
6
|
export class InferenceTypeSchema extends SchemaNode {
|
|
7
|
-
constructor(
|
|
7
|
+
constructor(
|
|
8
|
+
readonly location: SchemaLocation,
|
|
9
|
+
readonly type: string,
|
|
10
|
+
readonly name?: string,
|
|
11
|
+
readonly defaultValue?: string
|
|
12
|
+
) {
|
|
8
13
|
super();
|
|
9
14
|
}
|
|
10
15
|
|
|
@@ -14,4 +19,20 @@ export class InferenceTypeSchema extends SchemaNode {
|
|
|
14
19
|
}
|
|
15
20
|
return this.type;
|
|
16
21
|
}
|
|
22
|
+
|
|
23
|
+
toObject() {
|
|
24
|
+
return {
|
|
25
|
+
...super.toObject(),
|
|
26
|
+
type: this.type,
|
|
27
|
+
defaultValue: this.defaultValue,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static fromObject(obj: Record<string, any>): InferenceTypeSchema {
|
|
32
|
+
const location = obj.location;
|
|
33
|
+
const type = obj.type;
|
|
34
|
+
const name = obj.name;
|
|
35
|
+
const defaultValue = obj.defaultValue;
|
|
36
|
+
return new InferenceTypeSchema(location, type, name, defaultValue);
|
|
37
|
+
}
|
|
17
38
|
}
|
package/schemas/interface.ts
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import { Transform } from 'class-transformer';
|
|
2
1
|
import chalk from 'chalk';
|
|
3
|
-
import {
|
|
4
|
-
import { schemaObjArrayToInstances, schemaObjToInstance } from '../class-transformers';
|
|
2
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
5
3
|
import { DocSchema } from './docs';
|
|
6
4
|
import { ExpressionWithTypeArgumentsSchema } from './expression-with-arguments';
|
|
5
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
7
6
|
|
|
8
7
|
export class InterfaceSchema extends SchemaNode {
|
|
9
|
-
@Transform(schemaObjArrayToInstances)
|
|
10
8
|
readonly members: SchemaNode[];
|
|
11
|
-
|
|
12
|
-
@Transform(schemaObjToInstance)
|
|
13
9
|
readonly doc?: DocSchema;
|
|
14
10
|
|
|
15
11
|
constructor(
|
|
16
|
-
readonly location:
|
|
12
|
+
readonly location: SchemaLocation,
|
|
17
13
|
readonly name: string,
|
|
18
14
|
readonly signature: string,
|
|
19
15
|
readonly extendsNodes: ExpressionWithTypeArgumentsSchema[],
|
|
@@ -26,8 +22,35 @@ export class InterfaceSchema extends SchemaNode {
|
|
|
26
22
|
this.doc = doc;
|
|
27
23
|
}
|
|
28
24
|
|
|
25
|
+
getNodes() {
|
|
26
|
+
return this.members;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
29
|
toString() {
|
|
30
30
|
const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
|
|
31
31
|
return `${chalk.bold.underline(this.name)}\n${membersStr}`;
|
|
32
32
|
}
|
|
33
|
+
|
|
34
|
+
toObject() {
|
|
35
|
+
return {
|
|
36
|
+
...super.toObject(),
|
|
37
|
+
name: this.name,
|
|
38
|
+
members: this.members.map((member) => member.toObject()),
|
|
39
|
+
doc: this.doc?.toObject(),
|
|
40
|
+
signature: this.signature,
|
|
41
|
+
extendsNodes: this.extendsNodes?.map((node) => node.toObject()),
|
|
42
|
+
typeParams: this.typeParams,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static fromObject(obj: Record<string, any>): InterfaceSchema {
|
|
47
|
+
const location = obj.location;
|
|
48
|
+
const name = obj.name;
|
|
49
|
+
const signature = obj.signature;
|
|
50
|
+
const extendsNodes = obj.extendsNodes?.map((node: any) => ExpressionWithTypeArgumentsSchema.fromObject(node));
|
|
51
|
+
const members = obj.members.map((member: any) => SchemaRegistry.fromObject(member));
|
|
52
|
+
const doc = obj.doc ? DocSchema.fromObject(obj.doc) : undefined;
|
|
53
|
+
const typeParams = obj.typeParams;
|
|
54
|
+
return new InterfaceSchema(location, name, signature, extendsNodes, members, doc, typeParams);
|
|
55
|
+
}
|
|
33
56
|
}
|
package/schemas/keyword-type.ts
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* e.g. 'string', 'boolean', etc.
|
|
5
5
|
*/
|
|
6
6
|
export class KeywordTypeSchema extends SchemaNode {
|
|
7
|
-
constructor(readonly location:
|
|
7
|
+
constructor(readonly location: SchemaLocation, readonly name: string) {
|
|
8
8
|
super();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
toString() {
|
|
12
12
|
return this.name;
|
|
13
13
|
}
|
|
14
|
+
|
|
15
|
+
toObject() {
|
|
16
|
+
return {
|
|
17
|
+
...super.toObject(),
|
|
18
|
+
name: this.name,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static fromObject(obj: Record<string, any>): KeywordTypeSchema {
|
|
23
|
+
const location = obj.location;
|
|
24
|
+
const name = obj.name;
|
|
25
|
+
return new KeywordTypeSchema(location, name);
|
|
26
|
+
}
|
|
14
27
|
}
|
package/schemas/literal-type.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* e.g. const a: 'a';
|
|
5
5
|
*/
|
|
6
6
|
export class LiteralTypeSchema extends SchemaNode {
|
|
7
|
-
constructor(readonly location:
|
|
7
|
+
constructor(readonly location: SchemaLocation, readonly name: string) {
|
|
8
8
|
super();
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
toObject() {
|
|
12
12
|
return {
|
|
13
|
-
|
|
13
|
+
...super.toObject(),
|
|
14
14
|
name: this.name,
|
|
15
15
|
};
|
|
16
16
|
}
|
|
@@ -18,4 +18,10 @@ export class LiteralTypeSchema extends SchemaNode {
|
|
|
18
18
|
toString() {
|
|
19
19
|
return this.name;
|
|
20
20
|
}
|
|
21
|
+
|
|
22
|
+
static fromObject(obj: Record<string, any>): LiteralTypeSchema {
|
|
23
|
+
const location = obj.location;
|
|
24
|
+
const name = obj.name;
|
|
25
|
+
return new LiteralTypeSchema(location, name);
|
|
26
|
+
}
|
|
21
27
|
}
|
package/schemas/module.ts
CHANGED
|
@@ -1,29 +1,20 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { schemaObjArrayToInstances } from '../class-transformers';
|
|
2
|
+
import { SchemaLocation, SchemaNode } from '../schema-node';
|
|
3
|
+
import { SchemaRegistry } from '../schema-registry';
|
|
5
4
|
|
|
6
5
|
export class ModuleSchema extends SchemaNode {
|
|
7
|
-
@Transform(schemaObjArrayToInstances)
|
|
8
6
|
exports: SchemaNode[];
|
|
9
|
-
|
|
10
|
-
@Transform(schemaObjArrayToInstances)
|
|
11
7
|
internals: SchemaNode[];
|
|
12
|
-
|
|
13
8
|
namespace?: string;
|
|
14
9
|
|
|
15
|
-
constructor(readonly location:
|
|
10
|
+
constructor(readonly location: SchemaLocation, exports: SchemaNode[], internals: SchemaNode[]) {
|
|
16
11
|
super();
|
|
17
12
|
this.exports = exports;
|
|
18
13
|
this.internals = internals;
|
|
19
14
|
}
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
return
|
|
23
|
-
constructorName: this.constructor.name,
|
|
24
|
-
namespace: this.namespace,
|
|
25
|
-
exports: this.exports.map((exp) => exp.toObject()),
|
|
26
|
-
};
|
|
16
|
+
getNodes() {
|
|
17
|
+
return [...this.exports, ...this.internals];
|
|
27
18
|
}
|
|
28
19
|
|
|
29
20
|
flatExportsRecursively() {
|
|
@@ -45,4 +36,23 @@ export class ModuleSchema extends SchemaNode {
|
|
|
45
36
|
const exportsStr = this.exports.map((m) => `* ${m.toString()}`).join('\n');
|
|
46
37
|
return `${chalk.bold.underline(this.namespace)}\n${exportsStr}`;
|
|
47
38
|
}
|
|
39
|
+
|
|
40
|
+
toObject() {
|
|
41
|
+
return {
|
|
42
|
+
...super.toObject(),
|
|
43
|
+
exports: this.exports.map((member) => member.toObject()),
|
|
44
|
+
internals: this.internals.map((member) => member.toObject()),
|
|
45
|
+
namespace: this.namespace,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
static fromObject(obj: Record<string, any>): ModuleSchema {
|
|
50
|
+
const location = obj.location;
|
|
51
|
+
const exportNodes = (obj.exports || []).map((member: any) => SchemaRegistry.fromObject(member));
|
|
52
|
+
const internals = (obj.internals || []).map((member: any) => SchemaRegistry.fromObject(member));
|
|
53
|
+
const namespace = obj.namespace;
|
|
54
|
+
const module = new ModuleSchema(location, exportNodes, internals);
|
|
55
|
+
module.namespace = namespace;
|
|
56
|
+
return module;
|
|
57
|
+
}
|
|
48
58
|
}
|