@@ -14,7 +14,7 @@ const log = Object.assign(debug('datastore-pubsub:publisher'), {
1414 * @typedef {import('peer-id') } PeerId
1515 * @typedef {import('./types').Validator } Validator
1616 * @typedef {import('./types').SubscriptionKeyFn } SubscriptionKeyFn
17- * @typedef {import('libp2p-interfaces/src/pubsub/message ').Message } PubSubMessage
17+ * @typedef {import('libp2p-interfaces/src/pubsub').InMessage } PubSubMessage
1818 */
1919
2020// DatastorePubsub is responsible for providing an api for pubsub to be used as a datastore with
@@ -253,11 +253,11 @@ class DatastorePubsub extends Adapter {
253253 /**
254254 * Select the best record according to the received select function
255255 *
256- * @param {Uint8Array } receivedRecord
257- * @param {Uint8Array } currentRecord
256+ * @param {Uint8Array } key
257+ * @param {Uint8Array[] } records
258258 */
259- async _selectRecord ( receivedRecord , currentRecord ) {
260- const res = await this . _validator . select ( receivedRecord , currentRecord )
259+ async _selectRecord ( key , records ) {
260+ const res = await this . _validator . select ( key , records )
261261
262262 // If the selected was the first (0), it should be stored (true)
263263 return res === 0
@@ -270,17 +270,10 @@ class DatastorePubsub extends Adapter {
270270 * @param {Uint8Array } val
271271 */
272272 async _isBetter ( key , val ) {
273- // validate received record
274- let error , valid
275-
276273 try {
277- valid = await this . _validateRecord ( val , key )
274+ await this . _validateRecord ( val , key )
278275 } catch ( err ) {
279- error = err
280- }
281-
282- // If not valid, it is not better than the one currently available
283- if ( error || ! valid ) {
276+ // If not valid, it is not better than the one currently available
284277 const errMsg = 'record received through pubsub is not valid'
285278
286279 log . error ( errMsg )
@@ -304,7 +297,7 @@ class DatastorePubsub extends Adapter {
304297 }
305298
306299 // verify if the received record should replace the current one
307- return this . _selectRecord ( val , currentRecord )
300+ return this . _selectRecord ( key , [ currentRecord , val ] )
308301 }
309302
310303 /**
0 commit comments