@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
@@ -1,26 +1,101 @@
1
+ import { isJsonEventData, sseEvents } from "../../ir/sdk-model.js";
2
+ import { goString, lineComment } from "../shared/escape.js";
3
+ import { goExported } from "../shared/lang.js";
1
4
  import { sendArgs } from "./sdk-answer.js";
2
5
  import { goTypeOf } from "./types.js";
3
6
  /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
4
7
  export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
5
- /* LastEventID, sent only when set: an empty header would still name a position */
8
+ // LastEventID, sent only when set: an empty header would still name a position
6
9
  const SSE_OPTS = {
7
10
  before: [],
8
11
  carries: isLastEventIdHeader,
9
12
  fields: [{ name: "LastEventID", type: "string" }],
10
13
  sets: ['if opts.LastEventID != "" {', '\tc.headers["Last-Event-ID"] = opts.LastEventID', "}"],
11
14
  };
12
- /** The method of the SSE operation `op`, its event type hoisted into `at` as `<Op>Event` when inline. */
15
+ const DOC = "Breaking out of the loop closes the stream; ctx ends it quietly.";
16
+ /** A stream method yielding `elem`, each event read off the wire by `decode`, as sent without one (G12). */
17
+ const streamOf = (elem, decode, calls) => ({
18
+ calls,
19
+ doc: DOC,
20
+ opts: SSE_OPTS,
21
+ shape: {
22
+ fail: `sseFail[${elem}](err)`,
23
+ returns: `iter.Seq2[${elem}, error]`,
24
+ tail: (client) => [
25
+ decode === undefined
26
+ ? `\treturn streamText(${sendArgs(client)})`
27
+ : `\treturn streamEvents(${sendArgs(client, decode)})`,
28
+ ],
29
+ },
30
+ });
31
+ /** A type of the sealed `iface`, embedding `SSEEvent[data]`, with its marker method. */
32
+ const variantDecl = (iface, type, data, doc) => [
33
+ ...lineComment(doc, "//"),
34
+ `type ${type} struct {`,
35
+ `\tSSEEvent[${data}]`,
36
+ "}",
37
+ "",
38
+ `func (${type}) is${iface}() {}`,
39
+ ];
40
+ /** The `case` of the decoder for `variant`: its data decoded from JSON, or its event as sent. */
41
+ const caseOf = ({ event, json, type, data }) => [
42
+ `\tcase ${goString(event)}:`,
43
+ ...(json
44
+ ? [`\t\tev, err := sseData[${data}](raw)`, `\t\treturn ${type}{ev}, err`]
45
+ : [`\t\treturn ${type}{raw}, nil`]),
46
+ ];
47
+ /**
48
+ * `<Op>Event` and its types, declared in one block in `at` (the interface, a type per event name in the order
49
+ * declared, `<Op>OtherEvent`, the decoder); the interface's name and the decoder's.
50
+ */
51
+ function namedEvents(op, events, at) {
52
+ const base = goExported(op.id);
53
+ const iface = at.names.claimConst(`${base}Event`);
54
+ const variants = events.map(({ data, name }) => ({
55
+ data: goTypeOf(data, { ...at, fieldName: name, parentName: op.id }).replace(/^\*/, ""),
56
+ event: name,
57
+ json: isJsonEventData(data, at.names.resolve),
58
+ type: at.names.claimConst(`${base}${goExported(name)}Event`),
59
+ }));
60
+ const other = at.names.claimConst(`${base}OtherEvent`);
61
+ const decode = at.names.claimConst(`decode${iface}`);
62
+ const types = [...variants.map((variant) => variant.type), other];
63
+ at.decls.set(iface, [
64
+ ...lineComment(`${iface} is one event of ${op.id}: ${types.slice(0, -1).join(", ")}, or ${other} for a name the operation does not declare. A type switch on it reads the event's Data.`, "//"),
65
+ `type ${iface} interface {`,
66
+ "\t// Untyped is the event with its Data as text.",
67
+ "\tUntyped() SSEEvent[string]",
68
+ `\tis${iface}()`,
69
+ "}",
70
+ "",
71
+ ...variants.flatMap((variant) => [
72
+ ...variantDecl(iface, variant.type, variant.data, `${variant.type} is the ${goString(variant.event)} event.`),
73
+ "",
74
+ ]),
75
+ ...variantDecl(iface, other, "string", `${other} is an event of a name the operation does not declare, its Data as sent.`),
76
+ "",
77
+ `// ${decode} is raw as its event's type, its Data decoded by its name; an unnamed event is "message".`,
78
+ `func ${decode}(raw SSEEvent[string]) (${iface}, error) {`,
79
+ '\tif raw.Event == "" {',
80
+ '\t\traw.Event = "message"',
81
+ "\t}",
82
+ "\tswitch raw.Event {",
83
+ ...variants.flatMap(caseOf),
84
+ "\t}",
85
+ `\treturn ${other}{raw}, nil`,
86
+ "}",
87
+ ].join("\n"));
88
+ return { decode, iface };
89
+ }
90
+ /** The method of the SSE operation `op`, its event types hoisted into `at`. */
13
91
  export function sseStream(op, at) {
92
+ const events = sseEvents(op.ir);
93
+ if (events !== undefined) {
94
+ const { decode, iface } = namedEvents(op, events, at);
95
+ return streamOf(iface, decode, [decode]);
96
+ }
14
97
  const typed = op.events && goTypeOf(op.events, { ...at, fieldName: "Event", parentName: op.id }).replace(/^\*/, "");
15
- const event = typed ?? "string";
16
- const open = typed === undefined ? "streamText" : `streamJSON[${typed}]`;
17
- return {
18
- doc: "Breaking out of the loop closes the stream; ctx ends it quietly.",
19
- opts: SSE_OPTS,
20
- shape: {
21
- fail: `sseFail[${event}](err)`,
22
- returns: `iter.Seq2[SSEEvent[${event}], error]`,
23
- tail: (client) => [`\treturn ${open}(${sendArgs(client)})`],
24
- },
25
- };
98
+ if (typed === undefined)
99
+ return streamOf("SSEEvent[string]", undefined, []);
100
+ return streamOf(`SSEEvent[${typed}]`, `sseData[${typed}]`, []);
26
101
  }
