From c90233a6a12f2a91a37007728afd61e56d174b80 Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Tue, 6 Sep 2022 12:40:44 -0700 Subject: [PATCH] feat: consolidate types (#10) * feat: consolidate types * chore: fix lint errors --- .eslintrc.json | 19 +++++++ package.json | 3 +- src/add-all.js | 20 +++----- src/add.js | 7 +-- src/bitswap/stat.js | 7 +-- src/bitswap/unwant.js | 7 +-- src/bitswap/wantlist-for-peer.js | 7 +-- src/bitswap/wantlist.js | 7 +-- src/block/get.js | 7 +-- src/block/put.js | 9 +--- src/block/rm.js | 10 +--- src/block/stat.js | 7 +-- src/bootstrap/add.js | 7 +-- src/bootstrap/clear.js | 7 +-- src/bootstrap/list.js | 7 +-- src/bootstrap/reset.js | 7 +-- src/bootstrap/rm.js | 7 +-- src/cat.js | 7 +-- src/commands.js | 7 +-- src/config/get-all.js | 7 +-- src/config/get.js | 7 +-- src/config/profiles/apply.js | 7 +-- src/config/profiles/list.js | 7 +-- src/config/replace.js | 7 +-- src/config/set.js | 7 +-- src/dag/export.js | 7 +-- src/dag/get.js | 11 ++-- src/dag/import.js | 7 +-- src/dag/index.js | 2 +- src/dag/put.js | 9 +--- src/dag/resolve.js | 7 +-- src/dht/find-peer.js | 7 +-- src/dht/find-provs.js | 7 +-- src/dht/get.js | 7 +-- src/dht/map-event.js | 10 ++-- src/dht/provide.js | 10 +--- src/dht/put.js | 7 +-- src/dht/query.js | 7 +-- src/diag/cmds.js | 7 +-- src/diag/net.js | 7 +-- src/diag/sys.js | 7 +-- src/dns.js | 7 +-- src/files/chmod.js | 7 +-- src/files/cp.js | 9 +--- src/files/flush.js | 7 +-- src/files/ls.js | 6 +-- src/files/mkdir.js | 7 +-- src/files/mv.js | 7 +-- src/files/read.js | 7 +-- src/files/rm.js | 7 +-- src/files/stat.js | 7 +-- src/files/touch.js | 7 +-- src/files/write.js | 7 +-- src/get.js | 7 +-- src/id.js | 7 +-- src/index.js | 24 ++++----- src/is-online.js | 7 +-- src/key/export.js | 7 +-- src/key/gen.js | 7 +-- src/key/import.js | 7 +-- src/key/info.js | 7 +-- src/key/list.js | 7 +-- src/key/rename.js | 7 +-- src/key/rm.js | 7 +-- src/lib/configure.js | 23 ++------- src/lib/core.js | 3 +- src/lib/parse-mtime.js | 2 +- src/lib/resolve.js | 10 ++-- src/log/level.js | 7 +-- src/log/ls.js | 7 +-- src/log/tail.js | 7 +-- src/ls.js | 9 +--- src/mount.js | 7 +-- src/name/index.js | 1 + src/name/publish.js | 7 ++- src/name/pubsub/cancel.js | 7 ++- src/name/pubsub/index.js | 1 + src/name/pubsub/state.js | 7 +-- src/name/pubsub/subs.js | 7 +-- src/name/resolve.js | 7 +-- src/object/data.js | 7 +-- src/object/get.js | 7 +-- src/object/index.js | 2 +- src/object/links.js | 7 +-- src/object/new.js | 7 +-- src/object/patch/add-link.js | 7 +-- src/object/patch/append-data.js | 7 +-- src/object/patch/rm-link.js | 7 +-- src/object/patch/set-data.js | 7 +-- src/object/put.js | 9 +--- src/object/stat.js | 7 +-- src/pin/add-all.js | 8 +-- src/pin/add.js | 7 +-- src/pin/ls.js | 9 +--- src/pin/remote/add.js | 7 +-- src/pin/remote/ls.js | 7 +-- src/pin/remote/rm-all.js | 7 +-- src/pin/remote/rm.js | 7 +-- src/pin/remote/service/add.js | 7 +-- src/pin/remote/service/ls.js | 7 +-- src/pin/remote/service/rm.js | 7 +-- src/pin/remote/service/utils.js | 7 +-- src/pin/remote/utils.js | 16 ++---- src/pin/rm-all.js | 8 +-- src/pin/rm.js | 7 +-- src/ping.js | 7 +-- src/pubsub/ls.js | 7 +-- src/pubsub/peers.js | 7 +-- src/pubsub/publish.js | 7 +-- src/pubsub/subscribe.js | 19 +++---- src/pubsub/subscription-tracker.js | 12 ++--- src/pubsub/unsubscribe.js | 10 +--- src/refs/index.js | 9 +--- src/refs/local.js | 7 +-- src/repo/gc.js | 7 +-- src/repo/stat.js | 7 +-- src/repo/version.js | 7 +-- src/resolve.js | 7 +-- src/start.js | 7 +-- src/stats/bw.js | 7 +-- src/stop.js | 7 +-- src/swarm/addrs.js | 7 +-- src/swarm/connect.js | 7 +-- src/swarm/disconnect.js | 7 +-- src/swarm/index.js | 1 + src/swarm/local-addrs.js | 7 +-- src/swarm/peers.js | 8 +-- src/types.ts | 81 ++++++++++++++++++++++++++++-- src/version.js | 7 +-- test/commands.spec.js | 2 +- test/constructor.spec.js | 9 ++++ test/node/agent.js | 5 +- test/node/custom-headers.js | 4 ++ test/ping.spec.js | 4 ++ test/pubsub.spec.js | 2 +- test/utils/throws-async.js | 4 ++ 136 files changed, 304 insertions(+), 781 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 000000000..cc68cab0a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,19 @@ + +{ + "extends": [ + "ipfs" + ], + "env": { + "es2021": true, + "node": true + }, + "parserOptions": { + "sourceType": "module", + "project": "./tsconfig.json" + }, + "rules": { + "no-return-await": "off", + "no-undef-init": "off", + "no-warning-comments": "off" + } +} diff --git a/package.json b/package.json index f74d90f86..ab8d879a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kubo-rpc-client", - "version": "1.0.0", + "version": "0.0.2", "description": "A client library for the Kubo RPC API", "license": "Apache-2.0 OR MIT", "homepage": "https://github.com/ipfs/js-kubo-rpc-client#readme", @@ -191,6 +191,7 @@ "@libp2p/interfaces": "^3.0.3", "aegir": "^37.5.1", "delay": "^5.0.0", + "eslint-config-ipfs": "^3.1.0", "eslint-plugin-jsdoc": "^39.3.6", "go-ipfs": "^0.12.1", "ipfs-core-types": "^0.11.1", diff --git a/src/add-all.js b/src/add-all.js index bb48bdcc6..99159189f 100644 --- a/src/add-all.js +++ b/src/add-all.js @@ -5,17 +5,9 @@ import { multipartRequest } from 'ipfs-core-utils/multipart-request' import { toUrlSearchParams } from './lib/to-url-search-params.js' import { abortSignal } from './lib/abort-signal.js' -/** - * @typedef {import('ipfs-utils/src/types').ProgressFn} IPFSUtilsHttpUploadProgressFn - * @typedef {import('ipfs-core-types/src/root').AddProgressFn} IPFSCoreAddProgressFn - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - * @typedef {import('ipfs-core-types/src/root').AddResult} AddResult - */ - export const createAddAll = configure((api) => { /** - * @type {RootAPI["addAll"]} + * @type {import('./types.js').RootAPI["addAll"]} */ async function * addAll (source, options = {}) { // allow aborting requests on body errors @@ -64,8 +56,8 @@ export const createAddAll = configure((api) => { * * @param {number} total * @param {{name:string, start:number, end:number}[]|null} parts - * @param {IPFSCoreAddProgressFn} progress - * @returns {[IPFSCoreAddProgressFn|undefined, IPFSUtilsHttpUploadProgressFn|undefined]} + * @param {import('./types.js').IPFSCoreAddProgressFn} progress + * @returns {[import('./types.js').IPFSCoreAddProgressFn|undefined, import('./types.js').IPFSUtilsHttpUploadProgressFn|undefined]} */ const createProgressHandler = (total, parts, progress) => parts ? [undefined, createOnUploadProgress(total, parts, progress)] : [progress, undefined] @@ -76,8 +68,8 @@ const createProgressHandler = (total, parts, progress) => * * @param {number} size - actual content size * @param {{name:string, start:number, end:number}[]} parts - * @param {IPFSCoreAddProgressFn} progress - * @returns {IPFSUtilsHttpUploadProgressFn} + * @param {import('./types.js').IPFSCoreAddProgressFn} progress + * @returns {import('./types.js').IPFSUtilsHttpUploadProgressFn} */ const createOnUploadProgress = (size, parts, progress) => { let index = 0 @@ -111,7 +103,7 @@ const createOnUploadProgress = (size, parts, progress) => { * @param {number} [input.mtimeNsecs] */ function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) { - /** @type {AddResult} */ + /** @type {import('./types.js').AddResult} */ const output = { path: name, cid: CID.parse(hash), diff --git a/src/add.js b/src/add.js index 3ae7497ff..1bf6ff8c0 100644 --- a/src/add.js +++ b/src/add.js @@ -3,11 +3,6 @@ import last from 'it-last' import { configure } from './lib/configure.js' import { normaliseInput } from 'ipfs-core-utils/files/normalise-input-single' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - /** * @param {import('./types').Options} options */ @@ -15,7 +10,7 @@ export function createAdd (options) { const all = createAddAll(options) return configure(() => { /** - * @type {RootAPI["add"]} + * @type {import('./types').RootAPI["add"]} */ async function add (input, options = {}) { // @ts-expect-error - last may return undefined if source is empty diff --git a/src/bitswap/stat.js b/src/bitswap/stat.js index eca5d9804..e7a609a6f 100644 --- a/src/bitswap/stat.js +++ b/src/bitswap/stat.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { peerIdFromString } from '@libp2p/peer-id' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bitswap').API} BitswapAPI - */ - export const createStat = configure(api => { /** - * @type {BitswapAPI["stat"]} + * @type {import('../types').BitswapAPI["stat"]} */ async function stat (options = {}) { const res = await api.post('bitswap/stat', { diff --git a/src/bitswap/unwant.js b/src/bitswap/unwant.js index d2e93f8b1..7161d572c 100644 --- a/src/bitswap/unwant.js +++ b/src/bitswap/unwant.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bitswap').API} BitswapAPI - */ - export const createUnwant = configure(api => { /** - * @type {BitswapAPI["unwant"]} + * @type {import('../types').BitswapAPI["unwant"]} */ async function unwant (cid, options = {}) { const res = await api.post('bitswap/unwant', { diff --git a/src/bitswap/wantlist-for-peer.js b/src/bitswap/wantlist-for-peer.js index 8a7a9fd15..3c051b3fd 100644 --- a/src/bitswap/wantlist-for-peer.js +++ b/src/bitswap/wantlist-for-peer.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bitswap').API} BitswapAPI - */ - export const createWantlistForPeer = configure(api => { /** - * @type {BitswapAPI["wantlistForPeer"]} + * @type {import('../types').BitswapAPI["wantlistForPeer"]} */ async function wantlistForPeer (peerId, options = {}) { const res = await (await api.post('bitswap/wantlist', { diff --git a/src/bitswap/wantlist.js b/src/bitswap/wantlist.js index 268327ca3..98daabd02 100644 --- a/src/bitswap/wantlist.js +++ b/src/bitswap/wantlist.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bitswap').API} BitswapAPI - */ - export const createWantlist = configure(api => { /** - * @type {BitswapAPI["wantlist"]} + * @type {import('../types').BitswapAPI["wantlist"]} */ async function wantlist (options = {}) { const res = await (await api.post('bitswap/wantlist', { diff --git a/src/block/get.js b/src/block/get.js index 07764a143..2bd0f4410 100644 --- a/src/block/get.js +++ b/src/block/get.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/block').API} BlockAPI - */ - export const createGet = configure(api => { /** - * @type {BlockAPI["get"]} + * @type {import('../types').BlockAPI["get"]} */ async function get (cid, options = {}) { const res = await api.post('block/get', { diff --git a/src/block/put.js b/src/block/put.js index 40e83b62f..5e0a92f84 100644 --- a/src/block/put.js +++ b/src/block/put.js @@ -4,14 +4,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { abortSignal } from '../lib/abort-signal.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/block').API} BlockAPI - */ - export const createPut = configure(api => { /** - * @type {BlockAPI["put"]} + * @type {import('../types').BlockAPI["put"]} */ async function put (data, options = {}) { // allow aborting requests on body errors @@ -21,7 +16,7 @@ export const createPut = configure(api => { let res try { const response = await api.post('block/put', { - signal: signal, + signal, searchParams: toUrlSearchParams(options), ...( await multipartRequest([data], controller, options.headers) diff --git a/src/block/rm.js b/src/block/rm.js index 0f2b930ed..508243876 100644 --- a/src/block/rm.js +++ b/src/block/rm.js @@ -2,15 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/block').API} BlockAPI - * @typedef {import('ipfs-core-types/src/block').RmResult} RmResult - */ - export const createRm = configure(api => { /** - * @type {BlockAPI["rm"]} + * @type {import('../types').BlockAPI["rm"]} */ async function * rm (cid, options = {}) { if (!Array.isArray(cid)) { @@ -39,7 +33,7 @@ export const createRm = configure(api => { * @param {*} removed */ function toCoreInterface (removed) { - /** @type {RmResult} */ + /** @type {import('../types').RmResult} */ const out = { cid: CID.parse(removed.Hash) } diff --git a/src/block/stat.js b/src/block/stat.js index f136525d9..489831938 100644 --- a/src/block/stat.js +++ b/src/block/stat.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/block').API} BlockAPI - */ - export const createStat = configure(api => { /** - * @type {BlockAPI["stat"]} + * @type {import('../types').BlockAPI["stat"]} */ async function stat (cid, options = {}) { const res = await api.post('block/stat', { diff --git a/src/bootstrap/add.js b/src/bootstrap/add.js index 7c07e48d3..3b9c3e14e 100644 --- a/src/bootstrap/add.js +++ b/src/bootstrap/add.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { Multiaddr } from '@multiformats/multiaddr' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bootstrap').API} BootstrapAPI - */ - export const createAdd = configure(api => { /** - * @type {BootstrapAPI["add"]} + * @type {import('../types').BootstrapAPI["add"]} */ async function add (addr, options = {}) { const res = await api.post('bootstrap/add', { diff --git a/src/bootstrap/clear.js b/src/bootstrap/clear.js index e029343ca..a1dc876ea 100644 --- a/src/bootstrap/clear.js +++ b/src/bootstrap/clear.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { Multiaddr } from '@multiformats/multiaddr' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bootstrap').API} BootstrapAPI - */ - export const createClear = configure(api => { /** - * @type {BootstrapAPI["clear"]} + * @type {import('../types').BootstrapAPI["clear"]} */ async function clear (options = {}) { const res = await api.post('bootstrap/rm', { diff --git a/src/bootstrap/list.js b/src/bootstrap/list.js index 79be9211f..9373988c8 100644 --- a/src/bootstrap/list.js +++ b/src/bootstrap/list.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { Multiaddr } from '@multiformats/multiaddr' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bootstrap').API} BootstrapAPI - */ - export const createList = configure(api => { /** - * @type {BootstrapAPI["list"]} + * @type {import('../types').BootstrapAPI["list"]} */ async function list (options = {}) { const res = await api.post('bootstrap/list', { diff --git a/src/bootstrap/reset.js b/src/bootstrap/reset.js index 30ac17033..38cab0f13 100644 --- a/src/bootstrap/reset.js +++ b/src/bootstrap/reset.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { Multiaddr } from '@multiformats/multiaddr' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bootstrap').API} BootstrapAPI - */ - export const createReset = configure(api => { /** - * @type {BootstrapAPI["reset"]} + * @type {import('../types.js').BootstrapAPI["reset"]} */ async function reset (options = {}) { const res = await api.post('bootstrap/add', { diff --git a/src/bootstrap/rm.js b/src/bootstrap/rm.js index d84b23d3d..a519cef52 100644 --- a/src/bootstrap/rm.js +++ b/src/bootstrap/rm.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { Multiaddr } from '@multiformats/multiaddr' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/bootstrap').API} BootstrapAPI - */ - export const createRm = configure(api => { /** - * @type {BootstrapAPI["rm"]} + * @type {import('../types').BootstrapAPI["rm"]} */ async function rm (addr, options = {}) { const res = await api.post('bootstrap/rm', { diff --git a/src/cat.js b/src/cat.js index b28e3df12..700b35e1f 100644 --- a/src/cat.js +++ b/src/cat.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createCat = configure(api => { /** - * @type {RootAPI["cat"]} + * @type {import('./types').RootAPI["cat"]} */ async function * cat (path, options = {}) { const res = await api.post('cat', { diff --git a/src/commands.js b/src/commands.js index 9949f864b..6556b56f9 100644 --- a/src/commands.js +++ b/src/commands.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createCommands = configure(api => { /** - * @type {RootAPI["commands"]} + * @type {import('./types').RootAPI["commands"]} */ const commands = async (options = {}) => { const res = await api.post('commands', { diff --git a/src/config/get-all.js b/src/config/get-all.js index efd547832..57f19d4a0 100644 --- a/src/config/get-all.js +++ b/src/config/get-all.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config').API} ConfigAPI - */ - export const createGetAll = configure(api => { /** - * @type {ConfigAPI["getAll"]} + * @type {import('../types.js').ConfigAPI["getAll"]} */ const getAll = async (options = {}) => { const res = await api.post('config/show', { diff --git a/src/config/get.js b/src/config/get.js index dc422247f..54fd2c0e3 100644 --- a/src/config/get.js +++ b/src/config/get.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config').API} ConfigAPI - */ - export const createGet = configure(api => { /** - * @type {ConfigAPI["get"]} + * @type {import('../types.js').ConfigAPI["get"]} */ const get = async (key, options = {}) => { if (!key) { diff --git a/src/config/profiles/apply.js b/src/config/profiles/apply.js index 2e8ac2a6b..eaf5bfdf1 100644 --- a/src/config/profiles/apply.js +++ b/src/config/profiles/apply.js @@ -1,14 +1,9 @@ import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config/profiles').API} ConfigProfilesAPI - */ - export const createApply = configure(api => { /** - * @type {ConfigProfilesAPI["apply"]} + * @type {import('../../types').ConfigProfilesAPI["apply"]} */ async function apply (profile, options = {}) { const res = await api.post('config/profile/apply', { diff --git a/src/config/profiles/list.js b/src/config/profiles/list.js index 5692245cf..f518b06c7 100644 --- a/src/config/profiles/list.js +++ b/src/config/profiles/list.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../../lib/object-to-camel.js' import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config/profiles').API} ConfigProfilesAPI - */ - export const createList = configure(api => { /** - * @type {ConfigProfilesAPI["list"]} + * @type {import('../../types.js').ConfigProfilesAPI["list"]} */ async function list (options = {}) { const res = await api.post('config/profile/list', { diff --git a/src/config/replace.js b/src/config/replace.js index ac14bcfbf..15665e7e9 100644 --- a/src/config/replace.js +++ b/src/config/replace.js @@ -4,14 +4,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { abortSignal } from '../lib/abort-signal.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config').API} ConfigAPI - */ - export const createReplace = configure(api => { /** - * @type {ConfigAPI["replace"]} + * @type {import('../types.js').ConfigAPI["replace"]} */ const replace = async (config, options = {}) => { // allow aborting requests on body errors diff --git a/src/config/set.js b/src/config/set.js index 7c4910f0f..d03ec0617 100644 --- a/src/config/set.js +++ b/src/config/set.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/config').API} ConfigAPI - */ - export const createSet = configure(api => { /** - * @type {ConfigAPI["set"]} + * @type {import('../types.js').ConfigAPI["set"]} */ const set = async (key, value, options = {}) => { if (typeof key !== 'string') { diff --git a/src/dag/export.js b/src/dag/export.js index eb66d2655..811beacf5 100644 --- a/src/dag/export.js +++ b/src/dag/export.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dag').API} DAGAPI - */ - export const createExport = configure(api => { /** - * @type {DAGAPI["export"]} + * @type {import('../types').DAGAPI["export"]} */ async function * dagExport (root, options = {}) { const res = await api.post('dag/export', { diff --git a/src/dag/get.js b/src/dag/get.js index 5a4026bbb..6bb9da3cf 100644 --- a/src/dag/get.js +++ b/src/dag/get.js @@ -6,12 +6,7 @@ import errCode from 'err-code' import { createGet as createBlockGet } from '../block/get.js' /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dag').API} DAGAPI - */ - -/** - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs + * @param {import('../types').Multicodecs} codecs * @param {import('../types').Options} options */ export const createGet = (codecs, options) => { @@ -19,14 +14,14 @@ export const createGet = (codecs, options) => { const getBlock = createBlockGet(opts) /** - * @type {DAGAPI["get"]} + * @type {import('../types').DAGAPI["get"]} */ const get = async (cid, options = {}) => { if (options.path) { const entry = options.localResolve ? await first(resolve(cid, options.path, codecs, getBlock, options)) : await last(resolve(cid, options.path, codecs, getBlock, options)) - /** @type {import('ipfs-core-types/src/dag').GetResult | undefined} - first and last will return undefined when empty */ + /** @type {import('../types').GetResult | undefined} - first and last will return undefined when empty */ const result = (entry) if (!result) { diff --git a/src/dag/import.js b/src/dag/import.js index cc2830a11..afd62ee66 100644 --- a/src/dag/import.js +++ b/src/dag/import.js @@ -4,14 +4,9 @@ import { abortSignal } from '../lib/abort-signal.js' import { multipartRequest } from 'ipfs-core-utils/multipart-request' import { CID } from 'multiformats/cid' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dag').API} DAGAPI - */ - export const createImport = configure(api => { /** - * @type {DAGAPI["import"]} + * @type {import('../types.js').DAGAPI["import"]} */ async function * dagImport (source, options = {}) { const controller = new AbortController() diff --git a/src/dag/index.js b/src/dag/index.js index 3bb258ef0..4d2f9986e 100644 --- a/src/dag/index.js +++ b/src/dag/index.js @@ -5,7 +5,7 @@ import { createPut } from './put.js' import { createResolve } from './resolve.js' /** - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs + * @param {import('../types').Multicodecs} codecs * @param {import('../types').Options} config */ export function createDag (codecs, config) { diff --git a/src/dag/put.js b/src/dag/put.js index 548ac7d54..85f1cd844 100644 --- a/src/dag/put.js +++ b/src/dag/put.js @@ -5,18 +5,13 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { abortSignal } from '../lib/abort-signal.js' /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dag').API} DAGAPI - */ - -/** - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs + * @param {import('../types').Multicodecs} codecs * @param {import('../types').Options} options */ export const createPut = (codecs, options) => { const fn = configure((api) => { /** - * @type {DAGAPI["put"]} + * @type {import('../types').DAGAPI["put"]} */ const put = async (dagNode, options = {}) => { const settings = { diff --git a/src/dag/resolve.js b/src/dag/resolve.js index 8fcc663e2..c75ecd971 100644 --- a/src/dag/resolve.js +++ b/src/dag/resolve.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dag').API} DAGAPI - */ - export const createResolve = configure(api => { /** - * @type {DAGAPI["resolve"]} + * @type {import('../types.js').DAGAPI["resolve"]} */ const resolve = async (ipfsPath, options = {}) => { const res = await api.post('dag/resolve', { diff --git a/src/dht/find-peer.js b/src/dht/find-peer.js index 22c76b563..328c2683e 100644 --- a/src/dht/find-peer.js +++ b/src/dht/find-peer.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { mapEvent } from './map-event.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - */ - export const createFindPeer = configure(api => { /** - * @type {DHTAPI["findPeer"]} + * @type {import('../types').DHTAPI["findPeer"]} */ async function * findPeer (peerId, options = {}) { const res = await api.post('dht/findpeer', { diff --git a/src/dht/find-provs.js b/src/dht/find-provs.js index 46f0312cd..6479f8d73 100644 --- a/src/dht/find-provs.js +++ b/src/dht/find-provs.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { mapEvent } from './map-event.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - */ - export const createFindProvs = configure(api => { /** - * @type {DHTAPI["findProvs"]} + * @type {import('../types.js').DHTAPI["findProvs"]} */ async function * findProvs (cid, options = {}) { const res = await api.post('dht/findprovs', { diff --git a/src/dht/get.js b/src/dht/get.js index db9dac593..03d60d0db 100644 --- a/src/dht/get.js +++ b/src/dht/get.js @@ -3,14 +3,9 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { mapEvent } from './map-event.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - */ - export const createGet = configure(api => { /** - * @type {DHTAPI["get"]} + * @type {import('../types').DHTAPI["get"]} */ async function * get (key, options = {}) { const res = await api.post('dht/get', { diff --git a/src/dht/map-event.js b/src/dht/map-event.js index c08cd50f3..25dc620db 100644 --- a/src/dht/map-event.js +++ b/src/dht/map-event.js @@ -13,12 +13,8 @@ import { Multiaddr } from '@multiformats/multiaddr' import { peerIdFromString } from '@libp2p/peer-id' /** - * @typedef {import('@libp2p/interface-peer-id').PeerId} PeerId - */ - -/** - * @param {{Type: number, ID: string, Extra: string, Responses: {ID: string, Addrs: string[]}[]}} event - * @returns {import('ipfs-core-types/src/dht').QueryEvent} + * @param {import('../types').MapEvent} event + * @returns {import('../types').QueryEvent} */ export const mapEvent = (event) => { if (event.Type === SendingQuery) { @@ -46,7 +42,7 @@ export const mapEvent = (event) => { if (event.Type === FinalPeer) { // dht.query ends with a FinalPeer event with no Responses - /** @type {import('@libp2p/interface-peer-info').PeerInfo} */ + /** @type {import('../types.js').PeerInfo} */ let peer = { // @ts-expect-error go-ipfs does not return this id: event.ID ?? peerIdFromString(event.ID), diff --git a/src/dht/provide.js b/src/dht/provide.js index baeefbb2c..e63ce938f 100644 --- a/src/dht/provide.js +++ b/src/dht/provide.js @@ -2,18 +2,12 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { mapEvent } from './map-event.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - * @typedef {import('multiformats/cid').CID} CID - */ - export const createProvide = configure(api => { /** - * @type {DHTAPI["provide"]} + * @type {import('../types').DHTAPI["provide"]} */ async function * provide (cids, options = { recursive: false }) { - /** @type {CID[]} */ + /** @type {import('../types').CID[]} */ const cidArr = Array.isArray(cids) ? cids : [cids] const res = await api.post('dht/provide', { diff --git a/src/dht/put.js b/src/dht/put.js index b6d220c71..15dc6b66f 100644 --- a/src/dht/put.js +++ b/src/dht/put.js @@ -5,14 +5,9 @@ import { abortSignal } from '../lib/abort-signal.js' import { toString as uint8ArrayToString } from 'uint8arrays/to-string' import { mapEvent } from './map-event.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - */ - export const createPut = configure(api => { /** - * @type {DHTAPI["put"]} + * @type {import('../types.js').DHTAPI["put"]} */ async function * put (key, value, options = {}) { // allow aborting requests on body errors diff --git a/src/dht/query.js b/src/dht/query.js index 3f4465eae..e5af1be65 100644 --- a/src/dht/query.js +++ b/src/dht/query.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { mapEvent } from './map-event.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/dht').API} DHTAPI - */ - export const createQuery = configure(api => { /** - * @type {DHTAPI["query"]} + * @type {import('../types.js').DHTAPI["query"]} */ async function * query (peerId, options = {}) { const res = await api.post('dht/query', { diff --git a/src/diag/cmds.js b/src/diag/cmds.js index 291763908..981b57f07 100644 --- a/src/diag/cmds.js +++ b/src/diag/cmds.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/diag').API} DiagAPI - */ - export const createCmds = configure(api => { /** - * @type {DiagAPI["cmds"]} + * @type {import('../types').DiagAPI["cmds"]} */ async function cmds (options = {}) { const res = await api.post('diag/cmds', { diff --git a/src/diag/net.js b/src/diag/net.js index a4cad916e..357720fe6 100644 --- a/src/diag/net.js +++ b/src/diag/net.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/diag').API} DiagAPI - */ - export const createNet = configure(api => { /** - * @type {DiagAPI["net"]} + * @type {import('../types').DiagAPI["net"]} */ async function net (options = {}) { const res = await api.post('diag/net', { diff --git a/src/diag/sys.js b/src/diag/sys.js index c7500be06..13e86175b 100644 --- a/src/diag/sys.js +++ b/src/diag/sys.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/diag').API} DiagAPI - */ - export const createSys = configure(api => { /** - * @type {DiagAPI["sys"]} + * @type {import('../types').DiagAPI["sys"]} */ async function sys (options = {}) { const res = await api.post('diag/sys', { diff --git a/src/dns.js b/src/dns.js index 89c4a2f6e..fae5d5f89 100644 --- a/src/dns.js +++ b/src/dns.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createDns = configure(api => { /** - * @type {RootAPI["dns"]} + * @type {import('./types').RootAPI["dns"]} */ const dns = async (domain, options = {}) => { const res = await api.post('dns', { diff --git a/src/files/chmod.js b/src/files/chmod.js index d5317969e..1e0b1b2df 100644 --- a/src/files/chmod.js +++ b/src/files/chmod.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createChmod = configure(api => { /** - * @type {FilesAPI["chmod"]} + * @type {import('../types.js').FilesAPI["chmod"]} */ async function chmod (path, mode, options = {}) { const res = await api.post('files/chmod', { diff --git a/src/files/cp.js b/src/files/cp.js index 15086e6f4..86a34eb2b 100644 --- a/src/files/cp.js +++ b/src/files/cp.js @@ -2,17 +2,12 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createCp = configure(api => { /** - * @type {FilesAPI["cp"]} + * @type {import('../types').FilesAPI["cp"]} */ async function cp (sources, destination, options = {}) { - /** @type {import('ipfs-core-types/src/utils').IPFSPath[]} */ + /** @type {import('../types').IPFSPath[]} */ const sourceArr = Array.isArray(sources) ? sources : [sources] const res = await api.post('files/cp', { diff --git a/src/files/flush.js b/src/files/flush.js index 178435316..e607299c0 100644 --- a/src/files/flush.js +++ b/src/files/flush.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createFlush = configure(api => { /** - * @type {FilesAPI["flush"]} + * @type {import('../types').FilesAPI["flush"]} */ async function flush (path, options = {}) { if (!path || typeof path !== 'string') { diff --git a/src/files/ls.js b/src/files/ls.js index cd125f192..90204ee5d 100644 --- a/src/files/ls.js +++ b/src/files/ls.js @@ -3,13 +3,9 @@ import { objectToCamelWithMetadata } from '../lib/object-to-camel-with-metadata. import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ export const createLs = configure(api => { /** - * @type {FilesAPI["ls"]} + * @type {import('../types').FilesAPI["ls"]} */ async function * ls (path, options = {}) { if (!path) { diff --git a/src/files/mkdir.js b/src/files/mkdir.js index a81344c54..c6c1efae7 100644 --- a/src/files/mkdir.js +++ b/src/files/mkdir.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createMkdir = configure(api => { /** - * @type {FilesAPI["mkdir"]} + * @type {import('../types').FilesAPI["mkdir"]} */ async function mkdir (path, options = {}) { const res = await api.post('files/mkdir', { diff --git a/src/files/mv.js b/src/files/mv.js index 2a2ac1aa9..9f0363906 100644 --- a/src/files/mv.js +++ b/src/files/mv.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createMv = configure(api => { /** - * @type {FilesAPI["mv"]} + * @type {import('../types').FilesAPI["mv"]} */ async function mv (sources, destination, options = {}) { if (!Array.isArray(sources)) { diff --git a/src/files/read.js b/src/files/read.js index 73d83355a..41e522080 100644 --- a/src/files/read.js +++ b/src/files/read.js @@ -3,14 +3,9 @@ import { toUrlSearchParams } from '../lib/to-url-search-params.js' // @ts-expect-error no types import toIterable from 'stream-to-it/source.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createRead = configure(api => { /** - * @type {FilesAPI["read"]} + * @type {import('../types').FilesAPI["read"]} */ async function * read (path, options = {}) { const res = await api.post('files/read', { diff --git a/src/files/rm.js b/src/files/rm.js index 03aa688a2..b46669df5 100644 --- a/src/files/rm.js +++ b/src/files/rm.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import HTTP from 'ipfs-utils/src/http.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createRm = configure(api => { /** - * @type {FilesAPI["rm"]} + * @type {import('../types').FilesAPI["rm"]} */ async function rm (path, options = {}) { const res = await api.post('files/rm', { diff --git a/src/files/stat.js b/src/files/stat.js index 83381b265..9ce8ff17d 100644 --- a/src/files/stat.js +++ b/src/files/stat.js @@ -3,14 +3,9 @@ import { objectToCamelWithMetadata } from '../lib/object-to-camel-with-metadata. import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createStat = configure(api => { /** - * @type {FilesAPI["stat"]} + * @type {import('../types').FilesAPI["stat"]} */ async function stat (path, options = {}) { const res = await api.post('files/stat', { diff --git a/src/files/touch.js b/src/files/touch.js index 8a004f7c9..7548efb2f 100644 --- a/src/files/touch.js +++ b/src/files/touch.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createTouch = configure(api => { /** - * @type {FilesAPI["touch"]} + * @type {import('../types').FilesAPI["touch"]} */ async function touch (path, options = {}) { const res = await api.post('files/touch', { diff --git a/src/files/write.js b/src/files/write.js index 74796fcae..4e95accb2 100644 --- a/src/files/write.js +++ b/src/files/write.js @@ -5,14 +5,9 @@ import { multipartRequest } from 'ipfs-core-utils/multipart-request' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { abortSignal } from '../lib/abort-signal.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/files').API} FilesAPI - */ - export const createWrite = configure(api => { /** - * @type {FilesAPI["write"]} + * @type {import('../types').FilesAPI["write"]} */ async function write (path, input, options = {}) { // allow aborting requests on body errors diff --git a/src/get.js b/src/get.js index d01d23fcd..ce4ce78b6 100644 --- a/src/get.js +++ b/src/get.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createGet = configure(api => { /** - * @type {RootAPI["get"]} + * @type {import('./types').RootAPI["get"]} */ async function * get (path, options = {}) { /** @type {Record} */ diff --git a/src/id.js b/src/id.js index 00375d710..9ee878b61 100644 --- a/src/id.js +++ b/src/id.js @@ -4,14 +4,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' import { peerIdFromString } from '@libp2p/peer-id' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createId = configure(api => { /** - * @type {RootAPI["id"]} + * @type {import('./types').RootAPI["id"]} */ async function id (options = {}) { const res = await api.post('id', { diff --git a/src/index.js b/src/index.js index 2bc2340e7..42e69f7bc 100644 --- a/src/index.js +++ b/src/index.js @@ -46,9 +46,7 @@ import { createVersion } from './version.js' import globSourceImport from 'ipfs-utils/src/files/glob-source.js' /** - * @typedef {import('multiformats/codecs/interface').BlockCodec} BlockCodec - * @typedef {import('multiformats/hashes/interface').MultihashHasher} MultihashHasher - * @typedef {import('multiformats/bases/interface').MultibaseCodec} MultibaseCodec + * * @typedef {import('./types').Options} Options * @typedef {import('./types').LoadBaseFn} LoadBaseFn * @typedef {import('./types').LoadCodecFn} LoadCodecFn @@ -60,11 +58,11 @@ import globSourceImport from 'ipfs-utils/src/files/glob-source.js' */ /** - * @param {Options} options + * @param {import('./types').Options} options */ export function create (options = {}) { /** - * @type {BlockCodec} + * @type {import('./types').BlockCodec} */ const id = { name: identity.name, @@ -73,7 +71,7 @@ export function create (options = {}) { decode: (id) => id } - /** @type {MultibaseCodec[]} */ + /** @type {import('./types').MultibaseCodec[]} */ const multibaseCodecs = Object.values(bases); (options.ipld && options.ipld.bases ? options.ipld.bases : []).forEach(base => multibaseCodecs.push(base)) @@ -83,7 +81,7 @@ export function create (options = {}) { loadBase: options.ipld && options.ipld.loadBase }) - /** @type {BlockCodec[]} */ + /** @type {import('./types').BlockCodec[]} */ const blockCodecs = Object.values(codecs); [dagPB, dagCBOR, dagJSON, dagJOSE, id].concat((options.ipld && options.ipld.codecs) || []).forEach(codec => blockCodecs.push(codec)) @@ -93,7 +91,7 @@ export function create (options = {}) { loadCodec: options.ipld && options.ipld.loadCodec }) - /** @type {MultihashHasher[]} */ + /** @type {import('./types').MultihashHasher[]} */ const multihashHashers = Object.values(hashes); (options.ipld && options.ipld.hashers ? options.ipld.hashers : []).forEach(hasher => multihashHashers.push(hasher)) @@ -122,13 +120,13 @@ export function create (options = {}) { getEndpointConfig: createGetEndpointConfig(options), id: createId(options), isOnline: createIsOnline(options), - key: createKey(options), + key: /** @type {import('./types').IPFS['key']} */(createKey(options)), log: createLog(options), ls: createLs(options), mount: createMount(options), - name: createName(options), + name: /** @type {import('./types').IPFS['name']} */(createName(options)), object: createObject(multicodecs, options), - pin: createPin(options), + pin: /** @type {import('./types').IPFS['pin']} */(createPin(options)), ping: createPing(options), pubsub: createPubsub(options), refs: createRefs(options), @@ -137,8 +135,8 @@ export function create (options = {}) { start: createStart(options), stats: createStats(options), stop: createStop(options), - swarm: createSwarm(options), - version: createVersion(options), + swarm: /** @type {import('./types').IPFS['swarm']} */(createSwarm(options)), + version: /** @type {import('./types').IPFS['version']} */(createVersion(options)), bases: multibases, codecs: multicodecs, hashers: multihashes diff --git a/src/is-online.js b/src/is-online.js index bd42683b0..56194593c 100644 --- a/src/is-online.js +++ b/src/is-online.js @@ -1,10 +1,5 @@ import { createId } from './id.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - /** * @param {import('./types').Options} options */ @@ -12,7 +7,7 @@ export const createIsOnline = options => { const id = createId(options) /** - * @type {RootAPI["isOnline"]} + * @type {import('./types').RootAPI["isOnline"]} */ async function isOnline (options = {}) { const res = await id(options) diff --git a/src/key/export.js b/src/key/export.js index 3afb13a43..132551328 100644 --- a/src/key/export.js +++ b/src/key/export.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import errCode from 'err-code' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createExport = configure(api => { /** - * @type {KeyAPI["export"]} + * @type {import('../types').KeyAPI["export"]} */ const exportKey = async (name, password, options = {}) => { throw errCode(new Error('Not implemented'), 'ERR_NOT_IMPLEMENTED') diff --git a/src/key/gen.js b/src/key/gen.js index 50a5e634f..4338f3a58 100644 --- a/src/key/gen.js +++ b/src/key/gen.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createGen = configure(api => { /** - * @type {KeyAPI["gen"]} + * @type {import('../types').KeyAPI["gen"]} */ async function gen (name, options = { type: 'Ed25519' }) { const res = await api.post('key/gen', { diff --git a/src/key/import.js b/src/key/import.js index e5aa9477c..fc3f35bfe 100644 --- a/src/key/import.js +++ b/src/key/import.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createImport = configure(api => { /** - * @type {KeyAPI["import"]} + * @type {import('../types').KeyAPI["import"]} */ async function importKey (name, pem, password, options = {}) { const res = await api.post('key/import', { diff --git a/src/key/info.js b/src/key/info.js index 8e8602968..62d7529af 100644 --- a/src/key/info.js +++ b/src/key/info.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import errCode from 'err-code' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createInfo = configure(api => { /** - * @type {KeyAPI["info"]} + * @type {import('../types').KeyAPI["info"]} */ const info = async (name, options = {}) => { throw errCode(new Error('Not implemented'), 'ERR_NOT_IMPLEMENTED') diff --git a/src/key/list.js b/src/key/list.js index 3b53092b5..79d00c7ef 100644 --- a/src/key/list.js +++ b/src/key/list.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createList = configure(api => { /** - * @type {KeyAPI["list"]} + * @type {import('../types.js').KeyAPI["list"]} */ async function list (options = {}) { const res = await api.post('key/list', { diff --git a/src/key/rename.js b/src/key/rename.js index 61b2f8379..c2397825f 100644 --- a/src/key/rename.js +++ b/src/key/rename.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createRename = configure(api => { /** - * @type {KeyAPI["rename"]} + * @type {import('../types').KeyAPI["rename"]} */ async function rename (oldName, newName, options = {}) { const res = await api.post('key/rename', { diff --git a/src/key/rm.js b/src/key/rm.js index 4278167c3..04029c4a1 100644 --- a/src/key/rm.js +++ b/src/key/rm.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/key').API} KeyAPI - */ - export const createRm = configure(api => { /** - * @type {KeyAPI["rm"]} + * @type {import('../types').KeyAPI["rm"]} */ async function rm (name, options = {}) { const res = await api.post('key/rm', { diff --git a/src/lib/configure.js b/src/lib/configure.js index b00dd5217..b13276f7e 100644 --- a/src/lib/configure.js +++ b/src/lib/configure.js @@ -1,27 +1,12 @@ - /* eslint-env browser */ - import { Client } from './core.js' -// Set default configuration and call create function with them -/** - * @typedef { import("../types").Options } Options - */ - -/** - * @template T - * @typedef {(client: Client, clientOptions: Options) => T} Fn - */ - -/** - * @template T - * @typedef {(clientOptions: Options) => T} Factory - */ - /** + * Set default configuration and call create function with them + * * @template T - * @param {Fn} fn - * @returns {Factory} + * @param {import('../types').ConfigureFn} fn + * @returns {import('../types').ConfigureFactory} */ export const configure = (fn) => { return (options) => { diff --git a/src/lib/core.js b/src/lib/core.js index 326fcbf6e..4f9896324 100644 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -18,7 +18,6 @@ const DEFAULT_HOST = isBrowser || isWebWorker ? location.hostname : 'localhost' const DEFAULT_PORT = isBrowser || isWebWorker ? location.port : '5001' /** - * @typedef {import('ipfs-utils/src/types').HTTPOptions} HTTPOptions * @typedef {import('../types').Options} Options */ @@ -194,7 +193,7 @@ export class Client extends HTTP { /** * @param {string | Request} resource - * @param {HTTPOptions} options + * @param {import('../types').HTTPOptions} options */ this.fetch = (resource, options = {}) => { if (typeof resource === 'string' && !resource.startsWith('/')) { diff --git a/src/lib/parse-mtime.js b/src/lib/parse-mtime.js index 89a30164c..20e26bc45 100644 --- a/src/lib/parse-mtime.js +++ b/src/lib/parse-mtime.js @@ -41,7 +41,7 @@ export function parseMtime (input) { const secs = Math.floor(ms / 1000) mtime = { - secs: secs, + secs, nsecs: (ms - (secs * 1000)) * 1000 } } diff --git a/src/lib/resolve.js b/src/lib/resolve.js index b0a1e3205..d4d52afaa 100644 --- a/src/lib/resolve.js +++ b/src/lib/resolve.js @@ -1,18 +1,14 @@ import { CID } from 'multiformats/cid' import errCode from 'err-code' -/** - * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions - */ - /** * Retrieves IPLD Nodes along the `path` that is rooted at `cid`. * * @param {CID} cid - the CID where the resolving starts * @param {string} path - the path that should be resolved - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs - * @param {(cid: CID, options?: AbortOptions) => Promise} getBlock - * @param {AbortOptions} [options] + * @param {import('../types').Multicodecs} codecs + * @param {(cid: CID, options?: import('../types').AbortOptions) => Promise} getBlock + * @param {import('../types').AbortOptions} [options] */ export async function * resolve (cid, path, codecs, getBlock, options) { /** diff --git a/src/log/level.js b/src/log/level.js index f27906932..813c4ebad 100644 --- a/src/log/level.js +++ b/src/log/level.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/log').API} LogAPI - */ - export const createLevel = configure(api => { /** - * @type {LogAPI["level"]} + * @type {import('../types').LogAPI["level"]} */ async function level (subsystem, level, options = {}) { const res = await api.post('log/level', { diff --git a/src/log/ls.js b/src/log/ls.js index 8118cb5f1..9fd1ead44 100644 --- a/src/log/ls.js +++ b/src/log/ls.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/log').API} LogAPI - */ - export const createLs = configure(api => { /** - * @type {LogAPI["ls"]} + * @type {import('../types').LogAPI["ls"]} */ async function ls (options = {}) { const res = await api.post('log/ls', { diff --git a/src/log/tail.js b/src/log/tail.js index a52dd9f6c..23d8a3515 100644 --- a/src/log/tail.js +++ b/src/log/tail.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/log').API} LogAPI - */ - export const createTail = configure(api => { /** - * @type {LogAPI["tail"]} + * @type {import('../types').LogAPI["tail"]} */ async function * tail (options = {}) { const res = await api.post('log/tail', { diff --git a/src/ls.js b/src/ls.js index f2f4083fc..291d70638 100644 --- a/src/ls.js +++ b/src/ls.js @@ -3,14 +3,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' import { createStat } from './files/stat.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createLs = configure((api, opts) => { /** - * @type {RootAPI["ls"]} + * @type {import('./types').RootAPI["ls"]} */ async function * ls (path, options = {}) { const pathStr = `${path instanceof Uint8Array ? CID.decode(path) : path}` @@ -31,7 +26,7 @@ export const createLs = configure((api, opts) => { hash = CID.parse(hash) } - /** @type {import('ipfs-core-types/src/root').IPFSEntry} */ + /** @type {import('./types').IPFSEntry} */ const entry = { name: link.Name, path: pathStr + (link.Name ? `/${link.Name}` : ''), diff --git a/src/mount.js b/src/mount.js index 171461174..814185e33 100644 --- a/src/mount.js +++ b/src/mount.js @@ -2,14 +2,9 @@ import { objectToCamel } from './lib/object-to-camel.js' import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createMount = configure(api => { /** - * @type {RootAPI["mount"]} + * @type {import('./types').RootAPI["mount"]} */ async function mount (options = {}) { const res = await api.post('dns', { diff --git a/src/name/index.js b/src/name/index.js index ef7123cd1..da8e0d002 100644 --- a/src/name/index.js +++ b/src/name/index.js @@ -4,6 +4,7 @@ import { createPubsub } from './pubsub/index.js' /** * @param {import('../types').Options} config + * @returns {import('../types').IPFS['name']} */ export function createName (config) { return { diff --git a/src/name/publish.js b/src/name/publish.js index a8361f96a..b3c289336 100644 --- a/src/name/publish.js +++ b/src/name/publish.js @@ -3,13 +3,12 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/name').API} NameAPI + * @param {import('../types').Options} config + * @returns {import('../types').IPFS['publish']} */ - export const createPublish = configure(api => { /** - * @type {NameAPI["publish"]} + * @type {import('../types.js').NameAPI["publish"]} */ async function publish (path, options = {}) { const res = await api.post('name/publish', { diff --git a/src/name/pubsub/cancel.js b/src/name/pubsub/cancel.js index 74bf85b5f..437f985ec 100644 --- a/src/name/pubsub/cancel.js +++ b/src/name/pubsub/cancel.js @@ -3,13 +3,12 @@ import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' /** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/name/pubsub').API} NamePubsubAPI + * @param {import('../../types').Options} config + * @returns {import('../../types').NamePubsubAPI["cancel"]} */ - export const createCancel = configure(api => { /** - * @type {NamePubsubAPI["cancel"]} + * @type {import('../../types').NamePubsubAPI["cancel"]} */ async function cancel (name, options = {}) { const res = await api.post('name/pubsub/cancel', { diff --git a/src/name/pubsub/index.js b/src/name/pubsub/index.js index d7e9d4d41..56137193d 100644 --- a/src/name/pubsub/index.js +++ b/src/name/pubsub/index.js @@ -4,6 +4,7 @@ import { createSubs } from './subs.js' /** * @param {import('../../types').Options} config + * @returns {import('../../types').NamePubsubAPI} */ export function createPubsub (config) { return { diff --git a/src/name/pubsub/state.js b/src/name/pubsub/state.js index 136b89381..49a8adb58 100644 --- a/src/name/pubsub/state.js +++ b/src/name/pubsub/state.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../../lib/object-to-camel.js' import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/name/pubsub').API} NamePubsubAPI - */ - export const createState = configure(api => { /** - * @type {NamePubsubAPI["state"]} + * @type {import('../../types').NamePubsubAPI["state"]} */ async function state (options = {}) { const res = await api.post('name/pubsub/state', { diff --git a/src/name/pubsub/subs.js b/src/name/pubsub/subs.js index 5fef0dff5..0ba11b00f 100644 --- a/src/name/pubsub/subs.js +++ b/src/name/pubsub/subs.js @@ -1,14 +1,9 @@ import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/name/pubsub').API} NamePubsubAPI - */ - export const createSubs = configure(api => { /** - * @type {NamePubsubAPI["subs"]} + * @type {import('../../types').NamePubsubAPI["subs"]} */ async function subs (options = {}) { const res = await api.post('name/pubsub/subs', { diff --git a/src/name/resolve.js b/src/name/resolve.js index 92d90548a..c72f538f9 100644 --- a/src/name/resolve.js +++ b/src/name/resolve.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/name').API} NameAPI - */ - export const createResolve = configure(api => { /** - * @type {NameAPI["resolve"]} + * @type {import('../types').NameAPI["resolve"]} */ async function * resolve (path, options = {}) { const res = await api.post('name/resolve', { diff --git a/src/object/data.js b/src/object/data.js index d4760cf3b..45a7ce7ab 100644 --- a/src/object/data.js +++ b/src/object/data.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - export const createData = configure(api => { /** - * @type {ObjectAPI["data"]} + * @type {import('../types').ObjectAPI["data"]} */ async function data (cid, options = {}) { const res = await api.post('object/data', { diff --git a/src/object/get.js b/src/object/get.js index 0e091a0e2..399b73e21 100644 --- a/src/object/get.js +++ b/src/object/get.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - export const createGet = configure(api => { /** - * @type {ObjectAPI["get"]} + * @type {import('../types').ObjectAPI["get"]} */ async function get (cid, options = {}) { const res = await api.post('object/get', { diff --git a/src/object/index.js b/src/object/index.js index 96b344f41..b8ebb1a86 100644 --- a/src/object/index.js +++ b/src/object/index.js @@ -7,7 +7,7 @@ import { createStat } from './stat.js' import { createPatch } from './patch/index.js' /** - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs + * @param {import('../types').Multicodecs} codecs * @param {import('../types').Options} config */ export function createObject (codecs, config) { diff --git a/src/object/links.js b/src/object/links.js index 5d707e39b..133d0728c 100644 --- a/src/object/links.js +++ b/src/object/links.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - export const createLinks = configure(api => { /** - * @type {ObjectAPI["links"]} + * @type {import('../types').ObjectAPI["links"]} */ async function links (cid, options = {}) { const res = await api.post('object/links', { diff --git a/src/object/new.js b/src/object/new.js index 5dc6b9b5b..aef2f07b8 100644 --- a/src/object/new.js +++ b/src/object/new.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - export const createNew = configure(api => { /** - * @type {ObjectAPI["new"]} + * @type {import('../types').ObjectAPI["new"]} */ async function newObject (options = {}) { const res = await api.post('object/new', { diff --git a/src/object/patch/add-link.js b/src/object/patch/add-link.js index 652916d2a..943118a13 100644 --- a/src/object/patch/add-link.js +++ b/src/object/patch/add-link.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object/patch').API} ObjectPatchAPI - */ - export const createAddLink = configure(api => { /** - * @type {ObjectPatchAPI["addLink"]} + * @type {import('../../types').ObjectPatchAPI["addLink"]} */ async function addLink (cid, dLink, options = {}) { const res = await api.post('object/patch/add-link', { diff --git a/src/object/patch/append-data.js b/src/object/patch/append-data.js index cb4bda928..9a43d8980 100644 --- a/src/object/patch/append-data.js +++ b/src/object/patch/append-data.js @@ -4,14 +4,9 @@ import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' import { abortSignal } from '../../lib/abort-signal.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object/patch').API} ObjectPatchAPI - */ - export const createAppendData = configure(api => { /** - * @type {ObjectPatchAPI["appendData"]} + * @type {import('../../types').ObjectPatchAPI["appendData"]} */ async function appendData (cid, data, options = {}) { // allow aborting requests on body errors diff --git a/src/object/patch/rm-link.js b/src/object/patch/rm-link.js index 7ea075709..352d566b7 100644 --- a/src/object/patch/rm-link.js +++ b/src/object/patch/rm-link.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object/patch').API} ObjectPatchAPI - */ - export const createRmLink = configure(api => { /** - * @type {ObjectPatchAPI["rmLink"]} + * @type {import('../../types').ObjectPatchAPI["rmLink"]} */ async function rmLink (cid, dLink, options = {}) { const res = await api.post('object/patch/rm-link', { diff --git a/src/object/patch/set-data.js b/src/object/patch/set-data.js index 2d25e6a0c..d59121365 100644 --- a/src/object/patch/set-data.js +++ b/src/object/patch/set-data.js @@ -4,14 +4,9 @@ import { configure } from '../../lib/configure.js' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' import { abortSignal } from '../../lib/abort-signal.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object/patch').API} ObjectPatchAPI - */ - export const createSetData = configure(api => { /** - * @type {ObjectPatchAPI["setData"]} + * @type {import('../../types').ObjectPatchAPI["setData"]} */ async function setData (cid, data, options = {}) { // allow aborting requests on body errors diff --git a/src/object/put.js b/src/object/put.js index 0bf6d3362..c7302c55a 100644 --- a/src/object/put.js +++ b/src/object/put.js @@ -2,12 +2,7 @@ import { configure } from '../lib/configure.js' import { createPut as createDagPut } from '../dag/put.js' /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - -/** - * @param {import('ipfs-core-utils/multicodecs').Multicodecs} codecs + * @param {import('../types').Multicodecs} codecs * @param {import('../types').Options} options */ export const createPut = (codecs, options) => { @@ -15,7 +10,7 @@ export const createPut = (codecs, options) => { const dagPut = createDagPut(codecs, options) /** - * @type {ObjectAPI["put"]} + * @type {import('../types').ObjectAPI["put"]} */ async function put (obj, options = {}) { return dagPut(obj, { diff --git a/src/object/stat.js b/src/object/stat.js index bfc6b9024..024e8ed02 100644 --- a/src/object/stat.js +++ b/src/object/stat.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/object').API} ObjectAPI - */ - export const createStat = configure(api => { /** - * @type {ObjectAPI["stat"]} + * @type {import('../types.js').ObjectAPI["stat"]} */ async function stat (cid, options = {}) { const res = await api.post('object/stat', { diff --git a/src/pin/add-all.js b/src/pin/add-all.js index 46540b8d1..eaf0a0013 100644 --- a/src/pin/add-all.js +++ b/src/pin/add-all.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { normaliseInput } from 'ipfs-core-utils/pins/normalise-input' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin').API} PinAPI - */ - export const createAddAll = configure(api => { /** - * @type {PinAPI["addAll"]} + * @type {import('../types').PinAPI["addAll"]} */ async function * addAll (source, options = {}) { for await (const { path, recursive, metadata } of normaliseInput(source)) { @@ -31,6 +26,7 @@ export const createAddAll = configure(api => { for (const cid of pin.Pins) { yield CID.parse(cid) } + // eslint-disable-next-line no-continue continue } diff --git a/src/pin/add.js b/src/pin/add.js index 32a41d6af..f49be5a6a 100644 --- a/src/pin/add.js +++ b/src/pin/add.js @@ -2,11 +2,6 @@ import { createAddAll } from './add-all.js' import last from 'it-last' import { configure } from '../lib/configure.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin').API} PinAPI - */ - /** * @param {import('../types').Options} config */ @@ -15,7 +10,7 @@ export function createAdd (config) { return configure(() => { /** - * @type {PinAPI["add"]} + * @type {import('../types').PinAPI["add"]} */ async function add (path, options = {}) { // @ts-expect-error last can return undefined diff --git a/src/pin/ls.js b/src/pin/ls.js index 648631c3a..9a967f60a 100644 --- a/src/pin/ls.js +++ b/src/pin/ls.js @@ -2,18 +2,13 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin').API} PinAPI - */ - /** * @param {string} type * @param {string} cid * @param {Record} metadata */ function toPin (type, cid, metadata) { - /** @type {import('ipfs-core-types/src/pin').LsResult} */ + /** @type {import('../types').LsResult} */ const pin = { type, cid: CID.parse(cid) @@ -28,7 +23,7 @@ function toPin (type, cid, metadata) { export const createLs = configure(api => { /** - * @type {PinAPI["ls"]} + * @type {import('../types').PinAPI["ls"]} */ async function * ls (options = {}) { /** @type {any[]} */ diff --git a/src/pin/remote/add.js b/src/pin/remote/add.js index c3a2ac9d5..de295a85d 100644 --- a/src/pin/remote/add.js +++ b/src/pin/remote/add.js @@ -1,16 +1,11 @@ import { encodeAddParams, decodePin } from './utils.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote').API} RemotePiningAPI - */ - /** * @param {import('../../lib/core').Client} client */ export function createAdd (client) { /** - * @type {RemotePiningAPI["add"]} + * @type {import('../../types').RemotePiningAPI["add"]} */ async function add (cid, { timeout, signal, headers, ...query }) { const response = await client.post('pin/remote/add', { diff --git a/src/pin/remote/ls.js b/src/pin/remote/ls.js index 902dafe2d..288d5ef98 100644 --- a/src/pin/remote/ls.js +++ b/src/pin/remote/ls.js @@ -1,16 +1,11 @@ import { encodeQuery, decodePin } from './utils.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote').API} RemotePiningAPI - */ - /** * @param {import('../../lib/core').Client} client */ export function createLs (client) { /** - * @type {RemotePiningAPI["ls"]} + * @type {import('../../types.js').RemotePiningAPI["ls"]} */ async function * ls ({ timeout, signal, headers, ...query }) { const response = await client.post('pin/remote/ls', { diff --git a/src/pin/remote/rm-all.js b/src/pin/remote/rm-all.js index b825c13fe..3bcf1861d 100644 --- a/src/pin/remote/rm-all.js +++ b/src/pin/remote/rm-all.js @@ -1,16 +1,11 @@ import { encodeQuery } from './utils.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote').API} RemotePiningAPI - */ - /** * @param {import('../../lib/core').Client} client */ export function createRmAll (client) { /** - * @type {RemotePiningAPI["rmAll"]} + * @type {import('../../types').RemotePiningAPI["rmAll"]} */ async function rmAll ({ timeout, signal, headers, ...query }) { await client.post('pin/remote/rm', { diff --git a/src/pin/remote/rm.js b/src/pin/remote/rm.js index baa81c9de..5a8d4a2a7 100644 --- a/src/pin/remote/rm.js +++ b/src/pin/remote/rm.js @@ -1,16 +1,11 @@ import { encodeQuery } from './utils.js' -/** - * @typedef {import('../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote').API} RemotePiningAPI - */ - /** * @param {import('../../lib/core').Client} client */ export function createRm (client) { /** - * @type {RemotePiningAPI["rm"]} + * @type {import('../../types').RemotePiningAPI["rm"]} */ async function rm ({ timeout, signal, headers, ...query }) { await client.post('pin/remote/rm', { diff --git a/src/pin/remote/service/add.js b/src/pin/remote/service/add.js index f7bea8d83..1b1efbe07 100644 --- a/src/pin/remote/service/add.js +++ b/src/pin/remote/service/add.js @@ -1,17 +1,12 @@ import { toUrlSearchParams } from '../../../lib/to-url-search-params.js' import { encodeEndpoint } from './utils.js' -/** - * @typedef {import('../../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote/service').API} RemotePiningServiceAPI - */ - /** * @param {import('../../../lib/core').Client} client */ export function createAdd (client) { /** - * @type {RemotePiningServiceAPI["add"]} + * @type {import('../../../types').RemotePiningServiceAPI["add"]} */ async function add (name, options) { const { endpoint, key, headers, timeout, signal } = options diff --git a/src/pin/remote/service/ls.js b/src/pin/remote/service/ls.js index 830f4b9a8..269541660 100644 --- a/src/pin/remote/service/ls.js +++ b/src/pin/remote/service/ls.js @@ -1,17 +1,12 @@ import { toUrlSearchParams } from '../../../lib/to-url-search-params.js' import { decodeRemoteService } from './utils.js' -/** - * @typedef {import('../../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote/service').API} RemotePiningServiceAPI - */ - /** * @param {import('../../../lib/core').Client} client */ export function createLs (client) { /** - * @type {RemotePiningServiceAPI["ls"]} + * @type {import('../../../types').RemotePiningServiceAPI["ls"]} */ async function ls (options = {}) { // @ts-expect-error cannot derive option type from typedef diff --git a/src/pin/remote/service/rm.js b/src/pin/remote/service/rm.js index 377b29a2b..0b3d161d0 100644 --- a/src/pin/remote/service/rm.js +++ b/src/pin/remote/service/rm.js @@ -1,16 +1,11 @@ import { toUrlSearchParams } from '../../../lib/to-url-search-params.js' -/** - * @typedef {import('../../../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin/remote/service').API} RemotePiningServiceAPI - */ - /** * @param {import('../../../lib/core').Client} client */ export function createRm (client) { /** - * @type {RemotePiningServiceAPI["rm"]} + * @type {import('../../../types').RemotePiningServiceAPI["rm"]} */ async function rm (name, options = {}) { await client.post('pin/remote/service/rm', { diff --git a/src/pin/remote/service/utils.js b/src/pin/remote/service/utils.js index 398f8f9e8..e97b2c17d 100644 --- a/src/pin/remote/service/utils.js +++ b/src/pin/remote/service/utils.js @@ -1,6 +1,3 @@ -/** - * @typedef {import('ipfs-core-types/src/pin/remote/service').RemotePinServiceWithStat} RemotePinServiceWithStat - */ /** * @param {URL} url @@ -17,7 +14,7 @@ export function encodeEndpoint (url) { /** * @param {any} json - * @returns {RemotePinServiceWithStat} + * @returns {import('../../../types').RemotePinServiceWithStat} */ export function decodeRemoteService (json) { return { @@ -29,7 +26,7 @@ export function decodeRemoteService (json) { /** * @param {any} json - * @returns {import('ipfs-core-types/src/pin/remote/service').Stat} + * @returns {import('../../../types').Stat} */ export function decodeStat (json) { switch (json.Status) { diff --git a/src/pin/remote/utils.js b/src/pin/remote/utils.js index b67238c04..d6a857f14 100644 --- a/src/pin/remote/utils.js +++ b/src/pin/remote/utils.js @@ -1,20 +1,12 @@ import { CID } from 'multiformats/cid' import { toUrlSearchParams } from '../../lib/to-url-search-params.js' -/** - * @typedef {import('ipfs-core-types/src/utils').AbortOptions} AbortOptions - * @typedef {import('ipfs-core-types/src/pin/remote').Pin} Pin - * @typedef {import('ipfs-core-types/src/pin/remote').AddOptions} AddOptions - * @typedef {import('ipfs-core-types/src/pin/remote').Query} Query - * @typedef {import('ipfs-core-types/src/pin/remote').Status} Status - */ - /** * @param {object} json * @param {string} json.Name * @param {string} json.Cid - * @param {Status} json.Status - * @returns {Pin} + * @param {import('../../types.js').Status} json.Status + * @returns {import('../../types.js').Pin} */ export const decodePin = ({ Name: name, Status: status, Cid: cid }) => { return { @@ -49,7 +41,7 @@ export const encodeCID = (cid) => { } /** - * @param {Query & { all?: boolean }} query + * @param {import('../../types.js').Query & { all?: boolean }} query * @returns {URLSearchParams} */ export const encodeQuery = ({ service, cid, name, status, all }) => { @@ -75,7 +67,7 @@ export const encodeQuery = ({ service, cid, name, status, all }) => { } /** - * @param {AddOptions & {cid:CID}} options + * @param {import('../../types.js').AddOptions & {cid:CID}} options * @returns {URLSearchParams} */ export const encodeAddParams = ({ cid, service, background, name, origins }) => { diff --git a/src/pin/rm-all.js b/src/pin/rm-all.js index d18446be4..23e36b25e 100644 --- a/src/pin/rm-all.js +++ b/src/pin/rm-all.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { normaliseInput } from 'ipfs-core-utils/pins/normalise-input' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin').API} PinAPI - */ - export const createRmAll = configure(api => { /** - * @type {PinAPI["rmAll"]} + * @type {import('../types').PinAPI["rmAll"]} */ async function * rmAll (source, options = {}) { for await (const { path, recursive } of normaliseInput(source)) { @@ -32,6 +27,7 @@ export const createRmAll = configure(api => { for await (const pin of res.ndjson()) { if (pin.Pins) { // non-streaming response yield * pin.Pins.map((/** @type {string} */ cid) => CID.parse(cid)) + // eslint-disable-next-line no-continue continue } yield CID.parse(pin) diff --git a/src/pin/rm.js b/src/pin/rm.js index bf275c9ff..6ea93d82d 100644 --- a/src/pin/rm.js +++ b/src/pin/rm.js @@ -2,11 +2,6 @@ import { createRmAll } from './rm-all.js' import last from 'it-last' import { configure } from '../lib/configure.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pin').API} PinAPI - */ - /** * @param {import('../types').Options} config */ @@ -15,7 +10,7 @@ export const createRm = (config) => { return configure(() => { /** - * @type {PinAPI["rm"]} + * @type {import('../types').PinAPI["rm"]} */ async function rm (path, options = {}) { // @ts-expect-error last can return undefined diff --git a/src/ping.js b/src/ping.js index 7b119b124..5bc2e17c7 100644 --- a/src/ping.js +++ b/src/ping.js @@ -2,14 +2,9 @@ import { objectToCamel } from './lib/object-to-camel.js' import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createPing = configure(api => { /** - * @type {RootAPI["ping"]} + * @type {import('./types').RootAPI["ping"]} */ async function * ping (peerId, options = {}) { const res = await api.post('ping', { diff --git a/src/pubsub/ls.js b/src/pubsub/ls.js index 94fb4227a..f50a3dedd 100644 --- a/src/pubsub/ls.js +++ b/src/pubsub/ls.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { rpcArrayToTextArray } from '../lib/http-rpc-wire-format.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI - */ - export const createLs = configure(api => { /** - * @type {PubsubAPI["ls"]} + * @type {import('../types').PubsubAPI["ls"]} */ async function ls (options = {}) { const { Strings } = await (await api.post('pubsub/ls', { diff --git a/src/pubsub/peers.js b/src/pubsub/peers.js index a7cfff6c0..e130f3231 100644 --- a/src/pubsub/peers.js +++ b/src/pubsub/peers.js @@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { textToUrlSafeRpc } from '../lib/http-rpc-wire-format.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI - */ - export const createPeers = configure(api => { /** - * @type {PubsubAPI["peers"]} + * @type {import('../types').PubsubAPI["peers"]} */ async function peers (topic, options = {}) { const res = await api.post('pubsub/peers', { diff --git a/src/pubsub/publish.js b/src/pubsub/publish.js index 034996885..a0b923093 100644 --- a/src/pubsub/publish.js +++ b/src/pubsub/publish.js @@ -4,14 +4,9 @@ import { multipartRequest } from 'ipfs-core-utils/multipart-request' import { abortSignal } from '../lib/abort-signal.js' import { textToUrlSafeRpc } from '../lib/http-rpc-wire-format.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI - */ - export const createPublish = configure(api => { /** - * @type {PubsubAPI["publish"]} + * @type {import('../types').PubsubAPI["publish"]} */ async function publish (topic, data, options = {}) { const searchParams = toUrlSearchParams({ diff --git a/src/pubsub/subscribe.js b/src/pubsub/subscribe.js index 38fd85dce..33bd9a195 100644 --- a/src/pubsub/subscribe.js +++ b/src/pubsub/subscribe.js @@ -6,21 +6,13 @@ import { peerIdFromString } from '@libp2p/peer-id' const log = logger('ipfs-http-client:pubsub:subscribe') /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('@libp2p/interface-pubsub').Message} Message - * @typedef {(err: Error, fatal: boolean, msg?: Message) => void} ErrorHandlerFn - * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI - * @typedef {import('../types').Options} Options - */ - -/** - * @param {Options} options + * @param {import('../types').Options} options * @param {import('./subscription-tracker').SubscriptionTracker} subsTracker */ export const createSubscribe = (options, subsTracker) => { return configure((api) => { /** - * @type {PubsubAPI["subscribe"]} + * @type {import('../types').PubsubAPI["subscribe"]} */ async function subscribe (topic, handler, options = {}) { // eslint-disable-line require-await options.signal = subsTracker.subscribe(topic, handler, options.signal) @@ -91,11 +83,11 @@ export const createSubscribe = (options, subsTracker) => { } /** - * @param {import('ipfs-utils/src/types').ExtendedResponse} response + * @param {import('../types').ExtendedResponse} response * @param {object} options - * @param {(message: Message) => void} options.onMessage + * @param {(message: import('../types').Message) => void} options.onMessage * @param {() => void} options.onEnd - * @param {ErrorHandlerFn} [options.onError] + * @param {import('../types').PubsubApiErrorHandlerFn} [options.onError] */ async function readMessages (response, { onMessage, onEnd, onError }) { onError = onError || log @@ -104,6 +96,7 @@ async function readMessages (response, { onMessage, onEnd, onError }) { for await (const msg of response.ndjson()) { try { if (!msg.from) { + // eslint-disable-next-line no-continue continue } diff --git a/src/pubsub/subscription-tracker.js b/src/pubsub/subscription-tracker.js index ea3890d82..638a74293 100644 --- a/src/pubsub/subscription-tracker.js +++ b/src/pubsub/subscription-tracker.js @@ -1,21 +1,19 @@ /** - * @typedef {import('@libp2p/interface-pubsub').Message} Message - * @typedef {import('@libp2p/interfaces/events').EventHandler} MessageHandlerFn - * @typedef {object} Subscription - * @property {MessageHandlerFn} handler + * + * @property {import('../types').MessageHandlerFn} handler * @property {AbortController} controller */ export class SubscriptionTracker { constructor () { - /** @type {Map} */ + /** @type {Map} */ this._subs = new Map() } /** * @param {string} topic - * @param {MessageHandlerFn} handler + * @param {import('../types').MessageHandlerFn} handler * @param {AbortSignal} [signal] * @returns {AbortSignal} */ @@ -41,7 +39,7 @@ export class SubscriptionTracker { /** * @param {string} topic - * @param {MessageHandlerFn} [handler] + * @param {import('../types').MessageHandlerFn} [handler] */ unsubscribe (topic, handler) { const subs = this._subs.get(topic) || [] diff --git a/src/pubsub/unsubscribe.js b/src/pubsub/unsubscribe.js index c37252a48..a42dfb279 100644 --- a/src/pubsub/unsubscribe.js +++ b/src/pubsub/unsubscribe.js @@ -1,17 +1,11 @@ /** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/pubsub').API} PubsubAPI - * @typedef {import('../types').Options} Options - */ - -/** - * @param {Options} options + * @param {import('..').Options} options * @param {import('./subscription-tracker').SubscriptionTracker} subsTracker */ export const createUnsubscribe = (options, subsTracker) => { /** - * @type {PubsubAPI["unsubscribe"]} + * @type {import('../types').PubsubAPI["unsubscribe"]} */ async function unsubscribe (topic, handler) { subsTracker.unsubscribe(topic, handler) diff --git a/src/refs/index.js b/src/refs/index.js index 61905df61..012a6dce3 100644 --- a/src/refs/index.js +++ b/src/refs/index.js @@ -4,17 +4,12 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { createLocal } from './local.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/refs').API} RefsAPI - */ - export const createRefs = configure((api, opts) => { /** - * @type {RefsAPI["refs"]} + * @type {import('../types').RefsAPI["refs"]} */ const refs = async function * (args, options = {}) { - /** @type {import('ipfs-core-types/src/utils').IPFSPath[]} */ + /** @type {import('../types').IPFSPath[]} */ const argsArr = Array.isArray(args) ? args : [args] const res = await api.post('refs', { diff --git a/src/refs/local.js b/src/refs/local.js index 85170698f..a8d34743f 100644 --- a/src/refs/local.js +++ b/src/refs/local.js @@ -2,14 +2,9 @@ import { objectToCamel } from '../lib/object-to-camel.js' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/refs').API} RefsAPI - */ - export const createLocal = configure(api => { /** - * @type {RefsAPI["local"]} + * @type {import('../types').RefsAPI["local"]} */ async function * refsLocal (options = {}) { const res = await api.post('refs/local', { diff --git a/src/repo/gc.js b/src/repo/gc.js index 3312a458c..b9551f3bf 100644 --- a/src/repo/gc.js +++ b/src/repo/gc.js @@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/repo').API} RepoAPI - */ - export const createGc = configure(api => { /** - * @type {RepoAPI["gc"]} + * @type {import('../types').RepoAPI["gc"]} */ async function * gc (options = {}) { const res = await api.post('repo/gc', { diff --git a/src/repo/stat.js b/src/repo/stat.js index 6b42e7304..70625ca70 100644 --- a/src/repo/stat.js +++ b/src/repo/stat.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/repo').API} RepoAPI - */ - export const createStat = configure(api => { /** - * @type {RepoAPI["stat"]} + * @type {import('../types').RepoAPI["stat"]} */ async function stat (options = {}) { const res = await api.post('repo/stat', { diff --git a/src/repo/version.js b/src/repo/version.js index 62ed3198c..ad6558b48 100644 --- a/src/repo/version.js +++ b/src/repo/version.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/repo').API} RepoAPI - */ - export const createVersion = configure(api => { /** - * @type {RepoAPI["version"]} + * @type {import('../types').RepoAPI["version"]} */ async function version (options = {}) { const res = await (await api.post('repo/version', { diff --git a/src/resolve.js b/src/resolve.js index 93fbb7f3d..c02eb4288 100644 --- a/src/resolve.js +++ b/src/resolve.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createResolve = configure(api => { /** - * @type {RootAPI["resolve"]} + * @type {import('./types').RootAPI["resolve"]} */ async function resolve (path, options = {}) { const res = await api.post('resolve', { diff --git a/src/start.js b/src/start.js index c0b6aecd2..18365fffe 100644 --- a/src/start.js +++ b/src/start.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import errCode from 'err-code' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createStart = configure(api => { /** - * @type {RootAPI["start"]} + * @type {import('./types').RootAPI["start"]} */ const start = async (options = {}) => { throw errCode(new Error('Not implemented'), 'ERR_NOT_IMPLEMENTED') diff --git a/src/stats/bw.js b/src/stats/bw.js index 086b17811..90b03925a 100644 --- a/src/stats/bw.js +++ b/src/stats/bw.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/stats').API} StatsAPI - */ - export const createBw = configure(api => { /** - * @type {StatsAPI["bw"]} + * @type {import('../types').StatsAPI["bw"]} */ async function * bw (options = {}) { const res = await api.post('stats/bw', { diff --git a/src/stop.js b/src/stop.js index 4948580bc..10a96d0ed 100644 --- a/src/stop.js +++ b/src/stop.js @@ -1,14 +1,9 @@ import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createStop = configure(api => { /** - * @type {RootAPI["stop"]} + * @type {import('./types').RootAPI["stop"]} */ async function stop (options = {}) { const res = await api.post('shutdown', { diff --git a/src/swarm/addrs.js b/src/swarm/addrs.js index 468b6c95e..bd99b2d20 100644 --- a/src/swarm/addrs.js +++ b/src/swarm/addrs.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { peerIdFromString } from '@libp2p/peer-id' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/swarm').API} SwarmAPI - */ - export const createAddrs = configure(api => { /** - * @type {SwarmAPI["addrs"]} + * @type {import('../types.js').SwarmAPI["addrs"]} */ async function addrs (options = {}) { const res = await api.post('swarm/addrs', { diff --git a/src/swarm/connect.js b/src/swarm/connect.js index 0b61a99e2..26cf97335 100644 --- a/src/swarm/connect.js +++ b/src/swarm/connect.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/swarm').API} SwarmAPI - */ - export const createConnect = configure(api => { /** - * @type {SwarmAPI["connect"]} + * @type {import('../types').SwarmAPI["connect"]} */ async function connect (addr, options = {}) { const res = await api.post('swarm/connect', { diff --git a/src/swarm/disconnect.js b/src/swarm/disconnect.js index 97f45a268..855304b91 100644 --- a/src/swarm/disconnect.js +++ b/src/swarm/disconnect.js @@ -1,14 +1,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/swarm').API} SwarmAPI - */ - export const createDisconnect = configure(api => { /** - * @type {SwarmAPI["disconnect"]} + * @type {import('../types').SwarmAPI["disconnect"]} */ async function disconnect (addr, options = {}) { const res = await api.post('swarm/disconnect', { diff --git a/src/swarm/index.js b/src/swarm/index.js index ffc9f3ae5..ef8dceb1a 100644 --- a/src/swarm/index.js +++ b/src/swarm/index.js @@ -6,6 +6,7 @@ import { createPeers } from './peers.js' /** * @param {import('../types').Options} config + * @returns {import('../types').IPFS['swarm']} */ export function createSwarm (config) { return { diff --git a/src/swarm/local-addrs.js b/src/swarm/local-addrs.js index aaac2e627..32b3bfa3e 100644 --- a/src/swarm/local-addrs.js +++ b/src/swarm/local-addrs.js @@ -2,14 +2,9 @@ import { Multiaddr } from '@multiformats/multiaddr' import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/swarm').API} SwarmAPI - */ - export const createLocalAddrs = configure(api => { /** - * @type {SwarmAPI["localAddrs"]} + * @type {import('../types.js').SwarmAPI["localAddrs"]} */ async function localAddrs (options = {}) { const res = await api.post('swarm/addrs/local', { diff --git a/src/swarm/peers.js b/src/swarm/peers.js index 836bfa08c..b712b88a3 100644 --- a/src/swarm/peers.js +++ b/src/swarm/peers.js @@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js' import { toUrlSearchParams } from '../lib/to-url-search-params.js' import { peerIdFromString } from '@libp2p/peer-id' -/** - * @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/swarm').API} SwarmAPI - */ - export const createPeers = configure(api => { /** - * @type {SwarmAPI["peers"]} + * @type {import('../types').SwarmAPI["peers"]} */ async function peers (options = {}) { const res = await api.post('swarm/peers', { @@ -29,6 +24,7 @@ export const createPeers = configure(api => { muxer: peer.Muxer, latency: peer.Latency, streams: peer.Streams, + // eslint-disable-next-line no-nested-ternary direction: peer.Direction == null ? undefined : peer.Direction === 0 ? 'inbound' : 'outbound' } }) diff --git a/src/types.ts b/src/types.ts index 5385a20ad..9efecc218 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,10 +1,12 @@ +/* eslint-disable etc/prefer-interface */ +/* eslint-disable @typescript-eslint/consistent-type-definitions */ import type { Agent as HttpAgent } from 'http' import type { Agent as HttpsAgent } from 'https' import type { Multiaddr } from '@multiformats/multiaddr' -import type { BlockCodec } from 'multiformats/codecs/interface' import type { MultihashHasher } from 'multiformats/hashes/interface' -import type { MultibaseCodec } from 'multiformats/bases/interface' import type { IPFS } from 'ipfs-core-types' +import type { Message } from '@libp2p/interface-pubsub' +import type IpfsUtilsHttp from 'ipfs-utils/src/http.js' export interface Options { host?: string @@ -13,7 +15,7 @@ export interface Options { headers?: Headers | Record timeout?: number | string apiPath?: string - url?: URL|string|Multiaddr + url?: URL | string | Multiaddr ipld?: Partial agent?: HttpAgent | HttpsAgent } @@ -34,6 +36,7 @@ export interface IPLDOptions { export interface HTTPClientExtraOptions { headers?: Record searchParams?: URLSearchParams + // pubsub: IPFS['pubsub'] } export interface EndpointConfig { @@ -44,6 +47,78 @@ export interface EndpointConfig { 'api-path': string } +export interface IpfsUtilsHttpClient extends IpfsUtilsHttp { + +} + export interface IPFSHTTPClient extends IPFS { getEndpointConfig: () => EndpointConfig } + +export type MapEventResponses = { + ID: string + Addrs: string[] +} + +export type MapEvent = { + Type: number + ID: string + Extra: string + Responses: MapEventResponses[] +} + +export type PubsubSubscription = { + handler: MessageHandlerFn + controller: AbortController +} +export type ConfigureFn = (client: IpfsUtilsHttpClient, clientOptions: Options) => T +export type ConfigureFactory = (clientOptions: Options) => T + +export type { PeerInfo } from '@libp2p/interface-peer-info' +export type { IPFSEntry, AddResult, AddProgressFn as IPFSCoreAddProgressFn } from 'ipfs-core-types/src/root' +export type { GetResult } from 'ipfs-core-types/src/dag' +export type { IPFSPath, AbortOptions } from 'ipfs-core-types/src/utils' +export type { LsResult } from 'ipfs-core-types/src/pin' +export type { IPFS } from 'ipfs-core-types' +export type { Multicodecs } from 'ipfs-core-utils/multicodecs' +export type { QueryEvent } from 'ipfs-core-types/src/dht' +export type { Query, Status, Pin, AddOptions } from 'ipfs-core-types/src/pin/remote' +export type { RmResult } from 'ipfs-core-types/src/block' +export type { HTTPOptions, ProgressFn as IPFSUtilsHttpUploadProgressFn, ExtendedResponse } from 'ipfs-utils/src/types' +export type { CID } from 'multiformats/cid' +export type { + RemotePinServiceWithStat, + Stat +} from 'ipfs-core-types/src/pin/remote/service' +export type { PeerId } from '@libp2p/interface-peer-id' + +export type BitswapAPI = import('ipfs-core-types/src/bitswap').API +export type BlockAPI = import('ipfs-core-types/src/block').API +export type BlockCodec = import('multiformats/codecs/interface').BlockCodec +export type BootstrapAPI = import('ipfs-core-types/src/bootstrap').API +export type ConfigAPI = import('ipfs-core-types/src/config').API +export type ConfigProfilesAPI = import('ipfs-core-types/src/config/profiles').API +export type DAGAPI = import('ipfs-core-types/src/dag').API +export type DHTAPI = import('ipfs-core-types/src/dht').API +export type DiagAPI = import('ipfs-core-types/src/diag').API +export type FilesAPI = import('ipfs-core-types/src/files').API +export type KeyAPI = import('ipfs-core-types/src/key').API +export type LogAPI = import('ipfs-core-types/src/log').API +export type MessageHandlerFn = import('@libp2p/interfaces/events').EventHandler +export type NameAPI = import('ipfs-core-types/src/name').API +export type NamePubsubAPI = import('ipfs-core-types/src/name/pubsub').API +export type ObjectAPI = import('ipfs-core-types/src/object').API +export type ObjectPatchAPI = import('ipfs-core-types/src/object/patch').API +export type PinAPI = import('ipfs-core-types/src/pin').API +export type PubsubApiErrorHandlerFn = (err: Error, fatal: boolean, msg?: Message) => void +export type PubsubAPI = import('ipfs-core-types/src/pubsub').API +export type RefsAPI = import('ipfs-core-types/src/refs').API +export type RemotePiningAPI = import('ipfs-core-types/src/pin/remote').API +export type RemotePiningServiceAPI = import('ipfs-core-types/src/pin/remote/service').API +export type RepoAPI = import('ipfs-core-types/src/repo').API +export type RootAPI = import('ipfs-core-types/src/root').API +export type StatsAPI = import('ipfs-core-types/src/stats').API +export type SwarmAPI = import('ipfs-core-types/src/swarm').API + +export type MultibaseCodec = import('multiformats/bases/interface').MultibaseCodec +export type { Message, MultihashHasher } diff --git a/src/version.js b/src/version.js index c8000a9b0..4c6635b68 100644 --- a/src/version.js +++ b/src/version.js @@ -2,14 +2,9 @@ import { objectToCamel } from './lib/object-to-camel.js' import { configure } from './lib/configure.js' import { toUrlSearchParams } from './lib/to-url-search-params.js' -/** - * @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions - * @typedef {import('ipfs-core-types/src/root').API} RootAPI - */ - export const createVersion = configure(api => { /** - * @type {RootAPI["version"]} + * @type {import('./types').RootAPI["version"]} */ async function version (options = {}) { const res = await api.post('version', { diff --git a/test/commands.spec.js b/test/commands.spec.js index 42b3dec45..ba4666291 100644 --- a/test/commands.spec.js +++ b/test/commands.spec.js @@ -7,7 +7,7 @@ const f = factory() describe('.commands', function () { this.timeout(60 * 1000) - /** @type {import('ipfs-core-types').IPFS} */ + /** @type {import('../src/types').IPFS} */ let ipfs before(async () => { diff --git a/test/constructor.spec.js b/test/constructor.spec.js index 19fc02c83..279d0ec99 100644 --- a/test/constructor.spec.js +++ b/test/constructor.spec.js @@ -182,6 +182,10 @@ describe('js-kubo-rpc-client constructor tests', () => { }) }) +/** + * + * @param {import("../src/types.js").IPFSHTTPClient} client + */ async function clientWorks (client) { const id = await client.id() @@ -189,6 +193,11 @@ async function clientWorks (client) { expect(id).to.have.a.property('publicKey') } +/** + * + * @param {import("../src/types.js").IPFSHTTPClient} ipfs + * @param {{host: string, port: string, protocol: string, apiPath: string}} param1 + */ function expectConfig (ipfs, { host, port, protocol, apiPath }) { const conf = ipfs.getEndpointConfig() if (protocol) { diff --git a/test/node/agent.js b/test/node/agent.js index e85d3abfe..dd70bb04f 100644 --- a/test/node/agent.js +++ b/test/node/agent.js @@ -6,9 +6,8 @@ import { create as httpClient } from '../../src/index.js' import http, { Agent } from 'http' /** - * @typedef {import('http').IncomingMessage} IncomingMessage * - * @param {(message: IncomingMessage) => Promise} handler + * @param {(message: import('http').IncomingMessage) => Promise} handler */ function startServer (handler) { return new Promise((resolve) => { @@ -36,7 +35,7 @@ function startServer (handler) { } describe('agent', function () { - /** @type {import('http').Agent} */ + /** @type {Agent} */ let agent before(() => { diff --git a/test/node/custom-headers.js b/test/node/custom-headers.js index 0932d6523..de485e8b5 100644 --- a/test/node/custom-headers.js +++ b/test/node/custom-headers.js @@ -6,6 +6,10 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' import { create as httpClient } from '../../src/index.js' import http from 'http' +/** + * + * @param {() => any} fn + */ function startServer (fn) { let headersResolve const headers = new Promise((resolve) => { diff --git a/test/ping.spec.js b/test/ping.spec.js index dc71f5da9..572ccab33 100644 --- a/test/ping.spec.js +++ b/test/ping.spec.js @@ -7,6 +7,10 @@ import { factory } from './utils/factory.js' const f = factory() // Determine if a ping response object is a pong, or something else, like a status message +/** + * + * @param {unknown} pingResponse + */ function isPong (pingResponse) { return Boolean(pingResponse && pingResponse.success && !pingResponse.text) } diff --git a/test/pubsub.spec.js b/test/pubsub.spec.js index f85851b81..712449901 100644 --- a/test/pubsub.spec.js +++ b/test/pubsub.spec.js @@ -10,7 +10,7 @@ const f = factory() describe('.pubsub', function () { this.timeout(20 * 1000) describe('.subscribe', () => { - /** @type {import('ipfs-core-types').IPFS} */ + /** @type {import('../src/types.js').IPFS} */ let ipfs /** @type {any} */ let ctl diff --git a/test/utils/throws-async.js b/test/utils/throws-async.js index 5ea488284..45ba4223c 100644 --- a/test/utils/throws-async.js +++ b/test/utils/throws-async.js @@ -1,4 +1,8 @@ +/** + * + * @param {Promise | () => Promise} fnOrPromise + */ export async function throwsAsync (fnOrPromise) { try { await (fnOrPromise.then ? fnOrPromise : fnOrPromise())