@trapi/metadata 1.0.0-alpha.7 → 1.0.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.
Files changed (176) hide show
  1. package/dist/cache/driver.d.ts +13 -13
  2. package/dist/cache/driver.js +83 -83
  3. package/dist/cache/index.d.ts +3 -3
  4. package/dist/cache/index.js +25 -25
  5. package/dist/cache/type.d.ts +32 -32
  6. package/dist/cache/type.js +8 -8
  7. package/dist/cache/utils.d.ts +3 -3
  8. package/dist/cache/utils.js +52 -52
  9. package/dist/config/index.d.ts +1 -1
  10. package/dist/config/index.js +23 -23
  11. package/dist/config/type.d.ts +36 -36
  12. package/dist/config/type.js +8 -8
  13. package/dist/decorator/constants.d.ts +40 -40
  14. package/dist/decorator/constants.js +52 -52
  15. package/dist/decorator/constants.js.map +1 -1
  16. package/dist/decorator/index.d.ts +6 -6
  17. package/dist/decorator/index.js +28 -28
  18. package/dist/decorator/preset/index.d.ts +2 -2
  19. package/dist/decorator/preset/index.js +24 -24
  20. package/dist/decorator/preset/type.d.ts +5 -5
  21. package/dist/decorator/preset/type.js +8 -8
  22. package/dist/decorator/preset/utils/check.d.ts +2 -2
  23. package/dist/decorator/preset/utils/check.js +17 -17
  24. package/dist/decorator/preset/utils/index.d.ts +3 -3
  25. package/dist/decorator/preset/utils/index.js +25 -25
  26. package/dist/decorator/preset/utils/load.d.ts +2 -2
  27. package/dist/decorator/preset/utils/load.js +44 -44
  28. package/dist/decorator/preset/utils/normalize.d.ts +1 -1
  29. package/dist/decorator/preset/utils/normalize.js +26 -26
  30. package/dist/decorator/property-manager/index.d.ts +2 -2
  31. package/dist/decorator/property-manager/index.js +24 -24
  32. package/dist/decorator/property-manager/module.d.ts +16 -16
  33. package/dist/decorator/property-manager/module.js +58 -58
  34. package/dist/decorator/property-manager/utils.d.ts +5 -5
  35. package/dist/decorator/property-manager/utils.d.ts.map +1 -1
  36. package/dist/decorator/property-manager/utils.js +91 -91
  37. package/dist/decorator/resolver/index.d.ts +2 -2
  38. package/dist/decorator/resolver/index.js +24 -24
  39. package/dist/decorator/resolver/module.d.ts +26 -26
  40. package/dist/decorator/resolver/module.js +71 -71
  41. package/dist/decorator/resolver/type.d.ts +9 -9
  42. package/dist/decorator/resolver/type.js +2 -2
  43. package/dist/decorator/sets/class.d.ts +6 -6
  44. package/dist/decorator/sets/class.js +8 -8
  45. package/dist/decorator/sets/index.d.ts +7 -7
  46. package/dist/decorator/sets/index.js +28 -28
  47. package/dist/decorator/sets/method.d.ts +13 -13
  48. package/dist/decorator/sets/method.js +8 -8
  49. package/dist/decorator/sets/mixed.d.ts +11 -11
  50. package/dist/decorator/sets/mixed.js +8 -8
  51. package/dist/decorator/sets/parameter.d.ts +20 -20
  52. package/dist/decorator/sets/parameter.js +8 -8
  53. package/dist/decorator/sets/request.d.ts +5 -5
  54. package/dist/decorator/sets/request.js +8 -8
  55. package/dist/decorator/sets/response.d.ts +16 -16
  56. package/dist/decorator/sets/response.js +8 -8
  57. package/dist/decorator/sets/type.d.ts +3 -3
  58. package/dist/decorator/sets/type.js +2 -2
  59. package/dist/decorator/type.d.ts +31 -31
  60. package/dist/decorator/type.js +8 -8
  61. package/dist/error/base.d.ts +2 -2
  62. package/dist/error/base.js +12 -12
  63. package/dist/error/index.d.ts +1 -1
  64. package/dist/error/index.js +23 -23
  65. package/dist/generator/abstract.d.ts +18 -18
  66. package/dist/generator/abstract.js +150 -150
  67. package/dist/generator/abstract.js.map +1 -1
  68. package/dist/generator/controller/index.d.ts +2 -2
  69. package/dist/generator/controller/index.js +24 -24
  70. package/dist/generator/controller/module.d.ts +12 -12
  71. package/dist/generator/controller/module.js +67 -67
  72. package/dist/generator/controller/type.d.ts +46 -46
  73. package/dist/generator/controller/type.js +2 -2
  74. package/dist/generator/index.d.ts +6 -6
  75. package/dist/generator/index.js +28 -28
  76. package/dist/generator/metadata/index.d.ts +3 -3
  77. package/dist/generator/metadata/index.js +25 -25
  78. package/dist/generator/metadata/module.d.ts +38 -38
  79. package/dist/generator/metadata/module.js +139 -142
  80. package/dist/generator/metadata/module.js.map +1 -1
  81. package/dist/generator/metadata/type.d.ts +24 -24
  82. package/dist/generator/metadata/type.js +2 -2
  83. package/dist/generator/metadata/utils.d.ts +2 -2
  84. package/dist/generator/metadata/utils.js +18 -18
  85. package/dist/generator/method/constants.d.ts +10 -10
  86. package/dist/generator/method/constants.js +20 -20
  87. package/dist/generator/method/constants.js.map +1 -1
  88. package/dist/generator/method/index.d.ts +3 -3
  89. package/dist/generator/method/index.js +25 -25
  90. package/dist/generator/method/module.d.ts +18 -18
  91. package/dist/generator/method/module.js +187 -187
  92. package/dist/generator/method/type.d.ts +22 -22
  93. package/dist/generator/method/type.js +8 -8
  94. package/dist/generator/parameter/constants.d.ts +18 -18
  95. package/dist/generator/parameter/constants.js +29 -29
  96. package/dist/generator/parameter/constants.js.map +1 -1
  97. package/dist/generator/parameter/error.d.ts +34 -34
  98. package/dist/generator/parameter/error.js +67 -67
  99. package/dist/generator/parameter/index.d.ts +4 -4
  100. package/dist/generator/parameter/index.js +26 -26
  101. package/dist/generator/parameter/module.d.ts +28 -28
  102. package/dist/generator/parameter/module.js +555 -555
  103. package/dist/generator/parameter/type.d.ts +24 -24
  104. package/dist/generator/parameter/type.js +8 -8
  105. package/dist/generator/type.d.ts +19 -19
  106. package/dist/generator/type.js +8 -8
  107. package/dist/index.d.ts +9 -9
  108. package/dist/index.js +31 -31
  109. package/dist/module.d.ts +4 -4
  110. package/dist/module.js +40 -40
  111. package/dist/resolver/constants.d.ts +26 -26
  112. package/dist/resolver/constants.js +36 -36
  113. package/dist/resolver/constants.js.map +1 -1
  114. package/dist/resolver/error.d.ts +7 -7
  115. package/dist/resolver/error.js +40 -40
  116. package/dist/resolver/extension/index.d.ts +2 -2
  117. package/dist/resolver/extension/index.js +24 -24
  118. package/dist/resolver/extension/module.d.ts +4 -4
  119. package/dist/resolver/extension/module.js +26 -26
  120. package/dist/resolver/extension/type.d.ts +7 -7
  121. package/dist/resolver/extension/type.js +8 -8
  122. package/dist/resolver/index.d.ts +5 -5
  123. package/dist/resolver/index.js +27 -27
  124. package/dist/resolver/module.d.ts +53 -53
  125. package/dist/resolver/module.js +1102 -1102
  126. package/dist/resolver/type.d.ts +138 -138
  127. package/dist/resolver/type.js +129 -129
  128. package/dist/type.d.ts +1 -1
  129. package/dist/type.js +8 -8
  130. package/dist/utils/array.d.ts +2 -0
  131. package/dist/utils/array.d.ts.map +1 -0
  132. package/dist/utils/array.js +22 -0
  133. package/dist/utils/array.js.map +1 -0
  134. package/dist/utils/index.d.ts +9 -8
  135. package/dist/utils/index.d.ts.map +1 -1
  136. package/dist/utils/index.js +31 -30
  137. package/dist/utils/index.js.map +1 -1
  138. package/dist/utils/initializer.d.ts +4 -4
  139. package/dist/utils/initializer.js +130 -130
  140. package/dist/utils/js-doc/constants.d.ts +18 -18
  141. package/dist/utils/js-doc/constants.js +29 -29
  142. package/dist/utils/js-doc/constants.js.map +1 -1
  143. package/dist/utils/js-doc/index.d.ts +3 -3
  144. package/dist/utils/js-doc/index.js +25 -25
  145. package/dist/utils/js-doc/module.d.ts +8 -8
  146. package/dist/utils/js-doc/module.js +97 -97
  147. package/dist/utils/js-doc/utils.d.ts +2 -2
  148. package/dist/utils/js-doc/utils.js +28 -28
  149. package/dist/utils/node/index.d.ts +2 -2
  150. package/dist/utils/node/index.js +24 -24
  151. package/dist/utils/node/module.d.ts +9 -9
  152. package/dist/utils/node/module.js +51 -51
  153. package/dist/utils/node/type.d.ts +5 -5
  154. package/dist/utils/node/type.js +8 -8
  155. package/dist/utils/object.d.ts +1 -1
  156. package/dist/utils/object.js +14 -14
  157. package/dist/utils/path-normalize.d.ts +1 -1
  158. package/dist/utils/path-normalize.js +16 -16
  159. package/dist/utils/source-files.d.ts +2 -2
  160. package/dist/utils/source-files.js +31 -31
  161. package/dist/utils/tsconfig/index.d.ts +2 -2
  162. package/dist/utils/tsconfig/index.js +24 -24
  163. package/dist/utils/tsconfig/module.d.ts +3 -3
  164. package/dist/utils/tsconfig/module.js +53 -53
  165. package/dist/utils/tsconfig/type.d.ts +10 -10
  166. package/dist/utils/tsconfig/type.js +8 -8
  167. package/dist/utils/validator/constants.d.ts +12 -12
  168. package/dist/utils/validator/constants.js +22 -22
  169. package/dist/utils/validator/constants.js.map +1 -1
  170. package/dist/utils/validator/index.d.ts +3 -3
  171. package/dist/utils/validator/index.js +25 -25
  172. package/dist/utils/validator/module.d.ts +3 -3
  173. package/dist/utils/validator/module.js +141 -141
  174. package/dist/utils/validator/type.d.ts +5 -5
  175. package/dist/utils/validator/type.js +8 -8
  176. package/package.json +6 -7
