@nestia/sdk 14.0.0 → 14.0.2

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 (391) hide show
  1. package/README.md +1 -1
  2. package/assets/bundle/distribute/build-sdk.cjs +28 -0
  3. package/assets/bundle/distribute/package.json +7 -3
  4. package/assets/bundle/distribute/tsconfig.json +15 -105
  5. package/lib/INestiaConfig.d.ts +74 -34
  6. package/lib/NestiaSdkApplication.d.ts +60 -0
  7. package/lib/NestiaSdkApplication.js +121 -32
  8. package/lib/NestiaSdkApplication.js.map +1 -1
  9. package/lib/NestiaSwaggerComposer.d.ts +21 -0
  10. package/lib/NestiaSwaggerComposer.js +32 -13
  11. package/lib/NestiaSwaggerComposer.js.map +1 -1
  12. package/lib/analyses/AccessorAnalyzer.d.ts +26 -0
  13. package/lib/analyses/AccessorAnalyzer.js +26 -0
  14. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  15. package/lib/analyses/ConfigAnalyzer.d.ts +41 -0
  16. package/lib/analyses/ConfigAnalyzer.js +52 -77
  17. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  18. package/lib/analyses/ImportAnalyzer.d.ts +25 -0
  19. package/lib/analyses/ImportAnalyzer.js +25 -0
  20. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  21. package/lib/analyses/ParameterNameAnalyzer.d.ts +44 -0
  22. package/lib/analyses/ParameterNameAnalyzer.js +63 -0
  23. package/lib/analyses/ParameterNameAnalyzer.js.map +1 -0
  24. package/lib/analyses/PathAnalyzer.d.ts +93 -1
  25. package/lib/analyses/PathAnalyzer.js +160 -23
  26. package/lib/analyses/PathAnalyzer.js.map +1 -1
  27. package/lib/analyses/ReflectControllerAnalyzer.d.ts +32 -0
  28. package/lib/analyses/ReflectControllerAnalyzer.js +24 -1
  29. package/lib/analyses/ReflectControllerAnalyzer.js.map +1 -1
  30. package/lib/analyses/ReflectHttpOperationAnalyzer.d.ts +29 -0
  31. package/lib/analyses/ReflectHttpOperationAnalyzer.js +35 -24
  32. package/lib/analyses/ReflectHttpOperationAnalyzer.js.map +1 -1
  33. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.d.ts +31 -0
  34. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js +21 -0
  35. package/lib/analyses/ReflectHttpOperationExceptionAnalyzer.js.map +1 -1
  36. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.d.ts +31 -0
  37. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js +143 -23
  38. package/lib/analyses/ReflectHttpOperationParameterAnalyzer.js.map +1 -1
  39. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.d.ts +32 -0
  40. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js +27 -2
  41. package/lib/analyses/ReflectHttpOperationResponseAnalyzer.js.map +1 -1
  42. package/lib/analyses/ReflectMcpOperationAnalyzer.d.ts +29 -0
  43. package/lib/analyses/ReflectMcpOperationAnalyzer.js +35 -11
  44. package/lib/analyses/ReflectMcpOperationAnalyzer.js.map +1 -1
  45. package/lib/analyses/ReflectMetadataAnalyzer.d.ts +47 -0
  46. package/lib/analyses/ReflectMetadataAnalyzer.js +47 -0
  47. package/lib/analyses/ReflectMetadataAnalyzer.js.map +1 -1
  48. package/lib/analyses/ReflectWebSocketOperationAnalyzer.d.ts +29 -0
  49. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js +27 -5
  50. package/lib/analyses/ReflectWebSocketOperationAnalyzer.js.map +1 -1
  51. package/lib/analyses/SecurityAnalyzer.d.ts +25 -0
  52. package/lib/analyses/SecurityAnalyzer.js +39 -19
  53. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  54. package/lib/analyses/SwaggerExampleAnalyzer.d.ts +31 -0
  55. package/lib/analyses/SwaggerExampleAnalyzer.js +36 -0
  56. package/lib/analyses/SwaggerExampleAnalyzer.js.map +1 -0
  57. package/lib/analyses/TypedHttpRouteAnalyzer.d.ts +41 -3
  58. package/lib/analyses/TypedHttpRouteAnalyzer.js +196 -172
  59. package/lib/analyses/TypedHttpRouteAnalyzer.js.map +1 -1
  60. package/lib/analyses/TypedMcpRouteAnalyzer.d.ts +29 -0
  61. package/lib/analyses/TypedMcpRouteAnalyzer.js +152 -20
  62. package/lib/analyses/TypedMcpRouteAnalyzer.js.map +1 -1
  63. package/lib/analyses/TypedWebSocketRouteAnalyzer.d.ts +19 -0
  64. package/lib/analyses/TypedWebSocketRouteAnalyzer.js +20 -1
  65. package/lib/analyses/TypedWebSocketRouteAnalyzer.js.map +1 -1
  66. package/lib/decorators/OperationMetadata.d.ts +6 -0
  67. package/lib/decorators/OperationMetadata.js +6 -0
  68. package/lib/decorators/OperationMetadata.js.map +1 -1
  69. package/lib/executable/internal/CommandParser.d.ts +19 -0
  70. package/lib/executable/internal/CommandParser.js +19 -0
  71. package/lib/executable/internal/CommandParser.js.map +1 -1
  72. package/lib/executable/internal/NestiaConfigLoader.d.ts +56 -0
  73. package/lib/executable/internal/NestiaConfigLoader.js +48 -42
  74. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  75. package/lib/executable/internal/NestiaSdkCommand.d.ts +60 -0
  76. package/lib/executable/internal/NestiaSdkCommand.js +95 -3
  77. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  78. package/lib/executable/internal/NestiaSdkWatcher.d.ts +81 -0
  79. package/lib/executable/internal/NestiaSdkWatcher.js +125 -41
  80. package/lib/executable/internal/NestiaSdkWatcher.js.map +1 -1
  81. package/lib/executable/internal/NestiaSwaggerWatch.d.ts +80 -0
  82. package/lib/executable/internal/NestiaSwaggerWatch.js +308 -0
  83. package/lib/executable/internal/NestiaSwaggerWatch.js.map +1 -0
  84. package/lib/executable/sdk.js +16 -1
  85. package/lib/executable/sdk.js.map +1 -1
  86. package/lib/factories/ExpressionFactory.d.ts +18 -0
  87. package/lib/factories/ExpressionFactory.js +21 -2
  88. package/lib/factories/ExpressionFactory.js.map +1 -1
  89. package/lib/factories/IdentifierFactory.d.ts +24 -0
  90. package/lib/factories/IdentifierFactory.js +24 -0
  91. package/lib/factories/IdentifierFactory.js.map +1 -1
  92. package/lib/factories/LiteralFactory.d.ts +22 -4
  93. package/lib/factories/LiteralFactory.js +33 -11
  94. package/lib/factories/LiteralFactory.js.map +1 -1
  95. package/lib/factories/StatementFactory.d.ts +28 -1
  96. package/lib/factories/StatementFactory.js +28 -1
  97. package/lib/factories/StatementFactory.js.map +1 -1
  98. package/lib/factories/TypeFactory.d.ts +24 -0
  99. package/lib/factories/TypeFactory.js +15 -0
  100. package/lib/factories/TypeFactory.js.map +1 -1
  101. package/lib/generates/CloneGenerator.d.ts +22 -0
  102. package/lib/generates/CloneGenerator.js +26 -5
  103. package/lib/generates/CloneGenerator.js.map +1 -1
  104. package/lib/generates/E2eGenerator.d.ts +19 -0
  105. package/lib/generates/E2eGenerator.js +19 -0
  106. package/lib/generates/E2eGenerator.js.map +1 -1
  107. package/lib/generates/SdkGenerator.d.ts +38 -0
  108. package/lib/generates/SdkGenerator.js +43 -5
  109. package/lib/generates/SdkGenerator.js.map +1 -1
  110. package/lib/generates/SwaggerGenerator.d.ts +36 -6
  111. package/lib/generates/SwaggerGenerator.js +190 -40
  112. package/lib/generates/SwaggerGenerator.js.map +1 -1
  113. package/lib/generates/internal/E2eFileProgrammer.d.ts +19 -0
  114. package/lib/generates/internal/E2eFileProgrammer.js +20 -1
  115. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  116. package/lib/generates/internal/FilePrinter.d.ts +57 -0
  117. package/lib/generates/internal/FilePrinter.js +74 -0
  118. package/lib/generates/internal/FilePrinter.js.map +1 -1
  119. package/lib/generates/internal/ImportDictionary.d.ts +93 -1
  120. package/lib/generates/internal/ImportDictionary.js +103 -2
  121. package/lib/generates/internal/ImportDictionary.js.map +1 -1
  122. package/lib/generates/internal/SdkAliasCollection.d.ts +121 -1
  123. package/lib/generates/internal/SdkAliasCollection.js +132 -11
  124. package/lib/generates/internal/SdkAliasCollection.js.map +1 -1
  125. package/lib/generates/internal/SdkDistributionComposer.d.ts +19 -0
  126. package/lib/generates/internal/SdkDistributionComposer.js +149 -52
  127. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  128. package/lib/generates/internal/SdkFileProgrammer.d.ts +18 -0
  129. package/lib/generates/internal/SdkFileProgrammer.js +101 -12
  130. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  131. package/lib/generates/internal/SdkHttpCloneProgrammer.d.ts +29 -0
  132. package/lib/generates/internal/SdkHttpCloneProgrammer.js +33 -0
  133. package/lib/generates/internal/SdkHttpCloneProgrammer.js.map +1 -1
  134. package/lib/generates/internal/SdkHttpCloneReferencer.d.ts +19 -0
  135. package/lib/generates/internal/SdkHttpCloneReferencer.js +78 -25
  136. package/lib/generates/internal/SdkHttpCloneReferencer.js.map +1 -1
  137. package/lib/generates/internal/SdkHttpFunctionProgrammer.d.ts +19 -0
  138. package/lib/generates/internal/SdkHttpFunctionProgrammer.js +40 -23
  139. package/lib/generates/internal/SdkHttpFunctionProgrammer.js.map +1 -1
  140. package/lib/generates/internal/SdkHttpNamespaceProgrammer.d.ts +19 -0
  141. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js +46 -34
  142. package/lib/generates/internal/SdkHttpNamespaceProgrammer.js.map +1 -1
  143. package/lib/generates/internal/SdkHttpParameterProgrammer.d.ts +142 -1
  144. package/lib/generates/internal/SdkHttpParameterProgrammer.js +175 -6
  145. package/lib/generates/internal/SdkHttpParameterProgrammer.js.map +1 -1
  146. package/lib/generates/internal/SdkHttpRouteProgrammer.d.ts +20 -0
  147. package/lib/generates/internal/SdkHttpRouteProgrammer.js +36 -32
  148. package/lib/generates/internal/SdkHttpRouteProgrammer.js.map +1 -1
  149. package/lib/generates/internal/SdkHttpSimulationProgrammer.d.ts +38 -0
  150. package/lib/generates/internal/SdkHttpSimulationProgrammer.js +66 -18
  151. package/lib/generates/internal/SdkHttpSimulationProgrammer.js.map +1 -1
  152. package/lib/generates/internal/SdkImportWizard.d.ts +63 -0
  153. package/lib/generates/internal/SdkImportWizard.js +63 -0
  154. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  155. package/lib/generates/internal/SdkMcpRouteProgrammer.d.ts +17 -2
  156. package/lib/generates/internal/SdkMcpRouteProgrammer.js +72 -24
  157. package/lib/generates/internal/SdkMcpRouteProgrammer.js.map +1 -1
  158. package/lib/generates/internal/SdkPathTemplate.d.ts +36 -0
  159. package/lib/generates/internal/SdkPathTemplate.js +65 -0
  160. package/lib/generates/internal/SdkPathTemplate.js.map +1 -0
  161. package/lib/generates/internal/SdkRouteDirectory.d.ts +10 -0
  162. package/lib/generates/internal/SdkRouteDirectory.js +10 -0
  163. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  164. package/lib/generates/internal/SdkTypeProgrammer.d.ts +54 -1
  165. package/lib/generates/internal/SdkTypeProgrammer.js +111 -27
  166. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  167. package/lib/generates/internal/SdkTypeTagProgrammer.d.ts +53 -1
  168. package/lib/generates/internal/SdkTypeTagProgrammer.js +407 -67
  169. package/lib/generates/internal/SdkTypeTagProgrammer.js.map +1 -1
  170. package/lib/generates/internal/SdkWebSocketCloneProgrammer.d.ts +40 -0
  171. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js +149 -142
  172. package/lib/generates/internal/SdkWebSocketCloneProgrammer.js.map +1 -1
  173. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.d.ts +19 -0
  174. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js +46 -36
  175. package/lib/generates/internal/SdkWebSocketNamespaceProgrammer.js.map +1 -1
  176. package/lib/generates/internal/SdkWebSocketParameterProgrammer.d.ts +114 -1
  177. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js +120 -5
  178. package/lib/generates/internal/SdkWebSocketParameterProgrammer.js.map +1 -1
  179. package/lib/generates/internal/SdkWebSocketRouteProgrammer.d.ts +18 -0
  180. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js +75 -33
  181. package/lib/generates/internal/SdkWebSocketRouteProgrammer.js.map +1 -1
  182. package/lib/generates/internal/SwaggerDescriptionComposer.d.ts +42 -0
  183. package/lib/generates/internal/SwaggerDescriptionComposer.js +44 -1
  184. package/lib/generates/internal/SwaggerDescriptionComposer.js.map +1 -1
  185. package/lib/generates/internal/SwaggerOperationComposer.d.ts +18 -0
  186. package/lib/generates/internal/SwaggerOperationComposer.js +37 -8
  187. package/lib/generates/internal/SwaggerOperationComposer.js.map +1 -1
  188. package/lib/generates/internal/SwaggerOperationParameterComposer.d.ts +40 -1
  189. package/lib/generates/internal/SwaggerOperationParameterComposer.js +230 -25
  190. package/lib/generates/internal/SwaggerOperationParameterComposer.js.map +1 -1
  191. package/lib/generates/internal/SwaggerOperationResponseComposer.d.ts +21 -0
  192. package/lib/generates/internal/SwaggerOperationResponseComposer.js +58 -7
  193. package/lib/generates/internal/SwaggerOperationResponseComposer.js.map +1 -1
  194. package/lib/internal/legacy.d.ts +342 -31
  195. package/lib/internal/legacy.js +207 -31
  196. package/lib/internal/legacy.js.map +1 -1
  197. package/lib/structures/INestiaProject.d.ts +10 -0
  198. package/lib/structures/INestiaSdkInput.d.ts +30 -0
  199. package/lib/structures/IOperationMetadata.d.ts +77 -0
  200. package/lib/structures/IReflectController.d.ts +10 -0
  201. package/lib/structures/IReflectHttpOperation.d.ts +10 -0
  202. package/lib/structures/IReflectHttpOperationException.d.ts +13 -2
  203. package/lib/structures/IReflectHttpOperationParameter.d.ts +55 -3
  204. package/lib/structures/IReflectHttpOperationSuccess.d.ts +15 -3
  205. package/lib/structures/IReflectImport.d.ts +10 -0
  206. package/lib/structures/IReflectMcpOperation.d.ts +19 -0
  207. package/lib/structures/IReflectMcpOperationParameter.d.ts +9 -0
  208. package/lib/structures/IReflectOperationError.d.ts +28 -0
  209. package/lib/structures/IReflectOperationError.js +22 -2
  210. package/lib/structures/IReflectOperationError.js.map +1 -1
  211. package/lib/structures/IReflectType.d.ts +9 -0
  212. package/lib/structures/IReflectWebSocketOperation.d.ts +10 -0
  213. package/lib/structures/IReflectWebSocketOperationParameter.d.ts +55 -0
  214. package/lib/structures/ITypedApplication.d.ts +10 -0
  215. package/lib/structures/ITypedHttpRoute.d.ts +18 -0
  216. package/lib/structures/ITypedHttpRouteException.d.ts +13 -1
  217. package/lib/structures/ITypedHttpRouteParameter.d.ts +48 -1
  218. package/lib/structures/ITypedHttpRouteSuccess.d.ts +13 -1
  219. package/lib/structures/ITypedMcpRoute.d.ts +11 -0
  220. package/lib/structures/ITypedWebSocketRoute.d.ts +18 -0
  221. package/lib/transform.d.ts +6 -0
  222. package/lib/transform.js +6 -0
  223. package/lib/transform.js.map +1 -1
  224. package/lib/utils/ArrayUtil.d.ts +31 -1
  225. package/lib/utils/ArrayUtil.js +32 -11
  226. package/lib/utils/ArrayUtil.js.map +1 -1
  227. package/lib/utils/EmittedJavaScriptPatcher.d.ts +20 -0
  228. package/lib/utils/EmittedJavaScriptPatcher.js +65 -46
  229. package/lib/utils/EmittedJavaScriptPatcher.js.map +1 -1
  230. package/lib/utils/FileRetriever.d.ts +29 -0
  231. package/lib/utils/FileRetriever.js +29 -0
  232. package/lib/utils/FileRetriever.js.map +1 -1
  233. package/lib/utils/HttpResponseContentTypeUtil.d.ts +41 -0
  234. package/lib/utils/HttpResponseContentTypeUtil.js +31 -0
  235. package/lib/utils/HttpResponseContentTypeUtil.js.map +1 -1
  236. package/lib/utils/MapUtil.d.ts +64 -1
  237. package/lib/utils/MapUtil.js +24 -3
  238. package/lib/utils/MapUtil.js.map +1 -1
  239. package/lib/utils/PathUtil.d.ts +31 -0
  240. package/lib/utils/PathUtil.js +38 -0
  241. package/lib/utils/PathUtil.js.map +1 -1
  242. package/lib/utils/SdkBundlePath.d.ts +2 -0
  243. package/lib/utils/SdkBundlePath.js +10 -0
  244. package/lib/utils/SdkBundlePath.js.map +1 -0
  245. package/lib/utils/SdkInputFilter.d.ts +31 -0
  246. package/lib/utils/SdkInputFilter.js +115 -0
  247. package/lib/utils/SdkInputFilter.js.map +1 -0
  248. package/lib/utils/SourceFinder.d.ts +45 -0
  249. package/lib/utils/SourceFinder.js +74 -16
  250. package/lib/utils/SourceFinder.js.map +1 -1
  251. package/lib/utils/StringUtil.d.ts +77 -2
  252. package/lib/utils/StringUtil.js +166 -4
  253. package/lib/utils/StringUtil.js.map +1 -1
  254. package/lib/utils/TemporaryDirectory.d.ts +60 -0
  255. package/lib/utils/TemporaryDirectory.js +112 -0
  256. package/lib/utils/TemporaryDirectory.js.map +1 -0
  257. package/lib/utils/TsConfigReader.d.ts +42 -0
  258. package/lib/utils/TsConfigReader.js +98 -14
  259. package/lib/utils/TsConfigReader.js.map +1 -1
  260. package/lib/utils/TtscExecutor.d.ts +23 -1
  261. package/lib/utils/TtscExecutor.js +22 -0
  262. package/lib/utils/TtscExecutor.js.map +1 -1
  263. package/lib/utils/VersioningStrategy.d.ts +39 -2
  264. package/lib/utils/VersioningStrategy.js +46 -13
  265. package/lib/utils/VersioningStrategy.js.map +1 -1
  266. package/lib/validators/TextPlainValidator.d.ts +19 -0
  267. package/lib/validators/TextPlainValidator.js +19 -0
  268. package/lib/validators/TextPlainValidator.js.map +1 -1
  269. package/native/go.mod +1 -1
  270. package/native/go.sum +2 -2
  271. package/native/sdk/register.go +12 -2
  272. package/native/sdk/sdk_http_rules.go +210 -0
  273. package/native/sdk/sdk_metadata_json.go +79 -4
  274. package/native/sdk/sdk_transform.go +1157 -414
  275. package/package.json +8 -6
  276. package/src/INestiaConfig.ts +74 -34
  277. package/src/NestiaSdkApplication.ts +129 -41
  278. package/src/NestiaSwaggerComposer.ts +32 -14
  279. package/src/analyses/AccessorAnalyzer.ts +26 -0
  280. package/src/analyses/ConfigAnalyzer.ts +52 -90
  281. package/src/analyses/ImportAnalyzer.ts +25 -0
  282. package/src/analyses/ParameterNameAnalyzer.ts +75 -0
  283. package/src/analyses/PathAnalyzer.ts +167 -23
  284. package/src/analyses/ReflectControllerAnalyzer.ts +34 -1
  285. package/src/analyses/ReflectHttpOperationAnalyzer.ts +36 -14
  286. package/src/analyses/ReflectHttpOperationExceptionAnalyzer.ts +31 -0
  287. package/src/analyses/ReflectHttpOperationParameterAnalyzer.ts +153 -39
  288. package/src/analyses/ReflectHttpOperationResponseAnalyzer.ts +38 -7
  289. package/src/analyses/ReflectMcpOperationAnalyzer.ts +38 -3
  290. package/src/analyses/ReflectMetadataAnalyzer.ts +47 -0
  291. package/src/analyses/ReflectWebSocketOperationAnalyzer.ts +40 -7
  292. package/src/analyses/SecurityAnalyzer.ts +45 -20
  293. package/src/analyses/SwaggerExampleAnalyzer.ts +39 -0
  294. package/src/analyses/TypedHttpRouteAnalyzer.ts +263 -198
  295. package/src/analyses/TypedMcpRouteAnalyzer.ts +180 -20
  296. package/src/analyses/TypedWebSocketRouteAnalyzer.ts +20 -0
  297. package/src/decorators/OperationMetadata.ts +6 -0
  298. package/src/executable/internal/CommandParser.ts +19 -0
  299. package/src/executable/internal/NestiaConfigLoader.ts +66 -50
  300. package/src/executable/internal/NestiaSdkCommand.ts +96 -3
  301. package/src/executable/internal/NestiaSdkWatcher.ts +172 -44
  302. package/src/executable/internal/NestiaSwaggerWatch.ts +359 -0
  303. package/src/executable/sdk.ts +24 -1
  304. package/src/factories/ExpressionFactory.ts +23 -2
  305. package/src/factories/IdentifierFactory.ts +24 -0
  306. package/src/factories/LiteralFactory.ts +51 -13
  307. package/src/factories/StatementFactory.ts +28 -1
  308. package/src/factories/TypeFactory.ts +24 -0
  309. package/src/generates/CloneGenerator.ts +26 -5
  310. package/src/generates/E2eGenerator.ts +19 -0
  311. package/src/generates/SdkGenerator.ts +43 -12
  312. package/src/generates/SwaggerGenerator.ts +229 -46
  313. package/src/generates/internal/E2eFileProgrammer.ts +20 -0
  314. package/src/generates/internal/FilePrinter.ts +71 -0
  315. package/src/generates/internal/ImportDictionary.ts +120 -2
  316. package/src/generates/internal/SdkAliasCollection.ts +144 -15
  317. package/src/generates/internal/SdkDistributionComposer.ts +181 -56
  318. package/src/generates/internal/SdkFileProgrammer.ts +126 -16
  319. package/src/generates/internal/SdkHttpCloneProgrammer.ts +55 -0
  320. package/src/generates/internal/SdkHttpCloneReferencer.ts +97 -23
  321. package/src/generates/internal/SdkHttpFunctionProgrammer.ts +47 -30
  322. package/src/generates/internal/SdkHttpNamespaceProgrammer.ts +53 -64
  323. package/src/generates/internal/SdkHttpParameterProgrammer.ts +295 -13
  324. package/src/generates/internal/SdkHttpRouteProgrammer.ts +37 -31
  325. package/src/generates/internal/SdkHttpSimulationProgrammer.ts +122 -18
  326. package/src/generates/internal/SdkImportWizard.ts +63 -0
  327. package/src/generates/internal/SdkMcpRouteProgrammer.ts +150 -33
  328. package/src/generates/internal/SdkPathTemplate.ts +88 -0
  329. package/src/generates/internal/SdkRouteDirectory.ts +10 -0
  330. package/src/generates/internal/SdkTypeProgrammer.ts +137 -36
  331. package/src/generates/internal/SdkTypeTagProgrammer.ts +536 -78
  332. package/src/generates/internal/SdkWebSocketCloneProgrammer.ts +185 -142
  333. package/src/generates/internal/SdkWebSocketNamespaceProgrammer.ts +62 -68
  334. package/src/generates/internal/SdkWebSocketParameterProgrammer.ts +205 -5
  335. package/src/generates/internal/SdkWebSocketRouteProgrammer.ts +89 -48
  336. package/src/generates/internal/SwaggerDescriptionComposer.ts +47 -1
  337. package/src/generates/internal/SwaggerOperationComposer.ts +38 -6
  338. package/src/generates/internal/SwaggerOperationParameterComposer.ts +318 -36
  339. package/src/generates/internal/SwaggerOperationResponseComposer.ts +74 -11
  340. package/src/internal/legacy-augmentation.d.ts +16 -0
  341. package/src/internal/legacy.ts +407 -49
  342. package/src/structures/INestiaProject.ts +10 -0
  343. package/src/structures/INestiaSdkInput.ts +30 -0
  344. package/src/structures/IOperationMetadata.ts +83 -0
  345. package/src/structures/IReflectController.ts +10 -0
  346. package/src/structures/IReflectHttpOperation.ts +10 -0
  347. package/src/structures/IReflectHttpOperationException.ts +17 -2
  348. package/src/structures/IReflectHttpOperationParameter.ts +56 -2
  349. package/src/structures/IReflectHttpOperationSuccess.ts +19 -3
  350. package/src/structures/IReflectImport.ts +10 -0
  351. package/src/structures/IReflectMcpOperation.ts +19 -0
  352. package/src/structures/IReflectMcpOperationParameter.ts +9 -0
  353. package/src/structures/IReflectOperationError.ts +31 -2
  354. package/src/structures/IReflectType.ts +9 -0
  355. package/src/structures/IReflectWebSocketOperation.ts +10 -0
  356. package/src/structures/IReflectWebSocketOperationParameter.ts +55 -0
  357. package/src/structures/ITypedApplication.ts +10 -0
  358. package/src/structures/ITypedHttpRoute.ts +18 -0
  359. package/src/structures/ITypedHttpRouteException.ts +14 -1
  360. package/src/structures/ITypedHttpRouteParameter.ts +48 -1
  361. package/src/structures/ITypedHttpRouteSuccess.ts +14 -1
  362. package/src/structures/ITypedMcpRoute.ts +12 -0
  363. package/src/structures/ITypedWebSocketRoute.ts +18 -0
  364. package/src/transform.ts +6 -0
  365. package/src/utils/ArrayUtil.ts +32 -13
  366. package/src/utils/EmittedJavaScriptPatcher.ts +70 -47
  367. package/src/utils/FileRetriever.ts +29 -0
  368. package/src/utils/HttpResponseContentTypeUtil.ts +41 -0
  369. package/src/utils/MapUtil.ts +68 -3
  370. package/src/utils/PathUtil.ts +38 -0
  371. package/src/utils/SdkBundlePath.ts +11 -0
  372. package/src/utils/SdkInputFilter.ts +108 -0
  373. package/src/utils/SourceFinder.ts +76 -18
  374. package/src/utils/StringUtil.ts +182 -5
  375. package/src/utils/TemporaryDirectory.ts +108 -0
  376. package/src/utils/TsConfigReader.ts +124 -26
  377. package/src/utils/TtscExecutor.ts +23 -1
  378. package/src/utils/VersioningStrategy.ts +51 -16
  379. package/src/validators/TextPlainValidator.ts +19 -0
  380. package/lib/generates/internal/SwaggerReadonlyArrayEmender.d.ts +0 -9
  381. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js +0 -178
  382. package/lib/generates/internal/SwaggerReadonlyArrayEmender.js.map +0 -1
  383. package/lib/validators/HttpHeadersValidator.d.ts +0 -11
  384. package/lib/validators/HttpHeadersValidator.js +0 -15
  385. package/lib/validators/HttpHeadersValidator.js.map +0 -1
  386. package/lib/validators/HttpQueryValidator.d.ts +0 -10
  387. package/lib/validators/HttpQueryValidator.js +0 -14
  388. package/lib/validators/HttpQueryValidator.js.map +0 -1
  389. package/src/generates/internal/SwaggerReadonlyArrayEmender.ts +0 -264
  390. package/src/validators/HttpHeadersValidator.ts +0 -12
  391. package/src/validators/HttpQueryValidator.ts +0 -11
