Merge pull request #681 from tabcat/master

adds optional meta field to manifest
This commit is contained in:
Mark Robert Henderson 2019-09-27 14:04:43 -04:00 committed by GitHub
commit c04be71a4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 3 deletions

View File

@ -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)
}

View File

@ -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)
}

View File

@ -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'])
})
})
})
})