@helia/interface 3.0.1-5c6a066 → 3.0.1-76220cd

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 t=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(o,e,x,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let p of b(e))!c.call(o,p)&&p!==x&&t(o,p,{get:()=>e[p],enumerable:!(r=a(e,p))||r.enumerable});return o};var f=o=>d(t({},"__esModule",{value:!0}),o);var g={};return f(g);})();
2
+ "use strict";var HeliaInterface=(()=>{var t=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var b=(r,o,x,p)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of m(o))!a.call(r,e)&&e!==x&&t(r,e,{get:()=>o[e],enumerable:!(p=f(o,e))||p.enumerable});return r};var c=r=>b(t({},"__esModule",{value:!0}),r);var d={};return c(d);})();
3
3
  return HeliaInterface}));
@@ -1,17 +1,16 @@
1
1
  import type { Blockstore } from 'interface-blockstore';
2
2
  import type { AbortOptions } from 'interface-store';
3
- import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap';
4
3
  import type { CID } from 'multiformats/cid';
5
4
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
6
5
  export interface Pair {
7
6
  cid: CID;
8
7
  block: Uint8Array;
9
8
  }
10
- export type HasBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:providers:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID> | BitswapNotifyProgressEvents;
11
- export type PutBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:providers:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID> | BitswapNotifyProgressEvents;
12
- export type PutManyBlocksProgressEvents = ProgressEvent<'blocks:put-many:duplicate', CID> | ProgressEvent<'blocks:put-many:providers:notify', CID> | ProgressEvent<'blocks:put-many:blockstore:put-many'> | BitswapNotifyProgressEvents;
13
- export type GetBlockProgressEvents = ProgressEvent<'blocks:get:providers:want', CID> | ProgressEvent<'blocks:get:blockstore:get', CID> | ProgressEvent<'blocks:get:blockstore:put', CID> | BitswapWantProgressEvents;
14
- export type GetManyBlocksProgressEvents = ProgressEvent<'blocks:get-many:blockstore:get-many'> | ProgressEvent<'blocks:get-many:providers:want', CID> | ProgressEvent<'blocks:get-many:blockstore:put', CID> | BitswapWantProgressEvents;
9
+ export type HasBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:providers:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID>;
10
+ export type PutBlockProgressEvents = ProgressEvent<'blocks:put:duplicate', CID> | ProgressEvent<'blocks:put:providers:notify', CID> | ProgressEvent<'blocks:put:blockstore:put', CID>;
11
+ export type PutManyBlocksProgressEvents = ProgressEvent<'blocks:put-many:duplicate', CID> | ProgressEvent<'blocks:put-many:providers:notify', CID> | ProgressEvent<'blocks:put-many:blockstore:put-many'>;
12
+ export type GetBlockProgressEvents = ProgressEvent<'blocks:get:providers:want', CID> | ProgressEvent<'blocks:get:blockstore:get', CID> | ProgressEvent<'blocks:get:blockstore:put', CID>;
13
+ export type GetManyBlocksProgressEvents = ProgressEvent<'blocks:get-many:blockstore:get-many'> | ProgressEvent<'blocks:get-many:providers:want', CID> | ProgressEvent<'blocks:get-many:blockstore:put', CID>;
15
14
  export type GetAllBlocksProgressEvents = ProgressEvent<'blocks:get-all:blockstore:get-many'>;
16
15
  export type DeleteBlockProgressEvents = ProgressEvent<'blocks:delete:blockstore:delete', CID>;
17
16
  export type DeleteManyBlocksProgressEvents = ProgressEvent<'blocks:delete-many:blockstore:delete-many'>;
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../src/blocks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AAC1F,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,MAAM,sBAAsB,GAChC,aAAa,CAAC,sBAAsB,EAAE,GAAG,CAAC,GAC1C,aAAa,CAAC,6BAA6B,EAAE,GAAG,CAAC,GACjD,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,GAC/C,2BAA2B,CAAA;AAE7B,MAAM,MAAM,sBAAsB,GAChC,aAAa,CAAC,sBAAsB,EAAE,GAAG,CAAC,GAC1C,aAAa,CAAC,6BAA6B,EAAE,GAAG,CAAC,GACjD,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,GAC/C,2BAA2B,CAAA;AAE7B,MAAM,MAAM,2BAA2B,GACrC,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,GAC/C,aAAa,CAAC,kCAAkC,EAAE,GAAG,CAAC,GACtD,aAAa,CAAC,qCAAqC,CAAC,GACpD,2BAA2B,CAAA;AAE7B,MAAM,MAAM,sBAAsB,GAChC,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,GAC/C,aAAa,CAAC,2BAA2B,EAAE,GAAG,CAAC,GAC/C,aAAa,C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E,qBAAqB,CAAC,kBAAkB,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;CAC7F;AAED,MAAM,WAAW,cAAc,CAAC,qBAAqB,SAAS,eAAe,GAAG,eAAe;IAC7F;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,IAAI,CAAA;CAC7E;AAED,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,cAAc,CAAA"}
@@ -15,19 +15,16 @@
15
15
  */
