diff --git a/.gitignore b/.gitignore index 3a1f1fd..aec2bbe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,7 @@ node_modules pnpm-lock.yaml package-lock.json coverage -**/*.d.ts +lib/**/*.d.ts *~ # For misc scripts and experiments: diff --git a/declarations/obz.d.ts b/declarations/obz.d.ts new file mode 100644 index 0000000..11de2fc --- /dev/null +++ b/declarations/obz.d.ts @@ -0,0 +1,10 @@ +declare module 'obz' { + type Remove = () => void + export interface Obz { + (listener: (value: X) => void): Remove + set(value: X): unknown + value: X + } + function createObz(): Obz + export = createObz +} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js index 70a1eac..958318c 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,3 @@ -// @ts-ignore const Obz = require('obz') const MsgV4 = require('ppppp-db/msg-v4') @@ -24,9 +23,7 @@ const PREFIX = 'set_v1__' * del: Array, * supersedes: Array, * }} SetMsgData - * @typedef {{ - * set: (ev: { event: 'add' | 'del', subdomain: string, value: string }) => void - * }} ObzType + * @typedef {{ event: 'add' | 'del', subdomain: string, value: string }} Event * @typedef {{ * set?: { * ghostSpan?: number @@ -39,6 +36,11 @@ const PREFIX = 'set_v1__' * @typedef {import('ppppp-db/msg-v4').Msg} Msg */ +/** + * @template T + * @typedef {import('obz').Obz} ObzType + */ + /** * @template T * @typedef {T extends void ? @@ -84,7 +86,7 @@ function initSet(peer, config) { let loadedAccountID = /** @type {string | null} */ (null) let loadPromise = /** @type {Promise | null} */ (null) let cancelOnRecordAdded = /** @type {CallableFunction | null} */ (null) - const watch = /**@type {ObzType}*/ (Obz()) + const watch = /**@type {ObzType}*/ (Obz()) const tangles = /** @type {Map} */ (new Map()) const itemRoots = { diff --git a/tsconfig.json b/tsconfig.json index cc6e7af..7bd7313 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["lib/**/*.js"], + "include": ["declarations", "lib/**/*.js"], "exclude": ["coverage/", "node_modules/", "test/"], "compilerOptions": { "checkJs": true, @@ -11,6 +11,7 @@ "module": "node16", "skipLibCheck": true, "strict": true, - "target": "es2022" + "target": "es2022", + "typeRoots": ["node_modules/@types", "declarations"] } } \ No newline at end of file