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

Commit

Permalink
fix: add peer store query interfaces (#412)
Browse files Browse the repository at this point in the history
Add interfaces for peer store queries
  • Loading branch information
achingbrain committed Jun 11, 2023
1 parent 9e86d57 commit 0247215
Showing 1 changed file with 22 additions and 2 deletions.
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

0 comments on commit 0247215

Please sign in to comment.