Skip to content

Commit

Permalink
create multi transport
Browse files Browse the repository at this point in the history
  • Loading branch information
andogq committed Jun 21, 2024
1 parent c0d0f1f commit 0b7457a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/multi-transport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@qubit-rs/client": patch:feat
---

create multi tranasport
1 change: 1 addition & 0 deletions packages/client/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { RpcRequest, RpcResponse } from "../jsonrpc";

export { ws } from "./ws";
export { http, type HttpOptions } from "./http";
export { multi, type MultiOptions } from "./multi";
export type { SocketOptions } from "../util";

export type ClientBuilder<Server> = (host: string) => Server;
Expand Down
26 changes: 26 additions & 0 deletions packages/client/src/transport/multi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { http, type HttpOptions, type SocketOptions, type Transport, ws } from ".";

export type MultiOptions = {
ws?: SocketOptions;
http?: HttpOptions;
};

/**
* Transport that combines both `http` for query and mutate, and `ws` for subscriptions.
*/
export function multi(host: string, options?: MultiOptions) {
const http_client = http(host, options?.http);
const ws_client = ws(host, options?.ws);

return {
query: (id, payload) => {
return http_client.query(id, payload);
},
mutate: (id, payload) => {
return http_client.mutate(id, payload);
},
subscribe: (id, on_data) => {
return ws_client.subscribe(id, on_data);
},
} satisfies Transport;
}

0 comments on commit 0b7457a

Please sign in to comment.