@teambit/semantics.entities.semantic-schema 0.0.10 → 0.0.13
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 +18 -22
- package/dist/api-schema.d.ts +6 -19
- package/dist/api-schema.js +22 -12
- package/dist/api-schema.js.map +1 -1
- package/dist/{schemas/export.d.ts → export.d.ts} +5 -10
- package/dist/{schemas/export.js → export.js} +4 -5
- package/dist/export.js.map +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/schema-node.d.ts +9 -8
- package/dist/schema-node.js +16 -0
- package/dist/schema-node.js.map +1 -1
- package/dist/schema-obj-to-class.d.ts +10 -0
- package/dist/schema-obj-to-class.js +56 -0
- package/dist/schema-obj-to-class.js.map +1 -0
- package/dist/schemas/class.d.ts +2 -9
- package/dist/schemas/class.js +15 -9
- package/dist/schemas/class.js.map +1 -1
- package/dist/schemas/constructor.d.ts +4 -15
- package/dist/schemas/constructor.js +16 -8
- package/dist/schemas/constructor.js.map +1 -1
- package/dist/schemas/enum.d.ts +8 -0
- package/dist/schemas/enum.js +21 -0
- package/dist/schemas/enum.js.map +1 -1
- package/dist/schemas/function-like.d.ts +10 -18
- package/dist/schemas/function-like.js +30 -20
- package/dist/schemas/function-like.js.map +1 -1
- package/dist/schemas/get-accessor.d.ts +7 -14
- package/dist/schemas/get-accessor.js +17 -11
- package/dist/schemas/get-accessor.js.map +1 -1
- package/dist/schemas/index-signature.d.ts +6 -12
- package/dist/schemas/index-signature.js +19 -9
- package/dist/schemas/index-signature.js.map +1 -1
- package/dist/schemas/index.d.ts +4 -1
- package/dist/schemas/index.js +9 -3
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/indexed-access-type.d.ts +8 -0
- package/dist/schemas/indexed-access-type.js +31 -0
- package/dist/schemas/indexed-access-type.js.map +1 -0
- package/dist/schemas/inference-type.d.ts +6 -8
- package/dist/schemas/inference-type.js +9 -8
- package/dist/schemas/inference-type.js.map +1 -1
- package/dist/schemas/interface.d.ts +6 -12
- package/dist/schemas/interface.js +16 -9
- package/dist/schemas/interface.js.map +1 -1
- package/dist/schemas/keyword-type.d.ts +4 -7
- package/dist/schemas/keyword-type.js +5 -8
- package/dist/schemas/keyword-type.js.map +1 -1
- package/dist/schemas/literal-type.d.ts +5 -4
- package/dist/schemas/literal-type.js +5 -2
- package/dist/schemas/literal-type.js.map +1 -1
- package/dist/schemas/module.d.ts +5 -8
- package/dist/schemas/module.js +16 -6
- package/dist/schemas/module.js.map +1 -1
- package/dist/schemas/parameter.d.ts +5 -13
- package/dist/schemas/parameter.js +17 -12
- package/dist/schemas/parameter.js.map +1 -1
- package/dist/schemas/parenthesized-type.d.ts +11 -0
- package/dist/schemas/parenthesized-type.js +31 -0
- package/dist/schemas/parenthesized-type.js.map +1 -0
- package/dist/schemas/set-accessor.d.ts +7 -12
- package/dist/schemas/set-accessor.js +17 -11
- package/dist/schemas/set-accessor.js.map +1 -1
- package/dist/schemas/tuple-type.d.ts +5 -10
- package/dist/schemas/tuple-type.js +16 -8
- package/dist/schemas/tuple-type.js.map +1 -1
- package/dist/schemas/type-array.d.ts +5 -10
- package/dist/schemas/type-array.js +16 -8
- package/dist/schemas/type-array.js.map +1 -1
- package/dist/schemas/type-intersection.d.ts +5 -10
- package/dist/schemas/type-intersection.js +16 -8
- package/dist/schemas/type-intersection.js.map +1 -1
- package/dist/schemas/type-literal.d.ts +5 -10
- package/dist/schemas/type-literal.js +16 -8
- package/dist/schemas/type-literal.js.map +1 -1
- package/dist/schemas/type-operator.d.ts +6 -12
- package/dist/schemas/type-operator.js +16 -9
- package/dist/schemas/type-operator.js.map +1 -1
- package/dist/schemas/type-predicate.d.ts +22 -0
- package/dist/schemas/type-predicate.js +44 -0
- package/dist/schemas/type-predicate.js.map +1 -0
- package/dist/schemas/type-query.d.ts +6 -10
- package/dist/schemas/type-query.js +17 -10
- package/dist/schemas/type-query.js.map +1 -1
- package/dist/schemas/type-ref.d.ts +15 -10
- package/dist/schemas/type-ref.js +34 -16
- package/dist/schemas/type-ref.js.map +1 -1
- package/dist/schemas/type-union.d.ts +5 -10
- package/dist/schemas/type-union.js +16 -8
- package/dist/schemas/type-union.js.map +1 -1
- package/dist/schemas/type.d.ts +7 -14
- package/dist/schemas/type.js +17 -11
- package/dist/schemas/type.js.map +1 -1
- package/dist/schemas/variable.d.ts +9 -14
- package/dist/schemas/variable.js +19 -13
- package/dist/schemas/variable.js.map +1 -1
- package/{schemas/export.ts → export.ts} +5 -8
- package/index.ts +5 -2
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.13.tgz +0 -0
- package/package.json +6 -3
- package/{preview-1652757984397.js → preview-1653449228788.js} +1 -1
- package/schema-node.ts +13 -6
- package/schema-obj-to-class.ts +36 -0
- package/schemas/class.ts +8 -9
- package/schemas/constructor.ts +10 -10
- package/schemas/enum.ts +13 -0
- package/schemas/function-like.ts +36 -23
- package/schemas/get-accessor.ts +10 -12
- package/schemas/index-signature.ts +13 -9
- package/schemas/index.ts +4 -1
- package/schemas/indexed-access-type.ts +18 -0
- package/schemas/inference-type.ts +7 -9
- package/schemas/interface.ts +10 -9
- package/schemas/keyword-type.ts +4 -9
- package/schemas/literal-type.ts +5 -3
- package/schemas/module.ts +9 -7
- package/schemas/parameter.ts +12 -13
- package/schemas/parenthesized-type.ts +20 -0
- package/schemas/set-accessor.ts +10 -12
- package/schemas/tuple-type.ts +10 -8
- package/schemas/type-array.ts +10 -8
- package/schemas/type-intersection.ts +10 -8
- package/schemas/type-literal.ts +10 -8
- package/schemas/type-operator.ts +10 -9
- package/schemas/type-predicate.ts +36 -0
- package/schemas/type-query.ts +10 -11
- package/schemas/type-ref.ts +39 -20
- package/schemas/type-union.ts +9 -8
- package/schemas/type.ts +10 -10
- package/schemas/variable.ts +12 -14
- package/tsconfig.json +1 -0
- package/dist/schemas/export.js.map +0 -1
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.10.tgz +0 -0
package/schemas/enum.ts
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
|
|
4
|
+
export class EnumSchema extends SchemaNode {
|
|
5
|
+
constructor(readonly location: Location, readonly name: string, readonly members: string[]) {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
toString() {
|
|
10
|
+
const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
|
|
11
|
+
return `${chalk.bold.underline(this.name)}\n${membersStr}`;
|
|
12
|
+
}
|
|
13
|
+
}
|
package/schemas/function-like.ts
CHANGED
|
@@ -1,43 +1,56 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
3
|
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjArrayToInstances, schemaObjToInstance } from '../schema-obj-to-class';
|
|
3
5
|
import { ParameterSchema } from './parameter';
|
|
4
6
|
|
|
5
|
-
export type Modifier =
|
|
7
|
+
export type Modifier =
|
|
8
|
+
| 'static'
|
|
9
|
+
| 'public'
|
|
10
|
+
| 'private'
|
|
11
|
+
| 'protected'
|
|
12
|
+
| 'readonly'
|
|
13
|
+
| 'abstract'
|
|
14
|
+
| 'async'
|
|
15
|
+
| 'override'
|
|
16
|
+
| 'export';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* function-like can be a function, method, arrow-function, variable-function, etc.
|
|
20
|
+
*/
|
|
21
|
+
export class FunctionLikeSchema extends SchemaNode {
|
|
22
|
+
@Transform(schemaObjToInstance)
|
|
23
|
+
readonly returnType: SchemaNode;
|
|
24
|
+
|
|
25
|
+
@Transform(schemaObjArrayToInstances)
|
|
26
|
+
readonly params: ParameterSchema[];
|
|
6
27
|
|
|
7
|
-
export class FunctionLikeSchema implements SchemaNode {
|
|
8
28
|
constructor(
|
|
29
|
+
readonly location: Location,
|
|
9
30
|
readonly name: string,
|
|
10
31
|
// readonly doc: any,
|
|
11
|
-
|
|
32
|
+
params: ParameterSchema[],
|
|
12
33
|
|
|
13
|
-
|
|
34
|
+
returnType: SchemaNode,
|
|
14
35
|
readonly signature: string,
|
|
15
|
-
readonly location: Location,
|
|
16
36
|
readonly modifiers: Modifier[] = []
|
|
17
|
-
) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
) {
|
|
38
|
+
super();
|
|
39
|
+
this.params = params;
|
|
40
|
+
this.returnType = returnType;
|
|
41
|
+
}
|
|
22
42
|
|
|
23
43
|
getSignature() {
|
|
24
44
|
return this.signature;
|
|
25
45
|
}
|
|
26
46
|
|
|
27
|
-
toObject() {
|
|
28
|
-
return {
|
|
29
|
-
constructorName: this.constructor.name,
|
|
30
|
-
name: this.name,
|
|
31
|
-
params: this.params,
|
|
32
|
-
returnType: this.returnType.toObject(),
|
|
33
|
-
signature: this.signature,
|
|
34
|
-
modifiers: this.modifiers,
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
47
|
toString() {
|
|
39
48
|
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
40
|
-
|
|
41
|
-
|
|
49
|
+
return `${this.modifiersToString()}${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
private modifiersToString() {
|
|
53
|
+
const modifiersToPrint = this.modifiers.filter((modifier) => modifier !== 'export');
|
|
54
|
+
return modifiersToPrint.length ? `${modifiersToPrint.join(' ')} ` : '';
|
|
42
55
|
}
|
|
43
56
|
}
|
package/schemas/get-accessor.ts
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { SchemaNode } from '../schema-node';
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
3
5
|
|
|
4
|
-
export class GetAccessorSchema
|
|
5
|
-
|
|
6
|
+
export class GetAccessorSchema extends SchemaNode {
|
|
7
|
+
@Transform(schemaObjToInstance)
|
|
8
|
+
readonly type: SchemaNode;
|
|
9
|
+
constructor(readonly location: Location, readonly name: string, type: SchemaNode, readonly signature: string) {
|
|
10
|
+
super();
|
|
11
|
+
this.type = type;
|
|
12
|
+
}
|
|
6
13
|
getSignature() {
|
|
7
14
|
return this.signature;
|
|
8
15
|
}
|
|
9
16
|
|
|
10
|
-
toObject() {
|
|
11
|
-
return {
|
|
12
|
-
constructorName: this.constructor.name,
|
|
13
|
-
name: this.name,
|
|
14
|
-
type: this.type.toObject(),
|
|
15
|
-
signature: this.signature,
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
17
|
toString() {
|
|
20
18
|
return `get ${chalk.bold(this.name)}(): ${this.type.toString()}`;
|
|
21
19
|
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
3
|
import { ParameterSchema } from './parameter';
|
|
4
|
+
import { schemaObjArrayToInstances, schemaObjToInstance } from '../schema-obj-to-class';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* e.g. `{ [key: string]: boolean };`
|
|
6
8
|
* the "[key: string]" is the "parameter", and the "boolean" is the "type".
|
|
7
9
|
*/
|
|
8
|
-
export class IndexSignatureSchema
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export class IndexSignatureSchema extends SchemaNode {
|
|
11
|
+
@Transform(schemaObjArrayToInstances)
|
|
12
|
+
readonly params: ParameterSchema[];
|
|
13
|
+
@Transform(schemaObjToInstance)
|
|
14
|
+
readonly type: SchemaNode;
|
|
15
|
+
constructor(readonly location: Location, params: ParameterSchema[], type: SchemaNode) {
|
|
16
|
+
super();
|
|
17
|
+
this.params = params;
|
|
18
|
+
this.type = type;
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
toString() {
|
|
18
22
|
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
19
23
|
return `[${paramsStr}]: ${this.type.toString()}`;
|
package/schemas/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { Module } from './module';
|
|
2
|
-
export { Export, StaticProperties } from './export';
|
|
3
2
|
export { FunctionLikeSchema, Modifier } from './function-like';
|
|
4
3
|
export { TypeRefSchema } from './type-ref';
|
|
5
4
|
export { VariableSchema } from './variable';
|
|
@@ -21,3 +20,7 @@ export { TypeArraySchema } from './type-array';
|
|
|
21
20
|
export { TypeOperatorSchema } from './type-operator';
|
|
22
21
|
export { TupleTypeSchema } from './tuple-type';
|
|
23
22
|
export { ParameterSchema } from './parameter';
|
|
23
|
+
export { EnumSchema } from './enum';
|
|
24
|
+
export { ParenthesizedTypeSchema } from './parenthesized-type';
|
|
25
|
+
export { TypePredicateSchema } from './type-predicate';
|
|
26
|
+
export { IndexedAccessSchema } from './indexed-access-type';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
|
+
|
|
5
|
+
export class IndexedAccessSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
readonly objectType: SchemaNode;
|
|
8
|
+
@Transform(schemaObjToInstance)
|
|
9
|
+
readonly indexType: SchemaNode;
|
|
10
|
+
constructor(readonly location: Location, objectType: SchemaNode, indexType: SchemaNode) {
|
|
11
|
+
super();
|
|
12
|
+
this.objectType = objectType;
|
|
13
|
+
this.indexType = indexType;
|
|
14
|
+
}
|
|
15
|
+
toString() {
|
|
16
|
+
return `${this.objectType.toString()}[${this.indexType.toString()}]`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import { SchemaNode } from '../schema-node';
|
|
1
|
+
import { Location, 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
|
-
export class InferenceTypeSchema
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
toObject() {
|
|
10
|
-
return {
|
|
11
|
-
constructorName: this.constructor.name,
|
|
12
|
-
type: this.type,
|
|
13
|
-
};
|
|
6
|
+
export class InferenceTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, readonly type: string, readonly name?: string) {
|
|
8
|
+
super();
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
toString() {
|
|
12
|
+
if (this.name) {
|
|
13
|
+
return `${this.name}: ${this.type}`;
|
|
14
|
+
}
|
|
17
15
|
return this.type;
|
|
18
16
|
}
|
|
19
17
|
}
|
package/schemas/interface.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { SchemaNode } from '../schema-node';
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
3
5
|
|
|
4
|
-
export class InterfaceSchema
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
types: this.members.map((type) => type.toObject()),
|
|
11
|
-
};
|
|
6
|
+
export class InterfaceSchema extends SchemaNode {
|
|
7
|
+
@Transform(schemaObjArrayToInstances)
|
|
8
|
+
readonly members: SchemaNode[];
|
|
9
|
+
constructor(readonly location: Location, readonly name: string, members: SchemaNode[]) {
|
|
10
|
+
super();
|
|
11
|
+
this.members = members;
|
|
12
12
|
}
|
|
13
|
+
|
|
13
14
|
toString() {
|
|
14
15
|
const membersStr = this.members.map((m) => `* ${m.toString()}`).join('\n');
|
|
15
16
|
return `${chalk.bold.underline(this.name)}\n${membersStr}`;
|
package/schemas/keyword-type.ts
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
import { SchemaNode } from '../schema-node';
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* e.g. 'string', 'boolean', etc.
|
|
5
5
|
*/
|
|
6
|
-
export class KeywordTypeSchema
|
|
7
|
-
constructor(private name: string) {
|
|
8
|
-
|
|
9
|
-
toObject() {
|
|
10
|
-
return {
|
|
11
|
-
constructorName: this.constructor.name,
|
|
12
|
-
name: this.name,
|
|
13
|
-
};
|
|
6
|
+
export class KeywordTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, private name: string) {
|
|
8
|
+
super();
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
toString() {
|
package/schemas/literal-type.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { SchemaNode } from '../schema-node';
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* e.g. const a: 'a';
|
|
5
5
|
*/
|
|
6
|
-
export class LiteralTypeSchema
|
|
7
|
-
constructor(
|
|
6
|
+
export class LiteralTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, readonly name: string) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
8
10
|
|
|
9
11
|
toObject() {
|
|
10
12
|
return {
|
package/schemas/module.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import chalk from 'chalk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { Transform } from 'class-transformer';
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
4
5
|
|
|
5
|
-
export class Module
|
|
6
|
+
export class Module extends SchemaNode {
|
|
7
|
+
@Transform(schemaObjArrayToInstances)
|
|
8
|
+
exports: SchemaNode[];
|
|
6
9
|
namespace?: string;
|
|
7
|
-
constructor(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return this.exports.filter((e) => e instanceof Export) as Export[];
|
|
10
|
+
constructor(readonly location: Location, exports: SchemaNode[]) {
|
|
11
|
+
super();
|
|
12
|
+
this.exports = exports;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
toObject() {
|
package/schemas/parameter.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
|
-
export class ParameterSchema
|
|
5
|
+
export class ParameterSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
readonly type: SchemaNode;
|
|
4
8
|
constructor(
|
|
9
|
+
readonly location: Location,
|
|
5
10
|
readonly name: string,
|
|
6
|
-
|
|
11
|
+
type: SchemaNode,
|
|
7
12
|
readonly defaultValue?: any,
|
|
8
13
|
readonly description?: string
|
|
9
|
-
) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return {
|
|
13
|
-
constructorName: this.constructor.name,
|
|
14
|
-
name: this.name,
|
|
15
|
-
type: this.type.toObject(),
|
|
16
|
-
defaultValue: this.defaultValue,
|
|
17
|
-
description: this.description,
|
|
18
|
-
};
|
|
14
|
+
) {
|
|
15
|
+
super();
|
|
16
|
+
this.type = type;
|
|
19
17
|
}
|
|
18
|
+
|
|
20
19
|
toString() {
|
|
21
20
|
return `${this.name}: ${this.type.toString()}`;
|
|
22
21
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* type inside parentheses
|
|
7
|
+
* e.g. (T1 | T2)
|
|
8
|
+
*/
|
|
9
|
+
export class ParenthesizedTypeSchema extends SchemaNode {
|
|
10
|
+
@Transform(schemaObjToInstance)
|
|
11
|
+
readonly type: SchemaNode;
|
|
12
|
+
constructor(readonly location: Location, type: SchemaNode) {
|
|
13
|
+
super();
|
|
14
|
+
this.type = type;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toString() {
|
|
18
|
+
return `(${this.type.toString()})`;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/schemas/set-accessor.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { SchemaNode } from '../schema-node';
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
4
|
import { ParameterSchema } from './parameter';
|
|
5
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
6
|
|
|
5
|
-
export class SetAccessorSchema
|
|
6
|
-
|
|
7
|
+
export class SetAccessorSchema extends SchemaNode {
|
|
8
|
+
@Transform(schemaObjToInstance)
|
|
9
|
+
readonly param: ParameterSchema;
|
|
10
|
+
constructor(readonly location: Location, readonly name: string, param: ParameterSchema, readonly signature: string) {
|
|
11
|
+
super();
|
|
12
|
+
this.param = param;
|
|
13
|
+
}
|
|
7
14
|
getSignature() {
|
|
8
15
|
return this.signature;
|
|
9
16
|
}
|
|
10
17
|
|
|
11
|
-
toObject() {
|
|
12
|
-
return {
|
|
13
|
-
constructorName: this.constructor.name,
|
|
14
|
-
name: this.name,
|
|
15
|
-
param: this.param,
|
|
16
|
-
signature: this.signature,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
18
|
toString() {
|
|
21
19
|
return `set ${chalk.bold(this.name)}(${this.param.toString()})`;
|
|
22
20
|
}
|
package/schemas/tuple-type.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
|
-
export class TupleTypeSchema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
export class TupleTypeSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjArrayToInstances)
|
|
7
|
+
readonly elements: SchemaNode[];
|
|
8
|
+
constructor(readonly location: Location, elements: SchemaNode[]) {
|
|
9
|
+
super();
|
|
10
|
+
this.elements = elements;
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
toString() {
|
|
12
14
|
return `[${this.elements.map((elem) => elem.toString()).join(', ')}]`;
|
|
13
15
|
}
|
package/schemas/type-array.ts
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
|
-
export class TypeArraySchema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
export class TypeArraySchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
readonly type: SchemaNode;
|
|
8
|
+
constructor(readonly location: Location, type: SchemaNode) {
|
|
9
|
+
super();
|
|
10
|
+
this.type = type;
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
toString() {
|
|
12
14
|
return `${this.type.toString()}[]`;
|
|
13
15
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
|
-
export class TypeIntersectionSchema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
5
|
+
export class TypeIntersectionSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjArrayToInstances)
|
|
7
|
+
readonly types: SchemaNode[];
|
|
8
|
+
constructor(readonly location: Location, types: SchemaNode[]) {
|
|
9
|
+
super();
|
|
10
|
+
this.types = types;
|
|
10
11
|
}
|
|
12
|
+
|
|
11
13
|
toString() {
|
|
12
14
|
return `${this.types.map((type) => type.toString()).join(' & ')}`;
|
|
13
15
|
}
|
package/schemas/type-literal.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* e.g. `{ a: string; b: number }`
|
|
5
7
|
*/
|
|
6
|
-
export class TypeLiteralSchema
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
8
|
+
export class TypeLiteralSchema extends SchemaNode {
|
|
9
|
+
@Transform(schemaObjArrayToInstances)
|
|
10
|
+
readonly members: SchemaNode[];
|
|
11
|
+
constructor(readonly location: Location, members: SchemaNode[]) {
|
|
12
|
+
super();
|
|
13
|
+
this.members = members;
|
|
13
14
|
}
|
|
15
|
+
|
|
14
16
|
toString() {
|
|
15
17
|
return `{ ${this.members.map((type) => type.toString()).join('; ')} }`;
|
|
16
18
|
}
|
package/schemas/type-operator.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
|
-
export class TypeOperatorSchema
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
type: this.type.toObject(),
|
|
10
|
-
};
|
|
5
|
+
export class TypeOperatorSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
type: SchemaNode;
|
|
8
|
+
constructor(readonly location: Location, readonly operatorName: string, type: SchemaNode) {
|
|
9
|
+
super();
|
|
10
|
+
this.type = type;
|
|
11
11
|
}
|
|
12
|
+
|
|
12
13
|
toString() {
|
|
13
14
|
return `${this.operatorName} ${this.type.toString()}`;
|
|
14
15
|
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* e.g. `function f(str: any): str is string {}`
|
|
7
|
+
*
|
|
8
|
+
* example when the type is empty:
|
|
9
|
+
* ```ts
|
|
10
|
+
* function assert(condition: any, msg?: string): asserts condition {
|
|
11
|
+
* if (!condition) {
|
|
12
|
+
* throw new AssertionError(msg);
|
|
13
|
+
* }
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
export class TypePredicateSchema extends SchemaNode {
|
|
19
|
+
@Transform(schemaObjToInstance)
|
|
20
|
+
readonly type?: SchemaNode;
|
|
21
|
+
constructor(
|
|
22
|
+
readonly location: Location,
|
|
23
|
+
readonly parameterName: string,
|
|
24
|
+
type?: SchemaNode,
|
|
25
|
+
readonly hasAssertsModifier = false
|
|
26
|
+
) {
|
|
27
|
+
super();
|
|
28
|
+
this.type = type;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
toString() {
|
|
32
|
+
const assertsKeyword = this.hasAssertsModifier ? 'asserts ' : '';
|
|
33
|
+
const typeStr = this.type ? ` is ${this.type.toString()}` : '';
|
|
34
|
+
return assertsKeyword + this.parameterName + typeStr;
|
|
35
|
+
}
|
|
36
|
+
}
|
package/schemas/type-query.ts
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* e.g. `typeof Foo`
|
|
5
7
|
*/
|
|
6
|
-
export class TypeQuerySchema
|
|
7
|
-
|
|
8
|
+
export class TypeQuerySchema extends SchemaNode {
|
|
9
|
+
@Transform(schemaObjToInstance)
|
|
10
|
+
readonly type: SchemaNode;
|
|
11
|
+
constructor(readonly location: Location, type: SchemaNode, readonly signature: string) {
|
|
12
|
+
super();
|
|
13
|
+
this.type = type;
|
|
14
|
+
}
|
|
8
15
|
getSignature() {
|
|
9
16
|
return this.signature;
|
|
10
17
|
}
|
|
11
18
|
|
|
12
|
-
toObject() {
|
|
13
|
-
return {
|
|
14
|
-
constructorName: this.constructor.name,
|
|
15
|
-
type: this.type,
|
|
16
|
-
signature: this.signature,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
19
|
toString() {
|
|
21
20
|
return `typeof ${this.type.toString()}`;
|
|
22
21
|
}
|