Skip to content

Commit

Permalink
Merge e71a681 into ac61d77
Browse files Browse the repository at this point in the history
  • Loading branch information
e-e-e committed Mar 31, 2018
2 parents ac61d77 + e71a681 commit f440ccb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ const PassThrough = stream.PassThrough
function Graph (storage, key, opts) {
if (!(this instanceof Graph)) return new Graph(storage, key, opts)
events.EventEmitter.call(this)

if (typeof key === 'string') key = Buffer.from(key, 'hex')

if (!Buffer.isBuffer(key) && !opts) {
opts = key
key = null
}

if (!opts) opts = {}
this.db = hyperdb(storage, key, opts)
opts = opts || {}
this.db = (storage instanceof hyperdb) ? storage : hyperdb(storage, key, opts)
this._prefixes = Object.assign({}, opts.prefixes || constants.DEFAULT_PREFIXES)
this._basename = opts.name || constants.DEFAULT_BASE
this._prefixes._ = this._basename
Expand Down
9 changes: 9 additions & 0 deletions test/basic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ function ramStore (filename) {

describe('hypergraph', function () {
let db
describe('constructor storage argument', () => {
context('with instance of hyperdb', () => {
it('sets graph database to hyperdb passed into the constructor', () => {
var hyperdbInstance = hyperdb(ramStore)
db = hypergraph(hyperdbInstance)
expect(db.db).to.eql(hyperdbInstance)
})
})
})
context('when newly created it adds metadata to db', () => {
it('includes graph version', (done) => {
db = hypergraph(ramStore)
Expand Down

0 comments on commit f440ccb

Please sign in to comment.