bugfixes, tweaks and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-08-28 10:02:58 +03:00
parent a0aace804c
commit f94aef1360
3 changed files with 57 additions and 13 deletions

View File

@ -34,7 +34,7 @@ module.store = {
__proto__: basestore.MetaStore, __proto__: basestore.MetaStore,
//*/ //*/
next: { __proto__: basestore.BaseStore }, next: { __proto__: basestore.MetaStore },
} }
module.setup = module.setup =
@ -62,6 +62,23 @@ Promise.all([
store.update('@pouch', { store.update('@pouch', {
__proto__: pouchdbstore.PouchDBStore, __proto__: pouchdbstore.PouchDBStore,
}), }),
// next testing...
store.next.update('NextPage', {
text: 'next page...',
}),
store.next.update('Next', {
__proto__: localstoragestore.localStorageStore,
__prefix__: '--pwiki-next:',
data: localStorage,
}),
store.next.update('Next/Test', {
text: 'next test..'
}),
// XXX not sure of we need this to work...
store.next.update('System/NextTest', {
text: 'next test..'
}),
]) ])
// XXX // XXX
//typeof(Bootstrap) != 'undefined' //typeof(Bootstrap) != 'undefined'

View File

@ -292,7 +292,7 @@ module.BaseStore = {
return res }, new Set())] return res }, new Set())]
.sortAs(order) } .sortAs(order) }
// direct search... // direct search...
return this.find(path) }, return this.find(path, strict) },
// //
// .resolve(<path>) // .resolve(<path>)
// -> <path> // -> <path>
@ -360,11 +360,11 @@ module.BaseStore = {
// NOTE: p can match a non existing page at this point, // NOTE: p can match a non existing page at this point,
// this can be the result of matching a/* in a a/b/c // this can be the result of matching a/* in a a/b/c
// and returning a a/b which can be undefined... // and returning a a/b which can be undefined...
return that.get(p) }) return that.get(p, strict) })
: (await this.__get__(path) : (await this.__get__(path)
// XXX NEXT // XXX NEXT
?? ((this.next || {}).__get__ ?? ((this.next || {}).__get__
&& this.next.__get__(path))) }, && this.next.get(path, strict))) },
// //
// Get metadata... // Get metadata...
@ -390,7 +390,8 @@ module.BaseStore = {
// get... // get...
path = await this.exists(path) path = await this.exists(path)
return path return path
&& await this.__get__(path) && (await this.__get__(path)
?? await this.next.metadata(path))
|| undefined }, || undefined },
// NOTE: deleting and updating only applies to explicit matching // NOTE: deleting and updating only applies to explicit matching
@ -523,6 +524,7 @@ module.BaseStore = {
// be handled by nested stores. // be handled by nested stores.
// //
// XXX see inside...
var metaProxy = var metaProxy =
function(name, pre, post){ function(name, pre, post){
var func = async function(path, ...args){ var func = async function(path, ...args){
@ -530,13 +532,15 @@ function(name, pre, post){
await pre.call(this, path, ...args) await pre.call(this, path, ...args)
: path : path
var res
var p = this.substore(path) var p = this.substore(path)
if(p){ if(p){
// XXX can this be strict in all cases???
var res = this.substores[p][name]( var res = this.substores[p][name](
path.slice(path.indexOf(p)+p.length), path.slice(path.indexOf(p)+p.length),
...args) ...args) }
} else { res = res
var res = object.parentCall(MetaStore[name], this, ...arguments) } ?? object.parentCall(MetaStore[name], this, ...arguments)
return post ? return post ?
post.call(this, await res, path, ...args) post.call(this, await res, path, ...args)
@ -632,14 +636,28 @@ module.MetaStore = {
function(res, path){ function(res, path){
var s = this.substore(path) var s = this.substore(path)
return res == false ? return res == false ?
res (this.next ?
this.next.exists(path)
: res)
//res
: s ? : s ?
pwpath.join(s, res) pwpath.join(s, res)
: res }), : res }),
get: metaProxy('get', get: async function(path, strict=false){
async function(path){ path = await this.resolve(path)
return this.resolve(path) }), var res
var p = this.substore(path)
if(p){
res = await this.substores[p].get(
path.slice(path.indexOf(p)+p.length),
true) }
return res
?? object.parentCall(MetaStore.get, this, ...arguments) },
// XXX can't reach .next on get but will cheerfully mess things up
// on set (creating a local page)...
// ...should copy and merge...
metadata: metaProxy('metadata'), metadata: metaProxy('metadata'),
// NOTE: we intentionally do not delegate to .next here...
update: async function(path, data, mode='update'){ update: async function(path, data, mode='update'){
data = data instanceof Promise ? data = data instanceof Promise ?
await data await data

View File

@ -1,7 +1,16 @@
/********************************************************************** /**********************************************************************
* *
* *
* XXX BUG: .get(..) does not seem to resolve to <store>.next... * XXX Q: substore shadowing vs. mixing???
* should a substore completely shadow a .next stuff or should the
* layers mix???
* ...currently it's a bit of both, listing gets both but opening
* does not see the shadowed pages...
* .get(..) -- DONE
* .metadata(..) --
* .delete(..)
* ...
* XXX this broke "strict"...
* XXX page search: make things invariant via .names * XXX page search: make things invariant via .names
* - if a page is in a system path and there are no alternatives * - if a page is in a system path and there are no alternatives
* just return it and do not search. * just return it and do not search.