Socket
Book a DemoInstallSign in
Socket

entity-promises

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

entity-promises

Promise functions for working with model entities

latest
Source
npmnpm
Version
0.0.4
Version published
Maintainers
1
Created
Source

Entity Promises

Promise functions for working with entity models.

Functions

  • createIntroducer: Produce a function that augments objects with an id. Invoke with an id generator function. e.g. createIntroducer(intSeq) .
  • introduce: Pre-built introducer with an internal random id generator
  • createCleaner: produce a function that removes persistence artifacts. Invoke with a list of hash keys to remove.
  • moclean: Pre-built cleaner that removes mongodb persistence ids. e.g. createCleaner("_id") .

Both introducers and cleaners each operate on a single instance or an array of instances.

Example:

var entityp     = require("entity-promises"),
    u           = require("underscore"),
    q           = require("q"),
    model       = require("./model")
    mongocoll   = require("mongodb-q").connect().collection("trains");

/* create and persist entity instance from specification.  Return a promise of
 * the persisted instance data. 
 */
exports.create = function (spec) {

    return q(spec)
        .then(model.train)
        .then(entityp.introduce)
        .then(mongocoll.insert)
        .then(u.first)
        .then(entityp.moclean);

};


/* get a list of entities. Return a promise of the fetched instance data.
 */
exports.list = function () {
    return mongocoll.find()
        .then(entityp.moclean);          // an array of instances
};

Keywords

q

FAQs

Package last updated on 31 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts