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