@workerstack/clients 1.0.0-rc.28 → 1.0.0-rc.30

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 (368) hide show
  1. package/README.md +403 -21
  2. package/assets/installers/examples/github.config.ts +17 -19
  3. package/assets/installers/examples/goreleaser.config.ts +16 -18
  4. package/assets/installers/examples/raw.config.ts +13 -15
  5. package/bin/clients.js +87 -66
  6. package/bin/installgen.js +19 -10
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +18 -12
  9. package/dist/emit/cli/channels.d.ts +2 -2
  10. package/dist/emit/cli/channels.js +18 -13
  11. package/dist/emit/cli/commands.d.ts +1 -1
  12. package/dist/emit/cli/commands.js +39 -13
  13. package/dist/emit/cli/discovery.d.ts +0 -6
  14. package/dist/emit/cli/discovery.js +9 -7
  15. package/dist/emit/cli/flags.d.ts +1 -3
  16. package/dist/emit/cli/flags.js +18 -8
  17. package/dist/emit/cli/install.d.ts +0 -8
  18. package/dist/emit/cli/install.js +3 -3
  19. package/dist/emit/cli/layout.d.ts +1 -1
  20. package/dist/emit/cli/layout.js +13 -10
  21. package/dist/emit/cli/module.d.ts +6 -6
  22. package/dist/emit/cli/module.js +10 -10
  23. package/dist/emit/cli/release.d.ts +0 -11
  24. package/dist/emit/cli/release.js +4 -4
  25. package/dist/emit/cli/skills.js +8 -4
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.d.ts +1 -8
  29. package/dist/emit/csharp/realtime.js +26 -26
  30. package/dist/emit/csharp/sdk-answer.d.ts +10 -2
  31. package/dist/emit/csharp/sdk-answer.js +4 -4
  32. package/dist/emit/csharp/sdk-body.js +8 -6
  33. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  34. package/dist/emit/csharp/sdk-client.js +2 -2
  35. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  36. package/dist/emit/csharp/sdk-csproj.js +10 -10
  37. package/dist/emit/csharp/sdk-doc.js +1 -1
  38. package/dist/emit/csharp/sdk-method.d.ts +0 -1
  39. package/dist/emit/csharp/sdk-method.js +19 -8
  40. package/dist/emit/csharp/sdk-plan.js +0 -1
  41. package/dist/emit/csharp/sdk.js +3 -3
  42. package/dist/emit/csharp/sse.d.ts +0 -13
  43. package/dist/emit/csharp/sse.js +92 -11
  44. package/dist/emit/csharp/transport.js +9 -9
  45. package/dist/emit/csharp/types-enum.js +3 -1
  46. package/dist/emit/csharp/types-messages.d.ts +47 -0
  47. package/dist/emit/csharp/types-messages.js +172 -0
  48. package/dist/emit/csharp/types-names.js +13 -14
  49. package/dist/emit/csharp/types-record.js +3 -3
  50. package/dist/emit/csharp/types-union.d.ts +1 -1
  51. package/dist/emit/csharp/types.d.ts +0 -1
  52. package/dist/emit/csharp/types.js +3 -3
  53. package/dist/emit/csharp/ws.d.ts +0 -15
  54. package/dist/emit/csharp/ws.js +26 -5
  55. package/dist/emit/go/errors.js +1 -1
  56. package/dist/emit/go/http.js +2 -2
  57. package/dist/emit/go/module-path.js +2 -2
  58. package/dist/emit/go/sdk-answer.d.ts +24 -1
  59. package/dist/emit/go/sdk-answer.js +1 -1
  60. package/dist/emit/go/sdk-body.js +11 -7
  61. package/dist/emit/go/sdk-client.js +1 -1
  62. package/dist/emit/go/sdk-method.d.ts +3 -0
  63. package/dist/emit/go/sdk-method.js +18 -12
  64. package/dist/emit/go/sdk-mirror.js +2 -2
  65. package/dist/emit/go/sdk-opts.d.ts +0 -2
  66. package/dist/emit/go/sdk-opts.js +3 -3
  67. package/dist/emit/go/sdk.d.ts +1 -1
  68. package/dist/emit/go/sdk.js +9 -9
  69. package/dist/emit/go/sse.d.ts +2 -10
  70. package/dist/emit/go/sse.js +88 -13
  71. package/dist/emit/go/types-names.js +5 -0
  72. package/dist/emit/go/types-struct.d.ts +2 -1
  73. package/dist/emit/go/types-struct.js +1 -1
  74. package/dist/emit/go/types-union.d.ts +3 -2
  75. package/dist/emit/go/types-union.js +2 -0
  76. package/dist/emit/go/types.d.ts +6 -0
  77. package/dist/emit/go/types.js +20 -9
  78. package/dist/emit/go/ws.d.ts +4 -11
  79. package/dist/emit/go/ws.js +215 -59
  80. package/dist/emit/java/gradle.d.ts +7 -9
  81. package/dist/emit/java/gradle.js +8 -8
  82. package/dist/emit/java/json.d.ts +3 -0
  83. package/dist/emit/java/json.js +1 -1
  84. package/dist/emit/java/layout-ast.d.ts +4 -1
  85. package/dist/emit/java/layout-ast.js +1 -1
  86. package/dist/emit/java/layout-decl.js +5 -4
  87. package/dist/emit/java/layout-doc.js +13 -7
  88. package/dist/emit/java/layout-dot.js +1 -1
  89. package/dist/emit/java/layout-strings.js +4 -5
  90. package/dist/emit/java/layout-types.js +7 -5
  91. package/dist/emit/java/layout-visitor.js +4 -3
  92. package/dist/emit/java/layout.js +5 -4
  93. package/dist/emit/java/models-names.d.ts +2 -0
  94. package/dist/emit/java/models-names.js +6 -4
  95. package/dist/emit/java/models-record.d.ts +0 -1
  96. package/dist/emit/java/models-record.js +3 -3
  97. package/dist/emit/java/models-union.d.ts +13 -2
  98. package/dist/emit/java/models-union.js +12 -6
  99. package/dist/emit/java/models.d.ts +5 -1
  100. package/dist/emit/java/models.js +44 -20
  101. package/dist/emit/java/realtime.d.ts +34 -26
  102. package/dist/emit/java/realtime.js +45 -10
  103. package/dist/emit/java/sdk-client.d.ts +6 -6
  104. package/dist/emit/java/sdk-client.js +1 -1
  105. package/dist/emit/java/sdk-decl.js +2 -2
  106. package/dist/emit/java/sdk-errors.js +1 -1
  107. package/dist/emit/java/sdk-headers.js +2 -2
  108. package/dist/emit/java/sdk-mirror.js +7 -6
  109. package/dist/emit/java/sdk-models.d.ts +1 -1
  110. package/dist/emit/java/sdk-models.js +7 -7
  111. package/dist/emit/java/sdk-op.d.ts +1 -10
  112. package/dist/emit/java/sdk-op.js +9 -9
  113. package/dist/emit/java/sdk-params.d.ts +5 -5
  114. package/dist/emit/java/sdk-params.js +3 -2
  115. package/dist/emit/java/sdk-plan.js +0 -1
  116. package/dist/emit/java/sdk.d.ts +1 -1
  117. package/dist/emit/java/sdk.js +14 -13
  118. package/dist/emit/java/sse.d.ts +12 -13
  119. package/dist/emit/java/sse.js +105 -6
  120. package/dist/emit/java/ws.d.ts +48 -9
  121. package/dist/emit/java/ws.js +88 -4
  122. package/dist/emit/mcp/annotations.js +8 -4
  123. package/dist/emit/mcp/files.js +9 -9
  124. package/dist/emit/mcp/mounted.js +2 -2
  125. package/dist/emit/mcp/output-schema.d.ts +4 -2
  126. package/dist/emit/mcp/output-schema.js +58 -14
  127. package/dist/emit/mcp/registry.d.ts +0 -2
  128. package/dist/emit/mcp/registry.js +5 -4
  129. package/dist/emit/mcp/runtime.js +2 -2
  130. package/dist/emit/mcp/schema.js +22 -11
  131. package/dist/emit/mcp/server.d.ts +7 -7
  132. package/dist/emit/mcp/server.js +7 -6
  133. package/dist/emit/mcp/tools.js +7 -6
  134. package/dist/emit/python/errors.js +3 -3
  135. package/dist/emit/python/realtime.d.ts +9 -6
  136. package/dist/emit/python/realtime.js +22 -20
  137. package/dist/emit/python/sdk-answer.d.ts +8 -8
  138. package/dist/emit/python/sdk-answer.js +2 -2
  139. package/dist/emit/python/sdk-body.js +4 -5
  140. package/dist/emit/python/sdk-client.js +5 -5
  141. package/dist/emit/python/sdk-doc.js +2 -2
  142. package/dist/emit/python/sdk-method.d.ts +1 -1
  143. package/dist/emit/python/sdk-method.js +38 -11
  144. package/dist/emit/python/sdk-plan.js +0 -1
  145. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  146. package/dist/emit/python/sdk-pyproject.js +8 -8
  147. package/dist/emit/python/sdk.d.ts +1 -1
  148. package/dist/emit/python/sdk.js +28 -8
  149. package/dist/emit/python/sse.d.ts +0 -7
  150. package/dist/emit/python/sse.js +36 -6
  151. package/dist/emit/python/transport.js +4 -4
  152. package/dist/emit/python/types-dict.d.ts +2 -2
  153. package/dist/emit/python/types-dict.js +1 -1
  154. package/dist/emit/python/types-names.js +2 -2
  155. package/dist/emit/python/types-union.js +1 -1
  156. package/dist/emit/python/types.d.ts +7 -0
  157. package/dist/emit/python/types.js +23 -6
  158. package/dist/emit/python/ws.d.ts +21 -10
  159. package/dist/emit/python/ws.js +69 -3
  160. package/dist/emit/rust/errors.js +3 -3
  161. package/dist/emit/rust/http.js +4 -4
  162. package/dist/emit/rust/realtime.d.ts +7 -5
  163. package/dist/emit/rust/realtime.js +15 -18
  164. package/dist/emit/rust/sdk-body.js +8 -5
  165. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  166. package/dist/emit/rust/sdk-cargo.js +12 -12
  167. package/dist/emit/rust/sdk-client.d.ts +1 -1
  168. package/dist/emit/rust/sdk-client.js +3 -3
  169. package/dist/emit/rust/sdk-method.js +3 -3
  170. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  171. package/dist/emit/rust/sdk-opts.js +2 -2
  172. package/dist/emit/rust/sdk-plan.js +0 -1
  173. package/dist/emit/rust/sdk.d.ts +1 -1
  174. package/dist/emit/rust/sdk.js +5 -5
  175. package/dist/emit/rust/sse.d.ts +11 -12
  176. package/dist/emit/rust/sse.js +54 -8
  177. package/dist/emit/rust/types-names.js +3 -3
  178. package/dist/emit/rust/types-struct.js +1 -1
  179. package/dist/emit/rust/types-union.d.ts +10 -2
  180. package/dist/emit/rust/types-union.js +4 -0
  181. package/dist/emit/rust/types.d.ts +9 -0
  182. package/dist/emit/rust/types.js +20 -12
  183. package/dist/emit/rust/ws.d.ts +22 -15
  184. package/dist/emit/rust/ws.js +60 -10
  185. package/dist/emit/shared/escape.js +17 -17
  186. package/dist/emit/shared/format.js +1 -1
  187. package/dist/emit/shared/gofmt.js +1 -1
  188. package/dist/emit/shared/lang.js +10 -10
  189. package/dist/emit/shared/literals.d.ts +5 -0
  190. package/dist/emit/shared/literals.js +8 -0
  191. package/dist/emit/shared/metadata.d.ts +0 -6
  192. package/dist/emit/shared/metadata.js +8 -7
  193. package/dist/emit/shared/ruff.js +1 -1
  194. package/dist/emit/shared/rustfmt.js +1 -1
  195. package/dist/emit/shared/type-emitter.js +37 -20
  196. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  197. package/dist/emit/shared/unknown-type.constants.js +2 -0
  198. package/dist/emit/ts/http.d.ts +0 -2
  199. package/dist/emit/ts/http.js +4 -4
  200. package/dist/emit/ts/package.d.ts +14 -12
  201. package/dist/emit/ts/package.js +9 -8
  202. package/dist/emit/ts/route-tree.js +2 -2
  203. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  204. package/dist/emit/ts/sdk-types-preamble.js +6 -2
  205. package/dist/emit/ts/sdk-types.js +59 -20
  206. package/dist/emit/ts/sdk.js +6 -6
  207. package/dist/emit/ts/service-map.d.ts +10 -3
  208. package/dist/emit/ts/service-map.js +30 -2
  209. package/dist/emit/ts/tanstack-query.js +6 -6
  210. package/dist/emit/ts/type-gen.js +36 -21
  211. package/dist/emit/ts/webhooks.d.ts +0 -2
  212. package/dist/emit/ts/webhooks.js +3 -3
  213. package/dist/extract/chain.js +5 -4
  214. package/dist/extract/extract.js +5 -5
  215. package/dist/extract/serialize.d.ts +0 -2
  216. package/dist/extract/serialize.js +14 -15
  217. package/dist/extract/walk.js +15 -12
  218. package/dist/gen/args.js +9 -5
  219. package/dist/gen/formatters.js +5 -3
  220. package/dist/gen/shipped.js +2 -2
  221. package/dist/gen/targets.d.ts +2 -4
  222. package/dist/gen/targets.js +8 -4
  223. package/dist/gen/write.js +4 -2
  224. package/dist/index.js +2 -2
  225. package/dist/installers/cli.d.ts +4 -4
  226. package/dist/installers/cli.js +24 -24
  227. package/dist/installers/commands/build.d.ts +4 -4
  228. package/dist/installers/commands/build.js +2 -3
  229. package/dist/installers/commands/check.d.ts +2 -2
  230. package/dist/installers/commands/check.js +11 -10
  231. package/dist/installers/commands/init.d.ts +2 -2
  232. package/dist/installers/commands/init.js +1 -2
  233. package/dist/installers/config/define-config.d.ts +16 -16
  234. package/dist/installers/config/define-config.js +1 -1
  235. package/dist/installers/config/hooks/bun.d.ts +6 -6
  236. package/dist/installers/config/hooks/node.js +1 -1
  237. package/dist/installers/config/load.d.ts +6 -8
  238. package/dist/installers/config/load.js +7 -8
  239. package/dist/installers/config/resolve.d.ts +1 -2
  240. package/dist/installers/config/resolve.js +28 -33
  241. package/dist/installers/config/types.d.ts +6 -6
  242. package/dist/installers/config/types.js +0 -1
  243. package/dist/installers/render/quote.js +3 -5
  244. package/dist/installers/render/render.d.ts +6 -6
  245. package/dist/installers/render/render.js +26 -26
  246. package/dist/installers/ui.d.ts +4 -4
  247. package/dist/installers/ui.js +3 -3
  248. package/dist/ir/build.d.ts +3 -3
  249. package/dist/ir/build.js +12 -5
  250. package/dist/ir/load.js +9 -10
  251. package/dist/ir/model.d.ts +16 -1
  252. package/dist/ir/model.js +0 -1
  253. package/dist/ir/resolve-refs.js +2 -2
  254. package/dist/ir/resource-tree.js +2 -1
  255. package/dist/ir/route-tree-intern.js +1 -1
  256. package/dist/ir/schema.js +3 -3
  257. package/dist/ir/sdk-model.d.ts +25 -1
  258. package/dist/ir/sdk-model.js +38 -8
  259. package/dist/ir/slots.d.ts +1 -1
  260. package/dist/ir/slots.js +22 -11
  261. package/dist/ir/streams.d.ts +16 -0
  262. package/dist/ir/streams.js +40 -0
  263. package/dist/release/bootstrap.d.ts +3 -3
  264. package/dist/release/bootstrap.js +7 -7
  265. package/dist/release/bump-args.js +4 -4
  266. package/dist/release/bump-command.d.ts +1 -1
  267. package/dist/release/bump-command.js +9 -10
  268. package/dist/release/bump.d.ts +5 -4
  269. package/dist/release/bump.js +2 -2
  270. package/dist/release/cli.d.ts +4 -4
  271. package/dist/release/cli.js +4 -4
  272. package/dist/release/codegen.js +1 -1
  273. package/dist/release/digest.js +5 -7
  274. package/dist/release/git.js +5 -8
  275. package/dist/release/load.js +3 -3
  276. package/dist/release/manifest.js +9 -10
  277. package/dist/release/oasdiff.d.ts +10 -15
  278. package/dist/release/oasdiff.js +5 -6
  279. package/dist/release/registries.d.ts +0 -11
  280. package/dist/release/registries.js +17 -17
  281. package/dist/release/release-state.d.ts +16 -13
  282. package/dist/release/release-workflow.js +5 -7
  283. package/dist/release/repo-settings.d.ts +2 -1
  284. package/dist/release/spec-gate.d.ts +0 -2
  285. package/dist/release/spec-gate.js +6 -10
  286. package/dist/release/sync-command.d.ts +2 -2
  287. package/dist/release/sync-command.js +1 -1
  288. package/dist/release/sync-tree.js +9 -13
  289. package/dist/release/sync.d.ts +6 -6
  290. package/dist/release/sync.js +12 -13
  291. package/dist/release/types.d.ts +22 -22
  292. package/dist/release/types.js +0 -1
  293. package/dist/release/version-files.d.ts +3 -4
  294. package/dist/release/version-files.js +4 -5
  295. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  296. package/dist/runtime/cli/socket.go +107 -13
  297. package/dist/runtime/cli/stream.go +18 -11
  298. package/dist/runtime/csharp/Adapters.cs +12 -11
  299. package/dist/runtime/csharp/Events.cs +22 -17
  300. package/dist/runtime/csharp/Realtime.cs +50 -23
  301. package/dist/runtime/csharp/RealtimeLoop.cs +1 -1
  302. package/dist/runtime/csharp/TransportSse.cs +3 -3
  303. package/dist/runtime/csharp/Ws.cs +1 -1
  304. package/dist/runtime/csharp/WsDial.cs +19 -1
  305. package/dist/runtime/csharp/WsTyped.cs +109 -0
  306. package/dist/runtime/go/realtime.go +125 -41
  307. package/dist/runtime/go/realtime_loop.go +21 -18
  308. package/dist/runtime/go/result.go +2 -1
  309. package/dist/runtime/go/sse.go +11 -0
  310. package/dist/runtime/go/stream.go +29 -13
  311. package/dist/runtime/go/transport.go +15 -21
  312. package/dist/runtime/go/transport_longpoll.go +3 -4
  313. package/dist/runtime/go/transport_sse.go +6 -6
  314. package/dist/runtime/go/ws.go +157 -61
  315. package/dist/runtime/java/EventStream.java +47 -29
  316. package/dist/runtime/java/Exchange.java +5 -5
  317. package/dist/runtime/java/Flight.java +3 -3
  318. package/dist/runtime/java/Realtime.java +45 -11
  319. package/dist/runtime/java/ResumableConnection.java +77 -32
  320. package/dist/runtime/java/Socket.java +8 -4
  321. package/dist/runtime/java/SseAdapter.java +1 -1
  322. package/dist/runtime/java/TypedWebSocket.java +81 -24
  323. package/dist/runtime/java/WsAdapter.java +4 -2
  324. package/dist/runtime/java/WsDial.java +12 -5
  325. package/dist/runtime/mcp/files.ts +1 -1
  326. package/dist/runtime/mcp/http.ts +6 -2
  327. package/dist/runtime/mcp/listen.ts +1 -1
  328. package/dist/runtime/mcp/mount.ts +2 -2
  329. package/dist/runtime/mcp/protocol.ts +1 -1
  330. package/dist/runtime/python/events.py +25 -11
  331. package/dist/runtime/python/operation.py +6 -1
  332. package/dist/runtime/python/realtime.py +47 -33
  333. package/dist/runtime/python/send_async.py +1 -0
  334. package/dist/runtime/python/transport_sse.py +2 -2
  335. package/dist/runtime/python/transport_ws.py +1 -1
  336. package/dist/runtime/python/ws.py +100 -39
  337. package/dist/runtime/rust/events.rs +64 -41
  338. package/dist/runtime/rust/realtime.rs +80 -34
  339. package/dist/runtime/rust/realtime_loop.rs +37 -12
  340. package/dist/runtime/rust/sse.rs +3 -2
  341. package/dist/runtime/rust/transport_sse.rs +1 -1
  342. package/dist/runtime/rust/transport_ws.rs +3 -2
  343. package/dist/runtime/rust/ws.rs +122 -50
  344. package/dist/runtime/ts/realtime-connection.ts +22 -0
  345. package/dist/runtime/ts/realtime-transports.ts +13 -4
  346. package/dist/runtime/ts/realtime.ts +27 -3
  347. package/dist/runtime/ts/sdk-realtime.ts +1 -1
  348. package/dist/runtime/ts/sdk-sse.ts +31 -14
  349. package/dist/runtime/ts/sdk-ws.ts +2 -1
  350. package/dist/runtime/ts/sdk.ts +9 -2
  351. package/dist/runtime/ts/sse.ts +8 -0
  352. package/dist/runtime/ts/ws.ts +88 -50
  353. package/dist/runtime/ts-tanstack-query/query.ts +0 -2
  354. package/package.json +12 -40
  355. package/dist/emit/cli/index.d.ts +0 -1
  356. package/dist/emit/cli/index.js +0 -1
  357. package/dist/emit/csharp/index.d.ts +0 -1
  358. package/dist/emit/csharp/index.js +0 -1
  359. package/dist/emit/go/index.d.ts +0 -1
  360. package/dist/emit/go/index.js +0 -1
  361. package/dist/emit/java/index.d.ts +0 -2
  362. package/dist/emit/java/index.js +0 -2
  363. package/dist/emit/mcp/index.d.ts +0 -3
  364. package/dist/emit/mcp/index.js +0 -3
  365. package/dist/emit/python/index.d.ts +0 -1
  366. package/dist/emit/python/index.js +0 -1
  367. package/dist/emit/rust/index.d.ts +0 -1
  368. package/dist/emit/rust/index.js +0 -1
