Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 64fad8d

Browse files
committed
chore: undo some of the unintentded changes
1 parent c18a54d commit 64fad8d

File tree

14 files changed

+96
-41
lines changed

14 files changed

+96
-41
lines changed

packages/ipfs/src/core/components/block/get.js

+28-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,32 @@
33
const { cleanCid } = require('./utils')
44
const { withTimeoutOption } = require('../../utils')
55

6+
/**
7+
* @typedef {import('cids')} CID
8+
* @typedef {import('ipld-block')} Block
9+
* @typedef {import('ipfs-block-service')} BlockService
10+
* @typedef {import('../init').PreloadService} Preload
11+
*/
12+
13+
/**
14+
* @param {Object} config
15+
* @param {BlockService} config.blockService
16+
* @param {Preload} config.preload
17+
* @returns {Get}
18+
*/
619
module.exports = ({ blockService, preload }) => {
7-
return withTimeoutOption(async function get (cid, options) { // eslint-disable-line require-await
20+
/**
21+
* @typedef {Object} Options
22+
* @property {boolean} [preload]
23+
*
24+
* @callback Get
25+
* @param {CID} cid
26+
* @param {Options} [options]
27+
* @returns {Promise<Block>}
28+
*
29+
* @type {Get}
30+
*/
31+
async function get (cid, options) { // eslint-disable-line require-await
832
options = options || {}
933
cid = cleanCid(cid)
1034

@@ -13,5 +37,7 @@ module.exports = ({ blockService, preload }) => {
1337
}
1438

1539
return blockService.get(cid)
16-
})
40+
}
41+
42+
return withTimeoutOption(get)
1743
}

packages/ipfs/src/core/components/block/put.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ const isIPFS = require('is-ipfs')
77
const { withTimeoutOption } = require('../../utils')
88

99
/**
10-
* @typedef {import("ipfs-interface").BlockService} BlockService
11-
* @typedef {import("ipfs-interface").GCLock} GCLock
12-
* @typedef {import("ipfs-interface").PreloadService} PreloadService
13-
* @typedef {import("ipfs-interface").PinService} PinService
10+
* @typedef {import("ipfs-block-service")} BlockService
11+
* @typedef {import("../init").GCLock} GCLock
12+
* @typedef {import("../init").PreloadService} Preload
13+
* @typedef {import("../index").Pin} Pin
1414
*/
1515

