mirror of
https://github.com/flynx/pWiki.git
synced 2025-11-01 03:20:08 +00:00
now .exists(..) is sync/async depending on index readiness...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
1591abe0fa
commit
def671ffba
@ -648,52 +648,23 @@ module.BaseStore = {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// .exists(<path>)
|
// .exists(<path>)
|
||||||
|
// -> <promise>
|
||||||
// -> <normalized-path>
|
// -> <normalized-path>
|
||||||
// -> false
|
// -> false
|
||||||
//
|
//
|
||||||
// XXX INDEXED...
|
exists: function(path){
|
||||||
exists: async function(path){
|
|
||||||
var {path, args} =
|
var {path, args} =
|
||||||
pwpath.splitArgs(
|
pwpath.splitArgs(
|
||||||
pwpath.sanitize(path, 'string'))
|
pwpath.sanitize(path, 'string'))
|
||||||
//return new Set(await this.paths).has(path) ?
|
var test = function(paths){
|
||||||
//return (await this.paths).indexOf(path) != -1 ?
|
return paths.includes(path) ?
|
||||||
return (await this.paths).includes(path) ?
|
pwpath.joinArgs(path, args)
|
||||||
pwpath.joinArgs(path, args)
|
: undefined }
|
||||||
: undefined },
|
var paths = this.paths
|
||||||
/*/
|
return paths instanceof Promise ?
|
||||||
__exists__: async function(path){
|
paths.then(test)
|
||||||
return path in this.data
|
: test(paths) },
|
||||||
&& path },
|
|
||||||
// XXX might be a good idea to cache this...
|
|
||||||
exists: async function(path){
|
|
||||||
var {path, args} =
|
|
||||||
pwpath.splitArgs(
|
|
||||||
pwpath.sanitize(path, 'string'))
|
|
||||||
|
|
||||||
// NOTE: all paths at this point and in store are
|
|
||||||
// absolute, so we check both with the leading
|
|
||||||
// '/' and without it to make things a bit more
|
|
||||||
// relaxed and return the actual matching path...
|
|
||||||
var res = await this.__exists__(path)
|
|
||||||
// NOTE: res can be '' and thus we can't simply chain via || here...
|
|
||||||
typeof(res) != 'string'
|
|
||||||
&& (res = await this.__exists__('/'+ path))
|
|
||||||
|
|
||||||
// delegate to .next...
|
|
||||||
typeof(res) != 'string'
|
|
||||||
&& (this.next || {}).__exists__
|
|
||||||
&& (res = await this.next.__exists__(path))
|
|
||||||
typeof(res) != 'string'
|
|
||||||
&& (this.next || {}).__exists__
|
|
||||||
&& (res = await this.next.__exists__('/'+path))
|
|
||||||
|
|
||||||
if(typeof(res) != 'string'){
|
|
||||||
return false }
|
|
||||||
return pwpath.joinArgs(res, args) },
|
|
||||||
//*/
|
|
||||||
|
|
||||||
// XXX EXPERIMENTAL...
|
|
||||||
//
|
//
|
||||||
// .sort(<pattern>, <by>, ..)
|
// .sort(<pattern>, <by>, ..)
|
||||||
// .sort([<path>, ..], <by>, ..)
|
// .sort([<path>, ..], <by>, ..)
|
||||||
@ -707,7 +678,6 @@ module.BaseStore = {
|
|||||||
// | 'name'
|
// | 'name'
|
||||||
// | 'title'
|
// | 'title'
|
||||||
// | 'depth'
|
// | 'depth'
|
||||||
// | 'number'
|
|
||||||
// | <attr>
|
// | <attr>
|
||||||
// | <cmp-func>
|
// | <cmp-func>
|
||||||
//
|
//
|
||||||
@ -1323,23 +1293,32 @@ module.BaseStore = {
|
|||||||
// XXX see inside...
|
// XXX see inside...
|
||||||
var metaProxy =
|
var metaProxy =
|
||||||
function(name, pre, post){
|
function(name, pre, post){
|
||||||
var func = async function(path, ...args){
|
var func = function(path, ...args){
|
||||||
|
var that = this
|
||||||
|
var _do = function(path){
|
||||||
|
var res
|
||||||
|
var p = that.substore(path)
|
||||||
|
if(p){
|
||||||
|
// XXX can this be strict in all cases???
|
||||||
|
res = that.substores[p][name](
|
||||||
|
path.slice(path.indexOf(p)+p.length),
|
||||||
|
...args) }
|
||||||
|
return res
|
||||||
|
?? object.parentCall(MetaStore[name], that, ...arguments) }
|
||||||
|
|
||||||
path = pre ?
|
path = pre ?
|
||||||
await pre.call(this, path, ...args)
|
pre.call(this, path, ...args)
|
||||||
: path
|
: path
|
||||||
|
|
||||||
var res
|
var res = path instanceof Promise ?
|
||||||
var p = this.substore(path)
|
path.then(_do)
|
||||||
if(p){
|
: _do(path)
|
||||||
// XXX can this be strict in all cases???
|
|
||||||
var res = this.substores[p][name](
|
|
||||||
path.slice(path.indexOf(p)+p.length),
|
|
||||||
...args) }
|
|
||||||
res = res
|
|
||||||
?? object.parentCall(MetaStore[name], this, ...arguments)
|
|
||||||
|
|
||||||
return post ?
|
return post ?
|
||||||
post.call(this, await res, path, ...args)
|
(res instanceof Promise ?
|
||||||
|
res.then(function(res){
|
||||||
|
return post.call(that, res, path, ...args) })
|
||||||
|
: post.call(this, res, path, ...args))
|
||||||
: res }
|
: res }
|
||||||
Object.defineProperty(func, 'name', {value: name})
|
Object.defineProperty(func, 'name', {value: name})
|
||||||
return func }
|
return func }
|
||||||
@ -1532,7 +1511,7 @@ module.CachedStore = {
|
|||||||
this.cache = {}
|
this.cache = {}
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
exists: async function(path){
|
exists: function(path){
|
||||||
return (path in this.cache ?
|
return (path in this.cache ?
|
||||||
path
|
path
|
||||||
: false)
|
: false)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user