mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-10-07 22:57:07 +00:00
Remove Log and Database dependency injection
This commit is contained in:
@@ -2,7 +2,7 @@ import { strictEqual, deepStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import { copy } from 'fs-extra'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
import { Log, Entry, Database, KeyStore, Identities } from '../src/index.js'
|
||||
import { Database, KeyStore, Identities } from '../src/index.js'
|
||||
import config from './config.js'
|
||||
import testKeysPath from './fixtures/test-keys-path.js'
|
||||
import connectPeers from './utils/connect-nodes.js'
|
||||
@@ -11,7 +11,6 @@ import ComposedStorage from '../src/storage/composed.js'
|
||||
import IPFSBlockStorage from '../src/storage/ipfs-block.js'
|
||||
import MemoryStorage from '../src/storage/memory.js'
|
||||
|
||||
const OpLog = { Log, Entry }
|
||||
const keysPath = './testkeys'
|
||||
|
||||
describe('Database - Replication', function () {
|
||||
@@ -78,8 +77,8 @@ describe('Database - Replication', function () {
|
||||
|
||||
describe('Replicate across peers', () => {
|
||||
beforeEach(async () => {
|
||||
db1 = await Database({ OpLog, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' })
|
||||
db2 = await Database({ OpLog, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' })
|
||||
db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
})
|
||||
|
||||
it('replicates databases across two peers', async () => {
|
||||
@@ -176,7 +175,7 @@ describe('Database - Replication', function () {
|
||||
|
||||
await db1.addOperation({ op: 'PUT', key: 1, value: 'record 1 on db 1' })
|
||||
|
||||
db2 = await Database({ OpLog, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
|
||||
db2.events.on('join', onConnected)
|
||||
|
||||
@@ -200,8 +199,8 @@ describe('Database - Replication', function () {
|
||||
it('uses given ComposedStorage with MemoryStorage/IPFSBlockStorage for entryStorage', async () => {
|
||||
const storage1 = await ComposedStorage(await MemoryStorage(), await IPFSBlockStorage({ ipfs: ipfs1, pin: true }))
|
||||
const storage2 = await ComposedStorage(await MemoryStorage(), await IPFSBlockStorage({ ipfs: ipfs2, pin: true }))
|
||||
db1 = await Database({ OpLog, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1', entryStorage: storage1 })
|
||||
db2 = await Database({ OpLog, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2', entryStorage: storage2 })
|
||||
db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1', entryStorage: storage1 })
|
||||
db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2', entryStorage: storage2 })
|
||||
|
||||
let connected1 = false
|
||||
let connected2 = false
|
||||
@@ -241,8 +240,8 @@ describe('Database - Replication', function () {
|
||||
|
||||
describe('Events', () => {
|
||||
beforeEach(async () => {
|
||||
db1 = await Database({ OpLog, ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' })
|
||||
db2 = await Database({ OpLog, ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
db1 = await Database({ ipfs: ipfs1, identity: testIdentity1, address: databaseId, accessController, directory: './orbitdb1' })
|
||||
db2 = await Database({ ipfs: ipfs2, identity: testIdentity2, address: databaseId, accessController, directory: './orbitdb2' })
|
||||
})
|
||||
|
||||
it('emits \'update\' once when one operation is added', async () => {
|
||||
|
||||
@@ -4,13 +4,12 @@ import { existsSync } from 'fs'
|
||||
import { copy } from 'fs-extra'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
import Path from 'path'
|
||||
import { Log, Entry, Database, KeyStore, Identities } from '../src/index.js'
|
||||
import { Database, Entry, KeyStore, Identities } from '../src/index.js'
|
||||
import LevelStorage from '../src/storage/level.js'
|
||||
import MemoryStorage from '../src/storage/memory.js'
|
||||
import config from './config.js'
|
||||
import testKeysPath from './fixtures/test-keys-path.js'
|
||||
|
||||
const OpLog = { Log, Entry }
|
||||
const keysPath = './testkeys'
|
||||
|
||||
describe('Database', function () {
|
||||
@@ -58,7 +57,7 @@ describe('Database', function () {
|
||||
})
|
||||
|
||||
it('adds an operation', async () => {
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' })
|
||||
const expected = 'zdpuAwhx6xVpnMPUA7Q4JrvZsyoti5wZ18iDeFwBjPAwsRNof'
|
||||
const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' }
|
||||
const actual = await db.addOperation(op)
|
||||
@@ -70,7 +69,7 @@ describe('Database', function () {
|
||||
|
||||
describe('Options', () => {
|
||||
it('uses default directory for headsStorage', async () => {
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController })
|
||||
const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' }
|
||||
const hash = await db.addOperation(op)
|
||||
|
||||
@@ -90,7 +89,7 @@ describe('Database', function () {
|
||||
})
|
||||
|
||||
it('uses given directory for headsStorage', async () => {
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './custom-directory' })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './custom-directory' })
|
||||
const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' }
|
||||
const hash = await db.addOperation(op)
|
||||
|
||||
@@ -112,7 +111,7 @@ describe('Database', function () {
|
||||
|
||||
it('uses given MemoryStorage for headsStorage', async () => {
|
||||
const headsStorage = await MemoryStorage()
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', headsStorage })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', headsStorage })
|
||||
const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' }
|
||||
const hash = await db.addOperation(op)
|
||||
|
||||
@@ -123,7 +122,7 @@ describe('Database', function () {
|
||||
|
||||
it('uses given MemoryStorage for entryStorage', async () => {
|
||||
const entryStorage = await MemoryStorage()
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', entryStorage })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb', entryStorage })
|
||||
const op = { op: 'PUT', key: 1, value: 'record 1 on db 1' }
|
||||
const hash = await db.addOperation(op)
|
||||
|
||||
@@ -135,7 +134,7 @@ describe('Database', function () {
|
||||
|
||||
describe('Events', () => {
|
||||
beforeEach(async () => {
|
||||
db = await Database({ OpLog, ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' })
|
||||
db = await Database({ ipfs, identity: testIdentity, address: databaseId, accessController, directory: './orbitdb' })
|
||||
})
|
||||
|
||||
it('emits \'close\' when the database is closed', async () => {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { strictEqual, deepStrictEqual, notStrictEqual } from 'assert'
|
||||
import rmrf from 'rimraf'
|
||||
import * as IPFS from 'ipfs-core'
|
||||
import { OrbitDB, addDatabaseType, databaseTypes } from '../src/index.js'
|
||||
import { OrbitDB, addDatabaseType, databaseTypes, Database } from '../src/index.js'
|
||||
import config from './config.js'
|
||||
|
||||
const type = 'custom!'
|
||||
|
||||
const CustomStore = async ({ OpLog, Database, ipfs, identity, address, name, accessController, directory, storage, meta }) => {
|
||||
const database = await Database({ OpLog, ipfs, identity, address, name, accessController, directory, storage, meta })
|
||||
const CustomStore = async ({ ipfs, identity, address, name, accessController, directory, storage, meta }) => {
|
||||
const database = await Database({ ipfs, identity, address, name, accessController, directory, storage, meta })
|
||||
|
||||
return {
|
||||
...database,
|
||||
|
||||
Reference in New Issue
Block a user