aedes-persistence-nedb
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -9,14 +9,8 @@ 'use strict'; | ||
var test = opts.test; | ||
var _persistence = opts.persistence; | ||
// requiring it here so it will not error for modules | ||
// not using the default emitter | ||
var _persistence = function asyncify (cb) { | ||
cb(null, opts.persistence()); | ||
}; | ||
var buildEmitter = opts.buildEmitter || require('mqemitter'); | ||
if (_persistence.length === 0) { | ||
_persistence = function asyncify (cb) { | ||
cb(null, opts.persistence()); | ||
}; | ||
} | ||
function persistence (cb) { | ||
@@ -103,5 +97,3 @@ var mq = buildEmitter(); | ||
t.notOk(err, 'no error'); | ||
var stream = instance.createRetainedStream('#'); | ||
stream.pipe(concat(function (list) { | ||
@@ -819,4 +811,9 @@ t.deepEqual(list, [], 'must return an empty list'); | ||
}); | ||
test('done', function (t) { | ||
t.end(); | ||
process.exit(); | ||
}); | ||
} | ||
module.exports = abstractPersistence; |
{ | ||
"name": "aedes-persistence-nedb", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "NeDB persistence for Aedes.", | ||
@@ -9,2 +9,3 @@ "main": "persistence.js", | ||
"test": "semistandard && tape test.js | faucet", | ||
"test:test": "tape test.js", | ||
"fix": "semistandard --fix" | ||
@@ -11,0 +12,0 @@ }, |
@@ -5,2 +5,3 @@ 'use strict'; | ||
var EventEmitter = require('events').EventEmitter; | ||
var Path = require('path'); | ||
var Stream = require('stream'); | ||
@@ -12,4 +13,2 @@ var Util = require('util'); | ||
function noop () {} | ||
function transformPacket (packet) { | ||
@@ -27,8 +26,10 @@ var res = Object.assign({}, packet); | ||
function Persistence () { | ||
function Persistence (options) { | ||
if (!(this instanceof Persistence)) { | ||
return new Persistence(); | ||
return new Persistence(options); | ||
} | ||
var self = this; | ||
self._options = options || {}; | ||
self._path = self._options.path || './data'; | ||
self._ready = { incoming: false, outgoing: false, retained: false, subscriptions: false, wills: false }; | ||
@@ -51,4 +52,5 @@ self.ready = false; | ||
var _name = name; | ||
var filename = Path.join(self._path, _name + '.db'); | ||
var storage = new NeDB({ | ||
filename: './data/' + _name + '.db', | ||
filename: filename, | ||
autoload: true, | ||
@@ -369,6 +371,2 @@ onload: function () { | ||
var self = this; | ||
if (!self.ready) { | ||
self.once('ready', self.destroy.bind(self, callback)); | ||
return; | ||
} | ||
if (self._destroyed) { | ||
@@ -378,13 +376,14 @@ throw new Error('destroyed called twice!'); | ||
self._destroyed = true; | ||
callback = callback || noop; | ||
self.incoming = null; | ||
self.outgoing = null; | ||
self.retained = null; | ||
self.subscriptions = null; | ||
self.wills = null; | ||
self.removeAllListeners(); | ||
this.incoming = null; | ||
this.outgoing = null; | ||
this.retained = null; | ||
this.subscriptions = null; | ||
this.wills = null; | ||
if (callback) { return callback(null); } | ||
if (callback) { | ||
return callback(); | ||
} | ||
}; | ||
module.exports = Persistence; |
@@ -0,1 +1,7 @@ | ||
[![Build Status](https://img.shields.io/travis/ovhemert/aedes-persistence-nedb.svg)](https://travis-ci.org/ovhemert/aedes-persistence-nedb) | ||
[![Dependencies](https://img.shields.io/david/ovhemert/aedes-persistence-nedb.svg)]() | ||
[![Known Vulnerabilities](https://snyk.io/test/npm/aedes-persistence-nedb/badge.svg)](https://snyk.io/test/npm/aedes-persistence-nedb) | ||
[![npm](https://img.shields.io/npm/v/aedes-persistence-nedb.svg)]() | ||
[![npm](https://img.shields.io/npm/dm/aedes-persistence-nedb.svg)]() | ||
# aedes-persistence-nedb | ||
@@ -15,10 +21,18 @@ | ||
<a name="constructor"></a> | ||
### aedesPersistenceNeDB([opts]) | ||
### Persistence ([options]) | ||
Creates a new instance of aedes-persistence-nedb. | ||
Stores NEDB files in `./data` by default. | ||
Accepts an options object to override defaults. | ||
Example: | ||
```js | ||
var NedbPersistence = require('aedes-persistence-nedb'); | ||
var persistence = new NedbPersistence({ | ||
path: './db' // defaults to './data' | ||
}); | ||
``` | ||
## Example | ||
Creates a new Aedes instance that persists to NeDB. Connect to this instance with a MQTT client to see it working. | ||
```js | ||
@@ -25,0 +39,0 @@ var NedbPersistence = require('aedes-persistence-nedb'); |
@@ -15,2 +15,1 @@ 'use strict'; | ||
}); | ||
Sorry, the diff of this file is not supported yet
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
42653
59