Skip to content

Commit c90233a

Browse files
authored
feat: consolidate types (#10)
* feat: consolidate types * chore: fix lint errors
1 parent 75b8fca commit c90233a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+304
-781
lines changed

.eslintrc.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
{
3+
"extends": [
4+
"ipfs"
5+
],
6+
"env": {
7+
"es2021": true,
8+
"node": true
9+
},
10+
"parserOptions": {
11+
"sourceType": "module",
12+
"project": "./tsconfig.json"
13+
},
14+
"rules": {
15+
"no-return-await": "off",
16+
"no-undef-init": "off",
17+
"no-warning-comments": "off"
18+
}
19+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "kubo-rpc-client",
3-
"version": "1.0.0",
3+
"version": "0.0.2",
44
"description": "A client library for the Kubo RPC API",
55
"license": "Apache-2.0 OR MIT",
66
"homepage": "https://github.com/ipfs/js-kubo-rpc-client#readme",
@@ -191,6 +191,7 @@
191191
"@libp2p/interfaces": "^3.0.3",
192192
"aegir": "^37.5.1",
193193
"delay": "^5.0.0",
194+
"eslint-config-ipfs": "^3.1.0",
194195
"eslint-plugin-jsdoc": "^39.3.6",
195196
"go-ipfs": "^0.12.1",
196197
"ipfs-core-types": "^0.11.1",

src/add-all.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,9 @@ import { multipartRequest } from 'ipfs-core-utils/multipart-request'
55
import { toUrlSearchParams } from './lib/to-url-search-params.js'
66
import { abortSignal } from './lib/abort-signal.js'
77

8-
/**
9-
* @typedef {import('ipfs-utils/src/types').ProgressFn} IPFSUtilsHttpUploadProgressFn
10-
* @typedef {import('ipfs-core-types/src/root').AddProgressFn} IPFSCoreAddProgressFn
11-
* @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions
12-
* @typedef {import('ipfs-core-types/src/root').API<HTTPClientExtraOptions>} RootAPI
13-
* @typedef {import('ipfs-core-types/src/root').AddResult} AddResult
14-
*/
15-
168
export const createAddAll = configure((api) => {
179
/**
18-
* @type {RootAPI["addAll"]}
10+
* @type {import('./types.js').RootAPI["addAll"]}
1911
*/
2012
async function * addAll (source, options = {}) {
2113
// allow aborting requests on body errors
@@ -64,8 +56,8 @@ export const createAddAll = configure((api) => {
6456
*
6557
* @param {number} total
6658
* @param {{name:string, start:number, end:number}[]|null} parts
67-
* @param {IPFSCoreAddProgressFn} progress
68-
* @returns {[IPFSCoreAddProgressFn|undefined, IPFSUtilsHttpUploadProgressFn|undefined]}
59+
* @param {import('./types.js').IPFSCoreAddProgressFn} progress
60+
* @returns {[import('./types.js').IPFSCoreAddProgressFn|undefined, import('./types.js').IPFSUtilsHttpUploadProgressFn|undefined]}
6961
*/
7062
const createProgressHandler = (total, parts, progress) =>
7163
parts ? [undefined, createOnUploadProgress(total, parts, progress)] : [progress, undefined]
@@ -76,8 +68,8 @@ const createProgressHandler = (total, parts, progress) =>
7668
*
7769
* @param {number} size - actual content size
7870
* @param {{name:string, start:number, end:number}[]} parts
79-
* @param {IPFSCoreAddProgressFn} progress
80-
* @returns {IPFSUtilsHttpUploadProgressFn}
71+
* @param {import('./types.js').IPFSCoreAddProgressFn} progress
72+
* @returns {import('./types.js').IPFSUtilsHttpUploadProgressFn}
8173
*/
8274
const createOnUploadProgress = (size, parts, progress) => {
8375
let index = 0
@@ -111,7 +103,7 @@ const createOnUploadProgress = (size, parts, progress) => {
111103
* @param {number} [input.mtimeNsecs]
112104
*/
113105
function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) {
114-
/** @type {AddResult} */
106+
/** @type {import('./types.js').AddResult} */
115107
const output = {
116108
path: name,
117109
cid: CID.parse(hash),

src/add.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@ import last from 'it-last'
33
import { configure } from './lib/configure.js'
44
import { normaliseInput } from 'ipfs-core-utils/files/normalise-input-single'
55

6-
/**
7-
* @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions
8-
* @typedef {import('ipfs-core-types/src/root').API<HTTPClientExtraOptions>} RootAPI
9-
*/
10-
116
/**
127
* @param {import('./types').Options} options
138
*/
149
export function createAdd (options) {
1510
const all = createAddAll(options)
1611
return configure(() => {
1712
/**
18-
* @type {RootAPI["add"]}
13+
* @type {import('./types').RootAPI["add"]}
1914
*/
2015
async function add (input, options = {}) {
2116
// @ts-expect-error - last may return undefined if source is empty

src/bitswap/stat.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44
import { peerIdFromString } from '@libp2p/peer-id'
55

6-
/**
7-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
8-
* @typedef {import('ipfs-core-types/src/bitswap').API<HTTPClientExtraOptions>} BitswapAPI
9-
*/
10-
116
export const createStat = configure(api => {
127
/**
13-
* @type {BitswapAPI["stat"]}
8+
* @type {import('../types').BitswapAPI["stat"]}
149
*/
1510
async function stat (options = {}) {
1611
const res = await api.post('bitswap/stat', {

src/bitswap/unwant.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/bitswap').API<HTTPClientExtraOptions>} BitswapAPI
7-
*/
8-
94
export const createUnwant = configure(api => {
105
/**
11-
* @type {BitswapAPI["unwant"]}
6+
* @type {import('../types').BitswapAPI["unwant"]}
127
*/
138
async function unwant (cid, options = {}) {
149
const res = await api.post('bitswap/unwant', {

src/bitswap/wantlist-for-peer.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid'
22
import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bitswap').API<HTTPClientExtraOptions>} BitswapAPI
8-
*/
9-
105
export const createWantlistForPeer = configure(api => {
116
/**
12-
* @type {BitswapAPI["wantlistForPeer"]}
7+
* @type {import('../types').BitswapAPI["wantlistForPeer"]}
138
*/
149
async function wantlistForPeer (peerId, options = {}) {
1510
const res = await (await api.post('bitswap/wantlist', {

src/bitswap/wantlist.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid'
22
import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bitswap').API<HTTPClientExtraOptions>} BitswapAPI
8-
*/
9-
105
export const createWantlist = configure(api => {
116
/**
12-
* @type {BitswapAPI["wantlist"]}
7+
* @type {import('../types').BitswapAPI["wantlist"]}
138
*/
149
async function wantlist (options = {}) {
1510
const res = await (await api.post('bitswap/wantlist', {

src/block/get.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/block').API<HTTPClientExtraOptions>} BlockAPI
7-
*/
8-
94
export const createGet = configure(api => {
105
/**
11-
* @type {BlockAPI["get"]}
6+
* @type {import('../types').BlockAPI["get"]}
127
*/
138
async function get (cid, options = {}) {
149
const res = await api.post('block/get', {

src/block/put.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@ import { configure } from '../lib/configure.js'
44
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
55
import { abortSignal } from '../lib/abort-signal.js'
66

7-
/**
8-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
9-
* @typedef {import('ipfs-core-types/src/block').API<HTTPClientExtraOptions>} BlockAPI
10-
*/
11-
127
export const createPut = configure(api => {
138
/**
14-
* @type {BlockAPI["put"]}
9+
* @type {import('../types').BlockAPI["put"]}
1510
*/
1611
async function put (data, options = {}) {
1712
// allow aborting requests on body errors
@@ -21,7 +16,7 @@ export const createPut = configure(api => {
2116
let res
2217
try {
2318
const response = await api.post('block/put', {
24-
signal: signal,
19+
signal,
2520
searchParams: toUrlSearchParams(options),
2621
...(
2722
await multipartRequest([data], controller, options.headers)

src/block/rm.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,9 @@ import { CID } from 'multiformats/cid'
22
import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/block').API<HTTPClientExtraOptions>} BlockAPI
8-
* @typedef {import('ipfs-core-types/src/block').RmResult} RmResult
9-
*/
10-
115
export const createRm = configure(api => {
126
/**
13-
* @type {BlockAPI["rm"]}
7+
* @type {import('../types').BlockAPI["rm"]}
148
*/
159
async function * rm (cid, options = {}) {
1610
if (!Array.isArray(cid)) {
@@ -39,7 +33,7 @@ export const createRm = configure(api => {
3933
* @param {*} removed
4034
*/
4135
function toCoreInterface (removed) {
42-
/** @type {RmResult} */
36+
/** @type {import('../types').RmResult} */
4337
const out = {
4438
cid: CID.parse(removed.Hash)
4539
}

src/block/stat.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { CID } from 'multiformats/cid'
22
import { configure } from '../lib/configure.js'
33
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/block').API<HTTPClientExtraOptions>} BlockAPI
8-
*/
9-
105
export const createStat = configure(api => {
116
/**
12-
* @type {BlockAPI["stat"]}
7+
* @type {import('../types').BlockAPI["stat"]}
138
*/
149
async function stat (cid, options = {}) {
1510
const res = await api.post('block/stat', {

src/bootstrap/add.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33
import { Multiaddr } from '@multiformats/multiaddr'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bootstrap').API<HTTPClientExtraOptions>} BootstrapAPI
8-
*/
9-
105
export const createAdd = configure(api => {
116
/**
12-
* @type {BootstrapAPI["add"]}
7+
* @type {import('../types').BootstrapAPI["add"]}
138
*/
149
async function add (addr, options = {}) {
1510
const res = await api.post('bootstrap/add', {

src/bootstrap/clear.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33
import { Multiaddr } from '@multiformats/multiaddr'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bootstrap').API<HTTPClientExtraOptions>} BootstrapAPI
8-
*/
9-
105
export const createClear = configure(api => {
116
/**
12-
* @type {BootstrapAPI["clear"]}
7+
* @type {import('../types').BootstrapAPI["clear"]}
138
*/
149
async function clear (options = {}) {
1510
const res = await api.post('bootstrap/rm', {

src/bootstrap/list.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33
import { Multiaddr } from '@multiformats/multiaddr'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bootstrap').API<HTTPClientExtraOptions>} BootstrapAPI
8-
*/
9-
105
export const createList = configure(api => {
116
/**
12-
* @type {BootstrapAPI["list"]}
7+
* @type {import('../types').BootstrapAPI["list"]}
138
*/
149
async function list (options = {}) {
1510
const res = await api.post('bootstrap/list', {

src/bootstrap/reset.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33
import { Multiaddr } from '@multiformats/multiaddr'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bootstrap').API<HTTPClientExtraOptions>} BootstrapAPI
8-
*/
9-
105
export const createReset = configure(api => {
116
/**
12-
* @type {BootstrapAPI["reset"]}
7+
* @type {import('../types.js').BootstrapAPI["reset"]}
138
*/
149
async function reset (options = {}) {
1510
const res = await api.post('bootstrap/add', {

src/bootstrap/rm.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@ import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33
import { Multiaddr } from '@multiformats/multiaddr'
44

5-
/**
6-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
7-
* @typedef {import('ipfs-core-types/src/bootstrap').API<HTTPClientExtraOptions>} BootstrapAPI
8-
*/
9-
105
export const createRm = configure(api => {
116
/**
12-
* @type {BootstrapAPI["rm"]}
7+
* @type {import('../types').BootstrapAPI["rm"]}
138
*/
149
async function rm (addr, options = {}) {
1510
const res = await api.post('bootstrap/rm', {

src/cat.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from './lib/configure.js'
22
import { toUrlSearchParams } from './lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/root').API<HTTPClientExtraOptions>} RootAPI
7-
*/
8-
94
export const createCat = configure(api => {
105
/**
11-
* @type {RootAPI["cat"]}
6+
* @type {import('./types').RootAPI["cat"]}
127
*/
138
async function * cat (path, options = {}) {
149
const res = await api.post('cat', {

src/commands.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from './lib/configure.js'
22
import { toUrlSearchParams } from './lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('./types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/root').API<HTTPClientExtraOptions>} RootAPI
7-
*/
8-
94
export const createCommands = configure(api => {
105
/**
11-
* @type {RootAPI["commands"]}
6+
* @type {import('./types').RootAPI["commands"]}
127
*/
138
const commands = async (options = {}) => {
149
const res = await api.post('commands', {

src/config/get-all.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/config').API<HTTPClientExtraOptions>} ConfigAPI
7-
*/
8-
94
export const createGetAll = configure(api => {
105
/**
11-
* @type {ConfigAPI["getAll"]}
6+
* @type {import('../types.js').ConfigAPI["getAll"]}
127
*/
138
const getAll = async (options = {}) => {
149
const res = await api.post('config/show', {

src/config/get.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { configure } from '../lib/configure.js'
22
import { toUrlSearchParams } from '../lib/to-url-search-params.js'
33

4-
/**
5-
* @typedef {import('../types').HTTPClientExtraOptions} HTTPClientExtraOptions
6-
* @typedef {import('ipfs-core-types/src/config').API<HTTPClientExtraOptions>} ConfigAPI
7-
*/
8-
94
export const createGet = configure(api => {
105
/**
11-
* @type {ConfigAPI["get"]}
6+
* @type {import('../types.js').ConfigAPI["get"]}
127
*/
138
const get = async (key, options = {}) => {
149
if (!key) {

0 commit comments

Comments
 (0)