Comparing version 2.2.1 to 3.0.0
@@ -20,3 +20,4 @@ // Load modules | ||
Hoek.assert(engine, 'Missing catbox client engine'); | ||
Hoek.assert(typeof engine !== 'object' || !options, 'Cannot specify options with object instance engine config'); | ||
Hoek.assert(typeof engine === 'object' || typeof engine === 'function', 'engine must be an engine object or engine prototype (function)'); | ||
Hoek.assert(typeof engine === 'function' || !options, 'Can only specify options with function engine config'); | ||
@@ -26,13 +27,3 @@ var settings = Hoek.applyToDefaults(internals.defaults, options || {}); | ||
if (typeof engine === 'string') { | ||
var Connection = require(engine); | ||
this.connection = new Connection(settings); | ||
} | ||
else if (typeof engine === 'object') { | ||
this.connection = engine; | ||
} | ||
else { | ||
Hoek.assert(typeof engine === 'function', 'Invalid engine configuration'); | ||
this.connection = new engine(settings); | ||
} | ||
this.connection = (typeof engine === 'object' ? engine : new engine(settings)); | ||
}; | ||
@@ -130,6 +121,2 @@ | ||
if (ttl > 2147483647) { // Math.pow(2, 31) | ||
return callback(new Error('Invalid ttl (greater than 2147483647)')); | ||
} | ||
if (ttl <= 0) { | ||
@@ -136,0 +123,0 @@ // Not cachable (or bad rules) |
{ | ||
"name": "catbox", | ||
"description": "Multi-strategy object caching service", | ||
"version": "2.2.1", | ||
"version": "3.0.0", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [ |
@@ -5,3 +5,3 @@ <a href="https://github.com/spumko"><img src="https://raw.github.com/spumko/spumko/master/images/from.png" align="right" /></a> | ||
Multi-strategy object caching service | ||
Version: **2.x** | ||
Version: **3.x** | ||
@@ -29,7 +29,5 @@ [![Build Status](https://secure.travis-ci.org/spumko/catbox.png)](http://travis-ci.org/spumko/catbox) | ||
The `Client` object provides a low-level cache abstraction. The object is constructed using `new Client(engine, options, loader)` where: | ||
The `Client` object provides a low-level cache abstraction. The object is constructed using `new Client(engine, options)` where: | ||
- `engine` - is a string, object, or function detailing the cache strategy implementation details: | ||
- string - the node module name used via `require()`. The required module must export a prototype function with the signature | ||
`function(options)`. **catbox** will call `new require(name)(options)` with the provided `name` string. | ||
- `engine` - is an object or a prototype function implementing the cache strategy: | ||
- function - a prototype function with the signature `function(options)`. **catbox** will call `new func(options)`. | ||
@@ -36,0 +34,0 @@ - object - a pre instantiated client implementation object. Does not support passing `options`. |
@@ -23,24 +23,2 @@ // Load modules | ||
it('uses string engine', function (done) { | ||
var client = new Catbox.Client('../test/import'); | ||
client.start(function (err) { | ||
expect(err).to.not.exist; | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', 1000, function (err) { | ||
expect(err).to.not.exist; | ||
client.get(key, function (err, result) { | ||
expect(err).to.not.exist; | ||
expect(result.item).to.equal('123'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
it('uses prototype engine', function (done) { | ||
@@ -92,13 +70,2 @@ | ||
it('throws an error if using an unknown engine type', function (done) { | ||
var fn = function () { | ||
var client = new Catbox.Client('bob'); | ||
}; | ||
expect(fn).to.throw(Error); | ||
done(); | ||
}); | ||
it('errors when calling get on a bad connection', function (done) { | ||
@@ -317,3 +284,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(require('../test/import')); | ||
client.start(function (err) { | ||
@@ -320,0 +287,0 @@ |
@@ -5,2 +5,3 @@ // Load modules | ||
var Catbox = require('..'); | ||
var Import = require('./import'); | ||
@@ -26,3 +27,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -37,3 +38,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -50,3 +51,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -70,3 +71,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -85,19 +86,5 @@ | ||
it('fails setting an item with very long ttl', function (done) { | ||
var client = new Catbox.Client('../test/import'); | ||
client.start(function (err) { | ||
var key = { id: 'x', segment: 'test' }; | ||
client.set(key, '123', Math.pow(2, 31), function (err) { | ||
expect(err.message).to.equal('Invalid ttl (greater than 2147483647)'); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
it('ignored starting a connection twice on same event', function (done) { | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var x = 2; | ||
@@ -122,3 +109,3 @@ var start = function () { | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -140,3 +127,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -155,3 +142,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -178,3 +165,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -192,3 +179,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -206,3 +193,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -220,3 +207,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -234,3 +221,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -249,3 +236,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function (err) { | ||
@@ -263,3 +250,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.stop(); | ||
@@ -277,3 +264,3 @@ var key = { id: 'x', segment: 'test' }; | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.stop(); | ||
@@ -290,3 +277,3 @@ var key = { id: 'x', segment: 'test' }; | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.stop(); | ||
@@ -308,3 +295,3 @@ var key = { id: 'x', segment: 'test' }; | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy(config, client, ''); | ||
@@ -323,3 +310,3 @@ }; | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy(config, client, 'a\0b'); | ||
@@ -333,3 +320,3 @@ }; | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.stop(); | ||
@@ -336,0 +323,0 @@ client.drop('a', function (err) { |
@@ -5,2 +5,3 @@ // Load modules | ||
var Catbox = require('..'); | ||
var Import = require('./import'); | ||
@@ -26,3 +27,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy({ expiresIn: 1000 }, client, 'test'); | ||
@@ -50,3 +51,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy({}, client, 'test'); | ||
@@ -73,3 +74,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy({}, client, 'test'); | ||
@@ -133,3 +134,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
client.start(function () { | ||
@@ -374,3 +375,3 @@ | ||
var client = new Catbox.Client('../test/import'); | ||
var client = new Catbox.Client(Import); | ||
var cache = new Catbox.Policy(config, client); | ||
@@ -861,3 +862,3 @@ }; | ||
var client = new Catbox.Client('../test/import', { partition: 'test-partition' }); | ||
var client = new Catbox.Client(Import, { partition: 'test-partition' }); | ||
if (broken) { | ||
@@ -864,0 +865,0 @@ client.get = function (key, callback) { callback(new Error('bad client')); }; |
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
1
122899
1697
117