@libp2p/peer-store 6.0.2 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +9 -9
- package/dist/src/address-book.d.ts +2 -2
- package/dist/src/address-book.d.ts.map +1 -1
- package/dist/src/address-book.js +10 -10
- package/dist/src/address-book.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/key-book.d.ts.map +1 -1
- package/dist/src/key-book.js +1 -1
- package/dist/src/key-book.js.map +1 -1
- package/dist/src/metadata-book.d.ts +1 -1
- package/dist/src/metadata-book.d.ts.map +1 -1
- package/dist/src/proto-book.d.ts.map +1 -1
- package/dist/src/store.d.ts.map +1 -1
- package/package.json +3 -5
- package/src/address-book.ts +26 -25
- package/src/index.ts +7 -7
- package/src/key-book.ts +4 -4
- package/src/metadata-book.ts +6 -6
- package/src/proto-book.ts +5 -5
- package/src/store.ts +11 -11
package/src/store.ts
CHANGED
|
@@ -45,7 +45,7 @@ export class PersistentStore {
|
|
|
45
45
|
})
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
_peerIdToDatastoreKey (peerId: PeerId) {
|
|
48
|
+
_peerIdToDatastoreKey (peerId: PeerId): Key {
|
|
49
49
|
if (peerId.type == null) {
|
|
50
50
|
log.error('peerId must be an instance of peer-id to store data')
|
|
51
51
|
throw new CodeError('peerId must be an instance of peer-id', codes.ERR_INVALID_PARAMETERS)
|
|
@@ -55,11 +55,11 @@ export class PersistentStore {
|
|
|
55
55
|
return new Key(`${NAMESPACE_COMMON}${b32key}`)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
async has (peerId: PeerId) {
|
|
58
|
+
async has (peerId: PeerId): Promise<boolean> {
|
|
59
59
|
return await this.components.datastore.has(this._peerIdToDatastoreKey(peerId))
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
async delete (peerId: PeerId) {
|
|
62
|
+
async delete (peerId: PeerId): Promise<void> {
|
|
63
63
|
await this.components.datastore.delete(this._peerIdToDatastoreKey(peerId))
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -87,7 +87,7 @@ export class PersistentStore {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
async save (peer: Peer) {
|
|
90
|
+
async save (peer: Peer): Promise<Peer> {
|
|
91
91
|
if (peer.pubKey != null && peer.id.publicKey != null && !uint8arrayEquals(peer.pubKey, peer.id.publicKey)) {
|
|
92
92
|
log.error('peer publicKey bytes do not match peer id publicKey bytes')
|
|
93
93
|
throw new CodeError('publicKey bytes do not match peer id publicKey bytes', codes.ERR_INVALID_PARAMETERS)
|
|
@@ -135,13 +135,13 @@ export class PersistentStore {
|
|
|
135
135
|
return await this.load(peer.id)
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
async patch (peerId: PeerId, data: Partial<Peer>) {
|
|
138
|
+
async patch (peerId: PeerId, data: Partial<Peer>): Promise<Peer> {
|
|
139
139
|
const peer = await this.load(peerId)
|
|
140
140
|
|
|
141
141
|
return await this._patch(peerId, data, peer)
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
async patchOrCreate (peerId: PeerId, data: Partial<Peer>) {
|
|
144
|
+
async patchOrCreate (peerId: PeerId, data: Partial<Peer>): Promise<Peer> {
|
|
145
145
|
let peer: Peer
|
|
146
146
|
|
|
147
147
|
try {
|
|
@@ -157,7 +157,7 @@ export class PersistentStore {
|
|
|
157
157
|
return await this._patch(peerId, data, peer)
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
async _patch (peerId: PeerId, data: Partial<Peer>, peer: Peer) {
|
|
160
|
+
async _patch (peerId: PeerId, data: Partial<Peer>, peer: Peer): Promise<Peer> {
|
|
161
161
|
return await this.save({
|
|
162
162
|
...peer,
|
|
163
163
|
...data,
|
|
@@ -165,13 +165,13 @@ export class PersistentStore {
|
|
|
165
165
|
})
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
async merge (peerId: PeerId, data: Partial<Peer>) {
|
|
168
|
+
async merge (peerId: PeerId, data: Partial<Peer>): Promise<Peer> {
|
|
169
169
|
const peer = await this.load(peerId)
|
|
170
170
|
|
|
171
171
|
return await this._merge(peerId, data, peer)
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
async mergeOrCreate (peerId: PeerId, data: Partial<Peer>) {
|
|
174
|
+
async mergeOrCreate (peerId: PeerId, data: Partial<Peer>): Promise<Peer> {
|
|
175
175
|
/** @type {Peer} */
|
|
176
176
|
let peer
|
|
177
177
|
|
|
@@ -188,7 +188,7 @@ export class PersistentStore {
|
|
|
188
188
|
return await this._merge(peerId, data, peer)
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
-
async _merge (peerId: PeerId, data: Partial<Peer>, peer: Peer) {
|
|
191
|
+
async _merge (peerId: PeerId, data: Partial<Peer>, peer: Peer): Promise<Peer> {
|
|
192
192
|
// if the peer has certified addresses, use those in
|
|
193
193
|
// favour of the supplied versions
|
|
194
194
|
const addresses = new Map<string, boolean>()
|
|
@@ -227,7 +227,7 @@ export class PersistentStore {
|
|
|
227
227
|
})
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
async * all () {
|
|
230
|
+
async * all (): AsyncGenerator<Peer, void, unknown> {
|
|
231
231
|
for await (const key of this.components.datastore.queryKeys({
|
|
232
232
|
prefix: NAMESPACE_COMMON
|
|
233
233
|
})) {
|