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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (375) hide show
  1. package/README.md +548 -35
  2. package/assets/installers/examples/github.config.ts +17 -19
  3. package/assets/installers/examples/goreleaser.config.ts +16 -18
  4. package/assets/installers/examples/raw.config.ts +13 -15
  5. package/bin/clients.js +88 -68
  6. package/bin/installgen.js +18 -13
  7. package/dist/cli.d.ts +4 -4
  8. package/dist/cli.js +20 -12
  9. package/dist/emit/cli/channels.d.ts +2 -2
  10. package/dist/emit/cli/channels.js +18 -13
  11. package/dist/emit/cli/commands.d.ts +1 -1
  12. package/dist/emit/cli/commands.js +14 -8
  13. package/dist/emit/cli/discovery.d.ts +0 -6
  14. package/dist/emit/cli/discovery.js +9 -7
  15. package/dist/emit/cli/flags.d.ts +1 -3
  16. package/dist/emit/cli/flags.js +11 -5
  17. package/dist/emit/cli/install.d.ts +0 -8
  18. package/dist/emit/cli/install.js +3 -3
  19. package/dist/emit/cli/layout.d.ts +1 -1
  20. package/dist/emit/cli/layout.js +13 -10
  21. package/dist/emit/cli/module.d.ts +6 -6
  22. package/dist/emit/cli/module.js +10 -10
  23. package/dist/emit/cli/release.d.ts +0 -11
  24. package/dist/emit/cli/release.js +4 -4
  25. package/dist/emit/cli/skills.js +3 -3
  26. package/dist/emit/csharp/errors.js +4 -4
  27. package/dist/emit/csharp/json.js +8 -8
  28. package/dist/emit/csharp/realtime.js +3 -3
  29. package/dist/emit/csharp/sdk-answer.js +4 -4
  30. package/dist/emit/csharp/sdk-body.js +8 -6
  31. package/dist/emit/csharp/sdk-client.d.ts +3 -3
  32. package/dist/emit/csharp/sdk-client.js +2 -2
  33. package/dist/emit/csharp/sdk-csproj.d.ts +7 -9
  34. package/dist/emit/csharp/sdk-csproj.js +10 -10
  35. package/dist/emit/csharp/sdk-doc.js +1 -1
  36. package/dist/emit/csharp/sdk-method.d.ts +18 -2
  37. package/dist/emit/csharp/sdk-method.js +24 -9
  38. package/dist/emit/csharp/sdk-plan.js +0 -1
  39. package/dist/emit/csharp/sdk.js +7 -4
  40. package/dist/emit/csharp/sse.d.ts +0 -2
  41. package/dist/emit/csharp/sse.js +7 -7
  42. package/dist/emit/csharp/transport.js +7 -7
  43. package/dist/emit/csharp/types-enum.js +3 -1
  44. package/dist/emit/csharp/types-messages.js +3 -3
  45. package/dist/emit/csharp/types-names.js +10 -12
  46. package/dist/emit/csharp/types-record.js +3 -3
  47. package/dist/emit/csharp/types-union.d.ts +1 -1
  48. package/dist/emit/csharp/types.d.ts +0 -1
  49. package/dist/emit/csharp/types.js +3 -3
  50. package/dist/emit/csharp/ws.js +2 -2
  51. package/dist/emit/go/errors.js +1 -1
  52. package/dist/emit/go/http.js +2 -2
  53. package/dist/emit/go/module-path.js +2 -2
  54. package/dist/emit/go/sdk-answer.js +1 -1
  55. package/dist/emit/go/sdk-body.js +11 -7
  56. package/dist/emit/go/sdk-client.js +1 -1
  57. package/dist/emit/go/sdk-method.d.ts +9 -0
  58. package/dist/emit/go/sdk-method.js +12 -3
  59. package/dist/emit/go/sdk-mirror.js +2 -2
  60. package/dist/emit/go/sdk-opts.d.ts +0 -2
  61. package/dist/emit/go/sdk-opts.js +3 -3
  62. package/dist/emit/go/sdk.d.ts +1 -1
  63. package/dist/emit/go/sdk.js +12 -11
  64. package/dist/emit/go/sse.js +1 -1
  65. package/dist/emit/go/types-names.js +5 -0
  66. package/dist/emit/go/types-struct.d.ts +2 -1
  67. package/dist/emit/go/types-struct.js +1 -1
  68. package/dist/emit/go/types.js +9 -9
  69. package/dist/emit/go/ws.js +6 -6
  70. package/dist/emit/java/gradle.d.ts +7 -9
  71. package/dist/emit/java/gradle.js +8 -8
  72. package/dist/emit/java/json.js +1 -1
  73. package/dist/emit/java/layout-ast.js +1 -1
  74. package/dist/emit/java/layout-decl.js +5 -4
  75. package/dist/emit/java/layout-doc.js +13 -7
  76. package/dist/emit/java/layout-dot.js +1 -1
  77. package/dist/emit/java/layout-strings.js +4 -5
  78. package/dist/emit/java/layout-types.js +7 -5
  79. package/dist/emit/java/layout-visitor.js +4 -3
  80. package/dist/emit/java/layout.js +5 -4
  81. package/dist/emit/java/models-names.js +5 -4
  82. package/dist/emit/java/models-record.d.ts +0 -1
  83. package/dist/emit/java/models-record.js +3 -3
  84. package/dist/emit/java/models-union.d.ts +1 -1
  85. package/dist/emit/java/models-union.js +1 -1
  86. package/dist/emit/java/models.d.ts +1 -2
  87. package/dist/emit/java/models.js +25 -16
  88. package/dist/emit/java/realtime.d.ts +5 -17
  89. package/dist/emit/java/realtime.js +1 -1
  90. package/dist/emit/java/sdk-client.d.ts +6 -6
  91. package/dist/emit/java/sdk-client.js +2 -1
  92. package/dist/emit/java/sdk-decl.js +2 -2
  93. package/dist/emit/java/sdk-errors.js +1 -1
  94. package/dist/emit/java/sdk-headers.js +2 -2
  95. package/dist/emit/java/sdk-mirror.js +2 -2
  96. package/dist/emit/java/sdk-models.d.ts +1 -1
  97. package/dist/emit/java/sdk-models.js +7 -7
  98. package/dist/emit/java/sdk-op.d.ts +7 -11
  99. package/dist/emit/java/sdk-op.js +22 -10
  100. package/dist/emit/java/sdk-params.d.ts +5 -5
  101. package/dist/emit/java/sdk-params.js +3 -2
  102. package/dist/emit/java/sdk-plan.js +0 -1
  103. package/dist/emit/java/sdk.d.ts +1 -1
  104. package/dist/emit/java/sdk.js +21 -14
  105. package/dist/emit/java/sse.d.ts +2 -4
  106. package/dist/emit/java/sse.js +6 -6
  107. package/dist/emit/java/ws.d.ts +2 -2
  108. package/dist/emit/java/ws.js +3 -4
  109. package/dist/emit/mcp/annotations.js +8 -4
  110. package/dist/emit/mcp/files.js +9 -9
  111. package/dist/emit/mcp/mounted.js +2 -2
  112. package/dist/emit/mcp/output-schema.js +3 -3
  113. package/dist/emit/mcp/registry.d.ts +0 -2
  114. package/dist/emit/mcp/registry.js +5 -4
  115. package/dist/emit/mcp/runtime.js +2 -2
  116. package/dist/emit/mcp/schema.js +22 -11
  117. package/dist/emit/mcp/server.d.ts +7 -7
  118. package/dist/emit/mcp/server.js +7 -6
  119. package/dist/emit/mcp/tools.js +7 -6
  120. package/dist/emit/python/errors.js +3 -3
  121. package/dist/emit/python/realtime.js +2 -2
  122. package/dist/emit/python/sdk-answer.d.ts +3 -7
  123. package/dist/emit/python/sdk-answer.js +2 -2
  124. package/dist/emit/python/sdk-body.js +4 -5
  125. package/dist/emit/python/sdk-client.js +5 -5
  126. package/dist/emit/python/sdk-doc.js +2 -2
  127. package/dist/emit/python/sdk-method.d.ts +11 -0
  128. package/dist/emit/python/sdk-method.js +20 -5
  129. package/dist/emit/python/sdk-plan.js +0 -1
  130. package/dist/emit/python/sdk-pyproject.d.ts +0 -2
  131. package/dist/emit/python/sdk-pyproject.js +8 -8
  132. package/dist/emit/python/sdk.d.ts +1 -1
  133. package/dist/emit/python/sdk.js +12 -8
  134. package/dist/emit/python/sse.d.ts +0 -2
  135. package/dist/emit/python/sse.js +2 -2
  136. package/dist/emit/python/transport.js +4 -4
  137. package/dist/emit/python/types-dict.d.ts +2 -2
  138. package/dist/emit/python/types-dict.js +1 -1
  139. package/dist/emit/python/types-names.js +2 -2
  140. package/dist/emit/python/types-union.js +1 -1
  141. package/dist/emit/python/types.js +3 -3
  142. package/dist/emit/python/ws.d.ts +2 -5
  143. package/dist/emit/python/ws.js +4 -4
  144. package/dist/emit/rust/errors.js +3 -3
  145. package/dist/emit/rust/http.js +4 -4
  146. package/dist/emit/rust/realtime.js +2 -2
  147. package/dist/emit/rust/sdk-body.js +8 -5
  148. package/dist/emit/rust/sdk-cargo.d.ts +16 -18
  149. package/dist/emit/rust/sdk-cargo.js +12 -12
  150. package/dist/emit/rust/sdk-client.d.ts +1 -1
  151. package/dist/emit/rust/sdk-client.js +3 -3
  152. package/dist/emit/rust/sdk-method.d.ts +12 -1
  153. package/dist/emit/rust/sdk-method.js +12 -4
  154. package/dist/emit/rust/sdk-opts.d.ts +2 -1
  155. package/dist/emit/rust/sdk-opts.js +2 -2
  156. package/dist/emit/rust/sdk-plan.js +0 -1
  157. package/dist/emit/rust/sdk.d.ts +1 -1
  158. package/dist/emit/rust/sdk.js +9 -6
  159. package/dist/emit/rust/sse.d.ts +0 -5
  160. package/dist/emit/rust/sse.js +2 -2
  161. package/dist/emit/rust/types-names.js +3 -3
  162. package/dist/emit/rust/types-struct.js +1 -1
  163. package/dist/emit/rust/types-union.d.ts +1 -1
  164. package/dist/emit/rust/types.js +7 -5
  165. package/dist/emit/rust/ws.d.ts +0 -11
  166. package/dist/emit/rust/ws.js +5 -5
  167. package/dist/emit/shared/escape.js +17 -17
  168. package/dist/emit/shared/format.js +1 -1
  169. package/dist/emit/shared/gofmt.js +1 -1
  170. package/dist/emit/shared/lang.js +10 -10
  171. package/dist/emit/shared/literals.d.ts +5 -0
  172. package/dist/emit/shared/literals.js +8 -0
  173. package/dist/emit/shared/metadata.d.ts +0 -6
  174. package/dist/emit/shared/metadata.js +8 -7
  175. package/dist/emit/shared/ruff.js +1 -1
  176. package/dist/emit/shared/rustfmt.js +1 -1
  177. package/dist/emit/shared/type-emitter.js +37 -20
  178. package/dist/emit/shared/unknown-type.constants.d.ts +2 -0
  179. package/dist/emit/shared/unknown-type.constants.js +2 -0
  180. package/dist/emit/ts/http.d.ts +8 -2
  181. package/dist/emit/ts/http.js +51 -6
  182. package/dist/emit/ts/package.d.ts +14 -12
  183. package/dist/emit/ts/package.js +10 -8
  184. package/dist/emit/ts/route-tree.js +2 -2
  185. package/dist/emit/ts/sdk-types-preamble.d.ts +1 -1
  186. package/dist/emit/ts/sdk-types-preamble.js +12 -4
  187. package/dist/emit/ts/sdk-types.d.ts +0 -5
  188. package/dist/emit/ts/sdk-types.js +63 -19
  189. package/dist/emit/ts/sdk.d.ts +3 -1
  190. package/dist/emit/ts/sdk.js +44 -12
  191. package/dist/emit/ts/service-map.d.ts +7 -1
  192. package/dist/emit/ts/service-map.js +10 -1
  193. package/dist/emit/ts/single-flight-text.d.ts +3 -0
  194. package/dist/emit/ts/single-flight-text.js +38 -0
  195. package/dist/emit/ts/tanstack-query.d.ts +3 -2
  196. package/dist/emit/ts/tanstack-query.js +60 -35
  197. package/dist/emit/ts/type-gen.js +31 -18
  198. package/dist/emit/ts/webhooks.d.ts +0 -2
  199. package/dist/emit/ts/webhooks.js +3 -3
  200. package/dist/extract/chain.js +5 -4
  201. package/dist/extract/extract.js +5 -5
  202. package/dist/extract/serialize.d.ts +0 -2
  203. package/dist/extract/serialize.js +14 -15
  204. package/dist/extract/walk.js +15 -12
  205. package/dist/gen/args.js +9 -5
  206. package/dist/gen/formatters.js +5 -3
  207. package/dist/gen/process.js +2 -1
  208. package/dist/gen/shipped.js +2 -2
  209. package/dist/gen/switch-on.constants.d.ts +2 -0
  210. package/dist/gen/switch-on.constants.js +2 -0
  211. package/dist/gen/targets.d.ts +6 -7
  212. package/dist/gen/targets.js +11 -6
  213. package/dist/gen/write.js +4 -2
  214. package/dist/index.js +2 -2
  215. package/dist/installers/cli.d.ts +4 -4
  216. package/dist/installers/cli.js +24 -24
  217. package/dist/installers/commands/build.d.ts +4 -4
  218. package/dist/installers/commands/build.js +2 -3
  219. package/dist/installers/commands/check.d.ts +2 -2
  220. package/dist/installers/commands/check.js +11 -10
  221. package/dist/installers/commands/init.d.ts +2 -2
  222. package/dist/installers/commands/init.js +1 -2
  223. package/dist/installers/config/define-config.d.ts +16 -16
  224. package/dist/installers/config/define-config.js +1 -1
  225. package/dist/installers/config/hooks/bun.d.ts +6 -6
  226. package/dist/installers/config/hooks/node.js +1 -1
  227. package/dist/installers/config/load.d.ts +6 -8
  228. package/dist/installers/config/load.js +7 -8
  229. package/dist/installers/config/resolve.d.ts +1 -2
  230. package/dist/installers/config/resolve.js +28 -33
  231. package/dist/installers/config/types.d.ts +6 -6
  232. package/dist/installers/config/types.js +0 -1
  233. package/dist/installers/render/quote.js +3 -5
  234. package/dist/installers/render/render.d.ts +6 -6
  235. package/dist/installers/render/render.js +26 -26
  236. package/dist/installers/ui.d.ts +4 -4
  237. package/dist/installers/ui.js +3 -3
  238. package/dist/ir/build.d.ts +3 -3
  239. package/dist/ir/build.js +8 -5
  240. package/dist/ir/invalidate-reads.d.ts +17 -0
  241. package/dist/ir/invalidate-reads.js +104 -0
  242. package/dist/ir/load.d.ts +10 -0
  243. package/dist/ir/load.js +65 -18
  244. package/dist/ir/model.d.ts +2 -1
  245. package/dist/ir/model.js +0 -1
  246. package/dist/ir/read-method.constants.d.ts +2 -0
  247. package/dist/ir/read-method.constants.js +2 -0
  248. package/dist/ir/resolve-refs.js +2 -2
  249. package/dist/ir/resource-tree.js +2 -1
  250. package/dist/ir/route-tree-intern.js +1 -1
  251. package/dist/ir/schema.js +3 -3
  252. package/dist/ir/sdk-model.js +3 -3
  253. package/dist/ir/slots.js +13 -8
  254. package/dist/ir/streams.js +1 -1
  255. package/dist/release/bootstrap.d.ts +3 -3
  256. package/dist/release/bootstrap.js +7 -7
  257. package/dist/release/bump-args.js +4 -4
  258. package/dist/release/bump-command.d.ts +1 -1
  259. package/dist/release/bump-command.js +9 -10
  260. package/dist/release/bump.d.ts +5 -4
  261. package/dist/release/bump.js +2 -2
  262. package/dist/release/cli.d.ts +4 -4
  263. package/dist/release/cli.js +4 -4
  264. package/dist/release/codegen.js +1 -1
  265. package/dist/release/digest.js +5 -7
  266. package/dist/release/git.js +5 -8
  267. package/dist/release/load.js +4 -4
  268. package/dist/release/manifest.js +9 -10
  269. package/dist/release/oasdiff.d.ts +10 -15
  270. package/dist/release/oasdiff.js +5 -6
  271. package/dist/release/registries.d.ts +0 -11
  272. package/dist/release/registries.js +17 -17
  273. package/dist/release/release-state.d.ts +16 -13
  274. package/dist/release/release-workflow.js +5 -7
  275. package/dist/release/repo-settings.d.ts +2 -1
  276. package/dist/release/spec-gate.d.ts +0 -2
  277. package/dist/release/spec-gate.js +6 -10
  278. package/dist/release/sync-command.d.ts +2 -2
  279. package/dist/release/sync-command.js +1 -1
  280. package/dist/release/sync-tree.js +9 -13
  281. package/dist/release/sync.d.ts +6 -6
  282. package/dist/release/sync.js +12 -13
  283. package/dist/release/types.d.ts +22 -22
  284. package/dist/release/types.js +0 -1
  285. package/dist/release/version-files.d.ts +3 -4
  286. package/dist/release/version-files.js +4 -5
  287. package/dist/runtime/.oxfmtrc.jsonc +8 -0
  288. package/dist/runtime/csharp/Config.cs +9 -1
  289. package/dist/runtime/csharp/Exchange.cs +56 -4
  290. package/dist/runtime/csharp/Hooks.cs +9 -0
  291. package/dist/runtime/csharp/Operation.cs +6 -1
  292. package/dist/runtime/csharp/WsDial.cs +3 -1
  293. package/dist/runtime/go/config.go +5 -0
  294. package/dist/runtime/go/hooks.go +70 -0
  295. package/dist/runtime/go/request.go +6 -2
  296. package/dist/runtime/go/stream.go +4 -1
  297. package/dist/runtime/go/ws.go +3 -1
  298. package/dist/runtime/java/ClientConfig.java +11 -0
  299. package/dist/runtime/java/Flight.java +2 -12
  300. package/dist/runtime/java/Hooks.java +45 -0
  301. package/dist/runtime/java/InvalidateEvent.java +10 -0
  302. package/dist/runtime/java/InvalidateHook.java +12 -0
  303. package/dist/runtime/java/InvalidateTarget.java +7 -0
  304. package/dist/runtime/java/Operation.java +23 -3
  305. package/dist/runtime/java/Realtime.java +3 -1
  306. package/dist/runtime/java/WsDial.java +3 -0
  307. package/dist/runtime/mcp/files.ts +1 -1
  308. package/dist/runtime/mcp/http.ts +6 -2
  309. package/dist/runtime/mcp/listen.ts +1 -1
  310. package/dist/runtime/mcp/mount.ts +2 -2
  311. package/dist/runtime/mcp/protocol.ts +1 -1
  312. package/dist/runtime/python/config.py +8 -2
  313. package/dist/runtime/python/exchange.py +3 -1
  314. package/dist/runtime/python/hooks.py +110 -5
  315. package/dist/runtime/python/operation.py +2 -0
  316. package/dist/runtime/python/send_async.py +14 -2
  317. package/dist/runtime/python/send_sync.py +4 -2
  318. package/dist/runtime/python/ws.py +5 -1
  319. package/dist/runtime/rust/config.rs +6 -1
  320. package/dist/runtime/rust/exchange.rs +15 -3
  321. package/dist/runtime/rust/hooks.rs +127 -2
  322. package/dist/runtime/rust/log.rs +11 -3
  323. package/dist/runtime/rust/request.rs +17 -0
  324. package/dist/runtime/rust/ws.rs +9 -1
  325. package/dist/runtime/ts/config.ts +69 -0
  326. package/dist/runtime/ts/http.ts +12 -10
  327. package/dist/runtime/ts/request.ts +2 -0
  328. package/dist/runtime/ts/response.ts +7 -0
  329. package/dist/runtime/ts/sdk-invalidate.ts +82 -0
  330. package/dist/runtime/ts/sdk-single-flight.constants.ts +25 -0
  331. package/dist/runtime/ts/sdk-single-flight.ts +203 -0
  332. package/dist/runtime/ts/sdk-sse.ts +5 -1
  333. package/dist/runtime/ts/sdk-ws.ts +9 -3
  334. package/dist/runtime/ts/sdk.ts +55 -31
  335. package/dist/runtime/ts/single-flight-batch.ts +184 -0
  336. package/dist/runtime/ts/single-flight-body.ts +59 -0
  337. package/dist/runtime/ts/single-flight-run.ts +160 -0
  338. package/dist/runtime/ts/single-flight.constants.ts +31 -0
  339. package/dist/runtime/ts/single-flight.ts +158 -0
  340. package/dist/runtime/ts-tanstack-query/invalidate.ts +96 -92
  341. package/dist/runtime/ts-tanstack-query/query.ts +140 -170
  342. package/package.json +12 -17
  343. package/references/INDEX.md +31 -0
  344. package/references/cli.md +33 -0
  345. package/references/configuring.md +29 -0
  346. package/references/documentation.md +15 -0
  347. package/references/errors.md +23 -0
  348. package/references/flags.md +104 -0
  349. package/references/gates.md +46 -0
  350. package/references/generate.md +29 -0
  351. package/references/install-scripts.md +28 -0
  352. package/references/install.md +38 -0
  353. package/references/license.md +8 -0
  354. package/references/mcp.md +76 -0
  355. package/references/output.md +45 -0
  356. package/references/overview.md +14 -0
  357. package/references/release-tooling.md +34 -0
  358. package/references/release.md +305 -0
  359. package/references/sdks.md +393 -0
  360. package/references/start.md +22 -0
  361. package/references/tdd.md +16 -0
  362. package/dist/emit/cli/index.d.ts +0 -1
  363. package/dist/emit/cli/index.js +0 -1
  364. package/dist/emit/csharp/index.d.ts +0 -1
  365. package/dist/emit/csharp/index.js +0 -1
  366. package/dist/emit/go/index.d.ts +0 -1
  367. package/dist/emit/go/index.js +0 -1
  368. package/dist/emit/java/index.d.ts +0 -2
  369. package/dist/emit/java/index.js +0 -2
  370. package/dist/emit/mcp/index.d.ts +0 -3
  371. package/dist/emit/mcp/index.js +0 -3
  372. package/dist/emit/python/index.d.ts +0 -1
  373. package/dist/emit/python/index.js +0 -1
  374. package/dist/emit/rust/index.d.ts +0 -1
  375. package/dist/emit/rust/index.js +0 -1
