@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
package/bin/clients.js CHANGED
@@ -2,93 +2,114 @@
2
2
  // The clients bin (bit 17 phase h). A repository checkout (marked by tsconfig.json, which is not published)
3
3
  // runs the TypeScript source, natively on Bun (under the backend-source condition) and through jiti on Node, so a stale
4
4
  // dist/ never runs; an installed package runs the compiled JavaScript on any runtime (the tarball ships dist/, not src/).
5
- import { spawn } from "node:child_process"
6
- import { existsSync } from "node:fs"
7
- import { basename } from "node:path"
8
- import { fileURLToPath } from "node:url"
5
+ import { spawn } from "node:child_process";
6
+ import { existsSync } from "node:fs";
7
+ import { basename } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
9
 
10
- const isBun = typeof globalThis.Bun !== "undefined"
11
- const checkout = existsSync(new URL("../tsconfig.json", import.meta.url))
10
+ const isBun = typeof globalThis.Bun !== "undefined";
11
+ const checkout = existsSync(new URL("../tsconfig.json", import.meta.url));
12
12
 
13
13
  // `bun run` and `bunx` start this file through its node shebang, while what they run is meant for Bun: hand over to
14
14
  // the Bun that started us, which they name in npm_execpath. Once, never again in the child.
15
15
  function invokingBun() {
16
- if (isBun || process.env.CLIENTS_NO_BUN_HANDOFF === "1") return null
17
- if (!process.env.npm_config_user_agent?.startsWith("bun/")) return null
18
- const bun = process.env.npm_execpath
19
- if (!bun || !/^bunx?(\.exe)?$/.test(basename(bun)) || !existsSync(bun)) return null
20
- return bun
16
+ if (isBun || process.env.CLIENTS_NO_BUN_HANDOFF === "1") return null;
17
+
18
+ if (!process.env.npm_config_user_agent?.startsWith("bun/")) return null;
19
+ const bun = process.env.npm_execpath;
20
+
21
+ if (!bun || !/^bunx?(\.exe)?$/.test(basename(bun)) || !existsSync(bun)) return null;
22
+
23
+ return bun;
21
24
  }
22
25
 
23
26
  // The handoff: Bun runs this file with our arguments and `env` over ours; a signal we get is passed on to it, and we
24
27
  // end as it ended, its exit code or the same signal.
25
28
  function handOff(bun, env) {
26
- // Forwarders first: a signal landing as spawn returns would otherwise end this process by its default action,
27
- // orphaning the child. A handler runs from the event loop, after this block, so `child` is set by then.
28
- let child
29
- const forward = (signal) => child.kill(signal)
30
- for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, forward)
31
- child = spawn(bun, [fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
32
- env: { ...process.env, ...env, CLIENTS_NO_BUN_HANDOFF: "1" },
33
- stdio: "inherit",
34
- })
35
- child.on("error", (error) => {
36
- console.error(`clients: could not start ${bun}: ${error.message}`)
37
- process.exit(1)
38
- })
39
- child.on("exit", (code, signal) => {
40
- if (signal) {
41
- for (const each of ["SIGINT", "SIGTERM", "SIGHUP"]) process.off(each, forward)
42
- process.kill(process.pid, signal)
43
- return
44
- }
45
- process.exit(code ?? 1)
46
- })
29
+ // Forwarders first: a signal landing as spawn returns would otherwise end this process by its default action,
30
+ // orphaning the child. A handler runs from the event loop, after this block, so `child` is set by then.
31
+ let child;
32
+ const forward = (signal) => child.kill(signal);
33
+
34
+ for (const signal of ["SIGINT", "SIGTERM", "SIGHUP"]) process.on(signal, forward);
35
+ child = spawn(bun, [fileURLToPath(import.meta.url), ...process.argv.slice(2)], {
36
+ env: { ...process.env, ...env, CLIENTS_NO_BUN_HANDOFF: "1" },
37
+ stdio: "inherit",
38
+ });
39
+ child.on("error", (error) => {
40
+ console.error(`clients: could not start ${bun}: ${error.message}`);
41
+ process.exit(1);
42
+ });
43
+ child.on("exit", (code, signal) => {
44
+ if (signal) {
45
+ for (const each of ["SIGINT", "SIGTERM", "SIGHUP"]) process.off(each, forward);
46
+ process.kill(process.pid, signal);
47
+
48
+ return;
49
+ }
50
+
51
+ process.exit(code ?? 1);
52
+ });
47
53
  }
48
54
 
