Comparing version 3.0.0 to 3.0.1
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"homepage": "https://github.com/rvagg/node-level-ttl", | ||
@@ -36,10 +36,10 @@ "authors": [ | ||
"devDependencies": { | ||
"level": ">=0.18.0 <0.19.0-0", | ||
"rimraf": ">=2.2.8 <2.3.0-0", | ||
"faucet": "0.0.1", | ||
"ltest": "2.0.0", | ||
"tape": ">=2.14.0 <2.15.0-0" | ||
}, | ||
"scripts": { | ||
"test": "node ./test.js" | ||
"test": "tape test.js | faucet" | ||
}, | ||
"license": "MIT" | ||
} |
@@ -14,4 +14,6 @@ # Level TTL | ||
***Note: version 1.0.0 data stores are not backward compatible with previous versions. If you have unexpired entries in a data store managed by pre-1.0.0, don't expect them to expire if you upgrade to 1.0.0+.*** *This is due to a level-sublevel change. It is also recommended that you only use level-sublevel 6.0.0+ with level-ttl.* | ||
***Note 1: Version 1.0.0 data stores are not backward compatible with previous versions. If you have unexpired entries in a data store managed by pre-1.0.0, don't expect them to expire if you upgrade to 1.0.0+.*** *This is due to a level-sublevel change. It is also recommended that you only use level-sublevel 6.0.0+ with level-ttl.* | ||
***Note 2: `level-ttl` has partial support for `level-spaces`. It should work fine as long as you don't use the `'defaultTTL'` feature, see below. This is being worked on so we can have full support for `level-spaces` as well.*** | ||
```js | ||
@@ -49,3 +51,3 @@ var levelup = require('level') | ||
```js | ||
var db = level('/tmp/foo.db') | ||
var db = levelup('/tmp/foo.db') | ||
// scan for deletables every second | ||
@@ -66,3 +68,3 @@ db = ttl(db, { checkFrequency: 1000 }) | ||
```js | ||
var db = level('/tmp/foo.db') | ||
var db = levelup('/tmp/foo.db') | ||
db = ttl(db, { defaultTTL: 15 * 60 * 1000 }) | ||
@@ -69,0 +71,0 @@ db.put('foo', 'bar', function (err) { /* .. */ }) |
131
test.js
@@ -1,4 +0,3 @@ | ||
const test = require('tape') | ||
, rimraf = require('rimraf') | ||
, levelup = require('level') | ||
const tape = require('tape') | ||
, ltest = require('ltest')(tape) | ||
, listStream = require('list-stream') | ||
@@ -14,24 +13,11 @@ , ttl = require('./') | ||
function ltest (name, fn, opts, ttl_opts) { | ||
test(name, function (t) { | ||
var location = '__ttl-' + Math.random() | ||
, db | ||
function test (name, fn, opts) { | ||
ltest(name, opts, function (t, _db, createReadStream) { | ||
var db | ||
, close = _db.close.bind(_db) // unmolested close() | ||
t.__end = t.end | ||
t.end = function () { | ||
db.close(function (err) { | ||
t.notOk(err, 'no error on close()') | ||
rimraf(location, t.__end.bind(t)) | ||
}) | ||
} | ||
fixtape(t) | ||
levelup(location, opts, function (err, _db) { | ||
t.notOk(err, 'no error on open()') | ||
var createReadStream = _db.createReadStream.bind(_db) | ||
db = ttl(_db, xtend({ checkFrequency: 50 }, ttl_opts)) | ||
fn(db, t, createReadStream) | ||
}) | ||
db = ttl(_db, xtend({ checkFrequency: 50 }, opts)) | ||
fn(t, db, createReadStream, close) | ||
}) | ||
@@ -66,3 +52,3 @@ } | ||
// kind of a lame test but we know they should throw | ||
false && ltest('test single ttl entry', function (db, t) { | ||
false && test('test single ttl entry', function (db, t) { | ||
t.throws(db.put.bind(db), { name: 'WriteError', message: 'put() requires key and value arguments' }) | ||
@@ -73,3 +59,3 @@ t.throws(db.del.bind(db), { name: 'WriteError', message: 'del() requires a key argument' }) | ||
ltest('test single ttl entry with put', function (db, t, createReadStream) { | ||
test('test single ttl entry with put', function (t, db, createReadStream) { | ||
db.put('foo', 'foovalue', function (err) { | ||
@@ -106,3 +92,3 @@ t.notOk(err, 'no error') | ||
ltest('test multiple ttl entries with put', function (db, t, createReadStream) { | ||
test('test multiple ttl entries with put', function (t, db, createReadStream) { | ||
var expect = function (delay, keys) { | ||
@@ -146,3 +132,3 @@ setTimeout(function () { | ||
ltest('test multiple ttl entries with batch-put', function (db, t, createReadStream) { | ||
test('test multiple ttl entries with batch-put', function (t, db, createReadStream) { | ||
var expect = function (delay, keys) { | ||
@@ -193,3 +179,3 @@ setTimeout(function () { | ||
ltest('test prolong entry life with additional put', function (db, t, createReadStream) { | ||
test('test prolong entry life with additional put', function (t, db, createReadStream) { | ||
var putBar = function () { | ||
@@ -232,3 +218,3 @@ db.put('bar', 'barvalue', { ttl: 250 }) | ||
ltest('test prolong entry life with ttl(key, ttl)', function (db, t, createReadStream) { | ||
test('test prolong entry life with ttl(key, ttl)', function (t, db, createReadStream) { | ||
var ttlBar = function () { | ||
@@ -272,3 +258,3 @@ db.ttl('bar', 250) | ||
ltest('test del', function (db, t, createReadStream) { | ||
test('test del', function (t, db, createReadStream) { | ||
var verify = function (base, delay) { | ||
@@ -314,3 +300,3 @@ setTimeout(function () { | ||
ltest('test del with db value encoding', function (db, t, createReadStream) { | ||
test('test del with db value encoding', function (t, db, createReadStream) { | ||
var verify = function (base, delay) { | ||
@@ -356,29 +342,21 @@ setTimeout(function () { | ||
test('test stop() method stops interval and doesn\'t hold process up', function (t) { | ||
t.plan(9) | ||
function wrappedTest () { | ||
var intervals = 0 | ||
, _setInterval = global.setInterval | ||
, _clearInterval = global.clearInterval | ||
var location = '__ttl-' + Math.random() | ||
, intervals = 0 | ||
, db | ||
, close | ||
global._setInterval = global.setInterval | ||
global.setInterval = function () { | ||
intervals++ | ||
return global._setInterval.apply(global, arguments) | ||
return _setInterval.apply(global, arguments) | ||
} | ||
global._clearInterval = global.clearInterval | ||
global.clearInterval = function () { | ||
intervals-- | ||
return global._clearInterval.apply(global, arguments) | ||
return _clearInterval.apply(global, arguments) | ||
} | ||
levelup(location, function (err, _db) { | ||
t.notOk(err, 'no error on open()') | ||
close = _db.close.bind(_db) // unmolested close() | ||
test('test stop() method stops interval and doesn\'t hold process up', function (t, db, createReadStream, close) { | ||
db = ttl(_db, { checkFrequency: 50 }) | ||
t.equals(intervals, 1, '1 interval timer') | ||
t.equals(1, intervals, '1 interval timer') | ||
db.put( 'foo', 'bar1', { ttl: 25 }) | ||
@@ -401,14 +379,17 @@ setTimeout(function () { | ||
close(function () { | ||
global.setInterval = global._setInterval | ||
global.setInterval = _setInterval | ||
global.clearInterval = _clearInterval | ||
t.equals(0, intervals, 'all interval timers cleared') | ||
rimraf(location, function () { | ||
t.ok('rimraffed') | ||
}) | ||
t.end() | ||
}) | ||
}) | ||
}, 120) | ||
}) | ||
}) | ||
ltest('single put with default ttl set', function (db, t, createReadStream) { | ||
} | ||
wrappedTest() | ||
test('single put with default ttl set', function (t, db, createReadStream) { | ||
db.put('foo', 'bar1', function(err) { | ||
@@ -433,5 +414,5 @@ t.ok(!err, 'no error') | ||
setTimeout(t.end.bind(t), 175) | ||
}, {}, { defaultTTL: 75 } ) | ||
}, { defaultTTL: 75 } ) | ||
ltest('single put with overridden ttl set', function (db, t, createReadStream) { | ||
test('single put with overridden ttl set', function (t, db, createReadStream) { | ||
db.put('foo', 'bar1', { ttl: 99 }, function(err) { | ||
@@ -456,5 +437,5 @@ t.ok(!err, 'no error') | ||
setTimeout(t.end.bind(t), 175) | ||
}, {}, { defaultTTL: 75 } ) | ||
}, { defaultTTL: 75 } ) | ||
ltest('batch put with default ttl set', function (db, t, createReadStream) { | ||
test('batch put with default ttl set', function (t, db, createReadStream) { | ||
db.batch([ | ||
@@ -465,3 +446,3 @@ { type: 'put', key: 'foo', value: 'bar1' }, | ||
t.ok(!err, 'no error') | ||
setTimeout(function () { | ||
@@ -492,5 +473,5 @@ db.get('foo', function (err, value) { | ||
setTimeout(t.end.bind(t), 175) | ||
}, {}, { defaultTTL: 75 }) | ||
}, { defaultTTL: 75 }) | ||
ltest('batch put with overriden ttl set', function (db, t, createReadStream) { | ||
test('batch put with overriden ttl set', function (t, db, createReadStream) { | ||
db.batch([ | ||
@@ -525,27 +506,11 @@ { type: 'put', key: 'foo', value: 'bar1' }, | ||
setTimeout(t.end.bind(t), 175) | ||
}, {}, { defaultTTL: 75 }) | ||
}, { defaultTTL: 75 }) | ||
test('without options', function (t) { | ||
var location = '__ttl-' + Math.random() | ||
, db | ||
t.__end = t.end | ||
t.end = function () { | ||
db.close(function (err) { | ||
t.notOk(err, 'no error on close()') | ||
rimraf(location, t.__end.bind(t)) | ||
}) | ||
ltest('without options', function (t, db, createReadStream) { | ||
try { | ||
ttl(db) | ||
} catch(err) { | ||
t.notOk(err, 'no error on ttl()') | ||
} | ||
levelup(location, function (err, _db) { | ||
t.notOk(err, 'no error on open()') | ||
var createReadStream = _db.createReadStream.bind(_db) | ||
try { | ||
db = ttl(_db) | ||
} catch(err) { | ||
t.notOk(err, 'no error on ttl()') | ||
} | ||
t.end() | ||
}) | ||
t.end() | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
89
0
32506
723