refactor secret-stack plugin init function

This commit is contained in:
Andre Staltz 2023-10-26 15:56:01 +03:00
parent 6980d41207
commit b0afc57ed6
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
1 changed files with 388 additions and 399 deletions

View File

@ -73,15 +73,11 @@ function assert(check, message) {
if (!check) throw new Error(message) if (!check) throw new Error(message)
} }
module.exports = {
name: 'set',
manifest: {},
/** /**
* @param {{ db: PPPPPDB | null, close: ClosableHook }} peer * @param {{ db: PPPPPDB | null, close: ClosableHook }} peer
* @param {any} config * @param {any} config
*/ */
init(peer, config) { function initSet(peer, config) {
assertDBPlugin(peer) assertDBPlugin(peer)
//#region state //#region state
@ -363,9 +359,7 @@ module.exports = {
} }
const data = { add: [value], del: [], supersedes } const data = { add: [value], del: [], supersedes }
peer.db.feed.publish( peer.db.feed.publish({ account: accountID, domain, data }, (err, rec) => {
{ account: accountID, domain, data },
(err, rec) => {
// prettier-ignore // prettier-ignore
if (err) return cb(new Error(`Failed to create msg when adding to Set (${id}/${subdomain})`, { cause: err })) if (err) return cb(new Error(`Failed to create msg when adding to Set (${id}/${subdomain})`, { cause: err }))
for (const [msgID, item] of toDeleteFromItemRoots) { for (const [msgID, item] of toDeleteFromItemRoots) {
@ -373,8 +367,7 @@ module.exports = {
} }
// @ts-ignore // @ts-ignore
cb(null, true) cb(null, true)
} })
)
}) })
} }
@ -406,15 +399,12 @@ module.exports = {
} }
const data = { add: [], del: [value], supersedes } const data = { add: [], del: [value], supersedes }
peer.db.feed.publish( peer.db.feed.publish({ account: accountID, domain, data }, (err, rec) => {
{ account: accountID, domain, data },
(err, rec) => {
// prettier-ignore // prettier-ignore
if (err) return cb(new Error(`Failed to create msg when deleting from Set (${id}/${subdomain})`, { cause: err })) if (err) return cb(new Error(`Failed to create msg when deleting from Set (${id}/${subdomain})`, { cause: err }))
// @ts-ignore // @ts-ignore
cb(null, true) cb(null, true)
} })
)
}) })
} }
@ -473,15 +463,12 @@ module.exports = {
} }
const data = { add: [...currentSet], del: [], supersedes } const data = { add: [...currentSet], del: [], supersedes }
peer.db.feed.publish( peer.db.feed.publish({ account: accountID, domain, data }, (err, rec) => {
{ account: accountID, domain, data },
(err, rec) => {
// prettier-ignore // prettier-ignore
if (err) return cb(new Error(`Failed to create msg when squeezing Set (${id}/${subdomain})`, { cause: err })) if (err) return cb(new Error(`Failed to create msg when squeezing Set (${id}/${subdomain})`, { cause: err }))
// @ts-ignore // @ts-ignore
cb(null, true) cb(null, true)
} })
)
}) })
} }
//#endregion //#endregion
@ -497,5 +484,7 @@ module.exports = {
_squeezePotential, _squeezePotential,
} }
},
} }
exports.name = 'set'
exports.init = initSet