@@ -1,14 +1,79 @@
1
+ /**
2
+ * Helpers for maps.
3
+ *
4
+ * @evidence contracts/common.md#principled-implementation The namespace holds the get-or-create helper.
5
+ * @evidence contracts/common.md#clear-and-simple-design One function.
6
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a plain helper.
7
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
8
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
9
+ */
1
10
  export namespace MapUtil {
11
+ /**
12
+ * Returns the value of a key, creating and storing it when the key is absent.
13
+ *
14
+ * Presence is tested with `has`, so a stored falsy value is not created
15
+ * again. The dictionary may be a `Map` or a `WeakMap`, so a cache keyed by
16
+ * object identity can leave its entries to the garbage collector.
17
+ *
18
+ * @evidence contracts/common.md#principled-implementation The generator runs once per key and its result is stored as it is, in any dictionary with the three members it uses, so the retention of the entries stays the choice of the caller's dictionary.
19
+ * @evidence contracts/common.md#clear-and-simple-design One check, one call, and one store.
20
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The stored value is returned unchanged.
21
+ * @evidence contracts/common.md#meaningful-documentation The comment states the presence rule.
22
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil.take reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
23
+ */
2
24
  export function take<Key, T>(
3
- dict: Map<Key, T>,
25
+ dict: IDictionary<Key, T>,
4
26
  key: Key,
5
27
  generator: () => T,
6
28
  ): T {
7
- const oldbie: T | undefined = dict.get(key);
8
- if (oldbie) return oldbie;
29
+ if (dict.has(key)) return dict.get(key) as T;
9
30
 
10
31
  const value: T = generator();
11
32
  dict.set(key, value);
12
33
  return value;
13
34
  }
35
+
36
+ /**
37
+ * The members of a `Map` or a `WeakMap` that {@link take} reads and writes.
38
+ *
39
+ * @evidence contracts/common.md#principled-implementation The three members are the presence test, the read and the store that the get-or-create rule needs, and both `Map` and `WeakMap` provide them with these signatures.
40
+ * @evidence contracts/common.md#clear-and-simple-design A structural type of three members, so no wrapper or second helper is needed for a weakly keyed cache.
41
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a type and adds no runtime behavior.
42
+ * @evidence contracts/common.md#meaningful-documentation The comment names the two dictionaries it admits and the operations it needs.
43
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil.IDictionary reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
44
+ */
45
+ export interface IDictionary<Key, T> {
46
+ /**
47
+ * Whether the key is present, including a key whose value is `undefined`.
48
+ *
49
+ * @evidence contracts/common.md#principled-implementation Presence is a separate question from the stored value, which is what lets a stored falsy value count as present.
50
+ * @evidence contracts/common.md#clear-and-simple-design One member with the signature that `Map` and `WeakMap` share.
51
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a signature and adds no runtime behavior.
52
+ * @evidence contracts/common.md#meaningful-documentation The comment states what the member answers or does for {@link take}.
53
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil.IDictionary.has reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
54
+ */
55
+ has(key: Key): boolean;
56
+
57
+ /**
58
+ * The value stored for the key, or `undefined` when it is absent.
59
+ *
60
+ * @evidence contracts/common.md#principled-implementation The read is only made after a presence test, so `undefined` here always means a stored value.
61
+ * @evidence contracts/common.md#clear-and-simple-design One member with the signature that `Map` and `WeakMap` share.
62
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a signature and adds no runtime behavior.
63
+ * @evidence contracts/common.md#meaningful-documentation The comment states what the member answers or does for {@link take}.
64
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil.IDictionary.get reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
65
+ */
66
+ get(key: Key): T | undefined;
67
+
68
+ /**
69
+ * Stores the value for the key; the result is ignored.
70
+ *
71
+ * @evidence contracts/common.md#principled-implementation The store is the one effect of the get-or-create rule, and the return type is not read because `Map.set` and `WeakMap.set` return different receivers.
72
+ * @evidence contracts/common.md#clear-and-simple-design One member with the signature that `Map` and `WeakMap` share.
73
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is a signature and adds no runtime behavior.
74
+ * @evidence contracts/common.md#meaningful-documentation The comment states what the member answers or does for {@link take}.
75
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation MapUtil.IDictionary.set reads or initializes caller-supplied map entries; it neither interprets keys as native path identities nor owns a process boundary.
76
+ */
77
+ set(key: Key, value: T): unknown;
78
+ }
14
79
  }
