Skip to content

Commit a2bc9ff

Browse files
authored
fix: reverse validator args (#145)
They are `key`, `value`, not `value`, `key`.
1 parent e1d00b3 commit a2bc9ff

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ export class PubSubDatastore extends BaseDatastore {
241241
/**
242242
* Validate record according to the received validation function
243243
*
244+
* @param {Uint8Array} key
244245
* @param {Uint8Array} value
245-
* @param {Uint8Array} peerId
246246
*/
247-
async _validateRecord (value, peerId) { // eslint-disable-line require-await
248-
return this._validator(value, peerId)
247+
async _validateRecord (key, value) { // eslint-disable-line require-await
248+
return this._validator(key, value)
249249
}
250250

251251
/**
@@ -269,7 +269,7 @@ export class PubSubDatastore extends BaseDatastore {
269269
*/
270270
async _isBetter (key, val) {
271271
try {
272-
await this._validateRecord(val, key)
272+
await this._validateRecord(key, val)
273273
} catch (/** @type {any} */ err) {
274274
// If not valid, it is not better than the one currently available
275275
const errMsg = 'record received through pubsub is not valid'

test/index.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ describe('datastore-pubsub', function () {
143143

144144
it('should validate if record content is the same', async () => {
145145
/** @type {Validator} */
146-
const customValidator = async (data) => {
146+
const customValidator = async (key, data) => {
147147
const receivedRecord = Libp2pRecord.deserialize(data)
148148

149149
expect(uint8ArrayToString(receivedRecord.value)).to.equal(value) // validator should deserialize correctly

0 commit comments

Comments
 (0)