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,
//*/
next: { __proto__: basestore.BaseStore },
next: { __proto__: basestore.MetaStore },
}
module.setup =
@ -62,6 +62,23 @@ Promise.all([
store.update('@pouch', {
__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
//typeof(Bootstrap) != 'undefined'

View File

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