@helia/interface 5.4.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.min.js CHANGED
@@ -1,4 +1,4 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.HeliaInterface = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var HeliaInterface=(()=>{var s=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var x=Object.getOwnPropertyNames;var E=Object.prototype.hasOwnProperty;var u=(o,r)=>{for(var e in r)s(o,e,{get:r[e],enumerable:!0})},l=(o,r,e,p)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of x(r))!E.call(o,t)&&t!==e&&s(o,t,{get:()=>r[t],enumerable:!(p=m(r,t))||p.enumerable});return o};var d=o=>l(s({},"__esModule",{value:!0}),o);var f={};u(f,{DEFAULT_SESSION_MAX_PROVIDERS:()=>I,DEFAULT_SESSION_MIN_PROVIDERS:()=>S,InsufficientProvidersError:()=>n,NoRoutersAvailableError:()=>a,UnknownCodecError:()=>i,UnknownHashAlgorithmError:()=>c});var S=1,I=5;var n=class extends Error{static name="InsufficientProvidersError";constructor(r="Insufficient providers found"){super(r),this.name="InsufficientProvidersError"}},a=class extends Error{static name="NoRoutersAvailableError";constructor(r="No routers available"){super(r),this.name="NoRoutersAvailableError"}},c=class extends Error{static name="UnknownHashAlgorithmError";constructor(r="Unknown hash algorithm"){super(r),this.name="UnknownHashAlgorithmError"}},i=class extends Error{static name="UnknownCodecError";constructor(r="Unknown codec"){super(r),this.name="UnknownCodecError"}};return d(f);})();
2
+ "use strict";var HeliaInterface=(()=>{var s=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var u=Object.prototype.hasOwnProperty;var d=(o,r)=>{for(var e in r)s(o,e,{get:r[e],enumerable:!0})},l=(o,r,e,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let t of E(r))!u.call(o,t)&&t!==e&&s(o,t,{get:()=>r[t],enumerable:!(m=x(r,t))||m.enumerable});return o};var h=o=>l(s({},"__esModule",{value:!0}),o);var f={};d(f,{DEFAULT_SESSION_MAX_PROVIDERS:()=>v,DEFAULT_SESSION_MIN_PROVIDERS:()=>S,InsufficientProvidersError:()=>n,InvalidCodecError:()=>p,NoRoutersAvailableError:()=>a,UnknownCodecError:()=>i,UnknownHashAlgorithmError:()=>c});var S=1,v=5;var n=class extends Error{static name="InsufficientProvidersError";constructor(r="Insufficient providers found"){super(r),this.name="InsufficientProvidersError"}},a=class extends Error{static name="NoRoutersAvailableError";constructor(r="No routers available"){super(r),this.name="NoRoutersAvailableError"}},c=class extends Error{static name="UnknownHashAlgorithmError";constructor(r="Unknown hash algorithm"){super(r),this.name="UnknownHashAlgorithmError"}},i=class extends Error{static name="UnknownCodecError";constructor(r="Unknown codec"){super(r),this.name="UnknownCodecError"}},p=class extends Error{static name="InvalidCodecError";constructor(r="Invalid codec"){super(r),this.name="InvalidCodecError"}};return h(f);})();
3
3
  return HeliaInterface}));
4
4
  //# sourceMappingURL=index.min.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.ts", "../src/blocks.ts", "../src/errors.ts"],
4
- "sourcesContent": ["/**\n * @packageDocumentation\n *\n * The API defined by a {@link Helia} node\n *\n * @example\n *\n * ```typescript\n * import type { Helia } from '@helia/interface'\n *\n * export function doSomething(helia: Helia) {\n * // use helia node functions here\n * }\n * ```\n */\n\nimport type { Blocks } from './blocks.js'\nimport type { Pins } from './pins.js'\nimport type { Routing } from './routing.js'\nimport type { AbortOptions, ComponentLogger, Libp2p, Metrics } from '@libp2p/interface'\nimport type { DNS } from '@multiformats/dns'\nimport type { Datastore } from 'interface-datastore'\nimport type { Await } from 'interface-store'\nimport type { BlockCodec, MultihashHasher } from 'multiformats'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport type { Await, AwaitIterable } from 'interface-store'\n\nexport interface CodecLoader {\n <T = any, Code extends number = any>(code: Code): Await<BlockCodec<Code, T>>\n}\n\nexport interface HasherLoader {\n (code: number): Await<MultihashHasher>\n}\n\n/**\n * The API presented by a Helia node\n */\nexport interface Helia<T extends Libp2p = Libp2p> {\n /**\n * The libp2p instance\n */\n libp2p: T\n\n /**\n * Where the blocks are stored\n */\n blockstore: Blocks\n\n /**\n * A key/value store\n */\n datastore: Datastore\n\n /**\n * Pinning operations for blocks in the blockstore\n */\n pins: Pins\n\n /**\n * A logging component that can be reused by consumers\n */\n logger: ComponentLogger\n\n /**\n * The routing component allows performing operations such as looking up\n * content providers, information about peers, etc.\n */\n routing: Routing\n\n /**\n * The DNS property can be used to perform lookups of various record types and\n * will use a resolver appropriate to the current platform.\n */\n dns: DNS\n\n /**\n * A metrics object that can be used to collected arbitrary stats about node\n * usage.\n */\n metrics?: Metrics\n\n /**\n * Starts the Helia node\n */\n start(): Promise<void>\n\n /**\n * Stops the Helia node\n */\n stop(): Promise<void>\n\n /**\n * Remove any unpinned blocks from the blockstore\n */\n gc(options?: GCOptions): Promise<void>\n\n /**\n * Load an IPLD codec. Implementations may return a promise if, for example,\n * the codec is being fetched from the network.\n */\n getCodec: CodecLoader\n\n /**\n * Hashers can be used to hash a piece of data with the specified hashing\n * algorithm. Implementations may return a promise if, for example,\n * the hasher is being fetched from the network.\n */\n getHasher: HasherLoader\n}\n\nexport type GcEvents =\n ProgressEvent<'helia:gc:deleted', CID> |\n ProgressEvent<'helia:gc:error', Error>\n\nexport interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {\n\n}\n\nexport * from './blocks.js'\nexport * from './errors.js'\nexport * from './pins.js'\nexport * from './routing.js'\n", "import type { PeerId } from '@libp2p/interface'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { Blockstore } from 'interface-blockstore'\nimport type { AbortOptions } from 'interface-store'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport interface Pair {\n cid: CID\n block: Uint8Array\n}\n\nexport interface ProviderOptions {\n /**\n * An optional list of peers known to host at least the root block of the DAG\n * that will be fetched.\n *\n * If this list is omitted, or if the peers cannot supply the root or any\n * child blocks, a `findProviders` routing query will be run to find peers\n * that can supply the blocks.\n */\n providers?: Array<PeerId | Multiaddr | Multiaddr[]>\n}\n\nexport type HasBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutManyBlocksProgressEvents =\n ProgressEvent<'blocks:put-many:duplicate', CID> |\n ProgressEvent<'blocks:put-many:providers:notify', CID> |\n ProgressEvent<'blocks:put-many:blockstore:put-many'>\n\nexport type GetBlockProgressEvents =\n ProgressEvent<'blocks:get:providers:want', CID> |\n ProgressEvent<'blocks:get:blockstore:get', CID> |\n ProgressEvent<'blocks:get:blockstore:put', CID>\n\nexport type GetManyBlocksProgressEvents =\n ProgressEvent<'blocks:get-many:blockstore:get-many'> |\n ProgressEvent<'blocks:get-many:providers:want', CID> |\n ProgressEvent<'blocks:get-many:blockstore:put', CID>\n\nexport type GetAllBlocksProgressEvents =\n ProgressEvent<'blocks:get-all:blockstore:get-many'>\n\nexport type DeleteBlockProgressEvents =\n ProgressEvent<'blocks:delete:blockstore:delete', CID>\n\nexport type DeleteManyBlocksProgressEvents =\n ProgressEvent<'blocks:delete-many:blockstore:delete-many'>\n\nexport interface GetOfflineOptions {\n /**\n * If true, do not attempt to fetch any missing blocks from the network\n *\n * @default false\n */\n offline?: boolean\n}\n\nexport interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetBlockProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetManyBlocksProgressEvents>,\nProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * A blockstore session only fetches blocks from a subset of network peers to\n * reduce network traffic and improve performance.\n *\n * The initial set of peers can be specified, alternatively a `findProviders`\n * routing query will occur to populate the set instead.\n */\n createSession(root: CID, options?: CreateSessionOptions<GetOfflineOptions & ProviderOptions & GetBlockProgressEvents>): SessionBlockstore\n}\n\n/**\n * A session blockstore is a special blockstore that only pulls content from a\n * subset of network peers which respond as having the block for the initial\n * root CID.\n *\n * Any blocks written to the blockstore as part of the session will propagate\n * to the blockstore the session was created from.\n *\n */\nexport interface SessionBlockstore extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProgressOptions<GetBlockProgressEvents>, GetOfflineOptions & ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * Any in-progress operations will be aborted.\n */\n close(): void\n}\n\nexport interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * A function that blockBrokers should call prior to returning a block to ensure it can maintain control\n * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block\n * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway\n * and WILL consider the gateway that returned the invalid blocks completely unreliable.\n */\n validateFn?(block: Uint8Array): Promise<void>\n\n /**\n * The maximum size a block can be in bytes.\n *\n * Attempts to retrieve a block larger than this will cause an error to be thrown.\n *\n * @default 2_097_152\n */\n maxSize?: number\n}\n\nexport interface BlockAnnounceOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {\n\n}\n\nexport interface CreateSessionOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * The minimum number of providers for the root CID that are required for\n * successful session creation.\n *\n * The session will become usable once this many providers have been\n * discovered, up to `maxProviders` providers will continue to be added.\n *\n * @default 1\n */\n minProviders?: number\n\n /**\n * The maximum number of providers for the root CID to be added to a session.\n *\n * @default 5\n */\n maxProviders?: number\n}\n\nexport interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> {\n /**\n * Retrieve a block from a source\n */\n retrieve?(cid: CID, options?: BlockRetrievalOptions<RetrieveProgressEvents>): Promise<Uint8Array>\n\n /**\n * Make a new block available to peers\n */\n announce?(cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>\n\n /**\n * Create a new session\n */\n createSession?(options?: CreateSessionOptions<RetrieveProgressEvents>): BlockBroker<RetrieveProgressEvents, AnnounceProgressEvents>\n}\n\nexport const DEFAULT_SESSION_MIN_PROVIDERS = 1\nexport const DEFAULT_SESSION_MAX_PROVIDERS = 5\n", "export class InsufficientProvidersError extends Error {\n static name = 'InsufficientProvidersError'\n\n constructor (message = 'Insufficient providers found') {\n super(message)\n this.name = 'InsufficientProvidersError'\n }\n}\n\nexport class NoRoutersAvailableError extends Error {\n static name = 'NoRoutersAvailableError'\n\n constructor (message = 'No routers available') {\n super(message)\n this.name = 'NoRoutersAvailableError'\n }\n}\n\nexport class UnknownHashAlgorithmError extends Error {\n static name = 'UnknownHashAlgorithmError'\n\n constructor (message = 'Unknown hash algorithm') {\n super(message)\n this.name = 'UnknownHashAlgorithmError'\n }\n}\n\nexport class UnknownCodecError extends Error {\n static name = 'UnknownCodecError'\n\n constructor (message = 'Unknown codec') {\n super(message)\n this.name = 'UnknownCodecError'\n }\n}\n"],
5
- "mappings": ";kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,kCAAAC,EAAA,+BAAAC,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,8BAAAC,ICoKO,IAAMC,EAAgC,EAChCC,EAAgC,ECrKvC,IAAOC,EAAP,cAA0C,KAAK,CACnD,OAAO,KAAO,6BAEd,YAAaC,EAAU,+BAA8B,CACnD,MAAMA,CAAO,EACb,KAAK,KAAO,4BACd,GAGWC,EAAP,cAAuC,KAAK,CAChD,OAAO,KAAO,0BAEd,YAAaD,EAAU,uBAAsB,CAC3C,MAAMA,CAAO,EACb,KAAK,KAAO,yBACd,GAGWE,EAAP,cAAyC,KAAK,CAClD,OAAO,KAAO,4BAEd,YAAaF,EAAU,yBAAwB,CAC7C,MAAMA,CAAO,EACb,KAAK,KAAO,2BACd,GAGWG,EAAP,cAAiC,KAAK,CAC1C,OAAO,KAAO,oBAEd,YAAaH,EAAU,gBAAe,CACpC,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd",
6
- "names": ["index_exports", "__export", "DEFAULT_SESSION_MAX_PROVIDERS", "DEFAULT_SESSION_MIN_PROVIDERS", "InsufficientProvidersError", "NoRoutersAvailableError", "UnknownCodecError", "UnknownHashAlgorithmError", "DEFAULT_SESSION_MIN_PROVIDERS", "DEFAULT_SESSION_MAX_PROVIDERS", "InsufficientProvidersError", "message", "NoRoutersAvailableError", "UnknownHashAlgorithmError", "UnknownCodecError"]
4
+ "sourcesContent": ["/**\n * @packageDocumentation\n *\n * The API defined by a {@link Helia} node\n *\n * @example\n *\n * ```typescript\n * import type { Helia } from '@helia/interface'\n *\n * export function doSomething(helia: Helia) {\n * // use helia node functions here\n * }\n * ```\n */\n\nimport type { Blocks } from './blocks.js'\nimport type { Pins } from './pins.js'\nimport type { Routing } from './routing.js'\nimport type { AbortOptions, ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface'\nimport type { DNS } from '@multiformats/dns'\nimport type { Datastore } from 'interface-datastore'\nimport type { Await } from 'interface-store'\nimport type { BlockCodec, MultihashHasher } from 'multiformats'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport type { Await, AwaitIterable } from 'interface-store'\n\nexport interface CodecLoader {\n <T = any, Code extends number = any>(code: Code): Await<BlockCodec<Code, T>>\n}\n\nexport interface HasherLoader {\n (code: number): Await<MultihashHasher>\n}\n\n/**\n * The API presented by a Helia node\n */\nexport interface Helia<T extends Libp2p = Libp2p> {\n /**\n * The libp2p instance\n */\n libp2p: T\n\n /**\n * Where the blocks are stored\n */\n blockstore: Blocks\n\n /**\n * A key/value store\n */\n datastore: Datastore\n\n /**\n * Event emitter for Helia start and stop events\n */\n events: TypedEventEmitter<HeliaEvents<T>>\n\n /**\n * Pinning operations for blocks in the blockstore\n */\n pins: Pins\n\n /**\n * A logging component that can be reused by consumers\n */\n logger: ComponentLogger\n\n /**\n * The routing component allows performing operations such as looking up\n * content providers, information about peers, etc.\n */\n routing: Routing\n\n /**\n * The DNS property can be used to perform lookups of various record types and\n * will use a resolver appropriate to the current platform.\n */\n dns: DNS\n\n /**\n * A metrics object that can be used to collected arbitrary stats about node\n * usage.\n */\n metrics?: Metrics\n\n /**\n * Starts the Helia node\n */\n start(): Promise<void>\n\n /**\n * Stops the Helia node\n */\n stop(): Promise<void>\n\n /**\n * Remove any unpinned blocks from the blockstore\n */\n gc(options?: GCOptions): Promise<void>\n\n /**\n * Load an IPLD codec. Implementations may return a promise if, for example,\n * the codec is being fetched from the network.\n */\n getCodec: CodecLoader\n\n /**\n * Hashers can be used to hash a piece of data with the specified hashing\n * algorithm. Implementations may return a promise if, for example,\n * the hasher is being fetched from the network.\n */\n getHasher: HasherLoader\n}\n\nexport type GcEvents =\n ProgressEvent<'helia:gc:deleted', CID> |\n ProgressEvent<'helia:gc:error', Error>\n\nexport interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {\n\n}\n\nexport interface HeliaEvents<T extends Libp2p = Libp2p> {\n /**\n * This event notifies listeners that the node has started\n *\n * ```TypeScript\n * helia.addEventListener('start', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // true\n * })\n * ```\n */\n start: CustomEvent<Helia<T>>\n\n /**\n * This event notifies listeners that the node has stopped\n *\n * ```TypeScript\n * helia.addEventListener('stop', (event) => {\n * console.info(event.detail.libp2p.isStarted()) // false\n * })\n * ```\n */\n stop: CustomEvent<Helia<T>>\n}\n\nexport * from './blocks.js'\nexport * from './errors.js'\nexport * from './pins.js'\nexport * from './routing.js'\n", "import type { PeerId } from '@libp2p/interface'\nimport type { Multiaddr } from '@multiformats/multiaddr'\nimport type { Blockstore } from 'interface-blockstore'\nimport type { AbortOptions } from 'interface-store'\nimport type { CID } from 'multiformats/cid'\nimport type { ProgressEvent, ProgressOptions } from 'progress-events'\n\nexport type { Pair, InputPair } from 'interface-blockstore'\n\nexport interface ProviderOptions {\n /**\n * An optional list of peers known to host at least the root block of the DAG\n * that will be fetched.\n *\n * If this list is omitted, or if the peers cannot supply the root or any\n * child blocks, a `findProviders` routing query will be run to find peers\n * that can supply the blocks.\n */\n providers?: Array<PeerId | Multiaddr | Multiaddr[]>\n}\n\nexport type HasBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutBlockProgressEvents =\n ProgressEvent<'blocks:put:duplicate', CID> |\n ProgressEvent<'blocks:put:providers:notify', CID> |\n ProgressEvent<'blocks:put:blockstore:put', CID>\n\nexport type PutManyBlocksProgressEvents =\n ProgressEvent<'blocks:put-many:duplicate', CID> |\n ProgressEvent<'blocks:put-many:providers:notify', CID> |\n ProgressEvent<'blocks:put-many:blockstore:put-many'>\n\nexport type GetBlockProgressEvents =\n ProgressEvent<'blocks:get:providers:want', CID> |\n ProgressEvent<'blocks:get:blockstore:get', CID> |\n ProgressEvent<'blocks:get:blockstore:put', CID>\n\nexport type GetManyBlocksProgressEvents =\n ProgressEvent<'blocks:get-many:blockstore:get-many'> |\n ProgressEvent<'blocks:get-many:providers:want', CID> |\n ProgressEvent<'blocks:get-many:blockstore:put', CID>\n\nexport type GetAllBlocksProgressEvents =\n ProgressEvent<'blocks:get-all:blockstore:get-many'>\n\nexport type DeleteBlockProgressEvents =\n ProgressEvent<'blocks:delete:blockstore:delete', CID>\n\nexport type DeleteManyBlocksProgressEvents =\n ProgressEvent<'blocks:delete-many:blockstore:delete-many'>\n\nexport interface GetOfflineOptions {\n /**\n * If true, do not attempt to fetch any missing blocks from the network\n *\n * @default false\n */\n offline?: boolean\n}\n\nexport interface Blocks extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetBlockProgressEvents>,\nGetOfflineOptions & ProviderOptions & ProgressOptions<GetManyBlocksProgressEvents>,\nProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * A blockstore session only fetches blocks from a subset of network peers to\n * reduce network traffic and improve performance.\n *\n * The initial set of peers can be specified, alternatively a `findProviders`\n * routing query will occur to populate the set instead.\n */\n createSession(root: CID, options?: CreateSessionOptions<GetOfflineOptions & ProviderOptions & GetBlockProgressEvents>): SessionBlockstore\n}\n\n/**\n * A session blockstore is a special blockstore that only pulls content from a\n * subset of network peers which respond as having the block for the initial\n * root CID.\n *\n * Any blocks written to the blockstore as part of the session will propagate\n * to the blockstore the session was created from.\n *\n */\nexport interface SessionBlockstore extends Blockstore<ProgressOptions<HasBlockProgressEvents>,\nProgressOptions<PutBlockProgressEvents>, ProgressOptions<PutManyBlocksProgressEvents>,\nGetOfflineOptions & ProgressOptions<GetBlockProgressEvents>, GetOfflineOptions & ProgressOptions<GetManyBlocksProgressEvents>, ProgressOptions<GetAllBlocksProgressEvents>,\nProgressOptions<DeleteBlockProgressEvents>, ProgressOptions<DeleteManyBlocksProgressEvents>\n> {\n /**\n * Any in-progress operations will be aborted.\n */\n close(): void\n}\n\nexport interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * A function that blockBrokers should call prior to returning a block to ensure it can maintain control\n * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block\n * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway\n * and WILL consider the gateway that returned the invalid blocks completely unreliable.\n */\n validateFn?(block: Uint8Array): Promise<void>\n\n /**\n * The maximum size a block can be in bytes.\n *\n * Attempts to retrieve a block larger than this will cause an error to be thrown.\n *\n * @default 2_097_152\n */\n maxSize?: number\n}\n\nexport interface BlockAnnounceOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {\n\n}\n\nexport interface CreateSessionOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents>, ProviderOptions {\n /**\n * The minimum number of providers for the root CID that are required for\n * successful session creation.\n *\n * The session will become usable once this many providers have been\n * discovered, up to `maxProviders` providers will continue to be added.\n *\n * @default 1\n */\n minProviders?: number\n\n /**\n * The maximum number of providers for the root CID to be added to a session.\n *\n * @default 5\n */\n maxProviders?: number\n}\n\nexport interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>, AnnounceProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> {\n /**\n * Retrieve a block from a source\n */\n retrieve?(cid: CID, options?: BlockRetrievalOptions<RetrieveProgressEvents>): Promise<Uint8Array>\n\n /**\n * Make a new block available to peers\n */\n announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>\n\n /**\n * Create a new session\n */\n createSession?(options?: CreateSessionOptions<RetrieveProgressEvents>): BlockBroker<RetrieveProgressEvents, AnnounceProgressEvents>\n}\n\nexport const DEFAULT_SESSION_MIN_PROVIDERS = 1\nexport const DEFAULT_SESSION_MAX_PROVIDERS = 5\n", "export class InsufficientProvidersError extends Error {\n static name = 'InsufficientProvidersError'\n\n constructor (message = 'Insufficient providers found') {\n super(message)\n this.name = 'InsufficientProvidersError'\n }\n}\n\nexport class NoRoutersAvailableError extends Error {\n static name = 'NoRoutersAvailableError'\n\n constructor (message = 'No routers available') {\n super(message)\n this.name = 'NoRoutersAvailableError'\n }\n}\n\nexport class UnknownHashAlgorithmError extends Error {\n static name = 'UnknownHashAlgorithmError'\n\n constructor (message = 'Unknown hash algorithm') {\n super(message)\n this.name = 'UnknownHashAlgorithmError'\n }\n}\n\nexport class UnknownCodecError extends Error {\n static name = 'UnknownCodecError'\n\n constructor (message = 'Unknown codec') {\n super(message)\n this.name = 'UnknownCodecError'\n }\n}\n\nexport class InvalidCodecError extends Error {\n static name = 'InvalidCodecError'\n\n constructor (message = 'Invalid codec') {\n super(message)\n this.name = 'InvalidCodecError'\n }\n}\n"],
5
+ "mappings": ";kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,kCAAAC,EAAA,+BAAAC,EAAA,sBAAAC,EAAA,4BAAAC,EAAA,sBAAAC,EAAA,8BAAAC,ICiKO,IAAMC,EAAgC,EAChCC,EAAgC,EClKvC,IAAOC,EAAP,cAA0C,KAAK,CACnD,OAAO,KAAO,6BAEd,YAAaC,EAAU,+BAA8B,CACnD,MAAMA,CAAO,EACb,KAAK,KAAO,4BACd,GAGWC,EAAP,cAAuC,KAAK,CAChD,OAAO,KAAO,0BAEd,YAAaD,EAAU,uBAAsB,CAC3C,MAAMA,CAAO,EACb,KAAK,KAAO,yBACd,GAGWE,EAAP,cAAyC,KAAK,CAClD,OAAO,KAAO,4BAEd,YAAaF,EAAU,yBAAwB,CAC7C,MAAMA,CAAO,EACb,KAAK,KAAO,2BACd,GAGWG,EAAP,cAAiC,KAAK,CAC1C,OAAO,KAAO,oBAEd,YAAaH,EAAU,gBAAe,CACpC,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd,GAGWI,EAAP,cAAiC,KAAK,CAC1C,OAAO,KAAO,oBAEd,YAAaJ,EAAU,gBAAe,CACpC,MAAMA,CAAO,EACb,KAAK,KAAO,mBACd",
6
+ "names": ["index_exports", "__export", "DEFAULT_SESSION_MAX_PROVIDERS", "DEFAULT_SESSION_MIN_PROVIDERS", "InsufficientProvidersError", "InvalidCodecError", "NoRoutersAvailableError", "UnknownCodecError", "UnknownHashAlgorithmError", "DEFAULT_SESSION_MIN_PROVIDERS", "DEFAULT_SESSION_MAX_PROVIDERS", "InsufficientProvidersError", "message", "NoRoutersAvailableError", "UnknownHashAlgorithmError", "UnknownCodecError", "InvalidCodecError"]
7
7
  }
