import { DBOperations , openDatabase , Key , CreateObjectStore } from './indexed-db' ; export interface IndexedDBProps { name : string ; version : number ; objectStoresMeta : ObjectStoreMeta [ ] ; } export interface ObjectStoreMeta { store : string ; storeConfig : { keyPath : string ; autoIncrement : boolean ; [ key ] : any ; } ; storeSchema : ObjectStoreSchema [ ] ; } export interface ObjectStoreSchema { name : string ; keypath : string ; options : { unique : boolean ; [ key ] : any ; } ; } export interface useIndexedDB { dbName : string ; version : number ; objectStore : string ; } let indexeddbConfiguration = { version : null , name : null } ; export function initDB ( { name , version , objectStoresMeta } ) { indexeddbConfiguration . name = name ; indexeddbConfiguration . version = version ; Object . freeze ( indexeddbConfiguration ) ; CreateObjectStore ( name , version , objectStoresMeta ) ; } export function useIndexedDB ( objectStore ) { if ( ! indexeddbConfiguration . name || ! indexeddbConfiguration . version ) { throw new Error ( 'Please, initialize the DB before the use.' ) ; } return { ... DBOperations ( indexeddbConfiguration . name , indexeddbConfiguration . version , objectStore ) } ; }