mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-06 14:16:37 +00:00
WIP
This commit is contained in:
parent
f035d30398
commit
61af69678f
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ dump.rdb
|
|||||||
Vagrantfile
|
Vagrantfile
|
||||||
orbit-db-cache.json
|
orbit-db-cache.json
|
||||||
examples/browser/bundle.js
|
examples/browser/bundle.js
|
||||||
|
dist/*.map
|
||||||
|
dist/orbitdb.js
|
||||||
|
42646
dist/orbitdb.js
vendored
42646
dist/orbitdb.js
vendored
File diff suppressed because it is too large
Load Diff
68
dist/orbitdb.min.js
vendored
68
dist/orbitdb.min.js
vendored
File diff suppressed because one or more lines are too long
@ -6,10 +6,8 @@
|
|||||||
<div id="result">Loading...</div>
|
<div id="result">Loading...</div>
|
||||||
|
|
||||||
<script type="text/javascript" src="../../dist/orbitdb.min.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../dist/orbitdb.min.js" charset="utf-8"></script>
|
||||||
<script type="text/javascript" src="../../node_modules/logplease/dist/logplease.min.js" charset="utf-8"></script>
|
|
||||||
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
|
<script type="text/javascript" src="../../node_modules/ipfs/dist/index.min.js" charset="utf-8"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false })
|
|
||||||
const network = '178.62.241.75:3333'
|
const network = '178.62.241.75:3333'
|
||||||
const username = 'user1'
|
const username = 'user1'
|
||||||
const password = ''
|
const password = ''
|
||||||
@ -26,7 +24,7 @@
|
|||||||
const startTime = new Date().getTime()
|
const startTime = new Date().getTime()
|
||||||
db.put(key, value + " " + count).then((res) => {
|
db.put(key, value + " " + count).then((res) => {
|
||||||
const endTime = new Date().getTime()
|
const endTime = new Date().getTime()
|
||||||
logger.debug(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
|
console.log(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
|
||||||
count ++
|
count ++
|
||||||
|
|
||||||
const result = db.get(key)
|
const result = db.get(key)
|
||||||
@ -38,12 +36,12 @@
|
|||||||
---------------------------------------------------`
|
---------------------------------------------------`
|
||||||
|
|
||||||
elm.innerHTML = output.split("\n").join("<br>")
|
elm.innerHTML = output.split("\n").join("<br>")
|
||||||
logger.debug(output)
|
console.log(output)
|
||||||
}).catch((e) => logger.error(e))
|
}).catch((e) => console.error(e))
|
||||||
};
|
};
|
||||||
setInterval(query, 1000)
|
setInterval(query, 1000)
|
||||||
}).catch((e) => logger.error(e))
|
}).catch((e) => console.error(e))
|
||||||
}).catch((e) => logger.error(e))
|
}).catch((e) => console.error(e))
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
'use strict';
|
|
||||||
|
|
||||||
const IPFS = require('exports?Ipfs!ipfs/dist/index.js')
|
|
||||||
const Logger = require('logplease')
|
|
||||||
const logger = Logger.create("orbit-db example", { color: Logger.Colors.Green, showTimestamp: false, showLevel: false })
|
|
||||||
const OrbitDB = require('../../src/OrbitDB')
|
|
||||||
|
|
||||||
const network = '178.62.241.75:3333'
|
|
||||||
const username = 'user1'
|
|
||||||
const password = ''
|
|
||||||
const channel = 'browsertest1'
|
|
||||||
const key = 'greeting'
|
|
||||||
const value = 'Hello world'
|
|
||||||
|
|
||||||
try {
|
|
||||||
const elm = document.getElementById("result")
|
|
||||||
const ipfs = new IPFS()
|
|
||||||
OrbitDB.connect(network, username, password, ipfs).then((orbit) => {
|
|
||||||
orbit.kvstore(channel).then((db) => {
|
|
||||||
let count = 1
|
|
||||||
const query = () => {
|
|
||||||
const startTime = new Date().getTime()
|
|
||||||
db.put(key, value + " " + count).then((res) => {
|
|
||||||
const endTime = new Date().getTime()
|
|
||||||
logger.debug(`db.put (#${count}) took ${(endTime - startTime)} ms\n`)
|
|
||||||
count ++
|
|
||||||
|
|
||||||
const result = db.get(key)
|
|
||||||
const output = `
|
|
||||||
---------------------------------------------------
|
|
||||||
Key | Value
|
|
||||||
---------------------------------------------------
|
|
||||||
${key} | ${result}
|
|
||||||
---------------------------------------------------`
|
|
||||||
|
|
||||||
elm.innerHTML = output.split("\n").join("<br>")
|
|
||||||
logger.debug(output)
|
|
||||||
}).catch((e) => logger.error(e.stack))
|
|
||||||
}
|
|
||||||
setInterval(query, 1000)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
} catch(e) {
|
|
||||||
logger.error(e.stack)
|
|
||||||
}
|
|
70
examples/browser/index.js
Normal file
70
examples/browser/index.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const IpfsApi = require('exports?IpfsApi!ipfs-api/dist/index.js')
|
||||||
|
const OrbitDB = require('../../src/OrbitDB')
|
||||||
|
|
||||||
|
const username = 'user1'
|
||||||
|
const channel = 'browsertest1'
|
||||||
|
const key = 'greeting'
|
||||||
|
|
||||||
|
try {
|
||||||
|
const elm = document.getElementById("result")
|
||||||
|
const ipfs = IpfsApi('localhost', '5001')
|
||||||
|
const orbit = new OrbitDB(ipfs, username)
|
||||||
|
|
||||||
|
const db = orbit.kvstore(channel)
|
||||||
|
const log = orbit.eventlog(channel + ".log")
|
||||||
|
const counter = orbit.counter(channel + ".count")
|
||||||
|
|
||||||
|
const creatures = ['👻', '🤖', '🐬', '🐞', '🐈']
|
||||||
|
|
||||||
|
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(() => counter.inc()) // Increase the counter by one
|
||||||
|
.then(() => log.add(creatures[idx])) // Add an event to 'latest visitors' log
|
||||||
|
.then(() => {
|
||||||
|
const result = db.get(key)
|
||||||
|
const latest = log.iterator({ limit: 5 }).collect()
|
||||||
|
const count = counter.value()
|
||||||
|
|
||||||
|
const output =
|
||||||
|
`
|
||||||
|
---------------------------------------------------
|
||||||
|
Key | Value
|
||||||
|
---------------------------------------------------
|
||||||
|
${key} | ${result}
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
---------------------------------------------------
|
||||||
|
Latest Visitors
|
||||||
|
---------------------------------------------------
|
||||||
|
${latest.reverse().map((e) => e.payload.value).join('\n')}
|
||||||
|
|
||||||
|
---------------------------------------------------
|
||||||
|
Visitor Count: ${count}
|
||||||
|
---------------------------------------------------
|
||||||
|
`
|
||||||
|
elm.innerHTML = output.split("\n").join("<br>")
|
||||||
|
console.log(output)
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
elm.innerHTML = "<i>" + e.message + "</i><br><br>" + "Make sure you have an IPFS daemon running at localhost:5001"
|
||||||
|
console.error(e.stack)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
setInterval(query, 1000)
|
||||||
|
|
||||||
|
} catch(e) {
|
||||||
|
console.error(e.stack)
|
||||||
|
elm.innerHTML = e.message
|
||||||
|
}
|
15
package.json
15
package.json
@ -14,10 +14,10 @@
|
|||||||
"main": "src/OrbitDB.js",
|
"main": "src/OrbitDB.js",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"logplease": "^1.2.7",
|
"logplease": "^1.2.7",
|
||||||
"orbit-db-counterstore": "0.1.1",
|
"orbit-db-counterstore": "0.1.2",
|
||||||
"orbit-db-eventstore": "0.1.1",
|
"orbit-db-eventstore": "0.1.4",
|
||||||
"orbit-db-feedstore": "0.1.1",
|
"orbit-db-feedstore": "0.1.2",
|
||||||
"orbit-db-kvstore": "0.1.1",
|
"orbit-db-kvstore": "0.1.2",
|
||||||
"orbit-db-pubsub": "0.0.3"
|
"orbit-db-pubsub": "0.0.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@ -25,16 +25,17 @@
|
|||||||
"babel-core": "^6.11.4",
|
"babel-core": "^6.11.4",
|
||||||
"babel-loader": "^6.2.4",
|
"babel-loader": "^6.2.4",
|
||||||
"babel-plugin-transform-runtime": "^6.8.0",
|
"babel-plugin-transform-runtime": "^6.8.0",
|
||||||
|
"babel-polyfill": "^6.16.0",
|
||||||
"babel-preset-es2015": "^6.6.0",
|
"babel-preset-es2015": "^6.6.0",
|
||||||
"exports-loader": "^0.6.3",
|
"exports-loader": "^0.6.3",
|
||||||
"ipfs": "^0.15.0",
|
|
||||||
"ipfs-api": "https://github.com/haadcode/js-ipfs-api.git",
|
|
||||||
"go-ipfs-dep": "https://github.com/haadcode/go-ipfs-dep.git",
|
"go-ipfs-dep": "https://github.com/haadcode/go-ipfs-dep.git",
|
||||||
|
"html5-fs": "https://github.com/haadcode/html5-fs.git",
|
||||||
|
"ipfs": "^0.16.0",
|
||||||
|
"ipfs-api": "https://github.com/haadcode/js-ipfs-api.git",
|
||||||
"ipfsd-ctl": "https://github.com/haadcode/js-ipfsd-ctl.git",
|
"ipfsd-ctl": "https://github.com/haadcode/js-ipfsd-ctl.git",
|
||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"lodash": "^4.3.0",
|
"lodash": "^4.3.0",
|
||||||
"mocha": "^2.4.5",
|
"mocha": "^2.4.5",
|
||||||
"orbit-server": "^0.2.3",
|
|
||||||
"stream-http": "^2.2.1",
|
"stream-http": "^2.2.1",
|
||||||
"webpack": "^2.1.0-beta.7"
|
"webpack": "^2.1.0-beta.7"
|
||||||
},
|
},
|
||||||
|
@ -9,7 +9,6 @@ const await = require('asyncawait/await');
|
|||||||
const ipfsd = require('ipfsd-ctl');
|
const ipfsd = require('ipfsd-ctl');
|
||||||
// const IPFS = require('ipfs')
|
// const IPFS = require('ipfs')
|
||||||
const OrbitDB = require('../src/OrbitDB');
|
const OrbitDB = require('../src/OrbitDB');
|
||||||
const OrbitServer = require('orbit-server/src/server');
|
|
||||||
|
|
||||||
// Mute logging
|
// Mute logging
|
||||||
require('logplease').setLogLevel('ERROR');
|
require('logplease').setLogLevel('ERROR');
|
||||||
@ -63,7 +62,7 @@ const IpfsApis = [
|
|||||||
IpfsApis.forEach(function(ipfsApi) {
|
IpfsApis.forEach(function(ipfsApi) {
|
||||||
|
|
||||||
describe('Orbit Client with ' + ipfsApi.name, function() {
|
describe('Orbit Client with ' + ipfsApi.name, function() {
|
||||||
this.timeout(40000);
|
this.timeout(20000);
|
||||||
|
|
||||||
let client, client2, db;
|
let client, client2, db;
|
||||||
let channel = 'abcdefghijklmn';
|
let channel = 'abcdefghijklmn';
|
||||||
@ -407,18 +406,6 @@ IpfsApis.forEach(function(ipfsApi) {
|
|||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Options: reverse', function() {
|
|
||||||
it('returns all items reversed', async((done) => {
|
|
||||||
const messages = db.iterator({ limit: -1, reverse: true })
|
|
||||||
.collect()
|
|
||||||
.map((e) => e.hash);
|
|
||||||
|
|
||||||
assert.equal(messages.length, items.length);
|
|
||||||
assert.equal(messages[0], items[0]);
|
|
||||||
done();
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Option: ranges', function() {
|
describe('Option: ranges', function() {
|
||||||
describe('gt & gte', function() {
|
describe('gt & gte', function() {
|
||||||
it('returns 1 item when gte is the head', async((done) => {
|
it('returns 1 item when gte is the head', async((done) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './src/OrbitDB.js',
|
entry: './src/OrbitDB.js',
|
||||||
@ -8,21 +8,18 @@ module.exports = {
|
|||||||
library: 'OrbitDB',
|
library: 'OrbitDB',
|
||||||
filename: './dist/orbitdb.js'
|
filename: './dist/orbitdb.js'
|
||||||
},
|
},
|
||||||
|
devtool: 'sourcemap',
|
||||||
node: {
|
node: {
|
||||||
console: false,
|
console: false,
|
||||||
process: 'mock',
|
process: 'mock',
|
||||||
Buffer: 'buffer'
|
Buffer: true
|
||||||
},
|
|
||||||
resolveLoader: {
|
|
||||||
root: path.join(__dirname, 'node_modules')
|
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
modulesDirectories: [
|
modules: [
|
||||||
path.join(__dirname, 'node_modules')
|
path.join(__dirname, 'node_modules')
|
||||||
],
|
],
|
||||||
alias: {
|
alias: {
|
||||||
'orbit-db-stre': require.resolve('./node_modules/orbit-db-store'),
|
'fs': path.join(__dirname + '/node_modules', 'html5-fs'),
|
||||||
fs: require.resolve('./node_modules/logplease/src/fs-mock'),
|
|
||||||
http: 'stream-http',
|
http: 'stream-http',
|
||||||
https: 'https-browserify',
|
https: 'https-browserify',
|
||||||
Buffer: 'buffer'
|
Buffer: 'buffer'
|
||||||
@ -41,7 +38,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
include: /node_modules\/(hoek|qs|wreck|boom)/,
|
include: /node_modules\/(hoek|qs|wreck|boom|ipfs-.+|orbit-db.+|logplease|crdts|promisify-es6)/,
|
||||||
loader: 'babel',
|
loader: 'babel',
|
||||||
query: {
|
query: {
|
||||||
presets: require.resolve('babel-preset-es2015'),
|
presets: require.resolve('babel-preset-es2015'),
|
||||||
@ -51,11 +48,12 @@ module.exports = {
|
|||||||
{
|
{
|
||||||
test: /\.json$/,
|
test: /\.json$/,
|
||||||
loader: 'json'
|
loader: 'json'
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
externals: {
|
externals: {
|
||||||
net: '{}',
|
net: '{}',
|
||||||
tls: '{}',
|
tls: '{}',
|
||||||
'require-dir': '{}'
|
'require-dir': '{}'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './src/OrbitDB.js',
|
entry: './src/OrbitDB.js',
|
||||||
@ -8,10 +8,11 @@ module.exports = {
|
|||||||
library: 'OrbitDB',
|
library: 'OrbitDB',
|
||||||
filename: './dist/orbitdb.min.js'
|
filename: './dist/orbitdb.min.js'
|
||||||
},
|
},
|
||||||
|
devtool: 'sourcemap',
|
||||||
node: {
|
node: {
|
||||||
console: false,
|
console: false,
|
||||||
process: 'mock',
|
process: 'mock',
|
||||||
Buffer: 'buffer'
|
Buffer: true
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
new webpack.optimize.UglifyJsPlugin({
|
||||||
@ -20,17 +21,15 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
resolveLoader: {
|
resolveLoader: {
|
||||||
root: path.join(__dirname, 'node_modules')
|
modules: [path.join(__dirname, 'node_modules')]
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
modulesDirectories: [
|
modules: [
|
||||||
path.join(__dirname, 'node_modules')
|
path.join(__dirname, 'node_modules')
|
||||||
],
|
],
|
||||||
alias: {
|
alias: {
|
||||||
fs: require.resolve('./node_modules/logplease/src/fs-mock'),
|
'node_modules': path.join(__dirname + '/node_modules'),
|
||||||
http: 'stream-http',
|
'fs': path.join(__dirname + '/node_modules', 'html5-fs'),
|
||||||
https: 'https-browserify',
|
|
||||||
Buffer: 'buffer'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
@ -46,7 +45,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
include: /node_modules\/(hoek|qs|wreck|boom|ipfs-.+|orbit-db-.+|logplease|crdts)/,
|
include: /node_modules\/(hoek|qs|wreck|boom|ipfs-.+|orbit-db.+|logplease|crdts|promisify-es6)/,
|
||||||
loader: 'babel',
|
loader: 'babel',
|
||||||
query: {
|
query: {
|
||||||
presets: require.resolve('babel-preset-es2015'),
|
presets: require.resolve('babel-preset-es2015'),
|
||||||
@ -64,4 +63,4 @@ module.exports = {
|
|||||||
tls: '{}',
|
tls: '{}',
|
||||||
'require-dir': '{}'
|
'require-dir': '{}'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
@ -1,34 +1,30 @@
|
|||||||
const webpack = require('webpack');
|
const webpack = require('webpack')
|
||||||
const path = require('path');
|
const path = require('path')
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: './examples/browser/browser.js',
|
entry: [
|
||||||
|
'./examples/browser/index.js',
|
||||||
|
],
|
||||||
output: {
|
output: {
|
||||||
filename: './examples/browser/bundle.js'
|
filename: './examples/browser/bundle.js'
|
||||||
},
|
},
|
||||||
node: {
|
node: {
|
||||||
console: false,
|
console: false,
|
||||||
process: 'mock',
|
process: 'mock',
|
||||||
Buffer: 'buffer'
|
Buffer: true
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
new webpack.optimize.UglifyJsPlugin({
|
// new webpack.optimize.UglifyJsPlugin({
|
||||||
mangle: false,
|
// mangle: false,
|
||||||
compress: { warnings: false }
|
// compress: { warnings: false }
|
||||||
})
|
// })
|
||||||
],
|
],
|
||||||
resolveLoader: {
|
|
||||||
root: path.join(__dirname, 'node_modules')
|
|
||||||
},
|
|
||||||
resolve: {
|
resolve: {
|
||||||
modulesDirectories: [
|
modules: [
|
||||||
path.join(__dirname, 'node_modules')
|
path.join(__dirname, 'node_modules')
|
||||||
],
|
],
|
||||||
alias: {
|
alias: {
|
||||||
fs: require.resolve('./node_modules/logplease/src/fs-mock'),
|
'fs': path.join(__dirname + '/node_modules', 'html5-fs'),
|
||||||
http: 'stream-http',
|
|
||||||
https: 'https-browserify',
|
|
||||||
Buffer: 'buffer'
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
@ -44,7 +40,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
include: /node_modules\/(hoek|qs|wreck|boom|ipfs-.+|orbit-db-.+|logplease|crdts)/,
|
include: /node_modules\/(hoek|qs|wreck|boom|log|orbit.+|logplease|crdts|promisify-es|whatwg-fetch|node-fetch|isomorphic-fetch|db\.js)/,
|
||||||
loader: 'babel',
|
loader: 'babel',
|
||||||
query: {
|
query: {
|
||||||
presets: require.resolve('babel-preset-es2015'),
|
presets: require.resolve('babel-preset-es2015'),
|
||||||
@ -62,4 +58,4 @@ module.exports = {
|
|||||||
tls: '{}',
|
tls: '{}',
|
||||||
'require-dir': '{}'
|
'require-dir': '{}'
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user