From 6980d41207926e1560b021df023878f4e5fbcdbd Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 26 Oct 2023 15:53:38 +0300 Subject: [PATCH] refactor misc --- lib/index.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/index.js b/lib/index.js index b497e2b..4e0f935 100644 --- a/lib/index.js +++ b/lib/index.js @@ -21,7 +21,7 @@ const PREFIX = 'set_v1__' * add: Array, * del: Array, * supersedes: Array, - * }} SetData + * }} SetMsgData */ /** @@ -60,8 +60,8 @@ function fromSubdomain(subdomain) { * }} peer * @returns {asserts peer is { db: PPPPPDB, close: ClosableHook }} */ -function assertDBExists(peer) { - if (!peer.db) throw new Error('record plugin requires ppppp-db plugin') +function assertDBPlugin(peer) { + if (!peer.db) throw new Error('set plugin requires ppppp-db plugin') } /** @@ -82,7 +82,7 @@ module.exports = { * @param {any} config */ init(peer, config) { - assertDBExists(peer) + assertDBPlugin(peer) //#region state let accountID = /** @type {string | null} */ (null) @@ -102,10 +102,10 @@ module.exports = { }, /** * @param {string} subdomain - * @returns {Record>} + * @returns {{[item in string]: Array}} */ getAll(subdomain) { - const out = /** @type {Record>} */ ({}) + const out = /** @type {{[item in string]: Array}} */ ({}) for (const [key, value] of this._map.entries()) { if (key.startsWith(subdomain + '/')) { const item = key.slice(subdomain.length + 1) @@ -177,7 +177,7 @@ module.exports = { /** * @private * @param {Msg | null | undefined} msg - * @returns {msg is Msg} + * @returns {msg is Msg} */ function isValidSetMsg(msg) { if (!msg) return false @@ -195,7 +195,7 @@ module.exports = { * @param {string} subdomain */ function readSet(id, subdomain) { - assertDBExists(peer) + assertDBPlugin(peer) const domain = fromSubdomain(subdomain) const mootID = MsgV3.getMootID(id, domain) const tangle = peer.db.getTangle(mootID) @@ -227,7 +227,7 @@ module.exports = { /** * @param {string} msgID - * @param {Msg} msg + * @param {Msg} msg */ function learnSetUpdate(msgID, msg) { const { account, domain } = msg.metadata @@ -283,7 +283,7 @@ module.exports = { * @param {string} subdomain */ function _squeezePotential(subdomain) { - assertDBExists(peer) + assertDBPlugin(peer) if (!accountID) throw new Error('Cannot squeeze potential before loading') // TODO: improve this so that the squeezePotential is the size of the // tangle suffix built as a slice from the fieldRoots @@ -308,7 +308,7 @@ module.exports = { * @param {CB} cb */ function load(id, cb) { - assertDBExists(peer) + assertDBPlugin(peer) accountID = id loadPromise = new Promise((resolve, reject) => { for (const rec of peer.db.records()) { @@ -336,7 +336,7 @@ module.exports = { * @param {CB} cb */ function add(id, subdomain, value, cb) { - assertDBExists(peer) + assertDBPlugin(peer) assert(!!accountID, 'Cannot add to Set before loading') // prettier-ignore if (id !== accountID) return cb(new Error(`Cannot add to another user's Set (${id}/${subdomain})`)) @@ -385,7 +385,7 @@ module.exports = { * @param {CB} cb */ function del(id, subdomain, value, cb) { - assertDBExists(peer) + assertDBPlugin(peer) assert(!!accountID, 'Cannot add to Set before loading') // prettier-ignore if (id !== accountID) return cb(new Error(`Cannot delete from another user's Set (${id}/${subdomain})`)) @@ -453,7 +453,7 @@ module.exports = { * @param {CB} cb */ function squeeze(id, subdomain, cb) { - assertDBExists(peer) + assertDBPlugin(peer) assert(!!accountID, 'Cannot squeeze Set before loading') // prettier-ignore if (id !== accountID) return cb(new Error(`Cannot squeeze another user's Set (${id}/${subdomain})`))