Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PeerRecord Addrs and Protocols do not need to be optional #43

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: upate method
  • Loading branch information
achingbrain committed Oct 26, 2023
commit e56cfb5d9789d8ac0a26a362bfaed9160a341b46
1 change: 1 addition & 0 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@
"browser-readablestream-to-it": "^2.0.3",
"ipns": "^7.0.1",
"it-all": "^3.0.2",
"it-ndjson": "^1.0.4",
"iterable-ndjson": "^1.1.0",
"multiformats": "^12.1.1",
"p-defer": "^4.0.0",
Expand Down
5 changes: 2 additions & 3 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { anySignal } from 'any-signal'
import toIt from 'browser-readablestream-to-it'
import { unmarshal, type IPNSRecord, marshal, peerIdToRoutingKey } from 'ipns'
import { ipnsValidator } from 'ipns/validator'
// @ts-expect-error no types
import ndjson from 'iterable-ndjson'
import { parse as ndjson } from 'it-ndjson'
import defer from 'p-defer'
import PQueue from 'p-queue'
import type { DelegatedRoutingV1HttpApiClient, DelegatedRoutingV1HttpApiClientInit, PeerRecord } from './index.js'
Expand Down Expand Up @@ -107,7 +106,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
}
}

async * getPeerInfo (peerId: PeerId, options: AbortOptions | undefined = {}): AsyncGenerator<PeerRecord, any, unknown> {
async * getPeers (peerId: PeerId, options: AbortOptions | undefined = {}): AsyncGenerator<PeerRecord, any, unknown> {
log('getPeers starts: %c', peerId)

const signal = anySignal([this.shutDownController.signal, options.signal, AbortSignal.timeout(this.timeout)])
Expand Down
13 changes: 7 additions & 6 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@ export interface DelegatedRoutingV1HttpApiClientInit {

export interface DelegatedRoutingV1HttpApiClient {
/**
* Returns an async generator of PeerInfos that can provide the content
* for the passed CID
* Returns an async generator of {@link PeerRecord}s that can provide the
* content for the passed {@link CID}
*/
getProviders(cid: CID, options?: AbortOptions): AsyncGenerator<PeerRecord>

/**
* Returns an async generator of PeerInfos for the provided PeerId
* Returns an async generator of {@link PeerRecord}s for the provided
* {@link PeerId}
*/
getPeerInfo(peerId: PeerId, options?: AbortOptions): AsyncGenerator<PeerRecord>
getPeers(peerId: PeerId, options?: AbortOptions): AsyncGenerator<PeerRecord>

/**
* Returns a promise of a IPNSRecord for the given PeerId
* Returns a promise of a {@link IPNSRecord} for the given {@link PeerId}
*/
getIPNS(peerId: PeerId, options?: AbortOptions): Promise<IPNSRecord>

/**
* Publishes the given IPNSRecord for the provided PeerId
* Publishes the given {@link IPNSRecord} for the provided {@link PeerId}
*/
putIPNS(peerId: PeerId, record: IPNSRecord, options?: AbortOptions): Promise<void>

Expand Down
2 changes: 1 addition & 1 deletion packages/client/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('delegated-routing-v1-http-api-client', () => {
body: records.map(prov => JSON.stringify(prov)).join('\n')
})

const peerRecords = await all(client.getPeerInfo(peerId))
const peerRecords = await all(client.getPeers(peerId))
expect(peerRecords.map(peerRecord => ({
...peerRecord,
ID: peerRecord.ID.toString(),
Expand Down
2 changes: 1 addition & 1 deletion packages/interop/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ describe('delegated-routing-v1-http-api interop', () => {
})

it('should find peer info', async () => {
const result = await first(client.getPeerInfo(network[2].libp2p.peerId))
const result = await first(client.getPeers(network[2].libp2p.peerId))

if (result == null) {
throw new Error('PeerInfo not found')
Expand Down