@macalinao/grill
Version:
Modern Solana development kit for React applications with automatic account batching, caching, and transaction notifications
49 lines • 1.97 kB
TypeScript
import type { Account, Address, EncodedAccount } from "@solana/kit";
import type { QueryClient } from "@tanstack/react-query";
import type { RpcSubscriptions, SolanaRpcSubscriptionsApi } from "gill";
/**
* The data constraint for account types from @solana/kit
*/
export type AccountData = object | Uint8Array;
/**
* Function type for decoding account data from raw bytes to typed account.
*/
export type AccountDecoder<T extends AccountData> = (encodedAccount: EncodedAccount) => Account<T>;
/**
* RPC subscriptions type from gill's SolanaClient
*/
type RpcSubscriptionsType = RpcSubscriptions<SolanaRpcSubscriptionsApi>;
/**
* Interface for the subscription manager that handles WebSocket subscriptions.
*/
export interface SubscriptionManager {
/**
* Subscribe to an account's changes via WebSocket.
* Returns an unsubscribe function that must be called on cleanup.
*
* Multiple calls with the same address will share a single WebSocket subscription.
* The subscription is automatically cleaned up when all subscribers unsubscribe.
*/
subscribe<T extends AccountData>(address: Address, decoder: AccountDecoder<T>): () => void;
/**
* Get the current reference count for an address (for debugging).
*/
getSubscriptionCount(address: Address): number;
}
/**
* Creates a subscription manager instance.
*/
export declare function createSubscriptionManager(rpcSubscriptions: RpcSubscriptionsType, queryClient: QueryClient): SubscriptionManager;
/**
* React context for subscription manager.
*/
export declare const SubscriptionContext: React.Context<SubscriptionManager | null>;
/**
* Hook to access the subscription manager.
* Must be used within a provider that sets up SubscriptionContext.
*
* @throws Error if used outside of a provider with SubscriptionContext
*/
export declare function useSubscriptionManager(): SubscriptionManager;
export {};
//# sourceMappingURL=subscription-context.d.ts.map