refactor: Rename OrbitDB entry point.

This commit is contained in:
Hayden Young 2023-08-15 00:55:27 +01:00
parent 942f94d52d
commit 5079d490d9
12 changed files with 70 additions and 69 deletions

View File

@ -8,11 +8,11 @@ Different access controllers can be assigned to the database using the `AccessCo
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB, getAccessController } from 'orbit-db' import { createOrbitDB, getAccessController } from '@orbitdb/core'
const ipfs = create({ options }) const ipfs = create({ options })
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
// SomeAccessController must already be available in the AC list. // SomeAccessController must already be available in the AC list.
const SomeAccessController = getAccessController('some-access-controller') const SomeAccessController = getAccessController('some-access-controller')
@ -27,7 +27,7 @@ OrbitDB is bundled with two AccessControllers; IPFSAccessController, an immutabl
By default, the database `db` will use the IPFSAccessController and allow only the creator to write to the database. By default, the database `db` will use the IPFSAccessController and allow only the creator to write to the database.
```js ```js
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const db = orbitdb.open('my-db') const db = orbitdb.open('my-db')
await db.add('hello world') // only orbitdb.identity.id can write to the db. await db.add('hello world') // only orbitdb.identity.id can write to the db.
@ -37,7 +37,7 @@ To change write access, pass the IPFSAccessController with the `write` parameter
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB, Identities, getAccessController } from 'orbit-db' import { createOrbitDB, Identities, getAccessController } from '@orbitdb/core'
const ipfs = create({ options }) const ipfs = create({ options })
@ -45,7 +45,7 @@ const identities = await Identities()
const anotherIdentity = identities.createIdentity('userB') const anotherIdentity = identities.createIdentity('userB')
// OrbitDB will create an identity using the id 'UserA'. // OrbitDB will create an identity using the id 'UserA'.
const orbitdb = await OrbitDB({ ipfs, id: 'userA' }) const orbitdb = await createOrbitDB({ ipfs, id: 'userA' })
// Retrieve the access controller from the list of preloaded ACs. // Retrieve the access controller from the list of preloaded ACs.
const IPFSAccessController = getAccessController('ipfs') const IPFSAccessController = getAccessController('ipfs')
@ -58,11 +58,11 @@ To allow anyone to write to the database, specify the wildcard '*':
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB, Identities, getAccessController } from 'orbit-db' import { createOrbitDB, Identities, getAccessController } from '@orbitdb/core'
const ipfs = create({ options }) const ipfs = create({ options })
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const IPFSAccessController = getAccessController('ipfs') const IPFSAccessController = getAccessController('ipfs')
@ -77,11 +77,11 @@ The OrbitDB access controller provides configurable write access using grant and
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB, Identities, getAccessController } from 'orbit-db' import { createOrbitDB, Identities, getAccessController } from '@orbitdb/core'
const ipfs = create({ options }) const ipfs = create({ options })
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const identities = await Identities() const identities = await Identities()
const anotherIdentity = identities.createIdentity('userB') const anotherIdentity = identities.createIdentity('userB')
@ -164,9 +164,9 @@ Before passing the custom access controller to the `open` function, it must be a
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB, addAccessController } from 'orbit-db' import { createOrbitDB, addAccessController } from '@orbitdb/core'
addAccessController(CustomAccessController) addAccessController(CustomAccessController)
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.open('my-db', { AccessController: CustomAccessController(params) }) const db = await orbitdb.open('my-db', { AccessController: CustomAccessController(params) })
``` ```

View File

@ -36,10 +36,10 @@ In order to replicate the database with peers, the address is what you need to g
```js ```js
import IPFS from 'ipfs-core' import IPFS from 'ipfs-core'
import OrbitDB from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
const ipfs = await IPFS.create() const ipfs = await IPFS.create()
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.open('my-db') const db = await orbitdb.open('my-db')
console.log(db.address) console.log(db.address)
// /orbitdb/zdpuAmrcSRUhkQcnRQ6p4bphs7DJWGBkqczSGFYynX6moTcDL // /orbitdb/zdpuAmrcSRUhkQcnRQ6p4bphs7DJWGBkqczSGFYynX6moTcDL
@ -64,7 +64,7 @@ The manifest is an [IPLD data structure](https://ipld.io/docs/) which can be ret
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import * as Block from 'multiformats/block' import * as Block from 'multiformats/block'
import { OrbitDB, OrbitDBAddress } from 'orbit-db' import { createOrbitDB, OrbitDBAddress } from '@orbitdb/core'
import * as dagCbor from '@ipld/dag-cbor' import * as dagCbor from '@ipld/dag-cbor'
import { sha256 } from 'multiformats/hashes/sha2' import { sha256 } from 'multiformats/hashes/sha2'
import { base58btc } from 'multiformats/bases/base58' import { base58btc } from 'multiformats/bases/base58'
@ -73,7 +73,7 @@ import { CID } from 'multiformats/cid'
const ipfs = await create() const ipfs = await create()
// Create the db then close. // Create the db then close.
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.open('my-db') const db = await orbitdb.open('my-db')
await db.close() await db.close()
@ -99,21 +99,21 @@ console.log('manifest', value)
Creating a default event store: Creating a default event store:
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
await orbitdb.open('my-db') await orbitdb.open('my-db')
``` ```
Creating a documents database: Creating a documents database:
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
await orbitdb.open('my-db', { type: 'documents' }) await orbitdb.open('my-db', { type: 'documents' })
``` ```
Creating a keyvalue database: Creating a keyvalue database:
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
await orbitdb.open('my-db', { type: 'keyvalue' }) await orbitdb.open('my-db', { type: 'keyvalue' })
``` ```
@ -121,14 +121,14 @@ Creating a database and adding meta
```js ```js
const meta = { description: 'A database with metadata.' } const meta = { description: 'A database with metadata.' }
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
await orbitdb.open('my-db', { meta }) await orbitdb.open('my-db', { meta })
``` ```
## Opening an existing database ## Opening an existing database
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
const db = await orbitdb.open('my-db') const db = await orbitdb.open('my-db')
await db.close() await db.close()
const dbReopened = await orbitdb.open(db.address) const dbReopened = await orbitdb.open(db.address)
@ -141,7 +141,7 @@ const dbReopened = await orbitdb.open(db.address)
Database types such as **documents** and **keyvalue** expose the `put` function which is used to add items as a key/value combination to the database. Database types such as **documents** and **keyvalue** expose the `put` function which is used to add items as a key/value combination to the database.
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
const db = await orbitdb.open('my-db', { type: 'keyvalue' }) const db = await orbitdb.open('my-db', { type: 'keyvalue' })
const hash = await db.put('key', 'value') const hash = await db.put('key', 'value')
``` ```
@ -149,7 +149,7 @@ const hash = await db.put('key', 'value')
Alternatively, append-only database types such as **events** expose the `add` function which adds a value to the database: Alternatively, append-only database types such as **events** expose the `add` function which adds a value to the database:
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
const db = await orbitdb.open('my-db') const db = await orbitdb.open('my-db')
const hash = await db.add('event') const hash = await db.add('event')
``` ```
@ -159,7 +159,7 @@ const hash = await db.add('event')
To delete an item from a database, use the `del` function: To delete an item from a database, use the `del` function:
```js ```js
const orbitdb = await OrbitDB() const orbitdb = await createOrbitDB()
const db = await orbitdb.open('my-db', { type: 'keyvalue' }) const db = await orbitdb.open('my-db', { type: 'keyvalue' })
const hash = await db.put('key', 'value') const hash = await db.put('key', 'value')
await db.del(hash) await db.del(hash)
@ -173,13 +173,13 @@ A simple way to replicate a database between peers can be accomplished by openin
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB } from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
const ipfs1 = await create({ config1, repo: './ipfs1' }) const ipfs1 = await create({ config1, repo: './ipfs1' })
const ipfs2 = await create({ config2, repo: './ipfs2' }) const ipfs2 = await create({ config2, repo: './ipfs2' })
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
orbitdb2 = await OrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' })
const db1 = await orbitdb1.open('my-db') const db1 = await orbitdb1.open('my-db')

View File

@ -31,13 +31,13 @@ npm init
Create a file in your project called index.js and add the following code to it: Create a file in your project called index.js and add the following code to it:
```js ```js
import { OrbitDB } from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
// Create an IPFS instance with defaults. // Create an IPFS instance with defaults.
const ipfs = await create() const ipfs = await create()
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const db = await orbitdb.open('my-db') const db = await orbitdb.open('my-db')
@ -117,7 +117,7 @@ npm init
Create a new file called index.js and paste in the following code: Create a new file called index.js and paste in the following code:
```js ```js
import { OrbitDB, getAccessController } from 'orbit-db' import { OrbitDB, getAccessController } from '@orbitdb/core'
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
const main = async () => { const main = async () => {
@ -137,7 +137,7 @@ const main = async () => {
// This will create all OrbitDB-related databases (keystore, my-db, etc) in // This will create all OrbitDB-related databases (keystore, my-db, etc) in
// ./[randDir]/ipfs. // ./[randDir]/ipfs.
const orbitdb = await OrbitDB({ ipfs, directory: './' + randDir + '/orbitdb' }) const orbitdb = await createOrbitDB({ ipfs, directory: './' + randDir + '/orbitdb' })
// Get the IPFS AccessController function. We will need it to ensure everyone // Get the IPFS AccessController function. We will need it to ensure everyone
// can write to the database. // can write to the database.

View File

@ -17,7 +17,7 @@ A "signatures object" is then created to hold both the signed message and signed
Finally, a new identity consisting of the root public key and derived public key plus the signatures object is generated and stored to the Identities storage. Finally, a new identity consisting of the root public key and derived public key plus the signatures object is generated and stored to the Identities storage.
```js ```js
import { Identities } from 'orbit-db' import { Identities } from '@orbitdb/core'
const id = 'userA' const id = 'userA'
const identities = await Identities() const identities = await Identities()
@ -31,7 +31,7 @@ The PublicKeyIdentityProvider stores the id and the root keys as a key/value pai
Once created, `identities` and the associated `id` can be passed to OrbitDB: Once created, `identities` and the associated `id` can be passed to OrbitDB:
```js ```js
const orbitdb = await OrbitDB({ identities, id: 'userA' }) const orbitdb = await createOrbitDB({ identities, id: 'userA' })
``` ```
This identity can now be used by OrbitDB to control access to database actions such as write. This identity can now be used by OrbitDB to control access to database actions such as write.
@ -47,7 +47,7 @@ The key store is a local key manager for OrbitDB and is used to store the privat
An existing keystore can be passed to `Identities`: An existing keystore can be passed to `Identities`:
```js ```js
import { Identities, KeyStore } from 'orbit-db' import { Identities, KeyStore } from '@orbitdb/core'
const keystore = await KeyStore() const keystore = await KeyStore()
const id = 'userA' const id = 'userA'
@ -62,7 +62,7 @@ There are different ways to customize the location of the key store.
To change the keystore using `OrbitDB`, pass a custom directory: To change the keystore using `OrbitDB`, pass a custom directory:
```js ```js
// This will create a key store under ./different-path/key-store // This will create a key store under ./different-path/key-store
const orbitdb = await OrbitDB({ directory: './different-path' }) const orbitdb = await createOrbitDB({ directory: './different-path' })
// Be aware that this will change the base path to the database as well. // Be aware that this will change the base path to the database as well.
``` ```
@ -90,7 +90,7 @@ The identity object is stored like any other [IPLD data structure](https://ipld.
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import * as Block from 'multiformats/block' import * as Block from 'multiformats/block'
import { Identities } from 'orbit-db' import { Identities } from '@orbitdb/core'
import * as dagCbor from '@ipld/dag-cbor' import * as dagCbor from '@ipld/dag-cbor'
import { sha256 } from 'multiformats/hashes/sha2' import { sha256 } from 'multiformats/hashes/sha2'
import { base58btc } from 'multiformats/bases/base58' import { base58btc } from 'multiformats/bases/base58'
@ -165,7 +165,7 @@ export { MyCustomIdentityProvider as default, verifyIdentity, type }
To use it, add it to the list of known identity providers: To use it, add it to the list of known identity providers:
```js ```js
import { addIdentityProvider } from 'orbit-db' import { addIdentityProvider } from '@orbitdb/core'
import MyCustomIdentityProvider from 'my-custom-identity-provider' import MyCustomIdentityProvider from 'my-custom-identity-provider'
addIdentityProvider(MyCustomIdentityProvider) addIdentityProvider(MyCustomIdentityProvider)
const identity = await createIdentity({ id: 'some id', type: 'custom' }) const identity = await createIdentity({ id: 'some id', type: 'custom' })

View File

@ -3,7 +3,7 @@
Below is a simple replication example. Both peers run within the same Nodejs process. Below is a simple replication example. Both peers run within the same Nodejs process.
```js ```js
import { OrbitDB } from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
// The config will set up a TCP connection when dialling other node.js peers. // The config will set up a TCP connection when dialling other node.js peers.
@ -47,8 +47,8 @@ const ipfs2 = await create({ config: config2, repo: './ipfs/2' })
// const ipfs1PeerId = await ipfs1.id() // const ipfs1PeerId = await ipfs1.id()
// await ipfs2.swarm.connect(ipfs1PeerId.id) // await ipfs2.swarm.connect(ipfs1PeerId.id)
const orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'userA', directory: './orbitdb/1' }) const orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'userA', directory: './orbitdb/1' })
const orbitdb2 = await OrbitDB({ ipfs: ipfs2, id: 'userB', directory: './orbitdb/2' }) const orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'userB', directory: './orbitdb/2' })
// This opens a new db. Default db type will be 'events'. // This opens a new db. Default db type will be 'events'.
const db1 = await orbitdb1.open('my-db') const db1 = await orbitdb1.open('my-db')

View File

@ -17,10 +17,10 @@ Instantiate OrbitDB and create a database:
```js ```js
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB } from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
const ipfs = await create() // IPFS is required for storage and network communication const ipfs = await create() // IPFS is required for storage and network communication
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const mydb = await orbitdb.open('mydb') const mydb = await orbitdb.open('mydb')
console.log(mydb.address) // /orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13 console.log(mydb.address) // /orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13
await mydb.add("hello world!") await mydb.add("hello world!")
@ -31,10 +31,10 @@ Open and replicate an existing database:
```js ```js
// In another process // In another process
import { create } from 'ipfs-core' import { create } from 'ipfs-core'
import { OrbitDB } from 'orbit-db' import { createOrbitDB } from '@orbitdb/core'
const ipfs = await create() const ipfs = await create()
const orbitdb = await OrbitDB({ ipfs }) const orbitdb = await createOrbitDB({ ipfs })
const theirdb = await orbitdb.open('/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13') const theirdb = await orbitdb.open('/orbitdb/zdpuAuK3BHpS7NvMBivynypqciYCuy2UW77XYBPUYRnLjnw13')
for await (let record of theirdb.iterator()) { for await (let record of theirdb.iterator()) {
console.log(record) console.log(record)

View File

@ -1,5 +1,5 @@
export { export {
default as OrbitDB default as createOrbitDB
} from './orbitdb.js' } from './orbitdb.js'
export { export {

View File

@ -2,7 +2,7 @@ import { strictEqual, deepStrictEqual, notStrictEqual } from 'assert'
import rmrf from 'rimraf' import rmrf from 'rimraf'
import * as IPFS from 'ipfs-core' import * as IPFS from 'ipfs-core'
import { getDatabaseType } from '../src/databases/index.js' import { getDatabaseType } from '../src/databases/index.js'
import { OrbitDB, addDatabaseType, Database } from '../src/index.js' import { createOrbitDB, addDatabaseType, Database } from '../src/index.js'
import config from './config.js' import config from './config.js'
const type = 'custom!' const type = 'custom!'
@ -24,7 +24,7 @@ describe('Add a custom database type', function () {
before(async () => { before(async () => {
ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs1' }) ipfs = await IPFS.create({ ...config.daemon1, repo: './ipfs1' })
orbitdb = await OrbitDB({ ipfs }) orbitdb = await createOrbitDB({ ipfs })
}) })
after(async () => { after(async () => {

View File

@ -1,7 +1,7 @@
import { strictEqual } from 'assert' import { strictEqual } from 'assert'
import rmrf from 'rimraf' import rmrf from 'rimraf'
import * as IPFS from 'ipfs-core' import * as IPFS from 'ipfs-core'
import { OrbitDB } from '../src/index.js' import { createOrbitDB } from '../src/index.js'
import config from './config.js' import config from './config.js'
describe('Drop databases', function () { describe('Drop databases', function () {
@ -27,7 +27,7 @@ describe('Drop databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs, id: 'user1' })
db = await orbitdb1.open('helloworld') db = await orbitdb1.open('helloworld')
}) })
@ -89,7 +89,7 @@ describe('Drop databases', function () {
describe('dropping an empty database', () => { describe('dropping an empty database', () => {
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs, id: 'user1' })
db = await orbitdb1.open('helloworld') db = await orbitdb1.open('helloworld')
}) })

View File

@ -3,7 +3,7 @@ import rmrf from 'rimraf'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import * as IPFS from 'ipfs-core' import * as IPFS from 'ipfs-core'
import { OrbitDB, isValidAddress, LevelStorage } from '../src/index.js' import { createOrbitDB, isValidAddress, LevelStorage } from '../src/index.js'
import KeyValueIndexed from '../src/databases/keyvalue-indexed.js' import KeyValueIndexed from '../src/databases/keyvalue-indexed.js'
import config from './config.js' import config from './config.js'
import connectPeers from './utils/connect-nodes.js' import connectPeers from './utils/connect-nodes.js'
@ -38,7 +38,7 @@ describe('Open databases', function () {
let db let db
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
db = await orbitdb1.open('helloworld') db = await orbitdb1.open('helloworld')
}) })
@ -145,7 +145,7 @@ describe('Open databases', function () {
const expected = { hello: 'world' } const expected = { hello: 'world' }
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
db = await orbitdb1.open('helloworld', { meta: expected }) db = await orbitdb1.open('helloworld', { meta: expected })
}) })
@ -171,7 +171,7 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
db = await orbitdb1.open('helloworld') db = await orbitdb1.open('helloworld')
for (let i = 0; i < amount; i++) { for (let i = 0; i < amount; i++) {
@ -225,7 +225,7 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
db = await orbitdb1.open('helloworld2') db = await orbitdb1.open('helloworld2')
for (let i = 0; i < amount; i++) { for (let i = 0; i < amount; i++) {
@ -237,7 +237,7 @@ describe('Open databases', function () {
await db.close() await db.close()
await orbitdb1.stop() await orbitdb1.stop()
orbitdb2 = await OrbitDB({ ipfs: ipfs2, id: 'user2' }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2' })
}) })
after(async () => { after(async () => {
@ -277,8 +277,8 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
orbitdb2 = await OrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' })
db1 = await orbitdb1.open('helloworld2') db1 = await orbitdb1.open('helloworld2')
for (let i = 0; i < amount; i++) { for (let i = 0; i < amount; i++) {
await db1.add('hello' + i) await db1.add('hello' + i)
@ -379,7 +379,7 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
db = await orbitdb1.open('helloworld', { type: 'keyvalue' }) db = await orbitdb1.open('helloworld', { type: 'keyvalue' })
address = db.address address = db.address
@ -427,7 +427,7 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
db = await orbitdb1.open('helloworld', { type: 'keyvalue' }) db = await orbitdb1.open('helloworld', { type: 'keyvalue' })
address = db.address address = db.address
@ -487,7 +487,7 @@ describe('Open databases', function () {
const amount = 10 const amount = 10
before(async () => { before(async () => {
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1' })
db = await orbitdb1.open('helloworld', { type: 'documents' }) db = await orbitdb1.open('helloworld', { type: 'documents' })
address = db.address address = db.address

View File

@ -1,7 +1,7 @@
import { deepStrictEqual } from 'assert' import { deepStrictEqual } from 'assert'
import rmrf from 'rimraf' import rmrf from 'rimraf'
import * as IPFS from 'ipfs-core' import * as IPFS from 'ipfs-core'
import { OrbitDB } from '../src/index.js' import { createOrbitDB } from '../src/index.js'
import config from './config.js' import config from './config.js'
import connectPeers from './utils/connect-nodes.js' import connectPeers from './utils/connect-nodes.js'
import waitFor from './utils/wait-for.js' import waitFor from './utils/wait-for.js'
@ -16,8 +16,8 @@ describe('Replicating databases', function () {
ipfs1 = await IPFS.create({ ...config.daemon1, repo: './ipfs1' }) ipfs1 = await IPFS.create({ ...config.daemon1, repo: './ipfs1' })
ipfs2 = await IPFS.create({ ...config.daemon2, repo: './ipfs2' }) ipfs2 = await IPFS.create({ ...config.daemon2, repo: './ipfs2' })
await connectPeers(ipfs1, ipfs2) await connectPeers(ipfs1, ipfs2)
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
orbitdb2 = await OrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' }) orbitdb2 = await createOrbitDB({ ipfs: ipfs2, id: 'user2', directory: './orbitdb2' })
}) })
after(async () => { after(async () => {

View File

@ -3,7 +3,8 @@ import rmrf from 'rimraf'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import * as IPFS from 'ipfs-core' import * as IPFS from 'ipfs-core'
import { OrbitDB, isIdentity } from '../src/index.js' import { createOrbitDB } from '../src/index.js'
import { isIdentity } from '../src/index.js'
import config from './config.js' import config from './config.js'
import connectPeers from './utils/connect-nodes.js' import connectPeers from './utils/connect-nodes.js'
@ -35,7 +36,7 @@ describe('OrbitDB', function () {
describe('OrbitDB instance creation - defaults', () => { describe('OrbitDB instance creation - defaults', () => {
before(async () => { before(async () => {
await rmrf('./orbitdb') await rmrf('./orbitdb')
orbitdb1 = await OrbitDB({ ipfs: ipfs1 }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1 })
}) })
after(async () => { after(async () => {
@ -127,7 +128,7 @@ describe('OrbitDB', function () {
describe('OrbitDB instance creation - user given parameters', () => { describe('OrbitDB instance creation - user given parameters', () => {
before(async () => { before(async () => {
await rmrf('./orbitdb1') await rmrf('./orbitdb1')
orbitdb1 = await OrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' }) orbitdb1 = await createOrbitDB({ ipfs: ipfs1, id: 'user1', directory: './orbitdb1' })
}) })
after(async () => { after(async () => {
@ -226,7 +227,7 @@ describe('OrbitDB', function () {
it('throws an error if given an empty parameters object', async () => { it('throws an error if given an empty parameters object', async () => {
let err let err
try { try {
orbitdb1 = await OrbitDB({}) orbitdb1 = await createOrbitDB({})
} catch (e) { } catch (e) {
err = e err = e
} }
@ -237,7 +238,7 @@ describe('OrbitDB', function () {
it('throws an error if IPFS instance is not given', async () => { it('throws an error if IPFS instance is not given', async () => {
let err let err
try { try {
orbitdb1 = await OrbitDB() orbitdb1 = await createOrbitDB()
} catch (e) { } catch (e) {
err = e err = e
} }
@ -252,7 +253,7 @@ describe('OrbitDB', function () {
} }
try { try {
orbitdb1 = await OrbitDB() orbitdb1 = await createOrbitDB()
} catch (e) { } catch (e) {
} }
const dataDirectoryExists = fs.existsSync(path.join('./orbitdb')) const dataDirectoryExists = fs.existsSync(path.join('./orbitdb'))