@@ -1,11 +1,11 @@
1
- export declare enum MethodName {
2
- ALL = "ALL",
3
- GET = "GET",
4
- POST = "POST",
5
- PUT = "PUT",
6
- DELETE = "DELETE",
7
- PATCH = "PATCH",
8
- OPTIONS = "OPTIONS",
9
- HEAD = "HEAD"
10
- }
1
+ export declare enum MethodName {
2
+ ALL = "ALL",
3
+ GET = "GET",
4
+ POST = "POST",
5
+ PUT = "PUT",
6
+ DELETE = "DELETE",
7
+ PATCH = "PATCH",
8
+ OPTIONS = "OPTIONS",
9
+ HEAD = "HEAD"
10
+ }
11
11
  //# sourceMappingURL=constants.d.ts.map
@@ -1,21 +1,21 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.MethodName = void 0;
10
- var MethodName;
11
- (function (MethodName) {
12
- MethodName["ALL"] = "ALL";
13
- MethodName["GET"] = "GET";
14
- MethodName["POST"] = "POST";
15
- MethodName["PUT"] = "PUT";
16
- MethodName["DELETE"] = "DELETE";
17
- MethodName["PATCH"] = "PATCH";
18
- MethodName["OPTIONS"] = "OPTIONS";
19
- MethodName["HEAD"] = "HEAD";
20
- })(MethodName = exports.MethodName || (exports.MethodName = {}));
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.MethodName = void 0;
10
+ var MethodName;
11
+ (function (MethodName) {
12
+ MethodName["ALL"] = "ALL";
13
+ MethodName["GET"] = "GET";
14
+ MethodName["POST"] = "POST";
15
+ MethodName["PUT"] = "PUT";
16
+ MethodName["DELETE"] = "DELETE";
17
+ MethodName["PATCH"] = "PATCH";
18
+ MethodName["OPTIONS"] = "OPTIONS";
19
+ MethodName["HEAD"] = "HEAD";
20
+ })(MethodName || (exports.MethodName = MethodName = {}));
21
21
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/generator/method/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,IAAY,UASX;AATD,WAAY,UAAU;IAClB,yBAAW,CAAA;IACX,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,iCAAmB,CAAA;IACnB,2BAAa,CAAA;AACjB,CAAC,EATW,UAAU,GAAV,kBAAU,KAAV,kBAAU,QASrB"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/generator/method/constants.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,IAAY,UASX;AATD,WAAY,UAAU;IAClB,yBAAW,CAAA;IACX,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,+BAAiB,CAAA;IACjB,6BAAe,CAAA;IACf,iCAAmB,CAAA;IACnB,2BAAa,CAAA;AACjB,CAAC,EATW,UAAU,0BAAV,UAAU,QASrB"}
@@ -1,4 +1,4 @@
1
- export * from './constants';
2
- export * from './module';
3
- export * from './type';
1
+ export * from './constants';
2
+ export * from './module';
3
+ export * from './type';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -1,26 +1,26 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
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);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./constants"), exports);
24
- __exportStar(require("./module"), exports);
25
- __exportStar(require("./type"), exports);
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
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);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./constants"), exports);
24
+ __exportStar(require("./module"), exports);
25
+ __exportStar(require("./type"), exports);
26
26
  //# sourceMappingURL=index.js.map
