@workerstack/clients 0.0.0-stage → 1.0.0-rc.23

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 (558) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +619 -2
  3. package/bin/honey-clients.js +94 -0
  4. package/dist/cli.d.ts +102 -0
  5. package/dist/cli.js +190 -0
  6. package/dist/emit/cli/channels.d.ts +73 -0
  7. package/dist/emit/cli/channels.js +197 -0
  8. package/dist/emit/cli/commands.d.ts +27 -0
  9. package/dist/emit/cli/commands.js +187 -0
  10. package/dist/emit/cli/discovery.d.ts +35 -0
  11. package/dist/emit/cli/discovery.js +202 -0
  12. package/dist/emit/cli/flags.d.ts +59 -0
  13. package/dist/emit/cli/flags.js +186 -0
  14. package/dist/emit/cli/index.d.ts +1 -0
  15. package/dist/emit/cli/index.js +1 -0
  16. package/dist/emit/cli/install.d.ts +37 -0
  17. package/dist/emit/cli/install.js +88 -0
  18. package/dist/emit/cli/layout.d.ts +23 -0
  19. package/dist/emit/cli/layout.js +118 -0
  20. package/dist/emit/cli/module.d.ts +30 -0
  21. package/dist/emit/cli/module.js +186 -0
  22. package/dist/emit/cli/release.d.ts +40 -0
  23. package/dist/emit/cli/release.js +183 -0
  24. package/dist/emit/cli/skills.d.ts +11 -0
  25. package/dist/emit/cli/skills.js +56 -0
  26. package/dist/emit/csharp/errors.d.ts +7 -0
  27. package/dist/emit/csharp/errors.js +69 -0
  28. package/dist/emit/csharp/index.d.ts +1 -0
  29. package/dist/emit/csharp/index.js +1 -0
  30. package/dist/emit/csharp/json.d.ts +13 -0
  31. package/dist/emit/csharp/json.js +113 -0
  32. package/dist/emit/csharp/realtime.d.ts +10 -0
  33. package/dist/emit/csharp/realtime.js +33 -0
  34. package/dist/emit/csharp/sdk-answer.d.ts +48 -0
  35. package/dist/emit/csharp/sdk-answer.js +85 -0
  36. package/dist/emit/csharp/sdk-body.d.ts +10 -0
  37. package/dist/emit/csharp/sdk-body.js +87 -0
  38. package/dist/emit/csharp/sdk-client.d.ts +32 -0
  39. package/dist/emit/csharp/sdk-client.js +177 -0
  40. package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
  41. package/dist/emit/csharp/sdk-csproj.js +136 -0
  42. package/dist/emit/csharp/sdk-doc.d.ts +12 -0
  43. package/dist/emit/csharp/sdk-doc.js +35 -0
  44. package/dist/emit/csharp/sdk-method.d.ts +26 -0
  45. package/dist/emit/csharp/sdk-method.js +187 -0
  46. package/dist/emit/csharp/sdk-plan.d.ts +38 -0
  47. package/dist/emit/csharp/sdk-plan.js +1 -0
  48. package/dist/emit/csharp/sdk.d.ts +40 -0
  49. package/dist/emit/csharp/sdk.js +105 -0
  50. package/dist/emit/csharp/sse.d.ts +18 -0
  51. package/dist/emit/csharp/sse.js +29 -0
  52. package/dist/emit/csharp/transport.d.ts +11 -0
  53. package/dist/emit/csharp/transport.js +67 -0
  54. package/dist/emit/csharp/types-enum.d.ts +19 -0
  55. package/dist/emit/csharp/types-enum.js +63 -0
  56. package/dist/emit/csharp/types-names.d.ts +33 -0
  57. package/dist/emit/csharp/types-names.js +182 -0
  58. package/dist/emit/csharp/types-record.d.ts +25 -0
  59. package/dist/emit/csharp/types-record.js +65 -0
  60. package/dist/emit/csharp/types-union.d.ts +27 -0
  61. package/dist/emit/csharp/types-union.js +113 -0
  62. package/dist/emit/csharp/types.d.ts +36 -0
  63. package/dist/emit/csharp/types.js +126 -0
  64. package/dist/emit/csharp/ws.d.ts +20 -0
  65. package/dist/emit/csharp/ws.js +14 -0
  66. package/dist/emit/go/errors.d.ts +7 -0
  67. package/dist/emit/go/errors.js +44 -0
  68. package/dist/emit/go/http.d.ts +11 -0
  69. package/dist/emit/go/http.js +50 -0
  70. package/dist/emit/go/index.d.ts +1 -0
  71. package/dist/emit/go/index.js +1 -0
  72. package/dist/emit/go/module-path.d.ts +2 -0
  73. package/dist/emit/go/module-path.js +27 -0
  74. package/dist/emit/go/sdk-answer.d.ts +28 -0
  75. package/dist/emit/go/sdk-answer.js +41 -0
  76. package/dist/emit/go/sdk-body.d.ts +24 -0
  77. package/dist/emit/go/sdk-body.js +76 -0
  78. package/dist/emit/go/sdk-client.d.ts +29 -0
  79. package/dist/emit/go/sdk-client.js +141 -0
  80. package/dist/emit/go/sdk-method.d.ts +68 -0
  81. package/dist/emit/go/sdk-method.js +172 -0
  82. package/dist/emit/go/sdk-mirror.d.ts +23 -0
  83. package/dist/emit/go/sdk-mirror.js +97 -0
  84. package/dist/emit/go/sdk-opts.d.ts +55 -0
  85. package/dist/emit/go/sdk-opts.js +100 -0
  86. package/dist/emit/go/sdk.d.ts +26 -0
  87. package/dist/emit/go/sdk.js +111 -0
  88. package/dist/emit/go/sse.d.ts +16 -0
  89. package/dist/emit/go/sse.js +26 -0
  90. package/dist/emit/go/types-codec.d.ts +15 -0
  91. package/dist/emit/go/types-codec.js +171 -0
  92. package/dist/emit/go/types-names.d.ts +14 -0
  93. package/dist/emit/go/types-names.js +64 -0
  94. package/dist/emit/go/types-struct.d.ts +29 -0
  95. package/dist/emit/go/types-struct.js +65 -0
  96. package/dist/emit/go/types-union.d.ts +17 -0
  97. package/dist/emit/go/types-union.js +84 -0
  98. package/dist/emit/go/types.d.ts +32 -0
  99. package/dist/emit/go/types.js +177 -0
  100. package/dist/emit/go/ws.d.ts +12 -0
  101. package/dist/emit/go/ws.js +70 -0
  102. package/dist/emit/java/gradle.d.ts +57 -0
  103. package/dist/emit/java/gradle.js +221 -0
  104. package/dist/emit/java/index.d.ts +2 -0
  105. package/dist/emit/java/index.js +2 -0
  106. package/dist/emit/java/json.d.ts +13 -0
  107. package/dist/emit/java/json.js +84 -0
  108. package/dist/emit/java/layout-ast.d.ts +146 -0
  109. package/dist/emit/java/layout-ast.js +102 -0
  110. package/dist/emit/java/layout-decl.d.ts +20 -0
  111. package/dist/emit/java/layout-decl.js +155 -0
  112. package/dist/emit/java/layout-doc.d.ts +55 -0
  113. package/dist/emit/java/layout-doc.js +166 -0
  114. package/dist/emit/java/layout-dot.d.ts +18 -0
  115. package/dist/emit/java/layout-dot.js +127 -0
  116. package/dist/emit/java/layout-strings.d.ts +8 -0
  117. package/dist/emit/java/layout-strings.js +76 -0
  118. package/dist/emit/java/layout-types.d.ts +11 -0
  119. package/dist/emit/java/layout-types.js +95 -0
  120. package/dist/emit/java/layout-visitor.d.ts +38 -0
  121. package/dist/emit/java/layout-visitor.js +232 -0
  122. package/dist/emit/java/layout.d.ts +61 -0
  123. package/dist/emit/java/layout.js +121 -0
  124. package/dist/emit/java/models-enum.d.ts +17 -0
  125. package/dist/emit/java/models-enum.js +51 -0
  126. package/dist/emit/java/models-names.d.ts +29 -0
  127. package/dist/emit/java/models-names.js +97 -0
  128. package/dist/emit/java/models-record.d.ts +24 -0
  129. package/dist/emit/java/models-record.js +79 -0
  130. package/dist/emit/java/models-union.d.ts +27 -0
  131. package/dist/emit/java/models-union.js +86 -0
  132. package/dist/emit/java/models.d.ts +28 -0
  133. package/dist/emit/java/models.js +118 -0
  134. package/dist/emit/java/realtime.d.ts +50 -0
  135. package/dist/emit/java/realtime.js +69 -0
  136. package/dist/emit/java/sdk-client.d.ts +66 -0
  137. package/dist/emit/java/sdk-client.js +207 -0
  138. package/dist/emit/java/sdk-decl.d.ts +11 -0
  139. package/dist/emit/java/sdk-decl.js +63 -0
  140. package/dist/emit/java/sdk-errors.d.ts +13 -0
  141. package/dist/emit/java/sdk-errors.js +141 -0
  142. package/dist/emit/java/sdk-headers.d.ts +12 -0
  143. package/dist/emit/java/sdk-headers.js +74 -0
  144. package/dist/emit/java/sdk-mirror.d.ts +14 -0
  145. package/dist/emit/java/sdk-mirror.js +107 -0
  146. package/dist/emit/java/sdk-models.d.ts +16 -0
  147. package/dist/emit/java/sdk-models.js +68 -0
  148. package/dist/emit/java/sdk-op.d.ts +57 -0
  149. package/dist/emit/java/sdk-op.js +216 -0
  150. package/dist/emit/java/sdk-params.d.ts +38 -0
  151. package/dist/emit/java/sdk-params.js +133 -0
  152. package/dist/emit/java/sdk-plan.d.ts +52 -0
  153. package/dist/emit/java/sdk-plan.js +1 -0
  154. package/dist/emit/java/sdk-record.d.ts +16 -0
  155. package/dist/emit/java/sdk-record.js +99 -0
  156. package/dist/emit/java/sdk.d.ts +49 -0
  157. package/dist/emit/java/sdk.js +216 -0
  158. package/dist/emit/java/sse.d.ts +35 -0
  159. package/dist/emit/java/sse.js +57 -0
  160. package/dist/emit/java/ws.d.ts +27 -0
  161. package/dist/emit/java/ws.js +31 -0
  162. package/dist/emit/mcp/annotations.d.ts +15 -0
  163. package/dist/emit/mcp/annotations.js +15 -0
  164. package/dist/emit/mcp/files.d.ts +18 -0
  165. package/dist/emit/mcp/files.js +42 -0
  166. package/dist/emit/mcp/index.d.ts +3 -0
  167. package/dist/emit/mcp/index.js +3 -0
  168. package/dist/emit/mcp/literal.d.ts +2 -0
  169. package/dist/emit/mcp/literal.js +33 -0
  170. package/dist/emit/mcp/mounted.d.ts +21 -0
  171. package/dist/emit/mcp/mounted.js +89 -0
  172. package/dist/emit/mcp/output-schema.d.ts +18 -0
  173. package/dist/emit/mcp/output-schema.js +38 -0
  174. package/dist/emit/mcp/registry.d.ts +23 -0
  175. package/dist/emit/mcp/registry.js +83 -0
  176. package/dist/emit/mcp/runtime.d.ts +10 -0
  177. package/dist/emit/mcp/runtime.js +47 -0
  178. package/dist/emit/mcp/schema.d.ts +19 -0
  179. package/dist/emit/mcp/schema.js +88 -0
  180. package/dist/emit/mcp/server.d.ts +30 -0
  181. package/dist/emit/mcp/server.js +246 -0
  182. package/dist/emit/mcp/tools.d.ts +51 -0
  183. package/dist/emit/mcp/tools.js +153 -0
  184. package/dist/emit/python/errors.d.ts +8 -0
  185. package/dist/emit/python/errors.js +68 -0
  186. package/dist/emit/python/index.d.ts +1 -0
  187. package/dist/emit/python/index.js +1 -0
  188. package/dist/emit/python/realtime.d.ts +10 -0
  189. package/dist/emit/python/realtime.js +33 -0
  190. package/dist/emit/python/sdk-answer.d.ts +49 -0
  191. package/dist/emit/python/sdk-answer.js +89 -0
  192. package/dist/emit/python/sdk-body.d.ts +11 -0
  193. package/dist/emit/python/sdk-body.js +40 -0
  194. package/dist/emit/python/sdk-client.d.ts +36 -0
  195. package/dist/emit/python/sdk-client.js +163 -0
  196. package/dist/emit/python/sdk-doc.d.ts +9 -0
  197. package/dist/emit/python/sdk-doc.js +32 -0
  198. package/dist/emit/python/sdk-imports.d.ts +14 -0
  199. package/dist/emit/python/sdk-imports.js +38 -0
  200. package/dist/emit/python/sdk-method.d.ts +29 -0
  201. package/dist/emit/python/sdk-method.js +183 -0
  202. package/dist/emit/python/sdk-plan.d.ts +33 -0
  203. package/dist/emit/python/sdk-plan.js +1 -0
  204. package/dist/emit/python/sdk-pyproject.d.ts +27 -0
  205. package/dist/emit/python/sdk-pyproject.js +103 -0
  206. package/dist/emit/python/sdk.d.ts +22 -0
  207. package/dist/emit/python/sdk.js +154 -0
  208. package/dist/emit/python/sse.d.ts +12 -0
  209. package/dist/emit/python/sse.js +23 -0
  210. package/dist/emit/python/transport.d.ts +15 -0
  211. package/dist/emit/python/transport.js +60 -0
  212. package/dist/emit/python/types-dict.d.ts +31 -0
  213. package/dist/emit/python/types-dict.js +45 -0
  214. package/dist/emit/python/types-names.d.ts +16 -0
  215. package/dist/emit/python/types-names.js +52 -0
  216. package/dist/emit/python/types-union.d.ts +32 -0
  217. package/dist/emit/python/types-union.js +46 -0
  218. package/dist/emit/python/types.d.ts +36 -0
  219. package/dist/emit/python/types.js +128 -0
  220. package/dist/emit/python/ws.d.ts +14 -0
  221. package/dist/emit/python/ws.js +16 -0
  222. package/dist/emit/rust/errors.d.ts +7 -0
  223. package/dist/emit/rust/errors.js +107 -0
  224. package/dist/emit/rust/http.d.ts +13 -0
  225. package/dist/emit/rust/http.js +67 -0
  226. package/dist/emit/rust/index.d.ts +1 -0
  227. package/dist/emit/rust/index.js +1 -0
  228. package/dist/emit/rust/realtime.d.ts +11 -0
  229. package/dist/emit/rust/realtime.js +29 -0
  230. package/dist/emit/rust/sdk-body.d.ts +19 -0
  231. package/dist/emit/rust/sdk-body.js +53 -0
  232. package/dist/emit/rust/sdk-cargo.d.ts +43 -0
  233. package/dist/emit/rust/sdk-cargo.js +178 -0
  234. package/dist/emit/rust/sdk-client.d.ts +25 -0
  235. package/dist/emit/rust/sdk-client.js +108 -0
  236. package/dist/emit/rust/sdk-method.d.ts +15 -0
  237. package/dist/emit/rust/sdk-method.js +119 -0
  238. package/dist/emit/rust/sdk-opts.d.ts +58 -0
  239. package/dist/emit/rust/sdk-opts.js +117 -0
  240. package/dist/emit/rust/sdk-plan.d.ts +33 -0
  241. package/dist/emit/rust/sdk-plan.js +1 -0
  242. package/dist/emit/rust/sdk.d.ts +23 -0
  243. package/dist/emit/rust/sdk.js +111 -0
  244. package/dist/emit/rust/sse.d.ts +19 -0
  245. package/dist/emit/rust/sse.js +20 -0
  246. package/dist/emit/rust/types-enum.d.ts +13 -0
  247. package/dist/emit/rust/types-enum.js +62 -0
  248. package/dist/emit/rust/types-names.d.ts +19 -0
  249. package/dist/emit/rust/types-names.js +66 -0
  250. package/dist/emit/rust/types-struct.d.ts +21 -0
  251. package/dist/emit/rust/types-struct.js +59 -0
  252. package/dist/emit/rust/types-union.d.ts +24 -0
  253. package/dist/emit/rust/types-union.js +97 -0
  254. package/dist/emit/rust/types.d.ts +34 -0
  255. package/dist/emit/rust/types.js +105 -0
  256. package/dist/emit/rust/ws.d.ts +21 -0
  257. package/dist/emit/rust/ws.js +20 -0
  258. package/dist/emit/shared/escape.d.ts +55 -0
  259. package/dist/emit/shared/escape.js +144 -0
  260. package/dist/emit/shared/format.d.ts +24 -0
  261. package/dist/emit/shared/format.js +23 -0
  262. package/dist/emit/shared/gofmt.d.ts +3 -0
  263. package/dist/emit/shared/gofmt.js +26 -0
  264. package/dist/emit/shared/lang.d.ts +60 -0
  265. package/dist/emit/shared/lang.js +233 -0
  266. package/dist/emit/shared/literals.d.ts +4 -0
  267. package/dist/emit/shared/literals.js +31 -0
  268. package/dist/emit/shared/metadata.d.ts +106 -0
  269. package/dist/emit/shared/metadata.js +130 -0
  270. package/dist/emit/shared/mirror.d.ts +22 -0
  271. package/dist/emit/shared/mirror.js +26 -0
  272. package/dist/emit/shared/ruff.d.ts +3 -0
  273. package/dist/emit/shared/ruff.js +31 -0
  274. package/dist/emit/shared/rustfmt.d.ts +3 -0
  275. package/dist/emit/shared/rustfmt.js +32 -0
  276. package/dist/emit/shared/status-keys.d.ts +7 -0
  277. package/dist/emit/shared/status-keys.js +67 -0
  278. package/dist/emit/shared/type-emitter.d.ts +19 -0
  279. package/dist/emit/shared/type-emitter.js +100 -0
  280. package/dist/emit/ts/app-client.d.ts +4 -0
  281. package/dist/emit/ts/app-client.js +68 -0
  282. package/dist/emit/ts/http.d.ts +20 -0
  283. package/dist/emit/ts/http.js +74 -0
  284. package/dist/emit/ts/package.d.ts +36 -0
  285. package/dist/emit/ts/package.js +126 -0
  286. package/dist/emit/ts/route-tree.d.ts +68 -0
  287. package/dist/emit/ts/route-tree.js +240 -0
  288. package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
  289. package/dist/emit/ts/sdk-types-preamble.js +123 -0
  290. package/dist/emit/ts/sdk-types.d.ts +13 -0
  291. package/dist/emit/ts/sdk-types.js +213 -0
  292. package/dist/emit/ts/sdk.d.ts +21 -0
  293. package/dist/emit/ts/sdk.js +173 -0
  294. package/dist/emit/ts/service-map.d.ts +40 -0
  295. package/dist/emit/ts/service-map.js +171 -0
  296. package/dist/emit/ts/tanstack-query.d.ts +12 -0
  297. package/dist/emit/ts/tanstack-query.js +156 -0
  298. package/dist/emit/ts/type-gen.d.ts +26 -0
  299. package/dist/emit/ts/type-gen.js +255 -0
  300. package/dist/emit/ts/webhooks.d.ts +19 -0
  301. package/dist/emit/ts/webhooks.js +81 -0
  302. package/dist/extract/chain.d.ts +34 -0
  303. package/dist/extract/chain.js +84 -0
  304. package/dist/extract/extract.d.ts +41 -0
  305. package/dist/extract/extract.js +191 -0
  306. package/dist/extract/serialize.d.ts +34 -0
  307. package/dist/extract/serialize.js +295 -0
  308. package/dist/extract/walk.d.ts +47 -0
  309. package/dist/extract/walk.js +109 -0
  310. package/dist/gen/args.d.ts +28 -0
  311. package/dist/gen/args.js +133 -0
  312. package/dist/gen/formatters.d.ts +62 -0
  313. package/dist/gen/formatters.js +146 -0
  314. package/dist/gen/process.d.ts +13 -0
  315. package/dist/gen/process.js +35 -0
  316. package/dist/gen/shipped.d.ts +17 -0
  317. package/dist/gen/shipped.js +55 -0
  318. package/dist/gen/targets.d.ts +93 -0
  319. package/dist/gen/targets.js +171 -0
  320. package/dist/gen/write.d.ts +33 -0
  321. package/dist/gen/write.js +118 -0
  322. package/dist/index.d.ts +13 -0
  323. package/dist/index.js +15 -0
  324. package/dist/ir/build.d.ts +37 -0
  325. package/dist/ir/build.js +152 -0
  326. package/dist/ir/load.d.ts +11 -0
  327. package/dist/ir/load.js +112 -0
  328. package/dist/ir/model.d.ts +206 -0
  329. package/dist/ir/model.js +5 -0
  330. package/dist/ir/resolve-refs.d.ts +11 -0
  331. package/dist/ir/resolve-refs.js +66 -0
  332. package/dist/ir/resource-tree.d.ts +9 -0
  333. package/dist/ir/resource-tree.js +53 -0
  334. package/dist/ir/route-tree-intern.d.ts +18 -0
  335. package/dist/ir/route-tree-intern.js +174 -0
  336. package/dist/ir/schema.d.ts +11 -0
  337. package/dist/ir/schema.js +192 -0
  338. package/dist/ir/sdk-model.d.ts +86 -0
  339. package/dist/ir/sdk-model.js +204 -0
  340. package/dist/ir/slots.d.ts +42 -0
  341. package/dist/ir/slots.js +245 -0
  342. package/dist/runtime/cli/body.go +176 -0
  343. package/dist/runtime/cli/config.go +243 -0
  344. package/dist/runtime/cli/discovery.go +147 -0
  345. package/dist/runtime/cli/format.go +174 -0
  346. package/dist/runtime/cli/log.go +117 -0
  347. package/dist/runtime/cli/output.go +247 -0
  348. package/dist/runtime/cli/params.go +197 -0
  349. package/dist/runtime/cli/run.go +226 -0
  350. package/dist/runtime/cli/socket.go +60 -0
  351. package/dist/runtime/cli/stream.go +217 -0
  352. package/dist/runtime/cli/target.go +117 -0
  353. package/dist/runtime/csharp/Adapters.cs +183 -0
  354. package/dist/runtime/csharp/Auth.cs +56 -0
  355. package/dist/runtime/csharp/Body.cs +135 -0
  356. package/dist/runtime/csharp/Config.cs +161 -0
  357. package/dist/runtime/csharp/Envelope.cs +149 -0
  358. package/dist/runtime/csharp/Errors.cs +194 -0
  359. package/dist/runtime/csharp/Events.cs +155 -0
  360. package/dist/runtime/csharp/Exchange.cs +247 -0
  361. package/dist/runtime/csharp/Handler.cs +103 -0
  362. package/dist/runtime/csharp/Hooks.cs +128 -0
  363. package/dist/runtime/csharp/Invalidation.cs +102 -0
  364. package/dist/runtime/csharp/Json.cs +144 -0
  365. package/dist/runtime/csharp/Log.cs +48 -0
  366. package/dist/runtime/csharp/Operation.cs +33 -0
  367. package/dist/runtime/csharp/Path.cs +65 -0
  368. package/dist/runtime/csharp/Query.cs +72 -0
  369. package/dist/runtime/csharp/Realtime.cs +118 -0
  370. package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
  371. package/dist/runtime/csharp/Redirect.cs +53 -0
  372. package/dist/runtime/csharp/Result.cs +57 -0
  373. package/dist/runtime/csharp/Sse.cs +122 -0
  374. package/dist/runtime/csharp/Stale.cs +151 -0
  375. package/dist/runtime/csharp/Transport.cs +143 -0
  376. package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
  377. package/dist/runtime/csharp/TransportSse.cs +54 -0
  378. package/dist/runtime/csharp/TransportWs.cs +40 -0
  379. package/dist/runtime/csharp/Wire.cs +109 -0
  380. package/dist/runtime/csharp/Ws.cs +300 -0
  381. package/dist/runtime/csharp/WsDial.cs +127 -0
  382. package/dist/runtime/go/auth.go +127 -0
  383. package/dist/runtime/go/body.go +129 -0
  384. package/dist/runtime/go/config.go +75 -0
  385. package/dist/runtime/go/errors.go +185 -0
  386. package/dist/runtime/go/export.go +37 -0
  387. package/dist/runtime/go/hooks.go +53 -0
  388. package/dist/runtime/go/invalidation.go +112 -0
  389. package/dist/runtime/go/log.go +92 -0
  390. package/dist/runtime/go/nullable.go +64 -0
  391. package/dist/runtime/go/options.go +118 -0
  392. package/dist/runtime/go/path.go +156 -0
  393. package/dist/runtime/go/query.go +147 -0
  394. package/dist/runtime/go/realtime.go +239 -0
  395. package/dist/runtime/go/realtime_loop.go +208 -0
  396. package/dist/runtime/go/redirect.go +124 -0
  397. package/dist/runtime/go/request.go +222 -0
  398. package/dist/runtime/go/result.go +86 -0
  399. package/dist/runtime/go/sse.go +186 -0
  400. package/dist/runtime/go/stale.go +229 -0
  401. package/dist/runtime/go/stream.go +105 -0
  402. package/dist/runtime/go/transport.go +242 -0
  403. package/dist/runtime/go/transport_longpoll.go +121 -0
  404. package/dist/runtime/go/transport_sse.go +175 -0
  405. package/dist/runtime/go/ws.go +205 -0
  406. package/dist/runtime/java/Answer.java +107 -0
  407. package/dist/runtime/java/ApiException.java +110 -0
  408. package/dist/runtime/java/BinaryBody.java +36 -0
  409. package/dist/runtime/java/Body.java +105 -0
  410. package/dist/runtime/java/Call.java +23 -0
  411. package/dist/runtime/java/CallLog.java +51 -0
  412. package/dist/runtime/java/ClientConfig.java +233 -0
  413. package/dist/runtime/java/ConnectionState.java +12 -0
  414. package/dist/runtime/java/Credential.java +58 -0
  415. package/dist/runtime/java/Deadline.java +38 -0
  416. package/dist/runtime/java/Decode.java +181 -0
  417. package/dist/runtime/java/Envelope.java +141 -0
  418. package/dist/runtime/java/ErrorEnvelope.java +23 -0
  419. package/dist/runtime/java/EventStream.java +129 -0
  420. package/dist/runtime/java/Exchange.java +62 -0
  421. package/dist/runtime/java/FilePart.java +5 -0
  422. package/dist/runtime/java/Flight.java +306 -0
  423. package/dist/runtime/java/HoneyException.java +14 -0
  424. package/dist/runtime/java/Hooks.java +47 -0
  425. package/dist/runtime/java/Hops.java +133 -0
  426. package/dist/runtime/java/InvalidationConfig.java +73 -0
  427. package/dist/runtime/java/Json.java +23 -0
  428. package/dist/runtime/java/Keepalive.java +60 -0
  429. package/dist/runtime/java/LogEntry.java +14 -0
  430. package/dist/runtime/java/LongPollAdapter.java +68 -0
  431. package/dist/runtime/java/Operation.java +21 -0
  432. package/dist/runtime/java/Opt.java +121 -0
  433. package/dist/runtime/java/Pump.java +160 -0
  434. package/dist/runtime/java/RawResponse.java +48 -0
  435. package/dist/runtime/java/Realtime.java +152 -0
  436. package/dist/runtime/java/RealtimeLoop.java +371 -0
  437. package/dist/runtime/java/RedirectPolicy.java +13 -0
  438. package/dist/runtime/java/Redirects.java +126 -0
  439. package/dist/runtime/java/RequestContext.java +78 -0
  440. package/dist/runtime/java/RequestHook.java +9 -0
  441. package/dist/runtime/java/RequestOptions.java +91 -0
  442. package/dist/runtime/java/ResponseContext.java +70 -0
  443. package/dist/runtime/java/ResponseHook.java +12 -0
  444. package/dist/runtime/java/Result.java +32 -0
  445. package/dist/runtime/java/ResumableConnection.java +165 -0
  446. package/dist/runtime/java/SdkException.java +11 -0
  447. package/dist/runtime/java/Socket.java +301 -0
  448. package/dist/runtime/java/Sse.java +171 -0
  449. package/dist/runtime/java/SseAdapter.java +61 -0
  450. package/dist/runtime/java/SseEvent.java +10 -0
  451. package/dist/runtime/java/StaleMeta.java +16 -0
  452. package/dist/runtime/java/StaleTracker.java +287 -0
  453. package/dist/runtime/java/Transport.java +16 -0
  454. package/dist/runtime/java/TransportAdapter.java +14 -0
  455. package/dist/runtime/java/TransportConnection.java +15 -0
  456. package/dist/runtime/java/TransportKind.java +12 -0
  457. package/dist/runtime/java/TransportMessage.java +9 -0
  458. package/dist/runtime/java/TransportOptions.java +138 -0
  459. package/dist/runtime/java/TypedWebSocket.java +83 -0
  460. package/dist/runtime/java/UrlPath.java +49 -0
  461. package/dist/runtime/java/UrlQuery.java +99 -0
  462. package/dist/runtime/java/WsAdapter.java +52 -0
  463. package/dist/runtime/java/WsClose.java +47 -0
  464. package/dist/runtime/java/WsDial.java +148 -0
  465. package/dist/runtime/java/WsMessage.java +18 -0
  466. package/dist/runtime/mcp/call.ts +167 -0
  467. package/dist/runtime/mcp/files.ts +183 -0
  468. package/dist/runtime/mcp/guard.ts +176 -0
  469. package/dist/runtime/mcp/http.ts +159 -0
  470. package/dist/runtime/mcp/jsonrpc.ts +50 -0
  471. package/dist/runtime/mcp/listen.ts +76 -0
  472. package/dist/runtime/mcp/mount.ts +123 -0
  473. package/dist/runtime/mcp/protocol.ts +219 -0
  474. package/dist/runtime/mcp/reader.ts +57 -0
  475. package/dist/runtime/mcp/result.ts +85 -0
  476. package/dist/runtime/mcp/stdio.ts +79 -0
  477. package/dist/runtime/mcp/stream.ts +62 -0
  478. package/dist/runtime/python/__init__.py +2 -0
  479. package/dist/runtime/python/auth.py +67 -0
  480. package/dist/runtime/python/body.py +83 -0
  481. package/dist/runtime/python/config.py +139 -0
  482. package/dist/runtime/python/errors.py +213 -0
  483. package/dist/runtime/python/events.py +152 -0
  484. package/dist/runtime/python/exchange.py +298 -0
  485. package/dist/runtime/python/hooks.py +86 -0
  486. package/dist/runtime/python/invalidation.py +57 -0
  487. package/dist/runtime/python/log.py +60 -0
  488. package/dist/runtime/python/operation.py +25 -0
  489. package/dist/runtime/python/path.py +41 -0
  490. package/dist/runtime/python/query.py +48 -0
  491. package/dist/runtime/python/realtime.py +244 -0
  492. package/dist/runtime/python/redirect.py +93 -0
  493. package/dist/runtime/python/result.py +58 -0
  494. package/dist/runtime/python/send_async.py +189 -0
  495. package/dist/runtime/python/send_sync.py +105 -0
  496. package/dist/runtime/python/sse.py +81 -0
  497. package/dist/runtime/python/stale.py +94 -0
  498. package/dist/runtime/python/transport.py +157 -0
  499. package/dist/runtime/python/transport_longpoll.py +60 -0
  500. package/dist/runtime/python/transport_sse.py +60 -0
  501. package/dist/runtime/python/transport_ws.py +57 -0
  502. package/dist/runtime/python/ws.py +276 -0
  503. package/dist/runtime/rust/Cargo.lock +1763 -0
  504. package/dist/runtime/rust/answer.rs +120 -0
  505. package/dist/runtime/rust/auth.rs +80 -0
  506. package/dist/runtime/rust/body.rs +150 -0
  507. package/dist/runtime/rust/call.rs +200 -0
  508. package/dist/runtime/rust/config.rs +254 -0
  509. package/dist/runtime/rust/envelope.rs +84 -0
  510. package/dist/runtime/rust/errors.rs +235 -0
  511. package/dist/runtime/rust/events.rs +177 -0
  512. package/dist/runtime/rust/exchange.rs +287 -0
  513. package/dist/runtime/rust/hooks.rs +63 -0
  514. package/dist/runtime/rust/invalidation.rs +84 -0
  515. package/dist/runtime/rust/log.rs +88 -0
  516. package/dist/runtime/rust/nullable.rs +13 -0
  517. package/dist/runtime/rust/path.rs +83 -0
  518. package/dist/runtime/rust/query.rs +84 -0
  519. package/dist/runtime/rust/realtime.rs +182 -0
  520. package/dist/runtime/rust/realtime_loop.rs +177 -0
  521. package/dist/runtime/rust/redirect.rs +121 -0
  522. package/dist/runtime/rust/request.rs +178 -0
  523. package/dist/runtime/rust/result.rs +101 -0
  524. package/dist/runtime/rust/sse.rs +104 -0
  525. package/dist/runtime/rust/stale.rs +209 -0
  526. package/dist/runtime/rust/transport.rs +221 -0
  527. package/dist/runtime/rust/transport_longpoll.rs +108 -0
  528. package/dist/runtime/rust/transport_sse.rs +91 -0
  529. package/dist/runtime/rust/transport_ws.rs +75 -0
  530. package/dist/runtime/rust/ws.rs +322 -0
  531. package/dist/runtime/ts/app-types.ts +200 -0
  532. package/dist/runtime/ts/app.ts +104 -0
  533. package/dist/runtime/ts/config.ts +124 -0
  534. package/dist/runtime/ts/defaults.ts +48 -0
  535. package/dist/runtime/ts/error.ts +113 -0
  536. package/dist/runtime/ts/hooks.ts +92 -0
  537. package/dist/runtime/ts/http.ts +228 -0
  538. package/dist/runtime/ts/media-type.ts +36 -0
  539. package/dist/runtime/ts/path.ts +152 -0
  540. package/dist/runtime/ts/realtime-connection.ts +296 -0
  541. package/dist/runtime/ts/realtime-transports.ts +149 -0
  542. package/dist/runtime/ts/realtime.ts +293 -0
  543. package/dist/runtime/ts/redirect-policy.ts +17 -0
  544. package/dist/runtime/ts/redirects.ts +74 -0
  545. package/dist/runtime/ts/request.ts +239 -0
  546. package/dist/runtime/ts/response.ts +219 -0
  547. package/dist/runtime/ts/sdk-realtime.ts +10 -0
  548. package/dist/runtime/ts/sdk-sse.ts +55 -0
  549. package/dist/runtime/ts/sdk-ws.ts +21 -0
  550. package/dist/runtime/ts/sdk.ts +242 -0
  551. package/dist/runtime/ts/sse.ts +175 -0
  552. package/dist/runtime/ts/stale.ts +137 -0
  553. package/dist/runtime/ts/stream.ts +87 -0
  554. package/dist/runtime/ts/webhook.ts +116 -0
  555. package/dist/runtime/ts/ws.ts +155 -0
  556. package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
  557. package/dist/runtime/ts-tanstack-query/query.ts +261 -0
  558. package/package.json +84 -5
