mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-12 00:56:36 +00:00
feat: Accept identity as an option when opening a DB
This commit is contained in:
parent
66099dcda1
commit
ed1a6bf1a4
@ -168,8 +168,9 @@ let databaseTypes = {
|
|||||||
cache: cache,
|
cache: cache,
|
||||||
onClose: this._onClose.bind(this),
|
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))
|
store.events.on('write', this._onWrite.bind(this))
|
||||||
// ID of the store is the address as a string
|
// ID of the store is the address as a string
|
||||||
const addr = address.toString()
|
const addr = address.toString()
|
||||||
|
@ -9,6 +9,7 @@ const levelup = require('levelup')
|
|||||||
const leveldown = require('leveldown')
|
const leveldown = require('leveldown')
|
||||||
const OrbitDB = require('../src/OrbitDB')
|
const OrbitDB = require('../src/OrbitDB')
|
||||||
const OrbitDBAddress = require('../src/orbit-db-address')
|
const OrbitDBAddress = require('../src/orbit-db-address')
|
||||||
|
const Identities = require('orbit-db-identity-provider')
|
||||||
const io = require('orbit-db-io')
|
const io = require('orbit-db-io')
|
||||||
// Include test utilities
|
// Include test utilities
|
||||||
const {
|
const {
|
||||||
@ -258,6 +259,15 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
assert.equal(db.address.toString().indexOf('abc'), 59)
|
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 () => {
|
it('opens the same database - from an address', async () => {
|
||||||
db = await orbitdb.open(db.address)
|
db = await orbitdb.open(db.address)
|
||||||
assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
assert.equal(db.address.toString().indexOf('/orbitdb'), 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user