From f94aef1360a0f46ecde644765664cc2391232d61 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Sun, 28 Aug 2022 10:02:58 +0300 Subject: [PATCH] bugfixes, tweaks and cleanup... Signed-off-by: Alex A. Naanou --- browser.js | 19 ++++++++++++++++++- pwiki/store/base.js | 40 +++++++++++++++++++++++++++++----------- pwiki2.js | 11 ++++++++++- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/browser.js b/browser.js index 1835c2c..82cc6bf 100755 --- a/browser.js +++ b/browser.js @@ -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' diff --git a/pwiki/store/base.js b/pwiki/store/base.js index 9112a95..b2480a5 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -292,7 +292,7 @@ module.BaseStore = { return res }, new Set())] .sortAs(order) } // direct search... - return this.find(path) }, + return this.find(path, strict) }, // // .resolve() // -> @@ -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 diff --git a/pwiki2.js b/pwiki2.js index 0218c00..48c9dcd 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -1,7 +1,16 @@ /********************************************************************** * * -* XXX BUG: .get(..) does not seem to resolve to .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.