# All files / client object.js

43.75% Statements 7/16
0% Branches 0/10
0% Functions 0/5
46.67% Lines 7/15

    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
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    1181x
    1x
    1x
    1x
    1x
    1x

    1x

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

    export default function (opts) {
      return {
        new: callbackify.variadic(
          post(
            caller('ipfs.object.new', opts),
            (res) => isDagNodeJson(res) ? dagNodeFromJson(res) : res
          )
        ),
        put: callbackify.variadic(
          pre(
            preDagNodeToJson(0),
            preBufferToJson(0),
            (...args) => {
              if (args[0] && isBuffer(args[0].Data)) {
                args[0] = Object.assign({}, args[0], { Data: bufferToJson(args[0].Data) })
              }

              return args
            },
            post(
              caller('ipfs.object.put', opts),
              (res) => isDagNodeJson(res) ? dagNodeFromJson(res) : res
            )
          )
        ),
        get: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            post(
              caller('ipfs.object.get', opts),
              (res) => isDagNodeJson(res) ? dagNodeFromJson(res) : res
            )
          )
        ),
        data: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            post(
              caller('ipfs.object.data', opts),
              bufferFromJson
            )
          )
        ),
        links: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            post(
              caller('ipfs.object.links', opts),
              (res) => res.map(dagLinkFromJson)
            )
          )
        ),
        stat: callbackify.variadic(
          pre(
            preBufferToJson(0),
            preCidToJson(0),
            caller('ipfs.object.stat', opts)
          )
        ),
        patch: {
          addLink: callbackify.variadic(
            pre(
              preBufferToJson(0),
              preCidToJson(0),
              preDagLinkToJson(1),
              post(
                caller('ipfs.object.patch.addLink', opts),
                dagNodeFromJson
              )
            )
          ),
          rmLink: callbackify.variadic(
            pre(
              preBufferToJson(0),
              preCidToJson(0),
              preDagLinkToJson(1),
              post(
                caller('ipfs.object.patch.rmLink', opts),
                dagNodeFromJson
              )
            )
          ),
          appendData: callbackify.variadic(
            pre(
              preBufferToJson(0),
              preCidToJson(0),
              preBufferToJson(1),
              post(
                caller('ipfs.object.patch.appendData', opts),
                dagNodeFromJson
              )
            )
          ),
          setData: callbackify.variadic(
            pre(
              preBufferToJson(0),
              preCidToJson(0),
              preBufferToJson(1),
              post(
                caller('ipfs.object.patch.setData', opts),
                dagNodeFromJson
              )
            )
          )
        }
      }
    }