@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
@@ -17,8 +17,8 @@ function describeSettings(result, dryRun) {
17
17
  return "settings in step";
18
18
  return `settings ${dryRun ? "would change" : "changed"}: ${result.changed.join(", ")}`;
19
19
  }
20
- /* Applies the repo settings after the tree step, whatever it did: a failure there fails the package but keeps
21
- * what already landed (the pushed commit and tag) in the result. */
20
+ // Applies the repo settings after the tree step, whatever it did: a failure there fails the package but keeps
21
+ // what already landed (the pushed commit and tag) in the result.
22
22
  async function withSettings(entry, options, result) {
23
23
  try {
24
24
  return {
@@ -36,8 +36,8 @@ async function withSettings(entry, options, result) {
36
36
  }
37
37
  }
38
38
  const tagged = (tag) => (tag === undefined ? {} : { tag });
39
- /* Only the bot commits to a public repo. Any other committer is a hand edit there that a snapshot would silently
40
- erase: its reason, or undefined when the tip is the bot's, there is none, or bootstrap judged it already. */
39
+ // Only the bot commits to a public repo. Any other committer is a hand edit there that a snapshot would silently
40
+ // erase: its reason, or undefined when the tip is the bot's, there is none, or bootstrap judged it already.
41
41
  async function foreignTip({ entry, options, remoteTip, worktree }) {
42
42
  if (!remoteTip || options.overwriteForeignTip)
43
43
  return undefined;
@@ -46,8 +46,8 @@ async function foreignTip({ entry, options, remoteTip, worktree }) {
46
46
  return undefined;
47
47
  return `external push detected on mirror; reconcile manually (tip=${remoteTip}, committer=${committer})`;
48
48
  }
49
- /* The source's tree over the public tip, with the release workflow its registries render (a package that ships its
50
- own lists none): why it cannot be, or undefined. */
49
+ // The source's tree over the public tip, with the release workflow its registries render (a package that ships its
50
+ // own lists none): why it cannot be, or undefined.
51
51
  async function stageTree({ entry, options, worktree }) {
52
52
  await replaceTreeWithSource({
53
53
  excludes: options.applyBootstrapExclude && entry.bootstrapExclude ? [...entry.bootstrapExclude] : [],
@@ -58,14 +58,13 @@ async function stageTree({ entry, options, worktree }) {
58
58
  if (entry.registries.length === 0)
59
59
  return undefined;
60
60
  const workflow = join(worktree, RELEASE_WORKFLOW);
61
- if (existsSync(workflow)) {
61
+ if (existsSync(workflow))
62
62
  return `${join(entry.path, RELEASE_WORKFLOW)} exists and the package lists registries: drop one, the other writes it`;
63
- }
64
63
  mkdirSync(dirname(workflow), { recursive: true });
65
64
  writeFileSync(workflow, releaseWorkflow(entry.registries));
66
65
  return undefined;
67
66
  }
68
- /* Generated output prod does not serve must not ship; hand files go out regardless: the refusal, or undefined. */
67
+ // Generated output prod does not serve must not ship; hand files go out regardless: the refusal, or undefined.
69
68
  async function drift({ entry, key, options, worktree }) {
70
69
  const generated = generatedPaths(join(options.repoRoot, entry.path));
71
70
  const changed = (await gitOutput(["-C", worktree, "diff", "--cached", "--name-only"], worktree)).split("\n");
@@ -74,7 +73,7 @@ async function drift({ entry, key, options, worktree }) {
74
73
  const gate = await options.specGate(entry.spec);
75
74
  return gate.status === "drift" ? describeDrift(key, gate) : undefined;
76
75
  }
77
- /* the tip is the bot's and equals the source, so a tag a stopped run never pushed goes on it */
76
+ // the tip is the bot's and equals the source, so a tag a stopped run never pushed goes on it
78
77
  async function skipUnchanged(run) {
79
78
  const { entry, httpsUrl, key, options, worktree } = run;
80
79
  const tag = await pendingTag(entry, options.repoRoot, worktree, httpsUrl);
@@ -87,7 +86,7 @@ async function skipUnchanged(run) {
87
86
  ...tagged(tag),
88
87
  });
89
88
  }
90
- /* the snapshot committed and pushed, then its tag; on a dry run, what would be */
89
+ // the snapshot committed and pushed, then its tag; on a dry run, what would be
91
90
  async function push(run) {
92
91
  const { entry, headSha, httpsUrl, key, message, options, remoteTip, worktree } = run;
93
92
  const tag = await pendingTag(entry, options.repoRoot, worktree, httpsUrl);
@@ -106,7 +105,7 @@ async function push(run) {
106
105
  await pushTag(worktree, httpsUrl, tag);
107
106
  return withSettings(entry, options, { mirrorSha, name: key, sourceSha: headSha, status: "synced", ...tagged(tag) });
108
107
  }
109
- /* each step in turn; the first that refuses fails the package */
108
+ // each step in turn; the first that refuses fails the package
110
109
  async function syncIn(run) {
111
110
  await prepareWorktree(run.worktree, run.httpsUrl, run.entry, run.remoteTip);
112
111
  const foreign = await foreignTip(run);
@@ -138,7 +137,7 @@ export async function syncPackage(entry, options) {
138
137
  sidecarMessage: readSidecar(options.repoRoot, entry.path),
139
138
  templateMessage: entry.commitMessage,
140
139
  });
141
- const worktree = mkdtempSync(join(tmpdir(), `public-sync-${key.replace(/\//g, "-")}-`));
140
+ const worktree = mkdtempSync(join(tmpdir(), `public-sync-${key.replaceAll("/", "-")}-`));
142
141
  try {
143
142
  return await syncIn({ entry, headSha, httpsUrl, key, message, options, remoteTip, worktree });
144
143
  }
@@ -6,34 +6,34 @@ import type { Target } from "../gen/targets.ts";
6
6
  /** The package metadata clients writes into each generated package's manifest; every field is optional. */
7
7
  export type PackageMetadata = {
8
8
  /** Authors, as `Name <email>`. */
9
- readonly authors?: readonly string[];
9
+ readonly authors?: readonly string[] | undefined;
10
10
  /** The changelog's URL. */
11
- readonly changelog?: string;
11
+ readonly changelog?: string | undefined;
12
12
  /** The copyright line. */
13
- readonly copyright?: string;
13
+ readonly copyright?: string | undefined;
14
14
  /** A one-line description. */
15
- readonly description?: string;
15
+ readonly description?: string | undefined;
16
16
  /** The documentation's URL. */
17
- readonly documentation?: string;
17
+ readonly documentation?: string | undefined;
18
18
  /** The project's site. */
19
- readonly homepage?: string;
19
+ readonly homepage?: string | undefined;
20
20
  /** The package icon's path, relative to the repo root. */
21
- readonly icon?: string;
21
+ readonly icon?: string | undefined;
22
22
  /** Registry search keywords. */
23
- readonly keywords?: readonly string[];
23
+ readonly keywords?: readonly string[] | undefined;
24
24
  /** The SPDX license expression. */
25
- readonly license?: string;
25
+ readonly license?: string | undefined;
26
26
  /** The license file's path, relative to the repo root. */
27
- readonly licenseFile?: string;
27
+ readonly licenseFile?: string | undefined;
28
28
  /** The README's path, relative to the repo root. */
29
- readonly readme?: string;
29
+ readonly readme?: string | undefined;
30
30
  /** The source repository's URL. */
31
- readonly repository?: string;
31
+ readonly repository?: string | undefined;
32
32
  };
33
33
  /** How clients generates a package: its target, and that target's options by name. */
34
34
  export type ReleaseRun = {
35
35
  /** The target's options, as `--<target>-<option>` takes them; none by default. */
36
- readonly options?: Readonly<Record<string, string>>;
36
+ readonly options?: Readonly<Record<string, string>> | undefined;
37
37
  /** The clients target the package is generated with. */
38
38
  readonly target: Target;
39
39
  };
@@ -50,21 +50,21 @@ export type Registry = {
50
50
  /** One public package a config lists. */
51
51
  export type ManifestPackageInput = {
52
52
  /** Globs bootstrap leaves out of the first push, so the next sync adds them as their own commit. */
53
- readonly bootstrapExclude?: readonly string[];
53
+ readonly bootstrapExclude?: readonly string[] | undefined;
54
54
  /** The public repo's branch sync pushes to; `main` by default. */
55
- readonly branch?: string;
55
+ readonly branch?: string | undefined;
56
56
  /** The message of each snapshot commit, unless the package's `.publicsync-message` names one. */
57
57
  readonly commitMessage: string;
58
58
  /** The package's one description: its public repo's, every registry's, and its first CHANGELOG entry. */
59
59
  readonly description: string;
60
60
  /** How clients generates it; absent for a package backend does not generate (the spec itself). */
61
- readonly clients?: ReleaseRun;
61
+ readonly clients?: ReleaseRun | undefined;
62
62
  /** This package's metadata over the product's; its keywords add to the product's. */
63
- readonly metadata?: PackageMetadata;
63
+ readonly metadata?: PackageMetadata | undefined;
64
64
  /** The package's slug: its dir beside the config, and the key bump's `RELEASE_VERSIONS` uses. */
65
65
  readonly name: string;
66
66
  /** The registries its release workflow publishes to; none for a package that ships its own workflow. */
67
- readonly registries?: readonly Registry[];
67
+ readonly registries?: readonly Registry[] | undefined;
68
68
  /** The public repo, `owner/name` on github.com. */
69
69
  readonly repo: string;
70
70
  /** The public repo's GitHub topics, 1 to 20 lowercase slugs. */
@@ -89,11 +89,11 @@ export type ReleaseManifestInput = {
89
89
  /** The command that regenerates every package of the product, run from the repo root; it honors `RELEASE_VERSIONS`. */
90
90
  readonly codegen: readonly string[];
91
91
  /** The identity sync commits as; `public-sync[bot]` by default, so another org's GitHub App can sync. */
92
- readonly committer?: Committer;
92
+ readonly committer?: Committer | undefined;
93
93
  /** The product's site: every public repo's website and every registry's homepage. */
94
94
  readonly homepage: string;
95
95
  /** The metadata every generated package of the product carries. */
96
- readonly metadata?: PackageMetadata;
96
+ readonly metadata?: PackageMetadata | undefined;
97
97
  /** The product's public packages, at least one; each name and repo once. */
98
98
  readonly packages: readonly ManifestPackageInput[];
99
99
  /** The product's slug: the `<project>/<name>` key of each package, and what its codegen filters on. */
@@ -104,14 +104,14 @@ export type ReleaseManifestInput = {
104
104
  * The tools codegen needs, each a dep name in the repo root's `system.config.ts`; the release workflows install
105
105
  * them in this order before codegen runs. None by default.
106
106
  */
107
- readonly toolchains?: readonly string[];
107
+ readonly toolchains?: readonly string[] | undefined;
108
108
  };
109
109
  /** A listed package with its defaults applied. */
110
110
  export type ManifestPackage = ManifestPackageInput & {
111
111
  /** The public repo's branch. */
112
112
  readonly branch: string;
113
113
  /** The package's metadata: the product's, then its own over it. */
114
- readonly metadata?: PackageMetadata;
114
+ readonly metadata?: PackageMetadata | undefined;
115
115
  /** The registries its release workflow publishes to, possibly none. */
116
116
  readonly registries: readonly Registry[];
117
117
  };
@@ -1 +0,0 @@
1
- export {};
@@ -2,13 +2,12 @@ type VersionFile = {
2
2
  read(text: string): string;
3
3
  write(text: string, version: string): string;
4
4
  };
5
+ /** The name of a version file bump keeps in step. */
6
+ export type VersionFileName = "jsr.json" | "package.json" | "pyproject.toml";
5
7
  /** The version files bump keeps in step with `.release-state.json`, by file name. */
6
8
  export declare const VERSION_FILES: {
7
- readonly "jsr.json": VersionFile;
8
- readonly "package.json": VersionFile;
9
- readonly "pyproject.toml": VersionFile;
9
+ readonly [N in VersionFileName]: VersionFile;
10
10
  };
11
- export type VersionFileName = keyof typeof VERSION_FILES;
12
11
  /** Each version file present in `dir` with the version it holds; throws naming the file whose version line is missing or doubled. */
13
12
  export declare function readVersions(dir: string): Partial<Record<VersionFileName, string>>;
14
13
  /** Writes `version` into every version file present in `dir`; returns the paths written. */
@@ -3,21 +3,20 @@ import { join } from "node:path";
3
3
  /** The one match of `pattern` (whose group 1 always participates) in `text`, or a throw naming `what`. */
4
4
  function only(text, pattern, what) {
5
5
  const matches = [...text.matchAll(new RegExp(pattern.source, `${pattern.flags.replace("g", "")}g`))];
6
- if (matches.length !== 1) {
6
+ if (matches.length !== 1)
7
7
  throw new Error(`expected one ${what}, found ${matches.length}`);
8
- }
9
8
  return matches[0];
10
9
  }
11
10
  function replaceAt(text, match, replacement) {
12
11
  return text.slice(0, match.index) + replacement + text.slice(match.index + match[0].length);
13
12
  }
14
- /* The top-level `"version"` of a tab-indented JSON manifest. */
13
+ // The top-level `"version"` of a tab-indented JSON manifest.
15
14
  const JSON_VERSION = /^\t"version": "([^"]+)"/m;
16
15
  const json = {
17
16
  read: (text) => only(text, JSON_VERSION, 'top-level "version"')[1],
18
17
  write: (text, version) => replaceAt(text, only(text, JSON_VERSION, 'top-level "version"'), `\t"version": "${version}"`),
19
18
  };
20
- /* The `version = "…"` line of the `[project]` table, which ends at the next table header. */
19
+ // The `version = "…"` line of the `[project]` table, which ends at the next table header.
21
20
  const PROJECT_TABLE = /^\[project\]\n((?:(?!\[).*\n?)*)/m;
22
21
  const TOML_VERSION = /^version = "([^"]+)"$/m;
23
22
  const pyproject = {
@@ -51,7 +50,7 @@ export function readVersions(dir) {
51
50
  versions[name] = VERSION_FILES[name].read(readFileSync(file, "utf8"));
52
51
  }
53
52
  catch (error) {
54
- /* each read throws only `only`'s Error */
53
+ // each read throws only `only`'s Error
55
54
  throw new Error(`${file}: ${error.message}`, {
56
55
  cause: error,
57
56
  });
@@ -0,0 +1,8 @@
1
+ // The runtime is read as text and vendored into every generated TS and MCP SDK, so it keeps the style the
2
+ // emitters format SDKs in (EMIT_STYLE in src/emit/shared/format.ts), not the repo's: tabs, no semicolons, imports
3
+ // as written. Its byte locks in scripts/sdk-budget*.test.ts measure the shipped text.
4
+ {
5
+ "printWidth": 120,
6
+ "semi": false,
7
+ "useTabs": true,
8
+ }
@@ -63,6 +63,13 @@ public sealed record ClientConfig
63
63
  /// <summary>Asked once per call for a new token after a 401, with the call's token; null or empty keeps the 401.</summary>
64
64
  public Func<CancellationToken, Task<string?>>? OnAuthExpired { get; init; }
65
65
 
66
+ /// <summary>
67
+ /// Run in order once per successful write, each after the last, with what it made stale and the call's token: the
68
+ /// call returns after the last. An event stream or WebSocket runs them when it opens, without waiting. A hook's
69
+ /// error goes to <see cref="OnLog"/> as an error entry and never to the call; the next hook still runs.
70
+ /// </summary>
71
+ public IReadOnlyList<Func<InvalidateEvent, CancellationToken, Task>>? OnInvalidate { get; init; }
72
+
66
73
  /// <summary>Told of each call's start, its answer and its error; what it throws is ignored.</summary>
67
74
  public Action<LogEntry>? OnLog { get; init; }
68
75
 
@@ -83,7 +90,8 @@ public sealed record ClientConfig
83
90
  builder.Append(", Redirect = ").Append(Redirect);
84
91
  builder.Append(", MaxResponseBytes = ").Append(MaxResponseBytes);
85
92
  (string Name, bool Set)[] hooks =
86
- [("OnRequest", OnRequest is not null), ("OnResponse", OnResponse is not null), ("OnAuthExpired", OnAuthExpired is not null), ("OnLog", OnLog is not null)];
93
+ [("OnRequest", OnRequest is not null), ("OnResponse", OnResponse is not null), ("OnAuthExpired", OnAuthExpired is not null), ("OnInvalidate", OnInvalidate is not null),
94
+ ("OnLog", OnLog is not null)];
87
95
  builder.Append(", Hooks = [").Append(string.Join(", ", hooks.Where(hook => hook.Set).Select(hook => hook.Name))).Append(']');
88
96
  return true;
89
97
  }
@@ -31,8 +31,14 @@ internal sealed class Exchange(Transport client, Operation op, Call call, bool s
31
31
  private int _redirects;
32
32
  private HttpResponseMessage? _live;
33
33
 
34
- public async Task<(RawResponse Raw, SdkException? Error)> RunAsync(CancellationToken cancellationToken) =>
35
- Done(await BoundedAsync(cancellationToken).ConfigureAwait(false));
34
+ private bool _settled;
35
+
36
+ public async Task<(RawResponse Raw, SdkException? Error)> RunAsync(CancellationToken cancellationToken)
37
+ {
38
+ var done = Done(await BoundedAsync(cancellationToken).ConfigureAwait(false));
39
+ await InvalidatedAsync(cancellationToken).ConfigureAwait(false);
40
+ return done;
41
+ }
36
42
 
37
43
  public async Task<HttpResponseMessage> OpenAsync(CancellationToken cancellationToken)
38
44
  {
@@ -44,6 +50,7 @@ internal sealed class Exchange(Transport client, Operation op, Call call, bool s
44
50
  throw error;
45
51
  }
46
52
  call.Read?.Invoke(raw.Headers);
53
+ Detached();
47
54
  return _live!;
48
55
  }
49
56
  catch
@@ -231,8 +238,8 @@ internal sealed class Exchange(Transport client, Operation op, Call call, bool s
231
238
  SdkException? error = null;
232
239
  if (answer.Status is >= 200 and < 300)
233
240
  {
234
- var values = op.PathParams.Zip(call.Path).ToDictionary(pair => pair.First, pair => pair.Second);
235
- client.Stale.Settle(_meta, op.Invalidates ?? [], values);
241
+ client.Stale.Settle(_meta, op.Invalidates ?? [], Values);
242
+ _settled = true;
236
243
  error = answer.Over ? new DecodeException($"the answer exceeds {Max} bytes") : null;
237
244
  }
238
245
  else
@@ -244,4 +251,49 @@ internal sealed class Exchange(Transport client, Operation op, Call call, bool s
244
251
  raw.Fill(answer.Status, answer.Headers, answer.Body, answer.Url);
245
252
  return (raw, error);
246
253
  }
254
+
255
+ private Dictionary<string, string> Values => op.PathParams.Zip(call.Path).ToDictionary(pair => pair.First, pair => pair.Second);
256
+
257
+ /* a socket's 101: its targets marked stale, and the hooks run detached */
258
+ public void Opened()
259
+ {
260
+ _meta = client.Stale.Begin(op.Method, UrlPath.Expand(op, call.Path));
261
+ client.Stale.Settle(_meta, op.Invalidates ?? [], Values);
262
+ _settled = true;
263
+ Detached();
264
+ }
265
+
266
+ /* an open never waits on a hook nor ends its token; InvalidatedAsync never throws */
267
+ private void Detached()
268
+ {
269
+ if (op.Reads is { Length: > 0 } && client.Config.OnInvalidate is { Count: > 0 })
270
+ {
271
+ _ = Task.Run(() => InvalidatedAsync(CancellationToken.None));
272
+ }
273
+ }
274
+
275
+ /* each OnInvalidate hook in order after a 2xx, a hook's error logged and never the call's */
276
+ private async Task InvalidatedAsync(CancellationToken token)
277
+ {
278
+ if (!_settled || op.Reads is not { Length: > 0 } reads || client.Config.OnInvalidate is not { Count: > 0 } hooks)
279
+ {
280
+ return;
281
+ }
282
+ var values = Values;
283
+ var targets = reads.Select(read => new InvalidateTarget(read.Op, read.Params
284
+ .Where(name => values.TryGetValue(name, out var value) && value is not ("" or "." or ".."))
285
+ .ToDictionary(name => name, name => values[name], StringComparer.Ordinal))).ToList();
286
+ var e = new InvalidateEvent(op.By ?? "", targets);
287
+ foreach (var hook in hooks)
288
+ {
289
+ try
290
+ {
291
+ await hook(e, token).ConfigureAwait(false);
292
+ }
293
+ catch (Exception error)
294
+ {
295
+ _log.Failed(error);
296
+ }
297
+ }
298
+ }
247
299
  }
@@ -104,6 +104,15 @@ public sealed class ResponseContext
104
104
  $"ResponseContext {{ Status = {Status}, IsRetry = {IsRetry}, Selector = {Selector}, IsStale = {IsStale}, InvalidatedBy = [{string.Join(", ", InvalidatedBy)}] }}";
105
105
  }
106
106
 
107
+ /// <summary>
108
+ /// What each <c>ClientConfig.OnInvalidate</c> hook sees after a successful write: the write's operationId, and every
109
+ /// read its <c>x-invalidate</c> made stale.
110
+ /// </summary>
111
+ public sealed record InvalidateEvent(string By, IReadOnlyList<InvalidateTarget> Targets);
112
+
113
+ /// <summary>One read a write made stale: its operationId, and the write's values for the read's path params it has.</summary>
114
+ public sealed record InvalidateTarget(string OperationId, IReadOnlyDictionary<string, string> Params);
115
+
107
116
  internal sealed record CallState(bool IsRetry, string Selector, bool IsStale, IReadOnlyList<string> InvalidatedBy, IDictionary<string, object?> State);
108
117
 
109
118
  internal static class Hooks
@@ -6,7 +6,12 @@ using System.Text.Json.Serialization.Metadata;
6
6
 
7
7
  namespace Http.Runtime;
8
8
 
9
- internal sealed record Operation(string Method, string Path, string[] PathParams, bool Idempotent, string? Accept = null, string[]? Invalidates = null);
9
+ /* By and Reads: a write's operationId and the reads its success makes stale, for ClientConfig.OnInvalidate */
10
+ internal sealed record Operation(
11
+ string Method, string Path, string[] PathParams, bool Idempotent, string? Accept = null, string[]? Invalidates = null, string? By = null, StaleRead[]? Reads = null);
12
+
13
+ /* one read a write makes stale, as the generator resolved it: its operationId and its own path params */
14
+ internal sealed record StaleRead(string Op, string[] Params);
10
15
 
11
16
  internal sealed record Defaults(string? BaseUrl, string AuthHeader, string AuthPrefix, JsonSerializerOptions Json);
12
17
 
@@ -50,7 +50,9 @@ internal static class WsDial
50
50
  x.Raw?.Fill(101, headers, [], SocketUrl(url));
51
51
  var stream = Connection(await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false));
52
52
  var options = new WebSocketCreationOptions { SubProtocol = chosen, KeepAliveInterval = KeepAlive, KeepAliveTimeout = KeepAlive };
53
- return new TypedWebSocket(WebSocket.CreateFromStream(stream, options), chosen, response);
53
+ var socket = new TypedWebSocket(WebSocket.CreateFromStream(stream, options), chosen, response);
54
+ x.Opened();
55
+ return socket;
54
56
  }
55
57
  catch
56
58
  {
@@ -24,6 +24,10 @@ import (
24
24
  //
25
25
  // WSKeepalive is a WebSocket's ping interval and pong wait: zero means 20s, negative none.
26
26
  //
27
+ // OnInvalidate's hooks run in order once per successful write that makes reads stale, before the
28
+ // call returns and with its context: a stream or socket calls them detached once it opens. A
29
+ // hook's error goes to OnLog and never fails the call.
30
+ //
27
31
  // AuthHeaderName and AuthHeaderPrefix are a pair: leave both empty for the API's scheme; set the
28
32
  // name and the prefix is yours (empty means none); set only the prefix to keep the scheme's header.
29
33
  type Config struct {
@@ -40,6 +44,7 @@ type Config struct {
40
44
  OnRequest []func(*RequestContext) error
41
45
  OnResponse []func(*ResponseContext) error
42
46
  OnLog func(LogEntry)
47
+ OnInvalidate []func(context.Context, InvalidateEvent) error
43
48
  MaxResponseBytes int64
44
49
  WSKeepalive time.Duration
45
50
 
@@ -3,8 +3,10 @@
3
3
  package sdk
4
4
 
5
5
  import (
6
+ "context"
6
7
  "fmt"
7
8
  "net/http"
9
+ "time"
8
10
  )
9
11
 
10
12
  // RequestContext is what each OnRequest hook sees, in declaration order. A hook may change
@@ -51,3 +53,71 @@ func (m *RequestMeta) stale() (string, bool, []string) {
51
53
  }
52
54
  return m.Selector, m.IsStale, m.InvalidatedBy
53
55
  }
56
+
57
+ // InvalidateTarget is one read a write made stale: its operationId, and the write's values for the
58
+ // read's own path params. A param the write lacks, or holds as "", "." or "..", is left out.
59
+ type InvalidateTarget struct {
60
+ OperationID string
61
+ Params map[string]string
62
+ }
63
+
64
+ // InvalidateEvent is what each OnInvalidate hook sees after a successful write: the write's
65
+ // operationId and every read it made stale.
66
+ type InvalidateEvent struct {
67
+ By string
68
+ Targets []InvalidateTarget
69
+ }
70
+
71
+ // staleRead is one read a write makes stale, as the emitter resolved it: its operationId and its
72
+ // own path params.
73
+ type staleRead struct {
74
+ op string
75
+ params []string
76
+ }
77
+
78
+ // invalidated calls each OnInvalidate hook in order, each after the last returned, with what c
79
+ // made stale; none when c makes nothing stale. A hook's error or panic goes to OnLog as an error
80
+ // entry, never to the call, and is dropped without OnLog; the next hook still runs.
81
+ func invalidated(ctx context.Context, cfg Config, c *call) {
82
+ if len(c.reads) == 0 || len(cfg.OnInvalidate) == 0 {
83
+ return
84
+ }
85
+ event := InvalidateEvent{By: c.by, Targets: make([]InvalidateTarget, len(c.reads))}
86
+ for i, read := range c.reads {
87
+ known := map[string]string{}
88
+ for _, name := range read.params {
89
+ if v := c.params[name]; v != "" && v != "." && v != ".." {
90
+ known[name] = v
91
+ }
92
+ }
93
+ event.Targets[i] = InvalidateTarget{OperationID: read.op, Params: known}
94
+ }
95
+ for _, hook := range cfg.OnInvalidate {
96
+ start := time.Now()
97
+ if err := runInvalidateHook(ctx, hook, event); err != nil {
98
+ emitLog(cfg, errorEntry(c.operation, start, err))
99
+ }
100
+ }
101
+ }
102
+
103
+ // runInvalidateHook calls hook, its panic recovered as its error (wrapping a panicked error), so
104
+ // a faulty hook neither crashes a detached open nor changes the write's result.
105
+ func runInvalidateHook(ctx context.Context, hook func(context.Context, InvalidateEvent) error, event InvalidateEvent) (err error) {
106
+ defer func() {
107
+ switch r := recover().(type) {
108
+ case nil:
109
+ case error:
110
+ err = fmt.Errorf("httpsdk: OnInvalidate hook panicked: %w", r)
111
+ default:
112
+ err = fmt.Errorf("httpsdk: OnInvalidate hook panicked: %v", r)
113
+ }
114
+ }()
115
+ return hook(ctx, event)
116
+ }
117
+
118
+ // opened settles a stream or socket once it opened: its targets marked stale, and the
119
+ // OnInvalidate hooks called detached, so the open never waits on them nor ends their context.
120
+ func opened(ctx context.Context, cfg Config, c *call) {
121
+ c.stale.settle(c)
122
+ go invalidated(context.WithoutCancel(ctx), cfg, c)
123
+ }
@@ -26,6 +26,8 @@ type call struct {
26
26
  invalidates []string // declared invalidation targets, `METHOD /template`
27
27
  params map[string]string // path params, to expand templated targets
28
28
  meta *RequestMeta
29
+ by string // the operationId an InvalidateEvent names
30
+ reads []staleRead // the reads a success makes stale, for OnInvalidate
29
31
  }
30
32
 
31
33
  // requestResult is a buffered answer: its body after the OnResponse hooks, the response, and
@@ -50,8 +52,8 @@ type exchange struct {
50
52
  var ErrResponseTooLarge = errors.New("httpsdk: response body exceeds MaxResponseBytes")
51
53
 
52
54
  // doRequest sends c and buffers its answer (run), honoring the call's timeout and the stale
53
- // tracker. A ctx already done sends nothing: OnLog sees only its error. A 2xx past the cap is a
54
- // *DecodeError.
55
+ // tracker, then runs the OnInvalidate hooks with the caller's ctx. A ctx already done sends
56
+ // nothing: OnLog sees only its error. A 2xx past the cap is a *DecodeError.
55
57
  func doRequest(ctx context.Context, cfg Config, c *call, opts []RequestOption) (*requestResult, error) {
56
58
  x := &exchange{cfg: cfg, rc: newRequestConfig(cfg, opts), c: c}
57
59
  if ctx.Err() != nil {
@@ -59,6 +61,7 @@ func doRequest(ctx context.Context, cfg Config, c *call, opts []RequestOption) (
59
61
  emitLog(cfg, errorEntry(c.operation, time.Now(), err))
60
62
  return nil, err
61
63
  }
64
+ caller := ctx
62
65
  if x.rc.timeout > 0 {
63
66
  var cancel context.CancelFunc
64
67
  ctx, cancel = context.WithTimeout(ctx, x.rc.timeout)
@@ -70,6 +73,7 @@ func doRequest(ctx context.Context, cfg Config, c *call, opts []RequestOption) (
70
73
  return nil, err
71
74
  }
72
75
  c.stale.settle(c)
76
+ invalidated(caller, cfg, c)
73
77
  if result.over {
74
78
  return nil, &DecodeError{result.resp, ErrResponseTooLarge}
75
79
  }
@@ -14,7 +14,8 @@ import (
14
14
  )
15
15
 
16
16
  // openStream sends a streaming request through every call's exchange (run), the call's timeout
17
- // bounding it up to the headers, never the body. A non-2xx is a typed error. The caller owns the body.
17
+ // bounding it up to the headers, never the body. A non-2xx is a typed error; a 2xx settles the call
18
+ // (opened). The caller owns the body.
18
19
  func openStream(ctx context.Context, cfg Config, c *call, opts []RequestOption) (*http.Response, error) {
19
20
  if c.headers == nil {
20
21
  c.headers = map[string]string{}
@@ -28,6 +29,7 @@ func openStream(ctx context.Context, cfg Config, c *call, opts []RequestOption)
28
29
  if err != nil {
29
30
  return nil, err
30
31
  }
32
+ opened(ctx, cfg, c)
31
33
  return result.resp, nil
32
34
  }
33
35
  open, cancel := context.WithCancelCause(ctx)
@@ -38,6 +40,7 @@ func openStream(ctx context.Context, cfg Config, c *call, opts []RequestOption)
38
40
  cancel(nil)
39
41
  return nil, err
40
42
  }
43
+ opened(ctx, cfg, c)
41
44
  result.resp.Body = releasing{result.resp.Body, cancel}
42
45
  return result.resp, nil
43
46
  }
@@ -90,7 +90,8 @@ func dialWebSocket[In, Out any](ctx context.Context, cfg Config, c *call, read f
90
90
  return &TypedWebSocket[In, Out]{conn: conn, stop: keepAlive(conn, cfg.WSKeepalive), read: read, write: write}, nil
91
91
  }
92
92
 
93
- // dialSocket opens the call's WebSocket as the client calls; an error status is its *APIError.
93
+ // dialSocket opens the call's WebSocket as the client calls, settling it once open (opened); an
94
+ // error status is its *APIError.
94
95
  func dialSocket(ctx context.Context, cfg Config, c *call, opts []RequestOption) (*websocket.Conn, error) {
95
96
  rc := newRequestConfig(cfg, opts)
96
97
  u, err := buildURL(rc.baseURL, c.path, c.query)
@@ -115,6 +116,7 @@ func dialSocket(ctx context.Context, cfg Config, c *call, opts []RequestOption)
115
116
  }
116
117
  rc.deliver(resp, nil)
117
118
  conn.SetReadLimit(defaultWSReadLimit)
119
+ opened(ctx, cfg, c)
118
120
  return conn, nil
119
121
  }
120
122
 
@@ -24,6 +24,7 @@ final class ClientConfig {
24
24
  private final List<RequestHook> onRequest;
25
25
  private final List<ResponseHook> onResponse;
26
26
  private final Supplier<String> onAuthExpired;
27
+ private final List<InvalidateHook> onInvalidate;
27
28
  private final Consumer<LogEntry> onLog;
28
29
  private final RedirectPolicy redirect;
29
30
  private final long maxResponseBytes;
@@ -39,6 +40,7 @@ final class ClientConfig {
39
40
  this.onRequest = List.copyOf(builder.onRequest);
40
41
  this.onResponse = List.copyOf(builder.onResponse);
41
42
  this.onAuthExpired = builder.onAuthExpired;
43
+ this.onInvalidate = List.copyOf(builder.onInvalidate);
42
44
  this.onLog = builder.onLog;
43
45
  this.redirect = builder.redirect;
44
46
  this.maxResponseBytes = builder.maxResponseBytes;
@@ -100,6 +102,10 @@ final class ClientConfig {
100
102
  return onAuthExpired;
101
103
  }
102
104
 
105
+ List<InvalidateHook> onInvalidate() {
106
+ return onInvalidate;
107
+ }
108
+
103
109
  Consumer<LogEntry> onLog() {
104
110
  return onLog;
105
111
  }
@@ -135,6 +141,7 @@ final class ClientConfig {
135
141
  private final List<RequestHook> onRequest = new ArrayList<>();
136
142
  private final List<ResponseHook> onResponse = new ArrayList<>();
137
143
  private Supplier<String> onAuthExpired;
144
+ private final List<InvalidateHook> onInvalidate = new ArrayList<>();
138
145
  private Consumer<LogEntry> onLog;
139
146
  private String token;
140
147
  private String authHeader;
@@ -189,6 +196,10 @@ final class ClientConfig {
189
196
  this.onAuthExpired = refresh;
190
197
  }
191
198
 
199
+ void onInvalidate(InvalidateHook hook) {
200
+ this.onInvalidate.add(hook);
201
+ }
202
+
192
203
  void onLog(Consumer<LogEntry> log) {
193
204
  this.onLog = log;
194
205
  }