@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,9 +1,9 @@
1
1
  import { irResolver } from "../../ir/schema.js";
2
2
  import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
3
3
  import { runtimeFiles, runtimeTypeNames } from "./transport.js";
4
- /* the BCL names emitted text spells unqualified, by the namespace a `using` brings them from (§4.7) */
4
+ // the BCL names emitted text spells unqualified, by the namespace a `using` brings them from (§4.7)
5
5
  export const BCL = {
6
- System: ["Exception", "Func", "IDisposable", "Object", "String", "TimeSpan", "Type"],
6
+ System: ["Action", "Exception", "Func", "IDisposable", "Object", "String", "TimeSpan", "Type"],
7
7
  "System.Collections.Generic": ["IDictionary", "IReadOnlyDictionary", "IReadOnlyList"],
8
8
  "System.Text.Json": [
9
9
  "JsonElement",
@@ -30,13 +30,11 @@ export const BCL = {
30
30
  "System.Threading": ["CancellationToken"],
31
31
  "System.Threading.Tasks": ["Task"],
32
32
  };
33
- /*
34
- * the BCL names the vendored runtime spells unqualified (as a type or by static access) and emitted text never does:
35
- * the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
36
- */
33
+ // the BCL names the vendored runtime spells unqualified (as a type or by static access) and emitted text never does:
34
+ // the emitted types share the runtime's namespace (Fb2), so each is reserved, never a `using`
37
35
  export const RUNTIME_BCL = [
38
- "Action",
39
36
  "Array",
37
+ "BrotliStream",
40
38
  "ByteArrayContent",
41
39
  "CancellationTokenRegistration",
42
40
  "CancellationTokenSource",
@@ -48,6 +46,7 @@ export const RUNTIME_BCL = [
48
46
  "Encoding",
49
47
  "Enum",
50
48
  "EqualityComparer",
49
+ "GZipStream",
51
50
  "Guid",
52
51
  "HashCode",
53
52
  "HashSet",
@@ -95,7 +94,7 @@ export const RUNTIME_BCL = [
95
94
  "StringBuilder",
96
95
  "StringComparer",
97
96
  "StringComparison",
98
- /* System.Threading's, also a runtime property: the scan cannot tell `Timeout.InfiniteTimeSpan` (CS0117) from it */
97
+ // System.Threading's, also a runtime property: the scan cannot tell `Timeout.InfiniteTimeSpan` (CS0117) from it
99
98
  "Timeout",
100
99
  "UnicodeCategory",
101
100
  "Uri",
@@ -109,7 +108,7 @@ export const RUNTIME_BCL = [
109
108
  "WebSocketMessageType",
110
109
  "WebSocketState",
111
110
  ];
112
- /* the attributes emitted text spells without their `Attribute` suffix: the suffixed name is taken too */
111
+ // the attributes emitted text spells without their `Attribute` suffix: the suffixed name is taken too
113
112
  const ATTRIBUTES = [
114
113
  "JsonConverter",
115
114
  "JsonExtensionData",
@@ -125,7 +124,7 @@ const reserved = (taken) => [
125
124
  ...Object.values(BCL).flat(),
126
125
  ...RUNTIME_BCL,
127
126
  ...ATTRIBUTES.map((name) => `${name}Attribute`),
128
- /* the static class of the API's error keys (errors.ts), declared beside the types when any key is */
127
+ // the static class of the API's error keys (errors.ts), declared beside the types when any key is
129
128
  "ErrorKey",
130
129
  "System",
131
130
  ...taken,
@@ -161,7 +160,7 @@ export function irNames(schemas, taken, declares) {
161
160
  hoisted.set(key, name);
162
161
  return name;
163
162
  },
164
- /* a ref reaches here only for a declared component: `alias` answers for every other one */
163
+ // a ref reaches here only for a declared component: `alias` answers for every other one
165
164
  ref: (name) => components.get(name),
166
165
  renamed,
167
166
  resolve: irResolver(schemas),
@@ -169,9 +168,9 @@ export function irNames(schemas, taken, declares) {
169
168
  }
170
169
  /** `code` without its string and char literals and comments: the text that spells names. */
171
170
  const codeOf = (code) => code
172
- .replace(/"(?:[^"\\\n]|\\.)*"/g, '""')
173
- .replace(/'(?:[^'\\\n]|\\.)'/g, "''")
174
- .replace(/\/\/.*$/gm, "");
171
+ .replaceAll(/"(?:[^"\\\n]|\\.)*"/g, '""')
172
+ .replaceAll(/'(?:[^'\\\n]|\\.)'/g, "''")
173
+ .replaceAll(/\/\/.*$/gm, "");
175
174
  /** The `using` lines `code` needs: each namespace one of whose BCL names it spells as a type, in code-unit order. */
176
175
  export function usings(code) {
177
176
  const text = codeOf(code);
@@ -1,6 +1,6 @@
1
1
  import { csString } from "../shared/escape.js";
2
2
  import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
3
- /* every member name a record property collides with (CS0102, CS0108, CS8859, CS8874), and the name its attributes spell in an expression */
3
+ // every member name a record property collides with (CS0102, CS0108, CS8859, CS8874), and the name its attributes spell in an expression
4
4
  export const RECORD_MEMBERS = [
5
5
  "Clone",
6
6
  "EqualityContract",
@@ -12,7 +12,7 @@ export const RECORD_MEMBERS = [
12
12
  "PrintMembers",
13
13
  "ToString",
14
14
  ];
15
- /* a required nullable member is written even when null; an unset tri-state or open value is not written */
15
+ // a required nullable member is written even when null; an unset tri-state or open value is not written
16
16
  const NEVER = "[JsonIgnore(Condition = JsonIgnoreCondition.Never)]";
17
17
  const UNSET = "[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]";
18
18
  /** One property's lines, unindented: its attributes, then `public <type> <name> { get; init; }`. */
@@ -25,7 +25,7 @@ function propertyLines(field, name, member, at) {
25
25
  return [key, UNSET, `public ${type} ${name} { get; init; }`];
26
26
  if (!type.endsWith("?"))
27
27
  return [key, `public ${type}? ${name} { get; init; }`];
28
- /* OptConverter reads T through the context: it must list T */
28
+ // OptConverter reads T through the context: it must list T
29
29
  at.serialized.add(type);
30
30
  return [key, `[JsonConverter(typeof(OptConverter<${type}>))]`, UNSET, `public Opt<${type}> ${name} { get; init; }`];
31
31
  }
@@ -11,7 +11,7 @@ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
11
11
  kind: K;
12
12
  }>;
13
13
  /** Declares `schema` once under `names.hoist(key, base)`; its name. */
14
- export type Declare = (schema: IRSchema, key: string, base: string) => string;
14
+ type Declare = (schema: IRSchema, key: string, base: string) => string;
15
15
  /** What a union's declaration reaches: the context, its members' types, and the hoist. */
16
16
  export type UnionScope = {
17
17
  at: CsTypeContext;
@@ -7,7 +7,6 @@
7
7
  */
8
8
  import type { IR, IRSchema } from "../../ir/model.ts";
9
9
  import { type CsTypeNames } from "./types-names.ts";
10
- export type { CsTypeNames } from "./types-names.ts";
11
10
  /** Where a type is being written, the declarations it hoists, the names, and what the JSON context gathers. */
12
11
  export type CsTypeContext = {
13
12
  parentName: string;
@@ -5,7 +5,7 @@ import { fieldsOf, isOpen, recordDecl } from "./types-record.js";
5
5
  import { isLiteral, unionDecl } from "./types-union.js";
6
6
  export const JSON_ELEMENT = "JsonElement";
7
7
  const MAP = "IReadOnlyDictionary<string, ";
8
- /* deeper than this, a schema is any JSON value */
8
+ // deeper than this, a schema is any JSON value
9
9
  const MAX_DEPTH = 12;
10
10
  const SCALARS = {
11
11
  boolean: "bool",
@@ -45,7 +45,7 @@ export function declares(ir) {
45
45
  function declare(ir, at, key, base) {
46
46
  const name = at.names.hoist(key, base);
47
47
  if (!at.decls.has(name)) {
48
- /* claimed before its body: what the body hoists in turn comes after it */
48
+ // claimed before its body: what the body hoists in turn comes after it
49
49
  at.decls.set(name, "");
50
50
  at.decls.set(name, csTopLevel(name, ir, at));
51
51
  }
@@ -98,7 +98,7 @@ const USES = {
98
98
  ref: refUse,
99
99
  scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
100
100
  tuple: () => `IReadOnlyList<${JSON_ELEMENT}>`,
101
- /* a union in use position is any JSON value; a component union is declared (Fb7) */
101
+ // a union in use position is any JSON value; a component union is declared (Fb7)
102
102
  union: () => JSON_ELEMENT,
103
103
  unknown: () => JSON_ELEMENT,
104
104
  };
@@ -1,19 +1,4 @@
1
- /**
2
- * A WebSocket operation's answer (contract 50 §2, Fd5): `Task<TypedWebSocket>` through `SocketAsync`, opened by
3
- * awaiting the method and dialed offering `protocols`, its `reconnectToken` sent as one query param only when set and
4
- * non-empty; a declared `reconnect_token` query param is folded into that field.
5
- */
6
1
  import type { CsStream } from "./sdk-answer.ts";
7
- /** The subprotocols a WebSocket or realtime dial offers. */
8
- export declare const PROTOCOLS: {
9
- ident: string;
10
- type: string;
11
- };
12
- /** The resume cursor's token, which the WebSocket and realtime methods take. */
13
- export declare const RECONNECT_TOKEN: {
14
- ident: string;
15
- type: string;
16
- };
17
2
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
18
3
  export declare const isReconnectToken: (name: string, where: string) => boolean;
19
4
  /** The WebSocket operation's answer, its two fields and its `<returns>` text. */
@@ -1,12 +1,33 @@
1
- /** The subprotocols a WebSocket or realtime dial offers. */
2
- export const PROTOCOLS = { ident: "protocols", type: "IReadOnlyList<string>?" };
3
- /** The resume cursor's token, which the WebSocket and realtime methods take. */
4
- export const RECONNECT_TOKEN = { ident: "reconnectToken", type: "string?" };
1
+ import { messageType, valueHandlers } from "./types-messages.js";
2
+ import { JSON_ELEMENT } from "./types.js";
3
+ /** The subprotocols a WebSocket dial offers. */
4
+ const PROTOCOLS = { ident: "protocols", type: "IReadOnlyList<string>?" };
5
+ /** The resume cursor's token, which the WebSocket method takes. */
6
+ const RECONNECT_TOKEN = { ident: "reconnectToken", type: "string?" };
7
+ // the typed socket, and its own events: a member whose On<Value> one of them names gets none
8
+ const READER = { base: "TypedWebSocket", handlers: ["OnMessage", "OnClose", "OnError"], receiver: "socket" };
5
9
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
6
10
  export const isReconnectToken = (name, where) => where === "query" && name === "reconnect_token";
11
+ /** The WebSocket operation `op`'s answer, its message types hoisted into `env.at`. */
12
+ function wsAnswer(op, { at }) {
13
+ if (op.ir.messages === undefined)
14
+ return { render: () => ["Task<TypedWebSocket>", "SocketAsync"], type: null };
15
+ const { receive, send } = op.ir.messages;
16
+ const read = send === undefined ? { type: JSON_ELEMENT } : messageType(op, send, "Send", at);
17
+ const write = receive === undefined ? { type: JSON_ELEMENT } : messageType(op, receive, "Receive", at);
18
+ valueHandlers(READER, read, at);
19
+ return {
20
+ infos: [read.type, write.type],
21
+ render: (spell) => [
22
+ `Task<TypedWebSocket<${spell.runtime(read.type)}, ${spell.runtime(write.type)}>>`,
23
+ "TypedSocketAsync",
24
+ ],
25
+ type: null,
26
+ };
27
+ }
7
28
  /** The WebSocket operation's answer, its two fields and its `<returns>` text. */
8
29
  export const wsStream = {
9
- answer: () => ({ render: () => ["Task<TypedWebSocket>", "SocketAsync"], type: null }),
30
+ answer: wsAnswer,
10
31
  args: ["protocols", "reconnectToken"],
11
32
  carries: isReconnectToken,
12
33
  fields: [PROTOCOLS, RECONNECT_TOKEN],
@@ -5,7 +5,7 @@ import { goTopLevel } from "./types.js";
5
5
  /** Every declared key's schema (the first operation's to declare one), keys in code-unit order. */
6
6
  function declaredKeys(model) {
7
7
  const declared = model.ops.flatMap((op) => Object.entries(op.ir.extensions.errors ?? {}));
8
- /* reversed, so a key ends on its first declaration */
8
+ // reversed, so a key ends on its first declaration
9
9
  const first = new Map(declared.toReversed().map(([key, { schema }]) => [key, schema]));
10
10
  return [...first].sort(([a], [b]) => compareCodeUnits(a, b));
11
11
  }
@@ -6,7 +6,7 @@
6
6
  */
7
7
  import { readFileSync } from "node:fs";
8
8
  import { compareCodeUnits } from "../shared/lang.js";
9
- /* every SDK: config, request, auth, redirects, errors, SSE, invalidation */
9
+ // every SDK: config, request, auth, redirects, errors, SSE, invalidation
10
10
  const CORE = [
11
11
  "auth",
12
12
  "body",
@@ -27,7 +27,7 @@ const CORE = [
27
27
  "stale",
28
28
  "stream",
29
29
  ];
30
- /* a WebSocket operation; realtime adds the resumable transports on top of it */
30
+ // a WebSocket operation; realtime adds the resumable transports on top of it
31
31
  const WS = ["ws"];
32
32
  const REALTIME = ["realtime", "realtime_loop", "transport", "transport_longpoll", "transport_sse"];
33
33
  /** The runtime file names an SDK with `features` ships, in code-unit order. */
@@ -6,9 +6,9 @@
6
6
  * so the two can never disagree.
7
7
  */
8
8
  import { checked, SEMVER } from "../shared/metadata.js";
9
- /* a dotted domain, then path elements (Go's module.CheckPath, less its rarely used characters) */
9
+ // a dotted domain, then path elements (Go's module.CheckPath, less its rarely used characters)
10
10
  const MODULE_PATH = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)+(?:\/[A-Za-z0-9_~-](?:[A-Za-z0-9._~-]*[A-Za-z0-9_~-])?)*$/;
11
- /* a last element Go reads as a major version suffix, and the ones it takes */
11
+ // a last element Go reads as a major version suffix, and the ones it takes
12
12
  const SUFFIX = /\/v[\d.]+$/;
13
13
  const MAJOR = /\/v(?:[2-9]|[1-9]\d+)$/;
14
14
  /** `modulePath` with the major suffix `version` gives from v2 on, each refused unless Go would take it. */
@@ -11,11 +11,34 @@ export type Shape = {
11
11
  readonly fail: string;
12
12
  readonly tail: (client: string) => string[];
13
13
  };
14
- /** What a streaming operation's method is: how it answers, what its Opts add, and the note its godoc ends on. */
14
+ /**
15
+ * What a streaming operation's method is: how it answers, what its Opts add, the note its godoc ends on, and the
16
+ * package-level functions declared for it that its body calls, which a path param never shadows.
17
+ */
15
18
  export type GoStream = {
16
19
  readonly shape: Shape;
17
20
  readonly opts: StreamOpts;
18
21
  readonly doc: string;
22
+ readonly calls: readonly string[];
23
+ /** what a socket's server receives, typed; absent for an SSE op and a socket that declares no `receive` */
24
+ readonly sends?: GoSends;
25
+ };
26
+ /** A message type the server receives: its Go type, and the fields it requires at its top level. */
27
+ export type GoMessageType = {
28
+ readonly type: string;
29
+ readonly required: readonly string[];
30
+ };
31
+ /**
32
+ * What a socket's server receives, as the CLI checks an input line against it: one message type,
33
+ * or a union keyed on `key` (D9), each member by its value.
34
+ */
35
+ export type GoSends = (GoMessageType & {
36
+ readonly key: null;
37
+ }) | {
38
+ readonly key: string;
39
+ readonly members: readonly (GoMessageType & {
40
+ readonly value: string;
41
+ })[];
19
42
  };
20
43
  /** The runtime call's arguments: the ctx, the client's config, the call, each of `extra`, then the per-call options. */
21
44
  export declare const sendArgs: (client: string, ...extra: string[]) => string;
@@ -1,6 +1,6 @@
1
1
  /** The runtime call's arguments: the ctx, the client's config, the call, each of `extra`, then the per-call options. */
2
2
  export const sendArgs = (client, ...extra) => ["ctx", `${client}.cfg`, "c", ...extra, "reqOpts"].join(", ");
3
- /* an operation answering without a body */
3
+ // an operation answering without a body
4
4
  const NO_BODY_SHAPE = {
5
5
  fail: "err",
6
6
  returns: "error",
@@ -1,9 +1,9 @@
1
1
  import { goString, lineComment } from "../shared/escape.js";
2
2
  import { goExported, NameScope } from "../shared/lang.js";
3
3
  import { goTypeOf } from "./types.js";
4
- /* a body sent as it is: nothing to encode first */
4
+ // a body sent as it is: nothing to encode first
5
5
  const NO_LINES = () => [];
6
- /* a text part's Go type by its scalar type (v0 codegen-go.ts:382-391); any other schema is sent as a string */
6
+ // a text part's Go type by its scalar type (v0 codegen-go.ts:382-391); any other schema is sent as a string
7
7
  const PART_SCALARS = {
8
8
  boolean: "bool",
9
9
  integer: "int64",
@@ -15,7 +15,7 @@ const PART_SCALARS = {
15
15
  const appended = (indent, part) => `${indent}fields = append(fields, ${part})`;
16
16
  /** The field of `part` named `name` on the body `local`: a list repeats the part, an unset value sends none. */
17
17
  function partField(part, name, local, at) {
18
- /* the IR gives every part its schema (ir/slots.ts partsOf, sdk-model bodyOf) */
18
+ // the IR gives every part its schema (ir/slots.ts partsOf, sdk-model bodyOf)
19
19
  const schema = at.names.resolve(part.schema);
20
20
  const list = schema.kind === "array";
21
21
  const item = schema.kind === "array" ? at.names.resolve(schema.items) : schema;
@@ -64,13 +64,17 @@ export function goBody(op, body, env) {
64
64
  const type = goTypeOf(body.schema, { ...env.at, fieldName: "Body", parentName: op.id });
65
65
  return { lines: NO_LINES, send: `jsonBody(${local})`, type };
66
66
  }
67
- case "form":
67
+ case "form": {
68
68
  return { lines: NO_LINES, send: `formBody(${local})`, type: "url.Values" };
69
- case "binary":
69
+ }
70
+ case "binary": {
70
71
  return { lines: NO_LINES, send: `readerBody(${local}, ${contentType})`, type: "io.Reader" };
71
- case "text":
72
+ }
73
+ case "text": {
72
74
  return { lines: NO_LINES, send: `rawBody([]byte(${local}), ${contentType})`, type: "string" };
73
- case "multipart":
75
+ }
76
+ case "multipart": {
74
77
  return multipartBody(op, body.parts, env);
78
+ }
75
79
  }
76
80
  }
@@ -4,7 +4,7 @@ import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
4
4
  import { MIRROR, mirrorNotice } from "../shared/mirror.js";
5
5
  import { goMethod } from "./sdk-method.js";
6
6
  import { twinLines, twinLiteral, twinTypeLines, twinTypes } from "./sdk-mirror.js";
7
- /* the mirror as Go spells it, Client's method: goExported(MIRROR) */
7
+ // the mirror as Go spells it, Client's method: goExported(MIRROR)
8
8
  const SAFE = "Safe";
9
9
  /**
10
10
  * A member's name in `members`, `segment` exported; at the root (`path` empty) one spelled like the mirror is
@@ -1,4 +1,5 @@
1
1
  import { type SdkBody, type SdkOp, type SdkResponseKind, type SdkStream } from "../../ir/sdk-model.ts";
2
+ import { type GoSends } from "./sdk-answer.ts";
2
3
  import { type GoPart } from "./sdk-body.ts";
3
4
  import { type GoResponseHeaders } from "./sdk-opts.ts";
4
5
  import { type GoTypeContext } from "./types.ts";
@@ -32,6 +33,8 @@ export type GoMethodCall = {
32
33
  readonly opts: string;
33
34
  /** a multipart body's parts by their `<Op>Body` fields; null for any other body */
34
35
  readonly parts: readonly GoPart[] | null;
36
+ /** what a socket's server receives, typed: the CLI checks each input line against it; null when untyped or no socket */
37
+ readonly sends: GoSends | null;
35
38
  };
36
39
  /**
37
40
  * One operation's method, its client.go declarations by name (`<Op>Opts`, `<Op>Headers`), how a caller reaches it,
@@ -3,14 +3,15 @@ import { goString, lineComment } from "../shared/escape.js";
3
3
  import { goExported, goLocal, NameScope } from "../shared/lang.js";
4
4
  import { shapeOf } from "./sdk-answer.js";
5
5
  import { goBody } from "./sdk-body.js";
6
- import { optsDecl, optsFields, optsLines, responseHeaders } from "./sdk-opts.js";
6
+ import { optsDecl, optsFields, optsLines, responseHeaders, } from "./sdk-opts.js";
7
7
  import { sseStream } from "./sse.js";
8
8
  import { goTypeOf } from "./types.js";
9
9
  import { socketStream } from "./ws.js";
10
- /* the receiver, the method's own locals and the unexported runtime names its body calls: a path param never shadows one */
10
+ // the receiver, the method's own locals and the unexported runtime names its body calls: a path param never shadows one
11
11
  const METHOD_LOCALS = [
12
12
  "c",
13
13
  "call",
14
+ "conn",
14
15
  "ctx",
15
16
  "data",
16
17
  "decodeJSON",
@@ -37,8 +38,9 @@ const METHOD_LOCALS = [
37
38
  "result",
38
39
  "setHeaderValue",
39
40
  "setIdempotencyKey",
41
+ "sseData",
40
42
  "sseFail",
41
- "streamJSON",
43
+ "streamEvents",
42
44
  "streamText",
43
45
  "textField",
44
46
  "topts",
@@ -69,15 +71,18 @@ function methodDoc(op, name, stream) {
69
71
  const text = [route, op.summary, op.description].filter((part) => part !== "");
70
72
  return lineComment(text.join("\n\n"), "//");
71
73
  }
72
- /** How the method of `op` answers, and its stream: null for an operation that answers once. */
74
+ /**
75
+ * How the method of `op` answers, its stream (null for an operation that answers once), and the method's locals: the
76
+ * runtime's names, and the stream's own.
77
+ */
73
78
  function answering(op, env) {
74
79
  if (op.stream !== null) {
75
- const stream = op.stream === "sse" ? sseStream(op, env.at) : socketStream(op.stream);
76
- return { shape: stream.shape, stream };
80
+ const stream = op.stream === "sse" ? sseStream(op, env.at) : socketStream(op, op.stream, env.at);
81
+ return { locals: new NameScope([...METHOD_LOCALS, ...stream.calls]), shape: stream.shape, stream };
77
82
  }
78
83
  const schema = op.success.schema;
79
84
  const result = schema && goTypeOf(schema, { ...env.at, fieldName: "Response", parentName: op.id }).replace(/^\*/, "");
80
- return { shape: shapeOf({ kind: op.success.kind, result }), stream: null };
85
+ return { locals: new NameScope(METHOD_LOCALS), shape: shapeOf({ kind: op.success.kind, result }), stream: null };
81
86
  }
82
87
  /** The statements before `c`: the path expanded from its params, or the template as it is. */
83
88
  function pathLines(op, locals, fail) {
@@ -129,19 +134,19 @@ function twinOf(op, returns, params) {
129
134
  /** The method of `op` named `name` on `receiver`, and its `<Op>Opts` and `<Op>Headers`. */
130
135
  export function goMethod(op, name, receiver, env) {
131
136
  const opts = env.at.names.claimConst(`${goExported(op.id)}Opts`);
132
- const locals = new NameScope(METHOD_LOCALS);
137
+ const { locals, shape, stream } = answering(op, env);
133
138
  const bodyLocal = op.body && locals.claim("body");
134
139
  const body = op.body && goBody(op, op.body, { at: env.at, local: bodyLocal });
135
140
  const pathLocals = pathParamsOf(op).map((param) => [param, locals.claim(goLocal(param.name))]);
136
- const { shape, stream } = answering(op, env);
137
141
  const streamOpts = stream?.opts ?? null;
138
142
  const fields = optsFields(op, opts, env.at, streamOpts);
139
143
  const path = pathLines(op, pathLocals, shape.fail);
140
144
  const headers = responseHeaders(op, env.at);
145
+ const bodyTypes = body ? [body.type] : [];
141
146
  const params = [
142
147
  "ctx context.Context",
143
148
  ...pathLocals.map(([, local]) => `${local} string`),
144
- ...(body ? [`${bodyLocal} ${body.type}`] : []),
149
+ ...bodyTypes.map((type) => `${bodyLocal} ${type}`),
145
150
  `opts *${opts}`,
146
151
  "reqOpts ...RequestOption",
147
152
  ];
@@ -160,13 +165,14 @@ export function goMethod(op, name, receiver, env) {
160
165
  decls.push([headers.plan.type, headers.decl]);
161
166
  const call = {
162
167
  ...callOf(op, name, pathLocals, fields),
163
- bodyType: body ? body.type : null,
168
+ bodyType: bodyTypes[0] ?? null,
164
169
  opts,
165
170
  parts: body?.parts ?? null,
166
171
  responseHeaders: headers?.plan ?? null,
167
172
  returns: shape.returns,
173
+ sends: stream?.sends ?? null,
168
174
  };
169
- const types = ["context.Context", ...pathLocals.map(() => "string"), ...(body ? [body.type] : []), `*${opts}`];
175
+ const types = ["context.Context", ...pathLocals.map(() => "string"), ...bodyTypes, `*${opts}`];
170
176
  const twin = twinOf(op, shape.returns, types);
171
177
  return { call, decls, lines, twin };
172
178
  }
@@ -1,3 +1,4 @@
1
+ import { lineComment } from "../shared/escape.js";
1
2
  /**
2
3
  * The Go SDK's safe mirror, `Client.Safe()` (bit 21 i3): a twin struct per resource struct, each method a field of its
3
4
  * name holding the normal method value under a generic wrapper that answers a `Result`. The field's type is a generic
@@ -6,8 +7,7 @@
6
7
  * wrapper (`call<n>`, `none<n>`, `stream<n>`), so a twin spells its types once and the one request path runs.
7
8
  */
8
9
  import { compareCodeUnits } from "../shared/lang.js";
9
- import { lineComment } from "../shared/escape.js";
10
- /* each kind's type and wrapper base names: none shares call's type, a connection needs no wrapper */
10
+ // each kind's type and wrapper base names: none shares call's type, a connection needs no wrapper
11
11
  const TWIN_NAMES = {
12
12
  call: ["Call", "call"],
13
13
  conn: ["Conn", null],
@@ -30,8 +30,6 @@ export type GoResponseHeaders = {
30
30
  readonly type: string;
31
31
  readonly fields: Readonly<Record<string, string>>;
32
32
  };
33
- /** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
34
- export declare const takesIdempotencyKey: (op: SdkOp) => boolean;
35
33
  /**
36
34
  * `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
37
35
  * `stream` carries has none.
@@ -2,12 +2,12 @@ import { goString, lineComment } from "../shared/escape.js";
2
2
  import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
3
3
  import { isNilable } from "./types-codec.js";
4
4
  import { goTypeOf } from "./types.js";
5
- /* the Opts field an idempotent operation's caller sets its Idempotency-Key through */
5
+ // the Opts field an idempotent operation's caller sets its Idempotency-Key through
6
6
  const IDEMPOTENCY_KEY = "IdempotencyKey";
7
7
  /** A value's Go type when it may be absent: as is where nil already means unset (H4), else a pointer. */
8
8
  const optional = (type, required) => (required || isNilable(type) ? type : `*${type}`);
9
9
  /** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
10
- export const takesIdempotencyKey = (op) => op.idempotent && op.stream === null;
10
+ const takesIdempotencyKey = (op) => op.idempotent && op.stream === null;
11
11
  /**
12
12
  * `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
13
13
  * `stream` carries has none.
@@ -65,7 +65,7 @@ function declaredHeaders(op) {
65
65
  .filter((status) => /^2(?:\d\d|XX)$/i.test(status))
66
66
  .sort(compareCodeUnits)
67
67
  .flatMap((status) => op.ir.responses[status].headers ?? []);
68
- /* reversed, so the first spelling of a name is the one its key ends on */
68
+ // reversed, so the first spelling of a name is the one its key ends on
69
69
  const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
70
70
  return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
71
71
  }
@@ -14,7 +14,7 @@ export type GeneratedGoSdk = {
14
14
  readonly packages: readonly PackageIdentity[];
15
15
  };
16
16
  export declare const WEBSOCKET = "github.com/coder/websocket v1.8.15";
17
- export declare const WEBSOCKET_SUM: string[];
17
+ export declare const WEBSOCKET_SUM: readonly string[];
18
18
  /** String and rune literals and line comments: text an import check must not read as code (the CLI's cmd files too). */
19
19
  export declare const NOT_CODE: RegExp;
20
20
  /** The Go SDK module for `document`, by file name, and its notices. */
@@ -9,22 +9,22 @@
9
9
  import { toIR } from "../../ir/build.js";
10
10
  import { sdkModel } from "../../ir/sdk-model.js";
11
11
  import { lineComment } from "../shared/escape.js";
12
- import { packageOn } from "../shared/metadata.js";
13
12
  import { compareCodeUnits } from "../shared/lang.js";
13
+ import { packageOn } from "../shared/metadata.js";
14
14
  import { goErrorKeys } from "./errors.js";
15
15
  import { needsWebSocket, runtimeFiles } from "./http.js";
16
16
  import { goModulePath } from "./module-path.js";
17
17
  import { clientDecls } from "./sdk-client.js";
18
18
  import { goTopLevel, goTypeContext } from "./types.js";
19
- /* the marker gopls and linters read, apart from the package doc by a blank line */
19
+ // the marker gopls and linters read, apart from the package doc by a blank line
20
20
  const MARKER = "// Code generated by clients. DO NOT EDIT.";
21
- /* the WebSocket library and its go.sum lines, as the Go checksum database has them; the CLI's module requires them too */
21
+ // the WebSocket library and its go.sum lines, as the Go checksum database has them; the CLI's module requires them too
22
22
  export const WEBSOCKET = "github.com/coder/websocket v1.8.15";
23
23
  export const WEBSOCKET_SUM = [
24
24
  `${WEBSOCKET} h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=`,
25
25
  `${WEBSOCKET}/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=`,
26
26
  ];
27
- /* what client.go may import, each only when its code uses it */
27
+ // what client.go may import, each only when its code uses it
28
28
  const CLIENT_IMPORTS = [
29
29
  ["context", "context"],
30
30
  ["json", "encoding/json"],
@@ -37,7 +37,7 @@ const CLIENT_IMPORTS = [
37
37
  export const NOT_CODE = /"(?:[^"\\\n]|\\.)*"|`[^`]*`|'(?:[^'\\\n]|\\.)*'|\/\/[^\n]*/g;
38
38
  /** A `.go` file of package `sdk` holding `decls`, importing each of `imports` (`[name, path]`) its code uses. */
39
39
  function goFile(decls, imports) {
40
- const code = decls.replace(NOT_CODE, "");
40
+ const code = decls.replaceAll(NOT_CODE, "");
41
41
  const used = imports.filter(([name]) => new RegExp(`\\b${name}\\.`).test(code)).map(([, path]) => `\t"${path}"`);
42
42
  const block = used.length === 0 ? "" : `import (\n${used.join("\n")}\n)\n\n`;
43
43
  return `${MARKER}\n\npackage sdk\n\n${block}${decls}\n`;
@@ -70,7 +70,7 @@ function emitGo(document, options) {
70
70
  const ir = toIR(document, { deriveOperationIds: true });
71
71
  const model = sdkModel(ir);
72
72
  const at = goTypeContext(ir);
73
- /* components first: the client's hoisted types then land beside them */
73
+ // components first: the client's hoisted types then land beside them
74
74
  const components = componentDecls(ir, at);
75
75
  const ops = model.opsById;
76
76
  const notices = [];
@@ -83,9 +83,6 @@ function emitGo(document, options) {
83
83
  };
84
84
  const modulePath = goModulePath(options.modulePath ?? "example.com/sdk", options.version);
85
85
  return {
86
- notices,
87
- packages: [packageOn("go", modulePath, options.version)],
88
- plans: client.plans,
89
86
  files: {
90
87
  ...runtimeFiles(features),
91
88
  ...moduleFiles(modulePath, needsWebSocket(features)),
@@ -95,6 +92,9 @@ function emitGo(document, options) {
95
92
  ["json", "encoding/json"],
96
93
  ]),
97
94
  },
95
+ notices,
96
+ packages: [packageOn("go", modulePath, options.version)],
97
+ plans: client.plans,
98
98
  };
99
99
  }
100
100
  /** The Go SDK module for `document`, by file name, and its notices. */
@@ -1,16 +1,8 @@
1
- /**
2
- * A server-sent-events operation as a Go method (G12): it returns `iter.Seq2[SSEEvent[T], error]`,
3
- * `T` the type of the declared event schema (`string` when the events are untyped), and opens the
4
- * stream when ranged. `<Op>Opts.LastEventID` resumes it as the Last-Event-ID header, which also
5
- * carries a declared Last-Event-ID header param (Fd3). An error status at the opening is the
6
- * stream's error value; its `Client.Safe()` twin opens the stream on the call and answers that
7
- * status as its Result's Err (bit 21 i3).
8
- */
9
- import type { SdkOp } from "../../ir/sdk-model.ts";
1
+ import { type SdkOp } from "../../ir/sdk-model.ts";
10
2
  import { type GoStream } from "./sdk-answer.ts";
11
3
  import type { OptsField } from "./sdk-opts.ts";
12
4
  import { type GoTypeContext } from "./types.ts";
13
5
  /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
14
6
  export declare const isLastEventIdHeader: (param: string, where: OptsField["in"]) => boolean;
15
- /** The method of the SSE operation `op`, its event type hoisted into `at` as `<Op>Event` when inline. */
7
+ /** The method of the SSE operation `op`, its event types hoisted into `at`. */
16
8
  export declare function sseStream(op: SdkOp, at: GoTypeContext): GoStream;