import Store from "./Store" ; import EnvironmentAdapter from "./EnvironmentAdapter" ; import Collection from "./Collection" ; import { Ipfs } from "ipfs" ; import { OrbitDBOptions , StoreOptions , DatabaseConfigOptions , } from "./interfaces" ; const { Key } = require ( "interface-datastore" ) ; let datastore = EnvironmentAdapter . datastore ( EnvironmentAdapter . repoPath ( ) ) ; class AvionDB extends Store { static Collection = Collection ; param { string } name param { Ipfs } ipfs param { IStoreOptions } options param { OrbitDBOptions } orbitDbOptions returns { Promise < AvionDB > } static async init ( name , ipfs , options = { } , orbitDbOptions = { } ) { if ( options . path ) { this . setDatabaseConfig ( { path : options . path } ) ; } const aviondb = await super . init ( name , ipfs , options , orbitDbOptions ) ; const buf = Buffer . from ( JSON . stringify ( { address : `/orbitdb/${ aviondb . address . root }/${ aviondb . address . path }` , } ) ) ; await datastore . put ( new Key ( `${ name }` ) , buf ) ; return Promise . resolve ( aviondb ) ; } returns { Promise < Array < string > > } static async listDatabases ( ) { const dbs = datastore . query ( { } ) ; const list = [ ] ; for await ( const db of dbs ) { const arr = JSON . parse ( db . value . toString ( ) ) . address . split ( "/" ) ; list . push ( arr [ arr . length - 1 ] ) ; } return list ; } param options static setDatabaseConfig ( options ) { datastore = EnvironmentAdapter . datastore ( EnvironmentAdapter . repoPath ( options . path ) ) ; } /**
     * Get AvionDB configuration details
     */ static getDatabaseConfig ( ) { return datastore ; } } export default AvionDB ;