@@ -4,10 +4,7 @@ import type { Blockstore } from 'interface-blockstore';
4
4
  import type { AbortOptions } from 'interface-store';
5
5
  import type { CID } from 'multiformats/cid';
6
6
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
7
- export interface Pair {
8
- cid: CID;
9
- block: Uint8Array;
10
- }
7
+ export type { Pair, InputPair } from 'interface-blockstore';
11
8
  export interface ProviderOptions {
12
9
  /**
13
10
  * An optional list of peers known to host at least the root block of the DAG
@@ -105,7 +102,7 @@ export interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, a
105
102
  /**
106
103
  * Make a new block available to peers
107
104
  */
108
- announce?(cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>;
105
+ announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>;
109
106
  /**
110
107
  * Create a new session
111
108
  */
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"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../src/blocks.ts"],"names":[],"mappings":"AAiKA,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA"}
@@ -14,4 +14,8 @@ export declare class UnknownCodecError extends Error {
14
14
  static name: string;
15
15
  constructor(message?: string);
16
16
  }
17
+ export declare class InvalidCodecError extends Error {
18
+ static name: string;
19
+ constructor(message?: string);
20
+ }
17
21
  //# sourceMappingURL=errors.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,SAA+B;gBAE7B,OAAO,SAAiC;CAItD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,MAAM,CAAC,IAAI,SAA4B;gBAE1B,OAAO,SAAyB;CAI9C;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,SAA8B;gBAE5B,OAAO,SAA2B;CAIhD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,SAAsB;gBAEpB,OAAO,SAAkB;CAIvC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,SAA+B;gBAE7B,OAAO,SAAiC;CAItD;AAED,qBAAa,uBAAwB,SAAQ,KAAK;IAChD,MAAM,CAAC,IAAI,SAA4B;gBAE1B,OAAO,SAAyB;CAI9C;AAED,qBAAa,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,SAA8B;gBAE5B,OAAO,SAA2B;CAIhD;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,SAAsB;gBAEpB,OAAO,SAAkB;CAIvC;AAED,qBAAa,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,SAAsB;gBAEpB,OAAO,SAAkB;CAIvC"}
