@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,254 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! The client and its configuration: `Client::new` (emitted per API) builds one from a
3
+ //! `ClientConfig`, defaulting `base_url` to the API's first server.
4
+
5
+ use std::collections::HashMap;
6
+ use std::fmt;
7
+ use std::marker::PhantomData;
8
+ use std::sync::Arc;
9
+ use std::time::Duration;
10
+
11
+ use reqwest::header::HeaderName;
12
+
13
+ use crate::auth::AuthState;
14
+ use crate::errors::Error;
15
+ use crate::hooks::{HookState, OnAuthExpiredHook, OnRequestHook, OnResponseHook};
16
+ use crate::invalidation::InvalidationConfig;
17
+ use crate::log::OnLogHook;
18
+ use crate::redirect::RedirectPolicy;
19
+ use crate::result::{Safe, Throw};
20
+ use crate::stale::StaleTracker;
21
+
22
+ /// A regular call's timeout when `ClientConfig::timeout` is `None`.
23
+ const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);
24
+
25
+ /// The client-wide settings; `..Default::default()` fills the rest.
26
+ ///
27
+ /// `timeout` bounds a whole regular call, reading the answer included (`None`: 30 s; zero: none),
28
+ /// and a stream up to its headers, never its events. `max_response_bytes` caps a buffered answer (100 MiB; zero: no
29
+ /// cap). `bearer_token` (else `api_key`) is the credential, sent as `auth_header_name:
30
+ /// auth_header_prefix + token`; leave both `None` for the API's scheme, set the name and the prefix
31
+ /// is yours (`None` meaning none), set only the prefix to keep the scheme's header. `http_builder`
32
+ /// customizes the transport; the SDK always turns its redirects off and applies `redirect` itself.
33
+ /// `ws_keepalive` is a WebSocket's ping interval and pong wait (`None`: 20 s; zero: none).
34
+ ///
35
+ /// Credentials belong here, in `bearer_token`, `api_key` and `headers`: a hop to another origin
36
+ /// carries none of them. reqwest adds a header from the builder's `default_headers` to every hop
37
+ /// after the SDK strips, a cross-origin redirect included, so never put `Authorization`, `Cookie`,
38
+ /// `Proxy-Authorization`, `X-Api-Key` or the `auth_header_name` header there.
39
+ pub struct ClientConfig {
40
+ pub base_url: String,
41
+ pub bearer_token: Option<String>,
42
+ pub api_key: Option<String>,
43
+ pub auth_header_name: Option<String>,
44
+ pub auth_header_prefix: Option<String>,
45
+ pub headers: HashMap<String, String>,
46
+ pub timeout: Option<Duration>,
47
+ pub max_response_bytes: usize,
48
+ pub ws_keepalive: Option<Duration>,
49
+ pub redirect: RedirectPolicy,
50
+ /// The transport's builder. Its `default_headers` go on every hop, a cross-origin redirect
51
+ /// included: `Authorization`, `Cookie`, `Proxy-Authorization`, `X-Api-Key` or the
52
+ /// `auth_header_name` header set there leaks; set credentials in `bearer_token`, `api_key` and
53
+ /// `headers`, which the SDK strips from a hop to another origin.
54
+ pub http_builder: Option<reqwest::ClientBuilder>,
55
+ pub invalidation: Option<InvalidationConfig>,
56
+ pub on_request: Vec<OnRequestHook>,
57
+ pub on_response: Vec<OnResponseHook>,
58
+ pub on_auth_expired: Option<OnAuthExpiredHook>,
59
+ pub on_log: Option<OnLogHook>,
60
+ pub state: Option<HookState>,
61
+ }
62
+
63
+ impl Default for ClientConfig {
64
+ fn default() -> Self {
65
+ ClientConfig {
66
+ base_url: String::new(),
67
+ bearer_token: None,
68
+ api_key: None,
69
+ auth_header_name: None,
70
+ auth_header_prefix: None,
71
+ headers: HashMap::new(),
72
+ timeout: None,
73
+ max_response_bytes: 100 << 20,
74
+ ws_keepalive: None,
75
+ redirect: RedirectPolicy::default(),
76
+ http_builder: None,
77
+ invalidation: None,
78
+ on_request: Vec::new(),
79
+ on_response: Vec::new(),
80
+ on_auth_expired: None,
81
+ on_log: None,
82
+ state: None,
83
+ }
84
+ }
85
+ }
86
+
87
+ /// `Some("set")` for a set secret: Debug never shows one.
88
+ fn shown(secret: &Option<String>) -> Option<&'static str> {
89
+ secret.as_ref().map(|_| "set")
90
+ }
91
+
92
+ impl fmt::Debug for ClientConfig {
93
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94
+ let mut header_names: Vec<&String> = self.headers.keys().collect();
95
+ header_names.sort();
96
+ f.debug_struct("ClientConfig")
97
+ .field("base_url", &redacted(&self.base_url))
98
+ .field("bearer_token", &shown(&self.bearer_token))
99
+ .field("api_key", &shown(&self.api_key))
100
+ .field("auth_header_name", &self.auth_header_name)
101
+ .field("auth_header_prefix", &self.auth_header_prefix)
102
+ .field("header_names", &header_names)
103
+ .field("timeout", &self.timeout)
104
+ .field("max_response_bytes", &self.max_response_bytes)
105
+ .field("redirect", &self.redirect)
106
+ .field("invalidation", &self.invalidation)
107
+ .finish_non_exhaustive()
108
+ }
109
+ }
110
+
111
+ /// `url` without its user info, query and fragment, where a credential may sit.
112
+ fn redacted(url: &str) -> String {
113
+ match reqwest::Url::parse(url) {
114
+ Ok(mut u) => {
115
+ let _ = u.set_username("");
116
+ let _ = u.set_password(None);
117
+ u.set_query(None);
118
+ u.set_fragment(None);
119
+ u.to_string()
120
+ }
121
+ Err(_) => "(not a URL)".into(),
122
+ }
123
+ }
124
+
125
+ /// What the emitted `Client::new` fills in for its API: the first server, the auth scheme's header.
126
+ pub(crate) struct Defaults {
127
+ pub(crate) base_url: Option<&'static str>,
128
+ pub(crate) auth_header: &'static str,
129
+ pub(crate) auth_prefix: &'static str,
130
+ }
131
+
132
+ /// The client: cheap to clone, one connection pool. A call borrows nothing from it. `S` is how
133
+ /// its calls settle: `Throw`, or `Safe` for `safe()`'s.
134
+ #[derive(Clone)]
135
+ pub struct Client<S = Throw> {
136
+ pub(crate) inner: Arc<Inner>,
137
+ style: PhantomData<S>,
138
+ }
139
+
140
+ impl<S> fmt::Debug for Client<S> {
141
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
142
+ f.debug_struct("Client")
143
+ .field("base_url", &redacted(self.inner.base_url.as_str()))
144
+ .finish_non_exhaustive()
145
+ }
146
+ }
147
+
148
+ /// What every call of a client reads.
149
+ pub(crate) struct Inner {
150
+ pub(crate) http: reqwest::Client,
151
+ pub(crate) base_url: reqwest::Url,
152
+ pub(crate) headers: Vec<(String, String)>,
153
+ pub(crate) auth_header: HeaderName,
154
+ pub(crate) auth_prefix: String,
155
+ pub(crate) auth: AuthState,
156
+ pub(crate) timeout: Option<Duration>,
157
+ pub(crate) max_response_bytes: usize,
158
+ pub(crate) ws_keepalive: Option<Duration>,
159
+ pub(crate) redirect: RedirectPolicy,
160
+ pub(crate) on_request: Vec<OnRequestHook>,
161
+ pub(crate) on_response: Vec<OnResponseHook>,
162
+ pub(crate) on_auth_expired: Option<OnAuthExpiredHook>,
163
+ pub(crate) on_log: Option<OnLogHook>,
164
+ pub(crate) state: HookState,
165
+ pub(crate) stale: StaleTracker,
166
+ }
167
+
168
+ /// `url` as a base URL: absolute, http or https, with a host. `what` names it in the error, never
169
+ /// its value (a query may hold a credential).
170
+ pub(crate) fn parse_base(url: &str, what: &str) -> Result<reqwest::Url, Error> {
171
+ let parsed = reqwest::Url::parse(url).ok();
172
+ match parsed {
173
+ Some(u) if matches!(u.scheme(), "http" | "https") && u.host_str().is_some() => Ok(u),
174
+ _ => Err(Error::Config(format!(
175
+ "{what} is not an absolute http(s) URL"
176
+ ))),
177
+ }
178
+ }
179
+
180
+ /// The base URL: `base_url`, else the API's first server, which must itself be absolute.
181
+ fn base_of(base_url: &str, default: Option<&str>) -> Result<reqwest::Url, Error> {
182
+ if !base_url.is_empty() {
183
+ return parse_base(base_url, "base_url");
184
+ }
185
+ match default {
186
+ Some(server) => parse_base(server, "base_url is empty, and the API's first server")
187
+ .map_err(|_| Error::Config("base_url is empty, and the API's first server is a relative URL: set ClientConfig::base_url".into())),
188
+ None => Err(Error::Config(
189
+ "base_url is empty, and the API declares no server: set ClientConfig::base_url".into(),
190
+ )),
191
+ }
192
+ }
193
+
194
+ impl Client {
195
+ /// The safe mirror: the same resources and operations, each resolving `Result<Answer<T>, Error>`,
196
+ /// so an answer (an error status, a body that does not read) is `Ok` and `Err` is no answer alone.
197
+ pub fn safe(&self) -> Client<Safe> {
198
+ Client {
199
+ inner: Arc::clone(&self.inner),
200
+ style: PhantomData,
201
+ }
202
+ }
203
+
204
+ /// The client for `config` under the API's `defaults`; a bad `base_url` or header is `Error::Config`.
205
+ pub(crate) fn build(mut config: ClientConfig, defaults: Defaults) -> Result<Client, Error> {
206
+ let base_url = base_of(&config.base_url, defaults.base_url)?;
207
+ let (name, prefix) = match (
208
+ config.auth_header_name.take(),
209
+ config.auth_header_prefix.take(),
210
+ ) {
211
+ (None, prefix) => (
212
+ defaults.auth_header.to_owned(),
213
+ prefix.unwrap_or_else(|| defaults.auth_prefix.to_owned()),
214
+ ),
215
+ (Some(name), prefix) => (name, prefix.unwrap_or_default()),
216
+ };
217
+ let auth_header = HeaderName::from_bytes(name.as_bytes())
218
+ .map_err(|_| Error::Config("auth_header_name is not a valid header name".into()))?;
219
+ let http = config
220
+ .http_builder
221
+ .take()
222
+ .unwrap_or_default()
223
+ .redirect(reqwest::redirect::Policy::none())
224
+ .build()
225
+ .map_err(|e| Error::Config(format!("http_builder: {e}")))?;
226
+ let mut headers: Vec<(String, String)> = config.headers.into_iter().collect();
227
+ headers.sort();
228
+ let timeout = config.timeout.unwrap_or(DEFAULT_TIMEOUT);
229
+ let state = config.state.unwrap_or_default();
230
+ let inner = Inner {
231
+ http,
232
+ base_url,
233
+ headers,
234
+ auth_header,
235
+ auth_prefix: prefix,
236
+ auth: AuthState::new(config.bearer_token.or(config.api_key)),
237
+ timeout: (!timeout.is_zero()).then_some(timeout),
238
+ max_response_bytes: config.max_response_bytes,
239
+ ws_keepalive: Some(config.ws_keepalive.unwrap_or(Duration::from_secs(20)))
240
+ .filter(|d| !d.is_zero()),
241
+ redirect: config.redirect,
242
+ on_request: config.on_request,
243
+ on_response: config.on_response,
244
+ on_auth_expired: config.on_auth_expired,
245
+ on_log: config.on_log,
246
+ state,
247
+ stale: StaleTracker::new(config.invalidation.as_ref()),
248
+ };
249
+ Ok(Client {
250
+ inner: Arc::new(inner),
251
+ style: PhantomData,
252
+ })
253
+ }
254
+ }
@@ -0,0 +1,84 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! honey's error envelope, read leniently from an error status's body, and the message an error
3
+ //! shows: control characters dropped, capped at 512 characters.
4
+
5
+ use std::collections::HashMap;
6
+
7
+ use serde::de::DeserializeOwned;
8
+
9
+ /// The most characters of an error body `ApiError::message` keeps.
10
+ const MAX_MESSAGE_CHARS: usize = 512;
11
+
12
+ /// One problem with one input field.
13
+ #[derive(Debug, Clone, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
14
+ #[serde(default)]
15
+ pub struct FieldError {
16
+ pub error_key: String,
17
+ pub message: String,
18
+ pub path: String,
19
+ }
20
+
21
+ /// honey's error body; an absent member is empty, and a member it does not name, or of another type
22
+ /// than the envelope's, is kept as it came in `extra`.
23
+ #[derive(Debug, Clone, Default, PartialEq)]
24
+ #[non_exhaustive]
25
+ pub struct ErrorEnvelope {
26
+ pub status: Option<u16>,
27
+ pub error_key: Option<String>,
28
+ pub status_key: Option<String>,
29
+ pub message: Option<String>,
30
+ pub fields: HashMap<String, Vec<FieldError>>,
31
+ pub extra: HashMap<String, serde_json::Value>,
32
+ }
33
+
34
+ impl ErrorEnvelope {
35
+ /// The envelope of a JSON object `body`; `None` for any other body.
36
+ pub(crate) fn parse(body: &[u8]) -> Option<Self> {
37
+ let serde_json::Value::Object(members) = serde_json::from_slice(body).ok()? else {
38
+ return None;
39
+ };
40
+ let mut env = ErrorEnvelope::default();
41
+ for (name, value) in members {
42
+ let kept = match name.as_str() {
43
+ "status" => into(&value, &mut env.status),
44
+ "error_key" => into(&value, &mut env.error_key),
45
+ "status_key" => into(&value, &mut env.status_key),
46
+ "message" => into(&value, &mut env.message),
47
+ "fields" => into(&value, &mut env.fields),
48
+ _ => false,
49
+ };
50
+ if !kept {
51
+ env.extra.insert(name, value);
52
+ }
53
+ }
54
+ Some(env)
55
+ }
56
+ }
57
+
58
+ /// `value` decoded into `slot` (a member of the envelope's type); false when it is another type.
59
+ fn into<T: DeserializeOwned>(value: &serde_json::Value, slot: &mut T) -> bool {
60
+ match T::deserialize(value) {
61
+ Ok(v) => {
62
+ *slot = v;
63
+ true
64
+ }
65
+ Err(_) => false,
66
+ }
67
+ }
68
+
69
+ /// `text` without control characters or replacement characters, capped at 512 characters.
70
+ pub(crate) fn sanitized(text: &str) -> String {
71
+ let mut out = String::new();
72
+ for (n, c) in text
73
+ .chars()
74
+ .filter(|c| !c.is_control() && *c != char::REPLACEMENT_CHARACTER)
75
+ .enumerate()
76
+ {
77
+ if n == MAX_MESSAGE_CHARS {
78
+ out.push('…');
79
+ break;
80
+ }
81
+ out.push(c);
82
+ }
83
+ out
84
+ }
@@ -0,0 +1,235 @@
1
+ // @generated by honey. DO NOT EDIT.
2
+ //! The SDK's one error type (G6): an error status as `Api`, and each way a call fails without one.
3
+
4
+ use std::fmt;
5
+
6
+ use bytes::Bytes;
7
+ use reqwest::header::HeaderMap;
8
+ use serde::de::DeserializeOwned;
9
+
10
+ use crate::envelope::{ErrorEnvelope, sanitized};
11
+
12
+ /// Why a call failed.
13
+ #[derive(Debug)]
14
+ #[non_exhaustive]
15
+ pub enum Error {
16
+ /// The API answered with an error status (anything but 2xx, a redirect it did not follow included).
17
+ Api(ApiError),
18
+ /// The exchange failed without an answer: a refused connection, DNS, TLS, a broken or too large body.
19
+ Transport(Box<dyn std::error::Error + Send + Sync>),
20
+ /// A 2xx answer that is not the declared type, or past `max_response_bytes`.
21
+ Decode(DecodeError),
22
+ /// The call's timeout lapsed.
23
+ Timeout,
24
+ /// The call's cancel signal completed first.
25
+ Canceled,
26
+ /// `on_auth_expired` failed.
27
+ AuthExpired(String),
28
+ /// A path param that cannot be a path segment (empty, `.` or `..`), or one the call lacks.
29
+ PathParam(String),
30
+ /// The configuration cannot make the request: no usable `base_url`, an invalid header.
31
+ Config(String),
32
+ /// An `on_request` or `on_response` hook ended the call.
33
+ Hook(Box<dyn std::error::Error + Send + Sync>),
34
+ /// The stream or socket is closed.
35
+ Closed,
36
+ }
37
+
38
+ impl Error {
39
+ /// The error status, when the API answered with one.
40
+ pub fn status(&self) -> Option<u16> {
41
+ match self {
42
+ Error::Api(e) => Some(e.status()),
43
+ _ => None,
44
+ }
45
+ }
46
+
47
+ /// `Decode` with the text `m`.
48
+ pub(crate) fn decode(m: impl fmt::Display) -> Self {
49
+ Error::Decode(DecodeError(m.to_string()))
50
+ }
51
+
52
+ /// A reqwest failure: a lapsed timeout is `Timeout`, any other `Transport` without its URL, so the
53
+ /// text never carries a query credential.
54
+ pub(crate) fn from_reqwest(e: reqwest::Error) -> Self {
55
+ if e.is_timeout() {
56
+ Error::Timeout
57
+ } else {
58
+ Error::Transport(Box::new(e.without_url()))
59
+ }
60
+ }
61
+ }
62
+
63
+ impl fmt::Display for Error {
64
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65
+ match self {
66
+ Error::Api(e) => e.fmt(f),
67
+ Error::Transport(e) => write!(f, "transport: {e}"),
68
+ Error::Decode(e) => write!(f, "decode: {e}"),
69
+ Error::Timeout => f.write_str("the call timed out"),
70
+ Error::Canceled => f.write_str("the call was canceled"),
71
+ Error::AuthExpired(m) => write!(f, "on_auth_expired: {m}"),
72
+ Error::PathParam(m) => write!(f, "path param: {m}"),
73
+ Error::Config(m) => write!(f, "config: {m}"),
74
+ Error::Hook(e) => write!(f, "hook: {e}"),
75
+ Error::Closed => f.write_str("closed"),
76
+ }
77
+ }
78
+ }
79
+
80
+ impl std::error::Error for Error {
81
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
82
+ match self {
83
+ Error::Transport(e) | Error::Hook(e) => Some(e.as_ref()),
84
+ _ => None,
85
+ }
86
+ }
87
+ }
88
+
89
+ /// Why an answer is not the declared type, as its `Display` reads.
90
+ #[derive(Debug, Clone)]
91
+ pub struct DecodeError(pub(crate) String);
92
+
93
+ impl fmt::Display for DecodeError {
94
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
95
+ f.write_str(&self.0)
96
+ }
97
+ }
98
+
99
+ impl std::error::Error for DecodeError {}
100
+
101
+ /// An error status by its name: the eleven the TypeScript SDK names, any other `Other`.
102
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
103
+ #[non_exhaustive]
104
+ pub enum ErrorKind {
105
+ BadRequest,
106
+ Unauthorized,
107
+ Forbidden,
108
+ NotFound,
109
+ Conflict,
110
+ UnprocessableEntity,
111
+ RateLimit,
112
+ InternalServer,
113
+ BadGateway,
114
+ ServiceUnavailable,
115
+ GatewayTimeout,
116
+ Other,
117
+ }
118
+
119
+ impl ErrorKind {
120
+ fn of(status: u16) -> Self {
121
+ match status {
122
+ 400 => ErrorKind::BadRequest,
123
+ 401 => ErrorKind::Unauthorized,
124
+ 403 => ErrorKind::Forbidden,
125
+ 404 => ErrorKind::NotFound,
126
+ 409 => ErrorKind::Conflict,
127
+ 422 => ErrorKind::UnprocessableEntity,
128
+ 429 => ErrorKind::RateLimit,
129
+ 500 => ErrorKind::InternalServer,
130
+ 502 => ErrorKind::BadGateway,
131
+ 503 => ErrorKind::ServiceUnavailable,
132
+ 504 => ErrorKind::GatewayTimeout,
133
+ _ => ErrorKind::Other,
134
+ }
135
+ }
136
+ }
137
+
138
+ /// An error status: the response as it came, its parsed envelope, honey's error key, and a message
139
+ /// safe to show. Boxed, so an `Error` stays small.
140
+ #[derive(Clone)]
141
+ pub struct ApiError(Box<Answered>);
142
+
143
+ #[derive(Clone)]
144
+ struct Answered {
145
+ status: u16,
146
+ headers: HeaderMap,
147
+ body: Bytes,
148
+ message: String,
149
+ envelope: ErrorEnvelope,
150
+ }
151
+
152
+ impl ApiError {
153
+ pub(crate) fn new(status: u16, headers: HeaderMap, body: Bytes) -> Self {
154
+ let envelope = ErrorEnvelope::parse(&body);
155
+ let text = match envelope.as_ref().and_then(|e| e.message.as_deref()) {
156
+ Some(message) => message.to_owned(),
157
+ None => String::from_utf8_lossy(&body).into_owned(),
158
+ };
159
+ ApiError(Box::new(Answered {
160
+ status,
161
+ headers,
162
+ message: sanitized(&text),
163
+ envelope: envelope.unwrap_or_default(),
164
+ body,
165
+ }))
166
+ }
167
+
168
+ /// The envelope's `error_key`, which `key()` (emitted with the API's keys) reads.
169
+ pub(crate) fn raw_key(&self) -> Option<&str> {
170
+ self.0.envelope.error_key.as_deref()
171
+ }
172
+
173
+ /// The HTTP status.
174
+ pub fn status(&self) -> u16 {
175
+ self.0.status
176
+ }
177
+
178
+ /// The status by its name.
179
+ pub fn kind(&self) -> ErrorKind {
180
+ ErrorKind::of(self.0.status)
181
+ }
182
+
183
+ /// The envelope's message, else the body's text: control characters dropped, at most 512 characters.
184
+ pub fn message(&self) -> &str {
185
+ &self.0.message
186
+ }
187
+
188
+ /// honey's error envelope, empty for a body that is not a JSON object.
189
+ pub fn envelope(&self) -> &ErrorEnvelope {
190
+ &self.0.envelope
191
+ }
192
+
193
+ /// The body decoded as `T`, a declared key's own schema.
194
+ pub fn decode_body<T: DeserializeOwned>(&self) -> Result<T, Error> {
195
+ serde_json::from_slice(&self.0.body).map_err(Error::decode)
196
+ }
197
+
198
+ /// The response's headers.
199
+ pub fn headers(&self) -> &HeaderMap {
200
+ &self.0.headers
201
+ }
202
+
203
+ /// The response's body as it came.
204
+ pub fn body(&self) -> &[u8] {
205
+ &self.0.body
206
+ }
207
+ }
208
+
209
+ /// `HTTP 404: <message>`, as every SDK's error reads; no reason phrase, header or request detail.
210
+ impl fmt::Display for ApiError {
211
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
212
+ write!(f, "HTTP {}", self.0.status)?;
213
+ if !self.0.message.is_empty() {
214
+ write!(f, ": {}", self.0.message)?;
215
+ }
216
+ Ok(())
217
+ }
218
+ }
219
+
220
+ /// The status, kind, key and message, and the header names only: a response header (`Set-Cookie`)
221
+ /// may hold a credential, and a logger prints errors with `{:?}`.
222
+ impl fmt::Debug for ApiError {
223
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
224
+ let names: Vec<&str> = self.0.headers.keys().map(|k| k.as_str()).collect();
225
+ f.debug_struct("ApiError")
226
+ .field("status", &self.0.status)
227
+ .field("error_key", &self.raw_key())
228
+ .field("message", &self.0.message)
229
+ .field("header_names", &names)
230
+ .field("body_len", &self.0.body.len())
231
+ .finish()
232
+ }
233
+ }
234
+
235
+ impl std::error::Error for ApiError {}