@@ -1,10 +1,48 @@
1
+ import path from "path";
2
+ import { fileURLToPath } from "url";
3
+
4
+ /**
5
+ * Helpers for route paths used as accessors, and for source file locations.
6
+ *
7
+ * @evidence contracts/common.md#principled-implementation The namespace turns a path into accessor names and a source location into a plain path.
8
+ * @evidence contracts/common.md#clear-and-simple-design Two functions.
9
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts They are plain helpers.
10
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
11
+ * @evidence contracts/portability.md#os-neutral-implementation Route accessor spelling uses protocol slashes, while source file URLs are decoded with Node fileURLToPath before native separators are rendered as forward slashes. These operations do not infer filesystem identity or case policy from spelling.
12
+ */
1
13
  export namespace PathUtil {
14
+ /**
15
+ * Returns the accessor segments of a path: the segments that are not empty
16
+ * and not parameters, with dashes and dots replaced by underscores.
17
+ *
18
+ * @evidence contracts/common.md#principled-implementation Parameters do not name a namespace and the replaced characters are not valid in an identifier.
19
+ * @evidence contracts/common.md#clear-and-simple-design One pipeline.
20
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule applies to every path.
21
+ * @evidence contracts/common.md#meaningful-documentation The comment states the result.
22
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation This function processes route URL segments rather than native filesystem paths or identities.
23
+ */
2
24
  export const accessors = (path: string) =>
3
25
  path
4
26
  .split("/")
5
27
  .filter((str) => str.length && str[0] !== ":")
6
28
  .map(normalize);
7
29
 
30
+ /**
31
+ * Returns the plain path of a source location: a `file:` URL is decoded to
32
+ * the path it names, with forward slashes, and any other text is returned as
33
+ * it is.
34
+ *
35
+ * @evidence contracts/common.md#principled-implementation A file URL is percent-encoded, so a path with a space or a non-ASCII character reads back only through the URL decoder, and the platform separator is replaced so the result is the same on every platform.
36
+ * @evidence contracts/common.md#clear-and-simple-design One conditional over the standard decoder.
37
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Only a `file:` location is decoded; a plain path is never altered.
38
+ * @evidence contracts/common.md#meaningful-documentation The comment states both inputs and the separator.
39
+ * @evidence contracts/portability.md#os-neutral-implementation Node fileURLToPath handles platform-specific drive and UNC URL forms and percent decoding. The resulting native separators are rendered as forward slashes for source-location metadata; plain paths keep their original spelling and no filesystem identity comparison is attempted.
40
+ */
41
+ export const location = (str: string): string =>
42
+ str.startsWith("file:")
43
+ ? fileURLToPath(str).split(path.sep).join("/")
44
+ : str;
45
+
8
46
  const normalize = (str: string) =>
9
47
  str.split("-").join("_").split(".").join("_");
10
48
  }
