mirror of https://codeberg.org/pzp/pzp-dict.git
refactor: rename assert function
This commit is contained in:
parent
44929fb2c9
commit
e05e0b3313
14
lib/index.js
14
lib/index.js
|
@ -59,7 +59,7 @@ function fromSubdomain(subdomain) {
|
||||||
* }} peer
|
* }} peer
|
||||||
* @returns {asserts peer is { db: PPPPPDB, close: ClosableHook }}
|
* @returns {asserts peer is { db: PPPPPDB, close: ClosableHook }}
|
||||||
*/
|
*/
|
||||||
function assertDBExists(peer) {
|
function assertDBPlugin(peer) {
|
||||||
if (!peer.db) throw new Error('record plugin requires ppppp-db plugin')
|
if (!peer.db) throw new Error('record plugin requires ppppp-db plugin')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ function assertDBExists(peer) {
|
||||||
* @param {any} config
|
* @param {any} config
|
||||||
*/
|
*/
|
||||||
function initRecord(peer, config) {
|
function initRecord(peer, config) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
|
|
||||||
//#region state
|
//#region state
|
||||||
let accountID = /** @type {string | null} */ (null)
|
let accountID = /** @type {string | null} */ (null)
|
||||||
|
@ -251,7 +251,7 @@ function initRecord(peer, config) {
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function _squeezePotential(subdomain) {
|
function _squeezePotential(subdomain) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
if (!accountID) throw new Error('Cannot squeeze potential before loading')
|
if (!accountID) throw new Error('Cannot squeeze potential before loading')
|
||||||
// TODO: improve this so that the squeezePotential is the size of the
|
// TODO: improve this so that the squeezePotential is the size of the
|
||||||
// tangle suffix built as a slice from the fieldRoots
|
// tangle suffix built as a slice from the fieldRoots
|
||||||
|
@ -275,7 +275,7 @@ function initRecord(peer, config) {
|
||||||
* @param {CB<boolean>} cb
|
* @param {CB<boolean>} cb
|
||||||
*/
|
*/
|
||||||
function forceUpdate(subdomain, update, cb) {
|
function forceUpdate(subdomain, update, cb) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
if (!accountID) throw new Error('Cannot force update before loading')
|
if (!accountID) throw new Error('Cannot force update before loading')
|
||||||
const domain = fromSubdomain(subdomain)
|
const domain = fromSubdomain(subdomain)
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ function initRecord(peer, config) {
|
||||||
* @param {CB<void>} cb
|
* @param {CB<void>} cb
|
||||||
*/
|
*/
|
||||||
function load(id, cb) {
|
function load(id, cb) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
accountID = id
|
accountID = id
|
||||||
loadPromise = new Promise((resolve, reject) => {
|
loadPromise = new Promise((resolve, reject) => {
|
||||||
for (const rec of peer.db.records()) {
|
for (const rec of peer.db.records()) {
|
||||||
|
@ -338,7 +338,7 @@ function initRecord(peer, config) {
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
function getMinRequiredDepth(tangleID) {
|
function getMinRequiredDepth(tangleID) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
|
|
||||||
const rootMsg = peer.db.get(tangleID)
|
const rootMsg = peer.db.get(tangleID)
|
||||||
if (!rootMsg) throw new Error(`Cannot find tangle root "${tangleID}"`)
|
if (!rootMsg) throw new Error(`Cannot find tangle root "${tangleID}"`)
|
||||||
|
@ -378,7 +378,7 @@ function initRecord(peer, config) {
|
||||||
* @returns {Record<string, any> | null}
|
* @returns {Record<string, any> | null}
|
||||||
*/
|
*/
|
||||||
function read(id, subdomain) {
|
function read(id, subdomain) {
|
||||||
assertDBExists(peer)
|
assertDBPlugin(peer)
|
||||||
const domain = fromSubdomain(subdomain)
|
const domain = fromSubdomain(subdomain)
|
||||||
const mootID = MsgV3.getMootID(id, domain)
|
const mootID = MsgV3.getMootID(id, domain)
|
||||||
const tangle = peer.db.getTangle(mootID)
|
const tangle = peer.db.getTangle(mootID)
|
||||||
|
|
Loading…
Reference in New Issue