@workerstack/clients 1.0.0-rc.29 → 1.0.0-rc.31

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 (375) hide show
  1. package/README.md +548 -35
  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 +88 -68
  6. package/bin/installgen.js +18 -13
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +20 -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 +14 -8
  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 +11 -5
  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 +3 -3
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.js +3 -3
  29. package/dist/emit/csharp/sdk-answer.js +4 -4
  30. package/dist/emit/csharp/sdk-body.js +8 -6
  31. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  32. package/dist/emit/csharp/sdk-client.js +2 -2
  33. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  34. package/dist/emit/csharp/sdk-csproj.js +10 -10
  35. package/dist/emit/csharp/sdk-doc.js +1 -1
  36. package/dist/emit/csharp/sdk-method.d.ts +18 -2
  37. package/dist/emit/csharp/sdk-method.js +24 -9
  38. package/dist/emit/csharp/sdk-plan.js +0 -1
  39. package/dist/emit/csharp/sdk.js +7 -4
  40. package/dist/emit/csharp/sse.d.ts +0 -2
  41. package/dist/emit/csharp/sse.js +7 -7
  42. package/dist/emit/csharp/transport.js +7 -7
  43. package/dist/emit/csharp/types-enum.js +3 -1
  44. package/dist/emit/csharp/types-messages.js +3 -3
  45. package/dist/emit/csharp/types-names.js +10 -12
  46. package/dist/emit/csharp/types-record.js +3 -3
  47. package/dist/emit/csharp/types-union.d.ts +1 -1
  48. package/dist/emit/csharp/types.d.ts +0 -1
  49. package/dist/emit/csharp/types.js +3 -3
  50. package/dist/emit/csharp/ws.js +2 -2
  51. package/dist/emit/go/errors.js +1 -1
  52. package/dist/emit/go/http.js +2 -2
  53. package/dist/emit/go/module-path.js +2 -2
  54. package/dist/emit/go/sdk-answer.js +1 -1
  55. package/dist/emit/go/sdk-body.js +11 -7
  56. package/dist/emit/go/sdk-client.js +1 -1
  57. package/dist/emit/go/sdk-method.d.ts +9 -0
  58. package/dist/emit/go/sdk-method.js +12 -3
  59. package/dist/emit/go/sdk-mirror.js +2 -2
  60. package/dist/emit/go/sdk-opts.d.ts +0 -2
  61. package/dist/emit/go/sdk-opts.js +3 -3
  62. package/dist/emit/go/sdk.d.ts +1 -1
  63. package/dist/emit/go/sdk.js +12 -11
  64. package/dist/emit/go/sse.js +1 -1
  65. package/dist/emit/go/types-names.js +5 -0
  66. package/dist/emit/go/types-struct.d.ts +2 -1
  67. package/dist/emit/go/types-struct.js +1 -1
  68. package/dist/emit/go/types.js +9 -9
  69. package/dist/emit/go/ws.js +6 -6
  70. package/dist/emit/java/gradle.d.ts +7 -9
  71. package/dist/emit/java/gradle.js +8 -8
  72. package/dist/emit/java/json.js +1 -1
  73. package/dist/emit/java/layout-ast.js +1 -1
  74. package/dist/emit/java/layout-decl.js +5 -4
  75. package/dist/emit/java/layout-doc.js +13 -7
  76. package/dist/emit/java/layout-dot.js +1 -1
  77. package/dist/emit/java/layout-strings.js +4 -5
  78. package/dist/emit/java/layout-types.js +7 -5
  79. package/dist/emit/java/layout-visitor.js +4 -3
  80. package/dist/emit/java/layout.js +5 -4
  81. package/dist/emit/java/models-names.js +5 -4
  82. package/dist/emit/java/models-record.d.ts +0 -1
  83. package/dist/emit/java/models-record.js +3 -3
  84. package/dist/emit/java/models-union.d.ts +1 -1
  85. package/dist/emit/java/models-union.js +1 -1
  86. package/dist/emit/java/models.d.ts +1 -2
  87. package/dist/emit/java/models.js +25 -16
  88. package/dist/emit/java/realtime.d.ts +5 -17
  89. package/dist/emit/java/realtime.js +1 -1
  90. package/dist/emit/java/sdk-client.d.ts +6 -6
  91. package/dist/emit/java/sdk-client.js +2 -1
  92. package/dist/emit/java/sdk-decl.js +2 -2
  93. package/dist/emit/java/sdk-errors.js +1 -1
  94. package/dist/emit/java/sdk-headers.js +2 -2
  95. package/dist/emit/java/sdk-mirror.js +2 -2
  96. package/dist/emit/java/sdk-models.d.ts +1 -1
  97. package/dist/emit/java/sdk-models.js +7 -7
  98. package/dist/emit/java/sdk-op.d.ts +7 -11
  99. package/dist/emit/java/sdk-op.js +22 -10
  100. package/dist/emit/java/sdk-params.d.ts +5 -5
  101. package/dist/emit/java/sdk-params.js +3 -2
  102. package/dist/emit/java/sdk-plan.js +0 -1
  103. package/dist/emit/java/sdk.d.ts +1 -1
  104. package/dist/emit/java/sdk.js +21 -14
  105. package/dist/emit/java/sse.d.ts +2 -4
  106. package/dist/emit/java/sse.js +6 -6
  107. package/dist/emit/java/ws.d.ts +2 -2
  108. package/dist/emit/java/ws.js +3 -4
  109. package/dist/emit/mcp/annotations.js +8 -4
  110. package/dist/emit/mcp/files.js +9 -9
  111. package/dist/emit/mcp/mounted.js +2 -2
  112. package/dist/emit/mcp/output-schema.js +3 -3
  113. package/dist/emit/mcp/registry.d.ts +0 -2
  114. package/dist/emit/mcp/registry.js +5 -4
  115. package/dist/emit/mcp/runtime.js +2 -2
  116. package/dist/emit/mcp/schema.js +22 -11
  117. package/dist/emit/mcp/server.d.ts +7 -7
  118. package/dist/emit/mcp/server.js +7 -6
  119. package/dist/emit/mcp/tools.js +7 -6
  120. package/dist/emit/python/errors.js +3 -3
  121. package/dist/emit/python/realtime.js +2 -2
  122. package/dist/emit/python/sdk-answer.d.ts +3 -7
  123. package/dist/emit/python/sdk-answer.js +2 -2
  124. package/dist/emit/python/sdk-body.js +4 -5
  125. package/dist/emit/python/sdk-client.js +5 -5
  126. package/dist/emit/python/sdk-doc.js +2 -2
  127. package/dist/emit/python/sdk-method.d.ts +11 -0
  128. package/dist/emit/python/sdk-method.js +20 -5
  129. package/dist/emit/python/sdk-plan.js +0 -1
  130. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  131. package/dist/emit/python/sdk-pyproject.js +8 -8
  132. package/dist/emit/python/sdk.d.ts +1 -1
  133. package/dist/emit/python/sdk.js +12 -8
  134. package/dist/emit/python/sse.d.ts +0 -2
  135. package/dist/emit/python/sse.js +2 -2
  136. package/dist/emit/python/transport.js +4 -4
  137. package/dist/emit/python/types-dict.d.ts +2 -2
  138. package/dist/emit/python/types-dict.js +1 -1
  139. package/dist/emit/python/types-names.js +2 -2
  140. package/dist/emit/python/types-union.js +1 -1
  141. package/dist/emit/python/types.js +3 -3
  142. package/dist/emit/python/ws.d.ts +2 -5
  143. package/dist/emit/python/ws.js +4 -4
  144. package/dist/emit/rust/errors.js +3 -3
  145. package/dist/emit/rust/http.js +4 -4
  146. package/dist/emit/rust/realtime.js +2 -2
  147. package/dist/emit/rust/sdk-body.js +8 -5
  148. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  149. package/dist/emit/rust/sdk-cargo.js +12 -12
  150. package/dist/emit/rust/sdk-client.d.ts +1 -1
  151. package/dist/emit/rust/sdk-client.js +3 -3
  152. package/dist/emit/rust/sdk-method.d.ts +12 -1
  153. package/dist/emit/rust/sdk-method.js +12 -4
  154. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  155. package/dist/emit/rust/sdk-opts.js +2 -2
  156. package/dist/emit/rust/sdk-plan.js +0 -1
  157. package/dist/emit/rust/sdk.d.ts +1 -1
  158. package/dist/emit/rust/sdk.js +9 -6
  159. package/dist/emit/rust/sse.d.ts +0 -5
  160. package/dist/emit/rust/sse.js +2 -2
  161. package/dist/emit/rust/types-names.js +3 -3
  162. package/dist/emit/rust/types-struct.js +1 -1
  163. package/dist/emit/rust/types-union.d.ts +1 -1
  164. package/dist/emit/rust/types.js +7 -5
  165. package/dist/emit/rust/ws.d.ts +0 -11
  166. package/dist/emit/rust/ws.js +5 -5
  167. package/dist/emit/shared/escape.js +17 -17
  168. package/dist/emit/shared/format.js +1 -1
  169. package/dist/emit/shared/gofmt.js +1 -1
  170. package/dist/emit/shared/lang.js +10 -10
  171. package/dist/emit/shared/literals.d.ts +5 -0
  172. package/dist/emit/shared/literals.js +8 -0
  173. package/dist/emit/shared/metadata.d.ts +0 -6
  174. package/dist/emit/shared/metadata.js +8 -7
  175. package/dist/emit/shared/ruff.js +1 -1
  176. package/dist/emit/shared/rustfmt.js +1 -1
  177. package/dist/emit/shared/type-emitter.js +37 -20
  178. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  179. package/dist/emit/shared/unknown-type.constants.js +2 -0
  180. package/dist/emit/ts/http.d.ts +8 -2
  181. package/dist/emit/ts/http.js +51 -6
  182. package/dist/emit/ts/package.d.ts +14 -12
  183. package/dist/emit/ts/package.js +10 -8
  184. package/dist/emit/ts/route-tree.js +2 -2
  185. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  186. package/dist/emit/ts/sdk-types-preamble.js +12 -4
  187. package/dist/emit/ts/sdk-types.d.ts +0 -5
  188. package/dist/emit/ts/sdk-types.js +63 -19
  189. package/dist/emit/ts/sdk.d.ts +3 -1
  190. package/dist/emit/ts/sdk.js +44 -12
  191. package/dist/emit/ts/service-map.d.ts +7 -1
  192. package/dist/emit/ts/service-map.js +10 -1
  193. package/dist/emit/ts/single-flight-text.d.ts +3 -0
  194. package/dist/emit/ts/single-flight-text.js +38 -0
  195. package/dist/emit/ts/tanstack-query.d.ts +3 -2
  196. package/dist/emit/ts/tanstack-query.js +60 -35
  197. package/dist/emit/ts/type-gen.js +31 -18
  198. package/dist/emit/ts/webhooks.d.ts +0 -2
  199. package/dist/emit/ts/webhooks.js +3 -3
  200. package/dist/extract/chain.js +5 -4
  201. package/dist/extract/extract.js +5 -5
  202. package/dist/extract/serialize.d.ts +0 -2
  203. package/dist/extract/serialize.js +14 -15
  204. package/dist/extract/walk.js +15 -12
  205. package/dist/gen/args.js +9 -5
  206. package/dist/gen/formatters.js +5 -3
  207. package/dist/gen/process.js +2 -1
  208. package/dist/gen/shipped.js +2 -2
  209. package/dist/gen/switch-on.constants.d.ts +2 -0
  210. package/dist/gen/switch-on.constants.js +2 -0
  211. package/dist/gen/targets.d.ts +6 -7
  212. package/dist/gen/targets.js +11 -6
  213. package/dist/gen/write.js +4 -2
  214. package/dist/index.js +2 -2
  215. package/dist/installers/cli.d.ts +4 -4
  216. package/dist/installers/cli.js +24 -24
  217. package/dist/installers/commands/build.d.ts +4 -4
  218. package/dist/installers/commands/build.js +2 -3
  219. package/dist/installers/commands/check.d.ts +2 -2
  220. package/dist/installers/commands/check.js +11 -10
  221. package/dist/installers/commands/init.d.ts +2 -2
  222. package/dist/installers/commands/init.js +1 -2
  223. package/dist/installers/config/define-config.d.ts +16 -16
  224. package/dist/installers/config/define-config.js +1 -1
  225. package/dist/installers/config/hooks/bun.d.ts +6 -6
  226. package/dist/installers/config/hooks/node.js +1 -1
  227. package/dist/installers/config/load.d.ts +6 -8
  228. package/dist/installers/config/load.js +7 -8
  229. package/dist/installers/config/resolve.d.ts +1 -2
  230. package/dist/installers/config/resolve.js +28 -33
  231. package/dist/installers/config/types.d.ts +6 -6
  232. package/dist/installers/config/types.js +0 -1
  233. package/dist/installers/render/quote.js +3 -5
  234. package/dist/installers/render/render.d.ts +6 -6
  235. package/dist/installers/render/render.js +26 -26
  236. package/dist/installers/ui.d.ts +4 -4
  237. package/dist/installers/ui.js +3 -3
  238. package/dist/ir/build.d.ts +3 -3
  239. package/dist/ir/build.js +8 -5
  240. package/dist/ir/invalidate-reads.d.ts +17 -0
  241. package/dist/ir/invalidate-reads.js +104 -0
  242. package/dist/ir/load.d.ts +10 -0
  243. package/dist/ir/load.js +65 -18
  244. package/dist/ir/model.d.ts +2 -1
  245. package/dist/ir/model.js +0 -1
  246. package/dist/ir/read-method.constants.d.ts +2 -0
  247. package/dist/ir/read-method.constants.js +2 -0
  248. package/dist/ir/resolve-refs.js +2 -2
  249. package/dist/ir/resource-tree.js +2 -1
  250. package/dist/ir/route-tree-intern.js +1 -1
  251. package/dist/ir/schema.js +3 -3
  252. package/dist/ir/sdk-model.js +3 -3
  253. package/dist/ir/slots.js +13 -8
  254. package/dist/ir/streams.js +1 -1
  255. package/dist/release/bootstrap.d.ts +3 -3
  256. package/dist/release/bootstrap.js +7 -7
  257. package/dist/release/bump-args.js +4 -4
  258. package/dist/release/bump-command.d.ts +1 -1
  259. package/dist/release/bump-command.js +9 -10
  260. package/dist/release/bump.d.ts +5 -4
  261. package/dist/release/bump.js +2 -2
  262. package/dist/release/cli.d.ts +4 -4
  263. package/dist/release/cli.js +4 -4
  264. package/dist/release/codegen.js +1 -1
  265. package/dist/release/digest.js +5 -7
  266. package/dist/release/git.js +5 -8
  267. package/dist/release/load.js +4 -4
  268. package/dist/release/manifest.js +9 -10
  269. package/dist/release/oasdiff.d.ts +10 -15
  270. package/dist/release/oasdiff.js +5 -6
  271. package/dist/release/registries.d.ts +0 -11
  272. package/dist/release/registries.js +17 -17
  273. package/dist/release/release-state.d.ts +16 -13
  274. package/dist/release/release-workflow.js +5 -7
  275. package/dist/release/repo-settings.d.ts +2 -1
  276. package/dist/release/spec-gate.d.ts +0 -2
  277. package/dist/release/spec-gate.js +6 -10
  278. package/dist/release/sync-command.d.ts +2 -2
  279. package/dist/release/sync-command.js +1 -1
  280. package/dist/release/sync-tree.js +9 -13
  281. package/dist/release/sync.d.ts +6 -6
  282. package/dist/release/sync.js +12 -13
  283. package/dist/release/types.d.ts +22 -22
  284. package/dist/release/types.js +0 -1
  285. package/dist/release/version-files.d.ts +3 -4
  286. package/dist/release/version-files.js +4 -5
  287. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  288. package/dist/runtime/csharp/Config.cs +9 -1
  289. package/dist/runtime/csharp/Exchange.cs +56 -4
  290. package/dist/runtime/csharp/Hooks.cs +9 -0
  291. package/dist/runtime/csharp/Operation.cs +6 -1
  292. package/dist/runtime/csharp/WsDial.cs +3 -1
  293. package/dist/runtime/go/config.go +5 -0
  294. package/dist/runtime/go/hooks.go +70 -0
  295. package/dist/runtime/go/request.go +6 -2
  296. package/dist/runtime/go/stream.go +4 -1
  297. package/dist/runtime/go/ws.go +3 -1
  298. package/dist/runtime/java/ClientConfig.java +11 -0
  299. package/dist/runtime/java/Flight.java +2 -12
  300. package/dist/runtime/java/Hooks.java +45 -0
  301. package/dist/runtime/java/InvalidateEvent.java +10 -0
  302. package/dist/runtime/java/InvalidateHook.java +12 -0
  303. package/dist/runtime/java/InvalidateTarget.java +7 -0
  304. package/dist/runtime/java/Operation.java +23 -3
  305. package/dist/runtime/java/Realtime.java +3 -1
  306. package/dist/runtime/java/WsDial.java +3 -0
  307. package/dist/runtime/mcp/files.ts +1 -1
  308. package/dist/runtime/mcp/http.ts +6 -2
  309. package/dist/runtime/mcp/listen.ts +1 -1
  310. package/dist/runtime/mcp/mount.ts +2 -2
  311. package/dist/runtime/mcp/protocol.ts +1 -1
  312. package/dist/runtime/python/config.py +8 -2
  313. package/dist/runtime/python/exchange.py +3 -1
  314. package/dist/runtime/python/hooks.py +110 -5
  315. package/dist/runtime/python/operation.py +2 -0
  316. package/dist/runtime/python/send_async.py +14 -2
  317. package/dist/runtime/python/send_sync.py +4 -2
  318. package/dist/runtime/python/ws.py +5 -1
  319. package/dist/runtime/rust/config.rs +6 -1
  320. package/dist/runtime/rust/exchange.rs +15 -3
  321. package/dist/runtime/rust/hooks.rs +127 -2
  322. package/dist/runtime/rust/log.rs +11 -3
  323. package/dist/runtime/rust/request.rs +17 -0
  324. package/dist/runtime/rust/ws.rs +9 -1
  325. package/dist/runtime/ts/config.ts +69 -0
  326. package/dist/runtime/ts/http.ts +12 -10
  327. package/dist/runtime/ts/request.ts +2 -0
  328. package/dist/runtime/ts/response.ts +7 -0
  329. package/dist/runtime/ts/sdk-invalidate.ts +82 -0
  330. package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
  331. package/dist/runtime/ts/sdk-single-flight.ts +203 -0
  332. package/dist/runtime/ts/sdk-sse.ts +5 -1
  333. package/dist/runtime/ts/sdk-ws.ts +9 -3
  334. package/dist/runtime/ts/sdk.ts +55 -31
  335. package/dist/runtime/ts/single-flight-batch.ts +184 -0
  336. package/dist/runtime/ts/single-flight-body.ts +59 -0
  337. package/dist/runtime/ts/single-flight-run.ts +160 -0
  338. package/dist/runtime/ts/single-flight.constants.ts +31 -0
  339. package/dist/runtime/ts/single-flight.ts +158 -0
  340. package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
  341. package/dist/runtime/ts-tanstack-query/query.ts +140 -170
  342. package/package.json +12 -17
  343. package/references/INDEX.md +31 -0
  344. package/references/cli.md +33 -0
  345. package/references/configuring.md +29 -0
  346. package/references/documentation.md +15 -0
  347. package/references/errors.md +23 -0
  348. package/references/flags.md +104 -0
  349. package/references/gates.md +46 -0
  350. package/references/generate.md +29 -0
  351. package/references/install-scripts.md +28 -0
  352. package/references/install.md +38 -0
  353. package/references/license.md +8 -0
  354. package/references/mcp.md +76 -0
  355. package/references/output.md +45 -0
  356. package/references/overview.md +14 -0
  357. package/references/release-tooling.md +34 -0
  358. package/references/release.md +305 -0
  359. package/references/sdks.md +393 -0
  360. package/references/start.md +22 -0
  361. package/references/tdd.md +16 -0
  362. package/dist/emit/cli/index.d.ts +0 -1
  363. package/dist/emit/cli/index.js +0 -1
  364. package/dist/emit/csharp/index.d.ts +0 -1
  365. package/dist/emit/csharp/index.js +0 -1
  366. package/dist/emit/go/index.d.ts +0 -1
  367. package/dist/emit/go/index.js +0 -1
  368. package/dist/emit/java/index.d.ts +0 -2
  369. package/dist/emit/java/index.js +0 -2
  370. package/dist/emit/mcp/index.d.ts +0 -3
  371. package/dist/emit/mcp/index.js +0 -3
  372. package/dist/emit/python/index.d.ts +0 -1
  373. package/dist/emit/python/index.js +0 -1
  374. package/dist/emit/rust/index.d.ts +0 -1
  375. package/dist/emit/rust/index.js +0 -1