@@ -26,4 +26,11 @@ export class UnknownCodecError extends Error {
26
26
  this.name = 'UnknownCodecError';
27
27
  }
28
28
  }
29
+ export class InvalidCodecError extends Error {
30
+ static name = 'InvalidCodecError';
31
+ constructor(message = 'Invalid codec') {
32
+ super(message);
33
+ this.name = 'InvalidCodecError';
34
+ }
35
+ }
29
36
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAE1C,YAAa,OAAO,GAAG,8BAA8B;QACnD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC;;AAGH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,MAAM,CAAC,IAAI,GAAG,yBAAyB,CAAA;IAEvC,YAAa,OAAO,GAAG,sBAAsB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;IACvC,CAAC;;AAGH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,GAAG,2BAA2B,CAAA;IAEzC,YAAa,OAAO,GAAG,wBAAwB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;;AAGH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,GAAG,mBAAmB,CAAA;IAEjC,YAAa,OAAO,GAAG,eAAe;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC"}
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,MAAM,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAE1C,YAAa,OAAO,GAAG,8BAA8B;QACnD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC;;AAGH,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAChD,MAAM,CAAC,IAAI,GAAG,yBAAyB,CAAA;IAEvC,YAAa,OAAO,GAAG,sBAAsB;QAC3C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAA;IACvC,CAAC;;AAGH,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,MAAM,CAAC,IAAI,GAAG,2BAA2B,CAAA;IAEzC,YAAa,OAAO,GAAG,wBAAwB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;;AAGH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,GAAG,mBAAmB,CAAA;IAEjC,YAAa,OAAO,GAAG,eAAe;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;;AAGH,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAC1C,MAAM,CAAC,IAAI,GAAG,mBAAmB,CAAA;IAEjC,YAAa,OAAO,GAAG,eAAe;QACpC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC"}
@@ -16,7 +16,7 @@
16
16
  import type { Blocks } from './blocks.js';
