mirror of https://codeberg.org/pzp/pzp-dict.git
use msg generic
This commit is contained in:
parent
de9618667d
commit
cf207f9553
26
lib/index.js
26
lib/index.js
|
@ -3,7 +3,6 @@ const MsgV3 = require('ppppp-db/msg-v3')
|
|||
const PREFIX = 'record_v1__'
|
||||
|
||||
/**
|
||||
* @typedef {import('ppppp-db').Msg} Msg
|
||||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||
* @typedef {import('ppppp-db').RecPresent} RecPresent
|
||||
* @typedef {{
|
||||
|
@ -15,12 +14,18 @@ const PREFIX = 'record_v1__'
|
|||
* ) => void
|
||||
* ) => void
|
||||
* }} ClosableHook
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {string} Subdomain
|
||||
* @typedef {string} MsgID
|
||||
* @typedef {`${Subdomain}.${string}`} SubdomainField
|
||||
* @typedef {{
|
||||
* update: Record<string, any>,
|
||||
* supersedes: Array<MsgID>,
|
||||
* }} RecordData
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template [T = any]
|
||||
* @typedef {import('ppppp-db/msg-v3').Msg<T>} Msg<T>
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -63,10 +68,7 @@ module.exports = {
|
|||
manifest: {},
|
||||
|
||||
/**
|
||||
* @param {{
|
||||
* db: PPPPPDB | null,
|
||||
* close: ClosableHook,
|
||||
* }} peer
|
||||
* @param {{ db: PPPPPDB | null, close: ClosableHook }} peer
|
||||
* @param {any} config
|
||||
*/
|
||||
init(peer, config) {
|
||||
|
@ -74,8 +76,8 @@ module.exports = {
|
|||
|
||||
//#region state
|
||||
let accountID = /** @type {string | null} */ (null)
|
||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
||||
let loadPromise = /** @type {Promise<void> | null} */ (null)
|
||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
||||
const tangles = /** @type {Map<Subdomain, MsgV3.Tangle>} */ (new Map())
|
||||
|
||||
const fieldRoots = {
|
||||
|
@ -165,7 +167,7 @@ module.exports = {
|
|||
/**
|
||||
* @private
|
||||
* @param {Msg | null | undefined} msg
|
||||
* @returns {msg is Msg}
|
||||
* @returns {msg is Msg<RecordData>}
|
||||
*/
|
||||
function isValidRecordMsg(msg) {
|
||||
if (!msg) return false
|
||||
|
@ -194,7 +196,7 @@ module.exports = {
|
|||
/**
|
||||
* @private
|
||||
* @param {string} msgID
|
||||
* @param {Msg} msg
|
||||
* @param {Msg<RecordData>} msg
|
||||
*/
|
||||
function learnRecordUpdate(msgID, msg) {
|
||||
const { account, domain } = msg.metadata
|
||||
|
@ -241,7 +243,6 @@ module.exports = {
|
|||
/**
|
||||
* @private
|
||||
* @param {CB<void>} cb
|
||||
* @returns
|
||||
*/
|
||||
function loaded(cb) {
|
||||
if (cb === void 0) return loadPromise
|
||||
|
@ -302,7 +303,6 @@ module.exports = {
|
|||
//#endregion
|
||||
|
||||
//#region public methods
|
||||
|
||||
/**
|
||||
* @param {string} id
|
||||
* @param {CB<void>} cb
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
"devDependencies": {
|
||||
"bs58": "^5.0.0",
|
||||
"c8": "7",
|
||||
"ppppp-db": "file:../db",
|
||||
"ppppp-db": "github:staltz/ppppp-db",
|
||||
"ppppp-caps": "github:staltz/ppppp-caps",
|
||||
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
||||
"rimraf": "^4.4.0",
|
||||
|
|
|
@ -30,7 +30,7 @@ Reducing the tangle above in a topological sort allows you to build a record
|
|||
`msg.data` format:
|
||||
|
||||
```typescript
|
||||
interface MsgContent {
|
||||
interface MsgData {
|
||||
update: Record<string, any>,
|
||||
supersedes: Array<MsgHash>,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue