From df47658459ef0f691fa509475cea7161ddc0e78e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Mar 2023 11:53:40 +0000 Subject: [PATCH] deps(dev): bump aegir from 37.12.1 to 38.1.6 (#66) * deps(dev): bump aegir from 37.12.1 to 38.1.6 Bumps [aegir](https://github.com/ipfs/aegir) from 37.12.1 to 38.1.6. - [Release notes](https://github.com/ipfs/aegir/releases) - [Changelog](https://github.com/ipfs/aegir/blob/master/CHANGELOG.md) - [Commits](https://github.com/ipfs/aegir/compare/v37.12.1...v38.1.6) --- updated-dependencies: - dependency-name: aegir dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] * chore: fix linting and deps --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Potsides --- package.json | 5 ++--- src/address-book.ts | 20 ++++++++++---------- src/index.ts | 14 +++++++------- src/key-book.ts | 8 ++++---- src/metadata-book.ts | 12 ++++++------ src/proto-book.ts | 10 +++++----- src/store.ts | 22 +++++++++++----------- test/proto-book.spec.ts | 4 ++-- 8 files changed, 47 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index 5596542..67015a4 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "scripts": { "clean": "aegir clean", "lint": "aegir lint", - "dep-check": "aegir dep-check", + "dep-check": "aegir dep-check -i protons", "generate": "protons src/pb/peer.proto src/pb/tags.proto", "build": "aegir build", "test": "aegir test", @@ -166,10 +166,9 @@ "uint8arrays": "^4.0.2" }, "devDependencies": { - "@libp2p/interface-compliance-tests": "^3.0.2", "@libp2p/peer-id-factory": "^2.0.0", "@libp2p/utils": "^3.0.2", - "aegir": "^37.9.1", + "aegir": "^38.1.6", "datastore-core": "^8.0.1", "delay": "^5.0.0", "p-defer": "^4.0.0", diff --git a/src/address-book.ts b/src/address-book.ts index eaf8760..9b7580a 100644 --- a/src/address-book.ts +++ b/src/address-book.ts @@ -10,7 +10,7 @@ import map from 'it-map' import each from 'it-foreach' import { peerIdFromPeerId } from '@libp2p/peer-id' import { CustomEvent } from '@libp2p/interfaces/events' -import type { AddressFilter, Peer, PeerMultiaddrsChangeData, PeerStore } from '@libp2p/interface-peer-store' +import type { Address, AddressFilter, Peer, PeerMultiaddrsChangeData, PeerStore } from '@libp2p/interface-peer-store' import type { Store } from './store.js' import type { Envelope } from '@libp2p/interface-record' import type { PeerId } from '@libp2p/interface-peer-id' @@ -20,7 +20,7 @@ import type { Multiaddr } from '@multiformats/multiaddr' const log = logger('libp2p:peer-store:address-book') const EVENT_NAME = 'change:multiaddrs' -async function allowAll () { +async function allowAll (): Promise { return true } @@ -40,7 +40,7 @@ export class PeerStoreAddressBook { * This will return a boolean that indicates if the record was successfully processed and added * into the AddressBook. */ - async consumePeerRecord (envelope: Envelope) { + async consumePeerRecord (envelope: Envelope): Promise { log.trace('consumePeerRecord await write lock') const release = await this.store.lock.writeLock() log.trace('consumePeerRecord got write lock') @@ -113,7 +113,7 @@ export class PeerStoreAddressBook { return true } - async getRawEnvelope (peerId: PeerId) { + async getRawEnvelope (peerId: PeerId): Promise { log.trace('getRawEnvelope await read lock') const release = await this.store.lock.readLock() log.trace('getRawEnvelope got read lock') @@ -136,7 +136,7 @@ export class PeerStoreAddressBook { * Get an Envelope containing a PeerRecord for the given peer. * Returns undefined if no record exists. */ - async getPeerRecord (peerId: PeerId) { + async getPeerRecord (peerId: PeerId): Promise { const raw = await this.getRawEnvelope(peerId) if (raw == null) { @@ -146,7 +146,7 @@ export class PeerStoreAddressBook { return await RecordEnvelope.createFromProtobuf(raw) } - async get (peerId: PeerId) { + async get (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('get wait for read lock') @@ -169,7 +169,7 @@ export class PeerStoreAddressBook { return [] } - async set (peerId: PeerId, multiaddrs: Multiaddr[]) { + async set (peerId: PeerId, multiaddrs: Multiaddr[]): Promise { peerId = peerIdFromPeerId(peerId) if (!Array.isArray(multiaddrs)) { @@ -239,7 +239,7 @@ export class PeerStoreAddressBook { } } - async add (peerId: PeerId, multiaddrs: Multiaddr[]) { + async add (peerId: PeerId, multiaddrs: Multiaddr[]): Promise { peerId = peerIdFromPeerId(peerId) if (!Array.isArray(multiaddrs)) { @@ -307,7 +307,7 @@ export class PeerStoreAddressBook { } } - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('delete await write lock') @@ -345,7 +345,7 @@ export class PeerStoreAddressBook { } } -async function filterMultiaddrs (peerId: PeerId, multiaddrs: Multiaddr[], addressFilter: AddressFilter, isCertified: boolean = false) { +async function filterMultiaddrs (peerId: PeerId, multiaddrs: Multiaddr[], addressFilter: AddressFilter, isCertified: boolean = false): Promise { return await pipe( multiaddrs, (source) => each(source, (multiaddr) => { diff --git a/src/index.ts b/src/index.ts index abaf82e..4970254 100644 --- a/src/index.ts +++ b/src/index.ts @@ -41,7 +41,7 @@ export class PersistentPeerStore extends EventEmitter implement this.protoBook = new PeerStoreProtoBook(this.dispatchEvent.bind(this), this.store) } - async forEach (fn: (peer: Peer) => void) { + async forEach (fn: (peer: Peer) => void): Promise { log.trace('getPeers await read lock') const release = await this.store.lock.readLock() log.trace('getPeers got read lock') @@ -74,7 +74,7 @@ export class PersistentPeerStore extends EventEmitter implement /** * Delete the information of the given peer in every book */ - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { log.trace('delete await write lock') const release = await this.store.lock.writeLock() log.trace('delete got write lock') @@ -90,7 +90,7 @@ export class PersistentPeerStore extends EventEmitter implement /** * Get the stored information of a given peer */ - async get (peerId: PeerId) { + async get (peerId: PeerId): Promise { log.trace('get await read lock') const release = await this.store.lock.readLock() log.trace('get got read lock') @@ -106,7 +106,7 @@ export class PersistentPeerStore extends EventEmitter implement /** * Returns true if we have a record of the peer */ - async has (peerId: PeerId) { + async has (peerId: PeerId): Promise { log.trace('has await read lock') const release = await this.store.lock.readLock() log.trace('has got read lock') @@ -119,7 +119,7 @@ export class PersistentPeerStore extends EventEmitter implement } } - async tagPeer (peerId: PeerId, tag: string, options: TagOptions = {}) { + async tagPeer (peerId: PeerId, tag: string, options: TagOptions = {}): Promise { const providedValue = options.value ?? 0 const value = Math.round(providedValue) const ttl = options.ttl ?? undefined @@ -147,7 +147,7 @@ export class PersistentPeerStore extends EventEmitter implement await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }).subarray()) } - async unTagPeer (peerId: PeerId, tag: string) { + async unTagPeer (peerId: PeerId, tag: string): Promise { const buf = await this.metadataBook.getValue(peerId, 'tags') let tags: Tag[] = [] @@ -160,7 +160,7 @@ export class PersistentPeerStore extends EventEmitter implement await this.metadataBook.setValue(peerId, 'tags', Tags.encode({ tags }).subarray()) } - async getTags (peerId: PeerId) { + async getTags (peerId: PeerId): Promise> { const buf = await this.metadataBook.getValue(peerId, 'tags') let tags: Tag[] = [] diff --git a/src/key-book.ts b/src/key-book.ts index 65ef260..078964b 100644 --- a/src/key-book.ts +++ b/src/key-book.ts @@ -27,7 +27,7 @@ export class PeerStoreKeyBook implements KeyBook { /** * Set the Peer public key */ - async set (peerId: PeerId, publicKey: Uint8Array) { + async set (peerId: PeerId, publicKey: Uint8Array): Promise { peerId = peerIdFromPeerId(peerId) if (!(publicKey instanceof Uint8Array)) { @@ -68,7 +68,7 @@ export class PeerStoreKeyBook implements KeyBook { this.dispatchEvent(new CustomEvent(EVENT_NAME, { detail: { peerId, - publicKey: publicKey, + publicKey, oldPublicKey: peer == null ? undefined : peer.pubKey } })) @@ -78,7 +78,7 @@ export class PeerStoreKeyBook implements KeyBook { /** * Get Public key of the given PeerId, if stored */ - async get (peerId: PeerId) { + async get (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('get await write lock') @@ -99,7 +99,7 @@ export class PeerStoreKeyBook implements KeyBook { } } - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('delete await write lock') diff --git a/src/metadata-book.ts b/src/metadata-book.ts index f60fd4e..698a009 100644 --- a/src/metadata-book.ts +++ b/src/metadata-book.ts @@ -28,7 +28,7 @@ export class PeerStoreMetadataBook implements MetadataBook { /** * Get the known data of a provided peer */ - async get (peerId: PeerId) { + async get (peerId: PeerId): Promise> { peerId = peerIdFromPeerId(peerId) log.trace('get await read lock') @@ -54,7 +54,7 @@ export class PeerStoreMetadataBook implements MetadataBook { /** * Get specific metadata value, if it exists */ - async getValue (peerId: PeerId, key: string) { + async getValue (peerId: PeerId, key: string): Promise { peerId = peerIdFromPeerId(peerId) log.trace('getValue await read lock') @@ -75,7 +75,7 @@ export class PeerStoreMetadataBook implements MetadataBook { } } - async set (peerId: PeerId, metadata: Map) { + async set (peerId: PeerId, metadata: Map): Promise { peerId = peerIdFromPeerId(peerId) if (!(metadata instanceof Map)) { @@ -118,7 +118,7 @@ export class PeerStoreMetadataBook implements MetadataBook { /** * Set metadata key and value of a provided peer */ - async setValue (peerId: PeerId, key: string, value: Uint8Array) { + async setValue (peerId: PeerId, key: string, value: Uint8Array): Promise { peerId = peerIdFromPeerId(peerId) if (typeof key !== 'string' || !(value instanceof Uint8Array)) { @@ -164,7 +164,7 @@ export class PeerStoreMetadataBook implements MetadataBook { })) } - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('delete await write lock') @@ -203,7 +203,7 @@ export class PeerStoreMetadataBook implements MetadataBook { } } - async deleteValue (peerId: PeerId, key: string) { + async deleteValue (peerId: PeerId, key: string): Promise { peerId = peerIdFromPeerId(peerId) log.trace('deleteValue await write lock') diff --git a/src/proto-book.ts b/src/proto-book.ts index 3fb0b7a..9479e7e 100644 --- a/src/proto-book.ts +++ b/src/proto-book.ts @@ -24,7 +24,7 @@ export class PeerStoreProtoBook implements ProtoBook { this.store = store } - async get (peerId: PeerId) { + async get (peerId: PeerId): Promise { log.trace('get wait for read lock') const release = await this.store.lock.readLock() log.trace('get got read lock') @@ -45,7 +45,7 @@ export class PeerStoreProtoBook implements ProtoBook { return [] } - async set (peerId: PeerId, protocols: string[]) { + async set (peerId: PeerId, protocols: string[]): Promise { peerId = peerIdFromPeerId(peerId) if (!Array.isArray(protocols)) { @@ -94,7 +94,7 @@ export class PeerStoreProtoBook implements ProtoBook { })) } - async add (peerId: PeerId, protocols: string[]) { + async add (peerId: PeerId, protocols: string[]): Promise { peerId = peerIdFromPeerId(peerId) if (!Array.isArray(protocols)) { @@ -144,7 +144,7 @@ export class PeerStoreProtoBook implements ProtoBook { })) } - async remove (peerId: PeerId, protocols: string[]) { + async remove (peerId: PeerId, protocols: string[]): Promise { peerId = peerIdFromPeerId(peerId) if (!Array.isArray(protocols)) { @@ -196,7 +196,7 @@ export class PeerStoreProtoBook implements ProtoBook { })) } - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { peerId = peerIdFromPeerId(peerId) log.trace('delete await write lock') diff --git a/src/store.ts b/src/store.ts index ea0c6dd..9108fb9 100644 --- a/src/store.ts +++ b/src/store.ts @@ -45,7 +45,7 @@ export class PersistentStore { }) } - _peerIdToDatastoreKey (peerId: PeerId) { + _peerIdToDatastoreKey (peerId: PeerId): Key { if (peerId.type == null) { log.error('peerId must be an instance of peer-id to store data') throw new CodeError('peerId must be an instance of peer-id', codes.ERR_INVALID_PARAMETERS) @@ -55,11 +55,11 @@ export class PersistentStore { return new Key(`${NAMESPACE_COMMON}${b32key}`) } - async has (peerId: PeerId) { + async has (peerId: PeerId): Promise { return await this.components.datastore.has(this._peerIdToDatastoreKey(peerId)) } - async delete (peerId: PeerId) { + async delete (peerId: PeerId): Promise { await this.components.datastore.delete(this._peerIdToDatastoreKey(peerId)) } @@ -87,7 +87,7 @@ export class PersistentStore { } } - async save (peer: Peer) { + async save (peer: Peer): Promise { if (peer.pubKey != null && peer.id.publicKey != null && !uint8arrayEquals(peer.pubKey, peer.id.publicKey)) { log.error('peer publicKey bytes do not match peer id publicKey bytes') throw new CodeError('publicKey bytes do not match peer id publicKey bytes', codes.ERR_INVALID_PARAMETERS) @@ -135,13 +135,13 @@ export class PersistentStore { return await this.load(peer.id) } - async patch (peerId: PeerId, data: Partial) { + async patch (peerId: PeerId, data: Partial): Promise { const peer = await this.load(peerId) return await this._patch(peerId, data, peer) } - async patchOrCreate (peerId: PeerId, data: Partial) { + async patchOrCreate (peerId: PeerId, data: Partial): Promise { let peer: Peer try { @@ -157,7 +157,7 @@ export class PersistentStore { return await this._patch(peerId, data, peer) } - async _patch (peerId: PeerId, data: Partial, peer: Peer) { + async _patch (peerId: PeerId, data: Partial, peer: Peer): Promise { return await this.save({ ...peer, ...data, @@ -165,13 +165,13 @@ export class PersistentStore { }) } - async merge (peerId: PeerId, data: Partial) { + async merge (peerId: PeerId, data: Partial): Promise { const peer = await this.load(peerId) return await this._merge(peerId, data, peer) } - async mergeOrCreate (peerId: PeerId, data: Partial) { + async mergeOrCreate (peerId: PeerId, data: Partial): Promise { /** @type {Peer} */ let peer @@ -188,7 +188,7 @@ export class PersistentStore { return await this._merge(peerId, data, peer) } - async _merge (peerId: PeerId, data: Partial, peer: Peer) { + async _merge (peerId: PeerId, data: Partial, peer: Peer): Promise { // if the peer has certified addresses, use those in // favour of the supplied versions const addresses = new Map() @@ -227,7 +227,7 @@ export class PersistentStore { }) } - async * all () { + async * all (): AsyncGenerator { for await (const key of this.components.datastore.queryKeys({ prefix: NAMESPACE_COMMON })) { diff --git a/test/proto-book.spec.ts b/test/proto-book.spec.ts index ee3e7d4..84dbeb8 100644 --- a/test/proto-book.spec.ts +++ b/test/proto-book.spec.ts @@ -11,7 +11,7 @@ import { createEd25519PeerId } from '@libp2p/peer-id-factory' import type { PeerId } from '@libp2p/interface-peer-id' import type { ProtoBook } from '@libp2p/interface-peer-store' -const arraysAreEqual = (a: string[], b: string[]) => { +const arraysAreEqual = (a: string[], b: string[]): boolean => { if (a.length !== b.length) { return false } @@ -284,7 +284,7 @@ describe('protoBook', () => { const protocols = await pb.get(peerId) expect(protocols).to.have.deep.members(finalProtocols) - return await pWaitFor(() => spy.callCount === 2) + await pWaitFor(() => spy.callCount === 2) }) it('does not emit on remove if the content does not change', async () => {