diff --git a/packages/helia/src/index.ts b/packages/helia/src/index.ts index ae867722..e0377960 100644 --- a/packages/helia/src/index.ts +++ b/packages/helia/src/index.ts @@ -28,14 +28,11 @@ import { libp2pDefaults } from './utils/libp2p-defaults.js' import { createLibp2p } from './utils/libp2p.js' import type { DefaultLibp2pServices } from './utils/libp2p-defaults.js' import type { Helia } from '@helia/interface' -import type { BlockBroker } from '@helia/interface/blocks' -import type { ComponentLogger, Libp2p } from '@libp2p/interface' +import type { HeliaInit as HeliaClassInit } from '@helia/utils' +import type { Libp2p } from '@libp2p/interface' import type { KeychainInit } from '@libp2p/keychain' -import type { Blockstore } from 'interface-blockstore' -import type { Datastore } from 'interface-datastore' import type { Libp2pOptions } from 'libp2p' import type { CID } from 'multiformats/cid' -import type { MultihashHasher } from 'multiformats/hashes/interface' // re-export interface types so people don't have to depend on @helia/interface // if they don't want to @@ -55,7 +52,7 @@ export interface DAGWalker { /** * Options used to create a Helia node. */ -export interface HeliaInit { +export interface HeliaInit extends HeliaClassInit { /** * A libp2p node is required to perform network operations. Either a * preconfigured node or options to configure a node can be passed @@ -70,64 +67,11 @@ export interface HeliaInit { */ libp2p?: T | Omit - /** - * The blockstore is where blocks are stored - */ - blockstore?: Blockstore - - /** - * The datastore is where data is stored - */ - datastore?: Datastore - - /** - * By default sha256, sha512 and identity hashes are supported for - * bitswap operations. To bitswap blocks with CIDs using other hashes - * pass appropriate MultihashHashers here. - */ - hashers?: MultihashHasher[] - - /** - * In order to pin CIDs that correspond to a DAG, it's necessary to know - * how to traverse that DAG. DAGWalkers take a block and yield any CIDs - * encoded within that block. - */ - dagWalkers?: DAGWalker[] - - /** - * A list of strategies used to fetch blocks when they are not present in - * the local blockstore - */ - blockBrokers?: Array<(components: any) => BlockBroker> - /** * Pass `false` to not start the Helia node */ start?: boolean - /** - * Garbage collection requires preventing blockstore writes during searches - * for unpinned blocks as DAGs are typically pinned after they've been - * imported - without locking this could lead to the deletion of blocks while - * they are being added to the blockstore. - * - * By default this lock is held on the main process (e.g. node cluster's - * primary process, the renderer thread in browsers) and other processes will - * contact the main process for access (worker processes in node cluster, - * webworkers in the browser). - * - * If Helia is being run wholly in a non-primary process, with no other process - * expected to access the blockstore (e.g. being run in the background in a - * webworker), pass true here to hold the gc lock in this process. - */ - holdGcLock?: boolean - - /** - * An optional logging component to pass to libp2p. If not specified the - * default implementation from libp2p will be used. - */ - logger?: ComponentLogger - /** * By default Helia stores the node's PeerId in an encrypted form in a * libp2p keystore. These options control how that keystore is configured. @@ -142,9 +86,9 @@ export interface HeliaLibp2p> e /** * Create and return a Helia node */ -export async function createHelia (init: HeliaInit): Promise> -export async function createHelia (init?: HeliaInit>): Promise>> -export async function createHelia (init: HeliaInit = {}): Promise { +export async function createHelia (init: Partial>): Promise> +export async function createHelia (init?: Partial>>): Promise>> +export async function createHelia (init: Partial = {}): Promise { const datastore = init.datastore ?? new MemoryDatastore() const blockstore = init.blockstore ?? new MemoryBlockstore()