16
16
  import type { Blocks } from './blocks.js';
17
17
  import type { Pins } from './pins.js';
18
- import type { Libp2p, AbortOptions, ComponentLogger } from '@libp2p/interface';
18
+ import type { Routing } from './routing.js';
19
+ import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
19
20
  import type { Datastore } from 'interface-datastore';
20
21
  import type { CID } from 'multiformats/cid';
21
22
  import type { ProgressEvent, ProgressOptions } from 'progress-events';
22
23
  export type { Await, AwaitIterable } from 'interface-store';
23
24
  /**
24
- * The API presented by a Helia node.
25
+ * The API presented by a Helia node
25
26
  */
26
- export interface Helia<T = Libp2p> {
27
- /**
28
- * The underlying libp2p node
29
- */
30
- libp2p: T;
27
+ export interface Helia {
31
28
  /**
32
29
  * Where the blocks are stored
33
30
  */
@@ -44,6 +41,11 @@ export interface Helia<T = Libp2p> {
44
41
  * A logging component that can be reused by consumers
45
42
  */
46
43
  logger: ComponentLogger;
44
+ /**
45
+ * The routing component allows performing operations such as looking up
46
+ * content providers, information about peers, etc.
47
+ */
48
+ routing: Routing;
47
49
  /**
48
50
  * Starts the Helia node
49
51
  */
@@ -60,4 +62,14 @@ export interface Helia<T = Libp2p> {
60
62
  export type GcEvents = ProgressEvent<'helia:gc:deleted', CID> | ProgressEvent<'helia:gc:error', Error>;
61
63
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
62
64
  }
65
+ /**
66
+ * DAGWalkers take a block and yield CIDs encoded in that block
67
+ */
68
+ export interface DAGWalker {
69
+ codec: number;
70
+ walk(block: Uint8Array): Generator<CID, void, undefined>;
71
+ }
72
+ export * from './blocks.js';
73
+ export * from './pins.js';
74
+ export * from './routing.js';
63
75
  //# 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,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAC9E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACpD,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,EAAE,MAAM,iBAAiB,CAAA;AAE3D;;GAEG;AACH,MAAM,WAAW,KAAK,CAAC,CAAC,GAAG,MAAM;IAC/B;;OAEG;IACH,MAAM,EAAE,CAAC,CAAA;IAET;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;IAElB;;OAEG;IACH,SAAS,EAAE,SAAS,CAAA;IAEpB;;OAEG;IACH,IAAI,EAAE,IAAI,CAAA;IAEV;;OAEG;IACH,MAAM,EAAE,eAAe,CAAA;IAEvB;;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;CACvC;AAED,MAAM,MAAM,QAAQ,GAClB,aAAa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B,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;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;CACzD;AAED,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
package/dist/src/index.js CHANGED
@@ -13,5 +13,7 @@
13
13
  * }
14
14
  * ```
15
15
  */
16
- export {};
16
+ export * from './blocks.js';
17
+ export * from './pins.js';
18
+ export * from './routing.js';
17
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA0EH,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,cAAc,CAAA"}
@@ -0,0 +1,122 @@
1
+ import type { AbortOptions, PeerId, PeerInfo } from '@libp2p/interface';
2
+ import type { CID } from 'multiformats/cid';
3
+ import type { ProgressOptions } from 'progress-events';
4
+ /**
5
+ * When a routing operation involves reading values, these options allow
6
+ * controlling where the values are read from. Some implementations support a
7
+ * local cache that may be used in preference over network calls, for example
8
+ * when a record has a TTL.
9
+ */
10
+ export interface RoutingOptions extends AbortOptions, ProgressOptions {
11
+ /**
12
+ * Pass `false` to not use the network
13
+ *
14
+ * @default true
15
+ */
16
+ useNetwork?: boolean;
17
+ /**
18
+ * Pass `false` to not use cached values
19
+ *
20
+ * @default true
21
+ */
22
+ useCache?: boolean;
23
+ }
24
+ /**
25
+ * A provider can supply the content for a CID
26
+ */
27
+ export interface Provider extends PeerInfo {
28
+ /**
29
+ * If present these are the methods that the peer can supply the content via.
30
+ *
31
+ * If not present the caller should attempt to dial the remote peer and run
32
+ * the identify protocol to discover how to retrieve the content.
33
+ *
34
+ * Example values are (but not limited to):
35
+ *
36
+ * - transport-graphsync-filecoinv1
37
+ * - transport-ipfs-gateway-http
38
+ * - transport-bitswap
39
+ */
40
+ protocols?: string[];
41
+ }
42
+ export interface Routing {
43
+ /**
44
+ * The implementation of this method should ensure that network peers know the
45
+ * caller can provide content that corresponds to the passed CID.
46
+ *
47
+ * @example
48
+ *
49
+ * ```js
50
+ * // ...
51
+ * await contentRouting.provide(cid)
52
+ * ```
53
+ */
54
+ provide(cid: CID, options?: RoutingOptions): Promise<void>;
55
+ /**
56
+ * Find the providers of the passed CID.
57
+ *
58
+ * @example
59
+ *
60
+ * ```js
61
+ * // Iterate over the providers found for the given cid
62
+ * for await (const provider of contentRouting.findProviders(cid)) {
63
+ * console.log(provider.id, provider.multiaddrs)
64
+ * }
65
+ * ```
66
+ */
67
+ findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<Provider>;
68
+ /**
69
+ * Puts a value corresponding to the passed key in a way that can later be
70
+ * retrieved by another network peer using the get method.
71
+ *
72
+ * @example
73
+ *
74
+ * ```js
75
+ * // ...
76
+ * const key = '/key'
77
+ * const value = uint8ArrayFromString('oh hello there')
78
+ *
79
+ * await contentRouting.put(key, value)
80
+ * ```
81
+ */
82
+ put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions): Promise<void>;
83
+ /**
84
+ * Retrieves a value from the network corresponding to the passed key.
85
+ *
86
+ * @example
87
+ *
88
+ * ```js
89
+ * // ...
90
+ *
91
+ * const key = '/key'
92
+ * const value = await contentRouting.get(key)
93
+ * ```
94
+ */
95
+ get(key: Uint8Array, options?: RoutingOptions): Promise<Uint8Array>;
96
+ /**
97
+ * Searches the network for peer info corresponding to the passed peer id.
98
+ *
99
+ * @example
100
+ *
101
+ * ```js
102
+ * // ...
103
+ * const peer = await peerRouting.findPeer(peerId, options)
104
+ * ```
105
+ */
106
+ findPeer(peerId: PeerId, options?: RoutingOptions): Promise<PeerInfo>;
107
+ /**
108
+ * Search the network for peers that are closer to the passed key. Peer
109
+ * info should be yielded in ever-increasing closeness to the key.
110
+ *
111
+ * @example
112
+ *
113
+ * ```js
114
+ * // Iterate over the closest peers found for the given key
115
+ * for await (const peer of peerRouting.getClosestPeers(key)) {
116
+ * console.log(peer.id, peer.multiaddrs)
117
+ * }
118
+ * ```
119
+ */
120
+ getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>;
121
+ }
122
+ //# sourceMappingURL=routing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAA;AACvE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD;;;;;GAKG;AACH,MAAM,WAAW,cAAe,SAAQ,YAAY,EAAE,eAAe;IACnE;;;;OAIG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IAEpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,QAAS,SAAQ,QAAQ;IACxC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;CACrB;AAED,MAAM,WAAW,OAAO;IACtB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE1D;;;;;;;;;;;OAWG;IACH,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;IAE1E;;;;;;;;;;;;;OAaG;IACH,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhF;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,UAAU,CAAC,CAAA;IAEnE;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;IAErE;;;;;;;;;;;;OAYG;IACH,eAAe,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAA;CACpF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=routing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing.js","sourceRoot":"","sources":["../../src/routing.ts"],"names":[],"mappings":""}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helia/interface",
3
- "version": "3.0.1-5c6a066",
3
+ "version": "3.0.1-76220cd",
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",
@@ -72,9 +72,8 @@
72
72
  "dependencies": {
73
73
  "@libp2p/interface": "^1.1.1",
74
74
  "interface-blockstore": "^5.2.7",
75
- "interface-datastore": "^8.2.2",
75
+ "interface-datastore": "^8.2.9",
76
76
  "interface-store": "^5.1.5",
77
- "ipfs-bitswap": "^20.0.0",
78
77
  "multiformats": "^13.0.0",
79
78
  "progress-events": "^1.0.0"
80
79
  },
package/src/blocks.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import type { Blockstore } from 'interface-blockstore'
2
2
  import type { AbortOptions } from 'interface-store'
3
- import type { BitswapNotifyProgressEvents, BitswapWantProgressEvents } from 'ipfs-bitswap'
4
3
  import type { CID } from 'multiformats/cid'
5
4
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
6
5
 
@@ -12,32 +11,27 @@ export interface Pair {
12
11
  export type HasBlockProgressEvents =
13
12
  ProgressEvent<'blocks:put:duplicate', CID> |
14
13
  ProgressEvent<'blocks:put:providers:notify', CID> |
15
- ProgressEvent<'blocks:put:blockstore:put', CID> |
16
- BitswapNotifyProgressEvents
14
+ ProgressEvent<'blocks:put:blockstore:put', CID>
17
15
 
18
16
  export type PutBlockProgressEvents =
19
17
  ProgressEvent<'blocks:put:duplicate', CID> |
20
18
  ProgressEvent<'blocks:put:providers:notify', CID> |
21
- ProgressEvent<'blocks:put:blockstore:put', CID> |
22
- BitswapNotifyProgressEvents
19
+ ProgressEvent<'blocks:put:blockstore:put', CID>
23
20
 
24
21
  export type PutManyBlocksProgressEvents =
25
22
  ProgressEvent<'blocks:put-many:duplicate', CID> |
26
23
  ProgressEvent<'blocks:put-many:providers:notify', CID> |
27
- ProgressEvent<'blocks:put-many:blockstore:put-many'> |
28
- BitswapNotifyProgressEvents
24
+ ProgressEvent<'blocks:put-many:blockstore:put-many'>
29
25
 
30
26
  export type GetBlockProgressEvents =
31
27
  ProgressEvent<'blocks:get:providers:want', CID> |
32
28
  ProgressEvent<'blocks:get:blockstore:get', CID> |
33
- ProgressEvent<'blocks:get:blockstore:put', CID> |
34
- BitswapWantProgressEvents
29
+ ProgressEvent<'blocks:get:blockstore:put', CID>
35
30
 
36
31
  export type GetManyBlocksProgressEvents =
37
32
  ProgressEvent<'blocks:get-many:blockstore:get-many'> |
38
33
  ProgressEvent<'blocks:get-many:providers:want', CID> |
39
- ProgressEvent<'blocks:get-many:blockstore:put', CID> |
40
- BitswapWantProgressEvents
34
+ ProgressEvent<'blocks:get-many:blockstore:put', CID>
41
35
 
42
36
  export type GetAllBlocksProgressEvents =
43
37
  ProgressEvent<'blocks:get-all:blockstore:get-many'>
package/src/index.ts CHANGED
@@ -16,7 +16,8 @@
16
16
 
17
17
  import type { Blocks } from './blocks.js'
18
18
  import type { Pins } from './pins.js'
19
- import type { Libp2p, AbortOptions, ComponentLogger } from '@libp2p/interface'
19
+ import type { Routing } from './routing.js'
20
+ import type { AbortOptions, ComponentLogger } from '@libp2p/interface'
20
21
  import type { Datastore } from 'interface-datastore'
21
22
  import type { CID } from 'multiformats/cid'
22
23
  import type { ProgressEvent, ProgressOptions } from 'progress-events'
@@ -24,14 +25,9 @@ import type { ProgressEvent, ProgressOptions } from 'progress-events'
24
25
  export type { Await, AwaitIterable } from 'interface-store'
25
26
 
26
27
  /**
27
- * The API presented by a Helia node.
28
+ * The API presented by a Helia node
28
29
  */
29
- export interface Helia<T = Libp2p> {
30
- /**
31
- * The underlying libp2p node
32
- */
33
- libp2p: T
34
-
30
+ export interface Helia {
35
31
  /**
36
32
  * Where the blocks are stored
37
33
  */
@@ -52,6 +48,12 @@ export interface Helia<T = Libp2p> {
52
48
  */
53
49
  logger: ComponentLogger
54
50
 
51
+ /**
52
+ * The routing component allows performing operations such as looking up
53
+ * content providers, information about peers, etc.
54
+ */
55
+ routing: Routing
56
+
55
57
  /**
56
58
  * Starts the Helia node
57
59
  */
@@ -75,3 +77,15 @@ export type GcEvents =
75
77
  export interface GCOptions extends AbortOptions, ProgressOptions<GcEvents> {
76
78
 
77
79
  }
80
+
81
+ /**
82
+ * DAGWalkers take a block and yield CIDs encoded in that block
83
+ */
84
+ export interface DAGWalker {
85
+ codec: number
86
+ walk(block: Uint8Array): Generator<CID, void, undefined>
87
+ }
88
+
89
+ export * from './blocks.js'
90
+ export * from './pins.js'
91
+ export * from './routing.js'
package/src/routing.ts ADDED
@@ -0,0 +1,130 @@
1
+ import type { AbortOptions, PeerId, PeerInfo } from '@libp2p/interface'
2
+ import type { CID } from 'multiformats/cid'
3
+ import type { ProgressOptions } from 'progress-events'
4
+
5
+ /**
6
+ * When a routing operation involves reading values, these options allow
7
+ * controlling where the values are read from. Some implementations support a
8
+ * local cache that may be used in preference over network calls, for example
9
+ * when a record has a TTL.
10
+ */
11
+ export interface RoutingOptions extends AbortOptions, ProgressOptions {
12
+ /**
13
+ * Pass `false` to not use the network
14
+ *
15
+ * @default true
16
+ */
17
+ useNetwork?: boolean
18
+
19
+ /**
20
+ * Pass `false` to not use cached values
21
+ *
22
+ * @default true
23
+ */
24
+ useCache?: boolean
25
+ }
26
+
27
+ /**
28
+ * A provider can supply the content for a CID
29
+ */
30
+ export interface Provider extends PeerInfo {
31
+ /**
32
+ * If present these are the methods that the peer can supply the content via.
33
+ *
34
+ * If not present the caller should attempt to dial the remote peer and run
35
+ * the identify protocol to discover how to retrieve the content.
36
+ *
37
+ * Example values are (but not limited to):
38
+ *
39
+ * - transport-graphsync-filecoinv1
40
+ * - transport-ipfs-gateway-http
41
+ * - transport-bitswap
42
+ */
43
+ protocols?: string[]
44
+ }
45
+
46
+ export interface Routing {
47
+ /**
48
+ * The implementation of this method should ensure that network peers know the
49
+ * caller can provide content that corresponds to the passed CID.
50
+ *
51
+ * @example
52
+ *
53
+ * ```js
54
+ * // ...
55
+ * await contentRouting.provide(cid)
56
+ * ```
57
+ */
58
+ provide(cid: CID, options?: RoutingOptions): Promise<void>
59
+
60
+ /**
61
+ * Find the providers of the passed CID.
62
+ *
63
+ * @example
64
+ *
65
+ * ```js
66
+ * // Iterate over the providers found for the given cid
67
+ * for await (const provider of contentRouting.findProviders(cid)) {
68
+ * console.log(provider.id, provider.multiaddrs)
69
+ * }
70
+ * ```
71
+ */
72
+ findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<Provider>
73
+
74
+ /**
75
+ * Puts a value corresponding to the passed key in a way that can later be
76
+ * retrieved by another network peer using the get method.
77
+ *
78
+ * @example
79
+ *
80
+ * ```js
81
+ * // ...
82
+ * const key = '/key'
83
+ * const value = uint8ArrayFromString('oh hello there')
84
+ *
85
+ * await contentRouting.put(key, value)
86
+ * ```
87
+ */
88
+ put(key: Uint8Array, value: Uint8Array, options?: RoutingOptions): Promise<void>
89
+
90
+ /**
91
+ * Retrieves a value from the network corresponding to the passed key.
92
+ *
93
+ * @example
94
+ *
95
+ * ```js
96
+ * // ...
97
+ *
98
+ * const key = '/key'
99
+ * const value = await contentRouting.get(key)
100
+ * ```
101
+ */
102
+ get(key: Uint8Array, options?: RoutingOptions): Promise<Uint8Array>
103
+
104
+ /**
105
+ * Searches the network for peer info corresponding to the passed peer id.
106
+ *
107
+ * @example
108
+ *
109
+ * ```js
110
+ * // ...
111
+ * const peer = await peerRouting.findPeer(peerId, options)
112
+ * ```
113
+ */
114
+ findPeer(peerId: PeerId, options?: RoutingOptions): Promise<PeerInfo>
115
+
116
+ /**
117
+ * Search the network for peers that are closer to the passed key. Peer
118
+ * info should be yielded in ever-increasing closeness to the key.
119
+ *
120
+ * @example
121
+ *
122
+ * ```js
123
+ * // Iterate over the closest peers found for the given key
124
+ * for await (const peer of peerRouting.getClosestPeers(key)) {
125
+ * console.log(peer.id, peer.multiaddrs)
126
+ * }
127
+ * ```
128
+ */
129
+ getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>
130
+ }