-
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 API for transports
- Loading branch information
1 parent
25175d9
commit d6e8247
Showing
16 changed files
with
170 additions
and
28 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
packages/rpc-transport/src/__typetests__/json-rpc-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,47 @@ | ||
import { devnet, IRpcApiMethods, mainnet, Rpc, RpcDevnet, RpcMainnet, RpcTestnet, testnet } from '@solana/rpc-types'; | ||
|
||
import { createJsonRpcApi } from '../apis/methods/methods-api'; | ||
import { createJsonRpc } from '../json-rpc'; | ||
import { createHttpTransport } from '../transports/http/http-transport'; | ||
|
||
interface MyApiMethods extends IRpcApiMethods { | ||
foo(): number; | ||
bar(): string; | ||
} | ||
|
||
const api = createJsonRpcApi<MyApiMethods>(); | ||
|
||
const genericTransport = createHttpTransport({ url: 'http://localhost:8899' }); | ||
const devnetTransport = createHttpTransport({ url: devnet('https://api.devnet.solana.com') }); | ||
const testnetTransport = createHttpTransport({ url: testnet('https://api.testnet.solana.com') }); | ||
const mainnetTransport = createHttpTransport({ url: mainnet('https://api.mainnet.solana.com') }); | ||
|
||
// When providing a generic transport, the RPC should be typed as an Rpc | ||
createJsonRpc({ api, transport: genericTransport }) satisfies Rpc<MyApiMethods>; | ||
//@ts-expect-error Should not be a devnet RPC | ||
createJsonRpc({ api, transport: genericTransport }) satisfies RpcDevnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a testnet RPC | ||
createJsonRpc({ api, transport: genericTransport }) satisfies RpcTestnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a mainnet RPC | ||
createJsonRpc({ api, transport: genericTransport }) satisfies RpcMainnet<MyApiMethods>; | ||
|
||
// When providing a devnet transport, the RPC should be typed as an RpcDevnet | ||
createJsonRpc({ api, transport: devnetTransport }) satisfies RpcDevnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a testnet RPC | ||
createJsonRpc({ api, transport: devnetTransport }) satisfies RpcTestnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a mainnet RPC | ||
createJsonRpc({ api, transport: devnetTransport }) satisfies RpcMainnet<MyApiMethods>; | ||
|
||
// When providing a testnet transport, the RPC should be typed as an RpcTestnet | ||
createJsonRpc({ api, transport: testnetTransport }) satisfies RpcTestnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a devnet RPC | ||
createJsonRpc({ api, transport: testnetTransport }) satisfies RpcDevnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a mainnet RPC | ||
createJsonRpc({ api, transport: testnetTransport }) satisfies RpcMainnet<MyApiMethods>; | ||
|
||
// When providing a mainnet transport, the RPC should be typed as an RpcMainnet | ||
createJsonRpc({ api, transport: mainnetTransport }) satisfies RpcMainnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a devnet RPC | ||
createJsonRpc({ api, transport: mainnetTransport }) satisfies RpcDevnet<MyApiMethods>; | ||
//@ts-expect-error Should not be a testnet RPC | ||
createJsonRpc({ api, transport: mainnetTransport }) satisfies RpcTestnet<MyApiMethods>; |
2 changes: 1 addition & 1 deletion
2
...src/__typetests__/methods-api-typetest.ts → ...pis/__typetests__/methods-api-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
2 changes: 1 addition & 1 deletion
2
...typetests__/subscriptions-api-typetest.ts → ...typetests__/subscriptions-api-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
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
2 changes: 1 addition & 1 deletion
2
packages/rpc-transport/src/transports/http/__tests__/http-transport-abort-test.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
3 changes: 2 additions & 1 deletion
3
packages/rpc-transport/src/transports/http/__tests__/http-transport-headers-test.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
2 changes: 1 addition & 1 deletion
2
packages/rpc-transport/src/transports/http/__tests__/http-transport-test.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
46 changes: 46 additions & 0 deletions
46
packages/rpc-transport/src/transports/http/__typetests__/http-transport-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,46 @@ | ||
import { | ||
devnet, | ||
IRpcTransport, | ||
IRpcTransportDevnet, | ||
IRpcTransportMainnet, | ||
IRpcTransportTestnet, | ||
mainnet, | ||
testnet, | ||
} from '@solana/rpc-types'; | ||
|
||
import { createHttpTransport } from '../http-transport'; | ||
|
||
const genericUrl = 'http://localhost:8899'; | ||
const devnetUrl = devnet('https://api.devnet.solana.com'); | ||
const testnetUrl = testnet('https://api.testnet.solana.com'); | ||
const mainnetUrl = mainnet('https://api.mainnet.solana.com'); | ||
|
||
// When providing a generic URL, the transport should be typed as an IRpcTransport | ||
createHttpTransport({ url: genericUrl }) satisfies IRpcTransport; | ||
//@ts-expect-error Should not be a devnet transport | ||
createHttpTransport({ url: genericUrl }) satisfies IRpcTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createHttpTransport({ url: genericUrl }) satisfies IRpcTransportTestnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createHttpTransport({ url: genericUrl }) satisfies IRpcTransportMainnet; | ||
|
||
// When providing a devnet URL, the transport should be typed as an IRpcTransportDevnet | ||
createHttpTransport({ url: devnetUrl }) satisfies IRpcTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createHttpTransport({ url: devnetUrl }) satisfies IRpcTransportTestnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createHttpTransport({ url: devnetUrl }) satisfies IRpcTransportMainnet; | ||
|
||
// When providing a testnet URL, the transport should be typed as an IRpcTransportTestnet | ||
createHttpTransport({ url: testnetUrl }) satisfies IRpcTransportTestnet; | ||
//@ts-expect-error Should not be a devnet transport | ||
createHttpTransport({ url: testnetUrl }) satisfies IRpcTransportDevnet; | ||
//@ts-expect-error Should not be a mainnet transport | ||
createHttpTransport({ url: testnetUrl }) satisfies IRpcTransportMainnet; | ||
|
||
// When providing a mainnet URL, the transport should be typed as an IRpcTransportMainnet | ||
createHttpTransport({ url: mainnetUrl }) satisfies IRpcTransportMainnet; | ||
//@ts-expect-error Should not be a devnet transport | ||
createHttpTransport({ url: mainnetUrl }) satisfies IRpcTransportDevnet; | ||
//@ts-expect-error Should not be a testnet transport | ||
createHttpTransport({ url: mainnetUrl }) satisfies IRpcTransportTestnet; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export type MainnetUrl = string & { '~cluster': 'mainnet' }; | ||
export type DevnetUrl = string & { '~cluster': 'devnet' }; | ||
export type TestnetUrl = string & { '~cluster': 'testnet' }; | ||
export type ClusterUrl = string | MainnetUrl | DevnetUrl | TestnetUrl; | ||
|
||
export function mainnet(putativeString: string): MainnetUrl { | ||
return putativeString as MainnetUrl; | ||
} | ||
export function devnet(putativeString: string): DevnetUrl { | ||
return putativeString as DevnetUrl; | ||
} | ||
export function testnet(putativeString: string): TestnetUrl { | ||
return putativeString as TestnetUrl; | ||
} |
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