@teambit/semantics.entities.semantic-schema 0.0.8 → 0.0.11
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 +17 -22
- package/dist/api-schema.d.ts +6 -19
- package/dist/api-schema.js +21 -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 +3 -2
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/schema-node.d.ts +14 -7
- 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 +4 -10
- package/dist/schemas/class.js +16 -9
- package/dist/schemas/class.js.map +1 -1
- package/dist/schemas/constructor.d.ts +6 -9
- package/dist/schemas/constructor.js +19 -11
- package/dist/schemas/constructor.js.map +1 -1
- package/dist/schemas/function-like.d.ts +14 -0
- package/dist/schemas/function-like.js +45 -0
- package/dist/schemas/function-like.js.map +1 -0
- package/dist/schemas/get-accessor.d.ts +7 -18
- package/dist/schemas/get-accessor.js +17 -11
- package/dist/schemas/get-accessor.js.map +1 -1
- package/dist/schemas/index-signature.d.ts +7 -17
- package/dist/schemas/index-signature.js +22 -12
- package/dist/schemas/index-signature.js.map +1 -1
- package/dist/schemas/index.d.ts +9 -2
- package/dist/schemas/index.js +19 -5
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/inference-type.d.ts +10 -0
- package/dist/schemas/inference-type.js +19 -0
- package/dist/schemas/inference-type.js.map +1 -0
- 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 +10 -0
- package/dist/schemas/keyword-type.js +19 -0
- package/dist/schemas/keyword-type.js.map +1 -0
- package/dist/schemas/literal-type.d.ts +14 -0
- package/dist/schemas/literal-type.js +25 -0
- package/dist/schemas/literal-type.js.map +1 -0
- 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 +10 -0
- package/dist/schemas/parameter.js +30 -0
- package/dist/schemas/parameter.js.map +1 -0
- package/dist/schemas/set-accessor.d.ts +8 -13
- package/dist/schemas/set-accessor.js +18 -12
- package/dist/schemas/set-accessor.js.map +1 -1
- package/dist/schemas/tuple-type.d.ts +7 -0
- package/dist/schemas/tuple-type.js +27 -0
- package/dist/schemas/tuple-type.js.map +1 -0
- package/dist/schemas/type-array.d.ts +7 -0
- package/dist/schemas/type-array.js +27 -0
- package/dist/schemas/type-array.js.map +1 -0
- 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 +8 -0
- package/dist/schemas/type-operator.js +28 -0
- package/dist/schemas/type-operator.js.map +1 -0
- package/dist/schemas/type-query.d.ts +12 -0
- package/dist/schemas/type-query.js +34 -0
- package/dist/schemas/type-query.js.map +1 -0
- package/dist/schemas/type-ref.d.ts +9 -13
- package/dist/schemas/type-ref.js +11 -15
- 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 +6 -18
- package/dist/schemas/variable.js +16 -13
- package/dist/schemas/variable.js.map +1 -1
- package/{schemas/export.ts → export.ts} +5 -8
- package/index.ts +12 -5
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.11.tgz +0 -0
- package/package.json +7 -4
- package/{preview-1652239597845.js → preview-1652930732694.js} +1 -1
- package/schema-node.ts +15 -5
- package/schema-obj-to-class.ts +36 -0
- package/schemas/class.ts +9 -10
- package/schemas/constructor.ts +13 -13
- package/schemas/function-like.ts +40 -0
- package/schemas/get-accessor.ts +10 -13
- package/schemas/index-signature.ts +16 -13
- package/schemas/index.ts +9 -2
- package/schemas/inference-type.ts +14 -0
- package/schemas/interface.ts +10 -9
- package/schemas/keyword-type.ts +14 -0
- package/schemas/literal-type.ts +21 -0
- package/schemas/module.ts +9 -7
- package/schemas/parameter.ts +22 -0
- package/schemas/set-accessor.ts +12 -14
- package/schemas/tuple-type.ts +16 -0
- package/schemas/type-array.ts +16 -0
- package/schemas/type-intersection.ts +10 -8
- package/schemas/type-literal.ts +10 -8
- package/schemas/type-operator.ts +16 -0
- package/schemas/type-query.ts +22 -0
- package/schemas/type-ref.ts +19 -22
- package/schemas/type-union.ts +9 -8
- package/schemas/type.ts +10 -10
- package/schemas/variable.ts +9 -15
- package/tsconfig.json +1 -0
- package/dist/schemas/export.js.map +0 -1
- package/dist/schemas/function.d.ts +0 -31
- package/dist/schemas/function.js +0 -37
- package/dist/schemas/function.js.map +0 -1
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.8.tgz +0 -0
- package/schemas/function.ts +0 -44
package/dist/schemas/variable.js
CHANGED
|
@@ -1,30 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
9
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
10
|
};
|
|
5
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
12
|
exports.VariableSchema = void 0;
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
7
14
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
const schema_node_1 = require("../schema-node");
|
|
16
|
+
const schema_obj_to_class_1 = require("../schema-obj-to-class");
|
|
17
|
+
class VariableSchema extends schema_node_1.SchemaNode {
|
|
18
|
+
constructor(location, name, signature, type) {
|
|
19
|
+
super();
|
|
20
|
+
this.location = location;
|
|
10
21
|
this.name = name;
|
|
11
22
|
this.signature = signature;
|
|
12
23
|
this.type = type;
|
|
13
24
|
}
|
|
14
|
-
getSignature() {
|
|
15
|
-
return this.signature;
|
|
16
|
-
}
|
|
17
|
-
toObject() {
|
|
18
|
-
return {
|
|
19
|
-
constructorName: this.constructor.name,
|
|
20
|
-
name: this.name,
|
|
21
|
-
signature: this.signature,
|
|
22
|
-
type: this.type.toObject(),
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
25
|
toString() {
|
|
26
26
|
return `${chalk_1.default.bold(this.name)}: ${this.type.toString()}`;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, class_transformer_1.Transform)(schema_obj_to_class_1.schemaObjToInstance)
|
|
31
|
+
], VariableSchema.prototype, "type", void 0);
|
|
29
32
|
exports.VariableSchema = VariableSchema;
|
|
30
33
|
//# sourceMappingURL=variable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"variable.js","sourceRoot":"","sources":["../../schemas/variable.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"variable.js","sourceRoot":"","sources":["../../schemas/variable.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA8C;AAC9C,kDAA0B;AAC1B,gDAAsD;AACtD,gEAA6D;AAE7D,MAAa,cAAe,SAAQ,wBAAU;IAG5C,YAAqB,QAAkB,EAAW,IAAY,EAAW,SAAiB,EAAE,IAAgB;QAC1G,KAAK,EAAE,CAAC;QADW,aAAQ,GAAR,QAAQ,CAAU;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAAW,cAAS,GAAT,SAAS,CAAQ;QAExF,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,QAAQ;QACN,OAAO,GAAG,eAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,CAAC;CACF;AATC;IADC,IAAA,6BAAS,EAAC,yCAAmB,CAAC;4CACd;AAFnB,wCAWC"}
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
import { SchemaNode } from '../schema-node';
|
|
2
|
-
|
|
3
1
|
type Primitive = string | number | boolean | null | undefined;
|
|
4
2
|
export type StaticProperties = Map<string, Primitive>;
|
|
5
3
|
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* @todo: this was implemented before all other schemas and is used only for composition.
|
|
6
|
+
* it needs to be align with other schemas.
|
|
7
|
+
*/
|
|
8
|
+
export class Export {
|
|
7
9
|
constructor(
|
|
8
10
|
/**
|
|
9
11
|
* named export identifier of the module export.
|
|
10
12
|
*/
|
|
11
13
|
readonly identifier: string,
|
|
12
14
|
|
|
13
|
-
/**
|
|
14
|
-
* API node.
|
|
15
|
-
*/
|
|
16
|
-
readonly nodes?: SchemaNode[],
|
|
17
|
-
|
|
18
15
|
/**
|
|
19
16
|
* static properties attached to this export
|
|
20
17
|
* @example
|
package/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { APISchema } from './api-schema';
|
|
2
|
-
export
|
|
2
|
+
export { Export, StaticProperties } from './export';
|
|
3
|
+
export type { SchemaNode, Location } from './schema-node';
|
|
3
4
|
export {
|
|
4
|
-
Export,
|
|
5
5
|
Module,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Parameter,
|
|
6
|
+
FunctionLikeSchema,
|
|
7
|
+
Modifier,
|
|
9
8
|
TypeRefSchema,
|
|
10
9
|
VariableSchema,
|
|
11
10
|
ClassSchema,
|
|
@@ -18,5 +17,13 @@ export {
|
|
|
18
17
|
InterfaceSchema,
|
|
19
18
|
GetAccessorSchema,
|
|
20
19
|
SetAccessorSchema,
|
|
20
|
+
TypeQuerySchema,
|
|
21
|
+
InferenceTypeSchema,
|
|
22
|
+
LiteralTypeSchema,
|
|
23
|
+
KeywordTypeSchema,
|
|
24
|
+
TypeArraySchema,
|
|
25
|
+
TypeOperatorSchema,
|
|
26
|
+
TupleTypeSchema,
|
|
27
|
+
ParameterSchema,
|
|
21
28
|
} from './schemas';
|
|
22
29
|
export type { JSONSchema, JSONSchemaObject } from './json-schema';
|
package/package.json
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/semantics.entities.semantic-schema",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.11",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/semantics/entities/semantic-schema",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.semantics",
|
|
8
8
|
"name": "entities/semantic-schema",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.11"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"chalk": "4.
|
|
13
|
-
"
|
|
12
|
+
"chalk": "2.4.2",
|
|
13
|
+
"class-transformer": "0.5.1",
|
|
14
|
+
"json-schema": "0.4.0",
|
|
15
|
+
"lodash": "4.17.21"
|
|
14
16
|
},
|
|
15
17
|
"devDependencies": {
|
|
16
18
|
"@types/json-schema": "7.0.9",
|
|
19
|
+
"@types/lodash": "4.14.165",
|
|
17
20
|
"@types/mocha": "9.1.0",
|
|
18
21
|
"@babel/runtime": "7.12.18",
|
|
19
22
|
"@types/node": "12.20.4",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.
|
|
1
|
+
export const overview = [require('/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.semantics_entities_semantic-schema@0.0.11/dist/semantic-schema.docs.md')]
|
package/schema-node.ts
CHANGED
|
@@ -1,10 +1,20 @@
|
|
|
1
|
+
import { instanceToPlain } from 'class-transformer';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
|
-
*
|
|
4
|
+
* a convenient abstract class for all schema to extend.
|
|
5
|
+
* the reason for having it as an abstract class and not an interface, for now, is mostly for the `__schema` prop.
|
|
6
|
+
* this way it won't need to be implemented in each one of the subclasses.
|
|
3
7
|
*/
|
|
4
|
-
export
|
|
5
|
-
|
|
8
|
+
export abstract class SchemaNode {
|
|
9
|
+
readonly __schema = this.constructor.name;
|
|
10
|
+
abstract readonly location: Location;
|
|
11
|
+
readonly signature?: string;
|
|
6
12
|
|
|
7
|
-
toString(): string;
|
|
13
|
+
abstract toString(): string;
|
|
8
14
|
|
|
9
|
-
toObject()
|
|
15
|
+
toObject() {
|
|
16
|
+
return instanceToPlain(this);
|
|
17
|
+
}
|
|
10
18
|
}
|
|
19
|
+
|
|
20
|
+
export type Location = { file: string; line: number; character: number };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { plainToInstance, TransformationType, ClassConstructor } from 'class-transformer';
|
|
2
|
+
import { compact } from 'lodash';
|
|
3
|
+
import { SchemaNode } from './schema-node';
|
|
4
|
+
import * as Schemas from './schemas';
|
|
5
|
+
|
|
6
|
+
export function schemaObjArrayToInstances({ value, type }: { value: SchemaNode[]; type: TransformationType }) {
|
|
7
|
+
if (type !== TransformationType.PLAIN_TO_CLASS) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
return value.map((obj) => transformFromObjectToInstance(obj));
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function schemaObjToInstance({ value, type }: { value: Record<string, any>; type: TransformationType }) {
|
|
14
|
+
if (type !== TransformationType.PLAIN_TO_CLASS) {
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
return transformFromObjectToInstance(value);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function transformFromObjectToInstance(obj: Record<string, any>): SchemaNode {
|
|
21
|
+
if (!obj.__schema) {
|
|
22
|
+
throw new Error(`fatal: "__schema" is missing, make sure the transformer is set on SchemaNode type`);
|
|
23
|
+
}
|
|
24
|
+
const SchemaClass = getClassBySchemaName(obj.__schema);
|
|
25
|
+
return plainToInstance(SchemaClass, obj);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getClassBySchemaName(schemaName: string): ClassConstructor<SchemaNode> {
|
|
29
|
+
const schemasClasses = compact(Object.values(Schemas));
|
|
30
|
+
const schemaClass = schemasClasses.find((schema) => schema.name === schemaName);
|
|
31
|
+
if (!schemaClass) {
|
|
32
|
+
throw new Error(`unable to find schema "${schemaName}". the following schemas are supported:
|
|
33
|
+
${schemasClasses.map((s) => s.name).join(', ')}`);
|
|
34
|
+
}
|
|
35
|
+
return schemaClass;
|
|
36
|
+
}
|
package/schemas/class.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
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 ClassSchema
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
name: this.className,
|
|
11
|
-
members: this.members.map((member) => member.toObject()),
|
|
12
|
-
};
|
|
6
|
+
export class ClassSchema extends SchemaNode {
|
|
7
|
+
@Transform(schemaObjArrayToInstances)
|
|
8
|
+
readonly members: SchemaNode[];
|
|
9
|
+
constructor(readonly className: string, members: SchemaNode[], readonly location: Location) {
|
|
10
|
+
super();
|
|
11
|
+
this.members = members;
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
toString() {
|
package/schemas/constructor.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { SchemaNode } from '../schema-node';
|
|
3
|
-
import {
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { ParameterSchema } from './parameter';
|
|
5
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
4
6
|
|
|
5
|
-
export class ConstructorSchema
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export class ConstructorSchema extends SchemaNode {
|
|
8
|
+
@Transform(schemaObjArrayToInstances)
|
|
9
|
+
readonly params: ParameterSchema[];
|
|
10
|
+
constructor(readonly location: Location, params: ParameterSchema[]) {
|
|
11
|
+
super();
|
|
12
|
+
this.params = params;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
args: this.args,
|
|
17
|
-
};
|
|
15
|
+
toString() {
|
|
16
|
+
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
17
|
+
return `${chalk.bold('constructor')}(${paramsStr})`;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjArrayToInstances, schemaObjToInstance } from '../schema-obj-to-class';
|
|
5
|
+
import { ParameterSchema } from './parameter';
|
|
6
|
+
|
|
7
|
+
export type Modifier = 'static' | 'public' | 'private' | 'protected' | 'readonly' | 'abstract' | 'async' | 'override';
|
|
8
|
+
|
|
9
|
+
export class FunctionLikeSchema extends SchemaNode {
|
|
10
|
+
@Transform(schemaObjToInstance)
|
|
11
|
+
readonly returnType: SchemaNode;
|
|
12
|
+
|
|
13
|
+
@Transform(schemaObjArrayToInstances)
|
|
14
|
+
readonly params: ParameterSchema[];
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
readonly location: Location,
|
|
18
|
+
readonly name: string,
|
|
19
|
+
// readonly doc: any,
|
|
20
|
+
params: ParameterSchema[],
|
|
21
|
+
|
|
22
|
+
returnType: SchemaNode,
|
|
23
|
+
readonly signature: string,
|
|
24
|
+
readonly modifiers: Modifier[] = []
|
|
25
|
+
) {
|
|
26
|
+
super();
|
|
27
|
+
this.params = params;
|
|
28
|
+
this.returnType = returnType;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getSignature() {
|
|
32
|
+
return this.signature;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
toString() {
|
|
36
|
+
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
37
|
+
const modifiersStr = this.modifiers.length ? `${this.modifiers.join(' ')} ` : '';
|
|
38
|
+
return `${modifiersStr}${chalk.bold(this.name)}(${paramsStr}): ${this.returnType.toString()}`;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/schemas/get-accessor.ts
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import { SchemaNode } from '../schema-node';
|
|
3
|
-
import {
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
4
|
+
import { schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
5
|
|
|
5
|
-
export class GetAccessorSchema
|
|
6
|
-
|
|
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
|
+
}
|
|
7
13
|
getSignature() {
|
|
8
14
|
return this.signature;
|
|
9
15
|
}
|
|
10
16
|
|
|
11
|
-
toObject() {
|
|
12
|
-
return {
|
|
13
|
-
constructorName: this.constructor.name,
|
|
14
|
-
name: this.name,
|
|
15
|
-
type: this.type.toObject(),
|
|
16
|
-
signature: this.signature,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
|
|
20
17
|
toString() {
|
|
21
18
|
return `get ${chalk.bold(this.name)}(): ${this.type.toString()}`;
|
|
22
19
|
}
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { ParameterSchema } from './parameter';
|
|
4
|
+
import { schemaObjArrayToInstances, schemaObjToInstance } from '../schema-obj-to-class';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* e.g. `{ [key: string]: boolean };`
|
|
7
8
|
* the "[key: string]" is the "parameter", and the "boolean" is the "type".
|
|
8
9
|
*/
|
|
9
|
-
export class IndexSignatureSchema
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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;
|
|
17
19
|
}
|
|
20
|
+
|
|
18
21
|
toString() {
|
|
19
|
-
const
|
|
20
|
-
return `[${
|
|
22
|
+
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
23
|
+
return `[${paramsStr}]: ${this.type.toString()}`;
|
|
21
24
|
}
|
|
22
25
|
}
|
package/schemas/index.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { Module } from './module';
|
|
2
|
-
export {
|
|
3
|
-
export { FunctionSchema, Parameter } from './function';
|
|
2
|
+
export { FunctionLikeSchema, Modifier } from './function-like';
|
|
4
3
|
export { TypeRefSchema } from './type-ref';
|
|
5
4
|
export { VariableSchema } from './variable';
|
|
6
5
|
export { ClassSchema } from './class';
|
|
@@ -13,3 +12,11 @@ export { IndexSignatureSchema } from './index-signature';
|
|
|
13
12
|
export { InterfaceSchema } from './interface';
|
|
14
13
|
export { GetAccessorSchema } from './get-accessor';
|
|
15
14
|
export { SetAccessorSchema } from './set-accessor';
|
|
15
|
+
export { TypeQuerySchema } from './type-query';
|
|
16
|
+
export { InferenceTypeSchema } from './inference-type';
|
|
17
|
+
export { LiteralTypeSchema } from './literal-type';
|
|
18
|
+
export { KeywordTypeSchema } from './keyword-type';
|
|
19
|
+
export { TypeArraySchema } from './type-array';
|
|
20
|
+
export { TypeOperatorSchema } from './type-operator';
|
|
21
|
+
export { TupleTypeSchema } from './tuple-type';
|
|
22
|
+
export { ParameterSchema } from './parameter';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* where there is no explicit type, the type is taken from the "quickinfo" of tsserver
|
|
5
|
+
*/
|
|
6
|
+
export class InferenceTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, readonly type: string) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toString() {
|
|
12
|
+
return this.type;
|
|
13
|
+
}
|
|
14
|
+
}
|
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}`;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* e.g. 'string', 'boolean', etc.
|
|
5
|
+
*/
|
|
6
|
+
export class KeywordTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, private name: string) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toString() {
|
|
12
|
+
return this.name;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* e.g. const a: 'a';
|
|
5
|
+
*/
|
|
6
|
+
export class LiteralTypeSchema extends SchemaNode {
|
|
7
|
+
constructor(readonly location: Location, readonly name: string) {
|
|
8
|
+
super();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
toObject() {
|
|
12
|
+
return {
|
|
13
|
+
constructorName: this.constructor.name,
|
|
14
|
+
name: this.name,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
toString() {
|
|
19
|
+
return this.name;
|
|
20
|
+
}
|
|
21
|
+
}
|
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() {
|
|
@@ -0,0 +1,22 @@
|
|
|
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 ParameterSchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
readonly type: SchemaNode;
|
|
8
|
+
constructor(
|
|
9
|
+
readonly location: Location,
|
|
10
|
+
readonly name: string,
|
|
11
|
+
type: SchemaNode,
|
|
12
|
+
readonly defaultValue?: any,
|
|
13
|
+
readonly description?: string
|
|
14
|
+
) {
|
|
15
|
+
super();
|
|
16
|
+
this.type = type;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
toString() {
|
|
20
|
+
return `${this.name}: ${this.type.toString()}`;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/schemas/set-accessor.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
1
2
|
import chalk from 'chalk';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
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
|
-
return `set ${chalk.bold(this.name)}(${this.param.
|
|
19
|
+
return `set ${chalk.bold(this.name)}(${this.param.toString()})`;
|
|
22
20
|
}
|
|
23
21
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Transform } from 'class-transformer';
|
|
2
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
3
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
4
|
+
|
|
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;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
toString() {
|
|
14
|
+
return `[${this.elements.map((elem) => elem.toString()).join(', ')}]`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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 TypeArraySchema extends SchemaNode {
|
|
6
|
+
@Transform(schemaObjToInstance)
|
|
7
|
+
readonly type: SchemaNode;
|
|
8
|
+
constructor(readonly location: Location, type: SchemaNode) {
|
|
9
|
+
super();
|
|
10
|
+
this.type = type;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
toString() {
|
|
14
|
+
return `${this.type.toString()}[]`;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -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
|
}
|