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