1616
/**
1717
* @typedef {Object} PutConfig
1818
* @property {BlockService} blockService
1919
* @property {GCLock} gcLock
20-
* @property {PreloadService} preload
21-
* @property {PinService} pin
20+
* @property {Preload} preload
21+
* @property {Pin} pin
2222
*
2323
* @param {PutConfig} config
2424
* @returns {Put}

packages/ipfs/src/core/components/id.js

+28-5
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,34 @@ const multiaddr = require('multiaddr')
55
const { withTimeoutOption } = require('../utils')
66

77
/**
8-
* @param {*} config
9-
* @returns {*}
8+
* @typedef {import("peer-info")} PeerInfo
9+
* @typedef {import('multiaddr')} Multiaddr
10+
* @typedef {import("./init").LibP2P} LibP2P
11+
*/
12+
13+
/**
14+
* @param {Object} config
15+
* @param {PeerInfo} config.peerInfo
16+
* @param {LibP2P} config.libp2p
17+
* @returns {ID}
1018
*/
1119
module.exports = ({ peerInfo, libp2p }) => {
12-
return withTimeoutOption(async function id () { // eslint-disable-line require-await
20+
/**
21+
* @typedef {Object} IDInfo
22+
* @property {string} id
23+
* @property {string} publicKey
24+
* @property {Multiaddr[]} addresses
25+
* @property {string} agentVersion
26+
* @property {string} protocolVersion
27+
*
28+
* @callback ID
29+
* @returns {IDInfo}
30+
*
31+
* @type {ID}
32+
*/
33+
async function id () { // eslint-disable-line require-await
1334
const id = peerInfo.id.toB58String()
14-
/** @type {Buffer[]} */
35+
/** @type {Multiaddr[]} */
1536
let addresses = []
1637

1738
if (libp2p) {
@@ -39,5 +60,7 @@ module.exports = ({ peerInfo, libp2p }) => {
3960
agentVersion: `js-ipfs/${pkgversion}`,
4061
protocolVersion: '9000'
4162
}
42-
})
63+
}
64+
65+
return withTimeoutOption(id)
4366
}

packages/ipfs/src/core/components/index.js

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ exports.add = require('./add')
77

88
/**
99
* @typedef {Object} Block
10+
* @property {ReturnType<import('./block/get')>} get
11+
* @property {ReturnType<import('./block/put')>} put
12+
* @property {ReturnType<import('./block/rm')>} rm
13+
* @property {ReturnType<import('./block/stat')>} stat
1014
*/
1115
exports.block = {
1216
get: require('./block/get'),
@@ -60,8 +64,10 @@ exports.dht = require('./dht')
6064
exports.dns = require('./dns')
6165
exports.files = require('./files')
6266
exports.get = require('./get')
67+
/** @typedef {ReturnType<import('./id')>} ID */
6368
exports.id = require('./id')
6469
exports.init = require('./init')
70+
/** @typedef {ReturnType<import('./is-online')>} IsOnline */
6571
exports.isOnline = require('./is-online')
6672
exports.key = {
6773
export: require('./key/export'),
@@ -125,11 +131,15 @@ exports.repo = {
125131
stat: require('./repo/stat'),
126132
version: require('./repo/version')
127133
}
134+
135+
/** @typedef {ReturnType<import('./ping')>} Resolve */
128136
exports.resolve = require('./resolve')
137+
/** @typedef {ReturnType<import('./start')>} Start */
129138
exports.start = require('./start')
130139
exports.stats = {
131140
bw: require('./stats/bw')
132141
}
142+
/** @typedef {ReturnType<import('./stop')>} Stop */
133143
exports.stop = require('./stop')
134144
exports.swarm = {
135145
addrs: require('./swarm/addrs'),

packages/ipfs/src/core/components/init.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ module.exports = ({
205205

206206
const block = {
207207
get: Components.block.get({ blockService, preload }),
208-
put: Components.block.put({ blockService, gcLock, preload, pin }),
208+
put: Components.block.put({ blockService, pin, gcLock, preload }),
209209
rm: Components.block.rm({ blockService, gcLock, pinManager }),
210210
stat: Components.block.stat({ blockService, preload })
211211
}
@@ -494,7 +494,7 @@ function createApi ({
494494
bw: notStarted,
495495
repo: Components.repo.stat({ repo })
496496
},
497-
stop: () => apiManager.api,
497+
stop: () => {},
498498
swarm: {
499499
addrs: notStarted,
500500
connect: notStarted,

packages/ipfs/src/core/components/pin/add.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const { resolvePath, withTimeoutOption } = require('../../utils')
77
* @typedef {import('cids')} CID
88
* @typedef {import('./pin-manager')} PinManager
99
* @typedef {import('../init').GCLock} GCLock
10-
* @typedef {import('../index').DAGService} DAGService
10+
* @typedef {import('../index').DAG} DAG
1111
*/
1212
/**
1313
* @param {Object} config
1414
* @param {PinManager} config.pinManager
1515
* @param {GCLock} config.gcLock
16-
* @param {DAGService} config.dag
16+
* @param {DAG} config.dag
1717
* @returns {Add}
1818
*/
1919
module.exports = ({ pinManager, gcLock, dag }) => {
@@ -25,7 +25,7 @@ module.exports = ({ pinManager, gcLock, dag }) => {
2525
* @property {boolean} [preload]
2626
*
2727
* @callback Add
28-
* @param {string[]} paths
28+
* @param {string[]|CID} paths
2929
* @param {Options} [options]
3030
* @returns {Promise<{ cid:CID }[]>}
3131
*

packages/ipfs/src/core/components/repo/gc.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const { parallelMerge, transform, map } = require('streaming-iterables')
1313
const BLOCK_RM_CONCURRENCY = 256
1414

1515
/**
16-
* @typedef {import("interface-datastore").Key} Key
16+
* @typedef {import('interface-datastore').Key} Key
17+
* @typedef {import('../../utils').WithTimeoutOptions} WithTimeoutOptions
1718
* @typedef {Object} BlockID
1819
* @property {CID} cid
1920
* @property {err} [void]
@@ -27,13 +28,17 @@ const BLOCK_RM_CONCURRENCY = 256
2728
/**
2829
* Perform mark and sweep garbage collection
2930
* @param {*} config
30-
* @returns {function():AsyncIterable<Notification>}
31+
* @returns {GC}
3132
*/
3233
module.exports = ({ gcLock, pin, pinManager, refs, repo }) => {
3334
/**
35+
* @callback GC
36+
* @param {WithTimeoutOptions} [options]
3437
* @returns {AsyncIterable<Notification>}
38+
*
39+
* @type {GC}
3540
*/
36-
async function * gc () {
41+
async function * gc (options) {
3742
const start = Date.now()
3843
log('Creating set of marked blocks')
3944

packages/ipfs/src/core/components/repo/version.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = ({ repo }) => {
4444
throw err
4545
}
4646

47-
return repo.version.get()
47+
return repo.version.get(options)
4848
}
4949

5050
return withTimeoutOption(version)

packages/ipfs/src/core/components/swarm/connect.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { withTimeoutOption } = require('../../utils')
66
* @typedef {import('ipfs-interface').LibP2PService} LibP2PService
77
* @typedef {import('ipfs-interface').Address} Address
88
* @typedef {import('interface-connection').Connection} Connection
9+
* @typedef {import('../../utils').WithTimeoutOptions} WithTimeoutOptions
910
*/
1011

1112
/**
@@ -20,11 +21,12 @@ module.exports = ({ libp2p }) => {
2021
/**
2122
* @callback Connect
2223
* @param {Address} addr
24+
* @param {WithTimeoutOptions} [options]
2325
* @returns {Promise<Connection>}
2426
* @type {Connect}
2527
*/
26-
function connect (addr) {
27-
return libp2p.dial(addr)
28+
function connect (addr, options) {
29+
return libp2p.dial(addr, options)
2830
}
2931

3032
return withTimeoutOption(connect)

packages/ipfs/src/core/components/swarm/disconnect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = ({ libp2p }) => {
2222
* @type {Disconnect}
2323
*/
2424
function disconnect (addr, options) {
25-
return libp2p.hangUp(addr)
25+
return libp2p.hangUp(addr, options)
2626
}
2727

2828
return withTimeoutOption(disconnect)

packages/ipfs/src/core/runtime/ipld-nodejs.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const IpldFormats = {
5959
*/
6060
module.exports = (blockService, options, log) => {
6161
options = options || {}
62+
6263
return mergeOptions.call(
6364
// ensure we have the defaults formats even if the user overrides `formats: []`
6465
{ concatArrays: true },

types/ipfs-block-service/ipfs-block-service-tests.ts

Whitespace-only changes.

types/ipfs-interface/index.d.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ interface Metrics {
134134
}
135135

136136
export interface LibP2PService {
137+
transportManager: {
138+
getAddrs():Multiaddr[]
139+
}
137140
start():Promise<void>
138141
stop():Promise<void>
139142
connections:Map<string, Connection[]>
140143

141144
dial(address:Address, options?:DialOptions):Promise<Connection>
142145
dialProtocol(address:Address, protocols:string[], options?:DialOptions):Promise<{stream:DuplexStream<Buffer, Buffer>, protocol:string}>
143-
hangUp(peer:Address):Promise<void>
146+
hangUp(peer:Address, options?:DialOptions):Promise<void>
144147
handler(protocols:string, handler:LibP2PHandler):void
145148
unhandle(protocols:string):void
146149
ping(address:Address):Promise<number>

types/it-pipe/index.d.ts

-15
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
// Type definitions for it-pipe 1.1
2-
// Project: https://github.com/alanshaw/it-pipe#readme
3-
// Definitions by: Irakli Gozalishvili <https://github.com/me>
4-
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5-
6-
7-
81
type Source<T> =
92
| Iterable<T>
103
| AsyncIterable<T>
@@ -27,12 +20,4 @@ declare interface Pipe {
2720

2821
declare var pipe:Pipe;
2922

30-
// declare namespace pipe {
31-
// // Circular reference from it_pipe
32-
// const pipe: Pipe;
33-
// function isDuplex(obj: any): void;
34-
// function isIterable <T>(obj: any): obj is Source<T>;
35-
// function rawPipe(fns: any): any;
36-
// }
37-
3823
export = pipe;

0 commit comments

Comments
 (0)