@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,7 +1,7 @@
1
1
  import { goString, invisible } from "../shared/escape.js";
2
2
  import { NameScope, words } from "../shared/lang.js";
3
3
  /** The flags every command has, and those later phases give it: a parameter never takes one of these names. */
4
- export const GLOBAL_FLAGS = [
4
+ const GLOBAL_FLAGS = [
5
5
  "api-key",
6
6
  "base-url",
7
7
  "config",
@@ -29,7 +29,7 @@ const JSON_KIND = { enum: [], kind: "json", list: false };
29
29
  * the BOM, the line and paragraph separators, the bidi controls) dropped, so no spec can move the cursor, recolor a
30
30
  * user's terminal or reorder what it shows.
31
31
  */
32
- export const helpText = (text) => [...text.replace(/\r\n?/g, "\n")].filter((ch) => !hidden(ch.codePointAt(0))).join("");
32
+ export const helpText = (text) => [...text.replaceAll(/\r\n?/g, "\n")].filter((ch) => !hidden(ch.codePointAt(0))).join("");
33
33
  /** Whether a code point is one help drops: a C0 control but tab and line feed, DEL, C1, the BOM, U+2028, U+2029, bidi. */
34
34
  const hidden = (cp) => (cp < 0x20 && cp !== 0x09 && cp !== 0x0a) ||
35
35
  cp === 0x7f ||
@@ -98,7 +98,7 @@ export function commandFlags(op, plan, schemas) {
98
98
  lines.push(`\tp.Path(${names.map(goString).join(", ")})`);
99
99
  usage.push(...names.map((name, i) => ({ kind: STRING, name, param: plan.pathParams[i], positional: true, required: true })));
100
100
  }
101
- /* each param the SDK gives an Opts field, by the plan: a stream's channel param (Last-Event-ID) has none */
101
+ // each param the SDK gives an Opts field, by the plan: a stream's channel param (Last-Event-ID) has none
102
102
  const params = (specs, fields) => {
103
103
  for (const [param, field] of Object.entries(fields)) {
104
104
  const spec = specs.find((each) => each.name === param);
@@ -122,24 +122,34 @@ export function commandFlags(op, plan, schemas) {
122
122
  return { declare: lines, fields: [], opts, parts, usage };
123
123
  }
124
124
  const fields = bodyFields(op, schemas, scope, lines);
125
- if (op.body !== undefined)
126
- usage.push({ kind: { ...STRING, kind: op.body.kind }, name: "data", positional: false, required: op.body.required });
125
+ if (op.body !== undefined) {
126
+ usage.push({
127
+ kind: { ...STRING, kind: op.body.kind },
128
+ name: "data",
129
+ positional: false,
130
+ required: op.body.required,
131
+ });
132
+ }
127
133
  return { declare: lines, fields, opts, parts: [], usage };
128
134
  }
129
135
  /** A stream's cursor flags, each `[flag, its Opts field, usage]`: the names GLOBAL_FLAGS keeps from a parameter. */
130
136
  const LAST_EVENT_ID = ["last-event-id", "LastEventID", "resume after this event id"];
131
137
  const RECONNECT_TOKEN = ["reconnect-token", "ReconnectToken", "resume with this reconnect token"];
132
138
  const CURSOR = { realtime: [LAST_EVENT_ID, RECONNECT_TOKEN], sse: [LAST_EVENT_ID], ws: [RECONNECT_TOKEN] };
133
- /** A stream command's own flags: --take, a realtime one's --max-reconnects, and its cursor flags, each set into its Opts field. */
139
+ /**
140
+ * A stream command's own flags: --take, a realtime one's --max-reconnects, and its cursor flags, each set into its
141
+ * Opts field (a realtime one's into its one `Transport`).
142
+ */
134
143
  function streamFlags(stream, lines, opts) {
144
+ const into = stream === "realtime" ? "opts.Transport" : "opts";
135
145
  lines.push("\tp.Take()");
136
146
  if (stream === "realtime") {
137
147
  lines.push("\tp.MaxReconnects()");
138
- opts.push("\treconnects, err := p.Reconnects()", "\tif err != nil {", "\t\treturn err", "\t}", "\topts.MaxReconnectAttempts = reconnects");
148
+ opts.push("\treconnects, err := p.Reconnects()", "\tif err != nil {", "\t\treturn err", "\t}", `\t${into}.MaxReconnectAttempts = reconnects`);
139
149
  }
140
150
  for (const [flag, field, usage] of CURSOR[stream]) {
141
151
  lines.push(flagLine(flag, { enum: [], kind: "string", list: false }, false, usage));
142
- opts.push(`\tif err := cli.Set(&opts.${field}, p.Values(${goString(flag)})); err != nil {`, "\t\treturn err", "\t}");
152
+ opts.push(`\tif err := cli.Set(&${into}.${field}, p.Values(${goString(flag)})); err != nil {`, "\t\treturn err", "\t}");
143
153
  }
144
154
  }
145
155
  /** A multipart body's flags, each declared into `lines` by its part's name: a text part typed by its schema, a file part a path. */
@@ -19,8 +19,6 @@ export type InstallApp = {
19
19
  readonly prefix: string;
20
20
  readonly installUrl: string;
21
21
  };
22
- /** The issuer of the OIDC token a GitHub Actions run signs with. */
23
- export declare const ISSUER = "https://token.actions.githubusercontent.com";
24
22
  /**
25
23
  * The `npx` that runs installgen from the clients release that wrote the scripts: the release workflow's `check` runs
26
24
  * it on installgen.config.mts in the module's root, so the scripts and their check always come from one release.
@@ -30,11 +28,5 @@ export declare function installgenCommand(): string;
30
28
  export declare const INSTALLGEN_CONFIG = "installgen.config.mts";
31
29
  /** installgen's config for `app`, its files under `base` (the repository's GitHub Releases outside a test). */
32
30
  export declare function installerConfig(app: InstallApp, base?: string): InstallgenConfig;
33
- /**
34
- * `installgen.config.mts` for `app`: `installerConfig`'s config as a module installgen loads with no local install
35
- * (its one import is type-only, which Node 22.18+ strips), so `installgenCommand()`'s `check` runs in the module's root
36
- * with nothing installed.
37
- */
38
- export declare function installgenConfigFile(app: InstallApp): string;
39
31
  /** `install.sh`, `install.ps1` and `installgen.config.mts` for `app`, by file name. */
40
32
  export declare function installFiles(app: InstallApp): Record<string, string>;
@@ -14,7 +14,7 @@
14
14
  import { generateInstallers } from "../../installers/index.js";
15
15
  import { clientsVersion } from "../../version.js";
16
16
  /** The issuer of the OIDC token a GitHub Actions run signs with. */
17
- export const ISSUER = "https://token.actions.githubusercontent.com";
17
+ const ISSUER = "https://token.actions.githubusercontent.com";
18
18
  /**
19
19
  * The `npx` that runs installgen from the clients release that wrote the scripts: the release workflow's `check` runs
20
20
  * it on installgen.config.mts in the module's root, so the scripts and their check always come from one release.
@@ -60,7 +60,7 @@ export function installerConfig(app, base = `https://github.com/${app.repo}/rele
60
60
  * (its one import is type-only, which Node 22.18+ strips), so `installgenCommand()`'s `check` runs in the module's root
61
61
  * with nothing installed.
62
62
  */
63
- export function installgenConfigFile(app) {
63
+ function installgenConfigFile(app) {
64
64
  const installgen = installgenCommand();
65
65
  const { asset, checksums, identity, plain } = layout(app, `https://github.com/${app.repo}/releases`);
66
66
  const value = (key) => `\t${key}: ${JSON.stringify(plain[key])},\n`;
@@ -83,7 +83,7 @@ ${value("envPrefix")}${value("installDir")}${value("latestPath")}${value("messag
83
83
  /** `install.sh`, `install.ps1` and `installgen.config.mts` for `app`, by file name. */
84
84
  export function installFiles(app) {
85
85
  const { ps1, sh } = generateInstallers(installerConfig(app));
86
- /* every platform is configured, so installgen writes both */
86
+ // every platform is configured, so installgen writes both
87
87
  const scripts = [
88
88
  ["install.ps1", ps1],
89
89
  ["install.sh", sh],
@@ -10,7 +10,7 @@ import { type Entry } from "./discovery.ts";
10
10
  /** The CLI's name, description and environment prefix, and its module. */
11
11
  export type CliApp = {
12
12
  /** the base URL the root command is built with; none when the document declares no server */
13
- readonly baseUrl?: string;
13
+ readonly baseUrl?: string | undefined;
14
14
  readonly binaryName: string;
15
15
  readonly short: string;
16
16
  readonly envPrefix: string;
@@ -4,12 +4,15 @@ import { compareCodeUnits, NameScope, snakeWords } from "../shared/lang.js";
4
4
  import { groupFuncs } from "./commands.js";
5
5
  import { discoveryBody } from "./discovery.js";
6
6
  import { helpText } from "./flags.js";
7
- /* the marker gopls and linters read, apart from the package doc by a blank line */
7
+ // the marker gopls and linters read, apart from the package doc by a blank line
8
8
  const MARKER = "// Code generated by clients. DO NOT EDIT.";
9
9
  /** What a cmd file imports, by the packages its code names: the runtime always. */
10
10
  const importsOf = (text) => {
11
11
  const code = text.replace(NOT_CODE, "");
12
- return ["cli", ...["cobra", "errors", "http", "json", "sdk"].filter((name) => new RegExp(`\\b${name}\\.`).test(code))];
12
+ return [
13
+ "cli",
14
+ ...["cobra", "errors", "http", "json", "sdk"].filter((name) => new RegExp(`\\b${name}\\.`).test(code)),
15
+ ];
13
16
  };
14
17
  /** Each package a cmd file may import, by name, in its import group: the standard library, cobra, the module's own. */
15
18
  const PACKAGES = {
@@ -34,7 +37,7 @@ function cmdFile(module, body, doc = "") {
34
37
  return `${MARKER}\n\n${doc}package cmd\n\nimport (\n${block}\n)\n\n${body}\n`;
35
38
  }
36
39
  /** cmd/root.go: the root command, named by the binary, its skill given, its top-level commands its API ones. */
37
- function rootBody(app, ir, nodes) {
40
+ function rootBody(app, nodes) {
38
41
  const fields = [
39
42
  `Name: ${goString(app.binaryName)}`,
40
43
  `Short: ${goString(helpText(app.short))}`,
@@ -55,15 +58,15 @@ function rootBody(app, ir, nodes) {
55
58
  * cmd/client.go: the SDK client the run's settings configure, its requests and responses logged under --verbose, and
56
59
  * an answer outside 2xx as the runtime's APIError. An API that declares no server needs a base URL set.
57
60
  */
58
- function clientBody(app, ir) {
61
+ function clientBody(app) {
59
62
  const env = `$${app.envPrefix}_BASE_URL`;
60
- const noServer = app.baseUrl !== undefined
61
- ? []
62
- : [
63
+ const noServer = app.baseUrl === undefined
64
+ ? [
63
65
  '\tif s.BaseURL == "" {',
64
66
  `\t\treturn nil, cli.Usage(${goString(`no base URL: set --base-url, ${env} or base_url in the config file`)})`,
65
67
  "\t}",
66
- ];
68
+ ]
69
+ : [];
67
70
  return [
68
71
  "// newClient is the API client the run's settings configure.",
69
72
  "func newClient(c *cobra.Command) (*sdk.Client, error) {",
@@ -104,9 +107,9 @@ function clientBody(app, ir) {
104
107
  export function cmdFiles(app, ir, nodes, entries) {
105
108
  const stems = new NameScope(["client", "root"]);
106
109
  const files = {
107
- "cmd/client.go": cmdFile(app.modulePath, clientBody(app, ir)),
110
+ "cmd/client.go": cmdFile(app.modulePath, clientBody(app)),
108
111
  "cmd/discovery.go": cmdFile(app.modulePath, discoveryBody(entries)),
109
- "cmd/root.go": cmdFile(app.modulePath, rootBody(app, ir, nodes), `// Package cmd holds the ${app.binaryName} commands.\n`),
112
+ "cmd/root.go": cmdFile(app.modulePath, rootBody(app, nodes), `// Package cmd holds the ${app.binaryName} commands.\n`),
110
113
  };
111
114
  for (const node of nodes) {
112
115
  const body = groupFuncs(node, [], ir)
@@ -2,20 +2,20 @@ import { type PackageIdentity } from "../shared/metadata.ts";
2
2
  import { type ReleaseOptions } from "./release.ts";
3
3
  export type GoCliOptions = ReleaseOptions & {
4
4
  /** the binary and root command name: lowercase words joined by `-`, at most 64 characters; the title's, else `api` */
5
- readonly binaryName?: string;
5
+ readonly binaryName?: string | undefined;
6
6
  /** the module path go.mod declares, a domain first; `example.com/<binaryName>` by default */
7
- readonly modulePath?: string;
7
+ readonly modulePath?: string | undefined;
8
8
  /** the module's version, semver: from v2 on, its major suffix (`/v2`) ends the module path */
9
- readonly version?: string;
9
+ readonly version?: string | undefined;
10
10
  /** the environment variables' prefix: uppercase words joined by `_`; the binary name's by default */
11
- readonly envPrefix?: string;
11
+ readonly envPrefix?: string | undefined;
12
12
  /** the GitHub repository the release is published to, `owner/name`; none by default (then no install scripts) */
13
- readonly repo?: string;
13
+ readonly repo?: string | undefined;
14
14
  /**
15
15
  * the base URL the binary calls by default, absolute; the document's first server by default. A document
16
16
  * served under a path (a gateway's `servers: [{ url: "/api" }]`) names no host a CLI can call, so it needs this.
17
17
  */
18
- readonly baseUrl?: string;
18
+ readonly baseUrl?: string | undefined;
19
19
  };
20
20
  export type GeneratedGoCli = {
21
21
  readonly files: Readonly<Record<string, string>>;
@@ -11,17 +11,17 @@
11
11
  import { readFileSync } from "node:fs";
12
12
  import { toIR } from "../../ir/build.js";
13
13
  import { sdkModel } from "../../ir/sdk-model.js";
14
- import { compareCodeUnits } from "../shared/lang.js";
15
- import { packageOn } from "../shared/metadata.js";
16
14
  import { goModulePath } from "../go/module-path.js";
17
15
  import { generateGoSdk, goCallPlans, WEBSOCKET, WEBSOCKET_SUM } from "../go/sdk.js";
16
+ import { compareCodeUnits } from "../shared/lang.js";
17
+ import { packageOn } from "../shared/metadata.js";
18
18
  import { commandTree } from "./commands.js";
19
19
  import { discoveryEntries } from "./discovery.js";
20
20
  import { installFiles } from "./install.js";
21
21
  import { cmdFiles } from "./layout.js";
22
22
  import { goreleaserFile, releaseWorkflow, REPO, resolvedRelease } from "./release.js";
23
23
  import { skillFile, skillPath } from "./skills.js";
24
- /* the marker gopls and linters read, apart from the package doc by a blank line */
24
+ // the marker gopls and linters read, apart from the package doc by a blank line
25
25
  const MARKER = "// Code generated by clients. DO NOT EDIT.";
26
26
  /** The runtime files a CLI ships, read from `runtime/cli/` and nowhere else; SOCKET only beside the WebSocket library. */
27
27
  export const CLI_RUNTIME = [
@@ -39,7 +39,7 @@ export const CLI_RUNTIME = [
39
39
  ];
40
40
  /** The runtime file that names the WebSocket library: shipped only when the SDK requires it. */
41
41
  const SOCKET = "socket.go";
42
- /* the CLI's own requirements and their go.sum lines, exactly as `go mod tidy` writes them */
42
+ // the CLI's own requirements and their go.sum lines, exactly as `go mod tidy` writes them
43
43
  const DIRECT = [
44
44
  "github.com/pelletier/go-toml/v2 v2.4.3",
45
45
  "github.com/spf13/cobra v1.10.2",
@@ -61,11 +61,11 @@ const SUM = [
61
61
  "go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=",
62
62
  "gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=",
63
63
  ];
64
- /* a binary: lowercase words joined by `-`, at most 64 characters (its agent skill's name is the binary's); an
65
- * environment prefix: uppercase words joined by `_` */
64
+ // a binary: lowercase words joined by `-`, at most 64 characters (its agent skill's name is the binary's); an
65
+ // environment prefix: uppercase words joined by `_`
66
66
  const BINARY_NAME = /^(?=.{1,64}$)[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
67
67
  const ENV_PREFIX = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
68
- /* a base URL a CLI can call: a scheme and a host, never a path alone */
68
+ // a base URL a CLI can call: a scheme and a host, never a path alone
69
69
  const ABSOLUTE_URL = /^https?:\/\/[^\s/]+/;
70
70
  const refuse = (option, value) => {
71
71
  throw new Error(`Invalid ${option}: ${JSON.stringify(value)}`);
@@ -73,8 +73,8 @@ const refuse = (option, value) => {
73
73
  /** The binary name a title gives: its letters and digits, lowercased, joined by `-`; `api` when it has none. */
74
74
  export const binaryNameOf = (title) => (title ?? "")
75
75
  .toLowerCase()
76
- .replace(/[^a-z0-9]+/g, "-")
77
- .replace(/^[^a-z]+|-+$/g, "") || "api";
76
+ .replaceAll(/[^a-z0-9]+/g, "-")
77
+ .replaceAll(/^[^a-z]+|-+$/g, "") || "api";
78
78
  /**
79
79
  * The base URL the binary calls: the option, else the document's first server when that is absolute. A relative
80
80
  * server is no base URL a CLI can call — a gateway's document says `servers: [{ url: "/api" }]` — so it is left
@@ -103,7 +103,7 @@ function resolved(options, title) {
103
103
  return { baseUrl: options.baseUrl, binaryName, envPrefix, modulePath, repo: options.repo };
104
104
  }
105
105
  /** A go.sum line's order key: its module path, then its version with each number zero-padded, as Go sorts them. */
106
- const sumKey = (line) => line.replace(/\d+/g, (digits) => digits.padStart(20, "0"));
106
+ const sumKey = (line) => line.replaceAll(/\d+/g, (digits) => digits.padStart(20, "0"));
107
107
  /** A require directive as `go mod tidy` writes it: one requirement on its line, more in a block. */
108
108
  const requireOf = (lines) => lines.length === 1 ? `require ${lines[0]}\n` : `require (\n${lines.map((line) => `\t${line}`).join("\n")}\n)\n`;
109
109
  /** go.mod and go.sum: the CLI's requirements, and the WebSocket library's when the embedded SDK needs it. */
@@ -18,19 +18,8 @@
18
18
  */
19
19
  import { type Release } from "./channels.ts";
20
20
  export { REPO, type Release, type ReleaseOptions, resolvedRelease } from "./channels.ts";
21
- /** The tools release.yml runs, each pinned by commit (its release in the comment beside it). */
22
- export declare const RELEASE_ACTIONS: {
23
- attest: string;
24
- checkout: string;
25
- cosign: string;
26
- goreleaser: string;
27
- setupGo: string;
28
- setupNode: string;
29
- };
30
21
  /** A value as a YAML double-quoted scalar (a JSON string is one): a name like `true` or `1e3` stays a string. */
31
22
  export declare const q: (value: string) => string;
32
- /** The goreleaser release the action installs: the one the tests check the config with. */
33
- export declare const GORELEASER_VERSION = "v2.18.3";
34
23
  /** .goreleaser.yaml for the CLI `bin` in module `modulePath`, released per `release` when it names a repository. */
35
24
  export declare function goreleaserFile(bin: string, modulePath: string, release: Release | undefined): string;
36
25
  /**
@@ -19,10 +19,10 @@
19
19
  import { channelBlock, SECRETS } from "./channels.js";
20
20
  import { installgenCommand } from "./install.js";
21
21
  export { REPO, resolvedRelease } from "./channels.js";
22
- /* the marker generated YAML carries on its first line */
22
+ // the marker generated YAML carries on its first line
23
23
  const MARKER = "# Code generated by clients. DO NOT EDIT.";
24
24
  /** The tools release.yml runs, each pinned by commit (its release in the comment beside it). */
25
- export const RELEASE_ACTIONS = {
25
+ const RELEASE_ACTIONS = {
26
26
  attest: "actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4.2.2",
27
27
  checkout: "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1",
28
28
  cosign: "sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2",
@@ -33,10 +33,10 @@ export const RELEASE_ACTIONS = {
33
33
  /** A value as a YAML double-quoted scalar (a JSON string is one): a name like `true` or `1e3` stays a string. */
34
34
  export const q = (value) => JSON.stringify(value);
35
35
  /** The goreleaser release the action installs: the one the tests check the config with. */
36
- export const GORELEASER_VERSION = "v2.18.3";
36
+ const GORELEASER_VERSION = "v2.18.3";
37
37
  /** .goreleaser.yaml for the CLI `bin` in module `modulePath`, released per `release` when it names a repository. */
38
38
  export function goreleaserFile(bin, modulePath, release) {
39
- /* without a repository, goreleaser releases to the git remote's, and there is no version file to serve */
39
+ // without a repository, goreleaser releases to the git remote's, and there is no version file to serve
40
40
  const before = release === undefined
41
41
  ? ""
42
42
  : `# the release's tag, which the install scripts read through releases/latest/download
@@ -7,8 +7,8 @@ export const skillPath = (binaryName) => `skills/${binaryName}/SKILL.md`;
7
7
  const streamsOf = (ops) => ["sse", "ws", "realtime"].filter((kind) => ops.some((op) => op.stream === kind));
8
8
  /** SKILL.md for the CLI `bin` over the API `title` and its operations, its env variables prefixed `prefix`. */
9
9
  export function skillFile(bin, title, prefix, ops) {
10
- const named = [...(helpText(title).replace(/\s+/g, " ").trim() || bin)];
11
- /* the description stays within the format's 1024 characters whatever the title */
10
+ const named = [...(helpText(title).replaceAll(/\s+/g, " ").trim() || bin)];
11
+ // the description stays within the format's 1024 characters whatever the title
12
12
  const api = named.length <= TITLE_MAX ? named.join("") : `${named.slice(0, TITLE_MAX - 1).join("")}…`;
13
13
  const description = `Call the ${api} API from the shell with ${bin}: find a command, read its request and answer, call it, and branch on its JSON output and exit code.`;
14
14
  const streams = streamsOf(ops);
@@ -18,7 +18,11 @@ export function skillFile(bin, title, prefix, ops) {
18
18
  "",
19
19
  "## Streams",
20
20
  `A stream command (${streams.join(", ")}) prints one JSON line per event; \`--take N\` ends it after N.`,
21
- ...(streams.includes("ws") ? ["A ws command sends each stdin line as a text frame."] : []),
21
+ ...(streams.includes("ws")
22
+ ? [
23
+ "A ws command sends each stdin line as a text frame; where its messages are typed, a line that is not one is refused on stderr, not sent, and the run exits 4.",
24
+ ]
25
+ : []),
22
26
  ...(streams.includes("realtime")
23
27
  ? [
24
28
  "A realtime feed writes its resume cursor to stderr when it ends; pass it back with `--reconnect-token` and `--last-event-id`.",
@@ -28,7 +32,7 @@ export function skillFile(bin, title, prefix, ops) {
28
32
  return [
29
33
  "---",
30
34
  `name: ${bin}`,
31
- /* a JSON string is a YAML double-quoted scalar: a colon or quote in the title cannot end it */
35
+ // a JSON string is a YAML double-quoted scalar: a colon or quote in the title cannot end it
32
36
  `description: ${JSON.stringify(description)}`,
33
37
  "---",
34
38
  "",
@@ -3,12 +3,12 @@ import { csString } from "../shared/escape.js";
3
3
  import { compareCodeUnits, csTypeName, NameScope } from "../shared/lang.js";
4
4
  import { docLines } from "./sdk-doc.js";
5
5
  import { csTopLevel, declares } from "./types.js";
6
- /* the class's own name (CS0542) and the members a static class would hide (CS0108 under warnings as errors) */
6
+ // the class's own name (CS0542) and the members a static class would hide (CS0108 under warnings as errors)
7
7
  const RESERVED = ["ErrorKey", "Equals", "GetHashCode", "GetType", "MemberwiseClone", "ReferenceEquals", "ToString"];
8
8
  /** The keys an error response's envelope names, over every operation's JSON error statuses. */
9
9
  function envelopeKeys(model) {
10
10
  return model.ops.flatMap((op) => op.errorStatuses.flatMap((status) => {
11
- /* an error status is a declared response, and a schema comes with the content type it is under */
11
+ // an error status is a declared response, and a schema comes with the content type it is under
12
12
  const { contentType, schema } = op.ir.responses[String(status)];
13
13
  if (schema === undefined || !isJsonMedia(contentType))
14
14
  return [];
@@ -37,7 +37,7 @@ function bodyType(key, schema, model, at) {
37
37
  if (!declares(schema) || irErrorEnvelope(schema, model.resolve) !== null)
38
38
  return undefined;
39
39
  const name = at.names.claim(`${csTypeName(key)}Data`);
40
- /* claimed before its body: what the body hoists in turn comes after it */
40
+ // claimed before its body: what the body hoists in turn comes after it
41
41
  at.decls.set(name, "");
42
42
  at.decls.set(name, csTopLevel(name, schema, at));
43
43
  return name;
@@ -56,7 +56,7 @@ export function csharpErrorKeys(model, at) {
56
56
  member: members.claim(csTypeName(wire)),
57
57
  wire,
58
58
  }));
59
- const decoded = keys.flatMap(({ data, wire }) => (data === undefined ? [] : [`${wire}: its body decodes as ${data}`]));
59
+ const decoded = keys.flatMap(({ data, wire }) => data === undefined ? [] : [`${wire}: its body decodes as ${data}`]);
60
60
  const remark = decoded.map((line, i) => `${line}${i === 0 ? " (ApiStatusException.DecodeBody)" : ""}.`).join(" ");
61
61
  return [
62
62
  "/// <summary>The error keys the API declares: ApiStatusException.Key is one of these, else the server's own string.</summary>",
@@ -7,19 +7,19 @@
7
7
  * annotations are erased at run time, so such a type stays lenient everywhere).
8
8
  */
9
9
  import { compareCodeUnits, NameScope } from "../shared/lang.js";
10
- /* the value types emitted text spells, besides the declared enums: `T?` of one is `Nullable<T>` at run time */
10
+ // the value types emitted text spells, besides the declared enums: `T?` of one is `Nullable<T>` at run time
11
11
  const VALUE_TYPES = ["bool", "double", "JsonElement", "long"];
12
- /* the names the generator gives the BCL types it lists, which the context's own names follow */
12
+ // the names the generator gives the BCL types it lists, which the context's own names follow
13
13
  const BCL_NAMES = {
14
+ JsonElement: "JsonElement",
14
15
  bool: "Boolean",
15
16
  double: "Double",
16
- JsonElement: "JsonElement",
17
17
  long: "Int64",
18
18
  string: "String",
19
19
  };
20
20
  const LIST = /^IReadOnlyList<(.*)>$/;
21
21
  const MAP = /^IReadOnlyDictionary<string, (.*)>$/;
22
- /* the context's own members and the members every class has: no TypeInfoPropertyName may take one */
22
+ // the context's own members and the members every class has: no TypeInfoPropertyName may take one
23
23
  const CONTEXT_MEMBERS = [
24
24
  "Default",
25
25
  "Equals",
@@ -78,13 +78,13 @@ export function strictConverters(collections, runtime) {
78
78
  const lenient = new Set();
79
79
  const strict = new Set();
80
80
  for (const type of collections) {
81
- const list = LIST.exec(type)?.[1];
82
- const item = list ?? MAP.exec(type)?.[1];
81
+ const list = LIST.test(type);
82
+ const item = type.replace(list ? LIST : MAP, "$1");
83
83
  const base = runtime(item).replace(/\?$/, "");
84
- /* a value type keeps its `?` at run time: its null item fails the read already (Q2) */
84
+ // a value type keeps its `?` at run time: its null item fails the read already (Q2)
85
85
  if (runtime(`${base}?`).endsWith("?"))
86
86
  continue;
87
- const converter = `typeof(${list === undefined ? "NonNullMap" : "NonNullList"}<${base}>)`;
87
+ const converter = `typeof(${list ? "NonNullList" : "NonNullMap"}<${base}>)`;
88
88
  (item.endsWith("?") ? lenient : strict).add(converter);
89
89
  }
90
90
  return [...strict].filter((converter) => !lenient.has(converter)).sort(compareCodeUnits);
@@ -1,10 +1,3 @@
1
- /**
2
- * A realtime operation's answer (contract 50 §2, Fd6, Fd7): `Task<ResumableConnection<T>>` through `RealtimeAsync`,
3
- * `T` the declared event schema's type (`JsonElement` for a string or absent one), opened by awaiting the method over
4
- * WebSocket, else SSE, else long-poll. Its five fields are `TransportOptions.Of`'s: the resume cursor, the offered
5
- * subprotocols and the reconnect policy (`TimeSpan? reconnectDelay`). A declared param on a resume channel is folded
6
- * in, and one named like a field is claimed as `…2` (`sdk-method.ts`).
7
- */
8
1
  import { type CsStream } from "./sdk-answer.ts";
9
- /** The realtime operation's answer, its five fields and its `<returns>` text. */
2
+ /** The realtime operation's answer, its one field and its `<returns>` text. */
10
3
  export declare const realtimeStream: CsStream;
@@ -1,33 +1,33 @@
1
- /**
2
- * A realtime operation's answer (contract 50 §2, Fd6, Fd7): `Task<ResumableConnection<T>>` through `RealtimeAsync`,
3
- * `T` the declared event schema's type (`JsonElement` for a string or absent one), opened by awaiting the method over
4
- * WebSocket, else SSE, else long-poll. Its five fields are `TransportOptions.Of`'s: the resume cursor, the offered
5
- * subprotocols and the reconnect policy (`TimeSpan? reconnectDelay`). A declared param on a resume channel is folded
6
- * in, and one named like a field is claimed as `…2` (`sdk-method.ts`).
7
- */
8
1
  import { eventType } from "./sdk-answer.js";
9
- import { isLastEventIdHeader, LAST_EVENT_ID_FIELD } from "./sse.js";
10
- import { isReconnectToken, PROTOCOLS, RECONNECT_TOKEN } from "./ws.js";
11
- /** The realtime operation's answer, its five fields and its `<returns>` text. */
2
+ import { isLastEventIdHeader } from "./sse.js";
3
+ import { messageType, valueHandlers } from "./types-messages.js";
4
+ import { JSON_ELEMENT } from "./types.js";
5
+ import { isReconnectToken } from "./ws.js";
6
+ // the connection, and its own event: a member whose On<Value> it names gets none
7
+ const READER = { base: "ResumableConnection", handlers: ["OnMessage"], receiver: "connection" };
8
+ /** The realtime operation `op`'s answer, its message types hoisted into `env.at`. */
9
+ function realtimeAnswer(op, env) {
10
+ const { receive, send } = op.ir.messages ?? {};
11
+ const read = send === undefined ? undefined : messageType(op, send, "Send", env.at);
12
+ const write = receive === undefined ? JSON_ELEMENT : messageType(op, receive, "Receive", env.at).type;
13
+ if (read !== undefined)
14
+ valueHandlers(READER, read, env.at);
15
+ const type = read?.type ?? (op.events === undefined ? JSON_ELEMENT : eventType(op.events, op, env));
16
+ const run = send === undefined && receive === undefined ? "RealtimeAsync" : "TypedRealtimeAsync";
17
+ return {
18
+ infos: [type, write],
19
+ render: (spell) => [`Task<ResumableConnection<${spell.runtime(type)}, ${spell.runtime(write)}>>`, run],
20
+ type: null,
21
+ };
22
+ }
23
+ /** The realtime operation's answer, its one field and its `<returns>` text. */
12
24
  export const realtimeStream = {
13
- answer: (op, env) => {
14
- const type = op.events === undefined ? "JsonElement" : eventType(op.events, op, env);
15
- return {
16
- render: (spell) => [`Task<ResumableConnection<${spell.runtime(type)}>>`, "RealtimeAsync"],
17
- type,
18
- };
19
- },
20
- args: ["TransportOptions.Of(lastEventId, reconnectToken, protocols, maxReconnectAttempts, reconnectDelay)"],
21
- /* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
25
+ answer: realtimeAnswer,
26
+ args: ["(transport ?? new()).Copy()"],
27
+ // the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
22
28
  carries: (name, where) => isReconnectToken(name, where) ||
23
29
  (where === "query" && name === "last_event_id") ||
24
30
  isLastEventIdHeader(name, where),
25
- fields: [
26
- LAST_EVENT_ID_FIELD,
27
- RECONNECT_TOKEN,
28
- PROTOCOLS,
29
- { ident: "maxReconnectAttempts", type: "int?" },
30
- { ident: "reconnectDelay", type: "TimeSpan?" },
31
- ],
31
+ fields: [{ ident: "transport", type: "TransportOptions?" }],
32
32
  returns: "The connection over WebSocket, else SSE, else long-poll: it reconnects after a drop and resumes after the last message it delivered; the token, CloseAsync or DisposeAsync ends it.",
33
33
  };
@@ -6,14 +6,22 @@
6
6
  * in the JSON context) with one nullable `{ get; private set; }` property per header in code-unit order of its
7
7
  * name, typed by the header's scalar (`long?`, `double?`, `bool?`, else `string?`), and an `internal` `Read` the
8
8
  * transport calls on a 2xx; a WebSocket or realtime operation, whose 2xx no caller receives, gets none. A
9
- * stream operation answers as its `CsStream` says (`sse.ts`, `ws.ts`, `realtime.ts`).
9
+ * stream operation answers as its `CsStream` says (`sse.ts`, `ws.ts`, `realtime.ts`), its call passing the arguments
10
+ * and type infos its answer adds (a named-event stream's decode, a socket's or a connection's two types) before
11
+ * the type info.
10
12
  */
11
13
  import type { IRSchema } from "../../ir/model.ts";
12
14
  import type { SdkOp } from "../../ir/sdk-model.ts";
13
15
  import type { MethodEnv, Spelling } from "./sdk-method.ts";
14
- /** A method's answer: its JSON type (null for any other kind), and its return type and transport method. */
16
+ /**
17
+ * A method's answer: its JSON type (null for any other kind), the arguments its call passes before that type's info
18
+ * (a named-event stream's decode), the types whose infos it passes after them (a typed socket's or a realtime
19
+ * connection's read and send types), and its return type and transport method.
20
+ */
15
21
  export type CsAnswer = {
16
22
  readonly type: string | null;
23
+ readonly args?: readonly string[];
24
+ readonly infos?: readonly string[];
17
25
  readonly render: (spell: Spelling) => readonly [returns: string, run: string];
18
26
  };
19
27
  /**
@@ -35,17 +35,17 @@ function declaredHeaders(op) {
35
35
  .filter((status) => /^2(?:\d\d|XX)$/i.test(status))
36
36
  .sort(compareCodeUnits)
37
37
  .flatMap((status) => op.ir.responses[status].headers ?? []);
38
- /* reversed, so the first spelling of a name is the one its key ends on */
38
+ // reversed, so the first spelling of a name is the one its key ends on
39
39
  const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
40
40
  return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
41
41
  }
42
- /* a scalar header's C# type and its reader; anything else is its text */
42
+ // a scalar header's C# type and its reader; anything else is its text
43
43
  const READERS = {
44
44
  boolean: ["bool?", "Bool"],
45
45
  integer: ["long?", "Int64"],
46
46
  number: ["double?", "Double"],
47
47
  };
48
- /* the holder's own members and the members every class has */
48
+ // the holder's own members and the members every class has
49
49
  const HOLDER_MEMBERS = ["Equals", "Finalize", "GetHashCode", "GetType", "MemberwiseClone", "Read", "ToString"];
50
50
  /** `<Op>Headers` hoisted into `env.at.decls` (never listed), and its plan; null when `op` declares none. */
51
51
  export function csResponseHeaders(op, env) {
@@ -77,7 +77,7 @@ export function csResponseHeaders(op, env) {
77
77
  "",
78
78
  " internal void Read(IReadOnlyDictionary<string, string> headers)",
79
79
  " {",
80
- ...fields.map((f) => ` ${f.property} = ResponseHeaders.${f.reader}(headers, ${csString(f.header)}, required: ${f.required === true});`),
80
+ ...fields.map((f) => ` ${f.property} = ResponseHeaders.${f.reader}(headers, ${csString(f.header)}, required: ${f.required});`),
81
81
  " }",
82
82
  "}",
83
83
  ].join("\n"));
@@ -6,13 +6,13 @@ import { csTypeOf } from "./types.js";
6
6
  const NONE = { expr: () => "null", type: null, types: [] };
7
7
  /** The parts the body schema of `op` requires: none unless it is an object. */
8
8
  function requiredParts(op, env) {
9
- /* a multipart body, with file parts or text parts alone, is declared with its form's schema */
9
+ // a multipart body, with file parts or text parts alone, is declared with its form's schema
10
10
  const form = env.at.names.resolve(op.ir.body.schema);
11
11
  return new Set(form.kind === "object" ? form.fields.flatMap((f) => (f.required ? [f.name] : [])) : []);
12
12
  }
13
13
  /** The C# type of `part` as a property of `parent`: `FilePart` or its list for a file, its schema's type for text. */
14
14
  function partType(part, parent, env) {
15
- /* the IR gives every part its schema (ir/slots.ts partsOf, ir/sdk-model.ts bodyOf) */
15
+ // the IR gives every part its schema (ir/slots.ts partsOf, ir/sdk-model.ts bodyOf)
16
16
  const schema = part.schema;
17
17
  if (part.type === "text")
18
18
  return csTypeOf(schema, { ...env.at, fieldName: part.name, parentName: parent });
@@ -21,7 +21,7 @@ function partType(part, parent, env) {
21
21
  /** `<Op>Body` for `parts`, declared once into `env.at.decls` and never listed; its name and its parts. */
22
22
  function multipartBody(op, parts, env) {
23
23
  const name = env.at.names.hoist(`${op.id}.Body`, `${csTypeName(op.id)}Body`);
24
- /* claimed before its parts: what a text part hoists in turn comes after it */
24
+ // claimed before its parts: what a text part hoists in turn comes after it
25
25
  env.at.decls.set(name, "");
26
26
  env.at.unlisted.add(name);
27
27
  const required = requiredParts(op, env);
@@ -30,7 +30,7 @@ function multipartBody(op, parts, env) {
30
30
  .sort((a, b) => compareCodeUnits(a.name, b.name))
31
31
  .map((part) => {
32
32
  const type = partType(part, name, env);
33
- /* a part left unset is null: a value type's `?` makes it Nullable<T>, which the context lists */
33
+ // a part left unset is null: a value type's `?` makes it Nullable<T>, which the context lists
34
34
  return {
35
35
  file: part.type === "file",
36
36
  name: part.name,
@@ -74,10 +74,12 @@ export function csBody(op, env) {
74
74
  const type = schemaType(body.schema);
75
75
  return { expr: (spell) => `Body.Form(body, ${spell.info(type)})`, type, types: [type] };
76
76
  }
77
- case "text":
77
+ case "text": {
78
78
  return { expr: () => `Body.Text(body, ${media})`, type: "string", types: [] };
79
- case "binary":
79
+ }
80
+ case "binary": {
80
81
  return { expr: () => `Body.Binary(body, ${media})`, type: "BinaryBody", types: [] };
82
+ }
81
83
  case "multipart": {
82
84
  const { name, parts } = multipartBody(op, body.parts, env);
83
85
  const expr = (spell) => guarded(op, `Body.Multipart([${parts.map((part) => partExpr(part, spell)).join(", ")}])`);
@@ -26,7 +26,7 @@ export type ClientEnv = MethodEnv & {
26
26
  * them.
27
27
  */
28
28
  export declare function clientDecls(ir: IR, env: ClientEnv): {
29
- plans: CSharpCallPlan[];
30
- text: (spell: Spelling) => string;
31
- types: string[];
29
+ readonly plans: CSharpCallPlan[];
30
+ readonly text: (spell: Spelling) => string;
31
+ readonly types: string[];
32
32
  };