From c9bb45ea36c0f60305a610ca63b8837cc40a0a1d Mon Sep 17 00:00:00 2001 From: Joe Date: Wed, 31 Jan 2024 21:11:42 -0600 Subject: [PATCH] refactor(experimental): add `ClusterUrl` types --- packages/rpc-types/src/cluster-url.ts | 14 ++++++++++++++ packages/rpc-types/src/index.ts | 1 + 2 files changed, 15 insertions(+) create mode 100644 packages/rpc-types/src/cluster-url.ts diff --git a/packages/rpc-types/src/cluster-url.ts b/packages/rpc-types/src/cluster-url.ts new file mode 100644 index 000000000000..b1e244eade0d --- /dev/null +++ b/packages/rpc-types/src/cluster-url.ts @@ -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; +} diff --git a/packages/rpc-types/src/index.ts b/packages/rpc-types/src/index.ts index ef2e47bf4b09..ef807dc3dddf 100644 --- a/packages/rpc-types/src/index.ts +++ b/packages/rpc-types/src/index.ts @@ -1,4 +1,5 @@ export * from './blockhash'; +export * from './cluster-url'; export * from './commitment'; export * from './encoded-bytes'; export * from './lamports';