import { Driver, Storage, StorageValue } from 'unstorage'; import { NetworkIdType, TokenPrice, TokenPriceMap, TokenPriceSource, TokenYield } from '@sonarwatch/portfolio-core'; import { TokenYieldMap } from './TokenYieldMap'; export type TransactionOptions = { prefix: string; networkId?: NetworkIdType; }; /** * Represents the options for setting an item in the cache. */ export type TransactionOptionsSetItem = { /** * The time-to-live (TTL) value in milliseconds for the cached item. */ ttl?: number; }; export type CacheConfig = { name?: string; } & (CacheConfigOverlayHttp | CacheConfigMemory | CacheConfigRedis | CacheConfigFilesystem | CacheConfigHttp); export type CacheConfigOverlayHttp = { type: 'overlayHttp'; params: CacheConfigOverlayHttpParams; }; export type CacheConfigOverlayHttpParams = { configs: { base: string; headers: Record; }[]; }; export type CacheConfigMemory = { type: 'memory'; params: CacheConfigMemoryParams; }; export type CacheConfigMemoryParams = { ttl?: number; }; export type CacheConfigHttp = { type: 'http'; params: CacheConfigHttpParams; }; export type CacheConfigHttpParams = { base: string; headers?: Record; }; export type CacheConfigRedis = { type: 'redis'; params: CacheConfigRedisParams; }; export type CacheConfigRedisParams = { url: string; tls: boolean; db: number; ttl?: number; }; export type CacheConfigFilesystem = { type: 'filesystem'; params: CacheConfigFilesystemParams; }; export type CacheConfigFilesystemParams = { base: string; }; export type CacheConfigParams = { filesystem: { endpoint: string; }; redis: { url: string; tls: boolean; db: number; }; }; export declare class Cache { readonly name?: string; readonly storage: Storage; readonly driver: Driver; private tokenPriceStorage; constructor(cacheConfig: CacheConfig); importData(data: Map): void; exportData(): Map; hasItem(key: string, opts: TransactionOptions): Promise; hasTokenPrice(address: string, networkId: NetworkIdType): Promise; getItem(key: string, opts: TransactionOptions): Promise; private getTokenPriceLocal; private setTokenPriceLocal; getTokenPrice(address: string, networkId: NetworkIdType): Promise; getTokenPrices(addresses: string[], networkId: NetworkIdType): Promise<(TokenPrice | undefined)[]>; getTokenPricesAsMap(addresses: string[] | Set, networkId: NetworkIdType): Promise; private getTokenPriceSources; private getTokenPricesSources; getItems(keys: string[], opts: TransactionOptions): Promise<(K | undefined)[]>; setItem(key: string, value: K, opts: TransactionOptions & TransactionOptionsSetItem): Promise; setItems(items: { key: string; value: K; }[], opts: TransactionOptions & TransactionOptionsSetItem): Promise; setTokenPriceSource(source: TokenPriceSource): Promise; setTokenPriceSources(sources: (TokenPriceSource | null)[]): Promise; setTokenYield(tokenYield: TokenYield): Promise; setTokenYields(sources: (TokenYield | null)[]): Promise; getTokenYieldsAsMap(addresses: string[] | Set, networkId: NetworkIdType): Promise; removeItem(key: string, opts: TransactionOptions): Promise; dispose(): Promise; } export declare function getCacheConfig(): CacheConfig; export declare function getCache(): Cache;