@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.
Files changed (165) hide show
  1. package/dist/cache/driver.d.ts +1 -1
  2. package/dist/cache/driver.d.ts.map +1 -1
  3. package/dist/cache/driver.js +3 -6
  4. package/dist/cache/driver.js.map +1 -1
  5. package/dist/cache/type.d.ts +1 -1
  6. package/dist/cache/type.d.ts.map +1 -1
  7. package/dist/cache/utils.d.ts +1 -1
  8. package/dist/cache/utils.d.ts.map +1 -1
  9. package/dist/cache/utils.js +14 -14
  10. package/dist/cache/utils.js.map +1 -1
  11. package/dist/config/path.js.map +1 -1
  12. package/dist/decorator/functions.d.ts.map +1 -1
  13. package/dist/decorator/functions.js +9 -13
  14. package/dist/decorator/functions.js.map +1 -1
  15. package/dist/decorator/index.d.ts +1 -1
  16. package/dist/decorator/index.d.ts.map +1 -1
  17. package/dist/decorator/index.js +1 -3
  18. package/dist/decorator/index.js.map +1 -1
  19. package/dist/decorator/mapper/index.d.ts +3 -3
  20. package/dist/decorator/mapper/index.d.ts.map +1 -1
  21. package/dist/decorator/mapper/index.js +6 -11
  22. package/dist/decorator/mapper/index.js.map +1 -1
  23. package/dist/decorator/mapper/maps/decorators-express.d.ts +1 -1
  24. package/dist/decorator/mapper/maps/decorators-express.d.ts.map +1 -1
  25. package/dist/decorator/mapper/maps/decorators-express.js +33 -33
  26. package/dist/decorator/mapper/maps/internal.d.ts +1 -1
  27. package/dist/decorator/mapper/maps/internal.d.ts.map +1 -1
  28. package/dist/decorator/mapper/maps/internal.js +31 -27
  29. package/dist/decorator/mapper/maps/internal.js.map +1 -1
  30. package/dist/decorator/mapper/maps/typescript-rest.d.ts +1 -1
  31. package/dist/decorator/mapper/maps/typescript-rest.d.ts.map +1 -1
  32. package/dist/decorator/mapper/maps/typescript-rest.js +38 -38
  33. package/dist/decorator/mapper/maps/typescript-rest.js.map +1 -1
  34. package/dist/decorator/mapper/utils.d.ts +1 -1
  35. package/dist/decorator/mapper/utils.d.ts.map +1 -1
  36. package/dist/decorator/mapper/utils.js +1 -1
  37. package/dist/decorator/mapper/utils.js.map +1 -1
  38. package/dist/decorator/representation/index.d.ts +1 -1
  39. package/dist/decorator/representation/index.d.ts.map +1 -1
  40. package/dist/decorator/representation/index.js +2 -4
  41. package/dist/decorator/representation/index.js.map +1 -1
  42. package/dist/decorator/representation/property/utils.d.ts +1 -1
  43. package/dist/decorator/representation/property/utils.d.ts.map +1 -1
  44. package/dist/decorator/representation/property/utils.js +7 -6
  45. package/dist/decorator/representation/property/utils.js.map +1 -1
  46. package/dist/decorator/type.d.ts.map +1 -1
  47. package/dist/decorator/utils/node.d.ts +1 -1
  48. package/dist/decorator/utils/node.d.ts.map +1 -1
  49. package/dist/decorator/utils/node.js +4 -6
  50. package/dist/decorator/utils/node.js.map +1 -1
  51. package/dist/decorator/utils/validator.d.ts +2 -2
  52. package/dist/decorator/utils/validator.d.ts.map +1 -1
  53. package/dist/decorator/utils/validator.js +8 -8
  54. package/dist/decorator/utils/validator.js.map +1 -1
  55. package/dist/generator/controller.d.ts +1 -1
  56. package/dist/generator/controller.d.ts.map +1 -1
  57. package/dist/generator/controller.js +1 -1
  58. package/dist/generator/controller.js.map +1 -1
  59. package/dist/generator/endpoint.d.ts +2 -2
  60. package/dist/generator/endpoint.d.ts.map +1 -1
  61. package/dist/generator/endpoint.js +14 -19
  62. package/dist/generator/endpoint.js.map +1 -1
  63. package/dist/generator/index.d.ts +5 -33
  64. package/dist/generator/index.d.ts.map +1 -1
  65. package/dist/generator/index.js +15 -151
  66. package/dist/generator/index.js.map +1 -1
  67. package/dist/generator/method.d.ts +1 -1
  68. package/dist/generator/method.d.ts.map +1 -1
  69. package/dist/generator/method.js +10 -12
  70. package/dist/generator/method.js.map +1 -1
  71. package/dist/generator/module.d.ts +41 -0
  72. package/dist/generator/module.d.ts.map +1 -0
  73. package/dist/generator/module.js +166 -0
  74. package/dist/generator/module.js.map +1 -0
  75. package/dist/generator/parameter.d.ts +1 -1
  76. package/dist/generator/parameter.d.ts.map +1 -1
  77. package/dist/generator/parameter.js +26 -35
  78. package/dist/generator/parameter.js.map +1 -1
  79. package/dist/resolver/type-node.d.ts +1 -1
  80. package/dist/resolver/type-node.d.ts.map +1 -1
  81. package/dist/resolver/type-node.js +124 -189
  82. package/dist/resolver/type-node.js.map +1 -1
  83. package/dist/resolver/type.d.ts +1 -1
  84. package/dist/resolver/type.d.ts.map +1 -1
  85. package/dist/resolver/utils/initializer.d.ts +1 -1
  86. package/dist/resolver/utils/initializer.d.ts.map +1 -1
  87. package/dist/resolver/utils/initializer.js +11 -12
  88. package/dist/resolver/utils/initializer.js.map +1 -1
  89. package/dist/resolver/utils/validator.d.ts +1 -1
  90. package/dist/resolver/utils/validator.d.ts.map +1 -1
  91. package/dist/resolver/utils/validator.js +8 -11
  92. package/dist/resolver/utils/validator.js.map +1 -1
  93. package/dist/type.d.ts +8 -3
  94. package/dist/type.d.ts.map +1 -1
  95. package/dist/utils/generator.d.ts +2 -2
  96. package/dist/utils/generator.d.ts.map +1 -1
  97. package/dist/utils/generator.js +2 -2
  98. package/dist/utils/generator.js.map +1 -1
  99. package/dist/utils/js-doc.d.ts.map +1 -1
  100. package/dist/utils/js-doc.js +7 -11
  101. package/dist/utils/js-doc.js.map +1 -1
  102. package/dist/utils/validator.d.ts +2 -2
  103. package/dist/utils/validator.d.ts.map +1 -1
  104. package/dist/utils/validator.js +2 -2
  105. package/dist/utils/validator.js.map +1 -1
  106. package/package.json +19 -13
  107. package/src/cache/driver.ts +0 -97
  108. package/src/cache/index.ts +0 -10
  109. package/src/cache/type.ts +0 -43
  110. package/src/cache/utils.ts +0 -49
  111. package/src/config/index.ts +0 -8
  112. package/src/config/path.ts +0 -29
  113. package/src/decorator/functions.ts +0 -142
  114. package/src/decorator/index.ts +0 -13
  115. package/src/decorator/mapper/index.ts +0 -153
  116. package/src/decorator/mapper/maps/decorators-express.ts +0 -117
  117. package/src/decorator/mapper/maps/internal.ts +0 -95
  118. package/src/decorator/mapper/maps/typescript-rest.ts +0 -150
  119. package/src/decorator/mapper/utils.ts +0 -88
  120. package/src/decorator/representation/index.ts +0 -82
  121. package/src/decorator/representation/property/utils.ts +0 -146
  122. package/src/decorator/type.ts +0 -235
  123. package/src/decorator/utils/index.ts +0 -9
  124. package/src/decorator/utils/node.ts +0 -59
  125. package/src/decorator/utils/validator.ts +0 -104
  126. package/src/generator/controller.ts +0 -65
  127. package/src/generator/endpoint.ts +0 -212
  128. package/src/generator/index.ts +0 -219
  129. package/src/generator/method.ts +0 -198
  130. package/src/generator/parameter.ts +0 -392
  131. package/src/index.ts +0 -13
  132. package/src/resolver/error.ts +0 -38
  133. package/src/resolver/index.ts +0 -11
  134. package/src/resolver/type-node.ts +0 -1287
  135. package/src/resolver/type.ts +0 -257
  136. package/src/resolver/utils/index.ts +0 -9
  137. package/src/resolver/utils/initializer.ts +0 -81
  138. package/src/resolver/utils/validator.ts +0 -144
  139. package/src/type.ts +0 -185
  140. package/src/utils/generator.ts +0 -42
  141. package/src/utils/index.ts +0 -10
  142. package/src/utils/js-doc.ts +0 -125
  143. package/src/utils/validator.ts +0 -43
  144. package/test/data/library/@decorators-express/decorators.ts +0 -7
  145. package/test/data/library/self/api.ts +0 -37
  146. package/test/data/library/type.ts +0 -138
  147. package/test/data/library/typescript-rest/api.ts +0 -366
  148. package/test/data/library/typescript-rest/decorators/index.ts +0 -10
  149. package/test/data/library/typescript-rest/decorators/methods.ts +0 -34
  150. package/test/data/library/typescript-rest/decorators/parameters.ts +0 -62
  151. package/test/data/library/typescript-rest/decorators/services.ts +0 -47
  152. package/test/data/library/typescript-rest/return-types.ts +0 -94
  153. package/test/data/library/utils.ts +0 -7
  154. package/test/jest.config.js +0 -49
  155. package/test/unit/cache.spec.ts +0 -48
  156. package/test/unit/decorator/mapper/index.spec.ts +0 -83
  157. package/test/unit/decorator/representation/index.spec.ts +0 -102
  158. package/test/unit/decorator/utils/node.spec.ts +0 -47
  159. package/test/unit/library/typescript-rest.spec.ts +0 -342
  160. package/test/unit/resolver/type.spec.ts +0 -134
  161. package/test/unit/utils/generator.spec.ts +0 -41
  162. package/test/unit/utils/js-doc.spec.ts +0 -104
  163. package/tsconfig.build.json +0 -11
  164. package/tsconfig.json +0 -9
  165. package/writable/.gitignore +0 -3
