Merge pull request #681 from tabcat/master
adds optional meta field to manifest
This commit is contained in:
commit
c04be71a4f
@ -425,7 +425,7 @@ class OrbitDB {
|
||||
await this._addManifestToCache(options.cache, dbAddress)
|
||||
|
||||
// Open the the database
|
||||
options = Object.assign({}, options, { accessControllerAddress: manifest.accessController })
|
||||
options = Object.assign({}, options, { accessControllerAddress: manifest.accessController, meta: manifest.meta })
|
||||
return this._createStore(manifest.type, dbAddress, options)
|
||||
}
|
||||
|
||||
|
@ -3,11 +3,14 @@ const io = require('orbit-db-io')
|
||||
|
||||
// Creates a DB manifest file and saves it in IPFS
|
||||
const createDBManifest = async (ipfs, name, type, accessControllerAddress, options) => {
|
||||
const manifest = {
|
||||
const manifest = Object.assign({
|
||||
name: name,
|
||||
type: type,
|
||||
accessController: path.join('/ipfs', accessControllerAddress)
|
||||
}
|
||||
},
|
||||
// meta field is only added to manifest if options.meta is defined
|
||||
options.meta !== undefined ? { meta: options.meta } : {}
|
||||
)
|
||||
|
||||
return io.write(ipfs, options.format || 'dag-cbor', manifest, options)
|
||||
}
|
||||
|
@ -204,6 +204,36 @@ Object.keys(testAPIs).forEach(API => {
|
||||
assert.deepEqual(db.access.write, [orbitdb.identity.id])
|
||||
})
|
||||
})
|
||||
describe('Meta', function() {
|
||||
before(async () => {
|
||||
if (db) {
|
||||
await db.close()
|
||||
await db.drop()
|
||||
}
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
if (db) {
|
||||
await db.close()
|
||||
await db.drop()
|
||||
}
|
||||
})
|
||||
|
||||
it('creates a manifest with no meta field', async () => {
|
||||
db = await orbitdb.create('no-meta', 'feed')
|
||||
const manifest = await io.read(ipfs, db.address.root)
|
||||
assert.strictEqual(manifest.meta, undefined)
|
||||
assert.deepStrictEqual(Object.keys(manifest).filter(k => k === 'meta'), [])
|
||||
})
|
||||
|
||||
it('creates a manifest with a meta field', async () => {
|
||||
const meta = { test: 123 }
|
||||
db = await orbitdb.create('meta', 'feed', { meta })
|
||||
const manifest = await io.read(ipfs, db.address.root)
|
||||
assert.deepStrictEqual(manifest.meta, meta)
|
||||
assert.deepStrictEqual(Object.keys(manifest).filter(k => k === 'meta'), ['meta'])
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user