17
17
  import type { Pins } from './pins.js';
18
18
  import type { Routing } from './routing.js';
19
- import type { AbortOptions, ComponentLogger, Libp2p, Metrics } from '@libp2p/interface';
19
+ import type { AbortOptions, ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface';
20
20
  import type { DNS } from '@multiformats/dns';
21
21
  import type { Datastore } from 'interface-datastore';
22
22
  import type { Await } from 'interface-store';
@@ -46,6 +46,10 @@ export interface Helia<T extends Libp2p = Libp2p> {
46
46
  * A key/value store
47
47
  */
48
48
  datastore: Datastore;
49
+ /**
50
+ * Event emitter for Helia start and stop events
51
+ */
52
+ events: TypedEventEmitter<HeliaEvents<T>>;
49
53
  /**
50
54
  * Pinning operations for blocks in the blockstore
51
55
  */
@@ -96,6 +100,28 @@ export interface Helia<T extends Libp2p = Libp2p> {
96
100
  export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
97
101
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
98
102
  }
103
+ export interface HeliaEvents<T extends Libp2p = Libp2p> {
104
+ /**
105
+ * This event notifies listeners that the node has started
106
+ *
107
+ * ```TypeScript
108
+ * helia.addEventListener('start', (event) => {
109
+ * console.info(event.detail.libp2p.isStarted()) // true
110
+ * })
111
+ * ```
112
+ */
113
+ start: CustomEvent<Helia<T>>;
114
+ /**
115
+ * This event notifies listeners that the node has stopped
116
+ *
117
+ * ```TypeScript
118
+ * helia.addEventListener('stop', (event) => {
119
+ * console.info(event.detail.libp2p.isStarted()) // false
120
+ * })
121
+ * ```
122
+ */
123
+ stop: CustomEvent<Helia<T>>;
124
+ }
99
125
  export * from './blocks.js';
100
126
  export * from './errors.js';
101
127
  export * from './pins.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KA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AAE,WAAW,CAAA;IAErB;;;;OAIG;IACH,SAAS,EAAE,YAAY,CAAA;CACxB;AAED,MAAM,MAAM,QAAQ,GAClB,aAAa,CAAC,kBAAkB,EAAE,GAAG,CAAC,GACtC,aAAa,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAA;AAExC,MAAM,WAAW,SAAU,SAAQ,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC;CAEzE;AAED,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IACpD;;;;;;;;OAQG;IACH,KAAK,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;IAE5B;;;;;;;;OAQG;IACH,IAAI,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5B;AAED,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2GH,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAwIH,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "InsufficientProvidersError": "https://ipfs.github.io/helia/classes/_helia_http.InsufficientProvidersError.html",
3
+ "InvalidCodecError": "https://ipfs.github.io/helia/classes/_helia_http.InvalidCodecError.html",
3
4
  "NoRoutersAvailableError": "https://ipfs.github.io/helia/classes/_helia_http.NoRoutersAvailableError.html",
4
5
  "UnknownCodecError": "https://ipfs.github.io/helia/classes/_helia_http.UnknownCodecError.html",
5
6
  "UnknownHashAlgorithmError": "https://ipfs.github.io/helia/classes/_helia_http.UnknownHashAlgorithmError.html",
@@ -25,12 +26,12 @@
25
26
  ".:HasherLoader": "https://ipfs.github.io/helia/interfaces/helia.HasherLoader.html",
26
27
  "Helia": "https://ipfs.github.io/helia/interfaces/_helia_http.Helia.html",
27
28
  ".:Helia": "https://ipfs.github.io/helia/interfaces/helia.Helia.html",
29
+ "HeliaEvents": "https://ipfs.github.io/helia/interfaces/_helia_http.HeliaEvents.html",
30
+ ".:HeliaEvents": "https://ipfs.github.io/helia/interfaces/helia.HeliaEvents.html",
28
31
  "IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.IsPinnedOptions.html",
29
32
  "./pins:IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/helia.IsPinnedOptions.html",
30
33
  "LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.LsOptions.html",
31
34
  "./pins:LsOptions": "https://ipfs.github.io/helia/interfaces/helia.LsOptions.html",
32
- "Pair": "https://ipfs.github.io/helia/interfaces/_helia_http.Pair.html",
33
- "./blocks:Pair": "https://ipfs.github.io/helia/interfaces/helia.Pair.html",
34
35
  "Pin": "https://ipfs.github.io/helia/interfaces/_helia_http.Pin.html",
35
36
  "./pins:Pin": "https://ipfs.github.io/helia/interfaces/helia.Pin.html",
36
37
  "Pins": "https://ipfs.github.io/helia/interfaces/_helia_http.Pins.html",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "5.4.0",
3
+ "version": "6.0.0",
4
4
  "description": "The Helia API",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/ipfs/helia/tree/main/packages/interface#readme",
@@ -60,13 +60,6 @@
60
60
  "import": "./dist/src/routing.js"
61
61
  }
62
62
  },