49
55
  // A checkout on Bun runs under the backend-source condition: an --app module's checkout core then resolves to its
50
56
  // source, never to an unbuilt or stale dist/ (bit 20). Set through BUN_OPTIONS when the caller did not, in the one
51
57
  // handoff, so a watch's generation children inherit it; Bun reports BUN_OPTIONS' flags in execArgv, so a Bun started
52
58
  // with it never hands off again.
53
- const SOURCE_CONDITION = "--conditions=backend-source"
54
- const unconditioned = isBun && checkout && !process.execArgv.includes(SOURCE_CONDITION)
59
+ const SOURCE_CONDITION = "--conditions=backend-source";
60
+ const unconditioned = isBun && checkout && !process.execArgv.includes(SOURCE_CONDITION);
61
+
55
62
  // The hand-off's backstop: its child carries CLIENTS_BUN_HANDOFF, the depth of hand-offs before it. A child that would
56
63
  // hand off again (the condition set but not in its execArgv) refuses instead of re-running itself without end.
57
- const handOffDepth = Number(process.env.CLIENTS_BUN_HANDOFF ?? 0)
64
+ const handOffDepth = Number(process.env.CLIENTS_BUN_HANDOFF ?? 0);
65
+
58
66
  const sourceEnv = checkout
59
- ? {
60
- BUN_OPTIONS: `${process.env.BUN_OPTIONS ?? ""} ${SOURCE_CONDITION}`.trim(),
61
- CLIENTS_BUN_HANDOFF: String(handOffDepth + 1),
62
- }
63
- : {}
67
+ ? {
68
+ BUN_OPTIONS: `${process.env.BUN_OPTIONS ?? ""} ${SOURCE_CONDITION}`.trim(),
69
+ CLIENTS_BUN_HANDOFF: String(handOffDepth + 1),
70
+ }
71
+ : {};
64
72
 
73
+ /**
74
+ * The module to run: the source, or the build compiled from it, typed as the source.
75
+ *
76
+ * @returns {Promise<typeof import("../src/cli.ts")>}
77
+ */
65
78
  async function entry() {
66
- if (checkout) {
67
- if (isBun) return import("../src/cli.ts")
68
- const { createJiti } = await import("jiti")
69
- return createJiti(import.meta.url).import("../src/cli.ts")
70
- }
71
- try {
72
- return await import("../dist/cli.js")
73
- } catch (error) {
74
- if (error?.code === "ERR_MODULE_NOT_FOUND" && String(error.url).endsWith("/dist/cli.js")) {
75
- console.error("clients: dist/ is missing from this install. Reinstall it, or run it with Bun.")
76
- process.exit(1)
77
- }
78
- throw error
79
- }
79
+ if (checkout) {
80
+ if (isBun) return import("../src/cli.ts");
81
+ const { createJiti } = await import("jiti");
82
+
83
+ return createJiti(import.meta.url).import("../src/cli.ts");
84
+ }
85
+
86
+ try {
87
+ // typed as the source it compiles from, so lint reads the same types with or without a build
88
+ return /** @type {typeof import("../src/cli.ts")} */ (await import("../dist/cli.js"));
89
+ } catch (error) {
90
+ if (error?.code === "ERR_MODULE_NOT_FOUND" && String(error.url).endsWith("/dist/cli.js")) {
91
+ console.error("clients: dist/ is missing from this install. Reinstall it, or run it with Bun.");
92
+ process.exit(1);
93
+ }
94
+
95
+ throw error;
96
+ }
80
97
  }
81
98
 
