/** * @packageDocumentation * * Exports a `createHelia` function that returns an object that implements the {@link Helia} API. * * Pass it to other modules like {@link https://www.npmjs.com/package/@helia/unixfs | @helia/unixfs} to make files available on the distributed web. * * @example * * ```typescript * import { createHelia } from 'helia' * import { unixfs } from '@helia/unixfs' * import { CID } from 'multiformats/cid' * * const helia = await createHelia() * * const fs = unixfs(helia) * fs.cat(CID.parse('bafyFoo')) * ``` */ import { Helia as HeliaClass } from '@helia/utils' import { heliaDefaults } from './utils/helia-defaults.js' import { libp2pDefaults } from './utils/libp2p-defaults.js' import type { DefaultLibp2pServices } from './utils/libp2p-defaults.js' import type { Libp2pDefaultsOptions } from './utils/libp2p.js' import type { Helia } from '@helia/interface' import type { HeliaInit } from '@helia/utils' import type { Libp2p } from '@libp2p/interface' import type { CID } from 'multiformats/cid' // re-export interface types so people don't have to depend on @helia/interface // if they don't want to export * from '@helia/interface' export type { HeliaInit } export type { DefaultLibp2pServices, Libp2pDefaultsOptions } // allow amending the default config export { libp2pDefaults } export { heliaDefaults } /** * DAGWalkers take a block and yield CIDs encoded in that block */ export interface DAGWalker { codec: number walk(block: Uint8Array): Generator } /** * Create and return a Helia node * * @example Creating a Helia node * * ```ts * import { createHelia } from 'helia' * import { unixfs } from '@helia/unixfs' * import { CID } from 'multiformats/cid' * * const helia = await createHelia() * const fs = unixfs(helia) * const cid = CID.parse('QmFoo...') * * for await (const buf of fs.cat(cid, { * signal: AbortSignal.timeout(5_000) * })) { * console.info(buf) * } * ``` */ export async function createHelia (init: Partial>): Promise> export async function createHelia (init?: Partial>>): Promise>> export async function createHelia (init: Partial = {}): Promise { const options = await heliaDefaults(init) const helia = new HeliaClass(options) if (options.start !== false) { await helia.start() } return helia }