import { StorageService } from "jslib-common/abstractions/storage.service" ; export default class BrowserStorageService implements StorageService { private chromeStorageApi : any ; constructor ( ) { this . chromeStorageApi = chrome . storage . local ; } async get < T > ( key ) { return new Promise ( ( resolve ) => { this . chromeStorageApi . get ( key , ( obj ) => { if ( obj != null && obj [ key ] != null ) { resolve ( obj [ key ] as T ) ; return ; } resolve ( null ) ; } ) ; } ) ; } async has ( key ) { return ( await this . get ( key ) ) != null ; } async save ( key , obj ) { if ( obj == null ) { return new Promise < void > ( ( resolve ) => { this . chromeStorageApi . remove ( key , ( ) => { resolve ( ) ; } ) ; } ) ; } if ( obj instanceof Set ) { obj = Array . from ( obj ) ; } const keyedObj = { [ key ] : obj } ; return new Promise < void > ( ( resolve ) => { this . chromeStorageApi . set ( keyedObj , ( ) => { resolve ( ) ; } ) ; } ) ; } async remove ( key ) { return new Promise < void > ( ( resolve ) => { this . chromeStorageApi . remove ( key , ( ) => { resolve ( ) ; } ) ; } ) ; } }