periodicjs.core.data
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -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]; | ||
@@ -48,3 +48,3 @@ return result; | ||
let queryOptions = { | ||
where: (options.query && typeof options.query === 'object') ? options.query : {} | ||
where: (options.query && typeof options.query === 'object') ? options.query : {}, | ||
}; | ||
@@ -63,4 +63,3 @@ if (Object.keys(queryOptions.where).length === 0) delete queryOptions.where; | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -100,4 +99,3 @@ } | ||
}); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -124,3 +122,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, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength',].reduce((result, key) => { | ||
result[key] = options[key] || this[key]; | ||
@@ -131,3 +129,3 @@ return result; | ||
total: 0, | ||
total_pages: 0 | ||
total_pages: 0, | ||
}; | ||
@@ -139,3 +137,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, { sort, limit: (total + pagelength <= limit) ? pagelength : (limit - total), fields, skip, population, model: Model, }, (err, data) => { | ||
if (err) reject(err); | ||
@@ -158,4 +156,3 @@ else { | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -191,3 +188,3 @@ } | ||
let toplevel = (options.inclusive) ? '$or' : '$and'; | ||
query = { [toplevel]: [] }; | ||
query = { [toplevel]: [], }; | ||
//Pushes options.query if it already a composed query object | ||
@@ -202,9 +199,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, }); | ||
} | ||
@@ -215,4 +212,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, }, }); | ||
} | ||
@@ -222,4 +219,3 @@ options.query = query; | ||
else _QUERY.call(this, options, cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -244,3 +240,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]; | ||
@@ -251,7 +247,7 @@ return result; | ||
$or: [{ | ||
[docid || 'id']: options.query | ||
}] | ||
[docid || 'id']: options.query, | ||
},], | ||
}; | ||
let queryOptions = { | ||
where: query | ||
where: query, | ||
}; | ||
@@ -267,4 +263,3 @@ if (fields) queryOptions.attributes = GENERATE_SELECT(fields); | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -290,5 +285,8 @@ } | ||
options.track_changes = (typeof options.track_changes === 'boolean') ? options.track_changes : this.track_changes; | ||
if (!options.id) { | ||
options.id = options.updatedoc._id || options.updatedoc.id; | ||
} | ||
let changesetData = { | ||
update: Object.assign({}, options.updatedoc), | ||
original: Object.assign({}, options.originalrevision) | ||
original: Object.assign({}, options.originalrevision), | ||
}; | ||
@@ -309,3 +307,3 @@ let generateChanges = (callback) => { | ||
original: (changeset[key].length > 1) ? changeset[key][0] : 'new value', | ||
update: (changeset[key].length < 2) ? changeset[0] : ((changeset[key].length === 2) ? changeset[key][1] : 'deleted value') | ||
update: (changeset[key].length < 2) ? changeset[0] : ((changeset[key].length === 2) ? changeset[key][1] : 'deleted value'), | ||
}); | ||
@@ -326,4 +324,4 @@ }); | ||
$or: [{ | ||
[options.docid || this.docid]: options.id | ||
}] | ||
[options.docid || this.docid]: options.id, | ||
},], | ||
}; | ||
@@ -333,8 +331,8 @@ Promisie.parallel({ | ||
limit: 1, | ||
where: options.query | ||
where: options.query, | ||
} : { | ||
where, | ||
limit: 1 | ||
limit: 1, | ||
}), | ||
changes: Promisie.promisify(generateChanges)() | ||
changes: Promisie.promisify(generateChanges)(), | ||
}) | ||
@@ -345,4 +343,3 @@ .then(result => { | ||
}, cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -370,6 +367,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); | ||
@@ -398,4 +394,3 @@ } | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -426,4 +421,3 @@ } | ||
.catch(cb); | ||
} | ||
else { | ||
} else { | ||
Model.create(utility.enforceXSSRules(newdoc, xss_whitelist, (options.newdoc) ? options : undefined)) | ||
@@ -433,4 +427,3 @@ .then(result => cb(null, result)) | ||
} | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -456,13 +449,12 @@ } | ||
where: [{ | ||
id: deleteid | ||
id: deleteid, | ||
}, { | ||
[options.docid || this.docid]: deleteid | ||
}], | ||
[options.docid || this.docid]: deleteid, | ||
},], | ||
force: options.force, | ||
limit: 1 | ||
limit: 1, | ||
}) | ||
.then(result => cb(null, result)) | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -482,3 +474,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); | ||
@@ -492,4 +484,3 @@ else { | ||
}); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -518,7 +509,6 @@ } | ||
} | ||
this.db_connection.query(query, { type, model: Model }) | ||
this.db_connection.query(query, { type, model: Model, }) | ||
.then(result => cb(null, result)) | ||
.catch(cb); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
cb(e); | ||
@@ -558,5 +548,4 @@ } | ||
this.db_connection = new Sequelize(...connectionOptions); | ||
} | ||
else if (options.db_connection.db_name && options.db_connection.db_user && options.db_connection.db_password) { | ||
let { db_name, db_user, db_password, db_options } = options.db_connection; | ||
} else if (options.db_connection.db_name && options.db_connection.db_user && options.db_connection.db_password) { | ||
let { db_name, db_user, db_password, db_options, } = options.db_connection; | ||
this.db_connection = new Sequelize(db_name, db_user, db_password, db_options); | ||
@@ -570,4 +559,3 @@ } | ||
else this.model = options.model; | ||
} | ||
else this.model = this.db_connection.models[options.model]; | ||
} else this.model = this.db_connection.models[options.model]; | ||
this.sort = options.sort || 'createdat DESC'; | ||
@@ -604,10 +592,9 @@ this.limit = options.limit || 500; | ||
value: true, | ||
enumerable: false | ||
enumerable: false, | ||
}); | ||
} | ||
callback(null, { status: 'ok' }); | ||
callback(null, { status: 'ok', }); | ||
}) | ||
.catch(callback); | ||
} | ||
catch (e) { | ||
} catch (e) { | ||
callback(e); | ||
@@ -614,0 +601,0 @@ } |
@@ -96,4 +96,4 @@ { | ||
}, | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"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
1846726
85
5014