Remove Log and Database dependency injection

This commit is contained in:
haad
2023-04-06 08:45:23 +03:00
parent a94d2a7918
commit d681bb720a
9 changed files with 37 additions and 38 deletions

View File

@@ -1,7 +1,5 @@
import Database from './database.js'
import { Events, KeyValue, Documents } from './db/index.js'
import { Log, Entry } from './oplog/index.js'
import { ComposedStorage, IPFSBlockStorage, LevelStorage, LRUStorage } from './storage/index.js'
import { ComposedStorage, IPFSBlockStorage, LRUStorage } from './storage/index.js'
import KeyStore from './key-store.js'
import { Identities } from './identities/index.js'
import OrbitDBAddress, { isValidAddress } from './address.js'
@@ -48,8 +46,6 @@ const addDatabaseType = (type, store) => {
// const defaultTimeout = 30000 // 30 seconds
const OpLog = { Log, Entry, IPFSBlockStorage, LevelStorage }
const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
if (ipfs == null) {
throw new Error('IPFS instance is a required argument. See https://github.com/orbitdb/orbit-db/blob/master/API.md#createinstance')
@@ -113,7 +109,7 @@ const OrbitDB = async ({ ipfs, id, identity, keystore, directory } = {}) => {
throw new Error(`Unsupported database type: '${type}'`)
}
const db = await DatabaseModel({ OpLog, Database, ipfs, identity, address: address.toString(), name, access: accessController, directory, meta, syncAutomatically: sync != null ? sync : true })
const db = await DatabaseModel({ ipfs, identity, address: address.toString(), name, access: accessController, directory, meta, syncAutomatically: sync != null ? sync : true })
db.events.on('close', onDatabaseClosed(address.toString()))

View File

@@ -1,15 +1,14 @@
import { EventEmitter } from 'events'
import PQueue from 'p-queue'
import Sync from './sync.js'
import { Log, Entry } from './oplog/index.js'
import { ComposedStorage, LRUStorage, IPFSBlockStorage, LevelStorage } from './storage/index.js'
import pathJoin from './utils/path-join.js'
const defaultReferencesCount = 16
const defaultCacheSize = 1000
const Database = async ({ OpLog, ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically }) => {
const { Log, Entry } = OpLog
const Database = async ({ ipfs, identity, address, name, access, directory, meta, headsStorage, entryStorage, indexStorage, referencesCount, syncAutomatically }) => {
directory = pathJoin(directory || './orbitdb', `./${address}/`)
meta = meta || {}
referencesCount = referencesCount || defaultReferencesCount

View File

@@ -1,5 +1,7 @@
const Documents = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically, indexBy = '_id' }) => {
const database = await Database({ OpLog, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
import Database from '../database.js'
const Documents = async ({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically, indexBy = '_id' }) => {
const database = await Database({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
const { addOperation, log } = database

View File

@@ -1,5 +1,7 @@
const Events = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically }) => {
const database = await Database({ OpLog, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
import Database from '../database.js'
const Events = async ({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically }) => {
const database = await Database({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
const { addOperation, log } = database

View File

@@ -1,12 +1,12 @@
import LevelStorage from '../storage/level.js'
import { KeyValue } from './index.js'
import LevelStorage from '../storage/level.js'
import pathJoin from '../utils/path-join.js'
import PQueue from 'p-queue'
const valueEncoding = 'json'
const KeyValueIndexed = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta }) => {
const keyValueStore = await KeyValue({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta })
const KeyValueIndexed = async ({ ipfs, identity, address, name, access, directory, storage, meta }) => {
const keyValueStore = await KeyValue({ ipfs, identity, address, name, access, directory, storage, meta })
const { events, log } = keyValueStore
const queue = new PQueue({ concurrency: 1 })

View File

@@ -1,5 +1,7 @@
const KeyValue = async ({ OpLog, Database, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically }) => {
const database = await Database({ OpLog, ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
import Database from '../database.js'
const KeyValue = async ({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically }) => {
const database = await Database({ ipfs, identity, address, name, access, directory, storage, meta, syncAutomatically })
const { addOperation, log } = database