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

Commit 1af82d1

Browse files
Gozalaachingbrain
andauthored
fix: bitswap related typedefs (#3580)
Fixes up types so they align here ipfs/js-ipfs-bitswap#261 Co-authored-by: achingbrain <[email protected]>
1 parent 49f7880 commit 1af82d1

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

packages/ipfs-core-types/src/bitswap.ts

+19-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import BigInteger from 'bignumber.js'
2-
import PeerId from 'peer-id'
3-
import CID from 'cids'
4-
import { Block } from './block-service'
5-
import { AbortOptions, Await } from './basic'
6-
import { MovingAverage } from './bitswap/moving-avarage'
7-
import { StoreReader, StoreExporter, StoreImporter } from './store'
1+
import type BigInteger from 'bignumber.js'
2+
import type PeerId from 'peer-id'
3+
import type CID from 'cids'
4+
import type { Block } from './block-service'
5+
import type { AbortOptions, Await } from './basic'
6+
import type { MovingAverage } from './bitswap/moving-avarage'
7+
import type { StoreReader, StoreExporter, StoreImporter } from './store'
88

99
export interface Bitswap extends
1010
StoreReader<CID, Block>,
@@ -17,19 +17,27 @@ export interface Bitswap extends
1717
disableStats: () => void
1818

1919
wantlistForPeer: (peerId: PeerId, options?: AbortOptions) => Map<string, WantListEntry>
20-
ledgerForPeer: (peerId: PeerId) => Ledger
20+
ledgerForPeer: (peerId: PeerId) => null|LedgerForPeer
2121

2222
put: (block: Block, options?: AbortOptions) => Await<void>
2323

24-
unwant: (cids: Iterable<CID>, options?: AbortOptions) => void
25-
cancelWants: (cids: Iterable<CID>) => void
24+
unwant: (cids: CID|CID[], options?: AbortOptions) => void
25+
cancelWants: (cids: CID|CID[]) => void
2626
getWantlist: (options?: AbortOptions) => Iterable<[string, WantListEntry]>
2727
peers: () => PeerId[]
2828
stat: () => Stats
2929
start: () => void
3030
stop: () => void
3131
}
3232

33+
export interface LedgerForPeer {
34+
peer: string
35+
value: number
36+
sent: number
37+
recv: number
38+
exchanged: number
39+
}
40+
3341
export interface Ledger {
3442
sentBytes: (n: number) => void
3543
receivedBytes: (n: number) => void
@@ -87,5 +95,5 @@ export interface Stats {
8795
stop: () => void
8896
readonly snapshot: Record<string, BigInteger>
8997
readonly movingAverages: Record<string, Record<number, MovingAverage>>
90-
push: (counter: number, inc: number) => void
98+
push: (peer: string|null, counter: string, inc: number) => void
9199
}

packages/ipfs-core-types/src/block-service.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import CID from 'cids'
2-
import { Await, AbortOptions } from './basic'
3-
import { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store'
4-
import { Bitswap } from './bitswap'
1+
import type CID from 'cids'
2+
import type { Await, AbortOptions } from './basic'
3+
import type { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store'
4+
import type { Bitswap } from './bitswap'
55

66
export interface BlockService extends
77
StoreReader<CID, Block>,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { AbortOptions, Await, AwaitIterable } from './basic'
2+
import type { Block } from './block-service'
3+
import type CID from 'cids'
4+
5+
export interface BlockStore {
6+
has: (cid: CID, options?: AbortOptions) => Await<boolean>
7+
get: (cid: CID, options?: AbortOptions) => Await<Block>
8+
put: (block: Block, options?: AbortOptions) => Await<Block>
9+
putMany: (blocks: AsyncIterable<Block>|Iterable<Block>, options?: AbortOptions) => AwaitIterable<Block>
10+
}

packages/ipfs-core-types/src/datastore.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KeyValueStore, StoreBatch, StoreSelector, Resource } from './store'
1+
import type { KeyValueStore, StoreBatch, StoreSelector, Resource } from './store'
22
export interface DataStore extends
33
KeyValueStore<Key, Value, Entry>,
44
StoreSelector<Entry>,

packages/ipfs-core-types/src/store.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
import { Await, AwaitIterable, AbortOptions } from './basic'
2+
import type { Await, AwaitIterable, AbortOptions } from './basic'
33

44
export interface ValueStore<T> {
55
get: (options?: AbortOptions) => Await<T>

0 commit comments

Comments
 (0)