attempting to resurrect full beans
This commit is contained in:
parent
bceee7ecf1
commit
a961f387d6
9 changed files with 170 additions and 65 deletions
33
store/idb.js
Normal file
33
store/idb.js
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
// lib/idb.js
|
||||
import { createStore, get, set, del, entries, clear } from 'idb-keyval'
|
||||
|
||||
// Named stores — each maps to a distinct IDBObjectStore
|
||||
export const itemsStore = createStore('app-db', 'items')
|
||||
export const userStore = createStore('app-db', 'user')
|
||||
export const cacheStore = createStore('app-db', 'cache')
|
||||
|
||||
// Typed wrappers — keeps raw idb-keyval calls out of the rest of the app
|
||||
// and gives you one place to add validation, logging, or migration logic
|
||||
|
||||
export const db = {
|
||||
items: {
|
||||
getAll: () => entries(itemsStore),
|
||||
get: (id) => get(id, itemsStore),
|
||||
set: (id, value) => set(id, value, itemsStore),
|
||||
remove: (id) => del(id, itemsStore),
|
||||
clear: () => clear(itemsStore),
|
||||
},
|
||||
|
||||
user: {
|
||||
get: () => get('user', userStore),
|
||||
set: (value) => set('user', value, userStore),
|
||||
clear: () => del('user', userStore),
|
||||
},
|
||||
|
||||
cache: {
|
||||
get: (key) => get(key, cacheStore),
|
||||
set: (key, value) => set(key, value, cacheStore),
|
||||
remove: (key) => del(key, cacheStore),
|
||||
clear: () => clear(cacheStore),
|
||||
}
|
||||
}
|
||||
9
store/persistence.js
Normal file
9
store/persistence.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
// store/middleware/persistence.js
|
||||
import { db } from './idb.js'
|
||||
|
||||
export const makeIdbStorage = (storeName) =>
|
||||
createJSONStorage(() => ({
|
||||
getItem: (name) => db[storeName].get(name),
|
||||
setItem: (name, value) => db[storeName].set(name, value),
|
||||
removeItem: (name) => db[storeName].remove(name),
|
||||
}))
|
||||
Loading…
Add table
Add a link
Reference in a new issue