From 436c664fe56d5672b4019d494331587a047c17c2 Mon Sep 17 00:00:00 2001 From: Joel Torstensson Date: Tue, 23 Apr 2019 17:46:14 +0200 Subject: [PATCH 1/2] feat: Accept identity as an option when opening a DB --- src/OrbitDB.js | 3 ++- test/create-open.test.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/OrbitDB.js b/src/OrbitDB.js index 800569b..49b2c89 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -168,8 +168,9 @@ let databaseTypes = { cache: cache, onClose: this._onClose.bind(this), }) + const identity = options.identity || this.identity - const store = new Store(this._ipfs, this.identity, address, opts) + const store = new Store(this._ipfs, identity, address, opts) store.events.on('write', this._onWrite.bind(this)) // ID of the store is the address as a string const addr = address.toString() diff --git a/test/create-open.test.js b/test/create-open.test.js index 02dfcbe..95c8709 100644 --- a/test/create-open.test.js +++ b/test/create-open.test.js @@ -9,6 +9,7 @@ const levelup = require('levelup') const leveldown = require('leveldown') const OrbitDB = require('../src/OrbitDB') const OrbitDBAddress = require('../src/orbit-db-address') +const Identities = require('orbit-db-identity-provider') const io = require('orbit-db-io') // Include test utilities const { @@ -258,6 +259,15 @@ Object.keys(testAPIs).forEach(API => { assert.equal(db.address.toString().indexOf('abc'), 59) }) + it('opens a database - with a different identity', async () => { + const identity = await Identities.createIdentity({ id: 'test-id' }) + db = await orbitdb.open('abc', { create: true, type: 'feed', overwrite: true, identity }) + assert.equal(db.address.toString().indexOf('/orbitdb'), 0) + assert.equal(db.address.toString().indexOf('zd'), 9) + assert.equal(db.address.toString().indexOf('abc'), 59) + assert.equal(db.identity, identity) + }) + it('opens the same database - from an address', async () => { db = await orbitdb.open(db.address) assert.equal(db.address.toString().indexOf('/orbitdb'), 0) From f606cce0e0444cbe65bc2db295ceef2f9f48382b Mon Sep 17 00:00:00 2001 From: shamb0t Date: Tue, 23 Apr 2019 11:04:06 +0100 Subject: [PATCH 2/2] pass dbName to ac --- package-lock.json | 6 +++--- src/OrbitDB.js | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index acb585e..f28e34b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11030,9 +11030,9 @@ } }, "prometheus-gc-stats": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/prometheus-gc-stats/-/prometheus-gc-stats-0.6.1.tgz", - "integrity": "sha512-DUo/cDs+1XcVuqoFU6+DjmWjkjIRIVeswtZAIfslIPrYfli2NK0/g/BPoO/kqOgLvzbKRx4m9+MDeNsNIIJGkg==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/prometheus-gc-stats/-/prometheus-gc-stats-0.6.2.tgz", + "integrity": "sha512-ABSVHkAuYrMLj1WHmlLfS0hu9Vc2ELKuecwiMWPNQom+ZNiAdcILTn5yGK7sZg2ttoWc2u++W5NjdJ3IjdYJZw==", "dev": true, "optional": true, "requires": { diff --git a/src/OrbitDB.js b/src/OrbitDB.js index 49b2c89..90a78bf 100644 --- a/src/OrbitDB.js +++ b/src/OrbitDB.js @@ -247,7 +247,7 @@ let databaseTypes = { throw new Error(`Given database name is an address. Please give only the name of the database!`) // Create an AccessController, use IPFS AC as the default - options.accessController = Object.assign({}, { type: 'ipfs' }, options.accessController) + options.accessController = Object.assign({}, { address: name, type: 'ipfs' }, options.accessController) const accessControllerAddress = await AccessControllers.create(this, options.accessController.type, options.accessController || {}) // Save the manifest to IPFS