@@ -0,0 +1,117 @@
1
+ import { lineComment, rustString } from "../shared/escape.js";
2
+ import { compareCodeUnits, NameScope, rustTypeIdent, rustValueIdent } from "../shared/lang.js";
3
+ import { unboxed } from "./types-struct.js";
4
+ import { rustTypeOf } from "./types.js";
5
+ /* the Opts field an idempotent operation's caller sets its Idempotency-Key through */
6
+ const IDEMPOTENCY_KEY = "idempotency_key";
7
+ const isStringConst = (s) => s.kind === "const" && typeof s.value === "string";
8
+ /** Whether the type `schema` declares as a component has a `Default`: a struct, a newtype and a payload enum do not. */
9
+ function declaredDefault(schema, resolve) {
10
+ if (schema.kind === "const" || schema.kind === "allOf")
11
+ return false;
12
+ if (schema.kind === "object")
13
+ return schema.fields.length === 0 && schema.additional !== false;
14
+ if (schema.kind === "union" && schema.variants.length > 0)
15
+ return schema.discriminator === undefined && schema.variants.every(isStringConst);
16
+ return hasDefault(schema, resolve);
17
+ }
18
+ /** Whether the Rust type of `schema` in use position has a `Default`: only a hoisted struct or a component without one lacks it. */
19
+ function hasDefault(schema, resolve) {
20
+ if (schema.kind === "ref")
21
+ return declaredDefault(resolve(schema), resolve);
22
+ if (schema.kind === "object")
23
+ return schema.fields.length === 0;
24
+ if (schema.kind !== "allOf")
25
+ return true;
26
+ const { parts } = schema;
27
+ const part = parts.length === 1 ? parts[0] : parts.find((p) => p.kind === "ref");
28
+ return part === undefined || hasDefault(part, resolve);
29
+ }
30
+ /** `type` as a field that may be unset: as it is when it is an `Option` already. */
31
+ const optional = (type) => (type.startsWith("Option<") ? type : `Option<${type}>`);
32
+ /** Whether `op`'s Opts carry `idempotency_key`: an idempotent operation that answers once. */
33
+ export const takesIdempotencyKey = (op) => op.idempotent && op.stream === null;
34
+ /** `<Op>Opts`'s param fields: each query param, then each header param; a param `stream` carries has none. */
35
+ export function optsFields(op, opts, at, stream) {
36
+ const own = stream?.fields.map((field) => field.ident) ?? [];
37
+ const scope = new NameScope([...(takesIdempotencyKey(op) ? [IDEMPOTENCY_KEY] : []), ...own]);
38
+ const field = (param, where) => {
39
+ const ident = scope.claim(rustValueIdent(param.name));
40
+ const type = unboxed(param.schema, rustTypeOf(param.schema, { ...at, fieldName: param.name, parentName: opts }));
41
+ const required = param.required === true;
42
+ const bare = required && hasDefault(param.schema, at.names.resolve);
43
+ return { bare, ident, in: where, param: param.name, required, type: bare ? type : optional(type) };
44
+ };
45
+ const declared = (params, where) => params.filter((param) => stream?.carries(param.name, where) !== true).map((param) => field(param, where));
46
+ return [...declared(op.query, "query"), ...declared(op.headers, "header")];
47
+ }
48
+ /** `<Op>Opts`: the operation's inputs beyond its path and body, documented, then `stream`'s own fields. */
49
+ export function optsDecl(op, opts, fields, stream) {
50
+ const declared = fields.flatMap((field) => [
51
+ ...(field.required && !field.bare ? [" /// Required by the API."] : []),
52
+ ` pub ${field.ident}: ${field.type},`,
53
+ ]);
54
+ const own = (stream?.fields ?? []).flatMap((field) => [
55
+ ...(field.doc === undefined ? [] : lineComment(field.doc, "///", " ")),
56
+ ` pub ${field.ident}: ${field.type},`,
57
+ ]);
58
+ const keyed = takesIdempotencyKey(op) ? [` pub ${IDEMPOTENCY_KEY}: Option<String>,`] : [];
59
+ const body = [...declared, ...own, ...keyed];
60
+ return [
61
+ ...lineComment(`The parameters of ${op.id} beyond its path and body.`, "///"),
62
+ "#[derive(Debug, Clone, Default)]",
63
+ body.length === 0 ? `pub struct ${opts} {}` : [`pub struct ${opts} {`, ...body, "}"].join("\n"),
64
+ ].join("\n");
65
+ }
66
+ /** The statements sending `opts`: each declared field, then `stream`'s, then the Idempotency-Key. */
67
+ export function optsLines(op, fields, stream) {
68
+ return [
69
+ ...fields.map((field) => `spec.${field.in}(${rustString(field.param)}, &opts.${field.ident});`),
70
+ ...(stream?.sends ?? []),
71
+ ...(takesIdempotencyKey(op) ? [`spec.idempotency_key(&opts.${IDEMPOTENCY_KEY});`] : []),
72
+ ];
73
+ }
74
+ /** The headers `op`'s 2xx responses declare, statuses ascending, a name's first spelling (any casing) kept; by name. */
75
+ function declaredHeaders(op) {
76
+ const all = Object.keys(op.ir.responses)
77
+ .filter((status) => /^2(?:\d\d|XX)$/i.test(status))
78
+ .sort(compareCodeUnits)
79
+ .flatMap((status) => op.ir.responses[status].headers ?? []);
80
+ /* reversed, so the first spelling of a name is the one its key ends on */
81
+ const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
82
+ return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
83
+ }
84
+ /**
85
+ * `<Op>Headers` and its `FromHeaders` impl, and its plan; null when `op` declares no response header, or is a
86
+ * WebSocket or realtime operation, whose 2xx response no caller receives.
87
+ */
88
+ export function responseHeaders(op, at) {
89
+ const headers = op.stream === "ws" || op.stream === "realtime" ? [] : declaredHeaders(op);
90
+ if (headers.length === 0)
91
+ return null;
92
+ const type = at.names.claim(`${rustTypeIdent(op.id)}Headers`);
93
+ const scope = new NameScope();
94
+ const fields = headers.map((header) => {
95
+ const ident = scope.claim(rustValueIdent(header.name));
96
+ const use = unboxed(header.schema, rustTypeOf(header.schema, { ...at, fieldName: header.name, parentName: type }));
97
+ const read = header.required ? "required_header" : "header";
98
+ return { header: header.name, ident, read, type: header.required ? use : optional(use) };
99
+ });
100
+ const decl = [
101
+ ...lineComment(`The response headers of ${op.id}, read by \`.with_headers()\`.`, "///"),
102
+ "#[derive(Debug, Clone)]",
103
+ `pub struct ${type} {`,
104
+ ...fields.map((field) => ` pub ${field.ident}: ${field.type},`),
105
+ "}",
106
+ "",
107
+ `impl FromHeaders for ${type} {`,
108
+ " fn from_headers(headers: &reqwest::header::HeaderMap) -> Result<Self, Error> {",
109
+ ` Ok(${type} {`,
110
+ ...fields.map((field) => ` ${field.ident}: crate::answer::${field.read}(headers, ${rustString(field.header)})?,`),
111
+ " })",
112
+ " }",
113
+ "}",
114
+ ].join("\n");
115
+ const plan = { fields: Object.fromEntries(fields.map((field) => [field.header, field.ident])), type };
116
+ return { decl, plan };
117
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The Rust SDK's call plan for one operation (contract 18 §7.4), in the emitter's own names: what the test
3
+ * driver's `dispatch.rs` is written from, since Rust has no reflection to find a method or a field by name.
4
+ * A plan carries no Rust type: each type is inferred from the method's parameters and the Opts fields.
5
+ */
6
+ import type { SdkBody, SdkResponseKind, SdkStream } from "../../ir/sdk-model.ts";
7
+ export type RustCallPlan = {
8
+ readonly operation: string;
9
+ /** the accessor idents from the client to the method's resource, root first: `["orgs", "members", "notes"]` */
10
+ readonly accessors: readonly string[];
11
+ /** the method ident as emitted (may be `r#use`) */
12
+ readonly method: string;
13
+ /** the path params by spec name, in signature order */
14
+ readonly pathParams: readonly string[];
15
+ readonly body: SdkBody["kind"] | null;
16
+ /** the `<Op>Opts` type name */
17
+ readonly opts: string;
18
+ /** each query param's spec name to its Opts field ident */
19
+ readonly query: Readonly<Record<string, string>>;
20
+ /** each header param's spec name to its Opts field ident */
21
+ readonly headers: Readonly<Record<string, string>>;
22
+ /** the Opts field idents that are a bare `T`, set without `Some` */
23
+ readonly required: readonly string[];
24
+ /** the Opts field ident of the idempotency key */
25
+ readonly idempotencyKey: string | null;
26
+ readonly response: SdkResponseKind;
27
+ /** the `<Op>Headers` type name, and each declared header (as the spec spells it) to its field ident */
28
+ readonly responseHeaders: {
29
+ readonly type: string;
30
+ readonly fields: Readonly<Record<string, string>>;
31
+ } | null;
32
+ readonly stream: SdkStream;
33
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { type CrateOptions } from "./sdk-cargo.ts";
2
+ import { type PackageIdentity, type Shipped } from "../shared/metadata.ts";
3
+ import type { RustCallPlan } from "./sdk-plan.ts";
4
+ /**
5
+ * The crate's options: its name (`honey-sdk` by default), version (`0.1.0` by default) and what crates.io shows,
6
+ * `keywords` and `categories` each a list or the CLI's comma-separated value. `cargo publish` refuses a crate with
7
+ * no description and no license.
8
+ */
9
+ export type RustSdkOptions = CrateOptions;
10
+ /** The crate's files by path, and what the generation reports: a component or a root member renamed (never silently). */
11
+ export type GeneratedRustSdk = {
12
+ readonly files: Readonly<Record<string, string>>;
13
+ readonly notices: readonly string[];
14
+ /** the crate as crates.io lists it */
15
+ readonly packages: readonly PackageIdentity[];
16
+ };
17
+ /** The crate's files for `document`, by path, and its notices; its manifest points at the files it `shipped` beside. */
18
+ export declare function generateRustSdk(document: Record<string, unknown>, options?: RustSdkOptions, shipped?: Shipped): GeneratedRustSdk;
19
+ /**
20
+ * Each operation's call plan by id, from the very emit `generateRustSdk` runs with these options: the names
21
+ * the test driver's `dispatch.rs` is written from (G8.4), never re-derived outside the emitter.
22
+ */
23
+ export declare function rustCallPlans(document: Record<string, unknown>, options?: RustSdkOptions): Readonly<Record<string, RustCallPlan>>;
@@ -0,0 +1,111 @@
1
+ /**
2
+ * The Rust SDK (bit 13): a crate emitted from the IR alone (H2), its library named `sdk` — the vendored
3
+ * runtime verbatim under `src/`, `src/types.rs` (every component, then every hoisted declaration in name
4
+ * order, then the API's `ErrorKey` when it has an operation), `src/client.rs` (the client, its resources
5
+ * and methods, each in the client's style, so `client.safe()` answers each as an `Answer`, bit 21 i4),
6
+ * `src/lib.rs` (the modules, and the crate root's exports), `Cargo.toml` and `Cargo.lock`.
7
+ * Every `.rs` file carries the generated-code marker.
8
+ */
9
+ import { toIR } from "../../ir/build.js";
10
+ import { sdkModel } from "../../ir/sdk-model.js";
11
+ import { lineComment } from "../shared/escape.js";
12
+ import { compareCodeUnits, rustTypeIdent } from "../shared/lang.js";
13
+ import { renameNotice } from "../shared/mirror.js";
14
+ import { rustErrorKeys } from "./errors.js";
15
+ import { needsWebSocket, publicItems, runtimeFiles } from "./http.js";
16
+ import { cargoLock, cargoToml, crateIdentity } from "./sdk-cargo.js";
17
+ import { packageOn } from "../shared/metadata.js";
18
+ import { clientDecls } from "./sdk-client.js";
19
+ import { rustTopLevel, rustTypeContext } from "./types.js";
20
+ /* the marker rustfmt and linguist read */
21
+ const MARKER = "// @generated by honey. DO NOT EDIT.";
22
+ /** Each component's declaration in code-unit order, its description as its rustdoc. */
23
+ function componentDecls(ir, at) {
24
+ return Object.keys(ir.schemas)
25
+ .sort(compareCodeUnits)
26
+ .map((name) => {
27
+ const described = Object.hasOwn(ir.schemaDescriptions, name);
28
+ const doc = described ? lineComment(ir.schemaDescriptions[name], "///") : [];
29
+ return [...doc, rustTopLevel(at.names.ref(name), ir.schemas[name], at)].join("\n");
30
+ });
31
+ }
32
+ /** A `.rs` file: the marker, its inner doc, then `decls`. */
33
+ const rustFile = (doc, decls) => [MARKER, `//! ${doc}`, ...decls.flatMap((decl) => ["", decl]), ""].join("\n");
34
+ /**
35
+ * lib.rs: the crate doc (the API's title and description), each module, and the crate root's exports: each
36
+ * runtime module's public items by name (a crate-private runtime item may share a component's name), then
37
+ * the client's and the types', where they declare any.
38
+ */
39
+ function libFile(info, runtime, own) {
40
+ const title = info.title === undefined ? "The API's client" : `The ${info.title} client`;
41
+ const doc = [`${title}, generated by honey.`, info.description].filter((part) => part !== undefined);
42
+ const exports = runtime.flatMap(([module, source]) => {
43
+ const items = publicItems(source).sort(compareCodeUnits);
44
+ if (items.length < 2)
45
+ return items.map((item) => `pub use ${module}::${item};`);
46
+ return [`pub use ${module}::{${items.join(", ")}};`];
47
+ });
48
+ const modules = [...runtime.map(([module]) => module), "client", "types"].sort(compareCodeUnits);
49
+ return [
50
+ MARKER,
51
+ ...lineComment(doc.join("\n\n"), "//!"),
52
+ "",
53
+ ...modules.map((module) => `mod ${module};`),
54
+ "",
55
+ ...exports,
56
+ ...(own.client ? ["pub use client::*;"] : []),
57
+ ...(own.types ? ["pub use types::*;"] : []),
58
+ "",
59
+ ].join("\n");
60
+ }
61
+ /** The crate's files for `document`, and the call plan of every method in them. */
62
+ function emitRust(document, options, shipped) {
63
+ const crate = crateIdentity(options);
64
+ const ir = toIR(document, { deriveOperationIds: true });
65
+ const model = sdkModel(ir);
66
+ const at = rustTypeContext(ir);
67
+ /* components first: the client's hoisted types then land beside them */
68
+ const components = componentDecls(ir, at);
69
+ /* every component emitted under another name is noticed, as the mirror's rename is */
70
+ const notices = [...at.names.renamed].map(([name, emitted]) => renameNotice("rust", {
71
+ because: `"${rustTypeIdent(name)}" is a name the SDK's crate root or the Rust prelude holds`,
72
+ name,
73
+ renamed: emitted,
74
+ what: "component",
75
+ }));
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 */
78
+ const errorKeys = model.ops.length > 0 ? [rustErrorKeys(model, at)] : [];
79
+ const hoisted = [...at.decls].sort(([a], [b]) => compareCodeUnits(a, b)).map(([, decl]) => decl);
80
+ const features = {
81
+ realtime: model.ops.some((op) => op.stream === "realtime"),
82
+ ws: model.ops.some((op) => op.stream === "ws"),
83
+ };
84
+ const { "Cargo.lock": template, ...sources } = runtimeFiles(features);
85
+ const runtime = Object.entries(sources).map(([name, source]) => [name.replace(/\.rs$/, ""), source]);
86
+ const ws = needsWebSocket(features);
87
+ const types = [...components, ...hoisted, ...errorKeys];
88
+ const own = { client: model.ops.length > 0, types: types.length > 0 };
89
+ const files = {
90
+ "Cargo.lock": cargoLock(template, crate, ws),
91
+ "Cargo.toml": cargoToml(crate, ws, shipped),
92
+ "src/client.rs": rustFile("The client, its resources and their operations.", ["use crate::*;", client.decls]),
93
+ "src/lib.rs": libFile(ir.info, runtime, own),
94
+ "src/types.rs": rustFile("The API's types.", types),
95
+ ...Object.fromEntries(runtime.map(([module, source]) => [`src/${module}.rs`, source])),
96
+ };
97
+ const sorted = Object.fromEntries(Object.entries(files).sort(([a], [b]) => compareCodeUnits(a, b)));
98
+ return { crate, files: sorted, notices, plans: client.plans };
99
+ }
100
+ /** The crate's files for `document`, by path, and its notices; its manifest points at the files it `shipped` beside. */
101
+ export function generateRustSdk(document, options = {}, shipped) {
102
+ const { crate, files, notices } = emitRust(document, options, shipped);
103
+ return { files, notices, packages: [packageOn("crates.io", crate.name, crate.version)] };
104
+ }
105
+ /**
106
+ * Each operation's call plan by id, from the very emit `generateRustSdk` runs with these options: the names
107
+ * the test driver's `dispatch.rs` is written from (G8.4), never re-derived outside the emitter.
108
+ */
109
+ export function rustCallPlans(document, options = {}) {
110
+ return Object.fromEntries(emitRust(document, options).plans.map((plan) => [plan.operation, plan]));
111
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * An SSE operation's answer (contract 20 §2.0–2.1): `EventStream<E>`, `E` the declared event schema's type
3
+ * (`String` for untyped events), and its Opts' `last_event_id`, sent as Last-Event-ID only when set and
4
+ * non-empty; a declared Last-Event-ID header param is folded into that field (Fd3).
5
+ */
6
+ import type { SdkOp } from "../../ir/sdk-model.ts";
7
+ import type { OptsField, StreamAnswer } from "./sdk-opts.ts";
8
+ import type { RustTypeContext } from "./types.ts";
9
+ /** The resume cursor's id, which the SSE and realtime Opts carry. */
10
+ export declare const LAST_EVENT_ID: {
11
+ ident: string;
12
+ type: string;
13
+ };
14
+ /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
15
+ export declare const isLastEventIdHeader: (param: string, where: OptsField["in"]) => boolean;
16
+ /** A streamed event's type: the operation's declared event schema, else `fallback`. */
17
+ export declare const eventType: (op: SdkOp, at: RustTypeContext, fallback: string) => string;
18
+ /** The SSE operation `op`'s answer: its events as text, or JSON decoded into the event type. */
19
+ export declare function sseAnswer(op: SdkOp, at: RustTypeContext): StreamAnswer;
@@ -0,0 +1,20 @@
1
+ import { typeAt } from "./sdk-body.js";
2
+ /** The resume cursor's id, which the SSE and realtime Opts carry. */
3
+ export const LAST_EVENT_ID = { ident: "last_event_id", type: "Option<String>" };
4
+ /** Whether a declared param is the Last-Event-ID header (any casing), the resume channel an SSE dial sends. */
5
+ export const isLastEventIdHeader = (param, where) => where === "header" && param.toLowerCase() === "last-event-id";
6
+ /** A streamed event's type: the operation's declared event schema, else `fallback`. */
7
+ export const eventType = (op, at, fallback) => op.events === undefined ? fallback : typeAt(op.events, op.id, "Event", at);
8
+ /* Last-Event-ID, sent only when set: an empty cursor names no position */
9
+ const SSE = {
10
+ carries: isLastEventIdHeader,
11
+ fields: [LAST_EVENT_ID],
12
+ sends: ['spec.header("Last-Event-ID", &crate::request::cursor(&opts.last_event_id));'],
13
+ };
14
+ const DOC = "Resolves once the stream is open: an error status is the answer's error (`Err(Error::Api)`, on `client.safe()` an `Answer::Err`). No timeout bounds the stream after that; `cancel_on` ends it quietly, and dropping it closes it.";
15
+ /** The SSE operation `op`'s answer: its events as text, or JSON decoded into the event type. */
16
+ export function sseAnswer(op, at) {
17
+ const events = eventType(op, at, "String");
18
+ const run = op.events === undefined ? "crate::events::text" : `crate::events::json::<${events}>`;
19
+ return { doc: DOC, run, stream: SSE, type: `EventStream<${events}>` };
20
+ }
@@ -0,0 +1,13 @@
1
+ import { NameScope } from "../shared/lang.ts";
2
+ type EnumValue = boolean | number | string;
3
+ /** The string values an enum declares, each once: a null has no variant. */
4
+ export declare const stringValues: (values: readonly EnumValue[]) => string[];
5
+ /** The integer values an enum declares, each once: any other value has no variant. */
6
+ export declare const integerValues: (values: readonly EnumValue[]) => number[];
7
+ /** A variant for `value`, unique in `scope`: `""` is `Empty`, `self` is `SelfValue`, a repeat takes `…2`. */
8
+ export declare function variantOf(value: string, scope: NameScope): string;
9
+ /** `pub enum <name>` with one unit variant per value, renamed to the value where it differs. */
10
+ export declare function stringEnumDecl(name: string, values: readonly string[]): string;
11
+ /** `#[repr(i64)] pub enum <name>` with one `L<n>` variant per value, then its serde impls. */
12
+ export declare function intEnumDecl(name: string, values: readonly number[]): string;
13
+ export {};
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Rust enums for a string or integer `enum`. A string enum derives serde and renames a variant to its
3
+ * value only when the two differ; an integer enum is `#[repr(i64)]` with serde written by hand (G9
4
+ * drops serde_repr). The first variant is the default either way. Spec text reaches the source only
5
+ * through the shared escape layer.
6
+ */
7
+ import { rustString } from "../shared/escape.js";
8
+ import { NameScope, rustTypeIdent } from "../shared/lang.js";
9
+ const STRING_DERIVE = "#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize)]";
10
+ /** The string values an enum declares, each once: a null has no variant. */
11
+ export const stringValues = (values) => [
12
+ ...new Set(values.filter((value) => value !== null).map(String)),
13
+ ];
14
+ /** The integer values an enum declares, each once: any other value has no variant. */
15
+ export const integerValues = (values) => [
16
+ ...new Set(values.filter((value) => Number.isSafeInteger(value))),
17
+ ];
18
+ /** A variant for `value`, unique in `scope`: `""` is `Empty`, `self` is `SelfValue`, a repeat takes `…2`. */
19
+ export function variantOf(value, scope) {
20
+ const base = value === "" ? "Empty" : rustTypeIdent(value);
21
+ return scope.claim(base === "Self_" ? "SelfValue" : base);
22
+ }
23
+ /** `pub enum <name>` with one unit variant per value, renamed to the value where it differs. */
24
+ export function stringEnumDecl(name, values) {
25
+ const scope = new NameScope();
26
+ const variants = values.flatMap((value, i) => {
27
+ const variant = variantOf(value, scope);
28
+ return [
29
+ ...(i === 0 ? [" #[default]"] : []),
30
+ ...(variant === value ? [] : [` #[serde(rename = ${rustString(value)})]`]),
31
+ ` ${variant},`,
32
+ ];
33
+ });
34
+ return [STRING_DERIVE, `pub enum ${name} {`, ...variants, "}"].join("\n");
35
+ }
36
+ /** An integer value's variant: `L<n>`, or `Neg<n>` below zero. */
37
+ const label = (value) => `${value < 0 ? "Neg" : "L"}${String(Math.abs(value))}`;
38
+ /** `#[repr(i64)] pub enum <name>` with one `L<n>` variant per value, then its serde impls. */
39
+ export function intEnumDecl(name, values) {
40
+ return [
41
+ "#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]",
42
+ "#[repr(i64)]",
43
+ `pub enum ${name} {`,
44
+ ...values.flatMap((value, i) => [...(i === 0 ? [" #[default]"] : []), ` ${label(value)} = ${value},`]),
45
+ "}",
46
+ "",
47
+ `impl serde::Serialize for ${name} {`,
48
+ " fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {",
49
+ " serializer.serialize_i64(*self as i64)",
50
+ " }",
51
+ "}",
52
+ "",
53
+ `impl<'de> serde::Deserialize<'de> for ${name} {`,
54
+ " fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {",
55
+ " match <i64 as serde::Deserialize>::deserialize(deserializer)? {",
56
+ ...values.map((value) => ` ${value} => Ok(Self::${label(value)}),`),
57
+ ` other => Err(serde::de::Error::custom(format!("unknown ${name} {other}"))),`,
58
+ " }",
59
+ " }",
60
+ "}",
61
+ ].join("\n");
62
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The crate-level names Rust types are declared under: one scope that components, hoisted types and
3
+ * the client's own declarations all claim from, clear of every item the runtime makes public at the
4
+ * crate root (`lib.rs` re-exports each runtime module's public items), of the emitter's own `ErrorKey`,
5
+ * and of the prelude and std names generated code relies on (H52).
6
+ */
7
+ import type { IR } from "../../ir/model.ts";
8
+ import type { RustTypeNames } from "./types.ts";
9
+ /** The style parameter every resource and its methods' `Call` take (bit 21 i4): no type may be named it. */
10
+ export declare const STYLE = "S";
11
+ /** Names for one schema on its own: each as asked for, no cycles, refs left unresolved. */
12
+ export declare function plainNames(): RustTypeNames;
13
+ /**
14
+ * Names for the SDK of `ir`: each component claims its Rust name in code-unit order, as `<Name>Model`
15
+ * when the runtime, the emitter (`ErrorKey`, the style parameter `S`) or the prelude owns it, kept in `renamed` so
16
+ * the generation names it (bit 21 i4: never a silent rename); hoisted types and the client's declarations claim after
17
+ * them, a hoist key always getting the name it got first; `cyclic` is every component on a by-value cycle.
18
+ */
19
+ export declare function irNames(ir: IR): RustTypeNames;
@@ -0,0 +1,66 @@
1
+ import { irResolver } from "../../ir/schema.js";
2
+ import { valueCycleSchemas } from "../../ir/sdk-model.js";
3
+ import { compareCodeUnits, isRustPreludeType, NameScope, rustTypeIdent } from "../shared/lang.js";
4
+ import { publicItems, runtimeFiles } from "./http.js";
5
+ /**
6
+ * The top-level `pub` items of the runtime's Rust files (contract §6.2), `ws` and `realtime` included,
7
+ * so a component keeps its Rust name whichever runtime files its SDK ships: every
8
+ * `pub struct|enum|trait|type|fn|const|static` at column 0, the way `go/types-names.ts` reads the Go runtime.
9
+ */
10
+ function runtimeIdentifiers() {
11
+ return Object.entries(runtimeFiles({ realtime: true, ws: true }))
12
+ .filter(([name]) => name.endsWith(".rs"))
13
+ .flatMap(([, source]) => publicItems(source));
14
+ }
15
+ /** The style parameter every resource and its methods' `Call` take (bit 21 i4): no type may be named it. */
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 */
18
+ const EMITTED = ["ErrorKey", STYLE];
19
+ /** Names for one schema on its own: each as asked for, no cycles, refs left unresolved. */
20
+ export function plainNames() {
21
+ return {
22
+ claim: (base) => base,
23
+ cyclic: new Set(),
24
+ hoist: (_key, base) => base,
25
+ renamed: new Map(),
26
+ ref: rustTypeIdent,
27
+ resolve: (schema) => schema,
28
+ };
29
+ }
30
+ /**
31
+ * Names for the SDK of `ir`: each component claims its Rust name in code-unit order, as `<Name>Model`
32
+ * when the runtime, the emitter (`ErrorKey`, the style parameter `S`) or the prelude owns it, kept in `renamed` so
33
+ * the generation names it (bit 21 i4: never a silent rename); hoisted types and the client's declarations claim after
34
+ * them, a hoist key always getting the name it got first; `cyclic` is every component on a by-value cycle.
35
+ */
36
+ export function irNames(ir) {
37
+ const scope = new NameScope([...runtimeIdentifiers(), ...EMITTED]);
38
+ const components = new Map();
39
+ const renamed = new Map();
40
+ for (const name of Object.keys(ir.schemas).sort(compareCodeUnits)) {
41
+ const base = rustTypeIdent(name);
42
+ const taken = scope.has(base) || isRustPreludeType(base);
43
+ const claimed = scope.claim(taken ? `${base}Model` : base);
44
+ components.set(name, claimed);
45
+ if (taken)
46
+ renamed.set(name, claimed);
47
+ }
48
+ /* a joined name can spell a prelude one (`Hash` + `map`): that one is taken too, so the claim moves on */
49
+ const claim = (base) => {
50
+ const name = scope.claim(base);
51
+ return isRustPreludeType(name) ? scope.claim(base) : name;
52
+ };
53
+ const hoisted = new Map();
54
+ return {
55
+ claim,
56
+ cyclic: valueCycleSchemas(ir.schemas),
57
+ hoist: (key, base) => {
58
+ const name = hoisted.get(key) ?? claim(base);
59
+ hoisted.set(key, name);
60
+ return name;
61
+ },
62
+ ref: (name) => components.get(name) ?? rustTypeIdent(name),
63
+ renamed,
64
+ resolve: irResolver(ir.schemas),
65
+ };
66
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Rust structs for objects and allOf compositions. Fields sort by JSON key and take a snake_case
3
+ * identifier (a keyword raw, `r#type`), renamed to the key only when the two differ. An optional
4
+ * field is `Option<T>`, skipped when `None`; an optional nullable one is `Option<Option<T>>` through
5
+ * the runtime's null-keeping deserializer, so absent, null and a value stay three states. An allOf's
6
+ * refs and an object's extra keys are `#[serde(flatten)]` fields.
7
+ */
8
+ import type { IRSchema } from "../../ir/model.ts";
9
+ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
10
+ kind: K;
11
+ }>;
12
+ /** The Rust type of `schema` at the member `fieldName` of the struct being declared. */
13
+ export type Member = (schema: IRSchema, fieldName: string) => string;
14
+ export declare const DERIVE = "#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]";
15
+ /** A map element or value: a ref there is behind the map already, so it needs no `Box`. */
16
+ export declare const unboxed: (item: IRSchema, type: string) => string;
17
+ /** A struct of the object's fields in key order, then an `extra` map of the keys it admits beyond them. */
18
+ export declare function objectDecl(name: string, ir: Of<"object">, member: Member): string;
19
+ /** A struct flattening each ref part, with every object part's fields inlined (a key once, its first part's). */
20
+ export declare function allOfDecl(name: string, ir: Of<"allOf">, member: Member, ref: (name: string) => string): string;
21
+ export {};
@@ -0,0 +1,59 @@
1
+ import { rustString } from "../shared/escape.js";
2
+ import { compareCodeUnits, NameScope, rustValueIdent } from "../shared/lang.js";
3
+ export const DERIVE = "#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]";
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) */
6
+ const TRI_STATE = ["default", 'deserialize_with = "crate::nullable::deserialize"', SKIP];
7
+ /** A field's lines: its serde keys in one attribute when it has any, then `pub <ident>: <type>,`. */
8
+ const fieldLines = ({ ident, type, serde }) => [
9
+ ...(serde.length > 0 ? [` #[serde(${serde.join(", ")})]`] : []),
10
+ ` pub ${ident}: ${type},`,
11
+ ];
12
+ /** `pub struct <name> { … }` with its derives; `{}` without fields, which serde reads and writes as `{}`. */
13
+ function structDecl(name, fields) {
14
+ if (fields.length === 0)
15
+ return [DERIVE, `pub struct ${name} {}`].join("\n");
16
+ return [DERIVE, `pub struct ${name} {`, ...fields.flatMap(fieldLines), "}"].join("\n");
17
+ }
18
+ /** The field for `field`, its identifier claimed in `scope`. */
19
+ function fieldOf(field, scope, member) {
20
+ const ident = scope.claim(rustValueIdent(field.name));
21
+ const rename = ident.replace(/^r#/, "") === field.name ? [] : [`rename = ${rustString(field.name)}`];
22
+ if (field.required)
23
+ return { ident, serde: rename, type: member(field.schema, field.name) };
24
+ if (field.schema.kind === "nullable") {
25
+ const inner = member(field.schema.inner, field.name);
26
+ return { ident, serde: [...rename, ...TRI_STATE], type: `Option<Option<${inner}>>` };
27
+ }
28
+ return { ident, serde: [...rename, SKIP], type: `Option<${member(field.schema, field.name)}>` };
29
+ }
30
+ const byKey = (a, b) => compareCodeUnits(a.name, b.name);
31
+ /** A map element or value: a ref there is behind the map already, so it needs no `Box`. */
32
+ export const unboxed = (item, type) => item.kind === "ref" && type.startsWith("Box<") ? type.slice(4, -1) : type;
33
+ /** A struct of the object's fields in key order, then an `extra` map of the keys it admits beyond them. */
34
+ export function objectDecl(name, ir, member) {
35
+ const scope = new NameScope();
36
+ const fields = [...ir.fields].sort(byKey).map((field) => fieldOf(field, scope, member));
37
+ if (ir.additional) {
38
+ const value = unboxed(ir.additional, member(ir.additional, "Extra"));
39
+ const ident = scope.claim("extra");
40
+ fields.push({ ident, serde: ["flatten"], type: `std::collections::HashMap<String, ${value}>` });
41
+ }
42
+ return structDecl(name, fields);
43
+ }
44
+ /** A struct flattening each ref part, with every object part's fields inlined (a key once, its first part's). */
45
+ export function allOfDecl(name, ir, member, ref) {
46
+ const scope = new NameScope();
47
+ const flattened = ir.parts
48
+ .filter((part) => part.kind === "ref")
49
+ .map((part) => ({
50
+ ident: scope.claim(rustValueIdent(ref(part.name))),
51
+ serde: ["flatten"],
52
+ type: member(part, part.name),
53
+ }));
54
+ const fields = ir.parts
55
+ .flatMap((part) => (part.kind === "object" ? [...part.fields].sort(byKey) : []))
56
+ .filter((field, i, all) => all.findIndex((first) => first.name === field.name) === i)
57
+ .map((field) => fieldOf(field, scope, member));
58
+ return structDecl(name, [...flattened, ...fields]);
59
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Rust enums for unions. Without a discriminator: `#[serde(untagged)]`, one `Variant<i>(T)` per
3
+ * variant, and the const-string variants gathered into one `Literal` over a hoisted string enum (a
4
+ * union of const strings alone is that string enum). With one: a payload variant per ref or inline
5
+ * object, plus `Unknown` keeping any other payload whole, serialized as the payload and deserialized
6
+ * on the discriminator's value with the payload kept, the discriminator included.
7
+ */
8
+ import type { IRSchema } from "../../ir/model.ts";
9
+ import { type Member } from "./types-struct.ts";
10
+ import type { RustTypeNames } from "./types.ts";
11
+ type Of<K extends IRSchema["kind"]> = Extract<IRSchema, {
12
+ kind: K;
13
+ }>;
14
+ /** Declares `schema` once under `names.hoist(key, base)`; its name. */
15
+ export type Declare = (schema: IRSchema, key: string, base: string) => string;
16
+ /** What a union's declaration reaches: the names, its members' types, and the hoist. */
17
+ export type UnionScope = {
18
+ names: RustTypeNames;
19
+ member: Member;
20
+ declare: Declare;
21
+ };
22
+ /** The declaration of a union with at least one variant. */
23
+ export declare function unionDecl(name: string, union: Of<"union">, scope: UnionScope): string;
24
+ export {};