@helia/interface 5.3.2 → 5.4.0-061f3cdb

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.
@@ -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, 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 {\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\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,IC2JO,IAAMC,EAAgC,EAChCC,EAAgC,EC5JvC,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",
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"],
5
+ "mappings": ";kcAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,kCAAAC,EAAA,+BAAAC,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",
6
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"]
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
@@ -68,6 +65,14 @@ export interface BlockRetrievalOptions<ProgressEvents extends ProgressEvent<any,
68
65
  * and WILL consider the gateway that returned the invalid blocks completely unreliable.
69
66
  */
70
67
  validateFn?(block: Uint8Array): Promise<void>;
68
+ /**
69
+ * The maximum size a block can be in bytes.
70
+ *
71
+ * Attempts to retrieve a block larger than this will cause an error to be thrown.
72
+ *
73
+ * @default 2_097_152
74
+ */
75
+ maxSize?: number;
71
76
  }
72
77
  export interface BlockAnnounceOptions<ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {
73
78
  }
@@ -97,7 +102,7 @@ export interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, a
97
102
  /**
98
103
  * Make a new block available to peers
99
104
  */
100
- announce?(cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>;
105
+ announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>;
101
106
  /**
102
107
  * Create a new session
103
108
  */
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,WAAW,IAAI;IACnB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,UAAU,CAAA;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC,CAAA;CACpD;AAED,MAAM,MAAM,sBAAsB,GAChC,aAAa,CAAC,sBAAsB,EAAE,GAAG,CAAC,GAC1C,aAAa,CAAC,6BAA6B,EAAE,GAAG,CAAC,GACjD,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,CAAA;AAEjD,MAAM,MAAM,sBAAsB,GAChC,aAAa,CAAC,sBAAsB,EAAE,GAAG,CAAC,GAC1C,aAAa,CAAC,6BAA6B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AED,eAAO,MAAM,6BAA6B,IAAI,CAAA;AAC9C,eAAO,MAAM,6BAA6B,IAAI,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AA2JA,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA"}
1
+ {"version":3,"file":"blocks.js","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AAiKA,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA;AAC9C,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,CAAA"}
@@ -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, 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';
@@ -33,7 +33,11 @@ export interface HasherLoader {
33
33
  /**
34
34
  * The API presented by a Helia node
35
35
  */
36
- export interface Helia {
36
+ export interface Helia<T extends Libp2p = Libp2p> {
37
+ /**
38
+ * The libp2p instance
39
+ */
40
+ libp2p: T;
37
41
  /**
38
42
  * Where the blocks are stored
39
43
  */
@@ -42,6 +46,10 @@ export interface Helia {
42
46
  * A key/value store
43
47
  */
44
48
  datastore: Datastore;
49
+ /**
50
+ * Event emitter for Helia start and stop events
51
+ */
52
+ events: TypedEventEmitter<HeliaEvents<T>>;
45
53
  /**
46
54
  * Pinning operations for blocks in the blockstore
47
55
  */
@@ -92,6 +100,28 @@ export interface Helia {
92
100
  export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
93
101
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
94
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
+ }
95
125
  export * from './blocks.js';
96
126
  export * from './errors.js';
97
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,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAC/E,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAC5C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE,YAAY,EAAE,KAAK,EAAE,aAAa,EA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
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAsGH,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "5.3.2",
3
+ "version": "5.4.0-061f3cdb",
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
  /**
@@ -110,6 +107,15 @@ export interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any
110
107
  * and WILL consider the gateway that returned the invalid blocks completely unreliable.
111
108
  */
112
109
  validateFn?(block: Uint8Array): Promise<void>
110
+
111
+ /**
112
+ * The maximum size a block can be in bytes.
113
+ *
114
+ * Attempts to retrieve a block larger than this will cause an error to be thrown.
115
+ *
116
+ * @default 2_097_152
117
+ */
118
+ maxSize?: number
113
119
  }
114
120
 
115
121
  export interface BlockAnnounceOptions <ProgressEvents extends ProgressEvent<any, any> = ProgressEvent<any, any>> extends AbortOptions, ProgressOptions<ProgressEvents> {
@@ -145,7 +151,7 @@ export interface BlockBroker<RetrieveProgressEvents extends ProgressEvent<any, a
145
151
  /**
146
152
  * Make a new block available to peers
147
153
  */
148
- announce?(cid: CID, block: Uint8Array, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>
154
+ announce?(cid: CID, options?: BlockAnnounceOptions<AnnounceProgressEvents>): Promise<void>
149
155
 
150
156
  /**
151
157
  * Create a new session
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, 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'
@@ -38,7 +38,12 @@ export interface HasherLoader {
38
38
  /**
39
39
  * The API presented by a Helia node
40
40
  */
41
- export interface Helia {
41
+ export interface Helia<T extends Libp2p = Libp2p> {
42
+ /**
43
+ * The libp2p instance
44
+ */
45
+ libp2p: T
46
+
42
47
  /**
43
48
  * Where the blocks are stored
44
49
  */
@@ -49,6 +54,11 @@ export interface Helia {
49
54
  */
50
55
  datastore: Datastore
51
56
 
57
+ /**
58
+ * Event emitter for Helia start and stop events
59
+ */
60
+ events: TypedEventEmitter<HeliaEvents<T>>
61
+
52
62
  /**
53
63
  * Pinning operations for blocks in the blockstore
54
64
  */
@@ -114,6 +124,30 @@ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
114
124
 
115
125
  }
116
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
+
117
151
  export * from './blocks.js'
118
152
  export * from './errors.js'
119
153
  export * from './pins.js'
@@ -1,76 +0,0 @@
1
- {
2
- "InsufficientProvidersError": "https://ipfs.github.io/helia/classes/_helia_http.InsufficientProvidersError.html",
3
- "NoRoutersAvailableError": "https://ipfs.github.io/helia/classes/_helia_http.NoRoutersAvailableError.html",
4
- "UnknownCodecError": "https://ipfs.github.io/helia/classes/_helia_http.UnknownCodecError.html",
5
- "UnknownHashAlgorithmError": "https://ipfs.github.io/helia/classes/_helia_http.UnknownHashAlgorithmError.html",
6
- "AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.AddOptions.html",
7
- "./pins:AddOptions": "https://ipfs.github.io/helia/interfaces/helia.AddOptions.html",
8
- "BlockAnnounceOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.BlockAnnounceOptions.html",
9
- "./blocks:BlockAnnounceOptions": "https://ipfs.github.io/helia/interfaces/helia.BlockAnnounceOptions.html",
10
- "BlockBroker": "https://ipfs.github.io/helia/interfaces/_helia_http.BlockBroker.html",
11
- "./blocks:BlockBroker": "https://ipfs.github.io/helia/interfaces/helia.BlockBroker.html",
12
- "BlockRetrievalOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.BlockRetrievalOptions.html",
13
- "./blocks:BlockRetrievalOptions": "https://ipfs.github.io/helia/interfaces/helia.BlockRetrievalOptions.html",
14
- "Blocks": "https://ipfs.github.io/helia/interfaces/_helia_http.Blocks.html",
15
- "./blocks:Blocks": "https://ipfs.github.io/helia/interfaces/helia.Blocks.html",
16
- "CodecLoader": "https://ipfs.github.io/helia/interfaces/_helia_http.CodecLoader.html",
17
- ".:CodecLoader": "https://ipfs.github.io/helia/interfaces/helia.CodecLoader.html",
18
- "CreateSessionOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.CreateSessionOptions.html",
19
- "./blocks:CreateSessionOptions": "https://ipfs.github.io/helia/interfaces/helia.CreateSessionOptions.html",
20
- "GCOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.GCOptions.html",
21
- ".:GCOptions": "https://ipfs.github.io/helia/interfaces/helia.GCOptions.html",
22
- "GetOfflineOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.GetOfflineOptions.html",
23
- "./blocks:GetOfflineOptions": "https://ipfs.github.io/helia/interfaces/helia.GetOfflineOptions.html",
24
- "HasherLoader": "https://ipfs.github.io/helia/interfaces/_helia_http.HasherLoader.html",
25
- ".:HasherLoader": "https://ipfs.github.io/helia/interfaces/helia.HasherLoader.html",
26
- "Helia": "https://ipfs.github.io/helia/interfaces/_helia_http.Helia.html",
27
- ".:Helia": "https://ipfs.github.io/helia/interfaces/helia.Helia.html",
28
- "IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.IsPinnedOptions.html",
29
- "./pins:IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/helia.IsPinnedOptions.html",
30
- "LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.LsOptions.html",
31
- "./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
- "Pin": "https://ipfs.github.io/helia/interfaces/_helia_http.Pin.html",
35
- "./pins:Pin": "https://ipfs.github.io/helia/interfaces/helia.Pin.html",
36
- "Pins": "https://ipfs.github.io/helia/interfaces/_helia_http.Pins.html",
37
- "./pins:Pins": "https://ipfs.github.io/helia/interfaces/helia.Pins.html",
38
- "Provider": "https://ipfs.github.io/helia/interfaces/_helia_http.Provider.html",
39
- "./routing:Provider": "https://ipfs.github.io/helia/interfaces/helia.Provider.html",
40
- "ProviderOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.ProviderOptions.html",
41
- "./blocks:ProviderOptions": "https://ipfs.github.io/helia/interfaces/helia.ProviderOptions.html",
42
- "RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.RmOptions.html",
43
- "./pins:RmOptions": "https://ipfs.github.io/helia/interfaces/helia.RmOptions.html",
44
- "Routing": "https://ipfs.github.io/helia/interfaces/_helia_http.Routing.html",
45
- "./routing:Routing": "https://ipfs.github.io/helia/interfaces/helia.Routing.html",
46
- "RoutingOptions": "https://ipfs.github.io/helia/interfaces/_helia_http.RoutingOptions.html",
47
- "./routing:RoutingOptions": "https://ipfs.github.io/helia/interfaces/helia.RoutingOptions.html",
48
- "SessionBlockstore": "https://ipfs.github.io/helia/interfaces/_helia_http.SessionBlockstore.html",
49
- "./blocks:SessionBlockstore": "https://ipfs.github.io/helia/interfaces/helia.SessionBlockstore.html",
50
- "AddPinEvents": "https://ipfs.github.io/helia/types/_helia_http.AddPinEvents.html",
51
- "./pins:AddPinEvents": "https://ipfs.github.io/helia/types/helia.AddPinEvents.html",
52
- "DeleteBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.DeleteBlockProgressEvents.html",
53
- "./blocks:DeleteBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.DeleteBlockProgressEvents.html",
54
- "DeleteManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.DeleteManyBlocksProgressEvents.html",
55
- "./blocks:DeleteManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.DeleteManyBlocksProgressEvents.html",
56
- "GcEvents": "https://ipfs.github.io/helia/types/_helia_http.GcEvents.html",
57
- ".:GcEvents": "https://ipfs.github.io/helia/types/helia.GcEvents.html",
58
- "GetAllBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.GetAllBlocksProgressEvents.html",
59
- "./blocks:GetAllBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.GetAllBlocksProgressEvents.html",
60
- "GetBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.GetBlockProgressEvents.html",
61
- "./blocks:GetBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.GetBlockProgressEvents.html",
62
- "GetManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.GetManyBlocksProgressEvents.html",
63
- "./blocks:GetManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.GetManyBlocksProgressEvents.html",
64
- "HasBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.HasBlockProgressEvents.html",
65
- "./blocks:HasBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.HasBlockProgressEvents.html",
66
- "PinType": "https://ipfs.github.io/helia/types/_helia_http.PinType.html",
67
- "./pins:PinType": "https://ipfs.github.io/helia/types/helia.PinType.html",
68
- "PutBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.PutBlockProgressEvents.html",
69
- "./blocks:PutBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.PutBlockProgressEvents.html",
70
- "PutManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_http.PutManyBlocksProgressEvents.html",
71
- "./blocks:PutManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.PutManyBlocksProgressEvents.html",
72
- "DEFAULT_SESSION_MAX_PROVIDERS": "https://ipfs.github.io/helia/variables/_helia_http.DEFAULT_SESSION_MAX_PROVIDERS.html",
73
- "./blocks:DEFAULT_SESSION_MAX_PROVIDERS": "https://ipfs.github.io/helia/variables/helia.DEFAULT_SESSION_MAX_PROVIDERS.html",
74
- "DEFAULT_SESSION_MIN_PROVIDERS": "https://ipfs.github.io/helia/variables/_helia_http.DEFAULT_SESSION_MIN_PROVIDERS.html",
75
- "./blocks:DEFAULT_SESSION_MIN_PROVIDERS": "https://ipfs.github.io/helia/variables/helia.DEFAULT_SESSION_MIN_PROVIDERS.html"
76
- }