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

Feat/ipfs dag #210

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
# This is based on your 1.0 configuration file or project settings
- run:
working_directory: ~/orbitdb/ipfs-log
command: nvm install 8.2.0 && nvm alias default 8.2.0
command: nvm install 10.14.0 && nvm alias default 10.14.0
# Dependencies
# This would typically go in either a build or a build-and-test job when using workflows
# Restore the dependency cache
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
machine:
node:
version: 8.2.0
version: 10.14.0
4 changes: 2 additions & 2 deletions dist/ipfslog.min.js

Large diffs are not rendered by default.

40 changes: 18 additions & 22 deletions lib/es5/default-access-controller.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
'use strict';

var _regenerator = require('babel-runtime/regenerator');
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _regenerator2 = _interopRequireDefault(_regenerator);
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var AccessController = function () {
var AccessController =
/*#__PURE__*/
function () {
function AccessController() {
(0, _classCallCheck3.default)(this, AccessController);
(0, _classCallCheck2.default)(this, AccessController);
}

(0, _createClass3.default)(AccessController, [{
key: 'canAppend',
(0, _createClass2.default)(AccessController, [{
key: "canAppend",
value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(entry, identityProvider) {
return _regenerator2.default.wrap(function _callee$(_context) {
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) {
case 0:
return _context.abrupt('return', true);
return _context.abrupt("return", true);

case 1:
case 'end':
case "end":
return _context.stop();
}
}
}, _callee, this);
}));

function canAppend(_x, _x2) {
return _ref.apply(this, arguments);
return _canAppend.apply(this, arguments);
}

return canAppend;
Expand Down
162 changes: 86 additions & 76 deletions lib/es5/entry-io.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
'use strict';

var _promise = require('babel-runtime/core-js/promise');
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _promise2 = _interopRequireDefault(_promise);
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _regenerator = require('babel-runtime/regenerator');
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _regenerator2 = _interopRequireDefault(_regenerator);
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var pWhilst = require('p-whilst');

var pMap = require('p-map');

var Entry = require('./entry');

var EntryIO = function () {
var EntryIO =
/*#__PURE__*/
function () {
function EntryIO() {
(0, _classCallCheck3.default)(this, EntryIO);
(0, _classCallCheck2.default)(this, EntryIO);
}

(0, _createClass3.default)(EntryIO, null, [{
key: 'fetchParallel',

(0, _createClass2.default)(EntryIO, null, [{
key: "fetchParallel",
// Fetch log graphs in parallel
value: function () {
var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee(ipfs, hashes, length) {
var exclude = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
var concurrency = arguments[4];
var timeout = arguments[5];
var onProgressCallback = arguments[6];
var fetchOne, concatArrays, flatten, entries;
return _regenerator2.default.wrap(function _callee$(_context) {
var _fetchParallel = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee(ipfs, hashes, length) {
var exclude,
concurrency,
timeout,
onProgressCallback,
fetchOne,
concatArrays,
flatten,
entries,
_args = arguments;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
exclude = _args.length > 3 && _args[3] !== undefined ? _args[3] : [];
concurrency = _args.length > 4 ? _args[4] : undefined;
timeout = _args.length > 5 ? _args[5] : undefined;
onProgressCallback = _args.length > 6 ? _args[6] : undefined;

fetchOne = function fetchOne(hash) {
return EntryIO.fetchAll(ipfs, hash, length, exclude, timeout, onProgressCallback);
};
Expand All @@ -59,28 +61,29 @@ var EntryIO = function () {
};

concurrency = Math.max(concurrency || hashes.length, 1);
_context.next = 6;
return pMap(hashes, fetchOne, { concurrency: concurrency });
_context.next = 10;
return pMap(hashes, fetchOne, {
concurrency: concurrency
});

case 6:
case 10:
entries = _context.sent;
return _context.abrupt('return', flatten(entries));
return _context.abrupt("return", flatten(entries));

case 8:
case 'end':
case 12:
case "end":
return _context.stop();
}
}
}, _callee, this);
}));

function fetchParallel(_x2, _x3, _x4) {
return _ref.apply(this, arguments);
function fetchParallel(_x, _x2, _x3) {
return _fetchParallel.apply(this, arguments);
}

return fetchParallel;
}()

/**
* Fetch log entries sequentially
*
Expand All @@ -95,31 +98,36 @@ var EntryIO = function () {
*/

}, {
key: 'fetchAll',
key: "fetchAll",
value: function () {
var _ref2 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(ipfs, hashes, amount) {
var exclude = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];

var _this = this;

var timeout = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : null;
var onProgressCallback = arguments[5];
var result, cache, loadingQueue, addToLoadingQueue, addToExcludeCache, shouldFetchMore, fetchEntry;
return _regenerator2.default.wrap(function _callee3$(_context3) {
var _fetchAll = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee3(ipfs, hashes, amount) {
var exclude,
timeout,
onProgressCallback,
result,
cache,
loadingQueue,
addToLoadingQueue,
addToExcludeCache,
shouldFetchMore,
fetchEntry,
_args3 = arguments;
return _regenerator.default.wrap(function _callee3$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
exclude = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : [];
timeout = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : null;
onProgressCallback = _args3.length > 5 ? _args3[5] : undefined;
result = [];
cache = {};
loadingQueue = Array.isArray(hashes) ? hashes.slice() : [hashes];

// Add a multihash to the loading queue
loadingQueue = Array.isArray(hashes) ? hashes.slice() : [hashes]; // Add a multihash to the loading queue

addToLoadingQueue = function addToLoadingQueue(e) {
return loadingQueue.push(e);
};

// Add entries that we don't need to fetch to the "cache"
}; // Add entries that we don't need to fetch to the "cache"


exclude = exclude && Array.isArray(exclude) ? exclude : [];
Expand All @@ -138,36 +146,40 @@ var EntryIO = function () {
var hash = loadingQueue.shift();

if (cache[hash]) {
return _promise2.default.resolve();
return Promise.resolve();
}

return new _promise2.default(function () {
var _ref3 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee2(resolve, reject) {
return new Promise(
/*#__PURE__*/
function () {
var _ref = (0, _asyncToGenerator2.default)(
/*#__PURE__*/
_regenerator.default.mark(function _callee2(resolve, reject) {
var timer, addToResults, entry;
return _regenerator2.default.wrap(function _callee2$(_context2) {
return _regenerator.default.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
// Resolve the promise after a timeout (if given) in order to
// not get stuck loading a block that is unreachable
timer = timeout ? setTimeout(function () {
console.warn('Warning: Couldn\'t fetch entry \'' + hash + '\', request timed out (' + timeout + 'ms)');
console.warn("Warning: Couldn't fetch entry '".concat(hash, "', request timed out (").concat(timeout, "ms)"));
resolve();
}, timeout) : null;

addToResults = function addToResults(entry) {
clearTimeout(timer);

if (Entry.isEntry(entry)) {
entry.next.forEach(addToLoadingQueue);
result.push(entry);
cache[hash] = entry;

if (onProgressCallback) {
onProgressCallback(hash, entry, result.length);
}
}
};

// Load the entry
}; // Load the entry


_context2.prev = 2;
Expand All @@ -176,48 +188,46 @@ var EntryIO = function () {

case 5:
entry = _context2.sent;

addToResults(entry);
resolve();
_context2.next = 13;
break;

case 10:
_context2.prev = 10;
_context2.t0 = _context2['catch'](2);

_context2.t0 = _context2["catch"](2);
reject(_context2.t0);

case 13:
case 'end':
case "end":
return _context2.stop();
}
}
}, _callee2, _this, [[2, 10]]);
}, _callee2, this, [[2, 10]]);
}));

return function (_x10, _x11) {
return _ref3.apply(this, arguments);
return function (_x7, _x8) {
return _ref.apply(this, arguments);
};
}());
};

_context3.next = 11;
_context3.next = 14;
return pWhilst(shouldFetchMore, fetchEntry);

case 11:
return _context3.abrupt('return', result);
case 14:
return _context3.abrupt("return", result);

case 12:
case 'end':
case 15:
case "end":
return _context3.stop();
}
}
}, _callee3, this);
}));

function fetchAll(_x7, _x8, _x9) {
return _ref2.apply(this, arguments);
function fetchAll(_x4, _x5, _x6) {
return _fetchAll.apply(this, arguments);
}

return fetchAll;
Expand Down
Loading