nestjs-openapi-next 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 (244) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +211 -0
  3. package/bun.lock +2154 -0
  4. package/dist/constants.d.ts +23 -0
  5. package/dist/constants.js +26 -0
  6. package/dist/decorators/api-basic.decorator.d.ts +1 -0
  7. package/dist/decorators/api-basic.decorator.js +7 -0
  8. package/dist/decorators/api-bearer.decorator.d.ts +1 -0
  9. package/dist/decorators/api-bearer.decorator.js +7 -0
  10. package/dist/decorators/api-body.decorator.d.ts +16 -0
  11. package/dist/decorators/api-body.decorator.js +22 -0
  12. package/dist/decorators/api-callbacks.decorator.d.ts +2 -0
  13. package/dist/decorators/api-callbacks.decorator.js +8 -0
  14. package/dist/decorators/api-consumes.decorator.d.ts +1 -0
  15. package/dist/decorators/api-consumes.decorator.js +8 -0
  16. package/dist/decorators/api-cookie.decorator.d.ts +1 -0
  17. package/dist/decorators/api-cookie.decorator.js +7 -0
  18. package/dist/decorators/api-default-getter.decorator.d.ts +2 -0
  19. package/dist/decorators/api-default-getter.decorator.js +12 -0
  20. package/dist/decorators/api-exclude-controller.decorator.d.ts +1 -0
  21. package/dist/decorators/api-exclude-controller.decorator.js +8 -0
  22. package/dist/decorators/api-exclude-endpoint.decorator.d.ts +1 -0
  23. package/dist/decorators/api-exclude-endpoint.decorator.js +10 -0
  24. package/dist/decorators/api-extension.decorator.d.ts +1 -0
  25. package/dist/decorators/api-extension.decorator.js +38 -0
  26. package/dist/decorators/api-extra-models.decorator.d.ts +1 -0
  27. package/dist/decorators/api-extra-models.decorator.js +17 -0
  28. package/dist/decorators/api-header.decorator.d.ts +7 -0
  29. package/dist/decorators/api-header.decorator.js +37 -0
  30. package/dist/decorators/api-hide-property.decorator.d.ts +1 -0
  31. package/dist/decorators/api-hide-property.decorator.js +6 -0
  32. package/dist/decorators/api-link.decorator.d.ts +7 -0
  33. package/dist/decorators/api-link.decorator.js +21 -0
  34. package/dist/decorators/api-oauth2.decorator.d.ts +1 -0
  35. package/dist/decorators/api-oauth2.decorator.js +7 -0
  36. package/dist/decorators/api-operation.decorator.d.ts +5 -0
  37. package/dist/decorators/api-operation.decorator.js +12 -0
  38. package/dist/decorators/api-param.decorator.d.ts +22 -0
  39. package/dist/decorators/api-param.decorator.js +17 -0
  40. package/dist/decorators/api-produces.decorator.d.ts +1 -0
  41. package/dist/decorators/api-produces.decorator.js +8 -0
  42. package/dist/decorators/api-property.decorator.d.ts +15 -0
  43. package/dist/decorators/api-property.decorator.js +48 -0
  44. package/dist/decorators/api-query-method.decorator.d.ts +1 -0
  45. package/dist/decorators/api-query-method.decorator.js +8 -0
  46. package/dist/decorators/api-query.decorator.d.ts +24 -0
  47. package/dist/decorators/api-query.decorator.js +25 -0
  48. package/dist/decorators/api-response.decorator.d.ts +39 -0
  49. package/dist/decorators/api-response.decorator.js +55 -0
  50. package/dist/decorators/api-schema.decorator.d.ts +6 -0
  51. package/dist/decorators/api-schema.decorator.js +8 -0
  52. package/dist/decorators/api-security-device-flow.decorator.d.ts +1 -0
  53. package/dist/decorators/api-security-device-flow.decorator.js +7 -0
  54. package/dist/decorators/api-security.decorator.d.ts +2 -0
  55. package/dist/decorators/api-security.decorator.js +25 -0
  56. package/dist/decorators/api-streaming-response.decorator.d.ts +7 -0
  57. package/dist/decorators/api-streaming-response.decorator.js +9 -0
  58. package/dist/decorators/api-tag-group.decorator.d.ts +11 -0
  59. package/dist/decorators/api-tag-group.decorator.js +13 -0
  60. package/dist/decorators/api-use-tags.decorator.d.ts +1 -0
  61. package/dist/decorators/api-use-tags.decorator.js +8 -0
  62. package/dist/decorators/helpers.d.ts +8 -0
  63. package/dist/decorators/helpers.js +123 -0
  64. package/dist/decorators/index.d.ts +28 -0
  65. package/dist/decorators/index.js +48 -0
  66. package/dist/document-builder.d.ts +29 -0
  67. package/dist/document-builder.js +142 -0
  68. package/dist/explorers/api-callbacks.explorer.d.ts +2 -0
  69. package/dist/explorers/api-callbacks.explorer.js +36 -0
  70. package/dist/explorers/api-consumes.explorer.d.ts +5 -0
  71. package/dist/explorers/api-consumes.explorer.js +11 -0
  72. package/dist/explorers/api-exclude-controller.explorer.d.ts +2 -0
  73. package/dist/explorers/api-exclude-controller.explorer.js +10 -0
  74. package/dist/explorers/api-exclude-endpoint.explorer.d.ts +2 -0
  75. package/dist/explorers/api-exclude-endpoint.explorer.js +6 -0
  76. package/dist/explorers/api-extra-models.explorer.d.ts +3 -0
  77. package/dist/explorers/api-extra-models.explorer.js +11 -0
  78. package/dist/explorers/api-headers.explorer.d.ts +7 -0
  79. package/dist/explorers/api-headers.explorer.js +9 -0
  80. package/dist/explorers/api-operation.explorer.d.ts +2 -0
  81. package/dist/explorers/api-operation.explorer.js +43 -0
  82. package/dist/explorers/api-parameters.explorer.d.ts +71 -0
  83. package/dist/explorers/api-parameters.explorer.js +47 -0
  84. package/dist/explorers/api-produces.explorer.d.ts +5 -0
  85. package/dist/explorers/api-produces.explorer.js +11 -0
  86. package/dist/explorers/api-response.explorer.d.ts +13 -0
  87. package/dist/explorers/api-response.explorer.js +103 -0
  88. package/dist/explorers/api-security.explorer.d.ts +5 -0
  89. package/dist/explorers/api-security.explorer.js +13 -0
  90. package/dist/explorers/api-use-tags.explorer.d.ts +5 -0
  91. package/dist/explorers/api-use-tags.explorer.js +18 -0
  92. package/dist/extra/swagger-shim.d.ts +100 -0
  93. package/dist/extra/swagger-shim.js +367 -0
  94. package/dist/fixtures/document.base.d.ts +2 -0
  95. package/dist/fixtures/document.base.js +16 -0
  96. package/dist/index.d.ts +7 -0
  97. package/dist/index.js +23 -0
  98. package/dist/interfaces/callback-object.interface.d.ts +12 -0
  99. package/dist/interfaces/callback-object.interface.js +2 -0
  100. package/dist/interfaces/denormalized-doc-resolvers.interface.d.ts +7 -0
  101. package/dist/interfaces/denormalized-doc-resolvers.interface.js +2 -0
  102. package/dist/interfaces/denormalized-doc.interface.d.ts +8 -0
  103. package/dist/interfaces/denormalized-doc.interface.js +2 -0
  104. package/dist/interfaces/enum-schema-attributes.interface.d.ts +2 -0
  105. package/dist/interfaces/enum-schema-attributes.interface.js +2 -0
  106. package/dist/interfaces/index.d.ts +3 -0
  107. package/dist/interfaces/index.js +18 -0
  108. package/dist/interfaces/module-route.interface.d.ts +2 -0
  109. package/dist/interfaces/module-route.interface.js +2 -0
  110. package/dist/interfaces/open-api-spec.interface.d.ts +252 -0
  111. package/dist/interfaces/open-api-spec.interface.js +2 -0
  112. package/dist/interfaces/schema-object-metadata.interface.d.ts +30 -0
  113. package/dist/interfaces/schema-object-metadata.interface.js +2 -0
  114. package/dist/interfaces/swagger-custom-options.interface.d.ts +24 -0
  115. package/dist/interfaces/swagger-custom-options.interface.js +2 -0
  116. package/dist/interfaces/swagger-document-options.interface.d.ts +10 -0
  117. package/dist/interfaces/swagger-document-options.interface.js +2 -0
  118. package/dist/interfaces/swagger-ui-init-options.interface.d.ts +7 -0
  119. package/dist/interfaces/swagger-ui-init-options.interface.js +2 -0
  120. package/dist/interfaces/swagger-ui-options.interface.d.ts +15 -0
  121. package/dist/interfaces/swagger-ui-options.interface.js +2 -0
  122. package/dist/plugin/compiler-plugin.d.ts +2 -0
  123. package/dist/plugin/compiler-plugin.js +30 -0
  124. package/dist/plugin/index.d.ts +2 -0
  125. package/dist/plugin/index.js +18 -0
  126. package/dist/plugin/merge-options.d.ts +17 -0
  127. package/dist/plugin/merge-options.js +37 -0
  128. package/dist/plugin/metadata-loader.d.ts +7 -0
  129. package/dist/plugin/metadata-loader.js +51 -0
  130. package/dist/plugin/plugin-constants.d.ts +3 -0
  131. package/dist/plugin/plugin-constants.js +6 -0
  132. package/dist/plugin/plugin-debug-logger.d.ts +5 -0
  133. package/dist/plugin/plugin-debug-logger.js +7 -0
  134. package/dist/plugin/utils/ast-utils.d.ts +30 -0
  135. package/dist/plugin/utils/ast-utils.js +273 -0
  136. package/dist/plugin/utils/is-filename-matched.util.d.ts +1 -0
  137. package/dist/plugin/utils/is-filename-matched.util.js +5 -0
  138. package/dist/plugin/utils/plugin-utils.d.ts +30 -0
  139. package/dist/plugin/utils/plugin-utils.js +307 -0
  140. package/dist/plugin/utils/type-reference-to-identifier.util.d.ts +7 -0
  141. package/dist/plugin/utils/type-reference-to-identifier.util.js +52 -0
  142. package/dist/plugin/visitors/abstract.visitor.d.ts +4 -0
  143. package/dist/plugin/visitors/abstract.visitor.js +30 -0
  144. package/dist/plugin/visitors/controller-class.visitor.d.ts +20 -0
  145. package/dist/plugin/visitors/controller-class.visitor.js +265 -0
  146. package/dist/plugin/visitors/model-class.visitor.d.ts +35 -0
  147. package/dist/plugin/visitors/model-class.visitor.js +514 -0
  148. package/dist/plugin/visitors/readonly.visitor.d.ts +21 -0
  149. package/dist/plugin/visitors/readonly.visitor.js +40 -0
  150. package/dist/services/constants.d.ts +1 -0
  151. package/dist/services/constants.js +4 -0
  152. package/dist/services/decorators-properties.d.ts +21 -0
  153. package/dist/services/decorators-properties.js +149 -0
  154. package/dist/services/mimetype-content-wrapper.d.ts +4 -0
  155. package/dist/services/mimetype-content-wrapper.js +11 -0
  156. package/dist/services/model-properties-accessor.d.ts +6 -0
  157. package/dist/services/model-properties-accessor.js +37 -0
  158. package/dist/services/parameter-metadata-accessor.d.ts +22 -0
  159. package/dist/services/parameter-metadata-accessor.js +41 -0
  160. package/dist/services/parameters-metadata-mapper.d.ts +9 -0
  161. package/dist/services/parameters-metadata-mapper.js +38 -0
  162. package/dist/services/response-object-factory.d.ts +28 -0
  163. package/dist/services/response-object-factory.js +120 -0
  164. package/dist/services/response-object-mapper.d.ts +39 -0
  165. package/dist/services/response-object-mapper.js +38 -0
  166. package/dist/services/schema-object-factory.d.ts +156 -0
  167. package/dist/services/schema-object-factory.js +471 -0
  168. package/dist/services/swagger-types-mapper.d.ts +260 -0
  169. package/dist/services/swagger-types-mapper.js +107 -0
  170. package/dist/storages/global-parameters.storage.d.ts +8 -0
  171. package/dist/storages/global-parameters.storage.js +22 -0
  172. package/dist/storages/global-responses.storage.d.ts +10 -0
  173. package/dist/storages/global-responses.storage.js +21 -0
  174. package/dist/swagger-explorer.d.ts +41 -0
  175. package/dist/swagger-explorer.js +326 -0
  176. package/dist/swagger-module.d.ts +27 -0
  177. package/dist/swagger-module.js +223 -0
  178. package/dist/swagger-scanner.d.ts +25 -0
  179. package/dist/swagger-scanner.js +116 -0
  180. package/dist/swagger-transformer.d.ts +4 -0
  181. package/dist/swagger-transformer.js +22 -0
  182. package/dist/swagger-ui/constants.d.ts +3 -0
  183. package/dist/swagger-ui/constants.js +132 -0
  184. package/dist/swagger-ui/helpers.d.ts +2 -0
  185. package/dist/swagger-ui/helpers.js +16 -0
  186. package/dist/swagger-ui/index.d.ts +1 -0
  187. package/dist/swagger-ui/index.js +17 -0
  188. package/dist/swagger-ui/swagger-ui.d.ts +4 -0
  189. package/dist/swagger-ui/swagger-ui.js +62 -0
  190. package/dist/type-helpers/index.d.ts +4 -0
  191. package/dist/type-helpers/index.js +20 -0
  192. package/dist/type-helpers/intersection-type.helper.d.ts +8 -0
  193. package/dist/type-helpers/intersection-type.helper.js +42 -0
  194. package/dist/type-helpers/mapped-types.utils.d.ts +2 -0
  195. package/dist/type-helpers/mapped-types.utils.js +31 -0
  196. package/dist/type-helpers/omit-type.helper.d.ts +2 -0
  197. package/dist/type-helpers/omit-type.helper.js +40 -0
  198. package/dist/type-helpers/partial-type.helper.d.ts +4 -0
  199. package/dist/type-helpers/partial-type.helper.js +49 -0
  200. package/dist/type-helpers/pick-type.helper.d.ts +2 -0
  201. package/dist/type-helpers/pick-type.helper.js +40 -0
  202. package/dist/types/swagger-enum.type.d.ts +1 -0
  203. package/dist/types/swagger-enum.type.js +2 -0
  204. package/dist/utils/assign-two-levels-deep.d.ts +1 -0
  205. package/dist/utils/assign-two-levels-deep.js +12 -0
  206. package/dist/utils/enum.utils.d.ts +9 -0
  207. package/dist/utils/enum.utils.js +65 -0
  208. package/dist/utils/extend-metadata.util.d.ts +2 -0
  209. package/dist/utils/extend-metadata.util.js +11 -0
  210. package/dist/utils/get-global-prefix.d.ts +2 -0
  211. package/dist/utils/get-global-prefix.js +7 -0
  212. package/dist/utils/get-schema-path.util.d.ts +4 -0
  213. package/dist/utils/get-schema-path.util.js +26 -0
  214. package/dist/utils/index.d.ts +1 -0
  215. package/dist/utils/index.js +17 -0
  216. package/dist/utils/is-body-parameter.util.d.ts +2 -0
  217. package/dist/utils/is-body-parameter.util.js +6 -0
  218. package/dist/utils/is-built-in-type.util.d.ts +2 -0
  219. package/dist/utils/is-built-in-type.util.js +8 -0
  220. package/dist/utils/is-date-ctor.util.d.ts +2 -0
  221. package/dist/utils/is-date-ctor.util.js +6 -0
  222. package/dist/utils/merge-and-uniq.util.d.ts +1 -0
  223. package/dist/utils/merge-and-uniq.util.js +7 -0
  224. package/dist/utils/normalize-rel-path.d.ts +1 -0
  225. package/dist/utils/normalize-rel-path.js +7 -0
  226. package/dist/utils/remove-undefined-keys.d.ts +5 -0
  227. package/dist/utils/remove-undefined-keys.js +11 -0
  228. package/dist/utils/resolve-path.util.d.ts +1 -0
  229. package/dist/utils/resolve-path.util.js +7 -0
  230. package/dist/utils/reverse-object-keys.util.d.ts +1 -0
  231. package/dist/utils/reverse-object-keys.util.js +11 -0
  232. package/dist/utils/sort-object-lexicographically.d.ts +5 -0
  233. package/dist/utils/sort-object-lexicographically.js +11 -0
  234. package/dist/utils/strip-last-slash.util.d.ts +1 -0
  235. package/dist/utils/strip-last-slash.util.js +8 -0
  236. package/dist/utils/validate-global-prefix.util.d.ts +1 -0
  237. package/dist/utils/validate-global-prefix.util.js +5 -0
  238. package/dist/utils/validate-path.util.d.ts +1 -0
  239. package/dist/utils/validate-path.util.js +5 -0
  240. package/eslint.config.mjs +47 -0
  241. package/nest-cli.json +6 -0
  242. package/package.json +116 -0
  243. package/plugin.js +10 -0
  244. package/tsconfig.build.json +21 -0
