@trapi/metadata 0.1.6 → 0.2.0
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/README.md +7 -13
- package/dist/cache/driver.d.ts +1 -1
- package/dist/cache/driver.d.ts.map +1 -1
- package/dist/cache/driver.js +8 -6
- package/dist/cache/driver.js.map +1 -1
- package/dist/cache/index.js +5 -1
- package/dist/cache/index.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 +3 -3
- package/dist/cache/utils.js.map +1 -1
- package/dist/config/index.js +5 -1
- package/dist/config/index.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.js +5 -1
- 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 +5 -9
- 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.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 +3 -3
- package/dist/decorator/representation/property/utils.js.map +1 -1
- package/dist/decorator/type.d.ts.map +1 -1
- package/dist/decorator/utils/index.js +5 -1
- package/dist/decorator/utils/index.js.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.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 -16
- package/dist/generator/endpoint.js.map +1 -1
- package/dist/generator/index.js +5 -1
- 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 +15 -11
- package/dist/generator/method.js.map +1 -1
- package/dist/generator/module.d.ts +3 -3
- package/dist/generator/module.d.ts.map +1 -1
- package/dist/generator/module.js +16 -16
- package/dist/generator/module.js.map +1 -1
- package/dist/generator/parameter.d.ts +1 -1
- package/dist/generator/parameter.d.ts.map +1 -1
- package/dist/generator/parameter.js +31 -28
- package/dist/generator/parameter.js.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/resolver/index.js +5 -1
- package/dist/resolver/index.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 +111 -139
- 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/index.js +5 -1
- package/dist/resolver/utils/index.js.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 +16 -14
- 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 +6 -10
- package/dist/resolver/utils/validator.js.map +1 -1
- package/dist/type.d.ts +5 -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 +1 -1
- package/dist/utils/generator.js.map +1 -1
- package/dist/utils/index.js +5 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/js-doc.d.ts.map +1 -1
- package/dist/utils/js-doc.js +6 -10
- 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 +17 -13
|
@@ -7,7 +7,11 @@
|
|
|
7
7
|
*/
|
|
8
8
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
9
|
if (k2 === undefined) k2 = k;
|
|
10
|
-
Object.
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
11
15
|
}) : (function(o, m, k, k2) {
|
|
12
16
|
if (k2 === undefined) k2 = k;
|
|
13
17
|
o[k2] = m[k];
|
|
@@ -28,10 +32,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
32
|
exports.TypeNodeResolver = void 0;
|
|
29
33
|
const ts = __importStar(require("typescript"));
|
|
30
34
|
const metadata_utils_1 = require("@trapi/metadata-utils");
|
|
35
|
+
const decorator_1 = require("../decorator");
|
|
31
36
|
const utils_1 = require("../utils");
|
|
32
37
|
const error_1 = require("./error");
|
|
33
38
|
const utils_2 = require("./utils");
|
|
34
|
-
const decorator_1 = require("../decorator");
|
|
35
39
|
const localReferenceTypeCache = {};
|
|
36
40
|
const inProgressTypes = {};
|
|
37
41
|
function getPropertyValidators(property) {
|
|
@@ -48,25 +52,23 @@ class TypeNodeResolver {
|
|
|
48
52
|
if (syntaxKind === ts.SyntaxKind.NumberKeyword) {
|
|
49
53
|
return 'number';
|
|
50
54
|
}
|
|
51
|
-
|
|
55
|
+
if (syntaxKind === ts.SyntaxKind.StringKeyword) {
|
|
52
56
|
return 'string';
|
|
53
57
|
}
|
|
54
|
-
|
|
58
|
+
if (syntaxKind === ts.SyntaxKind.BooleanKeyword) {
|
|
55
59
|
return 'boolean';
|
|
56
60
|
}
|
|
57
|
-
|
|
61
|
+
if (syntaxKind === ts.SyntaxKind.VoidKeyword) {
|
|
58
62
|
return 'void';
|
|
59
63
|
}
|
|
60
|
-
|
|
61
|
-
return undefined;
|
|
62
|
-
}
|
|
64
|
+
return undefined;
|
|
63
65
|
};
|
|
64
66
|
}
|
|
65
67
|
static clearCache() {
|
|
66
|
-
Object.keys(localReferenceTypeCache).forEach(key => {
|
|
68
|
+
Object.keys(localReferenceTypeCache).forEach((key) => {
|
|
67
69
|
delete localReferenceTypeCache[key];
|
|
68
70
|
});
|
|
69
|
-
Object.keys(inProgressTypes).forEach(key => {
|
|
71
|
+
Object.keys(inProgressTypes).forEach((key) => {
|
|
70
72
|
delete inProgressTypes[key];
|
|
71
73
|
});
|
|
72
74
|
}
|
|
@@ -88,18 +90,14 @@ class TypeNodeResolver {
|
|
|
88
90
|
};
|
|
89
91
|
}
|
|
90
92
|
if (ts.isUnionTypeNode(this.typeNode)) {
|
|
91
|
-
const types = this.typeNode.types.map(type =>
|
|
92
|
-
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve();
|
|
93
|
-
});
|
|
93
|
+
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
94
94
|
return {
|
|
95
95
|
typeName: 'union',
|
|
96
96
|
members: types,
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
99
|
if (ts.isIntersectionTypeNode(this.typeNode)) {
|
|
100
|
-
const types = this.typeNode.types.map(type =>
|
|
101
|
-
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve();
|
|
102
|
-
});
|
|
100
|
+
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
103
101
|
return {
|
|
104
102
|
typeName: 'intersection',
|
|
105
103
|
members: types,
|
|
@@ -118,36 +116,36 @@ class TypeNodeResolver {
|
|
|
118
116
|
}
|
|
119
117
|
if (ts.isTypeLiteralNode(this.typeNode)) {
|
|
120
118
|
const properties = this.typeNode.members
|
|
121
|
-
.filter(member => ts.isPropertySignature(member))
|
|
119
|
+
.filter((member) => ts.isPropertySignature(member))
|
|
122
120
|
.reduce((res, propertySignature) => {
|
|
123
121
|
const type = new TypeNodeResolver(propertySignature.type, this.current, propertySignature, this.context).resolve();
|
|
124
122
|
const property = {
|
|
125
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'),
|
|
123
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'),
|
|
126
124
|
example: TypeNodeResolver.getNodeExample(propertySignature),
|
|
127
125
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'),
|
|
128
126
|
description: this.getNodeDescription(propertySignature),
|
|
129
127
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
130
128
|
name: propertySignature.name.text,
|
|
131
129
|
required: !propertySignature.questionToken,
|
|
132
|
-
type
|
|
133
|
-
validators: getPropertyValidators(propertySignature) || {}
|
|
130
|
+
type,
|
|
131
|
+
validators: getPropertyValidators(propertySignature) || {},
|
|
134
132
|
};
|
|
135
133
|
return [property, ...res];
|
|
136
134
|
}, []);
|
|
137
|
-
const indexMember = this.typeNode.members.find(member => ts.isIndexSignatureDeclaration(member));
|
|
135
|
+
const indexMember = this.typeNode.members.find((member) => ts.isIndexSignatureDeclaration(member));
|
|
138
136
|
let additionalType;
|
|
139
137
|
if (indexMember) {
|
|
140
138
|
const indexSignatureDeclaration = indexMember;
|
|
141
139
|
const indexType = new TypeNodeResolver(indexSignatureDeclaration.parameters[0].type, this.current, this.parentNode, this.context).resolve();
|
|
142
140
|
if (indexType.typeName !== 'string') {
|
|
143
|
-
throw new error_1.ResolverError(
|
|
141
|
+
throw new error_1.ResolverError('Only string indexes are supported.', this.typeNode);
|
|
144
142
|
}
|
|
145
143
|
additionalType = new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve();
|
|
146
144
|
}
|
|
147
145
|
return {
|
|
148
146
|
additionalProperties: indexMember && additionalType,
|
|
149
147
|
typeName: 'nestedObjectLiteral',
|
|
150
|
-
properties
|
|
148
|
+
properties,
|
|
151
149
|
};
|
|
152
150
|
}
|
|
153
151
|
if (this.typeNode.kind === ts.SyntaxKind.ObjectKeyword || ts.isFunctionTypeNode(this.typeNode)) {
|
|
@@ -156,25 +154,25 @@ class TypeNodeResolver {
|
|
|
156
154
|
if (ts.isMappedTypeNode(this.typeNode) && this.referencer) {
|
|
157
155
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer);
|
|
158
156
|
const mappedTypeNode = this.typeNode;
|
|
159
|
-
const typeChecker = this.current
|
|
157
|
+
const { typeChecker } = this.current;
|
|
160
158
|
const getDeclaration = (prop) => prop.declarations && prop.declarations[0];
|
|
161
159
|
const isIgnored = (prop) => {
|
|
162
160
|
const declaration = getDeclaration(prop);
|
|
163
|
-
return (prop.getJsDocTags().find(tag => tag.name === 'ignore') !== undefined ||
|
|
161
|
+
return (prop.getJsDocTags().find((tag) => tag.name === 'ignore') !== undefined ||
|
|
164
162
|
(declaration !== undefined && !ts.isPropertyDeclaration(declaration) && !ts.isPropertySignature(declaration) && !ts.isParameter(declaration)));
|
|
165
163
|
};
|
|
166
164
|
const properties = type
|
|
167
165
|
.getProperties()
|
|
168
166
|
// Ignore methods, getter, setter and @ignored props
|
|
169
|
-
.filter(property => isIgnored(property) === false)
|
|
167
|
+
.filter((property) => isIgnored(property) === false)
|
|
170
168
|
// Transform to property
|
|
171
|
-
.map(property => {
|
|
169
|
+
.map((property) => {
|
|
172
170
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, this.typeNode);
|
|
173
171
|
const declaration = getDeclaration(property);
|
|
174
172
|
if (declaration && ts.isPropertySignature(declaration)) {
|
|
175
173
|
return Object.assign(Object.assign({}, this.propertyFromSignature(declaration, mappedTypeNode.questionToken)), { name: property.getName() });
|
|
176
174
|
}
|
|
177
|
-
|
|
175
|
+
if (declaration && (ts.isPropertyDeclaration(declaration) || ts.isParameter(declaration))) {
|
|
178
176
|
return Object.assign(Object.assign({}, this.propertyFromDeclaration(declaration, mappedTypeNode.questionToken)), { name: property.getName() });
|
|
179
177
|
}
|
|
180
178
|
// Resolve default value, required and typeNode
|
|
@@ -189,7 +187,7 @@ class TypeNodeResolver {
|
|
|
189
187
|
// Push property
|
|
190
188
|
return {
|
|
191
189
|
name: property.getName(),
|
|
192
|
-
required
|
|
190
|
+
required,
|
|
193
191
|
deprecated: false,
|
|
194
192
|
type: new TypeNodeResolver(typeNode, this.current, this.typeNode, this.context, this.referencer).resolve(),
|
|
195
193
|
validators: {},
|
|
@@ -197,7 +195,7 @@ class TypeNodeResolver {
|
|
|
197
195
|
});
|
|
198
196
|
return {
|
|
199
197
|
typeName: 'nestedObjectLiteral',
|
|
200
|
-
properties
|
|
198
|
+
properties,
|
|
201
199
|
};
|
|
202
200
|
}
|
|
203
201
|
if (ts.isConditionalTypeNode(this.typeNode) && this.referencer && ts.isTypeReferenceNode(this.referencer)) {
|
|
@@ -213,15 +211,13 @@ class TypeNodeResolver {
|
|
|
213
211
|
// Note: I don't understand why typescript lose type for `this.referencer` (from above with isTypeReferenceNode())
|
|
214
212
|
return this.getTypeAliasReference(declaration, this.current.typeChecker.typeToString(type), this.referencer);
|
|
215
213
|
}
|
|
216
|
-
|
|
214
|
+
if (ts.isEnumDeclaration(declaration)) {
|
|
217
215
|
return this.getEnumerateType(declaration.name);
|
|
218
216
|
}
|
|
219
|
-
|
|
220
|
-
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. We found an aliasSymbol and it's declaration was of kind ${declaration.kind}`, this.typeNode);
|
|
221
|
-
}
|
|
217
|
+
throw new error_1.ResolverError(`Couldn't resolve Conditional to TypeNode. If you think this should be resolvable, please file an Issue. We found an aliasSymbol and it's declaration was of kind ${declaration.kind}`, this.typeNode);
|
|
222
218
|
});
|
|
223
219
|
}
|
|
224
|
-
|
|
220
|
+
if (type.isClassOrInterface()) {
|
|
225
221
|
let declaration = type.symbol.declarations[0];
|
|
226
222
|
if (declaration.name) {
|
|
227
223
|
declaration = this.getModelTypeDeclaration(declaration.name);
|
|
@@ -229,13 +225,11 @@ class TypeNodeResolver {
|
|
|
229
225
|
const name = TypeNodeResolver.getRefTypeName(this.referencer.getText());
|
|
230
226
|
return this.handleCachingAndCircularReferences(name, () => this.getModelReference(declaration, this.current.typeChecker.typeToString(type)));
|
|
231
227
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
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);
|
|
238
|
-
}
|
|
228
|
+
try {
|
|
229
|
+
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation), this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
230
|
+
}
|
|
231
|
+
catch (_a) {
|
|
232
|
+
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);
|
|
239
233
|
}
|
|
240
234
|
}
|
|
241
235
|
if (ts.isTypeOperatorNode(this.typeNode) && this.typeNode.operator === ts.SyntaxKind.KeyOfKeyword) {
|
|
@@ -279,15 +273,13 @@ class TypeNodeResolver {
|
|
|
279
273
|
// @ts-ignore
|
|
280
274
|
if (this.typeNode.kind === ts.SyntaxKind.TemplateLiteralType) {
|
|
281
275
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer || this.typeNode);
|
|
282
|
-
if (type.isUnion() && type.types.every(unionElementType => unionElementType.isStringLiteral())) {
|
|
276
|
+
if (type.isUnion() && type.types.every((unionElementType) => unionElementType.isStringLiteral())) {
|
|
283
277
|
return {
|
|
284
278
|
typeName: 'enum',
|
|
285
279
|
members: type.types.map((stringLiteralType) => stringLiteralType.value),
|
|
286
280
|
};
|
|
287
281
|
}
|
|
288
|
-
|
|
289
|
-
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode);
|
|
290
|
-
}
|
|
282
|
+
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode);
|
|
291
283
|
}
|
|
292
284
|
if (ts.isParenthesizedTypeNode(this.typeNode)) {
|
|
293
285
|
return new TypeNodeResolver(this.typeNode.type, this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
@@ -346,19 +338,19 @@ class TypeNodeResolver {
|
|
|
346
338
|
}
|
|
347
339
|
static getUtilityTypeOptions(typeArguments) {
|
|
348
340
|
const utilityOptions = {
|
|
349
|
-
keys: []
|
|
341
|
+
keys: [],
|
|
350
342
|
};
|
|
351
343
|
if (typeArguments.length >= 2) {
|
|
352
344
|
if (ts.isUnionTypeNode(typeArguments[1])) {
|
|
353
345
|
const args = typeArguments[1].types;
|
|
354
346
|
for (let i = 0; i < args.length; i++) {
|
|
355
347
|
if (ts.isLiteralTypeNode(args[i])) {
|
|
356
|
-
utilityOptions
|
|
348
|
+
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(args[i]));
|
|
357
349
|
}
|
|
358
350
|
}
|
|
359
351
|
}
|
|
360
352
|
if (ts.isLiteralTypeNode(typeArguments[1])) {
|
|
361
|
-
utilityOptions
|
|
353
|
+
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(typeArguments[1]));
|
|
362
354
|
}
|
|
363
355
|
}
|
|
364
356
|
return utilityOptions;
|
|
@@ -368,7 +360,7 @@ class TypeNodeResolver {
|
|
|
368
360
|
return properties;
|
|
369
361
|
}
|
|
370
362
|
return properties
|
|
371
|
-
.filter(property => {
|
|
363
|
+
.filter((property) => {
|
|
372
364
|
const name = typeof property.name !== 'string' ? property.name.text : property.name;
|
|
373
365
|
switch (utilityType) {
|
|
374
366
|
case 'Pick':
|
|
@@ -378,7 +370,7 @@ class TypeNodeResolver {
|
|
|
378
370
|
}
|
|
379
371
|
return true;
|
|
380
372
|
})
|
|
381
|
-
.map(property => {
|
|
373
|
+
.map((property) => {
|
|
382
374
|
if ((0, metadata_utils_1.hasOwnProperty)(property, 'required')) {
|
|
383
375
|
switch (utilityType) {
|
|
384
376
|
case 'Partial':
|
|
@@ -446,21 +438,19 @@ class TypeNodeResolver {
|
|
|
446
438
|
return { typeName: 'double' };
|
|
447
439
|
}
|
|
448
440
|
const tags = (0, utils_1.getJSDocTagNames)(parentNode)
|
|
449
|
-
.filter(name =>
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
.map(name => name.toLowerCase());
|
|
458
|
-
const data = (0, decorator_1.getNodeDecorators)(parentNode, identifier => [
|
|
441
|
+
.filter((name) => [
|
|
442
|
+
'isInt',
|
|
443
|
+
'isLong',
|
|
444
|
+
'isFloat',
|
|
445
|
+
'isDouble',
|
|
446
|
+
].some((m) => m.toLowerCase() === name.toLowerCase()))
|
|
447
|
+
.map((name) => name.toLowerCase());
|
|
448
|
+
const data = (0, decorator_1.getNodeDecorators)(parentNode, (identifier) => [
|
|
459
449
|
'isInt',
|
|
460
450
|
'isLong',
|
|
461
451
|
'isFloat',
|
|
462
|
-
'isDouble'
|
|
463
|
-
].some(m => m.toLowerCase() === identifier.text.toLowerCase()));
|
|
452
|
+
'isDouble',
|
|
453
|
+
].some((m) => m.toLowerCase() === identifier.text.toLowerCase()));
|
|
464
454
|
let decorator = data.length > 0 ? data[0].text : undefined;
|
|
465
455
|
if (typeof decorator !== 'undefined') {
|
|
466
456
|
decorator = decorator.toLowerCase();
|
|
@@ -505,9 +495,7 @@ class TypeNodeResolver {
|
|
|
505
495
|
if (!parentNode) {
|
|
506
496
|
return { typeName: 'datetime' };
|
|
507
497
|
}
|
|
508
|
-
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter(name =>
|
|
509
|
-
return ['isDate', 'isDateTime'].some(m => m === name);
|
|
510
|
-
});
|
|
498
|
+
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter((name) => ['isDate', 'isDateTime'].some((m) => m === name));
|
|
511
499
|
if (tags.length === 0) {
|
|
512
500
|
return { typeName: 'datetime' };
|
|
513
501
|
}
|
|
@@ -525,7 +513,7 @@ class TypeNodeResolver {
|
|
|
525
513
|
}
|
|
526
514
|
getEnumerateType(typeName) {
|
|
527
515
|
const enumName = typeName.text;
|
|
528
|
-
let enumNodes = this.current.nodes.filter(node => node.kind === ts.SyntaxKind.EnumDeclaration).filter(node => node.name.text === enumName);
|
|
516
|
+
let enumNodes = this.current.nodes.filter((node) => node.kind === ts.SyntaxKind.EnumDeclaration).filter((node) => node.name.text === enumName);
|
|
529
517
|
if (!enumNodes.length) {
|
|
530
518
|
return undefined;
|
|
531
519
|
}
|
|
@@ -534,18 +522,16 @@ class TypeNodeResolver {
|
|
|
534
522
|
throw new error_1.ResolverError(`Multiple matching enum found for enum ${enumName}; please make enum names unique.`);
|
|
535
523
|
}
|
|
536
524
|
const enumDeclaration = enumNodes[0];
|
|
537
|
-
const isNotUndefined = (item) =>
|
|
538
|
-
return item !== undefined;
|
|
539
|
-
};
|
|
525
|
+
const isNotUndefined = (item) => item !== undefined;
|
|
540
526
|
const enums = enumDeclaration.members.map(this.current.typeChecker.getConstantValue.bind(this.current.typeChecker)).filter(isNotUndefined);
|
|
541
|
-
const enumNames = enumDeclaration.members.map(e => e.name.getText()).filter(isNotUndefined);
|
|
527
|
+
const enumNames = enumDeclaration.members.map((e) => e.name.getText()).filter(isNotUndefined);
|
|
542
528
|
return {
|
|
543
529
|
typeName: 'refEnum',
|
|
544
530
|
description: this.getNodeDescription(enumDeclaration),
|
|
545
531
|
members: enums,
|
|
546
532
|
memberNames: enumNames,
|
|
547
533
|
refName: enumName,
|
|
548
|
-
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, tag => tag.tagName.text === 'deprecated')
|
|
534
|
+
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
549
535
|
};
|
|
550
536
|
}
|
|
551
537
|
getReferenceType(node) {
|
|
@@ -557,14 +543,14 @@ class TypeNodeResolver {
|
|
|
557
543
|
type = node.expression;
|
|
558
544
|
}
|
|
559
545
|
else {
|
|
560
|
-
throw new error_1.ResolverError(
|
|
546
|
+
throw new error_1.ResolverError('Can\'t resolve Reference type.');
|
|
561
547
|
}
|
|
562
548
|
// Can't invoke getText on Synthetic Nodes
|
|
563
549
|
let resolvableName = node.pos !== -1 ? node.getText() : type.text;
|
|
564
550
|
if (node.pos === -1 && 'typeArguments' in node && Array.isArray(node.typeArguments)) {
|
|
565
551
|
// Add typeArguments for Synthetic nodes (e.g. Record<> in TestClassModel.indexedResponse)
|
|
566
552
|
const argumentsString = node.typeArguments
|
|
567
|
-
.map(arg => {
|
|
553
|
+
.map((arg) => {
|
|
568
554
|
if (ts.isLiteralTypeNode(arg)) {
|
|
569
555
|
return `'${String(TypeNodeResolver.getLiteralValue(arg))}'`;
|
|
570
556
|
}
|
|
@@ -582,10 +568,10 @@ class TypeNodeResolver {
|
|
|
582
568
|
const utilityTypeSupported = TypeNodeResolver.isSupportedUtilityType(identifierName);
|
|
583
569
|
const utilityType = utilityTypeSupported ? identifierName : undefined;
|
|
584
570
|
let utilityOptions = {
|
|
585
|
-
keys: []
|
|
571
|
+
keys: [],
|
|
586
572
|
};
|
|
587
573
|
if (utilityTypeSupported) {
|
|
588
|
-
const typeArguments = type.parent
|
|
574
|
+
const { typeArguments } = type.parent;
|
|
589
575
|
if (ts.isTypeReferenceNode(typeArguments[0])) {
|
|
590
576
|
type = typeArguments[0].typeName;
|
|
591
577
|
}
|
|
@@ -593,7 +579,7 @@ class TypeNodeResolver {
|
|
|
593
579
|
type = typeArguments[0].expression;
|
|
594
580
|
}
|
|
595
581
|
else {
|
|
596
|
-
throw new error_1.ResolverError(
|
|
582
|
+
throw new error_1.ResolverError('Can\'t resolve Reference type.');
|
|
597
583
|
}
|
|
598
584
|
utilityOptions = TypeNodeResolver.getUtilityTypeOptions(typeArguments);
|
|
599
585
|
}
|
|
@@ -626,7 +612,7 @@ class TypeNodeResolver {
|
|
|
626
612
|
members: [this.current.typeChecker.getConstantValue(declaration)],
|
|
627
613
|
// @ts-ignore
|
|
628
614
|
memberNames: [declaration.name.getText()],
|
|
629
|
-
deprecated: (0, utils_1.isExistJSDocTag)(declaration, tag => tag.tagName.text === 'deprecated')
|
|
615
|
+
deprecated: (0, utils_1.isExistJSDocTag)(declaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
630
616
|
};
|
|
631
617
|
}
|
|
632
618
|
else {
|
|
@@ -654,15 +640,15 @@ class TypeNodeResolver {
|
|
|
654
640
|
type = new TypeNodeResolver(declaration.type, this.current, declaration, this.context, this.referencer || referencer).resolve();
|
|
655
641
|
}
|
|
656
642
|
const example = TypeNodeResolver.getNodeExample(declaration);
|
|
657
|
-
return Object.assign({ typeName: 'refAlias', default: (0, utils_1.getJSDocTagComment)(declaration, 'default'), description: this.getNodeDescription(declaration), refName
|
|
643
|
+
return Object.assign({ typeName: 'refAlias', default: (0, utils_1.getJSDocTagComment)(declaration, 'default'), description: this.getNodeDescription(declaration), refName, format: TypeNodeResolver.getNodeFormat(declaration), type, validators: getPropertyValidators(declaration) || {}, deprecated: (0, utils_1.isExistJSDocTag)(declaration, (tag) => tag.tagName.text === 'deprecated') }, (example && { example }));
|
|
658
644
|
}
|
|
659
645
|
getModelReference(modelType, name, utilityType, utilityOptions) {
|
|
660
646
|
const example = TypeNodeResolver.getNodeExample(modelType);
|
|
661
647
|
const description = this.getNodeDescription(modelType);
|
|
662
|
-
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, tag => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined';
|
|
648
|
+
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, (tag) => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined';
|
|
663
649
|
// Handle toJSON methods
|
|
664
650
|
if (!modelType.name) {
|
|
665
|
-
throw new error_1.ResolverError(
|
|
651
|
+
throw new error_1.ResolverError('Can\'t get Symbol from anonymous class', modelType);
|
|
666
652
|
}
|
|
667
653
|
const type = this.current.typeChecker.getTypeAtLocation(modelType.name);
|
|
668
654
|
const toJSON = this.current.typeChecker.getPropertyOfType(type, 'toJSON');
|
|
@@ -673,12 +659,12 @@ class TypeNodeResolver {
|
|
|
673
659
|
const implicitType = this.current.typeChecker.getReturnTypeOfSignature(signature);
|
|
674
660
|
nodeType = this.current.typeChecker.typeToTypeNode(implicitType, undefined, ts.NodeBuilderFlags.NoTruncation);
|
|
675
661
|
}
|
|
676
|
-
return Object.assign({ refName: TypeNodeResolver.getRefTypeName(name, utilityType)
|
|
662
|
+
return Object.assign({ refName: `${TypeNodeResolver.getRefTypeName(name, utilityType)}Alias`, typeName: 'refAlias', description, type: new TypeNodeResolver(nodeType, this.current).resolve(), deprecated, validators: {} }, (example && { example }));
|
|
677
663
|
}
|
|
678
664
|
const properties = this.getModelProperties(modelType, undefined, utilityType, utilityOptions);
|
|
679
665
|
const additionalProperties = this.getModelAdditionalProperties(modelType);
|
|
680
666
|
const inheritedProperties = this.getModelInheritedProperties(modelType) || [];
|
|
681
|
-
const referenceType = Object.assign({ additionalProperties
|
|
667
|
+
const referenceType = Object.assign({ additionalProperties, typeName: 'refObject', description, properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions), refName: TypeNodeResolver.getRefTypeName(name, utilityType), deprecated }, (example && { example }));
|
|
682
668
|
referenceType.properties = referenceType.properties.concat(properties);
|
|
683
669
|
return referenceType;
|
|
684
670
|
}
|
|
@@ -700,13 +686,11 @@ class TypeNodeResolver {
|
|
|
700
686
|
.replace(/-/g, ''));
|
|
701
687
|
}
|
|
702
688
|
contextualizedName(name) {
|
|
703
|
-
return Object.entries(this.context).reduce((acc, [key, entry]) =>
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`);
|
|
709
|
-
}, name);
|
|
689
|
+
return Object.entries(this.context).reduce((acc, [key, entry]) => acc
|
|
690
|
+
.replace(new RegExp(`<\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `<$1${entry.getText()}$3>`)
|
|
691
|
+
.replace(new RegExp(`<\\s*([^,]*\\s)*\\s*(${key})(\\s[^,]*)*\\s*,`, 'g'), `<$1${entry.getText()}$3,`)
|
|
692
|
+
.replace(new RegExp(`,\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `,$1${entry.getText()}$3>`)
|
|
693
|
+
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`), name);
|
|
710
694
|
}
|
|
711
695
|
handleCachingAndCircularReferences(name, declarationResolver) {
|
|
712
696
|
try {
|
|
@@ -732,9 +716,9 @@ class TypeNodeResolver {
|
|
|
732
716
|
createCircularDependencyResolver(refName) {
|
|
733
717
|
const referenceType = {
|
|
734
718
|
typeName: 'refObject',
|
|
735
|
-
refName
|
|
719
|
+
refName,
|
|
736
720
|
};
|
|
737
|
-
this.current.registerDependencyResolver(referenceTypes => {
|
|
721
|
+
this.current.registerDependencyResolver((referenceTypes) => {
|
|
738
722
|
const realReferenceType = referenceTypes[refName];
|
|
739
723
|
if (!realReferenceType) {
|
|
740
724
|
return;
|
|
@@ -788,16 +772,14 @@ class TypeNodeResolver {
|
|
|
788
772
|
const leftmostName = leftmost.kind === ts.SyntaxKind.Identifier ? leftmost.text : leftmost.right.text;
|
|
789
773
|
const moduleDeclarations = this.findMatchingModuleOrEnumDeclaration(statements, leftmostName);
|
|
790
774
|
if (moduleDeclarations.length > 0) {
|
|
791
|
-
statements = Array.prototype.concat(...moduleDeclarations.map(declaration => {
|
|
775
|
+
statements = Array.prototype.concat(...moduleDeclarations.map((declaration) => {
|
|
792
776
|
if (ts.isEnumDeclaration(declaration)) {
|
|
793
777
|
return declaration.members;
|
|
794
778
|
}
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`);
|
|
798
|
-
}
|
|
799
|
-
return declaration.body.statements;
|
|
779
|
+
if (!declaration.body || !ts.isModuleBlock(declaration.body)) {
|
|
780
|
+
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`);
|
|
800
781
|
}
|
|
782
|
+
return declaration.body.statements;
|
|
801
783
|
}));
|
|
802
784
|
}
|
|
803
785
|
leftmost = leftmost.parent;
|
|
@@ -808,7 +790,7 @@ class TypeNodeResolver {
|
|
|
808
790
|
const leftmostIdentifier = TypeNodeResolver.resolveLeftmostIdentifier(type);
|
|
809
791
|
const statements = this.resolveModelTypeScope(leftmostIdentifier, this.current.nodes);
|
|
810
792
|
const typeName = type.kind === ts.SyntaxKind.Identifier ? type.text : type.right.text;
|
|
811
|
-
let modelTypes = statements.filter(node => {
|
|
793
|
+
let modelTypes = statements.filter((node) => {
|
|
812
794
|
var _a;
|
|
813
795
|
if (!TypeNodeResolver.nodeIsUsable(node) || !this.current.isExportedNode(node)) {
|
|
814
796
|
return false;
|
|
@@ -821,43 +803,39 @@ class TypeNodeResolver {
|
|
|
821
803
|
}
|
|
822
804
|
if (modelTypes.length > 1) {
|
|
823
805
|
// remove types that are from typescript e.g. 'Account'
|
|
824
|
-
modelTypes = modelTypes.filter(modelType =>
|
|
825
|
-
return modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1;
|
|
826
|
-
});
|
|
806
|
+
modelTypes = modelTypes.filter((modelType) => modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1);
|
|
827
807
|
modelTypes = TypeNodeResolver.getDesignatedModels(modelTypes, typeName);
|
|
828
808
|
}
|
|
829
809
|
if (modelTypes.length > 1) {
|
|
830
|
-
const conflicts = modelTypes.map(modelType => modelType.getSourceFile().fileName).join('"; "');
|
|
810
|
+
const conflicts = modelTypes.map((modelType) => modelType.getSourceFile().fileName).join('"; "');
|
|
831
811
|
throw new error_1.ResolverError(`Multiple matching models found for referenced type ${typeName}; please make model names unique. Conflicts found: "${conflicts}".`);
|
|
832
812
|
}
|
|
833
813
|
return modelTypes[0];
|
|
834
814
|
}
|
|
835
815
|
getModelProperties(node, overrideToken, utilityType, utilityOptions) {
|
|
836
|
-
const isIgnored = (e) =>
|
|
837
|
-
return (0, utils_1.isExistJSDocTag)(e, tag => tag.tagName.text === 'ignore');
|
|
838
|
-
};
|
|
816
|
+
const isIgnored = (e) => (0, utils_1.isExistJSDocTag)(e, (tag) => tag.tagName.text === 'ignore');
|
|
839
817
|
// Interface model
|
|
840
818
|
if (ts.isInterfaceDeclaration(node)) {
|
|
841
|
-
return node.members.filter(member => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken));
|
|
819
|
+
return node.members.filter((member) => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken));
|
|
842
820
|
}
|
|
843
821
|
// Class model
|
|
844
822
|
let properties = node.members
|
|
845
|
-
.filter(member => !isIgnored(member))
|
|
846
|
-
.filter(member => member.kind === ts.SyntaxKind.PropertyDeclaration)
|
|
847
|
-
.filter(member => !this.hasStaticModifier(member))
|
|
848
|
-
.filter(member => this.hasPublicModifier(member));
|
|
849
|
-
const classConstructor = node.members.find(member => ts.isConstructorDeclaration(member));
|
|
823
|
+
.filter((member) => !isIgnored(member))
|
|
824
|
+
.filter((member) => member.kind === ts.SyntaxKind.PropertyDeclaration)
|
|
825
|
+
.filter((member) => !this.hasStaticModifier(member))
|
|
826
|
+
.filter((member) => this.hasPublicModifier(member));
|
|
827
|
+
const classConstructor = node.members.find((member) => ts.isConstructorDeclaration(member));
|
|
850
828
|
if (classConstructor && classConstructor.parameters) {
|
|
851
|
-
const constructorProperties = classConstructor.parameters.filter(parameter => this.isAccessibleParameter(parameter));
|
|
829
|
+
const constructorProperties = classConstructor.parameters.filter((parameter) => this.isAccessibleParameter(parameter));
|
|
852
830
|
properties.push(...constructorProperties);
|
|
853
831
|
}
|
|
854
832
|
properties = this.filterUtilityProperties(properties, utilityType, utilityOptions);
|
|
855
|
-
return properties.map(property => this.propertyFromDeclaration(property, overrideToken, utilityType));
|
|
833
|
+
return properties.map((property) => this.propertyFromDeclaration(property, overrideToken, utilityType));
|
|
856
834
|
}
|
|
857
835
|
propertyFromSignature(propertySignature, overrideToken) {
|
|
858
836
|
const identifier = propertySignature.name;
|
|
859
837
|
if (!propertySignature.type) {
|
|
860
|
-
throw new error_1.ResolverError(
|
|
838
|
+
throw new error_1.ResolverError('No valid type found for property declaration.');
|
|
861
839
|
}
|
|
862
840
|
let required = !propertySignature.questionToken;
|
|
863
841
|
if (overrideToken && overrideToken.kind === ts.SyntaxKind.MinusToken) {
|
|
@@ -867,15 +845,15 @@ class TypeNodeResolver {
|
|
|
867
845
|
required = false;
|
|
868
846
|
}
|
|
869
847
|
const property = {
|
|
870
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'),
|
|
848
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'),
|
|
871
849
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'),
|
|
872
850
|
description: this.getNodeDescription(propertySignature),
|
|
873
851
|
example: TypeNodeResolver.getNodeExample(propertySignature),
|
|
874
852
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
875
853
|
name: identifier.text,
|
|
876
|
-
required
|
|
854
|
+
required,
|
|
877
855
|
type: new TypeNodeResolver(propertySignature.type, this.current, propertySignature.type.parent, this.context, propertySignature.type).resolve(),
|
|
878
|
-
validators: getPropertyValidators(propertySignature) || {}
|
|
856
|
+
validators: getPropertyValidators(propertySignature) || {},
|
|
879
857
|
};
|
|
880
858
|
return property;
|
|
881
859
|
}
|
|
@@ -887,7 +865,7 @@ class TypeNodeResolver {
|
|
|
887
865
|
typeNode = this.current.typeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.NoTruncation);
|
|
888
866
|
}
|
|
889
867
|
if (!typeNode) {
|
|
890
|
-
throw new error_1.ResolverError(
|
|
868
|
+
throw new error_1.ResolverError('No valid type found for property declaration.');
|
|
891
869
|
}
|
|
892
870
|
const type = new TypeNodeResolver(typeNode, this.current, propertyDeclaration, this.context, typeNode).resolve();
|
|
893
871
|
let required = !propertyDeclaration.questionToken && !propertyDeclaration.initializer;
|
|
@@ -906,28 +884,28 @@ class TypeNodeResolver {
|
|
|
906
884
|
}
|
|
907
885
|
}
|
|
908
886
|
const property = {
|
|
909
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, tag => tag.tagName.text === 'deprecated'),
|
|
887
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
910
888
|
default: (0, utils_2.getInitializerValue)(propertyDeclaration.initializer, this.current.typeChecker),
|
|
911
889
|
description: this.getNodeDescription(propertyDeclaration),
|
|
912
890
|
example: TypeNodeResolver.getNodeExample(propertyDeclaration),
|
|
913
891
|
format: TypeNodeResolver.getNodeFormat(propertyDeclaration),
|
|
914
892
|
name: identifier.text,
|
|
915
|
-
required
|
|
916
|
-
type
|
|
893
|
+
required,
|
|
894
|
+
type,
|
|
917
895
|
validators: getPropertyValidators(propertyDeclaration) || {},
|
|
918
896
|
};
|
|
919
897
|
return property;
|
|
920
898
|
}
|
|
921
899
|
getModelAdditionalProperties(node) {
|
|
922
900
|
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
|
|
923
|
-
const indexMember = node.members.find(member => member.kind === ts.SyntaxKind.IndexSignature);
|
|
901
|
+
const indexMember = node.members.find((member) => member.kind === ts.SyntaxKind.IndexSignature);
|
|
924
902
|
if (!indexMember) {
|
|
925
903
|
return undefined;
|
|
926
904
|
}
|
|
927
905
|
const indexSignatureDeclaration = indexMember;
|
|
928
906
|
const indexType = new TypeNodeResolver(indexSignatureDeclaration.parameters[0].type, this.current, this.parentNode, this.context).resolve();
|
|
929
907
|
if (indexType.typeName !== 'string') {
|
|
930
|
-
throw new error_1.ResolverError(
|
|
908
|
+
throw new error_1.ResolverError('Only string indexers are supported.', this.typeNode);
|
|
931
909
|
}
|
|
932
910
|
return new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve();
|
|
933
911
|
}
|
|
@@ -962,15 +940,15 @@ class TypeNodeResolver {
|
|
|
962
940
|
}
|
|
963
941
|
getModelInheritedProperties(modelTypeDeclaration) {
|
|
964
942
|
let properties = [];
|
|
965
|
-
const heritageClauses = modelTypeDeclaration
|
|
943
|
+
const { heritageClauses } = modelTypeDeclaration;
|
|
966
944
|
if (!heritageClauses) {
|
|
967
945
|
return properties;
|
|
968
946
|
}
|
|
969
|
-
heritageClauses.forEach(clause => {
|
|
947
|
+
heritageClauses.forEach((clause) => {
|
|
970
948
|
if (!clause.types) {
|
|
971
949
|
return;
|
|
972
950
|
}
|
|
973
|
-
clause.types.forEach(t => {
|
|
951
|
+
clause.types.forEach((t) => {
|
|
974
952
|
const baseEntityName = t.expression;
|
|
975
953
|
// create subContext
|
|
976
954
|
const resetCtx = this.typeArgumentsToContext(t, baseEntityName, this.context);
|
|
@@ -992,7 +970,7 @@ class TypeNodeResolver {
|
|
|
992
970
|
}
|
|
993
971
|
}
|
|
994
972
|
else if (referenceType.typeName === 'refObject') {
|
|
995
|
-
referenceType.properties.forEach(property => properties.push(property));
|
|
973
|
+
referenceType.properties.forEach((property) => properties.push(property));
|
|
996
974
|
}
|
|
997
975
|
else {
|
|
998
976
|
// todo: should never assert
|
|
@@ -1006,15 +984,11 @@ class TypeNodeResolver {
|
|
|
1006
984
|
}
|
|
1007
985
|
hasPublicModifier(node) {
|
|
1008
986
|
return (!node.modifiers ||
|
|
1009
|
-
node.modifiers.every(modifier =>
|
|
1010
|
-
return modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword;
|
|
1011
|
-
}));
|
|
987
|
+
node.modifiers.every((modifier) => modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword));
|
|
1012
988
|
}
|
|
1013
989
|
hasStaticModifier(node) {
|
|
1014
990
|
return (node.modifiers &&
|
|
1015
|
-
node.modifiers.some(modifier =>
|
|
1016
|
-
return modifier.kind === ts.SyntaxKind.StaticKeyword;
|
|
1017
|
-
}));
|
|
991
|
+
node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword));
|
|
1018
992
|
}
|
|
1019
993
|
isAccessibleParameter(node) {
|
|
1020
994
|
// No modifiers
|
|
@@ -1022,14 +996,12 @@ class TypeNodeResolver {
|
|
|
1022
996
|
return false;
|
|
1023
997
|
}
|
|
1024
998
|
// public || public readonly
|
|
1025
|
-
if (node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PublicKeyword)) {
|
|
999
|
+
if (node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.PublicKeyword)) {
|
|
1026
1000
|
return true;
|
|
1027
1001
|
}
|
|
1028
1002
|
// readonly, not private readonly, not public readonly
|
|
1029
|
-
const isReadonly = node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ReadonlyKeyword);
|
|
1030
|
-
const isProtectedOrPrivate = node.modifiers.some(modifier =>
|
|
1031
|
-
return modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword;
|
|
1032
|
-
});
|
|
1003
|
+
const isReadonly = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword);
|
|
1004
|
+
const isProtectedOrPrivate = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword);
|
|
1033
1005
|
return isReadonly && !isProtectedOrPrivate;
|
|
1034
1006
|
}
|
|
1035
1007
|
getNodeDescription(node) {
|