periodicjs.core.data
Advanced tools
Comparing version 0.5.1 to 0.5.2
@@ -9,3 +9,2 @@ 'use strict'; | ||
const xss_default_whitelist = require(path.join(__dirname, '../defaults/index')).xss_whitelist(); | ||
/** | ||
@@ -27,6 +26,7 @@ * Convenience method for .find loki method | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip } = ['sort', 'limit', 'population', 'fields', 'skip'].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip', ].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
return result; | ||
}, {}); | ||
let chain = Model.chain() | ||
@@ -36,15 +36,15 @@ .find((options.query && typeof options.query === 'object') ? options.query : {}); | ||
switch (typeof sort) { | ||
case 'string': | ||
chain = chain.simplesort(sort); | ||
break; | ||
case 'object': | ||
if (Array.isArray(sort)) { | ||
chain = chain.compoundsort(sort); | ||
} else { | ||
chain = chain.compoundsort(convertSortObjToOrderArray(sort)); | ||
} | ||
break; | ||
case 'function': | ||
chain = chain.sort(sort); | ||
break; | ||
case 'string': | ||
chain = chain.simplesort(sort); | ||
break; | ||
case 'object': | ||
if (Array.isArray(sort)) { | ||
chain = chain.compoundsort(sort); | ||
} else { | ||
chain = chain.compoundsort(convertSortObjToOrderArray(sort)); | ||
} | ||
break; | ||
case 'function': | ||
chain = chain.sort(sort); | ||
break; | ||
} | ||
@@ -54,3 +54,3 @@ } | ||
if (limit) chain = chain.limit(Number(limit)); | ||
let result = chain.data(Object.assign({ forceClones: (options.forceClones === false) ? false : true })); | ||
let result = chain.data(Object.assign({ forceClones: (options.forceClones === false) ? false : true, })); | ||
cb(null, result); | ||
@@ -73,3 +73,3 @@ } catch (e) { | ||
if (sort[key] < 1) { //descending | ||
return [key, true]; | ||
return [key, true, ]; | ||
} else { | ||
@@ -133,3 +133,3 @@ return key; | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip, pagelength } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength'].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query', ].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -140,3 +140,3 @@ return result; | ||
total: 0, | ||
total_pages: 0 | ||
total_pages: 0, | ||
}; | ||
@@ -147,19 +147,19 @@ let total = 0; | ||
Promisie.doWhilst(() => { | ||
return new Promisie((resolve, reject) => { | ||
_QUERY.call(this, { sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model }, (err, data) => { | ||
if (err) reject(err); | ||
else { | ||
skip += data.length; | ||
total += data.length; | ||
pages.total += data.length; | ||
pages.total_pages++; | ||
pages[index++] = { | ||
documents: data, | ||
count: data.length, | ||
}; | ||
resolve(data.length); | ||
} | ||
}); | ||
return new Promisie((resolve, reject) => { | ||
_QUERY.call(this, { query, sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => { | ||
if (err) reject(err); | ||
else { | ||
skip += data.length; | ||
total += data.length; | ||
pages.total += data.length; | ||
pages.total_pages++; | ||
pages[index++] = { | ||
documents: data, | ||
count: data.length, | ||
}; | ||
resolve(data.length); | ||
} | ||
}); | ||
}, current => (current === pagelength && total < limit)) | ||
}); | ||
}, current => (current === pagelength && total < limit)) | ||
.then(() => cb(null, pages)) | ||
@@ -199,3 +199,3 @@ .catch(cb); | ||
query = { | ||
[toplevel]: [] }; | ||
[toplevel]: [], }; | ||
//Pushes options.query if it already a composed query object | ||
@@ -210,10 +210,10 @@ if (options.query && typeof options.query === 'object') query[toplevel].push(options.query); | ||
let statement = values.reduce((result, value) => { | ||
let block = { $or: [] }; | ||
let block = { $or: [], }; | ||
for (let i = 0; i < searchfields.length; i++) { | ||
block.$or.push({ | ||
[searchfields[i]]: value }); | ||
[searchfields[i]]: { $regex:value, }, }); | ||
} | ||
return result.concat(block); | ||
}, []); | ||
query[toplevel].push({ $or: statement }); | ||
query[toplevel].push({ $or: statement, }); | ||
} | ||
@@ -224,5 +224,5 @@ //Handles docnamelookup portion of query | ||
let isObjectIds = (split.filter(utility.isObjectId).length === split.length); | ||
if (isObjectIds) query[toplevel].push({ '_id': { $in: split } }); | ||
if (isObjectIds) query[toplevel].push({ '_id': { $in: split, }, }); | ||
else query[toplevel].push({ | ||
[(options.docid || this.docid) ? (options.docid || this.docid) : '_id']: { $in: split } }); | ||
[(options.docid || this.docid) ? (options.docid || this.docid) : '_id']: { $in: split, }, }); | ||
} | ||
@@ -252,3 +252,3 @@ options.query = query; | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, population, fields, docid } = ['sort', 'population', 'fields', 'docid'].reduce((result, key) => { | ||
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid', ].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -269,5 +269,5 @@ return result; | ||
query = (options.query && typeof options.query === 'object') ? options.query : { | ||
[(utility.isObjectId(options.query)) ? '_id' : (docid || '_id')]: options.query | ||
[(utility.isObjectId(options.query)) ? '_id' : (docid || '_id')]: options.query, | ||
}; | ||
if (useQuery) _QUERY.call(this, Object.assign(options, { limit: 1, query }), (err, result) => { | ||
if (useQuery) _QUERY.call(this, Object.assign(options, { limit: 1, query, }), (err, result) => { | ||
if (err) cb(err); | ||
@@ -295,5 +295,5 @@ else cb(null, result.slice(0, 1)[0]); | ||
// delete data.__v; | ||
let flattened = flatten(data, { safe: true }); | ||
let flattened = flatten(data, { safe: true, }); | ||
return function(updateValue) { | ||
let value = flatten(updateValue, { safe: true }); | ||
let value = flatten(updateValue, { safe: true, }); | ||
return str2json.convert(Object.assign(value, flattened)); | ||
@@ -331,3 +331,3 @@ }; | ||
update: Object.assign({}, options.updatedoc), | ||
original: Object.assign({}, options.originalrevision) | ||
original: Object.assign({}, options.originalrevision), | ||
}; | ||
@@ -340,4 +340,4 @@ let depopulate = (options.depopulate === false) ? false : true; | ||
this.changeset.create({ | ||
parent_document: { id: options.id }, | ||
changeset: changeset | ||
parent_document: { id: options.id, }, | ||
changeset: changeset, | ||
}, (err, result) => { | ||
@@ -358,15 +358,15 @@ if (options.ensure_changes) { | ||
Promisie.parallel({ | ||
update: (!usePatch) ? Model.update(updateOperation) : (() => { | ||
return () => { | ||
return Promisie.promisify(_QUERY, this)({ query: (options.query) ? options.query : { _id: options.id } }) | ||
update: (!usePatch) ? Model.update(updateOperation) : (() => { | ||
return () => { | ||
return Promisie.promisify(_QUERY, this)({ query: (options.query) ? options.query : { _id: options.id, }, }) | ||
.map(updateOperation) | ||
.map(Model.update.bind(Model)) | ||
.catch(e => Promisie.reject(e)); | ||
} | ||
})(), | ||
changes: Promisie.promisify(generateChanges)() | ||
}) | ||
}; | ||
})(), | ||
changes: Promisie.promisify(generateChanges)(), | ||
}) | ||
.then(result => { | ||
if (options.ensure_changes) cb(null, result); | ||
else cb(null, { status: 'ok' }); | ||
else cb(null, { status: 'ok', }); | ||
}, cb); | ||
@@ -395,3 +395,3 @@ } catch (e) { | ||
if (err) cb(err); | ||
else _LOAD.call(this, { model: options.model, query: options.id }, cb); | ||
else _LOAD.call(this, { model: options.model, query: options.id, }, cb); | ||
}); | ||
@@ -421,3 +421,3 @@ } catch (e) { | ||
else throw new Error('Either updateattributes or updatedoc option must be set in order to execute multi update'); | ||
_UPDATE.call(this, { query, isPatch: true, multi: true, updatedoc: doc }, cb); | ||
_UPDATE.call(this, { query, isPatch: true, multi: true, updatedoc: doc, }, cb); | ||
} catch (e) { | ||
@@ -473,3 +473,3 @@ cb(e); | ||
if (typeof deleteid !== 'string') throw new Error('Must specify "deleteid" or "id" for delete'); | ||
let object = Model.findObject({ _id: deleteid }); | ||
let object = Model.findObject({ _id: deleteid, }); | ||
let result = Model.remove(object); | ||
@@ -492,3 +492,3 @@ cb(null, result); | ||
try { | ||
_LOAD.call(this, { model: options.model, query: options.deleteid || options.id }, (err1, loaded) => { | ||
_LOAD.call(this, { model: options.model, query: options.deleteid || options.id, }, (err1, loaded) => { | ||
if (err1) cb(err1); | ||
@@ -528,20 +528,20 @@ else { | ||
constructor(options = {}) { | ||
this.db_connection = options.db_connection || lowkie; | ||
this.docid = options.docid; //previously docnamelookup | ||
this.model = (typeof options.model === 'string') ? this.db_connection.model(options.model) : options.model; | ||
this.sort = options.sort || '-createdat'; | ||
this.limit = options.limit || 500; | ||
this.skip = options.skip || 0; | ||
if (Array.isArray(options.search)) this.searchfields = options.search; | ||
else if (typeof options.search === 'string') this.searchfields = options.search.split(','); | ||
else this.searchfields = []; | ||
this.population = options.population; | ||
this.fields = options.fields; | ||
this.pagelength = options.pagelength || 15; | ||
this.cache = options.cache; | ||
this.track_changes = (options.track_changes === false) ? false : true; | ||
this.changeset = require(path.join(__dirname, '../changeset/index')).loki_default; | ||
this.xss_whitelist = options.xss_whitelist || xss_default_whitelist; | ||
this._useCache = (options.useCache && options.cache) ? true : false; | ||
} | ||
this.db_connection = options.db_connection || lowkie; | ||
this.docid = options.docid; //previously docnamelookup | ||
this.model = (typeof options.model === 'string') ? this.db_connection.model(options.model) : options.model; | ||
this.sort = options.sort || '-createdat'; | ||
this.limit = options.limit || 500; | ||
this.skip = options.skip || 0; | ||
if (Array.isArray(options.search)) this.searchfields = options.search; | ||
else if (typeof options.search === 'string') this.searchfields = options.search.split(','); | ||
else this.searchfields = []; | ||
this.population = options.population; | ||
this.fields = options.fields; | ||
this.pagelength = options.pagelength || 15; | ||
this.cache = options.cache; | ||
this.track_changes = (options.track_changes === false) ? false : true; | ||
this.changeset = require(path.join(__dirname, '../changeset/index')).loki_default; | ||
this.xss_whitelist = options.xss_whitelist || xss_default_whitelist; | ||
this._useCache = (options.useCache && options.cache) ? true : false; | ||
} | ||
/** | ||
@@ -555,6 +555,6 @@ * Query method for adapter see _QUERY and _QUERY_WITH_PAGINATION for more details | ||
query(options = {}, cb = false) { | ||
let _query = (options && options.paginate) ? _QUERY_WITH_PAGINATION.bind(this) : _QUERY.bind(this); | ||
if (typeof cb === 'function') _query(options, cb); | ||
else return Promisie.promisify(_query)(options); | ||
} | ||
let _query = (options && options.paginate) ? _QUERY_WITH_PAGINATION.bind(this) : _QUERY.bind(this); | ||
if (typeof cb === 'function') _query(options, cb); | ||
else return Promisie.promisify(_query)(options); | ||
} | ||
/** | ||
@@ -567,6 +567,6 @@ * Search method for adapter see _SEARCH for more details | ||
search(options = {}, cb = false) { | ||
let _search = _SEARCH.bind(this); | ||
if (typeof cb === 'function') _search(options, cb); | ||
else return Promisie.promisify(_search)(options); | ||
} | ||
let _search = _SEARCH.bind(this); | ||
if (typeof cb === 'function') _search(options, cb); | ||
else return Promisie.promisify(_search)(options); | ||
} | ||
/** | ||
@@ -579,6 +579,6 @@ * Stream method for adapter see _STREAM for more details | ||
stream(options = {}, cb = false) { | ||
let _stream = _STREAM.bind(this); | ||
if (typeof cb === 'function') _stream(options, cb); | ||
else return Promisie.promisify(_stream)(options); | ||
} | ||
let _stream = _STREAM.bind(this); | ||
if (typeof cb === 'function') _stream(options, cb); | ||
else return Promisie.promisify(_stream)(options); | ||
} | ||
/** | ||
@@ -591,6 +591,6 @@ * Load method for adapter see _LOAD for more details | ||
load(options = {}, cb = false) { | ||
let _load = _LOAD.bind(this); | ||
if (typeof cb === 'function') _load(options, cb); | ||
else return Promisie.promisify(_load)(options); | ||
} | ||
let _load = _LOAD.bind(this); | ||
if (typeof cb === 'function') _load(options, cb); | ||
else return Promisie.promisify(_load)(options); | ||
} | ||
/** | ||
@@ -605,6 +605,6 @@ * Update method for adapter see _UPDATE, _UPDATED and _UPDATE_ALL for more details | ||
update(options = {}, cb = false) { | ||
let _update = (options.multi) ? _UPDATE_ALL.bind(this) : ((options.return_updated) ? _UPDATED.bind(this) : _UPDATE.bind(this)); | ||
if (typeof cb === 'function') _update(options, cb); | ||
else return Promisie.promisify(_update)(options); | ||
} | ||
let _update = (options.multi) ? _UPDATE_ALL.bind(this) : ((options.return_updated) ? _UPDATED.bind(this) : _UPDATE.bind(this)); | ||
if (typeof cb === 'function') _update(options, cb); | ||
else return Promisie.promisify(_update)(options); | ||
} | ||
/** | ||
@@ -617,6 +617,6 @@ * Create method for adapter see _CREATE for more details | ||
create(options = {}, cb = false) { | ||
let _create = _CREATE.bind(this); | ||
if (typeof cb === 'function') _create(options, cb); | ||
else return Promisie.promisify(_create)(options); | ||
} | ||
let _create = _CREATE.bind(this); | ||
if (typeof cb === 'function') _create(options, cb); | ||
else return Promisie.promisify(_create)(options); | ||
} | ||
/** | ||
@@ -623,0 +623,0 @@ * Delete method for adapter see _DELETE and _DELETED for more details |
@@ -25,3 +25,3 @@ 'use strict'; | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip } = ['sort','limit','population','fields','skip'].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -36,4 +36,3 @@ return result; | ||
.exec(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -59,3 +58,3 @@ } | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip } = ['sort','limit','population','fields','skip'].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -72,4 +71,3 @@ return result; | ||
cb(null, stream); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -96,3 +94,3 @@ } | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip, pagelength } = ['sort','limit','population','fields','skip','pagelength'].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -103,3 +101,3 @@ return result; | ||
total: 0, | ||
total_pages: 0 | ||
total_pages: 0, | ||
}; | ||
@@ -111,3 +109,3 @@ let total = 0; | ||
return new Promisie((resolve, reject) => { | ||
_QUERY.call(this, { sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model }, (err, data) => { | ||
_QUERY.call(this, { query, sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => { | ||
if (err) reject(err); | ||
@@ -130,4 +128,3 @@ else { | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -163,3 +160,3 @@ } | ||
let toplevel = (options.inclusive) ? '$or' : '$and'; | ||
query = { [toplevel]: [] }; | ||
query = { [toplevel]: [], }; | ||
//Pushes options.query if it already a composed query object | ||
@@ -174,9 +171,9 @@ if (options.query && typeof options.query === 'object') query[toplevel].push(options.query); | ||
let statement = values.reduce((result, value) => { | ||
let block = { $or: [] }; | ||
let block = { $or: [], }; | ||
for (let i = 0; i < searchfields.length; i++) { | ||
block.$or.push({ [searchfields[i]]: value }); | ||
block.$or.push({ [searchfields[i]]: value, }); | ||
} | ||
return result.concat(block); | ||
}, []); | ||
query[toplevel].push({ $or: statement }); | ||
query[toplevel].push({ $or: statement, }); | ||
} | ||
@@ -187,4 +184,4 @@ //Handles docnamelookup portion of query | ||
let isObjectIds = (split.filter(utility.isObjectId).length === split.length); | ||
if (isObjectIds) query[toplevel].push({ '_id': { $in: split } }); | ||
else query[toplevel].push({ [(options.docid || this.docid) ? (options.docid || this.docid) : '_id']: { $in: split } }); | ||
if (isObjectIds) query[toplevel].push({ '_id': { $in: split, }, }); | ||
else query[toplevel].push({ [(options.docid || this.docid) ? (options.docid || this.docid) : '_id']: { $in: split, }, }); | ||
} | ||
@@ -194,4 +191,3 @@ options.query = query; | ||
else _QUERY.call(this, options, cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -216,3 +212,3 @@ } | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, population, fields, docid } = ['sort','population','fields','docid'].reduce((result, key) => { | ||
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -222,3 +218,3 @@ return result; | ||
let query = (options.query && typeof options.query === 'object') ? options.query : { | ||
[(utility.isObjectId(options.query)) ? '_id' : (docid || '_id')]: options.query | ||
[(utility.isObjectId(options.query)) ? '_id' : (docid || '_id')]: options.query, | ||
}; | ||
@@ -229,4 +225,3 @@ Model.findOne(query, fields) | ||
.exec(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -244,7 +239,7 @@ } | ||
delete data.__v; | ||
let flattened = flatten(data, { safe: true }); | ||
let flattened = flatten(data, { safe: true, }); | ||
let $set = {}; | ||
let $push = {}; | ||
for (let key in flattened) { | ||
if (Array.isArray(flattened[key])) $push[key] = { $each: flattened[key] }; | ||
if (Array.isArray(flattened[key])) $push[key] = { $each: flattened[key], }; | ||
else $set[key] = flattened[key]; | ||
@@ -290,3 +285,3 @@ } | ||
update: Object.assign({}, options.updatedoc), | ||
original: Object.assign({}, options.originalrevision) | ||
original: Object.assign({}, options.originalrevision), | ||
}; | ||
@@ -299,4 +294,4 @@ let depopulate = (options.depopulate === false) ? false : true; | ||
this.changeset.create({ | ||
parent_document: { id: options.id }, | ||
changeset: changeset | ||
parent_document: { id: options.id, }, | ||
changeset: changeset, | ||
}, (err, result) => { | ||
@@ -319,4 +314,4 @@ if (options.ensure_changes) { | ||
Promisie.parallel({ | ||
update: Promisie.promisify(Model.update, Model)({ _id: options.id }, updateOperation), | ||
changes: Promisie.promisify(generateChanges)() | ||
update: Promisie.promisify(Model.update, Model)({ _id: options.id, }, updateOperation), | ||
changes: Promisie.promisify(generateChanges)(), | ||
}) | ||
@@ -327,4 +322,3 @@ .then(result => { | ||
}, cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -351,6 +345,5 @@ } | ||
if (err) cb(err); | ||
else _LOAD.call(this, { model: options.model, query: options.id }, cb); | ||
else _LOAD.call(this, { model: options.model, query: options.id, }, cb); | ||
}); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -378,5 +371,4 @@ } | ||
else throw new Error('Either updateattributes or updatedoc option must be set in order to execute multi update'); | ||
Model.update(query, patch, { multi: true }, cb); | ||
} | ||
catch (e) { | ||
Model.update(query, patch, { multi: true, }, cb); | ||
} catch (e) { | ||
cb(e); | ||
@@ -408,6 +400,4 @@ } | ||
.catch(cb); | ||
} | ||
else Model.create(utility.enforceXSSRules(newdoc, xss_whitelist, (options.newdoc) ? options : undefined), cb); | ||
} | ||
catch (e) { | ||
} else Model.create(utility.enforceXSSRules(newdoc, xss_whitelist, (options.newdoc) ? options : undefined), cb); | ||
} catch (e) { | ||
cb(e); | ||
@@ -430,5 +420,4 @@ } | ||
if (typeof deleteid !== 'string') throw new Error('Must specify "deleteid" or "id" for delete'); | ||
Model.remove({ _id: deleteid }, cb); | ||
} | ||
catch (e) { | ||
Model.remove({ _id: deleteid, }, cb); | ||
} catch (e) { | ||
cb(e); | ||
@@ -448,3 +437,3 @@ } | ||
try { | ||
_LOAD.call(this, { model: options.model, query: options.deleteid || options.id }, (err1, loaded) => { | ||
_LOAD.call(this, { model: options.model, query: options.deleteid || options.id, }, (err1, loaded) => { | ||
if (err1) cb(err1); | ||
@@ -458,4 +447,3 @@ else { | ||
}); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -462,0 +450,0 @@ } |
@@ -19,3 +19,3 @@ 'use strict'; | ||
if (typeof fields[key] !== 'string') result.push(key); | ||
else result.push([key, fields[key], ]); | ||
else result.push([key, fields[key],]); | ||
} | ||
@@ -42,3 +42,3 @@ return result; | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip', ].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, } = ['sort', 'limit', 'population', 'fields', 'skip',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -89,3 +89,3 @@ return result; | ||
function convertSortObjToOrderArray(sort) { | ||
return Object.keys(sort).map(key => [key, getOrderFromSortObj(sort[key]), ]); | ||
return Object.keys(sort).map(key => [key, getOrderFromSortObj(sort[key]),]); | ||
} | ||
@@ -176,3 +176,3 @@ | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, limit, population, fields, skip, pagelength, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', ].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -190,3 +190,3 @@ return result; | ||
return new Promisie((resolve, reject) => { | ||
_QUERY.call(this, { sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => { | ||
_QUERY.call(this, { query, sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => { | ||
if (err) reject(err); | ||
@@ -199,6 +199,6 @@ else { | ||
pages[index++] = { | ||
documents: (this.jsonify_results) ? | ||
documents: (this.jsonify_results) ? | ||
getJSONResults(data) : data, | ||
count: data.length, | ||
}; | ||
count: data.length, | ||
}; | ||
resolve(data.length); | ||
@@ -257,3 +257,3 @@ } | ||
block.$or.push({ | ||
[searchfields[i]]: value, | ||
[searchfields[i]]: { $iLike:`${value}%` ,}, | ||
}); | ||
@@ -297,3 +297,3 @@ } | ||
//Iteratively checks if value was passed in options argument and conditionally assigns the default value if not passed in options | ||
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid', ].reduce((result, key) => { | ||
let { sort, population, fields, docid, } = ['sort', 'population', 'fields', 'docid',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -305,3 +305,3 @@ return result; | ||
[docid || 'id']: options.query, | ||
}, ], | ||
},], | ||
}; | ||
@@ -383,3 +383,3 @@ let queryOptions = { | ||
[options.docid || this.docid]: options.id, | ||
}, ], | ||
},], | ||
}; | ||
@@ -504,3 +504,3 @@ Promisie.parallel({ | ||
[options.docid || this.docid]: deleteid, | ||
}, ], | ||
},], | ||
force: options.force, | ||
@@ -507,0 +507,0 @@ limit: 1, |
@@ -97,4 +97,4 @@ { | ||
}, | ||
"version": "0.5.1", | ||
"version": "0.5.2", | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1849790
5087