@@ -0,0 +1,273 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renderDocNode = renderDocNode;
4
+ exports.isArray = isArray;
5
+ exports.getTypeArguments = getTypeArguments;
6
+ exports.isBoolean = isBoolean;
7
+ exports.isString = isString;
8
+ exports.isStringLiteral = isStringLiteral;
9
+ exports.isStringMapping = isStringMapping;
10
+ exports.isNumber = isNumber;
11
+ exports.isBigInt = isBigInt;
12
+ exports.isInterface = isInterface;
13
+ exports.isEnum = isEnum;
14
+ exports.isEnumLiteral = isEnumLiteral;
15
+ exports.hasFlag = hasFlag;
16
+ exports.hasObjectFlag = hasObjectFlag;
17
+ exports.getText = getText;
18
+ exports.getDefaultTypeFormatFlags = getDefaultTypeFormatFlags;
19
+ exports.getDocComment = getDocComment;
20
+ exports.getMainCommentOfNode = getMainCommentOfNode;
21
+ exports.parseCommentDocValue = parseCommentDocValue;
22
+ exports.getTsDocTagsOfNode = getTsDocTagsOfNode;
23
+ exports.getTsDocErrorsOfNode = getTsDocErrorsOfNode;
24
+ exports.getDecoratorArguments = getDecoratorArguments;
25
+ exports.getDecoratorName = getDecoratorName;
26
+ exports.findNullableTypeFromUnion = findNullableTypeFromUnion;
27
+ exports.createBooleanLiteral = createBooleanLiteral;
28
+ exports.createPrimitiveLiteral = createPrimitiveLiteral;
29
+ exports.createLiteralFromAnyValue = createLiteralFromAnyValue;
30
+ const tsdoc_1 = require("@microsoft/tsdoc");
31
+ const typescript_1 = require("typescript");
32
+ const plugin_utils_1 = require("./plugin-utils");
33
+ function renderDocNode(docNode) {
34
+ let result = '';
35
+ if (docNode) {
36
+ if (docNode instanceof tsdoc_1.DocExcerpt) {
37
+ result += docNode.content.toString();
38
+ }
39
+ for (const childNode of docNode.getChildNodes()) {
40
+ result += renderDocNode(childNode);
41
+ }
42
+ }
43
+ return result;
44
+ }
45
+ function isArray(type) {
46
+ const symbol = type.getSymbol();
47
+ if (!symbol) {
48
+ return false;
49
+ }
50
+ return symbol.getName() === 'Array' && getTypeArguments(type).length === 1;
51
+ }
52
+ function getTypeArguments(type) {
53
+ return type.typeArguments || [];
54
+ }
55
+ function isBoolean(type) {
56
+ return hasFlag(type, typescript_1.TypeFlags.Boolean);
57
+ }
58
+ function isString(type) {
59
+ return hasFlag(type, typescript_1.TypeFlags.String);
60
+ }
61
+ function isStringLiteral(type) {
62
+ return hasFlag(type, typescript_1.TypeFlags.StringLiteral) && !type.isUnion();
63
+ }
64
+ function isStringMapping(type) {
65
+ return hasFlag(type, typescript_1.TypeFlags.StringMapping);
66
+ }
67
+ function isNumber(type) {
68
+ return hasFlag(type, typescript_1.TypeFlags.Number);
69
+ }
70
+ function isBigInt(type) {
71
+ return hasFlag(type, typescript_1.TypeFlags.BigInt);
72
+ }
73
+ function isInterface(type) {
74
+ return hasObjectFlag(type, typescript_1.ObjectFlags.Interface);
75
+ }
76
+ function isEnum(type) {
77
+ const hasEnumFlag = hasFlag(type, typescript_1.TypeFlags.Enum);
78
+ if (hasEnumFlag) {
79
+ return true;
80
+ }
81
+ if (isEnumLiteral(type)) {
82
+ return false;
83
+ }
84
+ const symbol = type.getSymbol();
85
+ if (!symbol) {
86
+ return false;
87
+ }
88
+ const valueDeclaration = symbol.valueDeclaration;
89
+ if (!valueDeclaration) {
90
+ return false;
91
+ }
92
+ return valueDeclaration.kind === typescript_1.SyntaxKind.EnumDeclaration;
93
+ }
94
+ function isEnumLiteral(type) {
95
+ return hasFlag(type, typescript_1.TypeFlags.EnumLiteral) && !type.isUnion();
96
+ }
97
+ function hasFlag(type, flag) {
98
+ return (type.flags & flag) === flag;
99
+ }
100
+ function hasObjectFlag(type, flag) {
101
+ return (type.objectFlags & flag) === flag;
102
+ }
103
+ function getText(type, typeChecker, enclosingNode, typeFormatFlags) {
104
+ if (!typeFormatFlags) {
105
+ typeFormatFlags = getDefaultTypeFormatFlags(enclosingNode);
106
+ }
107
+ const compilerNode = !enclosingNode ? undefined : enclosingNode;
108
+ return typeChecker.typeToString(type, compilerNode, typeFormatFlags);
109
+ }
110
+ function getDefaultTypeFormatFlags(enclosingNode) {
111
+ let formatFlags = typescript_1.TypeFormatFlags.UseTypeOfFunction |
112
+ typescript_1.TypeFormatFlags.NoTruncation |
113
+ typescript_1.TypeFormatFlags.UseFullyQualifiedType |
114
+ typescript_1.TypeFormatFlags.WriteTypeArgumentsOfSignature;
115
+ if (enclosingNode && enclosingNode.kind === typescript_1.SyntaxKind.TypeAliasDeclaration)
116
+ formatFlags |= typescript_1.TypeFormatFlags.InTypeAlias;
117
+ return formatFlags;
118
+ }
119
+ function getDocComment(node) {
120
+ const tsdocParser = new tsdoc_1.TSDocParser();
121
+ const parserContext = tsdocParser.parseString(node.getFullText());
122
+ return parserContext.docComment;
123
+ }
124
+ function getMainCommentOfNode(node) {
125
+ const docComment = getDocComment(node);
126
+ return renderDocNode(docComment.summarySection).trim();
127
+ }
128
+ function parseCommentDocValue(docValue, type) {
129
+ let value = docValue.replace(/'/g, '"').trim();
130
+ if (!type || !isString(type)) {
131
+ try {
132
+ value = JSON.parse(value);
133
+ }
134
+ catch (_a) {
135
+ }
136
+ }
137
+ else if (isString(type)) {
138
+ if (value.split(' ').length !== 1 && !value.startsWith('"')) {
139
+ value = null;
140
+ }
141
+ else {
142
+ value = value.replace(/"/g, '');
143
+ }
144
+ }
145
+ return value;
146
+ }
147
+ function getTsDocTagsOfNode(node, typeChecker) {
148
+ const docComment = getDocComment(node);
149
+ const tagDefinitions = {
150
+ example: {
151
+ hasProperties: true,
152
+ repeatable: true
153
+ }
154
+ };
155
+ const tagResults = {};
156
+ const introspectTsDocTags = (docComment) => {
157
+ for (const tag in tagDefinitions) {
158
+ const { hasProperties, repeatable } = tagDefinitions[tag];
159
+ const blocks = docComment.customBlocks.filter((block) => block.blockTag.tagName === `@${tag}`);
160
+ if (blocks.length === 0) {
161
+ continue;
162
+ }
163
+ if (repeatable && !tagResults[tag]) {
164
+ tagResults[tag] = [];
165
+ }
166
+ const type = typeChecker.getTypeAtLocation(node);
167
+ if (hasProperties) {
168
+ blocks.forEach((block) => {
169
+ const docValue = renderDocNode(block.content).split('\n')[0];
170
+ const value = parseCommentDocValue(docValue, type);
171
+ if (value !== null) {
172
+ if (repeatable) {
173
+ tagResults[tag].push(value);
174
+ }
175
+ else {
176
+ tagResults[tag] = value;
177
+ }
178
+ }
179
+ });
180
+ }
181
+ else {
182
+ tagResults[tag] = true;
183
+ }
184
+ }
185
+ if (docComment.remarksBlock) {
186
+ tagResults['remarks'] = renderDocNode(docComment.remarksBlock.content).trim();
187
+ }
188
+ if (docComment.deprecatedBlock) {
189
+ tagResults['deprecated'] = true;
190
+ }
191
+ };
192
+ introspectTsDocTags(docComment);
193
+ return tagResults;
194
+ }
195
+ function getTsDocErrorsOfNode(node) {
196
+ const tsdocParser = new tsdoc_1.TSDocParser();
197
+ const parserContext = tsdocParser.parseString(node.getFullText());
198
+ const docComment = parserContext.docComment;
199
+ const tagResults = [];
200
+ const errorParsingRegex = /{(\d+)} (.*)/;
201
+ const introspectTsDocTags = (docComment) => {
202
+ const blocks = docComment.customBlocks.filter((block) => block.blockTag.tagName === '@throws');
203
+ blocks.forEach((block) => {
204
+ try {
205
+ const docValue = renderDocNode(block.content).split('\n')[0].trim();
206
+ const match = docValue.match(errorParsingRegex);
207
+ tagResults.push({
208
+ status: match[1],
209
+ description: `"${match[2]}"`
210
+ });
211
+ }
212
+ catch (_a) {
213
+ }
214
+ });
215
+ };
216
+ introspectTsDocTags(docComment);
217
+ return tagResults;
218
+ }
219
+ function getDecoratorArguments(decorator) {
220
+ const callExpression = decorator.expression;
221
+ return (callExpression && callExpression.arguments) || [];
222
+ }
223
+ function getDecoratorName(decorator) {
224
+ const isDecoratorFactory = decorator.expression.kind === typescript_1.SyntaxKind.CallExpression;
225
+ if (isDecoratorFactory) {
226
+ const callExpression = decorator.expression;
227
+ const identifier = callExpression
228
+ .expression;
229
+ if ((0, plugin_utils_1.isDynamicallyAdded)(identifier)) {
230
+ return undefined;
231
+ }
232
+ return getIdentifierFromName(callExpression.expression).getText();
233
+ }
234
+ return getIdentifierFromName(decorator.expression).getText();
235
+ }
236
+ function getIdentifierFromName(expression) {
237
+ const identifier = getNameFromExpression(expression);
238
+ if (expression && expression.kind !== typescript_1.SyntaxKind.Identifier) {
239
+ throw new Error();
240
+ }
241
+ return identifier;
242
+ }
243
+ function getNameFromExpression(expression) {
244
+ if (expression && expression.kind === typescript_1.SyntaxKind.PropertyAccessExpression) {
245
+ return expression.name;
246
+ }
247
+ return expression;
248
+ }
249
+ function findNullableTypeFromUnion(typeNode, typeChecker) {
250
+ return typeNode.types.find((tNode) => hasFlag(typeChecker.getTypeAtLocation(tNode), typescript_1.TypeFlags.Null));
251
+ }
252
+ function createBooleanLiteral(factory, flag) {
253
+ return flag ? factory.createTrue() : factory.createFalse();
254
+ }
255
+ function createPrimitiveLiteral(factory, item, typeOfItem = typeof item) {
256
+ switch (typeOfItem) {
257
+ case 'boolean':
258
+ return createBooleanLiteral(factory, item);
259
+ case 'number': {
260
+ if (item < 0) {
261
+ return factory.createPrefixUnaryExpression(typescript_1.SyntaxKind.MinusToken, factory.createNumericLiteral(Math.abs(item)));
262
+ }
263
+ return factory.createNumericLiteral(item);
264
+ }
265
+ case 'string':
266
+ return factory.createStringLiteral(item);
267
+ }
268
+ }
269
+ function createLiteralFromAnyValue(factory, item) {
270
+ return Array.isArray(item)
271
+ ? factory.createArrayLiteralExpression(item.map((item) => createLiteralFromAnyValue(factory, item)))
272
+ : createPrimitiveLiteral(factory, item);
273
+ }
@@ -0,0 +1 @@
1
+ export declare const isFilenameMatched: (patterns: string[], filename: string) => boolean;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isFilenameMatched = void 0;
4
+ const isFilenameMatched = (patterns, filename) => patterns.some((path) => filename.includes(path));
5
+ exports.isFilenameMatched = isFilenameMatched;
@@ -0,0 +1,30 @@
1
+ import * as ts from 'typescript';
2
+ import { PluginOptions } from '../merge-options';
3
+ export declare function getDecoratorOrUndefinedByNames(names: string[], decorators: readonly ts.Decorator[], factory: ts.NodeFactory): ts.Decorator | undefined;
4
+ export declare function getTypeReferenceAsString(type: ts.Type, typeChecker: ts.TypeChecker, arrayDepth?: number): {
5
+ typeName: string;
6
+ isArray?: boolean;
7
+ arrayDepth?: number;
8
+ };
9
+ export declare function isPromiseOrObservable(type: string): boolean;
10
+ export declare function hasPropertyKey(key: string, properties: ts.NodeArray<ts.PropertyAssignment>): boolean;
11
+ export declare function getOutputExtension(fileName: string): string;
12
+ export declare function replaceImportPath(typeReference: string, fileName: string, options: PluginOptions): {
13
+ typeReference: string;
14
+ typeName: string;
15
+ importPath: string;
16
+ } | {
17
+ typeReference: string;
18
+ importPath: string;
19
+ typeName?: undefined;
20
+ };
21
+ export declare function insertAt(string: string, index: number, substring: string): string;
22
+ export declare function isDynamicallyAdded(identifier: ts.Node): boolean;
23
+ export declare function isAutoGeneratedEnumUnion(type: ts.Type, typeChecker: ts.TypeChecker): ts.Type;
24
+ export declare function isAutoGeneratedTypeUnion(type: ts.Type): boolean;
25
+ export declare function extractTypeArgumentIfArray(type: ts.Type): {
26
+ type: ts.Type;
27
+ isArray: boolean;
28
+ };
29
+ export declare function convertPath(windowsPath: string): string;
30
+ export declare function canReferenceNode(node: ts.Node, options: PluginOptions): boolean;
@@ -0,0 +1,307 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDecoratorOrUndefinedByNames = getDecoratorOrUndefinedByNames;
4
+ exports.getTypeReferenceAsString = getTypeReferenceAsString;
5
+ exports.isPromiseOrObservable = isPromiseOrObservable;
6
+ exports.hasPropertyKey = hasPropertyKey;
7
+ exports.getOutputExtension = getOutputExtension;
8
+ exports.replaceImportPath = replaceImportPath;
9
+ exports.insertAt = insertAt;
10
+ exports.isDynamicallyAdded = isDynamicallyAdded;
11
+ exports.isAutoGeneratedEnumUnion = isAutoGeneratedEnumUnion;
12
+ exports.isAutoGeneratedTypeUnion = isAutoGeneratedTypeUnion;
13
+ exports.extractTypeArgumentIfArray = extractTypeArgumentIfArray;
14
+ exports.convertPath = convertPath;
15
+ exports.canReferenceNode = canReferenceNode;
16
+ const lodash_1 = require("lodash");
17
+ const path_1 = require("path");
18
+ const ts = require("typescript");
19
+ const ast_utils_1 = require("./ast-utils");
20
+ function getDecoratorOrUndefinedByNames(names, decorators, factory) {
21
+ return (decorators || factory.createNodeArray()).find((item) => {
22
+ try {
23
+ const decoratorName = (0, ast_utils_1.getDecoratorName)(item);
24
+ return names.includes(decoratorName);
25
+ }
26
+ catch (_a) {
27
+ return false;
28
+ }
29
+ });
30
+ }
31
+ function getTypeReferenceAsString(type, typeChecker, arrayDepth = 0) {
32
+ if ((0, ast_utils_1.isArray)(type)) {
33
+ const arrayType = (0, ast_utils_1.getTypeArguments)(type)[0];
34
+ const { typeName, arrayDepth: depth } = getTypeReferenceAsString(arrayType, typeChecker, arrayDepth + 1);
35
+ if (!typeName) {
36
+ return { typeName: undefined };
37
+ }
38
+ return {
39
+ typeName: `${typeName}`,
40
+ isArray: true,
41
+ arrayDepth: depth
42
+ };
43
+ }
44
+ if ((0, ast_utils_1.isBoolean)(type)) {
45
+ return { typeName: Boolean.name, arrayDepth };
46
+ }
47
+ if ((0, ast_utils_1.isNumber)(type)) {
48
+ return { typeName: Number.name, arrayDepth };
49
+ }
50
+ if ((0, ast_utils_1.isBigInt)(type)) {
51
+ return { typeName: BigInt.name, arrayDepth };
52
+ }
53
+ if ((0, ast_utils_1.isString)(type) || (0, ast_utils_1.isStringLiteral)(type) || (0, ast_utils_1.isStringMapping)(type)) {
54
+ return { typeName: String.name, arrayDepth };
55
+ }
56
+ if (isPromiseOrObservable((0, ast_utils_1.getText)(type, typeChecker))) {
57
+ const typeArguments = (0, ast_utils_1.getTypeArguments)(type);
58
+ const elementType = getTypeReferenceAsString((0, lodash_1.head)(typeArguments), typeChecker, arrayDepth);
59
+ return elementType;
60
+ }
61
+ if (type.isClass()) {
62
+ return { typeName: (0, ast_utils_1.getText)(type, typeChecker), arrayDepth };
63
+ }
64
+ try {
65
+ const text = (0, ast_utils_1.getText)(type, typeChecker);
66
+ if (text === Date.name) {
67
+ return { typeName: text, arrayDepth };
68
+ }
69
+ if (isOptionalBoolean(text)) {
70
+ return { typeName: Boolean.name, arrayDepth };
71
+ }
72
+ if (isAutoGeneratedTypeUnion(type) ||
73
+ isAutoGeneratedEnumUnion(type, typeChecker)) {
74
+ const types = type.types;
75
+ return getTypeReferenceAsString(types[types.length - 1], typeChecker, arrayDepth);
76
+ }
77
+ if (text === 'any' ||
78
+ text === 'unknown' ||
79
+ text === 'object' ||
80
+ (0, ast_utils_1.isInterface)(type) ||
81
+ (type.isUnionOrIntersection() && !(0, ast_utils_1.isEnum)(type))) {
82
+ return { typeName: 'Object', arrayDepth };
83
+ }
84
+ if ((0, ast_utils_1.isEnum)(type)) {
85
+ return { typeName: undefined, arrayDepth };
86
+ }
87
+ if (type.aliasSymbol) {
88
+ return { typeName: 'Object', arrayDepth };
89
+ }
90
+ if (typeChecker.getApparentType(type).getSymbol().getEscapedName() ===
91
+ 'String') {
92
+ return { typeName: String.name, arrayDepth };
93
+ }
94
+ return { typeName: undefined };
95
+ }
96
+ catch (_a) {
97
+ return { typeName: undefined };
98
+ }
99
+ }
100
+ function isPromiseOrObservable(type) {
101
+ return type.includes('Promise<') || type.includes('Observable<');
102
+ }
103
+ function hasPropertyKey(key, properties) {
104
+ return properties
105
+ .filter((item) => !isDynamicallyAdded(item))
106
+ .some((item) => item.name.getText() === key);
107
+ }
108
+ function getOutputExtension(fileName) {
109
+ if (fileName.endsWith('.mts')) {
110
+ return '.mjs';
111
+ }
112
+ else if (fileName.endsWith('.cts')) {
113
+ return '.cjs';
114
+ }
115
+ else {
116
+ return '.js';
117
+ }
118
+ }
119
+ function replaceImportPath(typeReference, fileName, options) {
120
+ if (!typeReference.includes('import')) {
121
+ return { typeReference, importPath: null };
122
+ }
123
+ if (options.esmCompatible) {
124
+ typeReference = typeReference.replace(', { with: { "resolution-mode": "import" } }', '');
125
+ }
126
+ let importPath = /\(\"([^)]).+(\")/.exec(typeReference)[0];
127
+ if (!importPath) {
128
+ return { typeReference: undefined, importPath: null };
129
+ }
130
+ importPath = convertPath(importPath);
131
+ importPath = importPath.slice(2, importPath.length - 1);
132
+ try {
133
+ if ((0, path_1.isAbsolute)(importPath)) {
134
+ throw new Error('Absolute import paths are not supported.');
135
+ }
136
+ require.resolve(importPath);
137
+ if (!options.esmCompatible) {
138
+ typeReference = typeReference.replace('import', 'require');
139
+ }
140
+ return {
141
+ typeReference,
142
+ importPath: null
143
+ };
144
+ }
145
+ catch (_a) {
146
+ const from = (options === null || options === void 0 ? void 0 : options.readonly)
147
+ ? convertPath(options.pathToSource)
148
+ : path_1.posix.dirname(convertPath(fileName));
149
+ let relativePath = path_1.posix.relative(from, importPath);
150
+ relativePath = relativePath[0] !== '.' ? './' + relativePath : relativePath;
151
+ const nodeModulesText = 'node_modules';
152
+ const nodeModulePos = relativePath.indexOf(nodeModulesText);
153
+ if (nodeModulePos >= 0) {
154
+ relativePath = relativePath.slice(nodeModulePos + nodeModulesText.length + 1);
155
+ const typesText = '@types';
156
+ const typesPos = relativePath.indexOf(typesText);
157
+ if (typesPos >= 0) {
158
+ relativePath = relativePath.slice(typesPos + typesText.length + 1);
159
+ }
160
+ const indexText = '/index';
161
+ const indexPos = relativePath.indexOf(indexText);
162
+ if (indexPos >= 0) {
163
+ relativePath = relativePath.slice(0, indexPos);
164
+ }
165
+ }
166
+ else if (options.esmCompatible) {
167
+ const extension = getOutputExtension(fileName);
168
+ relativePath += extension;
169
+ }
170
+ typeReference = typeReference.replace(importPath, relativePath);
171
+ if (options.readonly) {
172
+ const { typeName, typeImportStatement } = convertToAsyncImport(typeReference);
173
+ return {
174
+ typeReference: typeImportStatement,
175
+ typeName,
176
+ importPath: relativePath
177
+ };
178
+ }
179
+ if (options.esmCompatible) {
180
+ const { typeName, typeImportStatement } = convertToAsyncImport(typeReference);
181
+ return {
182
+ typeReference: `(${typeImportStatement}).${typeName}`,
183
+ importPath: relativePath
184
+ };
185
+ }
186
+ return {
187
+ typeReference: typeReference.replace('import', 'require'),
188
+ importPath: relativePath
189
+ };
190
+ }
191
+ }
192
+ function convertToAsyncImport(typeReference) {
193
+ const regexp = /import\(.+\).([^\]]+)(\])?/;
194
+ const match = regexp.exec(typeReference);
195
+ if ((match === null || match === void 0 ? void 0 : match.length) >= 2) {
196
+ const importPos = typeReference.indexOf(match[0]);
197
+ typeReference = typeReference.replace(`.${match[1]}`, '');
198
+ return {
199
+ typeImportStatement: insertAt(typeReference, importPos, 'await '),
200
+ typeName: match[1]
201
+ };
202
+ }
203
+ return { typeImportStatement: typeReference };
204
+ }
205
+ function insertAt(string, index, substring) {
206
+ return string.slice(0, index) + substring + string.slice(index);
207
+ }
208
+ function isDynamicallyAdded(identifier) {
209
+ return identifier && !identifier.parent && identifier.pos === -1;
210
+ }
211
+ function isAutoGeneratedEnumUnion(type, typeChecker) {
212
+ if (type.isUnionOrIntersection() && !(0, ast_utils_1.isEnum)(type)) {
213
+ if (!type.types) {
214
+ return undefined;
215
+ }
216
+ const undefinedTypeIndex = type.types.findIndex((type) => type.intrinsicName === 'undefined' || type.intrinsicName === 'null');
217
+ if (undefinedTypeIndex < 0) {
218
+ return undefined;
219
+ }
220
+ let parentType = undefined;
221
+ const isParentSymbolEqual = type.types.every((item, index) => {
222
+ if (index === undefinedTypeIndex) {
223
+ return true;
224
+ }
225
+ if (!item.symbol) {
226
+ return false;
227
+ }
228
+ if (!item.symbol.parent ||
229
+ item.symbol.flags !== ts.SymbolFlags.EnumMember) {
230
+ return false;
231
+ }
232
+ const symbolType = typeChecker.getDeclaredTypeOfSymbol(item.symbol.parent);
233
+ if (symbolType === parentType || !parentType) {
234
+ parentType = symbolType;
235
+ return true;
236
+ }
237
+ return false;
238
+ });
239
+ if (isParentSymbolEqual) {
240
+ return parentType;
241
+ }
242
+ }
243
+ return undefined;
244
+ }
245
+ function isAutoGeneratedTypeUnion(type) {
246
+ if (type.isUnionOrIntersection() && !(0, ast_utils_1.isEnum)(type)) {
247
+ if (!type.types) {
248
+ return false;
249
+ }
250
+ const undefinedTypeIndex = type.types.findIndex((type) => type.intrinsicName === 'undefined');
251
+ if (type.types.length === 2 && undefinedTypeIndex >= 0) {
252
+ return true;
253
+ }
254
+ }
255
+ return false;
256
+ }
257
+ function extractTypeArgumentIfArray(type) {
258
+ if ((0, ast_utils_1.isArray)(type)) {
259
+ type = (0, ast_utils_1.getTypeArguments)(type)[0];
260
+ if (!type) {
261
+ return undefined;
262
+ }
263
+ return {
264
+ type,
265
+ isArray: true
266
+ };
267
+ }
268
+ return {
269
+ type,
270
+ isArray: false
271
+ };
272
+ }
273
+ function isOptionalBoolean(text) {
274
+ return typeof text === 'string' && text === 'boolean | undefined';
275
+ }
276
+ function convertPath(windowsPath) {
277
+ return windowsPath
278
+ .replace(/^\\\\\?\\/, '')
279
+ .replace(/\\/g, '/')
280
+ .replace(/\/\/+/g, '/');
281
+ }
282
+ function canReferenceNode(node, options) {
283
+ var _a;
284
+ if (!options.readonly) {
285
+ return true;
286
+ }
287
+ if (ts.isCallExpression(node) || ts.isIdentifier(node)) {
288
+ return false;
289
+ }
290
+ if (ts.isNewExpression(node)) {
291
+ if (((_a = node.expression) === null || _a === void 0 ? void 0 : _a.escapedText) === 'Date') {
292
+ return true;
293
+ }
294
+ return false;
295
+ }
296
+ if (node.kind === ts.SyntaxKind.FalseKeyword ||
297
+ node.kind === ts.SyntaxKind.TrueKeyword ||
298
+ node.kind === ts.SyntaxKind.NullKeyword) {
299
+ return true;
300
+ }
301
+ if (ts.isNumericLiteral(node) ||
302
+ ts.isPrefixUnaryExpression(node) ||
303
+ ts.isStringLiteral(node)) {
304
+ return true;
305
+ }
306
+ return false;
307
+ }
@@ -0,0 +1,7 @@
1
+ import * as ts from 'typescript';
2
+ import { PluginOptions } from '../merge-options';
3
+ export declare function typeReferenceToIdentifier(typeReferenceDescriptor: {
4
+ typeName: string;
5
+ isArray?: boolean;
6
+ arrayDepth?: number;
7
+ }, hostFilename: string, options: PluginOptions, factory: ts.NodeFactory, type: ts.Type, typeImports: Record<string, string>): ts.Identifier;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.typeReferenceToIdentifier = typeReferenceToIdentifier;
4
+ const plugin_debug_logger_1 = require("../plugin-debug-logger");
5
+ const plugin_utils_1 = require("./plugin-utils");
6
+ function typeReferenceToIdentifier(typeReferenceDescriptor, hostFilename, options, factory, type, typeImports) {
7
+ if (options.readonly) {
8
+ assertReferenceableType(type, typeReferenceDescriptor.typeName, hostFilename, options);
9
+ }
10
+ const { typeReference, importPath, typeName } = (0, plugin_utils_1.replaceImportPath)(typeReferenceDescriptor.typeName, hostFilename, options);
11
+ let identifier;
12
+ if (options.readonly && (typeReference === null || typeReference === void 0 ? void 0 : typeReference.includes('import'))) {
13
+ if (!typeImports[importPath]) {
14
+ typeImports[importPath] = typeReference;
15
+ }
16
+ let ref = `t["${importPath}"].${typeName}`;
17
+ if (typeReferenceDescriptor.isArray) {
18
+ ref = wrapTypeInArray(ref, typeReferenceDescriptor.arrayDepth);
19
+ }
20
+ identifier = factory.createIdentifier(ref);
21
+ }
22
+ else {
23
+ let ref = typeReference;
24
+ if (typeReferenceDescriptor.isArray) {
25
+ ref = wrapTypeInArray(ref, typeReferenceDescriptor.arrayDepth);
26
+ }
27
+ identifier = factory.createIdentifier(ref);
28
+ }
29
+ return identifier;
30
+ }
31
+ function wrapTypeInArray(typeRef, arrayDepth) {
32
+ for (let i = 0; i < arrayDepth; i++) {
33
+ typeRef = `[${typeRef}]`;
34
+ }
35
+ return typeRef;
36
+ }
37
+ function assertReferenceableType(type, parsedTypeName, hostFilename, options) {
38
+ if (!type.symbol) {
39
+ return true;
40
+ }
41
+ if (!type.symbol.isReferenced) {
42
+ return true;
43
+ }
44
+ if (parsedTypeName.includes('import')) {
45
+ return true;
46
+ }
47
+ const errorMessage = `Type "${parsedTypeName}" is not referenceable ("${hostFilename}"). To fix this, make sure to export this type.`;
48
+ if (options.debug) {
49
+ plugin_debug_logger_1.pluginDebugLogger.debug(errorMessage);
50
+ }
51
+ throw new Error(errorMessage);
52
+ }
@@ -0,0 +1,4 @@
1
+ import * as ts from 'typescript';
2
+ export declare class AbstractFileVisitor {
3
+ updateImports(sourceFile: ts.SourceFile, factory: ts.NodeFactory | undefined, program: ts.Program): ts.SourceFile;
4
+ }