nedb-async
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -25,35 +25,16 @@ "use strict"; | ||
let count = 1; | ||
// @ts-ignore | ||
for (const modify of modifies) { | ||
for (const [method, value] of modifies) { | ||
const valid = ['sort', 'limit', 'skip']; | ||
if (valid.indexOf(modify[0]) === -1) { | ||
throw new Error(`${modify[0]} is not recognize, available methods are ${valid.join(',')}`); | ||
if (valid.includes(method)) { | ||
throw new Error(`${method} is not recognized, available methods are ${valid.join(',')}`); | ||
} | ||
if (typeof modify[0] !== 'string') { | ||
throw new Error(`${modify[0]} must be a type of string, available methods are ${valid.join(',')}`); | ||
if (typeof method !== 'string') { | ||
throw new Error(`${method} must be a type of string, available methods are ${valid.join(',')}`); | ||
} | ||
/** | ||
* If this modify is the last | ||
* element of the modifies | ||
* array append exec method | ||
* the modify array contains | ||
* two elements, first element | ||
* being the method name while | ||
* the last element the method | ||
* argument | ||
* ['sort',{name: -1, createdAt: -1}] | ||
* and so on | ||
*/ | ||
// call exec method if it's the last | ||
if (count === arg.length) { | ||
cursor[modify[0]](modify[1]).exec((err, docs) => { | ||
if (err) { | ||
rj(err); | ||
} | ||
else { | ||
rs(docs); | ||
} | ||
}); | ||
cursor[method](value).exec((err, docs) => (err ? rj(err) : rs(docs))); | ||
} | ||
else { | ||
cursor[modify[0]](modify[1]); | ||
cursor[method](value); | ||
} | ||
@@ -65,10 +46,3 @@ count++; | ||
// @ts-ignore | ||
this[name](...arg, (err, docs) => { | ||
if (err) { | ||
rj(err); | ||
} | ||
else { | ||
rs(docs); | ||
} | ||
}); | ||
this[name](...arg, (err, docs) => (err ? rj(err) : rs(docs))); | ||
} | ||
@@ -75,0 +49,0 @@ }); |
{ | ||
"name": "nedb-async", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Promise wrapper for Nedb that makes it possible to use all Nedb all cursor modifiers.", | ||
@@ -5,0 +5,0 @@ "repository": { |
8971
122