# All files / src/client dag.js

100% Statements 19/19
87.5% Branches 7/8
100% Functions 3/3
100% Lines 17/17

    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
    54
    55
    56
    571x
    1x
    1x
    1x
    1x
    1x
    1x

    23x

    24x
    12x
    7x

    12x

    9x
    2x

    7x
    7x

    7x

     import { caller } from 'postmsg-rpc'
    import callbackify from 'callbackify'
    import { pre, post } from 'prepost'
    import { isDagNodeJson, preDagNodeToJson, dagNodeFromJson } from '../serialization/dag'
    import { cidFromJson, preCidToJson } from '../serialization/cid'
    import { isBuffer, isBufferJson, preBufferToJson, bufferToJson, bufferFromJson } from '../serialization/buffer'
    import { convertValues } from '../converters'

    export default function (opts) {
      return {
        put: callbackify.variadic(
          pre(
            preDagNodeToJson(0),
            (...args) => {
              if (args[0] && !isDagNodeJson(args[0])) {
                args[0] = convertValues(args[0], isBuffer, bufferToJson)
              }

              return args
            },
            post(
              caller('ipfs.dag.put', opts),
              cidFromJson
            )
          )
        ),
        get: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            post(
              caller('ipfs.dag.get', opts),
              (res) => {
                if (isDagNodeJson(res.value)) {
                  return dagNodeFromJson(res.value).then((value) => ({ value }))
                }

                // TODO: CBOR node, is this correct?
                Eif (res.value) {
                  res.value = convertValues(res.value, isBufferJson, bufferFromJson)
                }

                return res
              }
            )
          )
        ),
        tree: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            caller('ipfs.dag.tree', opts)
          )
        )
      }
    }