@@ -1,19 +1,19 @@
1
- import type { MethodDeclaration } from 'typescript';
2
- import { AbstractGenerator } from '../abstract';
3
- import type { MetadataGenerator } from '../metadata';
4
- import type { Method } from './type';
5
- export declare class MethodGenerator extends AbstractGenerator<MethodDeclaration> {
6
- private method;
7
- constructor(node: MethodDeclaration, current: MetadataGenerator);
8
- isValid(): boolean;
9
- getMethodName(): string;
10
- generate(controllerPath: string): Method;
11
- protected getCurrentLocation(): string;
12
- private buildParameters;
13
- private determineVerb;
14
- private buildResponse;
15
- private guessResponseType;
16
- private getResponseExamples;
17
- private mergeResponses;
18
- }
1
+ import type { MethodDeclaration } from 'typescript';
2
+ import { AbstractGenerator } from '../abstract';
3
+ import type { MetadataGenerator } from '../metadata';
4
+ import type { Method } from './type';
5
+ export declare class MethodGenerator extends AbstractGenerator<MethodDeclaration> {
6
+ private method;
7
+ constructor(node: MethodDeclaration, current: MetadataGenerator);
8
+ isValid(): boolean;
9
+ getMethodName(): string;
10
+ generate(controllerPath: string): Method;
11
+ protected getCurrentLocation(): string;
12
+ private buildParameters;
13
+ private determineVerb;
14
+ private buildResponse;
15
+ private guessResponseType;
16
+ private getResponseExamples;
17
+ private mergeResponses;
18
+ }
19
19
  //# sourceMappingURL=module.d.ts.map