@@ -1,6 +1,6 @@
1
1
  import { eventType, isLastEventIdHeader } from "./sse.js";
2
2
  import { isReconnectToken, messageType, typeParams, valueHandlers } from "./ws.js";
3
- /* the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID */
3
+ // the WebSocket and long-poll dials send the cursor as query params, the SSE dial its id as Last-Event-ID
4
4
  const REALTIME = {
5
5
  carries: (param, where) => isReconnectToken(param, where) ||
6
6
  (where === "query" && param === "last_event_id") ||
@@ -18,7 +18,7 @@ export function realtimeAnswer(op, at) {
18
18
  const write = receive && messageType(op, receive, "Receive", at);
19
19
  if (send !== undefined && read !== undefined)
20
20
  valueHandlers("ResumableConnection", ["on_message"], { schema: send, type: read }, at);
21
- /* declared messages are JSON: one that is not is an error; an event type or none reads text too */
21
+ // declared messages are JSON: one that is not is an error; an event type or none reads text too
22
22
  const loop = read === undefined && write === undefined ? "connect" : "typed";
23
23
  const params = typeParams(read ?? (op.events === undefined ? undefined : eventType(op, op.events, at)), write, "serde_json::Value");
24
24
  const run = `crate::realtime_loop::${loop}(opts.transport.clone())`;
@@ -6,14 +6,13 @@ import { rustTypeOf } from "./types.js";
6
6
  export const typeAt = (schema, parent, field, at) => unboxed(schema, rustTypeOf(schema, { ...at, fieldName: field, parentName: parent }));
7
7
  /** The field of `part` named `ident` on the struct `parent`: its type by the part's kind, and its statement. */
8
8
  function partField(part, ident, parent, at) {
9
- /* the IR gives every part its schema (ir/slots.ts partsOf) */
9
+ // the IR gives every part its schema (ir/slots.ts partsOf)
10
10
  const declared = part.schema;
11
11
  const schema = at.names.resolve(declared);
12
12
  const call = part.type === "file" ? "files" : "text";
13
13
  const line = `form.${call}(${rustString(part.name)}, &body.${ident});`;
14
- if (part.type === "file") {
14
+ if (part.type === "file")
15
15
  return { decl: schema.kind === "array" ? "Vec<crate::FilePart>" : "Option<crate::FilePart>", line };
16
- }
17
16
  if (schema.kind === "array")
18
17
  return { decl: `Vec<${typeAt(schema.items, parent, part.name, at)}>`, line };
19
18
  return { decl: `Option<${typeAt(declared, parent, part.name, at)}>`, line };
@@ -28,7 +27,7 @@ function multipartBody(op, parts, at) {
28
27
  return { ident, ...partField(part, ident, type, at) };
29
28
  });
30
29
  const doc = `The multipart/form-data parts of ${op.id}'s body: None and an empty list send no part.`;
31
- /* never empty: a body is multipart only with a file part (ir/slots.ts bodyOf) */
30
+ // never empty: a body is multipart only with a file part (ir/slots.ts bodyOf)
32
31
  const decl = [
33
32
  ...lineComment(doc, "///"),
34
33
  "#[derive(Debug, Clone, Default)]",
@@ -37,7 +36,11 @@ function multipartBody(op, parts, at) {
37
36
  "}",
38
37
  ];
39
38
  at.decls.set(type, decl.join("\n"));
40
- const lines = ["let mut form = crate::body::Multipart::new();", ...fields.map((f) => f.line), "spec.multipart(form);"];
39
+ const lines = [
40
+ "let mut form = crate::body::Multipart::new();",
41
+ ...fields.map((f) => f.line),
42
+ "spec.multipart(form);",
43
+ ];
41
44
  return { lines, type: `&${type}` };
42
45
  }
43
46
  /** The body of `op` as its method takes it, and the statements encoding it into the spec at once. */
@@ -1,32 +1,30 @@
1
1
  import { type Shipped } from "../shared/metadata.ts";
2
2
  /** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
3
3
  export declare const RUST_VERSION = "1.85";
4
- /** The emitted edition, which the floor forces. */
5
- export declare const EDITION = "2024";
6
4
  /** The crate's name and version as Cargo.toml and the lock root carry them, and the metadata crates.io shows. */
7
5
  export type CrateIdentity = {
8
6
  readonly name: string;
9
7
  readonly version: string;
10
8
  /** what crates.io shows and `cargo publish` requires; left out when the caller names none */
11
- readonly description?: string;
12
- readonly documentation?: string;
13
- readonly homepage?: string;
14
- readonly keywords?: readonly string[];
15
- readonly categories?: readonly string[];
16
- readonly license?: string;
17
- readonly repository?: string;
9
+ readonly description?: string | undefined;
10
+ readonly documentation?: string | undefined;
11
+ readonly homepage?: string | undefined;
12
+ readonly keywords?: readonly string[] | undefined;
13
+ readonly categories?: readonly string[] | undefined;
14
+ readonly license?: string | undefined;
15
+ readonly repository?: string | undefined;
18
16
  };
19
17
  /** The crate options as a run gives them: a list as a list, or the CLI's comma-separated value. */
20
18
  export type CrateOptions = {
21
- readonly crateName?: string;
22
- readonly version?: string;
23
- readonly description?: string;
24
- readonly documentation?: string;
25
- readonly homepage?: string;
26
- readonly keywords?: readonly string[] | string;
27
- readonly categories?: readonly string[] | string;
28
- readonly license?: string;
29
- readonly repository?: string;
19
+ readonly crateName?: string | undefined;
20
+ readonly version?: string | undefined;
21
+ readonly description?: string | undefined;
22
+ readonly documentation?: string | undefined;
23
+ readonly homepage?: string | undefined;
24
+ readonly keywords?: readonly string[] | string | undefined;
25
+ readonly categories?: readonly string[] | string | undefined;
26
+ readonly license?: string | undefined;
27
+ readonly repository?: string | undefined;
30
28
  };
31
29
  /**
32
30
  * The crate `options` give, each value checked against the grammar every target shares and crates.io's own limits
@@ -10,12 +10,12 @@ import { checked, HTTPS_URL, LICENSE, README, SPDX_EXPRESSION, TEXT } from "../s
10
10
  /** The emitted `rust-version`: the toolchain floor every SDK builds with (Fb2). */
11
11
  export const RUST_VERSION = "1.85";
12
12
  /** The emitted edition, which the floor forces. */
13
- export const EDITION = "2024";
14
- /* a crate that ships nothing beside its code */
13
+ const EDITION = "2024";
14
+ // a crate that ships nothing beside its code
15
15
  const NONE_SHIPPED = { icon: undefined, licenseFile: false, readme: false };
16
- /* the dependency the WebSocket and realtime runtime files need, and only they */
16
+ // the dependency the WebSocket and realtime runtime files need, and only they
17
17
  const WEBSOCKET = "tokio-tungstenite";
18
- /* each dependency's requirement line, in name order: the floors are the template lock's versions */
18
+ // each dependency's requirement line, in name order: the floors are the template lock's versions
19
19
  const DEPENDENCIES = [
20
20
  ["bytes", '"1.12.1"'],
21
21
  ["futures-util", '{ version = "0.3.34", default-features = false, features = ["std", "sink"] }'],
@@ -30,17 +30,17 @@ const DEPENDENCIES = [
30
30
  ["url", '"2.5.8"'],
31
31
  ];
32
32
  const MARKER = "# @generated by clients. DO NOT EDIT.";
33
- /* a semver version: it lands inside a TOML string, so nothing else may */
33
+ // a semver version: it lands inside a TOML string, so nothing else may
34
34
  const SEMVER = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/;
35
- /* crates.io's keyword: ASCII, a letter or digit first, then letters, digits, `_`, `-` or `+`, at most 20 characters;
36
- * a category: a slug as https://crates.io/category_slugs lists them, which crates.io matches exactly; five of each */
35
+ // crates.io's keyword: ASCII, a letter or digit first, then letters, digits, `_`, `-` or `+`, at most 20 characters;
36
+ // a category: a slug as https://crates.io/category_slugs lists them, which crates.io matches exactly; five of each
37
37
  const CRATE_KEYWORD = /^[A-Za-z0-9][A-Za-z0-9_+-]{0,19}$/;
38
38
  const CATEGORY = /^[a-z0-9-]+(?:::[a-z0-9-]+)*$/;
39
39
  const MAX_LISTED = 5;
40
40
  /** A list option as a list, each entry checked against `grammar`, at most five: crates.io's limit for both lists. */
41
41
  function listed(option, value, grammar) {
42
42
  if (value === undefined)
43
- return undefined;
43
+ return;
44
44
  const list = (typeof value === "string" ? value.split(",") : value).map((word) => word.trim()).filter(Boolean);
45
45
  for (const word of list)
46
46
  checked(option, word, grammar);
@@ -102,11 +102,11 @@ export function cargoToml(crate, ws, shipped = NONE_SHIPPED) {
102
102
  `version = "${crate.version}"`,
103
103
  `edition = "${EDITION}"`,
104
104
  `rust-version = "${RUST_VERSION}"`,
105
- /* the metadata crates.io reads: each line only when the caller gave it */
105
+ // the metadata crates.io reads: each line only when the caller gave it
106
106
  ...metadata(crate),
107
107
  ...(shipped.readme ? [`readme = "${README}"`] : []),
108
- /* what the published crate holds beside Cargo.toml and its lock, which cargo always packs: its README and
109
- * license file when it ships them; clients' manifest and anything else written beside the crate stay out */
108
+ // what the published crate holds beside Cargo.toml and its lock, which cargo always packs: its README and
109
+ // license file when it ships them; clients' manifest and anything else written beside the crate stay out
110
110
  `include = ${toml(["/src", ...(shipped.readme ? [`/${README}`] : []), ...(shipped.licenseFile ? [`/${LICENSE}`] : [])])}`,
111
111
  "",
112
112
  "[lib]",
@@ -153,7 +153,7 @@ function referenced(kept, reference) {
153
153
  return kept.filter((p) => p.name === name).length > 1 ? reference : name;
154
154
  }
155
155
  /** `p`'s text with every dependency reference rewritten for `kept`. */
156
- const rewritten = (p, kept) => p.text.replace(/^ "([^"]+)",$/gm, (_, reference) => ` "${referenced(kept, reference)}",`);
156
+ const rewritten = (p, kept) => p.text.replaceAll(/^ "([^"]+)",$/gm, (_, reference) => ` "${referenced(kept, reference)}",`);
157
157
  /** The root entry as `crate`, without `tokio-tungstenite` unless `ws`. */
158
158
  function rootOf(root, crate, ws) {
159
159
  const named = root.text
@@ -8,8 +8,8 @@
8
8
  */
9
9
  import type { IR } from "../../ir/model.ts";
10
10
  import type { SdkOp } from "../../ir/sdk-model.ts";
11
- import type { RustCallPlan } from "./sdk-plan.ts";
12
11
  import { type MethodEnv } from "./sdk-method.ts";
12
+ import type { RustCallPlan } from "./sdk-plan.ts";
13
13
  /** The method env, the operations by id, and the notices the generation reports (a root member renamed for the mirror). */
14
14
  export type ClientEnv = MethodEnv & {
15
15
  readonly ops: ReadonlyMap<string, SdkOp>;
@@ -4,7 +4,7 @@ import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../s
4
4
  import { MIRROR, mirrorNotice } from "../shared/mirror.js";
5
5
  import { rustMethod } from "./sdk-method.js";
6
6
  import { STYLE } from "./types-names.js";
7
- /* the runtime's own associated functions on `Client`, the mirror among them: no operation takes their name */
7
+ // the runtime's own associated functions on `Client`, the mirror among them: no operation takes their name
8
8
  const CLIENT_FNS = ["build", "new", MIRROR];
9
9
  /** A member's name in `scope`; at the root (`path` empty) one spelled like the mirror is `safe_` instead, and noticed. */
10
10
  function memberName(segment, path, scope, env) {
@@ -22,7 +22,7 @@ function resourceOf(ns, path, type, env) {
22
22
  const children = namespacesOf(ns).map(([segment, child]) => {
23
23
  const accessor = memberName(segment, path, scope, env);
24
24
  const childPath = [...path, segment];
25
- /* the type rule over the whole name: a leading digit gets its guard, and `self` stays `SelfResource` */
25
+ // the type rule over the whole name: a leading digit gets its guard, and `self` stays `SelfResource`
26
26
  const childType = env.at.names.claim(rustTypeIdent([...childPath, "Resource"].join(".")));
27
27
  return { accessor, node: resourceOf(child, childPath, childType, env) };
28
28
  });
@@ -42,7 +42,7 @@ function accessorBlocks(node, lifetime, client) {
42
42
  const members = (blocks) => blocks.map((lines) => lines.join("\n")).join("\n\n");
43
43
  /** Each namespace below the client: its type, its accessors and methods, then its children's. */
44
44
  function resourceLines(node) {
45
- /* the lifetime is named only where an accessor hands it on */
45
+ // the lifetime is named only where an accessor hands it on
46
46
  const head = node.children.length > 0
47
47
  ? `impl<'a, ${STYLE}: Style> ${node.type}<'a, ${STYLE}> {`
48
48
  : `impl<${STYLE}: Style> ${node.type}<'_, ${STYLE}> {`;
@@ -1,3 +1,13 @@
1
+ /**
2
+ * One operation as a Rust method (G1, Fb1): `(&self, <path params as &str in path order>, <body>?, opts:
3
+ * &<Op>Opts) -> Call<T, S[, <Op>Headers]>`, `S` the client's style (bit 21 i4: `Throw` on the normal client,
4
+ * `Safe` on `client.safe()`, one method for both). The method copies everything into the runtime's
5
+ * `RequestSpec` up front (the body encoded at once) and hands it to `Call` with the run that reads its answer:
6
+ * JSON as its type, none as `()`, text as `String`, binary as `Vec<u8>`; a stream answers as sse.ts, ws.ts and
7
+ * realtime.ts say, an SSE stream in its style, a WebSocket or realtime connection the same on both clients.
8
+ * Spec text reaches the source only through the shared escape layer.
9
+ */
10
+ import type { InvalidatedRead } from "../../ir/invalidate-reads.ts";
1
11
  import { type SdkOp } from "../../ir/sdk-model.ts";
2
12
  import type { RustCallPlan } from "./sdk-plan.ts";
3
13
  import type { RustTypeContext } from "./types.ts";
@@ -7,9 +17,10 @@ export type RustMethod = {
7
17
  readonly decls: readonly (readonly [string, string])[];
8
18
  readonly lines: readonly string[];
9
19
  };
10
- /** What every method of one SDK shares: the type context it hoists into. */
20
+ /** The type context it hoists into, and each write's reads by operationId (`invalidateReads`): its event's targets. */
11
21
  export type MethodEnv = {
12
22
  readonly at: RustTypeContext;
23
+ readonly reads: ReadonlyMap<string, readonly InvalidatedRead[]>;
13
24
  };
14
25
  /** The method of `op` named `name`, its client reached as `client` (`self`, `self.client`), and its `<Op>Opts` and `<Op>Headers`. */
15
26
  export declare function rustMethod(op: SdkOp, name: string, client: string, env: MethodEnv): RustMethod;
@@ -1,13 +1,13 @@
1
1
  import { mediaEssence } from "../../ir/sdk-model.js";
2
2
  import { lineComment, rustString } from "../shared/escape.js";
3
3
  import { NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
4
+ import { realtimeAnswer } from "./realtime.js";
4
5
  import { rustBody, typeAt } from "./sdk-body.js";
5
6
  import { optsDecl, optsFields, optsLines, responseHeaders, takesIdempotencyKey, } from "./sdk-opts.js";
6
- import { realtimeAnswer } from "./realtime.js";
7
7
  import { sseAnswer } from "./sse.js";
8
8
  import { STYLE } from "./types-names.js";
9
9
  import { wsAnswer } from "./ws.js";
10
- /* the method's own locals: a path param never shadows one (it is claimed as `…2`) */
10
+ // the method's own locals: a path param never shadows one (it is claimed as `…2`)
11
11
  const METHOD_LOCALS = ["body", "client", "form", "opts", "spec"];
12
12
  /** How a stream operation answers. */
13
13
  function streamAnswer(op, at) {
@@ -62,6 +62,13 @@ function specLines(op, fields, answer, body) {
62
62
  ...(op.invalidates.length > 0 ? [`spec.invalidates(&[${op.invalidates.map(rustString).join(", ")}]);`] : []),
63
63
  ];
64
64
  }
65
+ /** The `spec.reads` statement of a write whose success stales `reads`: its operationId and each read's own params. */
66
+ function readsLines(op, reads) {
67
+ if (reads === undefined || reads.length === 0)
68
+ return [];
69
+ const each = reads.map((read) => `(${rustString(read.operationId)}, &[${read.params.map(rustString).join(", ")}])`);
70
+ return [`spec.reads(${rustString(op.id)}, &[${each.join(", ")}]);`];
71
+ }
65
72
  /** The method's lines: its signature over `client`, the spec it fills, the `Call` it returns. */
66
73
  function methodLines(parts, client, answer, body) {
67
74
  const { fields, headers, op, opts, path } = parts;
@@ -73,7 +80,7 @@ function methodLines(parts, client, answer, body) {
73
80
  `${empty ? "_opts" : "opts"}: &${opts}`,
74
81
  ];
75
82
  const bound = path.map(([param, local]) => `(${rustString(param.name)}, ${local})`).join(", ");
76
- const statements = specLines(op, fields, answer, body?.lines ?? []);
83
+ const statements = [...specLines(op, fields, answer, body?.lines ?? []), ...parts.reads];
77
84
  const returns = callType(op, answer, headers);
78
85
  return [
79
86
  ...(params.length > 7 ? [" #[allow(clippy::too_many_arguments)]"] : []),
@@ -111,7 +118,8 @@ export function rustMethod(op, name, client, env) {
111
118
  const body = op.body && rustBody(op, op.body, env.at);
112
119
  const answer = answerOf(op, env);
113
120
  const fields = optsFields(op, opts, env.at, answer.stream);
114
- const parts = { fields, headers: responseHeaders(op, env.at), name, op, opts, path };
121
+ const reads = readsLines(op, env.reads.get(op.id));
122
+ const parts = { fields, headers: responseHeaders(op, env.at), name, op, opts, path, reads };
115
123
  const decls = [[opts, optsDecl(op, opts, fields, answer.stream)]];
116
124
  if (parts.headers)
117
125
  decls.push([parts.headers.plan.type, parts.headers.decl]);
@@ -13,7 +13,7 @@ export type OptsField = {
13
13
  readonly bare: boolean;
14
14
  };
15
15
  /** A stream's own `<Op>Opts` field, after the declared ones. */
16
- export type StreamField = {
16
+ type StreamField = {
17
17
  readonly ident: string;
18
18
  readonly type: string;
19
19
  readonly doc?: string;
@@ -56,3 +56,4 @@ export declare function responseHeaders(op: SdkOp, at: RustTypeContext): {
56
56
  readonly plan: RustResponseHeaders;
57
57
  readonly decl: string;
58
58
  } | null;
59
+ export {};
@@ -2,7 +2,7 @@ import { lineComment, rustString } from "../shared/escape.js";
2
2
  import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
3
3
  import { unboxed } from "./types-struct.js";
4
4
  import { rustTypeOf } from "./types.js";
5
- /* the Opts field an idempotent operation's caller sets its Idempotency-Key through */
5
+ // the Opts field an idempotent operation's caller sets its Idempotency-Key through
6
6
  const IDEMPOTENCY_KEY = "idempotency_key";
7
7
  const isStringConst = (s) => s.kind === "const" && typeof s.value === "string";
8
8
  /** Whether the type `schema` declares as a component has a `Default`: a struct, a newtype and a payload enum do not. */
@@ -77,7 +77,7 @@ function declaredHeaders(op) {
77
77
  .filter((status) => /^2(?:\d\d|XX)$/i.test(status))
78
78
  .sort(compareCodeUnits)
79
79
  .flatMap((status) => op.ir.responses[status].headers ?? []);
80
- /* reversed, so the first spelling of a name is the one its key ends on */
80
+ // reversed, so the first spelling of a name is the one its key ends on
81
81
  const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
82
82
  return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
83
83
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +1,5 @@
1
- import { type CrateOptions } from "./sdk-cargo.ts";
2
1
  import { type PackageIdentity, type Shipped } from "../shared/metadata.ts";
2
+ import { type CrateOptions } from "./sdk-cargo.ts";
3
3
  import type { RustCallPlan } from "./sdk-plan.ts";
4
4
  /**
5
5
  * The crate's options: its name (`http-sdk` by default), version (`0.1.0` by default) and what crates.io shows,
@@ -7,17 +7,18 @@
7
7
  * Every `.rs` file carries the generated-code marker.
8
8
  */
9
9
  import { toIR } from "../../ir/build.js";
10
+ import { invalidateReads } from "../../ir/invalidate-reads.js";
10
11
  import { sdkModel } from "../../ir/sdk-model.js";
11
12
  import { lineComment } from "../shared/escape.js";
12
13
  import { compareCodeUnits, rustTypeIdent } from "../shared/lang.js";
14
+ import { packageOn } from "../shared/metadata.js";
13
15
  import { renameNotice } from "../shared/mirror.js";
14
16
  import { rustErrorKeys } from "./errors.js";
15
17
  import { needsWebSocket, publicItems, runtimeFiles } from "./http.js";
16
18
  import { cargoLock, cargoToml, crateIdentity } from "./sdk-cargo.js";
17
- import { packageOn } from "../shared/metadata.js";
18
19
  import { clientDecls } from "./sdk-client.js";
19
20
  import { rustTopLevel, rustTypeContext } from "./types.js";
20
- /* the marker rustfmt and linguist read */
21
+ // the marker rustfmt and linguist read
21
22
  const MARKER = "// @generated by clients. DO NOT EDIT.";
22
23
  /** Each component's declaration in code-unit order, its description as its rustdoc. */
23
24
  function componentDecls(ir, at) {
@@ -64,17 +65,19 @@ function emitRust(document, options, shipped) {
64
65
  const ir = toIR(document, { deriveOperationIds: true });
65
66
  const model = sdkModel(ir);
66
67
  const at = rustTypeContext(ir);
67
- /* components first: the client's hoisted types then land beside them */
68
+ // components first: the client's hoisted types then land beside them
68
69
  const components = componentDecls(ir, at);
69
- /* every component emitted under another name is noticed, as the mirror's rename is */
70
+ // every component emitted under another name is noticed, as the mirror's rename is
70
71
  const notices = [...at.names.renamed].map(([name, emitted]) => renameNotice("rust", {
71
72
  because: `"${rustTypeIdent(name)}" is a name the SDK's crate root or the Rust prelude holds`,
72
73
  name,
73
74
  renamed: emitted,
74
75
  what: "component",
75
76
  }));
76
- const client = clientDecls(ir, { at, notices, ops: model.opsById });
77
- /* before the hoisted are read: each key's <Key>Data lands among them; an API without operations answers no error */
77
+ const { reads, warnings } = invalidateReads(ir);
78
+ const client = clientDecls(ir, { at, notices, ops: model.opsById, reads });
79
+ notices.push(...warnings.map((warning) => `rust: ${warning}`));
80
+ // before the hoisted are read: each key's <Key>Data lands among them; an API without operations answers no error
78
81
  const errorKeys = model.ops.length > 0 ? [rustErrorKeys(model, at)] : [];
79
82
  const hoisted = [...at.decls].sort(([a], [b]) => compareCodeUnits(a, b)).map(([, decl]) => decl);
80
83
  const features = {
@@ -10,11 +10,6 @@ import type { IRSchema } from "../../ir/model.ts";
10
10
  import { type SdkOp } from "../../ir/sdk-model.ts";
11
11
  import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
12
12
  import type { RustTypeContext } from "./types.ts";
13
- /** The resume cursor's id, which the SSE and realtime Opts carry. */
14
- export declare const LAST_EVENT_ID: {
15
- ident: string;
16
- type: string;
17
- };
18
13
  /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
19
14
  export declare const isLastEventIdHeader: (param: string, where: OptsField["in"]) => boolean;
20
15
  /** The type of the events `op` declares as `events`. */
@@ -4,12 +4,12 @@ import { NameScope, rustTypeIdent } from "../shared/lang.js";
4
4
  import { typeAt } from "./sdk-body.js";
5
5
  import { variantOf } from "./types-enum.js";
6
6
  /** The resume cursor's id, which the SSE and realtime Opts carry. */
7
- export const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
7
+ const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
8
8
  /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
9
9
  export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
10
10
  /** The type of the events `op` declares as `events`. */
11
11
  export const eventType = (op, events, at) => typeAt(events, op.id, "Event", at);
12
- /* Last-Event-ID, sent only when set: an empty cursor names no position */
12
+ // Last-Event-ID, sent only when set: an empty cursor names no position
13
13
  const SSE = {
14
14
  carries: isLastEventIdHeader,
15
15
  fields: [LAST_EVENT_ID],
@@ -14,7 +14,7 @@ function runtimeIdentifiers() {
14
14
  }
15
15
  /** The style parameter every resource and its methods' `Call` take (bit 21 i4): no type may be named it. */
16
16
  export const STYLE = "S";
17
- /* the crate-root types the emitter itself declares beside the runtime's (errors.ts's enum), and the style parameter */
17
+ // the crate-root types the emitter itself declares beside the runtime's (errors.ts's enum), and the style parameter
18
18
  const EMITTED = ["ErrorKey", STYLE];
19
19
  /** Names for one schema on its own: each as asked for, no cycles, refs left unresolved. */
20
20
  export function plainNames() {
@@ -22,8 +22,8 @@ export function plainNames() {
22
22
  claim: (base) => base,
23
23
  cyclic: new Set(),
24
24
  hoist: (_key, base) => base,
25
- renamed: new Map(),
26
25
  ref: rustTypeIdent,
26
+ renamed: new Map(),
27
27
  resolve: (schema) => schema,
28
28
  };
29
29
  }
@@ -45,7 +45,7 @@ export function irNames(ir) {
45
45
  if (taken)
46
46
  renamed.set(name, claimed);
47
47
  }
48
- /* a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on */
48
+ // a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on
49
49
  const claim = (base) => {
50
50
  const name = scope.claim(base);
51
51
  return isRustPreludeType(name) ? scope.claim(base) : name;
@@ -2,7 +2,7 @@ import { rustString } from "../shared/escape.js";
2
2
  import { compareCodeUnits, NameScope, rustValueIdent } from "../shared/lang.js";
3
3
  export const DERIVE = "#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]";
4
4
  const SKIP = 'skip_serializing_if = "Option::is_none"';
5
- /* absent, null and a value: `default` for absent, the runtime's deserializer keeping null as Some(None) */
5
+ // absent, null and a value: `default` for absent, the runtime's deserializer keeping null as Some(None)
6
6
  const TRI_STATE = ["default", 'deserialize_with = "crate::nullable::deserialize"', SKIP];
7
7
  /** A field's lines: its serde keys in one attribute when it has any, then `pub <ident>: <type>,`. */
8
8
  const fieldLines = ({ ident, type, serde }) => [
@@ -12,7 +12,7 @@ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
12
12
  kind: K;
13
13
  }>;
14
14
  /** Declares `schema` once under `names.hoist(key, base)`; its name. */
15
- export type Declare = (schema: IRSchema, key: string, base: string) => string;
15
+ type Declare = (schema: IRSchema, key: string, base: string) => string;
16
16
  /** What a union's declaration reaches: the names, its members' types, and the hoist. */
17
17
  export type UnionScope = {
18
18
  names: RustTypeNames;
@@ -5,7 +5,7 @@ import { allOfDecl, DERIVE, objectDecl, unboxed } from "./types-struct.js";
5
5
  import { unionDecl, unionVariants } from "./types-union.js";
6
6
  const VALUE = "serde_json::Value";
7
7
  const MAP = "std::collections::HashMap";
8
- /* deeper than this, a schema is any JSON value */
8
+ // deeper than this, a schema is any JSON value
9
9
  const MAX_DEPTH = 12;
10
10
  const SCALARS = {
11
11
  boolean: "bool",
@@ -22,7 +22,7 @@ export function rustTypeContext(ir) {
22
22
  export function rustHoisted(ir, at, key, base) {
23
23
  const name = at.names.hoist(key, base);
24
24
  if (!at.decls.has(name)) {
25
- /* claimed before its body: what the body hoists in turn comes after it */
25
+ // claimed before its body: what the body hoists in turn comes after it
26
26
  at.decls.set(name, "");
27
27
  at.decls.set(name, rustTopLevel(name, ir, at));
28
28
  }
@@ -33,7 +33,9 @@ const hoist = (ir, at) => rustHoisted(ir, at, `${at.parentName}.${at.fieldName}`
33
33
  const deeper = (at, fieldName = at.fieldName) => ({ ...at, depth: at.depth + 1, fieldName });
34
34
  /** Whether a scalar is a string or integer enum with a value of its kind: a declared enum. */
35
35
  const isEnum = (ir) => ir.enum !== undefined &&
36
- (ir.type === "string" ? stringValues(ir.enum).length > 0 : ir.type === "integer" && integerValues(ir.enum).length > 0);
36
+ (ir.type === "string"
37
+ ? stringValues(ir.enum).length > 0
38
+ : ir.type === "integer" && integerValues(ir.enum).length > 0);
37
39
  /** A const's Rust type: its value's, a declared `number` making an integral value f64. */
38
40
  function constType({ type, value }) {
39
41
  if (typeof value === "number")
@@ -70,7 +72,7 @@ const USES = {
70
72
  ref: refUse,
71
73
  scalar: (ir, at) => (isEnum(ir) ? hoist(ir, at) : SCALARS[ir.type]),
72
74
  tuple: () => `Vec<${VALUE}>`,
73
- /* a union in use position is any JSON value; a component union is declared as an enum */
75
+ // a union in use position is any JSON value; a component union is declared as an enum
74
76
  union: () => VALUE,
75
77
  unknown: () => VALUE,
76
78
  };
@@ -102,7 +104,7 @@ export function rustTopLevel(name, ir, at) {
102
104
  return [DERIVE, `pub struct ${name}(pub ${constType(ir)});`].join("\n");
103
105
  if (ir.kind === "allOf")
104
106
  return allOfDecl(name, ir, member, at.names.ref);
105
- /* a closed object without fields is a struct too: `{}` on the wire, where a map alias would admit any key */
107
+ // a closed object without fields is a struct too: `{}` on the wire, where a map alias would admit any key
106
108
  if (ir.kind === "object" && (ir.fields.length > 0 || ir.additional === false))
107
109
  return objectDecl(name, ir, member);
108
110
  if (ir.kind === "union" && ir.variants.length > 0)
@@ -10,17 +10,6 @@ import type { IRSchema } from "../../ir/model.ts";
10
10
  import { type SdkOp } from "../../ir/sdk-model.ts";
11
11
  import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
12
12
  import { type RustTypeContext } from "./types.ts";
13
- /** The resume cursor's token, which the WebSocket and realtime Opts carry. */
14
- export declare const RECONNECT_TOKEN: {
15
- ident: string;
16
- type: string;
17
- };
18
- /** The subprotocols a WebSocket or realtime dial offers. */
19
- export declare const PROTOCOLS: {
20
- doc: string;
21
- ident: string;
22
- type: string;
23
- };
24
13
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
25
14
  export declare const isReconnectToken: (param: string, where: OptsField["in"]) => boolean;
26
15
  /** One direction of `op`'s messages as its Rust type: an inline union is declared as `<Op><side>`. */
@@ -4,12 +4,12 @@ import { NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
4
4
  import { typeAt } from "./sdk-body.js";
5
5
  import { rustHoisted, rustUnionVariants } from "./types.js";
6
6
  /** The resume cursor's token, which the WebSocket and realtime Opts carry. */
7
- export const RECONNECT_TOKEN = { ident: "reconnect_token", type: "Option<String>" };
7
+ const RECONNECT_TOKEN = { ident: "reconnect_token", type: "Option<String>" };
8
8
  /** The subprotocols a WebSocket or realtime dial offers. */
9
- export const PROTOCOLS = { doc: "The subprotocols the dial offers.", ident: "protocols", type: "Vec<String>" };
9
+ const PROTOCOLS = { doc: "The subprotocols the dial offers.", ident: "protocols", type: "Vec<String>" };
10
10
  /** Whether a declared param is the `reconnect_token` query param, the resume channel a socket dial sends. */
11
11
  export const isReconnectToken = (param, where) => where === "query" && param === "reconnect_token";
12
- /* reconnect_token, sent only when set: an empty cursor names no position */
12
+ // reconnect_token, sent only when set: an empty cursor names no position
13
13
  const WS = {
14
14
  carries: isReconnectToken,
15
15
  fields: [RECONNECT_TOKEN, PROTOCOLS],
@@ -54,7 +54,7 @@ export function valueHandlers(base, handlers, read, at) {
54
54
  }
55
55
  /** The type params of a socket reading `read` and sending `write`, the defaults left out. */
56
56
  export const typeParams = (read, write, untyped) => write === undefined ? (read === undefined ? "" : `<${read}>`) : `<${read ?? untyped}, ${write}>`;
57
- /* the handlers a socket takes: a member whose on_<value> one of them names gets none */
57
+ // the handlers a socket takes: a member whose on_<value> one of them names gets none
58
58
  const HANDLERS = ["on_message", "on_close", "on_error"];
59
59
  /** The WebSocket operation `op`'s answer, its message types hoisted into `at`. */
60
60
  export function wsAnswer(op, at) {
@@ -64,7 +64,7 @@ export function wsAnswer(op, at) {
64
64
  if (send !== undefined && read !== undefined)
65
65
  valueHandlers("TypedWebSocket", HANDLERS, { schema: send, type: read }, at);
66
66
  const params = typeParams(read, write, "Vec<u8>");
67
- /* the answer type fixes both params: a socket without a read type reads bytes */
67
+ // the answer type fixes both params: a socket without a read type reads bytes
68
68
  const run = `crate::ws::${read === undefined ? "dial" : "typed"}(opts.protocols.clone())`;
69
69
  return { doc: DOC, run, stream: WS, type: `TypedWebSocket${params}` };
70
70
  }