diff --git a/src/lib/symbols.ts b/src/lib/symbols.ts index 2a463ba..d8f00ef 100644 --- a/src/lib/symbols.ts +++ b/src/lib/symbols.ts @@ -1,4 +1,5 @@ import { InjectionToken } from '@angular/core'; +import { Observable, of } from 'rxjs'; export const enum StorageOption { LocalStorage, @@ -66,3 +67,43 @@ export interface StorageEngine { clear(): void; key(val: number): string; } + +export interface AsyncStorageEngine { + length(): Observable; + getItem(key): Observable; + setItem(key, val): void; + removeItem(key): void; + clear(): void; + key(val: number): Observable; +} + +/** + * @Description Proxy used around synchronous storage engines to provide the same internal API than async engines + */ +export class AsyncStorageEngineProxy implements AsyncStorageEngine { + constructor(private _storage: StorageEngine) { } + + public length(): Observable { + return of(this._storage.length); + } + + public getItem(key): Observable { + return of(this._storage.getItem(key)); + } + + public setItem(key, val): void { + this._storage.setItem(key, val); + } + + public removeItem(key): void { + this._storage.removeItem(key); + } + + public clear(): void { + this._storage.clear(); + } + + public key(val: number): Observable { + return of(this._storage.key(val)); + } +} diff --git a/src/public_api.ts b/src/public_api.ts index 5e31b90..2187259 100644 --- a/src/public_api.ts +++ b/src/public_api.ts @@ -2,4 +2,6 @@ * Public API Surface of async-storage-plugin */ -export * from './lib/async-storage.module'; +export { NgxsAsyncStoragePluginModule } from './lib/async-storage.module'; +export { NgxsAsyncStoragePlugin } from './lib/async-storage.plugin'; +export * from './lib/symbols';