Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakia committed Jan 15, 2021
1 parent b8e4b76 commit 2d3f048
Show file tree
Hide file tree
Showing 22 changed files with 1,340 additions and 697 deletions.
10 changes: 5 additions & 5 deletions dist/ipfslog.min.js

Large diffs are not rendered by default.

22 changes: 15 additions & 7 deletions lib/es5/entry-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,45 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var LRU = require('lru-cache');

var EntryIndex = /*#__PURE__*/function () {
function EntryIndex() {
var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
(0, _classCallCheck2["default"])(this, EntryIndex);
this._cache = entries;
this._cache = new LRU({
max: cacheSize
});
this.add(entries);
}

(0, _createClass2["default"])(EntryIndex, [{
key: "set",
value: function set(k, v) {
this._cache[k] = v;
this._cache.set(k, v);
}
}, {
key: "get",
value: function get(k) {
return this._cache[k];
return this._cache.get(k);
}
}, {
key: "delete",
value: function _delete(k) {
return delete this._cache[k];
this._cache.del(k);
}
}, {
key: "add",
value: function add(newItems) {
this._cache = Object.assign(this._cache, newItems);
value: function add(items) {
for (var k in items) {
this._cache.set(k, items[k]);
}
}
}, {
key: "length",
get: function get() {
return Object.values(this._cache).length;
return this._cache.length;
}
}]);
return EntryIndex;
Expand Down
5 changes: 5 additions & 0 deletions lib/es5/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ var getWriteFormatForVersion = function getWriteFormatForVersion(v) {
var getWriteFormat = function getWriteFormat(e) {
return Entry.isEntry(e) ? getWriteFormatForVersion(e.v) : getWriteFormatForVersion(e);
};
/*
* @description
* An ipfs-log entry
*/


var Entry = /*#__PURE__*/function () {
function Entry() {
Expand Down
14 changes: 10 additions & 4 deletions lib/es5/log-io.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ var LogIO = /*#__PURE__*/function () {
var _toMultihash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ipfs, log) {
var _ref,
format,
values,
_args = arguments;

return _regenerator["default"].wrap(function _callee$(_context) {
Expand All @@ -78,20 +79,25 @@ var LogIO = /*#__PURE__*/function () {

case 5:
if (!isDefined(format)) format = 'dag-cbor';
_context.next = 8;
return log.values();

if (!(log.values.length < 1)) {
_context.next = 8;
case 8:
values = _context.sent;

if (!(values.length < 1)) {
_context.next = 11;
break;
}

throw new Error('Can\'t serialize an empty log');

case 8:
case 11:
return _context.abrupt("return", io.write(ipfs, format, log.toJSON(), {
links: IPLD_LINKS
}));

case 9:
case 12:
case "end":
return _context.stop();
}
Expand Down
Loading

0 comments on commit 2d3f048

Please sign in to comment.