63
- "eslintConfig": {
64
- "extends": "ipfs",
65
- "parserOptions": {
66
- "project": true,
67
- "sourceType": "module"
68
- }
69
- },
70
63
  "scripts": {
71
64
  "clean": "aegir clean",
72
65
  "lint": "aegir lint",
@@ -75,17 +68,17 @@
75
68
  "build": "aegir build"
76
69
  },
77
70
  "dependencies": {
78
- "@libp2p/interface": "^2.2.1",
79
- "@multiformats/dns": "^1.0.6",
80
- "@multiformats/multiaddr": "^12.4.0",
81
- "interface-blockstore": "^5.3.1",
82
- "interface-datastore": "^8.3.1",
83
- "interface-store": "^6.0.2",
84
- "multiformats": "^13.3.1",
71
+ "@libp2p/interface": "^3.0.2",
72
+ "@multiformats/dns": "^1.0.9",
73
+ "@multiformats/multiaddr": "^13.0.1",
74
+ "interface-blockstore": "^6.0.1",
75
+ "interface-datastore": "^9.0.2",
76
+ "interface-store": "^7.0.0",
77
+ "multiformats": "^13.4.1",
85
78
  "progress-events": "^1.0.1"
86
79
  },
87
80
  "devDependencies": {
88
- "aegir": "^47.0.7"
81
+ "aegir": "^47.0.22"
89
82
  },
