@trapi/metadata 0.1.3 → 0.1.7
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/dist/cache/driver.d.ts +1 -1
- package/dist/cache/driver.d.ts.map +1 -1
- package/dist/cache/driver.js +3 -6
- package/dist/cache/driver.js.map +1 -1
- package/dist/cache/type.d.ts +1 -1
- package/dist/cache/type.d.ts.map +1 -1
- package/dist/cache/utils.d.ts +1 -1
- package/dist/cache/utils.d.ts.map +1 -1
- package/dist/cache/utils.js +14 -14
- package/dist/cache/utils.js.map +1 -1
- package/dist/config/path.js.map +1 -1
- package/dist/decorator/functions.d.ts.map +1 -1
- package/dist/decorator/functions.js +9 -13
- package/dist/decorator/functions.js.map +1 -1
- package/dist/decorator/index.d.ts +1 -1
- package/dist/decorator/index.d.ts.map +1 -1
- package/dist/decorator/index.js +1 -3
- package/dist/decorator/index.js.map +1 -1
- package/dist/decorator/mapper/index.d.ts +3 -3
- package/dist/decorator/mapper/index.d.ts.map +1 -1
- package/dist/decorator/mapper/index.js +6 -11
- package/dist/decorator/mapper/index.js.map +1 -1
- package/dist/decorator/mapper/maps/decorators-express.d.ts +1 -1
- package/dist/decorator/mapper/maps/decorators-express.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/decorators-express.js +33 -33
- package/dist/decorator/mapper/maps/internal.d.ts +1 -1
- package/dist/decorator/mapper/maps/internal.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/internal.js +31 -27
- package/dist/decorator/mapper/maps/internal.js.map +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.d.ts +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.js +38 -38
- package/dist/decorator/mapper/maps/typescript-rest.js.map +1 -1
- package/dist/decorator/mapper/utils.d.ts +1 -1
- package/dist/decorator/mapper/utils.d.ts.map +1 -1
- package/dist/decorator/mapper/utils.js +1 -1
- package/dist/decorator/mapper/utils.js.map +1 -1
- package/dist/decorator/representation/index.d.ts +1 -1
- package/dist/decorator/representation/index.d.ts.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.d.ts +1 -1
- package/dist/decorator/representation/property/utils.d.ts.map +1 -1
- package/dist/decorator/representation/property/utils.js +7 -6
- package/dist/decorator/representation/property/utils.js.map +1 -1
- package/dist/decorator/type.d.ts.map +1 -1
- package/dist/decorator/utils/node.d.ts +1 -1
- package/dist/decorator/utils/node.d.ts.map +1 -1
- package/dist/decorator/utils/node.js +4 -6
- package/dist/decorator/utils/node.js.map +1 -1
- package/dist/decorator/utils/validator.d.ts +2 -2
- package/dist/decorator/utils/validator.d.ts.map +1 -1
- package/dist/decorator/utils/validator.js +8 -8
- package/dist/decorator/utils/validator.js.map +1 -1
- package/dist/generator/controller.d.ts +1 -1
- package/dist/generator/controller.d.ts.map +1 -1
- package/dist/generator/controller.js +1 -1
- package/dist/generator/controller.js.map +1 -1
- package/dist/generator/endpoint.d.ts +2 -2
- package/dist/generator/endpoint.d.ts.map +1 -1
- package/dist/generator/endpoint.js +14 -19
- package/dist/generator/endpoint.js.map +1 -1
- package/dist/generator/index.d.ts +5 -33
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +15 -151
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/method.d.ts +1 -1
- package/dist/generator/method.d.ts.map +1 -1
- package/dist/generator/method.js +10 -12
- package/dist/generator/method.js.map +1 -1
- package/dist/generator/module.d.ts +41 -0
- package/dist/generator/module.d.ts.map +1 -0
- package/dist/generator/module.js +166 -0
- package/dist/generator/module.js.map +1 -0
- package/dist/generator/parameter.d.ts +1 -1
- package/dist/generator/parameter.d.ts.map +1 -1
- package/dist/generator/parameter.js +26 -35
- package/dist/generator/parameter.js.map +1 -1
- package/dist/resolver/type-node.d.ts +1 -1
- package/dist/resolver/type-node.d.ts.map +1 -1
- package/dist/resolver/type-node.js +124 -189
- package/dist/resolver/type-node.js.map +1 -1
- package/dist/resolver/type.d.ts +1 -1
- package/dist/resolver/type.d.ts.map +1 -1
- package/dist/resolver/utils/initializer.d.ts +1 -1
- package/dist/resolver/utils/initializer.d.ts.map +1 -1
- package/dist/resolver/utils/initializer.js +11 -12
- package/dist/resolver/utils/initializer.js.map +1 -1
- package/dist/resolver/utils/validator.d.ts +1 -1
- package/dist/resolver/utils/validator.d.ts.map +1 -1
- package/dist/resolver/utils/validator.js +8 -11
- package/dist/resolver/utils/validator.js.map +1 -1
- package/dist/type.d.ts +8 -3
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/generator.d.ts +2 -2
- package/dist/utils/generator.d.ts.map +1 -1
- package/dist/utils/generator.js +2 -2
- package/dist/utils/generator.js.map +1 -1
- package/dist/utils/js-doc.d.ts.map +1 -1
- package/dist/utils/js-doc.js +7 -11
- package/dist/utils/js-doc.js.map +1 -1
- package/dist/utils/validator.d.ts +2 -2
- package/dist/utils/validator.d.ts.map +1 -1
- package/dist/utils/validator.js +2 -2
- package/dist/utils/validator.js.map +1 -1
- package/package.json +19 -13
- 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 -49
- 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 -104
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -9
- package/writable/.gitignore +0 -3
package/package.json
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trapi/metadata",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Generate REST-API metadata scheme from TypeScript Decorators.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"typings": "./dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/"
|
|
9
|
+
],
|
|
7
10
|
"scripts": {
|
|
8
11
|
"start": "tsc -p tsconfig.build.json -w",
|
|
9
12
|
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
10
13
|
"clean": "rimraf dist && rimraf tsconfig.tsbuildinfo",
|
|
11
14
|
"test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
|
|
12
|
-
"test:coverage": "
|
|
15
|
+
"test:coverage": "npm run test -- --coverage",
|
|
13
16
|
"preblushOnly": "npm run build"
|
|
14
17
|
},
|
|
15
18
|
"keywords": [
|
|
@@ -22,26 +25,29 @@
|
|
|
22
25
|
],
|
|
23
26
|
"author": {
|
|
24
27
|
"name": "Peter Placzek",
|
|
25
|
-
"email": "
|
|
26
|
-
"url": "https
|
|
28
|
+
"email": "contact@tada5hi.net",
|
|
29
|
+
"url": "https://github.com/tada5hi"
|
|
27
30
|
},
|
|
28
31
|
"license": "MIT",
|
|
29
32
|
"devDependencies": {
|
|
30
|
-
"@types/glob": "^7.
|
|
31
|
-
"@types/jest": "^27.0
|
|
33
|
+
"@types/glob": "^7.2.0",
|
|
34
|
+
"@types/jest": "^27.4.0",
|
|
32
35
|
"@types/minimatch": "^3.0.5",
|
|
33
|
-
"@types/node": "^
|
|
36
|
+
"@types/node": "^17.0.14",
|
|
34
37
|
"@types/yup": "^0.29.13",
|
|
35
|
-
"jest": "^27.
|
|
38
|
+
"jest": "^27.4.7",
|
|
36
39
|
"jsonata": "^1.8.5",
|
|
37
40
|
"rimraf": "^3.0.2"
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@trapi/metadata-utils": "^0.0.
|
|
41
|
-
"glob": "^7.
|
|
43
|
+
"@trapi/metadata-utils": "^0.0.5",
|
|
44
|
+
"glob": "^7.2.0",
|
|
42
45
|
"minimatch": "^3.0.4",
|
|
43
|
-
"typescript": "^4.
|
|
44
|
-
"yup": "^0.32.
|
|
46
|
+
"typescript": "^4.5.5",
|
|
47
|
+
"yup": "^0.32.11"
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
45
51
|
},
|
|
46
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "f8ebabe5794093769ba5bf9fa4542544c06a0179"
|
|
47
53
|
}
|
package/src/cache/driver.ts
DELETED
|
@@ -1,97 +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 {Cache} from "./type";
|
|
9
|
-
import {buildCacheConfig, buildFileHash} from "./utils";
|
|
10
|
-
import fs from "fs";
|
|
11
|
-
import * as glob from "glob";
|
|
12
|
-
import path from "path";
|
|
13
|
-
|
|
14
|
-
export class CacheDriver {
|
|
15
|
-
private readonly config: Cache.Config;
|
|
16
|
-
|
|
17
|
-
constructor(config: string | boolean | Partial<Cache.Config>) {
|
|
18
|
-
this.config = buildCacheConfig(config);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// -------------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
public save(data: Cache.Data): string | undefined {
|
|
24
|
-
if (!this.config.enabled) {
|
|
25
|
-
return undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const filePath: string = this.buildFilePath(undefined, data.sourceFilesSize);
|
|
29
|
-
|
|
30
|
-
fs.writeFileSync(filePath, JSON.stringify(data));
|
|
31
|
-
|
|
32
|
-
return filePath;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public get(sourceFilesSize: number): Cache.Data | undefined {
|
|
36
|
-
if (!this.config.enabled) {
|
|
37
|
-
return undefined;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
this.clear();
|
|
41
|
-
|
|
42
|
-
const filePath: string = this.buildFilePath(undefined, sourceFilesSize);
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
const buffer: Buffer = fs.readFileSync(filePath);
|
|
46
|
-
|
|
47
|
-
const content: string = buffer.toString('utf-8');
|
|
48
|
-
|
|
49
|
-
// todo: maybe add shape validation here :)
|
|
50
|
-
const cache: Cache.Data | undefined = JSON.parse(content) as Cache.Data;
|
|
51
|
-
|
|
52
|
-
if (typeof cache === 'undefined' || cache.sourceFilesSize !== sourceFilesSize) {
|
|
53
|
-
return undefined;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return cache;
|
|
57
|
-
} catch (e) {
|
|
58
|
-
/* istanbul ignore next */
|
|
59
|
-
return undefined;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// -------------------------------------------------------------------------
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* At a 10% chance, clear all cache files :)
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
/* istanbul ignore next */
|
|
70
|
-
public clear(): void {
|
|
71
|
-
if (!this.config.enabled || !this.config.clearAtRandom) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const rand: number = Math.floor(Math.random() * 100) + 1;
|
|
76
|
-
if (rand > 10) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const files: string[] = glob.sync(this.buildFilePath('**'));
|
|
81
|
-
files.map(file => fs.unlinkSync(file));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// -------------------------------------------------------------------------
|
|
85
|
-
|
|
86
|
-
private buildFilePath(hash?: string, sourceFilesSize?: number): string {
|
|
87
|
-
return path.join(this.config.directoryPath, this.buildFileName(hash, sourceFilesSize));
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
private buildFileName(hash?: string, sourceFilesSize?: number): string {
|
|
91
|
-
if (typeof this.config.fileName === 'string') {
|
|
92
|
-
return this.config.fileName;
|
|
93
|
-
} else {
|
|
94
|
-
return `.swagger-${hash ?? buildFileHash(sourceFilesSize)}.json`;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
package/src/cache/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 './driver';
|
|
9
|
-
export * from './type';
|
|
10
|
-
export * from './utils';
|
package/src/cache/type.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 {GeneratorOutput} from "../type";
|
|
9
|
-
|
|
10
|
-
export namespace Cache {
|
|
11
|
-
export interface Config {
|
|
12
|
-
/**
|
|
13
|
-
* Specify if the cache driver should be enabled.
|
|
14
|
-
*
|
|
15
|
-
* Default: false
|
|
16
|
-
* */
|
|
17
|
-
enabled: boolean,
|
|
18
|
-
/**
|
|
19
|
-
* Directory relative or absolute path.
|
|
20
|
-
*
|
|
21
|
-
* Default: process.cwd()
|
|
22
|
-
*/
|
|
23
|
-
directoryPath: string,
|
|
24
|
-
/**
|
|
25
|
-
* Specify the cache file name.
|
|
26
|
-
*
|
|
27
|
-
* Default: metadata-{hash}.json
|
|
28
|
-
*/
|
|
29
|
-
fileName?: string,
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The cache file(s) will be cleared at a 10% percent change
|
|
33
|
-
* each time.
|
|
34
|
-
*
|
|
35
|
-
* Default: true
|
|
36
|
-
*/
|
|
37
|
-
clearAtRandom: boolean
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export type Data = {
|
|
41
|
-
sourceFilesSize: number;
|
|
42
|
-
} & GeneratorOutput;
|
|
43
|
-
}
|
package/src/cache/utils.ts
DELETED
|
@@ -1,49 +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 {Cache} from "./type";
|
|
9
|
-
import path from "path";
|
|
10
|
-
import crypto from "crypto";
|
|
11
|
-
|
|
12
|
-
export function buildCacheConfig(config?: string | boolean | Partial<Cache.Config>) : Cache.Config {
|
|
13
|
-
if(typeof config === 'string') {
|
|
14
|
-
config = {
|
|
15
|
-
enabled: true,
|
|
16
|
-
directoryPath: config
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if(typeof config === 'boolean') {
|
|
21
|
-
config = {
|
|
22
|
-
enabled: config
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
config ??= {};
|
|
27
|
-
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
const isTestEnvironment : boolean = !!process.env.NODE_ENV && process.env.NODE_ENV === 'test';
|
|
30
|
-
|
|
31
|
-
return {
|
|
32
|
-
fileName: config.fileName,
|
|
33
|
-
directoryPath: typeof config.directoryPath === 'string' ?
|
|
34
|
-
path.isAbsolute(config.directoryPath) ? config.directoryPath : path.join(process.cwd(), config.directoryPath) :
|
|
35
|
-
process.cwd(),
|
|
36
|
-
enabled: config.enabled ?? false,
|
|
37
|
-
clearAtRandom: config.clearAtRandom ?? !isTestEnvironment
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function buildFileHash(sourceFilesSize?: number): string {
|
|
42
|
-
const hash = crypto.createHash('sha256');
|
|
43
|
-
|
|
44
|
-
const strSize: string = (sourceFilesSize ?? 0).toString();
|
|
45
|
-
|
|
46
|
-
hash.update(strSize);
|
|
47
|
-
|
|
48
|
-
return hash.digest('hex');
|
|
49
|
-
}
|
package/src/config/index.ts
DELETED
package/src/config/path.ts
DELETED
|
@@ -1,29 +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 path from "path";
|
|
9
|
-
|
|
10
|
-
let writableDirPath : string | undefined;
|
|
11
|
-
let rootDirPath : string | undefined;
|
|
12
|
-
|
|
13
|
-
export function getWritableDirPath() {
|
|
14
|
-
if(typeof writableDirPath !== 'undefined') {
|
|
15
|
-
return writableDirPath;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
writableDirPath = path.join(getRootDirPath(), './writable');
|
|
19
|
-
return writableDirPath;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getRootDirPath() {
|
|
23
|
-
if(typeof rootDirPath !== 'undefined') {
|
|
24
|
-
return rootDirPath;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
rootDirPath = path.resolve(__dirname, '../../');
|
|
28
|
-
return rootDirPath;
|
|
29
|
-
}
|
|
@@ -1,142 +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
|
-
'use strict';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Document the method or class comsumes property in generated swagger docs
|
|
12
|
-
*/
|
|
13
|
-
export function RequestConsumes(...values: Array<string | string[]>): any {
|
|
14
|
-
return () => { return; };
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param key
|
|
22
|
-
* @constructor
|
|
23
|
-
*/
|
|
24
|
-
export function RequestFileParam(key: string) : any {
|
|
25
|
-
return () => { return; };
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* A decorator to document the responses that a given service method can return. It is used to generate
|
|
30
|
-
* documentation for the REST service.
|
|
31
|
-
* ```typescript
|
|
32
|
-
* interface MyError {
|
|
33
|
-
* message: string
|
|
34
|
-
* }
|
|
35
|
-
* @ Path('people')
|
|
36
|
-
* class PeopleService {
|
|
37
|
-
* @ ResponseDescription<string>(200, 'Retrieve a list of people.')
|
|
38
|
-
* @ ResponseDescription<MyError>(401, 'The user is unauthorized.', {message: 'The user is not authorized to access this operation.'})
|
|
39
|
-
* @ GET
|
|
40
|
-
* getPeople(@ Param('name') name: string) {
|
|
41
|
-
* // ...
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* ```
|
|
45
|
-
* A Default response is created in swagger documentation from the method return analisys. So any response declared
|
|
46
|
-
* through this decorator is an additional response created.
|
|
47
|
-
* @param name
|
|
48
|
-
* @param description A description for this response
|
|
49
|
-
* @param example An optional example of response to be added to method documentation.
|
|
50
|
-
*/
|
|
51
|
-
export function ResponseDescription<T>(name: string | number, description?: string, example?: T): any {
|
|
52
|
-
return () => { return; };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Used to provide an example of method return to be added into the method response section of the
|
|
57
|
-
* generated documentation for this method.
|
|
58
|
-
* ```typescript
|
|
59
|
-
* @ Path('people')
|
|
60
|
-
* class PeopleService {
|
|
61
|
-
* @ ResponseExample<Array<Person>>([{
|
|
62
|
-
* name: 'Joe'
|
|
63
|
-
* }])
|
|
64
|
-
* @ GET
|
|
65
|
-
* getPeople(@ Param('name') name: string): Person[] {
|
|
66
|
-
* // ...
|
|
67
|
-
* }
|
|
68
|
-
* }
|
|
69
|
-
* ```
|
|
70
|
-
* @param example The example returned object
|
|
71
|
-
*/
|
|
72
|
-
export function ResponseExample<T>(example: T): any {
|
|
73
|
-
return () => { return; };
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Document the method or class produces property in generated swagger docs
|
|
78
|
-
*/
|
|
79
|
-
export function ResponseProduces(...values: string[]): any {
|
|
80
|
-
return () => { return; };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Add tags for a given method on generated swagger documentation.
|
|
85
|
-
* ```typescript
|
|
86
|
-
* @ Path('people')
|
|
87
|
-
* class PeopleService {
|
|
88
|
-
* @ SwaggerTags('adiministrative', 'department1')
|
|
89
|
-
* @ GET
|
|
90
|
-
* getPeople(@ Param('name') name: string) {
|
|
91
|
-
* // ...
|
|
92
|
-
* }
|
|
93
|
-
* }
|
|
94
|
-
* ```
|
|
95
|
-
* @param values a list of tags
|
|
96
|
-
*/
|
|
97
|
-
export function SwaggerTags(...values: string[]): any {
|
|
98
|
-
return () => { return; };
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Document the method or class produces property in generated swagger docs.
|
|
103
|
-
*/
|
|
104
|
-
export function SwaggerHidden(): any {
|
|
105
|
-
return () => { return; };
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Document the method or collection of method paths are deprecated and should not be used.
|
|
110
|
-
*/
|
|
111
|
-
export function SwaggerDeprecated() : any {
|
|
112
|
-
return () => { return; };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Document the type of a property or parameter as `integer ($int32)` in generated swagger docs
|
|
117
|
-
*/
|
|
118
|
-
export function IsInt(target: any, propertyKey: string, parameterIndex?: number) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Document the type of a property or parameter as `integer ($int64)` in generated swagger docs
|
|
124
|
-
*/
|
|
125
|
-
export function IsLong(target: any, propertyKey: string, parameterIndex?: number) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Document the type of a property or parameter as `number ($float)` in generated swagger docs
|
|
131
|
-
*/
|
|
132
|
-
export function IsFloat(target: any, propertyKey: string, parameterIndex?: number) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Document the type of a property or parameter as `number ($double)` in generated swagger docs.
|
|
138
|
-
* This is the default for `number` types without a specifying decorator.
|
|
139
|
-
*/
|
|
140
|
-
export function IsDouble(target: any, propertyKey: string, parameterIndex?: number) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
package/src/decorator/index.ts
DELETED
|
@@ -1,13 +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 './mapper';
|
|
9
|
-
export * from './representation';
|
|
10
|
-
export * from './utils';
|
|
11
|
-
export * from './functions';
|
|
12
|
-
export * from './type';
|
|
13
|
-
export {getNodeDecorators} from "./utils/node";
|
|
@@ -1,153 +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 {Node} from "typescript";
|
|
9
|
-
import {hasOwnProperty} from "@trapi/metadata-utils";
|
|
10
|
-
import {RepresentationManager} from "../representation";
|
|
11
|
-
import {Decorator} from "../type";
|
|
12
|
-
import {getDecoratorMap, isMappingTypeIncluded, reduceTypeRepresentationMapping} from "./utils";
|
|
13
|
-
import {getNodeDecorators} from "../utils";
|
|
14
|
-
|
|
15
|
-
export class DecoratorMapper {
|
|
16
|
-
protected mapping : Partial<Decorator.TypeRepresentationMap> = {};
|
|
17
|
-
|
|
18
|
-
constructor(
|
|
19
|
-
protected config?: Decorator.Config
|
|
20
|
-
) {
|
|
21
|
-
this.aggregate();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
public setConfig(config?: Decorator.Config) {
|
|
25
|
-
this.config = config;
|
|
26
|
-
this.aggregate();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Try to find a matching representation for a given decorator type and decorators or node.
|
|
31
|
-
*
|
|
32
|
-
* @param type
|
|
33
|
-
* @param data
|
|
34
|
-
*/
|
|
35
|
-
public match<T extends Decorator.Type>(
|
|
36
|
-
type: T,
|
|
37
|
-
data: Decorator.Data[] | Node
|
|
38
|
-
) {
|
|
39
|
-
if(!hasOwnProperty(this.mapping, type)) {
|
|
40
|
-
return undefined;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const decorators : Decorator.Data[] = Array.isArray(data) ? data : getNodeDecorators(data);
|
|
44
|
-
|
|
45
|
-
const representations : Array<Decorator.Representation<T>> = (Array.isArray(this.mapping[type]) ? this.mapping[type] : [this.mapping[type]]) as Array<Decorator.Representation<T>>;
|
|
46
|
-
for(let i=0; i<representations.length; i++) {
|
|
47
|
-
const items = decorators.filter(decorator => decorator.text === representations[i].id);
|
|
48
|
-
if(items.length > 0) {
|
|
49
|
-
return new RepresentationManager<T>(
|
|
50
|
-
representations[i],
|
|
51
|
-
items
|
|
52
|
-
);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return undefined;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// -------------------------------------------
|
|
60
|
-
|
|
61
|
-
private aggregate() : void {
|
|
62
|
-
if(typeof this.config === 'undefined') {
|
|
63
|
-
this.mapping = {};
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const items : Array<Partial<Decorator.TypeRepresentationMap>> = [];
|
|
68
|
-
|
|
69
|
-
// mapping - internal
|
|
70
|
-
const internalMap = getDecoratorMap('internal');
|
|
71
|
-
items.push(
|
|
72
|
-
typeof this.config.internal === 'undefined' ?
|
|
73
|
-
internalMap :
|
|
74
|
-
reduceTypeRepresentationMapping(internalMap, (type) => {
|
|
75
|
-
return isMappingTypeIncluded(type, this.config.internal);
|
|
76
|
-
})
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// mapping - extension
|
|
80
|
-
if(typeof this.config.map !== 'undefined') {
|
|
81
|
-
items.push(this.config.map);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// mapping - library
|
|
85
|
-
if(typeof this.config.library !== 'undefined') {
|
|
86
|
-
// check if string or string[]
|
|
87
|
-
|
|
88
|
-
if(
|
|
89
|
-
typeof this.config.library === 'string' ||
|
|
90
|
-
Array.isArray(this.config.library)
|
|
91
|
-
) {
|
|
92
|
-
const libraries : string[] = Array.isArray(this.config.library) ?
|
|
93
|
-
this.config.library :
|
|
94
|
-
[this.config.library];
|
|
95
|
-
|
|
96
|
-
items.push(...libraries.map(library => getDecoratorMap(library)));
|
|
97
|
-
} else {
|
|
98
|
-
// tslint:disable-next-line:forin
|
|
99
|
-
for(const key in this.config.library) {
|
|
100
|
-
items.push(
|
|
101
|
-
reduceTypeRepresentationMapping(getDecoratorMap(key), (type) => {
|
|
102
|
-
return isMappingTypeIncluded(type, this.config.library[key]);
|
|
103
|
-
})
|
|
104
|
-
);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
this.mapping = this.merge(...items);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Merge decorator type-representation mappings of different libraries together.
|
|
114
|
-
*
|
|
115
|
-
* @param mappings
|
|
116
|
-
* @private
|
|
117
|
-
*/
|
|
118
|
-
private merge(...mappings: Array<Partial<Decorator.TypeRepresentationMap>>) : Partial<Decorator.TypeRepresentationMap> {
|
|
119
|
-
const result : Partial<Decorator.TypeRepresentationMap> = {};
|
|
120
|
-
|
|
121
|
-
// we need all available mapping keys :)
|
|
122
|
-
let keys : Decorator.Type[] = mappings
|
|
123
|
-
.map(mapping => Object.keys(mapping))
|
|
124
|
-
.reduce(((previousValue, currentValue) => [...previousValue, ...currentValue])) as Decorator.Type[];
|
|
125
|
-
|
|
126
|
-
keys = Array.from(new Set(keys));
|
|
127
|
-
|
|
128
|
-
for(let i=0; i<keys.length; i++) {
|
|
129
|
-
const representations : Array<Decorator.Representation<any>> = [];
|
|
130
|
-
|
|
131
|
-
for(let j=0; j<mappings.length; j++) {
|
|
132
|
-
if(hasOwnProperty(mappings[j], keys[i])) {
|
|
133
|
-
const value : Decorator.Representation<any> | Array<Decorator.Representation<any>> = mappings[j][keys[i]];
|
|
134
|
-
|
|
135
|
-
if(typeof value === 'undefined') {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if(Array.isArray(value)) {
|
|
140
|
-
representations.push(...value);
|
|
141
|
-
} else {
|
|
142
|
-
representations.push(value);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// @ts-ignore
|
|
148
|
-
result[keys[i]] = representations;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
}
|