Repository navigation
fix(client): keep streams out of REST clients, and add refetchInterval - #121
Merged
Merged
Conversation
SSE, EventStream, WebSocket and WebTransport routes are registered as plain GETs, so they landed in openapi.json as `GET -> 200 Success`, which nothing can tell apart from a REST read. The TypeScript generator bound every one of them as `query(...)`, and calling that fetches an endpoint whose body never ends. The Go and Dart REST clients had the same trap. The router now marks those operations with x-forge-protocol (the marker AsyncAPI channels already carry for WebTransport), answers an SSE route's 200 as text/event-stream, and gives a WebSocket route a 101 when its only response is the generated default. On the client side the IR records Endpoint.Stream from that marker, or from responses that are only text/event-stream or only 101, so a document from a gateway is caught too. Generator.Generate then takes streams out of Endpoints after merge and filtering. A stream AsyncAPI already describes is dropped, a stream only OpenAPI knows about becomes a stream endpoint of its kind, and one whose path has parameters is left out with a warning, because the generated stream clients don't substitute path parameters yet. Refs #106
Polling had to be written by hand at every call site, and the easy way to write it keys the timer on the result object, so it restarts on every response and a three second poll on a slow endpoint quietly becomes five. useQuery in React and Vue and injectQuery in Angular now take refetchInterval (number or false, as in TanStack Query) and refetchIntervalInBackground. The timer is keyed on the query and the two options, never on the result. Vue takes refs or getters and Angular signals or functions, the same way they take live and staleTime. All three run on the core's poll, which now holds its cadence too. It used to sleep the whole interval after each response, so the period was interval plus latency. It now waits the interval less the time the request took, starts the next request straight away when a response is slower than the interval, and never overlaps two. An interval that isn't a positive finite number polls nothing, where 0 used to spin. The freshness entry goes from 378 B to 451 B against its 500 B budget. Closes #100
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Conventional Commits ValidationPR Title: valid |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This clears the three open issues. Two needed code, one commit each. The third was already done by other work.
#106: stream endpoints generated as queries
The empty
streamsmanifest half was fixed by #109, which carriesx-forge-streambindings from AsyncAPI intostream-bindings.ts. To get rows in that table you declare a binding (WithStreamBinding, or messages throughWithSSEMessages/WithWebSocketMessages) and pass the AsyncAPI document toforge client generatealongside the OpenAPI one.The other half was still there.
SSE,EventStream,WebSocketandWebTransportall register a plain GET, and the OpenAPI generator never looked atroute.Kind, so every stream showed up inopenapi.jsonasGET -> 200 Success. You can't tell that apart from a REST read, so the TypeScript generator emittedquery(...)for it, and the Go and Dart REST clients got a method that fetches a body that never ends.What changed
x-forge-protocol: sse | websocket | webtransport, the same marker AsyncAPI channels already use for WebTransport. An SSE route's 200 is declared astext/event-stream, keeping any schema the route declared. A WebSocket route whose only response is the generated default gets101 Switching Protocolsin its place. The golden specs change for exactly the three streaming routes in them.Endpoint.Streamcomes from that marker. Failing that, it comes from the responses: every 2xx istext/event-stream, or the only success is101. That second rule is what catches a gateway document like the one in the issue. A malformed marker warns and falls back to the responses.Generator.Generatetakes streams out ofEndpointsafter merge and path filtering, before any language generator runs. So it covers introspection,--from-spec, merged sources,watchandcheckin one place.That last case is deliberate. The TypeScript and Go stream clients concatenate a channel path onto the base URL as written, so a client for
/instances/{instanceId}/logs/streamwould connect to a literal{instanceId}. That's true today for AsyncAPI channels with parameters too, so it isn't new, but we didn't want this change emitting more of it. Substituting path params in the stream clients is a good follow-up. Dart's streaming already has apathParamshelper to copy from.For the six portal endpoints in the issue, that means after a regen they disappear from
ops.ts,hooks.tsandrest.ts, andforge client generateprints one warning each. Declaring their messages on the services and passingasyncapi.jsontoo gives them proper stream clients and stream bindings.#100: polling from
useQueryuseQuery(React, Vue) andinjectQuery(Angular) takerefetchInterval?: number | falseandrefetchIntervalInBackground?: boolean, spelled and behaving the way TanStack does, sorefetchInterval: isExecuting ? 3000 : falsemoves over unchanged. The timer is keyed on the query and the two options, never on the result, which is the bug every hand-written hook in the issue had. Vue takes refs or getters and Angular signals or functions, same asliveandstaleTime.All three run on the core's
poll, which needed a fix of its own. It slept the full interval after each response settled, so its period was interval plus latency, the same drift the issue describes, just in a different place. It now waits the interval less however long the request took. A response slower than the interval is followed straight away by the next request, and two never overlap. An interval of 0, a negative number, NaN or Infinity polls nothing. Before, 0 would loop with no delay at all.#98: pin a dashboard shell release
Nothing left to do. b550666 (Sep 29) removed the embedded shell at
{BasePath}/ui, the two pin files,scripts/fetch-dashboard-shell.shand the GoReleaser hook, so there's no placeholder to ship and nothing to pin. The other blocker in the issue is gone too:forge-dashboardhas tagged v0.1.0 through v0.3.0, and all six@forge-go/dashboard-*packagesforge dashboard newscaffolds are on npm at 0.3.0, so the scaffold installs.How we checked it
go test ./...on the root module withtypescript@5.8.2andesbuildonPATH, as CI installs them, so none of the tsc gates skipped.cmd/forge/plugins(through a local go.work) andextensions/streamingpass too.golangci-lintis clean on the changed packages.:idversus{id}path match, the warning and idempotence.client.Generator.Generate: a gateway-style OpenAPI document with no AsyncAPI, and a real router's two documents merged. Both fail with the separation pass removed. The gateway one type-checks the synthesized SSE client.freshnessgoes from 378 B to 451 B against its 500 B budget. The new cadence tests fail against the oldpoll.Closes #100
Closes #106
Closes #98