UNPKG

@cmtlyt/storage

Version:
77 lines (70 loc) 2.76 kB
import { TRequired, TExclude } from '@cmtlyt/base'; interface BaseStorageOptions { dbName: string; autoSaveDelay: number; zipKeyLength: number; } type StorageBaseOptions = Partial<BaseStorageOptions>; declare abstract class BaseStorage { #private; name: string; protected config: BaseStorageOptions; constructor(options?: Partial<BaseStorageOptions>); private _createAutoSaveInterval; get length(): number; protected abstract init(): (Record<string, any> | string) | Promise<Record<string, any> | string>; protected _createHook(_config: BaseStorageOptions & Record<string, any>): any; protected _createdHook(): any; protected _setItemBeforeHook(_key: string, _value: any): any | void; protected _setItemAfterHook(_key: string, _value: any): any; protected _getItemBeforeHook(_key: string): any; protected _getItemAfterHook(_key: string, _value: any): any | void; protected _removeItemBeforeHook(_key: string): any; protected _removeItemAfterHook(_key: string): any; protected _clearBeforeHook(): any; protected _clearAfterHook(): any; protected _getKeysBeforeHook(): any; protected _getKeysAfterHook(_keys: string[]): string[] | void; protected autoSave(_data: string): void; protected getDataSchema(): Promise<string>; setItem(key: string, value: any): Promise<void>; getItem(key: string): Promise<any>; removeItem(key: string): Promise<void>; clear(): Promise<void>; getKeys(): Promise<string[]>; } interface IndexedDBStorageOptions extends TRequired<StorageBaseOptions, 'dbName'> { } declare class IndexedDBStorage extends BaseStorage { #private; name: string; constructor(options: IndexedDBStorageOptions); protected autoSave(data: string): void; protected init(): Promise<unknown>; forceSave(): Promise<unknown>; } interface LocalStorageOptions extends TRequired<StorageBaseOptions, 'dbName'> { } declare class LocalStorage extends BaseStorage { name: string; constructor(options: LocalStorageOptions); protected init(): {}; protected autoSave(data: string): void; } interface MemoryStorageOptions extends TExclude<StorageBaseOptions, 'autoSaveDelay'> { } declare class MemoryStorage extends BaseStorage { name: string; constructor(options: MemoryStorageOptions); protected init(): {}; protected autoSave(_data: string): void; } interface SessionStorageOptions extends TRequired<StorageBaseOptions, 'dbName'> { } declare class SessionStorage extends BaseStorage { name: string; constructor(options: SessionStorageOptions); protected init(): {}; protected autoSave(data: string): void; } export { IndexedDBStorage, LocalStorage, MemoryStorage, SessionStorage };