import { FactRecord } from '../storage' ; import { execRequest , withDatabase , withTransaction } from './driver' ; export interface LoginRecord { userFact : FactRecord ; displayName : string ; } export class IndexedDBLoginStore { constructor ( private indexName ) { } saveLogin ( sessionToken , userFact , displayName ) { return withDatabase ( this . indexName , db => { return withTransaction ( db , [ 'login' ] , 'readwrite' , async ( tx ) => { const loginObjectStore = tx . objectStore ( 'login' ) ; await execRequest ( loginObjectStore . put ( { userFact , displayName } , sessionToken ) ) ; } ) ; } ) ; } loadLogin ( sessionToken ) { return withDatabase ( this . indexName , async ( db ) => { return withTransaction ( db , [ 'login' ] , 'readonly' , tx => { const loginObjectStore = tx . objectStore ( 'login' ) ; return execRequest < LoginRecord > ( loginObjectStore . get ( sessionToken ) ) ; } ) ; } ) ; } }