@trapi/metadata 0.1.1 → 0.1.5
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/LICENSE +21 -0
- package/dist/cache/driver.js +1 -2
- package/dist/cache/driver.js.map +1 -1
- package/dist/cache/utils.d.ts.map +1 -1
- package/dist/cache/utils.js +12 -12
- package/dist/cache/utils.js.map +1 -1
- package/dist/decorator/mapper/index.js +1 -2
- package/dist/decorator/mapper/index.js.map +1 -1
- package/dist/decorator/representation/index.js +2 -4
- package/dist/decorator/representation/index.js.map +1 -1
- package/dist/decorator/representation/property/utils.js +4 -3
- package/dist/decorator/representation/property/utils.js.map +1 -1
- package/dist/generator/controller.js +1 -1
- package/dist/generator/controller.js.map +1 -1
- package/dist/generator/endpoint.js +0 -3
- package/dist/generator/endpoint.js.map +1 -1
- package/dist/generator/index.js +3 -9
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/method.js +0 -2
- package/dist/generator/method.js.map +1 -1
- package/dist/generator/parameter.js +1 -9
- package/dist/generator/parameter.js.map +1 -1
- package/dist/resolver/type-node.js +28 -61
- package/dist/resolver/type-node.js.map +1 -1
- package/dist/resolver/utils/initializer.d.ts.map +1 -1
- package/dist/resolver/utils/initializer.js +2 -1
- package/dist/resolver/utils/initializer.js.map +1 -1
- package/dist/resolver/utils/validator.js +2 -1
- package/dist/resolver/utils/validator.js.map +1 -1
- package/dist/utils/generator.js +1 -1
- package/dist/utils/generator.js.map +1 -1
- package/dist/utils/js-doc.js +1 -1
- package/dist/utils/js-doc.js.map +1 -1
- package/package.json +18 -12
- package/src/cache/driver.ts +0 -97
- package/src/cache/index.ts +0 -10
- package/src/cache/type.ts +0 -43
- package/src/cache/utils.ts +0 -51
- package/src/config/index.ts +0 -8
- package/src/config/path.ts +0 -29
- package/src/decorator/functions.ts +0 -142
- package/src/decorator/index.ts +0 -13
- package/src/decorator/mapper/index.ts +0 -153
- package/src/decorator/mapper/maps/decorators-express.ts +0 -117
- package/src/decorator/mapper/maps/internal.ts +0 -95
- package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
- package/src/decorator/mapper/utils.ts +0 -88
- package/src/decorator/representation/index.ts +0 -82
- package/src/decorator/representation/property/utils.ts +0 -146
- package/src/decorator/type.ts +0 -235
- package/src/decorator/utils/index.ts +0 -9
- package/src/decorator/utils/node.ts +0 -59
- package/src/decorator/utils/validator.ts +0 -104
- package/src/generator/controller.ts +0 -65
- package/src/generator/endpoint.ts +0 -212
- package/src/generator/index.ts +0 -219
- package/src/generator/method.ts +0 -198
- package/src/generator/parameter.ts +0 -392
- package/src/index.ts +0 -13
- package/src/resolver/error.ts +0 -38
- package/src/resolver/index.ts +0 -11
- package/src/resolver/type-node.ts +0 -1287
- package/src/resolver/type.ts +0 -257
- package/src/resolver/utils/index.ts +0 -9
- package/src/resolver/utils/initializer.ts +0 -81
- package/src/resolver/utils/validator.ts +0 -144
- package/src/type.ts +0 -185
- package/src/utils/generator.ts +0 -42
- package/src/utils/index.ts +0 -10
- package/src/utils/js-doc.ts +0 -125
- package/src/utils/validator.ts +0 -43
- package/test/data/library/@decorators-express/decorators.ts +0 -7
- package/test/data/library/self/api.ts +0 -37
- package/test/data/library/type.ts +0 -138
- package/test/data/library/typescript-rest/api.ts +0 -366
- package/test/data/library/typescript-rest/decorators/index.ts +0 -10
- package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
- package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
- package/test/data/library/typescript-rest/decorators/services.ts +0 -47
- package/test/data/library/typescript-rest/return-types.ts +0 -94
- package/test/data/library/utils.ts +0 -7
- package/test/jest.config.js +0 -49
- package/test/unit/cache.spec.ts +0 -48
- package/test/unit/decorator/mapper/index.spec.ts +0 -83
- package/test/unit/decorator/representation/index.spec.ts +0 -102
- package/test/unit/decorator/utils/node.spec.ts +0 -47
- package/test/unit/library/typescript-rest.spec.ts +0 -342
- package/test/unit/resolver/type.spec.ts +0 -134
- package/test/unit/utils/generator.spec.ts +0 -41
- package/test/unit/utils/js-doc.spec.ts +0 -95
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -9
- package/writable/.gitignore +0 -3
package/src/utils/generator.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {CompilerOptions} from 'typescript';
|
|
9
|
-
import {Config, GeneratorOutput} from "../type";
|
|
10
|
-
import {MetadataGenerator} from "../generator";
|
|
11
|
-
import {getCompilerOptions} from "@trapi/metadata-utils";
|
|
12
|
-
|
|
13
|
-
export function createMetadataGenerator(
|
|
14
|
-
config: Config,
|
|
15
|
-
compilerOptions?: CompilerOptions | boolean
|
|
16
|
-
): MetadataGenerator {
|
|
17
|
-
const skipLoad: boolean =
|
|
18
|
-
(typeof compilerOptions === 'boolean' && !compilerOptions) ||
|
|
19
|
-
(typeof compilerOptions !== 'boolean' && typeof compilerOptions !== 'undefined');
|
|
20
|
-
|
|
21
|
-
let tscConfig: CompilerOptions = typeof compilerOptions !== 'boolean' && typeof compilerOptions !== 'undefined' ? compilerOptions : {};
|
|
22
|
-
|
|
23
|
-
if (!skipLoad) {
|
|
24
|
-
try {
|
|
25
|
-
tscConfig ??= getCompilerOptions();
|
|
26
|
-
} catch (e) {
|
|
27
|
-
/* istanbul ignore next */
|
|
28
|
-
tscConfig = {};
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return new MetadataGenerator(config, tscConfig);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function generateMetadata(
|
|
36
|
-
config: Config,
|
|
37
|
-
compilerOptions?: CompilerOptions | boolean
|
|
38
|
-
) : GeneratorOutput {
|
|
39
|
-
const generator = createMetadataGenerator(config, compilerOptions);
|
|
40
|
-
|
|
41
|
-
return generator.generate();
|
|
42
|
-
}
|
package/src/utils/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export * from './generator';
|
|
9
|
-
export * from './js-doc';
|
|
10
|
-
export * from './validator';
|
package/src/utils/js-doc.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {Identifier, isJSDocParameterTag, JSDoc, JSDocTag, Node, SyntaxKind} from 'typescript';
|
|
9
|
-
import {hasOwnProperty} from "@trapi/metadata-utils";
|
|
10
|
-
import {ResolverError} from "../resolver";
|
|
11
|
-
|
|
12
|
-
// -----------------------------------------
|
|
13
|
-
// Description
|
|
14
|
-
// -----------------------------------------
|
|
15
|
-
export function getJSDocDescription(node: Node) : string | undefined {
|
|
16
|
-
if(!hasOwnProperty(node, 'jsDoc')) {
|
|
17
|
-
return undefined;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const jsDocs = ((node as any).jsDoc as JSDoc[])
|
|
21
|
-
.filter(jsDoc => typeof jsDoc.comment === 'string');
|
|
22
|
-
|
|
23
|
-
if (jsDocs.length === 0) {
|
|
24
|
-
return undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return Array.isArray(jsDocs[0].comment) ? (jsDocs[0].comment.length === 0 ? undefined : jsDocs[0].comment[0]) : jsDocs[0].comment;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// -----------------------------------------
|
|
32
|
-
// Tag
|
|
33
|
-
// -----------------------------------------
|
|
34
|
-
|
|
35
|
-
export function getJSDoc(node: Node, index?: number) : undefined | JSDoc {
|
|
36
|
-
if(!hasOwnProperty(node, 'jsDoc')) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const jsDoc : JSDoc[] | undefined = (node as any).jsDoc as JSDoc[];
|
|
41
|
-
|
|
42
|
-
if(!jsDoc || !Array.isArray(jsDoc) || !jsDoc.length) {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
index = index ?? 0;
|
|
47
|
-
return jsDoc.length > index && index >= 0 ? jsDoc[index] : undefined; // jsDoc[0] else case
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function getJSDocTags(
|
|
51
|
-
node: Node,
|
|
52
|
-
isMatching?: string | string[] | ((tag: JSDocTag) => boolean)
|
|
53
|
-
) : JSDocTag[] {
|
|
54
|
-
const jsDoc : JSDoc = getJSDoc(node);
|
|
55
|
-
if(typeof jsDoc === 'undefined') {
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const jsDocTags : JSDocTag[] = jsDoc.tags as unknown as JSDocTag[];
|
|
60
|
-
|
|
61
|
-
if(typeof jsDocTags === 'undefined') {
|
|
62
|
-
return [];
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if(typeof isMatching === 'undefined') {
|
|
66
|
-
return jsDocTags;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if(typeof isMatching === 'function') {
|
|
70
|
-
return jsDocTags.filter(isMatching);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const tagNames : string[] = Array.isArray(isMatching) ? isMatching : [isMatching];
|
|
74
|
-
|
|
75
|
-
return jsDocTags.filter(tag => tagNames.indexOf(tag.tagName.text) !== -1);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export function isExistJSDocTag(node: Node, tagName: ((tag: JSDocTag) => boolean) | string) : boolean {
|
|
79
|
-
const tags : JSDocTag[] = getJSDocTags(node, tagName);
|
|
80
|
-
|
|
81
|
-
return !(!tags || !tags.length);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// -----------------------------------------
|
|
86
|
-
// Tag Comment(s)
|
|
87
|
-
// -----------------------------------------
|
|
88
|
-
|
|
89
|
-
export function getJSDocTagComment(node: Node, tagName: ((tag: JSDocTag) => boolean) | string) : undefined | string {
|
|
90
|
-
const tags : JSDocTag[] = getJSDocTags(node, tagName);
|
|
91
|
-
|
|
92
|
-
if (!tags || !tags.length || typeof tags[0].comment !== 'string') {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
return tags[0].comment;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// -----------------------------------------
|
|
99
|
-
// Tag Names
|
|
100
|
-
// -----------------------------------------
|
|
101
|
-
|
|
102
|
-
export function getJSDocTagNames(node: Node, requireTagName = false) : string[] {
|
|
103
|
-
let tags: JSDocTag[];
|
|
104
|
-
|
|
105
|
-
/* istanbul ignore next */
|
|
106
|
-
if (node.kind === SyntaxKind.Parameter) {
|
|
107
|
-
const parameterName = ((node as any).name as Identifier).text;
|
|
108
|
-
tags = getJSDocTags(node.parent as any, tag => {
|
|
109
|
-
if (isJSDocParameterTag(tag)) {
|
|
110
|
-
return false;
|
|
111
|
-
} else if (tag.comment === undefined) {
|
|
112
|
-
throw new ResolverError(`Orphan tag: @${String(tag.tagName.text || tag.tagName.escapedText)} should have a parameter name follows with.`);
|
|
113
|
-
}
|
|
114
|
-
return typeof tag.comment === 'string' ? tag.comment.startsWith(parameterName) : false;
|
|
115
|
-
});
|
|
116
|
-
} else {
|
|
117
|
-
tags = getJSDocTags(node as any, tag => {
|
|
118
|
-
return requireTagName ? tag.comment !== undefined : true;
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return tags.map(tag => {
|
|
123
|
-
return tag.tagName.text;
|
|
124
|
-
});
|
|
125
|
-
}
|
package/src/utils/validator.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {array, boolean, lazy, mixed, object, SchemaOf, string} from "yup";
|
|
9
|
-
import {Config} from "../type";
|
|
10
|
-
import {useDecoratorConfigValidator} from "../decorator/utils/validator";
|
|
11
|
-
|
|
12
|
-
let validatorInstance : undefined | SchemaOf<Config>;
|
|
13
|
-
|
|
14
|
-
export function useConfigValidator() : SchemaOf<Config> {
|
|
15
|
-
if(typeof validatorInstance !== 'undefined') {
|
|
16
|
-
return validatorInstance;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
validatorInstance = object({
|
|
20
|
-
entryFile: lazy(value => {
|
|
21
|
-
if(typeof value === 'string') {
|
|
22
|
-
return string().required();
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return array().of(string()).required().min(1);
|
|
26
|
-
}),
|
|
27
|
-
cache: lazy(value => {
|
|
28
|
-
if(typeof value === 'string') {
|
|
29
|
-
return string();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if(typeof value === 'boolean') {
|
|
33
|
-
return boolean();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return mixed().optional().default(undefined);
|
|
37
|
-
}),
|
|
38
|
-
ignore: array(string()).optional().default(undefined),
|
|
39
|
-
decorator: useDecoratorConfigValidator(),
|
|
40
|
-
}) as unknown as SchemaOf<Config>;
|
|
41
|
-
|
|
42
|
-
return validatorInstance;
|
|
43
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import {GET, Path, POST} from "../typescript-rest/decorators";
|
|
9
|
-
import {RequestConsumes, ResponseDescription, ResponseExample, ResponseProduces, SwaggerTags} from "../../../../src";
|
|
10
|
-
import {Person} from "../type";
|
|
11
|
-
|
|
12
|
-
@Path('mypath')
|
|
13
|
-
@SwaggerTags('My Services')
|
|
14
|
-
export class MyService {
|
|
15
|
-
@ResponseDescription<string>('default', 'Error')
|
|
16
|
-
@ResponseDescription<string>(400, 'The request format was incorrect.')
|
|
17
|
-
@ResponseDescription<string>(500, 'There was an unexpected error.')
|
|
18
|
-
@GET
|
|
19
|
-
public test(): string {
|
|
20
|
-
return 'OK';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* a a
|
|
25
|
-
*
|
|
26
|
-
* @param body
|
|
27
|
-
*/
|
|
28
|
-
@POST
|
|
29
|
-
@ResponseExample<Person[]>([{
|
|
30
|
-
name: 'Joe'
|
|
31
|
-
}])
|
|
32
|
-
@RequestConsumes('application/json', 'text/html')
|
|
33
|
-
@ResponseProduces('application/json')
|
|
34
|
-
public testPostString(body: string): Person[] {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2021.
|
|
3
|
-
* Author Peter Placzek (tada5hi)
|
|
4
|
-
* For the full copyright and license information,
|
|
5
|
-
* view the LICENSE file that was distributed with this source code.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import * as swagger from "../../../src/decorator";
|
|
9
|
-
|
|
10
|
-
export interface TestInterface {
|
|
11
|
-
a: string;
|
|
12
|
-
b: number;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface MyTypeWithUnion {
|
|
16
|
-
property: 'value1' | 'value2';
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface Address {
|
|
20
|
-
street: string;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Person {
|
|
24
|
-
name: string;
|
|
25
|
-
address?: Address;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export enum TestEnum {
|
|
29
|
-
Option1 = 'option1',
|
|
30
|
-
Option2 = 'option2'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export enum TestNumericEnum {
|
|
34
|
-
Option1,
|
|
35
|
-
Option2,
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export enum TestMixedEnum {
|
|
39
|
-
Option1,
|
|
40
|
-
Option2 = 'option2',
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export interface BasicModel2<T> {
|
|
44
|
-
prop: T;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface MyDataType2 extends BasicModel2<string> {
|
|
48
|
-
property1: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type SimpleHelloType = {
|
|
52
|
-
/**
|
|
53
|
-
* Description for greeting property
|
|
54
|
-
*/
|
|
55
|
-
greeting: string;
|
|
56
|
-
|
|
57
|
-
arrayOfSomething: Something[];
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Description for profile
|
|
61
|
-
*/
|
|
62
|
-
profile: {
|
|
63
|
-
/**
|
|
64
|
-
* Description for profile name
|
|
65
|
-
*/
|
|
66
|
-
name: string
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
comparePassword: (candidatePassword: string, cb: (err: any, isMatch: any) => {}) => void;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
export class BasicModel {
|
|
73
|
-
public id: number;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export interface Something {
|
|
77
|
-
id: UUID;
|
|
78
|
-
someone: string;
|
|
79
|
-
kind: string;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type UUID = string;
|
|
83
|
-
|
|
84
|
-
export interface ResponseBody<T> {
|
|
85
|
-
data: T;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export class PrimitiveClassModel {
|
|
89
|
-
/**
|
|
90
|
-
* An integer
|
|
91
|
-
*/
|
|
92
|
-
@swagger.IsInt
|
|
93
|
-
public int?: number;
|
|
94
|
-
|
|
95
|
-
@swagger.IsLong
|
|
96
|
-
public long?: number;
|
|
97
|
-
|
|
98
|
-
@swagger.IsFloat
|
|
99
|
-
public float?: number;
|
|
100
|
-
|
|
101
|
-
@swagger.IsDouble
|
|
102
|
-
public double?: number;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
export interface PrimitiveInterfaceModel {
|
|
106
|
-
/**
|
|
107
|
-
* An integer
|
|
108
|
-
* @IsInt
|
|
109
|
-
*/
|
|
110
|
-
int?: number;
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @IsLong
|
|
114
|
-
*/
|
|
115
|
-
long?: number;
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @IsFloat
|
|
119
|
-
*/
|
|
120
|
-
float?: number;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @IsDouble
|
|
124
|
-
*/
|
|
125
|
-
double?: number;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export abstract class Entity {
|
|
129
|
-
/**
|
|
130
|
-
* A numeric identifier
|
|
131
|
-
*/
|
|
132
|
-
public id?: number;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
export class NamedEntity implements Entity {
|
|
136
|
-
public id: number;
|
|
137
|
-
public name: string;
|
|
138
|
-
}
|