@@ -1,188 +1,188 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2021-2023.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __importDefault = (this && this.__importDefault) || function (mod) {
9
- return (mod && mod.__esModule) ? mod : { "default": mod };
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.MethodGenerator = void 0;
13
- const node_path_1 = __importDefault(require("node:path"));
14
- const typescript_1 = require("typescript");
15
- const decorator_1 = require("../../decorator");
16
- const resolver_1 = require("../../resolver");
17
- const utils_1 = require("../../utils");
18
- const abstract_1 = require("../abstract");
19
- const parameter_1 = require("../parameter");
20
- class MethodGenerator extends abstract_1.AbstractGenerator {
21
- // --------------------------------------------------------------------
22
- constructor(node, current) {
23
- super(node, current);
24
- this.determineVerb();
25
- }
26
- // --------------------------------------------------------------------
27
- isValid() {
28
- return typeof this.method !== 'undefined';
29
- }
30
- getMethodName() {
31
- const identifier = this.node.name;
32
- return identifier.text;
33
- }
34
- generate(controllerPath) {
35
- let nodeType = this.node.type;
36
- if (!nodeType) {
37
- const { typeChecker } = this.current;
38
- const signature = typeChecker.getSignatureFromDeclaration(this.node);
39
- const implicitType = typeChecker.getReturnTypeOfSignature(signature);
40
- nodeType = typeChecker.typeToTypeNode(implicitType, undefined, typescript_1.NodeBuilderFlags.NoTruncation);
41
- }
42
- const type = new resolver_1.TypeNodeResolver(nodeType, this.current).resolve();
43
- const responses = this.mergeResponses(this.buildResponses(), this.buildResponse(type));
44
- const methodPath = this.buildPath();
45
- return {
46
- consumes: this.getConsumes(),
47
- deprecated: this.isDeprecated(this.node),
48
- description: (0, utils_1.getJSDocDescription)(this.node),
49
- extensions: (0, resolver_1.getNodeExtensions)(this.node, this.current.decoratorResolver),
50
- hidden: this.isHidden(this.node),
51
- method: this.method,
52
- name: this.node.name.text,
53
- path: methodPath,
54
- produces: this.getProduces(),
55
- responses,
56
- security: this.getSecurity(),
57
- summary: (0, utils_1.getJSDocTagComment)(this.node, utils_1.JSDocTagName.SUMMARY),
58
- tags: this.getTags(),
59
- type,
60
- parameters: this.buildParameters(controllerPath, methodPath),
61
- };
62
- }
63
- getCurrentLocation() {
64
- const methodId = this.node.name;
65
- const controllerId = this.node.parent.name;
66
- return `${controllerId.text}.${methodId.text}`;
67
- }
68
- buildParameters(controllerPath, methodPath) {
69
- const controllerId = this.node.parent.name;
70
- const methodId = this.node.name;
71
- const fullPath = node_path_1.default.posix.join('/', controllerPath, methodPath);
72
- const output = [];
73
- let bodyParameterCount = 0;
74
- let formParameterCount = 0;
75
- for (let i = 0; i < this.node.parameters.length; i++) {
76
- try {
77
- const generator = new parameter_1.ParameterGenerator(this.node.parameters[i], this.method, fullPath, this.current);
78
- const parameters = generator.generate();
79
- for (let j = 0; j < parameters.length; j++) {
80
- if (parameters[j].in === parameter_1.ParameterSource.BODY) {
81
- bodyParameterCount++;
82
- }
83
- if (parameters[j].in === parameter_1.ParameterSource.FORM_DATA) {
84
- formParameterCount++;
85
- }
86
- if (parameters[j].in !== parameter_1.ParameterSource.CONTEXT) {
87
- output.push(parameters[j]);
88
- }
89
- }
90
- }
91
- catch (e) {
92
- const parameterId = this.node.parameters[i].name;
93
- throw new Error(`Parameter generation: '${controllerId.text}.${methodId.text}' argument: ${parameterId.text} ${e}`);
94
- }
95
- }
96
- if (bodyParameterCount > 1) {
97
- throw new Error(`Only one body parameter allowed in '${this.getCurrentLocation()}' method.`);
98
- }
99
- if (bodyParameterCount > 0 && formParameterCount > 0) {
100
- throw new Error(`Choose either form-, file- or body-parameter in '${this.getCurrentLocation()}' method.`);
101
- }
102
- return output;
103
- }
104
- determineVerb() {
105
- const methods = [
106
- decorator_1.DecoratorID.ALL,
107
- decorator_1.DecoratorID.DELETE,
108
- decorator_1.DecoratorID.GET,
109
- decorator_1.DecoratorID.HEAD,
110
- decorator_1.DecoratorID.OPTIONS,
111
- decorator_1.DecoratorID.PATCH,
112
- decorator_1.DecoratorID.POST,
113
- decorator_1.DecoratorID.PUT,
114
- ];
115
- const decorators = (0, utils_1.getNodeDecorators)(this.node);
116
- let method;
117
- for (let i = 0; i < methods.length; i++) {
118
- const representationManager = this.current.decoratorResolver.match(methods[i], decorators);
119
- if (representationManager) {
120
- method = methods[i];
121
- break;
122
- }
123
- }
124
- if (typeof method === 'undefined') {
125
- return;
126
- }
127
- this.method = method.toLowerCase();
128
- }
129
- buildResponse(type) {
130
- type = this.guessResponseType(type);
131
- return {
132
- description: (0, resolver_1.isVoidType)(type) ? 'No content' : 'Ok',
133
- examples: this.getResponseExamples(),
134
- schema: type,
135
- status: (0, resolver_1.isVoidType)(type) ? '204' : '200',
136
- name: (0, resolver_1.isVoidType)(type) ? '204' : '200',
137
- };
138
- }
139
- guessResponseType(type) {
140
- if (!(0, resolver_1.isVoidType)(type)) {
141
- return type;
142
- }
143
- const representation = this.current.decoratorResolver.match(decorator_1.DecoratorID.EXAMPLE, this.node);
144
- if (typeof representation === 'undefined') {
145
- return type;
146
- }
147
- const value = representation.get('type');
148
- if (typeof value !== 'undefined' &&
149
- (0, utils_1.hasOwnProperty)(value, 'kind') &&
150
- (0, typescript_1.isTypeNode)(value)) {
151
- type = new resolver_1.TypeNodeResolver(value, this.current).resolve();
152
- }
153
- return type;
154
- }
155
- getResponseExamples() {
156
- const representation = this.current.decoratorResolver.match(decorator_1.DecoratorID.EXAMPLE, this.node);
157
- if (typeof representation === 'undefined') {
158
- return [];
159
- }
160
- const output = [];
161
- for (let i = 0; i < representation.decorators.length; i++) {
162
- const value = representation.get('payload');
163
- const label = representation.get('label');
164
- if (typeof value !== 'undefined') {
165
- output.push({ value, label });
166
- }
167
- }
168
- return output;
169
- }
170
- mergeResponses(responses, exampleResponse) {
171
- if (!responses || !responses.length) {
172
- return [exampleResponse];
173
- }
174
- const index = responses.findIndex((resp) => resp.status === exampleResponse.status);
175
- if (index >= 0) {
176
- if (exampleResponse.examples &&
177
- (!responses[index].examples || !responses[index].examples.length)) {
178
- responses[index].examples = exampleResponse.examples;
179
- }
180
- }
181
- else {
182
- responses.push(exampleResponse);
183
- }
184
- return responses;
185
- }
186
- }
187
- exports.MethodGenerator = MethodGenerator;
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2021-2023.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MethodGenerator = void 0;
13
+ const node_path_1 = __importDefault(require("node:path"));
14
+ const typescript_1 = require("typescript");
15
+ const decorator_1 = require("../../decorator");
16
+ const resolver_1 = require("../../resolver");
17
+ const utils_1 = require("../../utils");
18
+ const abstract_1 = require("../abstract");
19
+ const parameter_1 = require("../parameter");
20
+ class MethodGenerator extends abstract_1.AbstractGenerator {
21
+ // --------------------------------------------------------------------
22
+ constructor(node, current) {
23
+ super(node, current);
24
+ this.determineVerb();
25
+ }
26
+ // --------------------------------------------------------------------
27
+ isValid() {
28
+ return typeof this.method !== 'undefined';
29
+ }
30
+ getMethodName() {
31
+ const identifier = this.node.name;
32
+ return identifier.text;
33
+ }
34
+ generate(controllerPath) {
35
+ let nodeType = this.node.type;
36
+ if (!nodeType) {
37
+ const { typeChecker } = this.current;
38
+ const signature = typeChecker.getSignatureFromDeclaration(this.node);
39
+ const implicitType = typeChecker.getReturnTypeOfSignature(signature);
40
+ nodeType = typeChecker.typeToTypeNode(implicitType, undefined, typescript_1.NodeBuilderFlags.NoTruncation);
41
+ }
42
+ const type = new resolver_1.TypeNodeResolver(nodeType, this.current).resolve();
43
+ const responses = this.mergeResponses(this.buildResponses(), this.buildResponse(type));
44
+ const methodPath = this.buildPath();
45
+ return {
46
+ consumes: this.getConsumes(),
47
+ deprecated: this.isDeprecated(this.node),
48
+ description: (0, utils_1.getJSDocDescription)(this.node),
49
+ extensions: (0, resolver_1.getNodeExtensions)(this.node, this.current.decoratorResolver),
50
+ hidden: this.isHidden(this.node),
51
+ method: this.method,
52
+ name: this.node.name.text,
53
+ path: methodPath,
54
+ produces: this.getProduces(),
55
+ responses,
56
+ security: this.getSecurity(),
57
+ summary: (0, utils_1.getJSDocTagComment)(this.node, utils_1.JSDocTagName.SUMMARY),
58
+ tags: this.getTags(),
59
+ type,
60
+ parameters: this.buildParameters(controllerPath, methodPath),
61
+ };
62
+ }
63
+ getCurrentLocation() {
64
+ const methodId = this.node.name;
65
+ const controllerId = this.node.parent.name;
66
+ return `${controllerId.text}.${methodId.text}`;
67
+ }
68
+ buildParameters(controllerPath, methodPath) {
69
+ const controllerId = this.node.parent.name;
70
+ const methodId = this.node.name;
71
+ const fullPath = node_path_1.default.posix.join('/', controllerPath, methodPath);
72
+ const output = [];
73
+ let bodyParameterCount = 0;
74
+ let formParameterCount = 0;
75
+ for (let i = 0; i < this.node.parameters.length; i++) {
76
+ try {
77
+ const generator = new parameter_1.ParameterGenerator(this.node.parameters[i], this.method, fullPath, this.current);
78
+ const parameters = generator.generate();
79
+ for (let j = 0; j < parameters.length; j++) {
80
+ if (parameters[j].in === parameter_1.ParameterSource.BODY) {
81
+ bodyParameterCount++;
82
+ }
83
+ if (parameters[j].in === parameter_1.ParameterSource.FORM_DATA) {
84
+ formParameterCount++;
85
+ }
86
+ if (parameters[j].in !== parameter_1.ParameterSource.CONTEXT) {
87
+ output.push(parameters[j]);
88
+ }
89
+ }
90
+ }
91
+ catch (e) {
92
+ const parameterId = this.node.parameters[i].name;
93
+ throw new Error(`Parameter generation: '${controllerId.text}.${methodId.text}' argument: ${parameterId.text} ${e}`);
94
+ }
95
+ }
96
+ if (bodyParameterCount > 1) {
97
+ throw new Error(`Only one body parameter allowed in '${this.getCurrentLocation()}' method.`);
98
+ }
99
+ if (bodyParameterCount > 0 && formParameterCount > 0) {
100
+ throw new Error(`Choose either form-, file- or body-parameter in '${this.getCurrentLocation()}' method.`);
101
+ }
102
+ return output;
103
+ }
104
+ determineVerb() {
105
+ const methods = [
106
+ decorator_1.DecoratorID.ALL,
107
+ decorator_1.DecoratorID.DELETE,
108
+ decorator_1.DecoratorID.GET,
109
+ decorator_1.DecoratorID.HEAD,
110
+ decorator_1.DecoratorID.OPTIONS,
111
+ decorator_1.DecoratorID.PATCH,
112
+ decorator_1.DecoratorID.POST,
113
+ decorator_1.DecoratorID.PUT,
114
+ ];
115
+ const decorators = (0, utils_1.getNodeDecorators)(this.node);
116
+ let method;
117
+ for (let i = 0; i < methods.length; i++) {
118
+ const representationManager = this.current.decoratorResolver.match(methods[i], decorators);
119
+ if (representationManager) {
120
+ method = methods[i];
121
+ break;
122
+ }
123
+ }
124
+ if (typeof method === 'undefined') {
125
+ return;
126
+ }
127
+ this.method = method.toLowerCase();
128
+ }
129
+ buildResponse(type) {
130
+ type = this.guessResponseType(type);
131
+ return {
132
+ description: (0, resolver_1.isVoidType)(type) ? 'No content' : 'Ok',
133
+ examples: this.getResponseExamples(),
134
+ schema: type,
135
+ status: (0, resolver_1.isVoidType)(type) ? '204' : '200',
136
+ name: (0, resolver_1.isVoidType)(type) ? '204' : '200',
137
+ };
138
+ }
139
+ guessResponseType(type) {
140
+ if (!(0, resolver_1.isVoidType)(type)) {
141
+ return type;
142
+ }
143
+ const representation = this.current.decoratorResolver.match(decorator_1.DecoratorID.EXAMPLE, this.node);
144
+ if (typeof representation === 'undefined') {
145
+ return type;
146
+ }
147
+ const value = representation.get('type');
148
+ if (typeof value !== 'undefined' &&
149
+ (0, utils_1.hasOwnProperty)(value, 'kind') &&
150
+ (0, typescript_1.isTypeNode)(value)) {
151
+ type = new resolver_1.TypeNodeResolver(value, this.current).resolve();
152
+ }
153
+ return type;
154
+ }
155
+ getResponseExamples() {
156
+ const representation = this.current.decoratorResolver.match(decorator_1.DecoratorID.EXAMPLE, this.node);
157
+ if (typeof representation === 'undefined') {
158
+ return [];
159
+ }
160
+ const output = [];
161
+ for (let i = 0; i < representation.decorators.length; i++) {
162
+ const value = representation.get('payload');
163
+ const label = representation.get('label');
164
+ if (typeof value !== 'undefined') {
165
+ output.push({ value, label });
166
+ }
167
+ }
168
+ return output;
169
+ }
170
+ mergeResponses(responses, exampleResponse) {
171
+ if (!responses || !responses.length) {
172
+ return [exampleResponse];
173
+ }
174
+ const index = responses.findIndex((resp) => resp.status === exampleResponse.status);
175
+ if (index >= 0) {
176
+ if (exampleResponse.examples &&
177
+ (!responses[index].examples || !responses[index].examples.length)) {
178
+ responses[index].examples = exampleResponse.examples;
179
+ }
180
+ }
181
+ else {
182
+ responses.push(exampleResponse);
183
+ }
184
+ return responses;
185
+ }
186
+ }
187
+ exports.MethodGenerator = MethodGenerator;
188
188
  //# sourceMappingURL=module.js.map
@@ -1,23 +1,23 @@
1
- import type { BaseType, Extension } from '../../resolver';
2
- import type { Parameter } from '../parameter';
3
- import type { Response, Security } from '../type';
4
- export interface Method {
5
- operationId?: string;
6
- deprecated?: boolean;
7
- description: string;
8
- method: MethodType;
9
- extensions: Extension[];
10
- name: string;
11
- parameters: Parameter[];
12
- path: string;
13
- type: BaseType;
14
- tags: string[];
15
- responses: Response[];
16
- security?: Security[];
17
- summary?: string;
18
- consumes: string[];
19
- produces: string[];
20
- hidden: boolean;
21
- }
22
- export type MethodType = 'get' | 'post' | 'put' | 'delete' | 'options' | 'head' | 'patch';
1
+ import type { BaseType, Extension } from '../../resolver';
2
+ import type { Parameter } from '../parameter';
3
+ import type { Response, Security } from '../type';
4
+ export interface Method {
5
+ operationId?: string;
6
+ deprecated?: boolean;
7
+ description: string;
8
+ method: MethodType;
9
+ extensions: Extension[];
10
+ name: string;
11
+ parameters: Parameter[];
12
+ path: string;
13
+ type: BaseType;
14
+ tags: string[];
15
+ responses: Response[];
16
+ security?: Security[];
17
+ summary?: string;
18
+ consumes: string[];
19
+ produces: string[];
20
+ hidden: boolean;
21
+ }
22
+ export type MethodType = 'get' | 'post' | 'put' | 'delete' | 'options' | 'head' | 'patch';
23
23
  //# sourceMappingURL=type.d.ts.map
@@ -1,9 +1,9 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2023.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2023.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  //# sourceMappingURL=type.js.map
@@ -1,19 +1,19 @@
1
- export declare enum ParameterSource {
2
- BODY = "body",
3
- BODY_PROP = "bodyProp",
4
- CONTEXT = "context",
5
- COOKIE = "cookie",
6
- HEADER = "header",
7
- FORM_DATA = "formData",
8
- QUERY = "query",
9
- QUERY_PROP = "queryProp",
10
- PATH = "path"
11
- }
12
- export declare enum CollectionFormat {
13
- CSV = "csv",
14
- SSV = "ssv",
15
- TSV = "tsv",
16
- PIPES = "pipes",
17
- MULTI = "multi"
18
- }
1
+ export declare enum ParameterSource {
2
+ BODY = "body",
3
+ BODY_PROP = "bodyProp",
4
+ CONTEXT = "context",
5
+ COOKIE = "cookie",
6
+ HEADER = "header",
7
+ FORM_DATA = "formData",
8
+ QUERY = "query",
9
+ QUERY_PROP = "queryProp",
10
+ PATH = "path"
11
+ }
12
+ export declare enum CollectionFormat {
13
+ CSV = "csv",
14
+ SSV = "ssv",
15
+ TSV = "tsv",
16
+ PIPES = "pipes",
17
+ MULTI = "multi"
18
+ }
19
19
  //# sourceMappingURL=constants.d.ts.map