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

Commit

Permalink
fix: bitswap related typedefs (#3580)
Browse files Browse the repository at this point in the history
Fixes up types so they align here ipfs/js-ipfs-bitswap#261

Co-authored-by: achingbrain <alex@achingbrain.net>
  • Loading branch information
Gozala and achingbrain authored Mar 8, 2021
1 parent 49f7880 commit 1af82d1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 17 deletions.
30 changes: 19 additions & 11 deletions packages/ipfs-core-types/src/bitswap.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import BigInteger from 'bignumber.js'
import PeerId from 'peer-id'
import CID from 'cids'
import { Block } from './block-service'
import { AbortOptions, Await } from './basic'
import { MovingAverage } from './bitswap/moving-avarage'
import { StoreReader, StoreExporter, StoreImporter } from './store'
import type BigInteger from 'bignumber.js'
import type PeerId from 'peer-id'
import type CID from 'cids'
import type { Block } from './block-service'
import type { AbortOptions, Await } from './basic'
import type { MovingAverage } from './bitswap/moving-avarage'
import type { StoreReader, StoreExporter, StoreImporter } from './store'

export interface Bitswap extends
StoreReader<CID, Block>,
Expand All @@ -17,19 +17,27 @@ export interface Bitswap extends
disableStats: () => void

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

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

unwant: (cids: Iterable<CID>, options?: AbortOptions) => void
cancelWants: (cids: Iterable<CID>) => void
unwant: (cids: CID|CID[], options?: AbortOptions) => void
cancelWants: (cids: CID|CID[]) => void
getWantlist: (options?: AbortOptions) => Iterable<[string, WantListEntry]>
peers: () => PeerId[]
stat: () => Stats
start: () => void
stop: () => void
}

export interface LedgerForPeer {
peer: string
value: number
sent: number
recv: number
exchanged: number
}

export interface Ledger {
sentBytes: (n: number) => void
receivedBytes: (n: number) => void
Expand Down Expand Up @@ -87,5 +95,5 @@ export interface Stats {
stop: () => void
readonly snapshot: Record<string, BigInteger>
readonly movingAverages: Record<string, Record<number, MovingAverage>>
push: (counter: number, inc: number) => void
push: (peer: string|null, counter: string, inc: number) => void
}
8 changes: 4 additions & 4 deletions packages/ipfs-core-types/src/block-service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import CID from 'cids'
import { Await, AbortOptions } from './basic'
import { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store'
import { Bitswap } from './bitswap'
import type CID from 'cids'
import type { Await, AbortOptions } from './basic'
import type { StoreReader, StoreImporter, StoreExporter, StoreEraser } from './store'
import type { Bitswap } from './bitswap'

export interface BlockService extends
StoreReader<CID, Block>,
Expand Down
10 changes: 10 additions & 0 deletions packages/ipfs-core-types/src/block-store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { AbortOptions, Await, AwaitIterable } from './basic'
import type { Block } from './block-service'
import type CID from 'cids'

export interface BlockStore {
has: (cid: CID, options?: AbortOptions) => Await<boolean>
get: (cid: CID, options?: AbortOptions) => Await<Block>
put: (block: Block, options?: AbortOptions) => Await<Block>
putMany: (blocks: AsyncIterable<Block>|Iterable<Block>, options?: AbortOptions) => AwaitIterable<Block>
}
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/src/datastore.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KeyValueStore, StoreBatch, StoreSelector, Resource } from './store'
import type { KeyValueStore, StoreBatch, StoreSelector, Resource } from './store'
export interface DataStore extends
KeyValueStore<Key, Value, Entry>,
StoreSelector<Entry>,
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core-types/src/store.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import { Await, AwaitIterable, AbortOptions } from './basic'
import type { Await, AwaitIterable, AbortOptions } from './basic'

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

0 comments on commit 1af82d1

Please sign in to comment.