Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/remove-jsonrpc-websocket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': minor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're just doing this because this has never worked right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we removed all the methods in 2.0, I think everything we are removing is either internal only, or removing options that won't cause issues if you continue to pass them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there are some types that may have been re-exported, but unlikely they are being used

---

Remove WebSocket client and streaming subscription APIs from the JSON-RPC transport. The `subscribe` method, `WebSocketConstructor` option, `websocket` option, `JsonRpcTransportSubscribeOptions` type, and `Unsubscribe` type have been removed from the public API.
4 changes: 1 addition & 3 deletions packages/sui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@
"@parcel/watcher": "^2.5.4",
"@types/node": "^25.0.8",
"@types/tmp": "^0.2.6",
"@types/ws": "^8.18.1",
"cross-env": "^10.1.0",
"graphql-config": "^5.1.5",
"msw": "^2.12.7",
Expand All @@ -179,8 +178,7 @@
"vite": "^7.3.1",
"vite-tsconfig-paths": "^6.0.4",
"vitest": "^4.0.17",
"wait-on": "^9.0.3",
"ws": "^8.19.0"
"wait-on": "^9.0.3"
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.2.0",
Expand Down
52 changes: 0 additions & 52 deletions packages/sui/src/jsonRpc/http-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

import { PACKAGE_VERSION, TARGETED_RPC_VERSION } from '../version.js';
import { JsonRpcError, SuiHTTPStatusError } from './errors.js';
import type { WebsocketClientOptions } from './rpc-websocket-client.js';
import { WebsocketClient } from './rpc-websocket-client.js';

/**
* An object defining headers to be passed to the RPC server
Expand All @@ -13,15 +11,11 @@ export type HttpHeaders = { [header: string]: string };

export interface JsonRpcHTTPTransportOptions {
fetch?: typeof fetch;
WebSocketConstructor?: typeof WebSocket;
url: string;
rpc?: {
headers?: HttpHeaders;
url?: string;
};
websocket?: WebsocketClientOptions & {
url?: string;
};
}

export interface JsonRpcTransportRequestOptions {
Expand All @@ -30,25 +24,13 @@ export interface JsonRpcTransportRequestOptions {
signal?: AbortSignal;
}

export interface JsonRpcTransportSubscribeOptions<T> {
method: string;
unsubscribe: string;
params: unknown[];
onMessage: (event: T) => void;
signal?: AbortSignal;
}

export interface JsonRpcTransport {
request<T = unknown>(input: JsonRpcTransportRequestOptions): Promise<T>;
subscribe<T = unknown>(
input: JsonRpcTransportSubscribeOptions<T>,
): Promise<() => Promise<boolean>>;
}

export class JsonRpcHTTPTransport implements JsonRpcTransport {
#requestId = 0;
#options: JsonRpcHTTPTransportOptions;
#websocketClient?: WebsocketClient;

constructor(options: JsonRpcHTTPTransportOptions) {
this.#options = options;
Expand All @@ -66,27 +48,6 @@ export class JsonRpcHTTPTransport implements JsonRpcTransport {
return fetchFn(input, init);
}

#getWebsocketClient(): WebsocketClient {
if (!this.#websocketClient) {
const WebSocketConstructor = this.#options.WebSocketConstructor ?? WebSocket;
if (!WebSocketConstructor) {
throw new Error(
'The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.',
);
}

this.#websocketClient = new WebsocketClient(
this.#options.websocket?.url ?? this.#options.url,
{
WebSocketConstructor,
...this.#options.websocket,
},
);
}

return this.#websocketClient;
}

async request<T>(input: JsonRpcTransportRequestOptions): Promise<T> {
this.#requestId += 1;

Expand Down Expand Up @@ -125,17 +86,4 @@ export class JsonRpcHTTPTransport implements JsonRpcTransport {

return data.result;
}

async subscribe<T>(input: JsonRpcTransportSubscribeOptions<T>): Promise<() => Promise<boolean>> {
const unsubscribe = await this.#getWebsocketClient().subscribe(input);

if (input.signal) {
input.signal.throwIfAborted();
input.signal.addEventListener('abort', () => {
unsubscribe();
});
}

return async () => !!(await unsubscribe());
}
}
1 change: 0 additions & 1 deletion packages/sui/src/jsonRpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
export {
type JsonRpcTransport,
type JsonRpcTransportRequestOptions,
type JsonRpcTransportSubscribeOptions,
type HttpHeaders,
type JsonRpcHTTPTransportOptions,
JsonRpcHTTPTransport,
Expand Down
241 changes: 0 additions & 241 deletions packages/sui/src/jsonRpc/rpc-websocket-client.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/sui/src/jsonRpc/types/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
// SPDX-License-Identifier: Apache-2.0

export type Order = 'ascending' | 'descending';
export type Unsubscribe = () => Promise<boolean>;
3 changes: 0 additions & 3 deletions packages/sui/test/e2e/utils/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import type { ContainerRuntimeClient } from 'testcontainers';
import { getContainerRuntimeClient } from 'testcontainers';
import { retry } from 'ts-retry-promise';
import { expect, inject, it, test } from 'vitest';
import { WebSocket } from 'ws';

import type { SuiObjectChangePublished } from '../../../src/jsonRpc/index.js';
import {
Expand Down Expand Up @@ -64,7 +63,6 @@ export class TestToolbox {
network: 'localnet',
transport: new JsonRpcHTTPTransport({
url,
WebSocketConstructor: WebSocket as never,
}),
});
this.grpcClient = new SuiGrpcClient({
Expand Down Expand Up @@ -338,7 +336,6 @@ export function getClient(url = DEFAULT_FULLNODE_URL): SuiJsonRpcClient {
network: 'localnet',
transport: new JsonRpcHTTPTransport({
url,
WebSocketConstructor: WebSocket as never,
}),
});
}
Expand Down
Loading
Loading