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

Commit e782db5

Browse files
committed
docs: update & fix README
1 parent 84aa809 commit e782db5

File tree

2 files changed

+82
-21
lines changed

2 files changed

+82
-21
lines changed

README.md

Lines changed: 80 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,42 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You
1717

1818
### API
1919

20+
#### constructor(ipfs, peerId, address, options)
21+
22+
```javascript
23+
//TODO
24+
const store = new Store(ipfs, peerId, address, options)
25+
```
26+
27+
`options` is an object with any of the following properties
28+
29+
- `Index` ():
30+
- `maxHistory` (Integer):
31+
- `path` (String):
32+
- `replicate` (Boolean):
33+
- `referenceCount` (Integer):
34+
- `replicationConcurrency` (Integer):
35+
- `cache` ():
36+
- `keystore` ():
37+
- `key` ():
38+
- `accessController` ():
39+
- `onClose` (Function):
40+
2041
#### Public methods
2142

2243
##### `load(amount)`
2344

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

47+
##### `loadMoreFrom(amount, entries)`
48+
49+
TODO
50+
51+
```javascript
52+
//TODO
53+
db.loadMoreFrom()
54+
```
55+
2656
##### `saveSnapshot()`
2757

2858
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.
@@ -63,6 +93,14 @@ console.log(db.key.toPublic('hex'))
6393
// 042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839
6494
```
6595

96+
##### `all`
97+
98+
Returns an array of all store entries.
99+
100+
```javascript
101+
db.all
102+
```
103+
66104
##### `type`
67105

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

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

87-
- `load` - (dbname, hash)
125+
- `load` - (address, heads)
88126

89-
Emitted before loading the database history. *hash* is the hash from which the history is loaded from.
127+
Emitted before loading the database history. *address* is a string of the OrbitDB address that emitted the event. *heads* is an array of ipfs-log Entries.
90128

91129
```javascript
92-
db.events.on('load', (id, hash) => ... )
130+
db.events.on('load', (address, heads) => ... )
93131
db.load()
94132
```
95133

96-
- `ready` - (dbname)
134+
- `ready` - (address, heads)
97135

98-
Emitted after fully loading the database history.
136+
Emitted after fully loading the database history. *address* is a string of the OrbitDB address that emitted the event. *heads* is an array of ipfs-log Entries.
99137

100138
```javascript
101-
db.events.on('ready', (id) => ... )
139+
db.events.on('ready', (address, heads) => ... )
102140
db.load()
103141
```
104142

105-
- `load.progress` - (id, hash, entry, progress, total)
143+
- `load.progress` - (address, hash, entry, progress, total)
106144

107-
Emitted for each entry during load.
108-
109-
*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.
145+
Emitted for each entry during load. *address* is a string of the OrbitDB address that emitted the event. *hash* is the multihash of the entry that was just loaded. *entry* is the ipfs-log Entry that was loaded. *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.
110146

111147
```javascript
112-
db.events.on('load', (id, hash, entry, progress, total) => ... )
148+
db.events.on('load.progress', (address, hash, entry, progress, total) => ... )
113149
db.load()
114150
```
115151

116-
- `replicated` - (dbname)
152+
- `replicate` - (address, entry)
153+
154+
Emitted before replicating a part of the database. *address* is a string of the OrbitDB address that emitted the event. *entry* is the ipfs-log Entry that is being processed.
155+
156+
```javascript
157+
db.events.on('replicate', (address, entry) => ... )
158+
```
159+
160+
- `replicate.progress` - (address, hash, entry, progress, total)
161+
162+
Emitted while replicating a database. *address* is a string of the OrbitDB address of the database that emitted the event. *hash* is the multihash of the entry that was just replicated. *entry* is the ipfs-log Entry that was replicated. *progress* is an integer representing the current progress. *total* is an integer representing the remaining operations.
163+
164+
```javascript
165+
db.events.on('replicate.progress', (address, hash, entry, progress, total) => ... )
166+
```
167+
168+
- `replicated` - (address, logCount)
169+
170+
Emitted after the database was synced with an update from a peer database. *address* is a string of the OrbitDB address that emitted the event. *logCount* ...
171+
172+
```javascript
173+
db.events.on('replicated', (address, logCount) => ... )
174+
```
175+
176+
- `write` - (address, entry, heads)
117177

118-
Emitted after the database was synced with an update from a peer database.
178+
Emitted after an entry was added locally to the database. *address* is a string of the OrbitDB address that emitted the event. *entry* is the Entry that was added. *heads* is an array of ipfs-log Entries.
119179

120180
```javascript
121-
db.events.on('replicated', (id) => ... )
181+
db.events.on('write', (address, entry, heads) => ... )
122182
```
123183

124-
- `write` - (id, hash, entry)
184+
- `closed` - (address)
125185

126-
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.
186+
Emitted once the database has finished closing. *address* is a string of the OrbitDB address that emitted the event.
127187

128188
```javascript
129-
db.events.on('write', (id, hash, entry) => ... )
189+
db.events.on('closed', (address) => ... )
190+
db.close()
130191
```
131192

132193
#### Private methods
@@ -153,9 +214,9 @@ const Store = require('orbit-db-store');
153214
const KeyValueIndex = require('./KeyValueIndex');
154215
155216
class KeyValueStore extends Store {
156-
constructor(ipfs, id, dbname, options) {
217+
constructor(ipfs, peerId, address, options) {
157218
Object.assign(options || {}, { Index: KeyValueIndex });
158-
super(ipfs, id, dbname, options)
219+
super(ipfs, peerId, address, options)
159220
}
160221
161222
get(key) {

src/Store.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class Store {
310310
}
311311

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

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

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

0 commit comments

Comments
 (0)