@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/resolver/type.ts
DELETED
|
@@ -1,257 +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 {Property} from "../type";
|
|
9
|
-
|
|
10
|
-
export namespace Resolver {
|
|
11
|
-
export type TypeStringLiteral =
|
|
12
|
-
| 'string'
|
|
13
|
-
| 'boolean'
|
|
14
|
-
| 'double'
|
|
15
|
-
| 'float'
|
|
16
|
-
| 'file'
|
|
17
|
-
| 'integer'
|
|
18
|
-
| 'long'
|
|
19
|
-
| 'enum'
|
|
20
|
-
| 'array'
|
|
21
|
-
| 'datetime'
|
|
22
|
-
| 'date'
|
|
23
|
-
| 'binary'
|
|
24
|
-
| 'buffer'
|
|
25
|
-
| 'byte'
|
|
26
|
-
| 'void'
|
|
27
|
-
| 'object'
|
|
28
|
-
| 'any'
|
|
29
|
-
| 'refEnum'
|
|
30
|
-
| 'refObject'
|
|
31
|
-
| 'refAlias'
|
|
32
|
-
| 'nestedObjectLiteral'
|
|
33
|
-
| 'union'
|
|
34
|
-
| 'intersection';
|
|
35
|
-
|
|
36
|
-
export type RefTypeLiteral = 'refObject' | 'refEnum' | 'refAlias';
|
|
37
|
-
|
|
38
|
-
export type PrimitiveTypeLiteral = Exclude<TypeStringLiteral, RefTypeLiteral | 'enum' | 'array' | 'void' | 'nestedObjectLiteral' | 'union' | 'intersection'>;
|
|
39
|
-
|
|
40
|
-
export type Type =
|
|
41
|
-
| PrimitiveType
|
|
42
|
-
| ObjectsNoPropsType
|
|
43
|
-
| EnumType
|
|
44
|
-
| ArrayType
|
|
45
|
-
| FileType
|
|
46
|
-
| DateTimeType
|
|
47
|
-
| DateType
|
|
48
|
-
| BinaryType
|
|
49
|
-
| BufferType
|
|
50
|
-
| ByteType
|
|
51
|
-
| AnyType
|
|
52
|
-
| RefEnumType
|
|
53
|
-
| RefObjectType
|
|
54
|
-
| RefAliasType
|
|
55
|
-
| NestedObjectLiteralType
|
|
56
|
-
| UnionType
|
|
57
|
-
| IntersectionType;
|
|
58
|
-
|
|
59
|
-
// -------------------------------------------
|
|
60
|
-
|
|
61
|
-
export interface BaseType {
|
|
62
|
-
typeName: TypeStringLiteral;
|
|
63
|
-
typeArgument?: BaseType;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// -------------------------------------------
|
|
67
|
-
// Primitive Type(s)
|
|
68
|
-
// -------------------------------------------
|
|
69
|
-
|
|
70
|
-
export type PrimitiveType = StringType | BooleanType | DoubleType | FloatType | IntegerType | LongType | VoidType;
|
|
71
|
-
|
|
72
|
-
export interface AnyType extends BaseType {
|
|
73
|
-
typeName: 'any';
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function isAnyType(param: BaseType) : param is AnyType {
|
|
77
|
-
return param.typeName === 'any';
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export interface StringType extends BaseType {
|
|
81
|
-
typeName: 'string';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export interface BooleanType extends BaseType {
|
|
85
|
-
typeName: 'boolean';
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface DoubleType extends BaseType {
|
|
89
|
-
typeName: 'double';
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export interface FloatType extends BaseType {
|
|
93
|
-
typeName: 'float';
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export interface IntegerType extends BaseType {
|
|
97
|
-
typeName: 'integer';
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export interface LongType extends BaseType {
|
|
101
|
-
typeName: 'long';
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export interface VoidType extends BaseType {
|
|
105
|
-
typeName: 'void';
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
export function isVoidType(param: BaseType) : param is VoidType {
|
|
109
|
-
return typeof param === 'undefined' || param.typeName === 'void';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// -------------------------------------------
|
|
113
|
-
// Simple Type(s)
|
|
114
|
-
// -------------------------------------------
|
|
115
|
-
|
|
116
|
-
export interface DateType extends BaseType {
|
|
117
|
-
typeName: 'date';
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface FileType extends BaseType {
|
|
121
|
-
typeName: 'file';
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export interface DateTimeType extends BaseType {
|
|
125
|
-
typeName: 'datetime';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export interface BinaryType extends BaseType {
|
|
129
|
-
typeName: 'binary';
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export interface BufferType extends BaseType {
|
|
133
|
-
typeName: 'buffer';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export interface ByteType extends BaseType {
|
|
137
|
-
typeName: 'byte';
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface AnyType extends BaseType {
|
|
141
|
-
typeName: 'any';
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export interface ObjectsNoPropsType extends BaseType {
|
|
145
|
-
typeName: 'object';
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// -------------------------------------------
|
|
149
|
-
// Complex Type(s)
|
|
150
|
-
// -------------------------------------------
|
|
151
|
-
|
|
152
|
-
export interface EnumType extends BaseType {
|
|
153
|
-
members: Array<string | number | boolean | null>;
|
|
154
|
-
typeName: 'enum';
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function isEnumType(param: BaseType) : param is EnumType {
|
|
158
|
-
return param.typeName === 'enum';
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// -------------------------------------------
|
|
162
|
-
|
|
163
|
-
export interface ArrayType extends BaseType {
|
|
164
|
-
elementType: BaseType;
|
|
165
|
-
typeName: 'array';
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export function isArrayType(param: BaseType) : param is ArrayType {
|
|
169
|
-
return param.typeName === 'array';
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// -------------------------------------------
|
|
173
|
-
|
|
174
|
-
export interface NestedObjectLiteralType extends BaseType {
|
|
175
|
-
typeName: 'nestedObjectLiteral';
|
|
176
|
-
properties: Property[];
|
|
177
|
-
additionalProperties?: Type;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function isNestedObjectLiteralType(param: BaseType) : param is NestedObjectLiteralType {
|
|
181
|
-
return param.typeName === 'nestedObjectLiteral';
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
// -------------------------------------------
|
|
185
|
-
|
|
186
|
-
export interface IntersectionType extends BaseType {
|
|
187
|
-
typeName: 'intersection';
|
|
188
|
-
members: Type[];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export function isIntersectionType(param: BaseType) : param is IntersectionType {
|
|
192
|
-
return param.typeName === 'intersection';
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// -------------------------------------------
|
|
196
|
-
|
|
197
|
-
export interface UnionType extends BaseType {
|
|
198
|
-
typeName: 'union';
|
|
199
|
-
members: Type[];
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export function isUnionType(param: BaseType) : param is UnionType {
|
|
203
|
-
return param.typeName === 'union';
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// -------------------------------------------
|
|
207
|
-
// Reference Type(s)
|
|
208
|
-
// -------------------------------------------
|
|
209
|
-
|
|
210
|
-
export type ReferenceType = RefEnumType | RefObjectType | RefAliasType;
|
|
211
|
-
|
|
212
|
-
export interface ReferenceTypes {
|
|
213
|
-
[key: string]: ReferenceType;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export type DependencyResolver = (referenceTypes: Resolver.ReferenceTypes) => void;
|
|
217
|
-
|
|
218
|
-
export interface ReferenceTypeBase extends BaseType {
|
|
219
|
-
description?: string;
|
|
220
|
-
typeName: RefTypeLiteral;
|
|
221
|
-
refName: string;
|
|
222
|
-
example?: unknown;
|
|
223
|
-
deprecated: boolean;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
export interface RefEnumType extends ReferenceTypeBase {
|
|
227
|
-
typeName: 'refEnum';
|
|
228
|
-
members: Array<string | number>;
|
|
229
|
-
memberNames?: string[];
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
export function isRefEnumType(param: BaseType) : param is RefEnumType {
|
|
233
|
-
return param.typeName === 'refEnum';
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export interface RefObjectType extends ReferenceTypeBase {
|
|
237
|
-
typeName: 'refObject';
|
|
238
|
-
properties: Property[];
|
|
239
|
-
additionalProperties?: Type;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function isRefObjectType(param: BaseType) : param is RefObjectType {
|
|
243
|
-
return param.typeName === 'refObject';
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export interface RefAliasType extends Omit<Property, 'name' | 'required'>, ReferenceTypeBase {
|
|
247
|
-
typeName: 'refAlias';
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export function isRefAliasType(param: BaseType) : param is RefAliasType {
|
|
251
|
-
return param.typeName === 'refAlias';
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export function isReferenceType(param: BaseType) : param is ReferenceType {
|
|
255
|
-
return param.typeName === 'refEnum' || param.typeName === 'refAlias' || param.typeName === 'refObject';
|
|
256
|
-
}
|
|
257
|
-
}
|
|
@@ -1,81 +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 ts from 'typescript';
|
|
9
|
-
import {Resolver} from "../type";
|
|
10
|
-
import {hasOwnProperty} from "@trapi/metadata-utils";
|
|
11
|
-
|
|
12
|
-
export function getInitializerValue(
|
|
13
|
-
initializer?: ts.Expression,
|
|
14
|
-
typeChecker?: ts.TypeChecker,
|
|
15
|
-
type?: Resolver.Type
|
|
16
|
-
) : unknown {
|
|
17
|
-
if (!initializer) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
switch (initializer.kind) {
|
|
22
|
-
case ts.SyntaxKind.ArrayLiteralExpression:
|
|
23
|
-
const arrayLiteral = initializer as ts.ArrayLiteralExpression;
|
|
24
|
-
return arrayLiteral.elements.map(element => getInitializerValue(element, typeChecker));
|
|
25
|
-
case ts.SyntaxKind.StringLiteral:
|
|
26
|
-
return (initializer as ts.StringLiteral).text;
|
|
27
|
-
case ts.SyntaxKind.TrueKeyword:
|
|
28
|
-
return true;
|
|
29
|
-
case ts.SyntaxKind.FalseKeyword:
|
|
30
|
-
return false;
|
|
31
|
-
case ts.SyntaxKind.NumberKeyword:
|
|
32
|
-
case ts.SyntaxKind.FirstLiteralToken:
|
|
33
|
-
return Number((initializer as ts.NumericLiteral).text);
|
|
34
|
-
case ts.SyntaxKind.NewExpression:
|
|
35
|
-
const newExpression = initializer as ts.NewExpression;
|
|
36
|
-
const ident = newExpression.expression as ts.Identifier;
|
|
37
|
-
|
|
38
|
-
if (ident.text === 'Date') {
|
|
39
|
-
let date = new Date();
|
|
40
|
-
if (newExpression.arguments) {
|
|
41
|
-
const newArguments = newExpression.arguments.filter(args => args.kind !== undefined);
|
|
42
|
-
const argsValue = newArguments.map(args => getInitializerValue(args, typeChecker));
|
|
43
|
-
if (argsValue.length > 0) {
|
|
44
|
-
date = new Date(argsValue as any);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const dateString = date.toISOString();
|
|
48
|
-
if (type && type.typeName === 'date') {
|
|
49
|
-
return dateString.split('T')[0];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return dateString;
|
|
53
|
-
}
|
|
54
|
-
return;
|
|
55
|
-
case ts.SyntaxKind.ObjectLiteralExpression:
|
|
56
|
-
const objectLiteral = initializer as ts.ObjectLiteralExpression;
|
|
57
|
-
const nestedObject: any = {};
|
|
58
|
-
objectLiteral.properties.forEach((p: any) => {
|
|
59
|
-
nestedObject[p.name.text] = getInitializerValue(p.initializer, typeChecker);
|
|
60
|
-
});
|
|
61
|
-
return nestedObject;
|
|
62
|
-
default:
|
|
63
|
-
if(typeof initializer === 'undefined') {
|
|
64
|
-
return undefined;
|
|
65
|
-
} else {
|
|
66
|
-
if(typeof initializer.parent === 'undefined') {
|
|
67
|
-
if(hasOwnProperty(initializer, 'text')) {
|
|
68
|
-
return initializer.text;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return undefined;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const symbol = typeChecker.getSymbolAtLocation(initializer);
|
|
75
|
-
const extractedInitializer = symbol && symbol.valueDeclaration && hasInitializer(symbol.valueDeclaration) && (symbol.valueDeclaration.initializer as ts.Expression);
|
|
76
|
-
return extractedInitializer ? getInitializerValue(extractedInitializer, typeChecker) : undefined;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const hasInitializer = (node: ts.Node): node is ts.HasInitializer => node.hasOwnProperty('initializer');
|
|
@@ -1,144 +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 {ParameterDeclaration} from 'typescript';
|
|
9
|
-
import {Validator} from "../../type";
|
|
10
|
-
import {getJSDocTags} from "../../utils";
|
|
11
|
-
|
|
12
|
-
export function getParameterValidators(parameter: ParameterDeclaration, name: string): Record<string, Validator> {
|
|
13
|
-
if (!parameter.parent) {
|
|
14
|
-
return {};
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const getCommentValue = (comment?: string) => comment && comment.split(' ')[0];
|
|
18
|
-
|
|
19
|
-
const tags = getJSDocTags(parameter.parent, tag => {
|
|
20
|
-
let { comment } = tag;
|
|
21
|
-
const text : string = Array.isArray(comment) ? (comment.length > 0 ? comment[0].text : undefined) : comment;
|
|
22
|
-
return getSupportedParameterTags().some(value => !!comment && value === tag.tagName.text && getCommentValue(text) === name);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function getErrorMsg(comment?: string, isValue = true) : string {
|
|
26
|
-
if (!comment) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (isValue) {
|
|
30
|
-
const indexOf = comment.indexOf(' ');
|
|
31
|
-
if (indexOf > 0) {
|
|
32
|
-
return comment.substr(indexOf + 1);
|
|
33
|
-
} else {
|
|
34
|
-
return undefined;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
return comment;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const validators : Record<string, Validator> = {};
|
|
42
|
-
|
|
43
|
-
tags.map(tag => {
|
|
44
|
-
if (!tag.comment) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const name = tag.tagName.text;
|
|
49
|
-
|
|
50
|
-
let comment = typeof tag.comment === 'string' ? tag.comment : tag.comment[0].text ?? '';
|
|
51
|
-
comment = comment.substr(comment.indexOf(' ') + 1).trim();
|
|
52
|
-
|
|
53
|
-
const value = getCommentValue(comment);
|
|
54
|
-
|
|
55
|
-
switch (name) {
|
|
56
|
-
case 'uniqueItems':
|
|
57
|
-
validators[name] = {
|
|
58
|
-
message: getErrorMsg(comment, false),
|
|
59
|
-
value: undefined,
|
|
60
|
-
};
|
|
61
|
-
break;
|
|
62
|
-
case 'minimum':
|
|
63
|
-
case 'maximum':
|
|
64
|
-
case 'minItems':
|
|
65
|
-
case 'maxItems':
|
|
66
|
-
case 'minLength':
|
|
67
|
-
case 'maxLength':
|
|
68
|
-
if (isNaN(value as any)) {
|
|
69
|
-
throw new Error(`${name} parameter use number.`);
|
|
70
|
-
}
|
|
71
|
-
validators[name] = {
|
|
72
|
-
message: getErrorMsg(comment),
|
|
73
|
-
value: Number(value),
|
|
74
|
-
};
|
|
75
|
-
break;
|
|
76
|
-
case 'minDate':
|
|
77
|
-
case 'maxDate':
|
|
78
|
-
if (typeof value !== 'string') {
|
|
79
|
-
throw new Error(`${name} parameter use date format ISO 8601 ex. 2017-05-14, 2017-05-14T05:18Z`);
|
|
80
|
-
}
|
|
81
|
-
validators[name] = {
|
|
82
|
-
message: getErrorMsg(comment),
|
|
83
|
-
value,
|
|
84
|
-
};
|
|
85
|
-
break;
|
|
86
|
-
case 'pattern':
|
|
87
|
-
if (typeof value !== 'string') {
|
|
88
|
-
throw new Error(`${name} parameter use string.`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
validators[name] = {
|
|
92
|
-
message: getErrorMsg(comment),
|
|
93
|
-
value: removeSurroundingQuotes(value),
|
|
94
|
-
};
|
|
95
|
-
break;
|
|
96
|
-
default:
|
|
97
|
-
if (name.startsWith('is')) {
|
|
98
|
-
const errorMsg = getErrorMsg(comment, false);
|
|
99
|
-
if (errorMsg) {
|
|
100
|
-
validators[name] = {
|
|
101
|
-
message: errorMsg,
|
|
102
|
-
value: undefined,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
return validators;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function getSupportedParameterTags() {
|
|
114
|
-
return [
|
|
115
|
-
'isString',
|
|
116
|
-
'isBoolean',
|
|
117
|
-
'isInt',
|
|
118
|
-
'isLong',
|
|
119
|
-
'isFloat',
|
|
120
|
-
'isDouble',
|
|
121
|
-
'isDate',
|
|
122
|
-
'isDateTime',
|
|
123
|
-
'minItems',
|
|
124
|
-
'maxItems',
|
|
125
|
-
'uniqueItems',
|
|
126
|
-
'minLength',
|
|
127
|
-
'maxLength',
|
|
128
|
-
'pattern',
|
|
129
|
-
'minimum',
|
|
130
|
-
'maximum',
|
|
131
|
-
'minDate',
|
|
132
|
-
'maxDate',
|
|
133
|
-
];
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function removeSurroundingQuotes(str: string) {
|
|
137
|
-
if (str.startsWith('`') && str.endsWith('`')) {
|
|
138
|
-
return str.substring(1, str.length - 1);
|
|
139
|
-
}
|
|
140
|
-
if (str.startsWith('```') && str.endsWith('```')) {
|
|
141
|
-
return str.substring(3, str.length - 3);
|
|
142
|
-
}
|
|
143
|
-
return str;
|
|
144
|
-
}
|
package/src/type.ts
DELETED
|
@@ -1,185 +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 {Resolver} from "./resolver";
|
|
9
|
-
import {Decorator} from "./decorator";
|
|
10
|
-
import {Cache} from "./cache";
|
|
11
|
-
|
|
12
|
-
export interface Config {
|
|
13
|
-
/**
|
|
14
|
-
* The entry point to your API.
|
|
15
|
-
*/
|
|
16
|
-
entryFile: string | string[];
|
|
17
|
-
/**
|
|
18
|
-
* Directory to ignore during TypeScript files scan.
|
|
19
|
-
* Default: []
|
|
20
|
-
*/
|
|
21
|
-
ignore?: string[];
|
|
22
|
-
/**
|
|
23
|
-
* Directory to store and cache metadata cache files.
|
|
24
|
-
* Default: false
|
|
25
|
-
*/
|
|
26
|
-
cache?: string | boolean | Partial<Cache.Config>;
|
|
27
|
-
/**
|
|
28
|
-
* Decorator config.
|
|
29
|
-
* Default: {
|
|
30
|
-
* library: ['decorators-express', 'typescript-rest'],
|
|
31
|
-
* internal: true
|
|
32
|
-
* }
|
|
33
|
-
*/
|
|
34
|
-
decorator?: Decorator.Config;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* The output specification for metadata generation.
|
|
39
|
-
*/
|
|
40
|
-
export interface GeneratorOutput {
|
|
41
|
-
/**
|
|
42
|
-
* A Controller is a collection of grouped methods (GET, POST, ...)
|
|
43
|
-
* for a common URL path (i.e /users) or an more explicit URL path (i.e. /users/:id).
|
|
44
|
-
*/
|
|
45
|
-
controllers: Controller[];
|
|
46
|
-
/**
|
|
47
|
-
* ReferenceTypes is an object of found types (interfaces, type, ...),
|
|
48
|
-
* and classes which were detected during code analysis.
|
|
49
|
-
*/
|
|
50
|
-
referenceTypes: Resolver.ReferenceTypes;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface Controller {
|
|
54
|
-
/**
|
|
55
|
-
* File Location of the Controller.
|
|
56
|
-
*/
|
|
57
|
-
location: string;
|
|
58
|
-
/**
|
|
59
|
-
* Array of found method ( class functions )
|
|
60
|
-
* for a specific controller (class)
|
|
61
|
-
*/
|
|
62
|
-
methods: Method[];
|
|
63
|
-
name: string;
|
|
64
|
-
/**
|
|
65
|
-
* The relative URL Path, i.e /users
|
|
66
|
-
*/
|
|
67
|
-
path: string;
|
|
68
|
-
/**
|
|
69
|
-
* Allowed Content-Types to pass
|
|
70
|
-
* data according the definition.
|
|
71
|
-
*
|
|
72
|
-
* i.e. ['application/json']
|
|
73
|
-
*/
|
|
74
|
-
consumes: string[];
|
|
75
|
-
/**
|
|
76
|
-
* Possible Content-Types to receive
|
|
77
|
-
* data according the definition.
|
|
78
|
-
*
|
|
79
|
-
* i.e. ['application/json']
|
|
80
|
-
*/
|
|
81
|
-
produces: string[];
|
|
82
|
-
responses: Response[];
|
|
83
|
-
/**
|
|
84
|
-
* Tags can be used to group controllers
|
|
85
|
-
* by a name together.
|
|
86
|
-
*
|
|
87
|
-
* i.e. ['auth']
|
|
88
|
-
*/
|
|
89
|
-
tags: string[];
|
|
90
|
-
security?: Security[];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface Security {
|
|
94
|
-
name: string;
|
|
95
|
-
scopes?: string[];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export interface Method {
|
|
99
|
-
operationId?: string;
|
|
100
|
-
deprecated?: boolean;
|
|
101
|
-
description: string;
|
|
102
|
-
method: MethodType;
|
|
103
|
-
extensions: Extension[];
|
|
104
|
-
name: string;
|
|
105
|
-
parameters: Parameter[];
|
|
106
|
-
path: string;
|
|
107
|
-
type: Resolver.BaseType;
|
|
108
|
-
tags: string[];
|
|
109
|
-
responses: Response[];
|
|
110
|
-
security?: Security[];
|
|
111
|
-
summary?: string;
|
|
112
|
-
consumes: string[];
|
|
113
|
-
produces: string[];
|
|
114
|
-
hidden: boolean;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export type MethodType = 'get' | 'post' | 'put' | 'delete' | 'options' | 'head' | 'patch';
|
|
118
|
-
|
|
119
|
-
export interface Extension {
|
|
120
|
-
key: string;
|
|
121
|
-
value: ExtensionType | ExtensionType[];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export type ExtensionType =
|
|
125
|
-
string
|
|
126
|
-
| number
|
|
127
|
-
| boolean
|
|
128
|
-
| null
|
|
129
|
-
| ExtensionType[]
|
|
130
|
-
| { [name: string]: ExtensionType | ExtensionType[] };
|
|
131
|
-
|
|
132
|
-
export interface Parameter {
|
|
133
|
-
parameterName: string;
|
|
134
|
-
description: string;
|
|
135
|
-
in: string;
|
|
136
|
-
name: string;
|
|
137
|
-
required: boolean;
|
|
138
|
-
type: Resolver.BaseType;
|
|
139
|
-
collectionFormat?: 'csv' | 'multi' | 'pipes' | 'ssv' | 'tsv';
|
|
140
|
-
allowEmptyValue?: boolean;
|
|
141
|
-
default?: any;
|
|
142
|
-
maxItems?: number;
|
|
143
|
-
minItems?: number;
|
|
144
|
-
deprecated?: boolean;
|
|
145
|
-
|
|
146
|
-
example?: unknown[];
|
|
147
|
-
validators?: Record<string, Validator>;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export interface ArrayParameter extends Parameter {
|
|
151
|
-
type: Resolver.ArrayType;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export interface Validator {
|
|
155
|
-
value?: unknown,
|
|
156
|
-
message?: string
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
export interface Property {
|
|
160
|
-
default?: any;
|
|
161
|
-
format?: string;
|
|
162
|
-
example?: unknown;
|
|
163
|
-
validators?: Record<string, { value?: any, message?: string }>;
|
|
164
|
-
description?: string;
|
|
165
|
-
name: string;
|
|
166
|
-
type: Resolver.Type;
|
|
167
|
-
required: boolean;
|
|
168
|
-
deprecated: boolean;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export interface Response {
|
|
172
|
-
description: string;
|
|
173
|
-
examples?: unknown[] | unknown;
|
|
174
|
-
headers?: Resolver.NestedObjectLiteralType | Resolver.RefObjectType;
|
|
175
|
-
name: string;
|
|
176
|
-
status: string;
|
|
177
|
-
schema?: Resolver.BaseType;
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|