diff --git a/src/index.js b/src/index.js index a4b6e67..bb6e68e 100644 --- a/src/index.js +++ b/src/index.js @@ -241,11 +241,11 @@ export class PubSubDatastore extends BaseDatastore { /** * Validate record according to the received validation function * + * @param {Uint8Array} key * @param {Uint8Array} value - * @param {Uint8Array} peerId */ - async _validateRecord (value, peerId) { // eslint-disable-line require-await - return this._validator(value, peerId) + async _validateRecord (key, value) { // eslint-disable-line require-await + return this._validator(key, value) } /** @@ -269,7 +269,7 @@ export class PubSubDatastore extends BaseDatastore { */ async _isBetter (key, val) { try { - await this._validateRecord(val, key) + await this._validateRecord(key, val) } catch (/** @type {any} */ err) { // If not valid, it is not better than the one currently available const errMsg = 'record received through pubsub is not valid' diff --git a/test/index.spec.js b/test/index.spec.js index ab8feb2..1a3a709 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -143,7 +143,7 @@ describe('datastore-pubsub', function () { it('should validate if record content is the same', async () => { /** @type {Validator} */ - const customValidator = async (data) => { + const customValidator = async (key, data) => { const receivedRecord = Libp2pRecord.deserialize(data) expect(uint8ArrayToString(receivedRecord.value)).to.equal(value) // validator should deserialize correctly