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__'
|
const PREFIX = 'record_v1__'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('ppppp-db').Msg} Msg
|
|
||||||
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
* @typedef {ReturnType<import('ppppp-db').init>} PPPPPDB
|
||||||
* @typedef {import('ppppp-db').RecPresent} RecPresent
|
* @typedef {import('ppppp-db').RecPresent} RecPresent
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
|
@ -15,12 +14,18 @@ const PREFIX = 'record_v1__'
|
||||||
* ) => void
|
* ) => void
|
||||||
* ) => void
|
* ) => void
|
||||||
* }} ClosableHook
|
* }} ClosableHook
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @typedef {string} Subdomain
|
* @typedef {string} Subdomain
|
||||||
* @typedef {string} MsgID
|
* @typedef {string} MsgID
|
||||||
* @typedef {`${Subdomain}.${string}`} SubdomainField
|
* @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: {},
|
manifest: {},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{
|
* @param {{ db: PPPPPDB | null, close: ClosableHook }} peer
|
||||||
* db: PPPPPDB | null,
|
|
||||||
* close: ClosableHook,
|
|
||||||
* }} peer
|
|
||||||
* @param {any} config
|
* @param {any} config
|
||||||
*/
|
*/
|
||||||
init(peer, config) {
|
init(peer, config) {
|
||||||
|
@ -74,8 +76,8 @@ module.exports = {
|
||||||
|
|
||||||
//#region state
|
//#region state
|
||||||
let accountID = /** @type {string | null} */ (null)
|
let accountID = /** @type {string | null} */ (null)
|
||||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
|
||||||
let loadPromise = /** @type {Promise<void> | 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 tangles = /** @type {Map<Subdomain, MsgV3.Tangle>} */ (new Map())
|
||||||
|
|
||||||
const fieldRoots = {
|
const fieldRoots = {
|
||||||
|
@ -165,7 +167,7 @@ module.exports = {
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {Msg | null | undefined} msg
|
* @param {Msg | null | undefined} msg
|
||||||
* @returns {msg is Msg}
|
* @returns {msg is Msg<RecordData>}
|
||||||
*/
|
*/
|
||||||
function isValidRecordMsg(msg) {
|
function isValidRecordMsg(msg) {
|
||||||
if (!msg) return false
|
if (!msg) return false
|
||||||
|
@ -194,7 +196,7 @@ module.exports = {
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {string} msgID
|
* @param {string} msgID
|
||||||
* @param {Msg} msg
|
* @param {Msg<RecordData>} msg
|
||||||
*/
|
*/
|
||||||
function learnRecordUpdate(msgID, msg) {
|
function learnRecordUpdate(msgID, msg) {
|
||||||
const { account, domain } = msg.metadata
|
const { account, domain } = msg.metadata
|
||||||
|
@ -241,7 +243,6 @@ module.exports = {
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
* @param {CB<void>} cb
|
* @param {CB<void>} cb
|
||||||
* @returns
|
|
||||||
*/
|
*/
|
||||||
function loaded(cb) {
|
function loaded(cb) {
|
||||||
if (cb === void 0) return loadPromise
|
if (cb === void 0) return loadPromise
|
||||||
|
@ -302,7 +303,6 @@ module.exports = {
|
||||||
//#endregion
|
//#endregion
|
||||||
|
|
||||||
//#region public methods
|
//#region public methods
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} id
|
* @param {string} id
|
||||||
* @param {CB<void>} cb
|
* @param {CB<void>} cb
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"bs58": "^5.0.0",
|
"bs58": "^5.0.0",
|
||||||
"c8": "7",
|
"c8": "7",
|
||||||
"ppppp-db": "file:../db",
|
"ppppp-db": "github:staltz/ppppp-db",
|
||||||
"ppppp-caps": "github:staltz/ppppp-caps",
|
"ppppp-caps": "github:staltz/ppppp-caps",
|
||||||
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
"ppppp-keypair": "github:staltz/ppppp-keypair",
|
||||||
"rimraf": "^4.4.0",
|
"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:
|
`msg.data` format:
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
interface MsgContent {
|
interface MsgData {
|
||||||
update: Record<string, any>,
|
update: Record<string, any>,
|
||||||
supersedes: Array<MsgHash>,
|
supersedes: Array<MsgHash>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue