All files / client dht.js

58.33% Statements 7/12
0% Branches 0/6
0% Functions 0/5
58.33% Lines 7/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 541x 1x 1x 1x 1x 1x     39x                                                                                          
import { caller } from 'postmsg-rpc'
import callbackify from 'callbackify'
import { pre, post } from 'prepost'
import { preCidToJson, preArrayOfCidToJson } from '../serialization/cid'
import { prePeerIdToJson, peerInfoFromJson, isPeerInfo } from '../serialization/peer'
import { preBufferToJson, preArrayOfBufferToJson } from '../serialization/buffer'
 
export default function (opts) {
  return {
    put: callbackify.variadic(caller('ipfs.dht.put', opts)),
    get: callbackify.variadic(caller('ipfs.dht.get', opts)),
    findprovs: callbackify.variadic(
      pre(
        preBufferToJson(0),
        post(
          caller('ipfs.dht.findprovs', opts),
          (res) => Promise.all(
            res.map((item) => isPeerInfo(item) ? peerInfoFromJson(item) : Promise.resolve(item))
          )
        )
      )
    ),
    findpeer: callbackify.variadic(
      pre(
        prePeerIdToJson(0),
        post(
          caller('ipfs.dht.findpeer', opts),
          (res) => isPeerInfo(res) ? peerInfoFromJson(res) : res
        )
      )
    ),
    provide: callbackify.variadic(
      pre(
        preBufferToJson(0),
        preArrayOfBufferToJson(0),
        preCidToJson(0),
        preArrayOfCidToJson(0),
        caller('ipfs.dht.provide', opts)
      )
    ),
    query: callbackify.variadic(
      pre(
        prePeerIdToJson(0),
        post(
          caller('ipfs.dht.query', opts),
          (res) => Promise.all(
            res.map((item) => isPeerInfo(item) ? peerInfoFromJson(item) : Promise.resolve(item))
          )
        )
      )
    )
  }
}