ts-procedures 7.2.0 → 8.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 (325) hide show
  1. package/README.md +65 -3
  2. package/agent_config/claude-code/agents/ts-procedures-architect.md +6 -8
  3. package/agent_config/claude-code/skills/ts-procedures/SKILL.md +30 -33
  4. package/agent_config/claude-code/skills/ts-procedures/anti-patterns.md +139 -53
  5. package/agent_config/claude-code/skills/ts-procedures/api-reference.md +208 -231
  6. package/agent_config/claude-code/skills/ts-procedures/patterns.md +80 -153
  7. package/agent_config/claude-code/skills/ts-procedures-review/SKILL.md +1 -1
  8. package/agent_config/claude-code/skills/ts-procedures-review/checklist.md +4 -5
  9. package/agent_config/claude-code/skills/ts-procedures-scaffold/SKILL.md +4 -7
  10. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono.md +223 -0
  11. package/agent_config/copilot/copilot-instructions.md +36 -48
  12. package/agent_config/cursor/cursorrules +36 -48
  13. package/build/client/call.js +4 -1
  14. package/build/client/call.js.map +1 -1
  15. package/build/client/call.test.js +23 -0
  16. package/build/client/call.test.js.map +1 -1
  17. package/build/client/fetch-adapter.js +3 -1
  18. package/build/client/fetch-adapter.js.map +1 -1
  19. package/build/client/fetch-adapter.test.js +11 -1
  20. package/build/client/fetch-adapter.test.js.map +1 -1
  21. package/build/client/index.test.js +7 -7
  22. package/build/client/index.test.js.map +1 -1
  23. package/build/client/request-builder.d.ts +1 -1
  24. package/build/client/request-builder.js +2 -2
  25. package/build/client/request-builder.js.map +1 -1
  26. package/build/client/stream.js +13 -2
  27. package/build/client/stream.js.map +1 -1
  28. package/build/client/stream.test.js +32 -7
  29. package/build/client/stream.test.js.map +1 -1
  30. package/build/client/typed-error-dispatch.test.js +8 -92
  31. package/build/client/typed-error-dispatch.test.js.map +1 -1
  32. package/build/client/types.d.ts +21 -3
  33. package/build/codegen/bin/cli.js +0 -0
  34. package/build/codegen/e2e.test.js +87 -23
  35. package/build/codegen/e2e.test.js.map +1 -1
  36. package/build/codegen/emit-errors.integration.test.js +1 -1
  37. package/build/codegen/emit-errors.integration.test.js.map +1 -1
  38. package/build/codegen/emit-scope.js +308 -47
  39. package/build/codegen/emit-scope.js.map +1 -1
  40. package/build/codegen/emit-scope.test.js +363 -110
  41. package/build/codegen/emit-scope.test.js.map +1 -1
  42. package/build/codegen/pipeline.test.js +7 -7
  43. package/build/codegen/pipeline.test.js.map +1 -1
  44. package/build/codegen/resolve-envelope.js +1 -1
  45. package/build/codegen/resolve-envelope.js.map +1 -1
  46. package/build/codegen/resolve-envelope.test.js +5 -5
  47. package/build/codegen/resolve-envelope.test.js.map +1 -1
  48. package/build/codegen/targets/_shared/route-slots.d.ts +8 -3
  49. package/build/codegen/targets/_shared/route-slots.js +49 -8
  50. package/build/codegen/targets/_shared/route-slots.js.map +1 -1
  51. package/build/codegen/targets/_shared/route-slots.test.js +99 -26
  52. package/build/codegen/targets/_shared/route-slots.test.js.map +1 -1
  53. package/build/codegen/targets/kotlin/emit-route-kotlin.test.js +88 -17
  54. package/build/codegen/targets/kotlin/emit-route-kotlin.test.js.map +1 -1
  55. package/build/codegen/targets/kotlin/emit-scope-kotlin.test.js +9 -6
  56. package/build/codegen/targets/kotlin/emit-scope-kotlin.test.js.map +1 -1
  57. package/build/codegen/targets/kotlin/integration.test.js +6 -0
  58. package/build/codegen/targets/kotlin/integration.test.js.map +1 -1
  59. package/build/codegen/targets/swift/access-level.test.js +8 -11
  60. package/build/codegen/targets/swift/access-level.test.js.map +1 -1
  61. package/build/codegen/targets/swift/emit-route-swift.test.js +91 -20
  62. package/build/codegen/targets/swift/emit-route-swift.test.js.map +1 -1
  63. package/build/codegen/targets/swift/emit-scope-swift.test.js +12 -9
  64. package/build/codegen/targets/swift/emit-scope-swift.test.js.map +1 -1
  65. package/build/codegen/targets/swift/integration.test.js +6 -0
  66. package/build/codegen/targets/swift/integration.test.js.map +1 -1
  67. package/build/create-http-stream.d.ts +58 -0
  68. package/build/create-http-stream.js +122 -0
  69. package/build/create-http-stream.js.map +1 -0
  70. package/build/create-http-stream.test.js +88 -0
  71. package/build/create-http-stream.test.js.map +1 -0
  72. package/build/create-http.d.ts +49 -0
  73. package/build/create-http.js +108 -0
  74. package/build/create-http.js.map +1 -0
  75. package/build/create-http.test.js +137 -0
  76. package/build/create-http.test.js.map +1 -0
  77. package/build/create-stream.d.ts +35 -0
  78. package/build/create-stream.js +123 -0
  79. package/build/create-stream.js.map +1 -0
  80. package/build/create-stream.test.js +428 -0
  81. package/build/create-stream.test.js.map +1 -0
  82. package/build/create.d.ts +28 -0
  83. package/build/create.js +82 -0
  84. package/build/create.js.map +1 -0
  85. package/build/create.test.js +483 -0
  86. package/build/create.test.js.map +1 -0
  87. package/build/exports.d.ts +2 -0
  88. package/build/implementations/http/astro/index.test.js +20 -12
  89. package/build/implementations/http/astro/index.test.js.map +1 -1
  90. package/build/implementations/http/doc-registry.js +1 -1
  91. package/build/implementations/http/doc-registry.js.map +1 -1
  92. package/build/implementations/http/doc-registry.test.js +36 -5
  93. package/build/implementations/http/doc-registry.test.js.map +1 -1
  94. package/build/implementations/http/error-dispatch.d.ts +76 -0
  95. package/build/implementations/http/error-dispatch.js +77 -0
  96. package/build/implementations/http/error-dispatch.js.map +1 -0
  97. package/build/implementations/http/error-dispatch.test.js +254 -0
  98. package/build/implementations/http/error-dispatch.test.js.map +1 -0
  99. package/build/implementations/http/error-taxonomy.d.ts +5 -5
  100. package/build/implementations/http/hono/docs/http-doc.d.ts +6 -0
  101. package/build/implementations/http/hono/docs/http-doc.js +42 -0
  102. package/build/implementations/http/hono/docs/http-doc.js.map +1 -0
  103. package/build/implementations/http/hono/docs/http-stream-doc.d.ts +6 -0
  104. package/build/implementations/http/hono/docs/http-stream-doc.js +40 -0
  105. package/build/implementations/http/hono/docs/http-stream-doc.js.map +1 -0
  106. package/build/implementations/http/hono/docs/rpc-doc.d.ts +6 -0
  107. package/build/implementations/http/hono/docs/rpc-doc.js +24 -0
  108. package/build/implementations/http/hono/docs/rpc-doc.js.map +1 -0
  109. package/build/implementations/http/hono/docs/stream-doc.d.ts +6 -0
  110. package/build/implementations/http/hono/docs/stream-doc.js +42 -0
  111. package/build/implementations/http/hono/docs/stream-doc.js.map +1 -0
  112. package/build/implementations/http/hono/handlers/http-stream.d.ts +10 -0
  113. package/build/implementations/http/hono/handlers/http-stream.js +123 -0
  114. package/build/implementations/http/hono/handlers/http-stream.js.map +1 -0
  115. package/build/implementations/http/hono/handlers/http-stream.test.js +128 -0
  116. package/build/implementations/http/hono/handlers/http-stream.test.js.map +1 -0
  117. package/build/implementations/http/hono/handlers/http.d.ts +10 -0
  118. package/build/implementations/http/hono/handlers/http.js +115 -0
  119. package/build/implementations/http/hono/handlers/http.js.map +1 -0
  120. package/build/implementations/http/hono/handlers/http.test.js +118 -0
  121. package/build/implementations/http/hono/handlers/http.test.js.map +1 -0
  122. package/build/implementations/http/hono/handlers/rpc.d.ts +11 -0
  123. package/build/implementations/http/hono/handlers/rpc.js +32 -0
  124. package/build/implementations/http/hono/handlers/rpc.js.map +1 -0
  125. package/build/implementations/http/hono/handlers/rpc.test.js +73 -0
  126. package/build/implementations/http/hono/handlers/rpc.test.js.map +1 -0
  127. package/build/implementations/http/hono/handlers/stream.d.ts +23 -0
  128. package/build/implementations/http/hono/handlers/stream.js +147 -0
  129. package/build/implementations/http/hono/handlers/stream.js.map +1 -0
  130. package/build/implementations/http/hono/handlers/stream.test.d.ts +1 -0
  131. package/build/implementations/http/hono/handlers/stream.test.js +177 -0
  132. package/build/implementations/http/hono/handlers/stream.test.js.map +1 -0
  133. package/build/implementations/http/hono/index.d.ts +57 -0
  134. package/build/implementations/http/hono/index.js +149 -0
  135. package/build/implementations/http/hono/index.js.map +1 -0
  136. package/build/implementations/http/hono/index.test.d.ts +1 -0
  137. package/build/implementations/http/hono/index.test.js +274 -0
  138. package/build/implementations/http/hono/index.test.js.map +1 -0
  139. package/build/implementations/http/hono/path.d.ts +17 -0
  140. package/build/implementations/http/hono/path.js +39 -0
  141. package/build/implementations/http/hono/path.js.map +1 -0
  142. package/build/implementations/http/hono/path.test.d.ts +1 -0
  143. package/build/implementations/http/hono/path.test.js +83 -0
  144. package/build/implementations/http/hono/path.test.js.map +1 -0
  145. package/build/implementations/http/hono/types.d.ts +51 -0
  146. package/build/implementations/http/hono/types.js.map +1 -0
  147. package/build/implementations/http/on-request-error.test.js +6 -96
  148. package/build/implementations/http/on-request-error.test.js.map +1 -1
  149. package/build/implementations/http/route-errors.test.js +11 -59
  150. package/build/implementations/http/route-errors.test.js.map +1 -1
  151. package/build/implementations/types.d.ts +43 -9
  152. package/build/index.d.ts +125 -115
  153. package/build/index.js +10 -222
  154. package/build/index.js.map +1 -1
  155. package/build/index.test.js +30 -822
  156. package/build/index.test.js.map +1 -1
  157. package/build/migration.test.d.ts +1 -0
  158. package/build/migration.test.js +34 -0
  159. package/build/migration.test.js.map +1 -0
  160. package/build/schema/compute-schema.d.ts +11 -3
  161. package/build/schema/compute-schema.js +13 -7
  162. package/build/schema/compute-schema.js.map +1 -1
  163. package/build/schema/parser.d.ts +11 -3
  164. package/build/schema/parser.js +49 -9
  165. package/build/schema/parser.js.map +1 -1
  166. package/build/stack-utils.js +8 -0
  167. package/build/stack-utils.js.map +1 -1
  168. package/build/types.d.ts +142 -0
  169. package/build/types.js.map +1 -0
  170. package/docs/astro-adapter.md +5 -5
  171. package/docs/core.md +34 -17
  172. package/docs/http-integrations.md +83 -170
  173. package/docs/streaming.md +3 -60
  174. package/docs/superpowers/plans/2026-05-07-astro-adapter.md +2 -7
  175. package/docs/superpowers/plans/2026-05-08-create-http.md +3355 -0
  176. package/docs/superpowers/plans/2026-05-08-hono-app-builder-convergence.md +3365 -0
  177. package/docs/superpowers/specs/2026-05-07-astro-adapter-design.md +1 -3
  178. package/docs/superpowers/specs/2026-05-08-create-http-design.md +409 -0
  179. package/docs/superpowers/specs/2026-05-08-hono-app-builder-convergence-design.md +411 -0
  180. package/package.json +4 -22
  181. package/src/client/call.test.ts +26 -0
  182. package/src/client/call.ts +4 -1
  183. package/src/client/fetch-adapter.test.ts +14 -1
  184. package/src/client/fetch-adapter.ts +3 -1
  185. package/src/client/index.test.ts +7 -7
  186. package/src/client/request-builder.ts +2 -2
  187. package/src/client/stream.test.ts +39 -7
  188. package/src/client/stream.ts +16 -2
  189. package/src/client/typed-error-dispatch.test.ts +7 -97
  190. package/src/client/types.ts +21 -3
  191. package/src/codegen/__fixtures__/users-envelope.json +119 -38
  192. package/src/codegen/e2e.test.ts +98 -24
  193. package/src/codegen/emit-errors.integration.test.ts +1 -1
  194. package/src/codegen/emit-scope.test.ts +395 -110
  195. package/src/codegen/emit-scope.ts +350 -55
  196. package/src/codegen/pipeline.test.ts +7 -7
  197. package/src/codegen/resolve-envelope.test.ts +5 -5
  198. package/src/codegen/resolve-envelope.ts +1 -1
  199. package/src/codegen/targets/_shared/route-slots.test.ts +109 -26
  200. package/src/codegen/targets/_shared/route-slots.ts +48 -11
  201. package/src/codegen/targets/kotlin/__fixtures__/users-golden.kt +73 -0
  202. package/src/codegen/targets/kotlin/emit-route-kotlin.test.ts +100 -17
  203. package/src/codegen/targets/kotlin/emit-scope-kotlin.test.ts +9 -6
  204. package/src/codegen/targets/kotlin/integration.test.ts +19 -0
  205. package/src/codegen/targets/swift/__fixtures__/users-golden.swift +79 -0
  206. package/src/codegen/targets/swift/access-level.test.ts +8 -11
  207. package/src/codegen/targets/swift/emit-route-swift.test.ts +103 -20
  208. package/src/codegen/targets/swift/emit-scope-swift.test.ts +12 -9
  209. package/src/codegen/targets/swift/integration.test.ts +17 -0
  210. package/src/create-http-stream.test.ts +97 -0
  211. package/src/create-http-stream.ts +191 -0
  212. package/src/create-http.test.ts +163 -0
  213. package/src/create-http.ts +211 -0
  214. package/src/create-stream.test.ts +565 -0
  215. package/src/create-stream.ts +228 -0
  216. package/src/create.test.ts +658 -0
  217. package/src/create.ts +172 -0
  218. package/src/exports.ts +2 -0
  219. package/src/implementations/http/README.md +135 -95
  220. package/src/implementations/http/astro/README.md +4 -5
  221. package/src/implementations/http/astro/index.test.ts +25 -18
  222. package/src/implementations/http/doc-registry.test.ts +42 -5
  223. package/src/implementations/http/doc-registry.ts +1 -1
  224. package/src/implementations/http/error-dispatch.test.ts +283 -0
  225. package/src/implementations/http/error-dispatch.ts +176 -0
  226. package/src/implementations/http/error-taxonomy.ts +5 -5
  227. package/src/implementations/http/hono/docs/http-doc.ts +43 -0
  228. package/src/implementations/http/hono/docs/http-stream-doc.ts +44 -0
  229. package/src/implementations/http/hono/docs/rpc-doc.ts +34 -0
  230. package/src/implementations/http/hono/docs/stream-doc.ts +53 -0
  231. package/src/implementations/http/hono/handlers/http-stream.test.ts +150 -0
  232. package/src/implementations/http/hono/handlers/http-stream.ts +152 -0
  233. package/src/implementations/http/hono/handlers/http.test.ts +130 -0
  234. package/src/implementations/http/hono/handlers/http.ts +147 -0
  235. package/src/implementations/http/hono/handlers/rpc.test.ts +81 -0
  236. package/src/implementations/http/hono/handlers/rpc.ts +54 -0
  237. package/src/implementations/http/hono/handlers/stream.test.ts +198 -0
  238. package/src/implementations/http/hono/handlers/stream.ts +208 -0
  239. package/src/implementations/http/hono/index.test.ts +329 -0
  240. package/src/implementations/http/hono/index.ts +204 -0
  241. package/src/implementations/http/hono/path.test.ts +96 -0
  242. package/src/implementations/http/hono/path.ts +59 -0
  243. package/src/implementations/http/hono/types.ts +93 -0
  244. package/src/implementations/http/on-request-error.test.ts +10 -116
  245. package/src/implementations/http/route-errors.test.ts +11 -77
  246. package/src/implementations/types.ts +44 -9
  247. package/src/index.test.ts +35 -1091
  248. package/src/index.ts +50 -474
  249. package/src/migration.test.ts +48 -0
  250. package/src/schema/compute-schema.ts +26 -12
  251. package/src/schema/parser.ts +62 -12
  252. package/src/stack-utils.ts +8 -0
  253. package/src/types.ts +133 -0
  254. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/express-rpc.md +0 -137
  255. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-api.md +0 -173
  256. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-rpc.md +0 -142
  257. package/agent_config/claude-code/skills/ts-procedures-scaffold/templates/hono-stream.md +0 -147
  258. package/build/implementations/http/express-rpc/error-taxonomy.test.js +0 -83
  259. package/build/implementations/http/express-rpc/error-taxonomy.test.js.map +0 -1
  260. package/build/implementations/http/express-rpc/index.d.ts +0 -125
  261. package/build/implementations/http/express-rpc/index.js +0 -216
  262. package/build/implementations/http/express-rpc/index.js.map +0 -1
  263. package/build/implementations/http/express-rpc/index.test.js +0 -684
  264. package/build/implementations/http/express-rpc/index.test.js.map +0 -1
  265. package/build/implementations/http/express-rpc/types.d.ts +0 -11
  266. package/build/implementations/http/express-rpc/types.js.map +0 -1
  267. package/build/implementations/http/hono-api/error-taxonomy.test.js +0 -137
  268. package/build/implementations/http/hono-api/error-taxonomy.test.js.map +0 -1
  269. package/build/implementations/http/hono-api/index.d.ts +0 -151
  270. package/build/implementations/http/hono-api/index.js +0 -344
  271. package/build/implementations/http/hono-api/index.js.map +0 -1
  272. package/build/implementations/http/hono-api/index.test.js +0 -992
  273. package/build/implementations/http/hono-api/index.test.js.map +0 -1
  274. package/build/implementations/http/hono-api/types.d.ts +0 -13
  275. package/build/implementations/http/hono-api/types.js.map +0 -1
  276. package/build/implementations/http/hono-rpc/error-taxonomy.test.js +0 -64
  277. package/build/implementations/http/hono-rpc/error-taxonomy.test.js.map +0 -1
  278. package/build/implementations/http/hono-rpc/index.d.ts +0 -130
  279. package/build/implementations/http/hono-rpc/index.js +0 -209
  280. package/build/implementations/http/hono-rpc/index.js.map +0 -1
  281. package/build/implementations/http/hono-rpc/index.test.js +0 -828
  282. package/build/implementations/http/hono-rpc/index.test.js.map +0 -1
  283. package/build/implementations/http/hono-rpc/types.d.ts +0 -11
  284. package/build/implementations/http/hono-rpc/types.js +0 -2
  285. package/build/implementations/http/hono-rpc/types.js.map +0 -1
  286. package/build/implementations/http/hono-stream/error-taxonomy.test.js +0 -159
  287. package/build/implementations/http/hono-stream/error-taxonomy.test.js.map +0 -1
  288. package/build/implementations/http/hono-stream/index.d.ts +0 -171
  289. package/build/implementations/http/hono-stream/index.js +0 -415
  290. package/build/implementations/http/hono-stream/index.js.map +0 -1
  291. package/build/implementations/http/hono-stream/index.test.js +0 -1383
  292. package/build/implementations/http/hono-stream/index.test.js.map +0 -1
  293. package/build/implementations/http/hono-stream/types.d.ts +0 -15
  294. package/build/implementations/http/hono-stream/types.js +0 -2
  295. package/build/implementations/http/hono-stream/types.js.map +0 -1
  296. package/src/implementations/http/express-rpc/README.md +0 -280
  297. package/src/implementations/http/express-rpc/error-taxonomy.test.ts +0 -103
  298. package/src/implementations/http/express-rpc/index.test.ts +0 -957
  299. package/src/implementations/http/express-rpc/index.ts +0 -327
  300. package/src/implementations/http/express-rpc/types.ts +0 -16
  301. package/src/implementations/http/hono-api/README.md +0 -284
  302. package/src/implementations/http/hono-api/error-taxonomy.test.ts +0 -179
  303. package/src/implementations/http/hono-api/index.test.ts +0 -1341
  304. package/src/implementations/http/hono-api/index.ts +0 -519
  305. package/src/implementations/http/hono-api/types.ts +0 -16
  306. package/src/implementations/http/hono-rpc/README.md +0 -357
  307. package/src/implementations/http/hono-rpc/error-taxonomy.test.ts +0 -82
  308. package/src/implementations/http/hono-rpc/index.test.ts +0 -1107
  309. package/src/implementations/http/hono-rpc/index.ts +0 -320
  310. package/src/implementations/http/hono-rpc/types.ts +0 -16
  311. package/src/implementations/http/hono-stream/README.md +0 -559
  312. package/src/implementations/http/hono-stream/error-taxonomy.test.ts +0 -178
  313. package/src/implementations/http/hono-stream/index.test.ts +0 -1804
  314. package/src/implementations/http/hono-stream/index.ts +0 -622
  315. package/src/implementations/http/hono-stream/types.ts +0 -20
  316. /package/build/{implementations/http/express-rpc/error-taxonomy.test.d.ts → create-http-stream.test.d.ts} +0 -0
  317. /package/build/{implementations/http/express-rpc/index.test.d.ts → create-http.test.d.ts} +0 -0
  318. /package/build/{implementations/http/hono-api/error-taxonomy.test.d.ts → create-stream.test.d.ts} +0 -0
  319. /package/build/{implementations/http/hono-api/index.test.d.ts → create.test.d.ts} +0 -0
  320. /package/build/implementations/http/{hono-rpc/error-taxonomy.test.d.ts → error-dispatch.test.d.ts} +0 -0
  321. /package/build/implementations/http/{hono-rpc/index.test.d.ts → hono/handlers/http-stream.test.d.ts} +0 -0
  322. /package/build/implementations/http/{hono-stream/error-taxonomy.test.d.ts → hono/handlers/http.test.d.ts} +0 -0
  323. /package/build/implementations/http/{hono-stream/index.test.d.ts → hono/handlers/rpc.test.d.ts} +0 -0
  324. /package/build/implementations/http/{express-rpc → hono}/types.js +0 -0
  325. /package/build/{implementations/http/hono-api/types.js → types.js} +0 -0
