Ren handleUndefined to normalizeUndefinedInQuery
This commit is contained in:
parent
0ce3f4ead9
commit
a391762771
20
lib/dao.js
20
lib/dao.js
|
@ -804,9 +804,9 @@ DataAccessObject.upsertWithWhere = function(where, data, options, cb) {
|
||||||
function callConnector() {
|
function callConnector() {
|
||||||
try {
|
try {
|
||||||
// Support an optional where object
|
// Support an optional where object
|
||||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||||
// alter configuration of how sanitizeQuery handles undefined values
|
// 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);
|
ctx.where = Model._coerce(ctx.where, options);
|
||||||
update = Model._sanitize(update);
|
update = Model._sanitize(update);
|
||||||
update = Model._coerce(update, options);
|
update = Model._coerce(update, options);
|
||||||
|
@ -1579,9 +1579,9 @@ DataAccessObject._normalize = function(filter, options) {
|
||||||
Object.keys(this.definition.properties), this.settings.strict);
|
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
|
// 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);
|
this._coerce(filter.where, options);
|
||||||
return filter;
|
return filter;
|
||||||
};
|
};
|
||||||
|
@ -2325,9 +2325,9 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// Support an optional where object
|
// Support an optional where object
|
||||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||||
// alter configuration of how sanitizeQuery handles undefined values
|
// 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);
|
where = Model._coerce(where, options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return process.nextTick(function() {
|
return process.nextTick(function() {
|
||||||
|
@ -2480,9 +2480,9 @@ DataAccessObject.count = function(where, options, cb) {
|
||||||
where = query.where;
|
where = query.where;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||||
// alter configuration of how sanitizeQuery handles undefined values
|
// 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);
|
where = this._coerce(where, options);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
|
@ -2775,9 +2775,9 @@ DataAccessObject.updateAll = function(where, data, options, cb) {
|
||||||
function doUpdate(where, data) {
|
function doUpdate(where, data) {
|
||||||
try {
|
try {
|
||||||
// Support an optional where object
|
// Support an optional where object
|
||||||
var handleUndefined = Model._getSetting('normalizeUndefinedInQuery');
|
var normalizeUndefinedInQuery = Model._getSetting('normalizeUndefinedInQuery');
|
||||||
// alter configuration of how sanitizeQuery handles undefined values
|
// 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);
|
where = Model._coerce(where, options);
|
||||||
data = Model._sanitize(data);
|
data = Model._sanitize(data);
|
||||||
data = Model._coerce(data, options);
|
data = Model._coerce(data, options);
|
||||||
|
|
|
@ -306,7 +306,7 @@ function selectFields(fields) {
|
||||||
* Sanitize the query object
|
* Sanitize the query object
|
||||||
* @param query {object} The query object
|
* @param query {object} The query object
|
||||||
* @param options
|
* @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
|
* @property prohibitedKeys {String[]} An array of prohibited keys to be removed
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
|
@ -318,11 +318,11 @@ function sanitizeQuery(query, options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
if (typeof options === 'string') {
|
if (typeof options === 'string') {
|
||||||
// Keep it backward compatible
|
// Keep it backward compatible
|
||||||
options = {handleUndefined: options};
|
options = {normalizeUndefinedInQuery: options};
|
||||||
}
|
}
|
||||||
const prohibitedKeys = options.prohibitedKeys;
|
const prohibitedKeys = options.prohibitedKeys;
|
||||||
const offendingKeys = [];
|
const offendingKeys = [];
|
||||||
const handleUndefined = options.handleUndefined;
|
const normalizeUndefinedInQuery = options.normalizeUndefinedInQuery;
|
||||||
const maxDepth = options.maxDepth || 10;
|
const maxDepth = options.maxDepth || 10;
|
||||||
// WARNING: [rfeng] Use map() will cause mongodb to produce invalid BSON
|
// WARNING: [rfeng] Use map() will cause mongodb to produce invalid BSON
|
||||||
// as traverse doesn't transform the ObjectId correctly
|
// as traverse doesn't transform the ObjectId correctly
|
||||||
|
@ -351,7 +351,7 @@ function sanitizeQuery(query, options) {
|
||||||
* Handle undefined values
|
* Handle undefined values
|
||||||
*/
|
*/
|
||||||
if (x === undefined) {
|
if (x === undefined) {
|
||||||
switch (handleUndefined) {
|
switch (normalizeUndefinedInQuery) {
|
||||||
case 'nullify':
|
case 'nullify':
|
||||||
this.update(null);
|
this.update(null);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -78,7 +78,7 @@ describe('util.sanitizeQuery', function() {
|
||||||
should.deepEqual(sanitizeQuery(q5, 'nullify'), {where: {x: 1, y: null}});
|
should.deepEqual(sanitizeQuery(q5, 'nullify'), {where: {x: 1, y: null}});
|
||||||
|
|
||||||
q5 = {where: {x: 1, y: undefined}};
|
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}};
|
var q6 = {where: {x: 1, y: undefined}};
|
||||||
(function() { sanitizeQuery(q6, 'throw'); }).should.throw(/`undefined` in query/);
|
(function() { sanitizeQuery(q6, 'throw'); }).should.throw(/`undefined` in query/);
|
||||||
|
|
Loading…
Reference in New Issue