@@ -1,392 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import * as ts from 'typescript';
9
- import {RepresentationManager} from "../decorator/representation";
10
- import {Decorator} from "../decorator/type";
11
- import {MetadataGenerator} from './index';
12
- import {TypeNodeResolver} from '../resolver';
13
- import {Resolver} from "../resolver";
14
- import {getInitializerValue} from "../resolver";
15
- import {ArrayParameter, Parameter} from "../type";
16
- import {getNodeDecorators} from "../decorator/utils/node";
17
-
18
- const supportedParameterKeys : Decorator.ParameterServerType[] = [
19
- 'SERVER_CONTEXT',
20
- 'SERVER_PARAMS',
21
- 'SERVER_QUERY',
22
- 'SERVER_FORM',
23
- 'SERVER_BODY',
24
- 'SERVER_HEADERS',
25
- 'SERVER_COOKIES',
26
- 'SERVER_PATH_PARAMS',
27
- 'SERVER_FILES_PARAM'
28
- ];
29
-
30
- export class ParameterGenerator {
31
- constructor(
32
- private readonly parameter: ts.ParameterDeclaration,
33
- private readonly method: string,
34
- private readonly path: string,
35
- private readonly current: MetadataGenerator
36
- ) { }
37
-
38
- public generate(): Parameter{
39
- const decorators = getNodeDecorators(this.parameter);
40
-
41
- for(let i=0; i<supportedParameterKeys.length; i++) {
42
- const representation = this.current.decoratorMapper.match(supportedParameterKeys[i], decorators);
43
- if(typeof representation === 'undefined') {
44
- continue;
45
- }
46
-
47
- switch (supportedParameterKeys[i]) {
48
- case 'SERVER_CONTEXT':
49
- return this.getContextParameter();
50
- case 'SERVER_PARAMS':
51
- return this.getRequestParameter(representation);
52
- case 'SERVER_FORM':
53
- return this.getFormParameter(representation);
54
- case 'SERVER_QUERY':
55
- return this.getQueryParameter(representation);
56
- case 'SERVER_BODY':
57
- return this.getBodyParameter(representation);
58
- case 'SERVER_HEADERS':
59
- return this.getHeaderParameter(representation);
60
- case 'SERVER_COOKIES':
61
- return this.getCookieParameter(representation);
62
- case 'SERVER_PATH_PARAMS':
63
- return this.getPathParameter(representation);
64
- case 'SERVER_FILE_PARAM':
65
- return this.getFileParameter(representation);
66
- case 'SERVER_FILES_PARAM':
67
- return this.getFileParameter(representation, true);
68
- }
69
- }
70
-
71
- return this.getBodyParameter();
72
- }
73
-
74
- private getCurrentLocation() {
75
- const methodId = (this.parameter.parent as ts.MethodDeclaration).name as ts.Identifier;
76
- const controllerId = ((this.parameter.parent as ts.MethodDeclaration).parent as ts.ClassDeclaration).name as ts.Identifier;
77
- return `${controllerId.text}.${methodId.text}`;
78
- }
79
-
80
- private getRequestParameter(representationManager: RepresentationManager<'SERVER_PARAMS'>): Parameter{
81
- const parameterName = (this.parameter.name as ts.Identifier).text;
82
- let name = parameterName;
83
- const type = this.getValidatedType(this.parameter);
84
-
85
- if (!this.supportsBodyParameters(this.method)) {
86
- throw new Error(`Param can't support '${this.getCurrentLocation()}' method.`);
87
- }
88
-
89
- const value = representationManager.getPropertyValue('DEFAULT');
90
- if(typeof value === 'string') {
91
- name = value;
92
- }
93
-
94
-
95
- return {
96
- description: this.getParameterDescription(this.parameter),
97
- in: 'param',
98
- name: name || parameterName,
99
- parameterName: parameterName,
100
- required: !this.parameter.questionToken,
101
- type: type
102
- };
103
- }
104
-
105
- private getContextParameter(): Parameter {
106
- const parameterName = (this.parameter.name as ts.Identifier).text;
107
-
108
- return {
109
- description: this.getParameterDescription(this.parameter),
110
- in: 'context',
111
- name: parameterName,
112
- parameterName: parameterName,
113
- required: !this.parameter.questionToken,
114
- type: null
115
- };
116
- }
117
-
118
- /*
119
- private getFileParameter(parameter: ts.ParameterDeclaration): Metadata.Parameter{
120
- const parameterName = (parameter.name as ts.Identifier).text;
121
-
122
- if (!this.supportsBodyParameters(this.method)) {
123
- throw new Error(`FileParam can't support '${this.getCurrentLocation()}' method.`);
124
- }
125
-
126
- return {
127
- description: this.getParameterDescription(parameter),
128
- in: 'formData',
129
- name: getDecoratorTextValue(this.parameter, ident => ident.text === 'FileParam') || parameterName,
130
- parameterName: parameterName,
131
- required: !parameter.questionToken,
132
- type: { typeName: 'file' }
133
- };
134
- }
135
- */
136
-
137
- private getFileParameter(
138
- representationManager: RepresentationManager<'SERVER_FILE_PARAM' | 'SERVER_FILES_PARAM'>,
139
- isArray?: boolean
140
- ) : Parameter{
141
- const parameterName = (this.parameter.name as ts.Identifier).text;
142
- let name = parameterName;
143
-
144
- if (!this.supportsBodyParameters(this.method)) {
145
- throw new Error(`File(s)Param can't support '${this.getCurrentLocation()}' method.`);
146
- }
147
-
148
- const value = representationManager.getPropertyValue('DEFAULT');
149
- if(typeof value === 'string') {
150
- name = value;
151
- }
152
-
153
- const elementType: Resolver.Type = { typeName: 'file' };
154
- let type: Resolver.Type;
155
- if (isArray) {
156
- type = { typeName: 'array', elementType: elementType };
157
- } else {
158
- type = elementType;
159
- }
160
-
161
- return {
162
- description: this.getParameterDescription(this.parameter),
163
- in: 'formData',
164
- name: name || parameterName,
165
- parameterName: parameterName,
166
- required: !this.parameter.questionToken && !this.parameter.initializer,
167
- type: type
168
- };
169
- }
170
-
171
- private getFormParameter(representationManager: RepresentationManager<'SERVER_FORM'>): Parameter{
172
- const parameterName = (this.parameter.name as ts.Identifier).text;
173
- let name = parameterName;
174
-
175
- const type = this.getValidatedType(this.parameter);
176
-
177
- if (!this.supportsBodyParameters(this.method)) {
178
- throw new Error(`Form can't support '${this.getCurrentLocation()}' method.`);
179
- }
180
-
181
- const value = representationManager.getPropertyValue('DEFAULT');
182
- if(typeof value === 'string') {
183
- name = value;
184
- }
185
-
186
-
187
- return {
188
- description: this.getParameterDescription(this.parameter),
189
- in: 'formData',
190
- name: name || parameterName,
191
- parameterName: parameterName,
192
- required: !this.parameter.questionToken && !this.parameter.initializer,
193
- type: type
194
- };
195
- }
196
-
197
- private getCookieParameter(representationManager: RepresentationManager<'SERVER_COOKIES'>): Parameter{
198
- const parameterName = (this.parameter.name as ts.Identifier).text;
199
- let name = parameterName;
200
-
201
- const type = this.getValidatedType(this.parameter);
202
-
203
- if (!this.supportPathDataType(type)) {
204
- throw new Error(`Cookie can't support '${this.getCurrentLocation()}' method.`);
205
- }
206
-
207
- const value = representationManager.getPropertyValue('DEFAULT');
208
- if(typeof value === 'string') {
209
- name = value;
210
- }
211
-
212
- return {
213
- description: this.getParameterDescription(this.parameter),
214
- in: 'cookie',
215
- name: name || parameterName,
216
- parameterName: parameterName,
217
- required: !this.parameter.questionToken && !this.parameter.initializer,
218
- type: type
219
- };
220
- }
221
-
222
- private getBodyParameter(representationManager?: RepresentationManager<'SERVER_BODY'>): Parameter{
223
- const parameterName = (this.parameter.name as ts.Identifier).text;
224
- let name = parameterName;
225
-
226
- const type = this.getValidatedType(this.parameter);
227
-
228
- if (!this.supportsBodyParameters(this.method)) {
229
- throw new Error(`Body can't support ${this.method} method`);
230
- }
231
-
232
- if(typeof representationManager !== 'undefined') {
233
- const value = representationManager.getPropertyValue('DEFAULT');
234
- if (typeof value === 'string') {
235
- name = value;
236
- }
237
- }
238
-
239
- return {
240
- description: this.getParameterDescription(this.parameter),
241
- in: 'body',
242
- name: name || parameterName,
243
- parameterName: parameterName,
244
- required: !this.parameter.questionToken && !this.parameter.initializer,
245
- type: type
246
- };
247
- }
248
-
249
- private getHeaderParameter(representationManager: RepresentationManager<'SERVER_HEADERS'>) : Parameter{
250
- const parameterName = (this.parameter.name as ts.Identifier).text;
251
- let name = parameterName;
252
-
253
- const type = this.getValidatedType(this.parameter);
254
-
255
- if (!this.supportPathDataType(type)) {
256
- throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a header parameter in '${this.getCurrentLocation()}'.`);
257
- }
258
-
259
- const value = representationManager.getPropertyValue('DEFAULT');
260
- if(typeof value === 'string') {
261
- name = value;
262
- }
263
-
264
- return {
265
- description: this.getParameterDescription(this.parameter),
266
- in: 'header',
267
- name: name || parameterName,
268
- parameterName: parameterName,
269
- required: !this.parameter.questionToken && !this.parameter.initializer,
270
- type: type
271
- };
272
- }
273
-
274
- private getQueryParameter(representationManager: RepresentationManager<'SERVER_QUERY'>): Parameter| ArrayParameter {
275
- const parameterName = (this.parameter.name as ts.Identifier).text;
276
- const type = this.getValidatedType(this.parameter);
277
-
278
- if (!this.supportQueryDataType(type)) {
279
- /*
280
- const arrayType = getCommonPrimitiveAndArrayUnionType(parameter.type);
281
- if (arrayType && this.supportQueryDataType(arrayType)) {
282
- type = arrayType;
283
- } else {
284
- throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.`);
285
- }
286
- */
287
- // throw new InvalidParameterException(`Parameter '${parameterName}' can't be passed as a query parameter in '${this.getCurrentLocation()}'.`);
288
- }
289
- let name : string = parameterName;
290
- let options : any = {};
291
-
292
- const nameValue = representationManager.getPropertyValue('DEFAULT');
293
- if(typeof nameValue === 'string') {
294
- name = nameValue;
295
- }
296
-
297
- const optionsValue = representationManager.getPropertyValue('OPTIONS');
298
- if(typeof optionsValue !== 'undefined') {
299
- options = optionsValue;
300
- }
301
-
302
- const properties : Parameter= {
303
- allowEmptyValue: options.allowEmptyValue,
304
- collectionFormat: options.collectionFormat,
305
- default: getInitializerValue(this.parameter.initializer, this.current.typeChecker, type),
306
- description: this.getParameterDescription(this.parameter),
307
- in: 'query',
308
- maxItems: options.maxItems,
309
- minItems: options.minItems,
310
- name: name,
311
- parameterName: parameterName,
312
- required: !this.parameter.questionToken && !this.parameter.initializer,
313
- type: type
314
- };
315
-
316
- if (type.typeName === 'array') {
317
- return {
318
- ...properties,
319
- collectionFormat: 'multi',
320
- type: type,
321
- };
322
- }
323
-
324
- return properties;
325
- }
326
-
327
- private getPathParameter(representationManager: RepresentationManager<'SERVER_PATH_PARAMS'>): Parameter {
328
- const parameterName = (this.parameter.name as ts.Identifier).text;
329
- let pathName = parameterName;
330
-
331
- const type = this.getValidatedType(this.parameter);
332
-
333
- const value = representationManager.getPropertyValue('DEFAULT');
334
- if(typeof value === 'string') {
335
- pathName = value;
336
- }
337
-
338
-
339
- if (!this.supportPathDataType(type)) {
340
- throw new InvalidParameterException(`Parameter '${parameterName}:${type}' can't be passed as a path parameter in '${this.getCurrentLocation()}'.`);
341
- }
342
-
343
- if ((!this.path.includes(`{${pathName}}`)) && (!this.path.includes(`:${pathName}`))) {
344
- throw new Error(`Parameter '${parameterName}' can't match in path: '${this.path}'`);
345
- }
346
-
347
- return {
348
- description: this.getParameterDescription(this.parameter),
349
- in: 'path',
350
- name: pathName,
351
- parameterName: parameterName,
352
- required: true,
353
- type: type
354
- };
355
- }
356
-
357
- private getParameterDescription(node: ts.ParameterDeclaration) {
358
- const symbol = this.current.typeChecker.getSymbolAtLocation(node.name);
359
-
360
- if (symbol) {
361
- const comments = symbol.getDocumentationComment(this.current.typeChecker);
362
- if (comments.length) { return ts.displayPartsToString(comments); }
363
- }
364
-
365
- return '';
366
- }
367
-
368
- private supportsBodyParameters(method: string) {
369
- return ['delete', 'post', 'put', 'patch', 'get'].some(m => m === method);
370
- }
371
- private supportPathDataType(parameterType: Resolver.BaseType) {
372
- return ['string', 'integer', 'long', 'float', 'double', 'date', 'datetime', 'buffer', 'boolean', 'enum'].find(t => t === parameterType.typeName);
373
- }
374
-
375
- private supportQueryDataType(parameterType: Resolver.BaseType) {
376
- // Copied from supportPathDataType and added 'array'. Not sure if all options apply to queries, but kept to avoid breaking change.
377
- return ['string', 'integer', 'long', 'float', 'double', 'date',
378
- 'datetime', 'buffer', 'boolean', 'enum', 'array', 'object'].find(t => t === parameterType.typeName);
379
- }
380
-
381
- private getValidatedType(parameter: ts.ParameterDeclaration) {
382
- let typeNode = parameter.type;
383
- if (!typeNode) {
384
- const type = this.current.typeChecker.getTypeAtLocation(parameter);
385
- typeNode = this.current.typeChecker.typeToTypeNode(type, undefined, ts.NodeBuilderFlags.NoTruncation) as ts.TypeNode;
386
- }
387
-
388
- return new TypeNodeResolver(typeNode, this.current, parameter).resolve();
389
- }
390
- }
391
-
392
- class InvalidParameterException extends Error { }
package/src/index.ts DELETED
@@ -1,13 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- export * from './cache';
9
- export * from './decorator';
10
- export * from './generator';
11
- export * from './resolver';
12
- export * from './utils';
13
- export * from './type';
@@ -1,38 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- import { normalize } from "path";
9
- import { Node, TypeNode } from 'typescript';
10
-
11
- export class ResolverError extends Error {
12
- constructor(message?: string, node?: Node | TypeNode, onlyCurrent = false) {
13
- super(message);
14
-
15
- if (node) {
16
- this.message = `${message!}\n${prettyLocationOfNode(node)}\n${prettyTroubleCause(node, onlyCurrent)}`;
17
- }
18
- }
19
- }
20
-
21
- export function prettyLocationOfNode(node: Node | TypeNode) {
22
- const sourceFile = node.getSourceFile();
23
- const token = node.getFirstToken() || node.parent.getFirstToken();
24
- const start = token ? `:${sourceFile.getLineAndCharacterOfPosition(token.getStart()).line + 1}` : '';
25
- const end = token ? `:${sourceFile.getLineAndCharacterOfPosition(token.getEnd()).line + 1}` : '';
26
- const normalizedPath = normalize(`${sourceFile.fileName}${start}${end}`);
27
- return `At: ${normalizedPath}.`;
28
- }
29
-
30
- export function prettyTroubleCause(node: Node | TypeNode, onlyCurrent = false) {
31
- let name: string;
32
- if (onlyCurrent || !node.parent) {
33
- name = node.pos !== -1 ? node.getText() : (node as any).name.text;
34
- } else {
35
- name = node.parent.pos !== -1 ? node.parent.getText() : (node as any).parent.name.text;
36
- }
37
- return `This was caused by '${name}'`;
38
- }
@@ -1,11 +0,0 @@
1
- /*
2
- * Copyright (c) 2021.
3
- * Author Peter Placzek (tada5hi)
4
- * For the full copyright and license information,
5
- * view the LICENSE file that was distributed with this source code.
6
- */
7
-
8
- export * from './error';
9
- export * from './type';
10
- export * from './type-node';
11
- export * from './utils/initializer';