@@ -285,22 +285,12 @@ final class Flight {
285
285
  log.failed(error, error.status());
286
286
  }
287
287
  if (hop.status() >= 200 && hop.status() < 300) {
288
- exchange.stale().settle(meta, op.invalidates(), pathValues());
288
+ exchange.stale().settle(meta, op.invalidates(), op.values(call.path()));
289
+ Hooks.onInvalidate(config, op, call.path(), stream);
289
290
  if (over) {
290
291
  throw new DecodeException(Decode.exceeds(config.maxResponseBytes()), null);
291
292
  }
292
293
  }
293
294
  return new Answer(route, raw, error, hop.body());
294
295
  }
295
-
296
- /**
297
- * The call's path values by their template names: what a stale target's placeholders fill from.
298
- */
299
- private Map<String, String> pathValues() {
300
- Map<String, String> values = new TreeMap<>();
301
- for (int i = 0; i < op.names().length; i++) {
302
- values.put(op.names()[i], call.path()[i]);
303
- }
304
- return values;
305
- }
306
296
  }
@@ -1,8 +1,12 @@
1
1
  // @generated by clients. DO NOT EDIT.
2
2
  package http.runtime;
3
3
 
4
+ import java.util.ArrayList;
5
+ import java.util.LinkedHashMap;
4
6
  import java.util.List;
