import { StorageAdapter } from "./api/StorageAdapter" ; import { createLogger } from "../utils/logger" ; import { ModelSchema } from "../ModelSchema" ; import { Filter } from "../filters" ; const logger = createLogger ( "storage" ) ; /**
 * Implements local storage that saves data to specified adapter (underlying store)
 * and notifies developers about changes in store.
 */ export class LocalStorage { public readonly adapter : StorageAdapter ; constructor ( adapter ) { this . adapter = adapter ; } returns public async createTransaction ( ) { logger ( "creating transaction" ) ; const adapterTransaction = await this . adapter . createTransaction ( ) ; return new LocalStorage ( adapterTransaction ) ; } throws public async commit ( ) { await this . adapter . commit ( ) ; } throws public async rollback ( ) { await this . adapter . rollback ( ) ; } public async save ( storeName , input ) { return await this . adapter . save ( storeName , input ) ; } public query ( storeName , filter ? ) { return this . adapter . query ( storeName , filter ) ; } public queryById ( storeName , idField , id ) { return this . adapter . queryById ( storeName , idField , id ) ; } public async update ( storeName , input , filter ? ) { const result = await this . adapter . update ( storeName , input , filter ) ; return result ; } public updateById ( storeName , idField , input ) { return this . adapter . updateById ( storeName , idField , input ) ; } public saveOrUpdate ( storeName , idField , input ) { return this . adapter . saveOrUpdate ( storeName , idField , input ) ; } public async remove ( storeName , idField , filter ? ) { const result = await this . adapter . remove ( storeName , idField , filter ) ; return result ; } public removeById ( storeName , idField , input ) { return this . adapter . removeById ( storeName , idField , input ) ; } public deleteStore ( storeName ) { return this . adapter . deleteStore ( storeName ) ; } param config public addStore ( config ) { this . adapter . addStore ( config ) ; } param config public createStores ( ) { this . adapter . createStores ( ) ; } }