Merge pull request #428 from orbitdb/feat/automatically-add-tocs

docs: Add TOCs using an npm script
This commit is contained in:
Richard Littauer 2018-08-13 15:16:28 -04:00 committed by GitHub
commit 8ae7274d0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 1518 additions and 109 deletions

165
API.md
View File

@ -2,6 +2,69 @@
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.
## Table of Contents
<!-- toc -->
- [Constructor](#constructor)
* [constructor(ipfs, [directory], [options])](#constructoripfs-directory-options)
- [Public Instance Methods](#public-instance-methods)
* [orbitdb.create(name, type, [options])](#orbitdbcreatename-type-options)
* [orbitdb.open(address, [options])](#orbitdbopenaddress-options)
* [orbitdb.disconnect()](#orbitdbdisconnect)
* [orbitdb.stop()](#orbitdbstop)
* [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress)
+ [put(key, value)](#putkey-value)
+ [set(key, value)](#setkey-value)
+ [get(key)](#getkey)
* [orbitdb.kvstore(name|address)](#orbitdbkvstorenameaddress)
* [orbitdb.log(name|address)](#orbitdblognameaddress)
+ [add(event)](#addevent)
+ [get(hash)](#gethash)
+ [iterator([options])](#iteratoroptions)
* [orbitdb.eventlog(name|address)](#orbitdbeventlognameaddress)
* [orbitdb.feed(name|address)](#orbitdbfeednameaddress)
+ [add(data)](#adddata)
+ [get(hash)](#gethash-1)
+ [remove(hash)](#removehash)
+ [iterator([options])](#iteratoroptions-1)
* [orbitdb.docs(name|address, options)](#orbitdbdocsnameaddress-options)
+ [put(doc)](#putdoc)
+ [get(key)](#getkey-1)
+ [query(mapper)](#querymapper)
+ [del(key)](#delkey)
* [orbitdb.docstore(name|address, options)](#orbitdbdocstorenameaddress-options)
* [orbitdb.counter(name|address)](#orbitdbcounternameaddress)
+ [value](#value)
+ [inc([value])](#incvalue)
- [Static Properties](#static-properties)
* [OrbitDB.databaseTypes](#orbitdbdatabasetypes)
- [Static Methods](#static-methods)
* [OrbitDB.isValidType(type)](#orbitdbisvalidtypetype)
* [OrbitDB.addDatabaseType(type, store)](#orbitdbadddatabasetypetype-store)
* [OrbitDB.getDatabaseTypes()](#orbitdbgetdatabasetypes)
* [OrbitDB.isValidAddress(address)](#orbitdbisvalidaddressaddress)
* [OrbitDB.parseAddress(address)](#orbitdbparseaddressaddress)
- [Store API](#store-api)
* [store.load([amount])](#storeloadamount)
* [store.close()](#storeclose)
* [store.drop()](#storedrop)
* [store.key](#storekey)
* [store.type](#storetype)
- [Store Events](#store-events)
* [`replicated`](#replicated)
* [`replicate`](#replicate)
+ [`replicate.progress`](#replicateprogress)
* [`load`](#load)
+ [`load.progress`](#loadprogress)
* [`ready`](#ready)
* [`write`](#write)
* [`closed`](#closed)
<!-- tocstop -->
## Constructor
### constructor(ipfs, [directory], [options])
```javascript
const orbitdb = new OrbitDB(ipfs)
@ -12,7 +75,7 @@ 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](#store). See the [Store](#store) section for details of common methods and properties.
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-api). See the [Store](#store-api) 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).*
@ -20,68 +83,12 @@ After creating an `OrbitDB` instance , you can access the different data stores.
const db = await orbitdb.keyvalue('profile')
```
**Public OrbitDB Instance Methods**
- [orbitdb.create(name, type, [options])](#orbitdbcreatename-type-options)
- [orbitdb.open(name|address, [options])](#orbitdbopenaddress-options)
- [orbitdb.disconnect()](#orbitdbdisconnect)
- [orbitdb.stop()](#orbitdbstop)
- [orbitdb.keyvalue(name|address)](#orbitdbkeyvaluenameaddress)
- [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)
- [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.docstore(name|address, options)](#orbitdbdocstorenameaddress-options)
- [orbitdb.counter(name|address)](#orbitdbcounternameaddress)
- [counter.value](#value)
- [counter.inc([value])](#incvalue)
**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()](#storeloadamount)
- [store.close()](#storeclose)
- [store.drop()](#storedrop)
- [store.key](#storekey)
- [store.type](#storetype)
**[Store Events](#storeevents)**
- [replicated](#replicated)
- [replicate](#replicate)
- [replicate.progress](#replicateprogress)
- [load](#load)
- [load.progress](#loadprogress)
- [ready](#ready)
- [write](#write)
- [closed](#closed)
## 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:
Returns a `Promise` that resolves to [a database instance](#store-api). `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`)
@ -99,7 +106,7 @@ const db = await orbitdb.create('user.posts', 'eventlog', {
### orbitdb.open(address, [options])
> Opens an OrbitDB database.
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:
Returns a `Promise` that resolves to [a database instance](#store-api). `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).
@ -146,7 +153,7 @@ 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.**
**See the [Store](#store-api) 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.
@ -184,7 +191,7 @@ 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.**
**See the [Store](#store-api) section for details of common methods and properties.**
#### add(event)
Returns a `Promise` that resolves to the multihash of the entry as a `String`.
@ -244,7 +251,7 @@ 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.
See the [Store](#store-api) section for details of common methods and properties.
#### add(data)
Returns a `Promise` that resolves to the multihash of the entry as a `String`.
@ -312,7 +319,7 @@ 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.**
**See the [Store](#store-api) section for details of common methods and properties.**
#### put(doc)
Returns a `Promise` that resolves to the multihash of the entry as a `String`.
@ -358,7 +365,7 @@ 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.**
**See the [Store](#store-api) section for details of common methods and properties.**
#### value
Returns a `Number`.
@ -426,11 +433,11 @@ OrbitDB.parseAddress('/orbitdb/Qmdgwt7w4uBsw8LXduzCd18zfGXeTmBsiR8edQ1hSfzcJC/fi
// path: 'first-database' }
```
## Store
## Store API
Every database (store) has the following methods available in addition to their specific methods.
#### store.load([amount])
### store.load([amount])
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)
@ -450,7 +457,7 @@ await db.load()
/* database is now ready to be queried */
```
#### store.close()
### store.close()
> Close the database.
Returns a `Promise` that resolves once complete
@ -459,7 +466,7 @@ Async:
await db.close()
```
#### store.drop()
### store.drop()
> Remove the database locally. This does not delete any data from peers.
Returns a `Promise` that resolves once complete
@ -468,7 +475,7 @@ Returns a `Promise` that resolves once complete
await db.drop()
```
#### store.key
### store.key
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.
@ -486,27 +493,27 @@ console.log(db.key.getPublic('hex'))
// 04d009bd530f2fa0cda29202e1b15e97247893cb1e88601968abfe787f7ea03828fdb7624a618fd67c4c437ad7f48e670cc5a6ea2340b896e42b0c8a3e4d54aebe
```
The key can also be accessed from the [OrbitDB](#orbitdb) instance: `orbitdb.key.getPublic('hex')`.
The key can also be accessed from the OrbitDB instance: `orbitdb.key.getPublic('hex')`.
#### store.type
### store.type
Returns the type of the database as a `String`.
### Store 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`
### `replicated`
```javascript
db.events.on('replicated', (address) => ... )
```
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`
### `replicate`
```javascript
db.events.on('replicate', (address) => ... )
```
@ -520,7 +527,7 @@ 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) => ... )
```
@ -534,21 +541,21 @@ 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, heads) => ... )
```
Emitted after fully loading the local database.
#### `write`
### `write`
```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.
#### `closed`
### `closed`
Emitted once the database has finished closing.
```javascript
db.events.on('closed', (dbname) => ... )

View File

@ -1,5 +1,26 @@
# Changelog
## Table of Contents
<!-- toc -->
- [v0.19.0](#v0190)
* [Replication](#replication)
* [Browser compatibility](#browser-compatibility)
* [LevelDB](#leveldb)
* [General Updates](#general-updates)
* [Performance](#performance)
- [v0.18.0](#v0180)
* [Write-permissions](#write-permissions)
* [Addresses](#addresses)
* [Replication](#replication-1)
* [Performance](#performance-1)
* [Documentation and Examples](#documentation-and-examples)
* [Code Base Improvements](#code-base-improvements)
- [v0.12.0](#v0120)
<!-- tocstop -->
## v0.19.0
This release bring a bunch of fixes and updates improving performance, stability and browser compatibility. As always, we highly encourage to update to the latest version and report any problems in https://github.com/orbitdb/orbit-db/issues.

View File

@ -6,20 +6,25 @@ This guide is still being worked on and we would love to get [feedback and sugge
## Table of Contents
<!-- toc -->
- [Background](#background)
- [Install](#install)
- [Setup](#setup)
- [Create a database](#create-a-database)
- [Address](#address)
- [Manifest](#manifest)
- [Keys](#keys)
- [Access Control](#access-control)
- [Public databases](#public-databases)
* [Address](#address)
+ [Manifest](#manifest)
* [Keys](#keys)
* [Access Control](#access-control)
+ [Public databases](#public-databases)
- [Add an entry](#add-an-entry)
- [Get an entry](#get-an-entry)
- [Persistency](#persistency)
- [Replicating a database](#replicating-a-database)
- [Custom Database Stores](#custom-stores)
- [Custom Stores](#custom-stores)
- [More information](#more-information)
<!-- tocstop -->
## Background
@ -66,7 +71,7 @@ ipfs.on('ready', () => {
})
```
`orbitdb` is now the [OrbitDB](#orbitdb) instance we can use to interact with the databases.
`orbitdb` is now the OrbitDB instance we can use to interact with the databases.
## Create a database

View File

@ -28,17 +28,30 @@ This is the Javascript implementation and it works both in **Browsers** and **No
## Table of Contents
<!-- toc -->
- [Usage](#usage)
- [CLI](#cli)
- [Module with IPFS Instance](#module-with-ipfs-instance)
- [Module with IPFS Daemon](#module-with-ipfs-daemon)
* [CLI](#cli)
* [Module with IPFS Instance](#module-with-ipfs-instance)
* [Module with IPFS Daemon](#module-with-ipfs-daemon)
- [API](#api)
- [Examples](#examples)
* [Install dependencies](#install-dependencies)
* [Browser example](#browser-example)
* [Node.js example](#nodejs-example)
- [Packages](#packages)
* [OrbitDB Store Packages](#orbitdb-store-packages)
- [Development](#development)
* [Run Tests](#run-tests)
* [Build](#build)
* [Benchmark](#benchmark)
* [Logging](#logging)
- [Contributing](#contributing)
- [Sponsors](#sponsors)
- [License](#license)
<!-- tocstop -->
## Usage
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.
@ -126,20 +139,6 @@ const db = await orbitdb.log('hello')
See [API.md](https://github.com/orbitdb/orbit-db/blob/master/API.md) for the full documentation.
### constructor(ipfs, [directory], [options])
```javascript
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.
*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).*
## Examples
### Install dependencies
@ -212,7 +211,7 @@ OrbitDB uses the following modules:
- [orbit-db-pubsub](https://github.com/orbitdb/orbit-db-pubsub)
- [orbit-db-keystore](https://github.com/orbitdb/orbit-db-keystore)
##### OrbitDB Store Packages
### 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)
@ -224,24 +223,24 @@ To understand a little bit about the architecture, check out a visualization of
## Development
#### Run Tests
### Run Tests
```
npm test
```
#### Build
### Build
```
npm run build
```
#### Benchmark
### Benchmark
```
node benchmarks/benchmark-add.js
```
See [benchmarks/](https://github.com/orbitdb/orbit-db/tree/master/benchmarks) for more benchmarks.
#### Logging
### Logging
To enable OrbitDB's logging output, set a global ENV variable called `LOG` to `debug`,`warn` or `error`:

1372
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -37,9 +37,12 @@
"ipfs": "~0.30.0",
"ipfs-repo": "~0.22.1",
"ipfsd-ctl": "^0.37.5",
"markdown-toc": "^1.2.0",
"mocha": "^4.0.1",
"p-each-series": "^1.0.0",
"p-map-series": "^1.0.0",
"remark-cli": "^5.0.0",
"remark-validate-links": "^7.0.0",
"rimraf": "^2.6.2",
"uglifyjs-webpack-plugin": "^1.1.4",
"webpack": "^3.8.1"
@ -49,11 +52,13 @@
"examples:node": "node examples/eventlog.js",
"examples:browser-macos": "open examples/browser/browser.html",
"examples:browser-linux": "xdg-open examples/browser/browser.html",
"lint:docs": "remark -qf -u validate-links .",
"test": "TEST=all mocha",
"build": "npm run build:es5 && npm run build:debug && npm run build:dist && npm run build:examples",
"build": "npm run build:es5 && npm run build:debug && npm run build:dist && npm run build:examples && npm run build:docs/toc",
"build:examples": "webpack --config conf/webpack.example.config.js --sort-modules-by size && mkdir -p examples/browser/lib && cp node_modules/ipfs/dist/index.js examples/browser/lib/ipfs.js",
"build:dist": "webpack --config conf/webpack.config.js --sort-modules-by size && mkdir -p examples/browser/lib && cp dist/orbitdb.min.js examples/browser/lib/orbitdb.min.js",
"build:debug": "webpack --config conf/webpack.debug.config.js --sort-modules-by size && mkdir -p examples/browser/lib && cp dist/orbitdb.js examples/browser/lib/orbitdb.js && cp dist/orbitdb.js.map examples/browser/lib/orbitdb.js.map",
"build:docs/toc": "markdown-toc --no-first1 -i README.md && markdown-toc --no-first1 -i API.md && markdown-toc --no-first1 -i GUIDE.md && markdown-toc --no-first1 -i CHANGELOG.md",
"build:es5": "babel src --out-dir ./dist/es5/ --presets babel-preset-es2015 --plugins babel-plugin-transform-runtime"
}
}