Socket
Socket
Sign inDemoInstall

camo

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

camo - npm Package Compare versions

Comparing version 0.12.0 to 0.12.1

11

CHANGELOG.md

@@ -0,1 +1,12 @@

## 0.12.1 (2016-03-02)
Features:
- Updated README to warn about frequently changing API
- Added Contributing and Contact sections to README
Bugfixes:
- Fixed issue that prevented `save()` from being aborted when `Promise.reject` was returned in a hook ([#57](https://github.com/scottwrobinson/camo/issues/57))
- Replaced all `.id` references to `._id` in README
- Fixed issue where schema types `Array` and `[]` were not properly being validated ([#53](https://github.com/scottwrobinson/camo/issues/53))
- In README, changed an incorrect reference of `.findMany()` to `.find()` ([#54](https://github.com/scottwrobinson/camo/issues/54))
- Fixed issue where updated nested data wasn't returned when using `.findOneAndUpdate()` with NeDB ([#55](https://github.com/scottwrobinson/camo/issues/55))
## 0.12.0 (2016-02-24)

@@ -2,0 +13,0 @@ Features:

6

lib/base-document.js

@@ -161,4 +161,6 @@ "use strict";

var valueName = null;
if (Array.isArray(that._schema[key].type)) {
if (Array.isArray(that._schema[key].type) && that._schema[key].type.length > 0) {
typeName = '[' + that._schema[key].type[0].name + ']';
} else if (Array.isArray(that._schema[key].type) && that._schema[key].type.length === 0) {
typeName = '[]';
} else {

@@ -542,3 +544,3 @@ typeName = that._schema[key].type.name;

hookPromises = hookPromises.concat(_.invoke(embeddeds, hookName));
hookPromises.push(_.invoke([this], hookName));
hookPromises.push(this[hookName]());
return hookPromises;

@@ -545,0 +547,0 @@ }

@@ -155,4 +155,8 @@ "use strict";

if (error) return reject(error);
result = _.assign(data, values);
return resolve(result);
// Fixes issue #55. Remove when NeDB is updated to v1.8+
db.findOne({_id: data._id}, function(error, doc) {
if (error) return reject(error);
resolve(doc);
});
});

@@ -159,0 +163,0 @@ }

@@ -103,3 +103,3 @@ var _ = require('lodash');

if (isArray(type) && type.length === 1 && isArray(value)) {
var arrayType = type[0];
var arrayType = type[0];
for (var i = 0; i < value.length; i++) {

@@ -111,2 +111,6 @@ var v = value[i];

}
} else if (isArray(type) && type.length === 0 && !isArray(value)) {
return false;
} else if (type === Array && !isArray(value)) {
return false;
}

@@ -113,0 +117,0 @@

{
"name": "camo",
"version": "0.12.0",
"version": "0.12.1",
"description": "A class-based ES6 ODM for Mongo-like databases.",

@@ -5,0 +5,0 @@ "author": {

@@ -18,5 +18,7 @@ # Camo

* <a href="#transpiler-support">Transpiler Support</a>
* <a href="#contributing">Contributing</a>
* <a href="#contact">Contact</a>
* <a href="#copyright-license">Copyright & License</a>
**Note**: Please see the [CHANGELOG](https://github.com/scottwrobinson/camo/blob/master/CHANGELOG.md) for the latest API changes and bug fixes.
**Note**: Since Camo is still pre-1.0, the API will likely change often. Please see the [CHANGELOG](https://github.com/scottwrobinson/camo/blob/master/CHANGELOG.md) for the latest API changes and bug fixes.

@@ -246,7 +248,7 @@ ## Why do we need another ODM?

lassie.save().then(function(l) {
console.log(l.id);
console.log(l._id);
});
```
Once a document is saved, it will automatically be assigned a unique identifier by the backend database. This ID can be accessed by either `.id` or `._id`.
Once a document is saved, it will automatically be assigned a unique identifier by the backend database. This ID can be accessed by the `._id` property.

@@ -267,3 +269,3 @@ If you specified a default value (or function) for a schema variable, that value will be assigned on creation of the object.

The `.findOne()` method will return the first document found, even if multiple documents match the query. `.findMany()` will return all documents matching the query. Each should be called as static methods on the document type you want to load.
The `.findOne()` method will return the first document found, even if multiple documents match the query. `.find()` will return all documents matching the query. Each should be called as static methods on the document type you want to load.

@@ -273,3 +275,3 @@ ```javascript

console.log('Got Lassie!');
console.log('Her unique ID is', l.id);
console.log('Her unique ID is', l._id);
});

@@ -382,2 +384,28 @@ ```

## Contributing
Feel free to open new issues or submit pull requests for Camo. If you'd like to contact me before doing so, feel free to get in touch (see Contact section below).
Before opening an issue or submitting a PR, I ask that you follow these guidelines:
**Issues**
- Please state whether your issue is a question, feature request, or bug report.
- Always try the latest version of Camo before opening an issue.
- If the issue is a bug, be sure to clearly state your problem, what you expected to happen, and what all you have tried to resolve it.
- Always try to post simplified code that shows the problem. Use Gists for longer examples.
**Pull Requests**
- If your PR is a new feature, please consult with me first.
- Any PR should contain only one feature or bug fix. If you have more than one, please submit them as separate PRs.
- Always try to include relevant tests with your PRs. If you aren't sure where a test should go or how to create one, feel free to ask.
- Include updates to the README when needed.
- Do not update the package version or CHANGELOG. I'll handle that for each release.
## Contact
You can contact me with questions, issues, or ideas at either of the following:
- Email: [s.w.robinson+camo@gmail.com](mailto:s.w.robinson+camo@gmail.com)
- Twitter: [@ScottWRobinson](https://twitter.com/ScottWRobinson)
For short questions and faster responses, try Twitter.
## Copyright & License

@@ -384,0 +412,0 @@ Copyright (c) 2016 Scott Robinson

@@ -6,2 +6,4 @@ "use strict";

var Document = require('../index').Document;
var EmbeddedDocument = require('../index').EmbeddedDocument;
var ValidationError = require('../lib/errors').ValidationError;
var validateId = require('./util').validateId;

@@ -230,2 +232,144 @@

});
describe('#53', function() {
/*
* Camo should validate that all properties conform to
* the type they were given in the schema. However,
* array types are not properly validated due to not
* properly checking for 'type === Array' and
* 'type === []' in validator code.
*/
it('should validate Array types properly', function(done) {
class Foo extends Document {
constructor() {
super();
this.bar = Array;
}
}
var foo = Foo.create({bar: [1, 2, 3]});
foo.save().then(function(f) {
expect(f.bar).to.have.length(3);
expect(f.bar).to.include(1);
expect(f.bar).to.include(2);
expect(f.bar).to.include(3);
foo.bar = 1;
return foo.save();
}).then(function(f){
expect.fail(null, Error, 'Expected error, but got none.');
}).catch(function(error) {
expect(error).to.be.instanceof(ValidationError);
}).then(done, done);
});
it('should validate [] types properly', function(done) {
class Foo extends Document {
constructor() {
super();
this.bar = [];
}
}
var foo = Foo.create({bar: [1, 2, 3]});
foo.save().then(function(f) {
expect(f.bar).to.have.length(3);
expect(f.bar).to.include(1);
expect(f.bar).to.include(2);
expect(f.bar).to.include(3);
foo.bar = 2;
return foo.save();
}).then(function(f){
expect.fail(null, Error, 'Expected error, but got none.');
}).catch(function(error) {
expect(error).to.be.instanceof(ValidationError);
}).then(done, done);
});
});
describe('#55', function() {
it('should return updated data on findOneAndUpdate when updating nested data', function(done) {
/*
* When updating nested data with findOneAndUpdate,
* the document returned to you should contain
* all of the updated data. But due to lack of
* support in NeDB versions < 1.8, I had to use
* a hack (_.assign) to update the document. This
* doesn't properly update nested data.
*
* Temporary fix is to just reload the document
* with findOne.
*/
class Contact extends EmbeddedDocument {
constructor() {
super();
this.email = String;
this.phone = String;
}
}
class Person extends Document {
constructor() {
super();
this.name = String;
this.contact = Contact;
}
}
var person = Person.create({
name: 'John Doe',
contact: {
email: 'john@doe.info',
phone: 'NA'
}
});
person.save().then(function(person) {
return Person.findOneAndUpdate({_id: person._id}, {name: 'John Derp', 'contact.phone': '0123456789'});
}).then(function(person) {
expect(person.name).to.be.equal('John Derp');
expect(person.contact.email).to.be.equal('john@doe.info');
expect(person.contact.phone).to.be.equal('0123456789');
}).then(done, done);
});
});
describe('#57', function() {
it('should not save due to Promise.reject in hook', function(done) {
/*
* Rejecting a Promise inside of a pre-save hook should
* cause the save to be aborted, and the .caught() method
* should be invoked on the Promise chain. This wasn't
* happening due to how the hooks were being collected
* and executed.
*/
class Foo extends Document {
constructor() {
super();
this.bar = String;
}
preValidate() {
return Promise.reject('DO NOT SAVE');
}
}
Foo.create({bar: 'bar'}).save().then(function(foo) {
expect.fail(null, Error, 'Expected error, but got none.');
}).catch(function(error) {
expect(error).to.be.equal('DO NOT SAVE');
}).then(done, done);
});
});
});
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