From 577c6d86088b207edd756211834c07763f1945c8 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Sun, 12 Aug 2018 10:03:32 -0400 Subject: [PATCH 1/6] docs(README): add TOC & update API --- README.md | 188 +++++++++++++++++++++++++++++++++++++++------------ package.json | 4 +- src/Store.js | 6 +- 3 files changed, 151 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index e153a84..63667c2 100644 --- a/README.md +++ b/README.md @@ -15,39 +15,106 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You - Node.js >= 8.0.0 -### API +## Table of Contents -#### Public methods + -##### `load(amount)` +- [API](#api) + * [constructor(ipfs, peerId, address, options)](#constructoripfs-peerid-address-options) + * [Public methods](#public-methods) + + [load([amount])](#loadamount) + + [loadMoreFrom(amount, entries)](#loadmorefromamount-entries) + + [saveSnapshot()](#savesnapshot) + + [loadFromSnapshot()](#loadfromsnapshot) + + [close()](#close) + + [drop()](#drop) + + [sync(heads)](#syncheads) + * [Properties](#properties) + + [address](#address) + + [key](#key) + + [all](#all) + + [type](#type) + + [replicationStatus](#replicationstatus) + * [Events](#events) + * [Private methods](#private-methods) + + [_addOperation(data)](#_addoperationdata) + * [Creating Custom Data Stores](#creating-custom-data-stores) +- [Contributing](#contributing) +- [License](#license) -Load the database using locally persisted state. Can specify how many entries to load with `amount` argument. + -##### `saveSnapshot()` +## API -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. +### constructor(ipfs, peerId, address, options) -##### `loadFromSnapshot(hash, onProgressCallback)` +**ipfs** can be an [IPFS](https://github.com/ipfs/js-ipfs) instance or an [IPFS-API](https://github.com/ipfs/js-ipfs) instance. **peerId** is a string identifying the peer, usually the base58 string of the [PeerId](https://github.com/libp2p/js-peer-id#tob58string) of the IPFS instance. **address** is the OrbitDB address to be used for the store. -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. +`options` is an object with the following required properties: -##### `close()` +- `cache`: A [Cache](https://github.com/orbitdb/orbit-db-cache) instance to use for storing heads and snapshots. +- `Index` : By default it uses an instance of [Index](https://github.com/orbitdb/orbit-db-store/blob/master/src/Index.js). +- `keystore`: A [Keystore](https://github.com/orbitdb/orbit-db-keystore) instance to use for key management. -Uninitialize the store. Emits `close` after the store has been uninitialized. +the following properties are optional: -##### `drop()` +- `maxHistory` (Integer): The number of entries to load (Default: `-1`). +- `referenceCount` (Integer): The number of previous ipfs-log entries a new entry should reference (Default: `64`). +- `replicationConcurrency` (Integer): The number of concurrent replication processes (Default: `128`). +- `key`: A [KeyPair](https://github.com/indutny/elliptic/blob/master/lib/elliptic/ec/key.js#L8) instance. By default the provided keystore is used to find an existing KeyPair for the given `peerId`, otherwise a new KeyPair will be created using the given `peerId`. +- `accessController` (Object): By default only the owner will have write access. +- `onClose` (Function): A function to be called with a string of the OrbitDB address of the database that is closing. -Remove the database locally. This doesn't remove or delete the database from peers who have replicated the database. +### Public methods -##### `sync(heads)` +#### load([amount]) +> Load the database using locally persisted state. -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. +Returns a **Promise** that resolves once complete. Provide an `amount` argument to specify how many entries to load. -#### Properties +#### loadMoreFrom(amount, entries) +> TODO -##### `address` +```javascript +//TODO +db.loadMoreFrom() +``` + +#### saveSnapshot() +> Save the current state of the database locally. + +Returns a **Promise** that resolves to an array containing an object with the following properties: + +- `path` of the snapshot file +- `hash` representing the IPFS Multihash (as a Base58 encoded string) of the snapshot file +- `size` of the snapshot file + +#### loadFromSnapshot() +> Load the state of the database from a snapshot. + +Returns a **Promise** that resolves to a store instance once it has been loaded. + +#### close() +> Uninitialize the store. + +Returns a **promise** that resolves once complete. Emits `close` after the store has been uninitialized. -Get the address of this database. Returns an object `{ root: , path: }`. Convert to a string with `db.address.toString()`. +#### drop() +> Remove the database locally. + +Returns a **promise** that resolves once complete. This doesn't remove or delete the database from peers who have replicated the database. + +#### sync(heads) +> 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. + +### Properties + +#### address +> Get the address of this database. + +Returns an object `{ root: , path: }`. Convert to a string with `db.address.toString()`. ```javascript console.log(db.address.toString()) @@ -63,17 +130,28 @@ console.log(db.identity.publicKey) // 042c07044e7ea51a489c02854db5e09f0191690dc59db0afd95328c9db614a2976e088cab7c86d7e48183191258fc59dc699653508ce25bf0369d67f33d5d77839 ``` -##### `type` +#### all +> Get all of the entries in the store index + +Returns an array of all store entries within the index. + +```javascript +db.all +``` + +#### type +> Get the store type -The type of datastore model of the current instance. +Returns a string of the type of datastore model of the current instance. ```javascript console.log(db.type) // "eventlog" ``` -##### `replicationStatus` +#### replicationStatus +> Get database replication status information such as total number of entries and loading progress. -Get database replication status information such as total number of entries and loading progress. +Returns an instance of [ReplicationInfo](https://github.com/orbitdb/orbit-db-store/blob/master/src/replication-info.js). ```javascript console.log(db.replicationStatus) @@ -84,56 +162,80 @@ 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. + 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. ```javascript - db.events.on('load', (id, hash) => ... ) + db.events.on('load', (address, heads) => ... ) db.load() ``` - - `ready` - (dbname) + - `ready` - (address, heads) - Emitted after fully loading the database history. + 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. ```javascript - db.events.on('ready', (id) => ... ) + db.events.on('ready', (address, heads) => ... ) db.load() ``` - - `load.progress` - (id, hash, entry, progress, total) - - Emitted for each entry during load. + - `load.progress` - (address, hash, entry, progress, total) - *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. + 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. ```javascript - db.events.on('load.progress', (id, hash, entry, progress, total) => ... ) + db.events.on('load.progress', (address, hash, entry, progress, total) => ... ) db.load() ``` - - `replicated` - (dbname) + - `replicate` - (address, entry) + + 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. + + ```javascript + db.events.on('replicate', (address, entry) => ... ) + ``` + + - `replicate.progress` - (address, hash, entry, progress, total) + + 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. + + ```javascript + db.events.on('replicate.progress', (address, hash, entry, progress, total) => ... ) + ``` + + - `replicated` - (address, logCount) + + 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** ... + + ```javascript + db.events.on('replicated', (address, logCount) => ... ) + ``` + + - `write` - (address, entry, heads) - Emitted after the database was synced with an update from a peer database. + 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. ```javascript - db.events.on('replicated', (id, length) => ... ) + db.events.on('write', (address, entry, heads) => ... ) ``` - - `write` - (id, hash, entry) + - `closed` - (address) - 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 once the database has finished closing. **address** is a string of the OrbitDB address that emitted the event. ```javascript - db.events.on('write', (id, hash, entry) => ... ) + db.events.on('closed', (address) => ... ) + db.close() ``` -#### Private methods +### Private methods -##### `_addOperation(data)` +#### _addOperation(data) +> Add an entry to the store. -Add an entry to the store. Takes `data` as a parameter which can be of any type. +Returns a **Promise** that resolves to the IPFS Multihash of the added entry. Takes `data` as a parameter which can be of any type. ```javascript this._addOperation({ @@ -153,9 +255,9 @@ const Store = require('orbit-db-store'); const KeyValueIndex = require('./KeyValueIndex'); class KeyValueStore extends Store { - constructor(ipfs, identity, dbname, options) { + constructor(ipfs, identity, address, options) { Object.assign(options || {}, { Index: KeyValueIndex }); - super(ipfs, identity, dbname, options) + super(ipfs, identity, address, options) } get(key) { diff --git a/package.json b/package.json index c712b70..fb7457a 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "src/Store.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "lint": "standard" + "lint": "standard", + "build:docs/toc": "markdown-toc --no-first1 -i README.md" }, "repository": { "type": "git", @@ -29,6 +30,7 @@ ] }, "devDependencies": { + "markdown-toc": "^1.2.0", "standard": "^12.0.1" } } diff --git a/src/Store.js b/src/Store.js index 601408b..171d95a 100644 --- a/src/Store.js +++ b/src/Store.js @@ -310,8 +310,8 @@ class Store { return snapshot } - async loadFromSnapshot (onProgressCallback) { - this.events.emit('load', this.address.toString()) + async loadFromSnapshot () { + this.events.emit('load', this.address.toString()) //TODO: inconsistent params, line 205 const maxClock = (res, val) => Math.max(res, val.clock.time) @@ -401,7 +401,7 @@ class Store { const log = await Log.fromJSON(this._ipfs, this.identity, snapshotData, { access: this.access, length: -1, timeout: 1000, onProgressCallback: 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 { From 0d840afbd1d98fd392d67979ebb32fe288732729 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 30 May 2019 13:32:23 -0400 Subject: [PATCH 2/6] docs: clarify load & replicated events --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 63667c2..8e1ad38 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ console.log(db.replicationStatus) - `load` - (address, heads) - 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. + 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`. ```javascript db.events.on('load', (address, heads) => ... ) @@ -205,12 +205,12 @@ console.log(db.replicationStatus) db.events.on('replicate.progress', (address, hash, entry, progress, total) => ... ) ``` - - `replicated` - (address, logCount) + - `replicated` - (address, count) - 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** ... + 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 this event is emitted as a result of `loadFromSnapshot`. ```javascript - db.events.on('replicated', (address, logCount) => ... ) + db.events.on('replicated', (address, count) => ... ) ``` - `write` - (address, entry, heads) From 24cbd32230699e3a90146305ec3793b89eb53702 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 30 May 2019 13:34:07 -0400 Subject: [PATCH 3/6] chore: update/fix package-lock.json --- package-lock.json | 357 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 356 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 5b94573..c6061a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "orbit-db-store", - "version": "2.6.0", + "version": "2.6.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -58,6 +58,15 @@ "integrity": "sha512-cBhpre4ma+U0T1oM5fXg7Dy1Jw7zzwv7lt/GoCpr+hDQJoYnKVPLL4dCvSEFMmQurOQvSrwT7SL/DAlhBI97RQ==", "dev": true }, + "ansi-red": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/ansi-red/-/ansi-red-0.1.1.tgz", + "integrity": "sha1-jGOPnRCAgAo1PJwoyKgcpHBdlGw=", + "dev": true, + "requires": { + "ansi-wrap": "0.1.0" + } + }, "ansi-regex": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", @@ -69,6 +78,12 @@ "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", "dev": true }, + "ansi-wrap": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/ansi-wrap/-/ansi-wrap-0.1.0.tgz", + "integrity": "sha1-qCJQ3bABXponyoLoLqYDu/pF768=", + "dev": true + }, "aproba": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", @@ -125,6 +140,12 @@ "lodash": "^4.17.11" } }, + "autolinker": { + "version": "0.15.3", + "resolved": "https://registry.npmjs.org/autolinker/-/autolinker-0.15.3.tgz", + "integrity": "sha1-NCQX2PLzRhsUzwkIjV7fh5HcmDI=", + "dev": true + }, "babel-code-frame": { "version": "6.26.0", "resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.26.0.tgz", @@ -252,6 +273,12 @@ "resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz", "integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=" }, + "buffer-from": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz", + "integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==", + "dev": true + }, "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -365,6 +392,12 @@ "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=" }, + "coffee-script": { + "version": "1.12.7", + "resolved": "https://registry.npmjs.org/coffee-script/-/coffee-script-1.12.7.tgz", + "integrity": "sha512-fLeEhqwymYat/MpTPUjSKHVYYl0ec2mOyALEMLmzr5i1isuG+6jfI2j2d5oBO3VIzgUXgBVIcOT9uH1TFxBckw==", + "dev": true + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -386,6 +419,18 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "requires": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, "console-control-strings": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", @@ -535,6 +580,12 @@ "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=" }, + "diacritics-map": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/diacritics-map/-/diacritics-map-0.1.0.tgz", + "integrity": "sha1-bfwP+dAQAKLt8oZTccrDFulJd68=", + "dev": true + }, "doctrine": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", @@ -946,11 +997,29 @@ "safe-buffer": "^5.1.1" } }, + "expand-range": { + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/expand-range/-/expand-range-1.8.2.tgz", + "integrity": "sha1-opnv/TNf4nIeuujiV+x5ZE/IUzc=", + "dev": true, + "requires": { + "fill-range": "^2.1.0" + } + }, "expand-template": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/expand-template/-/expand-template-1.1.1.tgz", "integrity": "sha512-cebqLtV8KOZfw0UI8TEFWxtczxxC1jvyUvx6H4fyp1K1FN7A4Q+uggVUlOsI1K8AGU0rwOGqP8nCapdrw8CYQg==" }, + "extend-shallow": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/extend-shallow/-/extend-shallow-2.0.1.tgz", + "integrity": "sha1-Ua99YUrZqfYQ6huvu5idaxxWiQ8=", + "dev": true, + "requires": { + "is-extendable": "^0.1.0" + } + }, "external-editor": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/external-editor/-/external-editor-2.2.0.tgz", @@ -1004,6 +1073,19 @@ "object-assign": "^4.0.1" } }, + "fill-range": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-2.2.4.tgz", + "integrity": "sha512-cnrcCbj01+j2gTG921VZPnHbjmdAf8oQV/iGeV2kZxGSyfYjjTyY79ErsK1WJWMpw6DaApEX72binqJE+/d+5Q==", + "dev": true, + "requires": { + "is-number": "^2.1.0", + "isobject": "^2.0.0", + "randomatic": "^3.0.0", + "repeat-element": "^1.1.2", + "repeat-string": "^1.5.2" + } + }, "find-root": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/find-root/-/find-root-1.1.0.tgz", @@ -1031,6 +1113,12 @@ "write": "^0.2.1" } }, + "for-in": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz", + "integrity": "sha1-gQaNKVqBQuwKxybG4iAMMPttXoA=", + "dev": true + }, "fs-constants": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs-constants/-/fs-constants-1.0.0.tgz", @@ -1106,6 +1194,19 @@ "integrity": "sha512-6uHUhOPEBgQ24HM+r6b/QwWfZq+yiFcipKFrOFiBEnWdy5sdzYoi+pJeQaPI5qOLRFqWmAXUPQNsielzdLoecA==", "dev": true }, + "gray-matter": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/gray-matter/-/gray-matter-2.1.1.tgz", + "integrity": "sha1-MELZrewqHe1qdwep7SOA+KF6Qw4=", + "dev": true, + "requires": { + "ansi-red": "^0.1.1", + "coffee-script": "^1.12.4", + "extend-shallow": "^2.0.1", + "js-yaml": "^3.8.1", + "toml": "^2.3.2" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -1323,6 +1424,12 @@ "integrity": "sha1-d8mYQFJ6qOyxqLppe4BkWnqSap0=", "dev": true }, + "is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "dev": true + }, "is-callable": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.4.tgz", @@ -1335,6 +1442,12 @@ "integrity": "sha1-mqIOtq7rv/d/vTPnTKAbM1gdOhY=", "dev": true }, + "is-extendable": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-0.1.1.tgz", + "integrity": "sha1-YrEQ4omkcUGOPsNqYX1HLjAd/Ik=", + "dev": true + }, "is-fullwidth-code-point": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", @@ -1364,6 +1477,32 @@ "multihashes": "~0.4.13" } }, + "is-number": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-2.1.0.tgz", + "integrity": "sha1-Afy7s5NGOlSPL0ZszhbezknbkI8=", + "dev": true, + "requires": { + "kind-of": "^3.0.2" + } + }, + "is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "dev": true, + "requires": { + "isobject": "^3.0.1" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } + } + }, "is-promise": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-1.0.1.tgz", @@ -1414,6 +1553,15 @@ "resolved": "https://registry.npmjs.org/iso-random-stream/-/iso-random-stream-1.1.0.tgz", "integrity": "sha512-ywSWt0KrWcsaK0jVoVJIR30rLyjg9Rw3k2Sm/qp+3tdtSV0SNH7L7KilKnENcENOSoJxDFvpt2idvuMMQohdCQ==" }, + "isobject": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz", + "integrity": "sha1-8GVWEJaj8dou9GJy+BXIQNh+DIk=", + "dev": true, + "requires": { + "isarray": "1.0.0" + } + }, "js-sha3": { "version": "0.8.0", "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", @@ -1472,6 +1620,24 @@ "resolved": "https://registry.npmjs.org/keypair/-/keypair-1.0.1.tgz", "integrity": "sha1-dgNxknCvtlZO04oiCHoG/Jqk6hs=" }, + "kind-of": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz", + "integrity": "sha1-MeohpzS6ubuw8yRm2JOupR5KPGQ=", + "dev": true, + "requires": { + "is-buffer": "^1.1.5" + } + }, + "lazy-cache": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lazy-cache/-/lazy-cache-2.0.2.tgz", + "integrity": "sha1-uRkKT5EzVGlIQIWfio9whNiCImQ=", + "dev": true, + "requires": { + "set-getter": "^0.1.0" + } + }, "level-concat-iterator": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", @@ -1598,6 +1764,18 @@ "secp256k1": "^3.6.1" } }, + "list-item": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/list-item/-/list-item-1.1.1.tgz", + "integrity": "sha1-DGXQDih8tmPMs8s4Sad+iewmilY=", + "dev": true, + "requires": { + "expand-range": "^1.8.1", + "extend-shallow": "^2.0.1", + "is-number": "^2.1.0", + "repeat-string": "^1.5.2" + } + }, "load-json-file": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/load-json-file/-/load-json-file-2.0.0.tgz", @@ -1668,6 +1846,38 @@ "multiaddr": "^6.0.4" } }, + "markdown-link": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/markdown-link/-/markdown-link-0.1.1.tgz", + "integrity": "sha1-MsXGUZmmRXMWMi0eQinRNAfIx88=", + "dev": true + }, + "markdown-toc": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/markdown-toc/-/markdown-toc-1.2.0.tgz", + "integrity": "sha512-eOsq7EGd3asV0oBfmyqngeEIhrbkc7XVP63OwcJBIhH2EpG2PzFcbZdhy1jutXSlRBBVMNXHvMtSr5LAxSUvUg==", + "dev": true, + "requires": { + "concat-stream": "^1.5.2", + "diacritics-map": "^0.1.0", + "gray-matter": "^2.1.0", + "lazy-cache": "^2.0.2", + "list-item": "^1.1.1", + "markdown-link": "^0.1.1", + "minimist": "^1.2.0", + "mixin-deep": "^1.1.3", + "object.pick": "^1.2.0", + "remarkable": "^1.7.1", + "repeat-string": "^1.6.1", + "strip-color": "^0.1.0" + } + }, + "math-random": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/math-random/-/math-random-1.0.4.tgz", + "integrity": "sha512-rUxjysqif/BZQH2yhd5Aaq7vXMSx9NdEsQcyA07uEzIvxgI7zIr33gGsh+RU0/XjmQpCW7RsVof1vlkvQVCK5A==", + "dev": true + }, "md5.js": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", @@ -1713,6 +1923,27 @@ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" }, + "mixin-deep": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", + "integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", + "dev": true, + "requires": { + "for-in": "^1.0.2", + "is-extendable": "^1.0.1" + }, + "dependencies": { + "is-extendable": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-extendable/-/is-extendable-1.0.1.tgz", + "integrity": "sha512-arnXMxT1hhoKo9k1LZdmlNyJdDDfy2v0fXjFlmok4+i8ul/6WlbVge9bhM74OpNPQPMGUToDtz+KXa1PneJxOA==", + "dev": true, + "requires": { + "is-plain-object": "^2.0.4" + } + } + } + }, "mkdirp": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", @@ -1877,6 +2108,23 @@ "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true }, + "object.pick": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/object.pick/-/object.pick-1.3.0.tgz", + "integrity": "sha1-h6EKxMFpS9Lhy/U1kaZhQftd10c=", + "dev": true, + "requires": { + "isobject": "^3.0.1" + }, + "dependencies": { + "isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "dev": true + } + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -2272,6 +2520,31 @@ "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", "dev": true }, + "randomatic": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-3.1.1.tgz", + "integrity": "sha512-TuDE5KxZ0J461RVjrJZCJc+J+zCkTb1MbH9AQUq68sMhOMcy9jLcb3BrZKgp9q9Ncltdg4QVqWrH02W2EFFVYw==", + "dev": true, + "requires": { + "is-number": "^4.0.0", + "kind-of": "^6.0.0", + "math-random": "^1.0.1" + }, + "dependencies": { + "is-number": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-4.0.0.tgz", + "integrity": "sha512-rSklcAIlf1OmFdyAqbnWTLVelsQ58uvZ66S/ZyawjWqIviTWCjg2PzVGw8WUA+nNuPTqb4wgA+NszrJ+08LlgQ==", + "dev": true + }, + "kind-of": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.2.tgz", + "integrity": "sha512-s5kLOcnH0XqDO+FvuaLX8DDjZ18CGFk7VygH40QoKPUQhW4e2rvM0rwUq0t8IQDOwYSeLK01U90OjzBTme2QqA==", + "dev": true + } + } + }, "rc": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", @@ -2330,6 +2603,40 @@ "integrity": "sha512-lv0M6+TkDVniA3aD1Eg0DVpfU/booSu7Eev3TDO/mZKHBfVjgCGTV4t4buppESEYDtkArYFOxTJWv6S5C+iaNw==", "dev": true }, + "remarkable": { + "version": "1.7.1", + "resolved": "https://registry.npmjs.org/remarkable/-/remarkable-1.7.1.tgz", + "integrity": "sha1-qspJchALZqZCpjoQIcpLrBvjv/Y=", + "dev": true, + "requires": { + "argparse": "~0.1.15", + "autolinker": "~0.15.0" + }, + "dependencies": { + "argparse": { + "version": "0.1.16", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-0.1.16.tgz", + "integrity": "sha1-z9AeD7uj1srtBJ+9dY1A9lGW9Xw=", + "dev": true, + "requires": { + "underscore": "~1.7.0", + "underscore.string": "~2.4.0" + } + } + } + }, + "repeat-element": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/repeat-element/-/repeat-element-1.1.3.tgz", + "integrity": "sha512-ahGq0ZnV5m5XtZLMb+vP76kcAM5nkLqk0lpqAuojSKGgQtn4eRi4ZZGm2olo2zKFH+sMsWaqOCW1dqAnOru72g==", + "dev": true + }, + "repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", + "dev": true + }, "require-uncached": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz", @@ -2480,6 +2787,15 @@ "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" }, + "set-getter": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/set-getter/-/set-getter-0.1.0.tgz", + "integrity": "sha1-12nBgsnVpR9AkUXy+6guXoboA3Y=", + "dev": true, + "requires": { + "to-object-path": "^0.3.0" + } + }, "setimmediate": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.4.tgz", @@ -2658,6 +2974,12 @@ "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", "dev": true }, + "strip-color": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/strip-color/-/strip-color-0.1.0.tgz", + "integrity": "sha1-EG9l09PmotlAHKwOsM6LinArT3s=", + "dev": true + }, "strip-json-comments": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", @@ -2784,6 +3106,21 @@ "resolved": "https://registry.npmjs.org/to-buffer/-/to-buffer-1.1.1.tgz", "integrity": "sha512-lx9B5iv7msuFYE3dytT+KE5tap+rNYw+K4jVkb9R/asAb+pbBSM17jtunHplhBe6RRJdZx3Pn2Jph24O32mOVg==" }, + "to-object-path": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/to-object-path/-/to-object-path-0.3.0.tgz", + "integrity": "sha1-KXWIt7Dn4KwI4E5nL4XB9JmeF68=", + "dev": true, + "requires": { + "kind-of": "^3.0.2" + } + }, + "toml": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/toml/-/toml-2.3.6.tgz", + "integrity": "sha512-gVweAectJU3ebq//Ferr2JUY4WKSDe5N+z0FvjDncLGyHmIDoxgY/2Ie4qfEIDm4IS7OA6Rmdm7pdEEdMcV/xQ==", + "dev": true + }, "tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", @@ -2806,6 +3143,12 @@ "prelude-ls": "~1.1.2" } }, + "typedarray": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", + "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "dev": true + }, "typedarray-to-buffer": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", @@ -2814,6 +3157,18 @@ "is-typedarray": "^1.0.0" } }, + "underscore": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz", + "integrity": "sha1-a7rwh3UA02vjTsqlhODbn+8DUgk=", + "dev": true + }, + "underscore.string": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/underscore.string/-/underscore.string-2.4.0.tgz", + "integrity": "sha1-jN2PusTi0uoefi6Al8QvRCKA+Fs=", + "dev": true + }, "uniq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/uniq/-/uniq-1.0.1.tgz", From d21887183c8742afbf13b922a8ff545e9e6956aa Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 30 May 2019 13:48:24 -0400 Subject: [PATCH 4/6] docs: update constructor params --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8e1ad38..cd19eba 100644 --- a/README.md +++ b/README.md @@ -46,23 +46,21 @@ Base class for [orbit-db](https://github.com/orbitdb/orbit-db) data stores. You ## API -### constructor(ipfs, peerId, address, options) +### constructor(ipfs, identity, address, options) -**ipfs** can be an [IPFS](https://github.com/ipfs/js-ipfs) instance or an [IPFS-API](https://github.com/ipfs/js-ipfs) instance. **peerId** is a string identifying the peer, usually the base58 string of the [PeerId](https://github.com/libp2p/js-peer-id#tob58string) of the IPFS instance. **address** is the OrbitDB address to be used for the store. +**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. `options` is an object with the following required properties: - `cache`: A [Cache](https://github.com/orbitdb/orbit-db-cache) instance to use for storing heads and snapshots. - `Index` : By default it uses an instance of [Index](https://github.com/orbitdb/orbit-db-store/blob/master/src/Index.js). -- `keystore`: A [Keystore](https://github.com/orbitdb/orbit-db-keystore) instance to use for key management. the following properties are optional: - `maxHistory` (Integer): The number of entries to load (Default: `-1`). - `referenceCount` (Integer): The number of previous ipfs-log entries a new entry should reference (Default: `64`). - `replicationConcurrency` (Integer): The number of concurrent replication processes (Default: `128`). -- `key`: A [KeyPair](https://github.com/indutny/elliptic/blob/master/lib/elliptic/ec/key.js#L8) instance. By default the provided keystore is used to find an existing KeyPair for the given `peerId`, otherwise a new KeyPair will be created using the given `peerId`. -- `accessController` (Object): By default only the owner will have write access. +- `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. - `onClose` (Function): A function to be called with a string of the OrbitDB address of the database that is closing. ### Public methods From 5f92c67a9688f22cbf6d560827067d8a103f7825 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 30 May 2019 13:50:08 -0400 Subject: [PATCH 5/6] fix: remove unused default option --- src/Store.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Store.js b/src/Store.js index 171d95a..95d5b58 100644 --- a/src/Store.js +++ b/src/Store.js @@ -17,7 +17,6 @@ const DefaultOptions = { Index: Index, maxHistory: -1, directory: './orbitdb', - replicate: true, referenceCount: 64, replicationConcurrency: 128 } From a19b33045e1f03df80a014bd4e17c47e50536e12 Mon Sep 17 00:00:00 2001 From: Kia Rahimian Date: Thu, 30 May 2019 13:53:45 -0400 Subject: [PATCH 6/6] chore: lint --- src/Store.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Store.js b/src/Store.js index 95d5b58..d9a7a89 100644 --- a/src/Store.js +++ b/src/Store.js @@ -199,7 +199,6 @@ class Store { async load (amount) { amount = amount || this.options.maxHistory - const localHeads = await this._cache.get('_localHeads') || [] const remoteHeads = await this._cache.get('_remoteHeads') || [] const heads = localHeads.concat(remoteHeads) @@ -210,7 +209,7 @@ class Store { await mapSeries(heads, async (head) => { this._recalculateReplicationMax(head.clock.time) - let log = await Log.fromEntryHash(this._ipfs, this.identity, head.hash, { logId: this._oplog.id, access: this.access, length: amount, exclude: this._oplog.values, onProgressCallback: this._onLoadProgress.bind(this) }) + let log = await Log.fromEntryHash(this._ipfs, this.identity, head.hash, { logId: this._oplog.id, access: this.access, length: amount, exclude: this._oplog.values, onProgressCallback: this._onLoadProgress.bind(this) }) await this._oplog.join(log, amount) }) @@ -310,7 +309,7 @@ class Store { } async loadFromSnapshot () { - this.events.emit('load', this.address.toString()) //TODO: inconsistent params, line 205 + this.events.emit('load', this.address.toString()) const maxClock = (res, val) => Math.max(res, val.clock.time) @@ -400,7 +399,7 @@ class Store { const log = await Log.fromJSON(this._ipfs, this.identity, snapshotData, { access: this.access, length: -1, timeout: 1000, onProgressCallback: onProgress }) await this._oplog.join(log) await this._updateIndex() - this.events.emit('replicated', this.address.toString()) //TODO: inconsistent params, line 116 + this.events.emit('replicated', this.address.toString()) } this.events.emit('ready', this.address.toString(), this._oplog.heads) } else {