@helia/interface 4.3.0 → 4.3.1-2f88fc8

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,3 +1,3 @@
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 E=Object.defineProperty;var e=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var x=Object.prototype.hasOwnProperty;var I=(r,o)=>{for(var t in o)E(r,t,{get:o[t],enumerable:!0})},D=(r,o,t,_)=>{if(o&&typeof o=="object"||typeof o=="function")for(let S of p(o))!x.call(r,S)&&S!==t&&E(r,S,{get:()=>o[S],enumerable:!(_=e(o,S))||_.enumerable});return r};var O=r=>D(E({},"__esModule",{value:!0}),r);var R={};I(R,{DEFAULT_SESSION_MAX_PROVIDERS:()=>A,DEFAULT_SESSION_MIN_PROVIDERS:()=>m});var m=1,A=5;return O(R);})();
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);})();
3
3
  return HeliaInterface}));
@@ -44,7 +44,7 @@ export interface BlockRetrievalOptions<ProgressEvents extends ProgressEvent<any,
44
44
  /**
45
45
  * A function that blockBrokers should call prior to returning a block to ensure it can maintain control
46
46
  * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block
47
- * is valid from one of the gateways before assuming it's work is done. If the block is not valid, it should try another gateway
47
+ * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway
48
48
  * and WILL consider the gateway that returned the invalid blocks completely unreliable.
49
49
  */
50
50
  validateFn?(block: Uint8Array): Promise<void>;
@@ -0,0 +1,17 @@
1
+ export declare class InsufficientProvidersError extends Error {
2
+ static name: string;
3
+ constructor(message?: string);
4
+ }
5
+ export declare class NoRoutersAvailableError extends Error {
6
+ static name: string;
7
+ constructor(message?: string);
8
+ }
9
+ export declare class UnknownHashAlgorithmError extends Error {
10
+ static name: string;
11
+ constructor(message?: string);
12
+ }
13
+ export declare class UnknownCodecError extends Error {
14
+ static name: string;
15
+ constructor(message?: string);
16
+ }
17
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,29 @@
1
+ export class InsufficientProvidersError extends Error {
2
+ static name = 'InsufficientProvidersError';
3
+ constructor(message = 'Insufficient providers found') {
4
+ super(message);
5
+ this.name = 'InsufficientProvidersError';
6
+ }
7
+ }
8
+ export class NoRoutersAvailableError extends Error {
9
+ static name = 'NoRoutersAvailableError';
10
+ constructor(message = 'No routers available') {
11
+ super(message);
12
+ this.name = 'NoRoutersAvailableError';
13
+ }
14
+ }
15
+ export class UnknownHashAlgorithmError extends Error {
16
+ static name = 'UnknownHashAlgorithmError';
17
+ constructor(message = 'Unknown hash algorithm') {
18
+ super(message);
19
+ this.name = 'UnknownHashAlgorithmError';
20
+ }
21
+ }
22
+ export class UnknownCodecError extends Error {
23
+ static name = 'UnknownCodecError';
24
+ constructor(message = 'Unknown codec') {
25
+ super(message);
26
+ this.name = 'UnknownCodecError';
27
+ }
28
+ }
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +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"}
@@ -19,10 +19,17 @@ import type { Routing } from './routing.js';
19
19
  import type { AbortOptions, ComponentLogger, Metrics } from '@libp2p/interface';
20
20
  import type { DNS } from '@multiformats/dns';
21
21
  import type { Datastore } from 'interface-datastore';
22
- import type { MultihashHasher } from 'multiformats';
22
+ import type { Await } from 'interface-store';
23
+ import type { BlockCodec, MultihashHasher } from 'multiformats';
23
24
  import type { CID } from 'multiformats/cid';
24
25
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
25
26
  export type { Await, AwaitIterable } from 'interface-store';
27
+ export interface CodecLoader {
28
+ <T = any, Code extends number = any>(code: Code): Await<BlockCodec<Code, T>>;
29
+ }
30
+ export interface HasherLoader {
31
+ (code: number): Await<MultihashHasher>;
32
+ }
26
33
  /**
27
34
  * The API presented by a Helia node
28
35
  */
