mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-02 12:00:10 +00:00
more refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d4a1e3f055
commit
4e8159fc14
@ -1250,6 +1250,39 @@ module.BaseStore = {
|
|||||||
// XXX should this return a map for pattern matches???
|
// XXX should this return a map for pattern matches???
|
||||||
__get__: function(key){
|
__get__: function(key){
|
||||||
return this.data[key] },
|
return this.data[key] },
|
||||||
|
// XXX EXPERIMENTAL looks a bit convoluted...
|
||||||
|
get: function(path, strict=false, energetic=false){
|
||||||
|
var that = this
|
||||||
|
path = pwpath.sanitize(path, 'string')
|
||||||
|
var path = pwpath.splitArgs(path).path
|
||||||
|
var _path = path
|
||||||
|
path = Promise.awaitOrRun(
|
||||||
|
path.includes('*')
|
||||||
|
&& (energetic == true ?
|
||||||
|
this.find(path)
|
||||||
|
: this.isEnergetic(path)),
|
||||||
|
function(p){
|
||||||
|
return p
|
||||||
|
|| that.resolve(_path, strict) })
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
path,
|
||||||
|
function(path){
|
||||||
|
return path instanceof Array ?
|
||||||
|
// XXX should we return matched paths???
|
||||||
|
Promise.iter(path)
|
||||||
|
.map(function(p){
|
||||||
|
// 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, strict) })
|
||||||
|
.sync()
|
||||||
|
: Promise.awaitOrRun(
|
||||||
|
that.__get__(path),
|
||||||
|
function(res){
|
||||||
|
return res
|
||||||
|
?? ((that.next || {}).get
|
||||||
|
&& that.next.get(path, strict)) }) }) },
|
||||||
|
/*/ // XXX ASYNC...
|
||||||
get: async function(path, strict=false, energetic=false){
|
get: async function(path, strict=false, energetic=false){
|
||||||
var that = this
|
var that = this
|
||||||
path = pwpath.sanitize(path, 'string')
|
path = pwpath.sanitize(path, 'string')
|
||||||
@ -1259,7 +1292,6 @@ module.BaseStore = {
|
|||||||
await this.find(path)
|
await this.find(path)
|
||||||
: await this.isEnergetic(path))
|
: await this.isEnergetic(path))
|
||||||
|| await this.resolve(path, strict)
|
|| await this.resolve(path, strict)
|
||||||
//*/
|
|
||||||
return path instanceof Array ?
|
return path instanceof Array ?
|
||||||
// XXX should we return matched paths???
|
// XXX should we return matched paths???
|
||||||
Promise.iter(path)
|
Promise.iter(path)
|
||||||
@ -1271,11 +1303,24 @@ module.BaseStore = {
|
|||||||
: (await this.__get__(path)
|
: (await this.__get__(path)
|
||||||
?? ((this.next || {}).get
|
?? ((this.next || {}).get
|
||||||
&& this.next.get(path, strict))) },
|
&& this.next.get(path, strict))) },
|
||||||
|
//*/
|
||||||
|
|
||||||
|
// XXX EXPERIMENTAL looks a bit convoluted...
|
||||||
|
isEnergetic: function(path){
|
||||||
|
var that = this
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
this.find(path),
|
||||||
|
function(p){
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
that.get(p, true),
|
||||||
|
function(e){
|
||||||
|
return !!(e ?? {}).energetic && p }) }) },
|
||||||
|
/*/ // XXX ASYNC...
|
||||||
isEnergetic: async function(path){
|
isEnergetic: async function(path){
|
||||||
var p = await this.find(path)
|
var p = await this.find(path)
|
||||||
return !!(await this.get(p, true) ?? {}).energetic
|
return !!(await this.get(p, true) ?? {}).energetic
|
||||||
&& p },
|
&& p },
|
||||||
|
//*/
|
||||||
|
|
||||||
//
|
//
|
||||||
// Get metadata...
|
// Get metadata...
|
||||||
@ -1294,6 +1339,27 @@ module.BaseStore = {
|
|||||||
// and does not try to acquire a target page.
|
// and does not try to acquire a target page.
|
||||||
// NOTE: setting/removing metadata is done via .update(..) / .delete(..)
|
// NOTE: setting/removing metadata is done via .update(..) / .delete(..)
|
||||||
// NOTE: this uses .__get__(..) internally...
|
// NOTE: this uses .__get__(..) internally...
|
||||||
|
// XXX EXPERIMENTAL
|
||||||
|
metadata: function(path, ...args){
|
||||||
|
var that = this
|
||||||
|
path = pwpath.splitArgs(path).path
|
||||||
|
// set...
|
||||||
|
if(args.length > 0){
|
||||||
|
return this.update(path, ...args) }
|
||||||
|
// get...
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
this.exists(path),
|
||||||
|
function(path){
|
||||||
|
return path
|
||||||
|
&& Promise.awaitOrRun(
|
||||||
|
that.__get__(path),
|
||||||
|
function(res){
|
||||||
|
return res
|
||||||
|
?? Promise.awaitOrRun(
|
||||||
|
that.next.metadata(path),
|
||||||
|
function(res){
|
||||||
|
return res || undefined }) }) }) },
|
||||||
|
/*/ // XXX ASYNC...
|
||||||
metadata: async function(path, ...args){
|
metadata: async function(path, ...args){
|
||||||
path = pwpath.splitArgs(path).path
|
path = pwpath.splitArgs(path).path
|
||||||
// set...
|
// set...
|
||||||
@ -1306,6 +1372,7 @@ module.BaseStore = {
|
|||||||
?? (this.next
|
?? (this.next
|
||||||
&& await this.next.metadata(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
|
||||||
// paths -- no page acquisition is performed...
|
// paths -- no page acquisition is performed...
|
||||||
@ -1583,6 +1650,26 @@ module.MetaStore = {
|
|||||||
: s ?
|
: s ?
|
||||||
pwpath.join(s, res)
|
pwpath.join(s, res)
|
||||||
: res }),
|
: res }),
|
||||||
|
// XXX EXPERIMENTAL
|
||||||
|
get: function(path, strict=false){
|
||||||
|
var that = this
|
||||||
|
var args = [...arguments]
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
this.resolve(path, strict),
|
||||||
|
function(path){
|
||||||
|
if(path == undefined){
|
||||||
|
return }
|
||||||
|
var p = that.substore(path)
|
||||||
|
return Promise.awaitOrRun(
|
||||||
|
p ?
|
||||||
|
that.substores[p].get(
|
||||||
|
path.slice(path.indexOf(p) + p.length),
|
||||||
|
true)
|
||||||
|
: undefined,
|
||||||
|
function(res){
|
||||||
|
return res
|
||||||
|
?? object.parentCall(MetaStore.get, that, ...args) }) }) },
|
||||||
|
/*/ // XXX ASYNC...
|
||||||
get: async function(path, strict=false){
|
get: async function(path, strict=false){
|
||||||
path = await this.resolve(path, strict)
|
path = await this.resolve(path, strict)
|
||||||
if(path == undefined){
|
if(path == undefined){
|
||||||
@ -1591,10 +1678,11 @@ module.MetaStore = {
|
|||||||
var p = this.substore(path)
|
var p = this.substore(path)
|
||||||
if(p){
|
if(p){
|
||||||
res = await this.substores[p].get(
|
res = await this.substores[p].get(
|
||||||
path.slice(path.indexOf(p)+p.length),
|
path.slice(path.indexOf(p) + p.length),
|
||||||
true) }
|
true) }
|
||||||
return res
|
return res
|
||||||
?? object.parentCall(MetaStore.get, this, ...arguments) },
|
?? object.parentCall(MetaStore.get, this, ...arguments) },
|
||||||
|
//*/
|
||||||
// XXX can't reach .next on get but will cheerfully mess things up
|
// XXX can't reach .next on get but will cheerfully mess things up
|
||||||
// on set (creating a local page)...
|
// on set (creating a local page)...
|
||||||
// ...should copy and merge...
|
// ...should copy and merge...
|
||||||
@ -1686,10 +1774,20 @@ module.CachedStore = {
|
|||||||
: false)
|
: false)
|
||||||
|| object.parentCall(CachedStore.exists, this, ...arguments) },
|
|| object.parentCall(CachedStore.exists, this, ...arguments) },
|
||||||
// XXX this sometimes caches promises...
|
// XXX this sometimes caches promises...
|
||||||
|
// XXX EXPERIMENTAL
|
||||||
|
get: function(path){
|
||||||
|
var that = this
|
||||||
|
return this.cache[path]
|
||||||
|
?? Promise.awaitOrRun(
|
||||||
|
object.parentCall(CachedStore.get, this, ...arguments),
|
||||||
|
function(res){
|
||||||
|
return (that.cache[path] = res) }) },
|
||||||
|
/*/ // XXX ASYNC...
|
||||||
get: async function(path){
|
get: async function(path){
|
||||||
return this.cache[path]
|
return this.cache[path]
|
||||||
?? (this.cache[path] =
|
?? (this.cache[path] =
|
||||||
await object.parentCall(CachedStore.get, this, ...arguments)) },
|
await object.parentCall(CachedStore.get, this, ...arguments)) },
|
||||||
|
//*/
|
||||||
__update: async function(path, data){
|
__update: async function(path, data){
|
||||||
var that = this
|
var that = this
|
||||||
delete this.cache[path]
|
delete this.cache[path]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user