Permalink
Browse files

even more strict

  • Loading branch information...
1 parent 94b4a0f commit 7b5288852650c11c20fab885ede5ebcb2c76f036 @TrejGun TrejGun committed Jan 31, 2016
Showing with 1,184 additions and 1,169 deletions.
  1. +2 −2 benchmarks/benchjs/delete.js
  2. +10 −10 benchmarks/benchjs/multiop.js
  3. +14 −14 bin/mongoose.debug.js
  4. +17 −17 bin/mongoose.js
  5. +1 −1 docs/helpers/href.js
  6. +1 −1 docs/helpers/linktype.js
  7. +1 −1 docs/includes/googleanalytics.jade
  8. +1 −1 docs/includes/googlesearch.jade
  9. +4 −4 docs/source/api.js
  10. +1 −1 examples/schema/schema.js
  11. +1 −1 index.html
  12. +1 −1 lib/ES6Promise.js
  13. +7 −7 lib/aggregate.js
  14. +1 −1 lib/browserDocument.js
  15. +9 −9 lib/cast.js
  16. +3 −4 lib/collection.js
  17. +43 −37 lib/connection.js
  18. +83 −83 lib/document.js
  19. +21 −21 lib/drivers/node-mongodb-native/collection.js
  20. +21 −21 lib/drivers/node-mongodb-native/connection.js
  21. +3 −2 lib/error/validation.js
  22. +4 −4 lib/index.js
  23. +72 −72 lib/model.js
  24. +55 −56 lib/query.js
  25. +16 −16 lib/querystream.js
  26. +20 −20 lib/schema.js
  27. +7 −9 lib/schema/array.js
  28. +3 −3 lib/schema/boolean.js
  29. +3 −3 lib/schema/buffer.js
  30. +8 −8 lib/schema/date.js
  31. +11 −11 lib/schema/number.js
  32. +3 −3 lib/schema/objectid.js
  33. +4 −4 lib/schema/operators/bitwise.js
  34. +17 −17 lib/schema/string.js
  35. +26 −26 lib/schematype.js
  36. +4 −4 lib/statemachine.js
  37. +7 −7 lib/types/array.js
  38. +4 −4 lib/types/buffer.js
  39. +5 −5 lib/types/documentarray.js
  40. +3 −3 lib/types/embedded.js
  41. +17 −17 lib/utils.js
  42. +1 −1 static.js
  43. +2 −2 test/aggregate.test.js
  44. +4 −4 test/browser/schema.validation.test_.js
  45. +1 −1 test/browser/types.objectid.test_.js
  46. +9 −9 test/connection.test.js
  47. +5 −5 test/document.hooks.test.js
  48. +4 −4 test/document.test.js
  49. +4 −4 test/index.test.js
  50. +1 −1 test/model.aggregate.test.js
  51. +12 −17 test/model.findOneAndUpdate.test.js
  52. +1 −1 test/model.geonear.test.js
  53. +1 −1 test/model.hydrate.test.js
  54. +3 −3 test/model.indexes.test.js
  55. +8 −8 test/model.mapreduce.test.js
  56. +5 −5 test/model.middleware.test.js
  57. +5 −5 test/model.populate.test.js
  58. +15 −15 test/model.querying.test.js
  59. +61 −61 test/model.stream.test.js
  60. +171 −171 test/model.test.js
  61. +21 −27 test/model.update.test.js
  62. +1 −1 test/promise.test.js
  63. +6 −6 test/promise_provider.test.js
  64. +6 −6 test/query.test.js
  65. +2 −2 test/schema.select.test.js
  66. +1 −1 test/schema.test.js
  67. +2 −2 test/schema.timestamps.test.js
  68. +61 −40 test/schema.validation.test.js
  69. +1 −1 test/shard.test.js
  70. +6 −6 test/types.array.test.js
  71. +2 −2 test/types.documentarray.test.js
  72. +3 −3 test/utils.test.js
  73. +177 −177 test/versioning.test.js
  74. +48 −46 website.js