@@ -1,3 +1,8 @@
1
+ /**
2
+ * The package-level names Go types are declared under (v0 buildGoNames): one scope that components,
3
+ * hoisted types and constants all claim from, clear of every identifier the Go runtime declares.
4
+ */
5
+ import {} from "../../ir/model.js";
1
6
  import { irResolver } from "../../ir/schema.js";
2
7
  import { valueCycleSchemas } from "../../ir/sdk-model.js";
3
8
  import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
@@ -10,7 +10,7 @@ export type StructField = {
10
10
  triState: boolean;
11
11
  };
12
12
  /** The field holding the keys `additionalProperties` admits beyond the declared ones. */
13
- export type ExtraField = {
13
+ type ExtraField = {
14
14
  goName: string;
15
15
  valueType: string;
16
16
  };
@@ -27,3 +27,4 @@ export type StructShape = {
27
27
  export declare function isTagName(key: string): boolean;
28
28
  /** `type <name> struct { … }` with its embeds, fields and extra map, then whatever methods its keys need. */
29
29
  export declare function structDecl(name: string, shape: StructShape): string;
30
+ export {};
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { goString } from "../shared/escape.js";
8
8
  import { fillingMarshal, marshal, unmarshal } from "./types-codec.js";
9
- /* the punctuation encoding/json's isValidTag accepts in a tag name */
9
+ // the punctuation encoding/json's isValidTag accepts in a tag name
10
10
  const TAG_PUNCTUATION = "!#$%&()*+-./:;<=>?@[]^_{|}~ ";
11
11
  /** Whether encoding/json reads `key` as a tag name (its isValidTag: a letter, a decimal digit or that punctuation). */
12
12
  export function isTagName(key) {
@@ -5,13 +5,14 @@
5
5
  */
6
6
  import type { IRDiscriminator, IRSchema } from "../../ir/model.ts";
7
7
  import type { GoTypeNames } from "./types.ts";
8
- type Union = Extract<IRSchema, {
8
+ export type Union = Extract<IRSchema, {
9
9
  kind: "union";
10
10
  }> & {
11
11
  discriminator: IRDiscriminator;
12
12
  };
13
13
  /** Declares an inline variant once under `names.hoist(key, base)`; its name. */
14
14
  export type DeclareVariant = (schema: IRSchema, key: string, base: string) => string;
15
+ /** The Go type of each ref or inline-object variant of `union`, in order; inline ones declared through `declare`. */
16
+ export declare const variantTypes: (name: string, union: Union, names: GoTypeNames, declare: DeclareVariant) => string[];
15
17
  /** The union's struct and its (un)marshal methods; inline object variants are declared through `declare`. */
16
18
  export declare function unionDecl(name: string, union: Union, names: GoTypeNames, declare: DeclareVariant): string;
17
- export {};
@@ -65,6 +65,8 @@ function marshal(name, variants) {
65
65
  "}",
66
66
  ];
67
67
  }
68
+ /** The Go type of each ref or inline-object variant of `union`, in order; inline ones declared through `declare`. */
69
+ export const variantTypes = (name, union, names, declare) => variantsOf(name, union, names, declare).map(({ type }) => type);
68
70
  /** The union's struct and its (un)marshal methods; inline object variants are declared through `declare`. */
69
71
  export function unionDecl(name, union, names, declare) {
70
72
  const property = union.discriminator.propertyName;
@@ -5,6 +5,7 @@
5
5
  * the shared escape layer.
6
6
  */
7
7
  import type { IR, IRSchema } from "../../ir/model.ts";
8
+ import type { Dispatch } from "../../ir/sdk-model.ts";
8
9
  /** Package-level naming shared by every type one SDK declares. */
9
10
  export type GoTypeNames = {
10
11
  /** the Go type name of the component `schema` */
@@ -30,3 +31,8 @@ export declare function goTypeContext(ir?: IR): GoTypeContext;
30
31
  export declare function goTypeOf(ir: IRSchema, at: GoTypeContext): string;
31
32
  /** The top-level declaration of the type `name` (a Go identifier already) for `ir` (v0 irRenderTopLevel). */
32
33
  export declare function goTopLevel(name: string, ir: IRSchema, at: GoTypeContext): string;
34
+ /**
35
+ * Each member of the keyed union `schema` (D9) as its value beside its Go type: a component's struct names its
36
+ * members; an inline union, raw JSON in a struct, hoists each inline member into `at` as `<Parent><Field><Value>`.
37
+ */
38
+ export declare function goKeyedMembers(schema: IRSchema, dispatch: Dispatch, at: GoTypeContext): (readonly [string, string])[];
@@ -1,11 +1,11 @@
1
1
  import { goString } from "../shared/escape.js";
2
2
  import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
3
- import { irNames, plainNames } from "./types-names.js";
4
3
  import { isNilable } from "./types-codec.js";
4
+ import { irNames, plainNames } from "./types-names.js";
5
5
  import { isTagName, structDecl } from "./types-struct.js";
6
- import { unionDecl } from "./types-union.js";
6
+ import { unionDecl, variantTypes } from "./types-union.js";
7
7
  const RAW = "json.RawMessage";
8
- /* deeper than this, a schema is raw JSON */
8
+ // deeper than this, a schema is raw JSON
9
9
  const MAX_DEPTH = 12;
10
10
  const SCALARS = {
11
11
  boolean: "bool",
@@ -22,7 +22,7 @@ export function goTypeContext(ir) {
22
22
  function declare(ir, at, key, base) {
23
23
  const name = at.names.hoist(key, base);
24
24
  if (!at.decls.has(name)) {
25
- /* claimed before its body: what the body hoists in turn comes after it */
25
+ // claimed before its body: what the body hoists in turn comes after it
26
26
  at.decls.set(name, "");
27
27
  at.decls.set(name, goTopLevel(name, ir, at));
28
28
  }
@@ -71,7 +71,7 @@ const USES = {
71
71
  ref: refUse,
72
72
  scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
73
73
  tuple: (ir) => `[${ir.items.length}]interface{}`,
74
- /* Go has no union type */
74
+ // Go has no union type
75
75
  union: () => RAW,
76
76
  unknown: () => RAW,
77
77
  };
@@ -85,13 +85,13 @@ export function goTypeOf(ir, at) {
85
85
  /** A label for an enum value inside a constant name: `""` is `Empty`, a negative number `Neg<n>`. */
86
86
  function enumLabel(value) {
87
87
  if (typeof value === "number")
88
- return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).replace(/\W/g, "_")}`;
88
+ return `${value < 0 ? "Neg" : ""}${String(Math.abs(value)).replaceAll(/\W/g, "_")}`;
89
89
  return value === "" ? "Empty" : goExported(String(value));
90
90
  }
91
91
  /** `type <name> string|int` and one `<name><Label>` constant per value of its kind. */
92
92
  function enumDecl(name, ir, names) {
93
93
  const integer = ir.type === "integer";
94
- /* a value of the other kind (or a null) has no constant */
94
+ // a value of the other kind (or a null) has no constant
95
95
  const values = ir.enum.filter((value) => integer ? Number.isInteger(value) : value !== null);
96
96
  const labels = new NameScope();
97
97
  const consts = values.map((value) => {
@@ -132,7 +132,7 @@ function objectDecl(name, ir, at) {
132
132
  : undefined;
133
133
  return structDecl(name, { embeds: [], extra, fields });
134
134
  }
135
- /* the kinds a required field may render as a slice or a map, whose nil a MarshalJSON fills */
135
+ // the kinds a required field may render as a slice or a map, whose nil a MarshalJSON fills
136
136
  const SLICE_OR_MAP = ["allOf", "array", "nullable", "object"];
137
137
  /** A field encoding/json handles alone: a key a tag can name, never a required slice or map. */
138
138
  const plainField = (field) => isTagName(field.name) && !(field.required && SLICE_OR_MAP.includes(field.schema.kind));
@@ -172,6 +172,17 @@ export function goTopLevel(name, ir, at) {
172
172
  const variant = (schema, key, base) => declare(schema, at, key, base);
173
173
  return unionDecl(name, { ...ir, discriminator: ir.discriminator }, at.names, variant);
174
174
  }
175
- /* a map or an empty struct is a named type; anything else an alias */
175
+ // a map or an empty struct is a named type; anything else an alias
176
176
  return `type ${name} ${ir.kind === "object" ? "" : "= "}${use(ir, member(name, at, "Value"))}`;
177
177
  }
178
+ /**
179
+ * Each member of the keyed union `schema` (D9) as its value beside its Go type: a component's struct names its
180
+ * members; an inline union, raw JSON in a struct, hoists each inline member into `at` as `<Parent><Field><Value>`.
181
+ */
182
+ export function goKeyedMembers(schema, dispatch, at) {
183
+ const name = schema.kind === "ref" ? at.names.ref(schema.name) : `${goExported(at.parentName)}${goExported(at.fieldName)}`;
184
+ // a mapping names refs only, whose type is their component's: the key alone names each inline member
185
+ const union = { ...dispatch.union, discriminator: { propertyName: dispatch.key } };
186
+ const types = variantTypes(name, union, at.names, (variant, key, base) => declare(variant, at, key, base));
187
+ return dispatch.members.map(({ value }, i) => [value, types[i]]);
188
+ }
@@ -1,12 +1,5 @@
1
- /**
2
- * A WebSocket or realtime operation as a Go method. A WebSocket operation dials its socket and
3
- * returns `(*TypedWebSocket, error)`: `<Op>Opts.ReconnectToken` rides as the `reconnect_token`
4
- * query param after the declared ones, and `Protocols` are the subprotocols it offers. A realtime
5
- * operation returns `(*ResumableConnection, error)`, already open over the WebSocket, SSE and
6
- * long-poll chain, its ctx bounding the open (Fd1); its Opts carry the resume cursor, the protocols
7
- * and the reconnect policy. A declared param on a resume channel the runtime sends itself is carried
8
- * by those fields, so the wire holds one pair (Fd3). Neither declares a response a caller receives.
9
- */
1
+ import { type SdkOp } from "../../ir/sdk-model.ts";
10
2
  import { type GoStream } from "./sdk-answer.ts";
11
- /** The method of a WebSocket or realtime operation. */
12
- export declare const socketStream: (stream: "realtime" | "ws") => GoStream;
3
+ import { type GoTypeContext } from "./types.ts";
4
+ /** The method of a WebSocket or realtime operation, its message types hoisted into `at`. */
5
+ export declare const socketStream: (op: SdkOp, stream: "realtime" | "ws", at: GoTypeContext) => GoStream;
@@ -1,70 +1,226 @@
1
- /**
2
- * A WebSocket or realtime operation as a Go method. A WebSocket operation dials its socket and
3
- * returns `(*TypedWebSocket, error)`: `<Op>Opts.ReconnectToken` rides as the `reconnect_token`
4
- * query param after the declared ones, and `Protocols` are the subprotocols it offers. A realtime
5
- * operation returns `(*ResumableConnection, error)`, already open over the WebSocket, SSE and
6
- * long-poll chain, its ctx bounding the open (Fd1); its Opts carry the resume cursor, the protocols
7
- * and the reconnect policy. A declared param on a resume channel the runtime sends itself is carried
8
- * by those fields, so the wire holds one pair (Fd3). Neither declares a response a caller receives.
9
- */
1
+ import { dispatchOf, isJsonEventData } from "../../ir/sdk-model.js";
2
+ import { goString, lineComment } from "../shared/escape.js";
3
+ import { goExported, NameScope } from "../shared/lang.js";
10
4
  import { sendArgs } from "./sdk-answer.js";
11
5
  import { isLastEventIdHeader } from "./sse.js";
6
+ import { goKeyedMembers, goTypeOf } from "./types.js";
12
7
  /** Whether a declared param is the `reconnect_token` query param a WebSocket dial sends. */
13
8
  const isReconnectToken = (param, where) => where === "query" && param === "reconnect_token";
14
- /* both open a socket: a dial fails before any stream exists */
9
+ // both open a socket: a dial fails before any stream exists
15
10
  const FAIL = "nil, err";
16
- const WS_STREAM = {
17
- doc: "",
18
- opts: {
19
- before: [],
20
- carries: isReconnectToken,
21
- fields: [
22
- { name: "ReconnectToken", type: "string" },
23
- { name: "Protocols", type: "[]string" },
24
- ],
25
- sets: [
26
- 'if opts.ReconnectToken != "" {',
27
- '\tc.query.set("reconnect_token", opts.ReconnectToken)',
28
- "}",
29
- "c.protocols = opts.Protocols",
30
- ],
31
- },
32
- shape: {
33
- fail: FAIL,
34
- returns: "(*TypedWebSocket, error)",
35
- tail: (client) => [`\treturn dialWebSocket(${sendArgs(client)})`],
36
- },
11
+ const WS_OPTS = {
12
+ before: [],
13
+ carries: isReconnectToken,
14
+ fields: [
15
+ { name: "ReconnectToken", type: "string" },
16
+ { name: "Protocols", type: "[]string" },
17
+ ],
18
+ sets: [
19
+ 'if opts.ReconnectToken != "" {',
20
+ '\tc.query.set("reconnect_token", opts.ReconnectToken)',
21
+ "}",
22
+ "c.protocols = opts.Protocols",
23
+ ],
24
+ };
25
+ const WS = {
26
+ base: "TypedWebSocket",
27
+ handlers: ["OnMessage", "OnClose", "OnError"],
28
+ open: (client, read, write) => `dialWebSocket(${sendArgs(client, read, write)})`,
29
+ suffix: "Socket",
30
+ what: "socket",
37
31
  };
38
- /* the realtime Opts' own fields: each is the TransportOpts field of its name, which `sets` copies */
32
+ const REALTIME = {
33
+ base: "ResumableConnection",
34
+ handlers: ["OnMessage"],
35
+ open: (client, read, write) => `newRealtime(${sendArgs(client, "topts", read, write)})`,
36
+ suffix: "Connection",
37
+ what: "connection",
38
+ };
39
+ /** `<Op><direction>`, the sealed interface of the keyed union `schema`'s members, each marked as one; its lines. */
40
+ function sealed(op, members, iface, says) {
41
+ const types = [...new Set(members.map(([, type]) => type))];
42
+ return [
43
+ ...lineComment(`${iface} is a message ${says} on ${op.id}: ${types.join(", ")}.`, "//"),
44
+ `type ${iface} interface {`,
45
+ `\tis${iface}()`,
46
+ "}",
47
+ ...types.flatMap((type) => ["", `func (${type}) is${iface}() {}`]),
48
+ ];
49
+ }
50
+ /**
51
+ * The read side of `op`'s socket from what the server sends (`send`): `<Op>Inbound` when keyed, declared in `at` with
52
+ * `<Op>OtherMessage` for a value it does not declare and the decoder reading a frame by its key; else its Go type,
53
+ * read as JSON; `untyped()` when it declares none.
54
+ */
55
+ function inbound(op, send, untyped, at) {
56
+ if (send === undefined)
57
+ return untyped();
58
+ const here = { ...at, fieldName: "Send", parentName: op.id };
59
+ const dispatch = dispatchOf(send, at.names.resolve);
60
+ if (dispatch !== undefined)
61
+ return keyedInbound(op, send, dispatch, here);
62
+ const type = goTypeOf(send, here).replace(/^\*/, "");
63
+ return { codec: `frameJSON[${type}]`, type };
64
+ }
65
+ /** `<Op>Inbound`, its types, `<Op>OtherMessage` and its decoder, declared in one block in `at`. */
66
+ function keyedInbound(op, send, dispatch, at) {
67
+ const members = goKeyedMembers(send, dispatch, at);
68
+ const base = goExported(op.id);
69
+ const iface = at.names.claimConst(`${base}Inbound`);
70
+ const other = at.names.claimConst(`${base}OtherMessage`);
71
+ const decode = at.names.claimConst(`decode${iface}`);
72
+ const key = goString(dispatch.key);
73
+ at.decls.set(iface, [
74
+ ...sealed(op, [...members, ["", other]], iface, "the server sends"),
75
+ "",
76
+ ...lineComment(`${other} is a message whose ${key} ${op.id} does not declare, as sent.`, "//"),
77
+ `type ${other} struct {`,
78
+ "\tRaw json.RawMessage",
79
+ "}",
80
+ "",
81
+ "// MarshalJSON is the message as sent.",
82
+ `func (m ${other}) MarshalJSON() ([]byte, error) { return m.Raw.MarshalJSON() }`,
83
+ "",
84
+ `// ${decode} is a frame as the message its ${key} names.`,
85
+ `func ${decode}(data []byte) (${iface}, error) {`,
86
+ `\tkey, err := frameKey(data, ${key})`,
87
+ "\tif err != nil {",
88
+ "\t\treturn nil, err",
89
+ "\t}",
90
+ "\tswitch key {",
91
+ ...members.flatMap(([value, type]) => [
92
+ `\tcase ${goString(value)}:`,
93
+ `\t\tm, err := frameJSON[${type}](data)`,
94
+ "\t\treturn m, err",
95
+ ]),
96
+ "\t}",
97
+ `\treturn ${other}{Raw: data}, nil`,
98
+ "}",
99
+ ].join("\n"));
100
+ return { codec: decode, decode, key: dispatch.key, members, type: iface };
101
+ }
102
+ // a send of an op that declares none: as given
103
+ const UNTYPED_OUT = { codec: "messageAsIs", type: "any" };
104
+ /** The fields `schema` requires at its top level: an object's, none for any other schema. */
105
+ function requiredOf(schema, at) {
106
+ const resolved = at.names.resolve(schema);
107
+ return resolved.kind === "object" ? resolved.fields.filter((field) => field.required).map((field) => field.name) : [];
108
+ }
109
+ /** The write side of `op`'s socket from what the server receives (`receive`): `<Op>Outbound` when keyed, else its Go type, written as JSON; `any` when it declares none. */
110
+ function outbound(op, receive, at) {
111
+ if (receive === undefined)
112
+ return UNTYPED_OUT;
113
+ const here = { ...at, fieldName: "Receive", parentName: op.id };
114
+ const dispatch = dispatchOf(receive, at.names.resolve);
115
+ if (dispatch === undefined) {
116
+ const type = goTypeOf(receive, here).replace(/^\*/, "");
117
+ return { codec: `messageJSON[${type}]`, sends: { key: null, required: requiredOf(receive, at), type }, type };
118
+ }
119
+ const members = goKeyedMembers(receive, dispatch, here);
120
+ const iface = at.names.claimConst(`${goExported(op.id)}Outbound`);
121
+ at.decls.set(iface, sealed(op, members, iface, "the server receives").join("\n"));
122
+ const sends = {
123
+ key: dispatch.key,
124
+ members: members.map(([value, type], i) => ({
125
+ required: requiredOf(dispatch.members[i]?.variant, at),
126
+ type,
127
+ value,
128
+ })),
129
+ };
130
+ return { codec: `messageJSON[${iface}]`, sends, type: iface };
131
+ }
132
+ /** `<Op><suffix>` around `base`, an On<Value> per member whose method no handler names, declared in `at`; null when none is left. */
133
+ function socketType(op, kind, { base, read }, at) {
134
+ const scope = new NameScope(kind.handlers);
135
+ const handlers = read.members.flatMap(([value, type]) => {
136
+ const method = `On${goExported(value)}`;
137
+ return scope.has(method) ? [] : [{ method: scope.claim(method), type, value }];
138
+ });
139
+ if (handlers.length === 0)
140
+ return null;
141
+ const name = at.names.claimConst(`${goExported(op.id)}${kind.suffix}`);
142
+ at.decls.set(name, [
143
+ ...lineComment(`${name} is the ${kind.what} of ${op.id}: each On<Value> takes the messages whose ${goString(read.key)} is that value.`, "//"),
144
+ `type ${name} struct {`,
145
+ `\t*${base}`,
146
+ "}",
147
+ ...handlers.flatMap(({ method, type, value }) => [
148
+ "",
149
+ `// ${method} registers a handler for each ${goString(value)} message.`,
150
+ `func (s *${name}) ${method}(handler func(${type})) {`,
151
+ `\ts.OnMessage(func(m ${read.type}) {`,
152
+ `\t\tif v, ok := m.(${type}); ok {`,
153
+ "\t\t\thandler(v)",
154
+ "\t\t}",
155
+ "\t})",
156
+ "}",
157
+ ]),
158
+ ].join("\n"));
159
+ return name;
160
+ }
161
+ /** `op`'s answer of `kind`: its runtime type of both sides, or its own type around it; the call that opens it; what it sends, typed. */
162
+ function answerOf(op, kind, { read, write }, at) {
163
+ const base = `${kind.base}[${read.type}, ${write.type}]`;
164
+ const call = (client) => kind.open(client, read.codec, write.codec);
165
+ const keyed = "decode" in read ? read : undefined;
166
+ const own = keyed && socketType(op, kind, { base, read: keyed }, at);
167
+ return {
168
+ calls: keyed ? [keyed.decode] : [],
169
+ ...(write.sends === undefined ? {} : { sends: write.sends }),
170
+ shape: own
171
+ ? {
172
+ fail: FAIL,
173
+ returns: `(*${own}, error)`,
174
+ tail: (client) => [
175
+ `\tconn, err := ${call(client)}`,
176
+ "\tif err != nil {",
177
+ "\t\treturn nil, err",
178
+ "\t}",
179
+ `\treturn &${own}{conn}, nil`,
180
+ ],
181
+ }
182
+ : { fail: FAIL, returns: `(*${base}, error)`, tail: (client) => [`\treturn ${call(client)}`] },
183
+ };
184
+ }
185
+ /** The method of the WebSocket operation `op`, its message types hoisted into `at`. */
186
+ function wsStream(op, at) {
187
+ const { receive, send } = op.ir.messages ?? {};
188
+ const read = inbound(op, send, () => ({ codec: "frameBytes", type: "[]byte" }), at);
189
+ return { ...answerOf(op, WS, { read, write: outbound(op, receive, at) }, at), doc: "", opts: WS_OPTS };
190
+ }
191
+ // the realtime Opts' one own field, which `sets` copies: the method sets its Headers and HTTPClient
39
192
  const REALTIME_FIELDS = [
40
- { name: "LastEventID", type: "string" },
41
- { name: "ReconnectToken", type: "string" },
42
- { name: "Protocols", type: "[]string" },
43
193
  {
44
- doc: "MaxReconnectAttempts caps reconnects after a drop. Zero means 5; negative means unlimited.",
45
- name: "MaxReconnectAttempts",
46
- type: "int",
194
+ doc: "Transport is the resume cursor, the offered subprotocols and the reconnect policy; the connection advances its own copy, and the client sets Headers and HTTPClient.",
195
+ name: "Transport",
196
+ type: "TransportOpts",
47
197
  },
48
- { doc: "ReconnectDelayMs is the first backoff delay. Zero means 1000.", name: "ReconnectDelayMs", type: "int" },
49
198
  ];
50
- const REALTIME_STREAM = {
51
- doc: "The connection is open on return; Close it when done.",
52
- opts: {
53
- before: ["var topts TransportOpts"],
54
- /* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
55
- carries: (param, where) => isReconnectToken(param, where) ||
56
- (where === "query" && param === "last_event_id") ||
57
- isLastEventIdHeader(param, where),
58
- fields: REALTIME_FIELDS,
59
- sets: [
60
- "topts = TransportOpts{LastEventID: opts.LastEventID, ReconnectToken: opts.ReconnectToken, Protocols: opts.Protocols, MaxReconnectAttempts: opts.MaxReconnectAttempts, ReconnectDelayMs: opts.ReconnectDelayMs}",
61
- ],
62
- },
63
- shape: {
64
- fail: FAIL,
65
- returns: "(*ResumableConnection, error)",
66
- tail: (client) => [`\treturn newRealtime(${sendArgs(client, "topts")})`],
67
- },
199
+ const REALTIME_OPTS = {
200
+ before: ["var topts TransportOpts"],
201
+ // the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
202
+ carries: (param, where) => isReconnectToken(param, where) ||
203
+ (where === "query" && param === "last_event_id") ||
204
+ isLastEventIdHeader(param, where),
205
+ fields: REALTIME_FIELDS,
206
+ sets: ["topts = opts.Transport"],
68
207
  };
69
- /** The method of a WebSocket or realtime operation. */
70
- export const socketStream = (stream) => (stream === "ws" ? WS_STREAM : REALTIME_STREAM);
208
+ /** A realtime op's messages read without a declared `send`: the declared event schema's type, else each as its JSON value or text. */
209
+ function eventSide(op, at) {
210
+ if (op.events === undefined || !isJsonEventData(op.events, at.names.resolve))
211
+ return { codec: "framePayload", type: "any" };
212
+ const type = goTypeOf(op.events, { ...at, fieldName: "Event", parentName: op.id }).replace(/^\*/, "");
213
+ return { codec: `frameJSON[${type}]`, type };
214
+ }
215
+ /** The method of the realtime operation `op`, its message types hoisted into `at`. */
216
+ function realtimeStream(op, at) {
217
+ const { receive, send } = op.ir.messages ?? {};
218
+ const read = inbound(op, send, () => eventSide(op, at), at);
219
+ return {
220
+ ...answerOf(op, REALTIME, { read, write: outbound(op, receive, at) }, at),
221
+ doc: "The connection is open on return; Close it when done.",
222
+ opts: REALTIME_OPTS,
223
+ };
224
+ }
225
+ /** The method of a WebSocket or realtime operation, its message types hoisted into `at`. */
226
+ export const socketStream = (op, stream, at) => stream === "ws" ? wsStream(op, at) : realtimeStream(op, at);
@@ -6,8 +6,6 @@ export type JavaPackage = {
6
6
  readonly packageName: string;
7
7
  readonly version: string;
8
8
  };
9
- /** The one runtime dependency, its coordinates pinned with the test classpath's (java-pins.json). */
10
- export declare const JACKSON = "tools.jackson.core:jackson-databind:3.2.4";
11
9
  /** A Maven group id: lowercase dotted words. */
12
10
  export declare const validateGroupId: (value: string) => string;
13
11
  /** A Maven artifact id: lowercase words joined by `-`. */
@@ -21,23 +19,23 @@ export declare const validateVersion: (value: string) => string;
21
19
  /** What Maven Central requires of a POM beyond its name and description, each part the caller gave, validated. */
22
20
  export type JavaPomMetadata = {
23
21
  /** the POM's description, over the document's */
24
- readonly description?: string;
22
+ readonly description?: string | undefined;
25
23
  /** the project's https home page, the POM's `url` */
26
- readonly homepage?: string;
24
+ readonly homepage?: string | undefined;
27
25
  /** one SPDX license id */
28
- readonly license?: string;
26
+ readonly license?: string | undefined;
29
27
  /** the https URL of its git repository, without a trailing `/` or `.git` */
30
- readonly repository?: string;
28
+ readonly repository?: string | undefined;
31
29
  /** the POM's developers, comma separated: each a name, or `Name <email>` */
32
- readonly developers?: string;
30
+ readonly developers?: string | undefined;
33
31
  };
34
32
  /** The POM metadata validated: the developers one entry each. */
35
33
  type PomFields = Omit<JavaPomMetadata, "developers"> & {
36
- readonly developers?: readonly string[];
34
+ readonly developers?: readonly string[] | undefined;
37
35
  };
38
36
  /** The POM's words: the document's name and description (spec text, written only through `groovyString`), the rest. */
39
37
  export type JavaPom = PomFields & {
40
- readonly name?: string;
38
+ readonly name?: string | undefined;
41
39
  };
42
40
  /** The POM for `options` over the document's `info`: the metadata validated, its description over the document's. */
43
41
  export declare function pomOf(options: JavaPomMetadata, info: {