import { default as indexeddb , IDB , IStore } from "indexeddb" ; import { IDBOptions } from "./types" ; import version from "./version" ; let dbref = null ; export const db = ( options ? ) : IDB => { if ( dbref !== null ) { return dbref ; } const dbname = options && options . testing ? "kozmos-test-" + Date . now ( ) : "kozmos" ; dbref = indexeddb ( dbname , { version : ( options && options . version ) || version } ) ; return dbref as IDB ; } ; export const bookmarks = ( options ) => { return db ( ) . store ( "bookmarks" , { key : "url" , indexes : [ { name : "tags" , options : { multiEntry : true , unique : false } } , "cleanTitle" , "cleanUrl" , "createdAt" ] } ) ; } ; export const collections = ( options ) => { return db ( ) . store ( "collections" , { key : "title" , indexes : [ "normalizedTitle" , "desc" , "createdAt" ] } ) ; } ; export const collectionLinks = ( options ) => { return db ( ) . store ( "collection-links" , { key : "key" , indexes : [ "collection" , "url" , "createdAt" ] } ) ; } ; export const speedDial = ( options ) => { return db ( ) . store ( "speed-dial" , { key : "key" , indexes : [ "key" , "url" , "createdAt" ] } ) ; } ; export function reset ( ) { dbref = null ; }