periodicjs.core.data
Advanced tools
Comparing version 0.8.2 to 0.8.3
@@ -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) => { | ||
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]); | ||
@@ -63,3 +63,3 @@ result[key] = (typeof options[key]!=='undefined') ? options[key] : this[key]; | ||
// else queryOptions.include = population; | ||
queryOptions.include = [{ all: true }] | ||
queryOptions.include = [{ all: true, },]; | ||
} | ||
@@ -95,3 +95,3 @@ // queryOptions.raw = true; | ||
function convertSortObjToOrderArray(sort) { | ||
return Object.keys(sort).map(key => [key, getOrderFromSortObj(sort[key]),]); | ||
return Object.keys(sort).map(key => [key, getOrderFromSortObj(sort[key]), ]); | ||
} | ||
@@ -146,9 +146,9 @@ | ||
(this.jsonify_results) ? | ||
getPlainResult(documents[i]) : | ||
documents[i] | ||
getPlainResult(documents[i]) : | ||
documents[i] | ||
); | ||
else querystream.write( | ||
(this.jsonify_results) ? | ||
getPlainResult(documents[i]) : | ||
documents[i] | ||
getPlainResult(documents[i]) : | ||
documents[i] | ||
); | ||
@@ -183,3 +183,3 @@ clearImmediate(task); | ||
//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, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query',].reduce((result, key) => { | ||
let { sort, limit, population, fields, skip, pagelength, query, } = ['sort', 'limit', 'population', 'fields', 'skip', 'pagelength', 'query', ].reduce((result, key) => { | ||
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]); | ||
@@ -224,4 +224,4 @@ result[key] = options[key] || this[key]; | ||
}, current => (current === pagelength && total < limit)) | ||
.then(() => pages) | ||
.catch(e => Promisie.reject(e)); | ||
.then(() => pages) | ||
.catch(e => Promisie.reject(e)); | ||
}, | ||
@@ -347,3 +347,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) => { | ||
if (options[key] && !isNaN(Number(options[key]))) options[key] = Number(options[key]); | ||
@@ -390,16 +390,16 @@ result[key] = options[key] || this[key]; | ||
if (population && Array.isArray(population)) { | ||
// queryOptions.include = population.map(pop => ({ | ||
// model: this.db_connection.models[ pop.model ], | ||
// as: pop.as, | ||
// through: pop.through, | ||
// foreignKey: pop.foreignKey, | ||
// })); | ||
queryOptions.include = [{ all: true }] | ||
// queryOptions.include = population.map(pop => ({ | ||
// model: this.db_connection.models[ pop.model ], | ||
// as: pop.as, | ||
// through: pop.through, | ||
// foreignKey: pop.foreignKey, | ||
// })); | ||
queryOptions.include = [{ all: true, },]; | ||
// if (population && population.include) queryOptions.include = population.include; | ||
// else queryOptions.include = population.map(pop => ({ | ||
// model: this.db_connection.models[ pop.model ], | ||
// as: pop.as, | ||
// through: pop.through, | ||
// foreignKey: pop.foreignKey, | ||
// })); | ||
// model: this.db_connection.models[ pop.model ], | ||
// as: pop.as, | ||
// through: pop.through, | ||
// foreignKey: pop.foreignKey, | ||
// })); | ||
// console.log('this.db_connection.models', this.db_connection.models,'queryOptions.include',queryOptions.include,{queryOptions, population}); | ||
@@ -451,19 +451,19 @@ } | ||
})() | ||
.then(() => { | ||
return Promisie.map(Object.keys(changeset), (key) => { | ||
return this.changeset.create({ | ||
parent_document_id: options.id, | ||
field_name: key, | ||
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'), | ||
.then(() => { | ||
return Promisie.map(Object.keys(changeset), (key) => { | ||
return this.changeset.create({ | ||
parent_document_id: options.id, | ||
field_name: key, | ||
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'), | ||
}); | ||
}); | ||
}) | ||
.then(result => { | ||
if (options.ensure_changes) callback(null, (this.jsonify_results) ? | ||
getPlainResult(result) : | ||
result); | ||
}, e => { | ||
if (options.ensure_changes) callback(e); | ||
}); | ||
}) | ||
.then(result => { | ||
if (options.ensure_changes) callback(null, (this.jsonify_results) ? | ||
getPlainResult(result) : | ||
result); | ||
}, e => { | ||
if (options.ensure_changes) callback(e); | ||
}); | ||
} | ||
@@ -504,6 +504,6 @@ }; | ||
}) | ||
.then(result => { | ||
if (options.ensure_changes) cb(null, result); | ||
else cb(null, result.update); | ||
}, cb); | ||
.then(result => { | ||
if (options.ensure_changes) cb(null, result); | ||
else cb(null, result.update); | ||
}, cb); | ||
} catch (e) { | ||
@@ -608,8 +608,24 @@ cb(e); | ||
if (typeof deleteid !== 'string' && typeof deleteid !== 'number') throw new Error('Must specify "deleteid" or "id" for delete'); | ||
const docid = options.docid || this.docid || '_id'; | ||
const deleteWhere = []; | ||
if (Array.isArray(docid)) { | ||
deleteWhere.push(...docid | ||
.map(docidname => ({ | ||
[ docidname ]: deleteid, | ||
})) | ||
); | ||
} else if (docid.indexOf(',')!==-1) { | ||
deleteWhere.push(...docid | ||
.split(',') | ||
.map(docidname => ({ | ||
[ docidname ]: deleteid, | ||
})) | ||
); | ||
} else { | ||
deleteWhere.push({ | ||
[ docid ]: deleteid, | ||
}); | ||
} | ||
Model.destroy({ | ||
where: [{ | ||
id: deleteid, | ||
}, { | ||
[options.docid || this.docid]: deleteid, | ||
},], | ||
where: deleteWhere, | ||
force: options.force, | ||
@@ -616,0 +632,0 @@ limit: 1, |
@@ -97,4 +97,4 @@ { | ||
}, | ||
"version": "0.8.2", | ||
"version": "0.8.3", | ||
"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
1864273
5497