Merge branch 'master' into update-peer-exchanged

This commit is contained in:
Joel Torstensson 2020-06-12 17:37:21 +02:00
commit f876360e59
34 changed files with 11878 additions and 27629 deletions

16
API.md
View File

@ -100,7 +100,7 @@ const db = await orbitdb.keyvalue('profile')
Before starting, you should know that OrbitDB has different types of databases. Each one satisfies a different purpose. The databases that you can create are:
* [log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress): an imutable (write only) log database. Useful for transactions lists.
* [log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress): an immutable (write only) log database. Useful for transactions lists.
* [feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress): a mutable log database. Useful for blog comments.
* [keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress): Useful for loading data from keywords or an id.
* [docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options): a JSON documents database. Useful for user data or other structured data.
@ -116,6 +116,8 @@ Returns a `Promise` that resolves to [a database instance](#store-api). `name` (
- `overwrite` (boolean): Overwrite an existing database (Default: `false`)
- `replicate` (boolean): Replicate the database with peers, requires IPFS PubSub. (Default: `true`)
- `meta` (object): An optional object in [database manifest](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#address). Immutably stores any JSON-serializable value. Readable via `db.options.meta`. Default: `undefined`.
```javascript
const db = await orbitdb.create('user.posts', 'eventlog', {
accessController: {
@ -125,7 +127,10 @@ const db = await orbitdb.create('user.posts', 'eventlog', {
// Give access to the second peer
'042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839'
]
}
},
overwrite: true,
replicate: false,
meta: { hello: 'meta hello' }
})
// db created & opened
```
@ -222,6 +227,13 @@ Deletes the `Object` associated with `key`. Returns a `Promise` that resolves to
// QmbYHhnXEdmdfUDzZKeEg7HyG2f8veaF2wBrYFcSHJ3mvd
```
#### all
Returns an `Object` with the contents of all entries in the index.
```javascript
const value = db.all
// { hello: { name: 'Friend' } }
```
### orbitdb.kvstore(name|address)
Alias for [`orbitdb.keyvalue()`](#orbitdbkeyvaluenameaddress)

View File

@ -2,6 +2,63 @@
Note: OrbitDB follows [semver](https://semver.org/). We are currently in alpha: backwards-incompatible changes may occur in minor releases.
## v0.24.1
### JS-IPFS 0.44 Support
Until now the newest versions of js-ipfs were not supported. This was primarly because of js-ipfs api's move to async iteration starting in version 0.41. Now js-ipfs versions 0.41-0.44 are supported.
Relevant PRs:
- https://github.com/orbitdb/orbit-db-store/pull/86
- https://github.com/orbitdb/orbit-db/pull/782
### Store Operation Queue
All included stores (and any store extending orbit-db-store v3.3.0+) now queues operations. Any update sent to a store is executed sequentially and the store's close method now awaits for the queue to empty.
Relevant PRs:
- https://github.com/orbitdb/orbit-db-store/pull/85
- https://github.com/orbitdb/orbit-db-store/pull/91
### Docstore putAll Operation
A new method was added to the docstore named 'putAll'. This method allows for multiple keys to be set in the docstore in one oplog entry. This comes with some significant [performance benefits](https://gist.github.com/phillmac/155ed1eb232e75fda4a793e7672460fd). Something to note is any nodes running an older version of the docstore will ignore any changes made by putAll operations.
Relevant PRs:
- https://github.com/orbitdb/orbit-db-docstore/pull/36
### Oplog Events
It is now possible to listen for specific store operations as they are added to the store. To learn more about how to use this you can review the [documentation](https://github.com/orbitdb/orbit-db-store#events) and look at event `log.op.${operation}`.
Relevant PRs:
- https://github.com/orbitdb/orbit-db-store/pull/87
### orbit-db tests
Tests now use [orbit-db-test-utils](https://github.com/orbitdb/orbit-db-test-utils) package to deduplicate test utilities. It had already been used in most subpackages like [orbit-db-store](https://github.com/orbitdb/orbit-db-store) but now it's used in the [orbit-db](https://github.com/orbitdb/orbit-db) repo!
Relevant PRs:
- https://github.com/orbitdb/orbit-db-test-utils/pull/11
- https://github.com/orbitdb/orbit-db/pull/794
### orbit-db-store sync method
A method on orbit-db-store named sync is now an async method and only resolves after oplog heads have been added.
Relevant PRs:
- https://github.com/orbitdb/orbit-db-store/pull/38
- https://github.com/orbitdb/orbit-db-store/pull/84
### Electron Renderer FS Shim
Fixes a bug related to the native filesystem when used in electron.
Relevant PRs:
- https://github.com/orbitdb/orbit-db/pull/783
- https://github.com/orbitdb/orbit-db/pull/795
### Re-exports
Now import AccessControllers, Identities, and/or Keystore modules from OrbitDB with object destructuring like so:
`const { AccessControllers, Identities, Keystore } = require('orbit-db')`
Relevant PRs:
- https://github.com/orbitdb/orbit-db/pull/785
## v0.23.0
### Performance Improvements

6
FAQ.md
View File

@ -43,9 +43,9 @@ In short: it can't be assumed that data has been replicated to the network after
### Does OrbitDB already support pinning when using js-ipfs ?
Currently [js-ipfs](https://github.com/ipfs/js-ipfs) doesn't have GC, so nothing gets removed meaning everything is pinned by default.
Currently [js-ipfs](https://github.com/ipfs/js-ipfs) supports `ipfs.repo.gc()` but it's yet not run on any sort of schedule, so nothing gets removed from a `js-ipfs` node and therefore an OrbitDB database.
However, this will change in the future as js-ipfs gets GC and we want to make sure that OrbitDB is actually persisting everything (by default), so some work on pinning needs to happen. If you're using OrbitDB with go-ipfs (through js-ipfs-api), then GC happens and data may not be persisted anymore after a time. This is a known issue and we're planning to implement actual pinning (from IPFS perspective) soon.
However, this will change in the future as js-ipfs schedules GC and we want to make sure that OrbitDB is actually persisting everything (by default), so [some work on pinning needs to happen](https://github.com/ipfs/js-ipfs/issues/2650). If you're using OrbitDB with go-ipfs (through js-ipfs-api), and GC happens and data may not be persisted anymore. Once the pinning performance is fixed we will implement pinning-by-default in [`orbit-db-io`](https://github.com/orbitdb/orbit-db-io).
### Does orbit have a shared feed between peers where multiple peers can append to the same feed?
@ -79,7 +79,7 @@ To allow specific keys to write to the database, pass the keys as strings like s
`orbitdb.feed('name', { accessController: { write ['key1', 'key2'] }}) // keys cannot be revoked`
Allows anyone to write to the db. If you specify keys, the process involves granting and revoking keys. Granting is doable, but revokation is a harder and is being worked on by multiple parties, without a solution.
Allows anyone to write to the db. If you specify keys, the process involves granting and revoking keys. Granting is doable, but revocation is a harder and is being worked on by multiple parties, without a solution.
If you want to encrypt the keys or content, it's easier with a single user. If you want to use encryption with multiwriters, that's another bag which also hasn't been solved.

View File

@ -10,6 +10,7 @@ This guide is still being worked on and we would love to get [feedback and sugge
- [Background](#background)
- [Install](#install)
- [API](#api)
- [Setup](#setup)
- [Create a database](#create-a-database)
* [Address](#address)
@ -48,6 +49,10 @@ Install [orbit-db](https://github.com/orbitdb/orbit-db) and [ipfs](https://www.n
npm install orbit-db ipfs
```
## API
See [API.md](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation.
## Setup
Require OrbitDB and IPFS in your program and create the instances:

View File

@ -14,7 +14,7 @@ build: test
cp node_modules/ipfs/dist/index.min.js examples/browser/lib/ipfs.min.js
cp dist/orbitdb.js examples/browser/lib/orbitdb.js
cp dist/orbitdb.js.map examples/browser/lib/orbitdb.js.map
cp node_modules/ipfs/dist/index.js examples/browser/lib/ipfs.js
cp node_modules/ipfs/dist/index.min.js examples/browser/lib/ipfs.js
@echo "Build success!"
@echo "Output: 'dist/', 'examples/browser/'"

View File

@ -4,7 +4,7 @@
<img src="images/orbit_db_logo_color.jpg" width="256" />
</p>
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![Matrix](https://img.shields.io/badge/matrix-%23orbitdb%3Apermaweb.io-blue.svg)](https://riot.permaweb.io/#/room/#orbitdb:permaweb.io) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/v3RNE3M) [![CircleCI Status](https://circleci.com/gh/orbitdb/orbit-db.svg?style=shield)](https://circleci.com/gh/orbitdb/orbit-db) [![npm version](https://badge.fury.io/js/orbit-db.svg)](https://www.npmjs.com/package/orbit-db) [![node](https://img.shields.io/node/v/orbit-db.svg)](https://www.npmjs.com/package/orbit-db)
[![Gitter](https://img.shields.io/gitter/room/nwjs/nw.js.svg)](https://gitter.im/orbitdb/Lobby) [![Matrix](https://img.shields.io/badge/matrix-%23orbit--db%3Amatrix.org-blue.svg)](https://riot.im/app/#/room/#orbit-db:matrix.org) [![Discord](https://img.shields.io/discord/475789330380488707?color=blueviolet&label=discord)](https://discord.gg/v3RNE3M) [![CircleCI Status](https://circleci.com/gh/orbitdb/orbit-db.svg?style=shield)](https://circleci.com/gh/orbitdb/orbit-db) [![npm version](https://badge.fury.io/js/orbit-db.svg)](https://www.npmjs.com/package/orbit-db) [![node](https://img.shields.io/node/v/orbit-db.svg)](https://www.npmjs.com/package/orbit-db)
OrbitDB is a **serverless, distributed, peer-to-peer database**. OrbitDB uses [IPFS](https://ipfs.io) as its data storage and [IPFS Pubsub](https://github.com/ipfs/go-ipfs/blob/master/core/commands/pubsub.go#L23) to automatically sync databases with peers. It's an eventually consistent database that uses [CRDTs](https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type) for conflict-free database merges making OrbitDB an excellent choice for decentralized apps (dApps), blockchain applications and offline-first web applications.
@ -27,7 +27,7 @@ Status: **in active development**
***NOTE!*** *OrbitDB is **alpha-stage** software. It means OrbitDB hasn't been security audited and programming APIs and data formats can still change. We encourage you to [reach out to the maintainers](https://gitter.im/orbitdb/Lobby) if you plan to use OrbitDB in mission critical systems.*
This is the Javascript implementation and it works both in **Browsers** and **Node.js** with support for Linux and OS X (Windows is not supported yet). The minimum required version of Node.js is now 8.6.0 due to the usage of `...` spread syntax. LTS versions (even numbered versions 8, 10, etc) are preferred.
This is the Javascript implementation and it works both in **Browsers** and **Node.js** with support for Linux and OS X and Windows. The minimum required version of Node.js is now 8.6.0 due to the usage of `...` spread syntax. LTS versions (even numbered versions 8, 10, etc) are preferred.
To use with older versions of Node.js, we provide an ES5-compatible build through the npm package, located in `dist/es5/` when installed through npm.
@ -40,6 +40,7 @@ We also have regular community calls, which we announce in the issues in [the @o
- [Usage](#usage)
* [CLI](#cli)
* [Database browser UI](#database-browser-ui)
* [Module with IPFS Instance](#module-with-ipfs-instance)
* [Module with IPFS Daemon](#module-with-ipfs-daemon)
- [API](#api)
@ -79,6 +80,18 @@ It can be installed from npm with:
npm install orbit-db-cli -g
```
### Database browser UI
OrbitDB databases can easily be managed using a web UI, see **[OrbitDB Control Center](https://github.com/orbitdb/orbit-db-control-center)**.
Install and run it locally:
```
git clone https://github.com/orbitdb/orbit-db-control-center.git
cd orbit-db-control-center/
npm i && npm start
```
### Module with IPFS Instance
If you're using `orbit-db` to develop **browser** or **Node.js** applications, use it as a module with the javascript instance of IPFS
@ -93,51 +106,84 @@ npm install orbit-db ipfs
const IPFS = require('ipfs')
const OrbitDB = require('orbit-db')
// Create IPFS instance
// For js-ipfs >= 0.38
const ipfs = new IPFS()
// Create IPFS instance
const initIPFSInstance = async () => {
return await IPFS.create({ repo: "./path-for-js-ipfs-repo" });
};
initIPFSInstance().then(async ipfs => {
const orbitdb = await OrbitDB.createInstance(ipfs);
// Create / Open a database
const db = await orbitdb.log("hello");
await db.load();
// Listen for updates from peers
db.events.on("replicated", address => {
console.log(db.iterator({ limit: -1 }).collect());
});
// Add an entry
const hash = await db.add("world");
console.log(hash);
// Query
const result = db.iterator({ limit: -1 }).collect();
console.log(JSON.stringify(result, null, 2));
});
// For js-ipfs < 0.38
// Create IPFS instance
const ipfsOptions = {
EXPERIMENTAL: {
pubsub: true
}
}
const ipfs = new IPFS(ipfsOptions)
};
ipfs.on('error', (e) => console.error(e))
ipfs.on('ready', async () => {
const orbitdb = await OrbitDB.createInstance(ipfs)
ipfs = new IPFS(ipfsOptions);
initIPFSInstance().then(ipfs => {
ipfs.on("error", e => console.error(e));
ipfs.on("ready", async () => {
const orbitdb = await OrbitDB.createInstance(ipfs);
// Create / Open a database
const db = await orbitdb.log('hello')
await db.load()
const db = await orbitdb.log("hello");
await db.load();
// Listen for updates from peers
db.events.on('replicated', (address) => {
console.log(db.iterator({ limit: -1 }).collect())
})
db.events.on("replicated", address => {
console.log(db.iterator({ limit: -1 }).collect());
});
// Add an entry
const hash = await db.add('world')
console.log(hash)
const hash = await db.add("world");
console.log(hash);
// Query
const result = db.iterator({ limit: -1 }).collect()
console.log(JSON.stringify(result, null, 2))
})
const result = db.iterator({ limit: -1 }).collect();
console.log(JSON.stringify(result, null, 2));
});
});
```
### Module with IPFS Daemon
Alternatively, you can use [ipfs-api](https://npmjs.org/package/ipfs-api) to use `orbit-db` with a locally running IPFS daemon. Use this method if you're using `orbitd-db` to develop **backend** or **desktop** applications, eg. with [Electron](https://electron.atom.io).
Alternatively, you can use [ipfs-http-client](https://www.npmjs.com/package/ipfs-http-client) to use `orbit-db` with a locally running IPFS daemon. Use this method if you're using `orbitd-db` to develop **backend** or **desktop** applications, eg. with [Electron](https://electron.atom.io).
Install dependencies:
```
npm install orbit-db ipfs-http-client
npm install orbit-db ipfs-http-client@41.0.1
```
**Note:** need to use v41.0.1 until support for modern JS API is added in [orbit-db#767](https://github.com/orbitdb/orbit-db/pull/767).
```javascript
const IpfsClient = require('ipfs-http-client')
const OrbitDB = require('orbit-db')

38899
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "orbit-db",
"version": "0.23.1",
"version": "0.24.1",
"description": "Distributed p2p database on IPFS",
"author": "Haad",
"license": "MIT",
@ -21,17 +21,17 @@
"multihashes": "^0.4.12",
"orbit-db-access-controllers": "~0.2.2",
"orbit-db-cache": "~0.3.0",
"orbit-db-counterstore": "~1.7.0",
"orbit-db-docstore": "~1.7.0",
"orbit-db-eventstore": "~1.7.0",
"orbit-db-feedstore": "~1.7.0",
"orbit-db-counterstore": "~1.9.0",
"orbit-db-docstore": "~1.9.0",
"orbit-db-eventstore": "~1.9.0",
"orbit-db-feedstore": "~1.9.0",
"orbit-db-identity-provider": "~0.3.0",
"orbit-db-io": "~0.2.0",
"orbit-db-keystore": "~0.3.0",
"orbit-db-kvstore": "~1.7.0",
"orbit-db-kvstore": "~1.9.0",
"orbit-db-pubsub": "~0.5.5",
"orbit-db-storage-adapter": "~0.5.3",
"orbit-db-store": "git://github.com/orbitdb/orbit-db-store.git#3860443bf4f0fefaee9bd31d181a1a891afcba22"
"orbit-db-store": "~3.3.0"
},
"devDependencies": {
"adm-zip": "^0.4.13",
@ -45,15 +45,11 @@
"cross-env": "^6.0.3",
"datastore-level": "~0.14.0",
"fs-extra": "^7.0.1",
"go-ipfs-dep": "~0.4.20",
"ipfs": "~0.40.0",
"ipfs-http-client": "~37.0.1",
"ipfs-repo": "~0.30.1",
"ipfsd-ctl": "~0.42.3",
"localstorage-level-migration": "~0.1.0",
"markdown-toc": "^1.2.0",
"mkdirp": "^0.5.1",
"mocha": "^5.2.0",
"orbit-db-test-utils": "^0.9.4",
"p-each-series": "^1.0.0",
"p-map": "^1.2.0",
"p-map-series": "^1.0.0",
@ -76,7 +72,7 @@
"examples:browser-windows": "start examples/browser/browser.html",
"lint:docs": "remark -qf -u validate-links .",
"test:all": "npm run test:browser-multiple-tabs && npm run test",
"test": "cross-env TEST=all mocha",
"test": "cross-env TEST=js mocha && cross-env TEST=go mocha;",
"test:browser-multiple-tabs": "npm run build:dist && cpy dist/orbitdb.min.js ./test/browser --rename=orbitdb.js && cpy node_modules/ipfs/dist/index.js ./test/browser --rename=ipfs.js && cpy node_modules/orbit-db-identity-provider/dist/index-browser.min.js ./test/browser --rename=identities.js && cpy node_modules/ipfs-log/dist/ipfslog.min.js ./test/browser && mocha ./test/browser/concurrent.spec.js",
"build": "npm run build:es5 && npm run build:debug && npm run build:dist && npm run build:examples && npm run build:docs/toc",
"build:examples": "webpack --config conf/webpack.example.config.js --sort-modules-by size",
@ -85,6 +81,9 @@
"build:docs/toc": "markdown-toc --no-first1 -i README.md && markdown-toc --no-first1 -i API.md && markdown-toc --no-first1 -i GUIDE.md && markdown-toc --no-first1 -i CHANGELOG.md && markdown-toc --no-first1 -i FAQ.md ",
"build:es5": "babel src --out-dir ./dist/es5/ --presets babel-preset-env --plugins babel-plugin-transform-runtime"
},
"go-ipfs": {
"version": "v0.5.1"
},
"standard": {
"env": "mocha",
"ignore": [

View File

@ -519,4 +519,8 @@ class OrbitDB {
}
}
OrbitDB.prototype.AccessControllers = AccessControllers
OrbitDB.prototype.Identities = Identities
OrbitDB.prototype.Keystore = Keystore
module.exports = OrbitDB

View File

@ -1,5 +1,17 @@
/* eslint-disable */
const fs = (typeof window === 'object' || typeof self === 'object') ? null
: eval('require("fs")')
// adapted from https://github.com/cheton/is-electron - (c) Cheton Wu
const isElectron = () => {
if (typeof window !== 'undefined' && typeof window.process === 'object') {
return true
}
if (typeof process !== 'undefined' && typeof process.versions === 'object' && !!process.versions.electron) {
return true
}
return false
}
const fs = (!isElectron() && (typeof window === 'object' || typeof self === 'object')) ? null : eval('require("fs")')
module.exports = fs

View File

@ -22,16 +22,29 @@
</div>
<!-- </div> -->
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', async () => {
const randStr = () => Math.random().toString(36).substring(6)
const ipfs = new Ipfs({
repo: './odb/',
EXPERIMENTAL: {
pubsub: true
},
preload: { enabled: false },
config: {
Bootstrap: [ ]
}
const ipfs = await Ipfs.create({
repo: './odb/'
})
const identity = await Identities.createIdentity({ id: 'A'})
const orbitdb = await OrbitDB.createInstance(ipfs, { identity })
const consistentLog = await orbitdb.log('concurrent', { syncLocal: true, sortFn: Log.Sorting.SortByEntryHash })
const inconsistentLog = await orbitdb.log('concurrent2')
window.consistentLog = consistentLog
window.inconsistentLog = inconsistentLog
waitForOpenDB.innerHTML = consistentLog.address.toString() + ' + ' + inconsistentLog.address.toString()
await consistentLog.load()
await inconsistentLog.load()
addData.addEventListener('click', async event => {
const data = randStr()
await consistentLog.add(data)
await inconsistentLog.add(data)
})
})
async function getConsistentLogLength () {
@ -63,32 +76,6 @@
await window.inconsistentLog.load()
}
ipfs.on('ready', async () => {
const identity = await Identities.createIdentity({ id: 'A'})
const orbitdb = await OrbitDB.createInstance(ipfs, { identity })
const consistentLog = await orbitdb.log('concurrent', { syncLocal: true, sortFn: Log.Sorting.SortByEntryHash })
const inconsistentLog = await orbitdb.log('concurrent2')
window.consistentLog = consistentLog
window.inconsistentLog = inconsistentLog
waitForOpenDB.innerHTML = consistentLog.address.toString() + ' + ' + inconsistentLog.address.toString()
await consistentLog.load()
await inconsistentLog.load()
// const updateData = () => {
// logData.innerHTML = ''
// const count = consistentlog.iterator({ limit: -1 }).collect().map(e => {
// logData.innerHTML += e.clock.time + ': ' + e.hash + '<br />'
// })
// }
addData.addEventListener('click', async event => {
const data = randStr()
await consistentLog.add(data)
await inconsistentLog.add(data)
})
})
</script>
</body>
</html>

View File

@ -2,7 +2,6 @@
const assert = require('assert')
const mapSeries = require('p-each-series')
const path = require('path')
const rmrf = require('rimraf')
const OrbitDB = require('../src/OrbitDB')
// Include test utilities
@ -12,8 +11,8 @@ const {
stopIpfs,
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
waitForPeers
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/counters/peer1'
const dbPath2 = './orbitdb/tests/counters/peer2'
@ -21,7 +20,7 @@ const ipfsPath1 = './orbitdb/tests/counters/peer1/ipfs'
const ipfsPath2 = './orbitdb/tests/counters/peer2/ipfs'
Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Counters (${API})`, function() {
describe(`orbit-db - Counters (${API})`, function () {
this.timeout(config.timeout)
let orbitdb1, orbitdb2
@ -80,6 +79,7 @@ Object.keys(testAPIs).forEach(API => {
it('value is zero when it\'s a fresh database', async () => {
const db = await orbitdb1.counter('counter database')
assert.equal(db.value, 0)
await db.close()
})
it('increases a counter value', async () => {
@ -127,9 +127,12 @@ Object.keys(testAPIs).forEach(API => {
return new Promise(resolve => {
// Wait for a while to make sure db's have been synced
setTimeout(() => {
setTimeout(async () => {
assert.equal(counter1.value, 30)
assert.equal(counter2.value, 30)
await counter1.close()
await counter2.close()
resolve()
}, 1000)
})

View File

@ -19,7 +19,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = path.join('./orbitdb', 'tests', 'create-open')
const ipfsPath = path.join('./orbitdb', 'tests', 'create-open', 'ipfs')
@ -40,7 +40,6 @@ Object.keys(testAPIs).forEach(API => {
return !(src.includes('LOG') || src.includes('LOCK'))
}
before(async () => {
config.daemon1.repo = ipfsPath
rmrf.sync(config.daemon1.repo)
@ -142,7 +141,7 @@ Object.keys(testAPIs).forEach(API => {
it('saves database manifest file locally', async () => {
const manifestHash = db.id.split('/')[2]
const manifest = await io.read(ipfs, manifestHash)
assert.notEqual(manifest)
assert.notEqual(manifest, false)
assert.equal(manifest.name, 'second')
assert.equal(manifest.type, 'feed')
assert.notEqual(manifest.accessController, null)

View File

@ -11,7 +11,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = './orbitdb/tests/create-open'
const ipfsPath = './orbitdb/tests/create-open/ipfs'

View File

@ -14,7 +14,10 @@ const {
startIpfs,
stopIpfs,
testAPIs,
databases,
} = require('orbit-db-test-utils')
const {
databases
} = require('./utils')
const dbPath = './orbitdb/tests/customKeystore'
@ -24,10 +27,10 @@ Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - Use a Custom Cache (${API})`, function() {
this.timeout(20000)
let ipfsd, ipfs, orbitdb1
let ipfsd, ipfs, orbitdb1, store
before(async () => {
const store = await storage.createStore("local")
store = await storage.createStore("local")
const cache = new CustomCache(store)
config.daemon1.repo = ipfsPath
@ -42,24 +45,20 @@ Object.keys(testAPIs).forEach(API => {
})
after(async () => {
if(orbitdb1)
await orbitdb1.stop()
if (ipfsd)
await stopIpfs(ipfsd)
})
describe('allows orbit to use a custom cache with different store types', function() {
databases.forEach(async (database) => {
it(database.type + ' allows custom keystore', async () => {
for (let database of databases) {
it(database.type + ' allows custom cache', async () => {
const db1 = await database.create(orbitdb1, 'custom-keystore')
await database.tryInsert(db1)
assert.deepEqual(database.getTestValue(db1), database.expectedValue)
await db1.close()
})
})
}
})
})
})

View File

@ -11,6 +11,9 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('orbit-db-test-utils')
const {
CustomTestKeystore,
databases,
} = require('./utils')
@ -40,10 +43,7 @@ Object.keys(testAPIs).forEach(API => {
})
after(async () => {
if(orbitdb1)
await orbitdb1.stop()
if (ipfsd)
await stopIpfs(ipfsd)
})

View File

@ -11,7 +11,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = './orbitdb/tests/docstore'
const ipfsPath = './orbitdb/tests/docstore/ipfs'
@ -52,7 +52,7 @@ Object.keys(testAPIs).forEach(API => {
maxHistory: 0,
path: dbPath,
}
db = await orbitdb1.docstore(config.dbname, options)
db = await orbitdb1.docstore('orbit-db-tests', options)
})
afterEach(async () => {
@ -177,7 +177,7 @@ Object.keys(testAPIs).forEach(API => {
replicate: false,
maxHistory: 0
}
db = await orbitdb1.docstore(config.dbname, options)
db = await orbitdb1.docstore('orbit-db-tests', options)
})
afterEach(async () => {

View File

@ -12,7 +12,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = './orbitdb/tests/drop'
const ipfsPath = './orbitdb/tests/drop/ipfs'

View File

@ -12,7 +12,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const last = arr => arr[arr.length - 1]

View File

@ -12,7 +12,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const last = arr => arr[arr.length - 1]

View File

@ -12,7 +12,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const last = arr => arr[arr.length - 1]

View File

@ -11,7 +11,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = './orbitdb/tests/kvstore'
const ipfsPath = './orbitdb/tests/kvstore/ipfs'
@ -31,16 +31,15 @@ Object.keys(testAPIs).forEach(API => {
orbitdb1 = await OrbitDB.createInstance(ipfs, { directory: path.join(dbPath, '1') })
})
after(async () => {
if(orbitdb1)
after(() => {
setTimeout(async () => {
await orbitdb1.stop()
if (ipfsd)
await stopIpfs(ipfsd)
}, 0)
})
beforeEach(async () => {
db = await orbitdb1.kvstore(config.dbname, { path: dbPath })
db = await orbitdb1.kvstore('orbit-db-tests', { path: dbPath })
})
afterEach(async () => {

View File

@ -13,7 +13,7 @@ const {
connectPeers,
waitForPeers,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/multiple-databases/1'
const dbPath2 = './orbitdb/tests/multiple-databases/2'

View File

@ -18,7 +18,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/offline/db1'
const dbPath2 = './orbitdb/tests/offline/db2'

View File

@ -13,7 +13,7 @@ const {
startIpfs,
stopIpfs,
testAPIs
} = require('./utils')
} = require('orbit-db-test-utils')
Object.keys(testAPIs).forEach(API => {
describe(`orbit-db - OrbitDB Address (${API})`, function() {

View File

@ -16,7 +16,7 @@ const {
startIpfs,
stopIpfs,
testAPIs
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = './orbitdb/tests/persistency'
const ipfsPath = './orbitdb/tests/persistency/ipfs'

20
test/re-exports.test.js Normal file
View File

@ -0,0 +1,20 @@
'use strict'
const assert = require('assert')
const { AccessControllers, Identities, Keystore } = require('../src/OrbitDB')
describe('Re-exports', function () {
it('Successfully re-exports AccessControllers', () => {
assert.strictEqual(typeof AccessControllers, 'function')
assert.strictEqual(typeof AccessControllers.addAccessController, 'function')
})
it('Successfully re-exports Identities', () => {
assert.strictEqual(typeof Identities, 'function')
assert.strictEqual(typeof Identities.createIdentity, 'function')
})
it('Successfully re-exports Keystore', () => {
assert.strictEqual(typeof Keystore, 'function')
})
})

View File

@ -13,7 +13,7 @@ const {
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/replicate-and-load/1'
const dbPath2 = './orbitdb/tests/replicate-and-load/2'

View File

@ -13,7 +13,7 @@ const {
testAPIs,
connectPeers,
waitForPeers,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/replicate-automatically/1'
const dbPath2 = './orbitdb/tests/replicate-automatically/2'

View File

@ -14,7 +14,7 @@ const {
connectPeers,
waitForPeers,
MemStore,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/replication/1'
const dbPath2 = './orbitdb/tests/replication/2'

View File

@ -16,7 +16,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath1 = './orbitdb/tests/create-open/1'
const dbPath2 = './orbitdb/tests/create-open/2'

View File

@ -16,7 +16,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const keysPath = './orbitdb/identity/identitykeys'
const dbPath = './orbitdb/tests/change-identity'

View File

@ -26,7 +26,7 @@ const {
startIpfs,
stopIpfs,
testAPIs,
} = require('./utils')
} = require('orbit-db-test-utils')
const dbPath = path.join('./orbitdb', 'tests', 'v0')
const dbFixturesDir = path.join('./test', 'fixtures', 'v0', 'QmWDUfC4zcWJGgc9UHn1X3qQ5KZqBv4KCiCtjnpMmBT8JC', 'v0-db')
@ -61,10 +61,11 @@ Object.keys(testAPIs).forEach(API => {
await fs.copy(path.join(ipfsFixturesDir, 'blocks'), path.join(ipfsd.path, 'blocks'))
await fs.copy(path.join(ipfsFixturesDir, 'datastore'), path.join(ipfsd.path, 'datastore'), { filter: filterFunc })
const store = await storage.createStore(path.join(dbPath, ipfs._peerInfo.id._idB58String, 'keys'))
const peerId = (await ipfs.id()).id
const store = await storage.createStore(path.join(dbPath, peerId, 'keys'))
keystore = new Keystore(store)
let identity = await Identities.createIdentity({ id: ipfs._peerInfo.id._idB58String, migrate: migrate(keyFixtures), keystore })
let identity = await Identities.createIdentity({ id: peerId, migrate: migrate(keyFixtures), keystore })
orbitdb = await OrbitDB.createInstance(ipfs, { identity, keystore })
})

View File

@ -10,7 +10,10 @@ const {
config,
startIpfs,
stopIpfs,
testAPIs,
testAPIs
} = require('orbit-db-test-utils')
const {
databases
} = require('./utils')