added a simple IndexedDB store...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-10-10 01:10:32 +03:00
parent 5ff9906c1e
commit fe18674f50
4 changed files with 102 additions and 3 deletions

View File

@ -15,6 +15,7 @@ var page = require('./pwiki/page')
var basestore = require('./pwiki/store/base') var basestore = require('./pwiki/store/base')
var localstoragestore = require('./pwiki/store/localstorage') var localstoragestore = require('./pwiki/store/localstorage')
var indexeddb = require('./pwiki/store/indexeddb')
var pouchdbstore = require('./pwiki/store/pouchdb') var pouchdbstore = require('./pwiki/store/pouchdb')
@ -61,17 +62,20 @@ Promise.all([
// persistent stores... // persistent stores...
// //
store.update('@local', { store.update('/Stores/local', {
__proto__: localstoragestore.localStorageStore, __proto__: localstoragestore.localStorageStore,
data: localStorage, data: localStorage,
}), }),
store.update('@session', { store.update('Stores/session', {
__proto__: localstoragestore.localStorageStore, __proto__: localstoragestore.localStorageStore,
data: sessionStorage, data: sessionStorage,
}), }),
store.update('@pouch', { store.update('Stores/pouch', {
__proto__: pouchdbstore.PouchDBStore, __proto__: pouchdbstore.PouchDBStore,
}), }),
store.update('Stores/idb', {
__proto__: indexeddb.IndexedDBStore,
}),
/*/ XXX next testing... /*/ XXX next testing...
store.next.update('NextPage', { store.next.update('NextPage', {

88
pwiki/store/indexeddb.js Executable file
View File

@ -0,0 +1,88 @@
/**********************************************************************
*
*
*
**********************************************************************/
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/
var idb = require('idb-keyval')
var object = require('ig-object')
var types = require('ig-types')
var pwpath = require('../path')
var base = require('./base')
//---------------------------------------------------------------------
// XXX EXPERIMENTAL, needs testing in browser...
var IndexedDBStore =
module.IndexedDBStore = {
__proto__: base.Store,
__db__: 'pwiki',
__store__: 'pages',
// XXX add caching of unserialized data???
//__data: undefined,
get data(){
return this.__data
?? (this.__data = idb.createStore(this.__db__, this.__store__)) },
__paths__: function(){
return idb.keys(this.data) },
__exists__: function(path){
return idb.get(path, this.data) !== undefined
&& path },
__get__: function(path){
return idb.get(path, this.data) },
// XXX should this use idb.update(..) ???
__update__: function(path, data={}){
// XXX we seem to have some trouble caching things...
return idb.set(path, data, this.data) },
/*/
return idb.update(path,
function(value){
return data },
this.data) },
//*/
__delete__: function(path){
idb.del(path, this.data)
return this },
clear: function(){
idb.clear(this.data)
return this },
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// XXX
var localStorageNestedStore =
module.localStorageNestedStore = {
__proto__: base.BaseStore,
__data__: '__pwiki_data__',
__cache__: '__pwiki_cache__',
__data: undefined,
get data(){
return this.__data
?? (this.__data =
Object.assign(
{ __proto__: JSON.parse(localStorage[this.__data__] || '{}') },
JSON.parse(localStorage[this.__cache__] || '{}') )) },
// XXX do partials saves -> cache + write cache...
// XXX on full save merge cache and save...
}
/**********************************************************************
* vim:set ts=4 sw=4 : */ return module })

View File

@ -218,6 +218,7 @@ require.config({
'jszip': 'node_modules/jszip/dist/jszip', 'jszip': 'node_modules/jszip/dist/jszip',
'pouchdb': 'node_modules/pouchdb/dist/pouchdb', 'pouchdb': 'node_modules/pouchdb/dist/pouchdb',
'showdown': 'node_modules/showdown/dist/showdown', 'showdown': 'node_modules/showdown/dist/showdown',
'idb-keyval': 'node_modules/idb-keyval/dist/umd',
}, ['ext-lib']), }, ['ext-lib']),
}, },
packages: [ packages: [

View File

@ -15,6 +15,12 @@
* - images * - images
* *
* *
* XXX IndexedDB: after editing a page for some reason we do not see the
* final version until a full refresh -- cache???
* XXX Chrome started spamming CORS error:
* Access to manifest at 'file:///L:/work/pWiki/manifest.json'
* from origin 'null' ...
* not sure why...
* XXX test: can we store the file handler with permissions in a ServiceWorker?? * XXX test: can we store the file handler with permissions in a ServiceWorker??
* XXX store: add an indexedDB backend -- save on serialization... * XXX store: add an indexedDB backend -- save on serialization...
* - idb-keyval * - idb-keyval