mnehmos.trace.mcp 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 (339) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1662 -0
  3. package/dist/adapters/bootstrap.d.ts +29 -0
  4. package/dist/adapters/bootstrap.d.ts.map +1 -0
  5. package/dist/adapters/bootstrap.js +46 -0
  6. package/dist/adapters/bootstrap.js.map +1 -0
  7. package/dist/adapters/errors.d.ts +94 -0
  8. package/dist/adapters/errors.d.ts.map +1 -0
  9. package/dist/adapters/errors.js +107 -0
  10. package/dist/adapters/errors.js.map +1 -0
  11. package/dist/adapters/graphql/index.d.ts +9 -0
  12. package/dist/adapters/graphql/index.d.ts.map +1 -0
  13. package/dist/adapters/graphql/index.js +9 -0
  14. package/dist/adapters/graphql/index.js.map +1 -0
  15. package/dist/adapters/graphql/sdl-parser.d.ts +74 -0
  16. package/dist/adapters/graphql/sdl-parser.d.ts.map +1 -0
  17. package/dist/adapters/graphql/sdl-parser.js +559 -0
  18. package/dist/adapters/graphql/sdl-parser.js.map +1 -0
  19. package/dist/adapters/grpc/adapter.d.ts +76 -0
  20. package/dist/adapters/grpc/adapter.d.ts.map +1 -0
  21. package/dist/adapters/grpc/adapter.js +362 -0
  22. package/dist/adapters/grpc/adapter.js.map +1 -0
  23. package/dist/adapters/grpc/index.d.ts +10 -0
  24. package/dist/adapters/grpc/index.d.ts.map +1 -0
  25. package/dist/adapters/grpc/index.js +12 -0
  26. package/dist/adapters/grpc/index.js.map +1 -0
  27. package/dist/adapters/grpc/proto-parser.d.ts +76 -0
  28. package/dist/adapters/grpc/proto-parser.d.ts.map +1 -0
  29. package/dist/adapters/grpc/proto-parser.js +523 -0
  30. package/dist/adapters/grpc/proto-parser.js.map +1 -0
  31. package/dist/adapters/grpc/type-converter.d.ts +43 -0
  32. package/dist/adapters/grpc/type-converter.d.ts.map +1 -0
  33. package/dist/adapters/grpc/type-converter.js +270 -0
  34. package/dist/adapters/grpc/type-converter.js.map +1 -0
  35. package/dist/adapters/grpc/types.d.ts +85 -0
  36. package/dist/adapters/grpc/types.d.ts.map +1 -0
  37. package/dist/adapters/grpc/types.js +7 -0
  38. package/dist/adapters/grpc/types.js.map +1 -0
  39. package/dist/adapters/index.d.ts +39 -0
  40. package/dist/adapters/index.d.ts.map +1 -0
  41. package/dist/adapters/index.js +50 -0
  42. package/dist/adapters/index.js.map +1 -0
  43. package/dist/adapters/mcp.d.ts +23 -0
  44. package/dist/adapters/mcp.d.ts.map +1 -0
  45. package/dist/adapters/mcp.js +293 -0
  46. package/dist/adapters/mcp.js.map +1 -0
  47. package/dist/adapters/openapi/adapter.d.ts +213 -0
  48. package/dist/adapters/openapi/adapter.d.ts.map +1 -0
  49. package/dist/adapters/openapi/adapter.js +557 -0
  50. package/dist/adapters/openapi/adapter.js.map +1 -0
  51. package/dist/adapters/openapi/convert.d.ts +120 -0
  52. package/dist/adapters/openapi/convert.d.ts.map +1 -0
  53. package/dist/adapters/openapi/convert.js +363 -0
  54. package/dist/adapters/openapi/convert.js.map +1 -0
  55. package/dist/adapters/openapi/index.d.ts +39 -0
  56. package/dist/adapters/openapi/index.d.ts.map +1 -0
  57. package/dist/adapters/openapi/index.js +48 -0
  58. package/dist/adapters/openapi/index.js.map +1 -0
  59. package/dist/adapters/openapi/parser.d.ts +95 -0
  60. package/dist/adapters/openapi/parser.d.ts.map +1 -0
  61. package/dist/adapters/openapi/parser.js +171 -0
  62. package/dist/adapters/openapi/parser.js.map +1 -0
  63. package/dist/adapters/registry.d.ts +116 -0
  64. package/dist/adapters/registry.d.ts.map +1 -0
  65. package/dist/adapters/registry.js +246 -0
  66. package/dist/adapters/registry.js.map +1 -0
  67. package/dist/adapters/trpc/adapter.d.ts +159 -0
  68. package/dist/adapters/trpc/adapter.d.ts.map +1 -0
  69. package/dist/adapters/trpc/adapter.js +223 -0
  70. package/dist/adapters/trpc/adapter.js.map +1 -0
  71. package/dist/adapters/trpc/extractor.d.ts +218 -0
  72. package/dist/adapters/trpc/extractor.d.ts.map +1 -0
  73. package/dist/adapters/trpc/extractor.js +708 -0
  74. package/dist/adapters/trpc/extractor.js.map +1 -0
  75. package/dist/adapters/trpc/index.d.ts +31 -0
  76. package/dist/adapters/trpc/index.d.ts.map +1 -0
  77. package/dist/adapters/trpc/index.js +40 -0
  78. package/dist/adapters/trpc/index.js.map +1 -0
  79. package/dist/adapters/trpc/parser.d.ts +119 -0
  80. package/dist/adapters/trpc/parser.d.ts.map +1 -0
  81. package/dist/adapters/trpc/parser.js +128 -0
  82. package/dist/adapters/trpc/parser.js.map +1 -0
  83. package/dist/compare/index.d.ts +33 -0
  84. package/dist/compare/index.d.ts.map +1 -0
  85. package/dist/compare/index.js +261 -0
  86. package/dist/compare/index.js.map +1 -0
  87. package/dist/core/types.d.ts +188 -0
  88. package/dist/core/types.d.ts.map +1 -0
  89. package/dist/core/types.js +9 -0
  90. package/dist/core/types.js.map +1 -0
  91. package/dist/extract/index.d.ts +26 -0
  92. package/dist/extract/index.d.ts.map +1 -0
  93. package/dist/extract/index.js +44 -0
  94. package/dist/extract/index.js.map +1 -0
  95. package/dist/index.d.ts +9 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +674 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/languages/base.d.ts +57 -0
  100. package/dist/languages/base.d.ts.map +1 -0
  101. package/dist/languages/base.js +6 -0
  102. package/dist/languages/base.js.map +1 -0
  103. package/dist/languages/bootstrap.d.ts +10 -0
  104. package/dist/languages/bootstrap.d.ts.map +1 -0
  105. package/dist/languages/bootstrap.js +25 -0
  106. package/dist/languages/bootstrap.js.map +1 -0
  107. package/dist/languages/go/handlers/chi.d.ts +24 -0
  108. package/dist/languages/go/handlers/chi.d.ts.map +1 -0
  109. package/dist/languages/go/handlers/chi.js +205 -0
  110. package/dist/languages/go/handlers/chi.js.map +1 -0
  111. package/dist/languages/go/handlers/gin.d.ts +24 -0
  112. package/dist/languages/go/handlers/gin.d.ts.map +1 -0
  113. package/dist/languages/go/handlers/gin.js +156 -0
  114. package/dist/languages/go/handlers/gin.js.map +1 -0
  115. package/dist/languages/go/handlers/stdlib.d.ts +19 -0
  116. package/dist/languages/go/handlers/stdlib.d.ts.map +1 -0
  117. package/dist/languages/go/handlers/stdlib.js +112 -0
  118. package/dist/languages/go/handlers/stdlib.js.map +1 -0
  119. package/dist/languages/go/index.d.ts +18 -0
  120. package/dist/languages/go/index.d.ts.map +1 -0
  121. package/dist/languages/go/index.js +20 -0
  122. package/dist/languages/go/index.js.map +1 -0
  123. package/dist/languages/go/parser.d.ts +33 -0
  124. package/dist/languages/go/parser.d.ts.map +1 -0
  125. package/dist/languages/go/parser.js +95 -0
  126. package/dist/languages/go/parser.js.map +1 -0
  127. package/dist/languages/go/struct-extractor.d.ts +59 -0
  128. package/dist/languages/go/struct-extractor.d.ts.map +1 -0
  129. package/dist/languages/go/struct-extractor.js +483 -0
  130. package/dist/languages/go/struct-extractor.js.map +1 -0
  131. package/dist/languages/go/tag-parser.d.ts +62 -0
  132. package/dist/languages/go/tag-parser.d.ts.map +1 -0
  133. package/dist/languages/go/tag-parser.js +108 -0
  134. package/dist/languages/go/tag-parser.js.map +1 -0
  135. package/dist/languages/go/type-converter.d.ts +32 -0
  136. package/dist/languages/go/type-converter.d.ts.map +1 -0
  137. package/dist/languages/go/type-converter.js +226 -0
  138. package/dist/languages/go/type-converter.js.map +1 -0
  139. package/dist/languages/go/types.d.ts +153 -0
  140. package/dist/languages/go/types.d.ts.map +1 -0
  141. package/dist/languages/go/types.js +6 -0
  142. package/dist/languages/go/types.js.map +1 -0
  143. package/dist/languages/import-resolver.d.ts +645 -0
  144. package/dist/languages/import-resolver.d.ts.map +1 -0
  145. package/dist/languages/import-resolver.js +1278 -0
  146. package/dist/languages/import-resolver.js.map +1 -0
  147. package/dist/languages/index.d.ts +34 -0
  148. package/dist/languages/index.d.ts.map +1 -0
  149. package/dist/languages/index.js +93 -0
  150. package/dist/languages/index.js.map +1 -0
  151. package/dist/languages/json-schema.d.ts +40 -0
  152. package/dist/languages/json-schema.d.ts.map +1 -0
  153. package/dist/languages/json-schema.js +188 -0
  154. package/dist/languages/json-schema.js.map +1 -0
  155. package/dist/languages/python-ast/index.d.ts +8 -0
  156. package/dist/languages/python-ast/index.d.ts.map +1 -0
  157. package/dist/languages/python-ast/index.js +7 -0
  158. package/dist/languages/python-ast/index.js.map +1 -0
  159. package/dist/languages/python-ast/parser.d.ts +174 -0
  160. package/dist/languages/python-ast/parser.d.ts.map +1 -0
  161. package/dist/languages/python-ast/parser.js +1205 -0
  162. package/dist/languages/python-ast/parser.js.map +1 -0
  163. package/dist/languages/python-ast/type-resolver.d.ts +75 -0
  164. package/dist/languages/python-ast/type-resolver.d.ts.map +1 -0
  165. package/dist/languages/python-ast/type-resolver.js +421 -0
  166. package/dist/languages/python-ast/type-resolver.js.map +1 -0
  167. package/dist/languages/python-ast/types.d.ts +216 -0
  168. package/dist/languages/python-ast/types.d.ts.map +1 -0
  169. package/dist/languages/python-ast/types.js +6 -0
  170. package/dist/languages/python-ast/types.js.map +1 -0
  171. package/dist/languages/python.d.ts +55 -0
  172. package/dist/languages/python.d.ts.map +1 -0
  173. package/dist/languages/python.js +311 -0
  174. package/dist/languages/python.js.map +1 -0
  175. package/dist/languages/typescript.d.ts +272 -0
  176. package/dist/languages/typescript.d.ts.map +1 -0
  177. package/dist/languages/typescript.js +1381 -0
  178. package/dist/languages/typescript.js.map +1 -0
  179. package/dist/patterns/base.d.ts +146 -0
  180. package/dist/patterns/base.d.ts.map +1 -0
  181. package/dist/patterns/base.js +89 -0
  182. package/dist/patterns/base.js.map +1 -0
  183. package/dist/patterns/errors.d.ts +172 -0
  184. package/dist/patterns/errors.d.ts.map +1 -0
  185. package/dist/patterns/errors.js +185 -0
  186. package/dist/patterns/errors.js.map +1 -0
  187. package/dist/patterns/extractors.d.ts +170 -0
  188. package/dist/patterns/extractors.d.ts.map +1 -0
  189. package/dist/patterns/extractors.js +305 -0
  190. package/dist/patterns/extractors.js.map +1 -0
  191. package/dist/patterns/graphql/apollo-client.d.ts +80 -0
  192. package/dist/patterns/graphql/apollo-client.d.ts.map +1 -0
  193. package/dist/patterns/graphql/apollo-client.js +800 -0
  194. package/dist/patterns/graphql/apollo-client.js.map +1 -0
  195. package/dist/patterns/graphql/apollo-server.d.ts +55 -0
  196. package/dist/patterns/graphql/apollo-server.d.ts.map +1 -0
  197. package/dist/patterns/graphql/apollo-server.js +523 -0
  198. package/dist/patterns/graphql/apollo-server.js.map +1 -0
  199. package/dist/patterns/graphql/index.d.ts +11 -0
  200. package/dist/patterns/graphql/index.d.ts.map +1 -0
  201. package/dist/patterns/graphql/index.js +12 -0
  202. package/dist/patterns/graphql/index.js.map +1 -0
  203. package/dist/patterns/graphql/types.d.ts +213 -0
  204. package/dist/patterns/graphql/types.d.ts.map +1 -0
  205. package/dist/patterns/graphql/types.js +16 -0
  206. package/dist/patterns/graphql/types.js.map +1 -0
  207. package/dist/patterns/http-clients/axios.d.ts +148 -0
  208. package/dist/patterns/http-clients/axios.d.ts.map +1 -0
  209. package/dist/patterns/http-clients/axios.js +652 -0
  210. package/dist/patterns/http-clients/axios.js.map +1 -0
  211. package/dist/patterns/http-clients/fetch.d.ts +88 -0
  212. package/dist/patterns/http-clients/fetch.d.ts.map +1 -0
  213. package/dist/patterns/http-clients/fetch.js +364 -0
  214. package/dist/patterns/http-clients/fetch.js.map +1 -0
  215. package/dist/patterns/http-clients/index.d.ts +36 -0
  216. package/dist/patterns/http-clients/index.d.ts.map +1 -0
  217. package/dist/patterns/http-clients/index.js +50 -0
  218. package/dist/patterns/http-clients/index.js.map +1 -0
  219. package/dist/patterns/http-clients/property-access.d.ts +46 -0
  220. package/dist/patterns/http-clients/property-access.d.ts.map +1 -0
  221. package/dist/patterns/http-clients/property-access.js +818 -0
  222. package/dist/patterns/http-clients/property-access.js.map +1 -0
  223. package/dist/patterns/http-clients/type-inference.d.ts +48 -0
  224. package/dist/patterns/http-clients/type-inference.d.ts.map +1 -0
  225. package/dist/patterns/http-clients/type-inference.js +293 -0
  226. package/dist/patterns/http-clients/type-inference.js.map +1 -0
  227. package/dist/patterns/http-clients/types.d.ts +168 -0
  228. package/dist/patterns/http-clients/types.d.ts.map +1 -0
  229. package/dist/patterns/http-clients/types.js +10 -0
  230. package/dist/patterns/http-clients/types.js.map +1 -0
  231. package/dist/patterns/http-clients/url-extractor.d.ts +53 -0
  232. package/dist/patterns/http-clients/url-extractor.d.ts.map +1 -0
  233. package/dist/patterns/http-clients/url-extractor.js +338 -0
  234. package/dist/patterns/http-clients/url-extractor.js.map +1 -0
  235. package/dist/patterns/index.d.ts +44 -0
  236. package/dist/patterns/index.d.ts.map +1 -0
  237. package/dist/patterns/index.js +49 -0
  238. package/dist/patterns/index.js.map +1 -0
  239. package/dist/patterns/python/aiohttp.d.ts +21 -0
  240. package/dist/patterns/python/aiohttp.d.ts.map +1 -0
  241. package/dist/patterns/python/aiohttp.js +188 -0
  242. package/dist/patterns/python/aiohttp.js.map +1 -0
  243. package/dist/patterns/python/httpx.d.ts +20 -0
  244. package/dist/patterns/python/httpx.d.ts.map +1 -0
  245. package/dist/patterns/python/httpx.js +183 -0
  246. package/dist/patterns/python/httpx.js.map +1 -0
  247. package/dist/patterns/python/index.d.ts +32 -0
  248. package/dist/patterns/python/index.d.ts.map +1 -0
  249. package/dist/patterns/python/index.js +63 -0
  250. package/dist/patterns/python/index.js.map +1 -0
  251. package/dist/patterns/python/property-access.d.ts +27 -0
  252. package/dist/patterns/python/property-access.d.ts.map +1 -0
  253. package/dist/patterns/python/property-access.js +132 -0
  254. package/dist/patterns/python/property-access.js.map +1 -0
  255. package/dist/patterns/python/requests.d.ts +19 -0
  256. package/dist/patterns/python/requests.d.ts.map +1 -0
  257. package/dist/patterns/python/requests.js +239 -0
  258. package/dist/patterns/python/requests.js.map +1 -0
  259. package/dist/patterns/python/types.d.ts +95 -0
  260. package/dist/patterns/python/types.d.ts.map +1 -0
  261. package/dist/patterns/python/types.js +43 -0
  262. package/dist/patterns/python/types.js.map +1 -0
  263. package/dist/patterns/registry.d.ts +181 -0
  264. package/dist/patterns/registry.d.ts.map +1 -0
  265. package/dist/patterns/registry.js +304 -0
  266. package/dist/patterns/registry.js.map +1 -0
  267. package/dist/patterns/rest/express.d.ts +78 -0
  268. package/dist/patterns/rest/express.d.ts.map +1 -0
  269. package/dist/patterns/rest/express.js +289 -0
  270. package/dist/patterns/rest/express.js.map +1 -0
  271. package/dist/patterns/rest/fastify.d.ts +93 -0
  272. package/dist/patterns/rest/fastify.d.ts.map +1 -0
  273. package/dist/patterns/rest/fastify.js +420 -0
  274. package/dist/patterns/rest/fastify.js.map +1 -0
  275. package/dist/patterns/rest/index.d.ts +31 -0
  276. package/dist/patterns/rest/index.d.ts.map +1 -0
  277. package/dist/patterns/rest/index.js +45 -0
  278. package/dist/patterns/rest/index.js.map +1 -0
  279. package/dist/patterns/rest/middleware.d.ts +25 -0
  280. package/dist/patterns/rest/middleware.d.ts.map +1 -0
  281. package/dist/patterns/rest/middleware.js +219 -0
  282. package/dist/patterns/rest/middleware.js.map +1 -0
  283. package/dist/patterns/rest/path-parser.d.ts +50 -0
  284. package/dist/patterns/rest/path-parser.d.ts.map +1 -0
  285. package/dist/patterns/rest/path-parser.js +137 -0
  286. package/dist/patterns/rest/path-parser.js.map +1 -0
  287. package/dist/patterns/rest/response-inference.d.ts +44 -0
  288. package/dist/patterns/rest/response-inference.d.ts.map +1 -0
  289. package/dist/patterns/rest/response-inference.js +218 -0
  290. package/dist/patterns/rest/response-inference.js.map +1 -0
  291. package/dist/patterns/rest/types.d.ts +102 -0
  292. package/dist/patterns/rest/types.d.ts.map +1 -0
  293. package/dist/patterns/rest/types.js +10 -0
  294. package/dist/patterns/rest/types.js.map +1 -0
  295. package/dist/patterns/types.d.ts +105 -0
  296. package/dist/patterns/types.d.ts.map +1 -0
  297. package/dist/patterns/types.js +11 -0
  298. package/dist/patterns/types.js.map +1 -0
  299. package/dist/report/index.d.ts +11 -0
  300. package/dist/report/index.d.ts.map +1 -0
  301. package/dist/report/index.js +55 -0
  302. package/dist/report/index.js.map +1 -0
  303. package/dist/tools/contract-comments.d.ts +48 -0
  304. package/dist/tools/contract-comments.d.ts.map +1 -0
  305. package/dist/tools/contract-comments.js +130 -0
  306. package/dist/tools/contract-comments.js.map +1 -0
  307. package/dist/tools/index.d.ts +6 -0
  308. package/dist/tools/index.d.ts.map +1 -0
  309. package/dist/tools/index.js +6 -0
  310. package/dist/tools/index.js.map +1 -0
  311. package/dist/tools/scaffold.d.ts +38 -0
  312. package/dist/tools/scaffold.d.ts.map +1 -0
  313. package/dist/tools/scaffold.js +373 -0
  314. package/dist/tools/scaffold.js.map +1 -0
  315. package/dist/trace/index.d.ts +28 -0
  316. package/dist/trace/index.d.ts.map +1 -0
  317. package/dist/trace/index.js +45 -0
  318. package/dist/trace/index.js.map +1 -0
  319. package/dist/types.d.ts +135 -0
  320. package/dist/types.d.ts.map +1 -0
  321. package/dist/types.js +22 -0
  322. package/dist/types.js.map +1 -0
  323. package/dist/watch/cache.d.ts +41 -0
  324. package/dist/watch/cache.d.ts.map +1 -0
  325. package/dist/watch/cache.js +230 -0
  326. package/dist/watch/cache.js.map +1 -0
  327. package/dist/watch/index.d.ts +9 -0
  328. package/dist/watch/index.d.ts.map +1 -0
  329. package/dist/watch/index.js +7 -0
  330. package/dist/watch/index.js.map +1 -0
  331. package/dist/watch/project.d.ts +128 -0
  332. package/dist/watch/project.d.ts.map +1 -0
  333. package/dist/watch/project.js +152 -0
  334. package/dist/watch/project.js.map +1 -0
  335. package/dist/watch/watcher.d.ts +76 -0
  336. package/dist/watch/watcher.d.ts.map +1 -0
  337. package/dist/watch/watcher.js +235 -0
  338. package/dist/watch/watcher.js.map +1 -0
  339. package/package.json +70 -0
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Pattern Matcher Errors
3
+ *
4
+ * Error types for pattern matching and extraction operations.
5
+ * Each error includes a machine-readable error code for programmatic handling.
6
+ *
7
+ * @module patterns/errors
8
+ * @see .context/ADR-P2-1-PATTERN-MATCHER.md
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * try {
13
+ * const matcher = getPattern('unknown-framework');
14
+ * } catch (error) {
15
+ * if (error instanceof PatternNotFoundError) {
16
+ * console.log(`Code: ${error.code}`); // PATTERN_NOT_FOUND
17
+ * console.log(`Available: ${error.available.join(', ')}`);
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ /**
23
+ * Error codes for pattern matcher errors.
24
+ * Use these codes for machine-readable error handling.
25
+ */
26
+ export const PatternErrorCodes = {
27
+ /** Base registry error */
28
+ REGISTRY_ERROR: 'PATTERN_REGISTRY_ERROR',
29
+ /** Pattern matcher not found in registry */
30
+ NOT_FOUND: 'PATTERN_NOT_FOUND',
31
+ /** Pattern matcher failed validation */
32
+ VALIDATION_FAILED: 'PATTERN_VALIDATION_FAILED',
33
+ /** Pattern matching operation failed */
34
+ MATCH_FAILED: 'PATTERN_MATCH_FAILED',
35
+ /** Schema extraction from pattern failed */
36
+ EXTRACTION_FAILED: 'PATTERN_EXTRACTION_FAILED',
37
+ };
38
+ /**
39
+ * Base error for pattern registry operations.
40
+ * All pattern-related errors extend this class.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * if (error instanceof PatternRegistryError) {
45
+ * console.log(`Pattern error: ${error.code}`);
46
+ * }
47
+ * ```
48
+ */
49
+ export class PatternRegistryError extends Error {
50
+ /** Machine-readable error code */
51
+ code = PatternErrorCodes.REGISTRY_ERROR;
52
+ constructor(message) {
53
+ super(message);
54
+ this.name = 'PatternRegistryError';
55
+ }
56
+ }
57
+ /**
58
+ * Thrown when a pattern matcher is not found in the registry.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * try {
63
+ * getPattern('express');
64
+ * } catch (e) {
65
+ * if (e instanceof PatternNotFoundError) {
66
+ * console.log(`'${e.framework}' not found. Try: ${e.available.join(', ')}`);
67
+ * }
68
+ * }
69
+ * ```
70
+ */
71
+ export class PatternNotFoundError extends PatternRegistryError {
72
+ framework;
73
+ available;
74
+ code = PatternErrorCodes.NOT_FOUND;
75
+ constructor(
76
+ /** The framework name that was requested */
77
+ framework,
78
+ /** List of available pattern matcher names */
79
+ available) {
80
+ const availableList = available.length > 0 ? available.join(', ') : 'none';
81
+ super(`Pattern matcher '${framework}' not found. Available matchers: ${availableList}`);
82
+ this.framework = framework;
83
+ this.available = available;
84
+ this.name = 'PatternNotFoundError';
85
+ }
86
+ }
87
+ /**
88
+ * Thrown when a pattern matcher fails validation during registration.
89
+ * This typically indicates a malformed matcher implementation.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * try {
94
+ * registerPattern(invalidMatcher);
95
+ * } catch (e) {
96
+ * if (e instanceof PatternValidationError) {
97
+ * console.error(`Validation failed: ${e.reason}`);
98
+ * }
99
+ * }
100
+ * ```
101
+ */
102
+ export class PatternValidationError extends PatternRegistryError {
103
+ matcher;
104
+ reason;
105
+ code = PatternErrorCodes.VALIDATION_FAILED;
106
+ constructor(
107
+ /** The matcher object that failed validation */
108
+ matcher,
109
+ /** Human-readable description of why validation failed */
110
+ reason) {
111
+ super(`Invalid pattern matcher: ${reason}`);
112
+ this.matcher = matcher;
113
+ this.reason = reason;
114
+ this.name = 'PatternValidationError';
115
+ }
116
+ }
117
+ /**
118
+ * Thrown when pattern matching fails during AST analysis.
119
+ * This can occur when the AST structure doesn't match expectations.
120
+ *
121
+ * @example
122
+ * ```typescript
123
+ * try {
124
+ * matcher.match(node);
125
+ * } catch (e) {
126
+ * if (e instanceof PatternMatchError) {
127
+ * console.error(`Match failed in ${e.matcher}: ${e.reason}`);
128
+ * }
129
+ * }
130
+ * ```
131
+ */
132
+ export class PatternMatchError extends PatternRegistryError {
133
+ matcher;
134
+ nodeSummary;
135
+ reason;
136
+ code = PatternErrorCodes.MATCH_FAILED;
137
+ constructor(
138
+ /** Name of the matcher that failed */
139
+ matcher,
140
+ /** Summary of the AST node being matched */
141
+ nodeSummary,
142
+ /** Human-readable description of why matching failed */
143
+ reason) {
144
+ super(`Pattern match failed in '${matcher}' for ${nodeSummary}: ${reason}`);
145
+ this.matcher = matcher;
146
+ this.nodeSummary = nodeSummary;
147
+ this.reason = reason;
148
+ this.name = 'PatternMatchError';
149
+ }
150
+ }
151
+ /**
152
+ * Thrown when schema extraction fails from a matched pattern.
153
+ * This occurs when the schema location cannot be resolved.
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * try {
158
+ * const schema = await matcher.extract(match);
159
+ * } catch (e) {
160
+ * if (e instanceof PatternExtractionError) {
161
+ * console.error(`Cannot extract from ${e.schemaLocation.type}`);
162
+ * }
163
+ * }
164
+ * ```
165
+ */
166
+ export class PatternExtractionError extends PatternRegistryError {
167
+ match;
168
+ schemaLocation;
169
+ reason;
170
+ code = PatternErrorCodes.EXTRACTION_FAILED;
171
+ constructor(
172
+ /** The match result that extraction was attempted on */
173
+ match,
174
+ /** The schema location that could not be resolved */
175
+ schemaLocation,
176
+ /** Human-readable description of why extraction failed */
177
+ reason) {
178
+ super(`Schema extraction failed for '${match.identifier}' at ${schemaLocation.type}: ${reason}`);
179
+ this.match = match;
180
+ this.schemaLocation = schemaLocation;
181
+ this.reason = reason;
182
+ this.name = 'PatternExtractionError';
183
+ }
184
+ }
185
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/patterns/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,0BAA0B;IAC1B,cAAc,EAAE,wBAAwB;IACxC,4CAA4C;IAC5C,SAAS,EAAE,mBAAmB;IAC9B,wCAAwC;IACxC,iBAAiB,EAAE,2BAA2B;IAC9C,wCAAwC;IACxC,YAAY,EAAE,sBAAsB;IACpC,4CAA4C;IAC5C,iBAAiB,EAAE,2BAA2B;CACtC,CAAC;AA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AC,YAAY,CAAC;IAExD;IACE,sCAAsC;IACtB,OAAe;IAC/B,4CAA4C;IAC5B,WAAmB;IACnC,wDAAwD;IACxC,MAAc;QAE9B,KAAK,CAAC,4BAA4B,OAAO,SAAS,WAAW,KAAK,MAAM,EAAE,CAAC,CAAC;QAN5D,YAAO,GAAP,OAAO,CAAQ;QAEf,gBAAW,GAAX,WAAW,CAAQ;QAEnB,WAAM,GAAN,MAAM,CAAQ;QAG9B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IAClC,CAAC;CACF;AAED;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,sBAAuB,SAAQ,oBAAoB;IAK5C;IAEA;IAEA;IARA,IAAI,GAAG,iBAAiB,CAAC,iBAAiB,CAAC;IAE7D;IACE,wDAAwD;IACxC,KAAkB;IAClC,qDAAqD;IACrC,cAA8B;IAC9C,0DAA0D;IAC1C,MAAc;QAE9B,KAAK,CACH,iCAAiC,KAAK,CAAC,UAAU,QAAQ,cAAc,CAAC,IAAI,KAAK,MAAM,EAAE,CAC1F,CAAC;QARc,UAAK,GAAL,KAAK,CAAa;QAElB,mBAAc,GAAd,cAAc,CAAgB;QAE9B,WAAM,GAAN,MAAM,CAAQ;QAK9B,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,170 @@
1
+ /**
2
+ * Schema Extractors
3
+ *
4
+ * Utilities for extracting schema nodes based on {@link SchemaLocation} specifications.
5
+ * These functions navigate AST structures to locate schema definitions in various
6
+ * positions (arguments, return types, method chains, decorators, etc.).
7
+ *
8
+ * @module patterns/extractors
9
+ * @see .context/ADR-P2-1-PATTERN-MATCHER.md
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { extractSchemaNode } from './patterns';
14
+ *
15
+ * const schemaNode = extractSchemaNode(match, { type: 'arg', index: 0 });
16
+ * if (schemaNode) {
17
+ * // Process the schema node
18
+ * }
19
+ * ```
20
+ */
21
+ import { Node } from 'ts-morph';
22
+ import type { SchemaLocation, MatchResult } from './types.js';
23
+ /**
24
+ * Extract a schema AST node from a pattern match based on location specification.
25
+ *
26
+ * This is the primary entry point for schema extraction. It dispatches to
27
+ * specialized extractors based on the {@link SchemaLocation} type.
28
+ *
29
+ * @param match - The pattern match result containing the matched AST node
30
+ * @param location - Specification of where to find the schema in the AST
31
+ * @returns The schema AST node, or `null` if not found at the specified location
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * // Extract first argument from a call expression
36
+ * const inputSchema = extractSchemaNode(match, { type: 'arg', index: 0 });
37
+ *
38
+ * // Extract from method chain like .input(schema)
39
+ * const chainSchema = extractSchemaNode(match, {
40
+ * type: 'chain-method',
41
+ * method: 'input'
42
+ * });
43
+ * ```
44
+ */
45
+ export declare function extractSchemaNode(match: MatchResult, location: SchemaLocation): Node | null;
46
+ /**
47
+ * Extract a positional argument from a call expression.
48
+ *
49
+ * @param node - The call expression node
50
+ * @param index - Zero-based index of the argument to extract
51
+ * @returns The argument node at the specified index, or `null` if not found
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * // For: app.get('/users', schema, handler)
56
+ * const routePath = extractFromArg(callNode, 0); // '/users'
57
+ * const schema = extractFromArg(callNode, 1); // schema
58
+ * ```
59
+ */
60
+ export declare function extractFromArg(node: Node, index: number): Node | null;
61
+ /**
62
+ * Extract a named property from an options object argument.
63
+ *
64
+ * Searches through all object literal arguments to find a property
65
+ * with the specified name.
66
+ *
67
+ * @param node - The call expression node
68
+ * @param name - Name of the property to find
69
+ * @returns The property's initializer node, or `null` if not found
70
+ *
71
+ * @example
72
+ * ```typescript
73
+ * // For: server.tool({ schema: z.object({...}), handler })
74
+ * const schemaNode = extractFromNamedArg(callNode, 'schema');
75
+ * ```
76
+ */
77
+ export declare function extractFromNamedArg(node: Node, name: string): Node | null;
78
+ /**
79
+ * Extract return type annotation from an enclosing function.
80
+ *
81
+ * Walks up the AST to find the nearest function declaration,
82
+ * method declaration, or arrow function, then extracts its return type.
83
+ *
84
+ * @param node - A node within a function body
85
+ * @returns The return type node, or `null` if no explicit return type
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // For: function getUser(): UserSchema { ... }
90
+ * const returnType = extractFromReturn(bodyNode); // UserSchema
91
+ * ```
92
+ */
93
+ export declare function extractFromReturn(node: Node): Node | null;
94
+ /**
95
+ * Extract a generic type parameter at a specified index.
96
+ *
97
+ * Works with both type references (`Foo<T, U>`) and call expressions
98
+ * with type arguments (`foo<T>()`).
99
+ *
100
+ * @param node - A type reference or call expression node
101
+ * @param index - Zero-based index of the type argument
102
+ * @returns The type argument node, or `null` if not found
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * // For: Response<UserSchema, ErrorSchema>
107
+ * const successType = extractFromTypeParam(typeRef, 0); // UserSchema
108
+ * const errorType = extractFromTypeParam(typeRef, 1); // ErrorSchema
109
+ * ```
110
+ */
111
+ export declare function extractFromTypeParam(node: Node, index: number): Node | null;
112
+ /**
113
+ * Extract schema from function body or variable initializer.
114
+ *
115
+ * For functions: finds return statements and extracts the returned expression.
116
+ * For arrow functions: returns the expression body directly.
117
+ * For variable declarations: returns the initializer.
118
+ *
119
+ * @param node - A function-like node or variable declaration
120
+ * @returns The inferred schema node, or `null` if not found
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // For: const schema = z.object({ name: z.string() })
125
+ * const schemaValue = extractFromBody(varDecl); // z.object(...)
126
+ *
127
+ * // For: const handler = () => z.object({})
128
+ * const returnValue = extractFromBody(arrowFn); // z.object({})
129
+ * ```
130
+ */
131
+ export declare function extractFromBody(node: Node): Node | null;
132
+ /**
133
+ * Extract schema from a method in a call chain.
134
+ *
135
+ * Traverses a method chain (like tRPC's fluent API) to find a specific
136
+ * method call and extract its first argument.
137
+ *
138
+ * @param node - The call expression representing the chain
139
+ * @param methodName - Name of the method to find (e.g., 'input', 'output')
140
+ * @returns The first argument of the method, or `null` if not found
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * // For: t.procedure.input(userSchema).query(...)
145
+ * const inputSchema = extractFromChainMethod(callNode, 'input');
146
+ *
147
+ * // For: router.route().output(responseSchema).get()
148
+ * const outputSchema = extractFromChainMethod(callNode, 'output');
149
+ * ```
150
+ */
151
+ export declare function extractFromChainMethod(node: Node, methodName: string): Node | null;
152
+ /**
153
+ * Extract an argument from a decorator's call expression.
154
+ *
155
+ * @param node - The decorator node
156
+ * @param index - Zero-based index of the argument
157
+ * @returns The argument node, or `null` if not found
158
+ *
159
+ * @example
160
+ * ```typescript
161
+ * // For: @Body(validationSchema)
162
+ * const schema = extractFromDecoratorArg(decoratorNode, 0);
163
+ *
164
+ * // For: @Param('id', ParseIntPipe)
165
+ * const paramName = extractFromDecoratorArg(decoratorNode, 0); // 'id'
166
+ * const pipe = extractFromDecoratorArg(decoratorNode, 1); // ParseIntPipe
167
+ * ```
168
+ */
169
+ export declare function extractFromDecoratorArg(node: Node, index: number): Node | null;
170
+ //# sourceMappingURL=extractors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractors.d.ts","sourceRoot":"","sources":["../../src/patterns/extractors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAc,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,WAAW,EAClB,QAAQ,EAAE,cAAc,GACvB,IAAI,GAAG,IAAI,CAiCb;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAIrE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAczE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAczD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAc3E;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CA0BvD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAmClF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAQ9E"}
@@ -0,0 +1,305 @@
1
+ /**
2
+ * Schema Extractors
3
+ *
4
+ * Utilities for extracting schema nodes based on {@link SchemaLocation} specifications.
5
+ * These functions navigate AST structures to locate schema definitions in various
6
+ * positions (arguments, return types, method chains, decorators, etc.).
7
+ *
8
+ * @module patterns/extractors
9
+ * @see .context/ADR-P2-1-PATTERN-MATCHER.md
10
+ *
11
+ * @example
12
+ * ```typescript
13
+ * import { extractSchemaNode } from './patterns';
14
+ *
15
+ * const schemaNode = extractSchemaNode(match, { type: 'arg', index: 0 });
16
+ * if (schemaNode) {
17
+ * // Process the schema node
18
+ * }
19
+ * ```
20
+ */
21
+ import { Node, SyntaxKind } from 'ts-morph';
22
+ /**
23
+ * Extract a schema AST node from a pattern match based on location specification.
24
+ *
25
+ * This is the primary entry point for schema extraction. It dispatches to
26
+ * specialized extractors based on the {@link SchemaLocation} type.
27
+ *
28
+ * @param match - The pattern match result containing the matched AST node
29
+ * @param location - Specification of where to find the schema in the AST
30
+ * @returns The schema AST node, or `null` if not found at the specified location
31
+ *
32
+ * @example
33
+ * ```typescript
34
+ * // Extract first argument from a call expression
35
+ * const inputSchema = extractSchemaNode(match, { type: 'arg', index: 0 });
36
+ *
37
+ * // Extract from method chain like .input(schema)
38
+ * const chainSchema = extractSchemaNode(match, {
39
+ * type: 'chain-method',
40
+ * method: 'input'
41
+ * });
42
+ * ```
43
+ */
44
+ export function extractSchemaNode(match, location) {
45
+ const { node, captures } = match;
46
+ switch (location.type) {
47
+ case 'arg':
48
+ return extractFromArg(node, location.index);
49
+ case 'arg-named':
50
+ return extractFromNamedArg(node, location.name);
51
+ case 'return':
52
+ return extractFromReturn(node);
53
+ case 'type-param':
54
+ return extractFromTypeParam(node, location.index);
55
+ case 'body':
56
+ return extractFromBody(node);
57
+ case 'chain-method':
58
+ // Check if already captured during matching
59
+ const capturedNode = captures[`${location.method}SchemaNode`];
60
+ if (capturedNode && Node.isNode(capturedNode)) {
61
+ return capturedNode;
62
+ }
63
+ return extractFromChainMethod(node, location.method);
64
+ case 'decorator-arg':
65
+ return extractFromDecoratorArg(node, location.index);
66
+ default:
67
+ return null;
68
+ }
69
+ }
70
+ // ─────────────────────────────────────────────────────────────────────────────
71
+ // Individual Extractor Functions
72
+ // ─────────────────────────────────────────────────────────────────────────────
73
+ /**
74
+ * Extract a positional argument from a call expression.
75
+ *
76
+ * @param node - The call expression node
77
+ * @param index - Zero-based index of the argument to extract
78
+ * @returns The argument node at the specified index, or `null` if not found
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // For: app.get('/users', schema, handler)
83
+ * const routePath = extractFromArg(callNode, 0); // '/users'
84
+ * const schema = extractFromArg(callNode, 1); // schema
85
+ * ```
86
+ */
87
+ export function extractFromArg(node, index) {
88
+ if (!Node.isCallExpression(node))
89
+ return null;
90
+ const args = node.getArguments();
91
+ return args[index] ?? null;
92
+ }
93
+ /**
94
+ * Extract a named property from an options object argument.
95
+ *
96
+ * Searches through all object literal arguments to find a property
97
+ * with the specified name.
98
+ *
99
+ * @param node - The call expression node
100
+ * @param name - Name of the property to find
101
+ * @returns The property's initializer node, or `null` if not found
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * // For: server.tool({ schema: z.object({...}), handler })
106
+ * const schemaNode = extractFromNamedArg(callNode, 'schema');
107
+ * ```
108
+ */
109
+ export function extractFromNamedArg(node, name) {
110
+ if (!Node.isCallExpression(node))
111
+ return null;
112
+ const args = node.getArguments();
113
+ for (const arg of args) {
114
+ if (Node.isObjectLiteralExpression(arg)) {
115
+ for (const prop of arg.getProperties()) {
116
+ if (Node.isPropertyAssignment(prop) && prop.getName() === name) {
117
+ return prop.getInitializer() ?? null;
118
+ }
119
+ }
120
+ }
121
+ }
122
+ return null;
123
+ }
124
+ /**
125
+ * Extract return type annotation from an enclosing function.
126
+ *
127
+ * Walks up the AST to find the nearest function declaration,
128
+ * method declaration, or arrow function, then extracts its return type.
129
+ *
130
+ * @param node - A node within a function body
131
+ * @returns The return type node, or `null` if no explicit return type
132
+ *
133
+ * @example
134
+ * ```typescript
135
+ * // For: function getUser(): UserSchema { ... }
136
+ * const returnType = extractFromReturn(bodyNode); // UserSchema
137
+ * ```
138
+ */
139
+ export function extractFromReturn(node) {
140
+ // Walk up to find function declaration
141
+ const func = node.getFirstAncestorByKind(SyntaxKind.FunctionDeclaration)
142
+ ?? node.getFirstAncestorByKind(SyntaxKind.MethodDeclaration)
143
+ ?? node.getFirstAncestorByKind(SyntaxKind.ArrowFunction);
144
+ if (!func)
145
+ return null;
146
+ // Check if the node has getReturnTypeNode method
147
+ if ('getReturnTypeNode' in func && typeof func.getReturnTypeNode === 'function') {
148
+ return func.getReturnTypeNode() ?? null;
149
+ }
150
+ return null;
151
+ }
152
+ /**
153
+ * Extract a generic type parameter at a specified index.
154
+ *
155
+ * Works with both type references (`Foo<T, U>`) and call expressions
156
+ * with type arguments (`foo<T>()`).
157
+ *
158
+ * @param node - A type reference or call expression node
159
+ * @param index - Zero-based index of the type argument
160
+ * @returns The type argument node, or `null` if not found
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * // For: Response<UserSchema, ErrorSchema>
165
+ * const successType = extractFromTypeParam(typeRef, 0); // UserSchema
166
+ * const errorType = extractFromTypeParam(typeRef, 1); // ErrorSchema
167
+ * ```
168
+ */
169
+ export function extractFromTypeParam(node, index) {
170
+ // Handle type references with type arguments
171
+ if (Node.isTypeReference(node)) {
172
+ const typeArgs = node.getTypeArguments();
173
+ return typeArgs[index] ?? null;
174
+ }
175
+ // Handle call expressions with type arguments
176
+ if (Node.isCallExpression(node)) {
177
+ const typeArgs = node.getTypeArguments();
178
+ return typeArgs[index] ?? null;
179
+ }
180
+ return null;
181
+ }
182
+ /**
183
+ * Extract schema from function body or variable initializer.
184
+ *
185
+ * For functions: finds return statements and extracts the returned expression.
186
+ * For arrow functions: returns the expression body directly.
187
+ * For variable declarations: returns the initializer.
188
+ *
189
+ * @param node - A function-like node or variable declaration
190
+ * @returns The inferred schema node, or `null` if not found
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * // For: const schema = z.object({ name: z.string() })
195
+ * const schemaValue = extractFromBody(varDecl); // z.object(...)
196
+ *
197
+ * // For: const handler = () => z.object({})
198
+ * const returnValue = extractFromBody(arrowFn); // z.object({})
199
+ * ```
200
+ */
201
+ export function extractFromBody(node) {
202
+ // If node is a function-like, get its body
203
+ let body;
204
+ if (Node.isFunctionDeclaration(node) || Node.isMethodDeclaration(node)) {
205
+ body = node.getBody();
206
+ }
207
+ else if (Node.isArrowFunction(node)) {
208
+ body = node.getBody();
209
+ }
210
+ else if (Node.isVariableDeclaration(node)) {
211
+ // For variable declarations like `const schema = z.object(...)`
212
+ const initializer = node.getInitializer();
213
+ return initializer ?? null;
214
+ }
215
+ if (!body)
216
+ return node;
217
+ // If body is a block, find return statement
218
+ if (Node.isBlock(body)) {
219
+ const returnStmt = body.getFirstDescendantByKind(SyntaxKind.ReturnStatement);
220
+ if (returnStmt) {
221
+ return returnStmt.getExpression() ?? null;
222
+ }
223
+ }
224
+ // If body is an expression (arrow function), return it directly
225
+ return body;
226
+ }
227
+ /**
228
+ * Extract schema from a method in a call chain.
229
+ *
230
+ * Traverses a method chain (like tRPC's fluent API) to find a specific
231
+ * method call and extract its first argument.
232
+ *
233
+ * @param node - The call expression representing the chain
234
+ * @param methodName - Name of the method to find (e.g., 'input', 'output')
235
+ * @returns The first argument of the method, or `null` if not found
236
+ *
237
+ * @example
238
+ * ```typescript
239
+ * // For: t.procedure.input(userSchema).query(...)
240
+ * const inputSchema = extractFromChainMethod(callNode, 'input');
241
+ *
242
+ * // For: router.route().output(responseSchema).get()
243
+ * const outputSchema = extractFromChainMethod(callNode, 'output');
244
+ * ```
245
+ */
246
+ export function extractFromChainMethod(node, methodName) {
247
+ if (!Node.isCallExpression(node))
248
+ return null;
249
+ // Walk up the call chain to find the method
250
+ let current = node;
251
+ while (current) {
252
+ if (Node.isCallExpression(current)) {
253
+ const expr = current.getExpression();
254
+ if (Node.isPropertyAccessExpression(expr)) {
255
+ const name = expr.getName();
256
+ if (name === methodName) {
257
+ // Found the method, return its first argument
258
+ const args = current.getArguments();
259
+ return args[0] ?? null;
260
+ }
261
+ // Move to the receiver
262
+ current = expr.getExpression();
263
+ continue;
264
+ }
265
+ }
266
+ break;
267
+ }
268
+ // Also check children (for cases where node is the start of chain)
269
+ const descendants = node.getDescendantsOfKind(SyntaxKind.CallExpression);
270
+ for (const desc of descendants) {
271
+ const expr = desc.getExpression();
272
+ if (Node.isPropertyAccessExpression(expr) && expr.getName() === methodName) {
273
+ const args = desc.getArguments();
274
+ return args[0] ?? null;
275
+ }
276
+ }
277
+ return null;
278
+ }
279
+ /**
280
+ * Extract an argument from a decorator's call expression.
281
+ *
282
+ * @param node - The decorator node
283
+ * @param index - Zero-based index of the argument
284
+ * @returns The argument node, or `null` if not found
285
+ *
286
+ * @example
287
+ * ```typescript
288
+ * // For: @Body(validationSchema)
289
+ * const schema = extractFromDecoratorArg(decoratorNode, 0);
290
+ *
291
+ * // For: @Param('id', ParseIntPipe)
292
+ * const paramName = extractFromDecoratorArg(decoratorNode, 0); // 'id'
293
+ * const pipe = extractFromDecoratorArg(decoratorNode, 1); // ParseIntPipe
294
+ * ```
295
+ */
296
+ export function extractFromDecoratorArg(node, index) {
297
+ if (!Node.isDecorator(node))
298
+ return null;
299
+ const callExpr = node.getCallExpression();
300
+ if (!callExpr)
301
+ return null;
302
+ const args = callExpr.getArguments();
303
+ return args[index] ?? null;
304
+ }
305
+ //# sourceMappingURL=extractors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractors.js","sourceRoot":"","sources":["../../src/patterns/extractors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAG5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,iBAAiB,CAC/B,KAAkB,EAClB,QAAwB;IAExB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IAEjC,QAAQ,QAAQ,CAAC,IAAI,EAAE,CAAC;QACtB,KAAK,KAAK;YACR,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAE9C,KAAK,WAAW;YACd,OAAO,mBAAmB,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;QAElD,KAAK,QAAQ;YACX,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC;QAEjC,KAAK,YAAY;YACf,OAAO,oBAAoB,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEpD,KAAK,MAAM;YACT,OAAO,eAAe,CAAC,IAAI,CAAC,CAAC;QAE/B,KAAK,cAAc;YACjB,4CAA4C;YAC5C,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,MAAM,YAAY,CAAC,CAAC;YAC9D,IAAI,YAAY,IAAI,IAAI,CAAC,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