@@ -0,0 +1,88 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { Procedures } from './index.js';
3
+ import { Type } from 'typebox';
4
+ import { ProcedureValidationError } from './errors.js';
5
+ describe('CreateHttpStream basic generator', () => {
6
+ it('registers with kind: http-stream', () => {
7
+ const procs = Procedures();
8
+ procs.CreateHttpStream('Tail', {
9
+ path: '/streams/logs', method: 'get',
10
+ schema: {
11
+ req: { query: Type.Object({ source: Type.String() }) },
12
+ yield: Type.Object({ line: Type.String() }),
13
+ },
14
+ }, async function* () { yield { line: 'a' }; });
15
+ expect(procs.getProcedure('Tail')?.kind).toBe('http-stream');
16
+ });
17
+ it('yields and returns', async () => {
18
+ const procs = Procedures();
19
+ const { Tail } = procs.CreateHttpStream('Tail', {
20
+ path: '/streams/logs', method: 'get',
21
+ schema: {
22
+ req: { query: Type.Object({ source: Type.String() }) },
23
+ yield: Type.Object({ line: Type.String() }),
24
+ returnType: Type.Object({ totalLines: Type.Number() }),
25
+ },
26
+ }, async function* (_, { query }) {
27
+ yield { line: `from-${query.source}-1` };
28
+ yield { line: `from-${query.source}-2` };
29
+ return { totalLines: 2 };
30
+ });
31
+ const lines = [];
32
+ let returnVal;
33
+ const { stream } = await Tail({}, { query: { source: 'app' } });
34
+ let result = await stream.next();
35
+ while (!result.done) {
36
+ lines.push(result.value.line);
37
+ result = await stream.next();
38
+ }
39
+ returnVal = result.value;
40
+ expect(lines).toEqual(['from-app-1', 'from-app-2']);
41
+ expect(returnVal).toEqual({ totalLines: 2 });
42
+ });
43
+ it('rejects req.query validation error before opening stream', async () => {
44
+ const procs = Procedures();
45
+ const { Tail } = procs.CreateHttpStream('Tail', {
46
+ path: '/streams/logs', method: 'get',
47
+ schema: {
48
+ req: { query: Type.Object({ source: Type.String() }) },
49
+ yield: Type.Object({ line: Type.String() }),
50
+ },
51
+ }, async function* () { yield { line: 'should not run' }; });
52
+ // Two independent async calls — each rejects before a stream is produced.
53
+ await expect(Tail({}, { query: {} })).rejects.toThrow(ProcedureValidationError);
54
+ await expect(Tail({}, { query: {} })).rejects.toThrow(/req\.query/);
55
+ });
56
+ });
57
+ describe('CreateHttpStream async-preamble shape (res.headers)', () => {
58
+ it('handler returning Promise<{ headers, stream }> surfaces headers in initialHeaders', async () => {
59
+ const procs = Procedures();
60
+ const { Tail } = procs.CreateHttpStream('Tail', {
61
+ path: '/streams/logs', method: 'get',
62
+ schema: {
63
+ req: { query: Type.Object({ source: Type.String() }) },
64
+ yield: Type.Object({ line: Type.String() }),
65
+ res: { headers: Type.Object({ 'x-stream-id': Type.String() }) },
66
+ },
67
+ }, async (_, { query }) => ({
68
+ headers: { 'x-stream-id': `id-${query.source}` },
69
+ stream: (async function* () { yield { line: 'a' }; })(),
70
+ }));
71
+ const { stream, initialHeaders } = await Tail({}, { query: { source: 'app' } });
72
+ expect(initialHeaders).toEqual({ 'x-stream-id': 'id-app' });
73
+ const first = await stream.next();
74
+ expect(first.value).toEqual({ line: 'a' });
75
+ });
76
+ it('throws when handler returns malformed shape', async () => {
77
+ const procs = Procedures();
78
+ const { Bad } = procs.CreateHttpStream('Bad', {
79
+ path: '/streams', method: 'get',
80
+ schema: {
81
+ yield: Type.Number(),
82
+ res: { headers: Type.Object({}) },
83
+ },
84
+ }, (async () => 'not-a-shape'));
85
+ await expect(Bad({}, undefined)).rejects.toThrow(/did not resolve to/);
86
+ });
87
+ });
88
+ //# sourceMappingURL=create-http-stream.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-http-stream.test.js","sourceRoot":"","sources":["../src/create-http-stream.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAEtD,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE;QAC1C,MAAM,KAAK,GAAG,UAAU,EAAE,CAAA;QAC1B,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE;YAC7B,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,KAAK;YACpC,MAAM,EAAE;gBACN,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;gBACtD,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;aAC5C;SACF,EAAE,KAAK,SAAS,CAAC,MAAM,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;QAE9C,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAA;IAC9D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,oBAAoB,EAAE,KAAK,IAAI,EAAE;QAClC,MAAM,KAAK,GAAG,UAAU,EAAE,CAAA;QAC1B,M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,CAAC,6CAA6C,EAAE,KAAK,IAAI,EAAE;QAC3D,MAAM,KAAK,GAAG,UAAU,EAAE,CAAA;QAC1B,MAAM,EAAE,GAAG,EAAE,GAAG,KAAK,CAAC,gBAAgB,CAAC,KAAK,EAAE;YAC5C,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK;YAC/B,MAAM,EAAE;gBACN,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE;gBACpB,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;aAClC;SACF,EAAE,CAAC,KAAK,IAAI,EAAE,CAAC,aAAa,CAAQ,CAAC,CAAA;QAEtC,MAAM,MAAM,CAAC,GAAG,CAAC,EAAS,EAAE,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,oBAAoB,CAAC,CAAA;IAC/E,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,49 @@
1
+ import { Prettify, TSchemaLib } from './schema/types.js';
2
+ import { captureDefinitionInfo } from './stack-utils.js';
3
+ import { HttpMethod, TBuilderConfig, TCreateHttpConfig, TLocalContext, THttpProcedureRegistration, THttpStreamProcedureRegistration, TProcedureRegistration, TStreamProcedureRegistration } from './types.js';
4
+ type Infer<T> = TSchemaLib<T>;
5
+ export type HttpReturn<TRes> = TRes extends {
6
+ body: infer B;
7
+ headers: infer H;
8
+ } ? {
9
+ body: Infer<B>;
10
+ headers: Infer<H>;
11
+ } : TRes extends {
12
+ headers: infer H;
13
+ } ? {
14
+ headers: Infer<H>;
15
+ } : TRes extends {
16
+ body: infer B;
17
+ } ? Infer<B> : void;
18
+ export declare function checkPathParamConsistency(procedureName: string, path: string, pathParamsSchema: Record<string, unknown> | undefined, definitionInfo: ReturnType<typeof captureDefinitionInfo>): void;
19
+ export declare function makeCreateHttp<TContext>(procedures: Map<string, TProcedureRegistration<TContext, any> | TStreamProcedureRegistration<TContext, any> | THttpProcedureRegistration<TContext> | THttpStreamProcedureRegistration<TContext>>, builder?: {
20
+ config?: TBuilderConfig;
21
+ onCreate?: (procedure: any) => void;
22
+ }): <TName extends string, TReq extends Record<string, unknown> | undefined, TRes extends {
23
+ body?: unknown;
24
+ headers?: unknown;
25
+ } | undefined = undefined, TErrorKey extends string = string>(name: TName, config: TCreateHttpConfig<TReq, TRes, TErrorKey>, handler: (ctx: Prettify<TContext & TLocalContext>, req: TReq extends Record<string, unknown> ? Prettify<{ [K in keyof TReq]: TSchemaLib<TReq[K]>; }> : undefined) => Promise<HttpReturn<TRes>>) => { [K in TName]: (ctx: Prettify<TContext>, req: TReq extends Record<string, unknown> ? Prettify<{ [K_1 in keyof TReq]: TSchemaLib<TReq[K_1]>; }> : undefined) => Promise<HttpReturn<TRes>>; } & {
26
+ procedure: (ctx: Prettify<TContext>, req: TReq extends Record<string, unknown> ? Prettify<{ [K in keyof TReq]: TSchemaLib<TReq[K]>; }> : undefined) => Promise<HttpReturn<TRes>>;
27
+ info: {
28
+ path: string;
29
+ method: HttpMethod;
30
+ successStatus?: number;
31
+ scope?: string;
32
+ errors?: string[];
33
+ description?: string;
34
+ schema?: {
35
+ req?: Record<string, import("./schema/types.js").TJSONSchema>;
36
+ res?: {
37
+ body?: import("./schema/types.js").TJSONSchema;
38
+ headers?: import("./schema/types.js").TJSONSchema;
39
+ };
40
+ };
41
+ validation?: {
42
+ req?: Record<string, (value: any) => {
43
+ errors?: any[];
44
+ }>;
45
+ };
46
+ name: TName;
47
+ };
48
+ };
49
+ export {};
@@ -0,0 +1,108 @@
1
+ import { ProcedureError, ProcedureRegistrationError, ProcedureValidationError } from './errors.js';
2
+ import { computeSchema } from './schema/compute-schema.js';
3
+ import { captureDefinitionInfo } from './stack-utils.js';
4
+ const PATH_PARAM_RE = /:([a-zA-Z_][a-zA-Z0-9_]*)/g;
5
+ function extractPathParamNames(path) {
6
+ const matches = path.match(PATH_PARAM_RE);
7
+ return matches ? matches.map((m) => m.slice(1)) : [];
8
+ }
9
+ export function checkPathParamConsistency(procedureName, path, pathParamsSchema, definitionInfo) {
10
+ const pathParamNames = extractPathParamNames(path);
11
+ const hasPathParams = pathParamNames.length > 0;
12
+ const hasSchema = pathParamsSchema !== undefined;
13
+ if (hasPathParams && !hasSchema) {
14
+ throw new ProcedureRegistrationError(procedureName, `Path "${path}" has path parameters [${pathParamNames.join(', ')}] but schema.req.pathParams is not defined.`, definitionInfo);
15
+ }
16
+ if (!hasPathParams && hasSchema) {
17
+ throw new ProcedureRegistrationError(procedureName, `schema.req.pathParams is defined but path "${path}" has no path parameters.`, definitionInfo);
18
+ }
19
+ if (hasPathParams && hasSchema) {
20
+ const schemaProperties = pathParamsSchema.properties;
21
+ if (schemaProperties) {
22
+ const schemaKeys = Object.keys(schemaProperties);
23
+ const missing = pathParamNames.filter((p) => !schemaKeys.includes(p));
24
+ const extra = schemaKeys.filter((k) => !pathParamNames.includes(k));
25
+ if (missing.length > 0 || extra.length > 0) {
26
+ const parts = [];
27
+ if (missing.length > 0)
28
+ parts.push(`path has [${missing.join(', ')}] missing from schema`);
29
+ if (extra.length > 0)
30
+ parts.push(`schema has [${extra.join(', ')}] not in path`);
31
+ throw new ProcedureRegistrationError(procedureName, `Path param mismatch for "${procedureName}": ${parts.join('; ')}.`, definitionInfo);
32
+ }
33
+ }
34
+ }
35
+ }
36
+ export function makeCreateHttp(procedures, builder) {
37
+ return function CreateHttp(name, config, handler) {
38
+ const definitionInfo = captureDefinitionInfo();
39
+ if (procedures.has(name)) {
40
+ throw new Error(`Procedure with name ${name} is already registered`);
41
+ }
42
+ if (config.schema?.params) {
43
+ throw new ProcedureRegistrationError(name, `Use schema.req.body (or schema.req.query) instead of schema.params on CreateHttp. Procedure: "${name}".`, definitionInfo);
44
+ }
45
+ const { jsonSchema, validations } = computeSchema(name, {
46
+ req: config.schema.req,
47
+ res: config.schema.res,
48
+ }, definitionInfo);
49
+ const pathParamsSchema = jsonSchema.req?.pathParams;
50
+ checkPathParamConsistency(name, config.path, pathParamsSchema, definitionInfo);
51
+ const errorFactory = (message, meta) => new ProcedureError(name, message, meta, definitionInfo);
52
+ const registeredProcedure = {
53
+ name,
54
+ kind: 'http',
55
+ config: {
56
+ path: config.path,
57
+ method: config.method,
58
+ successStatus: config.successStatus,
59
+ scope: config.scope,
60
+ errors: config.errors,
61
+ description: config.description,
62
+ schema: jsonSchema,
63
+ validation: { req: validations.req },
64
+ },
65
+ handler: async (ctx, req) => {
66
+ try {
67
+ const skipValidation = ctx.isPrevalidated ||
68
+ builder?.config?.noRuntimeValidation;
69
+ if (validations?.req && !skipValidation) {
70
+ for (const [channel, validator] of Object.entries(validations.req)) {
71
+ const channelValue = req?.[channel];
72
+ const { errors } = validator(channelValue);
73
+ if (errors) {
74
+ throw new ProcedureValidationError(name, `Validation error for ${name} in req.${channel}`, errors, definitionInfo);
75
+ }
76
+ }
77
+ }
78
+ const localCtx = { error: errorFactory };
79
+ return await handler({ ...ctx, ...localCtx }, req);
80
+ }
81
+ catch (error) {
82
+ if (error instanceof ProcedureError)
83
+ throw error;
84
+ const err = new ProcedureError(name, `Error in handler for ${name} - ${error?.message}`, undefined, definitionInfo);
85
+ err.cause = error;
86
+ if (error.stack && definitionInfo.definedAt) {
87
+ const { file, line, column } = definitionInfo.definedAt;
88
+ err.stack =
89
+ error.stack + `\n--- Procedure "${name}" defined at ---\n at ${file}:${line}:${column}`;
90
+ }
91
+ else if (error.stack) {
92
+ err.stack = error.stack;
93
+ }
94
+ throw err;
95
+ }
96
+ },
97
+ };
98
+ procedures.set(name, registeredProcedure);
99
+ builder?.onCreate?.(registeredProcedure);
100
+ const info = { name, ...registeredProcedure.config };
101
+ return {
102
+ [name]: registeredProcedure.handler,
103
+ procedure: registeredProcedure.handler,
104
+ info,
105
+ };
106
+ };
107
+ }
108
+ //# sourceMappingURL=create-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-http.js","sourceRoot":"","sources":["../src/create-http.ts"],"names":[],"mappings":"AAAA,OAAO,EAA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oBACzB,CAAC;oBACD,MAAM,GAAG,CAAA;gBACX,CAAC;YACH,CAAC;SACF,CAAA;QAED,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,mBAA0B,CAAC,CAAA;QAChD,OAAO,EAAE,QAAQ,EAAE,CAAC,mBAAmB,CAAC,CAAA;QAExC,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,GAAG,mBAAmB,CAAC,MAAM,EAAE,CAAA;QAEpD,OAAO;YACL,CAAC,IAAI,CAAC,EAAE,mBAAmB,CAAC,OAAO;YACnC,SAAS,EAAE,mBAAmB,CAAC,OAAO;YACtC,IAAI;SAYL,CAAA;IACH,CAAC,CAAA;AACH,CAAC"}
@@ -0,0 +1,137 @@
1
+ import { describe, it, expect, expectTypeOf } from 'vitest';
2
+ import { Procedures } from './index.js';
3
+ import { ProcedureValidationError } from './errors.js';
4
+ import { Type } from 'typebox';
5
+ describe('CreateHttp registration', () => {
6
+ it('registers with kind: http', () => {
7
+ const procs = Procedures();
8
+ procs.CreateHttp('GetUser', {
9
+ path: '/users/:id',
10
+ method: 'get',
11
+ schema: { req: { pathParams: Type.Object({ id: Type.String() }) } },
12
+ }, async (_, { pathParams }) => ({ id: pathParams.id }));
13
+ const reg = procs.getProcedure('GetUser');
14
+ expect(reg?.kind).toBe('http');
15
+ });
16
+ it('rejects schema.params with v8 message', () => {
17
+ const procs = Procedures();
18
+ expect(() => procs.CreateHttp('Bad', {
19
+ path: '/x', method: 'get',
20
+ schema: { params: Type.Object({}) },
21
+ }, async () => undefined)).toThrow(/Use schema.req.body \(or schema.req.query\) instead of schema.params/);
22
+ });
23
+ it('rejects path with params but no pathParams schema', () => {
24
+ const procs = Procedures();
25
+ expect(() => procs.CreateHttp('Bad', {
26
+ path: '/users/:id', method: 'get',
27
+ schema: { req: {} },
28
+ }, async () => undefined)).toThrow(/path parameters \[id\] but schema.req.pathParams is not defined/);
29
+ });
30
+ it('rejects pathParams schema with no path params', () => {
31
+ const procs = Procedures();
32
+ expect(() => procs.CreateHttp('Bad', {
33
+ path: '/users', method: 'get',
34
+ schema: { req: { pathParams: Type.Object({ id: Type.String() }) } },
35
+ }, async () => undefined)).toThrow(/has no path parameters/);
36
+ });
37
+ it('rejects pathParams key mismatch', () => {
38
+ const procs = Procedures();
39
+ expect(() => procs.CreateHttp('Bad', {
40
+ path: '/users/:id', method: 'get',
41
+ schema: { req: { pathParams: Type.Object({ wrongKey: Type.String() }) } },
42
+ }, async () => undefined)).toThrow(/Path param mismatch/);
43
+ });
44
+ });
45
+ describe('CreateHttp res.body', () => {
46
+ it('handler returns body bare when only res.body declared', async () => {
47
+ const procs = Procedures();
48
+ const { GetUser } = procs.CreateHttp('GetUser', {
49
+ path: '/users/:id', method: 'get',
50
+ schema: {
51
+ req: { pathParams: Type.Object({ id: Type.String() }) },
52
+ res: { body: Type.Object({ id: Type.String(), name: Type.String() }) },
53
+ },
54
+ }, async (_, { pathParams }) => ({ id: pathParams.id, name: 'Alice' }));
55
+ const result = await GetUser({}, { pathParams: { id: '1' } });
56
+ expect(result).toEqual({ id: '1', name: 'Alice' });
57
+ });
58
+ });
59
+ describe('CreateHttp conditional return shape', () => {
60
+ it('res: { body, headers } → returns { body, headers }', async () => {
61
+ const procs = Procedures();
62
+ const { GetUser } = procs.CreateHttp('GetUser', {
63
+ path: '/users/:id', method: 'get',
64
+ schema: {
65
+ req: { pathParams: Type.Object({ id: Type.String() }) },
66
+ res: {
67
+ body: Type.Object({ id: Type.String() }),
68
+ headers: Type.Object({ 'x-rate-limit': Type.String() }),
69
+ },
70
+ },
71
+ }, async (_, { pathParams }) => ({
72
+ body: { id: pathParams.id },
73
+ headers: { 'x-rate-limit': '99' },
74
+ }));
75
+ const result = await GetUser({}, { pathParams: { id: '1' } });
76
+ expect(result).toEqual({ body: { id: '1' }, headers: { 'x-rate-limit': '99' } });
77
+ });
78
+ it('res: { headers } only → returns { headers }', async () => {
79
+ const procs = Procedures();
80
+ const { Healthcheck } = procs.CreateHttp('Healthcheck', {
81
+ path: '/health', method: 'get',
82
+ schema: {
83
+ res: { headers: Type.Object({ 'x-version': Type.String() }) },
84
+ },
85
+ }, async () => ({ headers: { 'x-version': '8.0.0' } }));
86
+ const result = await Healthcheck({}, undefined);
87
+ expect(result).toEqual({ headers: { 'x-version': '8.0.0' } });
88
+ });
89
+ it('no res → returns void', async () => {
90
+ const procs = Procedures();
91
+ const { Ping } = procs.CreateHttp('Ping', {
92
+ path: '/ping', method: 'post',
93
+ schema: { req: { body: Type.Object({}) } },
94
+ }, async () => undefined);
95
+ const result = await Ping({}, { body: {} });
96
+ expect(result).toBeUndefined();
97
+ });
98
+ });
99
+ describe('CreateHttp HttpReturn type inference', () => {
100
+ it('infers correct return shapes', () => {
101
+ const procs = Procedures();
102
+ const { GetUser } = procs.CreateHttp('GetUser', {
103
+ path: '/users/:id', method: 'get',
104
+ schema: {
105
+ req: { pathParams: Type.Object({ id: Type.String() }) },
106
+ res: {
107
+ body: Type.Object({ id: Type.String() }),
108
+ headers: Type.Object({ 'x-rate-limit': Type.String() }),
109
+ },
110
+ },
111
+ }, async () => ({ body: { id: '1' }, headers: { 'x-rate-limit': '99' } }));
112
+ expectTypeOf().toEqualTypeOf();
113
+ });
114
+ });
115
+ describe('CreateHttp req channel validation', () => {
116
+ it('validates each channel independently with channel-tagged error', async () => {
117
+ const procs = Procedures();
118
+ const { GetUser } = procs.CreateHttp('GetUser', {
119
+ path: '/users/:id', method: 'get',
120
+ schema: {
121
+ req: {
122
+ pathParams: Type.Object({ id: Type.String() }),
123
+ query: Type.Object({ limit: Type.Number() }),
124
+ },
125
+ },
126
+ }, async (_, { pathParams, query }) => ({ id: pathParams.id, limit: query.limit }));
127
+ await expect(GetUser({}, {
128
+ pathParams: { id: 'abc' },
129
+ query: { limit: 'not-a-number' },
130
+ })).rejects.toThrow(ProcedureValidationError);
131
+ await expect(GetUser({}, {
132
+ pathParams: { id: 'abc' },
133
+ query: { limit: 'not-a-number' },
134
+ })).rejects.toThrow(/req\.query/);
135
+ });
136
+ });
137
+ //# sourceMappingURL=create-http.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-http.test.js","sourceRoot":"","sources":["../src/create-http.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAA;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAA8B,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAClF,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAE9B,QAAQ,CAAC,yBAAyB,EAAE,GAAG,EAAE;IACvC,EAAE,CAAC,2BAA2B,EAAE,GAAG,EAAE;QACnC,MAAM,KAAK,GAAG,UAAU,EAAE,CAAA;QAC1B,KAAK,CAAC,UAAU,CAAC,SAAS,EAAE;YAC1B,IAAI,EAAE,YAAY;YAClB,MAAM,EAAE,KAAK;YACb,MAAM,EAAE,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE;SACpE,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,CAAQ,CAAC,CAAA;QAE/D,MAAM,GAAG,GAAG,KAAK,CAAC,YAAY,CAAC,SAAS,CAAC,CAAA;QACzC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAChC,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE;QAC/C,MAAM,KAAK,GAAG,UAAU,EAAE,CAAA;QAC1B,MAAM,CAAC,GAAG,EAAE,CACV,KAAK,CAAC,UAAU,CAAC,KAAK,EAAE;YACtB,IAAI,EAAE,IAAI,EAAE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EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;oBAC9C,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC;iBAC7C;aACF;SACF,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE,CAAQ,CAAC,CAAA;QAE1F,MAAM,MAAM,CAAC,OAAO,CAAC,EAAS,EAAE;YAC9B,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE;YACzB,KAAK,EAAE,EAAE,KAAK,EAAE,cAAqB,EAAE;SACxC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAA;QAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,EAAS,EAAE;YAC9B,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE;YACzB,KAAK,EAAE,EAAE,KAAK,EAAE,cAAqB,EAAE;SACxC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,35 @@
1
+ import { Prettify, TSchemaLib } from './schema/types.js';
2
+ import { TBuilderConfig, THttpProcedureRegistration, THttpStreamProcedureRegistration, TStreamContext, TProcedureRegistration, TStreamProcedureRegistration } from './types.js';
3
+ export type CreateStreamBuilderArg<TContext, TExtendedConfig> = {
4
+ config?: TBuilderConfig;
5
+ onCreate?: (procedure: TProcedureRegistration<TContext, TExtendedConfig> | TStreamProcedureRegistration<TContext, TExtendedConfig>) => void;
6
+ };
7
+ export declare function makeCreateStream<TContext, TExtendedConfig>(procedures: Map<string, TProcedureRegistration<TContext, TExtendedConfig> | TStreamProcedureRegistration<TContext, TExtendedConfig> | THttpProcedureRegistration<TContext> | THttpStreamProcedureRegistration<TContext>>, builder?: CreateStreamBuilderArg<TContext, TExtendedConfig>): <TName extends string, TParams, TYieldType, TReturnType = void>(name: TName, config: {
8
+ description?: string;
9
+ schema?: {
10
+ params?: TParams;
11
+ yieldType?: TYieldType;
12
+ returnType?: TReturnType;
13
+ };
14
+ validateYields?: boolean;
15
+ } & TExtendedConfig, handler: (ctx: Prettify<TContext & TStreamContext>, params: TSchemaLib<TParams>) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>) => { [K in TName]: (ctx: Prettify<TContext>, params: TSchemaLib<TParams>) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>; } & {
16
+ procedure: (ctx: Prettify<TContext>, params: TSchemaLib<TParams>) => AsyncGenerator<TSchemaLib<TYieldType>, TSchemaLib<TReturnType> | void, unknown>;
17
+ info: {
18
+ name: TName;
19
+ isStream: true;
20
+ description?: string;
21
+ schema: {
22
+ params?: TParams;
23
+ yieldType?: TYieldType;
24
+ returnType?: TReturnType;
25
+ };
26
+ validation?: {
27
+ params?: (params: any) => {
28
+ errors?: any[];
29
+ };
30
+ yield?: (value: any) => {
31
+ errors?: any[];
32
+ };
33
+ };
34
+ } & TExtendedConfig;
35
+ };
@@ -0,0 +1,123 @@
1
+ import { ProcedureError, ProcedureRegistrationError, ProcedureValidationError, ProcedureYieldValidationError } from './errors.js';
2
+ import { computeSchema } from './schema/compute-schema.js';
3
+ import { captureDefinitionInfo } from './stack-utils.js';
4
+ export function makeCreateStream(procedures, builder) {
5
+ return function CreateStream(name, config, handler) {
6
+ // Capture definition location as first action
7
+ const definitionInfo = captureDefinitionInfo();
8
+ const HTTP_FIELDS = ['path', 'method', 'req', 'res', 'successStatus'];
9
+ const presentHttpFields = HTTP_FIELDS.filter((f) => config[f] !== undefined);
10
+ if (presentHttpFields.length > 0) {
11
+ throw new ProcedureRegistrationError(name, `HTTP fields require CreateHttp / CreateHttpStream. Procedure "${name}" has [${presentHttpFields.join(', ')}] which are not valid on CreateStream.`, definitionInfo);
12
+ }
13
+ // BEFORE computeSchema - fail fast on duplicate
14
+ if (procedures.has(name)) {
15
+ throw new Error(`Procedure with name ${name} is already registered`);
16
+ }
17
+ const { jsonSchema, validations } = computeSchema(name, config.schema, definitionInfo);
18
+ // Create error factory once at registration time (outside handler)
19
+ const errorFactory = (message, meta) => {
20
+ return new ProcedureError(name, message, meta, definitionInfo);
21
+ };
22
+ const validateYields = config.validateYields ?? false;
23
+ const registeredProcedure = {
24
+ name,
25
+ kind: 'rpc-stream',
26
+ isStream: true,
27
+ config: {
28
+ ...config,
29
+ description: config.description,
30
+ schema: jsonSchema,
31
+ validation: {
32
+ params: validations.params,
33
+ yield: validations.yield,
34
+ },
35
+ },
36
+ handler: async function* wrappedHandler(ctx, params) {
37
+ // Create abort controller for this stream
38
+ const abortController = new AbortController();
39
+ // Skip validation if caller has already validated (e.g., HonoAppBuilder) or if builder config dictates noRuntimeValidation
40
+ const skipValidation = ctx.isPrevalidated ||
41
+ builder?.config?.noRuntimeValidation;
42
+ if (validations?.params && !skipValidation) {
43
+ const { errors } = validations.params(params);
44
+ if (errors) {
45
+ throw new ProcedureValidationError(name, `Validation error for ${name}`, errors, definitionInfo);
46
+ }
47
+ }
48
+ // Combine with external signal (e.g., from HTTP request) if provided
49
+ const incomingSignal = ctx.signal;
50
+ const signal = incomingSignal
51
+ ? AbortSignal.any([incomingSignal, abortController.signal])
52
+ : abortController.signal;
53
+ const streamCtx = {
54
+ error: errorFactory,
55
+ signal,
56
+ };
57
+ // params is correctly typed at the public API boundary via conditional type;
58
+ // cast here because TS cannot narrow conditional generics inside implementations
59
+ const userGenerator = handler({
60
+ ...ctx,
61
+ ...streamCtx,
62
+ }, params);
63
+ const userIterator = userGenerator[Symbol.asyncIterator]();
64
+ try {
65
+ let userIterResult = await userIterator.next();
66
+ while (!userIterResult.done) {
67
+ const value = userIterResult.value;
68
+ // Only validate if explicitly enabled via validateYields: true
69
+ if (validateYields && validations.yield) {
70
+ const { errors } = validations.yield(value);
71
+ if (errors) {
72
+ throw new ProcedureYieldValidationError(name, `Yield validation error for ${name}`, errors, definitionInfo);
73
+ }
74
+ }
75
+ yield value;
76
+ userIterResult = await userIterator.next();
77
+ }
78
+ // Propagate the generator's return value so consumers (e.g. HonoAppBuilder)
79
+ // can send it as a special 'return' SSE event
80
+ return userIterResult.value;
81
+ }
82
+ catch (error) {
83
+ // Preserve the original error class so HTTP builders' taxonomies and
84
+ // `onMidStreamError` callbacks see the actual thrown type — boxing
85
+ // user-defined errors inside ProcedureError defeats route-declared
86
+ // typed-error dispatch on the client. Augment the stack trace in
87
+ // place with the procedure's definition site when available.
88
+ if (definitionInfo.definedAt && error && typeof error.stack === 'string') {
89
+ const { file, line, column } = definitionInfo.definedAt;
90
+ error.stack = `${error.stack}\n--- Procedure "${name}" defined at ---\n at ${file}:${line}:${column}`;
91
+ }
92
+ throw error;
93
+ }
94
+ finally {
95
+ // Propagate `.return()` to the user generator so its `finally`
96
+ // blocks (and any `signal`-driven cleanup) run when the consumer
97
+ // closes the stream early. No-op when iteration already completed.
98
+ try {
99
+ await userIterator.return?.(undefined);
100
+ }
101
+ catch {
102
+ // Swallow — cleanup must not mask the primary error path
103
+ }
104
+ abortController.abort('stream-completed');
105
+ }
106
+ },
107
+ };
108
+ procedures.set(name, registeredProcedure);
109
+ builder?.onCreate?.(registeredProcedure);
110
+ const info = {
111
+ name,
112
+ isStream: true,
113
+ ...registeredProcedure.config,
114
+ };
115
+ // return so can be called directly (ie: int/unit tests)
116
+ return {
117
+ [name]: registeredProcedure.handler,
118
+ procedure: registeredProcedure.handler,
119
+ info,
120
+ };
121
+ };
122
+ }
123
+ //# sourceMappingURL=create-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-stream.js","sourceRoot":"","sources":["../src/create-stream.ts"],"names":[],"mappings":"AAAA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