@@ -0,0 +1,11 @@
1
+ import path from "path";
2
+
3
+ /** The installed API bundle shared by SDK emission and source exclusion. */
4
+ export const SDK_BUNDLE_PATH: string = path.join(
5
+ __dirname,
6
+ "..",
7
+ "..",
8
+ "assets",
9
+ "bundle",
10
+ "api",
11
+ );
@@ -0,0 +1,108 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { SDK_BUNDLE_PATH } from "./SdkBundlePath";
5
+ import { SourceFinder } from "./SourceFinder";
6
+
7
+ /**
8
+ * Separates authored TypeScript inputs from files owned by SDK generation.
9
+ *
10
+ * Each filter owns one output directory. Installed bundle metadata is shared;
11
+ * output-specific native paths are never stored in the process-wide cache.
12
+ *
13
+ * @evidence contracts/common.md#principled-implementation Source extensions are checked before generated functional descendants and exact bundled output files are excluded. Native identities and path.relative distinguish descendants from prefix-sharing siblings.
14
+ * @evidence contracts/common.md#clear-and-simple-design One filter factory separates source selection from controller compilation; its private helpers own bundle metadata and filesystem identity.
15
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Exclusions come from the actual installed bundle and the generated functional directory, without fixture names or a cached caller output.
16
+ * @evidence contracts/common.md#meaningful-documentation The comment states filter ownership and the cache's output-independent content.
17
+ * @evidence contracts/portability.md#os-neutral-implementation Native real paths resolve existing ancestors and path.relative judges directory containment; neither OS names nor lowercasing assume a volume's case or link policy.
18
+ * efficient algorithms: Successful installed bundle entries are scanned once and each filter builds its exclusion roots once; a candidate resolves one identity and compares at most the bundle entry count plus functional root, with no recursive source scan here.
19
+ * reuse equivalent work: Concurrent filters share installed bundle names and kinds; a failed metadata read clears the promise so a later request can retry. Output-specific resolved roots belong to each factory call, so another output cannot reuse the first caller's paths.
20
+ * bound retention and release resources: The one metadata promise retains only the fixed installed bundle population. Output roots live in the returned filter closure and are released with its source-discovery call; there is no growing per-output registry.
21
+ */
22
+ export namespace SdkInputFilter {
23
+ /**
24
+ * Creates the source predicate for one configuration's output, or an
25
+ * extension-only predicate when no SDK output is configured.
26
+ *
27
+ * @evidence contracts/common.md#principled-implementation The predicate accepts regular TypeScript source names, excludes descendants of this output's functional directory and the bundle's exact file/directory identities, and leaves same-named authored files outside that output eligible.
28
+ * @evidence contracts/common.md#clear-and-simple-design Output roots are prepared before discovery and captured in one returned predicate, so compilation never owns these path-selection rules.
29
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Every configuration resolves its own output; no first-call output, substring containment or operating-system case guess substitutes for filesystem identity.
30
+ * @evidence contracts/common.md#meaningful-documentation The comment documents both output-bound and extension-only modes.
31
+ * @evidence contracts/portability.md#os-neutral-implementation The nearest existing ancestor carries actual case/link identity and nonexistent suffixes retain their native spelling; path.relative rejects sibling and cross-root locations without protocol-path comparisons.
32
+ * efficient algorithms: Factory preparation is linear in installed bundle entries and each predicate call scans those prepared roots after one candidate identity resolution. It reuses the discovery traversal rather than walking inputs again.
33
+ * reuse equivalent work: Output-independent metadata comes from one shared in-flight or successful promise; rejection clears it for retry, while each output-specific root array is computed for its own factory call and is not shared across incompatible configurations.
34
+ * bound retention and release resources: The predicate retains only this configuration's fixed exclusion roots and no candidate history; once SourceFinder finishes, that closure has no persistent owner.
35
+ */
36
+ export const create = async (
37
+ output: string | undefined,
38
+ ): Promise<(location: string) => Promise<boolean>> => {
39
+ if (output === undefined)
40
+ return async (location) => SourceFinder.isTypeScriptSource(location);
41
+ const excluded = [
42
+ {
43
+ location: identity(path.resolve(output, "functional")),
44
+ directory: true,
45
+ },
46
+ ...(await bundle()).map((asset) => ({
47
+ location: identity(path.resolve(output, asset.name)),
48
+ directory: asset.directory,
49
+ })),
50
+ ];
51
+ return async (location) => {
52
+ if (SourceFinder.isTypeScriptSource(location) === false) return false;
53
+ const file = identity(location);
54
+ return excluded.every((entry) =>
55
+ entry.directory
56
+ ? within(entry.location, file) === false
57
+ : entry.location !== file,
58
+ );
59
+ };
60
+ };
61
+ }
62
+
63
+ let bundlePromise: Promise<{ name: string; directory: boolean }[]> | undefined;
64
+ const bundle = (): Promise<{ name: string; directory: boolean }[]> => {
65
+ if (bundlePromise === undefined)
66
+ bundlePromise = (async () =>
67
+ Promise.all(
68
+ (
69
+ await fs.promises.readdir(SDK_BUNDLE_PATH, { withFileTypes: true })
70
+ ).map(async (entry) => ({
71
+ name: entry.name,
72
+ directory: entry.isSymbolicLink()
73
+ ? (
74
+ await fs.promises.stat(path.join(SDK_BUNDLE_PATH, entry.name))
75
+ ).isDirectory()
76
+ : entry.isDirectory(),
77
+ })),
78
+ ))().catch((error) => {
79
+ bundlePromise = undefined;
80
+ throw error;
81
+ });
82
+ return bundlePromise;
83
+ };
84
+
85
+ const within = (directory: string, location: string): boolean => {
86
+ const relative = path.relative(directory, location);
87
+ return (
88
+ relative === "" ||
89
+ (path.isAbsolute(relative) === false &&
90
+ relative !== ".." &&
91
+ relative.startsWith(`..${path.sep}`) === false)
92
+ );
93
+ };
94
+
95
+ const identity = (location: string): string => {
96
+ const rest: string[] = [];
97
+ for (let current = path.resolve(location); ; ) {
98
+ try {
99
+ return path.join(fs.realpathSync.native(current), ...rest.reverse());
100
+ } catch (error) {
101
+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
102
+ const parent = path.dirname(current);
103
+ if (parent === current) throw error;
104
+ rest.push(path.basename(current));
105
+ current = parent;
106
+ }
107
+ }
108
+ };
@@ -2,6 +2,15 @@ import fs from "fs";
2
2
  import { glob } from "glob";
