{"id":20738922,"url":"https://github.com/moscajs/aedes-persistence","last_synced_at":"2025-04-04T12:05:36.212Z","repository":{"id":37977052,"uuid":"47059510","full_name":"moscajs/aedes-persistence","owner":"moscajs","description":"In-memory implementation of an Aedes persistence, with abstract tests","archived":false,"fork":false,"pushed_at":"2025-03-26T13:48:35.000Z","size":141,"stargazers_count":13,"open_issues_count":4,"forks_count":22,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-28T11:06:09.122Z","etag":null,"topics":["aedes"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/moscajs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-29T10:44:11.000Z","updated_at":"2025-03-26T13:48:40.000Z","dependencies_parsed_at":"2023-01-22T13:16:09.289Z","dependency_job_id":null,"html_url":"https://github.com/moscajs/aedes-persistence","commit_stats":null,"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moscajs%2Faedes-persistence","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moscajs%2Faedes-persistence/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moscajs%2Faedes-persistence/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/moscajs%2Faedes-persistence/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/moscajs","download_url":"https://codeload.github.com/moscajs/aedes-persistence/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174387,"owners_count":20896075,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aedes"],"created_at":"2024-11-17T06:21:36.895Z","updated_at":"2025-04-04T12:05:36.197Z","avatar_url":"https://github.com/moscajs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# aedes-persistence\n![](https://github.com/moscajs/aedes-persistence/workflows/ci/badge.svg)\n\u003cbr/\u003e\n[![Known Vulnerabilities](https://snyk.io/test/github/moscajs/aedes-persistence/badge.svg)](https://snyk.io/test/github/moscajs/aedes-persistence)\n[![Coverage Status](https://coveralls.io/repos/moscajs/aedes-persistence/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/moscajs/aedes-persistence?branch=master)\n[![NPM version](https://img.shields.io/npm/v/aedes-persistence.svg?style=flat)](https://www.npmjs.com/package/aedes-persistence)\n[![NPM downloads](https://img.shields.io/npm/dm/aedes-persistence.svg?style=flat)](https://www.npmjs.com/package/aedes-persistence)\n\nThe spec for an [Aedes](http://npm.im/aedes) persistence, with abstract\ntests and a fast in-memory implementation.\n\n* [Install](#install)\n* [API](#api)\n* [Implement another persistence](#implement)\n* [License](#license)\n\n\u003ca name=\"install\"\u003e\u003c/a\u003e\n## Install\nTo install aedes-persistence, simply use npm:\n\n```\nnpm install aedes-persistence --save\n```\n\n\u003ca name=\"api\"\u003e\u003c/a\u003e\n## API\n\n  * \u003ca href=\"#constructor\"\u003e\u003ccode\u003e\u003cb\u003epersistence()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#storeRetained\"\u003e\u003ccode\u003einstance.\u003cb\u003estoreRetained()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#createRetainedStream\"\u003e\u003ccode\u003einstance.\u003cb\u003ecreateRetainedStream()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#createRetainedStreamCombi\"\u003e\u003ccode\u003einstance.\u003cb\u003ecreateRetainedStreamCombi()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#addSubscriptions\"\u003e\u003ccode\u003einstance.\u003cb\u003eaddSubscriptions()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#removeSubscriptions\"\u003e\u003ccode\u003einstance.\u003cb\u003eremoveSubscriptions()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#subscriptionsByClient\"\u003e\u003ccode\u003einstance.\u003cb\u003esubscriptionsByClient()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#countOffline\"\u003e\u003ccode\u003einstance.\u003cb\u003ecountOffline()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#subscriptionsByTopic\"\u003e\u003ccode\u003einstance.\u003cb\u003esubscriptionsByTopic()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#cleanSubscriptions\"\u003e\u003ccode\u003einstance.\u003cb\u003ecleanSubscriptions()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#outgoingEnqueue\"\u003e\u003ccode\u003einstance.\u003cb\u003eoutgoingEnqueue()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#outgoingEnqueueCombi\"\u003e\u003ccode\u003einstance.\u003cb\u003eoutgoingEnqueueCombi()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#outgoingUpdate\"\u003e\u003ccode\u003einstance.\u003cb\u003eoutgoingUpdate()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#outgoingClearMessageId\"\u003e\u003ccode\u003einstance.\u003cb\u003eoutgoingClearMessageId()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#outgoingStream\"\u003e\u003ccode\u003einstance.\u003cb\u003eoutgoingStream()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#incomingStorePacket\"\u003e\u003ccode\u003einstance.\u003cb\u003eincomingStorePacket()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#incomingGetPacket\"\u003e\u003ccode\u003einstance.\u003cb\u003eincomingGetPacket()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#incomingDelPacket\"\u003e\u003ccode\u003einstance.\u003cb\u003eincomingDelPacket()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#putWill\"\u003e\u003ccode\u003einstance.\u003cb\u003eputWill()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#getWill\"\u003e\u003ccode\u003einstance.\u003cb\u003egetWill()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#delWill\"\u003e\u003ccode\u003einstance.\u003cb\u003edelWill()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#streamWill\"\u003e\u003ccode\u003einstance.\u003cb\u003estreamWill()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#getClientList\"\u003e\u003ccode\u003einstance.\u003cb\u003egetClientList()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n  * \u003ca href=\"#destroy\"\u003e\u003ccode\u003einstance.\u003cb\u003edestroy()\u003c/b\u003e\u003c/code\u003e\u003c/a\u003e\n\n-------------------------------------------------------\n\u003ca name=\"constructor\"\u003e\u003c/a\u003e\n### persistence([opts])\n\nCreates a new instance of a persistence, that is already ready to\noperate. The default implementation is in-memory only.\n\n-------------------------------------------------------\n\u003ca name=\"storeRetained\"\u003e\u003c/a\u003e\n### instance.storeRetained(packet, callback(err))\n\nStore a retained message, calls the callback when it was saved.\n\n-------------------------------------------------------\n\u003ca name=\"createRetainedStream\"\u003e\u003c/a\u003e\n### instance.createRetainedStream(pattern)\n\nReturn a stream that will load all retained messages matching the given\npattern (according to the MQTT spec) asynchronously. Deprecated.\n\n-------------------------------------------------------\n\u003ca name=\"createRetainedStreamCombi\"\u003e\u003c/a\u003e\n### instance.createRetainedStreamCombi(patterns)\n\nReturn a stream that will load all retained messages matching given\npatterns (according to the MQTT spec) asynchronously.\n\n-------------------------------------------------------\n\u003ca name=\"addSubscriptions\"\u003e\u003c/a\u003e\n### instance.addSubscriptions(client, subscriptions, callback(err, client))\n\nAdd the given offline subscriptions for the given\n[Client](https://github.com/moscajs/aedes#client). The client __must__\nhave connected with `clean: false`, as this is not checked here.\nThis is called when a client issue a SUBSCRIBE packet.\n\n`subscriptions` is in the same format of the `subscribe` property in the\n[SUBSCRIBE](https://github.com/mqttjs/mqtt-packet#subscribe) packet:\n\n```js\n[{\n  topic: 'hello/world',\n  qos: 1,\n}, {\n  topic: 'hello/#',\n  qos: 2,\n}]\n```\n\n-------------------------------------------------------\n\u003ca name=\"removeSubscriptions\"\u003e\u003c/a\u003e\n### instance.removeSubscriptions(client, subscriptions, callback(err, client))\n\nThe inverse of [`addSubscriptions`](#addSubscriptions) but subscriptions is an array of topic names.\n\n-------------------------------------------------------\n\u003ca name=\"subscriptionsByClient\"\u003e\u003c/a\u003e\n### instance.subscriptionsByClient(client, callback(err, subscriptions, client))\n\nReturns all the offline subscriptions for the given client. Called when\na client with `clean: false` connects to restore its subscriptions.\n\n`subscriptions` is in the same format of the `subscribe` property in the\n[SUBSCRIBE](https://github.com/mqttjs/mqtt-packet#subscribe) packet:\n\n```js\n[{\n  topic: 'hello/world',\n  qos: 1,\n}, {\n  topic: 'hello/#',\n  qos: 2,\n}]\n```\n\n-------------------------------------------------------\n\u003ca name=\"countOffline\"\u003e\u003c/a\u003e\n### instance.countOffline(cb(err, numOfSubscriptions, numOfClients))\n\nReturns the number of offline subscriptions and the number of offline\nclients.\n\n-------------------------------------------------------\n\u003ca name=\"subscriptionsByTopic\"\u003e\u003c/a\u003e\n### instance.subscriptionsByTopic(pattern, callback(err, subscriptions))\n\nReturns all the offline subscriptions matching the given pattern. Called when\na PUBLISH with `qos: 1` or `qos: 2` is received.\n\nThe subscriptions are in the format:\n\n```js\n{\n  clientId: client.id,\n  topic: sub.topic,\n  qos: sub.qos\n}\n```\n\n-------------------------------------------------------\n\u003ca name=\"cleanSubscriptions\"\u003e\u003c/a\u003e\n### instance.cleanSubscriptions(client, callback(err, client))\n\nRemoves all offline subscriptions for a given client.\n\n-------------------------------------------------------\n\u003ca name=\"outgoingEnqueue\"\u003e\u003c/a\u003e\n### instance.outgoingEnqueue(subscription, packet, callback(err))\n\nEnqueue a potentially offline delivery. `subscription` is one of the\nobjects returned by [`subscriptionsByTopic`](#subscriptionsByTopic). Deprecated.\n\n-------------------------------------------------------\n\u003ca name=\"outgoingEnqueueCombi\"\u003e\u003c/a\u003e\n### instance.outgoingEnqueueCombi(subscriptions, packet, callback(err))\n\nEnqueue a potentially offline delivery. `subscriptions` is the whole subscriptions\nobjects returned by [`subscriptionsByTopic`](#subscriptionsByTopic).\n\n-------------------------------------------------------\n\u003ca name=\"outgoingUpdate\"\u003e\u003c/a\u003e\n### instance.outgoingUpdate(client, packet, callback(err))\n\nCalled before a (potentially) offline packet is delivered, the caller\nshould update the `packet.messageId` before updating.\n\n-------------------------------------------------------\n\u003ca name=\"outgoingClearMessageId\"\u003e\u003c/a\u003e\n### instance.outgoingClearMessageId(client, packet, callback(err, packet))\n\nRemoves a packet with the given `messageId` (passing a PUBACK is ok)\nfrom the persistence. Passes back original packet to the callback.\n\n-------------------------------------------------------\n\u003ca name=\"outgoingStream\"\u003e\u003c/a\u003e\n### instance.outgoingStream(client)\n\nReturn a stream that will load all offline messages for the given client asynchronously.\n\n-------------------------------------------------------\n\u003ca name=\"incomingStorePacket\"\u003e\u003c/a\u003e\n### instance.incomingStorePacket(client, packet, cb(err, packet))\n\nStore an incoming packet for the given client. Used for QoS 2.\n\n-------------------------------------------------------\n\u003ca name=\"incomingGetPacket\"\u003e\u003c/a\u003e\n### instance.incomingGetPacket(client, packet, cb(err, packet))\n\nRetrieve an incoming packet with the same `messageId` for the given client. Used for QoS 2.\n\n-------------------------------------------------------\n\u003ca name=\"incomingDelPacket\"\u003e\u003c/a\u003e\n### instance.incomingDelPacket(client, packet, cb(err, packet))\n\nDeletes incoming packet with the same `messageId` for the given client. Used for QoS 2.\n\n-------------------------------------------------------\n\u003ca name=\"putWill\"\u003e\u003c/a\u003e\n### instance.putWill(client, packet, cb(err))\n\nStores the will of a client. Used to support multi-broker environments\nand to not lose wills in case of a crash.\n\n-------------------------------------------------------\n\u003ca name=\"getWill\"\u003e\u003c/a\u003e\n### instance.getWill(client, packet, cb(err))\n\nRetrieves the will of a client. Used to support multi-broker environments\nand to not lose wills in case of a crash.\n\n-------------------------------------------------------\n\u003ca name=\"delWill\"\u003e\u003c/a\u003e\n### instance.delWill(client, packet, cb(err))\n\nRemoves the will of a client. Used to support multi-broker environments\nand to not lose wills in case of a crash.\n\n-------------------------------------------------------\n\u003ca name=\"streamWill\"\u003e\u003c/a\u003e\n### instance.streamWill(brokers)\n\nStreams all the wills for the given brokers. The brokers are in the\nformat:\n\n```js\n{\n  mybroker: {\n    brokerId: 'mybroker'\n  }\n}\n```\n\n-------------------------------------------------------\n\u003ca name=\"getCLientList\"\u003e\u003c/a\u003e\n### instance.getClientList(topic)\n\nReturns a stream which has all the clientIds subscribed to the\nspecified topic\n\n\u003ca name=\"destroy\"\u003e\u003c/a\u003e\n### instance.destroy(cb(err))\n\nDestroy current persistence. Use callback `cb(err)` to catch errors if any\n\n\u003ca name=\"implement\"\u003e\u003c/a\u003e\n## Implement another persistence\n\nA persistence needs to pass all tests defined in\n[./abstract.js](./abstract.js). You can import and use that test suite\nin the following manner:\n\n```js\nconst test = require('tape').test\nconst myperst = require('./')\nconst abs = require('aedes-persistence/abstract')\n\nabs({\n  test: test,\n  persistence: myperst\n})\n```\n\nIf you require some async stuff before returning, a callback is also\nsupported:\n\n```js\nconst test = require('tape').test\nconst myperst = require('./')\nconst abs = require('aedes-persistence/abstract')\nconst clean = require('./clean') // invented module\n\nabs({\n  test: test,\n  buildEmitter: require('mymqemitter'), // optional\n  persistence: function build (cb) {\n    clean(function (err) {\n      cb(err, myperst())\n    })\n  }\n})\n```\n\n## Collaborators\n\n* [__Gnought__](https://github.com/gnought)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoscajs%2Faedes-persistence","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmoscajs%2Faedes-persistence","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmoscajs%2Faedes-persistence/lists"}