@trapi/metadata 1.0.0-alpha.5 → 1.0.0-alpha.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/generator/method/module.d.ts.map +1 -1
- package/dist/generator/method/module.js +1 -2
- package/dist/generator/method/module.js.map +1 -1
- package/dist/generator/method/type.d.ts +2 -9
- package/dist/generator/method/type.d.ts.map +1 -1
- package/dist/generator/parameter/index.d.ts +0 -1
- package/dist/generator/parameter/index.d.ts.map +1 -1
- package/dist/generator/parameter/index.js +0 -1
- package/dist/generator/parameter/index.js.map +1 -1
- package/dist/generator/parameter/module.d.ts.map +1 -1
- package/dist/generator/parameter/module.js +30 -30
- package/dist/generator/parameter/module.js.map +1 -1
- package/dist/generator/parameter/type.d.ts +3 -3
- package/dist/generator/parameter/type.d.ts.map +1 -1
- package/dist/generator/type.d.ts +1 -0
- package/dist/generator/type.d.ts.map +1 -1
- package/dist/resolver/constants.d.ts +27 -0
- package/dist/resolver/constants.d.ts.map +1 -0
- package/dist/resolver/constants.js +37 -0
- package/dist/resolver/constants.js.map +1 -0
- package/dist/resolver/extension/index.d.ts +3 -0
- package/dist/resolver/extension/index.d.ts.map +1 -0
- package/dist/resolver/extension/index.js +25 -0
- package/dist/resolver/extension/index.js.map +1 -0
- package/dist/resolver/extension/module.d.ts +5 -0
- package/dist/resolver/extension/module.d.ts.map +1 -0
- package/dist/resolver/extension/module.js +27 -0
- package/dist/resolver/extension/module.js.map +1 -0
- package/dist/resolver/extension/type.d.ts +8 -0
- package/dist/resolver/extension/type.d.ts.map +1 -0
- package/dist/resolver/extension/type.js +9 -0
- package/dist/resolver/extension/type.js.map +1 -0
- package/dist/resolver/index.d.ts +2 -0
- package/dist/resolver/index.d.ts.map +1 -1
- package/dist/resolver/index.js +2 -0
- package/dist/resolver/index.js.map +1 -1
- package/dist/resolver/module.d.ts +5 -2
- package/dist/resolver/module.d.ts.map +1 -1
- package/dist/resolver/module.js +93 -82
- package/dist/resolver/module.js.map +1 -1
- package/dist/resolver/type.d.ts +59 -46
- package/dist/resolver/type.d.ts.map +1 -1
- package/dist/resolver/type.js +88 -12
- package/dist/resolver/type.js.map +1 -1
- package/dist/type.d.ts +1 -4
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +6 -0
- package/dist/type.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/initializer.d.ts +2 -2
- package/dist/utils/initializer.d.ts.map +1 -1
- package/dist/utils/initializer.js.map +1 -1
- package/dist/utils/validator/constants.d.ts +13 -0
- package/dist/utils/validator/constants.d.ts.map +1 -0
- package/dist/utils/validator/constants.js +23 -0
- package/dist/utils/validator/constants.js.map +1 -0
- package/dist/utils/validator/index.d.ts +4 -0
- package/dist/utils/validator/index.d.ts.map +1 -0
- package/dist/utils/validator/index.js +26 -0
- package/dist/utils/validator/index.js.map +1 -0
- package/dist/utils/validator/module.d.ts +4 -0
- package/dist/utils/validator/module.d.ts.map +1 -0
- package/dist/{generator/parameter/validator.js → utils/validator/module.js} +28 -22
- package/dist/utils/validator/module.js.map +1 -0
- package/dist/utils/validator/type.d.ts +6 -0
- package/dist/utils/validator/type.d.ts.map +1 -0
- package/dist/utils/validator/type.js +9 -0
- package/dist/utils/validator/type.js.map +1 -0
- package/package.json +2 -2
- package/dist/generator/parameter/validator.d.ts +0 -4
- package/dist/generator/parameter/validator.d.ts.map +0 -1
- package/dist/generator/parameter/validator.js.map +0 -1
package/dist/resolver/index.js
CHANGED
|
@@ -20,7 +20,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
20
20
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
21
|
};
|
|
22
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./constants"), exports);
|
|
23
24
|
__exportStar(require("./error"), exports);
|
|
25
|
+
__exportStar(require("./extension"), exports);
|
|
24
26
|
__exportStar(require("./module"), exports);
|
|
25
27
|
__exportStar(require("./type"), exports);
|
|
26
28
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resolver/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB;AACxB,2CAAyB;AACzB,yCAAuB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/resolver/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,0CAAwB;AACxB,8CAA4B;AAC5B,2CAAyB;AACzB,yCAAuB"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import * as ts from 'typescript';
|
|
2
2
|
import type { MetadataGenerator } from '../generator';
|
|
3
|
-
import type {
|
|
3
|
+
import type { Extension } from './extension';
|
|
4
|
+
import type { Type } from './type';
|
|
5
|
+
type UsableDeclaration = ts.InterfaceDeclaration | ts.ClassDeclaration | ts.PropertySignature | ts.TypeAliasDeclaration | ts.EnumMember;
|
|
4
6
|
interface TypeNodeResolverContext {
|
|
5
7
|
[name: string]: ts.TypeReferenceNode | ts.TypeNode;
|
|
6
8
|
}
|
|
@@ -12,7 +14,7 @@ export declare class TypeNodeResolver {
|
|
|
12
14
|
private readonly referencer;
|
|
13
15
|
constructor(typeNode: ts.TypeNode, current: MetadataGenerator, parentNode?: ts.Node, context?: TypeNodeResolverContext, referencer?: ts.TypeNode);
|
|
14
16
|
static clearCache(): void;
|
|
15
|
-
resolve():
|
|
17
|
+
resolve(): Type;
|
|
16
18
|
private static isSupportedUtilityType;
|
|
17
19
|
private static getUtilityTypeOptions;
|
|
18
20
|
private filterUtilityProperties;
|
|
@@ -46,6 +48,7 @@ export declare class TypeNodeResolver {
|
|
|
46
48
|
private getNodeDescription;
|
|
47
49
|
private static getNodeFormat;
|
|
48
50
|
private getNodeExample;
|
|
51
|
+
protected getNodeExtensions(node: UsableDeclaration | ts.PropertyDeclaration | ts.ParameterDeclaration | ts.EnumDeclaration): Extension[];
|
|
49
52
|
}
|
|
50
53
|
export {};
|
|
51
54
|
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/resolver/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/resolver/module.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAY7C,OAAO,KAAK,EAcR,IAAI,EAEP,MAAM,QAAQ,CAAC;AAShB,KAAK,iBAAiB,GAAG,EAAE,CAAC,oBAAoB,GAChD,EAAE,CAAC,gBAAgB,GACnB,EAAE,CAAC,iBAAiB,GACpB,EAAE,CAAC,oBAAoB,GACvB,EAAE,CAAC,UAAU,CAAC;AAEd,UAAU,uBAAuB;IAC7B,CAAC,IAAI,EAAE,MAAM,GAAG,EAAE,CAAC,iBAAiB,GAAG,EAAE,CAAC,QAAQ,CAAC;CACtD;AAOD,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IAExC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAE5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAU;IAEtC,OAAO,CAAC,OAAO,CAA0B;IAEzC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;gBAGtC,QAAQ,EAAE,EAAE,CAAC,QAAQ,EACrB,OAAO,EAAE,iBAAiB,EAC1B,UAAU,CAAC,EAAE,EAAE,CAAC,IAAI,EACpB,OAAO,CAAC,EAAE,uBAAuB,EACjC,UAAU,CAAC,EAAE,EAAE,CAAC,QAAQ;WASd,UAAU;IAUjB,OAAO,IAAI,IAAI;IAibtB,OAAO,CAAC,MAAM,CAAC,sBAAsB;IAKrC,OAAO,CAAC,MAAM,CAAC,qBAAqB;IAuBpC,OAAO,CAAC,uBAAuB;IAuC/B,OAAO,CAAC,MAAM,CAAC,uBAAuB;IAWtC,OAAO,CAAC,MAAM,CAAC,eAAe;IA4B9B,OAAO,CAAC,gBAAgB;IAoFxB,OAAO,CAAC,WAAW;IAkBnB,OAAO,CAAC,MAAM,CAAC,mBAAmB;IAIlC,OAAO,CAAC,gBAAgB;IAiCxB,OAAO,CAAC,gBAAgB;IAkGxB,OAAO,CAAC,qBAAqB;IAmC7B,OAAO,CAAC,iBAAiB;IAoEzB,OAAO,CAAC,MAAM,CAAC,cAAc;IAqB7B,OAAO,CAAC,+BAA+B,CAWrC;IAEF,OAAO,CAAC,kBAAkB;IAQ1B,OAAO,CAAC,kCAAkC;IA2B1C,OAAO,CAAC,gCAAgC;IAuBxC,OAAO,CAAC,MAAM,CAAC,YAAY;IAa3B,OAAO,CAAC,uBAAuB;IA+C/B,OAAO,CAAC,OAAO;IAIf,OAAO,CAAC,mBAAmB;IAU3B,OAAO,CAAC,kBAAkB;IAoC1B,OAAO,CAAC,qBAAqB;IAmC7B,OAAO,CAAC,uBAAuB;IAmD/B,OAAO,CAAC,4BAA4B;IAyBpC,OAAO,CAAC,sBAAsB;IAwC9B,OAAO,CAAC,2BAA2B;IAiDnC,OAAO,CAAC,iBAAiB;IAazB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,qBAAqB;IAyB7B,OAAO,CAAC,kBAAkB;IAuB1B,OAAO,CAAC,MAAM,CAAC,aAAa;IAM5B,OAAO,CAAC,cAAc;IActB,SAAS,CAAC,iBAAiB,CAAC,IAAI,EAAE,iBAAiB,GAAG,EAAE,CAAC,mBAAmB,GAAG,EAAE,CAAC,oBAAoB,GAAG,EAAE,CAAC,eAAe,GAAI,SAAS,EAAE;CAG7I"}
|
package/dist/resolver/module.js
CHANGED
|
@@ -32,13 +32,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
32
32
|
exports.TypeNodeResolver = void 0;
|
|
33
33
|
const ts = __importStar(require("typescript"));
|
|
34
34
|
const decorator_1 = require("../decorator");
|
|
35
|
+
const constants_1 = require("./constants");
|
|
35
36
|
const utils_1 = require("../utils");
|
|
36
37
|
const error_1 = require("./error");
|
|
38
|
+
const extension_1 = require("./extension");
|
|
39
|
+
const type_1 = require("./type");
|
|
37
40
|
const localReferenceTypeCache = {};
|
|
38
41
|
const inProgressTypes = {};
|
|
39
|
-
function getPropertyValidators(_property) {
|
|
40
|
-
return {};
|
|
41
|
-
}
|
|
42
42
|
class TypeNodeResolver {
|
|
43
43
|
constructor(typeNode, current, parentNode, context, referencer) {
|
|
44
44
|
this.attemptToResolveKindToPrimitive = (syntaxKind) => {
|
|
@@ -77,40 +77,44 @@ class TypeNodeResolver {
|
|
|
77
77
|
}
|
|
78
78
|
if (this.typeNode.kind === ts.SyntaxKind.NullKeyword) {
|
|
79
79
|
return {
|
|
80
|
-
typeName:
|
|
80
|
+
typeName: constants_1.TypeName.ENUM,
|
|
81
81
|
members: [null],
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
-
if (this.typeNode.kind === ts.SyntaxKind.
|
|
84
|
+
if (this.typeNode.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
85
|
+
return {
|
|
86
|
+
typeName: constants_1.TypeName.UNDEFINED,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (ts.isArrayTypeNode(this.typeNode)) {
|
|
85
90
|
return {
|
|
86
|
-
typeName:
|
|
91
|
+
typeName: constants_1.TypeName.ARRAY,
|
|
87
92
|
elementType: new TypeNodeResolver(this.typeNode.elementType, this.current, this.parentNode, this.context).resolve(),
|
|
88
93
|
};
|
|
89
94
|
}
|
|
90
95
|
if (ts.isUnionTypeNode(this.typeNode)) {
|
|
91
|
-
const
|
|
96
|
+
const members = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
92
97
|
return {
|
|
93
|
-
typeName:
|
|
94
|
-
members
|
|
98
|
+
typeName: constants_1.TypeName.UNION,
|
|
99
|
+
members,
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
if (ts.isIntersectionTypeNode(this.typeNode)) {
|
|
98
|
-
const
|
|
103
|
+
const members = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
99
104
|
return {
|
|
100
|
-
typeName:
|
|
101
|
-
members
|
|
105
|
+
typeName: constants_1.TypeName.INTERSECTION,
|
|
106
|
+
members,
|
|
102
107
|
};
|
|
103
108
|
}
|
|
104
109
|
if (this.typeNode.kind === ts.SyntaxKind.AnyKeyword ||
|
|
105
|
-
this.typeNode.kind === ts.SyntaxKind.UnknownKeyword
|
|
106
|
-
this.typeNode.kind === ts.SyntaxKind.UndefinedKeyword) {
|
|
110
|
+
this.typeNode.kind === ts.SyntaxKind.UnknownKeyword) {
|
|
107
111
|
return {
|
|
108
|
-
typeName:
|
|
112
|
+
typeName: constants_1.TypeName.ANY,
|
|
109
113
|
};
|
|
110
114
|
}
|
|
111
115
|
if (ts.isLiteralTypeNode(this.typeNode)) {
|
|
112
116
|
return {
|
|
113
|
-
typeName:
|
|
117
|
+
typeName: constants_1.TypeName.ENUM,
|
|
114
118
|
members: [TypeNodeResolver.getLiteralValue(this.typeNode)],
|
|
115
119
|
};
|
|
116
120
|
}
|
|
@@ -122,13 +126,14 @@ class TypeNodeResolver {
|
|
|
122
126
|
const property = {
|
|
123
127
|
deprecated: (0, utils_1.hasJSDocTag)(propertySignature, utils_1.JSDocTagName.DEPRECATED),
|
|
124
128
|
example: this.getNodeExample(propertySignature),
|
|
129
|
+
extensions: this.getNodeExtensions(propertySignature),
|
|
125
130
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, utils_1.JSDocTagName.DEFAULT),
|
|
126
131
|
description: this.getNodeDescription(propertySignature),
|
|
127
132
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
128
133
|
name: propertySignature.name.text,
|
|
129
134
|
required: !propertySignature.questionToken,
|
|
130
135
|
type,
|
|
131
|
-
validators:
|
|
136
|
+
validators: (0, utils_1.getDeclarationValidators)(propertySignature) || {},
|
|
132
137
|
};
|
|
133
138
|
return [property, ...res];
|
|
134
139
|
}, []);
|
|
@@ -137,19 +142,20 @@ class TypeNodeResolver {
|
|
|
137
142
|
if (indexMember) {
|
|
138
143
|
const indexSignatureDeclaration = indexMember;
|
|
139
144
|
const indexType = new TypeNodeResolver(indexSignatureDeclaration.parameters[0].type, this.current, this.parentNode, this.context).resolve();
|
|
140
|
-
if (
|
|
145
|
+
if (!(0, type_1.isStringType)(indexType)) {
|
|
141
146
|
throw new error_1.ResolverError('Only string indexes are supported.', this.typeNode);
|
|
142
147
|
}
|
|
143
148
|
additionalType = new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve();
|
|
144
149
|
}
|
|
145
150
|
return {
|
|
146
151
|
additionalProperties: indexMember && additionalType,
|
|
147
|
-
typeName:
|
|
152
|
+
typeName: constants_1.TypeName.NESTED_OBJECT_LITERAL,
|
|
148
153
|
properties,
|
|
149
154
|
};
|
|
150
155
|
}
|
|
151
|
-
if (this.typeNode.kind === ts.SyntaxKind.ObjectKeyword ||
|
|
152
|
-
|
|
156
|
+
if (this.typeNode.kind === ts.SyntaxKind.ObjectKeyword ||
|
|
157
|
+
ts.isFunctionTypeNode(this.typeNode)) {
|
|
158
|
+
return { typeName: constants_1.TypeName.OBJECT };
|
|
153
159
|
}
|
|
154
160
|
if (ts.isMappedTypeNode(this.typeNode) && this.referencer) {
|
|
155
161
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer);
|
|
@@ -158,11 +164,15 @@ class TypeNodeResolver {
|
|
|
158
164
|
const getDeclaration = (prop) => prop.declarations && prop.declarations[0];
|
|
159
165
|
const isIgnored = (prop) => {
|
|
160
166
|
const declaration = getDeclaration(prop);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
167
|
+
const tagNames = prop.getJsDocTags();
|
|
168
|
+
const tagNameIndex = tagNames.findIndex((tag) => tag.name === utils_1.JSDocTagName.IGNORE);
|
|
169
|
+
if (tagNameIndex >= 0) {
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return (!!declaration &&
|
|
173
|
+
!ts.isPropertyDeclaration(declaration) &&
|
|
174
|
+
!ts.isPropertySignature(declaration) &&
|
|
175
|
+
!ts.isParameter(declaration));
|
|
166
176
|
};
|
|
167
177
|
const properties = type
|
|
168
178
|
.getProperties()
|
|
@@ -197,11 +207,13 @@ class TypeNodeResolver {
|
|
|
197
207
|
};
|
|
198
208
|
});
|
|
199
209
|
return {
|
|
200
|
-
typeName:
|
|
210
|
+
typeName: constants_1.TypeName.NESTED_OBJECT_LITERAL,
|
|
201
211
|
properties,
|
|
202
212
|
};
|
|
203
213
|
}
|
|
204
|
-
if (ts.isConditionalTypeNode(this.typeNode) &&
|
|
214
|
+
if (ts.isConditionalTypeNode(this.typeNode) &&
|
|
215
|
+
this.referencer &&
|
|
216
|
+
ts.isTypeReferenceNode(this.referencer)) {
|
|
205
217
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer);
|
|
206
218
|
if (type.aliasSymbol) {
|
|
207
219
|
let declaration = type.aliasSymbol.declarations[0];
|
|
@@ -235,19 +247,21 @@ class TypeNodeResolver {
|
|
|
235
247
|
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. The flags on the result of the ConditionalType was ${type.flags}`, this.typeNode);
|
|
236
248
|
}
|
|
237
249
|
}
|
|
238
|
-
if (ts.isTypeOperatorNode(this.typeNode)
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
250
|
+
if (ts.isTypeOperatorNode(this.typeNode)) {
|
|
251
|
+
if (this.typeNode.operator === ts.SyntaxKind.KeyOfKeyword) {
|
|
252
|
+
const type = this.current.typeChecker.getTypeFromTypeNode(this.typeNode);
|
|
253
|
+
try {
|
|
254
|
+
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation), this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
255
|
+
}
|
|
256
|
+
catch (err) {
|
|
257
|
+
const indexedTypeName = this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode.type));
|
|
258
|
+
throw new error_1.ResolverError(`Could not determine the keys on ${indexedTypeName}`, this.typeNode);
|
|
259
|
+
}
|
|
242
260
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
throw new error_1.ResolverError(`Could not determine the keys on ${indexedTypeName}`, this.typeNode);
|
|
261
|
+
if (this.typeNode.operator === ts.SyntaxKind.ReadonlyKeyword) {
|
|
262
|
+
return new TypeNodeResolver(this.typeNode.type, this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
246
263
|
}
|
|
247
264
|
}
|
|
248
|
-
if (ts.isTypeOperatorNode(this.typeNode) && this.typeNode.operator === ts.SyntaxKind.ReadonlyKeyword) {
|
|
249
|
-
return new TypeNodeResolver(this.typeNode.type, this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
250
|
-
}
|
|
251
265
|
if (ts.isIndexedAccessTypeNode(this.typeNode) &&
|
|
252
266
|
(this.typeNode.indexType.kind === ts.SyntaxKind.NumberKeyword ||
|
|
253
267
|
this.typeNode.indexType.kind === ts.SyntaxKind.StringKeyword)) {
|
|
@@ -283,7 +297,7 @@ class TypeNodeResolver {
|
|
|
283
297
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer || this.typeNode);
|
|
284
298
|
if (type.isUnion() && type.types.every((unionElementType) => unionElementType.isStringLiteral())) {
|
|
285
299
|
return {
|
|
286
|
-
typeName:
|
|
300
|
+
typeName: constants_1.TypeName.ENUM,
|
|
287
301
|
members: type.types.map((stringLiteralType) => stringLiteralType.value),
|
|
288
302
|
};
|
|
289
303
|
}
|
|
@@ -301,7 +315,7 @@ class TypeNodeResolver {
|
|
|
301
315
|
if (typeReference.typeName.text === 'Record') {
|
|
302
316
|
return {
|
|
303
317
|
additionalProperties: new TypeNodeResolver(typeReference.typeArguments[1], this.current, this.parentNode, this.context).resolve(),
|
|
304
|
-
typeName:
|
|
318
|
+
typeName: constants_1.TypeName.NESTED_OBJECT_LITERAL,
|
|
305
319
|
properties: [],
|
|
306
320
|
};
|
|
307
321
|
}
|
|
@@ -314,13 +328,13 @@ class TypeNodeResolver {
|
|
|
314
328
|
}
|
|
315
329
|
if (typeReference.typeName.text === 'Buffer' ||
|
|
316
330
|
typeReference.typeName.text === 'Readable') {
|
|
317
|
-
return { typeName:
|
|
331
|
+
return { typeName: constants_1.TypeName.BUFFER };
|
|
318
332
|
}
|
|
319
333
|
if (typeReference.typeName.text === 'Array' &&
|
|
320
334
|
typeReference.typeArguments &&
|
|
321
335
|
typeReference.typeArguments.length >= 1) {
|
|
322
336
|
return {
|
|
323
|
-
typeName:
|
|
337
|
+
typeName: constants_1.TypeName.ARRAY,
|
|
324
338
|
elementType: new TypeNodeResolver(typeReference.typeArguments[0], this.current, this.parentNode, this.context).resolve(),
|
|
325
339
|
};
|
|
326
340
|
}
|
|
@@ -330,7 +344,7 @@ class TypeNodeResolver {
|
|
|
330
344
|
return new TypeNodeResolver(typeReference.typeArguments[0], this.current, this.parentNode, this.context).resolve();
|
|
331
345
|
}
|
|
332
346
|
if (typeReference.typeName.text === 'String') {
|
|
333
|
-
return { typeName:
|
|
347
|
+
return { typeName: constants_1.TypeName.STRING };
|
|
334
348
|
}
|
|
335
349
|
if (this.context[typeReference.typeName.text]) {
|
|
336
350
|
return new TypeNodeResolver(this.context[typeReference.typeName.text], this.current, this.parentNode, this.context).resolve();
|
|
@@ -403,7 +417,7 @@ class TypeNodeResolver {
|
|
|
403
417
|
case 'Buffer':
|
|
404
418
|
case 'DownloadBinaryData':
|
|
405
419
|
case 'DownloadResource':
|
|
406
|
-
return { typeName:
|
|
420
|
+
return { typeName: constants_1.TypeName.BUFFER };
|
|
407
421
|
default:
|
|
408
422
|
return undefined;
|
|
409
423
|
}
|
|
@@ -439,7 +453,7 @@ class TypeNodeResolver {
|
|
|
439
453
|
getPrimitiveType(typeNode, parentNode) {
|
|
440
454
|
if (!typeNode) {
|
|
441
455
|
return {
|
|
442
|
-
typeName:
|
|
456
|
+
typeName: constants_1.TypeName.VOID,
|
|
443
457
|
};
|
|
444
458
|
}
|
|
445
459
|
const resolvedType = this.attemptToResolveKindToPrimitive(typeNode.kind);
|
|
@@ -448,7 +462,7 @@ class TypeNodeResolver {
|
|
|
448
462
|
}
|
|
449
463
|
if (resolvedType === 'number') {
|
|
450
464
|
if (!parentNode) {
|
|
451
|
-
return { typeName:
|
|
465
|
+
return { typeName: constants_1.TypeName.DOUBLE };
|
|
452
466
|
}
|
|
453
467
|
const lookupTags = [
|
|
454
468
|
'isInt',
|
|
@@ -474,38 +488,38 @@ class TypeNodeResolver {
|
|
|
474
488
|
}
|
|
475
489
|
}
|
|
476
490
|
if (!decoratorID && tags.length === 0) {
|
|
477
|
-
return { typeName:
|
|
491
|
+
return { typeName: constants_1.TypeName.DOUBLE };
|
|
478
492
|
}
|
|
479
493
|
switch (decoratorID || tags[0]) {
|
|
480
494
|
case decorator_1.DecoratorID.IS_INT:
|
|
481
495
|
case 'isint':
|
|
482
|
-
return { typeName:
|
|
496
|
+
return { typeName: constants_1.TypeName.INTEGER };
|
|
483
497
|
case decorator_1.DecoratorID.IS_LONG:
|
|
484
498
|
case 'islong':
|
|
485
|
-
return { typeName:
|
|
499
|
+
return { typeName: constants_1.TypeName.LONG };
|
|
486
500
|
case decorator_1.DecoratorID.IS_FLOAT:
|
|
487
501
|
case 'isfloat':
|
|
488
|
-
return { typeName:
|
|
502
|
+
return { typeName: constants_1.TypeName.FLOAT };
|
|
489
503
|
case decorator_1.DecoratorID.IS_DOUBLE:
|
|
490
504
|
case 'isdouble':
|
|
491
|
-
return { typeName:
|
|
505
|
+
return { typeName: constants_1.TypeName.DOUBLE };
|
|
492
506
|
default:
|
|
493
|
-
return { typeName:
|
|
507
|
+
return { typeName: constants_1.TypeName.DOUBLE };
|
|
494
508
|
}
|
|
495
509
|
}
|
|
496
510
|
else if (resolvedType === 'string') {
|
|
497
511
|
return {
|
|
498
|
-
typeName:
|
|
512
|
+
typeName: constants_1.TypeName.STRING,
|
|
499
513
|
};
|
|
500
514
|
}
|
|
501
515
|
else if (resolvedType === 'boolean') {
|
|
502
516
|
return {
|
|
503
|
-
typeName:
|
|
517
|
+
typeName: constants_1.TypeName.BOOLEAN,
|
|
504
518
|
};
|
|
505
519
|
}
|
|
506
520
|
else if (resolvedType === 'void') {
|
|
507
521
|
return {
|
|
508
|
-
typeName:
|
|
522
|
+
typeName: constants_1.TypeName.VOID,
|
|
509
523
|
};
|
|
510
524
|
}
|
|
511
525
|
else {
|
|
@@ -517,19 +531,17 @@ class TypeNodeResolver {
|
|
|
517
531
|
}
|
|
518
532
|
getDateType(parentNode) {
|
|
519
533
|
if (!parentNode) {
|
|
520
|
-
return { typeName:
|
|
534
|
+
return { typeName: constants_1.TypeName.DATETIME };
|
|
521
535
|
}
|
|
522
536
|
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter((name) => ['isDate', 'isDateTime'].some((m) => m === name));
|
|
523
537
|
if (tags.length === 0) {
|
|
524
|
-
return { typeName:
|
|
538
|
+
return { typeName: constants_1.TypeName.DATETIME };
|
|
525
539
|
}
|
|
526
540
|
switch (tags[0]) {
|
|
527
541
|
case 'isDate':
|
|
528
|
-
return { typeName:
|
|
529
|
-
case 'isDateTime':
|
|
530
|
-
return { typeName: 'datetime' };
|
|
542
|
+
return { typeName: constants_1.TypeName.DATE };
|
|
531
543
|
default:
|
|
532
|
-
return { typeName:
|
|
544
|
+
return { typeName: constants_1.TypeName.DATETIME };
|
|
533
545
|
}
|
|
534
546
|
}
|
|
535
547
|
static getDesignatedModels(nodes, typeName) {
|
|
@@ -550,7 +562,7 @@ class TypeNodeResolver {
|
|
|
550
562
|
const enums = enumDeclaration.members.map(this.current.typeChecker.getConstantValue.bind(this.current.typeChecker)).filter(isNotUndefined);
|
|
551
563
|
const enumNames = enumDeclaration.members.map((e) => e.name.getText()).filter(isNotUndefined);
|
|
552
564
|
return {
|
|
553
|
-
typeName:
|
|
565
|
+
typeName: constants_1.TypeName.REF_ENUM,
|
|
554
566
|
description: this.getNodeDescription(enumDeclaration),
|
|
555
567
|
members: enums,
|
|
556
568
|
memberNames: enumNames,
|
|
@@ -567,7 +579,7 @@ class TypeNodeResolver {
|
|
|
567
579
|
type = node.expression;
|
|
568
580
|
}
|
|
569
581
|
else {
|
|
570
|
-
throw new error_1.ResolverError('Can\'t resolve
|
|
582
|
+
throw new error_1.ResolverError('Can\'t resolve reference type.');
|
|
571
583
|
}
|
|
572
584
|
// Can't invoke getText on Synthetic Nodes
|
|
573
585
|
let resolvableName = node.pos !== -1 ? node.getText() : type.text;
|
|
@@ -631,7 +643,7 @@ class TypeNodeResolver {
|
|
|
631
643
|
}
|
|
632
644
|
else if (ts.isEnumMember(declaration)) {
|
|
633
645
|
referenceType = {
|
|
634
|
-
typeName:
|
|
646
|
+
typeName: constants_1.TypeName.REF_ENUM,
|
|
635
647
|
refName: TypeNodeResolver.getRefTypeName(name, utilityType),
|
|
636
648
|
members: [this.current.typeChecker.getConstantValue(declaration)],
|
|
637
649
|
memberNames: [declaration.name.getText()],
|
|
@@ -665,13 +677,13 @@ class TypeNodeResolver {
|
|
|
665
677
|
}
|
|
666
678
|
const example = this.getNodeExample(declaration);
|
|
667
679
|
return {
|
|
668
|
-
typeName:
|
|
680
|
+
typeName: constants_1.TypeName.REF_ALIAS,
|
|
669
681
|
default: (0, utils_1.getJSDocTagComment)(declaration, utils_1.JSDocTagName.DEFAULT),
|
|
670
682
|
description: this.getNodeDescription(declaration),
|
|
671
683
|
refName,
|
|
672
684
|
format: TypeNodeResolver.getNodeFormat(declaration),
|
|
673
685
|
type,
|
|
674
|
-
validators:
|
|
686
|
+
validators: (0, utils_1.getDeclarationValidators)(declaration) || {},
|
|
675
687
|
deprecated: (0, utils_1.hasJSDocTag)(declaration, utils_1.JSDocTagName.DEPRECATED),
|
|
676
688
|
...(example && { example }),
|
|
677
689
|
};
|
|
@@ -699,7 +711,7 @@ class TypeNodeResolver {
|
|
|
699
711
|
}
|
|
700
712
|
return {
|
|
701
713
|
refName: `${TypeNodeResolver.getRefTypeName(name, utilityType)}Alias`,
|
|
702
|
-
typeName:
|
|
714
|
+
typeName: constants_1.TypeName.REF_ALIAS,
|
|
703
715
|
description,
|
|
704
716
|
type: new TypeNodeResolver(nodeType, this.current).resolve(),
|
|
705
717
|
deprecated,
|
|
@@ -712,7 +724,7 @@ class TypeNodeResolver {
|
|
|
712
724
|
const inheritedProperties = this.getModelInheritedProperties(modelType) || [];
|
|
713
725
|
const referenceType = {
|
|
714
726
|
additionalProperties,
|
|
715
|
-
typeName:
|
|
727
|
+
typeName: constants_1.TypeName.REF_OBJECT,
|
|
716
728
|
description,
|
|
717
729
|
properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions),
|
|
718
730
|
refName: TypeNodeResolver.getRefTypeName(name, utilityType),
|
|
@@ -769,7 +781,7 @@ class TypeNodeResolver {
|
|
|
769
781
|
}
|
|
770
782
|
createCircularDependencyResolver(refName) {
|
|
771
783
|
const referenceType = {
|
|
772
|
-
typeName:
|
|
784
|
+
typeName: constants_1.TypeName.REF_OBJECT,
|
|
773
785
|
refName,
|
|
774
786
|
};
|
|
775
787
|
this.current.registerDependencyResolver((referenceTypes) => {
|
|
@@ -878,11 +890,12 @@ class TypeNodeResolver {
|
|
|
878
890
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, utils_1.JSDocTagName.DEFAULT),
|
|
879
891
|
description: this.getNodeDescription(propertySignature),
|
|
880
892
|
example: this.getNodeExample(propertySignature),
|
|
893
|
+
extensions: this.getNodeExtensions(propertySignature),
|
|
881
894
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
882
895
|
name: identifier.text,
|
|
883
896
|
required,
|
|
884
897
|
type: new TypeNodeResolver(propertySignature.type, this.current, propertySignature.type.parent, this.context, propertySignature.type).resolve(),
|
|
885
|
-
validators:
|
|
898
|
+
validators: (0, utils_1.getDeclarationValidators)(propertySignature) || {},
|
|
886
899
|
};
|
|
887
900
|
return property;
|
|
888
901
|
}
|
|
@@ -917,11 +930,12 @@ class TypeNodeResolver {
|
|
|
917
930
|
default: (0, utils_1.getInitializerValue)(propertyDeclaration.initializer, this.current.typeChecker),
|
|
918
931
|
description: this.getNodeDescription(propertyDeclaration),
|
|
919
932
|
example: this.getNodeExample(propertyDeclaration),
|
|
933
|
+
extensions: this.getNodeExtensions(propertyDeclaration),
|
|
920
934
|
format: TypeNodeResolver.getNodeFormat(propertyDeclaration),
|
|
921
935
|
name: identifier.text,
|
|
922
936
|
required,
|
|
923
937
|
type,
|
|
924
|
-
validators:
|
|
938
|
+
validators: (0, utils_1.getDeclarationValidators)(propertyDeclaration) || {},
|
|
925
939
|
};
|
|
926
940
|
return property;
|
|
927
941
|
}
|
|
@@ -989,27 +1003,21 @@ class TypeNodeResolver {
|
|
|
989
1003
|
const resetCtx = this.typeArgumentsToContext(t, baseEntityName, this.context);
|
|
990
1004
|
const referenceType = this.getReferenceType(t);
|
|
991
1005
|
if (referenceType) {
|
|
992
|
-
if (
|
|
993
|
-
// since it doesn't have properties to iterate over, then we don't do anything with it
|
|
994
|
-
}
|
|
995
|
-
else if (referenceType.typeName === 'refAlias') {
|
|
1006
|
+
if ((0, type_1.isRefAliasType)(referenceType)) {
|
|
996
1007
|
let type = referenceType;
|
|
997
|
-
while (
|
|
1008
|
+
while ((0, type_1.isRefAliasType)(type)) {
|
|
998
1009
|
type = type.type;
|
|
999
1010
|
}
|
|
1000
|
-
if (type.typeName ===
|
|
1011
|
+
if (type.typeName === constants_1.TypeName.REF_OBJECT) {
|
|
1001
1012
|
properties = [...properties, ...type.properties];
|
|
1002
1013
|
}
|
|
1003
|
-
else if (type.typeName ===
|
|
1014
|
+
else if (type.typeName === constants_1.TypeName.NESTED_OBJECT_LITERAL) {
|
|
1004
1015
|
properties = [...properties, ...type.properties];
|
|
1005
1016
|
}
|
|
1006
1017
|
}
|
|
1007
|
-
|
|
1018
|
+
if ((0, type_1.isRefObjectType)(referenceType)) {
|
|
1008
1019
|
referenceType.properties.forEach((property) => properties.push(property));
|
|
1009
1020
|
}
|
|
1010
|
-
else {
|
|
1011
|
-
// todo: should never assert
|
|
1012
|
-
}
|
|
1013
1021
|
}
|
|
1014
1022
|
// reset subContext
|
|
1015
1023
|
this.context = resetCtx;
|
|
@@ -1087,6 +1095,9 @@ class TypeNodeResolver {
|
|
|
1087
1095
|
}
|
|
1088
1096
|
return undefined;
|
|
1089
1097
|
}
|
|
1098
|
+
getNodeExtensions(node) {
|
|
1099
|
+
return (0, extension_1.getNodeExtensions)(node, this.current.decoratorResolver);
|
|
1100
|
+
}
|
|
1090
1101
|
}
|
|
1091
1102
|
exports.TypeNodeResolver = TypeNodeResolver;
|
|
1092
1103
|
//# sourceMappingURL=module.js.map
|