@@ -22,9 +22,11 @@ export const RESERVED = [
22
22
  "Result",
23
23
  "SDKConfig",
24
24
  "SSEEvent",
25
+ "SSEEventOf",
25
26
  "SseOptions",
26
27
  "TypedWebSocket",
27
28
  "Uint8Array",
29
+ "WsFrame",
28
30
  "WsOptions",
29
31
  ];
30
32
  /** What the types file may import from the runtime module, in the order the import lists them. */
@@ -34,7 +36,9 @@ const RUNTIME_TYPES = [
34
36
  "ResumableConnection",
35
37
  "SDKConfig",
36
38
  "SSEEvent",
39
+ "SSEEventOf",
37
40
  "TypedWebSocket",
41
+ "WsFrame",
38
42
  ];
39
43
  /** The input fields every call takes, by transport. */
40
44
  const OPTIONS = `export type HttpOptions = {
@@ -48,7 +52,7 @@ const OPTIONS = `export type HttpOptions = {
48
52
  export type SseOptions = Omit<HttpOptions, "idempotencyKey"> & { lastEventId?: string }
49
53
  export type WsOptions = { protocols?: string | string[]; reconnectToken?: string }
50
54
  `;
51
- /* the error envelope, the call and stream shapes, and the safe mirror's opening */
55
+ // the error envelope, the call and stream shapes, and the safe mirror's opening
52
56
  const CALLS = `
53
57
  type ErrorField = { error_key: string; message: string; path: string }
54
58
 
@@ -84,7 +88,7 @@ type HttpStream<I, V, E = never> = {
84
88
  /** \`client.safe\`: every REST and stream call answering a Result, never throwing an API answer; a connection as is. */
85
89
  export type HttpSafe<T> = {
86
90
  [K in keyof T]: `;
87
- /* the safe mirror's REST and stream arms */
91
+ // the safe mirror's REST and stream arms
88
92
  const SAFE_ARMS = ` ? {
89
93
  (input: I & HttpOptions & { raw: true }): Promise<Result<Response, E>>
90
94
  (...input: HttpArgs<I, HttpOptions & { raw?: false }>): Promise<Result<D, E, H>>
@@ -1,8 +1,8 @@
1
- import { irErrorEnvelope, isJsonMedia, mediaEssence, sdkModel, sseEventSchema } from "../../ir/sdk-model.js";
1
+ import { dispatchKey, irErrorEnvelope, isJsonMedia, mediaEssence, sdkModel, sseEventSchema, sseEvents, } from "../../ir/sdk-model.js";
2
2
  import { bodiesOf } from "../../ir/slots.js";
3
3
  import { blockCommentText, tsString } from "../shared/escape.js";
4
4
  import { compareCodeUnits, NameTable, pascalWords } from "../shared/lang.js";
5
- import { quoteKey } from "../shared/literals.js";
5
+ import { optionalType, quoteKey } from "../shared/literals.js";
6
6
  import { irToTs } from "../shared/type-emitter.js";
7
7
  import { runtimeFeatures } from "./http.js";
8
8
  import { importText, RESERVED, shared } from "./sdk-types-preamble.js";
@@ -15,7 +15,7 @@ function paramsPart(field, params, value) {
15
15
  return null;
16
16
  const entries = [...params]
17
17
  .sort((a, b) => compareCodeUnits(a.name, b.name))
18
- .map((p) => `${quoteKey(p.name)}${p.required === true ? "" : "?"}: ${value(p)}`);
18
+ .map((p) => p.required === true ? `${quoteKey(p.name)}: ${value(p)}` : `${quoteKey(p.name)}?: ${optionalType(value(p))}`);
19
19
  return { field, required: params.some((p) => p.required === true), type: objectText(entries) };
20
20
  }
21
21
  /** The input field a request body fills, by its media type. */
@@ -41,9 +41,9 @@ function bodyParts(op, ctx) {
41
41
  const body = byField.get(field);
42
42
  if (body === undefined)
43
43
  return [];
44
- /* a multipart file part is a Blob, so a File passes; in JSON a binary field stays a string. the form's own
45
- shape is emitted, never its component's name: one named type cannot be `string` for JSON and `Blob` here,
46
- and a name is what hid the Blob until bit 22 b */
44
+ // a multipart file part is a Blob, so a File passes; in JSON a binary field stays a string. the form's own
45
+ // shape is emitted, never its component's name: one named type cannot be `string` for JSON and `Blob` here,
46
+ // and a name is what hid the Blob until bit 22 b
47
47
  const type = body.kind === "stream"
48
48
  ? "ArrayBuffer | Blob | ReadableStream<Uint8Array> | Uint8Array"
49
49
  : field === "form"
@@ -55,18 +55,20 @@ function bodyParts(op, ctx) {
55
55
  /** A call's input object, and whether it must be passed. */
56
56
  function inputOf(op, ctx) {
57
57
  const { types } = ctx;
58
- /* a header or cookie is text on the wire: an enum keeps its values, anything else is a string */
58
+ // a header or cookie is text on the wire: an enum keeps its values, anything else is a string
59
59
  const text = (p) => (p.schema.kind === "scalar" && p.schema.enum ? irToTs(p.schema, types) : "string");
60
60
  const pathParams = op.pathParams.map((p) => ({ ...p, required: true }));
61
+ // a browser WebSocket sends no headers and sets no cookies, so a socket call takes neither
62
+ const socket = op.stream === "ws";
61
63
  const parts = [
62
64
  paramsPart("params", pathParams, (p) => irToTs(p.schema, types)),
63
65
  paramsPart("search", op.query, (p) => irToTs(p.schema, types)),
64
- paramsPart("headers", op.headers, text),
65
- paramsPart("cookies", op.ir.params.cookie ?? [], text),
66
+ socket ? null : paramsPart("headers", op.headers, text),
67
+ socket ? null : paramsPart("cookies", op.ir.params.cookie ?? [], text),
66
68
  ...bodyParts(op, ctx),
67
69
  ].filter((part) => part !== null);
68
70
  const ordered = [...parts.filter((p) => p.required), ...parts.filter((p) => !p.required)];
69
- const fields = ordered.map((p) => `${p.field}${p.required ? "" : "?"}: ${p.type}`);
71
+ const fields = ordered.map((p) => (p.required ? `${p.field}: ${p.type}` : `${p.field}?: ${optionalType(p.type)}`));
70
72
  return { required: parts.some((p) => p.required), type: objectText(fields) };
71
73
  }
72
74
  /** The data a successful call resolves to: JSON from its schema, text as a string, bytes (A1), else null. */
@@ -102,6 +104,46 @@ function headersOf(op) {
102
104
  const fields = [...byName].sort(([a], [b]) => compareCodeUnits(a, b));
103
105
  return objectText(fields.map(([name, required]) => `${quoteKey(name)}${required ? "" : "?"}: string`));
104
106
  }
107
+ /** A WebSocket op's socket: typed by its declared messages, `In` what the server receives, `Out` what it sends (D9). */
108
+ function socketType(op, ctx) {
109
+ const messages = op.ir.messages;
110
+ if (messages === undefined)
111
+ return "TypedWebSocket";
112
+ const { receive, send } = messages;
113
+ const key = send === undefined ? undefined : dispatchKey(send, ctx.resolve);
114
+ const args = [
115
+ receive === undefined ? "WsFrame" : irToTs(receive, ctx.types),
116
+ send === undefined ? "string" : irToTs(send, ctx.types),
117
+ ...(key === undefined ? [] : [tsString(key)]),
118
+ ];
119
+ while (args.length > 0 && args.at(-1) === ["WsFrame", "string"][args.length - 1])
120
+ args.pop();
121
+ return args.length === 0 ? "TypedWebSocket" : `TypedWebSocket<${args.join(", ")}>`;
122
+ }
123
+ /** A realtime op's connection: what it yields (the messages it hears, else its event data), sends, and dispatches on. */
124
+ function connectionType(op, ctx) {
125
+ const { receive, send } = op.ir.messages ?? {};
126
+ const yields = send ?? sseEventSchema(op.ir, ctx.resolve);
127
+ const key = send === undefined ? undefined : dispatchKey(send, ctx.resolve);
128
+ const args = [
129
+ yields === undefined ? "unknown" : irToTs(yields, ctx.types),
130
+ receive === undefined ? "unknown" : irToTs(receive, ctx.types),
131
+ ...(key === undefined ? [] : [tsString(key)]),
132
+ ];
133
+ while (args.length > 1 && args.at(-1) === "unknown")
134
+ args.pop();
135
+ return `ResumableConnection<${args.join(", ")}>`;
136
+ }
137
+ /** What an SSE op's stream yields: `SSEEventOf` its named events (D7), else `SSEEvent` of its one data schema. */
138
+ function sseEventType(op, ctx) {
139
+ const named = sseEvents(op.ir);
140
+ if (named !== undefined) {
141
+ const fields = named.map(({ data, name }) => `${quoteKey(name)}: ${irToTs(data, ctx.types)}`);
142
+ return `SSEEventOf<${objectText(fields)}>`;
143
+ }
144
+ const events = sseEventSchema(op.ir, ctx.resolve);
145
+ return events === undefined ? "SSEEvent" : `SSEEvent<${irToTs(events, ctx.types)}>`;
146
+ }
105
147
  /** `op`'s member line `name`: a REST call a HttpCall, a stream a HttpStream, defaults dropped; a connection its method. */
106
148
  function signature(name, op, ctx) {
107
149
  const input = inputOf(op, ctx);
@@ -110,25 +152,22 @@ function signature(name, op, ctx) {
110
152
  return `${input.required ? "input" : "input?"}: ${type}`;
111
153
  };
112
154
  const key = quoteKey(name);
113
- /* a realtime op is one resumable connection of its event data; any other is typed by its transport */
155
+ // a realtime op is one resumable connection of its event data; any other is typed by its transport
114
156
  const { realtime, sse, websocket } = op.ir.extensions;
115
- if (realtime) {
116
- const events = sseEventSchema(op.ir, ctx.resolve);
117
- return `${key}(${arg("RealtimeCallOptions")}): ResumableConnection<${events ? irToTs(events, ctx.types) : "unknown"}>`;
118
- }
157
+ if (realtime)
158
+ return `${key}(${arg("RealtimeCallOptions")}): ${connectionType(op, ctx)}`;
119
159
  if (websocket)
120
- return `${key}(${arg("WsOptions")}): TypedWebSocket`;
160
+ return `${key}(${arg("WsOptions")}): ${socketType(op, ctx)}`;
121
161
  const errors = errorsOf(op, ctx.types, ctx.resolve);
122
162
  if (sse) {
123
- const events = sseEventSchema(op.ir, ctx.resolve);
124
- const event = events === undefined ? "SSEEvent" : `SSEEvent<${irToTs(events, ctx.types)}>`;
163
+ const event = sseEventType(op, ctx);
125
164
  return `${key}: HttpStream<${[input.type, event, ...(errors === null ? [] : [errors])].join(", ")}>`;
126
165
  }
127
166
  const headers = headersOf(op);
128
167
  const tail = headers === null ? (errors === null ? [] : [errors]) : [errors ?? "never", headers];
129
168
  return `${key}: HttpCall<${[input.type, dataOf(op, ctx.types), ...tail].join(", ")}>`;
130
169
  }
131
- /* every line break a comment splits at, as the shared comment writers split (escape.ts) */
170
+ // every line break a comment splits at, as the shared comment writers split (escape.ts)
132
171
  const LINE_BREAKS = /\r\n|\r|\n|\u2028|\u2029/;
133
172
  /**
134
173
  * `op`'s summary and description as a JSDoc block above its overloads at `indent`, a paragraph each, as Go, Rust,
@@ -183,7 +222,7 @@ function configText(name, server, runtimeConfig) {
183
222
  /** The `${stem}.types.gen.ts` text of `ir` for the SDK `name`, importing the runtime module `runtime`. */
184
223
  export function sdkTypesText(ir, name, runtime) {
185
224
  const model = sdkModel(ir);
186
- /* the SDK named `SDK` declares `SDKConfig`, so the runtime's own is imported under another name */
225
+ // the SDK named `SDK` declares `SDKConfig`, so the runtime's own is imported under another name
187
226
  const aliases = name === "SDK" ? { SDKConfig: "HttpSDKConfig" } : {};
188
227
  const runtimeConfig = aliases["SDKConfig"] ?? "SDKConfig";
189
228
  const own = [
@@ -11,12 +11,12 @@ import { MIRROR, mirrorNotice } from "../shared/mirror.js";
11
11
  import { runtimeFeatures, runtimeSource } from "./http.js";
12
12
  import { RESERVED } from "./sdk-types-preamble.js";
13
13
  import { sdkTypesText } from "./sdk-types.js";
14
- import { tanstackQueryText } from "./tanstack-query.js";
15
14
  import { memberTree, serviceMapText } from "./service-map.js";
15
+ import { tanstackQueryText } from "./tanstack-query.js";
16
16
  import { webhooksText, webhookTypeNames } from "./webhooks.js";
17
17
  export { sdkMemberPaths, serviceMapOf } from "./service-map.js";
18
18
  const IDENTIFIER = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
19
- /* the error classes and helpers a consumer imports from the SDK beside the class, by the transport that ships them */
19
+ // the error classes and helpers a consumer imports from the SDK beside the class, by the transport that ships them
20
20
  const RUNTIME_EXPORTS = {
21
21
  core: [
22
22
  "APIConnectionError",
@@ -63,8 +63,8 @@ const RUNTIME_TYPES = {
63
63
  "TransportConnection",
64
64
  "TransportOpts",
65
65
  ],
66
- sse: ["SSEEvent"],
67
- ws: ["TypedWebSocket"],
66
+ sse: ["SSEEvent", "SSEEventOf"],
67
+ ws: ["TypedWebSocket", "WsFrame"],
68
68
  };
69
69
  /** The names of `lists` a runtime with `features` ships, ignoring case in their order. */
70
70
  function shipped(lists, features) {
@@ -153,7 +153,7 @@ export function generateSdk(document, options) {
153
153
  refuseClash(name, (own) => (events.has(own) ? "the document's webhook events" : undefined));
154
154
  const runtime = `${stem}.runtime.gen`;
155
155
  const features = runtimeFeatures(ir);
156
- /* memberTree emits the root groups in code-unit order, each renamed in place */
156
+ // memberTree emits the root groups in code-unit order, each renamed in place
157
157
  const emitted = [...memberTree(ir.tree).entries.keys()];
158
158
  const groups = [...ir.tree.entries.keys()].sort(compareCodeUnits);
159
159
  const notices = groups.flatMap((group, i) => mirrorNotice("ts", MIRROR, group, emitted[i]) ?? []);
@@ -166,7 +166,7 @@ export function generateSdk(document, options) {
166
166
  };
167
167
  if (ir.webhooks.some((webhook) => webhook.event))
168
168
  files[`${stem}.webhook.gen.ts`] = webhooksText(ir, stem);
169
- /* the index never names it: its text must not vary by option, and it must never name query-core */
169
+ // the index never names it: its text must not vary by option, and it must never name query-core
170
170
  if (options.tanstackQuery === true)
171
171
  files[`${stem}.tanstack-query.gen.ts`] = tanstackQueryText(ir, name, stem);
172
172
  return { files, notices, stem, version: ir.info.version };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { IR, IRNamespace } from "../../ir/model.ts";
6
6
  /** One operation as the runtime's service map holds it (`runtime/ts/sdk.ts` `ServiceEntry`). */
7
- export type ServiceEntry = {
7
+ type ServiceEntry = {
8
8
  accept?: string;
9
9
  /** the operation declares no success body: a 2xx reads as null, its body only through `raw` */
10
10
  empty?: true;
@@ -15,10 +15,16 @@ export type ServiceEntry = {
15
15
  params?: string[];
16
16
  path: string;
17
17
  realtime?: true;
18
- /** an event stream; `"json"` when its declared event schema is not a string */
19
- sse?: "json" | true;
18
+ /** an event stream; `"json"` when its declared event schema is not a string, its JSON events' names when it names them */
19
+ sse?: "json" | string[] | true;
20
20
  wildcard?: string;
21
21
  ws?: true;
22
+ /** the server declares what it sends: the socket parses each text frame */
23
+ decode?: true;
24
+ /** the field a socket's message union is keyed on (D9) */
25
+ dispatch?: string;
26
+ /** the server declares what it receives: the socket sends JSON */
27
+ encode?: true;
22
28
  };
23
29
  export type ServiceMapNode = ServiceEntry | {
24
30
  [key: string]: ServiceMapNode;
@@ -38,3 +44,4 @@ export declare function sdkMemberPaths(ir: IR): Map<string, string[]>;
38
44
  export declare function serviceMapOf(ir: IR): Record<string, ServiceMapNode>;
39
45
  /** The `${stem}.map.gen.ts` text: the service map as a `const`, importing the adapters its entries name. */
40
46
  export declare function serviceMapText(ir: IR, runtime: string): string;
47
+ export {};
@@ -1,4 +1,4 @@
1
- import { isJsonMedia, mediaEssence, sdkModel, sseEventSchema, } from "../../ir/sdk-model.js";
1
+ import { isJsonMedia, mediaEssence, sdkModel, dispatchKey, isJsonEventData, sseEventSchema, sseEvents, } from "../../ir/sdk-model.js";
2
2
  import { openApiPathParams } from "../../ir/slots.js";
3
3
  import { tsString } from "../shared/escape.js";
4
4
  import { compareCodeUnits } from "../shared/lang.js";
@@ -69,6 +69,33 @@ function headersOf(op, status) {
69
69
  const declared = op.responses[status]?.headers ?? [];
70
70
  return [...new Set(declared.map(({ name }) => name.toLowerCase()))].sort(compareCodeUnits);
71
71
  }
72
+ /** How the runtime reads `op`'s events: the names of its JSON events when it names them (D7), else all or none. */
73
+ function sseKind(op, resolve) {
74
+ const named = sseEvents(op);
75
+ if (named !== undefined)
76
+ return named.filter(({ data }) => isJsonEventData(data, resolve)).map(({ name }) => name);
77
+ return sseEventSchema(op, resolve) === undefined ? true : "json";
78
+ }
79
+ /**
80
+ * How a socket op's declared messages read on the wire: a WebSocket's sends JSON when the server declares `receive`
81
+ * and its frames parsed when it declares `send`; either kind's messages dispatched on `send`'s key (D9).
82
+ */
83
+ function socketEntry(op, resolve) {
84
+ const { messages } = op;
85
+ if (messages === undefined)
86
+ return {};
87
+ const out = {};
88
+ if (!op.extensions.realtime) {
89
+ if (messages.receive !== undefined)
90
+ out.encode = true;
91
+ if (messages.send !== undefined)
92
+ out.decode = true;
93
+ }
94
+ const key = messages.send === undefined ? undefined : dispatchKey(messages.send, resolve);
95
+ if (key !== undefined)
96
+ out.dispatch = key;
97
+ return out;
98
+ }
72
99
  /** The service entry of `op`; `success` is its success answer as the SDK model reads it. */
73
100
  function entryOf(op, success, resolve) {
74
101
  const entry = { method: op.method, path: op.path };
@@ -79,11 +106,12 @@ function entryOf(op, success, resolve) {
79
106
  if (wildcard)
80
107
  entry.wildcard = wildcard.name;
81
108
  if (op.extensions.sse)
82
- entry.sse = sseEventSchema(op, resolve) === undefined ? true : "json";
109
+ entry.sse = sseKind(op, resolve);
83
110
  if (op.extensions.websocket)
84
111
  entry.ws = true;
85
112
  if (op.extensions.realtime)
86
113
  entry.realtime = true;
114
+ Object.assign(entry, socketEntry(op, resolve));
87
115
  if (op.extensions.idempotencyKey)
88
116
  entry.idempotent = true;
89
117
  const invalidate = op.extensions.invalidates;
@@ -14,11 +14,11 @@ import { quoteKey } from "../shared/literals.js";
14
14
  import { memberTree } from "./service-map.js";
15
15
  /** The adapter's modules, each after the ones it imports, as `RUNTIME_MODULES` is ordered. */
16
16
  const QUERY_MODULES = ["invalidate", "query"];
17
- /* an import of a module beside this one: now the same file, so the names are already in scope */
17
+ // an import of a module beside this one: now the same file, so the names are already in scope
18
18
  const SIBLING_IMPORT = /^import\s+(?:type\s+)?\{[^}]*\}\s+from\s+"\.\/[\w-]+\.ts"\n/gm;
19
- /* an import of clients' own runtime, which the emitted file reads from `<stem>.runtime.gen` */
19
+ // an import of clients' own runtime, which the emitted file reads from `<stem>.runtime.gen`
20
20
  const RUNTIME_IMPORT = /^import\s+(type\s+)?\{([^}]*)\}\s+from\s+"\.\.\/ts\/[\w-]+\.ts"\n/gm;
21
- /* query-core, which stays exactly as written: type-only, so nothing has to resolve at run time */
21
+ // query-core, which stays exactly as written: type-only, so nothing has to resolve at run time
22
22
  const QUERY_CORE_IMPORT = /^import\s+type\s+\{([^}]*)\}\s+from\s+"@tanstack\/query-core"\n/gm;
23
23
  /** The names a `{ a, type b }` clause lists, in code-unit order and once each. */
24
24
  function namesOf(clauses) {
@@ -40,15 +40,15 @@ export function tanstackQuerySource(runtime) {
40
40
  const bodies = QUERY_MODULES.map((name) => {
41
41
  const text = readFileSync(new URL(`../../runtime/ts-tanstack-query/${name}.ts`, import.meta.url), "utf8");
42
42
  return text
43
- .replace(QUERY_CORE_IMPORT, (_, named) => {
43
+ .replaceAll(QUERY_CORE_IMPORT, (_, named) => {
44
44
  core.push(named);
45
45
  return "";
46
46
  })
47
- .replace(RUNTIME_IMPORT, (_, __, named) => {
47
+ .replaceAll(RUNTIME_IMPORT, (_, __, named) => {
48
48
  runtimeNames.push(named);
49
49
  return "";
50
50
  })
51
- .replace(SIBLING_IMPORT, "")
51
+ .replaceAll(SIBLING_IMPORT, "")
52
52
  .trim();
53
53
  });
54
54
  const imports = [
@@ -3,13 +3,13 @@ import { isJsonMedia, mediaEssence } from "../../ir/sdk-model.js";
3
3
  import { bodiesOf } from "../../ir/slots.js";
4
4
  import { tsString } from "../shared/escape.js";
5
5
  import { compareCodeUnits } from "../shared/lang.js";
6
- import { literalType, quoteKey } from "../shared/literals.js";
6
+ import { literalType, optionalType, quoteKey } from "../shared/literals.js";
7
7
  import { statusKeyOf } from "../shared/status-keys.js";
8
8
  import { irToTs } from "../shared/type-emitter.js";
9
9
  import { componentNames } from "./sdk-types.js";
10
- /* the names the file declares, which a component schema never takes */
10
+ // the names the file declares, which a component schema never takes
11
11
  const RESERVED = ["HttpContext", "HttpError", "HttpMeta", "Omit", "Partial", "Readonly", "Record", "Routes"];
12
- /* the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts) */
12
+ // the v1 error-factory signature of a key without a schema (core errors.ts ErrorFactoryOpts)
13
13
  const STANDARD_FACTORY = "(opts?: { cause?: unknown; fields?: Record<string, { error_key: string; message: string; path: string }[]>; headers?: Record<string, string>; vars?: Record<string, number | string> }) => HttpError";
14
14
  const EXTRACTORS = [
15
15
  ["RouteInput", "input"],
@@ -32,7 +32,7 @@ function routesOf(ir, report) {
32
32
  continue;
33
33
  if (id === undefined)
34
34
  missing.push(`${op.method} ${op.path}: no x-backend-route; left out of Routes`);
35
- /* `all()` and an optional param document one route as several operations: the first speaks for it */
35
+ // `all()` and an optional param document one route as several operations: the first speaks for it
36
36
  if (id !== undefined && !routes.has(id))
37
37
  routes.set(id, op);
38
38
  }
@@ -49,18 +49,24 @@ function paramsOf(pattern) {
49
49
  function wireInput(op, ctx) {
50
50
  const group = (params) => objectText([...params]
51
51
  .sort((a, b) => compareCodeUnits(a.name, b.name))
52
- .map((p) => [`${quoteKey(p.name)}${p.required === true ? "" : "?"}`, ctx.resolve(p.schema)]));
52
+ .map((p) => p.required === true
53
+ ? [quoteKey(p.name), ctx.resolve(p.schema)]
54
+ : [`${quoteKey(p.name)}?`, optionalType(ctx.resolve(p.schema))]));
53
55
  const fields = [];
54
56
  if (op.params.query.length > 0)
55
57
  fields.push(["search", group(op.params.query)]);
56
58
  if (op.params.header.length > 0)
57
59
  fields.push(["headers", group(op.params.header)]);
58
- /* the IR sets `cookie` only when the operation declares one */
60
+ // the IR sets `cookie` only when the operation declares one
59
61
  if (op.params.cookie !== undefined)
60
62
  fields.push(["cookies", group(op.params.cookie)]);
61
63
  const body = bodiesOf(op)[0];
62
- if (body?.kind === "stream")
63
- fields.push(["binary", `{ readonly bytes: Uint8Array<ArrayBuffer>; readonly type: ${tsString(body.contentType)} }`]);
64
+ if (body?.kind === "stream") {
65
+ fields.push([
66
+ "binary",
67
+ `{ readonly bytes: Uint8Array<ArrayBuffer>; readonly type: ${tsString(body.contentType)} }`,
68
+ ]);
69
+ }
64
70
  else if (body !== undefined) {
65
71
  const essence = mediaEssence(body.contentType);
66
72
  const field = isJsonMedia(body.contentType) ? "json" : "form";
@@ -136,12 +142,12 @@ function errorsOf(op, ctx) {
136
142
  * Without an extracted declaration (no ts-morph, or an app that declares no meta) the literals are all there is.
137
143
  */
138
144
  function ctxMeta(extracted, literal) {
139
- /* with nothing extracted, the tree's literals are all there is */
145
+ // with nothing extracted, the tree's literals are all there is
140
146
  if (extracted === null || extracted === undefined)
141
147
  return literal;
142
- /* the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
143
- that type in the handler, and intersecting backend's would conflict with it. An app that declares none
144
- holds them all, each widened by \`.meta()\` */
148
+ // the OpenAPI keys the declared meta does not redefine: a consumer that types `security` its own way holds
149
+ // that type in the handler, and intersecting backend's would conflict with it. An app that declares none
150
+ // holds them all, each widened by \`.meta()\`
145
151
  const declared = extracted.meta;
146
152
  return declared === null ? "Partial<HttpMeta>" : `Partial<Omit<HttpMeta, keyof ${declared}>> & ${declared}`;
147
153
  }
@@ -168,7 +174,7 @@ function routeEntry(id, op, options, ctx) {
168
174
  const params = ctxParams(extracted, id, pattern);
169
175
  const { factories, fields } = errorsOf(op, ctx);
170
176
  const mt = options.tree.routes[id]?.mt;
171
- /* the values the tree carries, as literals: what a consumer reads a route's configuration from */
177
+ // the values the tree carries, as literals: what a consumer reads a route's configuration from
172
178
  const literal = mt && Object.keys(mt).length > 0 ? literalType(mt) : "{}";
173
179
  const output = outputOf(op, ctx);
174
180
  const own = [];
@@ -204,13 +210,15 @@ function baseCtx(extracted, name) {
204
210
  }
205
211
  /**
206
212
  * A WebSocket route's ctx, as core's `WSRouteCtx` types its callbacks: the base with the pattern's params, and the
207
- * search input `.input()` declares. Extracted additions are keyed by HTTP routes only, so none join here.
213
+ * search, headers and cookies `.input()` declares. Extracted additions are keyed by HTTP routes only, so none join
214
+ * here.
208
215
  */
209
216
  function wsCtx(op, id, options, ctx) {
210
217
  const own = [];
211
- const search = wireInput(op, ctx).find(([key]) => key === "search");
212
- if (search !== undefined)
213
- own.push(["readonly input", objectText([search])]);
218
+ // the upgrade request's validated search, headers and cookies, as core's `WithInput` holds them
219
+ const input = wireInput(op, ctx).filter(([key]) => key === "search" || key === "headers" || key === "cookies");
220
+ if (input.length > 0)
221
+ own.push(["readonly input", objectText(input)]);
214
222
  const params = ctxParams(options.extracted, id, pathOf(id));
215
223
  if (params !== "{}")
216
224
  own.push(["readonly params", params]);
@@ -273,15 +281,21 @@ export function generateTypes(options) {
273
281
  const ir = toIR(options.document, { deriveOperationIds: true });
274
282
  const routes = routesOf(ir, options.report);
275
283
  const extra = Object.keys(options.extracted?.routes ?? {}).filter((id) => !routes.has(id));
276
- for (const id of extra.sort(compareCodeUnits))
284
+ for (const id of extra.sort(compareCodeUnits)) {
277
285
  options.report(`${id}: extracted ctx additions match no documented operation (internal and filtered routes are not documented); not typed`);
286
+ }
278
287
  const name = options.baseCtxName ?? "BaseCtx";
279
288
  const names = { refName: componentNames(ir, [...RESERVED, name]) };
280
289
  const ctx = { names, resolve: (schema) => irToTs(schema, names) };
281
290
  const hasErrors = [...routes.values()].some((op) => Object.keys(op.extensions.errors ?? {}).length > 0);
282
- /* HttpMeta once a route's ctx reads it: with anything extracted, the ctx's meta is built from its keys */
291
+ // HttpMeta once a route's ctx reads it: with anything extracted, the ctx's meta is built from its keys
283
292
  const readsMeta = options.extracted !== null && options.extracted !== undefined && routes.size > 0;
284
- const imports = ["HttpContext", "WithOutput", ...(hasErrors ? ["HttpError"] : []), ...(readsMeta ? ["HttpMeta"] : [])];
293
+ const imports = [
294
+ "HttpContext",
295
+ "WithOutput",
296
+ ...(hasErrors ? ["HttpError"] : []),
297
+ ...(readsMeta ? ["HttpMeta"] : []),
298
+ ];
285
299
  const out = [`import type { ${imports.join(", ")} } from "@workerstack/backend/http"`];
286
300
  out.push(baseCtx(options.extracted, name));
287
301
  const slot = operationSlot(ir, options, ctx);
@@ -290,7 +304,8 @@ export function generateTypes(options) {
290
304
  for (const schema of Object.keys(ir.schemas).sort(compareCodeUnits))
291
305
  out.push(`type ${names.refName?.(schema)} = ${ctx.resolve(ir.schemas[schema])}`);
292
306
  out.push(routesType(routes, options, ctx));
293
- for (const [type, field] of EXTRACTORS)
307
+ for (const [type, field] of EXTRACTORS) {
294
308
  out.push(`export type ${type}<TPath extends keyof Routes, TMethod extends keyof Routes[TPath] & string> = Routes[TPath][TMethod] extends { ${field}: infer T } ? T : never`);
309
+ }
295
310
  return `${out.join("\n\n")}\n`;
296
311
  }
@@ -5,8 +5,6 @@
5
5
  */
6
6
  import type { IR } from "../../ir/model.ts";
7
7
  import { type TypeOptions } from "../shared/type-emitter.ts";
8
- /** The catch-all event and the union, declared beside the events. */
9
- export declare const WEBHOOK_TYPES: readonly ["UnknownWebhookEvent", "WebhookEvent"];
10
8
  /** The type names `ir`'s events declare, for the component names to stay clear of; none without events. */
11
9
  export declare function webhookTypeNames(ir: IR): string[];
12
10
  /** The event types and their union, for `types.gen.ts`; empty for a document without events. */
@@ -3,7 +3,7 @@ import { compareCodeUnits, pascalWords } from "../shared/lang.js";
3
3
  import { irToTs } from "../shared/type-emitter.js";
4
4
  import { webhookSource } from "./http.js";
5
5
  /** The catch-all event and the union, declared beside the events. */
6
- export const WEBHOOK_TYPES = ["UnknownWebhookEvent", "WebhookEvent"];
6
+ const WEBHOOK_TYPES = ["UnknownWebhookEvent", "WebhookEvent"];
7
7
  /** `ir`'s events in code-unit order of their type, each named; two that name one type throw, naming both. */
8
8
  function namedEvents(ir) {
9
9
  const named = ir.webhooks
@@ -45,7 +45,7 @@ export type WebhookEvent = ${[...named.map(({ name }) => name), "UnknownWebhookE
45
45
 
46
46
  `;
47
47
  }
48
- /* the runtime verifier's untyped core, which `verifyWebhook` wraps: kept inside the file, out of a receiver's imports */
48
+ // the runtime verifier's untyped core, which `verifyWebhook` wraps: kept inside the file, out of a receiver's imports
49
49
  const INTERNAL = /^export ((?:async function verifyStandardWebhook|type VerifiedWebhook)\b)/gm;
50
50
  /**
51
51
  * The `${stem}.webhook.gen.ts` text of `ir`: the runtime's verifier, its untyped core unexported, then `verifyWebhook`
@@ -60,7 +60,7 @@ export function webhooksText(ir, stem) {
60
60
 
61
61
  export type { ${types.join(", ")} } from "./${stem}.types.gen.js"
62
62
 
63
- ${webhookSource().replace(INTERNAL, "$1")}
63
+ ${webhookSource().replaceAll(INTERNAL, "$1")}
64
64
 
65
65
  const KNOWN: ReadonlySet<string> = new Set([${known.join(", ")}])
66
66
 
@@ -16,7 +16,7 @@ function declaredRef(decl, ser) {
16
16
  const variable = checker.getShorthandAssignmentValueSymbol(decl)?.valueDeclaration;
17
17
  if (variable === undefined || !compiler.isBindingElement(variable))
18
18
  return ser.refFromDeclaration(variable);
19
- /* `const { db } = open()`: the pattern's own declaration; a parameter or a nested pattern names nothing */
19
+ // `const { db } = open()`: the pattern's own declaration; a parameter or a nested pattern names nothing
20
20
  const holder = variable.parent.parent;
21
21
  const init = compiler.isVariableDeclaration(holder) ? holder.initializer : undefined;
22
22
  const source = init === undefined ? undefined : checker.getTypeAtLocation(init).getProperty(decl.name.text);
@@ -28,7 +28,7 @@ function declaredRef(decl, ser) {
28
28
  /** The props of `ctx` the framework class does not own, in the ctx's order. */
29
29
  export function addedProps(ctx, owner, ser) {
30
30
  const { checker, compiler } = ser;
31
- /* a prop with no declaration (a mapped type's) is no member of anything */
31
+ // a prop with no declaration (a mapped type's) is no member of anything
32
32
  const owned = (decls) => owner !== undefined && decls.length > 0 && decls.every((d) => d.parent === owner);
33
33
  return ctx
34
34
  .getProperties()
@@ -36,7 +36,7 @@ export function addedProps(ctx, owner, ser) {
36
36
  .map((p) => {
37
37
  const decls = p.declarations ?? [];
38
38
  const optional = (p.flags & compiler.SymbolFlags.Optional) !== 0;
39
- /* a prop several middleware add is their intersection: only the checker's type says it */
39
+ // a prop several middleware add is their intersection: only the checker's type says it
40
40
  const ref = decls.length === 1 ? declaredRef(decls[0], ser) : undefined;
41
41
  const type = checker.getTypeOfSymbol(p);
42
42
  return { name: p.getName(), optional, type: ref ?? (optional ? ser.optional(type) : ser.text(type)) };
@@ -54,8 +54,9 @@ export function routeAdditions(found, ser, options) {
54
54
  const key = JSON.stringify(props);
55
55
  for (const id of ids) {
56
56
  const seen = byId.get(id);
57
- if (seen === undefined)
57
+ if (seen === undefined) {
58
58
  byId.set(id, { key, props });
59
+ }
59
60
  else if (seen.key !== key && !conflicted.has(id)) {
60
61
  conflicted.add(id);
61
62
  report(`${JSON.stringify(id)} is registered with different middleware; ${SKIPPED}`);
@@ -18,9 +18,9 @@ import { compareCodeUnits } from "../emit/shared/lang.js";
18
18
  import { addedProps, frameworkClass, routeAdditions, SKIPPED } from "./chain.js";
19
19
  import { Serializer } from "./serialize.js";
20
20
  import { loadEntry, registrations } from "./walk.js";
21
- /* the type-only members every backend app carries */
21
+ // the type-only members every backend app carries
22
22
  const APP_MEMBERS = ["$ctx", "$env"];
23
- /* the declared meta, read when the app carries it: an app from an older backend has no $meta and still extracts */
23
+ // the declared meta, read when the app carries it: an app from an older backend has no $meta and still extracts
24
24
  const META_MEMBER = "$meta";
25
25
  /** The nearest named package.json above `file` (one without a name only marks a module type). */
26
26
  function nearestPackage(file, cache) {
@@ -111,7 +111,7 @@ function moduleSpecifier(file, outputDir, cache) {
111
111
  }
112
112
  /** `import("/abs/file.ts").X` → a specifier the output resolves (lib types are never referenced: they are global). */
113
113
  function resolvable(text, outputDir, cache) {
114
- return text.replace(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
114
+ return text.replaceAll(/import\("([^"]+)"\)\./g, (_, file) => `import("${moduleSpecifier(file, outputDir, cache)}").`);
115
115
  }
116
116
  /**
117
117
  * Each registration with its route ids, methods by paths. A registration whose path is no literal, or a path the
@@ -187,8 +187,8 @@ export function extractTypes(options) {
187
187
  const base = new Set(middleware.map((p) => p.name));
188
188
  const found = routed(registrations(entry, report), routeId, report);
189
189
  const routes = routeAdditions(found, ser, { base, owner, report });
190
- /* what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
191
- literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a) */
190
+ // what `metaType<AppMeta>()` declared, written out: the ctx's meta is this and the OpenAPI keys, never the tree's
191
+ // literal values, so a handler may pass its own ctx to a function typed with the generated ctx (bit 22 a)
192
192
  const meta = metaType === undefined ? "{}" : ser.shape(metaType);
193
193
  const cache = new Map();
194
194
  const text = (t) => resolvable(t, options.outputDir, cache);
@@ -11,8 +11,6 @@
11
11
  */
12
12
  import type { ts } from "ts-morph";
13
13
  export type Compiler = typeof ts;
14
- /** Lib types every program has in scope: written by name, never imported. */
15
- export declare function isLibFile(fileName: string): boolean;
16
14
  export declare class Serializer {
17
15
  #private;
18
16
  readonly checker: ts.TypeChecker;