New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

sails-mongo

Package Overview
Dependencies
Maintainers
4
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sails-mongo - npm Package Compare versions

Comparing version 0.11.2 to 0.11.3

test/unit/utils.clarifyError.test.js

7

lib/adapter.js

@@ -13,2 +13,3 @@ /*---------------------------------------------------------------

var _ = require('lodash');
var utils = require('./utils');

@@ -280,3 +281,3 @@

collection.insert(data, function(err, results) {
if(err) return cb(err);
if(err) return cb(utils.clarifyError(err));
cb(null, results[0]);

@@ -306,3 +307,3 @@ });

collection.insert(data, function(err, results) {
if(err) return cb(err);
if(err) return cb(utils.clarifyError(err));
cb(null, results);

@@ -354,3 +355,3 @@ });

collection.update(options, values, function(err, results) {
if(err) return cb(err);
if(err) return cb(utils.clarifyError(err));
cb(null, results);

@@ -357,0 +358,0 @@ });

@@ -61,7 +61,2 @@

// Ignore `select` from waterline core
if (typeof criteria === 'object') {
delete criteria.select;
}
// Catch errors from building query and return to the callback

@@ -102,3 +97,3 @@ try {

// Run Normal Query on collection
collection.find(where, queryOptions).toArray(function(err, docs) {
collection.find(where, query.select, queryOptions).toArray(function(err, docs) {
if(err) return cb(err);

@@ -105,0 +100,0 @@ cb(null, utils.normalizeResults(docs, self.schema));

@@ -100,2 +100,6 @@

ssl: this.config.ssl,
sslValidate: this.config.sslValidate,
sslCA: this.config.sslCA,
sslCert: this.config.sslCert,
sslKey: this.config.sslKey,
poolSize: this.config.poolSize,

@@ -102,0 +106,0 @@ socketOptions: this.config.socketOptions,

@@ -32,2 +32,10 @@

// Retrieve select fields from criteria
if (options && typeof options === 'object' && options.select) {
this.select = this.parseSelect(options.select);
delete options.select;
} else {
this.select = {};
}
// Normalize Criteria

@@ -390,1 +398,17 @@ this.criteria = this.normalizeCriteria(options);

};
/**
*
* Parse Select
*
* @param original
* @returns {*}
*/
Query.prototype.parseSelect = function parseSelect(original) {
var select = {};
_.each(original, function (field) {
select[field] = 1;
});
return select;
};

@@ -164,1 +164,43 @@

};
/**
* Return a WLValidationError if the provided error was
* caused by a unique constraint violation; otherwise,
* return the existing error
*
* @param {Error} err
* @return {Error}
* @api public
*/
exports.clarifyError = function clarifyError(err) {
// MongoDB duplicate key error code
if(err.code !== 11000) {
return err;
}
// Example errmsg: `E11000 duplicate key error index: db_name.model_name.$attribute_name_1 dup key: { : "value" }`
var matches = /^E11000 duplicate key error index: .*?\..*?\.\$(.*?)_\d+ dup key: { : (.*) }$/.exec(err.errmsg);
var fieldName = matches[1]; // name of index (without _[digits] at the end)
var value;
try {
value = JSON.parse(matches[2]); // attempt to convert the value to a primitive representation
} catch (x) {
value = matches[2]; // for non-serializable objects (e.g. ObjectId representations), return as-is
}
var validationError = {
code: 'E_UNIQUE',
invalidAttributes: {},
originalError: err
};
validationError.invalidAttributes[fieldName] = [
{
rule: 'unique',
value: value
}
];
return validationError;
};
{
"name": "sails-mongo",
"version": "0.11.2",
"version": "0.11.3",
"description": "Mongo DB adapter for Sails.js",

@@ -44,6 +44,6 @@ "main": "./lib/adapter.js",

"dependencies": {
"async": "~0.8.0",
"lodash": "~2.4.1",
"mongodb": "^2.0.27",
"waterline-cursor": "~0.0.5",
"async": "~1.4.2",
"lodash": "~3.10.0",
"mongodb": "^2.0.42",
"waterline-cursor": "~0.0.6",
"waterline-errors": "~0.10.0"

@@ -50,0 +50,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc