Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(experimental): add ClusterUrl types #2084

Merged
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
14 changes: 14 additions & 0 deletions packages/rpc-types/src/cluster-url.ts
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 {
Copy link
Collaborator

@steveluscher steveluscher Feb 2, 2024

Choose a reason for hiding this comment

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

Just a nit regarding my favorite word to use in code. This is usually the word I use for assertion functions (ie. ones whose return type is foo is Bar). Putative means ‘supposed’ or ‘assumed to exist.’

This puppy doesn't make any assertions; it's just a typecast utility. mainnet(url: string): MainnetUrl would do fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is your favorite word in code? What about foo? Personally, mine is console.log("FLARE"), but that never gets committed :).

return putativeString as MainnetUrl;
}
export function devnet(putativeString: string): DevnetUrl {
return putativeString as DevnetUrl;
}
export function testnet(putativeString: string): TestnetUrl {
return putativeString as TestnetUrl;
}
1 change: 1 addition & 0 deletions packages/rpc-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './blockhash';
export * from './cluster-url';
export * from './commitment';
export * from './encoded-bytes';
export * from './lamports';
Expand Down
Loading