3
3
  import path from "path";
4
4
 
5
+ /**
6
+ * Finds source files by path, directory, or glob.
7
+ *
8
+ * @evidence contracts/common.md#principled-implementation Each pattern is resolved to files or directories, directories are walked, the filter is applied to files, and the excluded set is subtracted.
9
+ * @evidence contracts/common.md#clear-and-simple-design Three public functions and private walkers.
10
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The filter is the caller's.
11
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
12
+ * @evidence contracts/portability.md#os-neutral-implementation The finder turns each pattern into an absolute native path with `path.resolve` and asks the filesystem itself, through `existsSync`, `stat` and `readdir`, whether a path exists and what it is, so the volume's own case policy and links apply. Only the part of a pattern below its longest existing ancestor is globbed, rewritten from the native separator to `/` because glob reads a Windows backslash as an escape. Remaining assumptions: the case policy of wildcard matching is glob's own platform default and not a probe of the volume, and accepted files are keyed by filesystem real path while returned locations retain their discovered spelling, so include and exclude aliases identify the same file.
13
+ */
5
14
  export namespace SourceFinder {
6
15
  interface IProps {
7
16
  exclude?: string[];
@@ -9,29 +18,40 @@ export namespace SourceFinder {
9
18
  filter: (location: string) => Promise<boolean>;
10
19
  }
11
20
 
21
+ /**
22
+ * Returns the files matched by the include patterns and not by the exclude
23
+ * patterns and accepted by the filter.
24
+ *
25
+ * @evidence contracts/common.md#principled-implementation Every pattern is expanded, existing paths remain literal, and only regular files accepted by the filter enter either collection; the exclusion runs the same collection removing instead of adding.
26
+ * @evidence contracts/common.md#clear-and-simple-design One function that runs the collection twice.
27
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The result follows the patterns and the filter.
28
+ * @evidence contracts/common.md#meaningful-documentation The comment states the result.
29
+ * @evidence contracts/portability.md#os-neutral-implementation It composes the include and exclude collections over native absolute paths and returns them as `path.resolve` spelled them. A directory is walked through `stat`, which follows links; each include or exclude collection keeps a real-path set, so a linked directory is entered once and a link back to an ancestor is skipped.
30
+ */
12
31
  export const find = async (props: IProps): Promise<string[]> => {
13
- const dict: Set<string> = new Set();
32
+ const dict: Map<string, string> = new Map();
14
33
 
15
- await emplace(props.filter)(props.include)((str) => dict.add(str));
34
+ await emplace(props.filter)(props.include)((str) =>
35
+ dict.set(fs.realpathSync.native(str), str),
36
+ );
16
37
  if (props.exclude?.length)
17
- await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
38
+ await emplace(props.filter)(props.exclude)((str) =>
39
+ dict.delete(fs.realpathSync.native(str)),
40
+ );
18
41
 
19
- return [...dict];
42
+ return [...dict.values()];
20
43
  };
21
44
 
22
45
  const emplace =
23
46
  (filter: (file: string) => Promise<boolean>) =>
24
47
  (input: string[]) =>
25
48
  async (closure: (location: string) => void): Promise<void> => {
49
+ const visited: Set<string> = new Set();
26
50
  for (const pattern of input) {
27
- if (_Is_file(pattern)) {
28
- closure(path.resolve(pattern));
29
- continue;
30
- }
31
- for (const file of await _Glob(pattern)) {
51
+ for (const file of await expand(pattern)) {
32
52
  const stats: fs.Stats = await fs.promises.stat(file);
33
53
  if (stats.isDirectory() === true)
34
- await iterate(filter)(closure)(file);
54
+ await iterate(filter)(closure)(file, visited);
35
55
  else if (stats.isFile() && (await filter(file))) closure(file);
36
56
  }
37
57
  }
@@ -40,25 +60,63 @@ export namespace SourceFinder {
40
60
  const iterate =
41
61
  (filter: (location: string) => Promise<boolean>) =>
42
62
  (closure: (location: string) => void) =>
43
- async (location: string): Promise<void> => {
63
+ async (location: string, visited: Set<string>): Promise<void> => {
64
+ const identity: string = await fs.promises.realpath(location);
65
+ if (visited.has(identity)) return;
66
+ visited.add(identity);
44
67
  const directory: string[] = await fs.promises.readdir(location);
45
68
  for (const file of directory) {
46
69
  const next: string = path.resolve(`${location}/${file}`);
47
70
  const stats: fs.Stats = await fs.promises.stat(next);
48
71
 
49
- if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
72
+ if (stats.isDirectory() === true)
73
+ await iterate(filter)(closure)(next, visited);
50
74
  else if (stats.isFile() && (await filter(next))) closure(next);
51
75
  }
52
76
  };
53
77
 
54
- const _Glob = async (pattern: string): Promise<string[]> => {
55
- const matches = await glob(pattern);
56
- return matches.map((str) => path.resolve(str));
78
+ /**
79
+ * Files and directories a path or glob pattern names.
80
+ *
81
+ * An existing path is taken literally, whatever characters it holds, as a
82
+ * directory such as `app [v2]` would otherwise read as a character class. For
83
+ * a pattern, the longest existing ancestor is the literal base and only the
84
+ * rest is globbed, with `/` separators, since glob reads a Windows backslash
85
+ * as an escape.
86
+ *
87
+ * @evidence contracts/common.md#principled-implementation The wildcard part is matched below the part of the path that exists, and a base that does not exist matches nothing.
88
+ * @evidence contracts/common.md#clear-and-simple-design One function.
89
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It follows the filesystem.
90
+ * @evidence contracts/common.md#meaningful-documentation The comment states the two cases.
91
+ * @evidence contracts/portability.md#os-neutral-implementation An existing path is used literally, so no character glob reads specially is interpreted. Otherwise the nearest existing ancestor, found with `existsSync` and `dirname` until the filesystem root, is the glob's working directory, the remainder is rewritten from `path.sep` to `/`, and the matches are resolved against that base, so a drive letter or a UNC root never enters the pattern.
92
+ */
93
+ export const expand = async (pattern: string): Promise<string[]> => {
94
+ const absolute: string = path.resolve(pattern);
95
+ if (fs.existsSync(absolute)) return [absolute];
96
+ let base: string = absolute;
97
+ while (fs.existsSync(base) === false) {
98
+ const parent: string = path.dirname(base);
99
+ if (parent === base) return [];
100
+ base = parent;
101
+ }
102
+ const rest: string = path
103
+ .relative(base, absolute)
104
+ .split(path.sep)
105
+ .join("/");
106
+ const matches: string[] = await glob(rest, { cwd: base });
107
+ return matches.map((str) => path.resolve(base, str));
57
108
  };
58
109
 
59
- const _Is_file = (pattern: string): boolean =>
60
- isTypeScriptSource(pattern) && fs.existsSync(pattern);
61
-
110
+ /**
111
+ * Reports whether a file is a TypeScript source: an extension of `ts`, `mts`,
112
+ * or `cts` that is not a declaration file.
113
+ *
114
+ * @evidence contracts/common.md#principled-implementation The check is on the lower-cased name, and declaration files are excluded because they hold no runtime code.
115
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
116
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It is by extension.
117
+ * @evidence contracts/common.md#meaningful-documentation The comment states the accepted extensions.
118
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation The function judges the spelling of a name the caller supplies and opens no path, so it owns no filesystem or process decision; extensions are compared lower-cased on every platform by design.
119
+ */
62
120
  export const isTypeScriptSource = (file: string): boolean => {
63
121
  const lower: string = file.toLowerCase();
64
122
  return (
@@ -1,7 +1,44 @@
1
+ /**
2
+ * String helpers of the SDK generator.
3
+ *
4
+ * @evidence contracts/common.md#principled-implementation The namespace holds capitalization, duplicate escaping, and the recognition of anonymous type names.
5
+ * @evidence contracts/common.md#clear-and-simple-design Five small functions.
6
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The markers are the spellings typia uses for anonymous types.
7
+ * @evidence contracts/common.md#meaningful-documentation The comment states its purpose.
8
+ * efficient algorithms: The namespace groups string operations; each function owns its scan or duplicate lookup.
9
+ * reuse equivalent work: The namespace coordinates no shared computation.
10
+ * bound retention and release resources: The namespace owns no input-dependent retained state or handles.
11
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
12
+ */
1
13
  export namespace StringUtil {
14
+ /**
15
+ * Upper-cases the first character and lower-cases the rest.
16
+ *
17
+ * @evidence contracts/common.md#principled-implementation The first character is transformed alone and the rest is lower-cased.
18
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
19
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It applies to every input.
20
+ * @evidence contracts/common.md#meaningful-documentation The comment states the rule.
21
+ * efficient algorithms: Case conversion and copying process the input characters once with proportional returned string storage.
22
+ * reuse equivalent work: Case conversion coordinates no shared requests.
23
+ * bound retention and release resources: The returned string belongs to the caller; this operation retains no state or handles.
24
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil.capitalize transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
25
+ */
2
26
  export const capitalize = (text: string): string =>
3
27
  text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
4
28
 
29
+ /**
30
+ * Returns the name with underscores prefixed until it is not in the list of
31
+ * names to keep clear of.
32
+ *
33
+ * @evidence contracts/common.md#principled-implementation The recursion adds one underscore at a time, so the result is the shortest such name.
34
+ * @evidence contracts/common.md#clear-and-simple-design One curried function.
35
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The rule is generic.
36
+ * @evidence contracts/common.md#meaningful-documentation The comment states the result.
37
+ * efficient algorithms: Each occupied candidate scans the supplied keep list and adds one underscore; the number of recursive candidates is bounded by distinct occupied spellings in that list, with string comparison and copying costs proportional to candidate lengths.
38
+ * reuse equivalent work: The caller supplies the current keep list; this operation coordinates no shared computation between calls.
39
+ * bound retention and release resources: The closure retains only the caller's keep list for its own lifetime and owns no history, handles or tasks.
40
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil.escapeDuplicate transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
41
+ */
5
42
  export const escapeDuplicate =
6
43
  (keep: string[]) =>
7
44
  (change: string): string =>
@@ -18,6 +55,15 @@ export namespace StringUtil {
18
55
  * whether its name collided. Three call sites carried their own copy of this
19
56
  * list, only one of them learned the `-` spelling, and the two that did not
20
57
  * declared and referenced modules that do not exist.
58
+ *
59
+ * @evidence contracts/common.md#principled-implementation The names `__type` and `__object` and their dotted or dashed forms are the anonymous markers, so the predicate is a list of those spellings.
60
+ * @evidence contracts/common.md#clear-and-simple-design One expression.
61
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts The list is the shared definition that the generators use.
62
+ * @evidence contracts/common.md#meaningful-documentation The comment states the markers.
63
+ * efficient algorithms: A fixed number of equalities and constant-length prefix checks inspect each name without graph traversal or input-dependent state.
64
+ * reuse equivalent work: This predicate coordinates no shared computation.
65
+ * bound retention and release resources: This predicate retains no input or handles.
66
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil.isAnonymous transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
21
67
  */
22
68
  export const isAnonymous = (str: string): boolean =>
23
69
  str === "__type" ||
@@ -27,12 +73,32 @@ export namespace StringUtil {
27
73
  str.startsWith("__type-") ||
28
74
  str.startsWith("__object-");
29
75
 
76
+ /**
77
+ * Reports whether a type name is implicit: the name `object`, an anonymous
78
+ * name, or a readonly tuple.
79
+ *
80
+ * @evidence contracts/common.md#principled-implementation It extends the anonymous test with the two other names that cannot be referenced.
81
+ * @evidence contracts/common.md#clear-and-simple-design One expression over `isAnonymous`.
82
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts It shares the anonymous list.
83
+ * @evidence contracts/common.md#meaningful-documentation The comment states the cases.
84
+ * efficient algorithms: Fixed name checks and one substring search take at most linear time in the name's length, without allocating a graph or cache.
85
+ * reuse equivalent work: This predicate coordinates no shared computation.
86
+ * bound retention and release resources: This predicate retains no input or handles.
87
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil.isImplicit transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
88
+ */
30
89
  export const isImplicit = (str: string) =>
31
90
  str === "object" || isAnonymous(str) || str.includes("readonly [");
32
91
 
33
92
  /**
34
- * Split a typia metadata name into the accessor path a generated SDK declares
35
- * it under.
93
+ * Splits a metadata name into legal TypeScript declaration accessors.
94
+ *
95
+ * Component keys remain unchanged: this conversion owns only the cloned
96
+ * declaration, reference and import spelling. Identifier code points survive;
97
+ * other code points are written as hexadecimal identifier fragments. Reserved
98
+ * binding and intrinsic type names receive an underscore. The route
99
+ * dictionary compares these same accessors when separating unequal component
100
+ * definitions, including a source name which already contains an escaped
101
+ * fragment.
36
102
  *
37
103
  * Typia separates a qualified name with `.` and a _duplicated_ name from its
38
104
  * disambiguating counter with a trailing `-o<counter>`
@@ -47,11 +113,122 @@ export namespace StringUtil {
47
113
  * guessing at the name is what the new separator makes possible -- `-` cannot
48
114
  * occur in a qualified name, so unlike the old spelling this cannot be
49
115
  * confused with one.
116
+ *
117
+ * @evidence contracts/common.md#principled-implementation The historical trailing duplicate marker and namespace dots are interpreted before each segment is encoded under Unicode IdentifierStart/IdentifierPart and strict binding/type-name restrictions. All clone declarations, references, imports and collision slots consume this same spelling; raw metadata component keys are not rewritten.
118
+ * @evidence contracts/common.md#clear-and-simple-design One accessor operation delegates segment encoding to a private helper with language-defined reserved names.
119
+ * @evidence contracts/common.md#prohibited-implementation-shortcuts Encoding depends on identifier grammar, not a DTO or consumer name; the existing semantic collision partition separates unequal definitions whose accessors coincide.
120
+ * @evidence contracts/common.md#meaningful-documentation The comment distinguishes raw component keys from TypeScript accessors and explains Unicode encoding, reserved bindings and duplicate compatibility.
121
+ * efficient algorithms: Each name and its code points are scanned once, with output space proportional to the encoded spelling; reserved-name lookup uses a fixed set.
122
+ * reuse equivalent work: This pure conversion coordinates no completed or in-flight work across consumers; its callers own graph and dictionary reuse.
123
+ * bound retention and release resources: The fixed grammar set has no input-dependent history; temporary accessor strings belong to the caller and no handles or tasks are retained.
124
+ * @evidenceExclude contracts/portability.md#os-neutral-implementation StringUtil.accessorsOf transforms declaration names and textual content; separators in accessor names are language syntax rather than native filesystem separators.
50
125
  */
51
126
  export const accessorsOf = (name: string): string[] => {
52
127
  const duplicated: RegExpMatchArray | null = name.match(/^(.+)-o(\d+)$/);
53
- return duplicated === null
54
- ? name.split(".")
55
- : [...duplicated[1]!.split("."), `o${duplicated[2]!}`];
128
+ return (
129
+ duplicated === null
130
+ ? name.split(".")
131
+ : [...duplicated[1]!.split("."), `o${duplicated[2]!}`]
132
+ ).map((segment, index, accessors) =>
133
+ identifier(segment, index === 0, index === accessors.length - 1),
134
+ );
135
+ };
136
+
137
+ // Unicode IdentifierStart/IdentifierPart additionally admit $ and _, and
138
+ // IdentifierPart admits the two joining controls. Iterate code points so a
139
+ // supplementary letter is kept whole and an isolated surrogate is encoded.
140
+ const identifier = (
141
+ segment: string,
142
+ root: boolean,
143
+ leaf: boolean,
144
+ ): string => {
145
+ const fragments: string[] = [];
146
+ for (const point of segment) {
147
+ const valid = (
148
+ fragments.length === 0 ? identifierStart : identifierPart
149
+ ).test(point);
150
+ fragments.push(
151
+ valid
152
+ ? point
153
+ : `_x${point.codePointAt(0)!.toString(16).toUpperCase()}_`,
154
+ );
155
+ }
156
+ const output = fragments.join("");
157
+ if (output.length === 0) return "_";
158
+ return reserved.has(output) ||
159
+ (root && output === "await") ||
160
+ ((root || leaf) && typeNames.has(output))
161
+ ? `_${output}`
162
+ : output;
56
163
  };
164
+
165
+ const identifierStart = /^[$_\p{ID_Start}]$/u;
166
+ const identifierPart = /^[$_\u200C\u200D\p{ID_Continue}]$/u;
167
+
168
+ // ECMAScript strict/module bindings and names TypeScript reserves for its
169
+ // intrinsic types. Contextual labels such as type, async and readonly remain
170
+ // ordinary identifiers here.
171
+ const reserved = new Set([
172
+ "break",
173
+ "case",
174
+ "catch",
175
+ "class",
176
+ "const",
177
+ "continue",
178
+ "debugger",
179
+ "default",
180
+ "delete",
181
+ "do",
182
+ "else",
183
+ "enum",
184
+ "export",
185
+ "extends",
186
+ "false",
187
+ "finally",
188
+ "for",
189
+ "function",
190
+ "if",
191
+ "import",
192
+ "in",
193
+ "instanceof",
194
+ "new",
195
+ "null",
196
+ "return",
197
+ "super",
198
+ "switch",
199
+ "this",
200
+ "throw",
201
+ "true",
202
+ "try",
203
+ "typeof",
204
+ "var",
205
+ "void",
206
+ "while",
207
+ "with",
208
+ "implements",
209
+ "interface",
210
+ "let",
211
+ "package",
212
+ "private",
213
+ "protected",
214
+ "public",
215
+ "static",
216
+ "yield",
217
+ ]);
218
+
219
+ // These names are forbidden for type aliases and imported bindings, but a
220
+ // nested namespace can use them. Await likewise remains legal inside a
221
+ // namespace, whose scope is distinct from the surrounding external module.
222
+ const typeNames = new Set([
223
+ "any",
224
+ "unknown",
225
+ "never",
226
+ "number",
227
+ "bigint",
228
+ "boolean",
229
+ "string",
230
+ "symbol",
231
+ "object",
232
+ "undefined",
233
+ ]);
57
234
  }