aedes-cached-persistence
    TypeScript icon, indicating that this package has built-in type declarations

    9.0.0 • Public • Published

    aedes-cached-persistence

    Dependencies Status devDependencies Status
    Known Vulnerabilities Coverage Status NPM version NPM downloads

    Abstract class to write an Aedes persistence with in-process caching of subscriptions. It implements the API defined by aedes-persistence.

    Install

    To install aedes-cached-persistence, simply use npm:

    npm install aedes-cached-persistence --save

    Provided methods

    Implement another persistence

    Inheritance

    In order to reuse aedes-cached-persistence, you need to:

    const CachedPersistence = require('aedes-cached-persistence')
    
    // if you need http://npm.im/aedes-packet, it is available
    // from this module as well
    // const { Packet } = CachedPersistence
    
    class MyPersistence extends CachedPersistence {
        constructor(opts) {
           super(opts)
        }
        addSubscriptions(client, subs, cb) {
            // ..persistence specific implementation..
            // call super._addedSubscriptions when you are done
            super._addedSubscriptions(client, subs.map(mapSub), cb)
        }
        removeSubscriptions(client, subs, cb) {
            // ..persistence specific implementation..
            // call super._removedSubscriptions when you are done
            super._removedSubscriptions(client, subs.map(mapSub), cb)
        }
    }
    
    function mapSub (sub) {
      return { topic: sub.topic }
    }

    Tests

    A persistence needs to pass all tests defined in ./abstract.js. You can import and use that test suite in the following manner:

    var test = require('tape').test
    var myperst = require('./')
    var abs = require('aedes-cached-persistence/abstract')
    
    abs({
      test: test,
      persistence: myperst
    })

    If you require some async stuff before returning, a callback is also supported:

    var test = require('tape').test
    var myperst = require('./')
    var abs = require('aedes-persistence/abstract')
    var clean = require('./clean') // invented module
    
    abs({
      test: test,
      buildEmitter: require('mymqemitter'), // optional
      persistence: function build (cb) {
        clean(function (err) {
          cb(err, myperst())
        })
      }
    })

    License

    MIT

    Install

    npm i aedes-cached-persistence

    DownloadsWeekly Downloads

    3,260

    Version

    9.0.0

    License

    MIT

    Unpacked Size

    22.1 kB

    Total Files

    10

    Last publish

    Collaborators

    • matteo.collina
    • roberts_lando
    • gnought
    • getlarge