@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,141 @@
1
+ import { methodsOf, namespacesOf } from "../../ir/resource-tree.js";
2
+ import { goString, lineComment } from "../shared/escape.js";
3
+ import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
4
+ import { MIRROR, mirrorNotice } from "../shared/mirror.js";
5
+ import { goMethod } from "./sdk-method.js";
6
+ import { twinLines, twinLiteral, twinTypeLines, twinTypes } from "./sdk-mirror.js";
7
+ /* the mirror as Go spells it, Client's method: goExported(MIRROR) */
8
+ const SAFE = "Safe";
9
+ /**
10
+ * A member's name in `members`, `segment` exported; at the root (`path` empty) one spelled like the mirror is
11
+ * `Safe_` instead (shared/mirror.ts), and noticed.
12
+ */
13
+ function memberName(segment, path, members, env) {
14
+ const name = goExported(segment);
15
+ if (path.length > 0 || name !== SAFE)
16
+ return members.claim(name);
17
+ const renamed = members.claim(`${SAFE}_`);
18
+ env.notices.push(mirrorNotice("go", SAFE, name, renamed));
19
+ return renamed;
20
+ }
21
+ /** `ns` at `path` as the struct `struct`: its child namespaces first, so a method never takes a field's name. */
22
+ function resourceOf(ns, path, struct, env) {
23
+ const members = new NameScope(path.length === 0 ? [SAFE] : []);
24
+ const receiver = { client: path.length === 0 ? "r" : "r.client", type: struct };
25
+ const fields = namespacesOf(ns).map(([segment, child]) => {
26
+ const name = memberName(segment, path, members, env);
27
+ const childPath = [...path, segment];
28
+ const childStruct = env.at.names.claimConst(`${childPath.map(goExported).join("")}Resource`);
29
+ return { name, node: resourceOf(child, childPath, childStruct, env) };
30
+ });
31
+ const methods = methodsOf(ns).map(([segment, op]) => goMethod(env.ops.get(op.id), memberName(segment, path, members, env), receiver, env));
32
+ return { fields, methods, path, struct };
33
+ }
34
+ /** `type <struct> struct { … }` with its own unexported fields, then a field per child namespace (of `struct`). */
35
+ function structDecl(node, own, struct = (n) => n.struct) {
36
+ return [
37
+ `type ${struct(node)} struct {`,
38
+ ...own.map((field) => `\t${field}`),
39
+ ...node.fields.map(({ name, node: child }) => `\t${name} *${struct(child)}`),
40
+ "}",
41
+ ];
42
+ }
43
+ /** Each namespace below the client: its struct, its methods, then its children's. */
44
+ function resourceLines(node) {
45
+ return [
46
+ ...lineComment(`${node.struct} groups the ${node.path.join(".")} operations.`, "//"),
47
+ ...structDecl(node, ["client *Client"]),
48
+ ...node.methods.flatMap((method) => ["", ...method.lines]),
49
+ ...node.fields.flatMap(({ node: child }) => ["", ...resourceLines(child)]),
50
+ ];
51
+ }
52
+ /** Each struct's safe twin by its struct: `SafeClient` for the client, `Safe<Struct>` claimed for the rest. */
53
+ function twinNames(node, env, names = new Map()) {
54
+ names.set(node, node.path.length === 0 ? `${SAFE}Client` : env.at.names.claimConst(`${SAFE}${node.struct}`));
55
+ for (const { node: child } of node.fields)
56
+ twinNames(child, env, names);
57
+ return names;
58
+ }
59
+ /** `r.<at><chain><Field> = <literal>` for every namespace below `node`, parents first. */
60
+ function wiring(node, chain, wired) {
61
+ return node.fields.flatMap(({ name, node: child }) => [
62
+ `\tr.${wired.at}${chain}${name} = ${wired.literal(child, `${chain}${name}.`)}`,
63
+ ...wiring(child, `${chain}${name}.`, wired),
64
+ ]);
65
+ }
66
+ /**
67
+ * The auth header pair (F2): an unset name takes the scheme's, and its prefix too unless the caller
68
+ * set one; a set name keeps the caller's prefix, empty meaning none.
69
+ */
70
+ function authDefaults(auth) {
71
+ const prefix = auth.prefix === ""
72
+ ? []
73
+ : ['\t\tif cfg.AuthHeaderPrefix == "" {', `\t\t\tcfg.AuthHeaderPrefix = ${goString(auth.prefix)}`, "\t\t}"];
74
+ return ['\tif cfg.AuthHeaderName == "" {', `\t\tcfg.AuthHeaderName = ${goString(auth.headerName)}`, ...prefix, "\t}"];
75
+ }
76
+ /** NewClient: the BaseURL default (the document's first server; without one an empty BaseURL panics), auth, wiring. */
77
+ function newClient(root, ir, twins, types) {
78
+ const twin = (n) => twins.get(n);
79
+ const safe = (n, chain) => twinLiteral(n, `r.${chain}`, twin(n), types);
80
+ const server = ir.servers[0];
81
+ const [doc, fallback] = server === undefined
82
+ ? [
83
+ "Config.BaseURL is required: the API declares no server.",
84
+ `panic(${goString("honey: Config.BaseURL is empty and the API declares no server")})`,
85
+ ]
86
+ : [`An empty Config.BaseURL defaults to the API's first server, ${server}.`, `cfg.BaseURL = ${goString(server)}`];
87
+ return [
88
+ ...lineComment(`NewClient returns a client for cfg. ${doc}`, "//"),
89
+ "func NewClient(cfg Config) *Client {",
90
+ '\tif cfg.BaseURL == "" {',
91
+ `\t\t${fallback}`,
92
+ "\t}",
93
+ ...authDefaults(ir.auth),
94
+ "\tcfg = prepareConfig(cfg)",
95
+ "\tr := &Client{cfg: cfg, stale: NewStaleTracker(cfg.Invalidation)}",
96
+ ...wiring(root, "", { at: "", literal: (n) => `&${n.struct}{client: r}` }),
97
+ `\tr.${MIRROR} = ${safe(root, "")}`,
98
+ ...wiring(root, "", { at: `${MIRROR}.`, literal: safe }),
99
+ "\treturn r",
100
+ "}",
101
+ "",
102
+ ...lineComment(`${SAFE} is the client's safe mirror: the same resources and methods, each answering a Result, so an answer (an error status, an undecodable body) is a value and only a failure with no answer is an error.`, "//"),
103
+ `func (r *Client) ${SAFE}() *${twin(root)} { return r.${MIRROR} }`,
104
+ ];
105
+ }
106
+ /** Every method in the tree, depth first. */
107
+ const methodsIn = (node) => [
108
+ ...node.methods,
109
+ ...node.fields.flatMap(({ node: child }) => methodsIn(child)),
110
+ ];
111
+ /** Every method's call plan below `node`, reached through `members`, depth first. */
112
+ const plansIn = (node, members) => [
113
+ ...node.methods.map((method) => ({ ...method.call, members })),
114
+ ...node.fields.flatMap(({ name, node: child }) => plansIn(child, [...members, name])),
115
+ ];
116
+ /**
117
+ * client.go's declarations for `ir` (the client, its resources and methods, then every `<Op>Opts`
118
+ * and `<Op>Headers` in name order), and every method's call plan.
119
+ */
120
+ export function clientDecls(ir, env) {
121
+ const root = resourceOf(ir.tree, [], "Client", env);
122
+ const twins = twinNames(root, env);
123
+ const types = twinTypes(methodsIn(root), (base) => env.at.names.claimConst(base));
124
+ const opts = methodsIn(root)
125
+ .flatMap((method) => method.decls)
126
+ .sort(([a], [b]) => compareCodeUnits(a, b))
127
+ .map(([, decl]) => decl);
128
+ const decls = [
129
+ "// Client is the API's client: a field per resource namespace, a method per operation at the root.",
130
+ ...structDecl(root, ["cfg Config", "stale *StaleTracker", `${MIRROR} *${twins.get(root)}`]),
131
+ "",
132
+ ...newClient(root, ir, twins, types),
133
+ ...root.methods.flatMap((method) => ["", ...method.lines]),
134
+ ...root.fields.flatMap(({ node }) => ["", ...resourceLines(node)]),
135
+ "",
136
+ ...twinLines(root, twins, types),
137
+ ...twinTypeLines(types),
138
+ ...opts.flatMap((decl) => ["", decl]),
139
+ ].join("\n");
140
+ return { decls, plans: plansIn(root, []) };
141
+ }
@@ -0,0 +1,68 @@
1
+ import { type SdkBody, type SdkOp, type SdkResponseKind, type SdkStream } from "../../ir/sdk-model.ts";
2
+ import { type GoPart } from "./sdk-body.ts";
3
+ import { type GoResponseHeaders } from "./sdk-opts.ts";
4
+ import { type GoTypeContext } from "./types.ts";
5
+ /**
6
+ * How a caller reaches a method, by the names this emitter gave it: the test driver's call plan
7
+ * (G8.4), so a driver invokes the method by reflection without re-deriving a name.
8
+ */
9
+ export type GoMethodCall = {
10
+ readonly operation: string;
11
+ readonly method: string;
12
+ /** the path params by spec name, in signature order */
13
+ readonly pathParams: readonly string[];
14
+ /** the kind of the body parameter that follows them (`goBody`, which also emits it); null without one */
15
+ readonly body: SdkBody["kind"] | null;
16
+ /** each query param by spec name, to its `<Op>Opts` field */
17
+ readonly query: Readonly<Record<string, string>>;
18
+ /** each header param by spec name, to its `<Op>Opts` field */
19
+ readonly headers: Readonly<Record<string, string>>;
20
+ readonly response: SdkResponseKind;
21
+ /**
22
+ * the `<Op>Headers` struct `WithHeadersInto` fills: its type name and each declared response
23
+ * header (as the spec spells it) to its field; null for a method that has none
24
+ */
25
+ readonly responseHeaders: GoResponseHeaders | null;
26
+ readonly stream: SdkStream;
27
+ /** the body parameter's Go type (`goBody`); null without one: the CLI declares the value it decodes into */
28
+ readonly bodyType: string | null;
29
+ /** what the method returns, as its signature spells it: the CLI calls it in that shape */
30
+ readonly returns: string;
31
+ /** the method's `<Op>Opts` type, as claimed (a clash gets a suffix) */
32
+ readonly opts: string;
33
+ /** a multipart body's parts by their `<Op>Body` fields; null for any other body */
34
+ readonly parts: readonly GoPart[] | null;
35
+ };
36
+ /**
37
+ * One operation's method, its client.go declarations by name (`<Op>Opts`, `<Op>Headers`), how a caller reaches it,
38
+ * and its `Client.Safe()` twin.
39
+ */
40
+ export type GoMethod = {
41
+ readonly call: GoMethodCall;
42
+ readonly decls: readonly (readonly [string, string])[];
43
+ readonly lines: readonly string[];
44
+ readonly twin: Twin;
45
+ };
46
+ /** What every method of one SDK shares: the type context it hoists into. */
47
+ export type MethodEnv = {
48
+ readonly at: GoTypeContext;
49
+ };
50
+ /** Where a method lives: its receiver's type, and the expression reaching the `*Client` from it. */
51
+ export type Receiver = {
52
+ readonly type: string;
53
+ readonly client: string;
54
+ };
55
+ /**
56
+ * How a method's `Client.Safe()` twin answers, as the field of its name on the twin struct: `call` a `Result` of the
57
+ * answer, `none` one of `struct{}` (no body), `stream` one of the event stream opened on the call, `conn` the very
58
+ * method (a WebSocket or realtime connection). `params` are the types before `reqOpts`; `answer` is the `T` the field's
59
+ * type takes. The field is the normal method value under a generic wrapper (sdk-client.ts), so the one request path
60
+ * runs and the runtime moves only an answer (an error status, a `*DecodeError`) into `Err`.
61
+ */
62
+ export type Twin = {
63
+ readonly kind: "call" | "conn" | "none" | "stream";
64
+ readonly params: readonly string[];
65
+ readonly answer: string;
66
+ };
67
+ /** The method of `op` named `name` on `receiver`, and its `<Op>Opts` and `<Op>Headers`. */
68
+ export declare function goMethod(op: SdkOp, name: string, receiver: Receiver, env: MethodEnv): GoMethod;
@@ -0,0 +1,172 @@
1
+ import { mediaEssence } from "../../ir/sdk-model.js";
2
+ import { goString, lineComment } from "../shared/escape.js";
3
+ import { goExported, goLocal, NameScope } from "../shared/lang.js";
4
+ import { shapeOf } from "./sdk-answer.js";
5
+ import { goBody } from "./sdk-body.js";
6
+ import { optsDecl, optsFields, optsLines, responseHeaders } from "./sdk-opts.js";
7
+ import { sseStream } from "./sse.js";
8
+ import { goTypeOf } from "./types.js";
9
+ import { socketStream } from "./ws.js";
10
+ /* the receiver, the method's own locals and the unexported runtime names its body calls: a path param never shadows one */
11
+ const METHOD_LOCALS = [
12
+ "c",
13
+ "call",
14
+ "ctx",
15
+ "data",
16
+ "decodeJSON",
17
+ "dialWebSocket",
18
+ "doRequest",
19
+ "err",
20
+ "expandPath",
21
+ "fields",
22
+ "fileField",
23
+ "formBody",
24
+ "jsonBody",
25
+ "key",
26
+ "mp",
27
+ "multipartBody",
28
+ "multipartField",
29
+ "newRealtime",
30
+ "opts",
31
+ "params",
32
+ "path",
33
+ "r",
34
+ "rawBody",
35
+ "readerBody",
36
+ "reqOpts",
37
+ "result",
38
+ "setHeaderValue",
39
+ "setIdempotencyKey",
40
+ "sseFail",
41
+ "streamJSON",
42
+ "streamText",
43
+ "textField",
44
+ "topts",
45
+ "v",
46
+ ];
47
+ /** The operation's path params in the order the path holds them, whatever order they were declared in. */
48
+ function pathParamsOf(op) {
49
+ const order = op.pathSegments.flatMap((segment) => (segment.kind === "param" ? [segment.name] : []));
50
+ return [...op.pathParams].sort((a, b) => order.indexOf(a.name) - order.indexOf(b.name));
51
+ }
52
+ /** How a caller reaches the method `name` of `op`: its path params, body and Opts fields by spec name. */
53
+ function callOf(op, name, path, fields) {
54
+ const by = (at) => Object.fromEntries(fields.filter((field) => field.in === at).map((field) => [field.param, field.name]));
55
+ return {
56
+ body: op.body?.kind ?? null,
57
+ headers: by("header"),
58
+ method: name,
59
+ operation: op.id,
60
+ pathParams: path.map(([param]) => param.name),
61
+ query: by("query"),
62
+ response: op.success.kind,
63
+ stream: op.stream,
64
+ };
65
+ }
66
+ /** The method's godoc: its name and route and its stream's note, then the operation's summary and description. */
67
+ function methodDoc(op, name, stream) {
68
+ const route = [`${name} calls ${op.method} ${op.path}.`, stream?.doc ?? ""].filter((part) => part !== "").join(" ");
69
+ const text = [route, op.summary, op.description].filter((part) => part !== "");
70
+ return lineComment(text.join("\n\n"), "//");
71
+ }
72
+ /** How the method of `op` answers, and its stream: null for an operation that answers once. */
73
+ function answering(op, env) {
74
+ if (op.stream !== null) {
75
+ const stream = op.stream === "sse" ? sseStream(op, env.at) : socketStream(op.stream);
76
+ return { shape: stream.shape, stream };
77
+ }
78
+ const schema = op.success.schema;
79
+ const result = schema && goTypeOf(schema, { ...env.at, fieldName: "Response", parentName: op.id }).replace(/^\*/, "");
80
+ return { shape: shapeOf({ kind: op.success.kind, result }), stream: null };
81
+ }
82
+ /** The statements before `c`: the path expanded from its params, or the template as it is. */
83
+ function pathLines(op, locals, fail) {
84
+ if (locals.length === 0)
85
+ return { lines: [], path: goString(op.path) };
86
+ const params = locals.map(([param, local]) => `${goString(param.name)}: ${local}`).join(", ");
87
+ return {
88
+ lines: [
89
+ `\tparams := map[string]string{${params}}`,
90
+ `\tpath, err := expandPath(${goString(op.path)}, params)`,
91
+ "\tif err != nil {",
92
+ `\t\treturn ${fail}`,
93
+ "\t}",
94
+ ],
95
+ path: "path",
96
+ };
97
+ }
98
+ /** The operation's own headers: Accept for a binary or text answer (a per-call header still wins, G4). */
99
+ function acceptOf(op) {
100
+ const { contentType, kind } = op.success;
101
+ if (kind !== "binary" && kind !== "text")
102
+ return "map[string]string{}";
103
+ return `map[string]string{"Accept": ${goString(mediaEssence(contentType))}}`;
104
+ }
105
+ /** The `call` literal's members: the route, the operation's headers, the body, and the targets a success stales. */
106
+ function callMembers(op, path, body, client) {
107
+ return [
108
+ `method: ${goString(op.method)}`,
109
+ `path: ${path.path}`,
110
+ `operation: ${goString(`${op.method} ${op.path}`)}`,
111
+ `headers: ${acceptOf(op)}`,
112
+ ...(body ? [`body: ${body.send}`] : []),
113
+ ...(op.invalidates.length > 0 ? [`invalidates: []string{${op.invalidates.map(goString).join(", ")}}`] : []),
114
+ `stale: ${client}.stale`,
115
+ ...(path.lines.length > 0 ? ["params: params"] : []),
116
+ ];
117
+ }
118
+ /** The twin of a method of `op` returning `returns`, taking `params` before its RequestOptions. */
119
+ function twinOf(op, returns, params) {
120
+ const answered = returns.slice("(".length, -", error)".length);
121
+ if (op.stream === "ws" || op.stream === "realtime")
122
+ return { answer: answered, kind: "conn", params };
123
+ if (op.stream === "sse")
124
+ return { answer: returns.slice("iter.Seq2[".length, -", error]".length), kind: "stream", params };
125
+ if (returns === "error")
126
+ return { answer: "struct{}", kind: "none", params };
127
+ return { answer: answered, kind: "call", params };
128
+ }
129
+ /** The method of `op` named `name` on `receiver`, and its `<Op>Opts` and `<Op>Headers`. */
130
+ export function goMethod(op, name, receiver, env) {
131
+ const opts = env.at.names.claimConst(`${goExported(op.id)}Opts`);
132
+ const locals = new NameScope(METHOD_LOCALS);
133
+ const bodyLocal = op.body && locals.claim("body");
134
+ const body = op.body && goBody(op, op.body, { at: env.at, local: bodyLocal });
135
+ const pathLocals = pathParamsOf(op).map((param) => [param, locals.claim(goLocal(param.name))]);
136
+ const { shape, stream } = answering(op, env);
137
+ const streamOpts = stream?.opts ?? null;
138
+ const fields = optsFields(op, opts, env.at, streamOpts);
139
+ const path = pathLines(op, pathLocals, shape.fail);
140
+ const headers = responseHeaders(op, env.at);
141
+ const params = [
142
+ "ctx context.Context",
143
+ ...pathLocals.map(([, local]) => `${local} string`),
144
+ ...(body ? [`${bodyLocal} ${body.type}`] : []),
145
+ `opts *${opts}`,
146
+ "reqOpts ...RequestOption",
147
+ ];
148
+ const lines = [
149
+ ...methodDoc(op, name, stream),
150
+ `func (r *${receiver.type}) ${name}(${params.join(", ")}) ${shape.returns} {`,
151
+ ...path.lines,
152
+ ...(body ? body.lines(shape.fail) : []),
153
+ `\tc := &call{${callMembers(op, path, body, receiver.client).join(", ")}}`,
154
+ ...optsLines(op, fields, streamOpts),
155
+ ...shape.tail(receiver.client),
156
+ "}",
157
+ ];
158
+ const decls = [[opts, optsDecl(op, opts, fields, streamOpts)]];
159
+ if (headers)
160
+ decls.push([headers.plan.type, headers.decl]);
161
+ const call = {
162
+ ...callOf(op, name, pathLocals, fields),
163
+ bodyType: body ? body.type : null,
164
+ opts,
165
+ parts: body?.parts ?? null,
166
+ responseHeaders: headers?.plan ?? null,
167
+ returns: shape.returns,
168
+ };
169
+ const types = ["context.Context", ...pathLocals.map(() => "string"), ...(body ? [body.type] : []), `*${opts}`];
170
+ const twin = twinOf(op, shape.returns, types);
171
+ return { call, decls, lines, twin };
172
+ }
@@ -0,0 +1,23 @@
1
+ import type { GoMethod } from "./sdk-method.ts";
2
+ /** A resource struct as the mirror reads it: its name, its child structs by field name, its methods. */
3
+ export type MirrorNode = {
4
+ readonly struct: string;
5
+ readonly fields: readonly {
6
+ readonly name: string;
7
+ readonly node: MirrorNode;
8
+ }[];
9
+ readonly methods: readonly GoMethod[];
10
+ };
11
+ /** A twin field's generic type and the wrapper that makes it from the normal method value (none for a connection). */
12
+ export type TwinType = {
13
+ readonly type: string;
14
+ readonly wrap: string | null;
15
+ };
16
+ /** The twin types `methods` use, by kind and arity, each claimed by `claimConst` once (after every other name). */
17
+ export declare function twinTypes(methods: readonly GoMethod[], claimConst: (base: string) => string): Map<string, TwinType>;
18
+ /** The declarations of the twin types in `types`: each generic func type once, then each wrapper. */
19
+ export declare function twinTypeLines(types: ReadonlyMap<string, TwinType>): string[];
20
+ /** `node`'s safe twin and its children's: each method the field of its name, then each child's struct. */
21
+ export declare function twinLines(node: MirrorNode, twins: ReadonlyMap<MirrorNode, string>, types: ReadonlyMap<string, TwinType>): string[];
22
+ /** The literal of `node`'s twin at `path` (`r.` and its normal chain): each method field over its normal method value. */
23
+ export declare function twinLiteral(node: MirrorNode, path: string, twin: string, types: ReadonlyMap<string, TwinType>): string;
@@ -0,0 +1,97 @@
1
+ /**
2
+ * The Go SDK's safe mirror, `Client.Safe()` (bit 21 i3): a twin struct per resource struct, each method a field of its
3
+ * name holding the normal method value under a generic wrapper that answers a `Result`. The field's type is a generic
4
+ * func type by the arguments before the RequestOptions (`Call<n>` for an answer or none, `Stream<n>` for an event
5
+ * stream opened on the call, `Conn<n>` for a connection, the very method), each declared once its SDK uses it with its
6
+ * wrapper (`call<n>`, `none<n>`, `stream<n>`), so a twin spells its types once and the one request path runs.
7
+ */
8
+ import { compareCodeUnits } from "../shared/lang.js";
9
+ import { lineComment } from "../shared/escape.js";
10
+ /* each kind's type and wrapper base names: none shares call's type, a connection needs no wrapper */
11
+ const TWIN_NAMES = {
12
+ call: ["Call", "call"],
13
+ conn: ["Conn", null],
14
+ none: ["Call", "none"],
15
+ stream: ["Stream", "stream"],
16
+ };
17
+ /** The twin types `methods` use, by kind and arity, each claimed by `claimConst` once (after every other name). */
18
+ export function twinTypes(methods, claimConst) {
19
+ const claimed = new Map();
20
+ const claim = (base) => claimed.get(base) ?? claimed.set(base, claimConst(base)).get(base);
21
+ const types = new Map();
22
+ for (const { twin } of methods) {
23
+ const [type, wrap] = TWIN_NAMES[twin.kind];
24
+ const n = twin.params.length;
25
+ types.set(`${twin.kind} ${n}`, {
26
+ type: claim(`${type}${n}`),
27
+ wrap: wrap === null ? null : claim(`${wrap}${n}`),
28
+ });
29
+ }
30
+ return types;
31
+ }
32
+ /** The declarations of the twin types in `types`: each generic func type once, then each wrapper. */
33
+ export function twinTypeLines(types) {
34
+ const out = [];
35
+ const declared = new Set();
36
+ for (const [key, { type, wrap }] of [...types].sort(([a], [b]) => compareCodeUnits(a, b))) {
37
+ const [kind, count] = key.split(" ");
38
+ const ps = Array.from({ length: Number(count) }, (_, i) => `P${i}`);
39
+ const params = [...ps, "...RequestOption"].join(", ");
40
+ const answer = {
41
+ call: "(Result[T], error)",
42
+ conn: "(T, error)",
43
+ none: "(Result[T], error)",
44
+ stream: "(Result[iter.Seq2[T, error]], error)",
45
+ }[kind];
46
+ if (!declared.has(type)) {
47
+ declared.add(type);
48
+ const what = {
49
+ call: "a Result of T",
50
+ conn: "the connection T itself",
51
+ none: "a Result of T",
52
+ stream: "a Result of the opened event stream of T",
53
+ }[kind];
54
+ out.push("", ...lineComment(`${type} is a Client.Safe() method taking ${count} arguments before its RequestOptions and answering ${what}.`, "//"), `type ${type}[${ps.join(", ")}, T any] func(${params}) ${answer}`);
55
+ }
56
+ if (wrap === null)
57
+ continue;
58
+ const normal = { call: "(T, error)", none: "error", stream: "iter.Seq2[T, error]" }[kind];
59
+ const gen = kind === "none" ? ps.join(", ") : [...ps, "T"].join(", ");
60
+ const result = kind === "none" ? `${type}[${[...ps, "struct{}"].join(", ")}]` : `${type}[${gen}]`;
61
+ const args = ps.map((_, i) => `p${i}`);
62
+ const sent = `f(${[...args, "s.with(o)..."].join(", ")})`;
63
+ const tail = {
64
+ call: [`\t\tv, err := ${sent}`, "\t\treturn safeOf(v, err, &s)"],
65
+ none: [`\t\treturn safeOf(struct{}{}, ${sent}, &s)`],
66
+ stream: [`\t\treturn safeOpen(${sent}, &s)`],
67
+ }[kind];
68
+ const own = [...args.map((arg, i) => `${arg} P${i}`), "o ...RequestOption"].join(", ");
69
+ out.push("", `func ${wrap}[${gen} any](f func(${params}) ${normal}) ${result} {`, `\treturn func(${own}) ${kind === "none" ? "(Result[struct{}], error)" : answer} {`, "\t\tvar s safeCall", ...tail, "\t}", "}");
70
+ }
71
+ return out;
72
+ }
73
+ /** `node`'s safe twin and its children's: each method the field of its name, then each child's struct. */
74
+ export function twinLines(node, twins, types) {
75
+ const struct = (n) => twins.get(n);
76
+ const fields = node.methods.map(({ call, twin }) => {
77
+ const { type } = types.get(`${twin.kind} ${twin.params.length}`);
78
+ return `${call.method} ${type}[${[...twin.params, twin.answer].join(", ")}]`;
79
+ });
80
+ return [
81
+ ...lineComment(`${struct(node)} is ${node.struct} answering as Client.Safe() does: each method a field of its name.`, "//"),
82
+ `type ${struct(node)} struct {`,
83
+ ...fields.map((field) => `\t${field}`),
84
+ ...node.fields.map(({ name, node: child }) => `\t${name} *${struct(child)}`),
85
+ "}",
86
+ ...node.fields.flatMap(({ node: child }) => ["", ...twinLines(child, twins, types)]),
87
+ ];
88
+ }
89
+ /** The literal of `node`'s twin at `path` (`r.` and its normal chain): each method field over its normal method value. */
90
+ export function twinLiteral(node, path, twin, types) {
91
+ const fields = node.methods.map(({ call, twin: t }) => {
92
+ const { wrap } = types.get(`${t.kind} ${t.params.length}`);
93
+ const value = `${path}${call.method}`;
94
+ return `\t\t${call.method}: ${wrap === null ? value : `${wrap}(${value})`},`;
95
+ });
96
+ return fields.length === 0 ? `&${twin}{}` : [`&${twin}{`, ...fields, "\t}"].join("\n");
97
+ }
@@ -0,0 +1,55 @@
1
+ import type { SdkOp } from "../../ir/sdk-model.ts";
2
+ import { type GoTypeContext } from "./types.ts";
3
+ /** One `<Op>Opts` field: its Go name and type, the statement sending it, and the param it carries. */
4
+ export type OptsField = {
5
+ readonly name: string;
6
+ readonly type: string;
7
+ readonly set: string;
8
+ readonly param: string;
9
+ readonly in: "header" | "query";
10
+ };
11
+ /** A stream's own `<Op>Opts` field, after the declared ones; `doc` is its godoc. */
12
+ export type StreamField = {
13
+ readonly name: string;
14
+ readonly type: string;
15
+ readonly doc?: string;
16
+ };
17
+ /**
18
+ * What a stream adds to its `<Op>Opts`: its fields (claimed first, so a declared param that
19
+ * collides gets `…2`), whether a declared param is a channel a field carries (then it has no field
20
+ * of its own), the statements before the opts block, and those in it after the declared params.
21
+ */
22
+ export type StreamOpts = {
23
+ readonly fields: readonly StreamField[];
24
+ readonly carries: (param: string, where: OptsField["in"]) => boolean;
25
+ readonly before: readonly string[];
26
+ readonly sets: readonly string[];
27
+ };
28
+ /** A method's typed response headers, as a caller names them. */
29
+ export type GoResponseHeaders = {
30
+ readonly type: string;
31
+ readonly fields: Readonly<Record<string, string>>;
32
+ };
33
+ /** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
34
+ export declare const takesIdempotencyKey: (op: SdkOp) => boolean;
35
+ /**
36
+ * `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
37
+ * `stream` carries has none.
38
+ */
39
+ export declare function optsFields(op: SdkOp, opts: string, at: GoTypeContext, stream: StreamOpts | null): OptsField[];
40
+ /** `<Op>Opts`: the operation's optional inputs, documented, then `stream`'s own fields. */
41
+ export declare function optsDecl(op: SdkOp, opts: string, fields: readonly OptsField[], stream: StreamOpts | null): string;
42
+ /**
43
+ * The statements applying `opts` to `c`: each set field, then `stream`'s, then the Idempotency-Key
44
+ * (a header already set wins, then `IdempotencyKey`, then a fresh UUID, the same on an auth retry).
45
+ */
46
+ export declare function optsLines(op: SdkOp, fields: readonly OptsField[], stream: StreamOpts | null): string[];
47
+ /**
48
+ * `<Op>Headers` and its `setFrom` (named `type`), and its plan; null when `op` declares no response
49
+ * header, or is a WebSocket or realtime operation, whose 2xx response no caller ever receives (a
50
+ * handshake answers 101, and a realtime connection hands back no response).
51
+ */
52
+ export declare function responseHeaders(op: SdkOp, at: GoTypeContext): {
53
+ readonly plan: GoResponseHeaders;
54
+ readonly decl: string;
55
+ } | null;
@@ -0,0 +1,100 @@
1
+ import { goString, lineComment } from "../shared/escape.js";
2
+ import { compareCodeUnits, goExported, NameScope } from "../shared/lang.js";
3
+ import { isNilable } from "./types-codec.js";
4
+ import { goTypeOf } from "./types.js";
5
+ /* the Opts field an idempotent operation's caller sets its Idempotency-Key through */
6
+ const IDEMPOTENCY_KEY = "IdempotencyKey";
7
+ /** A value's Go type when it may be absent: as is where nil already means unset (H4), else a pointer. */
8
+ const optional = (type, required) => (required || isNilable(type) ? type : `*${type}`);
9
+ /** Whether `op`'s Opts carry `IdempotencyKey`: an idempotent operation that answers once. */
10
+ export const takesIdempotencyKey = (op) => op.idempotent && op.stream === null;
11
+ /**
12
+ * `<Op>Opts`'s param fields: each query param, then each header param, sent unless unset; a param
13
+ * `stream` carries has none.
14
+ */
15
+ export function optsFields(op, opts, at, stream) {
16
+ const own = stream?.fields.map((field) => field.name) ?? [];
17
+ const scope = new NameScope([...(takesIdempotencyKey(op) ? [IDEMPOTENCY_KEY] : []), ...own]);
18
+ const field = (param, where, send) => {
19
+ const name = scope.claim(goExported(param.name));
20
+ const type = goTypeOf(param.schema, { ...at, fieldName: name, parentName: opts });
21
+ return { in: where, name, param: param.name, set: send(name), type: optional(type, param.required === true) };
22
+ };
23
+ const declared = (params, where) => params.filter((param) => stream?.carries(param.name, where) !== true);
24
+ return [
25
+ ...declared(op.query, "query").map((param) => field(param, "query", (name) => `c.query.set(${goString(param.name)}, opts.${name})`)),
26
+ ...declared(op.headers, "header").map((param) => field(param, "header", (name) => `setHeaderValue(c.headers, ${goString(param.name)}, opts.${name})`)),
27
+ ];
28
+ }
29
+ /** `<Op>Opts`: the operation's optional inputs, documented, then `stream`'s own fields. */
30
+ export function optsDecl(op, opts, fields, stream) {
31
+ const own = (stream?.fields ?? []).flatMap((field) => [
32
+ ...(field.doc === undefined ? [] : lineComment(field.doc, "//", "\t")),
33
+ `\t${field.name} ${field.type}`,
34
+ ]);
35
+ return [
36
+ ...lineComment(`${opts} holds the optional parameters of ${op.id}.`, "//"),
37
+ `type ${opts} struct {`,
38
+ ...fields.map((field) => `\t${field.name} ${field.type}`),
39
+ ...own,
40
+ ...(takesIdempotencyKey(op) ? [`\t${IDEMPOTENCY_KEY} string`] : []),
41
+ "}",
42
+ ].join("\n");
43
+ }
44
+ /**
45
+ * The statements applying `opts` to `c`: each set field, then `stream`'s, then the Idempotency-Key
46
+ * (a header already set wins, then `IdempotencyKey`, then a fresh UUID, the same on an auth retry).
47
+ */
48
+ export function optsLines(op, fields, stream) {
49
+ const keyed = takesIdempotencyKey(op);
50
+ const sets = [
51
+ ...(keyed ? [`key = opts.${IDEMPOTENCY_KEY}`] : []),
52
+ ...fields.map((field) => field.set),
53
+ ...(stream?.sets ?? []),
54
+ ];
55
+ return [
56
+ ...(keyed ? ["\tvar key string"] : []),
57
+ ...(stream?.before ?? []).map((line) => `\t${line}`),
58
+ ...(sets.length > 0 ? ["\tif opts != nil {", ...sets.map((set) => `\t\t${set}`), "\t}"] : []),
59
+ ...(keyed ? ["\tsetIdempotencyKey(c.headers, key)"] : []),
60
+ ];
61
+ }
62
+ /** The headers `op`'s 2xx responses declare, statuses ascending, a name's first spelling (any casing) kept; by name. */
63
+ function declaredHeaders(op) {
64
+ const all = Object.keys(op.ir.responses)
65
+ .filter((status) => /^2(?:\d\d|XX)$/i.test(status))
66
+ .sort(compareCodeUnits)
67
+ .flatMap((status) => op.ir.responses[status].headers ?? []);
68
+ /* reversed, so the first spelling of a name is the one its key ends on */
69
+ const first = new Map(all.toReversed().map((header) => [header.name.toLowerCase(), header]));
70
+ return [...first.values()].sort((a, b) => compareCodeUnits(a.name, b.name));
71
+ }
72
+ /**
73
+ * `<Op>Headers` and its `setFrom` (named `type`), and its plan; null when `op` declares no response
74
+ * header, or is a WebSocket or realtime operation, whose 2xx response no caller ever receives (a
75
+ * handshake answers 101, and a realtime connection hands back no response).
76
+ */
77
+ export function responseHeaders(op, at) {
78
+ const headers = op.stream === "ws" || op.stream === "realtime" ? [] : declaredHeaders(op);
79
+ if (headers.length === 0)
80
+ return null;
81
+ const type = at.names.claimConst(`${goExported(op.id)}Headers`);
82
+ const scope = new NameScope();
83
+ const fields = headers.map((header) => {
84
+ const name = scope.claim(goExported(header.name));
85
+ const use = goTypeOf(header.schema, { ...at, fieldName: name, parentName: type });
86
+ return { header: header.name, name, type: optional(use, header.required) };
87
+ });
88
+ const decl = [
89
+ ...lineComment(`${type} holds the response headers of ${op.id}; WithHeadersInto fills it from a 2xx response.`, "//"),
90
+ `type ${type} struct {`,
91
+ ...fields.map((field) => `\t${field.name} ${field.type}`),
92
+ "}",
93
+ "",
94
+ `func (h *${type}) setFrom(hd http.Header) {`,
95
+ ...fields.map((field) => `\tsetHeaderField(hd, ${goString(field.header)}, &h.${field.name})`),
96
+ "}",
97
+ ].join("\n");
98
+ const plan = { fields: Object.fromEntries(fields.map((field) => [field.header, field.name])), type };
99
+ return { decl, plan };
100
+ }