7
+ import java.util.Map;
5
8
  import java.util.concurrent.CancellationException;
9
+ import java.util.concurrent.CompletableFuture;
6
10
 
7
11
  /**
8
12
  * Runs the hooks in order; a hook's own failure is the call's {@link HookException}, an SDK error
@@ -19,6 +23,47 @@ final class Hooks {
19
23
  run(hooks, hook -> hook.apply(context));
20
24
  }
21
25
 
26
+ /**
27
+ * A successful write's onInvalidate hooks, in order, each after the last, a throw logged and the
28
+ * next still run; none when {@code op} makes nothing stale. A stream's or socket's open runs them
29
+ * on the common pool, never waiting.
30
+ */
31
+ static void onInvalidate(ClientConfig config, Operation op, String[] path, boolean detached) {
32
+ List<InvalidateHook> hooks = config.onInvalidate();
33
+ if (op.reads().length == 0 || hooks.isEmpty()) {
34
+ return;
35
+ }
36
+ Map<String, String> values = op.values(path);
37
+ List<InvalidateTarget> targets = new ArrayList<>();
38
+ for (Operation.Read read : op.reads()) {
39
+ Map<String, String> known = new LinkedHashMap<>();
40
+ for (String name : read.params()) {
41
+ String value = values.get(name);
42
+ if (value != null && !value.isEmpty() && !".".equals(value) && !"..".equals(value)) {
43
+ known.put(name, value);
44
+ }
45
+ }
46
+ targets.add(new InvalidateTarget(read.op(), Map.copyOf(known)));
47
+ }
48
+ InvalidateEvent event = new InvalidateEvent(op.by(), List.copyOf(targets));
49
+ CallLog log = new CallLog(config.onLog(), op.route());
50
+ Runnable run =
51
+ () -> {
52
+ for (InvalidateHook hook : hooks) {
53
+ try {
54
+ hook.apply(event);
55
+ } catch (java.lang.Exception e) {
56
+ log.failed(e, null);
57
+ }
58
+ }
59
+ };
60
+ if (detached) {
61
+ CompletableFuture.runAsync(run);
62
+ } else {
63
+ run.run();
64
+ }
65
+ }
66
+
22
67
  /**
23
68
  * The error a failed {@code label} throws: an SDK error or a cancellation as it is, any other
24
69
  * failure wrapped as the call's {@link HookException}.
@@ -0,0 +1,10 @@
1
+ // @generated by clients. DO NOT EDIT.
2
+ package http.runtime;
3
+
4
+ import java.util.List;
5
+
6
+ /**
7
+ * What each {@link InvalidateHook} sees after a successful write: the write's operationId, and
8
+ * every read its {@code x-invalidate} made stale.
9
+ */
10
+ public record InvalidateEvent(String by, List<InvalidateTarget> targets) {}
@@ -0,0 +1,12 @@
1
+ // @generated by clients. DO NOT EDIT.
2
+ package http.runtime;
3
+
4
+ /**
5
+ * Runs once per successful write with what it made stale; a throw goes to the log as an error
6
+ * entry, never to the call.
7
+ */
8
+ @FunctionalInterface
9
+ public interface InvalidateHook {
10
+ /** Told of {@code event}. */
11
+ void apply(InvalidateEvent event) throws java.lang.Exception;
12
+ }
@@ -0,0 +1,7 @@
1
+ // @generated by clients. DO NOT EDIT.
2
+ package http.runtime;
3
+
4
+ import java.util.Map;
5
+
6
+ /** One read a write made stale: its operationId, and the write's values for its path params. */
7
+ public record InvalidateTarget(String operationId, Map<String, String> params) {}
@@ -1,17 +1,37 @@
1
1
  // @generated by clients. DO NOT EDIT.
