@fougere/core 0.2.0-alpha.2 → 0.4.0-alpha.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 (500) hide show
  1. package/README.md +3 -2
  2. package/dist/boot/AppLifecycle.d.ts +18 -0
  3. package/dist/boot/AppLifecycle.d.ts.map +1 -0
  4. package/dist/boot/AppLifecycle.js +42 -0
  5. package/dist/boot/AppLifecycle.js.map +1 -0
  6. package/dist/boot/Emissions.d.ts +126 -0
  7. package/dist/boot/Emissions.d.ts.map +1 -0
  8. package/dist/boot/Emissions.js +233 -0
  9. package/dist/boot/Emissions.js.map +1 -0
  10. package/dist/boot/HandlerFacade.d.ts +72 -0
  11. package/dist/boot/HandlerFacade.d.ts.map +1 -0
  12. package/dist/boot/HandlerFacade.js +174 -0
  13. package/dist/boot/HandlerFacade.js.map +1 -0
  14. package/dist/boot/Lifecycle.d.ts +4 -0
  15. package/dist/boot/Lifecycle.d.ts.map +1 -0
  16. package/dist/boot/Lifecycle.js +3 -0
  17. package/dist/boot/Lifecycle.js.map +1 -0
  18. package/dist/boot/ambient-port.d.ts +38 -0
  19. package/dist/boot/ambient-port.d.ts.map +1 -0
  20. package/dist/boot/ambient-port.js +2 -0
  21. package/dist/boot/ambient-port.js.map +1 -0
  22. package/dist/boot/ambient.als.d.ts +3 -0
  23. package/dist/boot/ambient.als.d.ts.map +1 -0
  24. package/dist/boot/ambient.als.js +34 -0
  25. package/dist/boot/ambient.als.js.map +1 -0
  26. package/dist/boot/ambient.queue.d.ts +10 -0
  27. package/dist/boot/ambient.queue.d.ts.map +1 -0
  28. package/dist/boot/ambient.queue.js +60 -0
  29. package/dist/boot/ambient.queue.js.map +1 -0
  30. package/dist/boot/apply.d.ts +22 -0
  31. package/dist/boot/apply.d.ts.map +1 -0
  32. package/dist/boot/apply.js +38 -0
  33. package/dist/boot/apply.js.map +1 -0
  34. package/dist/boot/auth.d.ts +53 -0
  35. package/dist/boot/auth.d.ts.map +1 -0
  36. package/dist/boot/auth.js +2 -0
  37. package/dist/boot/auth.js.map +1 -0
  38. package/dist/{binding.d.ts → boot/binding.d.ts} +14 -17
  39. package/dist/boot/binding.d.ts.map +1 -0
  40. package/dist/{binding.js → boot/binding.js} +19 -10
  41. package/dist/boot/binding.js.map +1 -0
  42. package/dist/{boot.d.ts → boot/boot.d.ts} +25 -5
  43. package/dist/boot/boot.d.ts.map +1 -0
  44. package/dist/boot/boot.js +70 -0
  45. package/dist/boot/boot.js.map +1 -0
  46. package/dist/boot/bootstrap.d.ts.map +1 -0
  47. package/dist/boot/bootstrap.js +722 -0
  48. package/dist/boot/bootstrap.js.map +1 -0
  49. package/dist/boot/frame.d.ts +44 -0
  50. package/dist/boot/frame.d.ts.map +1 -0
  51. package/dist/boot/frame.js +172 -0
  52. package/dist/boot/frame.js.map +1 -0
  53. package/dist/boot/ownership.d.ts +42 -0
  54. package/dist/boot/ownership.d.ts.map +1 -0
  55. package/dist/boot/ownership.js +127 -0
  56. package/dist/boot/ownership.js.map +1 -0
  57. package/dist/boot/ports.d.ts +17 -0
  58. package/dist/boot/ports.d.ts.map +1 -0
  59. package/dist/boot/ports.js +57 -0
  60. package/dist/boot/ports.js.map +1 -0
  61. package/dist/{remote.d.ts → boot/remote.d.ts} +11 -3
  62. package/dist/boot/remote.d.ts.map +1 -0
  63. package/dist/{remote.js → boot/remote.js} +26 -28
  64. package/dist/boot/remote.js.map +1 -0
  65. package/dist/{seed.d.ts → boot/seed.d.ts} +13 -1
  66. package/dist/boot/seed.d.ts.map +1 -0
  67. package/dist/{seed.js → boot/seed.js} +24 -3
  68. package/dist/boot/seed.js.map +1 -0
  69. package/dist/boot/together.d.ts +26 -0
  70. package/dist/boot/together.d.ts.map +1 -0
  71. package/dist/boot/together.js +163 -0
  72. package/dist/boot/together.js.map +1 -0
  73. package/dist/boot/types.d.ts +260 -0
  74. package/dist/boot/types.d.ts.map +1 -0
  75. package/dist/boot/types.js.map +1 -0
  76. package/dist/builtins/config.d.ts +9 -0
  77. package/dist/builtins/config.d.ts.map +1 -1
  78. package/dist/builtins/config.js +16 -1
  79. package/dist/builtins/config.js.map +1 -1
  80. package/dist/builtins/logger.d.ts +37 -4
  81. package/dist/builtins/logger.d.ts.map +1 -1
  82. package/dist/builtins/logger.js +66 -7
  83. package/dist/builtins/logger.js.map +1 -1
  84. package/dist/config-loader.d.ts +39 -35
  85. package/dist/config-loader.d.ts.map +1 -1
  86. package/dist/config-loader.js +15 -54
  87. package/dist/config-loader.js.map +1 -1
  88. package/dist/contract/Call.d.ts +10 -0
  89. package/dist/contract/Call.d.ts.map +1 -0
  90. package/dist/contract/Call.js +15 -0
  91. package/dist/contract/Call.js.map +1 -0
  92. package/dist/contract/Invocation.d.ts +27 -0
  93. package/dist/contract/Invocation.d.ts.map +1 -0
  94. package/dist/contract/Invocation.js +59 -0
  95. package/dist/contract/Invocation.js.map +1 -0
  96. package/dist/contract/RouteAddress.d.ts +17 -0
  97. package/dist/contract/RouteAddress.d.ts.map +1 -0
  98. package/dist/contract/RouteAddress.js +38 -0
  99. package/dist/contract/RouteAddress.js.map +1 -0
  100. package/dist/contract.d.ts +25 -19
  101. package/dist/contract.d.ts.map +1 -1
  102. package/dist/contract.js +25 -10
  103. package/dist/contract.js.map +1 -1
  104. package/dist/crypto/encoding.d.ts +25 -0
  105. package/dist/crypto/encoding.d.ts.map +1 -0
  106. package/dist/crypto/encoding.js +58 -0
  107. package/dist/crypto/encoding.js.map +1 -0
  108. package/dist/crypto/node.d.ts +4 -0
  109. package/dist/crypto/node.d.ts.map +1 -0
  110. package/dist/crypto/node.js +25 -0
  111. package/dist/crypto/node.js.map +1 -0
  112. package/dist/crypto/port.d.ts +42 -0
  113. package/dist/crypto/port.d.ts.map +1 -0
  114. package/dist/crypto/port.js +19 -0
  115. package/dist/crypto/port.js.map +1 -0
  116. package/dist/crypto/webcrypto.d.ts +4 -0
  117. package/dist/crypto/webcrypto.d.ts.map +1 -0
  118. package/dist/crypto/webcrypto.js +34 -0
  119. package/dist/crypto/webcrypto.js.map +1 -0
  120. package/dist/dispatch/ArgumentResolver.d.ts +10 -0
  121. package/dist/dispatch/ArgumentResolver.d.ts.map +1 -0
  122. package/dist/dispatch/ArgumentResolver.js +12 -0
  123. package/dist/dispatch/ArgumentResolver.js.map +1 -0
  124. package/dist/dispatch/ArrayResult.d.ts +3 -0
  125. package/dist/dispatch/ArrayResult.d.ts.map +1 -0
  126. package/dist/dispatch/ArrayResult.js +11 -0
  127. package/dist/dispatch/ArrayResult.js.map +1 -0
  128. package/dist/dispatch/DispatchEvent.d.ts +18 -0
  129. package/dist/dispatch/DispatchEvent.d.ts.map +1 -0
  130. package/dist/dispatch/DispatchEvent.js +30 -0
  131. package/dist/dispatch/DispatchEvent.js.map +1 -0
  132. package/dist/dispatch/DispatchLifecycle.d.ts +9 -0
  133. package/dist/dispatch/DispatchLifecycle.d.ts.map +1 -0
  134. package/dist/dispatch/DispatchLifecycle.js +25 -0
  135. package/dist/dispatch/DispatchLifecycle.js.map +1 -0
  136. package/dist/dispatch/DispatchPort.d.ts +6 -0
  137. package/dist/dispatch/DispatchPort.d.ts.map +1 -0
  138. package/dist/dispatch/DispatchPort.js +2 -0
  139. package/dist/dispatch/DispatchPort.js.map +1 -0
  140. package/dist/dispatch/Dispatcher.d.ts +16 -0
  141. package/dist/dispatch/Dispatcher.d.ts.map +1 -0
  142. package/dist/dispatch/Dispatcher.js +44 -0
  143. package/dist/dispatch/Dispatcher.js.map +1 -0
  144. package/dist/dispatch/InFlight.d.ts +12 -0
  145. package/dist/dispatch/InFlight.d.ts.map +1 -0
  146. package/dist/dispatch/InFlight.js +46 -0
  147. package/dist/dispatch/InFlight.js.map +1 -0
  148. package/dist/dispatch/InputValidator.d.ts +7 -0
  149. package/dist/dispatch/InputValidator.d.ts.map +1 -0
  150. package/dist/dispatch/InputValidator.js +22 -0
  151. package/dist/dispatch/InputValidator.js.map +1 -0
  152. package/dist/dispatch/LocalRoutePolicy.d.ts +11 -0
  153. package/dist/dispatch/LocalRoutePolicy.d.ts.map +1 -0
  154. package/dist/dispatch/LocalRoutePolicy.js +32 -0
  155. package/dist/dispatch/LocalRoutePolicy.js.map +1 -0
  156. package/dist/dispatch/OperationExecutor.d.ts +25 -0
  157. package/dist/dispatch/OperationExecutor.d.ts.map +1 -0
  158. package/dist/dispatch/OperationExecutor.js +32 -0
  159. package/dist/dispatch/OperationExecutor.js.map +1 -0
  160. package/dist/dispatch/OperationRoute.d.ts +13 -0
  161. package/dist/dispatch/OperationRoute.d.ts.map +1 -0
  162. package/dist/dispatch/OperationRoute.js +15 -0
  163. package/dist/dispatch/OperationRoute.js.map +1 -0
  164. package/dist/dispatch/OutputProjector.d.ts +12 -0
  165. package/dist/dispatch/OutputProjector.d.ts.map +1 -0
  166. package/dist/dispatch/OutputProjector.js +30 -0
  167. package/dist/dispatch/OutputProjector.js.map +1 -0
  168. package/dist/dispatch/OutputView.d.ts +8 -0
  169. package/dist/dispatch/OutputView.d.ts.map +1 -0
  170. package/dist/dispatch/OutputView.js +10 -0
  171. package/dist/dispatch/OutputView.js.map +1 -0
  172. package/dist/dispatch/PresenterArgumentResolver.d.ts +12 -0
  173. package/dist/dispatch/PresenterArgumentResolver.d.ts.map +1 -0
  174. package/dist/dispatch/PresenterArgumentResolver.js +20 -0
  175. package/dist/dispatch/PresenterArgumentResolver.js.map +1 -0
  176. package/dist/dispatch/PresenterExecutor.d.ts +11 -0
  177. package/dist/dispatch/PresenterExecutor.d.ts.map +1 -0
  178. package/dist/dispatch/PresenterExecutor.js +56 -0
  179. package/dist/dispatch/PresenterExecutor.js.map +1 -0
  180. package/dist/dispatch/RemoteRouteResolver.d.ts +13 -0
  181. package/dist/dispatch/RemoteRouteResolver.d.ts.map +1 -0
  182. package/dist/dispatch/RemoteRouteResolver.js +18 -0
  183. package/dist/dispatch/RemoteRouteResolver.js.map +1 -0
  184. package/dist/dispatch/Route.d.ts +10 -0
  185. package/dist/dispatch/Route.d.ts.map +1 -0
  186. package/dist/dispatch/Route.js +2 -0
  187. package/dist/dispatch/Route.js.map +1 -0
  188. package/dist/dispatch/RouteNotFoundError.d.ts +10 -0
  189. package/dist/dispatch/RouteNotFoundError.d.ts.map +1 -0
  190. package/dist/dispatch/RouteNotFoundError.js +24 -0
  191. package/dist/dispatch/RouteNotFoundError.js.map +1 -0
  192. package/dist/dispatch/RoutePolicy.d.ts +8 -0
  193. package/dist/dispatch/RoutePolicy.d.ts.map +1 -0
  194. package/dist/dispatch/RoutePolicy.js +2 -0
  195. package/dist/dispatch/RoutePolicy.js.map +1 -0
  196. package/dist/dispatch/RouteRegistry.d.ts +18 -0
  197. package/dist/dispatch/RouteRegistry.d.ts.map +1 -0
  198. package/dist/dispatch/RouteRegistry.js +62 -0
  199. package/dist/dispatch/RouteRegistry.js.map +1 -0
  200. package/dist/dispatch/RouteResolver.d.ts +7 -0
  201. package/dist/dispatch/RouteResolver.d.ts.map +1 -0
  202. package/dist/dispatch/RouteResolver.js +2 -0
  203. package/dist/dispatch/RouteResolver.js.map +1 -0
  204. package/dist/dispatch/StorageGuard.d.ts +15 -0
  205. package/dist/dispatch/StorageGuard.d.ts.map +1 -0
  206. package/dist/dispatch/StorageGuard.js +63 -0
  207. package/dist/dispatch/StorageGuard.js.map +1 -0
  208. package/dist/effective-operation.d.ts +90 -0
  209. package/dist/effective-operation.d.ts.map +1 -0
  210. package/dist/effective-operation.js +449 -0
  211. package/dist/effective-operation.js.map +1 -0
  212. package/dist/emit.d.ts +2 -2
  213. package/dist/emit.d.ts.map +1 -1
  214. package/dist/emit.js +2 -2
  215. package/dist/emit.js.map +1 -1
  216. package/dist/entry/DynamicFacade.d.ts +10 -0
  217. package/dist/entry/DynamicFacade.d.ts.map +1 -0
  218. package/dist/entry/DynamicFacade.js +27 -0
  219. package/dist/entry/DynamicFacade.js.map +1 -0
  220. package/dist/entry/FacadeEntry.d.ts +11 -0
  221. package/dist/entry/FacadeEntry.d.ts.map +1 -0
  222. package/dist/entry/FacadeEntry.js +26 -0
  223. package/dist/entry/FacadeEntry.js.map +1 -0
  224. package/dist/entry/TransportEntry.d.ts +13 -0
  225. package/dist/entry/TransportEntry.d.ts.map +1 -0
  226. package/dist/entry/TransportEntry.js +24 -0
  227. package/dist/entry/TransportEntry.js.map +1 -0
  228. package/dist/frond-config.d.ts +24 -7
  229. package/dist/frond-config.d.ts.map +1 -1
  230. package/dist/frond-config.js.map +1 -1
  231. package/dist/graph.d.ts +1 -1
  232. package/dist/graph.d.ts.map +1 -1
  233. package/dist/graph.js +3 -2
  234. package/dist/graph.js.map +1 -1
  235. package/dist/identity-keys.d.ts +14 -0
  236. package/dist/identity-keys.d.ts.map +1 -0
  237. package/dist/identity-keys.js +37 -0
  238. package/dist/identity-keys.js.map +1 -0
  239. package/dist/identity.d.ts +58 -0
  240. package/dist/identity.d.ts.map +1 -0
  241. package/dist/identity.js +182 -0
  242. package/dist/identity.js.map +1 -0
  243. package/dist/imports.d.ts +2 -2
  244. package/dist/imports.d.ts.map +1 -1
  245. package/dist/imports.js +7 -3
  246. package/dist/imports.js.map +1 -1
  247. package/dist/index.d.ts +57 -38
  248. package/dist/index.d.ts.map +1 -1
  249. package/dist/index.js +38 -32
  250. package/dist/index.js.map +1 -1
  251. package/dist/loader.d.ts +16 -0
  252. package/dist/loader.d.ts.map +1 -0
  253. package/dist/loader.js +25 -0
  254. package/dist/loader.js.map +1 -0
  255. package/dist/node.d.ts +21 -0
  256. package/dist/node.d.ts.map +1 -0
  257. package/dist/node.js +24 -0
  258. package/dist/node.js.map +1 -0
  259. package/dist/orm.d.ts +69 -8
  260. package/dist/orm.d.ts.map +1 -1
  261. package/dist/orm.js +35 -2
  262. package/dist/orm.js.map +1 -1
  263. package/dist/prefab/collector.d.ts +29 -0
  264. package/dist/prefab/collector.d.ts.map +1 -0
  265. package/dist/prefab/collector.js +34 -0
  266. package/dist/prefab/collector.js.map +1 -0
  267. package/dist/{crud.d.ts → prefab/crud.d.ts} +7 -8
  268. package/dist/prefab/crud.d.ts.map +1 -0
  269. package/dist/{crud.js → prefab/crud.js} +39 -5
  270. package/dist/prefab/crud.js.map +1 -0
  271. package/dist/prefab/mirror.d.ts +52 -0
  272. package/dist/prefab/mirror.d.ts.map +1 -0
  273. package/dist/prefab/mirror.js +66 -0
  274. package/dist/prefab/mirror.js.map +1 -0
  275. package/dist/prefab/prefab.d.ts +15 -0
  276. package/dist/prefab/prefab.d.ts.map +1 -0
  277. package/dist/prefab/prefab.js +19 -0
  278. package/dist/prefab/prefab.js.map +1 -0
  279. package/dist/{presenter.d.ts → prefab/presenter.d.ts} +6 -17
  280. package/dist/prefab/presenter.d.ts.map +1 -0
  281. package/dist/{presenter.js → prefab/presenter.js} +5 -23
  282. package/dist/prefab/presenter.js.map +1 -0
  283. package/dist/prefab/repository.d.ts +104 -0
  284. package/dist/prefab/repository.d.ts.map +1 -0
  285. package/dist/prefab/repository.js +62 -0
  286. package/dist/prefab/repository.js.map +1 -0
  287. package/dist/scan/Fronds.d.ts +45 -0
  288. package/dist/scan/Fronds.d.ts.map +1 -0
  289. package/dist/scan/Fronds.js +66 -0
  290. package/dist/scan/Fronds.js.map +1 -0
  291. package/dist/scan/conventions.d.ts +74 -0
  292. package/dist/scan/conventions.d.ts.map +1 -0
  293. package/dist/scan/conventions.js +82 -0
  294. package/dist/scan/conventions.js.map +1 -0
  295. package/dist/scan/emit.d.ts +14 -0
  296. package/dist/scan/emit.d.ts.map +1 -0
  297. package/dist/scan/emit.js +212 -0
  298. package/dist/scan/emit.js.map +1 -0
  299. package/dist/scan/frond.d.ts +224 -0
  300. package/dist/scan/frond.d.ts.map +1 -0
  301. package/dist/scan/frond.js +2 -0
  302. package/dist/scan/frond.js.map +1 -0
  303. package/dist/{handler-parser.d.ts → scan/handler-parser.d.ts} +20 -9
  304. package/dist/scan/handler-parser.d.ts.map +1 -0
  305. package/dist/scan/handler-parser.js +665 -0
  306. package/dist/scan/handler-parser.js.map +1 -0
  307. package/dist/scan/scan-cache.d.ts +16 -0
  308. package/dist/scan/scan-cache.d.ts.map +1 -0
  309. package/dist/{scan-cache.js → scan/scan-cache.js} +27 -20
  310. package/dist/scan/scan-cache.js.map +1 -0
  311. package/dist/scan/scanner.d.ts +20 -0
  312. package/dist/scan/scanner.d.ts.map +1 -0
  313. package/dist/{scanner.js → scan/scanner.js} +212 -167
  314. package/dist/scan/scanner.js.map +1 -0
  315. package/dist/verify.d.ts +16 -3
  316. package/dist/verify.d.ts.map +1 -1
  317. package/dist/verify.js +21 -18
  318. package/dist/verify.js.map +1 -1
  319. package/dist/{call.d.ts → wire/call.d.ts} +76 -7
  320. package/dist/wire/call.d.ts.map +1 -0
  321. package/dist/{call.js → wire/call.js} +53 -80
  322. package/dist/wire/call.js.map +1 -0
  323. package/dist/{middleware.d.ts → wire/errors.d.ts} +18 -19
  324. package/dist/wire/errors.d.ts.map +1 -0
  325. package/dist/{middleware.js → wire/errors.js} +26 -14
  326. package/dist/wire/errors.js.map +1 -0
  327. package/dist/{errors.d.ts → wire/http-error.d.ts} +5 -6
  328. package/dist/wire/http-error.d.ts.map +1 -0
  329. package/dist/{errors.js → wire/http-error.js} +7 -6
  330. package/dist/wire/http-error.js.map +1 -0
  331. package/dist/wire/invocation.d.ts +4 -0
  332. package/dist/wire/invocation.d.ts.map +1 -0
  333. package/dist/wire/invocation.js +3 -0
  334. package/dist/wire/invocation.js.map +1 -0
  335. package/dist/{middleware/logger.d.ts → wire/loggerMiddleware.d.ts} +3 -3
  336. package/dist/wire/loggerMiddleware.d.ts.map +1 -0
  337. package/dist/{middleware/logger.js → wire/loggerMiddleware.js} +2 -2
  338. package/dist/wire/loggerMiddleware.js.map +1 -0
  339. package/dist/wire/middleware.d.ts +29 -0
  340. package/dist/wire/middleware.d.ts.map +1 -0
  341. package/dist/wire/middleware.js +20 -0
  342. package/dist/wire/middleware.js.map +1 -0
  343. package/dist/{operation.d.ts → wire/operation.d.ts} +39 -10
  344. package/dist/wire/operation.d.ts.map +1 -0
  345. package/dist/wire/operation.js +167 -0
  346. package/dist/wire/operation.js.map +1 -0
  347. package/package.json +27 -8
  348. package/src/boot/AppLifecycle.ts +50 -0
  349. package/src/boot/Emissions.ts +263 -0
  350. package/src/boot/HandlerFacade.ts +242 -0
  351. package/src/boot/Lifecycle.ts +3 -0
  352. package/src/boot/ambient-port.ts +41 -0
  353. package/src/boot/ambient.als.ts +43 -0
  354. package/src/boot/ambient.queue.ts +75 -0
  355. package/src/boot/apply.ts +47 -0
  356. package/src/boot/auth.ts +55 -0
  357. package/src/boot/binding.ts +182 -0
  358. package/src/boot/boot.ts +125 -0
  359. package/src/boot/bootstrap.ts +839 -0
  360. package/src/boot/frame.ts +210 -0
  361. package/src/boot/ownership.ts +140 -0
  362. package/src/boot/ports.ts +66 -0
  363. package/src/boot/remote.ts +179 -0
  364. package/src/boot/seed.ts +158 -0
  365. package/src/boot/together.ts +215 -0
  366. package/src/boot/types.ts +261 -0
  367. package/src/builtins/config.ts +19 -0
  368. package/src/builtins/logger.ts +175 -0
  369. package/src/config-loader.ts +146 -0
  370. package/src/contract/Call.ts +18 -0
  371. package/src/contract/Invocation.ts +72 -0
  372. package/src/contract/RouteAddress.ts +49 -0
  373. package/src/contract.ts +74 -0
  374. package/src/crypto/encoding.ts +59 -0
  375. package/src/crypto/node.ts +30 -0
  376. package/src/crypto/port.ts +45 -0
  377. package/src/crypto/webcrypto.ts +55 -0
  378. package/src/define.ts +10 -0
  379. package/src/dispatch/ArgumentResolver.ts +17 -0
  380. package/src/dispatch/ArrayResult.ts +10 -0
  381. package/src/dispatch/DispatchEvent.ts +38 -0
  382. package/src/dispatch/DispatchLifecycle.ts +23 -0
  383. package/src/dispatch/DispatchPort.ts +6 -0
  384. package/src/dispatch/Dispatcher.ts +48 -0
  385. package/src/dispatch/InFlight.ts +49 -0
  386. package/src/dispatch/InputValidator.ts +28 -0
  387. package/src/dispatch/LocalRoutePolicy.ts +34 -0
  388. package/src/dispatch/OperationExecutor.ts +60 -0
  389. package/src/dispatch/OperationRoute.ts +18 -0
  390. package/src/dispatch/OutputProjector.ts +32 -0
  391. package/src/dispatch/OutputView.ts +9 -0
  392. package/src/dispatch/PresenterArgumentResolver.ts +25 -0
  393. package/src/dispatch/PresenterExecutor.ts +55 -0
  394. package/src/dispatch/RemoteRouteResolver.ts +21 -0
  395. package/src/dispatch/Route.ts +11 -0
  396. package/src/dispatch/RouteNotFoundError.ts +29 -0
  397. package/src/dispatch/RoutePolicy.ts +8 -0
  398. package/src/dispatch/RouteRegistry.ts +73 -0
  399. package/src/dispatch/RouteResolver.ts +7 -0
  400. package/src/dispatch/StorageGuard.ts +71 -0
  401. package/src/effective-operation.ts +597 -0
  402. package/src/emit.ts +90 -0
  403. package/src/entry/DynamicFacade.ts +28 -0
  404. package/src/entry/FacadeEntry.ts +32 -0
  405. package/src/entry/TransportEntry.ts +30 -0
  406. package/src/frond-config.ts +138 -0
  407. package/src/graph.ts +180 -0
  408. package/src/identity-keys.ts +43 -0
  409. package/src/identity.ts +235 -0
  410. package/src/imports.ts +123 -0
  411. package/src/index.ts +106 -0
  412. package/src/loader.ts +41 -0
  413. package/src/node.ts +28 -0
  414. package/src/orm.ts +252 -0
  415. package/src/prefab/collector.ts +36 -0
  416. package/src/prefab/crud.ts +188 -0
  417. package/src/prefab/mirror.ts +122 -0
  418. package/src/prefab/prefab.ts +46 -0
  419. package/src/prefab/presenter.ts +63 -0
  420. package/src/prefab/repository.ts +170 -0
  421. package/src/scan/Fronds.ts +73 -0
  422. package/src/scan/conventions.ts +122 -0
  423. package/src/scan/emit.ts +231 -0
  424. package/src/scan/frond.ts +235 -0
  425. package/src/scan/handler-parser.ts +818 -0
  426. package/src/scan/scan-cache.ts +115 -0
  427. package/src/scan/scanner.ts +758 -0
  428. package/src/verify.ts +193 -0
  429. package/src/wire/call.ts +369 -0
  430. package/src/wire/errors.ts +124 -0
  431. package/src/wire/http-error.ts +77 -0
  432. package/src/wire/invocation.ts +10 -0
  433. package/src/wire/loggerMiddleware.ts +29 -0
  434. package/src/wire/middleware.ts +47 -0
  435. package/src/wire/operation.ts +258 -0
  436. package/dist/binding.d.ts.map +0 -1
  437. package/dist/binding.js.map +0 -1
  438. package/dist/boot.d.ts.map +0 -1
  439. package/dist/boot.js +0 -53
  440. package/dist/boot.js.map +0 -1
  441. package/dist/bootstrap.d.ts.map +0 -1
  442. package/dist/bootstrap.js +0 -879
  443. package/dist/bootstrap.js.map +0 -1
  444. package/dist/call.d.ts.map +0 -1
  445. package/dist/call.js.map +0 -1
  446. package/dist/collector.d.ts +0 -28
  447. package/dist/collector.d.ts.map +0 -1
  448. package/dist/collector.js +0 -32
  449. package/dist/collector.js.map +0 -1
  450. package/dist/crud.d.ts.map +0 -1
  451. package/dist/crud.js.map +0 -1
  452. package/dist/egress.d.ts +0 -52
  453. package/dist/egress.d.ts.map +0 -1
  454. package/dist/egress.js +0 -186
  455. package/dist/egress.js.map +0 -1
  456. package/dist/errors.d.ts.map +0 -1
  457. package/dist/errors.js.map +0 -1
  458. package/dist/handler-parser.d.ts.map +0 -1
  459. package/dist/handler-parser.js +0 -505
  460. package/dist/handler-parser.js.map +0 -1
  461. package/dist/invocation.d.ts +0 -20
  462. package/dist/invocation.d.ts.map +0 -1
  463. package/dist/invocation.js +0 -15
  464. package/dist/invocation.js.map +0 -1
  465. package/dist/middleware/error-handler.d.ts +0 -15
  466. package/dist/middleware/error-handler.d.ts.map +0 -1
  467. package/dist/middleware/error-handler.js +0 -29
  468. package/dist/middleware/error-handler.js.map +0 -1
  469. package/dist/middleware/logger.d.ts.map +0 -1
  470. package/dist/middleware/logger.js.map +0 -1
  471. package/dist/middleware.d.ts.map +0 -1
  472. package/dist/middleware.js.map +0 -1
  473. package/dist/mirror.d.ts +0 -93
  474. package/dist/mirror.d.ts.map +0 -1
  475. package/dist/mirror.js +0 -96
  476. package/dist/mirror.js.map +0 -1
  477. package/dist/operation.d.ts.map +0 -1
  478. package/dist/operation.js +0 -95
  479. package/dist/operation.js.map +0 -1
  480. package/dist/presenter.d.ts.map +0 -1
  481. package/dist/presenter.js.map +0 -1
  482. package/dist/remote.d.ts.map +0 -1
  483. package/dist/remote.js.map +0 -1
  484. package/dist/repository.d.ts +0 -55
  485. package/dist/repository.d.ts.map +0 -1
  486. package/dist/repository.js +0 -26
  487. package/dist/repository.js.map +0 -1
  488. package/dist/scan-cache.d.ts +0 -10
  489. package/dist/scan-cache.d.ts.map +0 -1
  490. package/dist/scan-cache.js.map +0 -1
  491. package/dist/scanner.d.ts +0 -34
  492. package/dist/scanner.d.ts.map +0 -1
  493. package/dist/scanner.js.map +0 -1
  494. package/dist/seed.d.ts.map +0 -1
  495. package/dist/seed.js.map +0 -1
  496. package/dist/types.d.ts +0 -421
  497. package/dist/types.d.ts.map +0 -1
  498. package/dist/types.js.map +0 -1
  499. /package/dist/{bootstrap.d.ts → boot/bootstrap.d.ts} +0 -0
  500. /package/dist/{types.js → boot/types.js} +0 -0