82
- const bun = invokingBun()
83
- if (bun) handOff(bun, sourceEnv)
84
- else if (unconditioned && handOffDepth >= 1) {
85
- console.error("clients: Bun hand-off loop: --conditions=backend-source not visible after re-exec")
86
- process.exit(1)
87
- } else if (unconditioned) handOff(process.execPath, sourceEnv)
88
- else {
89
- const { main } = await entry()
90
- const code = await main(process.argv.slice(2))
91
- /* an --app module may leave a timer or a socket open: the run is over once main returns, its output flushed */
92
- for (const stream of [process.stdout, process.stderr]) await new Promise((done) => stream.write("", done))
93
- process.exit(code)
99
+ const bun = invokingBun();
100
+
101
+ if (bun) {
102
+ handOff(bun, sourceEnv);
103
+ } else if (unconditioned && handOffDepth >= 1) {
104
+ console.error("clients: Bun hand-off loop: --conditions=backend-source not visible after re-exec");
105
+ process.exit(1);
106
+ } else if (unconditioned) {
107
+ handOff(process.execPath, sourceEnv);
108
+ } else {
109
+ const { main } = await entry();
110
+ const code = await main(process.argv.slice(2));
111
+
112
+ // an --app module may leave a timer or a socket open: the run is over once main returns, its output flushed
113
+ for (const stream of [process.stdout, process.stderr]) await new Promise((done) => stream.write("", done));
114
+ process.exit(code);
94
115
  }
package/bin/installgen.js CHANGED
@@ -2,18 +2,27 @@
2
2
  // The installgen bin. A repository checkout (marked by tsconfig.json, which is not published) runs the TypeScript
3
3
  // source, natively on Bun and through jiti on Node, so a stale build never runs; an installed package runs the
4
4
  // compiled JavaScript (the tarball ships it, not src/).
5
- import { existsSync } from "node:fs"
5
+ import { existsSync } from "node:fs";
6
6
 
7
- const checkout = existsSync(new URL("../tsconfig.json", import.meta.url))
7
+ const checkout = existsSync(new URL("../tsconfig.json", import.meta.url));
8
8
 
9
+ /**
10
+ * The module to run: the source, or the build compiled from it, typed as the source.
11
+ *
12
+ * @returns {Promise<typeof import("../src/installers/cli.ts")>}
13
+ */
9
14
  async function entry() {
10
- if (checkout) {
11
- if (typeof globalThis.Bun !== "undefined") return import("../src/installers/cli.ts")
12
- const { createJiti } = await import("jiti")
13
- return createJiti(import.meta.url).import("../src/installers/cli.ts")
14
- }
15
- return import("../dist/installers/cli.js")
15
+ if (checkout) {
16
+ if (typeof globalThis.Bun !== "undefined") return import("../src/installers/cli.ts");
17
+ const { createJiti } = await import("jiti");
18
+
19
+ return createJiti(import.meta.url).import("../src/installers/cli.ts");
20
+ }
21
+
22
+ // typed as the source it compiles from, so lint reads the same types with or without a build
23
+ return /** @type {Promise<typeof import("../src/installers/cli.ts")>} */ (import("../dist/installers/cli.js"));
16
24
  }
17
25
 
18
- const { start } = await entry()
19
- await start()
26
+ const { start } = await entry();
27
+
28
+ await start();
package/dist/cli.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type Metadata, type PackageIdentity } from "./emit/shared/metadata.ts";
2
- import { type Target, type TargetOptions } from "./gen/targets.ts";
3
2
  import { type ReadFile } from "./gen/shipped.ts";
3
+ import { type Target, type TargetOptions } from "./gen/targets.ts";
4
4
  /**
5
5
  * What one run generates: its targets, and each target's options by name (a target whose options are left out
6
6
  * takes its generator's defaults). The CLI parses `generate` into one of these; a consumer writes one by hand.
@@ -86,17 +86,17 @@ export declare function writeGenerated(run: GenerateRun & {
86
86
  /** What a run takes beside its arguments: the environment, the directory paths resolve from, a watch's stop signal. */
87
87
  export type RunOptions = {
88
88
  /** The directory the spec, the app module and `--out` resolve from. Defaults to the process's. */
89
- readonly cwd?: string;
89
+ readonly cwd?: string | undefined;
90
90
  /**
91
91
  * The environment formatters are looked up in, laid over the process's for each `--watch` child. Defaults to the
92
92
  * process's.
93
93
  */
94
- readonly env?: NodeJS.ProcessEnv;
94
+ readonly env?: NodeJS.ProcessEnv | undefined;
95
95
  /**
96
96
  * Stops a `--watch` run, which ends with 0 once the generation in progress finishes. Without it a watch never
97
97
  * returns.
98
98
  */
99
- readonly signal?: AbortSignal;
99
+ readonly signal?: AbortSignal | undefined;
100
100
  };
101
101
  /** Runs `clients <argv>`: the exit code it ends with (a watch ends only by `options.signal`). */
102
102
  export declare function main(argv: readonly string[], io?: Io, options?: RunOptions): Promise<number>;
package/dist/cli.js CHANGED
@@ -19,22 +19,22 @@ import { generateMcpServer } from "./emit/mcp/server.js";
19
19
  import { generatePythonSdk } from "./emit/python/sdk.js";
20
20
  import { generateRustSdk } from "./emit/rust/sdk.js";
21
21
  import { formatFiles } from "./emit/shared/format.js";
22
+ import { checkedMetadata, shippedOf } from "./emit/shared/metadata.js";
22
23
  import { generateSdkPackage } from "./emit/ts/package.js";
