import { ApolloPersistOptions, PersistentStorage, PersistedData, } from './types'; export default class Storage { storage: PersistentStorage>; key: string; constructor(options: Pick, 'storage' | 'key'>) { const { storage, key = 'apollo-cache-persist' } = options; this.storage = storage; this.key = key; } async read(): Promise> { return this.storage.getItem(this.key); } async write(data: PersistedData): Promise { await this.storage.setItem(this.key, data); } async purge(): Promise { await this.storage.removeItem(this.key); } async getSize(): Promise { const data = await this.storage.getItem(this.key); if (data == null) { return 0; } else { return typeof data === 'string' ? data.length : null; } } }