@@ -0,0 +1,818 @@
1
+ /**
2
+ * Handler signature parser — extracts method signatures from handler source files.
3
+ *
4
+ * The AST says what the author declared; TypeScript's checker says what those types mean.
5
+ * TypeScript is lazy-loaded to avoid bundling the compiler in production builds.
6
+ */
7
+ import type ts from '@typescript/typescript6';
8
+ import { readFileSync, existsSync, statSync } from 'node:fs';
9
+ import { join, dirname, resolve as resolvePath } from 'node:path';
10
+
11
+ /** Lazy-loaded TypeScript module — avoids bundling the 9MB compiler. */
12
+ let _ts: typeof ts | undefined;
13
+ async function loadTS(): Promise<typeof ts> {
14
+ if (!_ts) _ts = (await import('@typescript/typescript6')).default;
15
+ return _ts;
16
+ }
17
+ function getTS(): typeof ts {
18
+ if (!_ts) throw new Error('TypeScript not loaded — call an async parse function first');
19
+ return _ts;
20
+ }
21
+
22
+ interface TypeProject {
23
+ roots: Set<string>;
24
+ options: ts.CompilerOptions;
25
+ program: ts.Program;
26
+ }
27
+
28
+ /**
29
+ * One checked program per project/configuration during a scan.
30
+ *
31
+ * A checker is a project reader, not a file parser: creating one per handler would reopen
32
+ * the standard library and every imported declaration for each method. `scanProject`
33
+ * resets this map at the start of a run, so an edited source can never meet a program from
34
+ * the previous run.
35
+ */
36
+ const typeProjects = new Map<string, TypeProject>();
37
+ const compilerProjects = new Map<string, { key: string; roots: string[]; options: ts.CompilerOptions }>();
38
+
39
+ /**
40
+ * What survives a run: the parsed declarations, and the program built over them.
41
+ *
42
+ * Rebuilding a program re-reads `lib.d.ts` and every imported `.d.ts`, and that is FIXED
43
+ * work — measured, a second scan in one process cost the same at 16 frond files as at 406.
44
+ * The mtime is the guard, so a run still cannot see a stale type: a file that moved is
45
+ * re-read and TypeScript invalidates it and everything depending on it, which is a
46
+ * narrower rule than discarding the program and not a weaker one.
47
+ */
48
+ const sourceFiles = new Map<string, { mtime: number; file: ts.SourceFile }>();
49
+ const retained = new Map<string, { host: ts.CompilerHost; program: ts.Program }>();
50
+
51
+ export function resetTypePrograms(): void {
52
+ typeProjects.clear();
53
+ compilerProjects.clear();
54
+ }
55
+
56
+ /** Drop what runs share. For a test that must prove a cold read. */
57
+ export function forgetParsedSources(): void {
58
+ sourceFiles.clear();
59
+ retained.clear();
60
+ }
61
+
62
+ function keptHost(key: string, options: ts.CompilerOptions): ts.CompilerHost {
63
+ const held = retained.get(key);
64
+ if (held) return held.host;
65
+ const typescript = getTS();
66
+ const base = typescript.createCompilerHost(options);
67
+ const host: ts.CompilerHost = {
68
+ ...base,
69
+ getSourceFile(fileName, languageVersion, onError, shouldCreate) {
70
+ const path = resolvePath(fileName);
71
+ const mtime = statSync(path, { throwIfNoEntry: false })?.mtimeMs ?? -1;
72
+ const cached = sourceFiles.get(path);
73
+ if (cached && cached.mtime === mtime) return cached.file;
74
+ const file = base.getSourceFile(fileName, languageVersion, onError, shouldCreate);
75
+ if (file && mtime >= 0) sourceFiles.set(path, { mtime, file });
76
+ return file;
77
+ },
78
+ };
79
+ retained.set(key, { host, program: undefined as unknown as ts.Program });
80
+ return host;
81
+ }
82
+
83
+ function builtProgram(key: string, roots: readonly string[], options: ts.CompilerOptions): ts.Program {
84
+ const typescript = getTS();
85
+ const host = keptHost(key, options);
86
+ const program = typescript.createProgram({
87
+ rootNames: [...roots], options, host, oldProgram: retained.get(key)?.program,
88
+ });
89
+ retained.set(key, { host, program });
90
+ return program;
91
+ }
92
+
93
+ function compilerProjectOf(filePath: string, projectRoot?: string): { key: string; roots: string[]; options: ts.CompilerOptions } {
94
+ const typescript = getTS();
95
+ const absolute = resolvePath(filePath);
96
+ const configPath = typescript.findConfigFile(dirname(absolute), typescript.sys.fileExists);
97
+
98
+ if (configPath) {
99
+ const key = `${configPath}:${projectRoot ?? ''}`;
100
+ const cached = compilerProjects.get(key);
101
+ if (cached) return cached;
102
+
103
+ const read = typescript.readConfigFile(configPath, typescript.sys.readFile);
104
+ if (read.error) throw new Error(typescript.flattenDiagnosticMessageText(read.error.messageText, '\n'));
105
+ const parsed = typescript.parseJsonConfigFileContent(read.config, typescript.sys, dirname(configPath));
106
+ const configured = {
107
+ key,
108
+ // Compiler options belong to the project; its entire include glob does not belong
109
+ // to this scan. Each declaration inspected below becomes a root and TypeScript
110
+ // follows its imports. Seeding the monorepo here made a one-file scan compile it all.
111
+ roots: [],
112
+ // Handlers may be authored or emitted as JavaScript. They still need to belong to
113
+ // the checked program so constructor parsing does not fail on the first cold scan.
114
+ options: { ...parsed.options, allowJs: true, noEmit: true },
115
+ };
116
+ compilerProjects.set(key, configured);
117
+ return configured;
118
+ }
119
+
120
+ const key = projectRoot ?? dirname(absolute);
121
+ const cached = compilerProjects.get(key);
122
+ if (cached) return cached;
123
+ const configured = {
124
+ key,
125
+ roots: [],
126
+ options: {
127
+ target: typescript.ScriptTarget.ES2022,
128
+ module: typescript.ModuleKind.Node16,
129
+ moduleResolution: typescript.ModuleResolutionKind.Node16,
130
+ strict: true,
131
+ skipLibCheck: true,
132
+ allowJs: true,
133
+ noEmit: true,
134
+ },
135
+ };
136
+ compilerProjects.set(key, configured);
137
+ return configured;
138
+ }
139
+
140
+ /**
141
+ * Declare every file a run will read, so one program covers it.
142
+ *
143
+ * `checkedSourceOf` rebuilds whenever it meets a root it has not seen, and a frond lives
144
+ * outside its project's tsconfig `include`, so every declaration was a new root: 44 files
145
+ * cost 7.3 s that way against 0.34 s for one program.
146
+ */
147
+ export async function seedTypeProgram(filePaths: readonly string[], projectRoot?: string): Promise<void> {
148
+ const typescript = await loadTS();
149
+ const grouped = new Map<string, { options: ts.CompilerOptions; paths: string[] }>();
150
+
151
+ for (const filePath of filePaths) {
152
+ const absolute = resolvePath(filePath);
153
+ const configured = compilerProjectOf(absolute, projectRoot);
154
+ const held = grouped.get(configured.key) ?? { options: configured.options, paths: [] };
155
+ held.paths.push(absolute);
156
+ grouped.set(configured.key, held);
157
+ }
158
+
159
+ for (const [key, { options, paths }] of grouped) {
160
+ const roots = new Set(typeProjects.get(key)?.roots ?? []);
161
+ for (const path of paths) roots.add(path);
162
+ typeProjects.set(key, { roots, options, program: builtProgram(key, [...roots], options) });
163
+ }
164
+ }
165
+
166
+ function checkedSourceOf(filePath: string, projectRoot?: string): { source: ts.SourceFile; checker: ts.TypeChecker } {
167
+ const typescript = getTS();
168
+ const absolute = resolvePath(filePath);
169
+ const configured = compilerProjectOf(absolute, projectRoot);
170
+ let held = typeProjects.get(configured.key);
171
+
172
+ if (!held) {
173
+ // `path.resolve` is variadic, so handing it directly to `map` also passed the
174
+ // index and the whole roots array as path segments. A fixture without a warm scan
175
+ // cache exposed that first-run-only failure.
176
+ const roots = new Set(configured.roots.map((root) => resolvePath(root)));
177
+ roots.add(absolute);
178
+ const program = builtProgram(configured.key, [...roots], configured.options);
179
+ held = { roots, options: configured.options, program };
180
+ typeProjects.set(configured.key, held);
181
+ } else if (!held.roots.has(absolute)) {
182
+ held.roots.add(absolute);
183
+ held.program = builtProgram(configured.key, [...held.roots], held.options);
184
+ }
185
+
186
+ const source = held.program.getSourceFile(absolute);
187
+ if (!source) throw new Error(`TypeScript did not include '${absolute}' in its program.`);
188
+ return { source, checker: held.program.getTypeChecker() };
189
+ }
190
+
191
+ /** A file, opened. Five places read and parsed one, each spelling the same two calls. */
192
+ function sourceOf(filePath: string): ts.SourceFile {
193
+ const ts = getTS();
194
+ return ts.createSourceFile(filePath, readFileSync(filePath, 'utf-8'), ts.ScriptTarget.Latest, true);
195
+ }
196
+
197
+ /** One declared parameter — a constructor's and a method's are read the same way. */
198
+ function parsedParam(param: ts.ParameterDeclaration, source: ts.SourceFile, checker?: ts.TypeChecker): ParsedParam {
199
+ const ts = getTS();
200
+ const type = param.type ? parseTypeNode(param.type, source, checker) : { raw: 'unknown', name: 'unknown' };
201
+ return {
202
+ name: ts.isIdentifier(param.name) ? param.name.text : param.name.getText(source),
203
+ type,
204
+ // `user?: User` and `user: User | undefined` are the same declaration of
205
+ // absence. A type alias may carry the latter, so only the checker can see it.
206
+ optional: param.questionToken !== undefined || param.initializer !== undefined || type.undefined === true,
207
+ };
208
+ }
209
+
210
+ /** A parsed type reference — supports primitives, entities, arrays, generics. */
211
+ export interface ParsedType {
212
+ /** Raw type text as written in source (e.g. 'Pagination<Post>'). */
213
+ raw: string;
214
+ /** Base type name (e.g. 'Pagination', 'string', 'Post'). */
215
+ name: string;
216
+ /** Whether this is an array (T[] or Array<T>) — true at any depth. */
217
+ array?: boolean;
218
+ /**
219
+ * How MANY array levels: `string[]` is 1, `string[][]` is 2. `array` only ever said
220
+ * "at least one", which sufficed while one level meant one thing. It stopped sufficing
221
+ * when a presenter method started taking the page — there the outer level IS the page
222
+ * and what remains is the field, so telling `string[]` from `string[][]` is telling a
223
+ * computed string from a computed list.
224
+ */
225
+ arrayDepth?: number;
226
+ /** Generic type arguments (e.g. for Pagination<Post> → [{ name: 'Post' }]). */
227
+ generics?: ParsedType[];
228
+ /** Whether `null` belongs to the type. */
229
+ nullable?: boolean;
230
+ /** Whether absence (`undefined` or `void`) belongs to the type. */
231
+ undefined?: boolean;
232
+ /** Whether this is a Promise wrapper (unwrapped in output). */
233
+ promise?: boolean;
234
+ }
235
+
236
+ /** A parsed method parameter. */
237
+ export interface ParsedParam {
238
+ name: string;
239
+ type: ParsedType;
240
+ optional?: boolean;
241
+ }
242
+
243
+ /** A parsed method signature from a handler source file. */
244
+ export interface ParsedMethod {
245
+ name: string;
246
+ params: ParsedParam[];
247
+ returnType?: ParsedType;
248
+ /**
249
+ * Came from a base class, not from the file being scanned. What a prefab
250
+ * handler declares about its own ops beats this — the scan reads a signature
251
+ * and guesses, the builder knows.
252
+ */
253
+ inherited?: boolean;
254
+ /**
255
+ * The operation in words — the first sentence of the method's doc comment.
256
+ *
257
+ * Not a new thing to write: handlers already carry it (`/** Judge: the author,
258
+ * a draft… *&#47;`), the AST already holds it, and nothing read it. A caller that
259
+ * discovers an operation over the wire has its name and its schema; what the
260
+ * operation is FOR lived only in the source.
261
+ */
262
+ description?: string;
263
+ }
264
+
265
+ /** Parse a TypeScript type node into a ParsedType. */
266
+ function parseTypeNode(node: ts.TypeNode, source: ts.SourceFile, checker?: ts.TypeChecker): ParsedType {
267
+ const ts = getTS();
268
+ const raw = node.getText(source);
269
+
270
+ if (checker) {
271
+ // `Fact<T>` is deliberately transparent in TypeScript (`type Fact<T> = T`), because
272
+ // a subscriber receives the payload itself. The checker erases that marker, while
273
+ // the binding plan still needs it to distinguish a fact from an ordinary body.
274
+ if (ts.isTypeReferenceNode(node) && ts.isIdentifier(node.typeName) && node.typeName.text === 'Fact') {
275
+ return {
276
+ raw,
277
+ name: 'Fact',
278
+ generics: node.typeArguments?.map((arg) => parseTypeNode(arg, source, checker)) ?? [],
279
+ };
280
+ }
281
+ return parseCheckedType(checker.getTypeFromTypeNode(node), raw, checker);
282
+ }
283
+
284
+ // Union types — extract nullable, strip Promise
285
+ if (ts.isUnionTypeNode(node)) {
286
+ const nonNull = node.types.filter(
287
+ (t) => !(ts.isLiteralTypeNode(t) && t.literal.kind === ts.SyntaxKind.NullKeyword)
288
+ && !(t.kind === ts.SyntaxKind.UndefinedKeyword)
289
+ && !(t.kind === ts.SyntaxKind.VoidKeyword)
290
+ && !(t.kind === ts.SyntaxKind.NullKeyword),
291
+ );
292
+ const nullable = node.types.some((t) =>
293
+ (ts.isLiteralTypeNode(t) && t.literal.kind === ts.SyntaxKind.NullKeyword)
294
+ || t.kind === ts.SyntaxKind.NullKeyword,
295
+ );
296
+ const undefinable = node.types.some((t) =>
297
+ t.kind === ts.SyntaxKind.UndefinedKeyword || t.kind === ts.SyntaxKind.VoidKeyword,
298
+ );
299
+ if (nonNull.length === 1) {
300
+ const inner = parseTypeNode(nonNull[0], source);
301
+ return { ...inner, nullable: nullable || inner.nullable, undefined: undefinable || inner.undefined, raw };
302
+ }
303
+ return { raw, name: raw, nullable, undefined: undefinable };
304
+ }
305
+
306
+ // Promise<T> — unwrap
307
+ if (ts.isTypeReferenceNode(node)) {
308
+ const typeName = node.typeName.getText(source);
309
+
310
+ if (typeName === 'Promise' && node.typeArguments?.length === 1) {
311
+ const inner = parseTypeNode(node.typeArguments[0], source);
312
+ return { ...inner, promise: true, raw };
313
+ }
314
+
315
+ // Array<T>
316
+ if (typeName === 'Array' && node.typeArguments?.length === 1) {
317
+ const inner = parseTypeNode(node.typeArguments[0], source);
318
+ return { ...inner, array: true, arrayDepth: (inner.arrayDepth ?? 0) + 1, raw };
319
+ }
320
+
321
+ // Generic type: Foo<Bar, Baz>
322
+ if (node.typeArguments && node.typeArguments.length > 0) {
323
+ const generics = node.typeArguments.map((arg) => parseTypeNode(arg, source));
324
+ return { raw, name: typeName, generics };
325
+ }
326
+
327
+ // Simple type reference: Post, string, etc.
328
+ return { raw, name: typeName };
329
+ }
330
+
331
+ // T[]
332
+ if (ts.isArrayTypeNode(node)) {
333
+ const inner = parseTypeNode(node.elementType, source);
334
+ return { ...inner, array: true, arrayDepth: (inner.arrayDepth ?? 0) + 1, raw };
335
+ }
336
+
337
+ // Keyword types: string, number, boolean, void
338
+ switch (node.kind) {
339
+ case ts.SyntaxKind.StringKeyword: return { raw, name: 'string' };
340
+ case ts.SyntaxKind.NumberKeyword: return { raw, name: 'number' };
341
+ case ts.SyntaxKind.BooleanKeyword: return { raw, name: 'boolean' };
342
+ case ts.SyntaxKind.VoidKeyword: return { raw, name: 'void', undefined: true };
343
+ case ts.SyntaxKind.UndefinedKeyword: return { raw, name: 'undefined', undefined: true };
344
+ case ts.SyntaxKind.NullKeyword: return { raw, name: 'null', nullable: true };
345
+ case ts.SyntaxKind.AnyKeyword: return { raw, name: 'any' };
346
+ case ts.SyntaxKind.UnknownKeyword: return { raw, name: 'unknown' };
347
+ }
348
+
349
+ // Object literal type: { title: string; limit: number }
350
+ if (ts.isTypeLiteralNode(node)) {
351
+ return { raw, name: raw };
352
+ }
353
+
354
+ // Fallback
355
+ return { raw, name: raw };
356
+ }
357
+
358
+ function meaningfulSymbolName(type: ts.Type, checker: ts.TypeChecker): string {
359
+ const typescript = getTS();
360
+ const symbol = type.aliasSymbol ?? type.getSymbol();
361
+ if (symbol && symbol.name !== 'default' && !symbol.name.startsWith('__')) return symbol.name;
362
+
363
+ for (const declaration of symbol?.declarations ?? []) {
364
+ if (
365
+ (typescript.isClassDeclaration(declaration)
366
+ || typescript.isInterfaceDeclaration(declaration)
367
+ || typescript.isTypeAliasDeclaration(declaration))
368
+ && declaration.name
369
+ ) return declaration.name.text;
370
+ }
371
+
372
+ return checker.typeToString(type, undefined, typescript.TypeFormatFlags.NoTruncation);
373
+ }
374
+
375
+ /** Turn a checked TypeScript type into the small, serializable vocabulary the runtime reads. */
376
+ function parseCheckedType(type: ts.Type, raw: string, checker: ts.TypeChecker, depth = 0): ParsedType {
377
+ const typescript = getTS();
378
+ if (depth > 12) return { raw, name: checker.typeToString(type) };
379
+
380
+ if (type.isUnion()) {
381
+ const nullable = type.types.some((member) => (member.flags & typescript.TypeFlags.Null) !== 0);
382
+ const undefinable = type.types.some((member) =>
383
+ (member.flags & (typescript.TypeFlags.Undefined | typescript.TypeFlags.Void)) !== 0,
384
+ );
385
+ const members = type.types.filter((member) =>
386
+ (member.flags & (typescript.TypeFlags.Null | typescript.TypeFlags.Undefined | typescript.TypeFlags.Void)) === 0,
387
+ );
388
+ // The checker represents the `boolean` keyword itself as `false | true`. Preserve
389
+ // the primitive vocabulary consumed by binding and presenter metadata.
390
+ if (
391
+ members.length > 0
392
+ && members.every((member) => (member.flags & typescript.TypeFlags.BooleanLiteral) !== 0)
393
+ ) {
394
+ return { raw, name: 'boolean', nullable, undefined: undefinable };
395
+ }
396
+ if (members.length === 1) {
397
+ const inner = parseCheckedType(members[0]!, raw, checker, depth + 1);
398
+ return {
399
+ ...inner,
400
+ raw,
401
+ nullable: nullable || inner.nullable,
402
+ undefined: undefinable || inner.undefined,
403
+ };
404
+ }
405
+ return {
406
+ raw,
407
+ name: members.map((member) => meaningfulSymbolName(member, checker)).join(' | ') || raw,
408
+ nullable,
409
+ undefined: undefinable,
410
+ };
411
+ }
412
+
413
+ // Present at runtime in the supported compiler versions, but intentionally omitted
414
+ // from TypeScript's public TypeChecker declaration.
415
+ const promised = (checker as ts.TypeChecker & {
416
+ getPromisedTypeOfPromise(candidate: ts.Type): ts.Type | undefined;
417
+ }).getPromisedTypeOfPromise(type);
418
+ if (promised) return { ...parseCheckedType(promised, raw, checker, depth + 1), raw, promise: true };
419
+
420
+ if (checker.isArrayType(type)) {
421
+ const [element] = checker.getTypeArguments(type as ts.TypeReference);
422
+ const inner = element ? parseCheckedType(element, raw, checker, depth + 1) : { raw, name: 'unknown' };
423
+ return { ...inner, raw, array: true, arrayDepth: (inner.arrayDepth ?? 0) + 1 };
424
+ }
425
+
426
+ if ((type.flags & typescript.TypeFlags.StringLike) !== 0) return { raw, name: 'string' };
427
+ if ((type.flags & typescript.TypeFlags.NumberLike) !== 0) return { raw, name: 'number' };
428
+ if ((type.flags & typescript.TypeFlags.BooleanLike) !== 0) return { raw, name: 'boolean' };
429
+ if ((type.flags & typescript.TypeFlags.Void) !== 0) return { raw, name: 'void', undefined: true };
430
+ if ((type.flags & typescript.TypeFlags.Undefined) !== 0) return { raw, name: 'undefined', undefined: true };
431
+ if ((type.flags & typescript.TypeFlags.Null) !== 0) return { raw, name: 'null', nullable: true };
432
+ if ((type.flags & typescript.TypeFlags.Any) !== 0) return { raw, name: 'any' };
433
+ if ((type.flags & typescript.TypeFlags.Unknown) !== 0) return { raw, name: 'unknown' };
434
+
435
+ const reference = type as ts.TypeReference;
436
+ // A declared alias such as `Emit<PostPublished>` may reduce to a function or object
437
+ // type, so it is no longer a TypeReference. The checker keeps its arguments beside
438
+ // `aliasSymbol`; losing them turns DI keys into bare `Emit`/`Facade`.
439
+ const args = (type as ts.Type & { aliasTypeArguments?: readonly ts.Type[] }).aliasTypeArguments
440
+ ?? checker.getTypeArguments(reference);
441
+ return {
442
+ raw,
443
+ name: meaningfulSymbolName(type, checker),
444
+ ...(args.length && { generics: args.map((arg) => parseCheckedType(arg, checker.typeToString(arg), checker, depth + 1)) }),
445
+ };
446
+ }
447
+
448
+ // ── Module resolution ────────────────────────
449
+
450
+ const TS_KEYWORDS = new Set([
451
+ 'string', 'number', 'boolean', 'void', 'undefined', 'null', 'any', 'unknown',
452
+ 'never', 'object', 'symbol', 'bigint',
453
+ ]);
454
+
455
+
456
+ /** Resolve an import specifier to an absolute file path. */
457
+ function resolveSpecifier(specifier: string, fromFile: string, projectRoot: string): string | undefined {
458
+ // Relative import
459
+ if (specifier.startsWith('.')) {
460
+ const dir = dirname(fromFile);
461
+ let resolved = resolvePath(dir, specifier);
462
+ // .js → .ts
463
+ if (resolved.endsWith('.js')) resolved = resolved.slice(0, -3) + '.ts';
464
+ if (!resolved.endsWith('.ts')) resolved += '.ts';
465
+ if (existsSync(resolved)) return resolved;
466
+ return undefined;
467
+ }
468
+
469
+ // Workspace package: @fougere/core → packages/core/src/index.ts
470
+ const match = specifier.match(/^@fougere\/([^/]+)$/);
471
+ if (match) {
472
+ const pkgDir = join(projectRoot, 'packages', match[1], 'src');
473
+ const indexPath = join(pkgDir, 'index.ts');
474
+ if (existsSync(indexPath)) return indexPath;
475
+ }
476
+
477
+ return undefined;
478
+ }
479
+
480
+
481
+
482
+ // ── Mixin / heritage parsing ─────────────────
483
+
484
+ /**
485
+ * The class a returned expression carries, however it is wrapped.
486
+ *
487
+ * A mixin does not always hand its class back bare. `Crud` returns
488
+ * `asCrudConstructor(class CrudHandler { … })` — one assertion helper standing between
489
+ * `return` and the class — and a parser accepting only a bare `return class` found
490
+ * nothing there, silently: the five inherited CRUD ops stopped being derived, and a warm
491
+ * scan cache kept answering the old parse for weeks (`scan-cache.ts` keys on source, not
492
+ * on parser version).
493
+ *
494
+ * So unwrap rather than match one shape: descend through call arguments, `as` and
495
+ * `satisfies` assertions, and parentheses. What is looked for is a class; where the
496
+ * author put it is their business.
497
+ */
498
+ function classInExpression(expr: ts.Node, depth = 0): ts.ClassExpression | undefined {
499
+ const ts = getTS();
500
+ if (depth > 8) return undefined;
501
+ if (ts.isClassExpression(expr)) return expr;
502
+ if (ts.isCallExpression(expr)) {
503
+ for (const arg of expr.arguments) {
504
+ const found = classInExpression(arg, depth + 1);
505
+ if (found) return found;
506
+ }
507
+ return undefined;
508
+ }
509
+ if (ts.isAsExpression(expr) || ts.isSatisfiesExpression(expr) || ts.isParenthesizedExpression(expr)) {
510
+ return classInExpression(expr.expression, depth + 1);
511
+ }
512
+ return undefined;
513
+ }
514
+
515
+ /** Find a class declaration inside a function (mixin pattern). */
516
+ function findClassInFunction(source: ts.SourceFile, functionName: string): ts.ClassDeclaration | ts.ClassExpression | undefined {
517
+ const ts = getTS();
518
+ for (const stmt of source.statements) {
519
+ if (!ts.isFunctionDeclaration(stmt)) continue;
520
+ if (stmt.name?.text !== functionName) continue;
521
+ if (!stmt.body) continue;
522
+
523
+ // Walk statements inside the function
524
+ for (const inner of stmt.body.statements) {
525
+ // return class CrudHandler { … }, or the same class behind a wrapper
526
+ if (ts.isReturnStatement(inner) && inner.expression) {
527
+ const found = classInExpression(inner.expression);
528
+ if (found) return found;
529
+ }
530
+ // class CrudHandler { ... } (followed by return)
531
+ if (ts.isClassDeclaration(inner)) return inner;
532
+ }
533
+ }
534
+ return undefined;
535
+ }
536
+
537
+
538
+
539
+
540
+ /**
541
+ * Extract methods from a class node (no file reading — works on already-parsed AST).
542
+ */
543
+ function extractClassMethods(
544
+ cls: ts.ClassDeclaration | ts.ClassExpression,
545
+ source: ts.SourceFile,
546
+ skip: Set<string>,
547
+ checker?: ts.TypeChecker,
548
+ ): ParsedMethod[] {
549
+ const ts = getTS();
550
+ const results: ParsedMethod[] = [];
551
+
552
+ for (const member of cls.members) {
553
+ if (!ts.isMethodDeclaration(member)) continue;
554
+ if (!member.name || !ts.isIdentifier(member.name)) continue;
555
+ // `private`/`protected` is a statement about the surface, and the AST carries it —
556
+ // it was read past. Every helper a handler names by intent (`mustOwn`, `readMany`,
557
+ // `refuse`) became a callable op: measured on the bench, `list.readMany` executed
558
+ // and `list.mayPublish` judged its argument. A door is what the author declares
559
+ // public, and TypeScript already has the word for it. `#name` is private too, but
560
+ // it is not an identifier, so it never reached here in the first place.
561
+ if (member.modifiers?.some((m) => m.kind === ts.SyntaxKind.PrivateKeyword || m.kind === ts.SyntaxKind.ProtectedKeyword)) continue;
562
+
563
+ const name = member.name.text;
564
+ if (skip.has(name)) continue;
565
+
566
+ const params = member.parameters.map((p) => parsedParam(p, source, checker));
567
+ const returnType = member.type ? parseTypeNode(member.type, source, checker) : undefined;
568
+ results.push({
569
+ name, params, returnType,
570
+ description: docSentenceOf(member, source),
571
+ });
572
+ }
573
+
574
+ return results;
575
+ }
576
+
577
+ /**
578
+ * The first sentence of a member's doc comment, or nothing.
579
+ *
580
+ * One sentence on purpose: what a caller needs to choose an operation is a claim,
581
+ * not an essay, and the rest of the comment addresses whoever edits the method.
582
+ * Reads the leading trivia rather than `ts.getJSDocTags` — the comment is what the
583
+ * author wrote, tags are a schema they never agreed to.
584
+ */
585
+ function docSentenceOf(member: ts.Node, source: ts.SourceFile): string | undefined {
586
+ const ts = getTS();
587
+ const ranges = ts.getLeadingCommentRanges(source.text, member.pos) ?? [];
588
+ const block = ranges.filter((r) => source.text.slice(r.pos, r.pos + 3) === '/**').pop();
589
+ if (!block) return undefined;
590
+
591
+ const body = source.text
592
+ .slice(block.pos + 3, block.end - 2)
593
+ .split('\n')
594
+ .map((line) => line.replace(/^\s*\*/, '').trim())
595
+ .join(' ')
596
+ .trim();
597
+
598
+ const [sentence] = body.split(/(?<=\.)\s/);
599
+
600
+ return sentence?.trim() || undefined;
601
+ }
602
+
603
+ /**
604
+ * Parse inherited methods from a class's heritage clause.
605
+ * Handles both `extends Crud(Entity)` (mixin) and `extends BaseClass` patterns.
606
+ */
607
+ /**
608
+ * Where a name used here is declared. The checker follows the import, the re-export chain
609
+ * and an installed package's types — the three cases three hand-rolled functions treated
610
+ * separately.
611
+ */
612
+ function declarationFileOf(node: ts.Node, checker: ts.TypeChecker): string | undefined {
613
+ const typescript = getTS();
614
+ let symbol = checker.getSymbolAtLocation(node);
615
+ if (!symbol) return undefined;
616
+ if (symbol.flags & typescript.SymbolFlags.Alias) symbol = checker.getAliasedSymbol(symbol);
617
+ return symbol.declarations?.[0]?.getSourceFile().fileName;
618
+ }
619
+
620
+ /**
621
+ * The methods a base class contributes, read from the INSTANTIATED type.
622
+ *
623
+ * `extends Crud(Post)` gives `create(input: Partial<Post>)` directly: the checker has
624
+ * already substituted the mixin's type parameter. The three functions this replaces
625
+ * detected the generic names and mapped them to the mixin's arguments by position.
626
+ */
627
+ function inheritedFromBase(
628
+ base: ts.ExpressionWithTypeArguments,
629
+ checker: ts.TypeChecker,
630
+ skip: Set<string>,
631
+ ): ParsedMethod[] {
632
+ const typescript = getTS();
633
+ const results: ParsedMethod[] = [];
634
+
635
+ for (const property of checker.getPropertiesOfType(checker.getTypeAtLocation(base))) {
636
+ if (skip.has(property.name)) continue;
637
+
638
+ // `private`/`protected` is a statement about the surface, and the declaration carries
639
+ // it. A door is what the author declares public.
640
+ const declaration = property.declarations?.[0];
641
+ if (declaration && typescript.canHaveModifiers(declaration)
642
+ && typescript.getModifiers(declaration)?.some((m) => m.kind === typescript.SyntaxKind.PrivateKeyword
643
+ || m.kind === typescript.SyntaxKind.ProtectedKeyword)) continue;
644
+
645
+ const signature = checker.getTypeOfSymbolAtLocation(property, base).getCallSignatures()[0];
646
+ if (!signature) continue;
647
+
648
+ const returned = signature.getReturnType();
649
+ const sentence = typescript.displayPartsToString(property.getDocumentationComment(checker)).trim();
650
+ results.push({
651
+ name: property.name,
652
+ params: signature.getParameters().map((parameter) => {
653
+ const type = checker.getTypeOfSymbolAtLocation(parameter, base);
654
+ return {
655
+ name: parameter.name,
656
+ type: parseCheckedType(type, checker.typeToString(type), checker),
657
+ optional: (parameter.flags & typescript.SymbolFlags.Optional) !== 0,
658
+ };
659
+ }),
660
+ returnType: parseCheckedType(returned, checker.typeToString(returned), checker),
661
+ ...(sentence ? { description: sentence.split(/(?<=\.)\s/)[0] } : {}),
662
+ });
663
+ }
664
+ return results;
665
+ }
666
+
667
+ function parseInheritedMethods(
668
+ cls: ts.ClassDeclaration,
669
+ source: ts.SourceFile,
670
+ checker: ts.TypeChecker,
671
+ skip: Set<string>,
672
+ /**
673
+ * Base classes this pass could not open — an INSTALLED one, typically, whose
674
+ * source is not in the workspace. Reported rather than treated as "no inherited
675
+ * method": the two used to be the same answer, so an op inherited from a
676
+ * published base class was absent from the façade without a word.
677
+ */
678
+ unresolved: string[],
679
+ ): ParsedMethod[] {
680
+ const ts = getTS();
681
+ if (!cls.heritageClauses) return [];
682
+
683
+ for (const clause of cls.heritageClauses) {
684
+ if (clause.token !== ts.SyntaxKind.ExtendsKeyword) continue;
685
+
686
+ for (const base of clause.types) {
687
+ const fromType = inheritedFromBase(base, checker, skip);
688
+ if (fromType.length > 0) return fromType;
689
+
690
+ // A factory that ERASES its own type — `assertShape<unknown>(class …)`, `as unknown`
691
+ // — leaves the checker with nothing to enumerate. The written class is still there,
692
+ // so read it. This is the one case where what the author wrote beats what it means.
693
+ const expression = base.expression;
694
+ const declared = ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)
695
+ ? declarationFileOf(expression.expression, checker)
696
+ : ts.isIdentifier(expression) ? declarationFileOf(expression, checker) : undefined;
697
+ if (!declared) { unresolved.push(expression.getText(source)); continue; }
698
+
699
+ const declaredSource = sourceOf(declared);
700
+ const written = ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)
701
+ ? findClassInFunction(declaredSource, expression.expression.text)
702
+ : findDefaultClass(declaredSource);
703
+ if (!written) { unresolved.push(expression.getText(source)); continue; }
704
+
705
+ return extractClassMethods(written, declaredSource, skip);
706
+ }
707
+ }
708
+
709
+ return [];
710
+ }
711
+
712
+ // ── Class finding ────────────────────────────
713
+
714
+ /** Find the default exported class in a source file. */
715
+ function findDefaultClass(source: ts.SourceFile): ts.ClassDeclaration | undefined {
716
+ const ts = getTS();
717
+ for (const stmt of source.statements) {
718
+ // export default class Foo { ... }
719
+ if (ts.isClassDeclaration(stmt) && stmt.modifiers?.some(
720
+ (m) => m.kind === ts.SyntaxKind.ExportKeyword,
721
+ ) && stmt.modifiers?.some(
722
+ (m) => m.kind === ts.SyntaxKind.DefaultKeyword,
723
+ )) {
724
+ return stmt;
725
+ }
726
+ }
727
+
728
+ // export default Foo (separate statement) — find the class it points to
729
+ for (const stmt of source.statements) {
730
+ if (ts.isExportAssignment(stmt) && !stmt.isExportEquals && ts.isIdentifier(stmt.expression)) {
731
+ const name = stmt.expression.text;
732
+ for (const s of source.statements) {
733
+ if (ts.isClassDeclaration(s) && s.name?.text === name) return s;
734
+ }
735
+ }
736
+ }
737
+
738
+ return undefined;
739
+ }
740
+
741
+ /**
742
+ * What a handler file yielded — its methods, AND what the pass could not open.
743
+ *
744
+ * The second half is why this is a pair rather than an array: an unresolvable base
745
+ * class used to give the same answer as a base class with no method, so an op
746
+ * inherited from an installed package was missing from the façade in silence. The
747
+ * pair travels through the scan cache, which is why {@link PARSER_VERSION} moved.
748
+ */
749
+ export interface HandlerParse {
750
+ methods: ParsedMethod[];
751
+ /** Base classes whose source this pass could not open. Empty is a claim. */
752
+ unresolvedHeritage: string[];
753
+ }
754
+
755
+ /**
756
+ * Every method a handler declares, its inherited ones included — the raw material of a
757
+ * binding plan. With a `projectRoot`, the heritage clause is followed too.
758
+ */
759
+ export async function parseAllHandlerMethods(filePath: string, projectRoot?: string): Promise<HandlerParse> {
760
+ await loadTS();
761
+ return parseClassMethods(filePath, CONSTRUCTOR_ONLY, projectRoot);
762
+ }
763
+
764
+ /**
765
+ * Parse a presenter source file and extract all method signatures.
766
+ *
767
+ * Returns all methods (no CRUD filtering) — each method is a computed field.
768
+ */
769
+ export async function parsePresenterMethods(filePath: string, projectRoot?: string): Promise<ParsedMethod[]> {
770
+ await loadTS();
771
+ // No `projectRoot`, so no heritage pass and nothing to report: a presenter's
772
+ // computed fields are its own methods.
773
+ return parseClassMethods(filePath, CONSTRUCTOR_ONLY, undefined, projectRoot).methods;
774
+ }
775
+
776
+ /**
777
+ * Parse constructor parameter types from a source file's default class.
778
+ * Returns type names (e.g. ['PostOrm', 'Logger']) for DI resolution.
779
+ */
780
+ export async function parseConstructorParams(filePath: string, projectRoot?: string): Promise<ParsedParam[]> {
781
+ const ts = await loadTS();
782
+ const { source, checker } = checkedSourceOf(filePath, projectRoot);
783
+ const cls = findDefaultClass(source);
784
+ if (!cls) return [];
785
+
786
+ const ctor = cls.members.find(ts.isConstructorDeclaration);
787
+ return ctor ? ctor.parameters.map((p) => parsedParam(p, source, checker)) : [];
788
+ }
789
+
790
+ const CONSTRUCTOR_ONLY = new Set(['constructor']);
791
+
792
+ function parseClassMethods(
793
+ filePath: string,
794
+ skip: Set<string>,
795
+ heritageRoot?: string,
796
+ typeRoot: string | undefined = heritageRoot,
797
+ ): HandlerParse {
798
+ const unresolved: string[] = [];
799
+ const { source, checker } = checkedSourceOf(filePath, typeRoot);
800
+ const cls = findDefaultClass(source);
801
+ if (!cls) return { methods: [], unresolvedHeritage: unresolved };
802
+
803
+ // Parse child class methods
804
+ const childMethods = extractClassMethods(cls, source, skip, checker);
805
+ const childNames = new Set(childMethods.map((m) => m.name));
806
+
807
+ // Parse inherited methods (if projectRoot is provided for resolution)
808
+ if (heritageRoot) {
809
+ const inherited = parseInheritedMethods(cls, source, checker, skip, unresolved);
810
+ // Merge: child methods win over inherited
811
+ const parentOnly = inherited
812
+ .filter((m) => !childNames.has(m.name))
813
+ .map((m) => ({ ...m, inherited: true }));
814
+ return { methods: [...childMethods, ...parentOnly], unresolvedHeritage: unresolved };
815
+ }
816
+
817
+ return { methods: childMethods, unresolvedHeritage: unresolved };
818
+ }