mirror of https://codeberg.org/pzp/pzp-set.git
Improve types of watch Obz
This commit is contained in:
parent
8983ba29f0
commit
3accb5e3b0
|
@ -3,7 +3,7 @@ node_modules
|
||||||
pnpm-lock.yaml
|
pnpm-lock.yaml
|
||||||
package-lock.json
|
package-lock.json
|
||||||
coverage
|
coverage
|
||||||
**/*.d.ts
|
lib/**/*.d.ts
|
||||||
*~
|
*~
|
||||||
|
|
||||||
# For misc scripts and experiments:
|
# For misc scripts and experiments:
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
declare module 'obz' {
|
||||||
|
type Remove = () => void
|
||||||
|
export interface Obz<X> {
|
||||||
|
(listener: (value: X) => void): Remove
|
||||||
|
set(value: X): unknown
|
||||||
|
value: X
|
||||||
|
}
|
||||||
|
function createObz(): Obz
|
||||||
|
export = createObz
|
||||||
|
}
|
12
lib/index.js
12
lib/index.js
|
@ -1,4 +1,3 @@
|
||||||
// @ts-ignore
|
|
||||||
const Obz = require('obz')
|
const Obz = require('obz')
|
||||||
const MsgV4 = require('ppppp-db/msg-v4')
|
const MsgV4 = require('ppppp-db/msg-v4')
|
||||||
|
|
||||||
|
@ -24,9 +23,7 @@ const PREFIX = 'set_v1__'
|
||||||
* del: Array<string>,
|
* del: Array<string>,
|
||||||
* supersedes: Array<MsgID>,
|
* supersedes: Array<MsgID>,
|
||||||
* }} SetMsgData
|
* }} SetMsgData
|
||||||
* @typedef {{
|
* @typedef {{ event: 'add' | 'del', subdomain: string, value: string }} Event
|
||||||
* set: (ev: { event: 'add' | 'del', subdomain: string, value: string }) => void
|
|
||||||
* }} ObzType
|
|
||||||
* @typedef {{
|
* @typedef {{
|
||||||
* set?: {
|
* set?: {
|
||||||
* ghostSpan?: number
|
* ghostSpan?: number
|
||||||
|
@ -39,6 +36,11 @@ const PREFIX = 'set_v1__'
|
||||||
* @typedef {import('ppppp-db/msg-v4').Msg<T>} Msg<T>
|
* @typedef {import('ppppp-db/msg-v4').Msg<T>} Msg<T>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template T
|
||||||
|
* @typedef {import('obz').Obz<T>} ObzType
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T
|
* @template T
|
||||||
* @typedef {T extends void ?
|
* @typedef {T extends void ?
|
||||||
|
@ -84,7 +86,7 @@ function initSet(peer, config) {
|
||||||
let loadedAccountID = /** @type {string | null} */ (null)
|
let loadedAccountID = /** @type {string | null} */ (null)
|
||||||
let loadPromise = /** @type {Promise<void> | null} */ (null)
|
let loadPromise = /** @type {Promise<void> | null} */ (null)
|
||||||
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null)
|
||||||
const watch = /**@type {ObzType}*/ (Obz())
|
const watch = /**@type {ObzType<Event>}*/ (Obz())
|
||||||
const tangles = /** @type {Map<Subdomain, MsgV4.Tangle>} */ (new Map())
|
const tangles = /** @type {Map<Subdomain, MsgV4.Tangle>} */ (new Map())
|
||||||
|
|
||||||
const itemRoots = {
|
const itemRoots = {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
"include": ["lib/**/*.js"],
|
"include": ["declarations", "lib/**/*.js"],
|
||||||
"exclude": ["coverage/", "node_modules/", "test/"],
|
"exclude": ["coverage/", "node_modules/", "test/"],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
|
@ -11,6 +11,7 @@
|
||||||
"module": "node16",
|
"module": "node16",
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"target": "es2022"
|
"target": "es2022",
|
||||||
|
"typeRoots": ["node_modules/@types", "declarations"]
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue