You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 30, 2023. It is now read-only.
# This is the 1st commit message:
# This is a combination of 2 commits.
# This is the 1st commit message:
docs(README): add TOC & update API
# This is the commit message #2:
docs: clarify load & replicated events
# This is the commit message #2:
docs: update constructor params
*[Creating Custom Data Stores](#creating-custom-data-stores)
42
+
-[Contributing](#contributing)
43
+
-[License](#license)
23
44
24
-
Load the database using locally persisted state. Can specify how many entries to load with `amount` argument.
45
+
<!-- tocstop -->
25
46
26
-
##### `saveSnapshot()`
47
+
##API
27
48
28
-
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.
**ipfs** can be an [IPFS](https://github.com/ipfs/js-ipfs) instance or an [IPFS-API](https://github.com/ipfs/js-ipfs) instance. **identity** is an instance of [Identity](https://github.com/orbitdb/orbit-db-identity-provider/). **address** is the OrbitDB address to be used for the store.
31
52
32
-
Load the state of the database from a snapshot. *hash*is the IPFS Multihash of the snapshot data. Returns a *Promise* that resolves when the database has been loaded.
53
+
`options`is an object with the following required properties:
33
54
34
-
##### `close()`
55
+
-`cache`: A [Cache](https://github.com/orbitdb/orbit-db-cache) instance to use for storing heads and snapshots.
56
+
-`Index` : By default it uses an instance of [Index](https://github.com/orbitdb/orbit-db-store/blob/master/src/Index.js).
35
57
36
-
Uninitialize the store. Emits `close` after the store has been uninitialized.
58
+
the following properties are optional:
37
59
38
-
##### `drop()`
60
+
-`maxHistory` (Integer): The number of entries to load (Default: `-1`).
61
+
-`referenceCount` (Integer): The number of previous ipfs-log entries a new entry should reference (Default: `64`).
62
+
-`replicationConcurrency` (Integer): The number of concurrent replication processes (Default: `128`).
63
+
-`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.
64
+
-`onClose` (Function): A function to be called with a string of the OrbitDB address of the database that is closing.
39
65
40
-
Remove the database locally. This doesn't remove or delete the database from peers who have replicated the database.
66
+
### Public methods
41
67
42
-
##### `sync(heads)`
68
+
#### load([amount])
69
+
> Load the database using locally persisted state.
43
70
44
-
Sync this database with entries from *heads* where *heads* is an array of ipfs-log Entries. Usually, you don't need to call this method manually as OrbitDB takes care of this for you.
71
+
Returns a **Promise** that resolves once complete. Provide an `amount` argument to specify how many entries to load.
45
72
46
-
#### Properties
73
+
#### loadMoreFrom(amount, entries)
74
+
> TODO
47
75
48
-
##### `address`
76
+
```javascript
77
+
//TODO
78
+
db.loadMoreFrom()
79
+
```
80
+
81
+
#### saveSnapshot()
82
+
> Save the current state of the database locally.
83
+
84
+
Returns a **Promise** that resolves to an array containing an object with the following properties:
85
+
86
+
-`path` of the snapshot file
87
+
-`hash` representing the IPFS Multihash (as a Base58 encoded string) of the snapshot file
88
+
-`size` of the snapshot file
89
+
90
+
#### loadFromSnapshot()
91
+
> Load the state of the database from a snapshot.
92
+
93
+
Returns a **Promise** that resolves to a store instance once it has been loaded.
94
+
95
+
#### close()
96
+
> Uninitialize the store.
97
+
98
+
Returns a **promise** that resolves once complete. Emits `close` after the store has been uninitialized.
49
99
50
-
Get the address of this database. Returns an object `{ root: <manifestHash>, path: <path> }`. Convert to a string with `db.address.toString()`.
100
+
#### drop()
101
+
> Remove the database locally.
102
+
103
+
Returns a **promise** that resolves once complete. This doesn't remove or delete the database from peers who have replicated the database.
104
+
105
+
#### sync(heads)
106
+
> Sync this database with entries from **heads** where **heads** is an array of ipfs-log Entries.
107
+
108
+
Usually, you don't need to call this method manually as OrbitDB takes care of this for you.
109
+
110
+
### Properties
111
+
112
+
#### address
113
+
> Get the address of this database.
114
+
115
+
Returns an object `{ root: <manifestHash>, path: <path> }`. Convert to a string with `db.address.toString()`.
Store has an `events` ([EventEmitter](https://nodejs.org/api/events.html)) object that emits events that describe what's happening in the database.
86
162
87
-
-`load` - (dbname, hash)
163
+
-`load` - (address, heads)
88
164
89
-
Emitted before loading the database history. *hash* is the hash from which the history is loaded.
165
+
Emitted before loading the database history. **address** is a string of the OrbitDB address being loaded. **heads** is an array of ipfs-log Entries from which the history is loaded from. **heads** is omitted when this event is emitted as a result of `loadFromSnapshot`.
90
166
91
167
```javascript
92
-
db.events.on('load', (id, hash) =>... )
168
+
db.events.on('load', (address, heads) =>... )
93
169
db.load()
94
170
```
95
171
96
-
-`ready`- (dbname)
172
+
-`ready`- (address, heads)
97
173
98
-
Emitted after fully loading the database history.
174
+
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.
*Progress* is the current load count. *Total* is the maximum load count (ie. lengthof the full database). These are useful eg. for displaying a load progress percentage.
183
+
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. lengthof the full database). These are useful eg. for displaying a load progress percentage.
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.
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.
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. **count** number of items replicated. **count** is omitted when thisevent is emitted as a result of`loadFromSnapshot`.
Emitted after the databasewas synced withan update from a peer database.
216
+
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.
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.
224
+
Emitted once the database has finished closing. **address** is a string of the OrbitDB address that emitted the event.
127
225
128
226
```javascript
129
-
db.events.on('write', (id, hash, entry) => ... )
227
+
db.events.on('closed', (address) => ... )
228
+
db.close()
130
229
```
131
230
132
-
#### Private methods
231
+
### Private methods
133
232
134
-
##### `_addOperation(data)`
233
+
#### _addOperation(data)
234
+
> Add an entry to the store.
135
235
136
-
Add an entry to the store. Takes`data` as a parameter which can be of any type.
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.
137
237
138
238
```javascript
139
239
this._addOperation({
@@ -153,9 +253,9 @@ const Store = require('orbit-db-store');
0 commit comments