Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Commit

Permalink
docs: update & fix README
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakia committed Aug 12, 2018
1 parent 84aa809 commit ca94bb0
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 17 deletions.
78 changes: 63 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,42 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You

### API

#### constructor(ipfs, peerId, address, options)

```javascript
//TODO
const store = new Store(ipfs, peerId, address, options)
```

`options` is an object with any of the following properties

- `Index` ():
- `maxHistory` (Integer):
- `path` (String):
- `replicate` (Boolean):
- `referenceCount` (Integer):
- `replicationConcurrency` (Integer):
- `cache` ():
- `keystore` ():
- `key` ():
- `accessController` ():
- `onClose` (Function):

#### Public methods

##### `load(amount)`

Load the database using locally persisted state. Can specify how many entries to load with `amount` argument.

##### `loadMoreFrom(amount, entries)`

TODO

```javascript
//TODO
db.loadMoreFrom()
```

##### `saveSnapshot()`

Save the current state of the database locally. Returns a *Promise* that resolves to a IPFS Multihash as a Base58 encoded string. The the database can be loaded using this hash.
Expand Down Expand Up @@ -63,6 +93,14 @@ console.log(db.key.toPublic('hex'))
// 042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839
```

##### `all`

Returns an array of all store entries.

```javascript
db.all
```

##### `type`

Remove all items from the local store. This doesn't remove or delete any entries in the distributed operations log.
Expand All @@ -84,51 +122,61 @@ console.log(db.replicationStatus)

Store has an `events` ([EventEmitter](https://nodejs.org/api/events.html)) object that emits events that describe what's happening in the database.

- `load` - (dbname, hash)
- `load` - (address, heads)

Emitted before loading the database history. *hash* is the hash from which the history is loaded from.
Emitted before loading the database history. *address* ... *heads* ...

```javascript
db.events.on('load', (id, hash) => ... )
db.events.on('load', (address, hash) => ... )
db.load()
```

- `ready` - (dbname)
- `ready` - (address, heads)

Emitted after fully loading the database history.
Emitted after fully loading the database history. *address* ... *heads* ...

```javascript
db.events.on('ready', (id) => ... )
db.events.on('ready', (address) => ... )
db.load()
```

- `load.progress` - (id, hash, entry, progress, total)
- `load.progress` - (address, hash, entry, progress, total)

Emitted for each entry during load.

*Progress* is the current load count. *Total* is the maximum load count (ie. length of the full database). These are useful eg. for displaying a load progress percentage.

```javascript
db.events.on('load', (id, hash, entry, progress, total) => ... )
db.events.on('load.progress', (address, hash, entry, progress, total) => ... )
db.load()
```

- `replicated` - (dbname)
- `replicate` - (address, entry) => ... )

Emitted while the database is syncing and an entry has been added.

- `replicate.progress` - (address, hash, entry, progress, total) => ... )

//TODO

- `replicated` - (address, logCount) => ... )

Emitted after the database was synced with an update from a peer database.

```javascript
db.events.on('replicated', (id) => ... )
db.events.on('replicated', (address) => ... )
```

- `write` - (id, hash, entry)
- `write` - (address, entry, heads)

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 Entry that was added.
Emitted after an entry was added locally to the database. *entry* is the Entry that was added. *heads* ...

```javascript
db.events.on('write', (id, hash, entry) => ... )
db.events.on('write', (address, hash, entry) => ... )
```

- `closed` - (address)

#### Private methods

##### `_addOperation(data)`
Expand All @@ -153,9 +201,9 @@ const Store = require('orbit-db-store');
const KeyValueIndex = require('./KeyValueIndex');
class KeyValueStore extends Store {
constructor(ipfs, id, dbname, options) {
constructor(ipfs, peerId, address, options) {
Object.assign(options || {}, { Index: KeyValueIndex });
super(ipfs, id, dbname, options)
super(ipfs, peerId, address, options)
}
get(key) {
Expand Down
4 changes: 2 additions & 2 deletions src/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class Store {
}

async loadFromSnapshot (onProgressCallback) {
this.events.emit('load', this.address.toString())
this.events.emit('load', this.address.toString()) //TODO: inconsistent params, line 207

const maxClock = (res, val) => Math.max(res, val.clock.time)

Expand Down Expand Up @@ -400,7 +400,7 @@ class Store {
const log = await Log.fromJSON(this._ipfs, snapshotData, -1, this._key, this.access.write, 1000, onProgress)
await this._oplog.join(log)
await this._updateIndex()
this.events.emit('replicated', this.address.toString())
this.events.emit('replicated', this.address.toString()) //TODO: inconsistent params, line 116
}
this.events.emit('ready', this.address.toString(), this._oplog.heads)
} else {
Expand Down

0 comments on commit ca94bb0

Please sign in to comment.