import { IStorageProvider } from "./IStorageProvider" ; import { IFilterInfo } from "../IFilter" ; import { IAppserviceStorageProvider } from "./IAppserviceStorageProvider" ; category export class MemoryStorageProvider implements IStorageProvider , IAppserviceStorageProvider { private namespaced = new Map < string , MemoryStorageProvider > ( ) ; private syncToken : string ; private filter : IFilterInfo ; private appserviceUsers : { [ userId ] : { registered : boolean ; } ; } = { } ; private appserviceTransactions : { [ txnId ] : boolean ; } = { } ; private kvStore : { [ key ] : string ; } = { } ; setSyncToken ( token ) { this . syncToken = token ; } getSyncToken ( ) { return this . syncToken ; } setFilter ( filter ) { this . filter = filter ; } getFilter ( ) { return this . filter ; } addRegisteredUser ( userId ) { this . appserviceUsers [ userId ] = { registered : true , } ; } isUserRegistered ( userId ) { return this . appserviceUsers [ userId ] && this . appserviceUsers [ userId ] . registered ; } isTransactionCompleted ( transactionId ) { return ! ! this . appserviceTransactions [ transactionId ] ; } setTransactionCompleted ( transactionId ) { this . appserviceTransactions [ transactionId ] = true ; } readValue ( key ) { return this . kvStore [ key ] ; } storeValue ( key , value ) { this . kvStore [ key ] = value ; } storageForUser ( userId ) { if ( ! this . namespaced . has ( userId ) ) { this . namespaced . set ( userId , new MemoryStorageProvider ( ) ) ; } return this . namespaced . get ( userId ) ; } }