Ren handleUndefined to normalizeUndefinedInQuery

This commit is contained in:
Raymond Feng 2018-10-26 09:05:47 -07:00
parent 89bb3079bd
commit 63f0fe20ed
3 changed files with 15 additions and 15 deletions

View File

@ -804,9 +804,9 @@ DataAccessObject.upsertWithWhere = function(where, data, options, cb) {
function callConnector() {
try {
// Support an optional where object
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
// alter configuration of how sanitizeQuery handles undefined values
ctx.where = Model._sanitize(ctx.where, {handleUndefined: handleUndefined});
ctx.where = Model._sanitize(ctx.where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
ctx.where = Model._coerce(ctx.where, options);
update = Model._sanitize(update);
update = Model._coerce(update, options);
@ -1579,9 +1579,9 @@ DataAccessObject._normalize = function(filter, options) {
Object.keys(this.definition.properties), this.settings.strict);
}
var handleUndefined = this._getSetting('normalizeUndefinedInQuery');
var normalizeUndefinedInQuery = this._getSetting('normalizeUndefinedInQuery');
// alter configuration of how sanitizeQuery handles undefined values
filter = this._sanitize(filter, {handleUndefined: handleUndefined});
filter = this._sanitize(filter, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
this._coerce(filter.where, options);
return filter;
};
@ -2325,9 +2325,9 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
} else {
try {
// Support an optional where object
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
// alter configuration of how sanitizeQuery handles undefined values
where = Model._sanitize(where, {handleUndefined: handleUndefined});
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
where = Model._coerce(where, options);
} catch (err) {
return process.nextTick(function() {
@ -2480,9 +2480,9 @@ DataAccessObject.count = function(where, options, cb) {
where = query.where;
try {
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
// alter configuration of how sanitizeQuery handles undefined values
where = Model._sanitize(where, {handleUndefined: handleUndefined});
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
where = this._coerce(where, options);
} catch (err) {
process.nextTick(function() {
@ -2775,9 +2775,9 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
function doUpdate(where, data) {
try {
// Support an optional where object
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
// alter configuration of how sanitizeQuery handles undefined values
where = Model._sanitize(where, {handleUndefined: handleUndefined});
where = Model._sanitize(where, {normalizeUndefinedInQuery: normalizeUndefinedInQuery});
where = Model._coerce(where, options);
data = Model._sanitize(data);
data = Model._coerce(data, options);

View File

@ -306,7 +306,7 @@ function selectFields(fields) {
* Sanitize the query object
* @param query {object} The query object
* @param options
* @property handleUndefined {String} either "nullify", "throw" or "ignore" (default: "ignore")
* @property normalizeUndefinedInQuery {String} either "nullify", "throw" or "ignore" (default: "ignore")
* @property prohibitedKeys {String[]} An array of prohibited keys to be removed
* @returns {*}
*/
@ -318,11 +318,11 @@ function sanitizeQuery(query, options) {
options = options || {};
if (typeof options === 'string') {
// Keep it backward compatible
options = {handleUndefined: options};
options = {normalizeUndefinedInQuery: options};
}
const prohibitedKeys = options.prohibitedKeys;
const offendingKeys = [];
const handleUndefined = options.handleUndefined;
const normalizeUndefinedInQuery = options.normalizeUndefinedInQuery;
const maxDepth = options.maxDepth || 10;
// WARNING: [rfeng] Use map() will cause mongodb to produce invalid BSON
// as traverse doesn't transform the ObjectId correctly
@ -351,7 +351,7 @@ function sanitizeQuery(query, options) {
* Handle undefined values
*/
if (x === undefined) {
switch (handleUndefined) {
switch (normalizeUndefinedInQuery) {
case 'nullify':
this.update(null);
break;

View File

@ -78,7 +78,7 @@ describe('util.sanitizeQuery', function() {
should.deepEqual(sanitizeQuery(q5, 'nullify'), {where: {x: 1, y: null}});
q5 = {where: {x: 1, y: undefined}};
should.deepEqual(sanitizeQuery(q5, {handleUndefined: 'nullify'}), {where: {x: 1, y: null}});
should.deepEqual(sanitizeQuery(q5, {normalizeUndefinedInQuery: 'nullify'}), {where: {x: 1, y: null}});
var q6 = {where: {x: 1, y: undefined}};
(function() { sanitizeQuery(q6, 'throw'); }).should.throw(/`undefined` in query/);