Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): ugrade aedes-persistence to 9.1.1 #52

Merged
merged 2 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
"tsd": "^0.14.0"
},
"dependencies": {
"aedes-persistence": "^8.1.3",
"aedes-persistence": "^9.1.1",
"fastparallel": "^2.4.0",
"multistream": "^4.0.1",
"qlobber": "^5.0.3"
"qlobber": "^7.0.0"
}
}
117 changes: 41 additions & 76 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,91 +1,56 @@
'use strict'

const test = require('tape').test
const CachedPersistence = require('./')
const util = require('util')
const Memory = require('aedes-persistence')
const abs = require('./abstract')

function MyPersistence () {
if (!(this instanceof MyPersistence)) {
return new MyPersistence()
class MyPersistence extends CachedPersistence {
constructor (opts) {
super(opts)
this.backend = opts.backend

// link methods
const methods = ['storeRetained', 'countOffline', 'outgoingEnqueue',
'outgoingUpdate', 'outgoingClearMessageId',
'incomingStorePacket', 'incomingGetPacket',
'incomingDelPacket', 'delWill',
'createRetainedStream',
'outgoingStream', 'subscriptionsByClient',
'getWill', 'streamWill', 'getClientList', 'destroy']
methods.forEach((key) => {
this[key] = this.backend[key].bind(this.backend)
})
// putWill is a special because it needs this.broker.id
this.putWill = (client, packet, cb) => {
this.backend.broker = this.broker
this.backend.putWill(client, packet, cb)
}
}

// copied from Memory
this._retained = []
this._subscriptions = new Map()
this._clientsCount = 0
this._outgoing = {}
this._incoming = {}
this._wills = {}

CachedPersistence.call(this)
}

util.inherits(MyPersistence, CachedPersistence)

// copy over methods
;['storeRetained', 'countOffline', 'outgoingEnqueue',
'outgoingUpdate', 'outgoingClearMessageId',
'incomingStorePacket', 'incomingGetPacket',
'incomingDelPacket', 'putWill', 'delWill',
'createRetainedStream',
'outgoingStream', 'subscriptionsByClient',
'getWill', 'streamWill', 'getClientList', 'destroy'].forEach(function (key) {
MyPersistence.prototype[key] = Memory.prototype[key]
})

MyPersistence.prototype.addSubscriptions = function (client, subs, cb) {
let stored = this._subscriptions.get(client.id)

if (!stored) {
stored = new Map()
this._subscriptions.set(client.id, stored)
this._clientsCount++
addSubscriptions (client, subs, cb) {
this.backend.addSubscriptions(client, subs, (err) => {
if (err) {
return cb(err)
}
this._addedSubscriptions(client, subs, cb)
})
}

const subsObjs = subs.map(function mapSub (sub) {
stored.set(sub.topic, sub.qos)
return {
clientId: client.id,
topic: sub.topic,
qos: sub.qos
}
})

this._addedSubscriptions(client, subsObjs, cb)
}

MyPersistence.prototype.removeSubscriptions = function (client, subs, cb) {
const stored = this._subscriptions.get(client.id)
const removed = []

if (stored) {
for (let i = 0; i < subs.length; i += 1) {
const topic = subs[i]
const qos = stored.get(topic)
if (qos !== undefined) {
if (qos > 0) {
removed.push({
clientId: client.id,
topic: topic,
qos: qos
})
}
stored.delete(topic)
removeSubscriptions (client, topics, cb) {
this.backend.removeSubscriptions(client, topics, (err) => {
if (err) {
return cb(err)
}
}

if (stored.size === 0) {
this._clientsCount--
this._subscriptions.delete(client.id)
}
const subsObjs = topics.map(function mapSub (topic) {
return { topic }
})
this._removedSubscriptions(client, subsObjs, cb)
})
}

this._removedSubscriptions(client, removed, cb)
}

const persistence = () => new MyPersistence({ backend: Memory() })

abs({
test: test,
persistence: MyPersistence
test,
persistence
})