Skip to content

feat: 🎸 dynamic base url and custom websocket message format - #149

Merged
prc5 merged 2 commits into
mainfrom
feat/dynamic-url-and-ws-codec
Oct 21, 2026
Merged

prc5 merged 2 commits into
mainfrom
feat/dynamic-url-and-ws-codec

Conversation

@prc5

@prc5 prc5 commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Closes #148

Core

  • client.setUrl(url, { abort?, invalidate? }) switches the base URL at runtime. Cache keys don't include the base URL, so:
    • abort cancels in-flight requests sent to the previous URL
    • invalidate invalidates the whole cache, plus the aborted requests, so mounted hooks refetch from the new URL
    • both default to false, and calling it with the current URL does nothing
  • client.cache.invalidate() with no arguments now invalidates every entry.

Sockets

  • socket.setUrl(url) applies to the next connection attempt, the same way setQueryParams does. Call reconnect() to apply it to a live connection. Listeners stay registered.
  • WebsocketAdapter has two new flat options:
    • decode(event) => { topic, data } | null maps incoming frames; returning null ignores the frame
    • encode({ topic, payload }) => frame maps outgoing frames, including heartbeat messages
  • ServerSentEventsAdapter gets the same flat decode option.
  • Errors thrown inside encode or decode are reported through onError and don't break the connection. When the options are not set, frames keep the current { topic, data } shape.
new Socket({
  url,
  adapterOptions: {
    decode: (event) => {
      const msg = JSON.parse(event.data);
      return msg.type === "pong" ? null : { topic: msg.type, data: msg.payload };
    },
    encode: ({ topic, payload }) => JSON.stringify({ type: topic, payload }),
  },
});

Docs are updated for the client, cache, socket and adapter pages.

Tests

  • core: client.set-url.spec.ts (new) and a cache.invalidate() no-argument case
  • sockets: adapter.websocket.codec.spec.ts and adapter.sse.codec.spec.ts (new), plus setUrl tests in socket.methods.spec.ts, including reconnecting to a second server
  • core and sockets: full test suites, typecheck, lint and build pass; react, axios and graphql typecheck

🤖 Generated with Claude Code

prc5 and others added 2 commits October 21, 2026 16:52
Add client.setUrl(url, { abort, invalidate }) to switch the base url at runtime.
Cache keys do not include the base url, so abort/invalidate let callers drop
in-flight requests and stale data of the previous server.

cache.invalidate() called without arguments now invalidates every entry.

Refs #148

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add socket.setUrl(url) - applied on the next connection attempt, like
setQueryParams. Add flat decode/encode options to the websocket adapter and
decode to the SSE adapter, so servers using a custom frame shape
(e.g. { type, payload }) work without a custom adapter. Frames decoded to null
are ignored; encode/decode errors are reported through onError.

Closes #148

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@prc5
prc5 requested a review from GerasNyx as a code owner October 21, 2026 14:53
@prc5
prc5 merged commit fad797c into main Oct 21, 2026
2 checks passed
@prc5
prc5 deleted the feat/dynamic-url-and-ws-codec branch October 21, 2026 14:55
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 9.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dynamic client base URL and custom WebSocket topic field

1 participant