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

waterline

Package Overview
Dependencies
Maintainers
2
Versions
165
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

waterline - npm Package Compare versions

Comparing version 0.9.8 to 0.9.9

79

lib/waterline/query/composite.js

@@ -48,75 +48,20 @@ /**

// Set Default Values if available
for(var key in this.attributes) {
if(values[key] === undefined && this.attributes[key].hasOwnProperty('defaultsTo')) {
values[key] = _.clone(this.attributes[key].defaultsTo);
}
}
// Cast values to proper types (handle numbers as strings)
values = this._cast.run(values);
// Try a find first.
this.find(criteria).exec(function(err, results) {
if (err) return cb(err);
async.series([
if (results.length !== 0) {
// Run Validation with Validation LifeCycle Callbacks
function(cb) {
self.validate(values, function(err) {
if(err) return cb(err);
cb();
})
},
// Unserialize values
results = self._transformer.unserialize(results[0]);
// Before Create Lifecycle Callback
function(cb) {
var runner = function(item, callback) {
item(values, function(err) {
if(err) return callback(err);
callback();
});
};
async.eachSeries(self._callbacks.beforeCreate, runner, function(err) {
if(err) return cb(err);
cb();
});
// Return an instance of Model
var model = new self._model(results);
return cb(null, model);
}
], function(err) {
if(err) return cb(err);
// Automatically add updatedAt and createdAt (if enabled)
if(self.autoCreatedAt) values.createdAt = new Date();
if(self.autoUpdatedAt) values.updatedAt = new Date();
// Transform Values
values = self._transformer.serialize(values);
// Clean attributes
values = self._schema.cleanValues(values);
// Transform Search Criteria
criteria = self._transformer.serialize(criteria);
// Build model(s) from result set
self._adapter.findOrCreate(criteria, values, function(err, values) {
if(err) return cb(err);
// Unserialize values
values = self._transformer.unserialize(values);
var runner = function(item, callback) {
item(values, function(err) {
if(err) return callback(err);
callback();
});
};
// Run afterCreate Lifecycle Callbacks
async.eachSeries(self._callbacks.afterCreate, runner, function(err) {
if(err) return cb(err);
/// Return an instance of Model
var model = new self._model(values);
cb(null, model);
});
// Create a new record if nothing is found.
self.create(values).exec(function(err, result) {
return cb(null, result);
});

@@ -123,0 +68,0 @@ });

2

package.json
{
"name": "waterline",
"description": "An ORM for Node.js and the Sails framework",
"version": "0.9.8",
"version": "0.9.9",
"contributors": [

@@ -6,0 +6,0 @@ {

@@ -7,6 +7,7 @@ var Collection = require('../../../lib/waterline/collection'),

describe('basic function', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -24,13 +25,3 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
done();
});

@@ -44,9 +35,50 @@

it('should run afterCreate and mutate values', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run afterCreate and mutate values on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
});
});
});
describe('with a record', function() {
before(function(done) {
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run afterCreate and mutate values on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});

@@ -61,6 +93,7 @@ });

describe('array of functions', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -87,24 +120,57 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
done();
});
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run the functions in order on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
});
});
});
it('should run the functions in order', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
describe('with a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run any of the functions on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});
});

@@ -7,6 +7,7 @@ var Collection = require('../../../lib/waterline/collection'),

describe('basic function', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -24,13 +25,3 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
done();
});

@@ -44,9 +35,52 @@

it('should run afterValidation and mutate values', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run afterValidation and mutate values on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
});
});
});
describe('with a record', function() {
before(function(done) {
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run afterValidation and mutate values on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});

@@ -61,6 +95,7 @@ });

describe('array of functions', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -87,24 +122,57 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
done();
});
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run the functions in order on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
});
});
});
it('should run the functions in order', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run any of the functions on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});
});

@@ -7,6 +7,7 @@ var Collection = require('../../../lib/waterline/collection'),

describe('basic function', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -24,13 +25,3 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
done();
});

@@ -44,10 +35,53 @@

it('should run beforeCreate and mutate values', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run beforeCreate and mutate values on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
});
});
});
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run beforeCreate and mutate values on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});
});

@@ -61,6 +95,7 @@

describe('array of functions', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -87,21 +122,53 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
done();
});
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run the functions in order on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
});
});
});
it('should run the functions in order', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should now run any of the functions on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});

@@ -108,0 +175,0 @@ });

@@ -7,6 +7,7 @@ var Collection = require('../../../lib/waterline/collection'),

describe('basic function', function() {
var person;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -24,13 +25,3 @@ adapter: 'foo',

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
done();
});

@@ -44,9 +35,52 @@

it('should run beforeValidation and mutate values', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run beforeValidation and mutate values on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test updated');
done();
});
});
});
describe('with a record', function() {
before(function(done) {
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run beforeValidation and mutate values on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});

@@ -61,6 +95,7 @@ });

describe('array of functions', function() {
var person, status;
var person,
Model;
before(function(done) {
var Model = Collection.extend({
Model = Collection.extend({
identity: 'user',

@@ -79,3 +114,3 @@ adapter: 'foo',

// Function 2
// Function 1
function(values, cb) {

@@ -88,24 +123,57 @@ values.name = values.name + ' fn2';

// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
create: function(col, values, cb) { return cb(null, values); }
};
done();
});
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should run the functions in order on create', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
});
});
});
it('should run the functions in order', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test fn1 fn2');
done();
describe('without a record', function() {
before(function(done) {
// Fixture Adapter Def
var adapterDef = {
find: function(col, criteria, cb) { return cb(null, [criteria.where]); },
create: function(col, values, cb) { return cb(null, values); }
};
new Model({ adapters: { foo: adapterDef }}, function(err, coll) {
if(err) done(err);
person = coll;
done();
});
});
it('should not run any of the functions on find', function(done) {
person.findOrCreate({ name: 'test' }, { name: 'test' }, function(err, user) {
assert(!err);
assert(user.name === 'test');
done();
});
});
});
});
});

@@ -28,3 +28,3 @@ var Collection = require('../../../lib/waterline/collection'),

var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }

@@ -106,3 +106,3 @@ };

var adapterDef = {
find: function(col, criteria, cb) { return cb(null, null); },
find: function(col, criteria, cb) { return cb(null, []); },
create: function(col, values, cb) { return cb(null, values); }

@@ -109,0 +109,0 @@ };

@@ -33,3 +33,3 @@ var Collection = require('../../../lib/waterline/collection'),

assert(criteria.where.login);
return cb(null, null);
return cb(null, []);
},

@@ -54,3 +54,3 @@ create: function(col, values, cb) {

assert(criteria.where.login);
return cb(null, null);
return cb(null, []);
},

@@ -75,3 +75,3 @@ create: function(col, values, cb) {

assert(criteria.where.login);
return cb(null, null);
return cb(null, []);
},

@@ -78,0 +78,0 @@ create: function(col, values, cb) {

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