import { DB_Object, DBDef_V3, DBProto, IndexKeys, InvalidResult, Logger, Module, TypedMap } from '@nu-art/ts-common'; import { OnClearWebsiteData } from '../clearWebsiteDataDispatcher.js'; import { DBApiFEConfig } from '../../core/db-api-gen/db-def.js'; import { DataStatus } from '../../core/db-api-gen/consts.js'; import { StorageKey } from '../ModuleFE_LocalStorage.js'; import { ThunderDispatcher } from '../../core/thunder-dispatcher.js'; import { IndexDb_Query, ReduceFunction } from '../../core/IndexedDB.js'; import { IndexedDB_Store } from '../../core/IndexedDBV4/IndexedDB_Store.js'; import { DBConfigV3 } from '../../core/IndexedDBV4/types.js'; import { CustomMemCreators, ModuleSyncType } from './types.js'; import { MultiApiEvent } from '../../core/db-api-gen/types.js'; export declare abstract class ModuleFE_BaseDB, Config extends DBApiFEConfig = DBApiFEConfig> extends Module implements OnClearWebsiteData { readonly validator: Proto['modifiablePropsValidator']; readonly cache: MemCache; readonly IDB: IDBCache; readonly dbDef: DBDef_V3; private dataStatus; readonly defaultDispatcher: ThunderDispatcher; readonly syncType: ModuleSyncType; private readonly ModuleFE_BaseDB; protected constructor(dbDef: DBDef_V3, defaultDispatcher: ThunderDispatcher, syncType: ModuleSyncType, customMemCreators?: CustomMemCreators); protected init(): void; /** * Upgrade processor functionality in the FE module will allow us to validate the items we cache in memory or * idb is up-to-date in case the data source is not coming directly from Storm managed backend (like the csv sync manager) */ private versionUpgrades; /** * Upgrades the entity from the given version to the next one (to the same version if the given version is the latest) * @param version - The version we start from * @param processor */ registerVersionUpgradeProcessor(version: K, processor: (items: Proto['versions']['types'][K][]) => Promise): void; upgradeInstances(instances: Proto['dbType'][], force?: boolean): Promise; attachOnLastSyncUpdatedListener: () => void; detachOnLastSyncUpdatedListener: () => void; private onLastSyncUpdatedListener; setDataStatus(status: DataStatus): void; protected OnDataStatusChanged(): void; getDataStatus(): DataStatus; __onClearWebsiteData(): Promise; getCollectionName: () => string; getCollectionKey: () => Proto["dbKey"]; private dispatchSingle; dispatchMulti: (event: MultiApiEvent, items: Proto["dbType"][]) => void; onEntriesDeleted: (items: Proto["dbType"][]) => Promise; protected onEntryDeleted: (item: Proto["dbType"]) => Promise; onEntriesUpdated: (items: Proto["dbType"][], updateIDBLastSynced?: boolean) => Promise; onEntryUpdated: (item: Proto["dbType"], original: Proto["uiType"], updateIDBLastSynced?: boolean) => Promise; protected onEntryPatched: (item: Proto["dbType"], updateIDBLastSynced?: boolean) => Promise; validateImpl(_instance: Partial): void; protected validateInternal(_instance: Partial): void; protected onValidationError(instance: Proto['uiType'], results: InvalidResult): void; private onEntryUpdatedImpl; protected onGotUnique: (item: Proto["dbType"]) => Promise; protected onQueryReturned: (toUpdate: Proto["dbType"][], toDelete?: DB_Object[]) => Promise; protected setCacheFilter: (filter: (item: Readonly) => boolean) => void; } export declare class IDBCache> extends Logger { readonly storeWrapper: IndexedDB_Store; protected lastSync: StorageKey; protected readonly lastVersion: StorageKey; private dbConfig; constructor(dbConfig: DBConfigV3, dbKey: string); init(): void; protected setLastSyncTimestampStorageKey(newLastSyncStorageKey: StorageKey): void; onLastUpdateListener(onChangeListener: (after?: number, before?: number) => Promise): void; forEach: (processor: (item: Proto["dbType"]) => void) => Promise; clear: () => Promise; delete: () => Promise; query: (query?: string | number | string[] | number[], indexKey?: string) => Promise; /** * Iterates over all DB objects in the related collection, and returns all the items that pass the filter * * @param {function} filter - Boolean returning function, to determine which objects to return. * @param {Object} [query] - A query object * * @return Array of items or empty array */ filter: (filter: (item: Proto["dbType"]) => boolean, query?: IndexDb_Query) => Promise; /** * Iterates over all DB objects in the related collection, and returns the first item that passes the filter * * @param {function} filter - Boolean returning function, to determine which object to return. * * @return a single item or undefined */ find: (filter: (item: Proto["dbType"]) => boolean) => Promise; /** * Iterates over all DB objects in the related collection, and returns an array of items based on the mapper. * * @param {function} mapper - Function that returns data to map for the object * @param {function} [filter] - Boolean returning function, to determine which item to map. * @param {Object} [query] - A query object * * @return An array of mapped items */ map: (mapper: (item: Proto["dbType"]) => MapType, filter?: (item: Proto["dbType"]) => boolean, query?: IndexDb_Query) => Promise; /** * iterates over all DB objects in the related collection, and reduces them to a single value based on the reducer. * @param {function} reducer - Function that determines who to reduce the array. * @param {*} initialValue - An initial value for the reducer * @param {function} [filter] - Function that determines which DB objects to reduce. * @param {Object} [query] - A query Object. * * @return a single reduced value. */ reduce: (reducer: ReduceFunction, initialValue: ReturnType, filter?: (item: Proto["dbType"]) => boolean, query?: IndexDb_Query) => Promise; unique: (_key?: string | IndexKeys) => Promise; getLastSync(): number; setLastUpdated(lastUpdated: number): void; syncIndexDb(toUpdate: Proto['dbType'][], toDelete?: DB_Object[]): Promise; count(): Promise; } export declare class MemCache> { protected readonly module: ModuleFE_BaseDB; private readonly keys; loaded: boolean; _map: Readonly>>; _array: Readonly[]>; protected cacheFilter?: (item: Readonly) => boolean; constructor(module: ModuleFE_BaseDB, keys: (keyof Proto['dbType'])[]); setCacheFilter: (filter: (item: Readonly) => boolean) => void; forEach: (processor: (item: Readonly) => void) => void; clear: () => void; load(cacheFilter?: (item: Readonly) => boolean): Promise; uniqueAssert: (_key?: Proto["uniqueParam"]) => Readonly; unique: (_key?: Proto["uniqueParam"]) => Readonly | undefined; all: () => Readonly[]>; allMutable: () => Readonly[]; filter: (filter: (item: Readonly, index: number, array: Readonly) => boolean) => Readonly[]; byIds: (ids: Proto["uniqueParam"][]) => Readonly; find: (filter: (item: Readonly, index: number, array: Readonly) => boolean) => Readonly | undefined; map: (mapper: (item: Readonly, index: number, array: Readonly) => MapType) => MapType[]; sort: (map?: keyof Proto["dbType"] | (keyof Proto["dbType"])[] | ((item: Readonly) => any), invert?: boolean) => Readonly[]; arrayToMap: (getKey: (item: Readonly, index: number, map: { [k: string]: Readonly; }) => string | number, map?: { [k: string]: Readonly; }) => { [k: string]: Readonly; }; private onEntriesDeleted; private onEntriesUpdated; protected setCache(cacheArray: Readonly[]): void; }