@@ -48,16 +55,6 @@ export interface Helia {
48
55
  * content providers, information about peers, etc.
49
56
  */
50
57
  routing: Routing;
51
- /**
52
- * DAGWalkers are codec-specific implementations that know how to yield all
53
- * CIDs contained within a block that corresponds to that codec.
54
- */
55
- dagWalkers: Record<number, DAGWalker>;
56
- /**
57
- * Hashers can be used to hash a piece of data with the specified hashing
58
- * algorithm.
59
- */
60
- hashers: Record<number, MultihashHasher>;
61
58
  /**
62
59
  * The DNS property can be used to perform lookups of various record types and
63
60
  * will use a resolver appropriate to the current platform.
@@ -80,18 +77,23 @@ export interface Helia {
80
77
  * Remove any unpinned blocks from the blockstore
81
78
  */
82
79
  gc(options?: GCOptions): Promise<void>;
80
+ /**
81
+ * Load an IPLD codec. Implementations may return a promise if, for example,
82
+ * the codec is being fetched from the network.
83
+ */
84
+ getCodec: CodecLoader;
85
+ /**
86
+ * Hashers can be used to hash a piece of data with the specified hashing
87
+ * algorithm. Implementations may return a promise if, for example,
88
+ * the hasher is being fetched from the network.
89
+ */
90
+ getHasher: HasherLoader;
83
91
  }
84
92
  export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
85
93
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
86
94
  }
87
- /**
88
- * DAGWalkers take a block and yield CIDs encoded in that block
89
- */
90
- export interface DAGWalker {
91
- codec: number;
92
- walk(block: Uint8Array): Generator<CID, void, undefined>;
93
- }
94
95
  export * from './blocks.js';
96
+ export * from './errors.js';
95
97
  export * from './pins.js';
96
98
  export * from './routing.js';
97
99
  //# sourceMappingURL=index.d.ts.map
