# All files / src/client dht.js

83.33% Statements 10/12
33.33% Branches 2/6
60% Functions 3/5
83.33% Lines 10/12

    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
    521x
    1x
    1x
    1x
    1x
    1x

    23x

    1x

    1x
    2x

     import { caller } from 'postmsg-rpc'
    import callbackify from 'callbackify'
    import { pre, post } from 'prepost'
    import { preCidToJson } from '../serialization/cid'
    import { prePeerIdToJson, peerInfoFromJson, isPeerInfo } from '../serialization/peer'
    import { preBufferToJson } 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),
            preCidToJson(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))
              )
            )
          )
        )
      }
    }