@teambit/semantics.entities.semantic-schema 0.0.10 → 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 +16 -29
- package/dist/api-schema.d.ts +6 -19
- package/dist/api-schema.js +20 -11
- 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 +2 -1
- 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/function-like.d.ts +5 -17
- package/dist/schemas/function-like.js +22 -18
- 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 +0 -1
- package/dist/schemas/index.js +1 -3
- package/dist/schemas/index.js.map +1 -1
- package/dist/schemas/inference-type.d.ts +5 -8
- package/dist/schemas/inference-type.js +5 -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/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-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 +4 -10
- package/dist/schemas/type-ref.js +5 -14
- 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 -14
- 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 +1 -2
- package/package-tar/teambit-semantics.entities.semantic-schema-0.0.11.tgz +0 -0
- package/package.json +6 -3
- package/{preview-1652757984397.js → preview-1652930732694.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/function-like.ts +17 -20
- package/schemas/get-accessor.ts +10 -12
- package/schemas/index-signature.ts +13 -9
- package/schemas/index.ts +0 -1
- package/schemas/inference-type.ts +4 -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/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-query.ts +10 -11
- package/schemas/type-ref.ts +12 -18
- package/schemas/type-union.ts +9 -8
- package/schemas/type.ts +10 -10
- package/schemas/variable.ts +9 -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/dist/schemas/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../schemas/type.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../schemas/type.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAA8C;AAC9C,kDAA0B;AAC1B,gDAAsD;AACtD,gEAA6D;AAE7D,MAAa,UAAW,SAAQ,wBAAU;IAGxC,YAAqB,QAAkB,EAAW,IAAY,EAAE,IAAgB,EAAW,SAAiB;QAC1G,KAAK,EAAE,CAAC;QADW,aAAQ,GAAR,QAAQ,CAAU;QAAW,SAAI,GAAJ,IAAI,CAAQ;QAA6B,cAAS,GAAT,SAAS,CAAQ;QAE1G,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;wCACL;AAF5B,gCAWC"}
|
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
import { SchemaNode } from '../schema-node';
|
|
2
|
-
export declare class VariableSchema
|
|
1
|
+
import { Location, SchemaNode } from '../schema-node';
|
|
2
|
+
export declare class VariableSchema extends SchemaNode {
|
|
3
|
+
readonly location: Location;
|
|
3
4
|
readonly name: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
constructor(name: string, signature: string, type: SchemaNode);
|
|
7
|
-
getSignature(): string;
|
|
8
|
-
toObject(): {
|
|
9
|
-
constructorName: string;
|
|
10
|
-
name: string;
|
|
11
|
-
signature: string;
|
|
12
|
-
type: Record<string, any> & {
|
|
13
|
-
constructorName: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
5
|
+
readonly signature: string;
|
|
6
|
+
type: SchemaNode;
|
|
7
|
+
constructor(location: Location, name: string, signature: string, type: SchemaNode);
|
|
16
8
|
toString(): string;
|
|
17
9
|
}
|
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
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
12
|
"chalk": "2.4.2",
|
|
13
|
-
"
|
|
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,13 +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
|
-
readonly
|
|
6
|
-
|
|
8
|
+
export abstract class SchemaNode {
|
|
9
|
+
readonly __schema = this.constructor.name;
|
|
10
|
+
abstract readonly location: Location;
|
|
11
|
+
readonly signature?: string;
|
|
7
12
|
|
|
8
|
-
toString(): string;
|
|
13
|
+
abstract toString(): string;
|
|
9
14
|
|
|
10
|
-
toObject()
|
|
15
|
+
toObject() {
|
|
16
|
+
return instanceToPlain(this);
|
|
17
|
+
}
|
|
11
18
|
}
|
|
12
19
|
|
|
13
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
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 { Location, SchemaNode } from '../schema-node';
|
|
3
4
|
import { ParameterSchema } from './parameter';
|
|
5
|
+
import { schemaObjArrayToInstances } from '../schema-obj-to-class';
|
|
4
6
|
|
|
5
|
-
export class ConstructorSchema
|
|
6
|
-
|
|
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;
|
|
13
|
+
}
|
|
7
14
|
|
|
8
15
|
toString() {
|
|
9
16
|
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
10
17
|
return `${chalk.bold('constructor')}(${paramsStr})`;
|
|
11
18
|
}
|
|
12
|
-
|
|
13
|
-
toObject() {
|
|
14
|
-
return {
|
|
15
|
-
constructorName: this.constructor.name,
|
|
16
|
-
args: this.params.map((arg) => arg.toObject()),
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
19
|
}
|
package/schemas/function-like.ts
CHANGED
|
@@ -1,40 +1,37 @@
|
|
|
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
7
|
export type Modifier = 'static' | 'public' | 'private' | 'protected' | 'readonly' | 'abstract' | 'async' | 'override';
|
|
6
8
|
|
|
7
|
-
export class FunctionLikeSchema
|
|
9
|
+
export class FunctionLikeSchema extends SchemaNode {
|
|
10
|
+
@Transform(schemaObjToInstance)
|
|
11
|
+
readonly returnType: SchemaNode;
|
|
12
|
+
|
|
13
|
+
@Transform(schemaObjArrayToInstances)
|
|
14
|
+
readonly params: ParameterSchema[];
|
|
15
|
+
|
|
8
16
|
constructor(
|
|
17
|
+
readonly location: Location,
|
|
9
18
|
readonly name: string,
|
|
10
19
|
// readonly doc: any,
|
|
11
|
-
|
|
20
|
+
params: ParameterSchema[],
|
|
12
21
|
|
|
13
|
-
|
|
22
|
+
returnType: SchemaNode,
|
|
14
23
|
readonly signature: string,
|
|
15
|
-
readonly location: Location,
|
|
16
24
|
readonly modifiers: Modifier[] = []
|
|
17
|
-
) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
) {
|
|
26
|
+
super();
|
|
27
|
+
this.params = params;
|
|
28
|
+
this.returnType = returnType;
|
|
29
|
+
}
|
|
22
30
|
|
|
23
31
|
getSignature() {
|
|
24
32
|
return this.signature;
|
|
25
33
|
}
|
|
26
34
|
|
|
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
35
|
toString() {
|
|
39
36
|
const paramsStr = this.params.map((param) => param.toString()).join(', ');
|
|
40
37
|
const modifiersStr = this.modifiers.length ? `${this.modifiers.join(' ')} ` : '';
|
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,16 +1,11 @@
|
|
|
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) {
|
|
8
|
+
super();
|
|
14
9
|
}
|
|
15
10
|
|
|
16
11
|
toString() {
|
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
|
}
|
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
|
}
|