From 9eca16a10770e181015585be9a082e876ef626fa Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 13:08:41 -0400 Subject: [PATCH 01/31] docs: update api with missing static methods & props --- API.md | 131 +++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 95 insertions(+), 36 deletions(-) diff --git a/API.md b/API.md index ccf2334..75fb240 100644 --- a/API.md +++ b/API.md @@ -1,6 +1,6 @@ # orbit-db API documentation -OrbitDB provides various types of databases for different data models: +OrbitDB provides various types of databases for different data models: - [log](#lognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. - [feed](#feednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". - [keyvalue](#keyvaluenameaddress) is a key-value database just like your favourite key-value database. @@ -43,7 +43,7 @@ ipfs.on('ready', () => { // Add an entry const hash = await db.add('world') console.log(hash) - + // Query const result = db.iterator({ limit: -1 }).collect() console.log(result) @@ -80,28 +80,38 @@ Choose this options if you're using `orbitd-db` to develop **backend** or **desk - [OrbitDB](#orbitdb) - [constructor(ipfs, [directory], [options])](#constructoripfs-directory-options) - - [keyvalue(name|address)](#keyvaluenameaddress) - - [put(key, value)](#putkey-value) - - [set(key, value)](#setkey-value) - - [get(key)](#getkey) - - [log(name|address)](#lognameaddress) - - [add(event)](#addevent) - - [get(hash)](#gethash) - - [iterator([options])](#iteratoroptions) - - [feed(name|address)](#feednameaddress) - - [add(data)](#adddata) - - [get(hash)](#gethash-1) - - [remove(hash)](#removehash) - - [iterator([options])](#iteratoroptions) - - [docs(name|address, options)](#docsnameaddress-options) - - [put(doc)](#putdoc) - - [get(hash)](#getkey-1) - - [query(mapper)](#querymapper) - - [del(key)](#delkey) - - [counter(name|address)](#counternameaddress) - - [value](#value) - - [inc([value])](#incvalue) - - [stop()](#stop) + - **Public Methods** + - [keyvalue(name|address)](#keyvaluenameaddress) + - [put(key, value)](#putkey-value) + - [set(key, value)](#setkey-value) + - [get(key)](#getkey) + - [log(name|address)](#lognameaddress) + - [add(event)](#addevent) + - [get(hash)](#gethash) + - [iterator([options])](#iteratoroptions) + - [feed(name|address)](#feednameaddress) + - [add(data)](#adddata) + - [get(hash)](#gethash-1) + - [remove(hash)](#removehash) + - [iterator([options])](#iteratoroptions) + - [docs(name|address, options)](#docsnameaddress-options) + - [put(doc)](#putdoc) + - [get(hash)](#getkey-1) + - [query(mapper)](#querymapper) + - [del(key)](#delkey) + - [counter(name|address)](#counternameaddress) + - [value](#value) + - [inc([value])](#incvalue) + - [create(name|address, type, [options])]() + - [stop()](#stop) + - **Static Properties** + - [databaseTypes]() + - **Static Methods** + - [isValidType()]() + - [addDatabaseType()]() + - [getDatabaseTypes()]() + - [isValidAddress()]() + - [parseAddress()]() - [Store](#store) - [load()](#load) - [close()](#close) @@ -127,9 +137,10 @@ ipfs.on('ready', () => { After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a [database instance](#store). See the [Store](#store) section for details of common methods and properties. ```javascript -const db = await orbitdb.kvstore('profile') +const db = await orbitdb.keyvalue('profile') ``` +### **Public Methods** ### keyvalue(name|address) Module: [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) @@ -176,14 +187,14 @@ const db = await orbitdb.eventlog(anotherlogdb.address) ```javascript const hash = await db.add({ name: 'User1' }) ``` - + #### get(hash) ```javascript const event = db.get(hash) .map((e) => e.payload.value) // { name: 'User1' } ``` - + #### iterator([options]) **options** : It is an object which supports the following properties @@ -225,19 +236,19 @@ See the [Store](#store) section for details of common methods and properties. ```javascript const hash = await db.add({ name: 'User1' }) ``` - + #### get(hash) ```javascript const event = db.get(hash) .map((e) => e.payload.value) // { name: 'User1' } ``` - + #### remove(hash) ```javascript const hash = await db.remove(hash) ``` - + #### iterator([options]) **options** : It is an object which supports the following properties @@ -285,14 +296,14 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } ```javascript const hash = await db.put({ _id: 'QmAwesomeIpfsHash', name: 'shamb0t', followers: 500 }) ``` - + #### get(key) ```javascript const profile = db.get('shamb0t') .map((e) => e.payload.value) // [{ _id: 'shamb0t', name: 'shamb0t', followers: 500 }] ``` - + #### query(mapper) ```javascript const all = db.query((doc) => doc.followers >= 500) @@ -303,7 +314,7 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } ```javascript const hash = await db.del('shamb0t') ``` - + ### counter(name|address) Module: [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) @@ -330,7 +341,7 @@ const counter = await orbitdb.counter(anothercounterdb.address) await counter.inc(-2) counter.value // 8 ``` - + ### stop() Stop OrbitDB, close databases and disconnect the databases from the network. @@ -338,6 +349,54 @@ const counter = await orbitdb.counter(anothercounterdb.address) ```javascript orbitdb.stop() ``` +### **Static Properties** +### databaseTypes +Returns supported database types (i.e. store types) as an Array of strings +```js +OrbitDB.databaseTypes +// [ 'counter', 'eventlog', 'feed', 'docstore', 'keyvalue'] +``` + +### **Static Methods** + +### isValidType(type) +Returns `true` if the provided string is a supported database type +```js +OrbitDB.isValidType('docstore') +// true +``` + +### addDatabaseType(type, store) +Adds a custom database type & store to OrbitDB +```js +const CustomStore = require('./CustomStore') +OrbitDB.addDatabaseType(CustomStore.type, CustomStore) +``` + +### getDatabaseTypes() +Returns an object mapping database types to Store Classes +```js +OrbitDB.getDatabaseTypes() +// { counter: [Function: CounterStore], +// eventlog: [Function: EventStore], +// feed: [Function: FeedStore], +// docstore: [Function: DocumentStore], +// keyvalue: [Function: KeyValueStore] } +``` +### isValidAddress(address) +Returns `true` if the provided string is a valid orbitdb address +```js +OrbitDB.isValidAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') +// true +``` +### parseAddress(address) +Returns an instance of OrbitDBAddress if the provided string is a valid orbitdb address +```js +OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') +// OrbitDBAddress { +// root: 'Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC', +// path: 'first-database' } +``` ## Store @@ -385,8 +444,8 @@ The [keypair](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#keys) use ``` const key = db.key console.log(key) -// > ``` From 2969cd4af135ede30de1360599c6962ff39fa50c Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 13:12:06 -0400 Subject: [PATCH 02/31] docs: update table with links to methods --- API.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/API.md b/API.md index 75fb240..c777f6b 100644 --- a/API.md +++ b/API.md @@ -105,13 +105,13 @@ Choose this options if you're using `orbitd-db` to develop **backend** or **desk - [create(name|address, type, [options])]() - [stop()](#stop) - **Static Properties** - - [databaseTypes]() + - [databaseTypes](#databasetypes) - **Static Methods** - - [isValidType()]() - - [addDatabaseType()]() - - [getDatabaseTypes()]() - - [isValidAddress()]() - - [parseAddress()]() + - [isValidType(type)](#isvalidtypetype) + - [addDatabaseType(type, store)](#adddatabasetypetype-store) + - [getDatabaseTypes()](#getdatabasetypes) + - [isValidAddress(address)](#isvalidaddressaddress) + - [parseAddress(address)](#parseaddressaddress) - [Store](#store) - [load()](#load) - [close()](#close) From 2c037a5236ecce9ee4ac8c1a90676fd16bf12550 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:07:30 -0400 Subject: [PATCH 03/31] docs: refractor --- API.md | 210 ++++++++++++++++--------------------------------- GUIDE.md | 26 +++--- README.md | 230 +++++++++++++++++++++++++++++++++++------------------- 3 files changed, 229 insertions(+), 237 deletions(-) diff --git a/API.md b/API.md index c777f6b..5b12ca1 100644 --- a/API.md +++ b/API.md @@ -1,138 +1,16 @@ -# orbit-db API documentation - -OrbitDB provides various types of databases for different data models: -- [log](#lognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. -- [feed](#feednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". -- [keyvalue](#keyvaluenameaddress) is a key-value database just like your favourite key-value database. -- [docs](#docsnameaddress-options) is a document database to which documents can be stored and indexed by a specified key. Useful for example building search indices or version controlling documents and data. -- [counter](#counternameaddress) for counting. Useful for example counting events separate from log/feed data. - -Which database to use depends on your use case and data model. - -## Usage +# OrbitDB API Documentation Read the **[GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** guide for a more in-depth tutorial and to understand how OrbitDB works. -### Using as a module - -Install [orbit-db](https://www.npmjs.com/package/orbit-db) and [ipfs](https://www.npmjs.com/package/ipfs) from npm: - -``` -npm install orbit-db ipfs -``` - -Require it in your program and create the instance: - -```javascript -const IPFS = require('ipfs') -const OrbitDB = require('orbit-db') - -const ipfs = new IPFS() -ipfs.on('ready', () => { - const orbitdb = new OrbitDB(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(result) -}) -``` - -`orbitdb` is now the [OrbitDB](#orbitdb) instance we can use to interact with the databases. - -This will tell `orbit-db` to use the [Javascript implementation](https://github.com/ipfs/js-ipfs) of IPFS. Choose this options if you're using `orbitd-db` to develop **browser** applications. - -### Using with a running IPFS daemon -Alternatively, you can use [ipfs-api](https://npmjs.org/package/ipfs-api) to use `orbit-db` with a locally running IPFS daemon: - -``` -npm install orbit-db ipfs-api -``` - -```javascript -const IpfsApi = require('ipfs-api') -const OrbitDB = require('orbit-db') - -const ipfs = IpfsApi('localhost', '5001') -const orbitdb = new OrbitDB(ipfs) -const db = await orbitdb.log('hello') -... -``` - -`orbitdb` is now the [OrbitDB](#orbitdb) instance we can use to interact with the databases. - -Choose this options if you're using `orbitd-db` to develop **backend** or **desktop** applications, eg. with [Electron](https://electron.atom.io). - - -## API - -- [OrbitDB](#orbitdb) - - [constructor(ipfs, [directory], [options])](#constructoripfs-directory-options) - - **Public Methods** - - [keyvalue(name|address)](#keyvaluenameaddress) - - [put(key, value)](#putkey-value) - - [set(key, value)](#setkey-value) - - [get(key)](#getkey) - - [log(name|address)](#lognameaddress) - - [add(event)](#addevent) - - [get(hash)](#gethash) - - [iterator([options])](#iteratoroptions) - - [feed(name|address)](#feednameaddress) - - [add(data)](#adddata) - - [get(hash)](#gethash-1) - - [remove(hash)](#removehash) - - [iterator([options])](#iteratoroptions) - - [docs(name|address, options)](#docsnameaddress-options) - - [put(doc)](#putdoc) - - [get(hash)](#getkey-1) - - [query(mapper)](#querymapper) - - [del(key)](#delkey) - - [counter(name|address)](#counternameaddress) - - [value](#value) - - [inc([value])](#incvalue) - - [create(name|address, type, [options])]() - - [stop()](#stop) - - **Static Properties** - - [databaseTypes](#databasetypes) - - **Static Methods** - - [isValidType(type)](#isvalidtypetype) - - [addDatabaseType(type, store)](#adddatabasetypetype-store) - - [getDatabaseTypes()](#getdatabasetypes) - - [isValidAddress(address)](#isvalidaddressaddress) - - [parseAddress(address)](#parseaddressaddress) -- [Store](#store) - - [load()](#load) - - [close()](#close) - - [drop()](#drop) - - [events](#events) - - [key](#key) - - [type](#type) - -## OrbitDB - ### constructor(ipfs, [directory], [options]) - ```javascript -const IPFS = require('ipfs') -const OrbitDB = require('orbit-db') - -const ipfs = new IPFS() -ipfs.on('ready', () => { - const orbitdb = new OrbitDB(ipfs) -}) +const orbitdb = new OrbitDB(ipfs) ``` +Creates and returns an instance of OrbitDB. Use the optional `directory` argument to specify a path to be used for the database files (Default: `'./orbitdb'`). In addition, you can use the optional `options` argument for further configuration. It is an object with any of these properties: + +- `peerId` (string): By default it uses the base58 string of the ipfs peer id. + +- `keystore` (Keystore Instance) : By default creates an instance of [Keystore](https://github.com/orbitdb/orbit-db-keystore). A custom keystore instance can be used, see [this](https://github.com/orbitdb/orbit-db/blob/master/test/utils/custom-test-keystore.js) for an example. After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a [database instance](#store). See the [Store](#store) section for details of common methods and properties. @@ -140,8 +18,52 @@ After creating an `OrbitDB` instance , you can access the different data stores. const db = await orbitdb.keyvalue('profile') ``` -### **Public Methods** -### keyvalue(name|address) +- **Public OrbitDB Instance Methods** + - [orbitdb.keyvalue(name|address)](#keyvaluenameaddress) + - [kv.put(key, value)](#putkey-value) + - [kv.set(key, value)](#setkey-value) + - [kv.get(key)](#getkey) + - [orbitdb.log(name|address)](#lognameaddress) + - [log.add(event)](#addevent) + - [log.get(hash)](#gethash) + - [log.iterator([options])](#iteratoroptions) + - [orbitdb.feed(name|address)](#feednameaddress) + - [feed.add(data)](#adddata) + - [feed.get(hash)](#gethash-1) + - [feed.remove(hash)](#removehash) + - [feed.iterator([options])](#iteratoroptions) + - [orbitdb.docs(name|address, options)](#docsnameaddress-options) + - [docs.put(doc)](#putdoc) + - [docs.get(hash)](#getkey-1) + - [docs.query(mapper)](#querymapper) + - [del(key)](#delkey) + - [orbitdb.counter(name|address)](#counternameaddress) + - [counter.value](#value) + - [counter.inc([value])](#incvalue) + - [orbitdb.create(name|address, type, [options])]() + - [orbitdb.open(name|address, [options])]() + - [orbitdb.stop()](#stop) + - [orbitdb.disconnect()]() +- **Static Properties** + - [OrbitDB.databaseTypes](#databasetypes) +- **Static Methods** + - [OrbitDB.isValidType(type)](#isvalidtypetype) + - [OrbitDB.addDatabaseType(type, store)](#adddatabasetypetype-store) + - [OrbitDB.getDatabaseTypes()](#getdatabasetypes) + - [OrbitDB.isValidAddress(address)](#isvalidaddressaddress) + - [OrbitDB.parseAddress(address)](#parseaddressaddress) + +- [Store API](#store) + - [store.load()](#load) + - [store.close()](#close) + - [store.drop()](#drop) + - [store.events](#events) + - [store.key](#key) + - [store.type](#type) + + +## Public Instance Methods +### orbitdb.keyvalue(name|address) Module: [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) @@ -171,7 +93,7 @@ const db = await orbitdb.keyvalue(anotherkvdb.address) // { name: 'Friend' } ``` -### log(name|address) +### orbitdb.log(name|address) Module: [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) @@ -220,7 +142,7 @@ const all = db.iterator({ limit: -1 }) // [{ name: 'User1' }] ``` -### feed(name|address) +### orbitdb.feed(name|address) Module: [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) @@ -274,7 +196,7 @@ const all = db.iterator({ limit: -1 }) // [{ name: 'User1' }] ``` -### docs(name|address, options) +### orbitdb.docs(name|address, options) Module: [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) @@ -315,7 +237,7 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } const hash = await db.del('shamb0t') ``` -### counter(name|address) +### orbitdb.counter(name|address) Module: [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) @@ -342,38 +264,38 @@ const counter = await orbitdb.counter(anothercounterdb.address) counter.value // 8 ``` -### stop() +### orbitdb.stop() Stop OrbitDB, close databases and disconnect the databases from the network. ```javascript orbitdb.stop() ``` -### **Static Properties** -### databaseTypes +## Static Properties +### OrbitDB.databaseTypes Returns supported database types (i.e. store types) as an Array of strings ```js OrbitDB.databaseTypes // [ 'counter', 'eventlog', 'feed', 'docstore', 'keyvalue'] ``` -### **Static Methods** +## Static Methods -### isValidType(type) +### OrbitDB.isValidType(type) Returns `true` if the provided string is a supported database type ```js OrbitDB.isValidType('docstore') // true ``` -### addDatabaseType(type, store) +### OrbitDB.addDatabaseType(type, store) Adds a custom database type & store to OrbitDB ```js const CustomStore = require('./CustomStore') OrbitDB.addDatabaseType(CustomStore.type, CustomStore) ``` -### getDatabaseTypes() +### OrbitDB.getDatabaseTypes() Returns an object mapping database types to Store Classes ```js OrbitDB.getDatabaseTypes() @@ -383,13 +305,13 @@ OrbitDB.getDatabaseTypes() // docstore: [Function: DocumentStore], // keyvalue: [Function: KeyValueStore] } ``` -### isValidAddress(address) +### OrbitDB.isValidAddress(address) Returns `true` if the provided string is a valid orbitdb address ```js OrbitDB.isValidAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') // true ``` -### parseAddress(address) +### OrbitDB.parseAddress(address) Returns an instance of OrbitDBAddress if the provided string is a valid orbitdb address ```js OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') diff --git a/GUIDE.md b/GUIDE.md index 81081b9..2ee017f 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -1,6 +1,6 @@ # Getting Started with OrbitDB -This guide will get you familiar using OrbitDB in your JavaScript application. OrbitDB and IPFS both work in Node.js applications as well as in browser applications. +This guide will get you familiar with using OrbitDB in your JavaScript application. OrbitDB and IPFS both work in Node.js applications as well as in browser applications. (Windows is not supported yet though) This guide is still being worked on and we would love to get [feedback and suggestions](https://github.com/orbitdb/orbit-db/issues) on how to improve it! @@ -26,7 +26,7 @@ OrbitDB is a peer-to-peer database meaning that each peer has its own instance o This means that each application contains the full database that they're using. This in turn changes the data modeling as compared to client-server model where there's usually one big database for all entries: in OrbitDB, the data should be stored, "partitioned" or "sharded" based on the access rights for that data. For example, in a twitter-like application, tweets would not be saved in a global "tweets" database to which millions of users write concurrently, but rather, ***each user would have their own database*** for their tweets. To follow a user, a peer would subscribe to a user's feed, ie. replicate their feed database. -OrbitDB supports multiple data models (see more details below) and as such the developer has a variety ways to structure data. Combined with the peer-to-peer paradigm, the data modeling is important factor to build scalable decentralized applications. +OrbitDB supports multiple data models (see more details below) and as such the developer has a variety of ways to structure data. Combined with the peer-to-peer paradigm, the data modeling is important factor to build scalable decentralized applications. This may not be intuitive or you might not be sure what the best approach would be and we'd be happy to help you decide on your data modeling and application needs, [feel free to reach out](https://github.com/orbitdb/orbit-db/issues)! @@ -47,13 +47,13 @@ const IPFS = require('ipfs') const OrbitDB = require('orbit-db') // OrbitDB uses Pubsub which is an experimental feature -// and need to be turned on manually. -// Note that these options need to be passed to IPFS in +// and need to be turned on manually. +// Note that these options need to be passed to IPFS in // all examples in this document even if not specfied so. const ipfsOptions = { EXPERIMENTAL: { pubsub: true - }, + } } // Create IPFS instance @@ -69,7 +69,7 @@ ipfs.on('ready', () => { ## Create a database -First, choose the data model you want to use. The available data models are: +First, choose the data model you want to use. The available data models are: - [Key-Value](https://github.com/orbitdb/orbit-db/blob/master/API.md##keyvaluenameaddress) - [Log](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress) (append-only log) - [Feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress) (same as log database but entries can be removed) @@ -116,7 +116,7 @@ ipfs.on('ready', async () => { #### Manifest -The second part of the address, the IPFS multihash `Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC`, is the manifest of a database. It's an IPFS object that contains information about the database. +The second part of the address, the IPFS multihash `Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC`, is the manifest of a database. It's an IPFS object that contains information about the database. The database manifest can be fetched from IPFS and it looks like this: @@ -136,8 +136,8 @@ Each entry in a database is signed by who created that entry. The signing key, t ``` const key = db.key console.log(key) -// > ``` @@ -175,9 +175,9 @@ ipfs.on('ready', async () => { }) ``` -To give write access to another peer, you'll need to get their public key with some means. They'll need to give you the output of their OrbitDB instance's key: `orbitdb.key.getPublic('hex')`. +To give write access to another peer, you'll need to get their public key with some means. They'll need to give you the output of their OrbitDB instance's key: `orbitdb.key.getPublic('hex')`. -The keys look like this: +The keys look like this: `042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839` Give access to another peer to write to the database: @@ -207,7 +207,7 @@ ipfs.on('ready', async () => { #### Public databases -The access control mechanism also support "public" databases to which anyone can write to. +The access control mechanism also support "public" databases to which anyone can write to. This can be done by adding a `*` to the write access array: ```javascript @@ -247,7 +247,7 @@ For adding entries to other databases, see: - [docs.put()](https://github.com/orbitdb/orbit-db/blob/master/API.md#putdoc) - [counter.inc()](https://github.com/orbitdb/orbit-db/blob/master/API.md#incvalue) -**Parallelism** +**Parallelism** We currently don't support parallel updates. Updates to a database need to be executed in a sequential manner. The write throughput is several hundreds or thousands of writes per second (depending on your platform and hardware, YMMV), so this shouldn't slow down your app too much. If it does, [lets us know](https://github.com/orbitdb/orbit-db/issues)! diff --git a/README.md b/README.md index 2a95449..f304fae 100644 --- a/README.md +++ b/README.md @@ -10,30 +10,31 @@ 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. -Data in OrbitDB can be stored in a +OrbitDB provides various types of databases for different data models and use cases: -- **[Key-Value Store](https://github.com/orbitdb/orbit-db/blob/master/API.md#keyvaluenameaddress)** -- **[Log Database](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress)** (append-only log) -- **[Feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress)** (same as log database but entries can be removed) -- **[Document Store](https://github.com/orbitdb/orbit-db/blob/master/API.md#docsnameaddress-options)** (store indexed JSON documents) -- **[Counters](https://github.com/orbitdb/orbit-db/blob/master/API.md#counternameaddress)** +- [log](#lognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. +- [feed](#feednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". +- [keyvalue](#keyvaluenameaddress) is a key-value database just like your favourite key-value database. +- [docs](#docsnameaddress-options) is a document database to which documents can be stored and indexed by a specified key. Useful for example building search indices or version controlling documents and data. +- [counter](#counternameaddress) for counting. Useful for example counting events separate from log/feed data. -This is the Javascript implementation and it works both in **Node.js** and **Browsers**. +#### Project status & support +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.0.0. 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.* + +### Getting Started To get started, try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[Getting Started Guide](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** or check **[Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/)**, **[Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/)** or **[P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! -

