Fix tests, build and examples. Update dist build.

This commit is contained in:
haad 2016-11-25 12:43:04 +01:00
parent 8be5def744
commit 799473eb86
7 changed files with 93 additions and 97 deletions

View File

@ -13,10 +13,10 @@ module.exports = {
Buffer: true
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
mangle: false,
compress: { warnings: false }
})
// new webpack.optimize.UglifyJsPlugin({
// mangle: false,
// compress: { warnings: false }
// })
],
resolve: {
modules: [

99
dist/orbitdb.js vendored
View File

@ -2624,36 +2624,36 @@ module.exports = function(key){
/* 35 */
/***/ function(module, exports, __webpack_require__) {
exports.nextTick = function nextTick(fn) {
setTimeout(fn, 0);
};
exports.platform = exports.arch =
exports.execPath = exports.title = 'browser';
exports.pid = 1;
exports.browser = true;
exports.env = {};
exports.argv = [];
exports.binding = function (name) {
throw new Error('No such module. (Possibly not yet loaded)')
};
(function () {
var cwd = '/';
var path;
exports.cwd = function () { return cwd };
exports.chdir = function (dir) {
if (!path) path = __webpack_require__(166);
cwd = path.resolve(dir, cwd);
};
})();
exports.exit = exports.kill =
exports.umask = exports.dlopen =
exports.uptime = exports.memoryUsage =
exports.uvCounters = function() {};
exports.features = {};
exports.nextTick = function nextTick(fn) {
setTimeout(fn, 0);
};
exports.platform = exports.arch =
exports.execPath = exports.title = 'browser';
exports.pid = 1;
exports.browser = true;
exports.env = {};
exports.argv = [];
exports.binding = function (name) {
throw new Error('No such module. (Possibly not yet loaded)')
};
(function () {
var cwd = '/';
var path;
exports.cwd = function () { return cwd };
exports.chdir = function (dir) {
if (!path) path = __webpack_require__(166);
cwd = path.resolve(dir, cwd);
};
})();
exports.exit = exports.kill =
exports.umask = exports.dlopen =
exports.uptime = exports.memoryUsage =
exports.uvCounters = function() {};
exports.features = {};
/***/ },
@ -4875,7 +4875,7 @@ module.exports = function () {
if (!ipfs) throw new Error("Entry requires ipfs instance");
var data = new Buffer((0, _stringify2.default)(entry));
return ipfs.object.put(data).then(function (res) {
return res.toJSON().Hash;
return res.toJSON().multihash;
});
}
@ -4890,7 +4890,7 @@ module.exports = function () {
if (!ipfs) throw new Error("Entry requires ipfs instance");
if (!hash) throw new Error("Invalid hash: " + hash);
return ipfs.object.get(hash, { enc: 'base58' }).then(function (obj) {
var data = JSON.parse(obj.toJSON().Data);
var data = JSON.parse(obj.toJSON().data);
var entry = {
hash: hash,
payload: data.payload,
@ -5093,7 +5093,7 @@ var Log = function () {
if (!ipfs) throw new Error("Ipfs instance not defined");
var data = new Buffer((0, _stringify2.default)(log.snapshot));
return ipfs.object.put(data).then(function (res) {
return res.toJSON().Hash;
return res.toJSON().multihash;
});
}
}, {
@ -5104,7 +5104,7 @@ var Log = function () {
if (!options) options = {};
var logData = void 0;
return ipfs.object.get(hash, { enc: 'base58' }).then(function (res) {
return logData = JSON.parse(res.toJSON().Data);
return logData = JSON.parse(res.toJSON().data);
}).then(function (res) {
if (!logData.items) throw new Error("Not a Log instance");
return Promise.all(logData.items.map(function (f) {
@ -5648,6 +5648,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var logger = __webpack_require__(92).create("orbit-db.IPFSPubSub");
// TODO: setup logging properly
var IPFSPubsub = function () {
function IPFSPubsub(ipfs) {
(0, _classCallCheck3.default)(this, IPFSPubsub);
@ -5663,25 +5665,29 @@ var IPFSPubsub = function () {
if (!this._subscriptions[hash]) {
this._subscriptions[hash] = { onMessage: onMessageCallback };
this._ipfs.pubsub.sub(encodeURIComponent(hash), { discover: true }, function (err, stream) {
this._ipfs.pubsub.subscribe(hash, { discover: true }, function (err, stream) {
if (err) logger.error(err);
if (stream) stream.on('data', _this._handleMessage.bind(_this));
if (stream) {
stream.on('data', _this._handleMessage.bind(_this));
// TODO: handle end of stream
// stream.on('end', () => console.log("Disconnected from pubsub"))
}
});
// FIXME: when js-ipfs-api returns the stream before the
// first message has been received, this can be remove
this._ipfs.pubsub.pub(encodeURIComponent(hash), '/connect');
}
}
}, {
key: 'unsubscribe',
value: function unsubscribe(hash) {
if (this._subscriptions[hash]) delete this._subscriptions[hash];
if (this._subscriptions[hash]) {
this._subscriptions[e].cancel();
delete this._subscriptions[hash];
}
}
}, {
key: 'publish',
value: function publish(hash, message) {
if (this._subscriptions[hash]) this._ipfs.pubsub.pub(encodeURIComponent(hash), message);
if (this._subscriptions[hash]) this._ipfs.pubsub.publish(hash, message);
}
}, {
key: 'disconnect',
@ -5689,20 +5695,17 @@ var IPFSPubsub = function () {
var _this2 = this;
(0, _keys2.default)(this._subscriptions).forEach(function (e) {
//this._subscriptions[e].stream.end() ???
delete _this2._subscriptions[e];
return _this2.unsubscribe(e);
});
}
}, {
key: '_handleMessage',
value: function _handleMessage(message) {
if (message.data === '/connect') return;
var hash = message.topicIDs[0];
var sub = this._subscriptions[hash];
var subscription = this._subscriptions[hash];
if (sub && sub.onMessage) {
sub.onMessage(hash, message.data);
if (subscription && subscription.onMessage) {
subscription.onMessage(hash, message.data);
}
}
}]);

4
dist/orbitdb.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,7 @@
<div id="result">Loading...</div>
<script type="text/javascript" src="../../dist/orbitdb.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/ipfs-api/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../../node_modules/@haad/ipfs-api/dist/index.min.js" charset="utf-8"></script>
<script type="text/javascript">
@ -16,7 +16,7 @@
try {
const elm = document.getElementById("result")
const ipfs = IpfsApi('localhost', '5001')
const ipfs = HaadIpfsApi('localhost', '5001')
const orbit = new OrbitDB(ipfs, username)
const db = orbit.kvstore(channel)
@ -27,17 +27,12 @@
let count = 1
const query = () => {
const startTime = new Date().getTime()
const idx = Math.floor(Math.random() * creatures.length)
const creature = creatures[idx] + " " + creatures[idx]
// Set a key-value pair
db.put(key, "db.put #" + count + " - GrEEtinGs to " + creature)
.then((res) => {
const endTime = new Date().getTime()
console.log(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
count ++
})
db.put(key, "db.put #" + count + " - GrEEtinGs from " + creature)
.then((res) => count ++)
.then(() => counter.inc()) // Increase the counter by one
.then(() => log.add(creature)) // Add an event to 'latest visitors' log
.then(() => {

View File

@ -1,6 +1,6 @@
'use strict'
const IpfsApi = require('exports-loader?IpfsApi!ipfs-api/dist/index.js')
const IpfsApi = require('exports-loader?HaadIpfsApi!@haad/ipfs-api/dist/index.js')
const OrbitDB = require('../../src/OrbitDB')
const username = new Date().getTime()
@ -20,16 +20,11 @@ try {
let count = 1
const query = () => {
const startTime = new Date().getTime()
const idx = Math.floor(Math.random() * creatures.length)
// Set a key-value pair
db.put(key, "db.put #" + count + " - GrEEtinGs to " + creatures[idx])
.then((res) => {
const endTime = new Date().getTime()
console.log(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
count ++
})
.then((res) => count ++)
.then(() => counter.inc()) // Increase the counter by one
.then(() => log.add(creatures[idx])) // Add an event to 'latest visitors' log
.then(() => {

View File

@ -4,6 +4,7 @@ const IpfsDaemon = require('ipfs-daemon')
const OrbitDB = require('../src/OrbitDB')
const userId = Math.floor(Math.random() * 1000)
const conf = {
IpfsDataDir: '/tmp/' + userId,
Addresses: {
@ -15,30 +16,32 @@ const conf = {
console.log("Starting...")
IpfsDaemon(conf)
.then((res) => {
const orbitdb = new OrbitDB(res.ipfs)
const db = orbitdb.eventlog("|orbit-db|examples|eventlog-example")
const ipfs = new IpfsDaemon(conf)
const creatures = ['🐙', '🐷', '🐬', '🐞', '🐈', '🙉', '🐸', '🐓']
ipfs.on('error', (err) => console.error(err))
const query = () => {
const index = Math.floor(Math.random() * creatures.length)
db.add({ avatar: creatures[index], userId: userId })
.then(() => {
const latest = db.iterator({ limit: 5 }).collect()
let output = ``
output += `--------------------\n`
output += `Latest Visitors\n`
output += `--------------------\n`
output += latest.reverse().map((e) => e.payload.value.avatar + " (userId: " + e.payload.value.userId + ")").join('\n') + `\n`
console.log(output)
})
.catch((e) => {
console.error(e.stack)
})
}
ipfs.on('ready', () => {
const orbitdb = new OrbitDB(ipfs, userId)
const db = orbitdb.eventlog("|orbit-db|examples|eventlog-example")
setInterval(query, 1000)
})
.catch((err) => console.error(err))
const creatures = ['🐙', '🐷', '🐬', '🐞', '🐈', '🙉', '🐸', '🐓']
const query = () => {
const index = Math.floor(Math.random() * creatures.length)
db.add({ avatar: creatures[index], userId: userId })
.then(() => {
const latest = db.iterator({ limit: 5 }).collect()
let output = ``
output += `--------------------\n`
output += `Latest Visitors\n`
output += `--------------------\n`
output += latest.reverse().map((e) => e.payload.value.avatar + " (userId: " + e.payload.value.userId + ")").join('\n') + `\n`
console.log(output)
})
.catch((e) => {
console.error(e.stack)
})
}
setInterval(query, 1000)
})

View File

@ -18,7 +18,7 @@ let ipfs
IpfsApis.forEach(function(ipfsApi) {
describe('Orbit Client with ' + ipfsApi.name, function() {
this.timeout(20000)
this.timeout(40000)
let client, client2, db
let channel = 'abcdefghijklmn'
@ -34,11 +34,11 @@ IpfsApis.forEach(function(ipfsApi) {
.catch(done)
})
after((done) => {
after(() => {
if(db) db.delete()
if(client) client.disconnect()
if(client2) client2.disconnect()
ipfsApi.stop().then(() => done())
ipfsApi.stop()
})
describe('Add events', function() {