mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-07 14:46:37 +00:00
use options.id
This commit is contained in:
parent
cb7b0809a3
commit
73f878d1e5
32
package-lock.json
generated
32
package-lock.json
generated
@ -6359,15 +6359,6 @@
|
|||||||
"integrity": "sha1-kV4tbQI8Q9UiStn20qPEFW9XEvU=",
|
"integrity": "sha1-kV4tbQI8Q9UiStn20qPEFW9XEvU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"for-each": {
|
|
||||||
"version": "0.3.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz",
|
|
||||||
"integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"is-callable": "^1.1.3"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"for-in": {
|
"for-in": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/for-in/-/for-in-1.0.2.tgz",
|
||||||
@ -14437,14 +14428,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"parse-headers": {
|
"parse-headers": {
|
||||||
"version": "2.0.2",
|
"version": "2.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/parse-headers/-/parse-headers-2.0.3.tgz",
|
||||||
"integrity": "sha512-/LypJhzFmyBIDYP9aDVgeyEb5sQfbfY5mnDq4hVhlQ69js87wXfmEI5V3xI6vvXasqebp0oCytYFLxsBVfCzSg==",
|
"integrity": "sha512-QhhZ+DCCit2Coi2vmAKbq5RGTRcQUOE2+REgv8vdyu7MnYx2eZztegqtTx99TZ86GTIwqiy3+4nQTWZ2tgmdCA==",
|
||||||
"dev": true,
|
"dev": true
|
||||||
"requires": {
|
|
||||||
"for-each": "^0.3.3",
|
|
||||||
"string.prototype.trim": "^1.1.2"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"parse-json": {
|
"parse-json": {
|
||||||
"version": "4.0.0",
|
"version": "4.0.0",
|
||||||
@ -17542,17 +17529,6 @@
|
|||||||
"strip-ansi": "^3.0.0"
|
"strip-ansi": "^3.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"string.prototype.trim": {
|
|
||||||
"version": "1.2.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/string.prototype.trim/-/string.prototype.trim-1.2.0.tgz",
|
|
||||||
"integrity": "sha512-9EIjYD/WdlvLpn987+ctkLf0FfvBefOCuiEr2henD8X+7jfwPnyvTdmW8OJhj5p+M0/96mBdynLWkxUr+rHlpg==",
|
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
|
||||||
"define-properties": "^1.1.3",
|
|
||||||
"es-abstract": "^1.13.0",
|
|
||||||
"function-bind": "^1.1.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"string.prototype.trimleft": {
|
"string.prototype.trimleft": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.0.tgz",
|
||||||
|
@ -78,7 +78,15 @@ class OrbitDB {
|
|||||||
static async createInstance (ipfs, options = {}) {
|
static async createInstance (ipfs, options = {}) {
|
||||||
if (!isDefined(ipfs)) { throw new Error('IPFS is a required argument. See https://github.com/orbitdb/orbit-db/blob/master/API.md#createinstance') }
|
if (!isDefined(ipfs)) { throw new Error('IPFS is a required argument. See https://github.com/orbitdb/orbit-db/blob/master/API.md#createinstance') }
|
||||||
|
|
||||||
const { id } = await ipfs.id()
|
if (options.offline === undefined) {
|
||||||
|
options.offline = false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.offline && !options.id ) {
|
||||||
|
throw new Error('Offline mode requires passing an `id` in the options')
|
||||||
|
}
|
||||||
|
|
||||||
|
const { id } = options.offline ? ({ id: options.id }) : await ipfs.id()
|
||||||
|
|
||||||
if (!options.directory) { options.directory = './orbitdb' }
|
if (!options.directory) { options.directory = './orbitdb' }
|
||||||
|
|
||||||
@ -112,10 +120,6 @@ class OrbitDB {
|
|||||||
options.cache = new Cache(cacheStorage)
|
options.cache = new Cache(cacheStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.offline === undefined) {
|
|
||||||
options.offline = false
|
|
||||||
}
|
|
||||||
|
|
||||||
const finalOptions = Object.assign({}, options, { peerId: id })
|
const finalOptions = Object.assign({}, options, { peerId: id })
|
||||||
return new OrbitDB(ipfs, options.identity, finalOptions)
|
return new OrbitDB(ipfs, options.identity, finalOptions)
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('starts in offline mode', async () => {
|
it('starts in offline mode', async () => {
|
||||||
orbitdb = await OrbitDB.createInstance(ipfs1, { offline: true, directory: dbPath1 })
|
orbitdb = await OrbitDB.createInstance(ipfs1, { id: 'A', offline: true, directory: dbPath1 })
|
||||||
assert.equal(orbitdb._pubsub, null)
|
assert.equal(orbitdb._pubsub, null)
|
||||||
await orbitdb.stop()
|
await orbitdb.stop()
|
||||||
})
|
})
|
||||||
@ -74,5 +74,16 @@ Object.keys(testAPIs).forEach(API => {
|
|||||||
assert.notEqual(orbitdb._pubsub, null)
|
assert.notEqual(orbitdb._pubsub, null)
|
||||||
await orbitdb.stop()
|
await orbitdb.stop()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('throws error if no `id` passed in offline mode', async () => {
|
||||||
|
let err
|
||||||
|
try {
|
||||||
|
orbitdb = await OrbitDB.createInstance(ipfs1, { offline: true, directory: dbPath1 })
|
||||||
|
} catch (e) {
|
||||||
|
err = e.message
|
||||||
|
}
|
||||||
|
assert.equal(err, 'Offline mode requires passing an `id` in the options')
|
||||||
|
await orbitdb.stop()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user