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

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 +135 -5
@@ -0,0 +1,177 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! An SSE operation's answer: the open event stream, each event's data as the operation declares
3
+ //! it (text, or JSON decoded into `T`). An error status at the open fails with its answer, which the
4
+ //! call's style settles; a failure once open is the stream's own. No timeout bounds it once open;
5
+ //! the call's `cancel_on` ends it quietly, and dropping it closes the connection.
6
+
7
+ use std::collections::VecDeque;
8
+ use std::pin::Pin;
9
+ use std::sync::Arc;
10
+ use std::task::{Context, Poll};
11
+
12
+ use bytes::Bytes;
13
+ use futures_util::{FutureExt, Stream};
14
+ use serde::de::DeserializeOwned;
15
+
16
+ use crate::answer::error_status;
17
+ use crate::call::{BoxFuture, Overrides, RawResponse, Signal};
18
+ use crate::config::Inner;
19
+ use crate::errors::Error;
20
+ use crate::exchange::open;
21
+ use crate::request::RequestSpec;
22
+ use crate::result::Failed;
23
+ use crate::sse::{SseEvent, SseParser};
24
+
25
+ type Chunks = Pin<Box<dyn Stream<Item = reqwest::Result<Bytes>> + Send>>;
26
+
27
+ /// The events of an open stream, in order; it ends when the server closes it, after the first
28
+ /// error it yields (a cap, a transport failure, data that is not `T`), or when the call's
29
+ /// `cancel_on` fires. Read it with `next().await`, or as a `futures_util::Stream`.
30
+ pub struct EventStream<T> {
31
+ chunks: Chunks,
32
+ parser: SseParser,
33
+ ready: VecDeque<SseEvent>,
34
+ failed: Option<Error>,
35
+ decode: fn(String) -> Result<T, Error>,
36
+ cancel: Option<Signal>,
37
+ done: bool,
38
+ /* the id of the last event handed out: a resume from it skips nothing */
39
+ delivered: String,
40
+ }
41
+
42
+ impl<T> EventStream<T> {
43
+ /// The next event; `None` once the stream ended.
44
+ pub async fn next(&mut self) -> Option<Result<SseEvent<T>, Error>> {
45
+ std::future::poll_fn(|cx| Pin::new(&mut *self).poll_next(cx)).await
46
+ }
47
+
48
+ /// The id of the last event delivered, to resume from with `Last-Event-ID`.
49
+ pub fn last_event_id(&self) -> &str {
50
+ &self.delivered
51
+ }
52
+
53
+ /// Ends the stream: no further event, and the connection is let go.
54
+ pub(crate) fn end(&mut self) {
55
+ self.done = true;
56
+ self.ready.clear();
57
+ self.failed = None;
58
+ self.cancel = None;
59
+ self.chunks = Box::pin(futures_util::stream::empty());
60
+ }
61
+
62
+ fn event(&self, e: SseEvent) -> Result<SseEvent<T>, Error> {
63
+ let SseEvent {
64
+ data,
65
+ event,
66
+ id,
67
+ retry,
68
+ } = e;
69
+ Ok(SseEvent {
70
+ data: (self.decode)(data)?,
71
+ event,
72
+ id,
73
+ retry,
74
+ })
75
+ }
76
+ }
77
+
78
+ impl<T> Stream for EventStream<T> {
79
+ type Item = Result<SseEvent<T>, Error>;
80
+
81
+ fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
82
+ loop {
83
+ if self
84
+ .cancel
85
+ .as_mut()
86
+ .is_some_and(|c| c.poll_unpin(cx).is_ready())
87
+ {
88
+ self.end();
89
+ }
90
+ if let Some(e) = self.ready.pop_front() {
91
+ let event = self.event(e);
92
+ if let Ok(delivered) = &event {
93
+ self.delivered.clone_from(&delivered.id);
94
+ }
95
+ if event.is_err() {
96
+ /* data that is not the declared type ends the stream: never a silent skip */
97
+ self.end();
98
+ }
99
+ return Poll::Ready(Some(event));
100
+ }
101
+ if let Some(e) = self.failed.take() {
102
+ self.end();
103
+ return Poll::Ready(Some(Err(e)));
104
+ }
105
+ if self.done {
106
+ return Poll::Ready(None);
107
+ }
108
+ match self.chunks.as_mut().poll_next(cx) {
109
+ Poll::Pending => return Poll::Pending,
110
+ /* a final event without its blank line is never dispatched */
111
+ Poll::Ready(None) => self.end(),
112
+ Poll::Ready(Some(Ok(chunk))) => {
113
+ let (events, failed) = self.parser.feed(&chunk);
114
+ self.ready.extend(events);
115
+ self.failed = failed;
116
+ }
117
+ Poll::Ready(Some(Err(e))) => self.failed = Some(Error::from_reqwest(e)),
118
+ }
119
+ }
120
+ }
121
+ }
122
+
123
+ fn text_data(data: String) -> Result<String, Error> {
124
+ Ok(data)
125
+ }
126
+
127
+ fn json_data<T: DeserializeOwned>(data: String) -> Result<T, Error> {
128
+ serde_json::from_str(&data).map_err(Error::decode)
129
+ }
130
+
131
+ /// Opens the stream of `spec`, its events read by `decode`.
132
+ fn opened<T: Send + 'static>(
133
+ inner: Arc<Inner>,
134
+ mut spec: RequestSpec,
135
+ ov: Overrides,
136
+ decode: fn(String) -> Result<T, Error>,
137
+ ) -> BoxFuture<Result<(EventStream<T>, RawResponse), Failed>> {
138
+ Box::pin(async move {
139
+ spec.accept("text/event-stream");
140
+ let answer = open(&inner, &mut spec, &ov).await?;
141
+ let Some(response) = answer.live else {
142
+ return Err(error_status(answer.raw));
143
+ };
144
+ let raw = answer.raw;
145
+ let stream = EventStream {
146
+ chunks: Box::pin(response.bytes_stream()),
147
+ parser: SseParser::default(),
148
+ ready: VecDeque::new(),
149
+ failed: None,
150
+ decode,
151
+ cancel: ov.cancel.clone(),
152
+ done: false,
153
+ delivered: String::new(),
154
+ };
155
+ Ok((stream, raw))
156
+ })
157
+ }
158
+
159
+ /// An SSE operation whose events carry text.
160
+ #[allow(dead_code)] // an SDK opens the event kinds its operations declare
161
+ pub(crate) fn text(
162
+ inner: Arc<Inner>,
163
+ spec: RequestSpec,
164
+ ov: Overrides,
165
+ ) -> BoxFuture<Result<(EventStream<String>, RawResponse), Failed>> {
166
+ opened(inner, spec, ov, text_data)
167
+ }
168
+
169
+ /// An SSE operation whose events carry JSON `T`.
170
+ #[allow(dead_code)] // an SDK opens the event kinds its operations declare
171
+ pub(crate) fn json<T: DeserializeOwned + Send + 'static>(
172
+ inner: Arc<Inner>,
173
+ spec: RequestSpec,
174
+ ov: Overrides,
175
+ ) -> BoxFuture<Result<(EventStream<T>, RawResponse), Failed>> {
176
+ opened(inner, spec, ov, json_data::<T>)
177
+ }
@@ -0,0 +1,287 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! The exchange every call shares: the URL, the header layers, the hooks in declaration order, one
3
+ //! retry with a refreshed token on a 401, the capped body read, the timeout, the log and the stale
4
+ //! tracker. A body past the cap is still an answer: its status and headers arrived, its body unread.
5
+
6
+ use bytes::Bytes;
7
+ use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
8
+
9
+ use crate::auth::new_v4;
10
+ use crate::body::Content;
11
+ use crate::call::{Overrides, RawResponse};
12
+ use crate::config::{Inner, parse_base};
13
+ use crate::errors::{ApiError, Error};
14
+ use crate::hooks::{RequestContext, ResponseContext};
15
+ use crate::invalidation::RequestMeta;
16
+ use crate::log::CallLog;
17
+ use crate::redirect::{Hop, send_following};
18
+ use crate::request::RequestSpec;
19
+
20
+ /// The most of an error body a stream reads.
21
+ const STREAM_ERROR_BYTES: usize = 64 << 10;
22
+
23
+ /// The call's URL: the base (the call's or the client's) with its path and query, then the call's.
24
+ pub(crate) fn url_of(
25
+ inner: &Inner,
26
+ spec: &RequestSpec,
27
+ ov: &Overrides,
28
+ ) -> Result<reqwest::Url, Error> {
29
+ let mut url = match &ov.base_url {
30
+ Some(base) => parse_base(base, "the call's base_url")?,
31
+ None => inner.base_url.clone(),
32
+ };
33
+ let path = format!("{}{}", url.path().trim_end_matches('/'), spec.path);
34
+ url.set_path(&path);
35
+ url.set_fragment(None);
36
+ if !spec.query.is_empty() {
37
+ url.query_pairs_mut().extend_pairs(&spec.query);
38
+ }
39
+ Ok(url)
40
+ }
41
+
42
+ fn set(headers: &mut HeaderMap, name: &str, value: &str) -> Result<(), Error> {
43
+ let name = HeaderName::from_bytes(name.as_bytes())
44
+ .map_err(|_| Error::Config(format!("{name:?} is not a valid header name")))?;
45
+ let value = HeaderValue::from_str(value).map_err(|_| {
46
+ Error::Config(format!(
47
+ "the {name} header's value is not valid in a header"
48
+ ))
49
+ })?;
50
+ headers.insert(name, value);
51
+ Ok(())
52
+ }
53
+
54
+ /// The headers, each layer over the last: the body's type, the client's, the operation's, the call's,
55
+ /// then the credential (marked sensitive), and an `X-Request-Id` unless one is set.
56
+ pub(crate) fn headers_of(
57
+ inner: &Inner,
58
+ spec: &RequestSpec,
59
+ ov: &Overrides,
60
+ token: Option<&str>,
61
+ ) -> Result<HeaderMap, Error> {
62
+ let mut headers = HeaderMap::new();
63
+ if let Some(media) = &spec.content_type {
64
+ set(&mut headers, "Content-Type", media)?;
65
+ }
66
+ for (name, value) in inner.headers.iter().chain(&spec.headers).chain(&ov.headers) {
67
+ set(&mut headers, name, value)?;
68
+ }
69
+ if let Some(token) = token {
70
+ let mut value = HeaderValue::from_str(&format!("{}{token}", inner.auth_prefix))
71
+ .map_err(|_| Error::Config("the credential is not valid in a header".into()))?;
72
+ value.set_sensitive(true);
73
+ headers.insert(inner.auth_header.clone(), value);
74
+ }
75
+ if !headers.contains_key("x-request-id") {
76
+ set(&mut headers, "X-Request-Id", &new_v4())?;
77
+ }
78
+ Ok(headers)
79
+ }
80
+
81
+ /// An answer: buffered (`over`: its body ran past the cap and is empty), or for a stream's 2xx the
82
+ /// live response with its body unread.
83
+ pub(crate) struct Answer {
84
+ pub(crate) raw: RawResponse,
85
+ pub(crate) live: Option<reqwest::Response>,
86
+ pub(crate) over: bool,
87
+ }
88
+
89
+ /// One exchange in flight.
90
+ struct Exchange<'a> {
91
+ inner: &'a Inner,
92
+ spec: &'a mut RequestSpec,
93
+ ov: &'a Overrides,
94
+ meta: RequestMeta,
95
+ stream: bool,
96
+ }
97
+
98
+ /// Sends `spec` and reads its answer whole, whatever its status; past the cap it is empty.
99
+ pub(crate) async fn send(
100
+ inner: &Inner,
101
+ spec: &mut RequestSpec,
102
+ ov: &Overrides,
103
+ ) -> Result<Answer, Error> {
104
+ run(inner, spec, ov, false).await
105
+ }
106
+
107
+ /// Sends `spec` for a stream: a 2xx comes back unread, the timeout bounding it only up to its headers.
108
+ pub(crate) async fn open(
109
+ inner: &Inner,
110
+ spec: &mut RequestSpec,
111
+ ov: &Overrides,
112
+ ) -> Result<Answer, Error> {
113
+ run(inner, spec, ov, true).await
114
+ }
115
+
116
+ async fn run(
117
+ inner: &Inner,
118
+ spec: &mut RequestSpec,
119
+ ov: &Overrides,
120
+ stream: bool,
121
+ ) -> Result<Answer, Error> {
122
+ let mut log = CallLog::new(inner.on_log.as_ref(), spec.operation());
123
+ if let Some(e) = spec.failed.take() {
124
+ log.failed(&e);
125
+ return Err(e);
126
+ }
127
+ log.started();
128
+ /* a stream's answer is its headers (the body is read later), so this bounds only its open */
129
+ let timeout = ov.timeout.or(inner.timeout).filter(|d| !d.is_zero());
130
+ let meta = inner.stale.begin(spec.method.as_str(), &spec.path);
131
+ let mut x = Exchange {
132
+ inner,
133
+ spec,
134
+ ov,
135
+ meta,
136
+ stream,
137
+ };
138
+ let answer = match timeout {
139
+ Some(d) => tokio::time::timeout(d, x.with_auth())
140
+ .await
141
+ .unwrap_or(Err(Error::Timeout)),
142
+ None => x.with_auth().await,
143
+ };
144
+ match &answer {
145
+ Ok(Answer { raw, .. }) => {
146
+ log.answered(raw.status);
147
+ if (200..300).contains(&raw.status) {
148
+ inner
149
+ .stale
150
+ .settle(&x.meta, x.spec.invalidates, &x.spec.params);
151
+ } else if inner.on_log.is_some() {
152
+ /* an error status logs the error its call ends with, as Go's does */
153
+ log.failed(&Error::Api(ApiError::new(
154
+ raw.status,
155
+ raw.headers.clone(),
156
+ raw.body.clone(),
157
+ )));
158
+ }
159
+ }
160
+ Err(e) => log.failed(e),
161
+ }
162
+ answer
163
+ }
164
+
165
+ pub(crate) async fn token_of(inner: &Inner, ov: &Overrides) -> Option<String> {
166
+ match &ov.token {
167
+ Some(token) => token.clone(),
168
+ None => inner.auth.current().await,
169
+ }
170
+ }
171
+
172
+ impl Exchange<'_> {
173
+ /// One send, and one more with a refreshed token when a replayable request got a 401.
174
+ async fn with_auth(&mut self) -> Result<Answer, Error> {
175
+ let token = token_of(self.inner, self.ov).await;
176
+ /* read before the first send, which takes a streamed body out of the spec */
177
+ let replayable = self.spec.replayable();
178
+ let first = self.attempt(token.as_deref(), false).await?;
179
+ let hook = match &self.inner.on_auth_expired {
180
+ Some(hook) if first.raw.status == 401 && replayable && self.ov.token.is_none() => hook,
181
+ _ => return Ok(first),
182
+ };
183
+ match self.inner.auth.refresh(hook, token.as_deref()).await? {
184
+ Some(fresh) => self.attempt(Some(&fresh), true).await,
185
+ None => Ok(first),
186
+ }
187
+ }
188
+
189
+ async fn attempt(&mut self, token: Option<&str>, is_retry: bool) -> Result<Answer, Error> {
190
+ let (inner, meta) = (self.inner, &self.meta);
191
+ let url = url_of(inner, self.spec, self.ov)?;
192
+ let headers = headers_of(inner, self.spec, self.ov, token)?;
193
+ let body = self.spec.take_body();
194
+ let (bytes, streamed) = match body.map(|b| b.0) {
195
+ Some(Content::Bytes(b)) => (Some(b), None),
196
+ Some(Content::Stream(s)) => (None, Some(s)),
197
+ None => (None, None),
198
+ };
199
+ let mut ctx = RequestContext {
200
+ method: self.spec.method.clone(),
201
+ url,
202
+ path: self.spec.path.clone(),
203
+ headers,
204
+ body: bytes,
205
+ is_retry,
206
+ selector: meta.selector.clone(),
207
+ is_stale: meta.is_stale,
208
+ invalidated_by: meta.invalidated_by.clone(),
209
+ state: inner.state.clone(),
210
+ };
211
+ for hook in &inner.on_request {
212
+ hook(&mut ctx).await?;
213
+ }
214
+ let body = match streamed {
215
+ Some(stream) => Some(Content::Stream(stream)),
216
+ None => ctx.body.map(Content::Bytes),
217
+ };
218
+ let hop = Hop {
219
+ method: ctx.method,
220
+ url: ctx.url,
221
+ headers: ctx.headers,
222
+ body,
223
+ };
224
+ let (response, url) = send_following(&inner.http, inner.redirect, hop).await?;
225
+ self.answer(response, url, is_retry).await
226
+ }
227
+
228
+ /// The answer after the `on_response` hooks; a stream's 2xx body stays unread.
229
+ async fn answer(
230
+ &self,
231
+ response: reqwest::Response,
232
+ url: reqwest::Url,
233
+ is_retry: bool,
234
+ ) -> Result<Answer, Error> {
235
+ let status = response.status().as_u16();
236
+ let headers = response.headers().clone();
237
+ let unread = self.stream && (200..300).contains(&status);
238
+ let (body, live) = if unread {
239
+ (Some(Bytes::new()), Some(response))
240
+ } else {
241
+ let limit = if self.stream {
242
+ STREAM_ERROR_BYTES
243
+ } else {
244
+ self.inner.max_response_bytes
245
+ };
246
+ (read_capped(response, limit).await?, None)
247
+ };
248
+ let over = body.is_none();
249
+ let meta = &self.meta;
250
+ let mut ctx = ResponseContext {
251
+ status,
252
+ headers,
253
+ body: body.unwrap_or_default(),
254
+ is_retry,
255
+ selector: meta.selector.clone(),
256
+ is_stale: meta.is_stale,
257
+ invalidated_by: meta.invalidated_by.clone(),
258
+ state: self.inner.state.clone(),
259
+ };
260
+ for hook in &self.inner.on_response {
261
+ hook(&mut ctx).await?;
262
+ }
263
+ let body = if unread { Bytes::new() } else { ctx.body };
264
+ let raw = RawResponse {
265
+ status,
266
+ url,
267
+ headers: ctx.headers,
268
+ body,
269
+ };
270
+ Ok(Answer { raw, live, over })
271
+ }
272
+ }
273
+
274
+ /// The body; `None` past `limit` bytes (zero: no limit), read no further.
275
+ async fn read_capped(
276
+ mut response: reqwest::Response,
277
+ limit: usize,
278
+ ) -> Result<Option<Bytes>, Error> {
279
+ let mut out = Vec::new();
280
+ while let Some(chunk) = response.chunk().await.map_err(Error::from_reqwest)? {
281
+ if limit > 0 && out.len() + chunk.len() > limit {
282
+ return Ok(None);
283
+ }
284
+ out.extend_from_slice(&chunk);
285
+ }
286
+ Ok(Some(Bytes::from(out)))
287
+ }
@@ -0,0 +1,63 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! The caller's async hooks (TypeScript parity): `on_request` before each send, `on_response` on
3
+ //! each answer, `on_auth_expired` on a 401, and the `state` map every hook of a client shares.
4
+
5
+ use std::collections::HashMap;
6
+ use std::future::Future;
7
+ use std::pin::Pin;
8
+ use std::sync::Arc;
9
+
10
+ use bytes::Bytes;
11
+ use reqwest::header::HeaderMap;
12
+
13
+ use crate::errors::Error;
14
+
15
+ /// The map every hook of one client shares: `ClientConfig::state`, or a fresh one per client.
16
+ pub type HookState = Arc<tokio::sync::Mutex<HashMap<String, serde_json::Value>>>;
17
+
18
+ /// What a hook returns: `Err` ends the call with that error.
19
+ pub type HookFuture<'a> = Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'a>>;
20
+
21
+ /// Runs before each send, in declaration order; it may change the method, URL, headers or body.
22
+ pub type OnRequestHook =
23
+ Arc<dyn for<'a> Fn(&'a mut RequestContext) -> HookFuture<'a> + Send + Sync>;
24
+
25
+ /// Runs on each answer before it is decoded, in declaration order; it may replace the body.
26
+ pub type OnResponseHook =
27
+ Arc<dyn for<'a> Fn(&'a mut ResponseContext) -> HookFuture<'a> + Send + Sync>;
28
+
29
+ /// Called on a 401 with the token it rejected: `Some(token)` retries the call once with it (and
30
+ /// later calls use it), `None` gives up. Concurrent 401s share one call. A streamed body is never
31
+ /// retried.
32
+ pub type OnAuthExpiredHook = Arc<
33
+ dyn Fn(Option<String>) -> Pin<Box<dyn Future<Output = Result<Option<String>, Error>> + Send>>
34
+ + Send
35
+ + Sync,
36
+ >;
37
+
38
+ /// A request about to be sent. `body` is `None` for a streamed body. `selector`, `is_stale` and
39
+ /// `invalidated_by` are set when invalidation is on.
40
+ pub struct RequestContext {
41
+ pub method: reqwest::Method,
42
+ pub url: reqwest::Url,
43
+ pub path: String,
44
+ pub headers: HeaderMap,
45
+ pub body: Option<Bytes>,
46
+ pub is_retry: bool,
47
+ pub selector: String,
48
+ pub is_stale: bool,
49
+ pub invalidated_by: Vec<String>,
50
+ pub state: HookState,
51
+ }
52
+
53
+ /// An answer before it is decoded. A stream's 2xx body is not read: `body` is empty for it.
54
+ pub struct ResponseContext {
55
+ pub status: u16,
56
+ pub headers: HeaderMap,
57
+ pub body: Bytes,
58
+ pub is_retry: bool,
59
+ pub selector: String,
60
+ pub is_stale: bool,
61
+ pub invalidated_by: Vec<String>,
62
+ pub state: HookState,
63
+ }
@@ -0,0 +1,84 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! Invalidation targets (`METHOD /path`): their placeholders filled from a call's path params, and
3
+ //! a concrete path matched against a templated one segment by segment (G19: no regex).
4
+
5
+ use std::time::Duration;
6
+
7
+ use crate::path::{colon_name, expand_path};
8
+
9
+ /// Turns on stale tracking: a call's declared targets are stale for `stale_time` after it succeeds,
10
+ /// and the hooks of a read of one see it. A zero `stale_time` disables it. `stale_max_entries` caps
11
+ /// the tracked selectors (1000 when zero), `max_sources_per_target` the mutations recorded per
12
+ /// selector (16 when zero).
13
+ #[derive(Debug, Clone, Default)]
14
+ pub struct InvalidationConfig {
15
+ pub stale_time: Duration,
16
+ pub stale_max_entries: usize,
17
+ pub max_sources_per_target: usize,
18
+ }
19
+
20
+ /// A request's staleness when it starts, as its hooks see it.
21
+ #[derive(Debug, Clone, Default)]
22
+ pub(crate) struct RequestMeta {
23
+ pub(crate) selector: String,
24
+ pub(crate) is_stale: bool,
25
+ pub(crate) invalidated_by: Vec<String>,
26
+ pub(crate) seq: u64,
27
+ }
28
+
29
+ /// Whether a path segment is a placeholder: `{name}` inside it, or a whole `:name`.
30
+ fn is_placeholder(segment: &str) -> bool {
31
+ colon_name(segment).is_some() || segment.contains('{') && segment.contains('}')
32
+ }
33
+
34
+ pub(crate) fn has_placeholders(path: &str) -> bool {
35
+ path.split('/').any(is_placeholder)
36
+ }
37
+
38
+ /// Whether `text` (one segment, non-empty) matches `pattern`, each `{name}` in it standing for one
39
+ /// or more characters.
40
+ fn segment_matches(text: &str, pattern: &str) -> bool {
41
+ let Some(open) = pattern.find('{') else {
42
+ return text == pattern;
43
+ };
44
+ let Some(close) = pattern[open..].find('}').map(|c| open + c) else {
45
+ return text == pattern;
46
+ };
47
+ let (prefix, rest) = (&pattern[..open], &pattern[close + 1..]);
48
+ let Some(tail) = text.strip_prefix(prefix) else {
49
+ return false;
50
+ };
51
+ (1..=tail.len())
52
+ .filter(|&i| tail.is_char_boundary(i))
53
+ .any(|i| segment_matches(&tail[i..], rest))
54
+ }
55
+
56
+ /// Whether `path` matches the templated `pattern`, segment by segment.
57
+ pub(crate) fn matches_pattern(path: &str, pattern: &str) -> bool {
58
+ if path == pattern {
59
+ return true;
60
+ }
61
+ let (got, want): (Vec<&str>, Vec<&str>) =
62
+ (path.split('/').collect(), pattern.split('/').collect());
63
+ got.len() == want.len()
64
+ && got.iter().zip(&want).all(|(g, w)| match colon_name(w) {
65
+ Some(_) => !g.is_empty(),
66
+ None => segment_matches(g, w),
67
+ })
68
+ }
69
+
70
+ /// Each target with its placeholders filled from `params`; one that cannot be filled stays a
71
+ /// pattern, so it stales every instance (TypeScript parity).
72
+ pub(crate) fn resolve_targets(targets: &[&str], params: &[(&str, String)]) -> Vec<String> {
73
+ let params: Vec<(&str, &str)> = params.iter().map(|(k, v)| (*k, v.as_str())).collect();
74
+ targets
75
+ .iter()
76
+ .map(|target| match target.split_once(' ') {
77
+ Some((method, path)) if has_placeholders(path) => match expand_path(path, &params) {
78
+ Ok(concrete) => format!("{method} {concrete}"),
79
+ Err(_) => (*target).to_owned(),
80
+ },
81
+ _ => (*target).to_owned(),
82
+ })
83
+ .collect()
84
+ }
@@ -0,0 +1,88 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! Lifecycle log entries for `on_log`. The SDK never formats, levels or persists them, and no
3
+ //! entry carries a path value, header value or query: `operation` is `METHOD /template`.
4
+
5
+ use std::sync::Arc;
6
+ use std::time::Instant;
7
+
8
+ use crate::errors::Error;
9
+
10
+ /// One lifecycle event of a call: `request_start`, `response_received` or `error`.
11
+ #[derive(Debug, Clone, PartialEq, Eq)]
12
+ pub struct LogEntry {
13
+ pub level: &'static str,
14
+ pub event: &'static str,
15
+ pub operation: String,
16
+ pub duration_ms: u64,
17
+ /// the answer's status; `None` when no answer arrived
18
+ pub status: Option<u16>,
19
+ /// the failure, for the `error` event
20
+ pub error: Option<String>,
21
+ }
22
+
23
+ /// Receives each `LogEntry`; a panic in it is caught, so a faulty logger cannot break a call.
24
+ pub type OnLogHook = Arc<dyn Fn(LogEntry) + Send + Sync>;
25
+
26
+ /// One call's log: its operation, when it started, and whether it is in flight. A call dropped in
27
+ /// flight (`cancel_on`, a caller's own timeout, a dropped future) logs its `error` entry as it goes.
28
+ pub(crate) struct CallLog<'a> {
29
+ hook: Option<&'a OnLogHook>,
30
+ operation: String,
31
+ start: Instant,
32
+ in_flight: bool,
33
+ }
34
+
35
+ impl<'a> CallLog<'a> {
36
+ pub(crate) fn new(hook: Option<&'a OnLogHook>, operation: String) -> Self {
37
+ CallLog {
38
+ hook,
39
+ operation,
40
+ start: Instant::now(),
41
+ in_flight: false,
42
+ }
43
+ }
44
+
45
+ fn emit(
46
+ &self,
47
+ level: &'static str,
48
+ event: &'static str,
49
+ status: Option<u16>,
50
+ error: Option<String>,
51
+ ) {
52
+ let Some(hook) = self.hook else { return };
53
+ let entry = LogEntry {
54
+ level,
55
+ event,
56
+ operation: self.operation.clone(),
57
+ duration_ms: self.start.elapsed().as_millis() as u64,
58
+ status,
59
+ error,
60
+ };
61
+ let hook = Arc::clone(hook);
62
+ let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(move || hook(entry)));
63
+ }
64
+
65
+ pub(crate) fn started(&mut self) {
66
+ self.in_flight = true;
67
+ self.emit("debug", "request_start", None, None);
68
+ }
69
+
70
+ pub(crate) fn answered(&mut self, status: u16) {
71
+ self.in_flight = false;
72
+ let level = if status >= 400 { "warn" } else { "info" };
73
+ self.emit(level, "response_received", Some(status), None);
74
+ }
75
+
76
+ pub(crate) fn failed(&mut self, e: &Error) {
77
+ self.in_flight = false;
78
+ self.emit("error", "error", e.status(), Some(e.to_string()));
79
+ }
80
+ }
81
+
82
+ impl Drop for CallLog<'_> {
83
+ fn drop(&mut self) {
84
+ if self.in_flight {
85
+ self.emit("error", "error", None, Some(Error::Canceled.to_string()));
86
+ }
87
+ }
88
+ }