2
2
  package http.runtime;
3
3
 
4
- /** One operation's fixed description: its path params by spec name in path order. */
4
+ import java.util.Map;
5
+ import java.util.TreeMap;
6
+
7
+ /**
8
+ * One operation's fixed description: its path params by spec name in path order; a write's
9
+ * operationId and the reads its success makes stale, for onInvalidate.
10
+ */
5
11
  record Operation(
6
12
  String method,
7
13
  String template,
8
14
  String[] names,
9
15
  String accept,
10
16
  boolean idempotent,
11
- String[] invalidates) {
17
+ String[] invalidates,
18
+ String by,
19
+ Read[] reads) {
20
+ /** One read a write makes stale, as the generator resolved it: its operationId and params. */
21
+ record Read(String op, String[] params) {}
22
+
12
23
  /** An operation with no x-invalidate targets. */
13
24
  Operation(String method, String template, String[] names, String accept, boolean idempotent) {
14
- this(method, template, names, accept, idempotent, new String[0]);
25
+ this(method, template, names, accept, idempotent, new String[0], null, new Read[0]);
26
+ }
27
+
28
+ /** The call's path values by their template names: what a stale target's placeholders fill. */
29
+ Map<String, String> values(String[] path) {
30
+ Map<String, String> values = new TreeMap<>();
31
+ for (int i = 0; i < names.length; i++) {
32
+ values.put(names[i], path[i]);
33
+ }
34
+ return values;
15
35
  }
16
36
 
17
37
  /** The route as the log and the errors name it: {@code METHOD /template}. */
@@ -109,7 +109,9 @@ final class Realtime {
109
109
  op.names(),
110
110
  "text/event-stream",
111
111
  op.idempotent(),
112
- op.invalidates());
112
+ op.invalidates(),
113
+ op.by(),
114
+ op.reads());
113
115
  Call at =
