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

Commit 2d3f048

Browse files
committed
wip
1 parent b8e4b76 commit 2d3f048

22 files changed

+1340
-697
lines changed

dist/ipfslog.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/es5/entry-index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,45 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
66

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

9+
var LRU = require('lru-cache');
10+
911
var EntryIndex = /*#__PURE__*/function () {
1012
function EntryIndex() {
1113
var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
14+
var cacheSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
1215
(0, _classCallCheck2["default"])(this, EntryIndex);
13-
this._cache = entries;
16+
this._cache = new LRU({
17+
max: cacheSize
18+
});
19+
this.add(entries);
1420
}
1521

1622
(0, _createClass2["default"])(EntryIndex, [{
1723
key: "set",
1824
value: function set(k, v) {
19-
this._cache[k] = v;
25+
this._cache.set(k, v);
2026
}
2127
}, {
2228
key: "get",
2329
value: function get(k) {
24-
return this._cache[k];
30+
return this._cache.get(k);
2531
}
2632
}, {
2733
key: "delete",
2834
value: function _delete(k) {
29-
return delete this._cache[k];
35+
this._cache.del(k);
3036
}
3137
}, {
3238
key: "add",
33-
value: function add(newItems) {
34-
this._cache = Object.assign(this._cache, newItems);
39+
value: function add(items) {
40+
for (var k in items) {
41+
this._cache.set(k, items[k]);
42+
}
3543
}
3644
}, {
3745
key: "length",
3846
get: function get() {
39-
return Object.values(this._cache).length;
47+
return this._cache.length;
4048
}
4149
}]);
4250
return EntryIndex;

lib/es5/entry.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ var getWriteFormatForVersion = function getWriteFormatForVersion(v) {
3131
var getWriteFormat = function getWriteFormat(e) {
3232
return Entry.isEntry(e) ? getWriteFormatForVersion(e.v) : getWriteFormatForVersion(e);
3333
};
34+
/*
35+
* @description
36+
* An ipfs-log entry
37+
*/
38+
3439

3540
var Entry = /*#__PURE__*/function () {
3641
function Entry() {

lib/es5/log-io.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var LogIO = /*#__PURE__*/function () {
5353
var _toMultihash = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee(ipfs, log) {
5454
var _ref,
5555
format,
56+
values,
5657
_args = arguments;
5758

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

7980
case 5:
8081
if (!isDefined(format)) format = 'dag-cbor';
82+
_context.next = 8;
83+
return log.values();
8184

82-
if (!(log.values.length < 1)) {
83-
_context.next = 8;
85+
case 8:
86+
values = _context.sent;
87+
88+
if (!(values.length < 1)) {
89+
_context.next = 11;
8490
break;
8591
}
8692

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

89-
case 8:
95+
case 11:
9096
return _context.abrupt("return", io.write(ipfs, format, log.toJSON(), {
9197
links: IPLD_LINKS
9298
}));
9399

94-
case 9:
100+
case 12:
95101
case "end":
96102
return _context.stop();
97103
}

0 commit comments

Comments
 (0)