# All files / lib/serialization dag.js

98.18% Statements 54/55
85% Branches 17/20
100% Functions 19/19
100% Lines 54/54

    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

    1x

    1x

    1x

    1x

    1x
    62x
    62x
    62x
    62x
    62x

    1x
    62x

    1x
    64x

    1x
    104x

    1x
    38x
    43x
    57x

    43x
    12x
    12x
    12x

    31x

    1x
    38x
    43x
    57x

    43x
    12x

    43x

    1x
    16x

    1x
    16x

    1x
    4x

    1x
    4x

    1x
    38x
    4x
    8x

    4x
    4x

    4x

    1x
    38x
    4x
    8x

    4x
    4x

    4x

     'use strict';

    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.preDagLinkToJson = exports.preDagLinkFromJson = exports.isDagLinkJson = exports.isDagLink = exports.dagLinkToJson = exports.dagLinkFromJson = exports.preDagNodeToJson = exports.preDagNodeFromJson = exports.isDagNodeJson = exports.isDagNode = exports.dagNodeToJson = exports.dagNodeFromJson = undefined;

    var _ipldDagPb = require('ipld-dag-pb');

    var _buffer = require('./buffer');

    var dagNodeFromJson = exports.dagNodeFromJson = function dagNodeFromJson(obj) {
      return new Promise(function (resolve, reject) {
        var links = obj.links.map(dagLinkFromJson);
        _ipldDagPb.DAGNode.create((0, _buffer.bufferFromJson)(obj.data), links, function (err, dagNode) {
          Iif (err) return reject(err);
          resolve(dagNode);
        });
      });
    };

    var dagNodeToJson = exports.dagNodeToJson = function dagNodeToJson(dagNode) {
      return {
        __ipfsPostMsgProxyType: 'DAGNode',
        links: dagNode.links.map(dagLinkToJson),
        data: (0, _buffer.bufferToJson)(dagNode.data)
      };
    };

    var isDagNode = exports.isDagNode = function isDagNode(obj) {
      return obj && obj.constructor && obj.constructor.name === 'DAGNode';
    };
    var isDagNodeJson = exports.isDagNodeJson = function isDagNodeJson(obj) {
      return obj && obj.__ipfsPostMsgProxyType === 'DAGNode';
    };

    var preDagNodeFromJson = exports.preDagNodeFromJson = function preDagNodeFromJson(index) {
      return function () {
        for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
          args[_key] = arguments[_key];
        }

        if (isDagNodeJson(args[index])) {
          return dagNodeFromJson(args[index]).then(function (dagNode) {
            args[index] = dagNode;
            return args;
          });
        }
        return args;
      };
    };

    var preDagNodeToJson = exports.preDagNodeToJson = function preDagNodeToJson(index) {
      return function () {
        for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
          args[_key2] = arguments[_key2];
        }

        if (isDagNode(args[index])) {
          args[index] = dagNodeToJson(args[index]);
        }
        return args;
      };
    };

    var dagLinkFromJson = exports.dagLinkFromJson = function dagLinkFromJson(obj) {
      return new _ipldDagPb.DAGLink(obj.name, obj.size, obj.multihash);
    };

    var dagLinkToJson = exports.dagLinkToJson = function dagLinkToJson(link) {
      return Object.assign({ __ipfsPostMsgProxyType: 'DAGLink' }, link.toJSON());
    };

    var isDagLink = exports.isDagLink = function isDagLink(obj) {
      return obj && obj.constructor && obj.constructor.name === 'DAGLink';
    };
    var isDagLinkJson = exports.isDagLinkJson = function isDagLinkJson(obj) {
      return obj && obj.__ipfsPostMsgProxyType === 'DAGLink';
    };

    var preDagLinkFromJson = exports.preDagLinkFromJson = function preDagLinkFromJson(index) {
      return function () {
        for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
          args[_key3] = arguments[_key3];
        }

        Eif (isDagLinkJson(args[index])) {
          args[index] = dagLinkFromJson(args[index]);
        }
        return args;
      };
    };

    var preDagLinkToJson = exports.preDagLinkToJson = function preDagLinkToJson(index) {
      return function () {
        for (var _len4 = arguments.length, args = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
          args[_key4] = arguments[_key4];
        }

        Eif (isDagLink(args[index])) {
          args[index] = dagLinkToJson(args[index]);
        }
        return args;
      };
    };