Socket
Socket
Sign inDemoInstall

iridium

Package Overview
Dependencies
Maintainers
1
Versions
157
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iridium - npm Package Compare versions

Comparing version 2.7.0 to 2.7.1

lib/caches/NoOpCache.js

4

benchmarks/mongodb.js

@@ -64,3 +64,3 @@ var async = require('async'),

var start = new Date();
model.insert(objects, false, function(err, inserted) {
model.insert(objects, { wrap: false }, function(err, inserted) {
if(err) return done(err);

@@ -83,3 +83,3 @@ printTime(' => %s', start);

var start = new Date();
model.find({}, false, function(err, results) {
model.find({}, { wrap: false }, function(err, results) {
if(err) return done(err);

@@ -86,0 +86,0 @@ printTime(' => %s', start);

@@ -145,3 +145,3 @@ /// <reference path="../nodelib/node.js"/>

if(err) return onError(err);
this.__state.model.onRetrieved(latest, callback || function() { }, (function(value) {

@@ -164,3 +164,5 @@ this.__state.model.fromSource(value);

var conditions = this.__state.model.uniqueConditions(this.__state.modified);
this.__state.model.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);
this.__state.model.cache.drop(conditions, function() {
this.__state.model.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);
});
};

@@ -167,0 +169,0 @@

@@ -13,2 +13,3 @@ /// <reference path="../nodelib/node.js"/>

var ObjectID = require('mongodb').ObjectID;
var NoOpCache = require('./caches/NoOpCache');

@@ -80,3 +81,8 @@

Object.defineProperty(this, 'cache', {
value: options.cache || new NoOpCache(),
enumerable: false
})
var extraValidators = [];

@@ -172,3 +178,3 @@ for(var i = 0; i < database.plugins.length; i++) {

Model.prototype.onRetrieved = function(results, callback, wrapper) {
Model.prototype.onRetrieved = function(results, callback, wrapper, options) {
///<signature>

@@ -196,6 +202,20 @@ ///<summary>Handles any post-receive hooks and the wrapping of objects from the database</summary>

///</signature>
///<signature>
///<summary>Handles any post-receive hooks and the wrapping of objects from the database</summary>
///<param name="results" type="Array" elementType="Object">The objects retrieved from the database</param>
///<param name="callback" type="Function">The function to be called once the objects have been wrapped</param>
///<param name="wrapper" type="Function">A function which converts the retrieved objects prior to submission</param>
///<param name="options" type="Object">A set of options determining how to handle the retrieved object</param>
///</signature>
var $ = this;
wrapper = (wrapper !== true && wrapper) || this.wrap.bind(this);
wrapper = wrapper || this.wrap.bind(this);
options = options || {};
_.defaults(options, {
wrap: true,
cache: true
});
var returnArray = Array.isArray(results);

@@ -223,8 +243,15 @@ if(!returnArray) results = [results];

var wrapped = wrapper(target);
var cacheDoc = _.cloneDeep(target);
doHook(this.options.hooks.ready, wrapped, function(err) {
var wrapped = options.wrap ? wrapper(target) : target;
doHook(this.options.hooks.ready, wrapped, (function(err) {
if(err) return done(err);
return done(null, wrapped);
});
if(options.cache)
return this.cache.store(cacheDoc, function() {
return done(null, wrapped);
});
else
return done(null, wrapped);
}).bind(this));
}).bind(this));

@@ -277,8 +304,6 @@ }).bind(this);

var $ = this;
doHook($.options.hooks.saving, instance, [changes], callback);
doHook(this.options.hooks.saving, instance, [changes], callback);
};
Model.prototype.find = function (conditions, wrap, callback) {
Model.prototype.find = function (conditions, options, callback) {
/// <signature>

@@ -300,3 +325,3 @@ /// <summary>Gets all objects in the collection.</summary>

/// <summary>Gets all objects in the collection.</summary>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -307,3 +332,3 @@ /// </signature>

/// <param name="conditions" type="Mixed">The _id field of the object to locate</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -314,3 +339,3 @@ /// </signature>

/// <param name="conditions" type="Object">The conditions which will be used to select matches</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -321,4 +346,4 @@ /// </signature>

conditions = {};
wrap = true;
conditions = null;
options = null;

@@ -328,8 +353,14 @@ for(var i = 0; i < args.length; i++) {

callback = args[i];
else if('boolean' == typeof args[i])
wrap = args[i];
else
else if(!conditions)
conditions = args[i];
else options = args[i];
}
conditions = conditions || {};
options = options || {};
_.defaults(options, {
wrap: true,
cache: true
});
var $ = this;

@@ -342,7 +373,7 @@ if (!_.isPlainObject(conditions)) conditions = this.downstreamID(conditions);

if (!results) return callback(null, null);
return $.onRetrieved(results, callback, wrap || function(value) { return value; });
return $.onRetrieved(results, callback, options.wrap || function(value) { return value; });
});
};
Model.prototype.findOne = Model.prototype.get = function (conditions, wrap, callback) {
Model.prototype.findOne = Model.prototype.get = function (conditions, options, callback) {
/// <signature>

@@ -364,3 +395,3 @@ /// <summary>Gets a single object from the collection.</summary>

/// <summary>Gets a single object from the collection.</summary>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -371,3 +402,3 @@ /// </signature>

/// <param name="conditions" type="Mixed">The _id field of the object to locate</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -378,3 +409,3 @@ /// </signature>

/// <param name="conditions" type="Object">The conditions which will be used to select matches</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called with the results once they have been retrieved.</param>

@@ -385,4 +416,4 @@ /// </signature>

conditions = {};
wrap = true;
conditions = null;
options = null;

@@ -392,23 +423,38 @@ for(var i = 0; i < args.length; i++) {

callback = args[i];
else if('boolean' == typeof args[i])
wrap = args[i];
else
else if(!conditions)
conditions = args[i];
else options = args[i];
}
conditions = conditions || {};
options = options || {};
_.defaults(options, {
wrap: true,
cache: true
});
var $ = this;
if (!_.isPlainObject(conditions)) conditions = this.downstreamID(conditions);
this.toSource(conditions);
this.toSource(conditions);
this.collection.findOne(conditions, function (err, results) {
if (err) return callback(err);
if (!results) return callback(null, null);
return $.onRetrieved(results, callback, wrap || function(value) { return value; });
});
var fromDB = (function() {
this.collection.findOne(conditions, (function (err, results) {
if (err) return callback(err);
if (!results) return callback(null, null);
return this.onRetrieved(results, callback, null, { wrap: options.wrap, cache: options.cache });
}).bind(this));
}).bind(this);
if(options.cache && this.cache && this.cache.valid(conditions))
this.cache.fetch(conditions, (function(err, doc) {
if(!err && doc)
return this.onRetrieved(doc, callback, null, { wrap: options.wrap, cache: false });
else
return fromDB();
}).bind(this));
else
return fromDB();
};
Model.prototype.insert = Model.prototype.create = function (object, wrap, callback) {
Model.prototype.insert = Model.prototype.create = function (object, options, callback) {
/// <signature>

@@ -434,3 +480,3 @@ /// <summary>Inserts the given object into the database</summary>

/// <param name="object" type="Object">The properties to set on the newly created object</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called once the object has been created</param>

@@ -441,3 +487,3 @@ /// </signature>

/// <param name="object" type="Array" elementType="Object">An array of objects representing the properties to set on the newly created objects</param>
/// <param name="wrap" type="Boolean">Whether or not to wrap results in an Instance object</param>
/// <param name="options" type="Object">Options dictating how Iridium handles this request</param>
/// <param name="callback" type="Function">A function to be called once the objects have been created</param>

@@ -451,6 +497,10 @@ /// </signature>

if(!callback) {
callback = wrap;
wrap = true;
callback = options;
options = options || {};
}
_.defaults(options, {
wrap: true
});
if(!Array.isArray(object)) {

@@ -477,3 +527,3 @@ object = [object];

if(callback)
return $.onRetrieved(inserted, end, wrap || function(value) { return value; });
return $.onRetrieved(inserted, end, null, options);
return end();

@@ -566,3 +616,8 @@ });

this.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);
if(this.cache && this.cache.valid(conditions))
this.cache.drop(conditions, function() {
this.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);
});
else
this.collection.remove(conditions, { w: callback ? 1 : 0 }, callback);
};

@@ -569,0 +624,0 @@

{
"name": "iridium",
"version": "2.7.0",
"version": "2.7.1",
"author": "Benjamin Pannell <admin@sierrasoftworks.com>",

@@ -28,7 +28,5 @@ "description": "A custom lightweight ORM for MongoDB designed for power-users",

"devDependencies": {
"async": "*",
"mocha": "*",
"should": "*",
"gitlablist-mocha": "*"
"should": "*"
}
}

@@ -23,2 +23,4 @@ # Iridium [![Build Status](https://travis-ci.org/SierraSoftworks/Iridium.png?branch=master)](https://travis-ci.org/SierraSoftworks/Iridium) [![](https://badge.fury.io/js/iridium.png)](https://npmjs.org/package/iridium)

Iridium's models are designed to exist as individual files or modules within your application, this helps simplify management of your models and separates database design code from your application code. In addition to this, Iridium supports virtual properties, extension methods, transforms, client side property renaming and validations in an easy to understand and implement package.
- **Caching Support**
High performance web applications depend on accessing your data as quickly as possible, Iridium provides support for automated inline caching through any key-value store, allowing you to ensure that you can build the fastest application possible.
- **Plugin Framework**

@@ -253,2 +255,37 @@ Iridium allows the creation and use of plugins which can extend models and reduce duplicated code across models for common behavioural use cases. Plugins can provide custom validation, manipulate models at creation time and have the opportunity to extend instances when they are created.

## Caching Framework
Our caching framework allows basic queries to be served against a high performance cache, offloading requests from your database server and allowing you to more easily develop high performance applications that scale well to user demand.
Your cache will **only** be tried for `Model.get` and `Model.findOne` requests for which the cache's `valid()` function returns true, allowing you to implement any basic cache structure you wish - including compound caches should you wish.
By default Iridium doesn't cache anything, implementing a no-op cache, but you can easily configure your own caching plugin on a per-model basis by following this example.
```javascript
function MemoryCache() {
this.cache = {};
}
// Tells Iridium whether it can use the cache for objects that match these conditions
MemoryCache.prototype.valid = function(conditions) {
return conditions && conditions._id;
};
MemoryCache.prototype.store = function(document, callback) {
var id = JSON.stringify(document._id);
this.cache[id] = document;
callback();
};
MemoryCache.prototype.fetch = function(id, callback) {
var id = JSON.stringify(conditions._id);
callback(this.cache[id]);
};
MemoryCache.prototype.drop = function(conditions, callback) {
var id = JSON.stringify(conditions._id);
if(this.cache[id]) delete this.cache[id];
callback();
};
```
## Preprocessing Framework

@@ -255,0 +292,0 @@ The preprocessing framework allows Iridium to convert values from a form better suited to your database into a form more suitable for your application in an entirely transparent manner. This is acomplished through the use of a number of preprocessors which run when retrieving an object from the database, their order is reversed when pushing an object to the database.

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