90
83
  "sideEffects": false
91
84
  }
package/src/blocks.ts CHANGED
@@ -5,10 +5,7 @@ import type { AbortOptions } from 'interface-store'
5
5
  import type { CID } from 'multiformats/cid'
6
6
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
7
7
 
8
- export interface Pair {
9
- cid: CID
10
- block: Uint8Array
11
- }
8
+ export type { Pair, InputPair } from 'interface-blockstore'
12
9
 
13
10
  export interface ProviderOptions {
14
11
  /**
@@ -154,7 +151,7 @@ export interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, a
154
151
  /**
155
152
  * Make a new block available to peers
156
153
  */
157
- announce?(cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>
154
+ announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>
158
155
 
159
156
  /**
160
157
  * Create a new session
package/src/errors.ts CHANGED
@@ -33,3 +33,12 @@ export class UnknownCodecError extends Error {
33
33
  this.name = 'UnknownCodecError'
34
34
  }
35
35
  }
36
+
37
+ export class InvalidCodecError extends Error {
38
+ static name = 'InvalidCodecError'
39
+
40
+ constructor (message = 'Invalid codec') {
41
+ super(message)
42
+ this.name = 'InvalidCodecError'
43
+ }
44
+ }
package/src/index.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  import type { Blocks } from './blocks.js'
18
18
  import type { Pins } from './pins.js'
19
19
  import type { Routing } from './routing.js'
20
- import type { AbortOptions, ComponentLogger, Libp2p, Metrics } from '@libp2p/interface'
20
+ import type { AbortOptions, ComponentLogger, Libp2p, Metrics, TypedEventEmitter } from '@libp2p/interface'
21
21
  import type { DNS } from '@multiformats/dns'
22
22
  import type { Datastore } from 'interface-datastore'
23
23
  import type { Await } from 'interface-store'
@@ -54,6 +54,11 @@ export interface Helia<T extends Libp2p = Libp2p> {
54
54
  */
55
55
  datastore: Datastore
56
56
 
57
+ /**
58
+ * Event emitter for Helia start and stop events
59
+ */
60
+ events: TypedEventEmitter<HeliaEvents<T>>
61
+
57
62
  /**
58
63
  * Pinning operations for blocks in the blockstore
59
64
  */
@@ -119,6 +124,30 @@ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
119
124
 
120
125
  }
121
126
 
127
+ export interface HeliaEvents<T extends Libp2p = Libp2p> {
128
+ /**
129
+ * This event notifies listeners that the node has started
130
+ *
131
+ * ```TypeScript
132
+ * helia.addEventListener('start', (event) => {
133
+ * console.info(event.detail.libp2p.isStarted()) // true
134
+ * })
135
+ * ```
136
+ */
137
+ start: CustomEvent<Helia<T>>
138
+
139
+ /**
140
+ * This event notifies listeners that the node has stopped
141
+ *
142
+ * ```TypeScript
143
+ * helia.addEventListener('stop', (event) => {
144
+ * console.info(event.detail.libp2p.isStarted()) // false
145
+ * })
146
+ * ```
147
+ */
148
+ stop: CustomEvent<Helia<T>>
149
+ }
150
+
122
151
  export * from './blocks.js'
123
152
  export * from './errors.js'
124
153
  export * from './pins.js'