From 39d48ac416af49de2b5251b54767654ec39ea1a7 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Wed, 18 Oct 2023 14:43:24 +0300 Subject: [PATCH] add semantic type MsgID in lib/index.js --- lib/index.js | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/index.js b/lib/index.js index 3fc8d7f..5223310 100644 --- a/lib/index.js +++ b/lib/index.js @@ -22,6 +22,7 @@ const { decrypt } = require('./encryption') * @typedef {import('ppppp-keypair').Keypair} Keypair * @typedef {import('ppppp-keypair').KeypairPublicSlice} KeypairPublicSlice * @typedef {import('ppppp-keypair').KeypairPrivateSlice} KeypairPrivateSlice + * @typedef {string} MsgID * @typedef {import('./msg-v3').Msg} Msg * @typedef {import('./msg-v3').AccountData} AccountData * @typedef {import('./msg-v3').AccountPower} AccountPower @@ -44,7 +45,7 @@ const { decrypt } = require('./encryption') * }} RecDeleted * * @typedef {{ - * id: string; + * id: MsgID; * msg: Msg; * received: number; * misc: { @@ -70,7 +71,7 @@ const { decrypt } = require('./encryption') class DBTangle extends MsgV3.Tangle { /** - * @param {string} rootID + * @param {MsgID} rootID * @param {Iterable} recordsIter */ constructor(rootID, recordsIter) { @@ -90,8 +91,8 @@ class DBTangle extends MsgV3.Tangle { * * *Erasables* are msgs that precede `msgsIDs` and can be erased without * losing a validation path toward the root. - * @param {Array} msgIDs - * @returns {{ deletables: Set, erasables: Set }} + * @param {Array} msgIDs + * @returns {{ deletables: Set, erasables: Set }} */ getDeletablesAndErasables(...msgIDs) { // Determine erasables @@ -204,7 +205,7 @@ function initDB(peer, config) { }) /** - * @param {string} id + * @param {MsgID} id * @param {Msg} msg * @param {CB} cb */ @@ -264,10 +265,10 @@ function initDB(peer, config) { } /** - * @param {Array} tangleIDs + * @param {Array} tangleIDs */ function populateTangles(tangleIDs) { - /** @type {Record} */ + /** @type {Record} */ const tangles = {} for (const tangleID of tangleIDs) { tangles[tangleID] ??= new DBTangle(tangleID, records()) @@ -332,7 +333,7 @@ function initDB(peer, config) { * locally known. * * @param {Pick} rec - * @param {string} tangleID + * @param {MsgID} tangleID * @returns {Error | null} */ function verifyRec(rec, tangleID) { @@ -387,7 +388,7 @@ function initDB(peer, config) { /** * @param {Msg} msg - * @param {string} tangleID + * @param {MsgID} tangleID * @param {CB} cb */ function add(msg, tangleID, cb) { @@ -438,7 +439,7 @@ function initDB(peer, config) { /** * @param {{ keypair?: Keypair; account: string; domain: string; }} opts - * @param {CB} cb + * @param {CB} cb */ function initializeFeed(opts, cb) { const keypair = opts.keypair ?? config.keypair @@ -777,7 +778,7 @@ function initDB(peer, config) { * data: any; * domain: string; * account: string; - * tangles?: Array; + * tangles?: Array; * }} opts * @param {CB} cb */ @@ -890,7 +891,7 @@ function initDB(peer, config) { } /** - * @param {string} msgID + * @param {MsgID} msgID * @returns {RecPresent | null} */ function getRecord(msgID) { @@ -907,14 +908,14 @@ function initDB(peer, config) { } /** - * @param {string} msgID + * @param {MsgID} msgID */ function get(msgID) { return getRecord(msgID)?.msg } /** - * @param {string} msgID + * @param {MsgID} msgID * @param {CB} cb */ function del(msgID, cb) { @@ -929,7 +930,7 @@ function initDB(peer, config) { } /** - * @param {string} msgID + * @param {MsgID} msgID * @param {CB} cb */ function erase(msgID, cb) { @@ -943,7 +944,7 @@ function initDB(peer, config) { } /** - * @param {string} tangleID + * @param {MsgID} tangleID * @returns {DBTangle} */ function getTangle(tangleID) {