# All files / server object.js

22.73% Statements 5/22
0% Branches 0/4
0% Functions 0/12
23.81% Lines 5/21

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

     import { expose } from 'postmsg-rpc'
    import { pre, post } from 'prepost'
    import { dagNodeToJson, preDagNodeFromJson, dagLinkToJson, preDagLinkFromJson } from '../serialization/dag'
    import { preCidFromJson } from '../serialization/cid'
    import { isBufferJson, bufferFromJson, preBufferFromJson, bufferToJson } from '../serialization/buffer'

    export default function (getIpfs, opts) {
      return {
        new: expose('ipfs.object.new', pre(
          opts.pre('object.new'),
          post(
            (...args) => getIpfs().object.new(...args),
            dagNodeToJson
          )
        ), opts),
        put: expose('ipfs.object.put', pre(
          preDagNodeFromJson(0),
          preBufferFromJson(0),
          (...args) => {
            if (args[0] && isBufferJson(args[0].Data)) {
              args[0].Data = bufferFromJson(args[0].Data)
            }

            return args
          },
          opts.pre('object.put'),
          post(
            (...args) => getIpfs().object.put(...args),
            dagNodeToJson
          )
        ), opts),
        get: expose('ipfs.object.get', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('object.get'),
          post(
            (...args) => getIpfs().object.get(...args),
            dagNodeToJson
          )
        ), opts),
        data: expose('ipfs.object.data', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('object.data'),
          post(
            (...args) => getIpfs().object.data(...args),
            bufferToJson
          )
        ), opts),
        links: expose('ipfs.object.links', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('object.links'),
          post(
            (...args) => getIpfs().object.links(...args),
            (res) => res.map(dagLinkToJson)
          )
        ), opts),
        stat: expose('ipfs.object.stat', pre(
          preBufferFromJson(0),
          preCidFromJson(0),
          opts.pre('object.stat'),
          (...args) => getIpfs().object.stat(...args)
        ), opts),
        patch: {
          addLink: expose('ipfs.object.patch.addLink', pre(
            preBufferFromJson(0),
            preCidFromJson(0),
            preDagLinkFromJson(1),
            opts.pre('object.patch.addLink'),
            post(
              (...args) => getIpfs().object.patch.addLink(...args),
              dagNodeToJson
            )
          ), opts),
          rmLink: expose('ipfs.object.patch.rmLink', pre(
            preBufferFromJson(0),
            preCidFromJson(0),
            preDagLinkFromJson(1),
            opts.pre('object.patch.rmLink'),
            post(
              (...args) => getIpfs().object.patch.rmLink(...args),
              dagNodeToJson
            )
          ), opts),
          appendData: expose('ipfs.object.patch.appendData', pre(
            preBufferFromJson(0),
            preCidFromJson(0),
            preBufferFromJson(1),
            opts.pre('object.patch.appendData'),
            post(
              (...args) => getIpfs().object.patch.appendData(...args),
              dagNodeToJson
            )
          ), opts),
          setData: expose('ipfs.object.patch.setData', pre(
            preBufferFromJson(0),
            preCidFromJson(0),
            preBufferFromJson(1),
            opts.pre('object.patch.setData'),
            post(
              (...args) => getIpfs().object.patch.setData(...args),
              dagNodeToJson
            )
          ), opts)
        }
      }
    }