From 5ad315d6ccb0317f7e1499f6b91a2bd90093645e Mon Sep 17 00:00:00 2001 From: Mark Henderson Date: Sun, 10 May 2020 21:58:37 -0400 Subject: [PATCH] wip: upgrade to js-ipfs 0.43.0 and go-ipfs 0.5.0 --- .gitignore | 1 + lib/es5/default-access-controller.js | 8 +- lib/es5/entry-index.js | 4 +- lib/es5/entry-io.js | 44 ++---- lib/es5/entry.js | 20 +-- lib/es5/g-set.js | 4 +- lib/es5/lamport-clock.js | 4 +- lib/es5/log-io.js | 24 +--- lib/es5/log.js | 192 ++++++++++++--------------- package.json | 27 ++-- test/browser/index.html | 6 +- test/entry-io.spec.js | 7 +- test/entry.spec.js | 7 +- test/log-append.spec.js | 7 +- test/log-crdt.spec.js | 7 +- test/log-heads-tails.spec.js | 7 +- test/log-iterator.spec.js | 7 +- test/log-join-concurrent.spec.js | 7 +- test/log-join.spec.js | 7 +- test/log-load.spec.js | 7 +- test/log-references.spec.js | 7 +- test/log.spec.js | 8 +- test/replicate.spec.js | 12 +- test/signed-log.spec.js | 7 +- webpack.tests.config.js | 4 +- 25 files changed, 184 insertions(+), 251 deletions(-) diff --git a/.gitignore b/.gitignore index f274a208..c2f4a377 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ ipfs-log-benchmarks/ examples/browser/bundle.js.map examples/browser/ipfs.min.js examples/browser/ipfslog.min.js +.nyc_output diff --git a/lib/es5/default-access-controller.js b/lib/es5/default-access-controller.js index 550591d5..c73d6597 100644 --- a/lib/es5/default-access-controller.js +++ b/lib/es5/default-access-controller.js @@ -10,9 +10,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); -var AccessController = -/*#__PURE__*/ -function () { +var AccessController = /*#__PURE__*/function () { function AccessController() { (0, _classCallCheck2.default)(this, AccessController); } @@ -20,9 +18,7 @@ function () { (0, _createClass2.default)(AccessController, [{ key: "canAppend", value: function () { - var _canAppend = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(entry, identityProvider) { + var _canAppend = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(entry, identityProvider) { return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { diff --git a/lib/es5/entry-index.js b/lib/es5/entry-index.js index 527841ba..b652336a 100644 --- a/lib/es5/entry-index.js +++ b/lib/es5/entry-index.js @@ -6,9 +6,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); -var EntryIndex = -/*#__PURE__*/ -function () { +var EntryIndex = /*#__PURE__*/function () { function EntryIndex() { var entries = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; (0, _classCallCheck2.default)(this, EntryIndex); diff --git a/lib/es5/entry-io.js b/lib/es5/entry-io.js index c44c2869..440e57db 100644 --- a/lib/es5/entry-io.js +++ b/lib/es5/entry-io.js @@ -20,9 +20,7 @@ var hasItems = function hasItems(arr) { return arr && arr.length > 0; }; -var EntryIO = -/*#__PURE__*/ -function () { +var EntryIO = /*#__PURE__*/function () { function EntryIO() { (0, _classCallCheck2.default)(this, EntryIO); } @@ -31,9 +29,7 @@ function () { key: "fetchParallel", // Fetch log graphs in parallel value: function () { - var _fetchParallel = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee2(ipfs, hashes, _ref) { + var _fetchParallel = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(ipfs, hashes, _ref) { var length, _ref$exclude, exclude, timeout, concurrency, onProgressCallback, fetchOne, concatArrays, flatten, res; return _regenerator.default.wrap(function _callee2$(_context2) { @@ -42,12 +38,8 @@ function () { case 0: length = _ref.length, _ref$exclude = _ref.exclude, exclude = _ref$exclude === void 0 ? [] : _ref$exclude, timeout = _ref.timeout, concurrency = _ref.concurrency, onProgressCallback = _ref.onProgressCallback; - fetchOne = - /*#__PURE__*/ - function () { - var _ref2 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(hash) { + fetchOne = /*#__PURE__*/function () { + var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(hash) { return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { @@ -120,9 +112,7 @@ function () { }, { key: "fetchAll", value: function () { - var _fetchAll = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee6(ipfs, hashes) { + var _fetchAll = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(ipfs, hashes) { var _ref3, _ref3$length, length, @@ -215,12 +205,8 @@ function () { }; // Fetch one entry and add it to the results - fetchEntry = - /*#__PURE__*/ - function () { - var _ref4 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee4(hash) { + fetchEntry = /*#__PURE__*/function () { + var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(hash) { return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { @@ -233,12 +219,8 @@ function () { return _context4.abrupt("return"); case 2: - return _context4.abrupt("return", new Promise( - /*#__PURE__*/ - function () { - var _ref5 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee3(resolve, reject) { + return _context4.abrupt("return", new Promise( /*#__PURE__*/function () { + var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) { var timer, addToResults, entry, sleep; return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { @@ -369,12 +351,8 @@ function () { }(); // One loop of processing the loading queue - _processQueue = - /*#__PURE__*/ - function () { - var _ref6 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee5() { + _processQueue = /*#__PURE__*/function () { + var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() { var nexts; return _regenerator.default.wrap(function _callee5$(_context5) { while (1) { diff --git a/lib/es5/entry.js b/lib/es5/entry.js index 7ce8d48b..78cf50f5 100644 --- a/lib/es5/entry.js +++ b/lib/es5/entry.js @@ -32,9 +32,7 @@ var getWriteFormat = function getWriteFormat(e) { return Entry.isEntry(e) ? getWriteFormatForVersion(e.v) : getWriteFormatForVersion(e); }; -var Entry = -/*#__PURE__*/ -function () { +var Entry = /*#__PURE__*/function () { function Entry() { (0, _classCallCheck2.default)(this, Entry); } @@ -57,9 +55,7 @@ function () { * // { hash: null, payload: "hello", next: [] } */ value: function () { - var _create = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(ipfs, identity, logId, data) { + var _create = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(ipfs, identity, logId, data) { var next, clock, refs, @@ -178,9 +174,7 @@ function () { }, { key: "verify", value: function () { - var _verify = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee2(identityProvider, entry) { + var _verify = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(identityProvider, entry) { var e, verifier; return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { @@ -265,9 +259,7 @@ function () { }, { key: "toMultihash", value: function () { - var _toMultihash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee3(ipfs, entry) { + var _toMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(ipfs, entry) { var pin, e, _args3 = arguments; @@ -365,9 +357,7 @@ function () { }, { key: "fromMultihash", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee4(ipfs, hash) { + var _fromMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(ipfs, hash) { var e, entry; return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { diff --git a/lib/es5/g-set.js b/lib/es5/g-set.js index de15cb63..2b89c85c 100644 --- a/lib/es5/g-set.js +++ b/lib/es5/g-set.js @@ -13,9 +13,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); -var GSet = -/*#__PURE__*/ -function () { +var GSet = /*#__PURE__*/function () { function GSet(values) { (0, _classCallCheck2.default)(this, GSet); } // eslint-disable-line diff --git a/lib/es5/lamport-clock.js b/lib/es5/lamport-clock.js index f64116ed..a2df6636 100644 --- a/lib/es5/lamport-clock.js +++ b/lib/es5/lamport-clock.js @@ -6,9 +6,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); -var LamportClock = -/*#__PURE__*/ -function () { +var LamportClock = /*#__PURE__*/function () { function LamportClock(id, time) { (0, _classCallCheck2.default)(this, LamportClock); this.id = id; diff --git a/lib/es5/log-io.js b/lib/es5/log-io.js index cbd791fd..6ea05a05 100644 --- a/lib/es5/log-io.js +++ b/lib/es5/log-io.js @@ -33,9 +33,7 @@ var last = function last(arr, n) { return arr.slice(arr.length - Math.min(arr.length, n), arr.length); }; -var LogIO = -/*#__PURE__*/ -function () { +var LogIO = /*#__PURE__*/function () { function LogIO() { (0, _classCallCheck2.default)(this, LogIO); } @@ -52,9 +50,7 @@ function () { * @deprecated */ value: function () { - var _toMultihash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(ipfs, log) { + var _toMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(ipfs, log) { var _ref, format, _args = arguments; @@ -122,9 +118,7 @@ function () { }, { key: "fromMultihash", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee2(ipfs, hash, _ref2) { + var _fromMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(ipfs, hash, _ref2) { var _ref2$length, length, _ref2$exclude, exclude, timeout, concurrency, sortFn, onProgressCallback, logData, isHead, all, logId, entries, heads; return _regenerator.default.wrap(function _callee2$(_context2) { @@ -219,9 +213,7 @@ function () { }, { key: "fromEntryHash", value: function () { - var _fromEntryHash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee3(ipfs, hash, _ref3) { + var _fromEntryHash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(ipfs, hash, _ref3) { var _ref3$length, length, _ref3$exclude, exclude, timeout, concurrency, sortFn, onProgressCallback, hashes, all, entries; return _regenerator.default.wrap(function _callee3$(_context3) { @@ -296,9 +288,7 @@ function () { }, { key: "fromJSON", value: function () { - var _fromJSON = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee4(ipfs, json, _ref4) { + var _fromJSON = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(ipfs, json, _ref4) { var _ref4$length, length, timeout, concurrency, onProgressCallback, id, heads, headHashes, all, entries; return _regenerator.default.wrap(function _callee4$(_context4) { @@ -363,9 +353,7 @@ function () { }, { key: "fromEntry", value: function () { - var _fromEntry = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee5(ipfs, sourceEntries, _ref5) { + var _fromEntry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(ipfs, sourceEntries, _ref5) { var _ref5$length, length, _ref5$exclude, exclude, timeout, concurrency, onProgressCallback, hashes, all, combined, uniques, sliced, missingSourceEntries, replaceInFront, entries, logId; return _regenerator.default.wrap(function _callee5$(_context5) { diff --git a/lib/es5/log.js b/lib/es5/log.js index 477116d7..10c934b9 100644 --- a/lib/es5/log.js +++ b/lib/es5/log.js @@ -12,11 +12,15 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); +var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); + var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")); var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")); -var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits")); +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function () { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } var pMap = require('p-map'); @@ -79,11 +83,11 @@ var uniqueEntriesReducer = function uniqueEntriesReducer(res, acc) { */ -var Log = -/*#__PURE__*/ -function (_GSet) { +var Log = /*#__PURE__*/function (_GSet) { (0, _inherits2.default)(Log, _GSet); + var _super = _createSuper(Log); + /** * Create a new Log instance * @param {IPFS} ipfs An IPFS instance @@ -135,7 +139,7 @@ function (_GSet) { sortFn = LastWriteWins; } - _this = (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Log).call(this)); + _this = _super.call(this); _this._sortFn = NoZeroes(sortFn); _this._storage = ipfs; _this._id = logId || randomId(); // Access Controller @@ -282,9 +286,7 @@ function (_GSet) { }, { key: "append", value: function () { - var _append = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee(data) { + var _append = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(data) { var _this3 = this; var pointerCount, @@ -431,20 +433,17 @@ function (_GSet) { _ref2$amount = _ref2.amount, amount = _ref2$amount === void 0 ? -1 : _ref2$amount; - if (amount === 0) return ( - /*#__PURE__*/ - _regenerator.default.mark(function _callee2() { - return _regenerator.default.wrap(function _callee2$(_context2) { - while (1) { - switch (_context2.prev = _context2.next) { - case 0: - case "end": - return _context2.stop(); - } + if (amount === 0) return /*#__PURE__*/_regenerator.default.mark(function _callee2() { + return _regenerator.default.wrap(function _callee2$(_context2) { + while (1) { + switch (_context2.prev = _context2.next) { + case 0: + case "end": + return _context2.stop(); } - }, _callee2); - })() - ); + } + }, _callee2); + })(); if (typeof lte === 'string') lte = [this.get(lte)]; if (typeof lt === 'string') lt = [this.get(this.get(lt).next)]; if (lte && !Array.isArray(lte)) throw LogError.LtOrLteMustBeStringOrArray(); @@ -461,38 +460,35 @@ function (_GSet) { entryValues = entryValues.slice(entryValues.length - amount, entryValues.length); } - return ( - /*#__PURE__*/ - _regenerator.default.mark(function _callee3() { - var i; - return _regenerator.default.wrap(function _callee3$(_context3) { - while (1) { - switch (_context3.prev = _context3.next) { - case 0: - _context3.t0 = _regenerator.default.keys(entryValues); - - case 1: - if ((_context3.t1 = _context3.t0()).done) { - _context3.next = 7; - break; - } - - i = _context3.t1.value; - _context3.next = 5; - return entryValues[i]; + return /*#__PURE__*/_regenerator.default.mark(function _callee3() { + var i; + return _regenerator.default.wrap(function _callee3$(_context3) { + while (1) { + switch (_context3.prev = _context3.next) { + case 0: + _context3.t0 = _regenerator.default.keys(entryValues); - case 5: - _context3.next = 1; + case 1: + if ((_context3.t1 = _context3.t0()).done) { + _context3.next = 7; break; + } + + i = _context3.t1.value; + _context3.next = 5; + return entryValues[i]; - case 7: - case "end": - return _context3.stop(); - } + case 5: + _context3.next = 1; + break; + + case 7: + case "end": + return _context3.stop(); } - }, _callee3); - })() - ); + } + }, _callee3); + })(); } /** * Join two logs. @@ -509,9 +505,7 @@ function (_GSet) { }, { key: "join", value: function () { - var _join = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee7(log) { + var _join = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(log) { var _this4 = this; var size, @@ -563,12 +557,8 @@ function (_GSet) { identityProvider = this._identity.provider; // Verify if entries are allowed to be added to the log and throws if // there's an invalid entry - permitted = - /*#__PURE__*/ - function () { - var _ref3 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee4(entry) { + permitted = /*#__PURE__*/function () { + var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(entry) { var canAppend; return _regenerator.default.wrap(function _callee4$(_context4) { while (1) { @@ -601,12 +591,8 @@ function (_GSet) { }(); // Verify signature for each entry and throws if there's an invalid signature - verify = - /*#__PURE__*/ - function () { - var _ref4 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee5(entry) { + verify = /*#__PURE__*/function () { + var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(entry) { var isValid, publicKey; return _regenerator.default.wrap(function _callee5$(_context5) { while (1) { @@ -641,12 +627,8 @@ function (_GSet) { entriesToJoin = Object.values(newItems); _context7.next = 14; - return pMap(entriesToJoin, - /*#__PURE__*/ - function () { - var _ref5 = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee6(e) { + return pMap(entriesToJoin, /*#__PURE__*/function () { + var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(e) { return _regenerator.default.wrap(function _callee6$(_context6) { while (1) { switch (_context6.prev = _context6.next) { @@ -908,9 +890,7 @@ function (_GSet) { }, { key: "fromMultihash", value: function () { - var _fromMultihash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee8(ipfs, identity, hash) { + var _fromMultihash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(ipfs, identity, hash) { var _ref7, access, _ref7$length, @@ -921,7 +901,7 @@ function (_GSet) { concurrency, sortFn, onProgressCallback, - _ref8, + _yield$LogIO$fromMult, logId, entries, heads, @@ -943,10 +923,10 @@ function (_GSet) { }); case 3: - _ref8 = _context8.sent; - logId = _ref8.logId; - entries = _ref8.entries; - heads = _ref8.heads; + _yield$LogIO$fromMult = _context8.sent; + logId = _yield$LogIO$fromMult.logId; + entries = _yield$LogIO$fromMult.entries; + heads = _yield$LogIO$fromMult.heads; return _context8.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, @@ -987,21 +967,19 @@ function (_GSet) { }, { key: "fromEntryHash", value: function () { - var _fromEntryHash = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee9(ipfs, identity, hash) { - var _ref9, + var _fromEntryHash = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(ipfs, identity, hash) { + var _ref8, logId, access, - _ref9$length, + _ref8$length, length, - _ref9$exclude, + _ref8$exclude, exclude, timeout, concurrency, sortFn, onProgressCallback, - _ref10, + _yield$LogIO$fromEntr, entries, _args9 = arguments; @@ -1009,7 +987,7 @@ function (_GSet) { while (1) { switch (_context9.prev = _context9.next) { case 0: - _ref9 = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {}, logId = _ref9.logId, access = _ref9.access, _ref9$length = _ref9.length, length = _ref9$length === void 0 ? -1 : _ref9$length, _ref9$exclude = _ref9.exclude, exclude = _ref9$exclude === void 0 ? [] : _ref9$exclude, timeout = _ref9.timeout, concurrency = _ref9.concurrency, sortFn = _ref9.sortFn, onProgressCallback = _ref9.onProgressCallback; + _ref8 = _args9.length > 3 && _args9[3] !== undefined ? _args9[3] : {}, logId = _ref8.logId, access = _ref8.access, _ref8$length = _ref8.length, length = _ref8$length === void 0 ? -1 : _ref8$length, _ref8$exclude = _ref8.exclude, exclude = _ref8$exclude === void 0 ? [] : _ref8$exclude, timeout = _ref8.timeout, concurrency = _ref8.concurrency, sortFn = _ref8.sortFn, onProgressCallback = _ref8.onProgressCallback; _context9.next = 3; return LogIO.fromEntryHash(ipfs, hash, { length: length, @@ -1020,8 +998,8 @@ function (_GSet) { }); case 3: - _ref10 = _context9.sent; - entries = _ref10.entries; + _yield$LogIO$fromEntr = _context9.sent; + entries = _yield$LogIO$fromEntr.entries; return _context9.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, @@ -1059,17 +1037,15 @@ function (_GSet) { }, { key: "fromJSON", value: function () { - var _fromJSON = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee10(ipfs, identity, json) { - var _ref11, + var _fromJSON = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee10(ipfs, identity, json) { + var _ref9, access, - _ref11$length, + _ref9$length, length, timeout, sortFn, onProgressCallback, - _ref12, + _yield$LogIO$fromJSON, logId, entries, _args10 = arguments; @@ -1078,7 +1054,7 @@ function (_GSet) { while (1) { switch (_context10.prev = _context10.next) { case 0: - _ref11 = _args10.length > 3 && _args10[3] !== undefined ? _args10[3] : {}, access = _ref11.access, _ref11$length = _ref11.length, length = _ref11$length === void 0 ? -1 : _ref11$length, timeout = _ref11.timeout, sortFn = _ref11.sortFn, onProgressCallback = _ref11.onProgressCallback; + _ref9 = _args10.length > 3 && _args10[3] !== undefined ? _args10[3] : {}, access = _ref9.access, _ref9$length = _ref9.length, length = _ref9$length === void 0 ? -1 : _ref9$length, timeout = _ref9.timeout, sortFn = _ref9.sortFn, onProgressCallback = _ref9.onProgressCallback; _context10.next = 3; return LogIO.fromJSON(ipfs, json, { length: length, @@ -1087,9 +1063,9 @@ function (_GSet) { }); case 3: - _ref12 = _context10.sent; - logId = _ref12.logId; - entries = _ref12.entries; + _yield$LogIO$fromJSON = _context10.sent; + logId = _yield$LogIO$fromJSON.logId; + entries = _yield$LogIO$fromJSON.entries; return _context10.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, @@ -1128,20 +1104,18 @@ function (_GSet) { }, { key: "fromEntry", value: function () { - var _fromEntry = (0, _asyncToGenerator2.default)( - /*#__PURE__*/ - _regenerator.default.mark(function _callee11(ipfs, identity, sourceEntries) { - var _ref13, + var _fromEntry = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee11(ipfs, identity, sourceEntries) { + var _ref10, access, - _ref13$length, + _ref10$length, length, - _ref13$exclude, + _ref10$exclude, exclude, timeout, concurrency, sortFn, onProgressCallback, - _ref14, + _yield$LogIO$fromEntr2, logId, entries, _args11 = arguments; @@ -1150,7 +1124,7 @@ function (_GSet) { while (1) { switch (_context11.prev = _context11.next) { case 0: - _ref13 = _args11.length > 3 && _args11[3] !== undefined ? _args11[3] : {}, access = _ref13.access, _ref13$length = _ref13.length, length = _ref13$length === void 0 ? -1 : _ref13$length, _ref13$exclude = _ref13.exclude, exclude = _ref13$exclude === void 0 ? [] : _ref13$exclude, timeout = _ref13.timeout, concurrency = _ref13.concurrency, sortFn = _ref13.sortFn, onProgressCallback = _ref13.onProgressCallback; + _ref10 = _args11.length > 3 && _args11[3] !== undefined ? _args11[3] : {}, access = _ref10.access, _ref10$length = _ref10.length, length = _ref10$length === void 0 ? -1 : _ref10$length, _ref10$exclude = _ref10.exclude, exclude = _ref10$exclude === void 0 ? [] : _ref10$exclude, timeout = _ref10.timeout, concurrency = _ref10.concurrency, sortFn = _ref10.sortFn, onProgressCallback = _ref10.onProgressCallback; _context11.next = 3; return LogIO.fromEntry(ipfs, sourceEntries, { length: length, @@ -1161,9 +1135,9 @@ function (_GSet) { }); case 3: - _ref14 = _context11.sent; - logId = _ref14.logId; - entries = _ref14.entries; + _yield$LogIO$fromEntr2 = _context11.sent; + logId = _yield$LogIO$fromEntr2.logId; + entries = _yield$LogIO$fromEntr2.entries; return _context11.abrupt("return", new Log(ipfs, identity, { logId: logId, access: access, diff --git a/package.json b/package.json index 33bd2ddf..92b1a94d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipfs-log", - "version": "4.5.5", + "version": "4.6.0", "description": "Append-only log CRDT on IPFS", "main": "src/log.js", "author": "Haad", @@ -29,31 +29,29 @@ "p-whilst": "^1.0.0" }, "devDependencies": { - "@babel/cli": "~7.2.3", - "@babel/core": "~7.2.2", - "@babel/plugin-syntax-object-rest-spread": "~7.2.0", + "@babel/cli": "~7.8.4", + "@babel/core": "~7.9.6", + "@babel/plugin-syntax-object-rest-spread": "~7.8.3", "@babel/plugin-transform-modules-commonjs": "~7.2.0", "@babel/plugin-transform-runtime": "~7.2.0", "@babel/preset-env": "~7.2.0", - "@babel/runtime": "~7.2.0", - "@orbitdb/eslint-config-orbitdb": "0.0.2", - "babel-loader": "~8.0.4", + "@babel/runtime": "~7.9.6", + "babel-loader": "~8.1.0", "datastore-level": "~0.12.0", "fs-extra": "^7.0.1", "http-server": "^0.11.1", - "ipfs": "^0.40.0", - "ipfs-repo": "^0.30.1", "ipld-dag-pb": "~0.18.0", - "istanbul": "~0.4.5", + "is-node": "^1.0.2", "json-loader": "~0.5.7", "mocha": "~5.2.0", "mocha-headless-chrome": "^2.0.1", + "nyc": "^15.0.1", "orbit-db-storage-adapter": "^0.4.2", - "orbit-db-test-utils": "~0.8.4", + "orbit-db-test-utils": "~0.9.1", "rimraf": "~2.6.1", "standard": "~12.0.1", - "webpack": "~4.28.0", - "webpack-cli": "~3.1.2", + "webpack": "~4.43.0", + "webpack-cli": "~3.3.11", "yargs": "^13.2.4" }, "standard": { @@ -76,8 +74,7 @@ "adam-palazzo" ], "scripts": { - "test": "TEST=all mocha", - "test:coverage": "istanbul cover -x src/g-set.js _mocha", + "test": "TEST=all nyc mocha", "test:browser": "npm run build:tests && mocha-headless-chrome -t 360000 -f ./test/browser/index.html -a no-sandbox", "build": "npm run build:es5 && npm run build:examples && npm run build:dist", "build:tests": "webpack --config webpack.tests.config.js --mode production", diff --git a/test/browser/index.html b/test/browser/index.html index 561e82a1..63a7a517 100644 --- a/test/browser/index.html +++ b/test/browser/index.html @@ -9,12 +9,12 @@
diff --git a/test/entry-io.spec.js b/test/entry-io.spec.js index c55864de..d863435b 100644 --- a/test/entry-io.spec.js +++ b/test/entry-io.spec.js @@ -16,7 +16,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 const last = arr => arr[arr.length - 1] @@ -51,11 +51,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity2 = await IdentityProvider.createIdentity(options[1]) testIdentity3 = await IdentityProvider.createIdentity(options[2]) testIdentity4 = await IdentityProvider.createIdentity(options[3]) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/entry.spec.js b/test/entry.spec.js index 2069f534..62536e4d 100644 --- a/test/entry.spec.js +++ b/test/entry.spec.js @@ -20,7 +20,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity +let ipfsd, ipfs, testIdentity Object.keys(testAPIs).forEach((IPFS) => { describe('Entry (' + IPFS + ')', function () { @@ -43,11 +43,12 @@ Object.keys(testAPIs).forEach((IPFS) => { signingKeystore = new Keystore(signingKeysPath) testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) await fs.copy(identityKeyFixtures, identityKeysPath) await fs.copy(signingKeyFixtures, signingKeysPath) rmrf.sync(identityKeysPath) diff --git a/test/log-append.spec.js b/test/log-append.spec.js index 2e0f1c94..426f79dd 100644 --- a/test/log-append.spec.js +++ b/test/log-append.spec.js @@ -15,7 +15,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity +let ipfsd, ipfs, testIdentity Object.keys(testAPIs).forEach((IPFS) => { describe('Log - Append (' + IPFS + ')', function () { @@ -39,11 +39,12 @@ Object.keys(testAPIs).forEach((IPFS) => { signingKeystore = new Keystore(signingKeysPath) testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-crdt.spec.js b/test/log-crdt.spec.js index b676fdd1..7cfd50ff 100644 --- a/test/log-crdt.spec.js +++ b/test/log-crdt.spec.js @@ -15,7 +15,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3 Object.keys(testAPIs).forEach((IPFS) => { describe('Log - CRDT (' + IPFS + ')', function () { @@ -41,11 +41,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) testIdentity3 = await IdentityProvider.createIdentity({ id: 'userC', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-heads-tails.spec.js b/test/log-heads-tails.spec.js index 2df3687e..2456e881 100644 --- a/test/log-heads-tails.spec.js +++ b/test/log-heads-tails.spec.js @@ -16,7 +16,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 const last = (arr) => { return arr[arr.length - 1] @@ -47,11 +47,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) testIdentity3 = await IdentityProvider.createIdentity({ id: 'userC', keystore, signingKeystore }) testIdentity4 = await IdentityProvider.createIdentity({ id: 'userD', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-iterator.spec.js b/test/log-iterator.spec.js index 519678ae..458ae6f2 100644 --- a/test/log-iterator.spec.js +++ b/test/log-iterator.spec.js @@ -16,7 +16,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3 Object.keys(testAPIs).forEach((IPFS) => { describe('Log - Iterator (' + IPFS + ')', function () { @@ -42,11 +42,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) testIdentity3 = await IdentityProvider.createIdentity({ id: 'userC', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-join-concurrent.spec.js b/test/log-join-concurrent.spec.js index 8fb48b16..3a5ea4f1 100644 --- a/test/log-join-concurrent.spec.js +++ b/test/log-join-concurrent.spec.js @@ -14,7 +14,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity +let ipfsd, ipfs, testIdentity Object.keys(testAPIs).forEach(IPFS => { describe('Log - Join Concurrent Entries (' + IPFS + ')', function () { @@ -32,11 +32,12 @@ Object.keys(testAPIs).forEach(IPFS => { await fs.copy(identityKeyFixtures, identityKeysPath) await fs.copy(signingKeyFixtures, signingKeysPath) testIdentity = await IdentityProvider.createIdentity({ id: 'userA', identityKeysPath, signingKeysPath }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) await testIdentity.provider.keystore.close() await testIdentity.provider.signingKeystore.close() rmrf.sync(ipfsConfig.repo) diff --git a/test/log-join.spec.js b/test/log-join.spec.js index bf86a685..e45f2b8a 100644 --- a/test/log-join.spec.js +++ b/test/log-join.spec.js @@ -17,7 +17,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 const last = (arr) => { return arr[arr.length - 1] @@ -49,11 +49,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity3 = await IdentityProvider.createIdentity({ id: 'userD', keystore, signingKeystore }) testIdentity4 = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-load.spec.js b/test/log-load.spec.js index de26ca1c..b9922029 100644 --- a/test/log-load.spec.js +++ b/test/log-load.spec.js @@ -27,7 +27,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3, testIdentity4 const last = (arr) => { return arr[arr.length - 1] @@ -65,7 +65,8 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) testIdentity3 = await IdentityProvider.createIdentity({ id: 'userD', keystore, signingKeystore }) testIdentity4 = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api const memstore = new MemStore() ipfs.object.put = memstore.put.bind(memstore) @@ -73,7 +74,7 @@ Object.keys(testAPIs).forEach((IPFS) => { }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log-references.spec.js b/test/log-references.spec.js index e3f8bc9c..057eb6b2 100644 --- a/test/log-references.spec.js +++ b/test/log-references.spec.js @@ -15,7 +15,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity +let ipfsd, ipfs, testIdentity Object.keys(testAPIs).forEach((IPFS) => { describe('Log - References (' + IPFS + ')', function () { @@ -39,11 +39,12 @@ Object.keys(testAPIs).forEach((IPFS) => { signingKeystore = new Keystore(signingKeysPath) testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/test/log.spec.js b/test/log.spec.js index 7a5a4e51..57ce47a1 100644 --- a/test/log.spec.js +++ b/test/log.spec.js @@ -22,7 +22,8 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2, testIdentity3 +let ipfsd, ipfs, testIdentity, testIdentity2, testIdentity3 + Object.keys(testAPIs).forEach((IPFS) => { describe('Log (' + IPFS + ')', function () { this.timeout(config.timeout) @@ -45,11 +46,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) testIdentity3 = await IdentityProvider.createIdentity({ id: 'userC', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(signingKeysPath) rmrf.sync(identityKeysPath) rmrf.sync(ipfsConfig.repo) diff --git a/test/replicate.spec.js b/test/replicate.spec.js index aa582279..06cf06d8 100644 --- a/test/replicate.spec.js +++ b/test/replicate.spec.js @@ -23,7 +23,7 @@ Object.keys(testAPIs).forEach((IPFS) => { describe('ipfs-log - Replication (' + IPFS + ')', function () { this.timeout(config.timeout) - let ipfs1, ipfs2, id1, id2, testIdentity, testIdentity2 + let ipfsd1, ipfsd2, ipfs1, ipfs2, id1, id2, testIdentity, testIdentity2 const { identityKeyFixtures, signingKeyFixtures, identityKeysPath, signingKeysPath } = config const ipfsConfig1 = Object.assign({}, config.daemon1, { @@ -45,8 +45,10 @@ Object.keys(testAPIs).forEach((IPFS) => { await fs.copy(signingKeyFixtures, signingKeysPath) // Start two IPFS instances - ipfs1 = await startIpfs(IPFS, ipfsConfig1) - ipfs2 = await startIpfs(IPFS, ipfsConfig2) + ipfsd1 = await startIpfs(IPFS, ipfsConfig1) + ipfsd2 = await startIpfs(IPFS, ipfsConfig2) + ipfs1 = ipfsd1.api + ipfs2 = ipfsd2.api await connectPeers(ipfs1, ipfs2) @@ -70,8 +72,8 @@ Object.keys(testAPIs).forEach((IPFS) => { }) after(async () => { - await stopIpfs(ipfs1) - await stopIpfs(ipfs2) + await stopIpfs(ipfsd1) + await stopIpfs(ipfsd2) rmrf.sync(ipfsConfig1.repo) rmrf.sync(ipfsConfig2.repo) rmrf.sync(identityKeysPath) diff --git a/test/signed-log.spec.js b/test/signed-log.spec.js index 155c8e3d..856776a0 100644 --- a/test/signed-log.spec.js +++ b/test/signed-log.spec.js @@ -15,7 +15,7 @@ const { stopIpfs } = require('orbit-db-test-utils') -let ipfs, testIdentity, testIdentity2 +let ipfsd, ipfs, testIdentity, testIdentity2 Object.keys(testAPIs).forEach((IPFS) => { describe('Signed Log (' + IPFS + ')', function () { @@ -40,11 +40,12 @@ Object.keys(testAPIs).forEach((IPFS) => { testIdentity = await IdentityProvider.createIdentity({ id: 'userA', keystore, signingKeystore }) testIdentity2 = await IdentityProvider.createIdentity({ id: 'userB', keystore, signingKeystore }) - ipfs = await startIpfs(IPFS, ipfsConfig) + ipfsd = await startIpfs(IPFS, ipfsConfig) + ipfs = ipfsd.api }) after(async () => { - await stopIpfs(ipfs) + await stopIpfs(ipfsd) rmrf.sync(ipfsConfig.repo) rmrf.sync(identityKeysPath) rmrf.sync(signingKeysPath) diff --git a/webpack.tests.config.js b/webpack.tests.config.js index 680e15e1..e7506f7c 100644 --- a/webpack.tests.config.js +++ b/webpack.tests.config.js @@ -14,7 +14,7 @@ module.exports = { devtool: 'source-map', node: { console: false, - process: 'mock', + process: true, Buffer: true }, plugins: [ @@ -26,7 +26,7 @@ module.exports = { new webpack.IgnorePlugin(/mongo|redis/) ], externals: { - fs: '{}', + fs: '{ existsSync: () => true }', fatfs: '{}', 'fs-extra': '{ copy: () => {} }', rimraf: '{ sync: () => {} }',