Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
refactor(experimental): move web socket transport types out of rpc-tr…
Browse files Browse the repository at this point in the history
…ansport
  • Loading branch information
buffalojoec committed Feb 1, 2024
1 parent c5fdaa6 commit bd0ef5d
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRpcWebSocketTransport } from '@solana/rpc-transport';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

import { getWebSocketTransportWithAutoping } from '../rpc-websocket-autopinger';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRpcWebSocketTransport } from '@solana/rpc-transport';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

import { getWebSocketTransportWithConnectionSharding } from '../rpc-websocket-connection-sharding';

Expand Down
2 changes: 1 addition & 1 deletion packages/library/src/rpc-websocket-autopinger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRpcWebSocketTransport } from '@solana/rpc-transport';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

type Config = Readonly<{
intervalMs: number;
Expand Down
2 changes: 1 addition & 1 deletion packages/library/src/rpc-websocket-connection-sharding.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IRpcWebSocketTransport } from '@solana/rpc-transport';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

import { getCachedAbortableIterableFactory } from './cached-abortable-iterable';

Expand Down
3 changes: 2 additions & 1 deletion packages/library/src/rpc-websocket-transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { pipe } from '@solana/functional';
import { createWebSocketTransport, type IRpcWebSocketTransport } from '@solana/rpc-transport';
import { createWebSocketTransport } from '@solana/rpc-transport';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

import { getWebSocketTransportWithAutoping } from './rpc-websocket-autopinger';
import { getWebSocketTransportWithConnectionSharding } from './rpc-websocket-connection-sharding';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { IRpcSubscriptionsApi, RpcSubscription, RpcSubscriptions } from '@solana/rpc-types';
import { IRpcSubscriptionsApi, IRpcWebSocketTransport, RpcSubscription, RpcSubscriptions } from '@solana/rpc-types';

import { SolanaJsonRpcError } from '../json-rpc-errors';
import { createJsonRpcMessage } from '../json-rpc-message';
import { getNextMessageId } from '../json-rpc-message-id';
import { createJsonSubscriptionRpc } from '../json-rpc-subscription';
import { IRpcWebSocketTransport } from '../transports/transport-types';

jest.mock('../json-rpc-message-id');

Expand Down
1 change: 0 additions & 1 deletion packages/rpc-transport/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export * from './json-rpc';
export type { SolanaJsonRpcErrorCode } from './json-rpc-errors';
export * from './json-rpc-subscription';
export * from './transports/http/http-transport';
export type { IRpcWebSocketTransport } from './transports/transport-types';
export * from './transports/websocket/websocket-transport';
4 changes: 1 addition & 3 deletions packages/rpc-transport/src/json-rpc-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { IIRpcTransport, IRpcApi, IRpcSubscriptionsApi } from '@solana/rpc-types';

import { IRpcWebSocketTransport } from './transports/transport-types';
import { IIRpcTransport, IRpcApi, IRpcSubscriptionsApi, IRpcWebSocketTransport } from '@solana/rpc-types';

export type RpcConfig<TRpcMethods> = Readonly<{
api: IRpcApi<TRpcMethods>;
Expand Down
16 changes: 0 additions & 16 deletions packages/rpc-transport/src/transports/transport-types.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { RpcWebSocketConnection } from '@solana/rpc-types';
import WS from 'jest-websocket-mock';
import { Client } from 'mock-socket';

import { createWebSocketConnection, RpcWebSocketConnection } from '../websocket-connection';
import { createWebSocketConnection } from '../websocket-connection';

const MOCK_SEND_BUFFER_HIGH_WATERMARK = 42069;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IRpcWebSocketTransport } from '../../transport-types';
import type { IRpcWebSocketTransport } from '@solana/rpc-types';

import { createWebSocketConnection } from '../websocket-connection';
import { createWebSocketTransport } from '../websocket-transport';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { RpcWebSocketConnection } from '@solana/rpc-types';
import WebSocket from 'ws-impl';

type Config = Readonly<{
Expand All @@ -16,10 +17,6 @@ type IteratorState =
__hasPolled: false;
queuedMessages: unknown[];
};
export type RpcWebSocketConnection = Readonly<{
send(payload: unknown): Promise<void>;
[Symbol.asyncIterator](): AsyncGenerator<unknown>;
}>;

const EXPLICIT_ABORT_TOKEN = Symbol(
__DEV__
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IRpcWebSocketTransport } from '../transport-types';
import { IRpcWebSocketTransport } from '@solana/rpc-types';

import { createWebSocketConnection } from './websocket-connection';

type Config = Readonly<{
Expand Down
19 changes: 19 additions & 0 deletions packages/rpc-types/src/rpc-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ type RpcTransportConfig = Readonly<{
signal?: AbortSignal;
}>;

export type RpcWebSocketConnection = Readonly<{
send(payload: unknown): Promise<void>;
[Symbol.asyncIterator](): AsyncGenerator<unknown>;
}>;

type RpcWebSocketTransportConfig = Readonly<{
payload: unknown;
signal: AbortSignal;
}>;

/**
* Public RPC Transport API
*/
Expand All @@ -25,6 +35,15 @@ export type IRpcTransportFromClusterUrl<TClusterUrl extends ClusterUrl> = TClust
? IRpcTransportMainnet
: IRpcTransport;

export interface IRpcWebSocketTransport {
(config: RpcWebSocketTransportConfig): Promise<
Readonly<
Omit<RpcWebSocketConnection, 'send'> & {
send_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: RpcWebSocketConnection['send'];
}
>
>;
}
/**
* Public RPC API.
*/
Expand Down

0 comments on commit bd0ef5d

Please sign in to comment.