@trapi/metadata 0.1.3 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cache/driver.d.ts +1 -1
- package/dist/cache/driver.d.ts.map +1 -1
- package/dist/cache/driver.js +3 -6
- package/dist/cache/driver.js.map +1 -1
- package/dist/cache/type.d.ts +1 -1
- package/dist/cache/type.d.ts.map +1 -1
- package/dist/cache/utils.d.ts +1 -1
- package/dist/cache/utils.d.ts.map +1 -1
- package/dist/cache/utils.js +14 -14
- package/dist/cache/utils.js.map +1 -1
- package/dist/config/path.js.map +1 -1
- package/dist/decorator/functions.d.ts.map +1 -1
- package/dist/decorator/functions.js +9 -13
- package/dist/decorator/functions.js.map +1 -1
- package/dist/decorator/index.d.ts +1 -1
- package/dist/decorator/index.d.ts.map +1 -1
- package/dist/decorator/index.js +1 -3
- package/dist/decorator/index.js.map +1 -1
- package/dist/decorator/mapper/index.d.ts +3 -3
- package/dist/decorator/mapper/index.d.ts.map +1 -1
- package/dist/decorator/mapper/index.js +6 -11
- package/dist/decorator/mapper/index.js.map +1 -1
- package/dist/decorator/mapper/maps/decorators-express.d.ts +1 -1
- package/dist/decorator/mapper/maps/decorators-express.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/decorators-express.js +33 -33
- package/dist/decorator/mapper/maps/internal.d.ts +1 -1
- package/dist/decorator/mapper/maps/internal.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/internal.js +31 -27
- package/dist/decorator/mapper/maps/internal.js.map +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.d.ts +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.d.ts.map +1 -1
- package/dist/decorator/mapper/maps/typescript-rest.js +38 -38
- package/dist/decorator/mapper/maps/typescript-rest.js.map +1 -1
- package/dist/decorator/mapper/utils.d.ts +1 -1
- package/dist/decorator/mapper/utils.d.ts.map +1 -1
- package/dist/decorator/mapper/utils.js +1 -1
- package/dist/decorator/mapper/utils.js.map +1 -1
- package/dist/decorator/representation/index.d.ts +1 -1
- package/dist/decorator/representation/index.d.ts.map +1 -1
- package/dist/decorator/representation/index.js +2 -4
- package/dist/decorator/representation/index.js.map +1 -1
- package/dist/decorator/representation/property/utils.d.ts +1 -1
- package/dist/decorator/representation/property/utils.d.ts.map +1 -1
- package/dist/decorator/representation/property/utils.js +7 -6
- package/dist/decorator/representation/property/utils.js.map +1 -1
- package/dist/decorator/type.d.ts.map +1 -1
- package/dist/decorator/utils/node.d.ts +1 -1
- package/dist/decorator/utils/node.d.ts.map +1 -1
- package/dist/decorator/utils/node.js +4 -6
- package/dist/decorator/utils/node.js.map +1 -1
- package/dist/decorator/utils/validator.d.ts +2 -2
- package/dist/decorator/utils/validator.d.ts.map +1 -1
- package/dist/decorator/utils/validator.js +8 -8
- package/dist/decorator/utils/validator.js.map +1 -1
- package/dist/generator/controller.d.ts +1 -1
- package/dist/generator/controller.d.ts.map +1 -1
- package/dist/generator/controller.js +1 -1
- package/dist/generator/controller.js.map +1 -1
- package/dist/generator/endpoint.d.ts +2 -2
- package/dist/generator/endpoint.d.ts.map +1 -1
- package/dist/generator/endpoint.js +14 -19
- package/dist/generator/endpoint.js.map +1 -1
- package/dist/generator/index.d.ts +5 -33
- package/dist/generator/index.d.ts.map +1 -1
- package/dist/generator/index.js +15 -151
- package/dist/generator/index.js.map +1 -1
- package/dist/generator/method.d.ts +1 -1
- package/dist/generator/method.d.ts.map +1 -1
- package/dist/generator/method.js +10 -12
- package/dist/generator/method.js.map +1 -1
- package/dist/generator/module.d.ts +41 -0
- package/dist/generator/module.d.ts.map +1 -0
- package/dist/generator/module.js +166 -0
- package/dist/generator/module.js.map +1 -0
- package/dist/generator/parameter.d.ts +1 -1
- package/dist/generator/parameter.d.ts.map +1 -1
- package/dist/generator/parameter.js +26 -35
- package/dist/generator/parameter.js.map +1 -1
- package/dist/resolver/type-node.d.ts +1 -1
- package/dist/resolver/type-node.d.ts.map +1 -1
- package/dist/resolver/type-node.js +124 -189
- package/dist/resolver/type-node.js.map +1 -1
- package/dist/resolver/type.d.ts +1 -1
- package/dist/resolver/type.d.ts.map +1 -1
- package/dist/resolver/utils/initializer.d.ts +1 -1
- package/dist/resolver/utils/initializer.d.ts.map +1 -1
- package/dist/resolver/utils/initializer.js +11 -12
- package/dist/resolver/utils/initializer.js.map +1 -1
- package/dist/resolver/utils/validator.d.ts +1 -1
- package/dist/resolver/utils/validator.d.ts.map +1 -1
- package/dist/resolver/utils/validator.js +8 -11
- package/dist/resolver/utils/validator.js.map +1 -1
- package/dist/type.d.ts +8 -3
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/generator.d.ts +2 -2
- package/dist/utils/generator.d.ts.map +1 -1
- package/dist/utils/generator.js +2 -2
- package/dist/utils/generator.js.map +1 -1
- package/dist/utils/js-doc.d.ts.map +1 -1
- package/dist/utils/js-doc.js +7 -11
- package/dist/utils/js-doc.js.map +1 -1
- package/dist/utils/validator.d.ts +2 -2
- package/dist/utils/validator.d.ts.map +1 -1
- package/dist/utils/validator.js +2 -2
- package/dist/utils/validator.js.map +1 -1
- package/package.json +19 -13
- package/src/cache/driver.ts +0 -97
- package/src/cache/index.ts +0 -10
- package/src/cache/type.ts +0 -43
- package/src/cache/utils.ts +0 -49
- package/src/config/index.ts +0 -8
- package/src/config/path.ts +0 -29
- package/src/decorator/functions.ts +0 -142
- package/src/decorator/index.ts +0 -13
- package/src/decorator/mapper/index.ts +0 -153
- package/src/decorator/mapper/maps/decorators-express.ts +0 -117
- package/src/decorator/mapper/maps/internal.ts +0 -95
- package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
- package/src/decorator/mapper/utils.ts +0 -88
- package/src/decorator/representation/index.ts +0 -82
- package/src/decorator/representation/property/utils.ts +0 -146
- package/src/decorator/type.ts +0 -235
- package/src/decorator/utils/index.ts +0 -9
- package/src/decorator/utils/node.ts +0 -59
- package/src/decorator/utils/validator.ts +0 -104
- package/src/generator/controller.ts +0 -65
- package/src/generator/endpoint.ts +0 -212
- package/src/generator/index.ts +0 -219
- package/src/generator/method.ts +0 -198
- package/src/generator/parameter.ts +0 -392
- package/src/index.ts +0 -13
- package/src/resolver/error.ts +0 -38
- package/src/resolver/index.ts +0 -11
- package/src/resolver/type-node.ts +0 -1287
- package/src/resolver/type.ts +0 -257
- package/src/resolver/utils/index.ts +0 -9
- package/src/resolver/utils/initializer.ts +0 -81
- package/src/resolver/utils/validator.ts +0 -144
- package/src/type.ts +0 -185
- package/src/utils/generator.ts +0 -42
- package/src/utils/index.ts +0 -10
- package/src/utils/js-doc.ts +0 -125
- package/src/utils/validator.ts +0 -43
- package/test/data/library/@decorators-express/decorators.ts +0 -7
- package/test/data/library/self/api.ts +0 -37
- package/test/data/library/type.ts +0 -138
- package/test/data/library/typescript-rest/api.ts +0 -366
- package/test/data/library/typescript-rest/decorators/index.ts +0 -10
- package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
- package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
- package/test/data/library/typescript-rest/decorators/services.ts +0 -47
- package/test/data/library/typescript-rest/return-types.ts +0 -94
- package/test/data/library/utils.ts +0 -7
- package/test/jest.config.js +0 -49
- package/test/unit/cache.spec.ts +0 -48
- package/test/unit/decorator/mapper/index.spec.ts +0 -83
- package/test/unit/decorator/representation/index.spec.ts +0 -102
- package/test/unit/decorator/utils/node.spec.ts +0 -47
- package/test/unit/library/typescript-rest.spec.ts +0 -342
- package/test/unit/resolver/type.spec.ts +0 -134
- package/test/unit/utils/generator.spec.ts +0 -41
- package/test/unit/utils/js-doc.spec.ts +0 -104
- package/tsconfig.build.json +0 -11
- package/tsconfig.json +0 -9
- package/writable/.gitignore +0 -3
|
@@ -28,33 +28,43 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
28
28
|
exports.TypeNodeResolver = void 0;
|
|
29
29
|
const ts = __importStar(require("typescript"));
|
|
30
30
|
const metadata_utils_1 = require("@trapi/metadata-utils");
|
|
31
|
+
const decorator_1 = require("../decorator");
|
|
31
32
|
const utils_1 = require("../utils");
|
|
32
33
|
const error_1 = require("./error");
|
|
33
34
|
const utils_2 = require("./utils");
|
|
34
|
-
const decorator_1 = require("../decorator");
|
|
35
35
|
const localReferenceTypeCache = {};
|
|
36
36
|
const inProgressTypes = {};
|
|
37
37
|
function getPropertyValidators(property) {
|
|
38
38
|
return {};
|
|
39
39
|
}
|
|
40
40
|
class TypeNodeResolver {
|
|
41
|
-
typeNode;
|
|
42
|
-
current;
|
|
43
|
-
parentNode;
|
|
44
|
-
context;
|
|
45
|
-
referencer;
|
|
46
41
|
constructor(typeNode, current, parentNode, context = {}, referencer) {
|
|
47
42
|
this.typeNode = typeNode;
|
|
48
43
|
this.current = current;
|
|
49
44
|
this.parentNode = parentNode;
|
|
50
45
|
this.context = context;
|
|
51
46
|
this.referencer = referencer;
|
|
47
|
+
this.attemptToResolveKindToPrimitive = (syntaxKind) => {
|
|
48
|
+
if (syntaxKind === ts.SyntaxKind.NumberKeyword) {
|
|
49
|
+
return 'number';
|
|
50
|
+
}
|
|
51
|
+
if (syntaxKind === ts.SyntaxKind.StringKeyword) {
|
|
52
|
+
return 'string';
|
|
53
|
+
}
|
|
54
|
+
if (syntaxKind === ts.SyntaxKind.BooleanKeyword) {
|
|
55
|
+
return 'boolean';
|
|
56
|
+
}
|
|
57
|
+
if (syntaxKind === ts.SyntaxKind.VoidKeyword) {
|
|
58
|
+
return 'void';
|
|
59
|
+
}
|
|
60
|
+
return undefined;
|
|
61
|
+
};
|
|
52
62
|
}
|
|
53
63
|
static clearCache() {
|
|
54
|
-
Object.keys(localReferenceTypeCache).forEach(key => {
|
|
64
|
+
Object.keys(localReferenceTypeCache).forEach((key) => {
|
|
55
65
|
delete localReferenceTypeCache[key];
|
|
56
66
|
});
|
|
57
|
-
Object.keys(inProgressTypes).forEach(key => {
|
|
67
|
+
Object.keys(inProgressTypes).forEach((key) => {
|
|
58
68
|
delete inProgressTypes[key];
|
|
59
69
|
});
|
|
60
70
|
}
|
|
@@ -76,18 +86,14 @@ class TypeNodeResolver {
|
|
|
76
86
|
};
|
|
77
87
|
}
|
|
78
88
|
if (ts.isUnionTypeNode(this.typeNode)) {
|
|
79
|
-
const types = this.typeNode.types.map(type =>
|
|
80
|
-
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve();
|
|
81
|
-
});
|
|
89
|
+
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
82
90
|
return {
|
|
83
91
|
typeName: 'union',
|
|
84
92
|
members: types,
|
|
85
93
|
};
|
|
86
94
|
}
|
|
87
95
|
if (ts.isIntersectionTypeNode(this.typeNode)) {
|
|
88
|
-
const types = this.typeNode.types.map(type =>
|
|
89
|
-
return new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve();
|
|
90
|
-
});
|
|
96
|
+
const types = this.typeNode.types.map((type) => new TypeNodeResolver(type, this.current, this.parentNode, this.context).resolve());
|
|
91
97
|
return {
|
|
92
98
|
typeName: 'intersection',
|
|
93
99
|
members: types,
|
|
@@ -106,36 +112,36 @@ class TypeNodeResolver {
|
|
|
106
112
|
}
|
|
107
113
|
if (ts.isTypeLiteralNode(this.typeNode)) {
|
|
108
114
|
const properties = this.typeNode.members
|
|
109
|
-
.filter(member => ts.isPropertySignature(member))
|
|
115
|
+
.filter((member) => ts.isPropertySignature(member))
|
|
110
116
|
.reduce((res, propertySignature) => {
|
|
111
117
|
const type = new TypeNodeResolver(propertySignature.type, this.current, propertySignature, this.context).resolve();
|
|
112
118
|
const property = {
|
|
113
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'),
|
|
119
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'),
|
|
114
120
|
example: TypeNodeResolver.getNodeExample(propertySignature),
|
|
115
121
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'),
|
|
116
122
|
description: this.getNodeDescription(propertySignature),
|
|
117
123
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
118
124
|
name: propertySignature.name.text,
|
|
119
125
|
required: !propertySignature.questionToken,
|
|
120
|
-
type
|
|
121
|
-
validators: getPropertyValidators(propertySignature) || {}
|
|
126
|
+
type,
|
|
127
|
+
validators: getPropertyValidators(propertySignature) || {},
|
|
122
128
|
};
|
|
123
129
|
return [property, ...res];
|
|
124
130
|
}, []);
|
|
125
|
-
const indexMember = this.typeNode.members.find(member => ts.isIndexSignatureDeclaration(member));
|
|
131
|
+
const indexMember = this.typeNode.members.find((member) => ts.isIndexSignatureDeclaration(member));
|
|
126
132
|
let additionalType;
|
|
127
133
|
if (indexMember) {
|
|
128
134
|
const indexSignatureDeclaration = indexMember;
|
|
129
135
|
const indexType = new TypeNodeResolver(indexSignatureDeclaration.parameters[0].type, this.current, this.parentNode, this.context).resolve();
|
|
130
136
|
if (indexType.typeName !== 'string') {
|
|
131
|
-
throw new error_1.ResolverError(
|
|
137
|
+
throw new error_1.ResolverError('Only string indexes are supported.', this.typeNode);
|
|
132
138
|
}
|
|
133
139
|
additionalType = new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve();
|
|
134
140
|
}
|
|
135
141
|
return {
|
|
136
142
|
additionalProperties: indexMember && additionalType,
|
|
137
143
|
typeName: 'nestedObjectLiteral',
|
|
138
|
-
properties
|
|
144
|
+
properties,
|
|
139
145
|
};
|
|
140
146
|
}
|
|
141
147
|
if (this.typeNode.kind === ts.SyntaxKind.ObjectKeyword || ts.isFunctionTypeNode(this.typeNode)) {
|
|
@@ -144,26 +150,26 @@ class TypeNodeResolver {
|
|
|
144
150
|
if (ts.isMappedTypeNode(this.typeNode) && this.referencer) {
|
|
145
151
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer);
|
|
146
152
|
const mappedTypeNode = this.typeNode;
|
|
147
|
-
const typeChecker = this.current
|
|
153
|
+
const { typeChecker } = this.current;
|
|
148
154
|
const getDeclaration = (prop) => prop.declarations && prop.declarations[0];
|
|
149
155
|
const isIgnored = (prop) => {
|
|
150
156
|
const declaration = getDeclaration(prop);
|
|
151
|
-
return (prop.getJsDocTags().find(tag => tag.name === 'ignore') !== undefined ||
|
|
157
|
+
return (prop.getJsDocTags().find((tag) => tag.name === 'ignore') !== undefined ||
|
|
152
158
|
(declaration !== undefined && !ts.isPropertyDeclaration(declaration) && !ts.isPropertySignature(declaration) && !ts.isParameter(declaration)));
|
|
153
159
|
};
|
|
154
160
|
const properties = type
|
|
155
161
|
.getProperties()
|
|
156
162
|
// Ignore methods, getter, setter and @ignored props
|
|
157
|
-
.filter(property => isIgnored(property) === false)
|
|
163
|
+
.filter((property) => isIgnored(property) === false)
|
|
158
164
|
// Transform to property
|
|
159
|
-
.map(property => {
|
|
165
|
+
.map((property) => {
|
|
160
166
|
const propertyType = typeChecker.getTypeOfSymbolAtLocation(property, this.typeNode);
|
|
161
167
|
const declaration = getDeclaration(property);
|
|
162
168
|
if (declaration && ts.isPropertySignature(declaration)) {
|
|
163
|
-
return {
|
|
169
|
+
return Object.assign(Object.assign({}, this.propertyFromSignature(declaration, mappedTypeNode.questionToken)), { name: property.getName() });
|
|
164
170
|
}
|
|
165
|
-
|
|
166
|
-
return {
|
|
171
|
+
if (declaration && (ts.isPropertyDeclaration(declaration) || ts.isParameter(declaration))) {
|
|
172
|
+
return Object.assign(Object.assign({}, this.propertyFromDeclaration(declaration, mappedTypeNode.questionToken)), { name: property.getName() });
|
|
167
173
|
}
|
|
168
174
|
// Resolve default value, required and typeNode
|
|
169
175
|
let required = false;
|
|
@@ -177,7 +183,7 @@ class TypeNodeResolver {
|
|
|
177
183
|
// Push property
|
|
178
184
|
return {
|
|
179
185
|
name: property.getName(),
|
|
180
|
-
required
|
|
186
|
+
required,
|
|
181
187
|
deprecated: false,
|
|
182
188
|
type: new TypeNodeResolver(typeNode, this.current, this.typeNode, this.context, this.referencer).resolve(),
|
|
183
189
|
validators: {},
|
|
@@ -185,7 +191,7 @@ class TypeNodeResolver {
|
|
|
185
191
|
});
|
|
186
192
|
return {
|
|
187
193
|
typeName: 'nestedObjectLiteral',
|
|
188
|
-
properties
|
|
194
|
+
properties,
|
|
189
195
|
};
|
|
190
196
|
}
|
|
191
197
|
if (ts.isConditionalTypeNode(this.typeNode) && this.referencer && ts.isTypeReferenceNode(this.referencer)) {
|
|
@@ -201,15 +207,13 @@ class TypeNodeResolver {
|
|
|
201
207
|
// Note: I don't understand why typescript lose type for `this.referencer` (from above with isTypeReferenceNode())
|
|
202
208
|
return this.getTypeAliasReference(declaration, this.current.typeChecker.typeToString(type), this.referencer);
|
|
203
209
|
}
|
|
204
|
-
|
|
210
|
+
if (ts.isEnumDeclaration(declaration)) {
|
|
205
211
|
return this.getEnumerateType(declaration.name);
|
|
206
212
|
}
|
|
207
|
-
|
|
208
|
-
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);
|
|
209
|
-
}
|
|
213
|
+
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);
|
|
210
214
|
});
|
|
211
215
|
}
|
|
212
|
-
|
|
216
|
+
if (type.isClassOrInterface()) {
|
|
213
217
|
let declaration = type.symbol.declarations[0];
|
|
214
218
|
if (declaration.name) {
|
|
215
219
|
declaration = this.getModelTypeDeclaration(declaration.name);
|
|
@@ -217,13 +221,11 @@ class TypeNodeResolver {
|
|
|
217
221
|
const name = TypeNodeResolver.getRefTypeName(this.referencer.getText());
|
|
218
222
|
return this.handleCachingAndCircularReferences(name, () => this.getModelReference(declaration, this.current.typeChecker.typeToString(type)));
|
|
219
223
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
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);
|
|
226
|
-
}
|
|
224
|
+
try {
|
|
225
|
+
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation), this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
226
|
+
}
|
|
227
|
+
catch (_a) {
|
|
228
|
+
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);
|
|
227
229
|
}
|
|
228
230
|
}
|
|
229
231
|
if (ts.isTypeOperatorNode(this.typeNode) && this.typeNode.operator === ts.SyntaxKind.KeyOfKeyword) {
|
|
@@ -260,22 +262,20 @@ class TypeNodeResolver {
|
|
|
260
262
|
try {
|
|
261
263
|
return new TypeNodeResolver(this.current.typeChecker.typeToTypeNode(declaration, undefined, undefined), this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
262
264
|
}
|
|
263
|
-
catch {
|
|
265
|
+
catch (_b) {
|
|
264
266
|
throw new error_1.ResolverError(`Could not determine the keys on ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.current.typeChecker.typeToTypeNode(declaration, undefined, undefined)))}`, this.typeNode);
|
|
265
267
|
}
|
|
266
268
|
}
|
|
267
269
|
// @ts-ignore
|
|
268
270
|
if (this.typeNode.kind === ts.SyntaxKind.TemplateLiteralType) {
|
|
269
271
|
const type = this.current.typeChecker.getTypeFromTypeNode(this.referencer || this.typeNode);
|
|
270
|
-
if (type.isUnion() && type.types.every(unionElementType => unionElementType.isStringLiteral())) {
|
|
272
|
+
if (type.isUnion() && type.types.every((unionElementType) => unionElementType.isStringLiteral())) {
|
|
271
273
|
return {
|
|
272
274
|
typeName: 'enum',
|
|
273
275
|
members: type.types.map((stringLiteralType) => stringLiteralType.value),
|
|
274
276
|
};
|
|
275
277
|
}
|
|
276
|
-
|
|
277
|
-
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode);
|
|
278
|
-
}
|
|
278
|
+
throw new error_1.ResolverError(`Could not the type of ${this.current.typeChecker.typeToString(this.current.typeChecker.getTypeFromTypeNode(this.typeNode), this.typeNode)}`, this.typeNode);
|
|
279
279
|
}
|
|
280
280
|
if (ts.isParenthesizedTypeNode(this.typeNode)) {
|
|
281
281
|
return new TypeNodeResolver(this.typeNode.type, this.current, this.typeNode, this.context, this.referencer).resolve();
|
|
@@ -334,19 +334,19 @@ class TypeNodeResolver {
|
|
|
334
334
|
}
|
|
335
335
|
static getUtilityTypeOptions(typeArguments) {
|
|
336
336
|
const utilityOptions = {
|
|
337
|
-
keys: []
|
|
337
|
+
keys: [],
|
|
338
338
|
};
|
|
339
339
|
if (typeArguments.length >= 2) {
|
|
340
340
|
if (ts.isUnionTypeNode(typeArguments[1])) {
|
|
341
341
|
const args = typeArguments[1].types;
|
|
342
342
|
for (let i = 0; i < args.length; i++) {
|
|
343
343
|
if (ts.isLiteralTypeNode(args[i])) {
|
|
344
|
-
utilityOptions
|
|
344
|
+
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(args[i]));
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
if (ts.isLiteralTypeNode(typeArguments[1])) {
|
|
349
|
-
utilityOptions
|
|
349
|
+
utilityOptions.keys.push(TypeNodeResolver.getLiteralValue(typeArguments[1]));
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
return utilityOptions;
|
|
@@ -356,7 +356,7 @@ class TypeNodeResolver {
|
|
|
356
356
|
return properties;
|
|
357
357
|
}
|
|
358
358
|
return properties
|
|
359
|
-
.filter(property => {
|
|
359
|
+
.filter((property) => {
|
|
360
360
|
const name = typeof property.name !== 'string' ? property.name.text : property.name;
|
|
361
361
|
switch (utilityType) {
|
|
362
362
|
case 'Pick':
|
|
@@ -366,7 +366,7 @@ class TypeNodeResolver {
|
|
|
366
366
|
}
|
|
367
367
|
return true;
|
|
368
368
|
})
|
|
369
|
-
.map(property => {
|
|
369
|
+
.map((property) => {
|
|
370
370
|
if ((0, metadata_utils_1.hasOwnProperty)(property, 'required')) {
|
|
371
371
|
switch (utilityType) {
|
|
372
372
|
case 'Partial':
|
|
@@ -434,21 +434,19 @@ class TypeNodeResolver {
|
|
|
434
434
|
return { typeName: 'double' };
|
|
435
435
|
}
|
|
436
436
|
const tags = (0, utils_1.getJSDocTagNames)(parentNode)
|
|
437
|
-
.filter(name =>
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
.map(name => name.toLowerCase());
|
|
446
|
-
const data = (0, decorator_1.getNodeDecorators)(parentNode, identifier => [
|
|
437
|
+
.filter((name) => [
|
|
438
|
+
'isInt',
|
|
439
|
+
'isLong',
|
|
440
|
+
'isFloat',
|
|
441
|
+
'isDouble',
|
|
442
|
+
].some((m) => m.toLowerCase() === name.toLowerCase()))
|
|
443
|
+
.map((name) => name.toLowerCase());
|
|
444
|
+
const data = (0, decorator_1.getNodeDecorators)(parentNode, (identifier) => [
|
|
447
445
|
'isInt',
|
|
448
446
|
'isLong',
|
|
449
447
|
'isFloat',
|
|
450
|
-
'isDouble'
|
|
451
|
-
].some(m => m.toLowerCase() === identifier.text.toLowerCase()));
|
|
448
|
+
'isDouble',
|
|
449
|
+
].some((m) => m.toLowerCase() === identifier.text.toLowerCase()));
|
|
452
450
|
let decorator = data.length > 0 ? data[0].text : undefined;
|
|
453
451
|
if (typeof decorator !== 'undefined') {
|
|
454
452
|
decorator = decorator.toLowerCase();
|
|
@@ -493,9 +491,7 @@ class TypeNodeResolver {
|
|
|
493
491
|
if (!parentNode) {
|
|
494
492
|
return { typeName: 'datetime' };
|
|
495
493
|
}
|
|
496
|
-
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter(name =>
|
|
497
|
-
return ['isDate', 'isDateTime'].some(m => m === name);
|
|
498
|
-
});
|
|
494
|
+
const tags = (0, utils_1.getJSDocTagNames)(parentNode).filter((name) => ['isDate', 'isDateTime'].some((m) => m === name));
|
|
499
495
|
if (tags.length === 0) {
|
|
500
496
|
return { typeName: 'datetime' };
|
|
501
497
|
}
|
|
@@ -513,7 +509,7 @@ class TypeNodeResolver {
|
|
|
513
509
|
}
|
|
514
510
|
getEnumerateType(typeName) {
|
|
515
511
|
const enumName = typeName.text;
|
|
516
|
-
let enumNodes = this.current.nodes.filter(node => node.kind === ts.SyntaxKind.EnumDeclaration).filter(node => node.name.text === enumName);
|
|
512
|
+
let enumNodes = this.current.nodes.filter((node) => node.kind === ts.SyntaxKind.EnumDeclaration).filter((node) => node.name.text === enumName);
|
|
517
513
|
if (!enumNodes.length) {
|
|
518
514
|
return undefined;
|
|
519
515
|
}
|
|
@@ -522,18 +518,16 @@ class TypeNodeResolver {
|
|
|
522
518
|
throw new error_1.ResolverError(`Multiple matching enum found for enum ${enumName}; please make enum names unique.`);
|
|
523
519
|
}
|
|
524
520
|
const enumDeclaration = enumNodes[0];
|
|
525
|
-
const isNotUndefined = (item) =>
|
|
526
|
-
return item !== undefined;
|
|
527
|
-
};
|
|
521
|
+
const isNotUndefined = (item) => item !== undefined;
|
|
528
522
|
const enums = enumDeclaration.members.map(this.current.typeChecker.getConstantValue.bind(this.current.typeChecker)).filter(isNotUndefined);
|
|
529
|
-
const enumNames = enumDeclaration.members.map(e => e.name.getText()).filter(isNotUndefined);
|
|
523
|
+
const enumNames = enumDeclaration.members.map((e) => e.name.getText()).filter(isNotUndefined);
|
|
530
524
|
return {
|
|
531
525
|
typeName: 'refEnum',
|
|
532
526
|
description: this.getNodeDescription(enumDeclaration),
|
|
533
527
|
members: enums,
|
|
534
528
|
memberNames: enumNames,
|
|
535
529
|
refName: enumName,
|
|
536
|
-
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, tag => tag.tagName.text === 'deprecated')
|
|
530
|
+
deprecated: (0, utils_1.isExistJSDocTag)(enumDeclaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
537
531
|
};
|
|
538
532
|
}
|
|
539
533
|
getReferenceType(node) {
|
|
@@ -545,14 +539,14 @@ class TypeNodeResolver {
|
|
|
545
539
|
type = node.expression;
|
|
546
540
|
}
|
|
547
541
|
else {
|
|
548
|
-
throw new error_1.ResolverError(
|
|
542
|
+
throw new error_1.ResolverError('Can\'t resolve Reference type.');
|
|
549
543
|
}
|
|
550
544
|
// Can't invoke getText on Synthetic Nodes
|
|
551
545
|
let resolvableName = node.pos !== -1 ? node.getText() : type.text;
|
|
552
546
|
if (node.pos === -1 && 'typeArguments' in node && Array.isArray(node.typeArguments)) {
|
|
553
547
|
// Add typeArguments for Synthetic nodes (e.g. Record<> in TestClassModel.indexedResponse)
|
|
554
548
|
const argumentsString = node.typeArguments
|
|
555
|
-
.map(arg => {
|
|
549
|
+
.map((arg) => {
|
|
556
550
|
if (ts.isLiteralTypeNode(arg)) {
|
|
557
551
|
return `'${String(TypeNodeResolver.getLiteralValue(arg))}'`;
|
|
558
552
|
}
|
|
@@ -570,10 +564,10 @@ class TypeNodeResolver {
|
|
|
570
564
|
const utilityTypeSupported = TypeNodeResolver.isSupportedUtilityType(identifierName);
|
|
571
565
|
const utilityType = utilityTypeSupported ? identifierName : undefined;
|
|
572
566
|
let utilityOptions = {
|
|
573
|
-
keys: []
|
|
567
|
+
keys: [],
|
|
574
568
|
};
|
|
575
569
|
if (utilityTypeSupported) {
|
|
576
|
-
const typeArguments = type.parent
|
|
570
|
+
const { typeArguments } = type.parent;
|
|
577
571
|
if (ts.isTypeReferenceNode(typeArguments[0])) {
|
|
578
572
|
type = typeArguments[0].typeName;
|
|
579
573
|
}
|
|
@@ -581,7 +575,7 @@ class TypeNodeResolver {
|
|
|
581
575
|
type = typeArguments[0].expression;
|
|
582
576
|
}
|
|
583
577
|
else {
|
|
584
|
-
throw new error_1.ResolverError(
|
|
578
|
+
throw new error_1.ResolverError('Can\'t resolve Reference type.');
|
|
585
579
|
}
|
|
586
580
|
utilityOptions = TypeNodeResolver.getUtilityTypeOptions(typeArguments);
|
|
587
581
|
}
|
|
@@ -614,7 +608,7 @@ class TypeNodeResolver {
|
|
|
614
608
|
members: [this.current.typeChecker.getConstantValue(declaration)],
|
|
615
609
|
// @ts-ignore
|
|
616
610
|
memberNames: [declaration.name.getText()],
|
|
617
|
-
deprecated: (0, utils_1.isExistJSDocTag)(declaration, tag => tag.tagName.text === 'deprecated')
|
|
611
|
+
deprecated: (0, utils_1.isExistJSDocTag)(declaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
618
612
|
};
|
|
619
613
|
}
|
|
620
614
|
else {
|
|
@@ -642,25 +636,15 @@ class TypeNodeResolver {
|
|
|
642
636
|
type = new TypeNodeResolver(declaration.type, this.current, declaration, this.context, this.referencer || referencer).resolve();
|
|
643
637
|
}
|
|
644
638
|
const example = TypeNodeResolver.getNodeExample(declaration);
|
|
645
|
-
return {
|
|
646
|
-
typeName: 'refAlias',
|
|
647
|
-
default: (0, utils_1.getJSDocTagComment)(declaration, 'default'),
|
|
648
|
-
description: this.getNodeDescription(declaration),
|
|
649
|
-
refName: refName,
|
|
650
|
-
format: TypeNodeResolver.getNodeFormat(declaration),
|
|
651
|
-
type: type,
|
|
652
|
-
validators: getPropertyValidators(declaration) || {},
|
|
653
|
-
deprecated: (0, utils_1.isExistJSDocTag)(declaration, tag => tag.tagName.text === 'deprecated'),
|
|
654
|
-
...(example && { example: example }),
|
|
655
|
-
};
|
|
639
|
+
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 }));
|
|
656
640
|
}
|
|
657
641
|
getModelReference(modelType, name, utilityType, utilityOptions) {
|
|
658
642
|
const example = TypeNodeResolver.getNodeExample(modelType);
|
|
659
643
|
const description = this.getNodeDescription(modelType);
|
|
660
|
-
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, tag => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined';
|
|
644
|
+
const deprecated = (0, utils_1.isExistJSDocTag)(modelType, (tag) => tag.tagName.text === 'deprecated') || typeof this.current.decoratorMapper.match('DEPRECATED', modelType) !== 'undefined';
|
|
661
645
|
// Handle toJSON methods
|
|
662
646
|
if (!modelType.name) {
|
|
663
|
-
throw new error_1.ResolverError(
|
|
647
|
+
throw new error_1.ResolverError('Can\'t get Symbol from anonymous class', modelType);
|
|
664
648
|
}
|
|
665
649
|
const type = this.current.typeChecker.getTypeAtLocation(modelType.name);
|
|
666
650
|
const toJSON = this.current.typeChecker.getPropertyOfType(type, 'toJSON');
|
|
@@ -671,28 +655,12 @@ class TypeNodeResolver {
|
|
|
671
655
|
const implicitType = this.current.typeChecker.getReturnTypeOfSignature(signature);
|
|
672
656
|
nodeType = this.current.typeChecker.typeToTypeNode(implicitType, undefined, ts.NodeBuilderFlags.NoTruncation);
|
|
673
657
|
}
|
|
674
|
-
return {
|
|
675
|
-
refName: TypeNodeResolver.getRefTypeName(name, utilityType) + 'Alias',
|
|
676
|
-
typeName: 'refAlias',
|
|
677
|
-
description: description,
|
|
678
|
-
type: new TypeNodeResolver(nodeType, this.current).resolve(),
|
|
679
|
-
deprecated: deprecated,
|
|
680
|
-
validators: {},
|
|
681
|
-
...(example && { example: example }),
|
|
682
|
-
};
|
|
658
|
+
return Object.assign({ refName: `${TypeNodeResolver.getRefTypeName(name, utilityType)}Alias`, typeName: 'refAlias', description, type: new TypeNodeResolver(nodeType, this.current).resolve(), deprecated, validators: {} }, (example && { example }));
|
|
683
659
|
}
|
|
684
660
|
const properties = this.getModelProperties(modelType, undefined, utilityType, utilityOptions);
|
|
685
661
|
const additionalProperties = this.getModelAdditionalProperties(modelType);
|
|
686
662
|
const inheritedProperties = this.getModelInheritedProperties(modelType) || [];
|
|
687
|
-
const referenceType = {
|
|
688
|
-
additionalProperties: additionalProperties,
|
|
689
|
-
typeName: 'refObject',
|
|
690
|
-
description: description,
|
|
691
|
-
properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions),
|
|
692
|
-
refName: TypeNodeResolver.getRefTypeName(name, utilityType),
|
|
693
|
-
deprecated: deprecated,
|
|
694
|
-
...(example && { example: example }),
|
|
695
|
-
};
|
|
663
|
+
const referenceType = Object.assign({ additionalProperties, typeName: 'refObject', description, properties: this.filterUtilityProperties(inheritedProperties, utilityType, utilityOptions), refName: TypeNodeResolver.getRefTypeName(name, utilityType), deprecated }, (example && { example }));
|
|
696
664
|
referenceType.properties = referenceType.properties.concat(properties);
|
|
697
665
|
return referenceType;
|
|
698
666
|
}
|
|
@@ -713,31 +681,12 @@ class TypeNodeResolver {
|
|
|
713
681
|
.replace(/_/g, '')
|
|
714
682
|
.replace(/-/g, ''));
|
|
715
683
|
}
|
|
716
|
-
attemptToResolveKindToPrimitive = (syntaxKind) => {
|
|
717
|
-
if (syntaxKind === ts.SyntaxKind.NumberKeyword) {
|
|
718
|
-
return 'number';
|
|
719
|
-
}
|
|
720
|
-
else if (syntaxKind === ts.SyntaxKind.StringKeyword) {
|
|
721
|
-
return 'string';
|
|
722
|
-
}
|
|
723
|
-
else if (syntaxKind === ts.SyntaxKind.BooleanKeyword) {
|
|
724
|
-
return 'boolean';
|
|
725
|
-
}
|
|
726
|
-
else if (syntaxKind === ts.SyntaxKind.VoidKeyword) {
|
|
727
|
-
return 'void';
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
return undefined;
|
|
731
|
-
}
|
|
732
|
-
};
|
|
733
684
|
contextualizedName(name) {
|
|
734
|
-
return Object.entries(this.context).reduce((acc, [key, entry]) =>
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`);
|
|
740
|
-
}, name);
|
|
685
|
+
return Object.entries(this.context).reduce((acc, [key, entry]) => acc
|
|
686
|
+
.replace(new RegExp(`<\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `<$1${entry.getText()}$3>`)
|
|
687
|
+
.replace(new RegExp(`<\\s*([^,]*\\s)*\\s*(${key})(\\s[^,]*)*\\s*,`, 'g'), `<$1${entry.getText()}$3,`)
|
|
688
|
+
.replace(new RegExp(`,\\s*([^>]*\\s)*\\s*(${key})(\\s[^>]*)*\\s*>`, 'g'), `,$1${entry.getText()}$3>`)
|
|
689
|
+
.replace(new RegExp(`<\\s*([^<]*\\s)*\\s*(${key})(\\s[^<]*)*\\s*<`, 'g'), `<$1${entry.getText()}$3<`), name);
|
|
741
690
|
}
|
|
742
691
|
handleCachingAndCircularReferences(name, declarationResolver) {
|
|
743
692
|
try {
|
|
@@ -763,9 +712,9 @@ class TypeNodeResolver {
|
|
|
763
712
|
createCircularDependencyResolver(refName) {
|
|
764
713
|
const referenceType = {
|
|
765
714
|
typeName: 'refObject',
|
|
766
|
-
refName
|
|
715
|
+
refName,
|
|
767
716
|
};
|
|
768
|
-
this.current.registerDependencyResolver(referenceTypes => {
|
|
717
|
+
this.current.registerDependencyResolver((referenceTypes) => {
|
|
769
718
|
const realReferenceType = referenceTypes[refName];
|
|
770
719
|
if (!realReferenceType) {
|
|
771
720
|
return;
|
|
@@ -819,16 +768,14 @@ class TypeNodeResolver {
|
|
|
819
768
|
const leftmostName = leftmost.kind === ts.SyntaxKind.Identifier ? leftmost.text : leftmost.right.text;
|
|
820
769
|
const moduleDeclarations = this.findMatchingModuleOrEnumDeclaration(statements, leftmostName);
|
|
821
770
|
if (moduleDeclarations.length > 0) {
|
|
822
|
-
statements = Array.prototype.concat(...moduleDeclarations.map(declaration => {
|
|
771
|
+
statements = Array.prototype.concat(...moduleDeclarations.map((declaration) => {
|
|
823
772
|
if (ts.isEnumDeclaration(declaration)) {
|
|
824
773
|
return declaration.members;
|
|
825
774
|
}
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`);
|
|
829
|
-
}
|
|
830
|
-
return declaration.body.statements;
|
|
775
|
+
if (!declaration.body || !ts.isModuleBlock(declaration.body)) {
|
|
776
|
+
throw new error_1.ResolverError(`Module declaration found for ${leftmostName} has no body.`);
|
|
831
777
|
}
|
|
778
|
+
return declaration.body.statements;
|
|
832
779
|
}));
|
|
833
780
|
}
|
|
834
781
|
leftmost = leftmost.parent;
|
|
@@ -839,55 +786,52 @@ class TypeNodeResolver {
|
|
|
839
786
|
const leftmostIdentifier = TypeNodeResolver.resolveLeftmostIdentifier(type);
|
|
840
787
|
const statements = this.resolveModelTypeScope(leftmostIdentifier, this.current.nodes);
|
|
841
788
|
const typeName = type.kind === ts.SyntaxKind.Identifier ? type.text : type.right.text;
|
|
842
|
-
let modelTypes = statements.filter(node => {
|
|
789
|
+
let modelTypes = statements.filter((node) => {
|
|
790
|
+
var _a;
|
|
843
791
|
if (!TypeNodeResolver.nodeIsUsable(node) || !this.current.isExportedNode(node)) {
|
|
844
792
|
return false;
|
|
845
793
|
}
|
|
846
794
|
const modelTypeDeclaration = node;
|
|
847
|
-
return modelTypeDeclaration.name
|
|
795
|
+
return ((_a = modelTypeDeclaration.name) === null || _a === void 0 ? void 0 : _a.text) === typeName;
|
|
848
796
|
});
|
|
849
797
|
if (!modelTypes.length) {
|
|
850
798
|
throw new error_1.ResolverError(`No matching model found for referenced type ${typeName}. If ${typeName} comes from a dependency, please create an interface in your own code that has the same structure. The compiler can not utilize interfaces from external dependencies.`);
|
|
851
799
|
}
|
|
852
800
|
if (modelTypes.length > 1) {
|
|
853
801
|
// remove types that are from typescript e.g. 'Account'
|
|
854
|
-
modelTypes = modelTypes.filter(modelType =>
|
|
855
|
-
return modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1;
|
|
856
|
-
});
|
|
802
|
+
modelTypes = modelTypes.filter((modelType) => modelType.getSourceFile().fileName.replace(/\\/g, '/').toLowerCase().indexOf('node_modules') <= -1);
|
|
857
803
|
modelTypes = TypeNodeResolver.getDesignatedModels(modelTypes, typeName);
|
|
858
804
|
}
|
|
859
805
|
if (modelTypes.length > 1) {
|
|
860
|
-
const conflicts = modelTypes.map(modelType => modelType.getSourceFile().fileName).join('"; "');
|
|
806
|
+
const conflicts = modelTypes.map((modelType) => modelType.getSourceFile().fileName).join('"; "');
|
|
861
807
|
throw new error_1.ResolverError(`Multiple matching models found for referenced type ${typeName}; please make model names unique. Conflicts found: "${conflicts}".`);
|
|
862
808
|
}
|
|
863
809
|
return modelTypes[0];
|
|
864
810
|
}
|
|
865
811
|
getModelProperties(node, overrideToken, utilityType, utilityOptions) {
|
|
866
|
-
const isIgnored = (e) =>
|
|
867
|
-
return (0, utils_1.isExistJSDocTag)(e, tag => tag.tagName.text === 'ignore');
|
|
868
|
-
};
|
|
812
|
+
const isIgnored = (e) => (0, utils_1.isExistJSDocTag)(e, (tag) => tag.tagName.text === 'ignore');
|
|
869
813
|
// Interface model
|
|
870
814
|
if (ts.isInterfaceDeclaration(node)) {
|
|
871
|
-
return node.members.filter(member => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken));
|
|
815
|
+
return node.members.filter((member) => !isIgnored(member) && ts.isPropertySignature(member)).map((member) => this.propertyFromSignature(member, overrideToken));
|
|
872
816
|
}
|
|
873
817
|
// Class model
|
|
874
818
|
let properties = node.members
|
|
875
|
-
.filter(member => !isIgnored(member))
|
|
876
|
-
.filter(member => member.kind === ts.SyntaxKind.PropertyDeclaration)
|
|
877
|
-
.filter(member => !this.hasStaticModifier(member))
|
|
878
|
-
.filter(member => this.hasPublicModifier(member));
|
|
879
|
-
const classConstructor = node.members.find(member => ts.isConstructorDeclaration(member));
|
|
819
|
+
.filter((member) => !isIgnored(member))
|
|
820
|
+
.filter((member) => member.kind === ts.SyntaxKind.PropertyDeclaration)
|
|
821
|
+
.filter((member) => !this.hasStaticModifier(member))
|
|
822
|
+
.filter((member) => this.hasPublicModifier(member));
|
|
823
|
+
const classConstructor = node.members.find((member) => ts.isConstructorDeclaration(member));
|
|
880
824
|
if (classConstructor && classConstructor.parameters) {
|
|
881
|
-
const constructorProperties = classConstructor.parameters.filter(parameter => this.isAccessibleParameter(parameter));
|
|
825
|
+
const constructorProperties = classConstructor.parameters.filter((parameter) => this.isAccessibleParameter(parameter));
|
|
882
826
|
properties.push(...constructorProperties);
|
|
883
827
|
}
|
|
884
828
|
properties = this.filterUtilityProperties(properties, utilityType, utilityOptions);
|
|
885
|
-
return properties.map(property => this.propertyFromDeclaration(property, overrideToken, utilityType));
|
|
829
|
+
return properties.map((property) => this.propertyFromDeclaration(property, overrideToken, utilityType));
|
|
886
830
|
}
|
|
887
831
|
propertyFromSignature(propertySignature, overrideToken) {
|
|
888
832
|
const identifier = propertySignature.name;
|
|
889
833
|
if (!propertySignature.type) {
|
|
890
|
-
throw new error_1.ResolverError(
|
|
834
|
+
throw new error_1.ResolverError('No valid type found for property declaration.');
|
|
891
835
|
}
|
|
892
836
|
let required = !propertySignature.questionToken;
|
|
893
837
|
if (overrideToken && overrideToken.kind === ts.SyntaxKind.MinusToken) {
|
|
@@ -897,15 +841,15 @@ class TypeNodeResolver {
|
|
|
897
841
|
required = false;
|
|
898
842
|
}
|
|
899
843
|
const property = {
|
|
900
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, tag => tag.tagName.text === 'deprecated'),
|
|
844
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertySignature, (tag) => tag.tagName.text === 'deprecated'),
|
|
901
845
|
default: (0, utils_1.getJSDocTagComment)(propertySignature, 'default'),
|
|
902
846
|
description: this.getNodeDescription(propertySignature),
|
|
903
847
|
example: TypeNodeResolver.getNodeExample(propertySignature),
|
|
904
848
|
format: TypeNodeResolver.getNodeFormat(propertySignature),
|
|
905
849
|
name: identifier.text,
|
|
906
|
-
required
|
|
850
|
+
required,
|
|
907
851
|
type: new TypeNodeResolver(propertySignature.type, this.current, propertySignature.type.parent, this.context, propertySignature.type).resolve(),
|
|
908
|
-
validators: getPropertyValidators(propertySignature) || {}
|
|
852
|
+
validators: getPropertyValidators(propertySignature) || {},
|
|
909
853
|
};
|
|
910
854
|
return property;
|
|
911
855
|
}
|
|
@@ -917,7 +861,7 @@ class TypeNodeResolver {
|
|
|
917
861
|
typeNode = this.current.typeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.NoTruncation);
|
|
918
862
|
}
|
|
919
863
|
if (!typeNode) {
|
|
920
|
-
throw new error_1.ResolverError(
|
|
864
|
+
throw new error_1.ResolverError('No valid type found for property declaration.');
|
|
921
865
|
}
|
|
922
866
|
const type = new TypeNodeResolver(typeNode, this.current, propertyDeclaration, this.context, typeNode).resolve();
|
|
923
867
|
let required = !propertyDeclaration.questionToken && !propertyDeclaration.initializer;
|
|
@@ -936,28 +880,28 @@ class TypeNodeResolver {
|
|
|
936
880
|
}
|
|
937
881
|
}
|
|
938
882
|
const property = {
|
|
939
|
-
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, tag => tag.tagName.text === 'deprecated'),
|
|
883
|
+
deprecated: (0, utils_1.isExistJSDocTag)(propertyDeclaration, (tag) => tag.tagName.text === 'deprecated'),
|
|
940
884
|
default: (0, utils_2.getInitializerValue)(propertyDeclaration.initializer, this.current.typeChecker),
|
|
941
885
|
description: this.getNodeDescription(propertyDeclaration),
|
|
942
886
|
example: TypeNodeResolver.getNodeExample(propertyDeclaration),
|
|
943
887
|
format: TypeNodeResolver.getNodeFormat(propertyDeclaration),
|
|
944
888
|
name: identifier.text,
|
|
945
|
-
required
|
|
946
|
-
type
|
|
889
|
+
required,
|
|
890
|
+
type,
|
|
947
891
|
validators: getPropertyValidators(propertyDeclaration) || {},
|
|
948
892
|
};
|
|
949
893
|
return property;
|
|
950
894
|
}
|
|
951
895
|
getModelAdditionalProperties(node) {
|
|
952
896
|
if (node.kind === ts.SyntaxKind.InterfaceDeclaration) {
|
|
953
|
-
const indexMember = node.members.find(member => member.kind === ts.SyntaxKind.IndexSignature);
|
|
897
|
+
const indexMember = node.members.find((member) => member.kind === ts.SyntaxKind.IndexSignature);
|
|
954
898
|
if (!indexMember) {
|
|
955
899
|
return undefined;
|
|
956
900
|
}
|
|
957
901
|
const indexSignatureDeclaration = indexMember;
|
|
958
902
|
const indexType = new TypeNodeResolver(indexSignatureDeclaration.parameters[0].type, this.current, this.parentNode, this.context).resolve();
|
|
959
903
|
if (indexType.typeName !== 'string') {
|
|
960
|
-
throw new error_1.ResolverError(
|
|
904
|
+
throw new error_1.ResolverError('Only string indexers are supported.', this.typeNode);
|
|
961
905
|
}
|
|
962
906
|
return new TypeNodeResolver(indexSignatureDeclaration.type, this.current, this.parentNode, this.context).resolve();
|
|
963
907
|
}
|
|
@@ -985,25 +929,22 @@ class TypeNodeResolver {
|
|
|
985
929
|
else {
|
|
986
930
|
throw new error_1.ResolverError(`Could not find a value for type parameter ${typeParameter.name.text}`, type);
|
|
987
931
|
}
|
|
988
|
-
this.context = {
|
|
989
|
-
...this.context,
|
|
990
|
-
[typeParameter.name.text]: resolvedType,
|
|
991
|
-
};
|
|
932
|
+
this.context = Object.assign(Object.assign({}, this.context), { [typeParameter.name.text]: resolvedType });
|
|
992
933
|
}
|
|
993
934
|
}
|
|
994
935
|
return context;
|
|
995
936
|
}
|
|
996
937
|
getModelInheritedProperties(modelTypeDeclaration) {
|
|
997
938
|
let properties = [];
|
|
998
|
-
const heritageClauses = modelTypeDeclaration
|
|
939
|
+
const { heritageClauses } = modelTypeDeclaration;
|
|
999
940
|
if (!heritageClauses) {
|
|
1000
941
|
return properties;
|
|
1001
942
|
}
|
|
1002
|
-
heritageClauses.forEach(clause => {
|
|
943
|
+
heritageClauses.forEach((clause) => {
|
|
1003
944
|
if (!clause.types) {
|
|
1004
945
|
return;
|
|
1005
946
|
}
|
|
1006
|
-
clause.types.forEach(t => {
|
|
947
|
+
clause.types.forEach((t) => {
|
|
1007
948
|
const baseEntityName = t.expression;
|
|
1008
949
|
// create subContext
|
|
1009
950
|
const resetCtx = this.typeArgumentsToContext(t, baseEntityName, this.context);
|
|
@@ -1025,7 +966,7 @@ class TypeNodeResolver {
|
|
|
1025
966
|
}
|
|
1026
967
|
}
|
|
1027
968
|
else if (referenceType.typeName === 'refObject') {
|
|
1028
|
-
referenceType.properties.forEach(property => properties.push(property));
|
|
969
|
+
referenceType.properties.forEach((property) => properties.push(property));
|
|
1029
970
|
}
|
|
1030
971
|
else {
|
|
1031
972
|
// todo: should never assert
|
|
@@ -1039,15 +980,11 @@ class TypeNodeResolver {
|
|
|
1039
980
|
}
|
|
1040
981
|
hasPublicModifier(node) {
|
|
1041
982
|
return (!node.modifiers ||
|
|
1042
|
-
node.modifiers.every(modifier =>
|
|
1043
|
-
return modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword;
|
|
1044
|
-
}));
|
|
983
|
+
node.modifiers.every((modifier) => modifier.kind !== ts.SyntaxKind.ProtectedKeyword && modifier.kind !== ts.SyntaxKind.PrivateKeyword));
|
|
1045
984
|
}
|
|
1046
985
|
hasStaticModifier(node) {
|
|
1047
986
|
return (node.modifiers &&
|
|
1048
|
-
node.modifiers.some(modifier =>
|
|
1049
|
-
return modifier.kind === ts.SyntaxKind.StaticKeyword;
|
|
1050
|
-
}));
|
|
987
|
+
node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.StaticKeyword));
|
|
1051
988
|
}
|
|
1052
989
|
isAccessibleParameter(node) {
|
|
1053
990
|
// No modifiers
|
|
@@ -1055,14 +992,12 @@ class TypeNodeResolver {
|
|
|
1055
992
|
return false;
|
|
1056
993
|
}
|
|
1057
994
|
// public || public readonly
|
|
1058
|
-
if (node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PublicKeyword)) {
|
|
995
|
+
if (node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.PublicKeyword)) {
|
|
1059
996
|
return true;
|
|
1060
997
|
}
|
|
1061
998
|
// readonly, not private readonly, not public readonly
|
|
1062
|
-
const isReadonly = node.modifiers.some(modifier => modifier.kind === ts.SyntaxKind.ReadonlyKeyword);
|
|
1063
|
-
const isProtectedOrPrivate = node.modifiers.some(modifier =>
|
|
1064
|
-
return modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword;
|
|
1065
|
-
});
|
|
999
|
+
const isReadonly = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword);
|
|
1000
|
+
const isProtectedOrPrivate = node.modifiers.some((modifier) => modifier.kind === ts.SyntaxKind.ProtectedKeyword || modifier.kind === ts.SyntaxKind.PrivateKeyword);
|
|
1066
1001
|
return isReadonly && !isProtectedOrPrivate;
|
|
1067
1002
|
}
|
|
1068
1003
|
getNodeDescription(node) {
|
|
@@ -1093,7 +1028,7 @@ class TypeNodeResolver {
|
|
|
1093
1028
|
try {
|
|
1094
1029
|
return JSON.parse(example);
|
|
1095
1030
|
}
|
|
1096
|
-
catch {
|
|
1031
|
+
catch (_a) {
|
|
1097
1032
|
return undefined;
|
|
1098
1033
|
}
|
|
1099
1034
|
}
|