-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): add cluster level subscriptions API for trans…
…ports This change mirrors the first change in the stack, but for subscriptions.
- Loading branch information
1 parent
5a6335d
commit cbf8f38
Showing
7 changed files
with
246 additions
and
12 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/rpc-transport/src/__typetests__/json-rpc-subscription-typetest.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { devnet, IRpcApiSubscriptions, mainnet, RpcSubscriptions, testnet } from '@solana/rpc-types'; | ||
|
||
import { createJsonRpcSubscriptionsApi } from '../apis/subscriptions/subscriptions-api'; | ||
import { createJsonSubscriptionRpc } from '../json-rpc-subscription'; | ||
import { RpcSubscriptionsDevnet, RpcSubscriptionsMainnet, RpcSubscriptionsTestnet } from '../json-rpc-types'; | ||
import { createWebSocketTransport } from '../transports/websocket/websocket-transport'; | ||
|
||
interface MySubscriptionApiMethods extends IRpcApiSubscriptions { | ||
foo(): number; | ||
bar(): string; | ||
} | ||
|
||
const api = null as unknown as ReturnType<typeof createJsonRpcSubscriptionsApi<MySubscriptionApiMethods>>; | ||
|
||
const genericTransport = createWebSocketTransport({ sendBufferHighWatermark: 0, url: 'http://localhost:8899' }); | ||
const devnetTransport = createWebSocketTransport({ | ||
sendBufferHighWatermark: 0, | ||
url: devnet('https://api.devnet.solana.com'), | ||
}); | ||
const testnetTransport = createWebSocketTransport({ | ||
sendBufferHighWatermark: 0, | ||
url: testnet('https://api.testnet.solana.com'), | ||
}); | ||
const mainnetTransport = createWebSocketTransport({ | ||
sendBufferHighWatermark: 0, | ||
url: mainnet('https://api.mainnet-beta.solana.com'), | ||
}); | ||
|
||
// When providing a generic transport, the RPC should be typed as RpcSubscription | ||
createJsonSubscriptionRpc({ api, transport: genericTransport }) satisfies RpcSubscriptions<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: genericTransport, | ||
//@ts-expect-error Should not be a devnet transport | ||
}) satisfies RpcSubscriptionsDevnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: genericTransport, | ||
//@ts-expect-error Should not be a testnet transport | ||
}) satisfies RpcSubscriptionsTestnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: genericTransport, | ||
//@ts-expect-error Should not be a mainnet transport | ||
}) satisfies RpcSubscriptionsMainnet<MySubscriptionApiMethods>; | ||
|
||
// When providing a devnet transport, the RPC should be typed as RpcSubscriptionsDevnet | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: devnetTransport, | ||
}) satisfies RpcSubscriptionsDevnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: devnetTransport, | ||
//@ts-expect-error Should not be a testnet transport | ||
}) satisfies RpcSubscriptionsTestnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: devnetTransport, | ||
//@ts-expect-error Should not be a mainnet transport | ||
}) satisfies RpcSubscriptionsMainnet<MySubscriptionApiMethods>; | ||
|
||
// When providing a testnet transport, the RPC should be typed as RpcSubscriptionsTestnet | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: testnetTransport, | ||
}) satisfies RpcSubscriptionsTestnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: testnetTransport, | ||
//@ts-expect-error Should not be a devnet transport | ||
}) satisfies RpcSubscriptionsDevnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: testnetTransport, | ||
//@ts-expect-error Should not be a mainnet transport | ||
}) satisfies RpcSubscriptionsMainnet<MySubscriptionApiMethods>; | ||
|
||
// When providing a mainnet transport, the RPC should be typed as RpcSubscriptionsMainnet | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: mainnetTransport, | ||
}) satisfies RpcSubscriptionsMainnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: mainnetTransport, | ||
//@ts-expect-error Should not be a devnet transport | ||
}) satisfies RpcSubscriptionsDevnet<MySubscriptionApiMethods>; | ||
createJsonSubscriptionRpc({ | ||
api, | ||
transport: mainnetTransport, | ||
//@ts-expect-error Should not be a testnet transport | ||
}) satisfies RpcSubscriptionsTestnet<MySubscriptionApiMethods>; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
44 changes: 44 additions & 0 deletions
44
packages/rpc-transport/src/transports/websocket/__typetests__/websocket-typetest.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { devnet, mainnet, testnet } from '@solana/rpc-types'; | ||
|
||
import { | ||
IRpcWebSocketTransport, | ||
IRpcWebSocketTransportDevnet, | ||
IRpcWebSocketTransportMainnet, | ||
IRpcWebSocketTransportTestnet, | ||
} from '../../transport-types'; | ||
import { createWebSocketTransport } from '../websocket-transport'; | ||
|
||
const genericConfig = { sendBufferHighWatermark: 0, url: 'http://localhost:8899' }; | ||
const devnetConfig = { sendBufferHighWatermark: 0, url: devnet('https://api.devnet.solana.com') }; | ||
const testnetConfig = { sendBufferHighWatermark: 0, url: testnet('https://api.testnet.solana.com') }; | ||
const mainnetConfig = { sendBufferHighWatermark: 0, url: mainnet('https://api.mainnet-beta.solana.com') }; | ||
|
||
// When providing a generic URL, the transport should be typed as an IRpcWebSocketTransport | ||
createWebSocketTransport(genericConfig) satisfies IRpcWebSocketTransport; | ||
//@ts-expect-error Should not be a devnet transport | ||
createWebSocketTransport(genericConfig) satisfies IRpcWebSocketTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createWebSocketTransport(genericConfig) satisfies IRpcWebSocketTransportTestnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createWebSocketTransport(genericConfig) satisfies IRpcWebSocketTransportMainnet; | ||
|
||
// When providing a devnet URL, the transport should be typed as an IRpcWebSocketTransportDevnet | ||
createWebSocketTransport(devnetConfig) satisfies IRpcWebSocketTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createWebSocketTransport(devnetConfig) satisfies IRpcWebSocketTransportTestnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createWebSocketTransport(devnetConfig) satisfies IRpcWebSocketTransportMainnet; | ||
|
||
// When providing a testnet URL, the transport should be typed as an IRpcWebSocketTransportTestnet | ||
createWebSocketTransport(testnetConfig) satisfies IRpcWebSocketTransportTestnet; | ||
//@ts-expect-error Should not be a devnet transport | ||
createWebSocketTransport(testnetConfig) satisfies IRpcWebSocketTransportDevnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createWebSocketTransport(testnetConfig) satisfies IRpcWebSocketTransportMainnet; | ||
|
||
// When providing a mainnet URL, the transport should be typed as an IRpcWebSocketTransportMainnet | ||
createWebSocketTransport(mainnetConfig) satisfies IRpcWebSocketTransportMainnet; | ||
//@ts-expect-error Should not be a devnet transport | ||
createWebSocketTransport(mainnetConfig) satisfies IRpcWebSocketTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createWebSocketTransport(mainnetConfig) satisfies IRpcWebSocketTransportTestnet; |
This file contains 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