23
24
  import { parseGenerate, usage, UsageError } from "./gen/args.js";
24
25
  import { FORMATTERS, formatterFor, missingFormatter } from "./gen/formatters.js";
25
26
  import { runCli } from "./gen/process.js";
26
- import { appRef, loadAppDocument } from "./ir/load.js";
27
- import { checkedMetadata, shippedOf } from "./emit/shared/metadata.js";
28
- import { optionsFor } from "./gen/targets.js";
29
27
  import { shippedFiles } from "./gen/shipped.js";
28
+ import { optionsFor } from "./gen/targets.js";
30
29
  import { writeTarget } from "./gen/write.js";
30
+ import { appRef, loadAppDocument } from "./ir/load.js";
31
31
  import { release } from "./release/cli.js";
32
32
  /** One SDK target's generation: its files, its package's identity on each registry, and what it reports (a name it renamed). */
33
33
  function sdkOf(target, document, options, metadata) {
34
34
  switch (target) {
35
- case "ts":
36
- /* mapped key by key, never spread: `options` holds strings, and `tanstackQuery` is a boolean —
37
- a spread under a cast would make "false" as truthy as "true" */
35
+ case "ts": {
36
+ // mapped key by key, never spread: `options` holds strings, and `tanstackQuery` is a boolean —
37
+ // a spread under a cast would make "false" as truthy as "true"
38
38
  return generateSdkPackage(document, {
39
39
  name: options.name ?? "SDK",
40
40
  ...(options.packageName === undefined ? {} : { packageName: options.packageName }),
@@ -42,16 +42,22 @@ function sdkOf(target, document, options, metadata) {
42
42
  tanstackQuery: options.tanstackQuery === "true",
43
43
  ...(options.version === undefined ? {} : { version: options.version }),
44
44
  }, metadata);
45
- case "go":
45
+ }
46
+ case "go": {
46
47
  return generateGoSdk(document, options);
47
- case "rust":
48
+ }
49
+ case "rust": {
48
50
  return generateRustSdk(document, options, shippedOf(metadata));
49
- case "python":
51
+ }
52
+ case "python": {
50
53
  return generatePythonSdk(document, options, metadata);
51
- case "csharp":
54
+ }
55
+ case "csharp": {
52
56
  return generateCSharpSdk(document, options, shippedOf(metadata));
53
- case "java":
57
+ }
58
+ case "java": {
54
59
  return generateJavaSdk(document, options);
60
+ }
55
61
  }
56
62
  }
57
63
  /**
@@ -168,7 +174,7 @@ function watchSpec(run, argv, io, options) {
168
174
  /** Runs `clients <argv>`: the exit code it ends with (a watch ends only by `options.signal`). */
169
175
  export async function main(argv, io = PROCESS_IO, options = {}) {
170
176
  try {
171
- /* release has subcommands of its own, each with its own --help */
177
+ // release has subcommands of its own, each with its own --help
172
178
  if (argv[0] === "release")
173
179
  return await release(argv.slice(1), io, { env: options.env });
174
180
  if (argv.length === 0 || argv[0] === "-h" || argv[0] === "--help" || argv.includes("--help")) {
@@ -1,6 +1,6 @@
1
1
  /** The Linux package formats nfpm builds. */
2
- export declare const PACKAGE_FORMATS: readonly ["deb", "rpm", "apk"];
3
- export type PackageFormat = (typeof PACKAGE_FORMATS)[number];
2
+ declare const PACKAGE_FORMATS: readonly ["deb", "rpm", "apk"];
3
+ type PackageFormat = (typeof PACKAGE_FORMATS)[number];
4
4
  /** What a package manager shows about the CLI. */
5
5
  type About = {
6
6
  readonly description: string;
@@ -8,7 +8,7 @@
8
8
  import { checked, HTTPS_URL, PERSON, refuse, SPDX_EXPRESSION } from "../shared/metadata.js";
9
9
  import { q } from "./release.js";
10
10
  /** The Linux package formats nfpm builds. */
11
- export const PACKAGE_FORMATS = ["deb", "rpm", "apk"];
11
+ const PACKAGE_FORMATS = ["deb", "rpm", "apk"];
12
12
  /** The secret each channel's push reads, by the environment variable goreleaser's config names. */
13
13
  export const SECRETS = {
14
14
  aur: "AUR_SSH_KEY",
@@ -17,13 +17,13 @@ export const SECRETS = {
17
17
  scoop: "SCOOP_BUCKET_TOKEN",
18
18
  winget: "WINGET_TOKEN",
19
19
  };
20
- /* a description: one line of printable text, at most 256 characters (winget's ShortDescription); a winget
21
- * publisher: a name of letters, digits, spaces and `.,&'-`, at most 64 characters; a homepage, an install URL, a
22
- * license and a maintainer take the grammars every target's package metadata shares (../shared/metadata.ts) */
20
+ // a description: one line of printable text, at most 256 characters (winget's ShortDescription); a winget
21
+ // publisher: a name of letters, digits, spaces and `.,&'-`, at most 64 characters; a homepage, an install URL, a
22
+ // license and a maintainer take the grammars every target's package metadata shares (../shared/metadata.ts)
23
23
  const DESCRIPTION = /^\P{Cc}{1,256}$/u;
24
24
  const PUBLISHER = /^[A-Za-z0-9][A-Za-z0-9 .,&'-]{0,63}$/;
25
- /* a GitHub repository: its owner 1 to 39 letters, digits and single inner hyphens; its name 1 to 100 of letters,
26
- * digits, `.`, `_` and `-`, not `.` or `..` and not ending in `.git` */
25
+ // a GitHub repository: its owner 1 to 39 letters, digits and single inner hyphens; its name 1 to 100 of letters,
26
+ // digits, `.`, `_` and `-`, not `.` or `..` and not ending in `.git`
27
27
  export const REPO = /^[A-Za-z0-9](?:-?[A-Za-z0-9]){0,38}\/(?!\.\.?$)(?![\s\S]*\.git$)[A-Za-z0-9._-]{1,100}$/;
28
28
  /** `owner/name` split, once REPO has checked it. */
29
29
  const split = (repo) => {
@@ -93,7 +93,7 @@ export function resolvedRelease(options, repo) {
93
93
  channels.push({ about: about("homebrew-tap"), kind: "homebrew", ...tap });
94
94
  if (bucket !== undefined)
95
95
  channels.push({ about: about("scoop-bucket"), kind: "scoop", ...bucket });
96
- /* winget needs both: the fork it pushes the manifests to, and the publisher they are filed under */
96
+ // winget needs both: the fork it pushes the manifests to, and the publisher they are filed under
97
97
  if (fork === undefined && publisher !== undefined)
98
98
  needed("winget-fork", undefined, "winget-publisher");
99
99
  if (fork !== undefined) {
@@ -138,7 +138,7 @@ const aboutLines = ({ description, homepage, license }, descriptionKey = "descri
138
138
  /** The goreleaser block for one channel of `bin`. */
139
139
  export function channelBlock(bin, channel) {
140
140
  switch (channel.kind) {
141
- case "homebrew":
141
+ case "homebrew": {
142
142
  return `# the Homebrew cask, pushed to the tap; the binaries are not notarized, so it clears macOS's quarantine flag
143
143
  homebrew_casks:
144
144
  - name: ${q(bin)}
@@ -150,19 +150,21 @@ ${pushTo(channel.owner, channel.name, SECRETS.homebrew, " ")}${aboutLines(cha
150
150
  system_command "/usr/bin/xattr", args: ["-dr", "com.apple.quarantine", "#{staged_path}/${bin}"]
151
151
  end
152
152
  `;
153
- case "scoop":
153
+ }
154
+ case "scoop": {
154
155
  return `# the Scoop manifest, pushed to the bucket
155
156
  scoops:
156
157
  - name: ${q(bin)}
157
158
  skip_upload: auto
158
159
  ${pushTo(channel.owner, channel.name, SECRETS.scoop, " ")}${aboutLines(channel.about)}`;
159
- case "winget":
160
+ }
161
+ case "winget": {
160
162
  return `# the winget manifests, pushed to the fork and proposed to microsoft/winget-pkgs
161
163
  winget:
162
164
  - name: ${q(bin)}
163
165
  skip_upload: auto
164
166
  publisher: ${q(channel.publisher)}
165
- package_identifier: ${q(`${channel.publisher.replace(/[^A-Za-z0-9]/g, "")}.${bin}`)}
167
+ package_identifier: ${q(`${channel.publisher.replaceAll(/[^A-Za-z0-9]/g, "")}.${bin}`)}
166
168
  ${aboutLines(channel.about, "short_description")} repository:
167
169
  owner: ${q(channel.owner)}
168
170
  name: ${q(channel.name)}
@@ -175,7 +177,8 @@ ${aboutLines(channel.about, "short_description")} repository:
175
177
  name: winget-pkgs
176
178
  branch: master
177
179
  `;
178
- case "aur":
180
+ }
181
+ case "aur": {
179
182
  return `# the AUR ${bin}-bin package, pushed over SSH
180
183
  aurs:
181
184
  - name: ${q(`${bin}-bin`)}
@@ -184,7 +187,8 @@ ${aboutLines(channel.about)} maintainers: [${q(channel.about.maintainer)}]
184
187
  private_key: "{{ .Env.${SECRETS.aur} }}"
185
188
  git_url: ${q(`ssh://aur@aur.archlinux.org/${bin}-bin.git`)}
186
189
  `;
187
- case "packages":
190
+ }
191
+ case "packages": {
188
192
  return `# Linux packages beside the archives, each named ${bin}_<os>_<arch>
189
193
  nfpms:
190
194
  - id: ${q(bin)}
@@ -193,5 +197,6 @@ nfpms:
193
197
  formats: [${channel.formats.join(", ")}]
194
198
  ${aboutLines(channel.about)} maintainer: ${q(channel.about.maintainer)}
195
199
  `;
200
+ }
196
201
  }
197
202
  }
@@ -10,7 +10,7 @@ import type { IR } from "../../ir/model.ts";
10
10
  import type { SdkOp } from "../../ir/sdk-model.ts";
11
11
  import type { GoCallPlan } from "../go/sdk-client.ts";
12
12
  /** The root's own commands, each taken before an operation's. */
13
- export declare const BUILT_INS: string[];
13
+ export declare const BUILT_INS: readonly string[];
14
14
  /** A command node: a group of others, or one operation's command. */
15
15
  export type CommandNode = {
16
16
  readonly name: string;
@@ -41,7 +41,7 @@ export function commandTree(ops, plans) {
41
41
  return named(rawTree(ops, plans), [], new NameScope(BUILT_INS), new NameScope(["Root", "newClient", "failed"]));
42
42
  }
43
43
  /** A named type of the SDK's, as package cmd spells it: `sdk.` before each exported name. */
44
- const qualified = (type) => type.replace(/(?<![\w.])([A-Z]\w*)/g, "sdk.$1");
44
+ const qualified = (type) => type.replaceAll(/(?<![\w.])([A-Z]\w*)/g, "sdk.$1");
45
45
  /** A multipart body's statements: each file part from its opened files, each text part from its flag. */
46
46
  function multipartLines(type, parts) {
47
47
  const lines = [`\tvar body ${type}`];
@@ -67,43 +67,68 @@ function bodyLines(op, plan, flags) {
67
67
  const fail = ["\tif err != nil {", "\t\treturn err", "\t}"];
68
68
  switch (body.kind) {
69
69
  case "json": {
70
- /* a pointer type decodes as well: json.Unmarshal allocates it, and an absent optional body stays nil */
70
+ // a pointer type decodes as well: json.Unmarshal allocates it, and an absent optional body stays nil
71
71
  const read = `\tif err := p.JSON(&body, ${required}, ${map}); err != nil {`;
72
72
  return [[`\tvar body ${qualified(plan.bodyType)}`, read, "\t\treturn err", "\t}"], ", body"];
73
73
  }
74
- case "form":
74
+ case "form": {
75
75
  return [[`\tbody, err := p.Form(${required}, ${map})`, ...fail], ", body"];
76
- case "text":
76
+ }
77
+ case "text": {
77
78
  return [[`\tbody, err := p.Text(${required})`, ...fail], ", body"];
78
- case "multipart":
79
+ }
80
+ case "multipart": {
79
81
  return [multipartLines(qualified(plan.bodyType), flags.parts), ", body"];
80
- default:
82
+ }
83
+ default: {
81
84
  return [[`\tbody, err := p.Reader(${required})`, ...fail], ", body"];
85
+ }
82
86
  }
83
87
  }
84
- /** A stream's call: its stream opened first (its output flags checked), then each event printed as it comes. */
85
- function streamLines(call, stream) {
88
+ /** The check of one message type: an input line decoded as it, holding each field it requires. */
89
+ const lineCheck = ({ required, type }) => `cli.JSONLine[${qualified(type)}](${required.map(goString).join(", ")})`;
90
+ /** The check a WebSocket command runs on each input line: by what the server receives; nil when it is untyped. */
91
+ function linesChecked(sends) {
92
+ if (sends === null)
93
+ return "nil";
94
+ if (sends.key === null)
95
+ return lineCheck(sends);
96
+ const members = [...sends.members]
97
+ .sort((a, b) => compareCodeUnits(a.value, b.value))
98
+ .map((member) => `${goString(member.value)}: ${lineCheck(member)}`);
99
+ return `cli.Keyed(${goString(sends.key)}, map[string]cli.LineCheck{${members.join(", ")}})`;
100
+ }
101
+ /**
102
+ * A stream's call: its stream opened first (its output flags checked), then each event printed as it comes. A
103
+ * WebSocket's input lines are checked against what the server receives, and a message that does not decode, the
104
+ * SDK's `*DecodeError`, ends the conversation.
105
+ */
106
+ function streamLines(call, stream, sends) {
86
107
  const open = ["\tout, err := cli.OpenStream(c)", "\tif err != nil {", "\t\treturn err", "\t}", "\tdefer out.Close()"];
87
- if (stream === "sse")
108
+ if (stream === "sse") {
88
109
  return [
89
110
  ...open,
90
111
  `\tfor event, err := range ${call} {`,
91
112
  "\t\tif err != nil {",
92
113
  "\t\t\treturn failed(err)",
93
114
  "\t\t}",
94
- "\t\tif !out.Event(event.Event, event.ID, event.Data) {",
115
+ "\t\tev := event.Untyped()",
116
+ "\t\tif !out.Event(ev.Event, ev.ID, ev.Data) {",
95
117
  "\t\t\tbreak",
96
118
  "\t\t}",
97
119
  "\t}",
98
120
  "\treturn out.Err()",
99
121
  ];
122
+ }
100
123
  return [
101
124
  ...open,
102
125
  `\tconn, err := ${call}`,
103
126
  "\tif err != nil {",
104
127
  "\t\treturn failed(err)",
105
128
  "\t}",
106
- stream === "realtime" ? "\treturn failed(out.Resume(conn))" : "\treturn out.Converse(conn)",
129
+ stream === "realtime"
130
+ ? "\treturn failed(cli.Resume(out, conn, conn.Events()))"
131
+ : `\treturn cli.Converse(out, conn, conn.Read, ${linesChecked(sends)}, cli.Undecoded[*sdk.DecodeError])`,
107
132
  ];
108
133
  }
109
134
  /** The call and what follows it, by what the method returns: the answer printed with the response it came on. */
@@ -112,7 +137,7 @@ function callLines(call, plan) {
112
137
  .map(goString)
113
138
  .join(", ");
114
139
  const answer = (data) => `\treturn cli.Print(c, cli.Answer{${data}Response: resp, Declared: []string{${declared}}})`;
115
- if (plan.returns === "error")
140
+ if (plan.returns === "error") {
116
141
  return [
117
142
  "\tvar resp *http.Response",
118
143
  `\tif err := ${call}; err != nil {`,
@@ -120,6 +145,7 @@ function callLines(call, plan) {
120
145
  "\t}",
121
146
  answer(""),
122
147
  ];
148
+ }
123
149
  return [
124
150
  "\tvar resp *http.Response",
125
151
  `\tanswer, err := ${call}`,
@@ -154,7 +180,7 @@ function opFunc(node, path, ir) {
154
180
  "\t}",
155
181
  ...(plan.stream === null
156
182
  ? callLines(`${method}(c.Context()${args}${bodyArg}, opts, sdk.WithResponseInto(&resp))`, plan)
157
- : streamLines(`${method}(c.Context()${args}${bodyArg}, opts)`, plan.stream)),
183
+ : streamLines(`${method}(c.Context()${args}${bodyArg}, opts)`, plan.stream, plan.sends)),
158
184
  ];
159
185
  return [
160
186
  ...lineComment(`${node.fn} is \`${[...path, node.name].join(" ")}\`: ${op.method} ${op.path}.`, "//"),
@@ -10,12 +10,6 @@
10
10
  import type { IRSchema } from "../../ir/model.ts";
11
11
  import { type SdkModel } from "../../ir/sdk-model.ts";
12
12
  import type { CommandNode } from "./commands.ts";
13
- /** How deep a schema sketch shows objects: deeper ones are `{…}`. */
14
- export declare const SKETCH_DEPTH = 3;
15
- /** The longest summary an index line carries, in characters, `…` included. */
16
- export declare const SUMMARY_MAX = 80;
17
- /** The most values an index line spells out for an enum: more show as `<enum:N>` (the schema lists them all). */
18
- export declare const ENUM_MAX = 6;
19
13
  /** One API command as discovery shows it. */
20
14
  export type Entry = {
21
15
  readonly path: string;
@@ -3,13 +3,13 @@ import { goString } from "../shared/escape.js";
3
3
  import { compareCodeUnits } from "../shared/lang.js";
4
4
  import { commandFlags, helpText } from "./flags.js";
5
5
  /** How deep a schema sketch shows objects: deeper ones are `{…}`. */
6
- export const SKETCH_DEPTH = 3;
6
+ const SKETCH_DEPTH = 3;
7
7
  /** The longest summary an index line carries, in characters, `…` included. */
8
- export const SUMMARY_MAX = 80;
8
+ const SUMMARY_MAX = 80;
9
9
  /** The most values an index line spells out for an enum: more show as `<enum:N>` (the schema lists them all). */
10
- export const ENUM_MAX = 6;
10
+ const ENUM_MAX = 6;
11
11
  /** Spec text on one line: helpText's, its whitespace runs one space. */
12
- const oneLine = (text) => helpText(text).replace(/\s+/g, " ").trim();
12
+ const oneLine = (text) => helpText(text).replaceAll(/\s+/g, " ").trim();
13
13
  /** A summary as the index carries it: its first sentence, at most SUMMARY_MAX characters with `…`. */
14
14
  export function summaryOf(text) {
15
15
  const line = oneLine(text);
@@ -18,7 +18,7 @@ export function summaryOf(text) {
18
18
  return chars.length <= SUMMARY_MAX ? sentence : `${chars.slice(0, SUMMARY_MAX - 1).join("")}…`;
19
19
  }
20
20
  /** JSON text with DEL, C1, the BOM and the line separators escaped too (JSON.stringify leaves them raw): exact, and safe. */
21
- const json = (value) => JSON.stringify(value).replace(/[\u007f-\u009f\u2028\u2029\ufeff]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`);
21
+ const json = (value) => JSON.stringify(value).replaceAll(/[\u007f-\u009f\u2028\u2029\ufeff]/g, (ch) => `\\u${ch.charCodeAt(0).toString(16).padStart(4, "0")}`);
22
22
  /** A value as a usage line shows it: bare when it is a plain word, else quoted. */
23
23
  const word = (value) => (/^[\w.:/@+-]+$/.test(value) ? value : json(value));
24
24
  /** A flag's value as the usage line shows it: its enum, `<enum:N>` past `enumMax`, else its kind; repeatable `...`. */
@@ -64,7 +64,9 @@ function objectSketch(schema, at) {
64
64
  /** A ref's sketch: its schema inlined, or its name when it is already open (recursive) or unknown. */
65
65
  function refSketch(name, at) {
66
66
  const target = at.model.ir.schemas[name];
67
- return target === undefined || at.open.includes(name) ? key(name) : shown(target, { ...at, open: [...at.open, name] });
67
+ return target === undefined || at.open.includes(name)
68
+ ? key(name)
69
+ : shown(target, { ...at, open: [...at.open, name] });
68
70
  }
69
71
  /** The sketch of a schema of each kind. */
70
72
  const SKETCHES = {
@@ -92,7 +94,7 @@ export const sketch = (schema, model) => shown(schema, { depth: 0, model, open:
92
94
  /** Each declared error status, with the keys its backend error envelope names: `[status, keys]`. */
93
95
  function errorsOf(op, model) {
94
96
  return op.errorStatuses.map((status) => {
95
- /* an error status is one of the operation's declared responses */
97
+ // an error status is one of the operation's declared responses
96
98
  const { schema } = op.ir.responses[String(status)];
97
99
  return [status, schema === undefined ? [] : (irErrorEnvelope(schema, model.resolve)?.keys ?? [])];
98
100
  });
@@ -9,8 +9,6 @@
9
9
  import type { IRSchema } from "../../ir/model.ts";
10
10
  import type { SdkOp } from "../../ir/sdk-model.ts";
11
11
  import type { GoCallPlan } from "../go/sdk-client.ts";
12
- /** The flags every command has, and those later phases give it: a parameter never takes one of these names. */
13
- export declare const GLOBAL_FLAGS: string[];
14
12
  /** A flag's kind as the runtime checks it, whether it repeats, and its allowed values. */
15
13
  export type Kind = {
16
14
  readonly kind: string;
@@ -45,7 +43,7 @@ export type Usage = {
45
43
  readonly kind: Kind;
46
44
  readonly required: boolean;
47
45
  /** the parameter's own name, for a path, query or header parameter */
48
- readonly param?: string;
46
+ readonly param?: string | undefined;
49
47
  };
50
48
  /** One multipart part's flag, `--<part>`: a value of `kind` for a text part, a path for a file part. */
51
49
  export type PartFlag = {