- - -

- ## Table of Contents - [Usage](#usage) + - [CLI](#cli) + - [Module with IPFS Instance]() + - [Module with IPFS Daemon]() - [API](#api) - [Examples](#examples) +- [Packages](#packages) - [Development](#development) -- [Background](#background) - [Contributing](#contributing) - [License](#license) @@ -41,7 +42,7 @@ To get started, try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli) Read the **[GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** guide for a more in-depth tutorial and to understand how OrbitDB works. -OrbitDB currently supports Linux and OS X, Windows is not supported yet. +*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/haadcode/orbit-db-eventstore#usage), [feed](https://github.com/haadcode/orbit-db-feedstore#usage), [docstore](https://github.com/shamb0t/orbit-db-docstore#usage) and [counter](https://github.com/haadcode/orbit-db-counterstore#usage).* ### CLI @@ -53,7 +54,9 @@ It can be installed from Npm with: npm install orbit-db-cli -g ``` -### As a library +### Module with IPFS Instance + +If you're using `orbitd-db` to develop **browser** applications, use it as a module with the javascript instance of IPFS Install dependencies: @@ -61,20 +64,18 @@ Install dependencies: npm install orbit-db ipfs ``` -Use it as a module: - ```javascript const IPFS = require('ipfs') const OrbitDB = require('orbit-db') // OrbitDB uses Pubsub which is an experimental feature // and need to be turned on manually. -// Note that these options need to be passed to IPFS in +// Note that these options need to be passed to IPFS in // all examples even if not specfied so. const ipfsOptions = { EXPERIMENTAL: { pubsub: true - }, + } } // Create IPFS instance @@ -82,33 +83,127 @@ const ipfs = new IPFS(ipfsOptions) ipfs.on('error', (e) => console.error(e)) ipfs.on('ready', async () => { - // Create a database const orbitdb = new OrbitDB(ipfs) - const db = await orbitdb.log('database name') - // Add an entry to the database - const hash = await db.add('hello world') - // Get last 5 entries - const latest = db.iterator({ limit: 5 }).collect() - console.log(JSON.stringify(latest, null, 2)) + + // 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 more details, see examples for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/haadcode/orbit-db-eventstore#usage), [feed](https://github.com/haadcode/orbit-db-feedstore#usage), [docstore](https://github.com/shamb0t/orbit-db-docstore#usage) and [counter](https://github.com/haadcode/orbit-db-counterstore#usage).* +### 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). -*The minimum required version of Node.js is now 8.0.0. 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.* +Install dependencies: + +``` +npm install orbit-db ipfs-api +``` + +```javascript +const IpfsApi = require('ipfs-api') +const OrbitDB = require('orbit-db') + +const ipfs = IpfsApi('localhost', '5001') +const orbitdb = new OrbitDB(ipfs) +const db = await orbitdb.log('hello') +... +``` ## API -See [API documentation](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbit-db-api-documentation) for the full documentation. +See [API documentation](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation. -- [Getting Started](https://github.com/orbitdb/orbit-db/blob/master/API.md#getting-started) -- [OrbitDB](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdb) - - [keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#keyvaluenameaddress) - - [log](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress) - - [feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress) - - [docstore](https://github.com/orbitdb/orbit-db/blob/master/API.md#docsnameaddress-options) - - [counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#counternameaddress) - - [common](https://github.com/orbitdb/orbit-db/blob/master/API.md#store) +### constructor(ipfs, [directory], [options]) +```javascript +OBconst orbitdb = new OrbitDB(ipfs) +``` +Creates and returns an instance of OrbitDB. Use the optional `directory` argument to specify a path to be used for the database files (Default: `'./orbitdb'`). In addition, you can use the optional `options` argument for further configuration. It is an object with any of these properties: + +- `peerId` (string): By default it uses the base58 string of the ipfs peer id. + +- `keystore` (Keystore Instance) : By default creates an instance of [Keystore](https://github.com/orbitdb/orbit-db-keystore). A custom keystore instance can be used, see [this](https://github.com/orbitdb/orbit-db/blob/master/test/utils/custom-test-keystore.js) for an example. + +- **Public OrbitDB Instance Methods** + - [orbitdb.keyvalue(name|address)](#keyvaluenameaddress) + - [kv.put(key, value)](#putkey-value) + - [kv.set(key, value)](#setkey-value) + - [kv.get(key)](#getkey) + - [orbitdb.log(name|address)](#lognameaddress) + - [log.add(event)](#addevent) + - [log.get(hash)](#gethash) + - [log.iterator([options])](#iteratoroptions) + - [orbitdb.feed(name|address)](#feednameaddress) + - [feed.add(data)](#adddata) + - [feed.get(hash)](#gethash-1) + - [feed.remove(hash)](#removehash) + - [feed.iterator([options])](#iteratoroptions) + - [orbitdb.docs(name|address, options)](#docsnameaddress-options) + - [docs.put(doc)](#putdoc) + - [docs.get(hash)](#getkey-1) + - [docs.query(mapper)](#querymapper) + - [del(key)](#delkey) + - [orbitdb.counter(name|address)](#counternameaddress) + - [counter.value](#value) + - [counter.inc([value])](#incvalue) + - [orbitdb.create(name|address, type, [options])]() + - [orbitdb.open(name|address, [options])]() + - [orbitdb.stop()](#stop) + - [orbitdb.disconnect()]() +- **Static Properties** + - [OrbitDB.databaseTypes](#databasetypes) +- **Static Methods** + - [OrbitDB.isValidType(type)](#isvalidtypetype) + - [OrbitDB.addDatabaseType(type, store)](#adddatabasetypetype-store) + - [OrbitDB.getDatabaseTypes()](#getdatabasetypes) + - [OrbitDB.isValidAddress(address)](#isvalidaddressaddress) + - [OrbitDB.parseAddress(address)](#parseaddressaddress) + +- [Store API](#store) + - [load()](#load) + - [close()](#close) + - [drop()](#drop) + - [events](#events) + - [key](#key) + - [type](#type) + +### Custom Store Types + +You can add custom store types to OrbitDB: + +```javascript +// define custom store type +class CustomStore extends DocumentStore { + constructor (ipfs, id, dbname, options) { + super(ipfs, id, dbname, options) + this._type = CustomStore.type + } + + static get type () { + return 'custom' + } +} + +// add custom type to orbitdb +OrbitDB.addDatabaseType(CustomStore.type, CustomStore) + +// instantiate custom store +let orbitdb = new OrbitDB(ipfs, dbPath) +let store = orbitdb.create(name, CustomStore.type) +``` ## Examples @@ -127,11 +222,11 @@ npm install --global babel-cli npm install --global webpack ``` -Some dependencies depend on native addon modules, so you'll also need to meet [node-gyp's](https://github.com/nodejs/node-gyp#installation) installation prerequisites. Therefore, Linux users may need to +Some dependencies depend on native addon modules, so you'll also need to meet [node-gyp's](https://github.com/nodejs/node-gyp#installation) installation prerequisites. Therefore, Linux users may need to ``` make clean && make ``` -to redo the local package-lock.json with working native dependencies. +to redo the local package-lock.json with working native dependencies. ### Browser example @@ -170,30 +265,25 @@ node examples/eventlog.js More examples at [examples](https://github.com/orbitdb/orbit-db/tree/master/examples). -### Custom Store Types +## Packages -You can add custom store types to OrbitDB: +OrbitDB uses the following modules: -```javascript -// define custom store type -class CustomStore extends DocumentStore { - constructor (ipfs, id, dbname, options) { - super(ipfs, id, dbname, options) - this._type = CustomStore.type - } +- [ipfs](https://github.com/ipfs/js-ipfs) +- [ipfs-log](https://github.com/orbitdb/ipfs-log) +- [ipfs-pubub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) +- [crdts](https://github.com/orbitdb/crdts) +- [orbit-db-cache](https://github.com/orbitdb/orbit-db-cache) +- [orbit-db-store](https://github.com/orbitdb/orbit-db-store) +- [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) +- [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) +- [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) +- [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) +- [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) +- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub) +- [orbit-db-keystore](https://github.com/orbitdb/orbit-db-keystore) - static get type () { - return 'custom' - } -} - -// add custom type to orbitdb -OrbitDB.addDatabaseType(CustomStore.type, CustomStore) - -// instantiate custom store -let orbitdb = new OrbitDB(ipfs, dbPath) -let store = orbitdb.create(name, CustomStore.type) -``` +To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/. ## Development @@ -222,26 +312,6 @@ To enable OrbitDB's logging output, set a global ENV variable called `LOG` to `d LOG=debug node ``` -## Background - -Uses the following modules: - -- [ipfs-log](https://github.com/orbitdb/ipfs-log) -- [crdts](https://github.com/orbitdb/crdts) -- [orbit-db-cache](https://github.com/orbitdb/orbit-db-cache) -- [orbit-db-store](https://github.com/orbitdb/orbit-db-store) -- [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) -- [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) -- [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) -- [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) -- [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) -- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub) -- [orbit-db-keystore](https://github.com/orbitdb/orbit-db-keystore) -- [ipfs](https://github.com/ipfs/js-ipfs) -- [ipfs-pubub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) - -To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/. - ## Contributing We would be happy to accept PRs! If you want to work on something, it'd be good to talk beforehand to make sure nobody else is working on it. You can reach us on IRC [#orbitdb](http://webchat.freenode.net/?channels=%23orbitdb) on Freenode, or in the comments of the [issues section](https://github.com/orbitdb/orbit-db/issues). From 680c0f35a25cd855061529de072cbfde9c479b08 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:33:28 -0400 Subject: [PATCH 04/31] docs: update links --- API.md | 21 ++++++++------- GUIDE.md | 10 ++++---- README.md | 76 +++++++++++++++++++++++++++---------------------------- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/API.md b/API.md index 5b12ca1..076c355 100644 --- a/API.md +++ b/API.md @@ -19,31 +19,31 @@ const db = await orbitdb.keyvalue('profile') ``` - **Public OrbitDB Instance Methods** - - [orbitdb.keyvalue(name|address)](#keyvaluenameaddress) + - [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress) - [kv.put(key, value)](#putkey-value) - [kv.set(key, value)](#setkey-value) - [kv.get(key)](#getkey) - - [orbitdb.log(name|address)](#lognameaddress) + - [orbitdb.log(name|address)](#orbitdblognameaddress) - [log.add(event)](#addevent) - [log.get(hash)](#gethash) - [log.iterator([options])](#iteratoroptions) - - [orbitdb.feed(name|address)](#feednameaddress) + - [orbitdb.feed(name|address)](#orbitdbfeednameaddress) - [feed.add(data)](#adddata) - [feed.get(hash)](#gethash-1) - [feed.remove(hash)](#removehash) - - [feed.iterator([options])](#iteratoroptions) - - [orbitdb.docs(name|address, options)](#docsnameaddress-options) + - [feed.iterator([options])](#iteratoroptions-1) + - [orbitdb.docs(name|address, options)](#orbitdbdocsnameaddress-options) - [docs.put(doc)](#putdoc) - [docs.get(hash)](#getkey-1) - [docs.query(mapper)](#querymapper) - [del(key)](#delkey) - - [orbitdb.counter(name|address)](#counternameaddress) + - [orbitdb.counter(name|address)](#orbitdbcounternameaddress) - [counter.value](#value) - [counter.inc([value])](#incvalue) - [orbitdb.create(name|address, type, [options])]() - [orbitdb.open(name|address, [options])]() - - [orbitdb.stop()](#stop) - - [orbitdb.disconnect()]() + - [orbitdb.stop()](#orbitdbstop) + - [orbitdb.disconnect()](orbitdbdisconnect) - **Static Properties** - [OrbitDB.databaseTypes](#databasetypes) - **Static Methods** @@ -61,7 +61,6 @@ const db = await orbitdb.keyvalue('profile') - [store.key](#key) - [store.type](#type) - ## Public Instance Methods ### orbitdb.keyvalue(name|address) @@ -264,6 +263,8 @@ const counter = await orbitdb.counter(anothercounterdb.address) counter.value // 8 ``` +### orbitdb.create(name|address, type, [options]) +### orbitdb.open(name|address, [options]) ### orbitdb.stop() Stop OrbitDB, close databases and disconnect the databases from the network. @@ -271,6 +272,8 @@ const counter = await orbitdb.counter(anothercounterdb.address) ```javascript orbitdb.stop() ``` +### orbitdb.disconnect() + ## Static Properties ### OrbitDB.databaseTypes Returns supported database types (i.e. store types) as an Array of strings diff --git a/GUIDE.md b/GUIDE.md index 2ee017f..1d1b215 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -70,11 +70,11 @@ ipfs.on('ready', () => { ## Create a database First, choose the data model you want to use. The available data models are: -- [Key-Value](https://github.com/orbitdb/orbit-db/blob/master/API.md##keyvaluenameaddress) -- [Log](https://github.com/orbitdb/orbit-db/blob/master/API.md#lognameaddress) (append-only log) -- [Feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#feednameaddress) (same as log database but entries can be removed) -- [Documents](https://github.com/orbitdb/orbit-db/blob/master/API.md#docsnameaddress-options) (store indexed JSON documents) -- [Counters](https://github.com/orbitdb/orbit-db/blob/master/API.md#counternameaddress) +- [Key-Value](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) +- [Log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) (append-only log) +- [Feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) (same as log database but entries can be removed) +- [Documents](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) (store indexed JSON documents) +- [Counters](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) Then, create a database instance (we'll use Key-Value database in this example): diff --git a/README.md b/README.md index f304fae..1258819 100644 --- a/README.md +++ b/README.md @@ -12,16 +12,16 @@ OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses [IPFS] OrbitDB provides various types of databases for different data models and use cases: -- [log](#lognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. -- [feed](#feednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". -- [keyvalue](#keyvaluenameaddress) is a key-value database just like your favourite key-value database. -- [docs](#docsnameaddress-options) is a document database to which documents can be stored and indexed by a specified key. Useful for example building search indices or version controlling documents and data. -- [counter](#counternameaddress) for counting. Useful for example counting events separate from log/feed data. +- [log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. +- [feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". +- [keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) is a key-value database just like your favourite key-value database. +- [docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) is a document database to which documents can be stored and indexed by a specified key. Useful for example building search indices or version controlling documents and data. +- [counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) for counting. Useful for example counting events separate from log/feed data. #### Project status & support 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.0.0. 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.* -### Getting Started +#### Getting Started To get started, try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[Getting Started Guide](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** or check **[Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/)**, **[Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/)** or **[P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! @@ -29,8 +29,8 @@ To get started, try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli) - [Usage](#usage) - [CLI](#cli) - - [Module with IPFS Instance]() - - [Module with IPFS Daemon]() + - [Module with IPFS Instance](#module-with-ipfs-instance) + - [Module with IPFS Daemon](#module-with-ipfs-daemon) - [API](#api) - [Examples](#examples) - [Packages](#packages) @@ -138,39 +138,39 @@ Creates and returns an instance of OrbitDB. Use the optional `directory` argumen - `keystore` (Keystore Instance) : By default creates an instance of [Keystore](https://github.com/orbitdb/orbit-db-keystore). A custom keystore instance can be used, see [this](https://github.com/orbitdb/orbit-db/blob/master/test/utils/custom-test-keystore.js) for an example. - **Public OrbitDB Instance Methods** - - [orbitdb.keyvalue(name|address)](#keyvaluenameaddress) - - [kv.put(key, value)](#putkey-value) - - [kv.set(key, value)](#setkey-value) - - [kv.get(key)](#getkey) - - [orbitdb.log(name|address)](#lognameaddress) - - [log.add(event)](#addevent) - - [log.get(hash)](#gethash) - - [log.iterator([options])](#iteratoroptions) - - [orbitdb.feed(name|address)](#feednameaddress) - - [feed.add(data)](#adddata) - - [feed.get(hash)](#gethash-1) - - [feed.remove(hash)](#removehash) - - [feed.iterator([options])](#iteratoroptions) - - [orbitdb.docs(name|address, options)](#docsnameaddress-options) - - [docs.put(doc)](#putdoc) - - [docs.get(hash)](#getkey-1) - - [docs.query(mapper)](#querymapper) - - [del(key)](#delkey) - - [orbitdb.counter(name|address)](#counternameaddress) - - [counter.value](#value) - - [counter.inc([value])](#incvalue) + - [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) + - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) + - [kv.set(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#setkey-value) + - [kv.get(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getKey) + - [orbitdb.log(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) + - [log.add(event)](https://github.com/orbitdb/orbit-db/blob/master/API.md#addevent) + - [log.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash) + - [log.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions) + - [orbitdb.feed(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) + - [feed.add(data)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddata) + - [feed.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash-1) + - [feed.remove(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#removehash) + - [feed.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1) + - [orbitdb.docs(name|address, options)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) + - [docs.put(doc)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putdoc) + - [docs.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getkey-1) + - [docs.query(mapper)](https://github.com/orbitdb/orbit-db/blob/master/API.md#querymapper) + - [del(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#delkey) + - [orbitdb.counter(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) + - [counter.value](https://github.com/orbitdb/orbit-db/blob/master/API.md#value) + - [counter.inc([value])](https://github.com/orbitdb/orbit-db/blob/master/API.md#incvalue) - [orbitdb.create(name|address, type, [options])]() - [orbitdb.open(name|address, [options])]() - - [orbitdb.stop()](#stop) - - [orbitdb.disconnect()]() + - [orbitdb.stop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbstop) + - [orbitdb.disconnect()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdisconnect) - **Static Properties** - - [OrbitDB.databaseTypes](#databasetypes) + - [OrbitDB.databaseTypes](https://github.com/orbitdb/orbit-db/blob/master/API.md#databasetypes) - **Static Methods** - - [OrbitDB.isValidType(type)](#isvalidtypetype) - - [OrbitDB.addDatabaseType(type, store)](#adddatabasetypetype-store) - - [OrbitDB.getDatabaseTypes()](#getdatabasetypes) - - [OrbitDB.isValidAddress(address)](#isvalidaddressaddress) - - [OrbitDB.parseAddress(address)](#parseaddressaddress) + - [OrbitDB.isValidType(type)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidtypetype) + - [OrbitDB.addDatabaseType(type, store)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddatabasetypetype-store) + - [OrbitDB.getDatabaseTypes()](https://github.com/orbitdb/orbit-db/blob/master/API.md#getdatabasetypes) + - [OrbitDB.isValidAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidaddressaddress) + - [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) - [Store API](#store) - [load()](#load) @@ -302,7 +302,7 @@ npm run build node benchmarks/benchmark-add.js ``` -See [benchmarks/]() for more benchmarks. +See [benchmarks/](https://github.com/orbitdb/orbit-db/tree/master/benchmarks) for more benchmarks. #### Logging From 4eed70b6100e15a987763ffa7d4ce7c973678ae8 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:37:21 -0400 Subject: [PATCH 05/31] docs: cleanup --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1258819..5ade189 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ OrbitDB provides various types of databases for different data models and use ca - [counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) for counting. Useful for example counting events separate from log/feed data. #### Project status & support -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.0.0. 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.* +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.0.0. 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. #### Getting Started @@ -129,7 +129,7 @@ See [API documentation](https://github.com/orbitdb/orbit-db/blob/master/API.md) ### constructor(ipfs, [directory], [options]) ```javascript -OBconst orbitdb = new OrbitDB(ipfs) +const orbitdb = new OrbitDB(ipfs) ``` Creates and returns an instance of OrbitDB. Use the optional `directory` argument to specify a path to be used for the database files (Default: `'./orbitdb'`). In addition, you can use the optional `options` argument for further configuration. It is an object with any of these properties: @@ -137,6 +137,8 @@ Creates and returns an instance of OrbitDB. Use the optional `directory` argumen - `keystore` (Keystore Instance) : By default creates an instance of [Keystore](https://github.com/orbitdb/orbit-db-keystore). A custom keystore instance can be used, see [this](https://github.com/orbitdb/orbit-db/blob/master/test/utils/custom-test-keystore.js) for an example. +After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a database instance. + - **Public OrbitDB Instance Methods** - [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) From 45f7e04f22b07e67027a81a55bdca27f2f2cbec5 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:51:36 -0400 Subject: [PATCH 06/31] docs(readme): update store info --- README.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 5ade189..1bda7d8 100644 --- a/README.md +++ b/README.md @@ -12,11 +12,13 @@ OrbitDB is a serverless, distributed, peer-to-peer database. OrbitDB uses [IPFS] OrbitDB provides various types of databases for different data models and use cases: -- [log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) is an append-only log with traversable history. Useful for *"latest N"* use cases or as a message queue. -- [feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) is a log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". -- [keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) is a key-value database just like your favourite key-value database. -- [docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) is a document database to which documents can be stored and indexed by a specified key. Useful for example building search indices or version controlling documents and data. -- [counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) for counting. Useful for example counting events separate from log/feed data. +- **[log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress)**: an immutable (append-only) log with traversable history. Useful for *"latest N"* use cases or as a message queue. +- **[feed](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress)**: a mutable log with traversable history. Entries can be added and removed. Useful for *"shopping cart" type of use cases, or for example as a feed of blog posts or "tweets". +- **[keyvalue](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress)**: a key-value database just like your favourite key-value database. +- **[docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options)**: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data. +- **[counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress)**: Useful for counting events separate from log/feed data. + +All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on top of [ipfs-log](https://github.com/orbitdb/ipfs-log), an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. #### Project status & support 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.0.0. 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. @@ -276,14 +278,16 @@ OrbitDB uses the following modules: - [ipfs-pubub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) - [crdts](https://github.com/orbitdb/crdts) - [orbit-db-cache](https://github.com/orbitdb/orbit-db-cache) +- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub) +- [orbit-db-keystore](https://github.com/orbitdb/orbit-db-keystore) + +##### OrbitDB Store Packages - [orbit-db-store](https://github.com/orbitdb/orbit-db-store) - [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) - [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) - [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) - [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) - [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) -- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub) -- [orbit-db-keystore](https://github.com/orbitdb/orbit-db-keystore) To understand a little bit about the architecture, check out a visualization of the data flow at https://github.com/haadcode/proto2 or a live demo: http://celebdil.benet.ai:8080/ipfs/Qmezm7g8mBpWyuPk6D84CNcfLKJwU6mpXuEN5GJZNkX3XK/. From e20b60ba3fabf9522f075158054f3e3eacf2bd9e Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:53:57 -0400 Subject: [PATCH 07/31] docs(readme): refractor --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 1bda7d8..a2c3abb 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,7 @@ All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on to 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.0.0. 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. #### Getting Started - -To get started, try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[Getting Started Guide](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** or check **[Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/)**, **[Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/)** or **[P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! +Try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[Getting Started Guide](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** or check **[Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/)**, **[Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/)** or **[P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! ## Table of Contents From 463fed966ba8caec8546223f3f38fd1e5fcd9161 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:56:14 -0400 Subject: [PATCH 08/31] docs(readme): update links --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a2c3abb..e39e38a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[ Read the **[GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** guide for a more in-depth tutorial and to understand how OrbitDB works. -*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/haadcode/orbit-db-eventstore#usage), [feed](https://github.com/haadcode/orbit-db-feedstore#usage), [docstore](https://github.com/shamb0t/orbit-db-docstore#usage) and [counter](https://github.com/haadcode/orbit-db-counterstore#usage).* +*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* ### CLI From 7ce81d49137a398db47e7abee7ac1cde8dd7b92c Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 15:57:27 -0400 Subject: [PATCH 09/31] docs(readme): refractor --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e39e38a..e61764b 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,6 @@ Try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[ Read the **[GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** guide for a more in-depth tutorial and to understand how OrbitDB works. -*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* - ### CLI For the CLI tool to manage orbit-db database, see **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**. @@ -140,6 +138,8 @@ Creates and returns an instance of OrbitDB. Use the optional `directory` argumen After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a database instance. +*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* + - **Public OrbitDB Instance Methods** - [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) From 7d7b70f0fd57df9e8c10767350b2aa471e2414da Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 16:14:55 -0400 Subject: [PATCH 10/31] docs: cleanup events --- API.md | 90 ++++++++++++++++++++++++++++--------------------------- README.md | 21 ++++++++----- 2 files changed, 60 insertions(+), 51 deletions(-) diff --git a/API.md b/API.md index 076c355..d7eb733 100644 --- a/API.md +++ b/API.md @@ -14,6 +14,8 @@ Creates and returns an instance of OrbitDB. Use the optional `directory` argumen After creating an `OrbitDB` instance , you can access the different data stores. Creating a database instance, eg. with `orbitdb.keyvalue(...)`, returns a *Promise* that resolves to a [database instance](#store). See the [Store](#store) section for details of common methods and properties. +*For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* + ```javascript const db = await orbitdb.keyvalue('profile') ``` @@ -57,9 +59,16 @@ const db = await orbitdb.keyvalue('profile') - [store.load()](#load) - [store.close()](#close) - [store.drop()](#drop) - - [store.events](#events) - [store.key](#key) - [store.type](#type) +- [Store Events](#storeevents) + - [replicated](#replicated) + - [replicate](#replicate) + - [replicate.progress](#replicateprogress) + - [load](#load) + - [load.progress](#loadprogess) + - [ready](#ready) + - [write](#write) ## Public Instance Methods ### orbitdb.keyvalue(name|address) @@ -386,65 +395,58 @@ The key can also be accessed from the [OrbitDB](#orbitdb) instance: `orbitdb.key The type of the database as a string. -#### events +### Store Events Each database in `orbit-db` contains an `events` ([EventEmitter](https://nodejs.org/api/events.html)) object that emits events that describe what's happening in the database. Events can be listened to with: ```javascript db.events.on(name, callback) ``` -- **`replicated`** - (address) +#### replicated +```javascript +db.events.on('replicated', (address) => ... ) +``` - Emitted when a the database was synced with another peer. This is usually a good place to re-query the database for updated results, eg. if a value of a key was changed or if there are new events in an event log. +Emitted when a the database was synced with another peer. This is usually a good place to re-query the database for updated results, eg. if a value of a key was changed or if there are new events in an event log. - ```javascript - db.events.on('replicated', (address) => ... ) - ``` +#### replicate +```javascript +db.events.on('replicate', (address) => ... ) +``` -- **`replicate`** - (address) +Emitted before replicating a part of the database with a peer. - Emitted before replicating a part of the database with a peer. +#### replicate.progress +```javascript +db.events.on('replicate.progress', (address, hash, entry, progress, have) => ... ) +``` - ```javascript - db.events.on('replicate', (address) => ... ) - ``` +Emitted while replicating a database. *address* is id of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is the current progress. *have* is a map of database pieces we have. -- **`replicate.progress`** - (address, hash, entry, progress, have) +#### load +```javascript +db.events.on('load', (dbname) => ... ) +``` - Emitted while replicating a database. *address* is id of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is the current progress. *have* is a map of database pieces we have. +Emitted before loading the database. - ```javascript - db.events.on('replicate.progress', (address, hash, entry, progress, have) => ... ) - ``` +#### load.progress +```javascript +db.events.on('load.progress', (address, hash, entry, progress, total) => ... ) +``` -- **`load`** - (dbname) +Emitted while loading the local database, once for each entry. *dbname* is the name of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is a sequential number starting from 0 upon calling `load()`. - Emitted before loading the database. +#### ready +```javascript +db.events.on('ready', (dbname) => ... ) +``` - ```javascript - db.events.on('load', (dbname) => ... ) - ``` +Emitted after fully loading the local database. -- **`load.progress`** - (address, hash, entry, progress, total) +#### write +```javascript +db.events.on('write', (dbname, hash, entry) => ... ) +``` - Emitted while loading the local database, once for each entry. *dbname* is the name of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is a sequential number starting from 0 upon calling `load()`. - - ```javascript - db.events.on('load.progress', (address, hash, entry, progress, total) => ... ) - ``` - -- **`ready`** - (dbname) - - Emitted after fully loading the local database. - - ```javascript - db.events.on('ready', (dbname) => ... ) - ``` - -- **`write`** - (dbname, hash, entry) - - Emitted after an entry was added locally to the database. *hash* is the IPFS hash of the latest state of the database. *entry* is the added database op. - - ```javascript - db.events.on('write', (dbname, hash, entry) => ... ) - ``` +Emitted after an entry was added locally to the database. *hash* is the IPFS hash of the latest state of the database. *entry* is the added database op. diff --git a/README.md b/README.md index e61764b..7c53839 100644 --- a/README.md +++ b/README.md @@ -175,13 +175,20 @@ After creating an `OrbitDB` instance , you can access the different data stores. - [OrbitDB.isValidAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidaddressaddress) - [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) -- [Store API](#store) - - [load()](#load) - - [close()](#close) - - [drop()](#drop) - - [events](#events) - - [key](#key) - - [type](#type) +- [Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store) + - [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#load) + - [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#close) + - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#drop) + - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#key) + - [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#type) +- [Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents) + - [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) + - [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) + - [replicate.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicateprogress) + - [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load) + - [load.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#loadprogress) + - [ready](https://github.com/orbitdb/orbit-db/blob/master/API.md#ready) + - [write](https://github.com/orbitdb/orbit-db/blob/master/API.md#write) ### Custom Store Types From 41d7e24e5bc5d04196b32a98c7adeef9ba49cd59 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 16:17:35 -0400 Subject: [PATCH 11/31] docs: fix event links --- API.md | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index d7eb733..f97a9c8 100644 --- a/API.md +++ b/API.md @@ -65,8 +65,8 @@ const db = await orbitdb.keyvalue('profile') - [replicated](#replicated) - [replicate](#replicate) - [replicate.progress](#replicateprogress) - - [load](#load) - - [load.progress](#loadprogess) + - [load](#load-1) + - [load.progress](#loadprogress) - [ready](#ready) - [write](#write) diff --git a/README.md b/README.md index 7c53839..6ddd3d1 100644 --- a/README.md +++ b/README.md @@ -185,7 +185,7 @@ After creating an `OrbitDB` instance , you can access the different data stores. - [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) - [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) - [replicate.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicateprogress) - - [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load) + - [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load-1) - [load.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#loadprogress) - [ready](https://github.com/orbitdb/orbit-db/blob/master/API.md#ready) - [write](https://github.com/orbitdb/orbit-db/blob/master/API.md#write) From a187f9ba6974b809363fff66e19f1508c62bf4b1 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 12 Jul 2018 16:23:08 -0400 Subject: [PATCH 12/31] docs: store cleanup --- API.md | 34 +++++++++++++++++----------------- README.md | 10 +++++----- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/API.md b/API.md index f97a9c8..9229ddd 100644 --- a/API.md +++ b/API.md @@ -56,11 +56,11 @@ const db = await orbitdb.keyvalue('profile') - [OrbitDB.parseAddress(address)](#parseaddressaddress) - [Store API](#store) - - [store.load()](#load) - - [store.close()](#close) - - [store.drop()](#drop) - - [store.key](#key) - - [store.type](#type) + - [store.load()](#storeload) + - [store.close()](#storeclose) + - [store.drop()](#storedrop) + - [store.key](#storekey) + - [store.type](#storetype) - [Store Events](#storeevents) - [replicated](#replicated) - [replicate](#replicate) @@ -336,7 +336,7 @@ OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/fi Every database (store) has the following methods available in addition to their specific methods. -#### load() +#### store.load() Load the locally persisted database state to memory. @@ -354,7 +354,7 @@ await db.load() /* database is now ready to be queried */ ``` -#### close() +#### store.close() Close the database. @@ -363,7 +363,7 @@ Async: await db.close() ``` -#### drop() +#### store.drop() Remove the database locally. This does not delete any data from peers. @@ -371,7 +371,7 @@ Remove the database locally. This does not delete any data from peers. await db.drop() ``` -#### key +#### store.key The [keypair](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#keys) used to access the database. @@ -391,7 +391,7 @@ console.log(db.key.getPublic('hex')) The key can also be accessed from the [OrbitDB](#orbitdb) instance: `orbitdb.key.getPublic('hex')`. -#### type +#### store.type The type of the database as a string. @@ -402,49 +402,49 @@ Each database in `orbit-db` contains an `events` ([EventEmitter](https://nodejs. db.events.on(name, callback) ``` -#### replicated +#### `replicated` ```javascript db.events.on('replicated', (address) => ... ) ``` Emitted when a the database was synced with another peer. This is usually a good place to re-query the database for updated results, eg. if a value of a key was changed or if there are new events in an event log. -#### replicate +#### `replicate` ```javascript db.events.on('replicate', (address) => ... ) ``` Emitted before replicating a part of the database with a peer. -#### replicate.progress +#### `replicate.progress` ```javascript db.events.on('replicate.progress', (address, hash, entry, progress, have) => ... ) ``` Emitted while replicating a database. *address* is id of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is the current progress. *have* is a map of database pieces we have. -#### load +#### `load` ```javascript db.events.on('load', (dbname) => ... ) ``` Emitted before loading the database. -#### load.progress +#### `load.progress` ```javascript db.events.on('load.progress', (address, hash, entry, progress, total) => ... ) ``` Emitted while loading the local database, once for each entry. *dbname* is the name of the database that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the database operation entry. *progress* is a sequential number starting from 0 upon calling `load()`. -#### ready +#### `ready` ```javascript db.events.on('ready', (dbname) => ... ) ``` Emitted after fully loading the local database. -#### write +#### `write` ```javascript db.events.on('write', (dbname, hash, entry) => ... ) ``` diff --git a/README.md b/README.md index 6ddd3d1..2c57f4a 100644 --- a/README.md +++ b/README.md @@ -176,11 +176,11 @@ After creating an `OrbitDB` instance , you can access the different data stores. - [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) - [Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store) - - [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#load) - - [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#close) - - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#drop) - - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#key) - - [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#type) + - [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeload) + - [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeclose) + - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) + - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) + - [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#storetype) - [Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents) - [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) - [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) From 73013936f30f6888e3dc3183d52a5670a22745af Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 14:39:00 -0400 Subject: [PATCH 13/31] docs: add api description for orbitdb.create --- API.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index 9229ddd..1c96cbf 100644 --- a/API.md +++ b/API.md @@ -272,7 +272,22 @@ const counter = await orbitdb.counter(anothercounterdb.address) counter.value // 8 ``` -### orbitdb.create(name|address, type, [options]) +### orbitdb.create(name, type, [options]) +Creates and opens an OrbitDB database. Returns a `Promise` that resolves to [a database instance](#store). `name` (string) should be the database name, not an OrbitDB address (i.e. `user.posts`). `type` is a supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). `options` is an object with any of the following properties: +- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). +- `write` (array): An array of hex encoded public keys which are used to set write acces to the database. `["*"]` can be passed in to give write access to everyone. See the [GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md) guide for more info. (Default: uses the OrbitDB instance key `orbitdb.key`, which would give write access only to yourself) +- `overwrite` (boolean): Overwrite an existing database (Default: `false`) +```javascript +const db = await orbitdb.create('user.posts', 'eventlog', { + write: [ + // Give access to ourselves + orbitdb.key.getPublic('hex'), + // Give access to the second peer + '042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839' + ] +}) +// db created & opened +``` ### orbitdb.open(name|address, [options]) ### orbitdb.stop() From ca78ae7a55ff55c8b0f17d95b27360a9c66ee19b Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 14:47:37 -0400 Subject: [PATCH 14/31] docs: styling --- API.md | 99 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 51 insertions(+), 48 deletions(-) diff --git a/API.md b/API.md index 1c96cbf..8617535 100644 --- a/API.md +++ b/API.md @@ -20,55 +20,58 @@ After creating an `OrbitDB` instance , you can access the different data stores. const db = await orbitdb.keyvalue('profile') ``` -- **Public OrbitDB Instance Methods** - - [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress) - - [kv.put(key, value)](#putkey-value) - - [kv.set(key, value)](#setkey-value) - - [kv.get(key)](#getkey) - - [orbitdb.log(name|address)](#orbitdblognameaddress) - - [log.add(event)](#addevent) - - [log.get(hash)](#gethash) - - [log.iterator([options])](#iteratoroptions) - - [orbitdb.feed(name|address)](#orbitdbfeednameaddress) - - [feed.add(data)](#adddata) - - [feed.get(hash)](#gethash-1) - - [feed.remove(hash)](#removehash) - - [feed.iterator([options])](#iteratoroptions-1) - - [orbitdb.docs(name|address, options)](#orbitdbdocsnameaddress-options) - - [docs.put(doc)](#putdoc) - - [docs.get(hash)](#getkey-1) - - [docs.query(mapper)](#querymapper) - - [del(key)](#delkey) - - [orbitdb.counter(name|address)](#orbitdbcounternameaddress) - - [counter.value](#value) - - [counter.inc([value])](#incvalue) - - [orbitdb.create(name|address, type, [options])]() - - [orbitdb.open(name|address, [options])]() - - [orbitdb.stop()](#orbitdbstop) - - [orbitdb.disconnect()](orbitdbdisconnect) -- **Static Properties** - - [OrbitDB.databaseTypes](#databasetypes) -- **Static Methods** - - [OrbitDB.isValidType(type)](#isvalidtypetype) - - [OrbitDB.addDatabaseType(type, store)](#adddatabasetypetype-store) - - [OrbitDB.getDatabaseTypes()](#getdatabasetypes) - - [OrbitDB.isValidAddress(address)](#isvalidaddressaddress) - - [OrbitDB.parseAddress(address)](#parseaddressaddress) +**Public OrbitDB Instance Methods** +- [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress) + - [kv.put(key, value)](#putkey-value) + - [kv.set(key, value)](#setkey-value) + - [kv.get(key)](#getkey) +- [orbitdb.log(name|address)](#orbitdblognameaddress) + - [log.add(event)](#addevent) + - [log.get(hash)](#gethash) + - [log.iterator([options])](#iteratoroptions) +- [orbitdb.feed(name|address)](#orbitdbfeednameaddress) + - [feed.add(data)](#adddata) + - [feed.get(hash)](#gethash-1) + - [feed.remove(hash)](#removehash) + - [feed.iterator([options])](#iteratoroptions-1) +- [orbitdb.docs(name|address, options)](#orbitdbdocsnameaddress-options) + - [docs.put(doc)](#putdoc) + - [docs.get(hash)](#getkey-1) + - [docs.query(mapper)](#querymapper) + - [del(key)](#delkey) +- [orbitdb.counter(name|address)](#orbitdbcounternameaddress) + - [counter.value](#value) + - [counter.inc([value])](#incvalue) +- [orbitdb.create(name, type, [options])]() +- [orbitdb.open(name|address, [options])]() +- [orbitdb.stop()](#orbitdbstop) +- [orbitdb.disconnect()](orbitdbdisconnect) -- [Store API](#store) - - [store.load()](#storeload) - - [store.close()](#storeclose) - - [store.drop()](#storedrop) - - [store.key](#storekey) - - [store.type](#storetype) -- [Store Events](#storeevents) - - [replicated](#replicated) - - [replicate](#replicate) - - [replicate.progress](#replicateprogress) - - [load](#load-1) - - [load.progress](#loadprogress) - - [ready](#ready) - - [write](#write) +**Static Properties** +- [OrbitDB.databaseTypes](#databasetypes) + +**Static Methods** +- [OrbitDB.isValidType(type)](#isvalidtypetype) +- [OrbitDB.addDatabaseType(type, store)](#adddatabasetypetype-store) +- [OrbitDB.getDatabaseTypes()](#getdatabasetypes) +- [OrbitDB.isValidAddress(address)](#isvalidaddressaddress) +- [OrbitDB.parseAddress(address)](#parseaddressaddress) + +**[Store API](#store)** +- [store.load()](#storeload) +- [store.close()](#storeclose) +- [store.drop()](#storedrop) +- [store.key](#storekey) +- [store.type](#storetype) + +**[Store Events](#storeevents)** +- [replicated](#replicated) +- [replicate](#replicate) +- [replicate.progress](#replicateprogress) +- [load](#load-1) +- [load.progress](#loadprogress) +- [ready](#ready) +- [write](#write) ## Public Instance Methods ### orbitdb.keyvalue(name|address) From 96fe2a9c6a7123ce2d79cd4b03e34f431b43179f Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 15:14:48 -0400 Subject: [PATCH 15/31] docs: add api description for orbitdb.open --- API.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/API.md b/API.md index 8617535..5ac85be 100644 --- a/API.md +++ b/API.md @@ -291,7 +291,19 @@ const db = await orbitdb.create('user.posts', 'eventlog', { }) // db created & opened ``` -### orbitdb.open(name|address, [options]) +### orbitdb.open(address, [options]) +> Opens an OrbitDB database. + +Convienance methods are available when opening/creating any of the default OrbitDB database types (i.e. `orbitdb.feed(address, options)` instead of `orbitdb.open(address, { type: 'feed', ... })`) + +Returns a `Promise` that resolves to [a database instance](#store). `address` (string) should be a valid OrbitDB address. If a database name is provided instead, it will check `options.create` to determine if it should create the database. `options` is an object with any of the following properties: + +- `localOnly` (boolean): If set to `true`, will throw an error if the database can't be found locally. (Default: `false`) +- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). +- `create` (boolean): Whether to create the database if a valid OrbitDB address is not provided. (Default: `false`) +- `type` (string): A supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). Required if create is set to `true`. Otherwise it's used to validate the manifest. +- `overwrite` (boolean): Overwrite an existing database (Default: `false`) + ### orbitdb.stop() Stop OrbitDB, close databases and disconnect the databases from the network. From f4cb33b4aab955a3a841008b00e1e0ac6dd602b8 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 15:21:21 -0400 Subject: [PATCH 16/31] docs(api): reorganize orbitdb public methods --- API.md | 91 +++++++++++++++++++++++++++++++--------------------------- 1 file changed, 49 insertions(+), 42 deletions(-) diff --git a/API.md b/API.md index 5ac85be..64d0b66 100644 --- a/API.md +++ b/API.md @@ -21,6 +21,10 @@ const db = await orbitdb.keyvalue('profile') ``` **Public OrbitDB Instance Methods** +- [orbitdb.create(name, type, [options])]() +- [orbitdb.open(name|address, [options])]() +- [orbitdb.stop()](#orbitdbstop) +- [orbitdb.disconnect()](orbitdbdisconnect) - [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress) - [kv.put(key, value)](#putkey-value) - [kv.set(key, value)](#setkey-value) @@ -42,10 +46,6 @@ const db = await orbitdb.keyvalue('profile') - [orbitdb.counter(name|address)](#orbitdbcounternameaddress) - [counter.value](#value) - [counter.inc([value])](#incvalue) -- [orbitdb.create(name, type, [options])]() -- [orbitdb.open(name|address, [options])]() -- [orbitdb.stop()](#orbitdbstop) -- [orbitdb.disconnect()](orbitdbdisconnect) **Static Properties** - [OrbitDB.databaseTypes](#databasetypes) @@ -74,7 +74,48 @@ const db = await orbitdb.keyvalue('profile') - [write](#write) ## Public Instance Methods +### orbitdb.create(name, type, [options]) +> Creates and opens an OrbitDB database. + +Returns a `Promise` that resolves to [a database instance](#store). `name` (string) should be the database name, not an OrbitDB address (i.e. `user.posts`). `type` is a supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). `options` is an object with any of the following properties: +- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). +- `write` (array): An array of hex encoded public keys which are used to set write acces to the database. `["*"]` can be passed in to give write access to everyone. See the [GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md) guide for more info. (Default: uses the OrbitDB instance key `orbitdb.key`, which would give write access only to yourself) +- `overwrite` (boolean): Overwrite an existing database (Default: `false`) +```javascript +const db = await orbitdb.create('user.posts', 'eventlog', { + write: [ + // Give access to ourselves + orbitdb.key.getPublic('hex'), + // Give access to the second peer + '042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839' + ] +}) +// db created & opened +``` +### orbitdb.open(address, [options]) +> Opens an OrbitDB database. + +Convienance methods are available when opening/creating any of the default OrbitDB database types (i.e. `orbitdb.feed(address, options)` instead of `orbitdb.open(address, { type: 'feed', ... })`) + +Returns a `Promise` that resolves to [a database instance](#store). `address` (string) should be a valid OrbitDB address. If a database name is provided instead, it will check `options.create` to determine if it should create the database. `options` is an object with any of the following properties: + +- `localOnly` (boolean): If set to `true`, will throw an error if the database can't be found locally. (Default: `false`) +- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). +- `create` (boolean): Whether to create the database if a valid OrbitDB address is not provided. (Default: `false`) +- `type` (string): A supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). Required if create is set to `true`. Otherwise it's used to validate the manifest. +- `overwrite` (boolean): Overwrite an existing database (Default: `false`) + +### orbitdb.stop() + + Stop OrbitDB, close databases and disconnect the databases from the network. + + ```javascript + orbitdb.stop() + ``` +### orbitdb.disconnect() + ### orbitdb.keyvalue(name|address) +> Creates and opens a keyvalue database Module: [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) @@ -105,6 +146,7 @@ const db = await orbitdb.keyvalue(anotherkvdb.address) ``` ### orbitdb.log(name|address) +> Creates and opens an eventlog database Module: [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) @@ -154,6 +196,7 @@ const all = db.iterator({ limit: -1 }) ``` ### orbitdb.feed(name|address) +> Creates and opens a feed database Module: [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) @@ -208,6 +251,7 @@ const all = db.iterator({ limit: -1 }) ``` ### orbitdb.docs(name|address, options) +> Creates and opens a docstore database Module: [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) @@ -249,6 +293,7 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } ``` ### orbitdb.counter(name|address) +> Creates and opens a counter database Module: [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) @@ -275,44 +320,6 @@ const counter = await orbitdb.counter(anothercounterdb.address) counter.value // 8 ``` -### orbitdb.create(name, type, [options]) -Creates and opens an OrbitDB database. Returns a `Promise` that resolves to [a database instance](#store). `name` (string) should be the database name, not an OrbitDB address (i.e. `user.posts`). `type` is a supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). `options` is an object with any of the following properties: -- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). -- `write` (array): An array of hex encoded public keys which are used to set write acces to the database. `["*"]` can be passed in to give write access to everyone. See the [GETTING STARTED](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md) guide for more info. (Default: uses the OrbitDB instance key `orbitdb.key`, which would give write access only to yourself) -- `overwrite` (boolean): Overwrite an existing database (Default: `false`) -```javascript -const db = await orbitdb.create('user.posts', 'eventlog', { - write: [ - // Give access to ourselves - orbitdb.key.getPublic('hex'), - // Give access to the second peer - '042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839' - ] -}) -// db created & opened -``` -### orbitdb.open(address, [options]) -> Opens an OrbitDB database. - -Convienance methods are available when opening/creating any of the default OrbitDB database types (i.e. `orbitdb.feed(address, options)` instead of `orbitdb.open(address, { type: 'feed', ... })`) - -Returns a `Promise` that resolves to [a database instance](#store). `address` (string) should be a valid OrbitDB address. If a database name is provided instead, it will check `options.create` to determine if it should create the database. `options` is an object with any of the following properties: - -- `localOnly` (boolean): If set to `true`, will throw an error if the database can't be found locally. (Default: `false`) -- `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). -- `create` (boolean): Whether to create the database if a valid OrbitDB address is not provided. (Default: `false`) -- `type` (string): A supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). Required if create is set to `true`. Otherwise it's used to validate the manifest. -- `overwrite` (boolean): Overwrite an existing database (Default: `false`) - -### orbitdb.stop() - - Stop OrbitDB, close databases and disconnect the databases from the network. - - ```javascript - orbitdb.stop() - ``` -### orbitdb.disconnect() - ## Static Properties ### OrbitDB.databaseTypes Returns supported database types (i.e. store types) as an Array of strings From b045667cddeb696c5c720c760625e318df750b0f Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 15:30:09 -0400 Subject: [PATCH 17/31] docs: add description for orbitdb.disconnect + update links --- API.md | 24 +++++++++----- README.md | 98 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 65 insertions(+), 57 deletions(-) diff --git a/API.md b/API.md index 64d0b66..d94dd0a 100644 --- a/API.md +++ b/API.md @@ -21,10 +21,10 @@ const db = await orbitdb.keyvalue('profile') ``` **Public OrbitDB Instance Methods** -- [orbitdb.create(name, type, [options])]() -- [orbitdb.open(name|address, [options])]() +- [orbitdb.create(name, type, [options])](#orbitdbcreatename-type-options) +- [orbitdb.open(name|address, [options])](#orbitdbopenaddress-options) +- [orbitdb.disconnect()](#orbitdbdisconnect) - [orbitdb.stop()](#orbitdbstop) -- [orbitdb.disconnect()](orbitdbdisconnect) - [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress) - [kv.put(key, value)](#putkey-value) - [kv.set(key, value)](#setkey-value) @@ -105,14 +105,20 @@ Returns a `Promise` that resolves to [a database instance](#store). `address` (s - `type` (string): A supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). Required if create is set to `true`. Otherwise it's used to validate the manifest. - `overwrite` (boolean): Overwrite an existing database (Default: `false`) +### orbitdb.disconnect() + +Close databases, connections, pubsub and reset orbitdb state. + +```javascript +await orbitdb.disconnect() +``` + ### orbitdb.stop() - Stop OrbitDB, close databases and disconnect the databases from the network. - - ```javascript - orbitdb.stop() - ``` -### orbitdb.disconnect() +Alias for `orbitdb.disconnect()` +```javascript +await orbitdb.stop() +``` ### orbitdb.keyvalue(name|address) > Creates and opens a keyvalue database diff --git a/README.md b/README.md index 2c57f4a..3d3b593 100644 --- a/README.md +++ b/README.md @@ -140,55 +140,57 @@ After creating an `OrbitDB` instance , you can access the different data stores. *For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* -- **Public OrbitDB Instance Methods** - - [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) - - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) - - [kv.set(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#setkey-value) - - [kv.get(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getKey) - - [orbitdb.log(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) - - [log.add(event)](https://github.com/orbitdb/orbit-db/blob/master/API.md#addevent) - - [log.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash) - - [log.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions) - - [orbitdb.feed(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) - - [feed.add(data)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddata) - - [feed.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash-1) - - [feed.remove(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#removehash) - - [feed.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1) - - [orbitdb.docs(name|address, options)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) - - [docs.put(doc)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putdoc) - - [docs.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getkey-1) - - [docs.query(mapper)](https://github.com/orbitdb/orbit-db/blob/master/API.md#querymapper) - - [del(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#delkey) - - [orbitdb.counter(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) - - [counter.value](https://github.com/orbitdb/orbit-db/blob/master/API.md#value) - - [counter.inc([value])](https://github.com/orbitdb/orbit-db/blob/master/API.md#incvalue) - - [orbitdb.create(name|address, type, [options])]() - - [orbitdb.open(name|address, [options])]() - - [orbitdb.stop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbstop) - - [orbitdb.disconnect()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdisconnect) -- **Static Properties** - - [OrbitDB.databaseTypes](https://github.com/orbitdb/orbit-db/blob/master/API.md#databasetypes) -- **Static Methods** - - [OrbitDB.isValidType(type)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidtypetype) - - [OrbitDB.addDatabaseType(type, store)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddatabasetypetype-store) - - [OrbitDB.getDatabaseTypes()](https://github.com/orbitdb/orbit-db/blob/master/API.md#getdatabasetypes) - - [OrbitDB.isValidAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidaddressaddress) - - [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) +**Public OrbitDB Instance Methods** +- [orbitdb.create(name|address, type, [options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcreatename-type-options) +- [orbitdb.open(name|address, [options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbopenaddress-options) +- [orbitdb.disconnect()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdisconnect) +- [orbitdb.stop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbstop) +- [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) + - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) + - [kv.set(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#setkey-value) + - [kv.get(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getKey) +- [orbitdb.log(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) + - [log.add(event)](https://github.com/orbitdb/orbit-db/blob/master/API.md#addevent) + - [log.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash) + - [log.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions) +- [orbitdb.feed(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) + - [feed.add(data)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddata) + - [feed.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash-1) + - [feed.remove(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#removehash) + - [feed.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1) +- [orbitdb.docs(name|address, options)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) + - [docs.put(doc)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putdoc) + - [docs.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getkey-1) + - [docs.query(mapper)](https://github.com/orbitdb/orbit-db/blob/master/API.md#querymapper) + - [del(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#delkey) +- [orbitdb.counter(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) + - [counter.value](https://github.com/orbitdb/orbit-db/blob/master/API.md#value) + - [counter.inc([value])](https://github.com/orbitdb/orbit-db/blob/master/API.md#incvalue) -- [Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store) - - [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeload) - - [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeclose) - - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) - - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) - - [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#storetype) -- [Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents) - - [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) - - [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) - - [replicate.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicateprogress) - - [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load-1) - - [load.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#loadprogress) - - [ready](https://github.com/orbitdb/orbit-db/blob/master/API.md#ready) - - [write](https://github.com/orbitdb/orbit-db/blob/master/API.md#write) +**Static Properties** +- [OrbitDB.databaseTypes](https://github.com/orbitdb/orbit-db/blob/master/API.md#databasetypes) + +**Static Methods** +- [OrbitDB.isValidType(type)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidtypetype) +- [OrbitDB.addDatabaseType(type, store)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddatabasetypetype-store) +- [OrbitDB.getDatabaseTypes()](https://github.com/orbitdb/orbit-db/blob/master/API.md#getdatabasetypes) +- [OrbitDB.isValidAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidaddressaddress) +- [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) + +**[Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store)** +- [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeload) +- [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeclose) +- [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) +- [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) +- [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#storetype) +**[Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents)** +- [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) +- [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) +- [replicate.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicateprogress) +- [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load-1) +- [load.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#loadprogress) +- [ready](https://github.com/orbitdb/orbit-db/blob/master/API.md#ready) +- [write](https://github.com/orbitdb/orbit-db/blob/master/API.md#write) ### Custom Store Types From ab568e383e1426bbe250158b8e713c02ddbdd712 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 13 Jul 2018 15:44:09 -0400 Subject: [PATCH 18/31] docs: amend orbitdb.open description --- API.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index d94dd0a..fc13ca1 100644 --- a/API.md +++ b/API.md @@ -95,16 +95,24 @@ const db = await orbitdb.create('user.posts', 'eventlog', { ### orbitdb.open(address, [options]) > Opens an OrbitDB database. -Convienance methods are available when opening/creating any of the default OrbitDB database types (i.e. `orbitdb.feed(address, options)` instead of `orbitdb.open(address, { type: 'feed', ... })`) +Convienance methods are available when opening/creating any of the default OrbitDB database types: [feed](#orbitdbfeednameaddress), [docs](#orbitdbdocsnameaddress-options), [log](#orbitdblognameaddress), [keyvalue](#orbitdbkeyvaluenameaddress), [counter](#orbitdbcounternameaddress) + +You can use: `orbitdb.feed(address, options)` + +Instead of: `orbitdb.open(address, { type: 'feed', ...options })` Returns a `Promise` that resolves to [a database instance](#store). `address` (string) should be a valid OrbitDB address. If a database name is provided instead, it will check `options.create` to determine if it should create the database. `options` is an object with any of the following properties: - `localOnly` (boolean): If set to `true`, will throw an error if the database can't be found locally. (Default: `false`) - `directory` (string): The directory where data will be stored (Default: uses directory option passed to OrbitDB constructor or `./orbitdb` if none was provided). -- `create` (boolean): Whether to create the database if a valid OrbitDB address is not provided. (Default: `false`) +- `create` (boolean): Whether or not to create the database if a valid OrbitDB address is not provided. (Default: `false`) - `type` (string): A supported database type (i.e. `eventlog` or [an added custom type](https://github.com/orbitdb/orbit-db#custom-store-types)). Required if create is set to `true`. Otherwise it's used to validate the manifest. - `overwrite` (boolean): Overwrite an existing database (Default: `false`) +```javascript +const db = await orbitdb.open('/orbitdb/Qmd8TmZrWASypEp4Er9tgWP4kCNQnW4ncSnvjvyHQ3EVSU/first-database') +``` + ### orbitdb.disconnect() Close databases, connections, pubsub and reset orbitdb state. From 6be510decd3114c544880c5ac9082f9eee4d3ce3 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Tue, 17 Jul 2018 16:55:07 -0400 Subject: [PATCH 19/31] docs: fix typos --- API.md | 2 +- GUIDE.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/API.md b/API.md index fc13ca1..bd438ec 100644 --- a/API.md +++ b/API.md @@ -458,7 +458,7 @@ db.events.on(name, callback) db.events.on('replicated', (address) => ... ) ``` -Emitted when a the database was synced with another peer. This is usually a good place to re-query the database for updated results, eg. if a value of a key was changed or if there are new events in an event log. +Emitted when the database has synced with another peer. This is usually a good place to re-query the database for updated results, eg. if a value of a key was changed or if there are new events in an event log. #### `replicate` ```javascript diff --git a/GUIDE.md b/GUIDE.md index 1d1b215..89a11de 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -1,6 +1,6 @@ # Getting Started with OrbitDB -This guide will get you familiar with using OrbitDB in your JavaScript application. OrbitDB and IPFS both work in Node.js applications as well as in browser applications. (Windows is not supported yet though) +This guide will get you familiar with using OrbitDB in your JavaScript application. OrbitDB and IPFS both work in Node.js applications as well as in browser applications. (Windows is not supported yet though). This guide is still being worked on and we would love to get [feedback and suggestions](https://github.com/orbitdb/orbit-db/issues) on how to improve it! From cbd03c0528f772ef1713297114916f0946e89055 Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Tue, 17 Jul 2018 17:20:47 -0400 Subject: [PATCH 20/31] docs: refractor test demo links, remove duplicate links remove duplicate info about GUIDE.md and CLI --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3d3b593..1204e35 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,9 @@ 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. +**Test it live at [Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/), [Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/), or [P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! + + OrbitDB provides various types of databases for different data models and use cases: - **[log](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress)**: an immutable (append-only) log with traversable history. Useful for *"latest N"* use cases or as a message queue. @@ -23,9 +26,6 @@ All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on to #### Project status & support 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.0.0. 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. -#### Getting Started -Try the **[OrbitDB CLI](https://github.com/orbitdb/orbit-db-cli)**, read the **[Getting Started Guide](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md)** or check **[Live demo 1](https://ipfs.io/ipfs/QmeESXh9wPib8Xz7hdRzHuYLDuEUgkYTSuujZ2phQfvznQ/)**, **[Live demo 2](https://ipfs.io/ipfs/QmasHFRj6unJ3nSmtPn97tWDaQWEZw3W9Eh3gUgZktuZDZ/)** or **[P2P TodoMVC app](https://ipfs.io/ipfs/QmTJGHccriUtq3qf3bvAQUcDUHnBbHNJG2x2FYwYUecN43/)**! - ## Table of Contents - [Usage](#usage) From 88ebe6a459bce10eb0e0965e8d4c5e408b728bfa Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Wed, 18 Jul 2018 07:56:27 -0400 Subject: [PATCH 21/31] docs: fix styling --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1204e35..e8f7f6d 100644 --- a/README.md +++ b/README.md @@ -183,6 +183,7 @@ After creating an `OrbitDB` instance , you can access the different data stores. - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) - [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#storetype) + **[Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents)** - [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) - [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) From a7ab7c4d4a893695bec42fdc85340cee18da46b6 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Wed, 18 Jul 2018 13:42:15 -0400 Subject: [PATCH 22/31] docs: add store.load param --- API.md | 6 +++--- README.md | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/API.md b/API.md index bd438ec..4ebb8be 100644 --- a/API.md +++ b/API.md @@ -58,7 +58,7 @@ const db = await orbitdb.keyvalue('profile') - [OrbitDB.parseAddress(address)](#parseaddressaddress) **[Store API](#store)** -- [store.load()](#storeload) +- [store.load()](#storeloadamount) - [store.close()](#storeclose) - [store.drop()](#storedrop) - [store.key](#storekey) @@ -387,9 +387,9 @@ OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/fi Every database (store) has the following methods available in addition to their specific methods. -#### store.load() +#### store.load([amount]) -Load the locally persisted database state to memory. +Load the locally persisted database state to memory. Use the optional `amount` argument to limit the number of entries loaded into memory, starting from the head(s) (Default: `-1` will load all entries) With events: ```javascript diff --git a/README.md b/README.md index e8f7f6d..1fffb6c 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,7 @@ After creating an `OrbitDB` instance , you can access the different data stores. - [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) **[Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store)** -- [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeload) +- [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeloadamount) - [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeclose) - [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) - [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) From 5585bff7391adf16b978d25536d946afcff856a5 Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Thu, 19 Jul 2018 08:54:33 -0400 Subject: [PATCH 23/31] docs: fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fffb6c..663db82 100644 --- a/README.md +++ b/README.md @@ -284,7 +284,7 @@ OrbitDB uses the following modules: - [ipfs](https://github.com/ipfs/js-ipfs) - [ipfs-log](https://github.com/orbitdb/ipfs-log) -- [ipfs-pubub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) +- [ipfs-pubsub-room](https://github.com/ipfs-shipyard/ipfs-pubsub-room) - [crdts](https://github.com/orbitdb/crdts) - [orbit-db-cache](https://github.com/orbitdb/orbit-db-cache) - [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub) From 51d0c2c3e9e9a5cc21090716a66b0a09d804be7d Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Fri, 20 Jul 2018 08:40:46 -0400 Subject: [PATCH 24/31] docs(readme): remove api list keep README.md concise --- README.md | 55 +------------------------------------------------------ 1 file changed, 1 insertion(+), 54 deletions(-) diff --git a/README.md b/README.md index 663db82..da4b272 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ const db = await orbitdb.log('hello') ## API -See [API documentation](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation. +See [API.md](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation. ### constructor(ipfs, [directory], [options]) ```javascript @@ -140,59 +140,6 @@ After creating an `OrbitDB` instance , you can access the different data stores. *For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* -**Public OrbitDB Instance Methods** -- [orbitdb.create(name|address, type, [options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcreatename-type-options) -- [orbitdb.open(name|address, [options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbopenaddress-options) -- [orbitdb.disconnect()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdisconnect) -- [orbitdb.stop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbstop) -- [orbitdb.keyvalue(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbkeyvaluenameaddress) - - [kv.put(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putkey-value) - - [kv.set(key, value)](https://github.com/orbitdb/orbit-db/blob/master/API.md#setkey-value) - - [kv.get(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getKey) -- [orbitdb.log(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdblognameaddress) - - [log.add(event)](https://github.com/orbitdb/orbit-db/blob/master/API.md#addevent) - - [log.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash) - - [log.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions) -- [orbitdb.feed(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbfeednameaddress) - - [feed.add(data)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddata) - - [feed.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#gethash-1) - - [feed.remove(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#removehash) - - [feed.iterator([options])](https://github.com/orbitdb/orbit-db/blob/master/API.md#iteratoroptions-1) -- [orbitdb.docs(name|address, options)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options) - - [docs.put(doc)](https://github.com/orbitdb/orbit-db/blob/master/API.md#putdoc) - - [docs.get(hash)](https://github.com/orbitdb/orbit-db/blob/master/API.md#getkey-1) - - [docs.query(mapper)](https://github.com/orbitdb/orbit-db/blob/master/API.md#querymapper) - - [del(key)](https://github.com/orbitdb/orbit-db/blob/master/API.md#delkey) -- [orbitdb.counter(name|address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress) - - [counter.value](https://github.com/orbitdb/orbit-db/blob/master/API.md#value) - - [counter.inc([value])](https://github.com/orbitdb/orbit-db/blob/master/API.md#incvalue) - -**Static Properties** -- [OrbitDB.databaseTypes](https://github.com/orbitdb/orbit-db/blob/master/API.md#databasetypes) - -**Static Methods** -- [OrbitDB.isValidType(type)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidtypetype) -- [OrbitDB.addDatabaseType(type, store)](https://github.com/orbitdb/orbit-db/blob/master/API.md#adddatabasetypetype-store) -- [OrbitDB.getDatabaseTypes()](https://github.com/orbitdb/orbit-db/blob/master/API.md#getdatabasetypes) -- [OrbitDB.isValidAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#isvalidaddressaddress) -- [OrbitDB.parseAddress(address)](https://github.com/orbitdb/orbit-db/blob/master/API.md#parseaddressaddress) - -**[Store API](https://github.com/orbitdb/orbit-db/blob/master/API.md#store)** -- [load()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeloadamount) -- [close()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeclose) -- [drop()](https://github.com/orbitdb/orbit-db/blob/master/API.md#storedrop) -- [key](https://github.com/orbitdb/orbit-db/blob/master/API.md#storekey) -- [type](https://github.com/orbitdb/orbit-db/blob/master/API.md#storetype) - -**[Store Events](https://github.com/orbitdb/orbit-db/blob/master/API.md#storeevents)** -- [replicated](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicated) -- [replicate](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicate) -- [replicate.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#replicateprogress) -- [load](https://github.com/orbitdb/orbit-db/blob/master/API.md#load-1) -- [load.progress](https://github.com/orbitdb/orbit-db/blob/master/API.md#loadprogress) -- [ready](https://github.com/orbitdb/orbit-db/blob/master/API.md#ready) -- [write](https://github.com/orbitdb/orbit-db/blob/master/API.md#write) - ### Custom Store Types You can add custom store types to OrbitDB: From 3177f2c634c0313b269c6bca2055b08e7f36738d Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Fri, 20 Jul 2018 08:42:43 -0400 Subject: [PATCH 25/31] docs(readme): expand on usage with IPFS instance --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index da4b272..42f86d6 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ npm install orbit-db-cli -g ### Module with IPFS Instance -If you're using `orbitd-db` to develop **browser** applications, use it as a module with the javascript instance of IPFS +If you're using `orbitd-db` to develop **browser** or **Node.js** applications, use it as a module with the javascript instance of IPFS Install dependencies: From 2f84c96c9dfc641b9441e64c4d18bcb930b86bde Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Fri, 20 Jul 2018 09:22:53 -0400 Subject: [PATCH 26/31] docs: move custom store to GUIDE.md --- GUIDE.md | 26 ++++++++++++++++++++++++++ README.md | 27 +-------------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/GUIDE.md b/GUIDE.md index 89a11de..ae8cbb2 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -19,6 +19,7 @@ This guide is still being worked on and we would love to get [feedback and sugge - [Get an entry](#get-an-entry) - [Persistency](#persistency) - [Replicating a database](#replicating-a-database) +- [Custom Database Stores](#custom-stores) ## Background @@ -350,6 +351,31 @@ ipfs1.on('ready', async () => { }) ``` +## Custom Stores + +Use a custom store to implement case specifc functionality that is not supported by the default OrbitDB database stores. Then, you can easily add and use your custom store with OrbitDB: + +```javascript +// define custom store type +class CustomStore extends DocumentStore { + constructor (ipfs, id, dbname, options) { + super(ipfs, id, dbname, options) + this._type = CustomStore.type + } + + static get type () { + return 'custom' + } +} + +// add custom type to orbitdb +OrbitDB.addDatabaseType(CustomStore.type, CustomStore) + +// instantiate custom store +let orbitdb = new OrbitDB(ipfs, dbPath) +let store = orbitdb.create(name, CustomStore.type) +``` + ## More information Is this guide missing something you'd like to understand or found an error? Please [open an issue](https://github.com/orbitdb/orbit-db/issues) and let us know what's missing! diff --git a/README.md b/README.md index 42f86d6..8b49fb2 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ OrbitDB provides various types of databases for different data models and use ca - **[docs](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbdocsnameaddress-options)**: a document database to which JSON documents can be stored and indexed by a specified key. Useful for building search indices or version controlling documents and data. - **[counter](https://github.com/orbitdb/orbit-db/blob/master/API.md#orbitdbcounternameaddress)**: Useful for counting events separate from log/feed data. -All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on top of [ipfs-log](https://github.com/orbitdb/ipfs-log), an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. +All databases are [implemented](https://github.com/orbitdb/orbit-db-store) on top of [ipfs-log](https://github.com/orbitdb/ipfs-log), an immutable, operation-based conflict-free replicated data structure (CRDT) for distributed systems. If none of the OrbitDB database types match your needs and/or you need case-specific functionality, you can easily [implement and use a custom database store](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#custom-stores) of your own. #### Project status & support 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.0.0. 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. @@ -140,31 +140,6 @@ After creating an `OrbitDB` instance , you can access the different data stores. *For further details, see usage for [kvstore](https://github.com/orbitdb/orbit-db-kvstore#usage), [eventlog](https://github.com/orbitdb/orbit-db-eventstore#usage), [feed](https://github.com/orbitdb/orbit-db-feedstore#usage), [docstore](https://github.com/orbitdb/orbit-db-docstore#usage) and [counter](https://github.com/orbitdb/orbit-db-counterstore#usage).* -### Custom Store Types - -You can add custom store types to OrbitDB: - -```javascript -// define custom store type -class CustomStore extends DocumentStore { - constructor (ipfs, id, dbname, options) { - super(ipfs, id, dbname, options) - this._type = CustomStore.type - } - - static get type () { - return 'custom' - } -} - -// add custom type to orbitdb -OrbitDB.addDatabaseType(CustomStore.type, CustomStore) - -// instantiate custom store -let orbitdb = new OrbitDB(ipfs, dbPath) -let store = orbitdb.create(name, CustomStore.type) -``` - ## Examples ### Install dependencies From 383f0ce6d209d4042700433710a8cd3596d2c9f5 Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Sat, 21 Jul 2018 09:11:03 -0400 Subject: [PATCH 27/31] docs(api): document returns --- API.md | 82 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 26 deletions(-) diff --git a/API.md b/API.md index 4ebb8be..8ebd9b3 100644 --- a/API.md +++ b/API.md @@ -95,12 +95,6 @@ const db = await orbitdb.create('user.posts', 'eventlog', { ### orbitdb.open(address, [options]) > Opens an OrbitDB database. -Convienance methods are available when opening/creating any of the default OrbitDB database types: [feed](#orbitdbfeednameaddress), [docs](#orbitdbdocsnameaddress-options), [log](#orbitdblognameaddress), [keyvalue](#orbitdbkeyvaluenameaddress), [counter](#orbitdbcounternameaddress) - -You can use: `orbitdb.feed(address, options)` - -Instead of: `orbitdb.open(address, { type: 'feed', ...options })` - Returns a `Promise` that resolves to [a database instance](#store). `address` (string) should be a valid OrbitDB address. If a database name is provided instead, it will check `options.create` to determine if it should create the database. `options` is an object with any of the following properties: - `localOnly` (boolean): If set to `true`, will throw an error if the database can't be found locally. (Default: `false`) @@ -113,9 +107,16 @@ Returns a `Promise` that resolves to [a database instance](#store). `address` (s const db = await orbitdb.open('/orbitdb/Qmd8TmZrWASypEp4Er9tgWP4kCNQnW4ncSnvjvyHQ3EVSU/first-database') ``` -### orbitdb.disconnect() +Convienance methods are available when opening/creating any of the default OrbitDB database types: [feed](#orbitdbfeednameaddress), [docs](#orbitdbdocsnameaddress-options), [log](#orbitdblognameaddress), [keyvalue](#orbitdbkeyvaluenameaddress), [counter](#orbitdbcounternameaddress) -Close databases, connections, pubsub and reset orbitdb state. +You can use: `orbitdb.feed(address, options)` + +Instead of: `orbitdb.open(address, { type: 'feed', ...options })` + +### orbitdb.disconnect() +>Close databases, connections, pubsub and reset orbitdb state. + +Returns a `Promise` that resolves once complete. ```javascript await orbitdb.disconnect() @@ -131,7 +132,7 @@ await orbitdb.stop() ### orbitdb.keyvalue(name|address) > Creates and opens a keyvalue database -Module: [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) +Returns a `Promise` that resolves to a [`KeyValueStore` instance](https://github.com/orbitdb/orbit-db-kvstore). ```javascript const db = await orbitdb.keyvalue('application.settings') @@ -139,21 +140,24 @@ const db = await orbitdb.keyvalue('application.settings') const db = await orbitdb.keyvalue(anotherkvdb.address) ``` +Module: [orbit-db-kvstore](https://github.com/orbitdb/orbit-db-kvstore) + **See the [Store](#store) section for details of common methods and properties.** #### put(key, value) +Returns a `Promise` that resolves to a `String` that is the multihash of the entry. ```javascript await db.put('hello', { name: 'World' }) ``` #### set(key, value) +Alias for `.put()` ```javascript await db.set('hello', { name: 'Friend' }) ``` -*set() is an alias of put(). They both work the same.* - #### get(key) +Returns an `Object` with the contents of the entry. ```javascript const value = db.get('hello') // { name: 'Friend' } @@ -162,7 +166,7 @@ const db = await orbitdb.keyvalue(anotherkvdb.address) ### orbitdb.log(name|address) > Creates and opens an eventlog database -Module: [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) +Returns a `Promise` that resolves to a [`EventStore` instance](https://github.com/orbitdb/orbit-db-eventstore). ```javascript const db = await orbitdb.eventlog('site.visitors') @@ -170,14 +174,18 @@ const db = await orbitdb.eventlog('site.visitors') const db = await orbitdb.eventlog(anotherlogdb.address) ``` +Module: [orbit-db-eventstore](https://github.com/orbitdb/orbit-db-eventstore) + **See the [Store](#store) section for details of common methods and properties.** #### add(event) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript const hash = await db.add({ name: 'User1' }) ``` #### get(hash) +Returns an `Object` with the contents of the entry. ```javascript const event = db.get(hash) .map((e) => e.payload.value) @@ -186,6 +194,8 @@ const db = await orbitdb.eventlog(anotherlogdb.address) #### iterator([options]) +Returns an `Array` of `Objects` based on the `options`. + **options** : It is an object which supports the following properties `gt - (string)` Greater than, takes an item's `hash`. @@ -212,7 +222,7 @@ const all = db.iterator({ limit: -1 }) ### orbitdb.feed(name|address) > Creates and opens a feed database -Module: [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) +Returns a `Promise` that resolves to a [`FeedStore` instance](https://github.com/orbitdb/orbit-db-feedstore). ```javascript const db = await orbitdb.feed('orbit-db.issues') @@ -220,14 +230,18 @@ const db = await orbitdb.feed('orbit-db.issues') const db = await orbitdb.feed(anotherfeeddb.address) ``` +Module: [orbit-db-feedstore](https://github.com/orbitdb/orbit-db-feedstore) + See the [Store](#store) section for details of common methods and properties. #### add(data) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript const hash = await db.add({ name: 'User1' }) ``` #### get(hash) +Returns an `Object` with the contents of the entry. ```javascript const event = db.get(hash) .map((e) => e.payload.value) @@ -235,12 +249,15 @@ See the [Store](#store) section for details of common methods and properties. ``` #### remove(hash) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript const hash = await db.remove(hash) ``` #### iterator([options]) +Returns an `Array` of `Objects` based on the `options`. + **options** : It is an object which supports the following properties `gt - (string)` Greater than, takes an item's `hash`. @@ -267,7 +284,7 @@ const all = db.iterator({ limit: -1 }) ### orbitdb.docs(name|address, options) > Creates and opens a docstore database -Module: [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) +Returns a `Promise` that resolves to a [`DocumentStore` instance](https://github.com/orbitdb/orbit-db-docstore). ```javascript const db = await orbitdb.docs('orbit.users.shamb0t.profile') @@ -281,14 +298,18 @@ By default, documents are indexed by field `_id`. You can also specify the field const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' }) ``` +Module: [orbit-db-docstore](https://github.com/orbitdb/orbit-db-docstore) + **See the [Store](#store) section for details of common methods and properties.** #### put(doc) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript const hash = await db.put({ _id: 'QmAwesomeIpfsHash', name: 'shamb0t', followers: 500 }) ``` #### get(key) +Returns an `Array` with a single `Object` if key exists. ```javascript const profile = db.get('shamb0t') .map((e) => e.payload.value) @@ -296,12 +317,14 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } ``` #### query(mapper) +Returns an `Array` of `Objects` based on the `mapper`. ```javascript const all = db.query((doc) => doc.followers >= 500) // [{ _id: 'shamb0t', name: 'shamb0t', followers: 500 }] ``` #### del(key) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript const hash = await db.del('shamb0t') ``` @@ -309,7 +332,7 @@ const db = await orbitdb.docs('orbit.users.shamb0t.profile', { indexBy: 'name' } ### orbitdb.counter(name|address) > Creates and opens a counter database -Module: [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore) +Returns a `Promise` that resolves to a [`DocumentStore` instance](https://github.com/orbitdb/orbit-db-docstore). ```javascript const counter = await orbitdb.counter('song_123.play_count') @@ -317,14 +340,18 @@ const counter = await orbitdb.counter('song_123.play_count') const counter = await orbitdb.counter(anothercounterdb.address) ``` +Module: [orbit-db-counterstore](https://github.com/orbitdb/orbit-db-counterstore). + **See the [Store](#store) section for details of common methods and properties.** #### value +Returns a `Number`. ```javascript counter.value // 0 ``` #### inc([value]) +Returns a `Promise` that resolves to the multihash of the entry as a `String`. ```javascript await counter.inc() counter.value // 1 @@ -336,7 +363,7 @@ const counter = await orbitdb.counter(anothercounterdb.address) ## Static Properties ### OrbitDB.databaseTypes -Returns supported database types (i.e. store types) as an Array of strings +Returns supported database types (i.e. store types) as an `Array` of `Strings` ```js OrbitDB.databaseTypes // [ 'counter', 'eventlog', 'feed', 'docstore', 'keyvalue'] @@ -345,7 +372,7 @@ OrbitDB.databaseTypes ## Static Methods ### OrbitDB.isValidType(type) -Returns `true` if the provided string is a supported database type +Returns `true` if the provided `String` is a supported database type ```js OrbitDB.isValidType('docstore') // true @@ -359,7 +386,7 @@ OrbitDB.addDatabaseType(CustomStore.type, CustomStore) ``` ### OrbitDB.getDatabaseTypes() -Returns an object mapping database types to Store Classes +Returns an `Object` mapping database types to Store Classes ```js OrbitDB.getDatabaseTypes() // { counter: [Function: CounterStore], @@ -369,13 +396,13 @@ OrbitDB.getDatabaseTypes() // keyvalue: [Function: KeyValueStore] } ``` ### OrbitDB.isValidAddress(address) -Returns `true` if the provided string is a valid orbitdb address +Returns `true` if the provided `String` is a valid OrbitDB address ```js OrbitDB.isValidAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') // true ``` ### OrbitDB.parseAddress(address) -Returns an instance of OrbitDBAddress if the provided string is a valid orbitdb address +Returns an instance of OrbitDBAddress if the provided `String` is a valid orbitdb address ```js OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/first-database') // OrbitDBAddress { @@ -391,6 +418,8 @@ Every database (store) has the following methods available in addition to their Load the locally persisted database state to memory. Use the optional `amount` argument to limit the number of entries loaded into memory, starting from the head(s) (Default: `-1` will load all entries) +Returns a `Promise` that resolves once complete + With events: ```javascript db.events.on('ready', () => { @@ -406,8 +435,8 @@ await db.load() ``` #### store.close() - -Close the database. +> Close the database. +Returns a `Promise` that resolves once complete Async: ```javascript @@ -415,8 +444,9 @@ await db.close() ``` #### store.drop() +> Remove the database locally. This does not delete any data from peers. -Remove the database locally. This does not delete any data from peers. +Returns a `Promise` that resolves once complete ```javascript await db.drop() @@ -424,7 +454,7 @@ await db.drop() #### store.key -The [keypair](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#keys) used to access the database. +Returns an instance of [`KeyPair`](https://github.com/indutny/elliptic/blob/master/lib/elliptic/ec/key.js#L8). The keypair is used to sign the database entries. See the [GUIDE](https://github.com/orbitdb/orbit-db/blob/master/GUIDE.md#keys) for more information on how OrbitDB uses the keypair. ``` const key = db.key @@ -434,7 +464,7 @@ console.log(key) // y: ce206bfccf889465c6g6f9a7fdf452f9c3e1204a6f1b4582ec427ec12b116de9> > ``` -The key contains the keypair used to sign the database entries. The public key can be retrieved with: +The public key can be retrieved with: ``` console.log(db.key.getPublic('hex')) // 04d009bd530f2fa0cda29202e1b15e97247893cb1e88601968abfe787f7ea03828fdb7624a618fd67c4c437ad7f48e670cc5a6ea2340b896e42b0c8a3e4d54aebe @@ -444,7 +474,7 @@ The key can also be accessed from the [OrbitDB](#orbitdb) instance: `orbitdb.key #### store.type -The type of the database as a string. +Returns the type of the database as a `String`. ### Store Events From a4eb5e1c6022d05fe6ff08cabb823c9626ff2b80 Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Sat, 21 Jul 2018 09:21:03 -0400 Subject: [PATCH 28/31] docs(api): add missing aliases --- API.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/API.md b/API.md index 8ebd9b3..2a85354 100644 --- a/API.md +++ b/API.md @@ -29,10 +29,12 @@ const db = await orbitdb.keyvalue('profile') - [kv.put(key, value)](#putkey-value) - [kv.set(key, value)](#setkey-value) - [kv.get(key)](#getkey) +- [orbitdb.kvstore(name|address)](#orbitdbkvstorenameaddress) - [orbitdb.log(name|address)](#orbitdblognameaddress) - [log.add(event)](#addevent) - [log.get(hash)](#gethash) - [log.iterator([options])](#iteratoroptions) +- [orbitdb.eventlog(name|address)](#orbitdbeventlognameaddress) - [orbitdb.feed(name|address)](#orbitdbfeednameaddress) - [feed.add(data)](#adddata) - [feed.get(hash)](#gethash-1) @@ -43,6 +45,7 @@ const db = await orbitdb.keyvalue('profile') - [docs.get(hash)](#getkey-1) - [docs.query(mapper)](#querymapper) - [del(key)](#delkey) +- [orbitdb.docstore(name|address, options)](#orbitdbdocstorenameaddress-options) - [orbitdb.counter(name|address)](#orbitdbcounternameaddress) - [counter.value](#value) - [counter.inc([value])](#incvalue) @@ -163,6 +166,10 @@ Returns an `Object` with the contents of the entry. // { name: 'Friend' } ``` +### orbitdb.kvstore(name|address) + +Alias for [`orbitdb.keyvalue()`](#orbitdbkeyvaluenameaddress) + ### orbitdb.log(name|address) > Creates and opens an eventlog database @@ -219,6 +226,10 @@ const all = db.iterator({ limit: -1 }) // [{ name: 'User1' }] ``` +### orbitdb.eventlog(name|address) + +Alias for [`orbitdb.log()`](#orbitdblognameaddress) + ### orbitdb.feed(name|address) > Creates and opens a feed database @@ -329,6 +340,10 @@ Returns a `Promise` that resolves to the multihash of the entry as a `String`. const hash = await db.del('shamb0t') ``` +### orbitdb.docstore(name|address, options) + +Alias for [`orbitdb.docs()`](#orbitdbdocsnameaddress-options) + ### orbitdb.counter(name|address) > Creates and opens a counter database From b35e0f67b1b0101e8970d6e892d8a47a84bf570d Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Wed, 25 Jul 2018 21:03:59 -0400 Subject: [PATCH 29/31] docs(api): add missing param to store ready event --- API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API.md b/API.md index 2a85354..87a4631 100644 --- a/API.md +++ b/API.md @@ -535,7 +535,7 @@ Emitted while loading the local database, once for each entry. *dbname* is the n #### `ready` ```javascript -db.events.on('ready', (dbname) => ... ) +db.events.on('ready', (dbname, heads) => ... ) ``` Emitted after fully loading the local database. From e0693720f0e8bb71265e68e7483eb0ba800ee8c0 Mon Sep 17 00:00:00 2001 From: Kia <1823355+mistakia@users.noreply.github.com> Date: Wed, 25 Jul 2018 21:08:31 -0400 Subject: [PATCH 30/31] docs(api): add store closed event --- API.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/API.md b/API.md index 87a4631..6db41f6 100644 --- a/API.md +++ b/API.md @@ -75,6 +75,7 @@ const db = await orbitdb.keyvalue('profile') - [load.progress](#loadprogress) - [ready](#ready) - [write](#write) +- [closed](#closed) ## Public Instance Methods ### orbitdb.create(name, type, [options]) @@ -546,3 +547,9 @@ db.events.on('write', (dbname, hash, entry) => ... ) ``` Emitted after an entry was added locally to the database. *hash* is the IPFS hash of the latest state of the database. *entry* is the added database op. + +#### `closed` +Emitted once the database has finished closing. +```javascript +db.events.on('closed', (dbname) => ... ) +``` From cb33a6f1fab0821d6e5b29c819bd1e289779b21b Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Wed, 25 Jul 2018 21:10:06 -0400 Subject: [PATCH 31/31] docs(api): fix broken link to load event --- API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/API.md b/API.md index 6db41f6..5011746 100644 --- a/API.md +++ b/API.md @@ -71,7 +71,7 @@ const db = await orbitdb.keyvalue('profile') - [replicated](#replicated) - [replicate](#replicate) - [replicate.progress](#replicateprogress) -- [load](#load-1) +- [load](#load) - [load.progress](#loadprogress) - [ready](#ready) - [write](#write)