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

Commit 673d3b3

Browse files
committed
docs: update README
1 parent 856215f commit 673d3b3

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

README.md

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You
2020
<!-- toc -->
2121

2222
- [API](#api)
23-
* [constructor(ipfs, peerId, address, options)](#constructoripfs-peerid-address-options)
23+
* [constructor(ipfs, identity, address, options)](#constructoripfs-identity-address-options)
2424
* [Public methods](#public-methods)
25-
+ [load([amount])](#loadamount)
25+
+ [load([amount], [opts])](#loadamount-opts)
2626
+ [loadMoreFrom(amount, entries)](#loadmorefromamount-entries)
27+
+ [setIdentity (identity)](#setidentity-identity)
2728
+ [saveSnapshot()](#savesnapshot)
2829
+ [loadFromSnapshot()](#loadfromsnapshot)
2930
+ [close()](#close)
3031
+ [drop()](#drop)
3132
+ [sync(heads)](#syncheads)
3233
* [Properties](#properties)
3334
+ [address](#address)
34-
+ [key](#key)
35+
+ [identity](#identity)
3536
+ [all](#all)
3637
+ [type](#type)
3738
+ [replicationStatus](#replicationstatus)
3839
* [Events](#events)
3940
* [Private methods](#private-methods)
40-
+ [_addOperation(data)](#_addoperationdata)
41+
+ [_addOperation(data, [options])](#_addoperationdata-options)
4142
* [Creating Custom Data Stores](#creating-custom-data-stores)
4243
- [Contributing](#contributing)
4344
- [License](#license)
@@ -58,17 +59,22 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You
5859
the following properties are optional:
5960

6061
- `maxHistory` (Integer): The number of entries to load (Default: `-1`).
62+
- `syncLocal` (Boolean): Load local database before performing any append operations. (Default: `false`).
63+
- `fetchEntryTimeout` (Integer): The number in `ms` specifying a timeout when fetching entries from IPFS. (Default: `null`).
6164
- `referenceCount` (Integer): The number of previous ipfs-log entries a new entry should reference (Default: `64`).
6265
- `replicationConcurrency` (Integer): The number of concurrent replication processes (Default: `128`).
6366
- `accessController` (Object): An instance of AccessController with the following [interface](https://github.com/orbitdb/orbit-db-access-controllers/blob/master/src/access-controller-interface.js). See [orbit-db-access-controllers](https://github.com/orbitdb/orbit-db-access-controllers) for more information on how to create custom access controllers. By default only the owner will have write access.
67+
- `sortFn` (Function): A function used to sort ipfs-log entries (Default: `undefined`).
6468
- `onClose` (Function): A function to be called with a string of the OrbitDB address of the database that is closing.
69+
- `onDrop` (Function): A function to be called with the orbit-db-store instance when the database is being removed.
70+
- `onLoad` (Function): A function to be called with the orbit-db-store instance when the database is being loaded.
6571

6672
### Public methods
6773

68-
#### load([amount])
74+
#### load([amount], [opts])
6975
> Load the database using locally persisted state.
7076
71-
Returns a **Promise** that resolves once complete. Provide an `amount` argument to specify how many entries to load.
77+
Returns a **Promise** that resolves once complete. Provide an optional `amount` argument to specify how many entries to load. By default the `maxHistory` option is used. Provide an optional `options` object with a `fetchEntryTimeout` property to be used when loading entries from IPFS.
7278

7379
#### loadMoreFrom(amount, entries)
7480
> TODO
@@ -78,6 +84,10 @@ Returns a **Promise** that resolves once complete. Provide an `amount` argument
7884
db.loadMoreFrom()
7985
```
8086

87+
#### setIdentity (identity)
88+
> Set the identity for the database
89+
90+
8191
#### saveSnapshot()
8292
> Save the current state of the database locally.
8393
@@ -119,7 +129,7 @@ console.log(db.address.toString())
119129
// /orbitdb/zdpuB383kQWjyCd5nv4FKqZwe2FH4nqxBBE7kzoDrmdtZ6GPu/databaseName
120130
```
121131

122-
##### `identity`
132+
#### identity
123133

124134
Each store has an `identity` property containing the public key used with this store to sign and access entries. This `publicKey` property of `identity` is the peer/node/user key.
125135

@@ -230,10 +240,13 @@ console.log(db.replicationStatus)
230240

231241
### Private methods
232242

233-
#### _addOperation(data)
243+
#### `_addOperation(data, [options])`
234244
> Add an entry to the store.
235245

236-
Returns a **Promise** that resolves to the IPFS Multihash of the added entry. Takes `data` as a parameter which can be of any type.
246+
Returns a **Promise** that resolves to the IPFS Multihash of the added entry. Takes `data` as a parameter which can be of any type. Provide an optional `options` arguement, which is an object with the following properties:
247+
248+
- `onProgressCallback` (Function): To be called once the data is appended.
249+
- `pin` (Boolean): To specify whether or not to pin the entry in IPFS. (Default: `false`).
237250

238251
```javascript
239252
this._addOperation({

src/Store.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ const DefaultOptions = {
2121
Index: Index,
2222
maxHistory: -1,
2323
fetchEntryTimeout: null,
24-
replicate: true,
2524
referenceCount: 32,
2625
replicationConcurrency: 128,
2726
syncLocal: false,
@@ -227,9 +226,13 @@ class Store {
227226
this._cache = this.options.cache
228227
}
229228

230-
async load (amount, { fetchEntryTimeout } = {}) {
229+
async load (amount, opts = {}) {
230+
if (typeof amount === 'object') {
231+
opts = amount
232+
amount = undefined
233+
}
231234
amount = amount || this.options.maxHistory
232-
fetchEntryTimeout = fetchEntryTimeout || this.options.fetchEntryTimeout
235+
const fetchEntryTimeout = opts.fetchEntryTimeout || this.options.fetchEntryTimeout
233236

234237
if (this.options.onLoad) {
235238
await this.options.onLoad(this)
@@ -380,7 +383,7 @@ class Store {
380383
await this.options.onLoad(this)
381384
}
382385

383-
this.events.emit('load', this.address.toString()) //TODO: inconsistent params
386+
this.events.emit('load', this.address.toString()) // TODO emits inconsistent params, missing heads param
384387

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

0 commit comments

Comments
 (0)