Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

fix: add peer store query interfaces #412

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/interface-peer-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,26 @@ export interface Tag {
value: number
}

/**
* A predicate by which to filter lists of peers
*/
export interface PeerQueryFilter { (peer: Peer): boolean }

/**
* A predicate by which to sort lists of peers
*/
export interface PeerQueryOrder { (a: Peer, b: Peer): -1 | 0 | 1 }

/**
* A query for getting lists of peers
*/
export interface PeerQuery {
filters?: PeerQueryFilter[]
orders?: PeerQueryOrder[]
limit?: number
offset?: number
}

export interface PeerStore {
/**
* Loop over every peer - the looping is async because we read from a
Expand All @@ -136,7 +156,7 @@ export interface PeerStore {
* })
* ```
*/
forEach: (fn: (peer: Peer) => void) => Promise<void>
forEach: (fn: (peer: Peer) => void, query?: PeerQuery) => Promise<void>

/**
* Returns all peers in the peer store.
Expand All @@ -149,7 +169,7 @@ export interface PeerStore {
* }
* ```
*/
all: () => Promise<Peer[]>
all: (query?: PeerQuery) => Promise<Peer[]>

/**
* Delete all data stored for the passed peer
Expand Down