114
116
  new Call(
115
117
  call.path(),
@@ -72,6 +72,9 @@ final class WsDial {
72
72
  if (options.raw() != null) {
73
73
  options.raw().fill(101, Map.of(), new byte[0], url);
74
74
  }
75
+ StaleTracker stale = exchange.stale();
76
+ stale.settle(stale.begin(op.method(), path), op.invalidates(), op.values(call.path()));
77
+ Hooks.onInvalidate(config, op, call.path(), true);
75
78
  return new TypedWebSocket<>(socket, read);
76
79
  }
77
80
 
@@ -41,7 +41,7 @@ export type Files = {
41
41
  readonly uploads?: Uploads
42
42
  readonly credential?: string
43
43
  readonly asked?: Record<string, unknown>
44
- readonly client?: { readonly extensions?: Record<string, unknown> }
44
+ readonly client?: { readonly extensions?: Record<string, unknown> } | undefined
45
45
  }
46
46
 
47
47
  /* canonical base64: whole quads, the last padded, its unused bits zero */
@@ -9,7 +9,11 @@ import { ErrorCode, failure, isId, type Reply } from "./jsonrpc.ts"
9
9
  import { BATCHED, claimed, isObject, MODERN, type Protocol, PROTOCOL_VERSIONS, unserved, VERSION } from "./protocol.ts"
10
10
 
11
11
  /** What the transport serves beside its own origin, its body cap in bytes, and its calls' files (a mount's). */
12
- export type HttpOptions = { readonly origins?: readonly string[]; readonly max?: number; readonly files?: Files }
12
+ export type HttpOptions = {
13
+ readonly origins?: readonly string[] | undefined
14
+ readonly max?: number | undefined
15
+ readonly files?: Files | undefined
16
+ }
13
17
 
14
18
  const SSE = { "cache-control": "no-cache", "content-type": "text/event-stream", "x-accel-buffering": "no" }
15
19
 
@@ -103,7 +107,7 @@ function streamed(
103
107
  protocol: Protocol,
104
108
  body: unknown,
105
109
  version: string,
106
- { closed, files }: { closed?: AbortSignal; files?: Files },
110
+ { closed, files }: { closed?: AbortSignal | undefined; files?: Files | undefined },
107
111
  ) {
108
112
  const call = new AbortController()
109
113
  const signal = closed ? AbortSignal.any([closed, call.signal]) : call.signal
@@ -25,7 +25,7 @@ export const bearer = (authorization: string | null, token: string): boolean =>
25
25
  /** `incoming` as a Request to `url`, every header kept as sent (a repeated one joined), `closed` its signal. */
26
26
  function requestOf(incoming: IncomingMessage, headers: Headers, url: string, closed: AbortSignal) {
27
27
  const post = incoming.method === "POST"
28
- const body = post ? (Readable.toWeb(incoming) as ReadableStream) : null
28
+ const body = post ? Readable.toWeb(incoming) : null
29
29
  return new Request(url, { body, duplex: "half", headers, method: incoming.method, signal: closed } as RequestInit)
30
30
  }
31
31
 
@@ -28,8 +28,8 @@ export type MountConfig = {
28
28
  */
29
29
  export type Mount = {
30
30
  readonly dispatch: (request: Request) => Promise<Response>
31
- readonly origins?: readonly string[]
32
- readonly max?: number
31
+ readonly origins?: readonly string[] | undefined
32
+ readonly max?: number | undefined
33
33
  readonly uploads?: Uploads | undefined
34
34
  readonly fetchFile?: FetchFile | undefined
35
35
  }
@@ -60,7 +60,7 @@ export type Context = {
60
60
  readonly signal: AbortSignal
61
61
  readonly notify: (message: object) => void
62
62
  readonly connection: Connection
63
- readonly files?: Files
63
+ readonly files?: Files | undefined
64
64
  }
65
65
 
66
66
  /** Each message's reply, a batch's, or none; a promise only for a call, never rejected. */
@@ -15,7 +15,7 @@ import httpx2
15
15
  from .errors import ConfigError
16
16
 
17
17
  if TYPE_CHECKING:
18
- from .hooks import RequestContext, ResponseContext
18
+ from .hooks import InvalidateEvent, RequestContext, ResponseContext
19
19
  from .log import LogEntry
20
20
 
21
21
  __all__ = ["ClientConfig", "InvalidationConfig", "RawResponse", "RequestOptions"]
@@ -41,7 +41,11 @@ class ClientConfig:
41
41
  WebSocket's ping interval and pong wait. A redirect to another origin is followed only under ``"follow"``, and
42
42
  never carries credentials, a body, or what an ``http_client`` adds. ``SDK`` runs the ``*_sync``
43
43
  hooks and a plain ``on_auth_expired``; ``AsyncSDK`` runs the others, and coroutine functions too.
44
- Either refuses, at construction, a hook it would not run.
44
+ Either refuses, at construction, a hook it would not run. ``on_invalidate`` (``on_invalidate_sync``)
45
+ runs once per call, after the final answer (an auth refresh included), for a 2xx write, its body
46
+ decoded or not, with the reads it made stale; the call returns after the last hook, so a hung one
47
+ holds it past ``timeout``. A stream's or socket's open runs them detached, waiting on none. A hook
48
+ that raises is an ``on_log`` error entry (dropped without ``on_log``), never the call's error.
45
49
  """
46
50
 
47
51
  base_url: str = ""
@@ -60,6 +64,8 @@ class ClientConfig:
60
64
  on_response: Sequence[Callable[[ResponseContext], Awaitable[None] | None]] = ()
61
65
  on_request_sync: Sequence[Callable[[RequestContext], None]] = ()
62
66
  on_response_sync: Sequence[Callable[[ResponseContext], None]] = ()
67
+ on_invalidate: Sequence[Callable[[InvalidateEvent], Awaitable[None] | None]] = ()
68
+ on_invalidate_sync: Sequence[Callable[[InvalidateEvent], None]] = ()
63
69
  on_log: Callable[[LogEntry], None] | None = None
64
70
  on_auth_expired: Callable[[], Awaitable[str | None] | str | None] | None = None
65
71
  invalidation: InvalidationConfig | None = None
@@ -29,7 +29,7 @@ from .errors import (
29
29
  loads,
30
30
  status_error,
31
31
  )
32
- from .hooks import RequestContext, ResponseContext
32
+ from .hooks import InvalidateEvent, RequestContext, ResponseContext, invalidation
33
33
  from .log import CallLog
34
34
  from .operation import Operation
35
35
  from .path import expand
@@ -112,6 +112,7 @@ class Exchange:
112
112
  self.hops = 0
113
113
  self.raw = options.get("raw") or RawResponse()
114
114
  self.failure: APIStatusError | None = None
115
+ self.invalidated: InvalidateEvent | None = None
115
116
 
116
117
  def check(self) -> float | None:
117
118
  cancel = self.options.get("cancel")
@@ -226,6 +227,7 @@ class Exchange:
226
227
  self.log.answered(answer.status)
227
228
  if 200 <= answer.status < 300:
228
229
  self.core.stale.settle(self.meta, self.op.invalidates, self.params)
230
+ self.invalidated = invalidation(self.op, self.params)
229
231
  else:
230
232
  self.failure = failure(answer, self.core)
231
233
  self.log.failed(self.failure)
@@ -1,9 +1,12 @@
1
1
  # @generated by clients. DO NOT EDIT.
2
2
  """The caller's hooks, TypeScript parity: ``on_request`` before each send, ``on_response`` on each
3
- answer, in order, sharing one ``state``; a hook that raises ends the call."""
3
+ answer, in order, sharing one ``state``; a hook that raises ends the call. ``on_invalidate`` once per
4
+ successful write (or stream open), in order, with what it made stale; a hook that raises is logged,
5
+ never the call's error."""
4
6
 
5
7
  from __future__ import annotations
6
8
 
9
+ import asyncio
7
10
  import inspect
8
11
  from collections.abc import Awaitable, Callable, Mapping, Sequence
9
12
  from dataclasses import dataclass, field
@@ -13,8 +16,10 @@ from .errors import ConfigError, HookError, HttpError
13
16
 
14
17
  if TYPE_CHECKING:
15
18
  from .config import ClientConfig
19
+ from .log import CallLog
20
+ from .operation import Operation
16
21
 
17
- __all__ = ["RequestContext", "ResponseContext"]
22
+ __all__ = ["InvalidateEvent", "InvalidateTarget", "RequestContext", "ResponseContext"]
18
23
 
19
24
  C = TypeVar("C")
20
25
 
@@ -49,6 +54,102 @@ class ResponseContext:
49
54
  state: dict[str, Any] = field(default_factory=dict, repr=False)
50
55
 
51
56
 
57
+ @dataclass(frozen=True)
58
+ class InvalidateTarget:
59
+ """One read a write made stale: its operationId, and the write's values for the read's own path
60
+ params; one the write lacks, or holds as ``""``, ``"."`` or ``".."``, is left out."""
61
+
62
+ operation_id: str
63
+ params: Mapping[str, str]
64
+
65
+
66
+ @dataclass(frozen=True)
67
+ class InvalidateEvent:
68
+ """What each ``on_invalidate`` hook sees: the write's operationId and every read it made stale."""
69
+
70
+ by: str
71
+ targets: tuple[InvalidateTarget, ...]
72
+
73
+
74
+ # a detached open's hook runs, held until they end so none is garbage-collected mid-run
75
+ DETACHED: set[asyncio.Task[None]] = set()
76
+
77
+ SEGMENTS = ("", ".", "..")
78
+
79
+
80
+ def invalidation(
81
+ op: Operation[object], params: Mapping[str, str]
82
+ ) -> InvalidateEvent | None:
83
+ """What a success of ``op`` with ``params`` made stale; ``None`` when it makes nothing stale."""
84
+ if not op.reads:
85
+ return None
86
+ targets = tuple(
87
+ InvalidateTarget(
88
+ read,
89
+ {n: params[n] for n in names if params.get(n, "") not in SEGMENTS},
90
+ )
91
+ for read, names in op.reads
92
+ )
93
+ return InvalidateEvent(op.by, targets)
94
+
95
+
96
+ class Logged:
97
+ """An ``Exception`` the block raises, swallowed as an ``on_log`` error entry."""
98
+
99
+ def __init__(self, log: CallLog) -> None:
100
+ self.log = log
101
+
102
+ def __enter__(self) -> None:
103
+ pass
104
+
105
+ def __exit__(
106
+ self, kind: object, error: BaseException | None, trace: object
107
+ ) -> bool:
108
+ if isinstance(error, Exception):
109
+ self.log.failed(error)
110
+ return True
111
+ return False
112
+
113
+
114
+ def invalidate_sync(
115
+ hooks: Sequence[Callable[[InvalidateEvent], None]],
116
+ event: InvalidateEvent | None,
117
+ log: CallLog,
118
+ ) -> None:
119
+ if event is None:
120
+ return
121
+ for hook in hooks:
122
+ with Logged(log):
123
+ hook(event)
124
+
125
+
126
+ async def invalidate_async(
127
+ hooks: Sequence[Callable[[InvalidateEvent], Awaitable[None] | None]],
128
+ event: InvalidateEvent | None,
129
+ log: CallLog,
130
+ ) -> None:
131
+ if event is None:
132
+ return
133
+ for hook in hooks:
134
+ with Logged(log):
135
+ result = hook(event)
136
+ if inspect.isawaitable(result):
137
+ await result
138
+
139
+
140
+ def detach(
141
+ hooks: Sequence[Callable[[InvalidateEvent], Awaitable[None] | None]],
142
+ event: InvalidateEvent | None,
143
+ log: CallLog,
144
+ ) -> None:
145
+ """The hooks run as a task the open never awaits; their errors logged as ``invalidate_async``'s."""
146
+ if event is None or not hooks:
147
+ return
148
+ task = asyncio.get_running_loop().create_task(invalidate_async(hooks, event, log))
149
+ DETACHED.add(task)
150
+ task.add_done_callback(DETACHED.discard)
151
+
152
+
52
153
  def wrapped(error: Exception, what: str = "hook") -> HttpError:
53
154
  return error if isinstance(error, HttpError) else HookError(f"{what}: {error}")
54
155
 
@@ -57,13 +158,17 @@ def refuse_hooks(config: ClientConfig, sync: bool) -> None:
57
158
  if sync and (
58
159
  config.on_request
59
160
  or config.on_response
161
+ or config.on_invalidate
60
162
  or inspect.iscoroutinefunction(config.on_auth_expired)
61
163
  ):
62
164
  raise ConfigError(
63
- "SDK runs on_request_sync, on_response_sync and a plain on_auth_expired"
165
+ "SDK runs on_request_sync, on_response_sync, on_invalidate_sync"
166
+ " and a plain on_auth_expired"
64
167
  )
65
- if not sync and (config.on_request_sync or config.on_response_sync):
66
- raise ConfigError("AsyncSDK runs on_request and on_response")
168
+ if not sync and (
169
+ config.on_request_sync or config.on_response_sync or config.on_invalidate_sync
170
+ ):
171
+ raise ConfigError("AsyncSDK runs on_request, on_response and on_invalidate")
67
172
 
68
173
 
69
174
  def run_sync(hooks: Sequence[Callable[[C], None]], context: C) -> None:
@@ -21,6 +21,8 @@ class Operation(Generic[T]):
21
21
  shape: Literal["array", "boolean", "number", "object", "string"] | None = None
22
22
  idempotent: bool = False
23
23
  invalidates: tuple[str, ...] = ()
24
+ by: str = ""
25
+ reads: tuple[tuple[str, tuple[str, ...]], ...] = ()
24
26
  stream: Literal["realtime", "sse", "ws"] | None = None
25
27
  headers: tuple[tuple[str, str, HeaderKind, bool], ...] = ()
26
28
  events: tuple[str, ...] | None = None
@@ -12,7 +12,13 @@ from .config import ClientConfig, Defaults
12
12
  from .errors import APIConnectionError, APITimeoutError, HttpError
13
13
  from .events import EventStream, raced
14
14
  from .exchange import CallArgs, ClientCore, Exchange, HttpAnswer, failure
15
- from .hooks import RequestContext, refuse_hooks, run_async
15
+ from .hooks import (
16
+ RequestContext,
17
+ detach,
18
+ invalidate_async,
19
+ refuse_hooks,
20
+ run_async,
21
+ )
16
22
  from .operation import Operation
17
23
  from .redirect import Hop, cross
18
24
  from .result import ANSWERS, Err, Ok, Result
@@ -108,7 +114,13 @@ class AsyncTransport(ClientCore):
108
114
  except asyncio.CancelledError:
109
115
  x.log.emit("error", "error", error="the call was canceled")
110
116
  raise
111
- return x.done(answer), live
117
+ x.done(answer)
118
+ hooks = self.config.on_invalidate
119
+ if x.stream:
120
+ detach(hooks, x.invalidated, x.log)
121
+ else:
122
+ await invalidate_async(hooks, x.invalidated, x.log)
123
+ return answer, live
112
124
 
113
125
  async def prepared(
114
126
  self, x: Exchange, token: str | None, is_retry: bool = False
@@ -9,7 +9,7 @@ from .auth import refresh_sync
9
9
  from .config import ClientConfig, Defaults
10
10
  from .errors import APIConnectionError, APITimeoutError, HttpError
11
11
  from .exchange import CallArgs, ClientCore, Exchange, HttpAnswer
12
- from .hooks import refuse_hooks, run_sync
12
+ from .hooks import invalidate_sync, refuse_hooks, run_sync
13
13
  from .operation import Operation
14
14
  from .redirect import Hop, cross
15
15
  from .result import ANSWERS, Err, Ok, Result
@@ -47,7 +47,9 @@ class SyncTransport(ClientCore):
47
47
  except HttpError as error:
48
48
  x.log.failed(error)
49
49
  raise
50
- return x.done(answer)
50
+ x.done(answer)
51
+ invalidate_sync(self.config.on_invalidate_sync, x.invalidated, x.log)
52
+ return answer
51
53
 
52
54
  def attempt(self, x: Exchange, token: str | None, is_retry: bool) -> HttpAnswer:
53
55
  ctx = x.request(token, is_retry)
@@ -37,6 +37,7 @@ from .errors import (
37
37
  )
38
38
  from .events import Cancel, raced
39
39
  from .exchange import CallArgs, Exchange
40
+ from .hooks import detach, invalidation
40
41
  from .operation import Operation
41
42
  from .send_async import AsyncTransport
42
43
 
@@ -324,7 +325,10 @@ class AsyncWsTransport(AsyncTransport):
324
325
  resume = {"reconnect_token": reconnect_token or None}
325
326
  query = {**(args.get("query") or {}), **resume}
326
327
  x = Exchange(self, op, {**args, "query": query}, stream=True)
327
- return cast("T", await self.socket(x, protocols, op))
328
+ socket = await self.socket(x, protocols, op)
329
+ self.stale.settle(x.meta, op.invalidates, x.params)
330
+ detach(self.config.on_invalidate, invalidation(op, x.params), x.log)
331
+ return cast("T", socket)
328
332
 
329
333
  async def socket(
330
334
  self,
@@ -12,7 +12,7 @@ use reqwest::header::HeaderName;
12
12
 
13
13
  use crate::auth::AuthState;
14
14
  use crate::errors::Error;
15
- use crate::hooks::{HookState, OnAuthExpiredHook, OnRequestHook, OnResponseHook};
15
+ use crate::hooks::{HookState, OnAuthExpiredHook, OnInvalidateHook, OnRequestHook, OnResponseHook};
16
16
  use crate::invalidation::InvalidationConfig;
17
17
  use crate::log::OnLogHook;
18
18
  use crate::redirect::RedirectPolicy;
@@ -56,6 +56,8 @@ pub struct ClientConfig {
56
56
  pub on_request: Vec<OnRequestHook>,
57
57
  pub on_response: Vec<OnResponseHook>,
58
58
  pub on_auth_expired: Option<OnAuthExpiredHook>,
59
+ /// Called with the reads each successful write made stale (`OnInvalidateHook`).
60
+ pub on_invalidate: Vec<OnInvalidateHook>,
59
61
  pub on_log: Option<OnLogHook>,
60
62
  pub state: Option<HookState>,
61
63
  }
@@ -78,6 +80,7 @@ impl Default for ClientConfig {
78
80
  on_request: Vec::new(),
79
81
  on_response: Vec::new(),
80
82
  on_auth_expired: None,
83
+ on_invalidate: Vec::new(),
81
84
  on_log: None,
82
85
  state: None,
83
86
  }
@@ -160,6 +163,7 @@ pub(crate) struct Inner {
160
163
  pub(crate) on_request: Vec<OnRequestHook>,
161
164
  pub(crate) on_response: Vec<OnResponseHook>,
162
165
  pub(crate) on_auth_expired: Option<OnAuthExpiredHook>,
166
+ pub(crate) on_invalidate: Vec<OnInvalidateHook>,
163
167
  pub(crate) on_log: Option<OnLogHook>,
164
168
  pub(crate) state: HookState,
165
169
  pub(crate) stale: StaleTracker,
@@ -242,6 +246,7 @@ impl Client {
242
246
  on_request: config.on_request,
243
247
  on_response: config.on_response,
244
248
  on_auth_expired: config.on_auth_expired,
249
+ on_invalidate: config.on_invalidate,
245
250
  on_log: config.on_log,
246
251
  state,
247
252
  stale: StaleTracker::new(config.invalidation.as_ref()),
@@ -1,7 +1,7 @@
1
1
  // @generated by clients. DO NOT EDIT.
2
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.
3
+ //! retry with a refreshed token on a 401, the capped body read, the timeout, the log, the stale
4
+ //! tracker and, after a 2xx, the `on_invalidate` hooks. A body past the cap is still an answer: its status and headers arrived, its body unread.
5
5
 
6
6
  use bytes::Bytes;
7
7
  use reqwest::header::{HeaderMap, HeaderName, HeaderValue};
@@ -11,7 +11,7 @@ use crate::body::Content;
11
11
  use crate::call::{Overrides, RawResponse};
12
12
  use crate::config::{Inner, parse_base};
13
13
  use crate::errors::{ApiError, Error};
14
- use crate::hooks::{RequestContext, ResponseContext};
14
+ use crate::hooks::{RequestContext, ResponseContext, detached, invalidated};
15
15
  use crate::invalidation::RequestMeta;
16
16
  use crate::log::CallLog;
17
17
  use crate::redirect::{Hop, send_following};
@@ -141,6 +141,7 @@ async fn run(
141
141
  .unwrap_or(Err(Error::Timeout)),
142
142
  None => x.with_auth().await,
143
143
  };
144
+ let mut event = None;
144
145
  match &answer {
145
146
  Ok(Answer { raw, .. }) => {
146
147
  log.answered(raw.status);
@@ -148,6 +149,7 @@ async fn run(
148
149
  inner
149
150
  .stale
150
151
  .settle(&x.meta, x.spec.invalidates, &x.spec.params);
152
+ event = x.spec.invalidate_event();
151
153
  } else if inner.on_log.is_some() {
152
154
  /* an error status logs the error its call ends with, as Go's does */
153
155
  log.failed(&Error::Api(ApiError::new(
@@ -159,6 +161,16 @@ async fn run(
159
161
  }
160
162
  Err(e) => log.failed(e),
161
163
  }
164
+ /* after the timeout: a hook never fails the call, and a stream's open never waits on one */
165
+ if let Some(event) = event {
166
+ let operation = x.spec.operation();
167
+ if stream {
168
+ detached(inner, operation, event);
169
+ } else {
170
+ let on_log = inner.on_log.as_ref();
171
+ invalidated(&inner.on_invalidate, on_log, &operation, event).await;
172
+ }
173
+ }
162
174
  answer
163
175
  }
164
176