@@ -68,13 +68,13 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
function closeDB() {
User.count(function (err, res) {
- if (res != 0) {
+ if (res !== 0) {
console.log('Still mongoose entries left...');
}
mongoose.disconnect();
});
user.count({}, function (err, res) {
- if (res != 0) {
+ if (res !== 0) {
console.log('Still driver entries left...');
}
if (err) {
@@ -190,7 +190,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(data);
User.create(nData, function (err) {
if (err) {
@@ -212,7 +212,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(data);
user.insert(nData, function (err) {
if (err) {
@@ -234,7 +234,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(blogData);
BlogPost.create(nData, function (err) {
if (err) {
@@ -256,7 +256,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(blogData);
blogpost.insert(nData, function (err) {
if (err) {
@@ -280,7 +280,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
User.findOne({_id: getNextmId()}, function (err) {
if (err) {
throw err;
@@ -303,7 +303,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
user.findOne({_id: getNextdId()}, function (err) {
if (err) {
throw err;
@@ -326,7 +326,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
BlogPost.findOne({_id: getNextbmId()}, function (err) {
if (err) {
throw err;
@@ -349,7 +349,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
}
--count || deferred.resolve();
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
blogpost.findOne({_id: getNextbdId()}, function (err) {
if (err) {
throw err;
@@ -384,7 +384,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
--count || deferred.resolve();
}
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(blogData);
BlogPost.create(nData, function (err) {
if (err) {
@@ -420,7 +420,7 @@ mongoose.connect('mongodb://localhost/mongoose-bench', function (err) {
--count || deferred.resolve();
}
});
- if (i % 15 == 0) {
+ if (i % 15 === 0) {
var nData = utils.clone(blogData);
blogpost.insert(nData, function (err) {
if (err) {
View
@@ -263,7 +263,7 @@ var cast = module.exports = function(schema, obj) {
throw new Error("Must have a string or function for $where");
}
- if ('function' === type) {
+ if (type === 'function') {
obj[path] = val.toString();
}
@@ -379,7 +379,7 @@ var cast = module.exports = function(schema, obj) {
} else if (val === null || val === undefined) {
continue;
- } else if ('Object' === val.constructor.name) {
+ } else if (val.constructor.name === 'Object') {
any$conditionals = Object.keys(val).some(function (k) {
return k.charAt(0) === '$' && k !== '$id' && k !== '$ref';
@@ -577,7 +577,7 @@ Document.prototype.$__buildDoc = function (obj, fields, skipId) {
// determine if this doc is a result of a query with
// excluded fields
- if (fields && 'Object' === utils.getFunctionName(fields.constructor)) {
+ if (fields && utils.getFunctionName(fields.constructor) === 'Object') {
keys = Object.keys(fields);
ki = keys.length;
@@ -895,7 +895,7 @@ Document.prototype.set = function (path, val, type, options) {
) {
this.set(path[key], prefix + key, constructing);
} else if (strict) {
- if ('real' === pathtype || 'virtual' === pathtype) {
+ if ('real' === pathtype || pathtype === 'virtual') {
this.set(prefix + key, path[key], constructing);
} else if ('throw' == strict) {
throw new Error("Field `" + key + "` is not in schema.");
@@ -1088,7 +1088,7 @@ Document.prototype.$__set = function (
if (last) {
obj[parts[i]] = val;
} else {
- if (obj[parts[i]] && 'Object' === utils.getFunctionName(obj[parts[i]].constructor)) {
+ if (obj[parts[i]] && utils.getFunctionName(obj[parts[i]].constructor) === 'Object') {
obj = obj[parts[i]];
} else if (obj[parts[i]] && obj[parts[i]] instanceof Embedded) {
obj = obj[parts[i]];
@@ -1658,7 +1658,7 @@ function compile (tree, proto, prefix) {
limb = tree[key];
define(key
- , (('Object' === utils.getFunctionName(limb.constructor)
+ , ((utils.getFunctionName(limb.constructor === 'Object')
&& Object.keys(limb).length)
&& (!limb.type || limb.type.type)
? limb
@@ -4204,7 +4204,7 @@ function SchemaArray (key, cast, options) {
if (cast) {
var castOptions = {};
- if ('Object' === utils.getFunctionName(cast.constructor)) {
+ if (utils.getFunctionName(cast.constructor) === 'Object') {
if (cast.type) {
// support { type: Woot }
castOptions = utils.clone(cast); // do not alter user arguments
@@ -4307,7 +4307,7 @@ SchemaArray.prototype.cast = function (value, doc, init) {
for (var i = 0, l = indexes.length; i < l; ++i) {
var pathIndex = indexes[i][0][this.path];
- if ('2dsphere' === pathIndex || '2d' === pathIndex) {
+ if ('2dsphere' === pathIndex || pathIndex === '2d') {
return;
}
}
@@ -4602,9 +4602,9 @@ SchemaBoolean.prototype.checkRequired = function (value) {
SchemaBoolean.prototype.cast = function (value) {
if (null === value) return value;
- if ('0' === value) return false;
- if ('true' === value) return true;
- if ('false' === value) return false;
+ if (value === '0') return false;
+ if (value === 'true') return true;
+ if (value === 'false') return false;
return !! value;
}
@@ -6647,7 +6647,7 @@ SchemaType.prototype.get = function (fn) {
*/
SchemaType.prototype.validate = function (obj, message, type) {
- if ('function' == typeof obj || obj && 'RegExp' === utils.getFunctionName(obj.constructor)) {
+ if ('function' == typeof obj || obj && utils.getFunctionName(obj.constructor) === 'RegExp') {
var properties;
if (message instanceof Object && !type) {
properties = utils.clone(message);
@@ -6670,7 +6670,7 @@ SchemaType.prototype.validate = function (obj, message, type) {
for (i=0, length=arguments.length; i<length; i++) {
arg = arguments[i];
- if (!(arg && 'Object' === utils.getFunctionName(arg.constructor))) {
+ if (!(arg && utils.getFunctionName(arg.constructor)) === 'Object') {
var msg = 'Invalid validator. Received (' + typeof arg + ') '
+ arg
+ '. See http://mongoosejs.com/docs/api.html#schematype_SchemaType-validate';
@@ -7442,7 +7442,7 @@ MongooseArray.mixin = {
*/
hasAtomics: function hasAtomics () {
- if (!(this._atomics && 'Object' === this._atomics.constructor.name)) {
+ if (!(this._atomics && this._atomics.constructor.name) === 'Object') {
return 0;
}
View
@@ -280,7 +280,7 @@ var cast = module.exports = function(schema, obj) {
throw new Error("Must have a string or function for $where");
}
- if ('function' === type) {
+ if (type === 'function') {
obj[path] = val.toString();
}
@@ -400,7 +400,7 @@ var cast = module.exports = function(schema, obj) {
} else if (val === null || val === undefined) {
obj[path] = null;
continue;
- } else if ('Object' === val.constructor.name) {
+ } else if (val.constructor.name === 'Object') {
any$conditionals = Object.keys(val).some(function(k) {
return k.charAt(0) === '$' && k !== '$id' && k !== '$ref';
@@ -610,7 +610,7 @@ Document.prototype.$__buildDoc = function(obj, fields, skipId) {
// determine if this doc is a result of a query with
// excluded fields
- if (fields && 'Object' === utils.getFunctionName(fields.constructor)) {
+ if (fields && utils.getFunctionName(fields.constructor) === 'Object') {
keys = Object.keys(fields);
ki = keys.length;
@@ -957,7 +957,7 @@ Document.prototype.set = function(path, val, type, options) {
this.schema.paths[pathName].options.ref)) {
this.set(path[key], prefix + key, constructing);
} else if (strict) {
- if ('real' === pathtype || 'virtual' === pathtype) {
+ if ('real' === pathtype || pathtype === 'virtual') {
// Check for setting single embedded schema to document (gh-3535)
if (this.schema.paths[pathName] &&
this.schema.paths[pathName].$isSingleNested &&
@@ -1208,7 +1208,7 @@ Document.prototype.$__set = function(
if (last) {
obj[parts[i]] = val;
} else {
- if (obj[parts[i]] && 'Object' === utils.getFunctionName(obj[parts[i]].constructor)) {
+ if (obj[parts[i]] && utils.getFunctionName(obj[parts[i]].constructor) === 'Object') {
obj = obj[parts[i]];
} else if (obj[parts[i]] && obj[parts[i]] instanceof Embedded) {
obj = obj[parts[i]];
@@ -1931,7 +1931,7 @@ function compile(tree, proto, prefix, options) {
limb = tree[key];
defineKey(key
- , (('Object' === utils.getFunctionName(limb.constructor)
+ , ((utils.getFunctionName(limb.constructor === 'Object')
&& Object.keys(limb).length)
&& (!limb[options.typeKey] || (options.typeKey === 'type' && limb.type.type))
? limb
@@ -5091,7 +5091,7 @@ function SchemaArray(key, cast, options) {
if (cast) {
var castOptions = {};
- if ('Object' === utils.getFunctionName(cast.constructor)) {
+ if (utils.getFunctionName(cast.constructor) === 'Object') {
if (cast.type) {
// support { type: Woot }
castOptions = utils.clone(cast); // do not alter user arguments
@@ -5194,7 +5194,7 @@ SchemaArray.prototype.cast = function(value, doc, init) {
for (var i = 0, l = indexes.length; i < l; ++i) {
var pathIndex = indexes[i][0][this.path];
- if ('2dsphere' === pathIndex || '2d' === pathIndex) {
+ if ('2dsphere' === pathIndex || pathIndex === '2d') {
return;
}
}
@@ -5506,9 +5506,9 @@ SchemaBoolean.prototype.checkRequired = function(value) {
SchemaBoolean.prototype.cast = function(value) {
if (null === value) return value;
- if ('0' === value) return false;
- if ('true' === value) return true;
- if ('false' === value) return false;
+ if (value === '0') return false;
+ if (value === 'true') return true;
+ if (value === 'false') return false;
return !!value;
};
@@ -8009,7 +8009,7 @@ SchemaType.prototype.get = function(fn) {
*/
SchemaType.prototype.validate = function(obj, message, type) {
- if ('function' == typeof obj || obj && 'RegExp' === utils.getFunctionName(obj.constructor)) {
+ if ('function' == typeof obj || obj && utils.getFunctionName(obj.constructor) === 'RegExp') {
var properties;
if (message instanceof Object && !type) {
properties = utils.clone(message);
@@ -8033,7 +8033,7 @@ SchemaType.prototype.validate = function(obj, message, type) {
for (i = 0, length = arguments.length; i < length; i++) {
arg = arguments[i];
- if (!(arg && 'Object' === utils.getFunctionName(arg.constructor))) {
+ if (!(arg && utils.getFunctionName(arg.constructor)) === 'Object') {
var msg = 'Invalid validator. Received (' + typeof arg + ') '
+ arg
+ '. See http://mongoosejs.com/docs/api.html#schematype_SchemaType-validate';
@@ -8892,7 +8892,7 @@ MongooseArray.mixin = {
*/
hasAtomics: function hasAtomics() {
- if (!(this._atomics && 'Object' === this._atomics.constructor.name)) {
+ if (!(this._atomics && this._atomics.constructor.name) === 'Object') {
return 0;
}
@@ -23994,13 +23994,13 @@ var clone = exports.clone = function clone (obj, options) {
: new obj.constructor(obj.value(true), obj.sub_type);
}
- if ('Date' === obj.constructor.name || 'Function' === obj.constructor.name)
+ if ('Date' === obj.constructor.name || obj.constructor.name === 'Function')
return new obj.constructor(+obj);
- if ('RegExp' === obj.constructor.name)
+ if (obj.constructor.name === 'RegExp')
return RegExpClone(obj);
- if ('Buffer' === obj.constructor.name)
+ if (obj.constructor.name === 'Buffer')
return exports.cloneBuffer(obj);
}
@@ -1,6 +1,6 @@
module.exports = exports = function (str, char) {
- if ('string' != typeof str) return str;
+ if ('string' !== typeof str) return str;
return encodeURIComponent(
str.replace(/\.js$/, '')
.replace(/#/g, char || '-')
@@ -39,7 +39,7 @@ types.any = 'nolink';
module.exports= function (type) {
if (types[type]) {
- if ('nolink' == types[type]) return 'T';
+ if ('nolink' === types[type]) return 'T';
return '<a href="' + types[type] + '">' + type + '</a>';
}
return '<a href="#' + type + '">' + type + '</a>';
@@ -5,6 +5,6 @@ script.
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+ ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
@@ -4,7 +4,7 @@ script
var gcse = document.createElement('script');
gcse.type = 'text/javascript';
gcse.async = true;
- gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
+ gcse.src = (document.location.protocol === 'https:' ? 'https:' : 'http:') +
'//www.google.com/cse/cse.js?cx=' + cx;
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(gcse, s);
Oops, something went wrong.

0 comments on commit 7b52888

Please sign in to comment.