account-cache.d.ts
1 import { Account } from './sdk-provider'; 2 /** 3 * Disk cache which maps access key IDs to account IDs. 4 * Usage: 5 * cache.get(accessKey) => accountId | undefined 6 * cache.put(accessKey, accountId) 7 */ 8 export declare class AccountAccessKeyCache { 9 /** 10 * Max number of entries in the cache, after which the cache will be reset. 11 */ 12 static readonly MAX_ENTRIES = 1000; 13 private readonly cacheFile; 14 /** 15 * @param filePath Path to the cache file 16 */ 17 constructor(filePath?: string); 18 /** 19 * Tries to fetch the account ID from cache. If it's not in the cache, invokes 20 * the resolver function which should retrieve the account ID and return it. 21 * Then, it will be stored into disk cache returned. 22 * 23 * Example: 24 * 25 * const accountId = cache.fetch(accessKey, async () => { 26 * return await fetchAccountIdFromSomewhere(accessKey); 27 * }); 28 * 29 * @param accessKeyId 30 * @param resolver 31 */ 32 fetch<A extends Account>(accessKeyId: string, resolver: () => Promise<A>): Promise<Account>; 33 /** Get the account ID from an access key or undefined if not in cache */ 34 get(accessKeyId: string): Promise<Account | undefined>; 35 /** Put a mapping betweenn access key and account ID */ 36 put(accessKeyId: string, account: Account): Promise<void>; 37 private loadMap; 38 private saveMap; 39 }