@@ -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,eAAe,EAAE,MAAM,cAAc,CAAA;AACnD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,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AAI,EAAE,IAAI,CAAA;IAEV;;OAEG;IACH,MAAM,EAAE,eAAe,CAAA;IAEvB;;;OAGG;IACH,OAAO,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,GAAG,EAAE,GAAG,CAAA;IAER;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;OAEG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IAErB;;OAEG;IACH,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEtC;;;OAGG;IACH,QAAQ,EAAE,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,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
package/dist/src/index.js CHANGED
@@ -14,6 +14,7 @@
14
14
  * ```
15
15
  */
16
16
  export * from './blocks.js';
17
+ export * from './errors.js';
17
18
  export * from './pins.js';
18
19
  export * from './routing.js';
19
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAoGH,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;AAsGH,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
@@ -6,7 +6,7 @@ export type PinType = 'recursive' | 'direct' | 'indirect';
6
6
  export interface Pin {
7
7
  cid: CID;
8
8
  depth: number;
9
- metadata: Record<string, any>;
9
+ metadata: Record<string, string | number | boolean>;
10
10
  }
11
11
  export type AddPinEvents = ProgressEvent<'helia:pin:add', CID>;
12
12
  export interface AddOptions extends AbortOptions, ProgressOptions<AddPinEvents | GetBlockProgressEvents> {
@@ -1 +1 @@
1
- {"version":3,"file":"pins.d.ts","sourceRoot":"","sources":["../../src/pins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAErE,MAAM,MAAM,OAAO,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,CAAA;AAEzD,MAAM,WAAW,GAAG;IAClB,GAAG,EAAE,GAAG,CAAA;IACR,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC9B;AAED,MAAM,MAAM,YAAY,GACtB,aAAa,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;AAErC,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe,CAAC,YAAY,GAAG,sBAAsB,CAAC;IACtG;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,SAAU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CACpD;AAED,MAAM,MAAM,YAAY,GACtB,aAAa,CAAC,eAAe,EAAE,GAAG,CAAC,CAAA;AAErC,MAAM,WAAW,UAAW,SAAQ,YAAY,EAAE,eAAe,CAAC,YAAY,GAAG,sBAAsB,CAAC;IACtG;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAA;CACrD;AAED,MAAM,WAAW,SAAU,SAAQ,YAAY;CAE9C;AAED,MAAM,WAAW,SAAU,SAAQ,YAAY;IAC7C,GAAG,CAAC,EAAE,GAAG,CAAA;CACV;AAED,MAAM,WAAW,eAAgB,SAAQ,YAAY;CAEpD;AAED,MAAM,WAAW,IAAI;IACnB;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAEzE;;;OAGG;IACH,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,SAAS,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAEvE;;OAEG;IACH,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAE7D;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CAChE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "4.3.0",
3
+ "version": "4.3.1-2f88fc8",
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",
@@ -67,19 +67,20 @@
67
67
  "clean": "aegir clean",
68
68
  "lint": "aegir lint",
69
69
  "dep-check": "aegir dep-check",
70
+ "doc-check": "aegir doc-check",
70
71
  "build": "aegir build"
71
72
  },
72
73
  "dependencies": {
73
- "@libp2p/interface": "^1.1.4",
74
+ "@libp2p/interface": "^2.0.0",
74
75
  "@multiformats/dns": "^1.0.1",
75
76
  "interface-blockstore": "^5.2.10",
76
77
  "interface-datastore": "^8.2.11",
77
- "interface-store": "^5.1.8",
78
+ "interface-store": "^6.0.0",
78
79
  "multiformats": "^13.1.0",
79
80
  "progress-events": "^1.0.0"
80
81
  },
81
82
  "devDependencies": {
82
- "aegir": "^42.2.5"
83
+ "aegir": "^44.0.1"
83
84
  },
84
85
  "sideEffects": false
85
86
  }
package/src/blocks.ts CHANGED
@@ -84,7 +84,7 @@ export interface BlockRetrievalOptions <ProgressEvents extends ProgressEvent<any
84
84
  /**
85
85
  * A function that blockBrokers should call prior to returning a block to ensure it can maintain control
86
86
  * of the block request flow. e.g. TrustedGatewayBlockBroker will use this to ensure that the block
87
- * is valid from one of the gateways before assuming it's work is done. If the block is not valid, it should try another gateway
87
+ * is valid from one of the gateways before assuming its work is done. If the block is not valid, it should try another gateway
88
88
  * and WILL consider the gateway that returned the invalid blocks completely unreliable.
89
89
  */
90
90
  validateFn?(block: Uint8Array): Promise<void>
package/src/errors.ts ADDED
@@ -0,0 +1,35 @@
1
+ export class InsufficientProvidersError extends Error {
2
+ static name = 'InsufficientProvidersError'
3
+
4
+ constructor (message = 'Insufficient providers found') {
5
+ super(message)
6
+ this.name = 'InsufficientProvidersError'
7
+ }
8
+ }
9
+
10
+ export class NoRoutersAvailableError extends Error {
11
+ static name = 'NoRoutersAvailableError'
12
+
13
+ constructor (message = 'No routers available') {
14
+ super(message)
15
+ this.name = 'NoRoutersAvailableError'
16
+ }
17
+ }
18
+
19
+ export class UnknownHashAlgorithmError extends Error {
20
+ static name = 'UnknownHashAlgorithmError'
21
+
22
+ constructor (message = 'Unknown hash algorithm') {
23
+ super(message)
24
+ this.name = 'UnknownHashAlgorithmError'
25
+ }
26
+ }
27
+
28
+ export class UnknownCodecError extends Error {
29
+ static name = 'UnknownCodecError'
30
+
31
+ constructor (message = 'Unknown codec') {
32
+ super(message)
33
+ this.name = 'UnknownCodecError'
34
+ }
35
+ }
package/src/index.ts CHANGED
@@ -20,12 +20,21 @@ import type { Routing } from './routing.js'
20
20
  import type { AbortOptions, ComponentLogger, Metrics } from '@libp2p/interface'
21
21
  import type { DNS } from '@multiformats/dns'
22
22
  import type { Datastore } from 'interface-datastore'
23
- import type { MultihashHasher } from 'multiformats'
23
+ import type { Await } from 'interface-store'
24
+ import type { BlockCodec, MultihashHasher } from 'multiformats'
24
25
  import type { CID } from 'multiformats/cid'
25
26
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
26
27
 
27
28
  export type { Await, AwaitIterable } from 'interface-store'
28
29
 
30
+ export interface CodecLoader {
31
+ <T = any, Code extends number = any>(code: Code): Await<BlockCodec<Code, T>>
32
+ }
33
+
34
+ export interface HasherLoader {
35
+ (code: number): Await<MultihashHasher>
36
+ }
37
+
29
38
  /**
30
39
  * The API presented by a Helia node
31
40
  */
@@ -56,18 +65,6 @@ export interface Helia {
56
65
  */
57
66
  routing: Routing
58
67
 
59
- /**
60
- * DAGWalkers are codec-specific implementations that know how to yield all
61
- * CIDs contained within a block that corresponds to that codec.
62
- */
63
- dagWalkers: Record<number, DAGWalker>
64
-
65
- /**
66
- * Hashers can be used to hash a piece of data with the specified hashing
67
- * algorithm.
68
- */
69
- hashers: Record<number, MultihashHasher>
70
-
71
68
  /**
72
69
  * The DNS property can be used to perform lookups of various record types and
73
70
  * will use a resolver appropriate to the current platform.
@@ -94,6 +91,19 @@ export interface Helia {
94
91
  * Remove any unpinned blocks from the blockstore
95
92
  */
96
93
  gc(options?: GCOptions): Promise<void>
94
+
95
+ /**
96
+ * Load an IPLD codec. Implementations may return a promise if, for example,
97
+ * the codec is being fetched from the network.
98
+ */
99
+ getCodec: CodecLoader
100
+
101
+ /**
102
+ * Hashers can be used to hash a piece of data with the specified hashing
103
+ * algorithm. Implementations may return a promise if, for example,
104
+ * the hasher is being fetched from the network.
105
+ */
106
+ getHasher: HasherLoader
97
107
  }
98
108
 
99
109
  export type GcEvents =
@@ -104,14 +114,7 @@ export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
104
114
 
105
115
  }
106
116
 
107
- /**
108
- * DAGWalkers take a block and yield CIDs encoded in that block
109
- */
110
- export interface DAGWalker {
111
- codec: number
112
- walk(block: Uint8Array): Generator<CID, void, undefined>
113
- }
114
-
115
117
  export * from './blocks.js'
118
+ export * from './errors.js'
116
119
  export * from './pins.js'
117
120
  export * from './routing.js'
package/src/pins.ts CHANGED
@@ -8,7 +8,7 @@ export type PinType = 'recursive' | 'direct' | 'indirect'
8
8
  export interface Pin {
9
9
  cid: CID
10
10
  depth: number
11
- metadata: Record<string, any>
11
+ metadata: Record<string, string | number | boolean>
12
12
  }
13
13
 
14
14
  export type AddPinEvents =
@@ -1,65 +0,0 @@
1
- {
2
- "AddOptions": "https://ipfs.github.io/helia/interfaces/helia.AddOptions.html",
3
- "./pins:AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.AddOptions.html",
4
- "BlockAnnounceOptions": "https://ipfs.github.io/helia/interfaces/helia.BlockAnnounceOptions.html",
5
- "./blocks:BlockAnnounceOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.BlockAnnounceOptions.html",
6
- "BlockBroker": "https://ipfs.github.io/helia/interfaces/helia.BlockBroker.html",
7
- "./blocks:BlockBroker": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.BlockBroker.html",
8
- "BlockRetrievalOptions": "https://ipfs.github.io/helia/interfaces/helia.BlockRetrievalOptions.html",
9
- "./blocks:BlockRetrievalOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.BlockRetrievalOptions.html",
10
- "Blocks": "https://ipfs.github.io/helia/interfaces/helia.Blocks.html",
11
- "./blocks:Blocks": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.Blocks.html",
12
- "CreateSessionOptions": "https://ipfs.github.io/helia/interfaces/helia.CreateSessionOptions.html",
13
- "./blocks:CreateSessionOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.CreateSessionOptions.html",
14
- "GCOptions": "https://ipfs.github.io/helia/interfaces/helia.GCOptions.html",
15
- ".:GCOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.index.GCOptions.html",
16
- "GetOfflineOptions": "https://ipfs.github.io/helia/interfaces/helia.GetOfflineOptions.html",
17
- "./blocks:GetOfflineOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.GetOfflineOptions.html",
18
- "Helia": "https://ipfs.github.io/helia/interfaces/helia.Helia.html",
19
- ".:Helia": "https://ipfs.github.io/helia/interfaces/_helia_interface.index.Helia.html",
20
- "IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/helia.IsPinnedOptions.html",
21
- "./pins:IsPinnedOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.IsPinnedOptions.html",
22
- "LsOptions": "https://ipfs.github.io/helia/interfaces/helia.LsOptions.html",
23
- "./pins:LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.LsOptions.html",
24
- "Pair": "https://ipfs.github.io/helia/interfaces/helia.Pair.html",
25
- "./blocks:Pair": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.Pair.html",
26
- "Pin": "https://ipfs.github.io/helia/interfaces/helia.Pin.html",
27
- "./pins:Pin": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.Pin.html",
28
- "Pins": "https://ipfs.github.io/helia/interfaces/helia.Pins.html",
29
- "./pins:Pins": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.Pins.html",
30
- "Provider": "https://ipfs.github.io/helia/interfaces/helia.Provider.html",
31
- "RmOptions": "https://ipfs.github.io/helia/interfaces/helia.RmOptions.html",
32
- "./pins:RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_interface.pins.RmOptions.html",
33
- "Routing": "https://ipfs.github.io/helia/interfaces/helia.Routing.html",
34
- "RoutingOptions": "https://ipfs.github.io/helia/interfaces/helia.RoutingOptions.html",
35
- "SessionBlockstore": "https://ipfs.github.io/helia/interfaces/helia.SessionBlockstore.html",
36
- "./blocks:SessionBlockstore": "https://ipfs.github.io/helia/interfaces/_helia_interface.blocks.SessionBlockstore.html",
37
- "AddPinEvents": "https://ipfs.github.io/helia/types/helia.AddPinEvents.html",
38
- "./pins:AddPinEvents": "https://ipfs.github.io/helia/types/_helia_interface.pins.AddPinEvents.html",
39
- "DeleteBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.DeleteBlockProgressEvents.html",
40
- "./blocks:DeleteBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.DeleteBlockProgressEvents.html",
41
- "DeleteManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.DeleteManyBlocksProgressEvents.html",
42
- "./blocks:DeleteManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.DeleteManyBlocksProgressEvents.html",
43
- "GcEvents": "https://ipfs.github.io/helia/types/helia.GcEvents.html",
44
- ".:GcEvents": "https://ipfs.github.io/helia/types/_helia_interface.index.GcEvents.html",
45
- "GetAllBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.GetAllBlocksProgressEvents.html",
46
- "./blocks:GetAllBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.GetAllBlocksProgressEvents.html",
47
- "GetBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.GetBlockProgressEvents.html",
48
- "./blocks:GetBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.GetBlockProgressEvents.html",
49
- "GetManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.GetManyBlocksProgressEvents.html",
50
- "./blocks:GetManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.GetManyBlocksProgressEvents.html",
51
- "HasBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.HasBlockProgressEvents.html",
52
- "./blocks:HasBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.HasBlockProgressEvents.html",
53
- "PinType": "https://ipfs.github.io/helia/types/helia.PinType.html",
54
- "./pins:PinType": "https://ipfs.github.io/helia/types/_helia_interface.pins.PinType.html",
55
- "PutBlockProgressEvents": "https://ipfs.github.io/helia/types/helia.PutBlockProgressEvents.html",
56
- "./blocks:PutBlockProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.PutBlockProgressEvents.html",
57
- "PutManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/helia.PutManyBlocksProgressEvents.html",
58
- "./blocks:PutManyBlocksProgressEvents": "https://ipfs.github.io/helia/types/_helia_interface.blocks.PutManyBlocksProgressEvents.html",
59
- "DEFAULT_SESSION_MAX_PROVIDERS": "https://ipfs.github.io/helia/variables/helia.DEFAULT_SESSION_MAX_PROVIDERS.html",
60
- "./blocks:DEFAULT_SESSION_MAX_PROVIDERS": "https://ipfs.github.io/helia/variables/_helia_interface.blocks.DEFAULT_SESSION_MAX_PROVIDERS.html",
61
- "DEFAULT_SESSION_MIN_PROVIDERS": "https://ipfs.github.io/helia/variables/helia.DEFAULT_SESSION_MIN_PROVIDERS.html",
62
- "./blocks:DEFAULT_SESSION_MIN_PROVIDERS": "https://ipfs.github.io/helia/variables/_helia_interface.blocks.DEFAULT_SESSION_MIN_PROVIDERS.html",
63
- "DAGWalker": "https://ipfs.github.io/helia/interfaces/_helia_http.DAGWalker.html",
64
- ".:DAGWalker": "https://ipfs.github.io/helia/interfaces/_helia_interface.index.DAGWalker.html"
65
- }