Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-entity

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-entity - npm Package Compare versions

Comparing version 0.2.12 to 0.2.13

test/unit/adaptor-crud-events.test.js

39

lib/entity-crud.js

@@ -46,2 +46,7 @@ /*jshint unused:false */

this.method('count', this._count.bind(this));
// Add event emissions
this.create.last(this.emit.bind(this, 'create'));
this.update.last(this.emit.bind(this, 'update'));
this.delete.last(this._deleteEmit.bind(this));
});

@@ -96,6 +101,5 @@

* @param {Object} itemData The data to use for creating.
* @param {Function(Error=, Object=)} done callback.
* @protected
*/
EntityCrud.prototype._create = function(itemData, done) {
EntityCrud.prototype._create = function(itemData) {
throw new Error('Not Implemented');

@@ -108,6 +112,5 @@ };

* @param {string|Object} id the item id or an Object to query against.
* @param {Function(Error=, Object=)} done callback.
* @protected
*/
EntityCrud.prototype._readOne = function(id, done) {
EntityCrud.prototype._readOne = function(id) {
throw new Error('Not Implemented');

@@ -121,6 +124,5 @@ };

* @param {Object|string=} optQuery Optionally define a query to limit results.
* @param {Function(Error=, Object=)} done callback.
* @protected
*/
EntityCrud.prototype._read = function(optQuery, done) {
EntityCrud.prototype._read = function(optQuery) {
throw new Error('Not Implemented');

@@ -135,6 +137,5 @@ };

* @param {number} limit how many records to fetch.
* @param {Function(Error=, Array.<Object>=)} done callback.
* @protected
*/
EntityCrud.prototype._readLimit = function(query, skip, limit, done) {
EntityCrud.prototype._readLimit = function(query, skip, limit) {
throw new Error('Not Implemented');

@@ -147,6 +148,5 @@ };

* @param {?Object} query Narrow down the set, set to null for all.
* @param {Function(Error=, number=)} done callback.
* @protected
*/
EntityCrud.prototype._count = function(query, done) {
EntityCrud.prototype._count = function(query) {
throw new Error('Not Implemented');

@@ -160,6 +160,5 @@ };

* @param {Object} itemData The data to use for creating.
* @param {Function(Error=, Object=)} done callback.
* @protected
*/
EntityCrud.prototype._update = function(id, itemData, done) {
EntityCrud.prototype._update = function(id, itemData) {
throw new Error('Not Implemented');

@@ -171,9 +170,19 @@ };

*
* @param {string} id the item id.
* @param {Function(Error=, Object=)} done callback.
* @param {string|Object} maybeQuery Query or the item id.
* @protected
*/
EntityCrud.prototype._delete = function(id, done) {
EntityCrud.prototype._delete = function(maybeQuery) {
throw new Error('Not Implemented');
};
/**
* The Delete event emission requires special care so it can guarantee that
* the record ID is properly propagated.
*
* @param {string|Object} maybeQuery Query or the item id.
* @private
*/
EntityCrud.prototype._deleteEmit = function(maybeQuery) {
var query = this._getQuery(maybeQuery);
this.emit('delete', maybeQuery, query[this._idName]);
};
{
"name": "node-entity",
"description": "The MVCe implementation for Node.js",
"version": "0.2.12",
"version": "0.2.13",
"homepage": "https://github.com/thanpolas/entity",

@@ -35,17 +35,17 @@ "author": {

"lodash": "~2.4.1",
"middlewarify": "~0.3.3",
"mschema": "~0.5.2",
"bluebird": "~1.0.5",
"middlewarify": "^0.3.8",
"mschema": "^0.5.3",
"bluebird": "~2.2.2",
"grunt-release": "~0.7.0",
"cip": "~0.2.1"
"cip": "^0.2.5"
},
"devDependencies": {
"sinon": "~1.8.2",
"mongoose": "~3.8.7",
"mocha": "~1.17.1",
"chai": "~1.9.0",
"pg": "~2.11.1",
"grunt": "~0.4.2",
"grunt-services": "0.0.1",
"sequelize": "~2.0.0-dev6"
"sinon": "~1.10.3",
"mongoose": "~3.8.13",
"mocha": "~1.21.0",
"chai": "~1.9.1",
"pg": "~3.4.0",
"grunt": "~0.4.5",
"grunt-services": "0.0.2",
"sequelize": "~1.7.9"
},

@@ -52,0 +52,0 @@ "peerDependencies": {},

@@ -79,3 +79,3 @@ # Entity

All primitive methods offer Before/After hooks and return a Promise to determine resolution.
All primitive methods offer Before/After/Last hooks and return a Promise to determine resolution.

@@ -234,5 +234,5 @@ #### entity.create(data)

### Before / After Hooks
### Before / After / Last Hooks
Every CRUD operation offers Before/After hooks courtesy of [Middlewarify][]. Each middleware will receive the same exact arguments. To pass control to the next middleware you need to return a promise that conforms to the [Promises/A+ spec](http://promises-aplus.github.io/promises-spec/).
Every CRUD operation offers Before/After/Last hooks courtesy of [Middlewarify][]. Each middleware will receive the same exact arguments. To pass control to the next middleware you need to return a promise that conforms to the [Promises/A+ spec](http://promises-aplus.github.io/promises-spec/).

@@ -382,2 +382,35 @@

### CRUD Events
The base entity class inherits from Node's [standard EventEmitter][EventEmitter]. The CRUD interface provides 3 convenient events that get triggered after each corresponding operation and all its' middleware have finished invocation.
* `create` Triggers after a create OP finished, arguments:
- **data** `Object` The data provided by the user to create the record.
- **result** `Object` The result as provided by the underlying ORM.
* `update` Triggers after an update OP finished, arguments:
- **query** `Object|string` The query used to define which record to update.
* `delete` Triggers after a delete OP finished, arguments:
- **query** `Object|string` The query used to define which record to delete.
- **id** `string` An attempt to provide the ID of the deleted record.
Example:
```javascript
var EntitySequelize = require('entity').Sequelize;
var UserModel = require('../models/user.model');
var UserEntity = module.exports = Entity.Sequelize.extend(function(){
// pass the Sequelize User Model
this.setModel(UserModel.Model);
});
/* ... */
var userEntity = UserEntity.getInstance();
userEntity.on('create', function(data, result) {/* ... */});
userEntity.on('update', function(query) {/* ... */});
userEntity.on('delete', function(query, id) {/* ... */});
```
## Entity Schema

@@ -479,4 +512,6 @@

- **v0.2.13**, *24 Jul 2014*
- Added events on CRUD ops.
- **v0.2.12**, *23 Jul 2014*
- Count operation fix for mongoose adp
- Count operation fix for mongoose adp.
- **v0.2.11**, *07 Jul 2014*

@@ -529,1 +564,3 @@ - Fix mongoose adp query building sequence.

[mschema]: https://github.com/mschema/mschema/
[EventEmitter]: http://nodejs.org/api/events.html#events_class_events_eventemitter

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

var testAdaptorSchema = require('./adaptor-crud-schema.test');
var testAdaptorEvents = require('./adaptor-crud-events.test');

@@ -77,2 +78,3 @@ var core = module.exports = {};

testAdaptorSchema(adaptor, adaptor.majNum);
testAdaptorEvents(adaptor);
});

@@ -79,0 +81,0 @@ });

@@ -34,3 +34,3 @@ /**

ent.update(id, {name: newVal}).then(function(obj) {
if (adaptor.name !== 'Sequelize') {
if (adaptor.name === 'Mongoose') {
assert.equal(obj.name, newVal, 'Name should have been updated on returned object');

@@ -37,0 +37,0 @@ }

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